< prev index next >

test/hotspot/jtreg/runtime/vthread/JNIMonitor/JNIMonitor.java

Print this page
@@ -117,10 +117,12 @@
              // Enable the JNI warning
              "-Xcheck:jni",
              "-Xlog:jni=debug",
              // Enable thread termination logging as a visual cross-check
              "-Xlog:thread+os=info",
+             // We only count monitors in LM_LEGACY mode
+             "-XX:LockingMode=1",
              "JNIMonitor$" + test,
          };
          OutputAnalyzer oa = ProcessTools.executeTestJava(cmdArgs);
          oa.shouldHaveExitValue(0);
          oa.stdoutShouldMatch(terminated);

@@ -217,16 +219,20 @@
                  throw new RuntimeException(e);
              }
          }
  
          static void runTest(int nThreads, boolean skipUnlock, boolean throwOnExit) throws Throwable {
-             final Object monitor = new Object();
+             final Object[] monitors = new Object[nThreads];
+             for (int i = 0; i < nThreads; i++) {
+                 monitors[i] = new Object();
+             }
              final AtomicReference<Throwable> exception = new AtomicReference();
              // Ensure all our VT's operate of the same carrier, sequentially.
              ExecutorService scheduler = Executors.newSingleThreadExecutor();
              ThreadFactory factory = virtualThreadBuilder(scheduler).factory();
              for (int i = 0 ; i < nThreads; i++) {
+                 Object monitor = skipUnlock ? monitors[i] : monitors[0];
                  Thread th = factory.newThread(() -> {
                          try {
                              int res = monitorEnter(monitor);
                              Asserts.assertTrue(res == 0, "monitorEnter should return 0.");
                              Asserts.assertTrue(Thread.holdsLock(monitor), "monitor should be owned");
< prev index next >