Package ghidra.pcode.emu.jit.gen.tgt

# Record Class JitCompiledPassageClass

java.lang.Object
java.lang.Record
ghidra.pcode.emu.jit.gen.tgt.JitCompiledPassageClass

Record Components:
  `lookup` - the means of accessing the generated class's elements
  `cls` - the generated class as loaded into this JVM
  `constructor` - the reflected constructor having signature `CONSTRUCTOR_TYPE`

public record JitCompiledPassageClass(MethodHandles.Lookup lookup, Class<? extends JitCompiledPassage> cls, MethodHandle constructor) extends Record
A compiled passage that is not yet bound/instantiated to a thread.

This is the output of `JitCompiler.compilePassage(Lookup, JitPassage)`, and it will be cached (indirectly) by `JitPcodeEmulator`. The emulator actually caches the various entry points returned by `getBlockEntries()`. Each of those retains a reference to this object. An `JitCompiledPassage.EntryPointPrototype` pairs this with a entry block ID. That prototype can then be instantiated/bound to a thread, producing an `JitCompiledPassage.EntryPoint`. That bound entry point is produced by invoking `createInstance(JitPcodeThread)` and just copying the block id.

This object wraps the generated (and now loaded) class and provides the mechanisms for reflecting and processing the `ENTRIES` field, and for reflecting and invoking the generated constructor. Note that explicit invocation of the static initializer via reflection is not necessary.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final MethodType`
  `CONSTRUCTOR_TYPE`
  The constructor signature: `Passage$at_[entry](JitPcodeThread)`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `JitCompiledPassageClass(MethodHandles.Lookup lookup, Class<? extends JitCompiledPassage> cls, MethodHandle constructor)`
  Creates an instance of a `JitCompiledPassageClass` record class.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Class<? extends JitCompiledPassage>`
  `cls()`
  Returns the value of the `cls` record component.
  `MethodHandle`
  `constructor()`
  Returns the value of the `constructor` record component.
  `JitCompiledPassage`
  `createInstance(JitPcodeThread thread)`
  Create an instance bound to the given thread
  `final boolean`
  `equals(Object o)`
  Indicates whether some other object is "equal to" this one.
  `Map<JitPassage.AddrCtx,JitCompiledPassage.EntryPointPrototype>`
  `getBlockEntries()`
  Get the entry points for this compiled passage
  `final int`
  `hashCode()`
  Returns a hash code value for this object.
  `static JitCompiledPassageClass`
  `load(MethodHandles.Lookup lookup, byte[] bytes)`
  Load the generated class from the given bytes
  `MethodHandles.Lookup`
  `lookup()`
  Returns the value of the `lookup` record component.
  `final String`
  `toString()`
  Returns a string representation of this record class.

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### CONSTRUCTOR_TYPE

    public static final MethodType CONSTRUCTOR_TYPE
    The constructor signature: `Passage$at_[entry](JitPcodeThread)`

- ## Constructor Details

  - ### JitCompiledPassageClass

    public JitCompiledPassageClass(MethodHandles.Lookup lookup, Class<? extends JitCompiledPassage> cls, MethodHandle constructor)
    Creates an instance of a `JitCompiledPassageClass` record class.
    Parameters:
      `lookup` - the value for the `lookup` record component
      `cls` - the value for the `cls` record component
      `constructor` - the value for the `constructor` record component

- ## Method Details

  - ### load

    public static JitCompiledPassageClass load(MethodHandles.Lookup lookup, byte[] bytes)
    Load the generated class from the given bytes

    The bytes must define a class that implements `JitCompiledPassage`. It must define a constructor having the signature `CONSTRUCTOR_TYPE`, and it must define a static field `List<AddrCtx> ENTRIES`.

    Parameters:
      `lookup` - a lookup that can see all the elements the generated class needs. Likely, this should be from the emulator implementation, which may be an extension in a script.
      `bytes` - the classfile bytes
    Returns:
      the wrapped class

  - ### createInstance

    public JitCompiledPassage createInstance(JitPcodeThread thread)
    Create an instance bound to the given thread
    Parameters:
      `thread` - the thread
    Returns:
      the instance, prepared to execute on the given thread

  - ### getBlockEntries

    public Map<JitPassage.AddrCtx,JitCompiledPassage.EntryPointPrototype> getBlockEntries()
    Get the entry points for this compiled passage

    This processes the `ENTRIES` field, which is just a list of targets. The position of each target in the list corresponds to the block id accepted by the generated `JitCompiledPassage.run(int)` method.

    Returns:
      the map of targets to their corresponding entry point prototypes

  - ### toString

    public final String toString()
    Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
    Specified by:
      `toString` in class `Record`
    Returns:
      a string representation of this object

  - ### hashCode

    public final int hashCode()
    Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
    Specified by:
      `hashCode` in class `Record`
    Returns:
      a hash code value for this object

  - ### equals

    public final boolean equals(Object o)
    Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with `Objects::equals(Object,Object)`.
    Specified by:
      `equals` in class `Record`
    Parameters:
      `o` - the object with which to compare
    Returns:
      `true` if this object is the same as the `o` argument; `false` otherwise.

  - ### lookup

    public MethodHandles.Lookup lookup()
    Returns the value of the `lookup` record component.
    Returns:
      the value of the `lookup` record component

  - ### cls

    public Class<? extends JitCompiledPassage> cls()
    Returns the value of the `cls` record component.
    Returns:
      the value of the `cls` record component

  - ### constructor

    public MethodHandle constructor()
    Returns the value of the `constructor` record component.
    Returns:
      the value of the `constructor` record component