Wed, 14 Jan 2015 09:53:36 +0300
8068269: RTM tests that assert on non-zero lock statistics are too strict in RTMTotalCountIncrRate > 1 cases
Reviewed-by: kvn, iignatyev
1.1 --- a/test/compiler/rtm/locking/TestRTMTotalCountIncrRate.java Wed Feb 27 10:23:05 2019 +0100 1.2 +++ b/test/compiler/rtm/locking/TestRTMTotalCountIncrRate.java Wed Jan 14 09:53:36 2015 +0300 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -34,6 +34,7 @@ 1.11 * -XX:+WhiteBoxAPI TestRTMTotalCountIncrRate 1.12 */ 1.13 1.14 +import sun.misc.Unsafe; 1.15 import java.util.List; 1.16 1.17 import com.oracle.java.testlibrary.*; 1.18 @@ -96,14 +97,12 @@ 1.19 Asserts.assertEQ(lock.getTotalLocks(), Test.TOTAL_ITERATIONS, 1.20 "Total locks should be exactly the same as amount of " 1.21 + "iterations."); 1.22 - } else { 1.23 - Asserts.assertGT(lock.getTotalLocks(), 0L, "RTM statistics " 1.24 - + "should contain information for at least on lock."); 1.25 } 1.26 } 1.27 1.28 public static class Test implements CompilableTest { 1.29 private static final long TOTAL_ITERATIONS = 10000L; 1.30 + private static final Unsafe UNSAFE = Utils.getUnsafe(); 1.31 private final Object monitor = new Object(); 1.32 // Following field have to be static in order to avoid escape analysis. 1.33 @SuppressWarnings("UnsuedDeclaration") 1.34 @@ -119,8 +118,17 @@ 1.35 return new String[] { getMethodWithLockName() }; 1.36 } 1.37 1.38 - public void lock() { 1.39 + public void lock(boolean forceAbort) { 1.40 synchronized(monitor) { 1.41 + if (forceAbort) { 1.42 + // We're calling native method in order to force 1.43 + // abort. It's done by explicit xabort call emitted 1.44 + // in SharedRuntime::generate_native_wrapper. 1.45 + // If an actual JNI call will be replaced by 1.46 + // intrinsic - we'll be in trouble, since xabort 1.47 + // will be no longer called and test may fail. 1.48 + UNSAFE.addressSize(); 1.49 + } 1.50 Test.field++; 1.51 } 1.52 } 1.53 @@ -139,7 +147,11 @@ 1.54 for (long i = 0L; i < Test.TOTAL_ITERATIONS; i++) { 1.55 AbortProvoker.verifyMonitorState(test.monitor, 1.56 shouldBeInflated); 1.57 - test.lock(); 1.58 + // Force abort on first iteration to avoid rare case when 1.59 + // there were no aborts and locks count was not incremented 1.60 + // with RTMTotalCountIncrRate > 1 (in such case JVM won't 1.61 + // print JVM locking statistics). 1.62 + test.lock(i == 0); 1.63 } 1.64 } 1.65 }
2.1 --- a/test/compiler/rtm/print/TestPrintPreciseRTMLockingStatistics.java Wed Feb 27 10:23:05 2019 +0100 2.2 +++ b/test/compiler/rtm/print/TestPrintPreciseRTMLockingStatistics.java Wed Jan 14 09:53:36 2015 +0300 2.3 @@ -124,9 +124,6 @@ 2.4 2.5 RTMLockingStatistics lock = statistics.get(0); 2.6 2.7 - Asserts.assertGT(lock.getTotalLocks(), 0L, "RTM locking statistics " 2.8 - + "should contain non zero total locks count"); 2.9 - 2.10 Asserts.assertGT(lock.getTotalAborts(), 0L, 2.11 "RTM locking statistics should contain non zero total aborts " 2.12 + "count");