hotspot/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug/src/org/graalvm/compiler/debug/internal/method/MethodMetricsRootScopeInfo.java
changeset 46640 70bdce04c59b
parent 46638 3c5c50af29a7
child 46641 f64dc604ef8d
equal deleted inserted replaced
46638:3c5c50af29a7 46640:70bdce04c59b
     1 /*
       
     2  * Copyright (c) 2015, 2016, 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.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 package org.graalvm.compiler.debug.internal.method;
       
    24 
       
    25 import org.graalvm.compiler.debug.Debug;
       
    26 import org.graalvm.compiler.debug.internal.DebugScope;
       
    27 import org.graalvm.compiler.debug.internal.DebugScope.ExtraInfo;
       
    28 
       
    29 import jdk.vm.ci.meta.ResolvedJavaMethod;
       
    30 
       
    31 public class MethodMetricsRootScopeInfo implements ExtraInfo {
       
    32     protected final ResolvedJavaMethod rootMethod;
       
    33 
       
    34     MethodMetricsRootScopeInfo(ResolvedJavaMethod rootMethod) {
       
    35         this.rootMethod = rootMethod;
       
    36     }
       
    37 
       
    38     public ResolvedJavaMethod getRootMethod() {
       
    39         return rootMethod;
       
    40     }
       
    41 
       
    42     public static MethodMetricsRootScopeInfo create(ResolvedJavaMethod rootMethod) {
       
    43         return new MethodMetricsRootScopeInfo(rootMethod);
       
    44     }
       
    45 
       
    46     /**
       
    47      * Creates and returns a {@link org.graalvm.compiler.debug.Debug.Scope scope} iff there is no
       
    48      * existing {@linkplain org.graalvm.compiler.debug.internal.DebugScope.ExtraInfo extraInfo}
       
    49      * object of type {@link MethodMetricsRootScopeInfo} present in the current {@link DebugScope
       
    50      * scope}.
       
    51      *
       
    52      * @param method
       
    53      * @return a new {@link org.graalvm.compiler.debug.Debug.Scope scope} or {@code null} iff there
       
    54      *         is already an existing one on the scope
       
    55      */
       
    56     public static Debug.Scope createRootScopeIfAbsent(ResolvedJavaMethod method) {
       
    57         if (Debug.isEnabled()) {
       
    58             /*
       
    59              * if the current compilation is not triggered from JVMCI we need a valid context root
       
    60              * method for method metrics
       
    61              */
       
    62             return DebugScope.getInstance().getExtraInfo() instanceof MethodMetricsRootScopeInfo ? null
       
    63                             : Debug.methodMetricsScope("GraalCompilerRoot", MethodMetricsRootScopeInfo.create(method), true);
       
    64         } else {
       
    65             return null;
       
    66         }
       
    67     }
       
    68 
       
    69 }