Skip to content

VMProcessClassLoader

opencode-agent[bot] edited this page May 10, 2026 · 1 revision

VMProcessClassLoader

Classloader for VM processes that loads classes from the VM process's classpath, providing process isolation through a dedicated classloader hierarchy.

Overview

JNode's VMProcessClassLoader (org.jnode.vm.VmProcessClassLoader) is a specialized Java ClassLoader that provides class loading for VM processes created via VmProcess.createProcess(). Unlike JNode's primary VmClassLoader hierarchy (which integrates with the plugin system and handles class definition for the VM kernel), VMProcessClassLoader operates at the user-level process abstraction.

The key design rationale is process isolation: each VmProcess gets its own VmProcessClassLoader instance with a parent-first delegation that can selectively skip the parent for specific core classes. This ensures that system classes like java.lang.System and org.jnode.vm.VmProcess are loaded from the VM's core classes rather than from the process's classpath, preventing processes from accidentally overriding critical system classes.

VmProcessClassLoader extends the standard Java ClassLoader rather than JNode's VmClassLoader because it operates in a different layer — the user-process layer built on top of the VM, not the VM kernel itself.

Key Components

Class / File Role
core/src/core/org/jnode/vm/VmProcessClassLoader.java Main classloader implementation
core/src/core/org/jnode/vm/VmProcess.java VM process creation, uses VmProcessClassLoader for process isolation

How It Works

Process Creation Flow

When VmProcess.createProcess() is invoked, it:

  1. Creates a new VmProcessClassLoader instance
  2. Uses this classloader to load VmProcess class
  3. Reflectively instantiates a new VmProcess via the constructor
  4. The new process runs with its own classloader, isolated from the parent
// From VmProcess.java:121-142
public static Process createProcess(String mainClassName, String[] args, String[] envp)
    throws Exception {
    final ClassLoader cl = new VmProcessClassLoader();
    final Class processClass = cl.loadClass(VmProcess.class.getName());
    // ... reflective instantiation
}

Skip Class Mechanism

The VmProcessClassLoader maintains a HashSet<String> of class names that should not be delegated to the parent classloader:

// From VmProcessClassLoader.java:33-45
private final HashSet<String> skipClassNames;
public VmProcessClassLoader(ClassLoader parent) {
    super(parent);
    skipClassNames = new HashSet<String>();
    skipClassNames.add("java.lang.System");
    skipClassNames.add("org.jnode.vm.VmProcess");
}

The skipParentLoader(String name) method checks if a class should bypass the parent:

// From VmProcessClassLoader.java:54-57
public boolean skipParentLoader(String name) {
    name = name.replace('/', '.');
    return skipClassNames.contains(name);
}

This ensures that critical system classes are always loaded from the VM's core, not from any process-specific classpath.

Classloader Hierarchy

BootstrapClassLoader (JVM built-in)
  └── SystemClassLoader (ClassLoader.getSystemClassLoader())
        └── VmProcessClassLoader (per-process instance)
              └── [Process classes loaded from process classpath]

Gotchas & Non-Obvious Behavior

  • Standard ClassLoader, not VmClassLoaderVmProcessClassLoader extends java.lang.ClassLoader directly, not JNode's VmClassLoader. This is by design: it operates in the user-process layer, not the VM kernel layer.
  • skipParentLoader is advisory — The skipParentLoader() method exists but is not automatically invoked during normal loadClass() delegation. The caller (typically VmProcess) must check this explicitly before deciding whether to delegate to the parent.
  • Process isolation is lightweight — Unlike Isolate which provides strong isolation via separate statics tables, VmProcess isolation is primarily through the classloader. Both approaches exist in JNode for different use cases.
  • Default parent is system classloader — The no-arg constructor uses ClassLoader.getSystemClassLoader() as the parent, ensuring access to core Java classes.

Related Pages

Clone this wiki locally