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 26 package jdk.jfr.startupargs; 27 28 import java.util.ArrayList; 29 import java.util.List; 30 31 import jdk.jfr.Recording; 32 import jdk.jfr.consumer.RecordedEvent; 33 import jdk.jfr.internal.test.WhiteBox; 34 import jdk.test.lib.jfr.EventNames; 35 import jdk.test.lib.jfr.Events; 36 37 /** 38 * @test 39 * @summary Test -XX:FlightRecorderOptions=old-object-queue-size 40 * 41 * 42 * @library /lib / 43 * @key jfr 44 * 45 * @run main/othervm -XX:TLABSize=2k -XX:-FastTLABRefill -XX:FlightRecorderOptions=old-object-queue-size=0 jdk.jfr.startupargs.TestOldObjectQueueSize off 46 * @run main/othervm -XX:TLABSize=2k -XX:+PrintGCDetails -XX:+PrintGC -XX:-FastTLABRefill -XX:FlightRecorderOptions=old-object-queue-size=10000 jdk.jfr.startupargs.TestOldObjectQueueSize many 47 * @run main/othervm -XX:TLABSize=2k -XX:+PrintGCDetails -XX:+PrintGC -XX:-FastTLABRefill -XX:FlightRecorderOptions=old-object-queue-size=1000000 jdk.jfr.startupargs.TestOldObjectQueueSize many 48 */ 49 public class TestOldObjectQueueSize { 50 51 private static final int OBJECT_COUNT = 10_000; 52 private static final int DEFAULT_OLD_OBJECT_QUEUE_SIZE = 256; 53 54 public final static List<Object> leak = new ArrayList<>(OBJECT_COUNT); 55 56 public static void main(String[] args) throws Exception { 57 WhiteBox.setWriteAllObjectSamples(true); 58 System.out.println("TESTING: " + args[0]); 59 60 String amount = args[0]; 61 try (Recording recording = new Recording()) { 62 recording.enable(EventNames.OldObjectSample).withoutStackTrace().with("cutoff", "infinity"); 63 recording.start(); 64 // It's hard to get a larger number of samples without running into OOM 65 // since the TLAB size increases when there is more allocation. 66 // Allocate 200 MB, which should give at least 400 samples if the TLAB 67 // size manages to stay below 512kb, which logging with -Xlog:gc+tlab=trace indicates. 68 for (int i = 0; i < OBJECT_COUNT; i++) { 69 leak.add(new byte[20_000]); 70 } 71 recording.stop(); 72 List<RecordedEvent> events = Events.fromRecording(recording); 73 System.out.println("Found samples: " + events.size()); 74 if (amount.equals("off")) { 75 if (!events.isEmpty()) { 76 throw new Exception("No objects shuld be emitted when queue size 0"); 77 } 78 } 79 if (amount.equals("many")) { 80 // Sanity check that we at least have managed to set a value above the default 81 if (events.size() <= DEFAULT_OLD_OBJECT_QUEUE_SIZE) { 82 throw new Exception("Should be at least be " + DEFAULT_OLD_OBJECT_QUEUE_SIZE + ", but found " + events.size()); 83 } 84 } 85 } 86 } 87 }