8309400: JDI spec needs to clarify when OpaqueFrameException and NativeMethodException are thrown

Reviewed-by: sspitsyn, alanb, amenkov
This commit is contained in:
Chris Plummer 2025-08-20 15:32:17 +00:00
parent 3e60ab51fe
commit 9041f4c47f
3 changed files with 25 additions and 30 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -402,8 +402,8 @@ public interface ThreadReference extends ObjectReference {
* @throws java.lang.IllegalArgumentException if <CODE>frame</CODE>
* is not on this thread's call stack.
*
* @throws OpaqueFrameException if this thread is a suspended virtual thread and the
* target VM was unable to pop the frames.
* @throws OpaqueFrameException if the target VM is unable to pop this frame
* (e.g. a virtual thread is suspended, but not at an event).
*
* @throws NativeMethodException if one of the frames that would be
* popped is that of a native method or if the frame previous to
@ -484,8 +484,8 @@ public interface ThreadReference extends ObjectReference {
* @throws IncompatibleThreadStateException if this
* thread is not suspended.
*
* @throws OpaqueFrameException if this thread is a suspended virtual thread and the
* target VM is unable to force the method to return.
* @throws OpaqueFrameException if the target VM is unable to force the method to return
* (e.g. a virtual thread is suspended, but not at an event).
*
* @throws NativeMethodException if the frame to be returned from
* is that of a native method.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -395,29 +395,24 @@ public class StackFrameImpl extends MirrorImpl
} catch (JDWPException exc) {
switch (exc.errorCode()) {
case JDWP.Error.OPAQUE_FRAME:
if (thread.isVirtual()) {
// We first need to find out if the current frame is native, or if the
// previous frame is native, in which case we throw NativeMethodException
for (int i = 0; i < 2; i++) {
StackFrameImpl sf;
try {
sf = (StackFrameImpl)thread.frame(i);
} catch (IndexOutOfBoundsException e) {
// This should never happen, but we need to check for it.
break;
}
sf.validateStackFrame();
MethodImpl meth = (MethodImpl)sf.location().method();
if (meth.isNative()) {
throw new NativeMethodException();
}
// We first need to find out if the current frame is native, or if the
// previous frame is native, in which case we throw NativeMethodException
for (int i = 0; i < 2; i++) {
StackFrame sf;
try {
sf = thread.frame(i);
} catch (IndexOutOfBoundsException e) {
// This should never happen, but we need to check for it.
break;
}
Method meth = sf.location().method();
if (meth.isNative()) {
throw new NativeMethodException();
}
// No native frames involved. Must have been due to thread
// not being mounted.
throw new OpaqueFrameException();
} else {
throw new NativeMethodException();
}
// No native frames involved. Must have been due to virtual thread
// not being mounted or some other reason such as failure to deopt.
throw new OpaqueFrameException();
case JDWP.Error.THREAD_NOT_SUSPENDED:
throw new IncompatibleThreadStateException(
"Thread not current or suspended");

View File

@ -597,10 +597,10 @@ public class ThreadReferenceImpl extends ObjectReferenceImpl
} catch (JDWPException exc) {
switch (exc.errorCode()) {
case JDWP.Error.OPAQUE_FRAME:
if (isVirtual() && !meth.isNative()) {
throw new OpaqueFrameException();
} else {
if (meth.isNative()) {
throw new NativeMethodException();
} else {
throw new OpaqueFrameException();
}
case JDWP.Error.THREAD_NOT_SUSPENDED:
throw new IncompatibleThreadStateException(