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