See this article for a high-level view of goals and what the dynamic runtime is used for. This section describes the details for how it's implemented for developers and framework builders.
When you have the dynamic runtime, you have an important option to choose for classes - should the system track "live dynamic types". When this is true for a type, we code-generate an additional code into the constructor to register each instance for a given class. We can return the list of instances of any of these tracked types, and update these instances in response to code changes. This requires the use of DynUtil.dispose() for instances you manage yourself. Top-level object instances and their children are usually disposed automatically by the framework code that creates them (e.g. when a session expires, or at the end of a request, or when a managed list of components gets smaller).
You can set the liveDynamicTypes flag globally with an 'scc' command line option, on a specific type via CompilerSettings, or in a layer to restrict the setting to a specific group of types in that layer.
All dynamic objects implement the IDynObject interface. When one dynamic object extends a class which is already dynamic, it will use the IDynObject implementation of it's base class and unless "needsCompiledClass" is true, it will not even generate a Java class of its own. When a dynamic class extends a compiled class, a dynamic stub class is generated. This class implements IDynObject and stores the type and properties for that instance. When a class neither extends a compiled class, or another dynamic class an instance of DynObject is created to store the type and properties.
You can make a layer dynamic in one of two ways. Use the dynamic keyword before the layer name in the layer definition file. It will be dynamic whenever it's used. You can also use the -dyn option on the command line. Any layers after the -dyn option will be made dynamic by default unless they are marked as "compiledOnly" in the layer definition file. In addition, any layers extended by those -dyn layers are also made dynamic unless they are compiled only (use -dynone so only the specified layers are dynamic). Dynamic layers always follow compiled layers in the layer stack, so it's not allowed to extend a dynamic layer from a compiled layer.
A type can be made dynamic by defining it or modifying it in a dynamic layer, or by using the dynamic keyword before the 'class' or 'object' when you define it in the layer.