Skip to content

Commit 9041f4c

Browse files
committed
8309400: JDI spec needs to clarify when OpaqueFrameException and NativeMethodException are thrown
Reviewed-by: sspitsyn, alanb, amenkov
1 parent 3e60ab5 commit 9041f4c

File tree

3 files changed

+25
-30
lines changed

3 files changed

+25
-30
lines changed

src/jdk.jdi/share/classes/com/sun/jdi/ThreadReference.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -402,8 +402,8 @@ List<MonitorInfo> ownedMonitorsAndFrames()
402402
* @throws java.lang.IllegalArgumentException if <CODE>frame</CODE>
403403
* is not on this thread's call stack.
404404
*
405-
* @throws OpaqueFrameException if this thread is a suspended virtual thread and the
406-
* target VM was unable to pop the frames.
405+
* @throws OpaqueFrameException if the target VM is unable to pop this frame
406+
* (e.g. a virtual thread is suspended, but not at an event).
407407
*
408408
* @throws NativeMethodException if one of the frames that would be
409409
* popped is that of a native method or if the frame previous to
@@ -484,8 +484,8 @@ List<MonitorInfo> ownedMonitorsAndFrames()
484484
* @throws IncompatibleThreadStateException if this
485485
* thread is not suspended.
486486
*
487-
* @throws OpaqueFrameException if this thread is a suspended virtual thread and the
488-
* target VM is unable to force the method to return.
487+
* @throws OpaqueFrameException if the target VM is unable to force the method to return
488+
* (e.g. a virtual thread is suspended, but not at an event).
489489
*
490490
* @throws NativeMethodException if the frame to be returned from
491491
* is that of a native method.

src/jdk.jdi/share/classes/com/sun/tools/jdi/StackFrameImpl.java

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -395,29 +395,24 @@ public PacketStream send() {
395395
} catch (JDWPException exc) {
396396
switch (exc.errorCode()) {
397397
case JDWP.Error.OPAQUE_FRAME:
398-
if (thread.isVirtual()) {
399-
// We first need to find out if the current frame is native, or if the
400-
// previous frame is native, in which case we throw NativeMethodException
401-
for (int i = 0; i < 2; i++) {
402-
StackFrameImpl sf;
403-
try {
404-
sf = (StackFrameImpl)thread.frame(i);
405-
} catch (IndexOutOfBoundsException e) {
406-
// This should never happen, but we need to check for it.
407-
break;
408-
}
409-
sf.validateStackFrame();
410-
MethodImpl meth = (MethodImpl)sf.location().method();
411-
if (meth.isNative()) {
412-
throw new NativeMethodException();
413-
}
398+
// We first need to find out if the current frame is native, or if the
399+
// previous frame is native, in which case we throw NativeMethodException
400+
for (int i = 0; i < 2; i++) {
401+
StackFrame sf;
402+
try {
403+
sf = thread.frame(i);
404+
} catch (IndexOutOfBoundsException e) {
405+
// This should never happen, but we need to check for it.
406+
break;
407+
}
408+
Method meth = sf.location().method();
409+
if (meth.isNative()) {
410+
throw new NativeMethodException();
414411
}
415-
// No native frames involved. Must have been due to thread
416-
// not being mounted.
417-
throw new OpaqueFrameException();
418-
} else {
419-
throw new NativeMethodException();
420412
}
413+
// No native frames involved. Must have been due to virtual thread
414+
// not being mounted or some other reason such as failure to deopt.
415+
throw new OpaqueFrameException();
421416
case JDWP.Error.THREAD_NOT_SUSPENDED:
422417
throw new IncompatibleThreadStateException(
423418
"Thread not current or suspended");

src/jdk.jdi/share/classes/com/sun/tools/jdi/ThreadReferenceImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,10 +597,10 @@ public void forceEarlyReturn(Value returnValue) throws InvalidTypeException,
597597
} catch (JDWPException exc) {
598598
switch (exc.errorCode()) {
599599
case JDWP.Error.OPAQUE_FRAME:
600-
if (isVirtual() && !meth.isNative()) {
601-
throw new OpaqueFrameException();
602-
} else {
600+
if (meth.isNative()) {
603601
throw new NativeMethodException();
602+
} else {
603+
throw new OpaqueFrameException();
604604
}
605605
case JDWP.Error.THREAD_NOT_SUSPENDED:
606606
throw new IncompatibleThreadStateException(

0 commit comments

Comments
 (0)