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 26 package jdk.jfr.consumer; 27 28 import java.lang.reflect.Modifier; 29 import java.util.List; 30 31 import jdk.jfr.ValueDescriptor; 32 import jdk.jfr.internal.Type; 33 34 /** 35 * A recorded frame in a stack trace. 36 * 37 * @since 9 38 */ 39 public final class RecordedFrame extends RecordedObject { 40 41 static ObjectFactory<RecordedFrame> createFactory(Type type, TimeConverter timeConverter) { 42 return new ObjectFactory<RecordedFrame>(type) { 43 @Override 44 RecordedFrame createTyped(List<ValueDescriptor> desc, long id, Object[] object) { 45 return new RecordedFrame(desc, object, timeConverter); 46 } 47 }; 48 } 49 50 // package private 51 RecordedFrame(List<ValueDescriptor> desc, Object[] objects, TimeConverter timeConverter) { 52 super(desc, objects, timeConverter); 53 } 54 55 /** 56 * Returns {@code true} if this is a Java frame, {@code false} otherwise. 57 * <p> 58 * A Java method that has a native modifier is considered a Java frame. 59 * 60 * @return {@code true} if this is a Java frame, {@code false} otherwise 61 * 62 * @see Modifier#isNative(int) 63 */ 64 public boolean isJavaFrame() { 65 // Only Java frames exist today, but this allows 66 // API to be extended for native frame in the future. 67 if (hasField("javaFrame")) { 68 return getTyped("javaFrame", Boolean.class, Boolean.TRUE); 69 } 70 return true; 71 } 72 73 /** 74 * Returns the bytecode index for the execution point that is represented by 75 * this recorded frame. 76 * 77 * @return byte code index, or {@code -1} if not available 78 */ 79 public int getBytecodeIndex() { 80 return getTyped("bytecodeIndex", Integer.class, Integer.valueOf(-1)); 81 } 82 83 /** 84 * Returns the line number for the execution point that is represented by this 85 * recorded frame, or {@code -1} if not available. 86 * 87 * @return the line number, or {@code -1} if not available 88 */ 89 public int getLineNumber() { 90 return getTyped("lineNumber", Integer.class, Integer.valueOf(-1)); 91 } 92 93 /** 94 * Returns the frame type for the execution point that is represented by this 95 * recorded frame (for example, {@code "Interpreted"}, {@code "JIT compiled"} or 96 * {@code "Inlined"}). 97 * 98 * @return the frame type, or {@code null} if not available 99 */ 100 public String getType() { 101 return getTyped("type", String.class, null); 102 } 103 104 /** 105 * Returns the method for the execution point that is represented by this 106 * recorded frame. 107 * 108 * @return the method, not {@code null} 109 */ 110 public RecordedMethod getMethod() { 111 return getTyped("method", RecordedMethod.class, null); 112 } 113 }