Class VirtualMachine
java.lang.Object
org.geysermc.conduit.VirtualMachine
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 Summary
Modifier and TypeMethodDescription<T> VirtualMachinecapture(CaptureChannel<T> channel, Consumer<T> listener) Listens on a channel for the nextexecute()only.voidexecute()Scans the context, invoking handlers as matching calls are found.Runsexecute()on the common pool.Registers intercept handlers.Stops summaries and traces from following code into some classes, keeping calls to them as calls.@Nullable SummaryWorks 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.@Nullable Summarysummarize(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.Evaluates a call to a static method, recording every instance call made along the way.
-
Method Details
-
intercept
Registers intercept handlers. Each must be annotated withIntercept, and anyIntercept.Capturefields on it are created if they are still null.- Parameters:
handlerClasses- the handlers- Returns:
- this machine
- Throws:
IllegalArgumentException- if a class has noInterceptannotation
-
capture
Listens on a channel for the nextexecute()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'sIntercept.Capturefieldlistener- the listener- Returns:
- this machine
-
execute
public void execute()Scans the context, invoking handlers as matching calls are found. -
opaque
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 onthisand 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 frommethodName- the method, found on the class or inheriteddescriptor- 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
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
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 methodmethodName- the methodargs- the arguments, chosen between overloads by count- Returns:
- the trace, with a null value returned if the method couldn't be followed
-
executeUninterruptibly
Runsexecute()on the common pool.- Returns:
- a future completing when the scan finishes
-