Class JmcRuntimeUtils

java.lang.Object
org.mpi_sws.jmc.runtime.JmcRuntimeUtils

public class JmcRuntimeUtils extends Object
Utility class for JMC runtime operations.

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 Details

    • JmcRuntimeUtils

      public JmcRuntimeUtils()
  • Method Details

    • readEvent

      public static void readEvent(String owner, String name, String descriptor, Object instance)
      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 field
      name - the name of the field
      descriptor - the descriptor of the field
      instance - 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 accessed
      owner - the owner of the field
      name - the name of the field
      descriptor - 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 accessed
      value - the new value being written
      owner - the owner of the field
      name - the name of the field
      descriptor - 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 written
      owner - the owner of the field
      name - the name of the field
      descriptor - the descriptor of the field
      instance - 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 lock
      name - the name of the lock
      value - the value of the lock
      descriptor - the descriptor of the lock
      instance - 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 acquired
      owner - the owner of the lock
      name - the name of the lock
      value - the value of the lock
      descriptor - the descriptor of the lock
      newValue - 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 released
      owner - the owner of the lock
      name - the name of the lock
      value - the value of the lock
      descriptor - the descriptor of the lock
      newValue - the new value after releasing the lock
    • join

      public static void join(Thread t) throws InterruptedException
      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

      public static void join(Thread t, long millis) throws InterruptedException
      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 join
      millis - the maximum time to wait in milliseconds
      Throws:
      InterruptedException - if the current thread is interrupted while waiting
    • join

      public static void join(Thread t, long millis, int nanos) throws InterruptedException
      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 join
      millis - the maximum time to wait in milliseconds
      nanos - additional nanoseconds to wait
      Throws:
      InterruptedException - if the current thread is interrupted while waiting
    • shouldInstrumentThreadCall

      public static boolean shouldInstrumentThreadCall(Object t)
      Checks if the given object is an instance of JmcThread and 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

      public static void syncMethodLock(Object instance)
      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

      public static void syncMethodUnLock(Object instance)
      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

      public static void syncMethodLock(String className)
      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

      public static void syncMethodUnLock(String className)
      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

      public static void registerSyncLock(Object instance)
      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

      public static void registerSyncLock(String className)
      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

      public static void syncBlockLock(Object instance)
      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

      public static void syncBlockUnLock(Object instance)
      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.