Class VirtualMachine

java.lang.Object
org.geysermc.conduit.VirtualMachine

public class VirtualMachine extends Object
Scans every jar in a ConduitContext and dispatches matching calls to Intercept handlers.
VirtualMachine vm = VirtualMachineFactory.create(context).await();
vm.intercept(ColorRegistry.class);
vm.capture(ColorRegistry.CAPTURE, color -> colors.add(color));
vm.execute();

Nothing in the scanned jars is loaded or run. Context jars are read to follow calls into them, but are not scanned themselves.

  • Method Details

    • intercept

      public VirtualMachine intercept(Class<?>... handlerClasses)
      Registers intercept handlers. Each must be annotated with Intercept, and any Intercept.Capture fields on it are created if they are still null.
      Parameters:
      handlerClasses - the handlers
      Returns:
      this machine
      Throws:
      IllegalArgumentException - if a class has no Intercept annotation
    • capture

      public <T> VirtualMachine capture(CaptureChannel<T> channel, Consumer<T> listener)
      Listens on a channel for the next execute() only. Channels are static and shared between machines, so the listener is removed once the run finishes.
      Type Parameters:
      T - the type of item emitted
      Parameters:
      channel - the channel, usually a handler's Intercept.Capture field
      listener - the listener
      Returns:
      this machine
    • execute

      public void execute()
      Scans the context, invoking handlers as matching calls are found.
    • opaque

      public VirtualMachine opaque(String... names)
      Stops summaries and traces from following code into some classes, keeping calls to them as calls. Useful when the context contains an API whose calls should be read, not its internals.
      Parameters:
      names - binary or internal class names, or package prefixes ending in a dot or slash
      Returns:
      this machine
    • summarize

      @Nullable public @Nullable Summary summarize(String className, String methodName, @Nullable @Nullable String descriptor)
      Works out what a method does without running it: the fields it leaves assigned, the calls it makes, and what it returns, all in terms of its inputs. Calls on this and static calls into the context are followed; anything else is kept as a call.
      Summary summary = vm.summarize("com.example.Dial", "turn", null);
      Value angle = summary.assigned(new Value.This(), "angle");
      
      Parameters:
      className - the binary or internal name of the class to start the lookup from
      methodName - the method, found on the class or inherited
      descriptor - the method descriptor, or null for the first non-bridge method of that name
      Returns:
      the summary, or null if the method can't be found or is too large to follow
    • summarize

      @Nullable public @Nullable Summary summarize(Value.Constructed constructed)
      Works out what the constructor call that built a value did, with the arguments it was given standing in for its parameters. The constructor is chosen by the number of arguments, or is the first one declared if none matches, as for a constructor reference that was never called.
      Parameters:
      constructed - the constructed value, such as one a handler received
      Returns:
      the summary, or null if the constructor can't be found or is too large to follow
    • trace

      public Trace trace(String className, String methodName, List<Value> args)
      Evaluates a call to a static method, recording every instance call made along the way.
      Parameters:
      className - the binary or internal name of the class declaring the method
      methodName - the method
      args - the arguments, chosen between overloads by count
      Returns:
      the trace, with a null value returned if the method couldn't be followed
    • executeUninterruptibly

      public CompletableFuture<Void> executeUninterruptibly()
      Runs execute() on the common pool.
      Returns:
      a future completing when the scan finishes