1 /* 2 * Copyright (c) 2015, 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 package jdk.jfr.event.runtime; 26 27 import static jdk.test.lib.Asserts.assertTrue; 28 29 import java.nio.file.Paths; 30 import java.time.Duration; 31 32 import jdk.jfr.Recording; 33 import jdk.jfr.consumer.RecordedEvent; 34 import jdk.test.lib.jfr.EventNames; 35 import jdk.test.lib.jfr.Events; 36 37 /* 38 * @test 39 * @bug 8058552 40 * @requires vm.gc == "G1" | vm.gc == null 41 * @key jfr 42 * @summary Test checks that flags of type size_t are being sent to the jfr 43 * @library /test/lib 44 * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:-UseFastUnorderedTimeStamps -XX:+UseG1GC -XX:+UseTLAB -XX:MinTLABSize=3k -XX:OldSize=30m -XX:YoungPLABSize=3k -XX:MaxDirectMemorySize=5M jdk.jfr.event.runtime.TestSizeTFlags 45 */ 46 public class TestSizeTFlags { 47 private static final String EVENT_NAME = EventNames.UnsignedLongFlag; 48 private static final int NUMBER_OF_FLAGS_TO_CHECK = 4; 49 private static final long MIN_TLAB_SIZE_FLAG_VALUE = 3*1024L; 50 private static final long OLD_SIZE_FLAG_VALUE = 30*1024*1024L; 51 private static final long YOUNG_PLAB_SIZE_FLAG_VALUE = 3*1024L; 52 private static final long MAX_DIRECT_MEMORY_SIZE_FLAG_VALUE = 5*1024*1024L; 53 54 // Test run java with some of the flags of type size_t. 55 // Goals are 56 // - to check that flags are reported to the jfr; 57 // - to make sure values are as expected. 58 public static void main(String[] args) throws Exception { 59 final boolean[] flagsFoundWithExpectedValue = new boolean[NUMBER_OF_FLAGS_TO_CHECK]; 60 Recording recording = null; 61 try { 62 recording = new Recording(); 63 recording.enable(EVENT_NAME).withThreshold(Duration.ofMillis(0)); 64 recording.start(); 65 recording.stop(); 66 67 for (final RecordedEvent event : Events.fromRecording(recording)) { 68 final String recordedFlagName = Events.assertField(event, "name").getValue(); 69 final long value = Events.assertField(event, "value").getValue(); 70 switch (recordedFlagName) { 71 case "MinTLABSize": { 72 flagsFoundWithExpectedValue[0] = MIN_TLAB_SIZE_FLAG_VALUE == value; 73 continue; 74 } 75 case "OldSize": { 76 flagsFoundWithExpectedValue[1] = OLD_SIZE_FLAG_VALUE == value; 77 continue; 78 } 79 case "YoungPLABSize": { 80 flagsFoundWithExpectedValue[2] = YOUNG_PLAB_SIZE_FLAG_VALUE == value; 81 continue; 82 } 83 case "MaxDirectMemorySize": { 84 flagsFoundWithExpectedValue[3] = MAX_DIRECT_MEMORY_SIZE_FLAG_VALUE == value; 85 continue; 86 } 87 default: { 88 continue; 89 } 90 } 91 } 92 93 for (int i = 0; i < flagsFoundWithExpectedValue.length; ++i) { 94 assertTrue(flagsFoundWithExpectedValue[i], "Flag not found or value error!"); 95 } 96 97 } catch (Throwable e) { 98 if (recording != null) { 99 recording.dump(Paths.get("failed.jfr")); 100 } 101 throw e; 102 } finally { 103 if (recording != null) { 104 recording.close(); 105 } 106 } 107 } 108 }