org.jikesrvm
Class Callbacks

java.lang.Object
  extended by org.jikesrvm.Callbacks

public final class Callbacks
extends Object

A class for managing various callbacks from the VM.

Consumers should register an implementation of the needed interface with a given callback method, and will get notified when the event happens.

Note: callback consumers should not rely on any particular order of callback invocation.

TODO: allow limited control over callback order.

The following events are currently implemented. See code for exact invocation syntax.


Nested Class Summary
static interface Callbacks.AppCompleteMonitor
          Interface for monitoring when an application completes executing
static interface Callbacks.AppRunCompleteMonitor
          Interface for monitoring when an application completes a run
static interface Callbacks.AppRunStartMonitor
          Interface for monitoring when an application starts a run
static interface Callbacks.AppStartMonitor
          Interface for monitoring when an application starts executing
static interface Callbacks.BootImageMonitor
          Interface for monitoring boot image writing.
private static class Callbacks.CallbackList
          Linked list of callbacks.
static interface Callbacks.ClassInitializedMonitor
          Interface for monitoring class initialization.
static interface Callbacks.ClassInstantiatedMonitor
          Interface for monitoring class instantiation.
static interface Callbacks.ClassLoadedMonitor
          Interface for monitoring class loading.
static interface Callbacks.ClassResolvedMonitor
          Interface for monitoring class resolution.
static interface Callbacks.DefineClassMonitor
          Interface for monitoring defineClass calls.
static interface Callbacks.ExitMonitor
          Interface for monitoring VM exit.
static interface Callbacks.ForNameMonitor
          Interface for monitoring forName calls.
static interface Callbacks.LoadClassMonitor
          Interface for monitoring loadClass calls.
static interface Callbacks.MethodCompileMonitor
          Interface for monitoring method compile.
static interface Callbacks.MethodOverrideMonitor
          Interface for monitoring method override.
static interface Callbacks.RecompileAllDynamicallyLoadedMethodsMonitor
          Interface for requesting VM to recompile all previously dynamically compiled methods
static interface Callbacks.StartupMonitor
          Interface for monitoring VM startup.
 
Field Summary
private static Callbacks.CallbackList appCompleteCallbacks
          Application Execution Complete callback list.
private static Object appCompleteLock
           
private static Callbacks.CallbackList appRunCompleteCallbacks
          Application Run Complete callback list.
private static Object appRunCompleteLock
           
private static Callbacks.CallbackList appRunStartCallbacks
          Application Run Start callback list.
private static Object appRunStartLock
           
private static Callbacks.CallbackList appStartCallbacks
          Application Start executing callback list.
private static Object appStartLock
           
private static Callbacks.CallbackList bootImageCallbacks
          Boot image writing callback list.
private static boolean bootImageEnabled
           
private static Object bootImageLock
           
private static Callbacks.CallbackList classInitializedCallbacks
          Class initialization callback list.
private static boolean classInitializedEnabled
           
private static Object classInitializedLock
           
private static Callbacks.CallbackList classInstantiatedCallbacks
          Class instantiation callback list.
private static boolean classInstantiatedEnabled
           
private static Object classInstantiatedLock
           
private static Callbacks.CallbackList classLoadedCallbacks
          Class loading callback list.
private static boolean classLoadedEnabled
           
private static Object classLoadedLock
           
private static Callbacks.CallbackList classResolvedCallbacks
          Class resolution callback list.
private static boolean classResolvedEnabled
           
private static Object classResolvedLock
           
private static Callbacks.CallbackList defineClassCallbacks
          defineclass call callback list.
private static boolean defineClassEnabled
           
private static Object defineClassLock
           
private static Callbacks.CallbackList exitCallbacks
          VM exit callback list.
private static boolean exitCallbacksStarted
           
private static Object exitLock
           
private static Callbacks.CallbackList forNameCallbacks
          forName call callback list.
private static boolean forNameEnabled
           
private static Object forNameLock
           
private static Callbacks.CallbackList loadClassCallbacks
          loadclass call callback list.
private static boolean loadClassEnabled
           
private static Object loadClassLock
           
private static Callbacks.CallbackList methodCompileCallbacks
          Method compile callback list.
private static boolean methodCompileEnabled
           
private static Object methodCompileLock
           
private static Callbacks.CallbackList methodOverrideCallbacks
          Method override callback list.
private static boolean methodOverrideEnabled
           
private static Object methodOverrideLock
           
private static Callbacks.CallbackList recompileAllCallbacks
          Recompile all callback list.
private static Object recompileAllLock
           
private static Callbacks.CallbackList startupCallbacks
          VM startup callback list.
private static boolean startupEnabled
           
private static Object startupLock
           
private static boolean TRACE_ADDMONITOR
           
private static boolean TRACE_APP_COMPLETE
           
private static boolean TRACE_APP_RUN_COMPLETE
           
private static boolean TRACE_APP_RUN_START
           
private static boolean TRACE_APP_START
           
private static boolean TRACE_BOOTIMAGE
           
private static boolean TRACE_CLASSINITIALIZED
           
private static boolean TRACE_CLASSINSTANTIATED
           
private static boolean TRACE_CLASSLOADED
           
private static boolean TRACE_CLASSRESOLVED
           
private static boolean TRACE_DEFINECLASS
           
private static boolean TRACE_EXIT
           
private static boolean TRACE_FORNAME
           
private static boolean TRACE_LOADCLASS
           
private static boolean TRACE_METHODCOMPILE
           
private static boolean TRACE_METHODOVERRIDE
           
private static boolean TRACE_RECOMPILE_ALL
           
private static boolean TRACE_STARTUP
           
 
Constructor Summary
Callbacks()
           
 
Method Summary
static void addAppCompleteMonitor(Callbacks.AppCompleteMonitor cb)
          Register a callback for when the application completes executing
static void addAppRunCompleteMonitor(Callbacks.AppRunCompleteMonitor cb)
          Register a callback for when the application completes a run
static void addAppRunStartMonitor(Callbacks.AppRunStartMonitor cb)
          Register a callback for when the application starts a run
static void addAppStartMonitor(Callbacks.AppStartMonitor cb)
          Register a callback for when the application starts executing
static void addBootImageMonitor(Callbacks.BootImageMonitor cb)
          Register a callback for boot image writing.
static void addClassInitializedMonitor(Callbacks.ClassInitializedMonitor cb)
          Register a callback for class initialization.
static void addClassInstantiatedMonitor(Callbacks.ClassInstantiatedMonitor cb)
          Register a callback for class instantiation.
static void addClassLoadedMonitor(Callbacks.ClassLoadedMonitor cb)
          Register a callback for class loading.
static void addClassResolvedMonitor(Callbacks.ClassResolvedMonitor cb)
          Register a callback for class resolution.
static void addDefineClassMonitor(Callbacks.DefineClassMonitor cb)
          Register a callback for defineClass call.
static void addExitMonitor(Callbacks.ExitMonitor cb)
          Register a callback for VM exit.
static void addForNameMonitor(Callbacks.ForNameMonitor cb)
          Register a callback for forName call.
static void addLoadClassMonitor(Callbacks.LoadClassMonitor cb)
          Register a callback for loadClass call.
static void addMethodCompileMonitor(Callbacks.MethodCompileMonitor cb)
          Register a callback for method compile.
static void addMethodOverrideMonitor(Callbacks.MethodOverrideMonitor cb)
          Register a callback for method override.
static void addRecompileAllDynamicallyLoadedMethodsMonitor(Callbacks.RecompileAllDynamicallyLoadedMethodsMonitor cb)
          Register a callback for when the application requests to recompile all dynamically loaded classes
static void addStartupMonitor(Callbacks.StartupMonitor cb)
          Register a callback for VM startup.
static void boot()
          Perform boot-time actions.
private static Atom getClass(Object o)
          Return class name of the object.
private static int getThread()
          Return current thread id.
static void init()
          Initialize callbacks.
static void notifyAppComplete(String app)
          Notify the callback manager that the application completed executing Will return once all the callbacks are invoked.
static void notifyAppRunComplete(String app, int run)
          Notify the callback manager that the application completed a run Will return once all the callbacks are invoked.
static void notifyAppRunStart(String app, int run)
          Notify the callback manager that the application started a run Will return once all the callbacks are invoked.
static void notifyAppStart(String app)
          Notify the callback manager that the application started executing Will return once all the callbacks are invoked.
static void notifyBootImage(Enumeration<String> types)
          Notify the monitor that boot image writing is in progress.
static void notifyClassInitialized(RVMClass klass)
          Notify the callback manager that a class has been initialized.
static void notifyClassInstantiated(RVMClass klass)
          Notify the callback manager that a class has been instantiated.
static void notifyClassLoaded(RVMClass klass)
          Notify the callback manager that a class has been loaded.
static void notifyClassResolved(RVMClass klass)
          Notify the callback manager that a class has been resolved.
static void notifyDefineClass(RVMType type)
          Notify the monitor that java.lang.Class.defineclass was called.
static void notifyExit(int value)
          Notify the callback manager that the VM is about to exit.
static void notifyForName(RVMType type)
          Notify the monitor that java.lang.Class.forName was called.
static void notifyLoadClass(RVMType type)
          Notify the monitor that java.lang.Class.loadclass was called.
static void notifyMethodCompile(RVMMethod method, int compiler)
          Notify the callback manager that a method is about to be compiled.
static void notifyMethodOverride(RVMMethod method, RVMMethod parent)
          Notify the callback manager that a method has been overridden.
static void notifyStartup()
          Notify the callback manager that the VM has started up.
private static void printStack(String message)
          Print current stack trace.
static void recompileAllDynamicallyLoadedMethods()
          Notify the callback manager that the application requested a recompile all Will return once all the callbacks are invoked.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

classLoadedCallbacks

private static Callbacks.CallbackList classLoadedCallbacks
Class loading callback list.


classLoadedLock

private static final Object classLoadedLock

classLoadedEnabled

private static boolean classLoadedEnabled

classResolvedCallbacks

private static Callbacks.CallbackList classResolvedCallbacks
Class resolution callback list.


classResolvedLock

private static final Object classResolvedLock

classResolvedEnabled

private static boolean classResolvedEnabled

classInstantiatedCallbacks

private static Callbacks.CallbackList classInstantiatedCallbacks
Class instantiation callback list.


classInstantiatedLock

private static final Object classInstantiatedLock

classInstantiatedEnabled

private static boolean classInstantiatedEnabled

classInitializedCallbacks

private static Callbacks.CallbackList classInitializedCallbacks
Class initialization callback list.


classInitializedLock

private static final Object classInitializedLock

classInitializedEnabled

private static boolean classInitializedEnabled

methodOverrideCallbacks

private static Callbacks.CallbackList methodOverrideCallbacks
Method override callback list.


methodOverrideLock

private static final Object methodOverrideLock

methodOverrideEnabled

private static boolean methodOverrideEnabled

methodCompileCallbacks

private static Callbacks.CallbackList methodCompileCallbacks
Method compile callback list.


methodCompileLock

private static final Object methodCompileLock

methodCompileEnabled

private static boolean methodCompileEnabled

forNameCallbacks

private static Callbacks.CallbackList forNameCallbacks
forName call callback list.


forNameLock

private static final Object forNameLock

forNameEnabled

private static boolean forNameEnabled

defineClassCallbacks

private static Callbacks.CallbackList defineClassCallbacks
defineclass call callback list.


defineClassLock

private static final Object defineClassLock

defineClassEnabled

private static boolean defineClassEnabled

loadClassCallbacks

private static Callbacks.CallbackList loadClassCallbacks
loadclass call callback list.


loadClassLock

private static final Object loadClassLock

loadClassEnabled

private static boolean loadClassEnabled

bootImageCallbacks

private static Callbacks.CallbackList bootImageCallbacks
Boot image writing callback list.


bootImageLock

private static final Object bootImageLock

bootImageEnabled

private static boolean bootImageEnabled

startupCallbacks

private static Callbacks.CallbackList startupCallbacks
VM startup callback list.


startupLock

private static final Object startupLock

startupEnabled

private static boolean startupEnabled

exitCallbacks

private static Callbacks.CallbackList exitCallbacks
VM exit callback list.


exitLock

private static final Object exitLock

exitCallbacksStarted

private static boolean exitCallbacksStarted

appStartCallbacks

private static Callbacks.CallbackList appStartCallbacks
Application Start executing callback list.


appStartLock

private static final Object appStartLock

appCompleteCallbacks

private static Callbacks.CallbackList appCompleteCallbacks
Application Execution Complete callback list.


appCompleteLock

private static final Object appCompleteLock

appRunStartCallbacks

private static Callbacks.CallbackList appRunStartCallbacks
Application Run Start callback list.


appRunStartLock

private static final Object appRunStartLock

appRunCompleteCallbacks

private static Callbacks.CallbackList appRunCompleteCallbacks
Application Run Complete callback list.


appRunCompleteLock

private static final Object appRunCompleteLock

recompileAllCallbacks

private static Callbacks.CallbackList recompileAllCallbacks
Recompile all callback list.


recompileAllLock

private static final Object recompileAllLock

TRACE_ADDMONITOR

private static final boolean TRACE_ADDMONITOR
See Also:
Constant Field Values

TRACE_CLASSLOADED

private static final boolean TRACE_CLASSLOADED
See Also:
Constant Field Values

TRACE_CLASSRESOLVED

private static final boolean TRACE_CLASSRESOLVED
See Also:
Constant Field Values

TRACE_CLASSINITIALIZED

private static final boolean TRACE_CLASSINITIALIZED
See Also:
Constant Field Values

TRACE_CLASSINSTANTIATED

private static final boolean TRACE_CLASSINSTANTIATED
See Also:
Constant Field Values

TRACE_METHODOVERRIDE

private static final boolean TRACE_METHODOVERRIDE
See Also:
Constant Field Values

TRACE_METHODCOMPILE

private static final boolean TRACE_METHODCOMPILE
See Also:
Constant Field Values

TRACE_FORNAME

private static final boolean TRACE_FORNAME
See Also:
Constant Field Values

TRACE_DEFINECLASS

private static final boolean TRACE_DEFINECLASS
See Also:
Constant Field Values

TRACE_LOADCLASS

private static final boolean TRACE_LOADCLASS
See Also:
Constant Field Values

TRACE_BOOTIMAGE

private static final boolean TRACE_BOOTIMAGE
See Also:
Constant Field Values

TRACE_STARTUP

private static final boolean TRACE_STARTUP
See Also:
Constant Field Values

TRACE_EXIT

private static final boolean TRACE_EXIT
See Also:
Constant Field Values

TRACE_APP_RUN_START

private static final boolean TRACE_APP_RUN_START
See Also:
Constant Field Values

TRACE_APP_RUN_COMPLETE

private static final boolean TRACE_APP_RUN_COMPLETE
See Also:
Constant Field Values

TRACE_APP_START

private static final boolean TRACE_APP_START
See Also:
Constant Field Values

TRACE_APP_COMPLETE

private static final boolean TRACE_APP_COMPLETE
See Also:
Constant Field Values

TRACE_RECOMPILE_ALL

private static final boolean TRACE_RECOMPILE_ALL
See Also:
Constant Field Values
Constructor Detail

Callbacks

public Callbacks()
Method Detail

addClassLoadedMonitor

public static void addClassLoadedMonitor(Callbacks.ClassLoadedMonitor cb)
Register a callback for class loading.

Parameters:
cb - the object to notify when event happens

notifyClassLoaded

public static void notifyClassLoaded(RVMClass klass)
Notify the callback manager that a class has been loaded.

Parameters:
klass - the class that was loaded

addClassResolvedMonitor

public static void addClassResolvedMonitor(Callbacks.ClassResolvedMonitor cb)
Register a callback for class resolution.

Parameters:
cb - the object to notify when event happens

notifyClassResolved

public static void notifyClassResolved(RVMClass klass)
Notify the callback manager that a class has been resolved.

Parameters:
klass - the class that was resolved

addClassInstantiatedMonitor

public static void addClassInstantiatedMonitor(Callbacks.ClassInstantiatedMonitor cb)
Register a callback for class instantiation.

Parameters:
cb - the object to notify when event happens

notifyClassInstantiated

public static void notifyClassInstantiated(RVMClass klass)
Notify the callback manager that a class has been instantiated.

Parameters:
klass - the class that was instantiated

addClassInitializedMonitor

public static void addClassInitializedMonitor(Callbacks.ClassInitializedMonitor cb)
Register a callback for class initialization.

Parameters:
cb - the object to notify when event happens

notifyClassInitialized

public static void notifyClassInitialized(RVMClass klass)
Notify the callback manager that a class has been initialized.

Parameters:
klass - the class that was initialized

addMethodOverrideMonitor

public static void addMethodOverrideMonitor(Callbacks.MethodOverrideMonitor cb)
Register a callback for method override.

Parameters:
cb - the object to notify when event happens

notifyMethodOverride

public static void notifyMethodOverride(RVMMethod method,
                                        RVMMethod parent)
Notify the callback manager that a method has been overridden.

Parameters:
method - the method that was loaded
parent - the method that it overrides (null if none)

addMethodCompileMonitor

public static void addMethodCompileMonitor(Callbacks.MethodCompileMonitor cb)
Register a callback for method compile.

Parameters:
cb - the object to notify when event happens

notifyMethodCompile

public static void notifyMethodCompile(RVMMethod method,
                                       int compiler)
Notify the callback manager that a method is about to be compiled. NOTE: use VM.runningVM and VM.writingBootImage to determine whether the VM is running

Parameters:
method - the method that will be compiled
compiler - the compiler that will be invoked Values are constants in CompiledMethod

addForNameMonitor

public static void addForNameMonitor(Callbacks.ForNameMonitor cb)
Register a callback for forName call.

Parameters:
cb - the object to notify when event happens

notifyForName

public static void notifyForName(RVMType type)
Notify the monitor that java.lang.Class.forName was called.

Parameters:
type - the type that will be returned

addDefineClassMonitor

public static void addDefineClassMonitor(Callbacks.DefineClassMonitor cb)
Register a callback for defineClass call.

Parameters:
cb - the object to notify when event happens

notifyDefineClass

public static void notifyDefineClass(RVMType type)
Notify the monitor that java.lang.Class.defineclass was called.

Parameters:
type - the type that will be returned

addLoadClassMonitor

public static void addLoadClassMonitor(Callbacks.LoadClassMonitor cb)
Register a callback for loadClass call.

Parameters:
cb - the object to notify when event happens

notifyLoadClass

public static void notifyLoadClass(RVMType type)
Notify the monitor that java.lang.Class.loadclass was called.

Parameters:
type - the type that will be returned

addBootImageMonitor

public static void addBootImageMonitor(Callbacks.BootImageMonitor cb)
Register a callback for boot image writing.

Parameters:
cb - the object to notify when event happens

notifyBootImage

public static void notifyBootImage(Enumeration<String> types)
Notify the monitor that boot image writing is in progress.

Parameters:
types - the types that are included in the boot image

addStartupMonitor

public static void addStartupMonitor(Callbacks.StartupMonitor cb)
Register a callback for VM startup.

Parameters:
cb - the object to notify when event happens

notifyStartup

public static void notifyStartup()
Notify the callback manager that the VM has started up. NOTE: Runs in the main thread!


addExitMonitor

public static void addExitMonitor(Callbacks.ExitMonitor cb)
Register a callback for VM exit.

Parameters:
cb - the object to notify when event happens

notifyExit

public static void notifyExit(int value)
Notify the callback manager that the VM is about to exit. Will return once all the callbacks are invoked.

Parameters:
value - the exit value

addAppStartMonitor

public static void addAppStartMonitor(Callbacks.AppStartMonitor cb)
Register a callback for when the application starts executing

Parameters:
cb - the object to notify when event happens

notifyAppStart

public static void notifyAppStart(String app)
Notify the callback manager that the application started executing Will return once all the callbacks are invoked.

Parameters:
app - name of application

addAppCompleteMonitor

public static void addAppCompleteMonitor(Callbacks.AppCompleteMonitor cb)
Register a callback for when the application completes executing

Parameters:
cb - the object to notify when event happens

notifyAppComplete

public static void notifyAppComplete(String app)
Notify the callback manager that the application completed executing Will return once all the callbacks are invoked.

Parameters:
app - name of application

addAppRunStartMonitor

public static void addAppRunStartMonitor(Callbacks.AppRunStartMonitor cb)
Register a callback for when the application starts a run

Parameters:
cb - the object to notify when event happens

notifyAppRunStart

public static void notifyAppRunStart(String app,
                                     int run)
Notify the callback manager that the application started a run Will return once all the callbacks are invoked.

Parameters:
app - application name
run - run number

addAppRunCompleteMonitor

public static void addAppRunCompleteMonitor(Callbacks.AppRunCompleteMonitor cb)
Register a callback for when the application completes a run

Parameters:
cb - the object to notify when event happens

notifyAppRunComplete

public static void notifyAppRunComplete(String app,
                                        int run)
Notify the callback manager that the application completed a run Will return once all the callbacks are invoked.

Parameters:
app - name of application
run - run number

addRecompileAllDynamicallyLoadedMethodsMonitor

public static void addRecompileAllDynamicallyLoadedMethodsMonitor(Callbacks.RecompileAllDynamicallyLoadedMethodsMonitor cb)
Register a callback for when the application requests to recompile all dynamically loaded classes

Parameters:
cb - the object to notify when event happens

recompileAllDynamicallyLoadedMethods

public static void recompileAllDynamicallyLoadedMethods()
Notify the callback manager that the application requested a recompile all Will return once all the callbacks are invoked.


init

public static void init()
Initialize callbacks.


boot

public static void boot()
Perform boot-time actions.


getClass

private static Atom getClass(Object o)
Return class name of the object.

Parameters:
o - the object
Returns:
class name of the object

getThread

private static int getThread()
Return current thread id.

Returns:
current thread id

printStack

private static void printStack(String message)
Print current stack trace.

Parameters:
message - error message