test/jdk/jdk/jfr/event/compiler/TestCodeCacheConfig.java
changeset 50113 caf115bb98ad
child 51214 67736b4846a0
equal deleted inserted replaced
50112:7a2a740815b7 50113:caf115bb98ad
       
     1 /*
       
     2  * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 package jdk.jfr.event.compiler;
       
    27 
       
    28 import java.util.List;
       
    29 
       
    30 import jdk.jfr.Recording;
       
    31 import jdk.jfr.consumer.RecordedEvent;
       
    32 import jdk.test.lib.Asserts;
       
    33 import jdk.test.lib.jfr.EventNames;
       
    34 import jdk.test.lib.jfr.Events;
       
    35 import sun.hotspot.WhiteBox;
       
    36 
       
    37 /*
       
    38  * @test TestCodeCacheConfig
       
    39  * @key jfr
       
    40  * @library /test/lib
       
    41  * @build sun.hotspot.WhiteBox
       
    42  * @run main ClassFileInstaller sun.hotspot.WhiteBox
       
    43  *     sun.hotspot.WhiteBox$WhiteBoxPermission
       
    44  * @run main/othervm -Xbootclasspath/a:.
       
    45  *     -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
       
    46  *     -XX:+SegmentedCodeCache jdk.jfr.event.compiler.TestCodeCacheConfig
       
    47  * @run main/othervm -Xbootclasspath/a:.
       
    48  *     -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
       
    49  *     -XX:-SegmentedCodeCache jdk.jfr.event.compiler.TestCodeCacheConfig
       
    50  * @summary check "Code Cache Configuration" jfr event
       
    51  */
       
    52 public class TestCodeCacheConfig {
       
    53     private final static String EVENT_NAME = EventNames.CodeCacheConfiguration;
       
    54 
       
    55     private static final long CodeCacheExpectedSize = WhiteBox.getWhiteBox().getUintxVMFlag("ReservedCodeCacheSize");
       
    56 
       
    57     public static void main(String[] args) throws Exception {
       
    58         Recording recording = new Recording();
       
    59         recording.enable(EVENT_NAME);
       
    60         recording.start();
       
    61         recording.stop();
       
    62 
       
    63         List<RecordedEvent> events = Events.fromRecording(recording);
       
    64         Events.hasEvents(events);
       
    65         RecordedEvent event = events.get(0);
       
    66         long initialSize = (long) event.getValue("initialSize");
       
    67         long reservedSize = (long) event.getValue("reservedSize");
       
    68         long nonNMethodSize = (long) event.getValue("nonNMethodSize");
       
    69         long profiledSize = (long) event.getValue("profiledSize");
       
    70         long nonProfiledSize = (long) event.getValue("nonProfiledSize");
       
    71         long expansionSize = (long) event.getValue("expansionSize");
       
    72         long minBlockLength = (long) event.getValue("minBlockLength");
       
    73         long startAddress = (long) event.getValue("startAddress");
       
    74         long reservedTopAddress = (long) event.getValue("reservedTopAddress");
       
    75 
       
    76         Asserts.assertGT(initialSize, 1024L,
       
    77             "initialSize less than 1024 byte, got " + initialSize);
       
    78 
       
    79         Asserts.assertEQ(reservedSize, CodeCacheExpectedSize,
       
    80             String.format("Unexpected reservedSize value. Expected %d but " + "got %d", CodeCacheExpectedSize, reservedSize));
       
    81 
       
    82         Asserts.assertLTE(nonNMethodSize, CodeCacheExpectedSize,
       
    83             String.format("Unexpected nonNMethodSize value. Expected <= %d but " + "got %d", CodeCacheExpectedSize, nonNMethodSize));
       
    84 
       
    85         Asserts.assertLTE(profiledSize, CodeCacheExpectedSize,
       
    86             String.format("Unexpected profiledSize value. Expected <= %d but " + "got %d", CodeCacheExpectedSize, profiledSize));
       
    87 
       
    88         Asserts.assertLTE(nonProfiledSize, CodeCacheExpectedSize,
       
    89             String.format("Unexpected nonProfiledSize value. Expected <= %d but " + "got %d", CodeCacheExpectedSize, nonProfiledSize));
       
    90 
       
    91         Asserts.assertGTE(expansionSize, 1024L,
       
    92             "expansionSize less than 1024 " + "bytes, got " + expansionSize);
       
    93 
       
    94         Asserts.assertGTE(minBlockLength, 1L,
       
    95             "minBlockLength less than 1 byte, got " + minBlockLength);
       
    96 
       
    97         Asserts.assertNE(startAddress, 0L,
       
    98             "startAddress null");
       
    99 
       
   100         Asserts.assertNE(reservedTopAddress, 0L,
       
   101             "codeCacheReservedTopAddr null");
       
   102     }
       
   103 }