1 /*
   2  * Copyright (c) 2016, 2019, 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, or {@code null} if this method
  56      * doesn't belong to a Java frame.
  57      *
  58      * @return the class, or {@code null} if this method doesn't belong
  59      *         to a Java frame.
  60      *
  61      * @see RecordedFrame#isJavaFrame()
  62      */
  63     public RecordedClass getType() {
  64         return getTyped("type", RecordedClass.class, null);
  65     }
  66 
  67     /**
  68      * Returns the name of this method, for example {@code "toString"}.
  69      * <p>
  70      * If this method doesn't belong to a Java frame the result is undefined.
  71      *
  72      * @return method name, or {@code null} not available
  73      *
  74      * @see RecordedFrame#isJavaFrame()
  75      */
  76     public String getName() {
  77         return getTyped("name", String.class, null);
  78     }
  79 
  80     /**
  81      * Returns the method descriptor for this method (for example,
  82      * {@code "(Ljava/lang/String;)V"}).
  83      * <p>
  84      * See Java Virtual Machine Specification, 4.3
  85      * <p>
  86      * If this method doesn't belong to a Java frame then the the result is undefined.
  87      *
  88      * @return method descriptor.
  89      *
  90      * @see RecordedFrame#isJavaFrame()
  91      */
  92     public String getDescriptor() {
  93         return getTyped("descriptor", String.class, null);
  94     }
  95 
  96     /**
  97      * Returns the modifiers for this method.
  98      * <p>
  99      * If this method doesn't belong to a Java frame, then the result is undefined.
 100      *
 101      * @return the modifiers
 102      *
 103      * @see Modifier
 104      * @see RecordedFrame#isJavaFrame
 105      */
 106     public int getModifiers() {
 107         return getTyped("modifiers", Integer.class, Integer.valueOf(0));
 108     }
 109 
 110     /**
 111      * Returns whether this method is hidden (for example, wrapper code in a lambda
 112      * expressions).
 113      *
 114      * @return {@code true} if method is hidden, {@code false} otherwise
 115      */
 116     public boolean isHidden() {
 117         return getTyped("hidden", Boolean.class, Boolean.FALSE);
 118     }
 119 }