1 /* 2 * Copyright (c) 2016, 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.api.consumer; 26 27 import static jdk.test.lib.Asserts.assertEquals; 28 import static jdk.test.lib.Asserts.assertFalse; 29 import static jdk.test.lib.Asserts.assertNotNull; 30 import static jdk.test.lib.Asserts.assertTrue; 31 32 import java.util.List; 33 34 import jdk.jfr.Event; 35 import jdk.jfr.Recording; 36 import jdk.jfr.consumer.RecordedEvent; 37 import jdk.jfr.consumer.RecordedFrame; 38 import jdk.jfr.consumer.RecordedMethod; 39 import jdk.jfr.consumer.RecordedStackTrace; 40 import jdk.test.lib.jfr.Events; 41 42 43 /** 44 * @test 45 * @summary Verifies that the method descriptor is correct 46 * @key jfr 47 * @requires vm.hasJFR 48 * @library /test/lib 49 * @run main/othervm jdk.jfr.api.consumer.TestRecordedMethodDescriptor 50 */ 51 public final class TestRecordedMethodDescriptor { 52 53 public static class MyEvent extends Event { 54 } 55 56 private static final String MAIN_METHOD_DESCRIPTOR = "([Ljava/lang/String;)V"; 57 private static final String MAIN_METHOD_NAME = "main"; 58 main(String[] args)59 public static void main(String[] args) throws Exception { 60 try (Recording recording = new Recording()) { 61 recording.enable(MyEvent.class); 62 recording.start(); 63 64 MyEvent event = new MyEvent(); 65 event.commit(); 66 recording.stop(); 67 68 List<RecordedEvent> recordedEvents = Events.fromRecording(recording); 69 assertEquals(1, recordedEvents.size(), "Expected one event"); 70 RecordedEvent recordedEvent = recordedEvents.get(0); 71 72 RecordedStackTrace stacktrace = recordedEvent.getStackTrace(); 73 List<RecordedFrame> frames = stacktrace.getFrames(); 74 assertFalse(frames.isEmpty(), "Stacktrace frames was empty"); 75 76 boolean foundMainMethod = false; 77 for (RecordedFrame frame : frames) { 78 RecordedMethod method = frame.getMethod(); 79 String descr = method.getDescriptor(); 80 assertNotNull(descr, "Method descriptor is null"); 81 String name = method.getName(); 82 assertNotNull(name, "Method name is null"); 83 if (name.equals(MAIN_METHOD_NAME) && descr.equals(MAIN_METHOD_DESCRIPTOR)) { 84 assertFalse(foundMainMethod, "main() method descriptor already recorded"); 85 foundMainMethod = true; 86 } 87 } 88 assertTrue(foundMainMethod, "main() method descriptor has never been recorded"); 89 } 90 } 91 } 92