Path: blob/master/test/jdk/jdk/jfr/event/oldobject/TestSanityDefault.java
42873 views
/*1* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package jdk.jfr.event.oldobject;2425import java.util.ArrayList;26import java.util.List;2728import jdk.jfr.Recording;29import jdk.jfr.consumer.RecordedEvent;30import jdk.test.lib.jfr.EventNames;31import jdk.test.lib.jfr.Events;3233/**34* @test35* @key jfr36* @requires vm.hasJFR37* @library /test/lib /test/jdk38* @summary Purpose of this test is to run leak profiler without command line tweaks or WhiteBox hacks until we succeed39* @run main/othervm jdk.jfr.event.oldobject.TestSanityDefault40*/41public class TestSanityDefault {4243static private class FindMe {44}4546public static List<FindMe> list = new ArrayList<>(OldObjects.MIN_SIZE);4748public static void main(String[] args) throws Exception {49// Should not use WhiteBox API, we want to execute actual code paths5051// Trigger c2 compilation, so we get sample52for (long i = 0; i < 100_000_000; i++) {53allocateFindMe(true);54}555657// It's hard to get samples with interpreter / C1 so loop until we do58while (true) {59try (Recording r = new Recording()) {60r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");61r.start();62allocateFindMe(false);63System.gc();64r.stop();65List<RecordedEvent> events = Events.fromRecording(r);66if (OldObjects.countMatchingEvents(events, FindMe.class, null, null, -1, "allocateFindMe") > 0) {67return;68}69// no events found, retry70}71}72}7374public static void allocateFindMe(boolean doNothing) {75if (doNothing) {76return;77}78for (int i = 0; i < OldObjects.MIN_SIZE; i++) {79// Purposely don't allocate array, so we at least80// in one old-object test check an ordinary object.81list.add(new FindMe());82}83}84}858687