Class JmcRuntimeUtils
This class provides methods to create and manage JMC runtime events, synchronize method execution, and handle thread join operations. It is primarily used for bytecode instrumentation and is not intended for direct use within the codebase.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidClears all synchronization locks.static voidJoins the specified thread, waiting indefinitely for it to finish.static voidJoins the specified thread, waiting for it to finish for a specified time.static voidJoins the specified thread, waiting for it to finish for a specified time and nanoseconds.static voidlockAcquiredEventWithoutYield(Object instance, String owner, String name, Object value, String descriptor, Object newValue) Creates a lock acquired event for the specified instance, owner, name, value, descriptor, and new value without yielding.static voidCreates a lock acquire event for the specified owner, name, value, descriptor, and instance.static voidlockReleaseEvent(Object instance, String owner, String name, Object value, String descriptor, Object newValue) Creates a lock release event for the specified instance, owner, name, value, descriptor, and new value.static voidCreates a read event for the specified instance, owner, name, and descriptor.static voidreadEventWithoutYield(Object instance, String owner, String name, String descriptor) Creates a read event for the specified instance, owner, name, and descriptor without yielding.static voidregisterSyncLock(Object instance) Registers a synchronization lock for the given instance.static voidregisterSyncLock(String className) Registers a synchronization lock for the given class name.static booleanChecks if the given object is an instance ofJmcThreadand should be instrumented for thread calls.static voidsyncBlockLock(Object instance) Locks the block for the given instance.static voidsyncBlockUnLock(Object instance) Unlocks the block for the given instance.static voidsyncMethodLock(Object instance) Locks the corresponding lock of the given instance.static voidsyncMethodLock(String className) Locks the corresponding lock of the given class's static synchronized method.static voidsyncMethodUnLock(Object instance) Unlocks the corresponding lock of the given instance.static voidsyncMethodUnLock(String className) Unlocks the corresponding lock of the given class's static synchronized method.static voidCreates a write event for the specified value, owner, name, descriptor, and instance.static voidCreates a write event for the specified value, owner, name, descriptor, and instance without yielding.
-
Constructor Details
-
JmcRuntimeUtils
public JmcRuntimeUtils()
-
-
Method Details
-
readEvent
Creates a read event for the specified instance, owner, name, and descriptor.This method updates the JMC runtime event and yields control to the scheduler.
- Parameters:
owner- the owner of the fieldname- the name of the fielddescriptor- the descriptor of the fieldinstance- the instance on which the field is accessed
-
readEventWithoutYield
public static void readEventWithoutYield(Object instance, String owner, String name, String descriptor) Creates a read event for the specified instance, owner, name, and descriptor without yielding.This method updates the JMC runtime event without yielding control to the scheduler.
- Parameters:
instance- the instance on which the field is accessedowner- the owner of the fieldname- the name of the fielddescriptor- the descriptor of the field
-
writeEventWithoutYield
public static void writeEventWithoutYield(Object instance, Object value, String owner, String name, String descriptor) Creates a write event for the specified value, owner, name, descriptor, and instance without yielding.- Parameters:
instance- the instance on which the field is accessedvalue- the new value being writtenowner- the owner of the fieldname- the name of the fielddescriptor- the descriptor of the field
-
writeEvent
public static void writeEvent(Object value, String owner, String name, String descriptor, Object instance) Creates a write event for the specified value, owner, name, descriptor, and instance.This method updates the JMC runtime event and yields control to the scheduler.
- Parameters:
value- the new value being writtenowner- the owner of the fieldname- the name of the fielddescriptor- the descriptor of the fieldinstance- the instance on which the field is accessed
-
lockAcquireEvent
public static void lockAcquireEvent(String owner, String name, Object value, String descriptor, Object instance) Creates a lock acquire event for the specified owner, name, value, descriptor, and instance.This method updates the JMC runtime event and yields control to the scheduler.
- Parameters:
owner- the owner of the lockname- the name of the lockvalue- the value of the lockdescriptor- the descriptor of the lockinstance- the instance on which the lock is acquired
-
lockAcquiredEventWithoutYield
public static void lockAcquiredEventWithoutYield(Object instance, String owner, String name, Object value, String descriptor, Object newValue) Creates a lock acquired event for the specified instance, owner, name, value, descriptor, and new value without yielding.This method updates the JMC runtime event without yielding control to the scheduler.
- Parameters:
instance- the instance on which the lock is acquiredowner- the owner of the lockname- the name of the lockvalue- the value of the lockdescriptor- the descriptor of the locknewValue- the new value after acquiring the lock
-
lockReleaseEvent
public static void lockReleaseEvent(Object instance, String owner, String name, Object value, String descriptor, Object newValue) Creates a lock release event for the specified instance, owner, name, value, descriptor, and new value.This method updates the JMC runtime event and yields control to the scheduler.
- Parameters:
instance- the instance on which the lock is releasedowner- the owner of the lockname- the name of the lockvalue- the value of the lockdescriptor- the descriptor of the locknewValue- the new value after releasing the lock
-
join
Joins the specified thread, waiting indefinitely for it to finish.This method updates the JMC runtime event and yields control to the scheduler.
Join calls used by the instrumentation to replace existing join calls. Why do these exist? While bytecode instrumentation allows us to change base class, we cannot control the order in which the classes are loaded. So blindly replacing calls to join join1 doesn't work and hence we need to do it at runtime. These calls are added instead of thread.join calls at runtime.
- Parameters:
t- the thread to join- Throws:
InterruptedException- if the current thread is interrupted while waiting
-
join
Joins the specified thread, waiting for it to finish for a specified time.This method updates the JMC runtime event and yields control to the scheduler.
- Parameters:
t- the thread to joinmillis- the maximum time to wait in milliseconds- Throws:
InterruptedException- if the current thread is interrupted while waiting
-
join
Joins the specified thread, waiting for it to finish for a specified time and nanoseconds.This method updates the JMC runtime event and yields control to the scheduler.
- Parameters:
t- the thread to joinmillis- the maximum time to wait in millisecondsnanos- additional nanoseconds to wait- Throws:
InterruptedException- if the current thread is interrupted while waiting
-
shouldInstrumentThreadCall
Checks if the given object is an instance ofJmcThreadand should be instrumented for thread calls.- Parameters:
t- the object to check- Returns:
- true if the object is an instance of
JmcThread, false otherwise
-
syncMethodLock
Locks the corresponding lock of the given instance.This method acquires a lock on the instance's hash code.
- Parameters:
instance- the instance to lock
-
syncMethodUnLock
Unlocks the corresponding lock of the given instance.This method releases a lock on the instance's hash code.
- Parameters:
instance- the instance to unlock
-
syncMethodLock
Locks the corresponding lock of the given class's static synchronized method.This method acquires a lock on the class name's hash code.
- Parameters:
className- the class name to lock
-
syncMethodUnLock
Unlocks the corresponding lock of the given class's static synchronized method.This method releases a lock on the class name's hash code.
- Parameters:
className- the class name to unlock
-
registerSyncLock
Registers a synchronization lock for the given instance.This method registers a lock based on the instance's hash code.
- Parameters:
instance- the instance to register a lock for
-
registerSyncLock
Registers a synchronization lock for the given class name.This method registers a lock based on the class name's hash code.
- Parameters:
className- the class name to register a lock for
-
syncBlockLock
Locks the block for the given instance.This method acquires a lock on the instance's hash code for synchronized blocks.
- Parameters:
instance- the instance to lock
-
syncBlockUnLock
Unlocks the block for the given instance.This method releases a lock on the instance's hash code for synchronized blocks.
- Parameters:
instance- the instance to unlock
-
clearSyncLocks
public static void clearSyncLocks()Clears all synchronization locks.This method clears the internal store of synchronization locks.
-