Class JavaRuntime

java.lang.Object
com.ibm.dtfj.java.j9.JavaRuntime
All Implemented Interfaces:
JavaRuntime, ManagedRuntime

public class JavaRuntime extends Object implements JavaRuntime
  • Constructor Details

  • Method Details

    • getJavaVM

      public ImagePointer getJavaVM() throws CorruptDataException
      Description copied from interface: JavaRuntime
      Get the object that represents the virtual machine
      Specified by:
      getJavaVM in interface JavaRuntime
      Returns:
      the address of the JavaVM structure which represents this JVM instance in JNI
      Throws:
      CorruptDataException
    • getJavaClassLoaders

      public Iterator getJavaClassLoaders()
      Description copied from interface: JavaRuntime
      Get the set of class loaders active in this VM
      Specified by:
      getJavaClassLoaders in interface JavaRuntime
      Returns:
      an iterator of all of the class loaders within this JavaVM
      See Also:
    • getThreads

      public Iterator getThreads()
      Description copied from interface: JavaRuntime
      Get the set of Java threads known by the VM
      Specified by:
      getThreads in interface JavaRuntime
      Returns:
      an iterator of the JavaThreads in the runtime
      See Also:
    • getCompiledMethods

      public Iterator getCompiledMethods()
      Description copied from interface: JavaRuntime
      This is short cut method. The same result can be found by iterating over all methods in all class loaders in all classes.
      Specified by:
      getCompiledMethods in interface JavaRuntime
      Returns:
      an iterator over all of the JavaMethods in the JavaRuntime which have been compiled
      See Also:
    • getMonitors

      public Iterator getMonitors()
      Description copied from interface: JavaRuntime
      Provides access to the collection of monitors used in the JavaVM. This collection includes both monitors associated with managed objects (e.g. object monitors) and monitors associated with internal control structures (e.g. raw monitors)
      Specified by:
      getMonitors in interface JavaRuntime
      Returns:
      an iterator over the collection of monitors
      See Also:
    • getHeaps

      public Iterator getHeaps()
      Description copied from interface: JavaRuntime
      Get the set of heaps known by the VM
      Specified by:
      getHeaps in interface JavaRuntime
      Returns:
      an iterator for all of the Java heaps within this runtime. Heaps may be specific to this JavaVM instance, or may be shared between multiple JavaVM instances
      See Also:
    • getTraceBuffer

      public Object getTraceBuffer(String bufferName, boolean formatted) throws CorruptDataException
      Description copied from interface: JavaRuntime
      Fetches implementation specific trace buffers, like the verbose GC buffer or the Universal Trace Engine (UTE) buffer
      Specified by:
      getTraceBuffer in interface JavaRuntime
      Parameters:
      bufferName - a String naming the buffer to be fetched
      formatted - true if formatting should be performed on the buffer, or false if the raw buffer contents should be returned
      Returns:
      an implementation specific result, depending on the parameters
      Throws:
      CorruptDataException
    • getFullVersion

      public String getFullVersion() throws CorruptDataException
      Description copied from interface: ManagedRuntime
      Get the 'full' version information for this runtime.
      Specified by:
      getFullVersion in interface ManagedRuntime
      Returns:
      a string representation of the version information for this runtime instance
      Throws:
      CorruptDataException - If the runtime presents no understandable version data
      See Also:
    • getVersion

      public String getVersion() throws CorruptDataException
      Description copied from interface: ManagedRuntime
      Get the version data available for this runtime instance.
      Specified by:
      getVersion in interface ManagedRuntime
      Returns:
      a string representing all the version data available for this runtime instance.
      Throws:
      CorruptDataException - If the runtime presents no understandable version data
    • addClass

      public void addClass(JavaAbstractClass theClass)
    • addClassLoader

      public void addClassLoader(JavaClassLoader loader)
    • getClassForID

      public JavaClass getClassForID(long classID)
    • getClassLoaderForID

      public JavaClassLoader getClassLoaderForID(long loaderID)
    • addMonitor

      public void addMonitor(JavaMonitor monitor)
    • addHeap

      public void addHeap(JavaHeap heap)
    • addHeapRoot

      public void addHeapRoot(JavaReference heapRoot)
    • addThread

      public void addThread(JavaThread thread, long blockedOnMonitor, long waitingOnMonitor)
      Adds a JavaThread to the runtime along with optional IDs of monitors that it is blocked on or waiting on
      Parameters:
      thread - The JavaThread to add to the runtime
      blockedOnMonitor - The ID of the monitor that this thread is blocked on (0 if it is not blocked)
      waitingOnMonitor - The ID of the monitor that this thread is waiting on (0 if it is not waiting)
    • setTraceBufferForName

      public void setTraceBufferForName(TraceBuffer buffer, String key)
    • getSystemProperty

      public String getSystemProperty(String key)
      Description copied from interface: JavaRuntime
      Get a system property of the virtual machine.
      Specified by:
      getSystemProperty in interface JavaRuntime
      Parameters:
      key - the name of the property to retrieve
      Returns:
      the value of the requested system property from this VM
    • getSystemProperty

      public String getSystemProperty(String key, String defaultValue)
    • setSystemProperty

      public void setSystemProperty(String key, String value)
    • equals

      public boolean equals(Object obj)
      Description copied from class: java.lang.Object
      Compares the argument to the receiver, and answers true if they represent the same object using a class specific comparison. The implementation in Object answers true only if the argument is the exact same object as the receiver (==).
      Specified by:
      equals in interface JavaRuntime
      Overrides:
      equals in class Object
      Parameters:
      obj -
      Returns:
      True if the given object refers to the same Java Runtime in the image
      See Also:
    • hashCode

      public int hashCode()
      Description copied from class: java.lang.Object
      Answers an integer hash code for the receiver. Any two objects which answer true when passed to .equals must answer the same value for this method.
      Specified by:
      hashCode in interface JavaRuntime
      Overrides:
      hashCode in class Object
      Returns:
      the receiver's hash.
      See Also:
    • getJavaVMInitArgs

      public JavaVMInitArgs getJavaVMInitArgs() throws DataUnavailable, CorruptDataException
      Description copied from interface: JavaRuntime
      Fetch the JavaVMInitArgs which were used to create this VM. See JNI_CreateJavaVM in the JNI Specification for more details.
      Specified by:
      getJavaVMInitArgs in interface JavaRuntime
      Returns:
      the JavaVMInitArgs which were used to create this VM.
      Throws:
      DataUnavailable - if the arguments are not available
      CorruptDataException
    • pointerInAddressSpace

      public ImagePointer pointerInAddressSpace(long id)
      Since a JavaVM cannot span address spaces, use the VM's container address space to build this pointer, given the raw ID
      Parameters:
      id -
      Returns:
    • nativeThreadForID

      public ImageThread nativeThreadForID(long nativeID)
    • methodForID

      public JavaMethod methodForID(long method)
    • addMethodForID

      public void addMethodForID(JavaMethod method, long id)
    • createJavaVMInitArgs

      public JavaVMInitArgs createJavaVMInitArgs(int version, boolean ignoreUnrecognized)
    • bytesPerPointer

      public int bytesPerPointer()
      A helper method required by some of the structures hanging off of the VM. Returns the number of bytes required to express a native pointer on the VM target platform
      Returns:
      4 or 8, depending on the pointer size of the target platform
    • getClasses

      protected Iterator getClasses()
    • getHeapRoots

      public Iterator getHeapRoots()
      Description copied from interface: JavaRuntime
      Get the set of object and class roots known to the VM. Stack frame roots are not included in the set, they can be retrieved using JavaStackFrame.getHeapRoots().
      Specified by:
      getHeapRoots in interface JavaRuntime
      Returns:
      an iterator over the collection of JavaReferences representing the known global heap roots within this runtime.
      See Also:
    • getObjectAtAddress

      public JavaObject getObjectAtAddress(ImagePointer address) throws CorruptDataException, IllegalArgumentException
      Description copied from interface: JavaRuntime
      Gets the object located at address address in the heap.
      Specified by:
      getObjectAtAddress in interface JavaRuntime
      Parameters:
      address - the ImagePointer instance representing the start address of object in the heap;
      Returns:
      the JavaObject instance representing the located object.
      Throws:
      CorruptDataException - if any data needed to build the returned instance of JavaObject is corrupt.
      IllegalArgumentException - if address is outside the heap's boundaries, or if it doesn't point to the start location of an object;
      See Also:
    • addSpecialObject

      public void addSpecialObject(JavaObject obj)
    • getSpecialObject

      public JavaObject getSpecialObject(ImagePointer address)
    • getMemoryCategories

      public Iterator getMemoryCategories() throws DataUnavailable
      Description copied from interface: JavaRuntime
      Returns iterator of the top-level memory categories used by this Java runtime.
      Specified by:
      getMemoryCategories in interface JavaRuntime
      Returns:
      Iterator of memory categories
      Throws:
      DataUnavailable
      See Also:
    • getMemorySections

      public Iterator getMemorySections(boolean includeFreed) throws DataUnavailable
      Description copied from interface: JavaRuntime
      Returns an iterator of JavaRuntimeMemorySection objects corresponding to the blocks of memory allocated by the JavaRuntime.
      Specified by:
      getMemorySections in interface JavaRuntime
      Parameters:
      includeFreed - If true, iterator will iterate over blocks of memory that have been freed, but haven't been re-used yet.
      Returns:
      Iterator of memory sections.
      Throws:
      DataUnavailable
      See Also:
    • isJITEnabled

      public boolean isJITEnabled() throws DataUnavailable, CorruptDataException
      Description copied from interface: JavaRuntime
      Determine if the JIT was enabled for this Java runtime.
      Specified by:
      isJITEnabled in interface JavaRuntime
      Returns:
      true if the JIT was enabled, false if not
      Throws:
      DataUnavailable - if it is not possible to determine the JIT status
      CorruptDataException
    • getJITProperties

      public Properties getJITProperties() throws DataUnavailable, CorruptDataException
      Description copied from interface: JavaRuntime
      Get any vendor specific properties in use by the JIT for this Java runtime
      Specified by:
      getJITProperties in interface JavaRuntime
      Returns:
      the set of properties, which may be empty if none were set.
      Throws:
      DataUnavailable - if the JIT was not enabled for this runtime
      CorruptDataException
    • getStartTime

      public long getStartTime() throws DataUnavailable, CorruptDataException
      Description copied from interface: JavaRuntime
      Get the time when the JVM was started.
      Specified by:
      getStartTime in interface JavaRuntime
      Returns:
      the time the JVM was started, in milliseconds since 1970
      Throws:
      DataUnavailable - if the JVM start time is not available
      CorruptDataException - if the JVM start time is corrupted
    • getStartTimeNanos

      public long getStartTimeNanos() throws DataUnavailable, CorruptDataException
      Description copied from interface: JavaRuntime
      Get the value of the JVM's high-resolution timer when the JVM was started.
      Specified by:
      getStartTimeNanos in interface JavaRuntime
      Returns:
      the value of the high-resolution timer when the JVM was started, in nanoseconds
      Throws:
      DataUnavailable - if the JVM start time is not available
      CorruptDataException - if the JVM start time is corrupted