Path: blob/master/test/jdk/jdk/jfr/api/consumer/TestRecordedMethodDescriptor.java
42332 views
/*1* Copyright (c) 2016, 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*/22package jdk.jfr.api.consumer;2324import static jdk.test.lib.Asserts.assertEquals;25import static jdk.test.lib.Asserts.assertFalse;26import static jdk.test.lib.Asserts.assertNotNull;27import static jdk.test.lib.Asserts.assertTrue;2829import java.util.List;3031import jdk.jfr.Event;32import jdk.jfr.Recording;33import jdk.jfr.consumer.RecordedEvent;34import jdk.jfr.consumer.RecordedFrame;35import jdk.jfr.consumer.RecordedMethod;36import jdk.jfr.consumer.RecordedStackTrace;37import jdk.test.lib.jfr.Events;383940/**41* @test42* @summary Verifies that the method descriptor is correct43* @key jfr44* @requires vm.hasJFR45* @library /test/lib46* @run main/othervm jdk.jfr.api.consumer.TestRecordedMethodDescriptor47*/48public final class TestRecordedMethodDescriptor {4950public static class MyEvent extends Event {51}5253private static final String MAIN_METHOD_DESCRIPTOR = "([Ljava/lang/String;)V";54private static final String MAIN_METHOD_NAME = "main";5556public static void main(String[] args) throws Exception {57try (Recording recording = new Recording()) {58recording.enable(MyEvent.class);59recording.start();6061MyEvent event = new MyEvent();62event.commit();63recording.stop();6465List<RecordedEvent> recordedEvents = Events.fromRecording(recording);66assertEquals(1, recordedEvents.size(), "Expected one event");67RecordedEvent recordedEvent = recordedEvents.get(0);6869RecordedStackTrace stacktrace = recordedEvent.getStackTrace();70List<RecordedFrame> frames = stacktrace.getFrames();71assertFalse(frames.isEmpty(), "Stacktrace frames was empty");7273boolean foundMainMethod = false;74for (RecordedFrame frame : frames) {75RecordedMethod method = frame.getMethod();76String descr = method.getDescriptor();77assertNotNull(descr, "Method descriptor is null");78String name = method.getName();79assertNotNull(name, "Method name is null");80if (name.equals(MAIN_METHOD_NAME) && descr.equals(MAIN_METHOD_DESCRIPTOR)) {81assertFalse(foundMainMethod, "main() method descriptor already recorded");82foundMainMethod = true;83}84}85assertTrue(foundMainMethod, "main() method descriptor has never been recorded");86}87}88}899091