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 method.
  36  *
  37  * @since 9
  38  */
  39 public final class RecordedMethod extends RecordedObject {
  40 
  41     static ObjectFactory<RecordedMethod> createFactory(Type type, TimeConverter timeConverter) {
  42         return new ObjectFactory<RecordedMethod>(type) {
  43             @Override
  44             RecordedMethod createTyped(List<ValueDescriptor> desc, long id, Object[] object) {
  45                 return new RecordedMethod(desc, object, timeConverter);
  46             }
  47         };
  48     }
  49 
  50     private RecordedMethod(List<ValueDescriptor> descriptors, Object[] objects, TimeConverter timeConverter) {
  51         super(descriptors, objects, timeConverter);
  52     }
  53 
  54     /**
  55      * Returns the class this method belongs to, if it belong to a Java frame.
  56      * <p>
  57      * To ensure this is a Java frame, use the {@link RecordedFrame#isJavaFrame()}
  58      * method.
  59      *
  60      * @return the class, may be {@code null} if not a Java frame
  61      *
  62      * @see RecordedFrame#isJavaFrame()
  63      */
  64     public RecordedClass getType() {
  65         return getTyped("type", RecordedClass.class, null);
  66     }
  67 
  68     /**
  69      * Returns the name of this method, for example {@code "toString"}.
  70      * <p>
  71      * If this method doesn't belong to a Java frame the result is undefined.
  72      *
  73      * @return method name, or {@code null} if doesn't exist
  74      *
  75      * @see RecordedFrame#isJavaFrame()
  76      */
  77     public String getName() {
  78         return getTyped("name", String.class, null);
  79     }
  80 
  81     /**
  82      * Returns the method descriptor for this method (for example,
  83      * {@code "(Ljava/lang/String;)V"}).
  84      * <p>
  85      * See Java Virtual Machine Specification, 4.3
  86      * <p>
  87      * If this method doesn't belong to a Java frame then the the result is undefined.
  88      *
  89      * @return method descriptor.
  90      *
  91      * @see RecordedFrame#isJavaFrame()
  92      */
  93     public String getDescriptor() {
  94         return getTyped("descriptor", String.class, null);
  95     }
  96 
  97     /**
  98      * Returns the modifiers for this method.
  99      * <p>
 100      * If this method doesn't belong to a Java frame, then the result is undefined.
 101      *
 102      * @return the modifiers
 103      *
 104      * @see Modifier
 105      * @see RecordedFrame#isJavaFrame
 106      */
 107     public int getModifiers() {
 108         return getTyped("modifiers", Integer.class, Integer.valueOf(0));
 109     }
 110 
 111     /**
 112      * Returns whether this method is hidden (for example, wrapper code in a lambda
 113      * expressions).
 114      *
 115      * @return {@code true} if method is hidden, {@code false} otherwise
 116      */
 117     public boolean isHidden() {
 118         return getTyped("hidden", Boolean.class, Boolean.FALSE);
 119     }
 120 }