Skip to main content

Compiling and Deploying Classes

You can compile classes using an IDE (as documented elsewhere), and you can compile them programmatically as described in this topic. This topic also provides details on the compiler behavior. Finally, this topic describes how to put compiled classes into deployed mode.

Compiling Programmatically

You can compile classes programmatically by using the Compile() method of the %SYSTEM.OBJOpens in a new tab class:

 Do $System.OBJ.Compile("MyApp.MyClass")

The %SYSTEM.OBJOpens in a new tab class provides additional methods you can use for compiling multiple classes.

Class Compiler Basics

InterSystems IRIS® data platform class definitions must be compiled before they can be used.

The class compiler differs from the compilers available with other programming languages, such Java, in two significant ways: first, the results of compilation are placed into a shared repository (database), not a file system. Second, it automatically provides support for persistent classes.

Specifically, the class compiler does the following:

  1. It generates a list of dependencies — classes that must be compiled first. Depending on the compile options used, any dependencies that have been modified since last being compiled will also be compiled.

  2. It resolves inheritance — it determines which methods, properties, and other class members are inherited from superclasses. It stores this inheritance information into the class dictionary for later reference.

  3. For persistent and serial classes, it determines the storage structure needed to store objects in the database and creates the necessary runtime information needed for the SQL representation of the class.

  4. It executes any method generators defined (or inherited) by the class.

  5. It creates one or more routines that contain the runtime code for the class. The class compiler groups methods according to language (ObjectScript and Basic) and generates separate routines, each containing methods of one language or the other.

  6. It compiles all of the generated routines into executable code.

  7. It creates a class descriptor. This is a special data structure (stored as a routine) that contains all the runtime dispatch information needed to support a class (names of properties, locations of methods, and so on).

Class Compiler Notes

Compilation Order

When you compile a class, the system also recompiles other classes if the class that you are compiling contains information about dependencies. For example, the system compiles any subclasses of the class. On some occasions, you may need to control the order in which the classes are compiled. To do so, use the System, DependsOn, and CompileAfter keywords. For details, see the Class Definition Reference.

To find the classes that the compiler will recompile when you compile a given class, use the $SYSTEM.OBJ.GetDependencies() method. For example:

TESTNAMESPACE>d $system.OBJ.GetDependencies("Sample.Address",.included)

The signature of this method is as follows:

classmethod GetDependencies(ByRef class As %String, 
                            Output included As %String,
                            qspec As %String) as %Status


  • class is either a single class name (as in the example), a comma-separated list of class names, or a multidimensional array of class names. (If it is a multidimensional array, be sure to pass this argument by reference.) It can also include wildcards.

  • included is a multidimensional array of the names of the classes that will be compiled when class is compiled.

  • qspec is a string of compiler flags and qualifiers. If you omit this, the method uses the current compiler flags and qualifiers.

Compiling Classes that Include Bitmap Indexes

When compiling a class that contains a bitmap index, the class compiler generates a bitmap extent index if no bitmap extent index is defined for that class. Special care is required when adding a bitmap index to a class on a production system. For more information, see Generating a Bitmap Extent Index.

Compiling When There Are Existing Instances of a Class in Memory

If the compiler is called while an instance of the class being compiled is open, there is no error. The already open instance continues to use its existing code. If another instance is opened after compilation, it uses the newly compiled code.

Putting Classes in Deployed Mode

You might want to put some of your classes in deployed mode before you send them to customers; this process hides the source code.

For any class definitions that contain method definitions that you do not want customers to see, compile the classes and then use $SYSTEM.OBJ.MakeClassDeployed(). For example:

 do $system.OBJ.MakeClassDeployed("MyApp.MyClass")

For an alternative approach, see Adding Compiled Code to Customer Databases.

About Deployed Mode

When a class is in deployed mode, its method and trigger definitions have been removed. (Note that if the class is a data type class, its method definitions are retained because they may be needed at runtime by cached queries.)

You cannot export or compile a class that is in deployed mode, but you can compile its subclasses (if they are not in deployed mode).

There is no way to reverse or undo deployment of a class. You can, however, replace the class by importing the definition from a file, if you previously saved it to disk. (This is useful if you accidentally put one of your classes into deployed mode prematurely.)

See Also

FeedbackOpens in a new tab