Path: blob/master/test/jdk/jdk/jfr/startupargs/TestRetransformUsingLog.java
41893 views
/*1* Copyright (c) 2016, 2021, 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.startupargs;2425import java.util.ArrayList;26import java.util.List;27import java.util.function.Consumer;2829import jdk.test.lib.jfr.EventNames;30import jdk.test.lib.jfr.SimpleEvent;31import jdk.test.lib.process.OutputAnalyzer;32import jdk.test.lib.process.ProcessTools;3334/**35* @test36* @key jfr37* @requires vm.hasJFR38* @library /test/lib39* @run main/othervm jdk.jfr.startupargs.TestRetransformUsingLog40*/41public class TestRetransformUsingLog {4243private static final String FILE_READ_FORCED_CLASS_LOAD = "Adding forced instrumentation for event type " + EventNames.FileRead + " during initial class load";44private static final String SIMPLE_EVENT_FORCED_CLASS_LOAD = "Adding forced instrumentation for event type jdk.test.lib.jfr.SimpleEvent during initial class load";45private static final String SIMPLE_EVENT_UNFORCED_CLASS_LOAD = "Adding instrumentation for event type jdk.test.lib.jfr.SimpleEvent during initial class load";4647public static class TestApp {48public static void main(String[] args) throws Exception {49SimpleEvent event = new SimpleEvent();50event.commit();51}52}5354public static void main(String[] args) throws Exception {55testRecordingRetransFormFalse();56testRecordingRetransFormTrue();57testNoRecordingRetransFormFalse();58testNoRecordingRetransFormTrue();59}6061private static void testRecordingRetransFormFalse() throws Exception {62startApp(true, false, out -> {63out.shouldContain(FILE_READ_FORCED_CLASS_LOAD);64out.shouldContain(SIMPLE_EVENT_FORCED_CLASS_LOAD);65});66}6768private static void testRecordingRetransFormTrue() throws Exception {69startApp(true, true, out -> {70out.shouldContain(FILE_READ_FORCED_CLASS_LOAD);71out.shouldContain(SIMPLE_EVENT_UNFORCED_CLASS_LOAD);72});73}7475private static void testNoRecordingRetransFormFalse() throws Exception {76startApp(false, false, out -> {77out.shouldNotContain(FILE_READ_FORCED_CLASS_LOAD);78out.shouldContain(SIMPLE_EVENT_FORCED_CLASS_LOAD);79});80}8182private static void testNoRecordingRetransFormTrue() throws Exception {83startApp(false, true, out -> {84out.shouldNotContain(FILE_READ_FORCED_CLASS_LOAD);85out.shouldNotContain(SIMPLE_EVENT_FORCED_CLASS_LOAD);86out.shouldNotContain(SIMPLE_EVENT_UNFORCED_CLASS_LOAD);87});88}8990private static void startApp(boolean recording, boolean retransform, Consumer<OutputAnalyzer> verifier) throws Exception {91List<String> args = new ArrayList<>();92args.add("-Xlog:jfr+system");93args.add("-XX:FlightRecorderOptions:retransform=" + retransform);94if (recording) {95args.add("-XX:StartFlightRecording");96}97args.add(TestApp.class.getName());98System.out.println();99System.out.println("Starting test app:");100System.out.print("java ");101for (String arg : args) {102System.out.print(arg + " ");103}104System.out.println();105System.out.println();106ProcessBuilder pb = ProcessTools.createTestJvm(args);107OutputAnalyzer out = ProcessTools.executeProcess(pb);108System.out.println(out.getOutput());109verifier.accept(out);110}111}112113114