Mercurial > hg > truffle
comparison graal/com.oracle.graal.java/src/com/oracle/graal/java/IntrinsicContext.java @ 20901:c4691265275a
made ReplacementContext and IntrinsicContext top level classes
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 10 Apr 2015 13:21:33 +0200 |
parents | |
children | a0b348543802 |
comparison
equal
deleted
inserted
replaced
20884:dc41766b35e1 | 20901:c4691265275a |
---|---|
1 /* | |
2 * Copyright (c) 2015, 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 com.oracle.graal.java; | |
24 | |
25 import static com.oracle.graal.java.HIRFrameStateBuilder.*; | |
26 | |
27 import java.util.*; | |
28 | |
29 import com.oracle.graal.api.code.*; | |
30 import com.oracle.graal.api.meta.*; | |
31 import com.oracle.graal.java.GraphBuilderPhase.Instance.*; | |
32 import com.oracle.graal.nodes.*; | |
33 import com.oracle.graal.nodes.java.*; | |
34 | |
35 /** | |
36 * Context for a replacement being inlined as a compiler intrinsic. Deoptimization within a compiler | |
37 * intrinsic must replay the intrinsified call. This context object retains the information required | |
38 * to build a frame state denoting the JVM state just before the intrinsified call. | |
39 */ | |
40 public class IntrinsicContext extends ReplacementContext { | |
41 | |
42 /** | |
43 * BCI denoting an intrinsic is being parsed for inlining after the caller has been parsed. | |
44 */ | |
45 public static final int POST_PARSE_INLINE_BCI = -1; | |
46 | |
47 /** | |
48 * BCI denoting an intrinsic is the compilation root. | |
49 */ | |
50 public static final int ROOT_COMPILATION_BCI = -2; | |
51 | |
52 /** | |
53 * The arguments to the intrinsic. | |
54 */ | |
55 ValueNode[] args; | |
56 | |
57 /** | |
58 * The BCI of the intrinsified invocation, {@link #POST_PARSE_INLINE_BCI} or | |
59 * {@link #ROOT_COMPILATION_BCI}. | |
60 */ | |
61 final int bci; | |
62 | |
63 private FrameState stateBeforeCache; | |
64 | |
65 public IntrinsicContext(ResolvedJavaMethod method, ResolvedJavaMethod substitute, ValueNode[] args, int bci) { | |
66 super(method, substitute); | |
67 assert bci != POST_PARSE_INLINE_BCI || args == null; | |
68 this.args = args; | |
69 this.bci = bci; | |
70 assert !isCompilationRoot() || method.hasBytecodes() : "Cannot intrinsic for native or abstract method " + method.format("%H.%n(%p)"); | |
71 } | |
72 | |
73 @Override | |
74 public boolean isIntrinsic() { | |
75 return true; | |
76 } | |
77 | |
78 public boolean isPostParseInlined() { | |
79 return bci == POST_PARSE_INLINE_BCI; | |
80 } | |
81 | |
82 public boolean isCompilationRoot() { | |
83 return bci == ROOT_COMPILATION_BCI; | |
84 } | |
85 | |
86 public FrameState getInvokeStateBefore(StructuredGraph graph, BytecodeParser parent) { | |
87 if (isCompilationRoot()) { | |
88 int maxLocals = method.getMaxLocals(); | |
89 // The 'args' were initialized based on the intrinsic method but a | |
90 // frame state's 'locals' needs to have the same length as the frame | |
91 // state method's 'max_locals'. | |
92 ValueNode[] locals = maxLocals == args.length ? args : Arrays.copyOf(args, maxLocals); | |
93 ValueNode[] stack = EMPTY_ARRAY; | |
94 int stackSize = 0; | |
95 ValueNode[] locks = EMPTY_ARRAY; | |
96 List<MonitorIdNode> monitorIds = Collections.emptyList(); | |
97 return graph.add(new FrameState(null, method, 0, locals, stack, stackSize, locks, monitorIds, false, false)); | |
98 } else if (isPostParseInlined()) { | |
99 return graph.add(new FrameState(BytecodeFrame.BEFORE_BCI)); | |
100 } else { | |
101 assert !parent.parsingReplacement() || parent.replacementContext instanceof IntrinsicContext; | |
102 if (stateBeforeCache == null) { | |
103 assert stateBeforeCache == null; | |
104 | |
105 // Find the non-intrinsic ancestor calling the intrinsified method | |
106 BytecodeParser ancestor = parent; | |
107 while (ancestor.parsingReplacement()) { | |
108 assert ancestor.replacementContext instanceof IntrinsicContext; | |
109 ancestor = ancestor.getParent(); | |
110 } | |
111 FrameState stateDuring = ancestor.getFrameState().create(ancestor.bci(), ancestor.getParent(), true); | |
112 stateBeforeCache = stateDuring.duplicateModifiedBeforeCall(bci, Kind.Void, args); | |
113 } | |
114 return stateBeforeCache; | |
115 } | |
116 } | |
117 | |
118 @Override | |
119 IntrinsicContext asIntrinsic() { | |
120 return this; | |
121 } | |
122 | |
123 @Override | |
124 public String toString() { | |
125 return "Intrinsic{original: " + method.format("%H.%n(%p)") + ", replacement: " + replacement.format("%H.%n(%p)") + ", bci: " + bci + (args == null ? "" : ", args: " + Arrays.toString(args)) + | |
126 (stateBeforeCache == null ? "" : ", stateBefore: " + stateBeforeCache) + "}"; | |
127 } | |
128 } |