< prev index next >

test/jdk/com/sun/jdi/EATests.java

Print this page
*** 40,58 ***
--- 40,102 ---
   *                 -Xbootclasspath/a:.
   *                 -XX:CompileCommand=dontinline,*::dontinline_*
   *                 -XX:+WhiteBoxAPI
   *                 -Xbatch
   *                 -XX:+DoEscapeAnalysis -XX:+EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks -XX:+UseBiasedLocking
+  *                 -XX:+UnlockExperimentalVMOptions -XX:LockingMode=1
   * @run driver EATests
   *                 -XX:+UnlockDiagnosticVMOptions
   *                 -Xms256m -Xmx256m
   *                 -Xbootclasspath/a:.
   *                 -XX:CompileCommand=dontinline,*::dontinline_*
   *                 -XX:+WhiteBoxAPI
   *                 -Xbatch
   *                 -XX:+DoEscapeAnalysis -XX:+EliminateAllocations -XX:-EliminateLocks -XX:+EliminateNestedLocks -XX:+UseBiasedLocking -XX:-UseOptoBiasInlining
+  *                 -XX:+UnlockExperimentalVMOptions -XX:LockingMode=1
   * @run driver EATests
   *                 -XX:+UnlockDiagnosticVMOptions
   *                 -Xms256m -Xmx256m
   *                 -Xbootclasspath/a:.
   *                 -XX:CompileCommand=dontinline,*::dontinline_*
   *                 -XX:+WhiteBoxAPI
   *                 -Xbatch
   *                 -XX:+DoEscapeAnalysis -XX:-EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks -XX:+UseBiasedLocking
+  *                 -XX:+UnlockExperimentalVMOptions -XX:LockingMode=1
   * @run driver EATests
   *                 -XX:+UnlockDiagnosticVMOptions
   *                 -Xms256m -Xmx256m
   *                 -Xbootclasspath/a:.
   *                 -XX:CompileCommand=dontinline,*::dontinline_*
   *                 -XX:+WhiteBoxAPI
   *                 -Xbatch
   *                 -XX:-DoEscapeAnalysis -XX:-EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks -XX:+UseBiasedLocking
+  *                 -XX:+UnlockExperimentalVMOptions -XX:LockingMode=1
   * @run driver EATests
   *                 -XX:+UnlockDiagnosticVMOptions
   *                 -Xms256m -Xmx256m
   *                 -Xbootclasspath/a:.
   *                 -XX:CompileCommand=dontinline,*::dontinline_*
   *                 -XX:+WhiteBoxAPI
   *                 -Xbatch
   *                 -XX:+DoEscapeAnalysis -XX:+EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks -XX:-UseBiasedLocking
+  *                 -XX:+UnlockExperimentalVMOptions -XX:LockingMode=1
   * @run driver EATests
   *                 -XX:+UnlockDiagnosticVMOptions
   *                 -Xms256m -Xmx256m
   *                 -Xbootclasspath/a:.
   *                 -XX:CompileCommand=dontinline,*::dontinline_*
   *                 -XX:+WhiteBoxAPI
   *                 -Xbatch
   *                 -XX:+DoEscapeAnalysis -XX:-EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks -XX:-UseBiasedLocking
+  *                 -XX:+UnlockExperimentalVMOptions -XX:LockingMode=1
   * @run driver EATests
   *                 -XX:+UnlockDiagnosticVMOptions
   *                 -Xms256m -Xmx256m
   *                 -Xbootclasspath/a:.
   *                 -XX:CompileCommand=dontinline,*::dontinline_*
   *                 -XX:+WhiteBoxAPI
   *                 -Xbatch
   *                 -XX:-DoEscapeAnalysis -XX:-EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks -XX:-UseBiasedLocking
+  *                 -XX:+UnlockExperimentalVMOptions -XX:LockingMode=1
+  *
+  * @run driver EATests
+  *                 -XX:+UnlockDiagnosticVMOptions
+  *                 -Xms256m -Xmx256m
+  *                 -Xbootclasspath/a:.
+  *                 -XX:CompileCommand=dontinline,*::dontinline_*
+  *                 -XX:+WhiteBoxAPI
+  *                 -Xbatch
+  *                 -XX:+DoEscapeAnalysis -XX:+EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks
+  *                 -XX:+UnlockExperimentalVMOptions -XX:LockingMode=2
+  * @run driver EATests
+  *                 -XX:+UnlockDiagnosticVMOptions
+  *                 -Xms256m -Xmx256m
+  *                 -Xbootclasspath/a:.
+  *                 -XX:CompileCommand=dontinline,*::dontinline_*
+  *                 -XX:+WhiteBoxAPI
+  *                 -Xbatch
+  *                 -XX:+DoEscapeAnalysis -XX:+EliminateAllocations -XX:-EliminateLocks -XX:+EliminateNestedLocks
+  *                 -XX:+UnlockExperimentalVMOptions -XX:LockingMode=2
+  * @run driver EATests
+  *                 -XX:+UnlockDiagnosticVMOptions
+  *                 -Xms256m -Xmx256m
+  *                 -Xbootclasspath/a:.
+  *                 -XX:CompileCommand=dontinline,*::dontinline_*
+  *                 -XX:+WhiteBoxAPI
+  *                 -Xbatch
+  *                 -XX:+DoEscapeAnalysis -XX:-EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks
+  *                 -XX:+UnlockExperimentalVMOptions -XX:LockingMode=2
+  * @run driver EATests
+  *                 -XX:+UnlockDiagnosticVMOptions
+  *                 -Xms256m -Xmx256m
+  *                 -Xbootclasspath/a:.
+  *                 -XX:CompileCommand=dontinline,*::dontinline_*
+  *                 -XX:+WhiteBoxAPI
+  *                 -Xbatch
+  *                 -XX:-DoEscapeAnalysis -XX:-EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks
+  *                 -XX:+UnlockExperimentalVMOptions -XX:LockingMode=2
   *
   * @comment Excercise -XX:+DeoptimizeObjectsALot. Mostly to prevent bit-rot because the option is meant to stress object deoptimization
   *          with non-synthetic workloads.
   * @run driver EATests
   *                 -XX:+UnlockDiagnosticVMOptions

*** 101,11 ***
--- 145,50 ---
   *                 -XX:+WhiteBoxAPI
   *                 -Xbatch
   *                 -XX:-DoEscapeAnalysis -XX:-EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks -XX:-UseBiasedLocking
   *                 -XX:+IgnoreUnrecognizedVMOptions -XX:+DeoptimizeObjectsALot
   *
+  * @bug 8324881
+  * @comment Regression test for using the wrong thread when logging during re-locking from deoptimization.
+  *
+  * @comment DiagnoseSyncOnValueBasedClasses=2 will cause logging when locking on \@ValueBased objects.
+  * @run driver EATests
+  *                 -XX:+UnlockDiagnosticVMOptions
+  *                 -Xms256m -Xmx256m
+  *                 -Xbootclasspath/a:.
+  *                 -XX:CompileCommand=dontinline,*::dontinline_*
+  *                 -XX:+WhiteBoxAPI
+  *                 -Xbatch
+  *                 -XX:+DoEscapeAnalysis -XX:+EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks
+  *                 -XX:+UnlockExperimentalVMOptions -XX:LockingMode=1
+  *                 -XX:DiagnoseSyncOnValueBasedClasses=2
+  *
+  * @comment Re-lock may inflate monitors when re-locking, which cause monitorinflation trace logging.
+  * @run driver EATests
+  *                 -XX:+UnlockDiagnosticVMOptions
+  *                 -Xms256m -Xmx256m
+  *                 -Xbootclasspath/a:.
+  *                 -XX:CompileCommand=dontinline,*::dontinline_*
+  *                 -XX:+WhiteBoxAPI
+  *                 -Xbatch
+  *                 -XX:+DoEscapeAnalysis -XX:+EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks
+  *                 -XX:+UnlockExperimentalVMOptions -XX:LockingMode=2
+  *                 -Xlog:monitorinflation=trace:file=monitorinflation.log
+  *
+  * @comment Re-lock may race with deflation.
+  * @run driver EATests
+  *                 -XX:+UnlockDiagnosticVMOptions
+  *                 -Xms256m -Xmx256m
+  *                 -Xbootclasspath/a:.
+  *                 -XX:CompileCommand=dontinline,*::dontinline_*
+  *                 -XX:+WhiteBoxAPI
+  *                 -Xbatch
+  *                 -XX:+DoEscapeAnalysis -XX:+EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks
+  *                 -XX:+UnlockExperimentalVMOptions -XX:LockingMode=0
+  *                 -XX:GuaranteedAsyncDeflationInterval=1000
   */
+ 
  /**
   * @test
   * @bug 8227745
   *
   * @summary This is another configuration of EATests.java to test Graal. Some testcases are expected

*** 231,20 ***
--- 314,23 ---
          new EAMaterializeLocalVariableUponGetAfterSetIntegerTarget()                        .run();
  
          // Relocking test cases
          new EARelockingSimpleTarget()                                                       .run();
          new EARelockingSimple_2Target()                                                     .run();
+         new EARelockingSimpleWithAccessInOtherThreadTarget()                                .run();
          new EARelockingRecursiveTarget()                                                    .run();
          new EARelockingNestedInflatedTarget()                                               .run();
          new EARelockingNestedInflated_02Target()                                            .run();
+         new EARelockingNestedInflated_03Target()                                            .run();
          new EARelockingArgEscapeLWLockedInCalleeFrameTarget()                               .run();
          new EARelockingArgEscapeLWLockedInCalleeFrame_2Target()                             .run();
          new EARelockingArgEscapeLWLockedInCalleeFrame_3Target()                             .run();
          new EARelockingArgEscapeLWLockedInCalleeFrame_4Target()                             .run();
          new EAGetOwnedMonitorsTarget()                                                      .run();
          new EAEntryCountTarget()                                                            .run();
          new EARelockingObjectCurrentlyWaitingOnTarget()                                     .run();
+         new EARelockingValueBasedTarget()                                                   .run();
  
          // Test cases that require deoptimization even though neither
          // locks nor allocations are eliminated at the point where
          // escape state is changed.
          new EADeoptFrameAfterReadLocalObject_01Target()                                     .run();

*** 351,20 ***
--- 437,23 ---
          new EAMaterializeLocalVariableUponGetAfterSetInteger()                        .run(this);
  
          // Relocking test cases
          new EARelockingSimple()                                                       .run(this);
          new EARelockingSimple_2()                                                     .run(this);
+         new EARelockingSimpleWithAccessInOtherThread()                                .run(this);
          new EARelockingRecursive()                                                    .run(this);
          new EARelockingNestedInflated()                                               .run(this);
          new EARelockingNestedInflated_02()                                            .run(this);
+         new EARelockingNestedInflated_03()                                            .run(this);
          new EARelockingArgEscapeLWLockedInCalleeFrame()                               .run(this);
          new EARelockingArgEscapeLWLockedInCalleeFrame_2()                             .run(this);
          new EARelockingArgEscapeLWLockedInCalleeFrame_3()                             .run(this);
          new EARelockingArgEscapeLWLockedInCalleeFrame_4()                             .run(this);
          new EAGetOwnedMonitors()                                                      .run(this);
          new EAEntryCount()                                                            .run(this);
          new EARelockingObjectCurrentlyWaitingOn()                                     .run(this);
+         new EARelockingValueBased()                                                   .run(this);
  
          // Test cases that require deoptimization even though neither
          // locks nor allocations are eliminated at the point where
          // escape state is changed.
          new EADeoptFrameAfterReadLocalObject_01()                                     .run(this);

*** 1785,10 ***
--- 1874,11 ---
   * escape through JVMTI. O is referenced by field l0.
   * This tests a regression of a previous version of the implementation.
   */
  class EARelockingSimple_2 extends EATestCaseBaseDebugger {
  
+ 
      public void runTestCase() throws Exception {
          BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
          printStack(bpe.thread());
          @SuppressWarnings("unused")
          ObjectReference o = getLocalRef(bpe.thread().frame(1), XYVAL_NAME, "l1");

*** 1810,10 ***
--- 1900,70 ---
      }
  }
  
  /////////////////////////////////////////////////////////////////////////////
  
+ // The debugger reads and publishes an object with eliminated locking to an instance field.
+ // A 2nd thread in the debuggee finds it there and changes its state using a synchronized method.
+ // Without eager relocking the accesses are unsynchronized which can be observed.
+ class EARelockingSimpleWithAccessInOtherThread extends EATestCaseBaseDebugger {
+ 
+     public void runTestCase() throws Exception {
+         BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
+         printStack(bpe.thread());
+         String l1ClassName = EARelockingSimpleWithAccessInOtherThreadTarget.SyncCounter.class.getName();
+         ObjectReference ctr = getLocalRef(bpe.thread().frame(1), l1ClassName, "l1");
+         setField(testCase, "sharedCounter", ctr);
+         terminateEndlessLoop();
+     }
+ }
+ 
+ class EARelockingSimpleWithAccessInOtherThreadTarget extends EATestCaseBaseTarget {
+ 
+     public static class SyncCounter {
+         private int val;
+         public synchronized int inc() { return val++; }
+     }
+ 
+     public volatile SyncCounter sharedCounter;
+ 
+     @Override
+     public void setUp() {
+         super.setUp();
+         doLoop = true;
+         Thread t = new Thread() {
+             public void run() {
+                 while (doLoop) {
+                     SyncCounter ctr = sharedCounter;
+                     if (ctr != null) {
+                         ctr.inc();
+                     }
+                 }
+             }
+         };
+         t.setDaemon(true);
+         t.start();
+     }
+ 
+     public void dontinline_testMethod() {
+         SyncCounter l1 = new SyncCounter();
+         synchronized (l1) {      // Eliminated locking
+             l1.inc();
+             dontinline_brkpt();  // Debugger publishes l1 to sharedCounter.
+             iResult = l1.inc();  // Changes by the 2nd thread will be observed if l1
+                                  // was not relocked before passing it to the debugger.
+         }
+     }
+ 
+     @Override
+     public int getExpectedIResult() {
+         return 1;
+     }
+ }
+ 
+ /////////////////////////////////////////////////////////////////////////////
+ 
  // Test recursive locking
  class EARelockingRecursiveTarget extends EATestCaseBaseTarget {
  
      @Override
      public void setUp() {

*** 1928,10 ***
--- 2078,98 ---
      }
  }
  
  /////////////////////////////////////////////////////////////////////////////
  
+ /**
+  * Like {@link EARelockingNestedInflated_02} with the difference that the
+  * inflation of the lock happens because of contention.
+  */
+ class EARelockingNestedInflated_03 extends EATestCaseBaseDebugger {
+ 
+     public void runTestCase() throws Exception {
+         BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
+         printStack(bpe.thread());
+         @SuppressWarnings("unused")
+         ObjectReference o = getLocalRef(bpe.thread().frame(2), XYVAL_NAME, "l1");
+     }
+ }
+ 
+ class EARelockingNestedInflated_03Target extends EATestCaseBaseTarget {
+ 
+     public XYVal lockInflatedByContention;
+     public boolean doLockNow;
+     public EATestCaseBaseTarget testCase;
+ 
+     @Override
+     public void setUp() {
+         super.setUp();
+         testMethodDepth = 2;
+         lockInflatedByContention = new XYVal(1, 1);
+         testCase = this;
+     }
+ 
+     @Override
+     public void warmupDone() {
+         super.warmupDone();
+         // Use new lock. lockInflatedByContention might have been inflated because of recursion.
+         lockInflatedByContention = new XYVal(1, 1);
+         // Start thread that tries to enter lockInflatedByContention while the main thread owns it -> inflation
+         new Thread(() -> {
+             while (true) {
+                 synchronized (testCase) {
+                     try {
+                         if (doLockNow) {
+                             doLockNow = false; // reset for main thread
+                             testCase.notify();
+                             break;
+                         }
+                         testCase.wait();
+                     } catch (InterruptedException e) { /* ignored */ }
+                 }
+             }
+             synchronized (lockInflatedByContention) { // will block and trigger inflation
+                 msg(Thread.currentThread().getName() + ": acquired lockInflatedByContention");
+             }
+             }, testCaseName + ": Lock Contender (test thread)").start();
+     }
+ 
+     public void dontinline_testMethod() {
+         @SuppressWarnings("unused")
+         XYVal xy = new XYVal(1, 1);            // scalar replaced
+         XYVal l1 = lockInflatedByContention;   // read by debugger
+         synchronized (l1) {
+             testMethod_inlined(l1);
+         }
+     }
+ 
+     public void testMethod_inlined(XYVal l2) {
+         synchronized (l2) {                 // eliminated nested locking
+             dontinline_notifyOtherThread();
+             dontinline_brkpt();
+         }
+     }
+ 
+     public void dontinline_notifyOtherThread() {
+         if (!warmupDone) {
+             return;
+         }
+         synchronized (testCase) {
+             doLockNow = true;
+             testCase.notify();
+             // wait for other thread to reset doLockNow again
+             while (doLockNow) {
+                 try {
+                     testCase.wait();
+                 } catch (InterruptedException e) { /* ignored */ }
+             }
+         }
+     }
+ }
+ 
+ /////////////////////////////////////////////////////////////////////////////
+ 
  /**
   * Checks if an eliminated lock of an ArgEscape object l1 can be relocked if
   * l1 is locked in a callee frame.
   */
  class EARelockingArgEscapeLWLockedInCalleeFrame extends EATestCaseBaseDebugger {

*** 2107,10 ***
--- 2345,52 ---
      }
  }
  
  /////////////////////////////////////////////////////////////////////////////
  
+ /**
+  * Similar to {@link EARelockingArgEscapeLWLockedInCalleeFrame_2Target}. It does
+  * not use recursive locking and exposed a bug in the lightweight-locking implementation.
+  */
+ class EARelockingArgEscapeLWLockedInCalleeFrameNoRecursive extends EATestCaseBaseDebugger {
+ 
+     public void runTestCase() throws Exception {
+         BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
+         printStack(bpe.thread());
+         @SuppressWarnings("unused")
+         ObjectReference o = getLocalRef(bpe.thread().frame(2), XYVAL_NAME, "l1");
+     }
+ }
+ 
+ class EARelockingArgEscapeLWLockedInCalleeFrameNoRecursiveTarget extends EATestCaseBaseTarget {
+ 
+     @Override
+     public void setUp() {
+         super.setUp();
+         testMethodDepth = 2;
+     }
+ 
+     public void dontinline_testMethod() {
+         XYVal l1 = new XYVal(1, 1);       // NoEscape, scalar replaced
+         XYVal l2 = new XYVal(4, 2);       // NoEscape, scalar replaced
+         XYVal l3 = new XYVal(5, 3);       // ArgEscape
+         synchronized (l1) {                   // eliminated
+             synchronized (l2) {               // eliminated
+                 l3.dontinline_sync_method(this);  // l3 escapes
+             }
+         }
+         iResult = l2.x + l2.y;
+     }
+ 
+     @Override
+     public int getExpectedIResult() {
+         return 6;
+     }
+ }
+ 
+ /////////////////////////////////////////////////////////////////////////////
+ 
  /**
   * Test relocking eliminated (nested) locks of an object on which the
   * target thread currently waits.
   */
  class EARelockingObjectCurrentlyWaitingOn extends EATestCaseBaseDebugger {

*** 2200,10 ***
--- 2480,36 ---
              l2.wait();
          }
      }
  }
  
+ 
+ /////////////////////////////////////////////////////////////////////////////
+ 
+ /**
+  * Test relocking eliminated @ValueBased object.
+  */
+ class EARelockingValueBased extends EATestCaseBaseDebugger {
+ 
+     public void runTestCase() throws Exception {
+         BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
+         printStack(bpe.thread());
+         @SuppressWarnings("unused")
+         ObjectReference o = getLocalRef(bpe.thread().frame(1), Integer.class.getName(), "l1");
+     }
+ }
+ 
+ class EARelockingValueBasedTarget extends EATestCaseBaseTarget {
+ 
+     public void dontinline_testMethod() {
+         Integer l1 = new Integer(255);
+         synchronized (l1) {
+             dontinline_brkpt();
+         }
+     }
+ }
+ 
  /////////////////////////////////////////////////////////////////////////////
  //
  // Test cases that require deoptimization even though neither locks
  // nor allocations are eliminated at the point where escape state is changed.
  //
< prev index next >