Search in sources :

Example 6 with StackBrowser

use of org.jikesrvm.runtime.StackBrowser in project JikesRVM by JikesRVM.

the class RVMClass method getClassLoaderFromStackFrame.

// --------------------------------------------------------------------//
// Miscellaneous queries.                         //
// ---------------------------------------------------------------------//
/**
 * Support for user-written class loaders:
 * It's required to find the classloader of the class
 * whose method requires another class to be loaded;
 * the initiating loader of the required class is the
 * defining loader of the requiring class.
 *
 * @param skip specifies the number of frames back from the
 *             caller to the method whose class's loader is required
 *
 * @return the class loader
 */
@Entrypoint
public static ClassLoader getClassLoaderFromStackFrame(int skip) {
    // account for stack frame of this function
    skip++;
    StackBrowser browser = new StackBrowser();
    VM.disableGC();
    browser.init();
    while (skip-- > 0) browser.up();
    VM.enableGC();
    return browser.getClassLoader();
}
Also used : StackBrowser(org.jikesrvm.runtime.StackBrowser) Entrypoint(org.vmmagic.pragma.Entrypoint)

Aggregations

StackBrowser (org.jikesrvm.runtime.StackBrowser)6 RVMType (org.jikesrvm.classloader.RVMType)2 Entrypoint (org.vmmagic.pragma.Entrypoint)2 BootstrapClassLoader (org.jikesrvm.classloader.BootstrapClassLoader)1 RVMClass (org.jikesrvm.classloader.RVMClass)1