Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8328083: degrade virtual thread support for GetObjectMonitorUsage #19030

Closed
wants to merge 8 commits into from
11 changes: 6 additions & 5 deletions src/hotspot/share/prims/jvmti.xml
Original file line number Diff line number Diff line change
@@ -8256,14 +8256,15 @@ class C2 extends C1 implements I2 {
<field id="entry_count">
<jint/>
<description>
The number of times the owning platform thread has entered the monitor
The number of times the platform thread owning this monitor has entered it,
or <code>0</code> if owned by a virtual thread or not owned
</description>
</field>
<field id="waiter_count">
<jint/>
<description>
The number of platform threads waiting to own this monitor,
or <code>0</code> if the monitor is owned by a virtual thread or not owned
The number of platform threads waiting to own this monitor, or <code>0</code>
if only virtual threads are waiting or no threads are waiting
</description>
</field>
<field id="waiters">
@@ -8275,8 +8276,8 @@ class C2 extends C1 implements I2 {
<field id="notify_waiter_count">
<jint/>
<description>
The number of platform threads waiting to be notified by this monitor,
or <code>0</code> if the monitor is owned by a virtual thread or not owned
The number of platform threads waiting to own this monitor, or <code>0</code>
if only virtual threads are waiting or no threads are waiting
</description>
</field>
<field id="notify_waiters">
4 changes: 2 additions & 2 deletions src/java.se/share/data/jdwp/jdwp.spec
Original file line number Diff line number Diff line change
@@ -1617,8 +1617,8 @@ JDWP "Java(tm) Debug Wire Protocol"
(object object "The object ID")
)
(Reply
(threadObject owner "The platform thread owning this monitor, or <code>nullptr</code> "
"if owned` by a virtual thread or not owned.")
(threadObject owner "The platform thread owning this monitor, or null "
"if owned by a virtual thread or not owned.")
(int entryCount "The number of times the owning platform thread has entered the monitor.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comment I left for the JVMTI spec. We should be more complete in the explanation here, explaining how it is 0 for virtual threads.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this has been resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thanks! Fixed now. The update is:

--- a/src/java.se/share/data/jdwp/jdwp.spec
+++ b/src/java.se/share/data/jdwp/jdwp.spec
@@ -1619,9 +1619,11 @@ JDWP "Java(tm) Debug Wire Protocol"
         (Reply
             (threadObject owner "The platform thread owning this monitor, or null "
                                 "if owned by a virtual thread or not owned.")
-            (int entryCount "The number of times the owning platform thread has entered the monitor.")
+            (int entryCount "The number of times the owning platform thread has entered the monitor, "
+                            "or 0 if owned by a virtual thread or not owned.")
             (Repeat waiters "The total number of platform threads that are waiting to enter or re-enter "
-                            "the monitor, or waiting to be notified by the monitor."
+                            "the monitor, or waiting to be notified by the monitor, or 0 if "
+                            "only virtual threads are waiting or no threads are waiting."
                 (threadObject thread "A platform thread waiting for this monitor.")
             )
         )

(Repeat waiters "The total number of platform threads that are waiting to enter or re-enter "
"the monitor, or waiting to be notified by the monitor."
Original file line number Diff line number Diff line change
@@ -166,7 +166,7 @@ static void test1(boolean isVirtual) {
Thread[] eThreads = null;

synchronized (lockCheck) {
// Virtual threads are not supported by the GetObjectMonitorUsage.
// Virtual threads are not supported by GetObjectMonitorUsage.
// Correct the expected values for the virtual thread case.
int expEnteringCount = isVirtual ? 0 : NUMBER_OF_ENTERING_THREADS;

@@ -251,7 +251,7 @@ static void test3(boolean isVirtual) throws Error {
Thread[] eThreads = null;

synchronized (lockCheck) {
// Virtual threads are not supported by the GetObjectMonitorUsage.
// Virtual threads are not supported by GetObjectMonitorUsage.
// Correct the expected values for the virtual thread case.
int expEnteringCount = isVirtual ? 0 : NUMBER_OF_ENTERING_THREADS;
int expWaitingCount = isVirtual ? 0 : NUMBER_OF_WAITING_THREADS;
Original file line number Diff line number Diff line change
@@ -113,7 +113,6 @@ private static void execTest() {

// Wait up to waitTime until all MyThreads will be blocked on entering in monitor
int waitingCount = 0;
int expWaitingCount = 0;
long oldTime = System.currentTimeMillis();
while ((System.currentTimeMillis() - oldTime) <= waitTime && waitingCount < waitingthreads002a.threadCount) {
Iterator threads = debuggee.VM().allThreads().iterator();
@@ -125,7 +124,6 @@ private static void execTest() {
waitingCount++;
// Virtual threads are not present in result returned by objRef.waitingThreads().
if (!thread.isVirtual()) {
expWaitingCount++;
}
}
}
@@ -164,6 +162,8 @@ private static void execTest() {
objRef = (ObjectReference) debuggeeClass.getValue(debuggeeClass.fieldByName(fieldName));
try {
List waitingThreads = objRef.waitingThreads();
final boolean vthreadMode = "Virtual".equals(System.getProperty("test.thread.factory"));
final int expWaitingCount = vthreadMode ? 0 : waitingthreads002a.threadCount;
if (waitingThreads.size() != expWaitingCount) {
exitStatus = Consts.TEST_FAILED;
complain("waitingThreads method returned list with unexpected size for " + fieldName +
Original file line number Diff line number Diff line change
@@ -61,8 +61,9 @@ public static int run(String argv[], PrintStream out) {
syncObject[i] = new Object();
runn[i] = new objmonusage001a(mainThread, i, syncObject[i]);
}
// Virtual threads are not supported by the GetObjectMonitorUsage. Correct
// the expected values if the test is executed with MainWrapper=virtual.
// Virtual threads are not supported by GetObjectMonitorUsage.
// Correct the expected values if the test is executed with
// JTREG_TEST_THREAD_FACTORY=Virtual.
Thread expOwner = mainThread.isVirtual() ? null : mainThread;
int expEntryCount = mainThread.isVirtual() ? 0 : 1;

@@ -154,8 +155,9 @@ public objmonusage001a(Thread mt, int i, Object s) {
}

public void run() {
// Virtual threads are not supported by the GetObjectMonitorUsage. Correct
// the expected values if the test is executed with MainWrapper=virtual.
// Virtual threads are not supported by GetObjectMonitorUsage.
// Correct the expected values if the test is executed with
// JTREG_TEST_THREAD_FACTORY=Virtual.
Thread expOwner = this.isVirtual() ? null : this;
Thread expNotifyWaiter = mainThread.isVirtual() ? null : mainThread;
int expEntryCount = this.isVirtual() ? 0 : 1;
Original file line number Diff line number Diff line change
@@ -60,8 +60,9 @@ public static int run(String args[], PrintStream out) {
Thread currThread = Thread.currentThread();
ContendThread thr[] = new ContendThread[NUMBER_OF_THREADS];
synchronized (lockCheck) {
// Virtual threads are not supported by the GetObjectMonitorUsage. Correct
// the expected values if the test is executed with MainWrapper=virtual.
// Virtual threads are not supported by GetObjectMonitorUsage.
// Correct the expected values if the test is executed with
// JTREG_TEST_THREAD_FACTORY=Virtual.
Thread expOwner = currThread.isVirtual() ? null : currThread;
int expEntryCount = currThread.isVirtual() ? 0 : 2;