Class InstrumentationAgent

java.lang.Object
edu.fiu.adwise.homomorphic_encryption.misc.InstrumentationAgent

public class InstrumentationAgent extends Object
This class serves as a Java instrumentation agent, allowing the measurement of object sizes at runtime. It uses the Instrumentation API to provide functionality for determining the size of objects in memory.

To use this agent, it must be specified as a Java agent in the JVM arguments. The premain method is invoked before the application's main method, initializing the instrumentation instance.

For more details, refer to: Baeldung: Measuring Object Size in Java

  • Constructor Details

    • InstrumentationAgent

      public InstrumentationAgent()
  • Method Details

    • premain

      public static void premain(String agentArgs, Instrumentation inst)
      The premain method is called by the JVM before the application's main method. It initializes the Instrumentation instance for use in the agent.
      Parameters:
      agentArgs - The agent arguments passed to the JVM.
      inst - The Instrumentation instance provided by the JVM.
    • getObjectSize

      public static long getObjectSize(Object object)
      Returns the size of the specified object in bytes.
      Parameters:
      object - The object whose size is to be measured.
      Returns:
      The size of the object in bytes.
      Throws:
      IllegalStateException - If the agent has not been initialized.