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