hotspot/test/compiler/codecache/jmx/PeakUsageTest.java
changeset 40624 cb96161ede05
parent 40059 c2304140ed64
child 40631 ed82623d7831
equal deleted inserted replaced
40385:a7011a835634 40624:cb96161ede05
    25  * @test PeakUsageTest
    25  * @test PeakUsageTest
    26  * @library /testlibrary /test/lib /
    26  * @library /testlibrary /test/lib /
    27  * @modules java.base/jdk.internal.misc
    27  * @modules java.base/jdk.internal.misc
    28  *          java.management
    28  *          java.management
    29  *
    29  *
    30  * @ignore 8151345
       
    31  * @build ompiler.codecache.jmx.PeakUsageTest
    30  * @build ompiler.codecache.jmx.PeakUsageTest
    32  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
    31  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
    33  *     sun.hotspot.WhiteBox$WhiteBoxPermission
    32  *     sun.hotspot.WhiteBox$WhiteBoxPermission
    34  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
    33  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
    35  *     -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,null::*
    34  *     -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,null::*
    67     protected void runTest() {
    66     protected void runTest() {
    68         MemoryPoolMXBean bean = btype.getMemoryPool();
    67         MemoryPoolMXBean bean = btype.getMemoryPool();
    69         bean.resetPeakUsage();
    68         bean.resetPeakUsage();
    70         long addr = CodeCacheUtils.WB.allocateCodeBlob(
    69         long addr = CodeCacheUtils.WB.allocateCodeBlob(
    71                 CodeCacheUtils.ALLOCATION_SIZE, btype.id);
    70                 CodeCacheUtils.ALLOCATION_SIZE, btype.id);
    72         long newPeakUsage = bean.getPeakUsage().getUsed();
    71 
    73         try {
    72         try {
    74             CodeCacheUtils.assertEQorGTE(btype, newPeakUsage, bean.getUsage().getUsed(),
    73             /*
       
    74             Always save peakUsage after saving currentUsage. Reversing the order
       
    75             can lead to inconsistent results (currentUsage > peakUsage) because
       
    76             of intermediate allocations.
       
    77             */
       
    78             long currUsage = bean.getUsage().getUsed();
       
    79             long peakUsage = bean.getPeakUsage().getUsed();
       
    80             CodeCacheUtils.assertEQorLTE(btype, currUsage,
       
    81                     peakUsage,
    75                     "Peak usage does not match usage after allocation for "
    82                     "Peak usage does not match usage after allocation for "
    76                     + bean.getName());
    83                     + bean.getName());
    77         } finally {
    84         } finally {
    78             if (addr != 0) {
    85             if (addr != 0) {
    79                 CodeCacheUtils.WB.freeCodeBlob(addr);
    86                 CodeCacheUtils.WB.freeCodeBlob(addr);
    80             }
    87             }
    81         }
    88         }
    82         CodeCacheUtils.assertEQorGTE(btype, newPeakUsage, bean.getPeakUsage().getUsed(),
       
    83                 "Code cache peak usage has changed after usage decreased for "
       
    84                 + bean.getName());
       
    85         bean.resetPeakUsage();
    89         bean.resetPeakUsage();
    86         CodeCacheUtils.assertEQorGTE(btype, bean.getPeakUsage().getUsed(),
    90         long currUsage = bean.getUsage().getUsed();
    87                 bean.getUsage().getUsed(),
    91         long peakUsage = bean.getPeakUsage().getUsed();
       
    92         CodeCacheUtils.assertEQorLTE(btype, currUsage,
       
    93                 peakUsage,
    88                 "Code cache peak usage is not equal to usage after reset for "
    94                 "Code cache peak usage is not equal to usage after reset for "
    89                 + bean.getName());
    95                 + bean.getName());
    90         long addr2 = CodeCacheUtils.WB.allocateCodeBlob(
    96         long addr2 = CodeCacheUtils.WB.allocateCodeBlob(
    91                 CodeCacheUtils.ALLOCATION_SIZE, btype.id);
    97                 CodeCacheUtils.ALLOCATION_SIZE, btype.id);
    92         try {
    98         try {
    93             CodeCacheUtils.assertEQorGTE(btype, bean.getPeakUsage().getUsed(),
    99             currUsage = bean.getUsage().getUsed();
    94                     bean.getUsage().getUsed(),
   100             peakUsage = bean.getPeakUsage().getUsed();
       
   101 
       
   102             CodeCacheUtils.assertEQorLTE(btype, currUsage,
       
   103                     peakUsage,
    95                     "Code cache peak usage is not equal to usage after fresh "
   104                     "Code cache peak usage is not equal to usage after fresh "
    96                     + "allocation for " + bean.getName());
   105                     + "allocation for " + bean.getName());
    97         } finally {
   106         } finally {
    98             if (addr2 != 0) {
   107             if (addr2 != 0) {
    99                 CodeCacheUtils.WB.freeCodeBlob(addr2);
   108                 CodeCacheUtils.WB.freeCodeBlob(addr2);