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  * @requires vm.hasJFR
41  * @library /test/lib
42  * @build sun.hotspot.WhiteBox
43  * @run main ClassFileInstaller sun.hotspot.WhiteBox
44  *     sun.hotspot.WhiteBox$WhiteBoxPermission
45  * @run main/othervm -Xbootclasspath/a:.
46  *     -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
47  *     -XX:+SegmentedCodeCache jdk.jfr.event.compiler.TestCodeCacheConfig
48  * @run main/othervm -Xbootclasspath/a:.
49  *     -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
50  *     -XX:-SegmentedCodeCache jdk.jfr.event.compiler.TestCodeCacheConfig
51  * @summary check "Code Cache Configuration" jfr event
52  */
53 public class TestCodeCacheConfig {
54     private final static String EVENT_NAME = EventNames.CodeCacheConfiguration;
55 
56     private static final long CodeCacheExpectedSize = WhiteBox.getWhiteBox().getUintxVMFlag("ReservedCodeCacheSize");
57 
main(String[] args)58     public static void main(String[] args) throws Exception {
59         Recording recording = new Recording();
60         recording.enable(EVENT_NAME);
61         recording.start();
62         recording.stop();
63 
64         List<RecordedEvent> events = Events.fromRecording(recording);
65         Events.hasEvents(events);
66         RecordedEvent event = events.get(0);
67         long initialSize = (long) event.getValue("initialSize");
68         long reservedSize = (long) event.getValue("reservedSize");
69         long nonNMethodSize = (long) event.getValue("nonNMethodSize");
70         long profiledSize = (long) event.getValue("profiledSize");
71         long nonProfiledSize = (long) event.getValue("nonProfiledSize");
72         long expansionSize = (long) event.getValue("expansionSize");
73         long minBlockLength = (long) event.getValue("minBlockLength");
74         long startAddress = (long) event.getValue("startAddress");
75         long reservedTopAddress = (long) event.getValue("reservedTopAddress");
76 
77         Asserts.assertGT(initialSize, 1024L,
78             "initialSize less than 1024 byte, got " + initialSize);
79 
80         Asserts.assertEQ(reservedSize, CodeCacheExpectedSize,
81             String.format("Unexpected reservedSize value. Expected %d but " + "got %d", CodeCacheExpectedSize, reservedSize));
82 
83         Asserts.assertLTE(nonNMethodSize, CodeCacheExpectedSize,
84             String.format("Unexpected nonNMethodSize value. Expected <= %d but " + "got %d", CodeCacheExpectedSize, nonNMethodSize));
85 
86         Asserts.assertLTE(profiledSize, CodeCacheExpectedSize,
87             String.format("Unexpected profiledSize value. Expected <= %d but " + "got %d", CodeCacheExpectedSize, profiledSize));
88 
89         Asserts.assertLTE(nonProfiledSize, CodeCacheExpectedSize,
90             String.format("Unexpected nonProfiledSize value. Expected <= %d but " + "got %d", CodeCacheExpectedSize, nonProfiledSize));
91 
92         Asserts.assertGTE(expansionSize, 1024L,
93             "expansionSize less than 1024 " + "bytes, got " + expansionSize);
94 
95         Asserts.assertGTE(minBlockLength, 1L,
96             "minBlockLength less than 1 byte, got " + minBlockLength);
97 
98         Asserts.assertNE(startAddress, 0L,
99             "startAddress null");
100 
101         Asserts.assertNE(reservedTopAddress, 0L,
102             "codeCacheReservedTopAddr null");
103     }
104 }
105