Skip to content

Commit

Permalink
[GR-58999] Support invoke non-virtual jdwp invoke option.
Browse files Browse the repository at this point in the history
PullRequest: graal/19034
  • Loading branch information
javeleon committed Oct 24, 2024
2 parents e05805b + 00df696 commit 0f833fd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,17 @@ public interface MethodRef {
* @param args guest-language arguments used when calling the method
* @return the guest-language return value
*/
Object invokeInterfaceMethod(Object... args);
Object invokeMethodInterface(Object... args);

/**
* Invokes an instance method in a non-virtual fashion with input arguments. Overridden methods
* that would normally be called when invoking from Java source code using the self object is
* not invoked. The first argument must be the self object.
*
* @param args guest-language arguments used when calling the method
* @return the guest-language return value
*/
Object invokeMethodNonVirtual(Object... args);

/**
* Determines if the declaring class has a source file attribute.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public final class JDWP {

private static final int ACC_SYNTHETIC = 0x00001000;
private static final int JDWP_SYNTHETIC = 0xF0000000;
public static final int INVOKE_SINGLE_THREADED = 0x01;
public static final int INVOKE_NON_VIRTUAL = 0x02;

private JDWP() {
}
Expand Down Expand Up @@ -1799,15 +1801,19 @@ static CommandResult createReply(Packet packet, DebuggerController controller, D
controller.fine(() -> "trying to invoke method: " + method.getNameAsString());

int invocationOptions = input.readInt();
byte suspensionStrategy = invocationOptions == 1 ? SuspendStrategy.EVENT_THREAD : SuspendStrategy.ALL;
boolean invokeSingleThreaded = (invocationOptions & INVOKE_SINGLE_THREADED) != 0;
boolean invokeNonvirtual = (invocationOptions & INVOKE_NON_VIRTUAL) != 0;
byte suspensionStrategy = invokeSingleThreaded ? SuspendStrategy.EVENT_THREAD : SuspendStrategy.ALL;
try {
// we have to call the method in the correct thread, so post a
// Callable to the controller and wait for the result to appear
ThreadJob<Object> job = new ThreadJob<>(thread, () -> {
if (Modifier.isPrivate(method.getModifiers())) {
if (invokeNonvirtual) {
return method.invokeMethodNonVirtual(args);
} else if (Modifier.isPrivate(method.getModifiers())) {
return method.invokeMethodSpecial(args);
} else if (method.getDeclaringKlassRef().isInterface()) {
return method.invokeInterfaceMethod(args);
return method.invokeMethodInterface(args);
} else {
return method.invokeMethodVirtual(args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1708,11 +1708,17 @@ public Object invokeMethodSpecial(Object... args) {
}

@Override
public Object invokeInterfaceMethod(Object... args) {
public Object invokeMethodInterface(Object... args) {
checkRemovedByRedefinition();
return invokeDirectInterface(args);
}

@Override
public Object invokeMethodNonVirtual(Object... args) {
checkRemovedByRedefinition();
return invokeDirect(args);
}

private void checkRemovedByRedefinition() {
if (getMethod().isRemovedByRedefinition()) {
Meta meta = getMeta();
Expand Down

0 comments on commit 0f833fd

Please sign in to comment.