8151345: compiler/codecache/jmx/PeakUsageTest.java is failing on jdk9/dev for JPRT -testset hotspot
authordsamersoff
Thu, 18 Aug 2016 12:10:18 +0300
changeset 40624 cb96161ede05
parent 40385 a7011a835634
child 40626 86b5b9f4e1e1
8151345: compiler/codecache/jmx/PeakUsageTest.java is failing on jdk9/dev for JPRT -testset hotspot Reviewed-by: sla, dsamersoff
hotspot/test/compiler/codecache/jmx/CodeCacheUtils.java
hotspot/test/compiler/codecache/jmx/PeakUsageTest.java
--- a/hotspot/test/compiler/codecache/jmx/CodeCacheUtils.java	Tue Aug 16 09:56:18 2016 -0400
+++ b/hotspot/test/compiler/codecache/jmx/CodeCacheUtils.java	Thu Aug 18 12:10:18 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -119,6 +119,28 @@
         }
     }
 
+    /**
+     * Verifies that 'newValue' is equal to 'oldValue' if usage of the
+     * corresponding code heap is predictable. Checks the weaker condition
+     * 'newValue <= oldValue' if usage is not predictable because intermediate
+     * allocations may happen.
+     *
+     * @param btype BlobType of the code heap to be checked
+     * @param newValue New value to be verified
+     * @param oldValue Old value to be verified
+     * @param msg Error message if verification fails
+     */
+    public static void assertEQorLTE(BlobType btype, long newValue, long oldValue, String msg) {
+        if (CodeCacheUtils.isCodeHeapPredictable(btype)) {
+            // Usage is predictable, check strong == condition
+            Asserts.assertEQ(newValue, oldValue, msg);
+        } else {
+            // Usage is not predictable, check weaker <= condition
+            Asserts.assertLTE(newValue, oldValue, msg);
+        }
+    }
+
+
     public static void disableCollectionUsageThresholds() {
         BlobType.getAvailable().stream()
                 .map(BlobType::getMemoryPool)
--- a/hotspot/test/compiler/codecache/jmx/PeakUsageTest.java	Tue Aug 16 09:56:18 2016 -0400
+++ b/hotspot/test/compiler/codecache/jmx/PeakUsageTest.java	Thu Aug 18 12:10:18 2016 +0300
@@ -27,7 +27,6 @@
  * @modules java.base/jdk.internal.misc
  *          java.management
  *
- * @ignore 8151345
  * @build ompiler.codecache.jmx.PeakUsageTest
  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  *     sun.hotspot.WhiteBox$WhiteBoxPermission
@@ -69,9 +68,17 @@
         bean.resetPeakUsage();
         long addr = CodeCacheUtils.WB.allocateCodeBlob(
                 CodeCacheUtils.ALLOCATION_SIZE, btype.id);
-        long newPeakUsage = bean.getPeakUsage().getUsed();
+
         try {
-            CodeCacheUtils.assertEQorGTE(btype, newPeakUsage, bean.getUsage().getUsed(),
+            /*
+            Always save peakUsage after saving currentUsage. Reversing the order
+            can lead to inconsistent results (currentUsage > peakUsage) because
+            of intermediate allocations.
+            */
+            long currUsage = bean.getUsage().getUsed();
+            long peakUsage = bean.getPeakUsage().getUsed();
+            CodeCacheUtils.assertEQorLTE(btype, currUsage,
+                    peakUsage,
                     "Peak usage does not match usage after allocation for "
                     + bean.getName());
         } finally {
@@ -79,19 +86,21 @@
                 CodeCacheUtils.WB.freeCodeBlob(addr);
             }
         }
-        CodeCacheUtils.assertEQorGTE(btype, newPeakUsage, bean.getPeakUsage().getUsed(),
-                "Code cache peak usage has changed after usage decreased for "
-                + bean.getName());
         bean.resetPeakUsage();
-        CodeCacheUtils.assertEQorGTE(btype, bean.getPeakUsage().getUsed(),
-                bean.getUsage().getUsed(),
+        long currUsage = bean.getUsage().getUsed();
+        long peakUsage = bean.getPeakUsage().getUsed();
+        CodeCacheUtils.assertEQorLTE(btype, currUsage,
+                peakUsage,
                 "Code cache peak usage is not equal to usage after reset for "
                 + bean.getName());
         long addr2 = CodeCacheUtils.WB.allocateCodeBlob(
                 CodeCacheUtils.ALLOCATION_SIZE, btype.id);
         try {
-            CodeCacheUtils.assertEQorGTE(btype, bean.getPeakUsage().getUsed(),
-                    bean.getUsage().getUsed(),
+            currUsage = bean.getUsage().getUsed();
+            peakUsage = bean.getPeakUsage().getUsed();
+
+            CodeCacheUtils.assertEQorLTE(btype, currUsage,
+                    peakUsage,
                     "Code cache peak usage is not equal to usage after fresh "
                     + "allocation for " + bean.getName());
         } finally {