1 /*
2  * Copyright (c) 2013, 2014, 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 
24 
25 package org.graalvm.compiler.phases.common.inlining.info;
26 
27 import jdk.internal.vm.compiler.collections.EconomicSet;
28 import org.graalvm.compiler.graph.Node;
29 import org.graalvm.compiler.nodes.Invoke;
30 import org.graalvm.compiler.phases.common.inlining.info.elem.Inlineable;
31 import org.graalvm.compiler.phases.util.Providers;
32 
33 import jdk.vm.ci.meta.ResolvedJavaMethod;
34 
35 /**
36  * Represents an inlining opportunity where the compiler can statically determine a monomorphic
37  * target method and therefore is able to determine the called method exactly.
38  */
39 public class ExactInlineInfo extends AbstractInlineInfo {
40 
41     protected final ResolvedJavaMethod concrete;
42     private Inlineable inlineableElement;
43     private boolean suppressNullCheck;
44 
ExactInlineInfo(Invoke invoke, ResolvedJavaMethod concrete)45     public ExactInlineInfo(Invoke invoke, ResolvedJavaMethod concrete) {
46         super(invoke);
47         this.concrete = concrete;
48         assert concrete != null;
49     }
50 
suppressNullCheck()51     public void suppressNullCheck() {
52         suppressNullCheck = true;
53     }
54 
55     @Override
inline(Providers providers, String reason)56     public EconomicSet<Node> inline(Providers providers, String reason) {
57         return inline(invoke, concrete, inlineableElement, !suppressNullCheck, reason);
58     }
59 
60     @Override
tryToDevirtualizeInvoke(Providers providers)61     public void tryToDevirtualizeInvoke(Providers providers) {
62         // nothing todo, can already be bound statically
63     }
64 
65     @Override
numberOfMethods()66     public int numberOfMethods() {
67         return 1;
68     }
69 
70     @Override
methodAt(int index)71     public ResolvedJavaMethod methodAt(int index) {
72         assert index == 0;
73         return concrete;
74     }
75 
76     @Override
probabilityAt(int index)77     public double probabilityAt(int index) {
78         assert index == 0;
79         return 1.0;
80     }
81 
82     @Override
relevanceAt(int index)83     public double relevanceAt(int index) {
84         assert index == 0;
85         return 1.0;
86     }
87 
88     @Override
toString()89     public String toString() {
90         return "exact " + concrete.format("%H.%n(%p):%r");
91     }
92 
93     @Override
inlineableElementAt(int index)94     public Inlineable inlineableElementAt(int index) {
95         assert index == 0;
96         return inlineableElement;
97     }
98 
99     @Override
setInlinableElement(int index, Inlineable inlineableElement)100     public void setInlinableElement(int index, Inlineable inlineableElement) {
101         assert index == 0;
102         this.inlineableElement = inlineableElement;
103     }
104 
105     @Override
shouldInline()106     public boolean shouldInline() {
107         return concrete.shouldBeInlined();
108     }
109 }
110