author | jwilhelm |
Thu, 27 Jun 2019 03:33:44 +0200 | |
changeset 55509 | d58442b8abc1 |
parent 54601 | c40b2a190173 |
child 55621 | ea3b1a8fd4bb |
permissions | -rw-r--r-- |
43972 | 1 |
/* |
53425
312880c38a7f
8215375: [Graal] jck:vm/jvmti/Exception/excp001/excp00101 fails in Graal as JIT mode and -Xcomp mode
dnsimon
parents:
53033
diff
changeset
|
2 |
* Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved. |
43972 | 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 |
*/ |
|
50858 | 23 |
|
24 |
||
43972 | 25 |
package org.graalvm.compiler.java; |
26 |
||
46344 | 27 |
import static java.lang.String.format; |
28 |
import static java.lang.reflect.Modifier.STATIC; |
|
29 |
import static java.lang.reflect.Modifier.SYNCHRONIZED; |
|
54601 | 30 |
import static jdk.vm.ci.code.BytecodeFrame.UNKNOWN_BCI; |
46344 | 31 |
import static jdk.vm.ci.meta.DeoptimizationAction.InvalidateRecompile; |
32 |
import static jdk.vm.ci.meta.DeoptimizationAction.InvalidateReprofile; |
|
46640 | 33 |
import static jdk.vm.ci.meta.DeoptimizationAction.None; |
34 |
import static jdk.vm.ci.meta.DeoptimizationReason.ClassCastException; |
|
46344 | 35 |
import static jdk.vm.ci.meta.DeoptimizationReason.JavaSubroutineMismatch; |
36 |
import static jdk.vm.ci.meta.DeoptimizationReason.NullCheckException; |
|
37 |
import static jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint; |
|
38 |
import static jdk.vm.ci.meta.DeoptimizationReason.UnreachedCode; |
|
39 |
import static jdk.vm.ci.meta.DeoptimizationReason.Unresolved; |
|
40 |
import static jdk.vm.ci.runtime.JVMCICompiler.INVOCATION_ENTRY_BCI; |
|
54084 | 41 |
import static jdk.vm.ci.services.Services.IS_BUILDING_NATIVE_IMAGE; |
43972 | 42 |
import static org.graalvm.compiler.bytecode.Bytecodes.AALOAD; |
43 |
import static org.graalvm.compiler.bytecode.Bytecodes.AASTORE; |
|
44 |
import static org.graalvm.compiler.bytecode.Bytecodes.ACONST_NULL; |
|
45 |
import static org.graalvm.compiler.bytecode.Bytecodes.ALOAD; |
|
46 |
import static org.graalvm.compiler.bytecode.Bytecodes.ALOAD_0; |
|
47 |
import static org.graalvm.compiler.bytecode.Bytecodes.ALOAD_1; |
|
48 |
import static org.graalvm.compiler.bytecode.Bytecodes.ALOAD_2; |
|
49 |
import static org.graalvm.compiler.bytecode.Bytecodes.ALOAD_3; |
|
50 |
import static org.graalvm.compiler.bytecode.Bytecodes.ANEWARRAY; |
|
51 |
import static org.graalvm.compiler.bytecode.Bytecodes.ARETURN; |
|
52 |
import static org.graalvm.compiler.bytecode.Bytecodes.ARRAYLENGTH; |
|
53 |
import static org.graalvm.compiler.bytecode.Bytecodes.ASTORE; |
|
54 |
import static org.graalvm.compiler.bytecode.Bytecodes.ASTORE_0; |
|
55 |
import static org.graalvm.compiler.bytecode.Bytecodes.ASTORE_1; |
|
56 |
import static org.graalvm.compiler.bytecode.Bytecodes.ASTORE_2; |
|
57 |
import static org.graalvm.compiler.bytecode.Bytecodes.ASTORE_3; |
|
58 |
import static org.graalvm.compiler.bytecode.Bytecodes.ATHROW; |
|
59 |
import static org.graalvm.compiler.bytecode.Bytecodes.BALOAD; |
|
60 |
import static org.graalvm.compiler.bytecode.Bytecodes.BASTORE; |
|
61 |
import static org.graalvm.compiler.bytecode.Bytecodes.BIPUSH; |
|
62 |
import static org.graalvm.compiler.bytecode.Bytecodes.BREAKPOINT; |
|
63 |
import static org.graalvm.compiler.bytecode.Bytecodes.CALOAD; |
|
64 |
import static org.graalvm.compiler.bytecode.Bytecodes.CASTORE; |
|
65 |
import static org.graalvm.compiler.bytecode.Bytecodes.CHECKCAST; |
|
66 |
import static org.graalvm.compiler.bytecode.Bytecodes.D2F; |
|
67 |
import static org.graalvm.compiler.bytecode.Bytecodes.D2I; |
|
68 |
import static org.graalvm.compiler.bytecode.Bytecodes.D2L; |
|
69 |
import static org.graalvm.compiler.bytecode.Bytecodes.DADD; |
|
70 |
import static org.graalvm.compiler.bytecode.Bytecodes.DALOAD; |
|
71 |
import static org.graalvm.compiler.bytecode.Bytecodes.DASTORE; |
|
72 |
import static org.graalvm.compiler.bytecode.Bytecodes.DCMPG; |
|
73 |
import static org.graalvm.compiler.bytecode.Bytecodes.DCMPL; |
|
74 |
import static org.graalvm.compiler.bytecode.Bytecodes.DCONST_0; |
|
75 |
import static org.graalvm.compiler.bytecode.Bytecodes.DCONST_1; |
|
76 |
import static org.graalvm.compiler.bytecode.Bytecodes.DDIV; |
|
77 |
import static org.graalvm.compiler.bytecode.Bytecodes.DLOAD; |
|
78 |
import static org.graalvm.compiler.bytecode.Bytecodes.DLOAD_0; |
|
79 |
import static org.graalvm.compiler.bytecode.Bytecodes.DLOAD_1; |
|
80 |
import static org.graalvm.compiler.bytecode.Bytecodes.DLOAD_2; |
|
81 |
import static org.graalvm.compiler.bytecode.Bytecodes.DLOAD_3; |
|
82 |
import static org.graalvm.compiler.bytecode.Bytecodes.DMUL; |
|
83 |
import static org.graalvm.compiler.bytecode.Bytecodes.DNEG; |
|
84 |
import static org.graalvm.compiler.bytecode.Bytecodes.DREM; |
|
85 |
import static org.graalvm.compiler.bytecode.Bytecodes.DRETURN; |
|
86 |
import static org.graalvm.compiler.bytecode.Bytecodes.DSTORE; |
|
87 |
import static org.graalvm.compiler.bytecode.Bytecodes.DSTORE_0; |
|
88 |
import static org.graalvm.compiler.bytecode.Bytecodes.DSTORE_1; |
|
89 |
import static org.graalvm.compiler.bytecode.Bytecodes.DSTORE_2; |
|
90 |
import static org.graalvm.compiler.bytecode.Bytecodes.DSTORE_3; |
|
91 |
import static org.graalvm.compiler.bytecode.Bytecodes.DSUB; |
|
92 |
import static org.graalvm.compiler.bytecode.Bytecodes.DUP; |
|
93 |
import static org.graalvm.compiler.bytecode.Bytecodes.DUP2; |
|
94 |
import static org.graalvm.compiler.bytecode.Bytecodes.DUP2_X1; |
|
95 |
import static org.graalvm.compiler.bytecode.Bytecodes.DUP2_X2; |
|
96 |
import static org.graalvm.compiler.bytecode.Bytecodes.DUP_X1; |
|
97 |
import static org.graalvm.compiler.bytecode.Bytecodes.DUP_X2; |
|
98 |
import static org.graalvm.compiler.bytecode.Bytecodes.F2D; |
|
99 |
import static org.graalvm.compiler.bytecode.Bytecodes.F2I; |
|
100 |
import static org.graalvm.compiler.bytecode.Bytecodes.F2L; |
|
101 |
import static org.graalvm.compiler.bytecode.Bytecodes.FADD; |
|
102 |
import static org.graalvm.compiler.bytecode.Bytecodes.FALOAD; |
|
103 |
import static org.graalvm.compiler.bytecode.Bytecodes.FASTORE; |
|
104 |
import static org.graalvm.compiler.bytecode.Bytecodes.FCMPG; |
|
105 |
import static org.graalvm.compiler.bytecode.Bytecodes.FCMPL; |
|
106 |
import static org.graalvm.compiler.bytecode.Bytecodes.FCONST_0; |
|
107 |
import static org.graalvm.compiler.bytecode.Bytecodes.FCONST_1; |
|
108 |
import static org.graalvm.compiler.bytecode.Bytecodes.FCONST_2; |
|
109 |
import static org.graalvm.compiler.bytecode.Bytecodes.FDIV; |
|
110 |
import static org.graalvm.compiler.bytecode.Bytecodes.FLOAD; |
|
111 |
import static org.graalvm.compiler.bytecode.Bytecodes.FLOAD_0; |
|
112 |
import static org.graalvm.compiler.bytecode.Bytecodes.FLOAD_1; |
|
113 |
import static org.graalvm.compiler.bytecode.Bytecodes.FLOAD_2; |
|
114 |
import static org.graalvm.compiler.bytecode.Bytecodes.FLOAD_3; |
|
115 |
import static org.graalvm.compiler.bytecode.Bytecodes.FMUL; |
|
116 |
import static org.graalvm.compiler.bytecode.Bytecodes.FNEG; |
|
117 |
import static org.graalvm.compiler.bytecode.Bytecodes.FREM; |
|
118 |
import static org.graalvm.compiler.bytecode.Bytecodes.FRETURN; |
|
119 |
import static org.graalvm.compiler.bytecode.Bytecodes.FSTORE; |
|
120 |
import static org.graalvm.compiler.bytecode.Bytecodes.FSTORE_0; |
|
121 |
import static org.graalvm.compiler.bytecode.Bytecodes.FSTORE_1; |
|
122 |
import static org.graalvm.compiler.bytecode.Bytecodes.FSTORE_2; |
|
123 |
import static org.graalvm.compiler.bytecode.Bytecodes.FSTORE_3; |
|
124 |
import static org.graalvm.compiler.bytecode.Bytecodes.FSUB; |
|
125 |
import static org.graalvm.compiler.bytecode.Bytecodes.GETFIELD; |
|
126 |
import static org.graalvm.compiler.bytecode.Bytecodes.GETSTATIC; |
|
127 |
import static org.graalvm.compiler.bytecode.Bytecodes.GOTO; |
|
128 |
import static org.graalvm.compiler.bytecode.Bytecodes.GOTO_W; |
|
129 |
import static org.graalvm.compiler.bytecode.Bytecodes.I2B; |
|
130 |
import static org.graalvm.compiler.bytecode.Bytecodes.I2C; |
|
131 |
import static org.graalvm.compiler.bytecode.Bytecodes.I2D; |
|
132 |
import static org.graalvm.compiler.bytecode.Bytecodes.I2F; |
|
133 |
import static org.graalvm.compiler.bytecode.Bytecodes.I2L; |
|
134 |
import static org.graalvm.compiler.bytecode.Bytecodes.I2S; |
|
135 |
import static org.graalvm.compiler.bytecode.Bytecodes.IADD; |
|
136 |
import static org.graalvm.compiler.bytecode.Bytecodes.IALOAD; |
|
137 |
import static org.graalvm.compiler.bytecode.Bytecodes.IAND; |
|
138 |
import static org.graalvm.compiler.bytecode.Bytecodes.IASTORE; |
|
139 |
import static org.graalvm.compiler.bytecode.Bytecodes.ICONST_0; |
|
140 |
import static org.graalvm.compiler.bytecode.Bytecodes.ICONST_1; |
|
141 |
import static org.graalvm.compiler.bytecode.Bytecodes.ICONST_2; |
|
142 |
import static org.graalvm.compiler.bytecode.Bytecodes.ICONST_3; |
|
143 |
import static org.graalvm.compiler.bytecode.Bytecodes.ICONST_4; |
|
144 |
import static org.graalvm.compiler.bytecode.Bytecodes.ICONST_5; |
|
145 |
import static org.graalvm.compiler.bytecode.Bytecodes.ICONST_M1; |
|
146 |
import static org.graalvm.compiler.bytecode.Bytecodes.IDIV; |
|
147 |
import static org.graalvm.compiler.bytecode.Bytecodes.IFEQ; |
|
148 |
import static org.graalvm.compiler.bytecode.Bytecodes.IFGE; |
|
149 |
import static org.graalvm.compiler.bytecode.Bytecodes.IFGT; |
|
150 |
import static org.graalvm.compiler.bytecode.Bytecodes.IFLE; |
|
151 |
import static org.graalvm.compiler.bytecode.Bytecodes.IFLT; |
|
152 |
import static org.graalvm.compiler.bytecode.Bytecodes.IFNE; |
|
153 |
import static org.graalvm.compiler.bytecode.Bytecodes.IFNONNULL; |
|
154 |
import static org.graalvm.compiler.bytecode.Bytecodes.IFNULL; |
|
155 |
import static org.graalvm.compiler.bytecode.Bytecodes.IF_ACMPEQ; |
|
156 |
import static org.graalvm.compiler.bytecode.Bytecodes.IF_ACMPNE; |
|
157 |
import static org.graalvm.compiler.bytecode.Bytecodes.IF_ICMPEQ; |
|
158 |
import static org.graalvm.compiler.bytecode.Bytecodes.IF_ICMPGE; |
|
159 |
import static org.graalvm.compiler.bytecode.Bytecodes.IF_ICMPGT; |
|
160 |
import static org.graalvm.compiler.bytecode.Bytecodes.IF_ICMPLE; |
|
161 |
import static org.graalvm.compiler.bytecode.Bytecodes.IF_ICMPLT; |
|
162 |
import static org.graalvm.compiler.bytecode.Bytecodes.IF_ICMPNE; |
|
163 |
import static org.graalvm.compiler.bytecode.Bytecodes.IINC; |
|
164 |
import static org.graalvm.compiler.bytecode.Bytecodes.ILOAD; |
|
165 |
import static org.graalvm.compiler.bytecode.Bytecodes.ILOAD_0; |
|
166 |
import static org.graalvm.compiler.bytecode.Bytecodes.ILOAD_1; |
|
167 |
import static org.graalvm.compiler.bytecode.Bytecodes.ILOAD_2; |
|
168 |
import static org.graalvm.compiler.bytecode.Bytecodes.ILOAD_3; |
|
169 |
import static org.graalvm.compiler.bytecode.Bytecodes.IMUL; |
|
170 |
import static org.graalvm.compiler.bytecode.Bytecodes.INEG; |
|
171 |
import static org.graalvm.compiler.bytecode.Bytecodes.INSTANCEOF; |
|
172 |
import static org.graalvm.compiler.bytecode.Bytecodes.INVOKEDYNAMIC; |
|
173 |
import static org.graalvm.compiler.bytecode.Bytecodes.INVOKEINTERFACE; |
|
174 |
import static org.graalvm.compiler.bytecode.Bytecodes.INVOKESPECIAL; |
|
175 |
import static org.graalvm.compiler.bytecode.Bytecodes.INVOKESTATIC; |
|
176 |
import static org.graalvm.compiler.bytecode.Bytecodes.INVOKEVIRTUAL; |
|
177 |
import static org.graalvm.compiler.bytecode.Bytecodes.IOR; |
|
178 |
import static org.graalvm.compiler.bytecode.Bytecodes.IREM; |
|
179 |
import static org.graalvm.compiler.bytecode.Bytecodes.IRETURN; |
|
180 |
import static org.graalvm.compiler.bytecode.Bytecodes.ISHL; |
|
181 |
import static org.graalvm.compiler.bytecode.Bytecodes.ISHR; |
|
182 |
import static org.graalvm.compiler.bytecode.Bytecodes.ISTORE; |
|
183 |
import static org.graalvm.compiler.bytecode.Bytecodes.ISTORE_0; |
|
184 |
import static org.graalvm.compiler.bytecode.Bytecodes.ISTORE_1; |
|
185 |
import static org.graalvm.compiler.bytecode.Bytecodes.ISTORE_2; |
|
186 |
import static org.graalvm.compiler.bytecode.Bytecodes.ISTORE_3; |
|
187 |
import static org.graalvm.compiler.bytecode.Bytecodes.ISUB; |
|
188 |
import static org.graalvm.compiler.bytecode.Bytecodes.IUSHR; |
|
189 |
import static org.graalvm.compiler.bytecode.Bytecodes.IXOR; |
|
190 |
import static org.graalvm.compiler.bytecode.Bytecodes.JSR; |
|
191 |
import static org.graalvm.compiler.bytecode.Bytecodes.JSR_W; |
|
192 |
import static org.graalvm.compiler.bytecode.Bytecodes.L2D; |
|
193 |
import static org.graalvm.compiler.bytecode.Bytecodes.L2F; |
|
194 |
import static org.graalvm.compiler.bytecode.Bytecodes.L2I; |
|
195 |
import static org.graalvm.compiler.bytecode.Bytecodes.LADD; |
|
196 |
import static org.graalvm.compiler.bytecode.Bytecodes.LALOAD; |
|
197 |
import static org.graalvm.compiler.bytecode.Bytecodes.LAND; |
|
198 |
import static org.graalvm.compiler.bytecode.Bytecodes.LASTORE; |
|
199 |
import static org.graalvm.compiler.bytecode.Bytecodes.LCMP; |
|
200 |
import static org.graalvm.compiler.bytecode.Bytecodes.LCONST_0; |
|
201 |
import static org.graalvm.compiler.bytecode.Bytecodes.LCONST_1; |
|
202 |
import static org.graalvm.compiler.bytecode.Bytecodes.LDC; |
|
203 |
import static org.graalvm.compiler.bytecode.Bytecodes.LDC2_W; |
|
204 |
import static org.graalvm.compiler.bytecode.Bytecodes.LDC_W; |
|
205 |
import static org.graalvm.compiler.bytecode.Bytecodes.LDIV; |
|
206 |
import static org.graalvm.compiler.bytecode.Bytecodes.LLOAD; |
|
207 |
import static org.graalvm.compiler.bytecode.Bytecodes.LLOAD_0; |
|
208 |
import static org.graalvm.compiler.bytecode.Bytecodes.LLOAD_1; |
|
209 |
import static org.graalvm.compiler.bytecode.Bytecodes.LLOAD_2; |
|
210 |
import static org.graalvm.compiler.bytecode.Bytecodes.LLOAD_3; |
|
211 |
import static org.graalvm.compiler.bytecode.Bytecodes.LMUL; |
|
212 |
import static org.graalvm.compiler.bytecode.Bytecodes.LNEG; |
|
213 |
import static org.graalvm.compiler.bytecode.Bytecodes.LOOKUPSWITCH; |
|
214 |
import static org.graalvm.compiler.bytecode.Bytecodes.LOR; |
|
215 |
import static org.graalvm.compiler.bytecode.Bytecodes.LREM; |
|
216 |
import static org.graalvm.compiler.bytecode.Bytecodes.LRETURN; |
|
217 |
import static org.graalvm.compiler.bytecode.Bytecodes.LSHL; |
|
218 |
import static org.graalvm.compiler.bytecode.Bytecodes.LSHR; |
|
219 |
import static org.graalvm.compiler.bytecode.Bytecodes.LSTORE; |
|
220 |
import static org.graalvm.compiler.bytecode.Bytecodes.LSTORE_0; |
|
221 |
import static org.graalvm.compiler.bytecode.Bytecodes.LSTORE_1; |
|
222 |
import static org.graalvm.compiler.bytecode.Bytecodes.LSTORE_2; |
|
223 |
import static org.graalvm.compiler.bytecode.Bytecodes.LSTORE_3; |
|
224 |
import static org.graalvm.compiler.bytecode.Bytecodes.LSUB; |
|
225 |
import static org.graalvm.compiler.bytecode.Bytecodes.LUSHR; |
|
226 |
import static org.graalvm.compiler.bytecode.Bytecodes.LXOR; |
|
227 |
import static org.graalvm.compiler.bytecode.Bytecodes.MONITORENTER; |
|
228 |
import static org.graalvm.compiler.bytecode.Bytecodes.MONITOREXIT; |
|
229 |
import static org.graalvm.compiler.bytecode.Bytecodes.MULTIANEWARRAY; |
|
230 |
import static org.graalvm.compiler.bytecode.Bytecodes.NEW; |
|
231 |
import static org.graalvm.compiler.bytecode.Bytecodes.NEWARRAY; |
|
232 |
import static org.graalvm.compiler.bytecode.Bytecodes.NOP; |
|
233 |
import static org.graalvm.compiler.bytecode.Bytecodes.POP; |
|
234 |
import static org.graalvm.compiler.bytecode.Bytecodes.POP2; |
|
235 |
import static org.graalvm.compiler.bytecode.Bytecodes.PUTFIELD; |
|
236 |
import static org.graalvm.compiler.bytecode.Bytecodes.PUTSTATIC; |
|
237 |
import static org.graalvm.compiler.bytecode.Bytecodes.RET; |
|
238 |
import static org.graalvm.compiler.bytecode.Bytecodes.RETURN; |
|
239 |
import static org.graalvm.compiler.bytecode.Bytecodes.SALOAD; |
|
240 |
import static org.graalvm.compiler.bytecode.Bytecodes.SASTORE; |
|
241 |
import static org.graalvm.compiler.bytecode.Bytecodes.SIPUSH; |
|
242 |
import static org.graalvm.compiler.bytecode.Bytecodes.SWAP; |
|
243 |
import static org.graalvm.compiler.bytecode.Bytecodes.TABLESWITCH; |
|
244 |
import static org.graalvm.compiler.bytecode.Bytecodes.nameOf; |
|
245 |
import static org.graalvm.compiler.core.common.GraalOptions.DeoptALot; |
|
246 |
import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC; |
|
46344 | 247 |
import static org.graalvm.compiler.core.common.GraalOptions.HotSpotPrintInlining; |
43972 | 248 |
import static org.graalvm.compiler.core.common.GraalOptions.PrintProfilingInformation; |
46344 | 249 |
import static org.graalvm.compiler.core.common.GraalOptions.StressExplicitExceptionCode; |
43972 | 250 |
import static org.graalvm.compiler.core.common.GraalOptions.StressInvokeWithExceptionNode; |
251 |
import static org.graalvm.compiler.core.common.type.StampFactory.objectNonNull; |
|
252 |
import static org.graalvm.compiler.debug.GraalError.guarantee; |
|
253 |
import static org.graalvm.compiler.debug.GraalError.shouldNotReachHere; |
|
46509 | 254 |
import static org.graalvm.compiler.java.BytecodeParserOptions.InlinePartialIntrinsicExitDuringParsing; |
46344 | 255 |
import static org.graalvm.compiler.java.BytecodeParserOptions.TraceBytecodeParserLevel; |
43972 | 256 |
import static org.graalvm.compiler.java.BytecodeParserOptions.TraceInlineDuringParsing; |
257 |
import static org.graalvm.compiler.java.BytecodeParserOptions.TraceParserPlugins; |
|
50858 | 258 |
import static org.graalvm.compiler.nodes.extended.BranchProbabilityNode.LUDICROUSLY_FAST_PATH_PROBABILITY; |
259 |
import static org.graalvm.compiler.nodes.extended.BranchProbabilityNode.LUDICROUSLY_SLOW_PATH_PROBABILITY; |
|
43972 | 260 |
import static org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext.CompilationContext.INLINE_DURING_PARSING; |
261 |
import static org.graalvm.compiler.nodes.type.StampTool.isPointerNonNull; |
|
46344 | 262 |
|
43972 | 263 |
import java.util.ArrayList; |
264 |
import java.util.Collections; |
|
265 |
import java.util.Comparator; |
|
266 |
import java.util.Formatter; |
|
267 |
import java.util.List; |
|
52910 | 268 |
import java.util.function.Supplier; |
43972 | 269 |
|
49873 | 270 |
import jdk.internal.vm.compiler.collections.EconomicMap; |
271 |
import jdk.internal.vm.compiler.collections.Equivalence; |
|
54601 | 272 |
import jdk.internal.vm.compiler.collections.UnmodifiableEconomicMap; |
54084 | 273 |
import org.graalvm.compiler.api.replacements.Fold; |
46509 | 274 |
import org.graalvm.compiler.api.replacements.Snippet; |
43972 | 275 |
import org.graalvm.compiler.bytecode.Bytecode; |
276 |
import org.graalvm.compiler.bytecode.BytecodeDisassembler; |
|
277 |
import org.graalvm.compiler.bytecode.BytecodeLookupSwitch; |
|
278 |
import org.graalvm.compiler.bytecode.BytecodeProvider; |
|
279 |
import org.graalvm.compiler.bytecode.BytecodeStream; |
|
280 |
import org.graalvm.compiler.bytecode.BytecodeSwitch; |
|
281 |
import org.graalvm.compiler.bytecode.BytecodeTableSwitch; |
|
282 |
import org.graalvm.compiler.bytecode.Bytecodes; |
|
46344 | 283 |
import org.graalvm.compiler.bytecode.Bytes; |
43972 | 284 |
import org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode; |
285 |
import org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecodeProvider; |
|
49451 | 286 |
import org.graalvm.compiler.core.common.GraalOptions; |
46344 | 287 |
import org.graalvm.compiler.core.common.PermanentBailoutException; |
55509 | 288 |
import org.graalvm.compiler.core.common.RetryableBailoutException; |
48861 | 289 |
import org.graalvm.compiler.core.common.calc.CanonicalCondition; |
43972 | 290 |
import org.graalvm.compiler.core.common.calc.Condition; |
48861 | 291 |
import org.graalvm.compiler.core.common.calc.Condition.CanonicalizedCondition; |
43972 | 292 |
import org.graalvm.compiler.core.common.calc.FloatConvert; |
293 |
import org.graalvm.compiler.core.common.spi.ConstantFieldProvider; |
|
48861 | 294 |
import org.graalvm.compiler.core.common.type.IntegerStamp; |
43972 | 295 |
import org.graalvm.compiler.core.common.type.ObjectStamp; |
296 |
import org.graalvm.compiler.core.common.type.Stamp; |
|
297 |
import org.graalvm.compiler.core.common.type.StampFactory; |
|
298 |
import org.graalvm.compiler.core.common.type.StampPair; |
|
299 |
import org.graalvm.compiler.core.common.type.TypeReference; |
|
300 |
import org.graalvm.compiler.core.common.util.Util; |
|
46344 | 301 |
import org.graalvm.compiler.debug.Assertions; |
46640 | 302 |
import org.graalvm.compiler.debug.CounterKey; |
43972 | 303 |
import org.graalvm.compiler.debug.DebugCloseable; |
46640 | 304 |
import org.graalvm.compiler.debug.DebugContext; |
49873 | 305 |
import org.graalvm.compiler.debug.DebugOptions; |
43972 | 306 |
import org.graalvm.compiler.debug.GraalError; |
307 |
import org.graalvm.compiler.debug.Indent; |
|
49873 | 308 |
import org.graalvm.compiler.debug.MethodFilter; |
43972 | 309 |
import org.graalvm.compiler.debug.TTY; |
310 |
import org.graalvm.compiler.graph.Graph.Mark; |
|
311 |
import org.graalvm.compiler.graph.Node; |
|
312 |
import org.graalvm.compiler.graph.NodeSourcePosition; |
|
313 |
import org.graalvm.compiler.graph.iterators.NodeIterable; |
|
314 |
import org.graalvm.compiler.java.BciBlockMapping.BciBlock; |
|
315 |
import org.graalvm.compiler.java.BciBlockMapping.ExceptionDispatchBlock; |
|
316 |
import org.graalvm.compiler.nodes.AbstractBeginNode; |
|
317 |
import org.graalvm.compiler.nodes.AbstractMergeNode; |
|
318 |
import org.graalvm.compiler.nodes.BeginNode; |
|
319 |
import org.graalvm.compiler.nodes.BeginStateSplitNode; |
|
320 |
import org.graalvm.compiler.nodes.CallTargetNode; |
|
321 |
import org.graalvm.compiler.nodes.CallTargetNode.InvokeKind; |
|
322 |
import org.graalvm.compiler.nodes.ConstantNode; |
|
323 |
import org.graalvm.compiler.nodes.ControlSplitNode; |
|
324 |
import org.graalvm.compiler.nodes.DeoptimizeNode; |
|
325 |
import org.graalvm.compiler.nodes.EndNode; |
|
326 |
import org.graalvm.compiler.nodes.EntryMarkerNode; |
|
327 |
import org.graalvm.compiler.nodes.EntryProxyNode; |
|
328 |
import org.graalvm.compiler.nodes.FieldLocationIdentity; |
|
329 |
import org.graalvm.compiler.nodes.FixedGuardNode; |
|
330 |
import org.graalvm.compiler.nodes.FixedNode; |
|
331 |
import org.graalvm.compiler.nodes.FixedWithNextNode; |
|
332 |
import org.graalvm.compiler.nodes.FrameState; |
|
333 |
import org.graalvm.compiler.nodes.FullInfopointNode; |
|
334 |
import org.graalvm.compiler.nodes.IfNode; |
|
49873 | 335 |
import org.graalvm.compiler.nodes.InliningLog; |
43972 | 336 |
import org.graalvm.compiler.nodes.Invoke; |
337 |
import org.graalvm.compiler.nodes.InvokeNode; |
|
338 |
import org.graalvm.compiler.nodes.InvokeWithExceptionNode; |
|
339 |
import org.graalvm.compiler.nodes.KillingBeginNode; |
|
340 |
import org.graalvm.compiler.nodes.LogicConstantNode; |
|
341 |
import org.graalvm.compiler.nodes.LogicNegationNode; |
|
342 |
import org.graalvm.compiler.nodes.LogicNode; |
|
343 |
import org.graalvm.compiler.nodes.LoopBeginNode; |
|
344 |
import org.graalvm.compiler.nodes.LoopEndNode; |
|
345 |
import org.graalvm.compiler.nodes.LoopExitNode; |
|
346 |
import org.graalvm.compiler.nodes.MergeNode; |
|
48190 | 347 |
import org.graalvm.compiler.nodes.NodeView; |
43972 | 348 |
import org.graalvm.compiler.nodes.ParameterNode; |
349 |
import org.graalvm.compiler.nodes.PiNode; |
|
350 |
import org.graalvm.compiler.nodes.ReturnNode; |
|
351 |
import org.graalvm.compiler.nodes.StartNode; |
|
352 |
import org.graalvm.compiler.nodes.StateSplit; |
|
353 |
import org.graalvm.compiler.nodes.StructuredGraph; |
|
354 |
import org.graalvm.compiler.nodes.UnwindNode; |
|
355 |
import org.graalvm.compiler.nodes.ValueNode; |
|
55509 | 356 |
import org.graalvm.compiler.nodes.ValuePhiNode; |
43972 | 357 |
import org.graalvm.compiler.nodes.calc.AddNode; |
358 |
import org.graalvm.compiler.nodes.calc.AndNode; |
|
359 |
import org.graalvm.compiler.nodes.calc.CompareNode; |
|
360 |
import org.graalvm.compiler.nodes.calc.ConditionalNode; |
|
48861 | 361 |
import org.graalvm.compiler.nodes.calc.FloatConvertNode; |
47798 | 362 |
import org.graalvm.compiler.nodes.calc.FloatDivNode; |
43972 | 363 |
import org.graalvm.compiler.nodes.calc.IntegerBelowNode; |
364 |
import org.graalvm.compiler.nodes.calc.IntegerEqualsNode; |
|
365 |
import org.graalvm.compiler.nodes.calc.IntegerLessThanNode; |
|
366 |
import org.graalvm.compiler.nodes.calc.IsNullNode; |
|
367 |
import org.graalvm.compiler.nodes.calc.LeftShiftNode; |
|
368 |
import org.graalvm.compiler.nodes.calc.MulNode; |
|
369 |
import org.graalvm.compiler.nodes.calc.NarrowNode; |
|
370 |
import org.graalvm.compiler.nodes.calc.NegateNode; |
|
371 |
import org.graalvm.compiler.nodes.calc.NormalizeCompareNode; |
|
372 |
import org.graalvm.compiler.nodes.calc.ObjectEqualsNode; |
|
373 |
import org.graalvm.compiler.nodes.calc.OrNode; |
|
374 |
import org.graalvm.compiler.nodes.calc.RemNode; |
|
375 |
import org.graalvm.compiler.nodes.calc.RightShiftNode; |
|
376 |
import org.graalvm.compiler.nodes.calc.SignExtendNode; |
|
377 |
import org.graalvm.compiler.nodes.calc.SignedDivNode; |
|
378 |
import org.graalvm.compiler.nodes.calc.SignedRemNode; |
|
379 |
import org.graalvm.compiler.nodes.calc.SubNode; |
|
380 |
import org.graalvm.compiler.nodes.calc.UnsignedRightShiftNode; |
|
381 |
import org.graalvm.compiler.nodes.calc.XorNode; |
|
382 |
import org.graalvm.compiler.nodes.calc.ZeroExtendNode; |
|
383 |
import org.graalvm.compiler.nodes.extended.AnchoringNode; |
|
46680 | 384 |
import org.graalvm.compiler.nodes.extended.BranchProbabilityNode; |
43972 | 385 |
import org.graalvm.compiler.nodes.extended.BytecodeExceptionNode; |
50330 | 386 |
import org.graalvm.compiler.nodes.extended.BytecodeExceptionNode.BytecodeExceptionKind; |
54601 | 387 |
import org.graalvm.compiler.nodes.extended.ForeignCallNode; |
50330 | 388 |
import org.graalvm.compiler.nodes.extended.GuardingNode; |
43972 | 389 |
import org.graalvm.compiler.nodes.extended.IntegerSwitchNode; |
50330 | 390 |
import org.graalvm.compiler.nodes.extended.LoadArrayComponentHubNode; |
43972 | 391 |
import org.graalvm.compiler.nodes.extended.LoadHubNode; |
392 |
import org.graalvm.compiler.nodes.extended.MembarNode; |
|
46762 | 393 |
import org.graalvm.compiler.nodes.extended.StateSplitProxyNode; |
43972 | 394 |
import org.graalvm.compiler.nodes.extended.ValueAnchorNode; |
395 |
import org.graalvm.compiler.nodes.graphbuilderconf.ClassInitializationPlugin; |
|
396 |
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; |
|
397 |
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.BytecodeExceptionMode; |
|
398 |
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext; |
|
399 |
import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin; |
|
400 |
import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo; |
|
401 |
import org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext; |
|
402 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin; |
|
403 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.InvocationPluginReceiver; |
|
47798 | 404 |
import org.graalvm.compiler.nodes.graphbuilderconf.InvokeDynamicPlugin; |
43972 | 405 |
import org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin; |
406 |
import org.graalvm.compiler.nodes.graphbuilderconf.ProfilingPlugin; |
|
407 |
import org.graalvm.compiler.nodes.java.ArrayLengthNode; |
|
408 |
import org.graalvm.compiler.nodes.java.ExceptionObjectNode; |
|
409 |
import org.graalvm.compiler.nodes.java.FinalFieldBarrierNode; |
|
50330 | 410 |
import org.graalvm.compiler.nodes.java.InstanceOfDynamicNode; |
43972 | 411 |
import org.graalvm.compiler.nodes.java.InstanceOfNode; |
412 |
import org.graalvm.compiler.nodes.java.LoadFieldNode; |
|
413 |
import org.graalvm.compiler.nodes.java.LoadIndexedNode; |
|
414 |
import org.graalvm.compiler.nodes.java.MethodCallTargetNode; |
|
415 |
import org.graalvm.compiler.nodes.java.MonitorEnterNode; |
|
416 |
import org.graalvm.compiler.nodes.java.MonitorExitNode; |
|
417 |
import org.graalvm.compiler.nodes.java.MonitorIdNode; |
|
418 |
import org.graalvm.compiler.nodes.java.NewArrayNode; |
|
419 |
import org.graalvm.compiler.nodes.java.NewInstanceNode; |
|
420 |
import org.graalvm.compiler.nodes.java.NewMultiArrayNode; |
|
421 |
import org.graalvm.compiler.nodes.java.RegisterFinalizerNode; |
|
422 |
import org.graalvm.compiler.nodes.java.StoreFieldNode; |
|
423 |
import org.graalvm.compiler.nodes.java.StoreIndexedNode; |
|
54328 | 424 |
import org.graalvm.compiler.nodes.spi.CoreProviders; |
425 |
import org.graalvm.compiler.nodes.spi.Replacements; |
|
43972 | 426 |
import org.graalvm.compiler.nodes.spi.StampProvider; |
427 |
import org.graalvm.compiler.nodes.type.StampTool; |
|
428 |
import org.graalvm.compiler.nodes.util.GraphUtil; |
|
46344 | 429 |
import org.graalvm.compiler.options.OptionValues; |
43972 | 430 |
import org.graalvm.compiler.phases.OptimisticOptimizations; |
46393 | 431 |
import org.graalvm.compiler.phases.util.ValueMergeUtil; |
54084 | 432 |
import org.graalvm.compiler.serviceprovider.JavaVersionUtil; |
49873 | 433 |
import jdk.internal.vm.compiler.word.LocationIdentity; |
43972 | 434 |
|
435 |
import jdk.vm.ci.code.BailoutException; |
|
436 |
import jdk.vm.ci.code.BytecodeFrame; |
|
437 |
import jdk.vm.ci.code.CodeUtil; |
|
438 |
import jdk.vm.ci.code.site.InfopointReason; |
|
50330 | 439 |
import jdk.vm.ci.meta.Constant; |
43972 | 440 |
import jdk.vm.ci.meta.ConstantPool; |
441 |
import jdk.vm.ci.meta.ConstantReflectionProvider; |
|
442 |
import jdk.vm.ci.meta.DeoptimizationAction; |
|
443 |
import jdk.vm.ci.meta.DeoptimizationReason; |
|
444 |
import jdk.vm.ci.meta.JavaConstant; |
|
445 |
import jdk.vm.ci.meta.JavaField; |
|
446 |
import jdk.vm.ci.meta.JavaKind; |
|
447 |
import jdk.vm.ci.meta.JavaMethod; |
|
448 |
import jdk.vm.ci.meta.JavaType; |
|
449 |
import jdk.vm.ci.meta.JavaTypeProfile; |
|
450 |
import jdk.vm.ci.meta.LineNumberTable; |
|
451 |
import jdk.vm.ci.meta.MetaAccessProvider; |
|
452 |
import jdk.vm.ci.meta.ProfilingInfo; |
|
453 |
import jdk.vm.ci.meta.RawConstant; |
|
454 |
import jdk.vm.ci.meta.ResolvedJavaField; |
|
455 |
import jdk.vm.ci.meta.ResolvedJavaMethod; |
|
456 |
import jdk.vm.ci.meta.ResolvedJavaType; |
|
46459 | 457 |
import jdk.vm.ci.meta.Signature; |
43972 | 458 |
import jdk.vm.ci.meta.TriState; |
459 |
||
460 |
/** |
|
461 |
* The {@code GraphBuilder} class parses the bytecode of a method and builds the IR graph. |
|
462 |
*/ |
|
463 |
public class BytecodeParser implements GraphBuilderContext { |
|
464 |
||
465 |
/** |
|
466 |
* The minimum value to which {@link BytecodeParserOptions#TraceBytecodeParserLevel} must be set |
|
467 |
* to trace the bytecode instructions as they are parsed. |
|
468 |
*/ |
|
469 |
public static final int TRACELEVEL_INSTRUCTIONS = 1; |
|
470 |
||
471 |
/** |
|
472 |
* The minimum value to which {@link BytecodeParserOptions#TraceBytecodeParserLevel} must be set |
|
49873 | 473 |
* to emit the frame state for each traced bytecode instruction. |
43972 | 474 |
*/ |
475 |
public static final int TRACELEVEL_STATE = 2; |
|
476 |
||
477 |
/** |
|
49873 | 478 |
* The minimum value to which {@link BytecodeParserOptions#TraceBytecodeParserLevel} must be set |
479 |
* to emit the block map for each traced method. |
|
480 |
*/ |
|
481 |
public static final int TRACELEVEL_BLOCKMAP = 3; |
|
482 |
||
483 |
/** |
|
43972 | 484 |
* Meters the number of actual bytecodes parsed. |
485 |
*/ |
|
46640 | 486 |
public static final CounterKey BytecodesParsed = DebugContext.counter("BytecodesParsed"); |
487 |
||
488 |
protected static final CounterKey EXPLICIT_EXCEPTIONS = DebugContext.counter("ExplicitExceptions"); |
|
43972 | 489 |
|
490 |
/** |
|
54601 | 491 |
* A scoped object for tasks to be performed after inlining during parsing such as processing |
43972 | 492 |
* {@linkplain BytecodeFrame#isPlaceholderBci(int) placeholder} frames states. |
493 |
*/ |
|
54601 | 494 |
static class InliningScope implements AutoCloseable { |
495 |
final ResolvedJavaMethod callee; |
|
43972 | 496 |
FrameState stateBefore; |
497 |
final Mark mark; |
|
498 |
final BytecodeParser parser; |
|
46509 | 499 |
List<ReturnToCallerData> returnDataList; |
43972 | 500 |
|
501 |
/** |
|
502 |
* Creates a scope for root parsing an intrinsic. |
|
503 |
* |
|
504 |
* @param parser the parsing context of the intrinsic |
|
505 |
*/ |
|
54601 | 506 |
InliningScope(BytecodeParser parser) { |
43972 | 507 |
this.parser = parser; |
508 |
assert parser.parent == null; |
|
509 |
assert parser.bci() == 0; |
|
510 |
mark = null; |
|
54601 | 511 |
callee = null; |
43972 | 512 |
} |
513 |
||
514 |
/** |
|
54601 | 515 |
* Creates a scope for graph builder inlining. |
43972 | 516 |
* |
517 |
* @param parser the parsing context of the (non-intrinsic) method calling the intrinsic |
|
518 |
* @param args the arguments to the call |
|
519 |
*/ |
|
54601 | 520 |
InliningScope(BytecodeParser parser, ResolvedJavaMethod callee, ValueNode[] args) { |
521 |
this.callee = callee; |
|
43972 | 522 |
assert !parser.parsingIntrinsic(); |
523 |
this.parser = parser; |
|
524 |
mark = parser.getGraph().getMark(); |
|
54601 | 525 |
JavaKind[] argSlotKinds = callee.getSignature().toParameterKinds(!callee.isStatic()); |
43972 | 526 |
stateBefore = parser.frameState.create(parser.bci(), parser.getNonIntrinsicAncestor(), false, argSlotKinds, args); |
527 |
} |
|
528 |
||
529 |
@Override |
|
530 |
public void close() { |
|
54601 | 531 |
processPlaceholderFrameStates(false); |
43972 | 532 |
} |
533 |
||
534 |
/** |
|
535 |
* Fixes up the {@linkplain BytecodeFrame#isPlaceholderBci(int) placeholder} frame states |
|
536 |
* added to the graph while parsing/inlining the intrinsic for which this object exists. |
|
537 |
*/ |
|
54601 | 538 |
protected void processPlaceholderFrameStates(boolean isCompilationRoot) { |
43972 | 539 |
StructuredGraph graph = parser.getGraph(); |
46807 | 540 |
graph.getDebug().dump(DebugContext.DETAILED_LEVEL, graph, "Before processPlaceholderFrameStates in %s", parser.method); |
43972 | 541 |
for (Node node : graph.getNewNodes(mark)) { |
542 |
if (node instanceof FrameState) { |
|
543 |
FrameState frameState = (FrameState) node; |
|
544 |
if (BytecodeFrame.isPlaceholderBci(frameState.bci)) { |
|
545 |
if (frameState.bci == BytecodeFrame.AFTER_BCI) { |
|
46509 | 546 |
if (parser.getInvokeReturnType() == null) { |
547 |
// A frame state in a root compiled intrinsic. |
|
54601 | 548 |
assert isCompilationRoot; |
46509 | 549 |
FrameState newFrameState = graph.add(new FrameState(BytecodeFrame.INVALID_FRAMESTATE_BCI)); |
550 |
frameState.replaceAndDelete(newFrameState); |
|
551 |
} else { |
|
552 |
JavaKind returnKind = parser.getInvokeReturnType().getJavaKind(); |
|
553 |
FrameStateBuilder frameStateBuilder = parser.frameState; |
|
554 |
assert !frameState.rethrowException(); |
|
555 |
if (frameState.stackSize() != 0) { |
|
556 |
ValueNode returnVal = frameState.stackAt(0); |
|
557 |
if (!ReturnToCallerData.containsReturnValue(returnDataList, returnVal)) { |
|
54601 | 558 |
throw new GraalError("AFTER_BCI frame state within a sub-parse has a non-return value on the stack: %s", returnVal); |
46509 | 559 |
} |
560 |
||
561 |
// Swap the top-of-stack value with the return value |
|
43972 | 562 |
ValueNode tos = frameStateBuilder.pop(returnKind); |
563 |
assert tos.getStackKind() == returnVal.getStackKind(); |
|
564 |
FrameState newFrameState = frameStateBuilder.create(parser.stream.nextBCI(), parser.getNonIntrinsicAncestor(), false, new JavaKind[]{returnKind}, |
|
565 |
new ValueNode[]{returnVal}); |
|
566 |
frameState.replaceAndDelete(newFrameState); |
|
46509 | 567 |
newFrameState.setNodeSourcePosition(frameState.getNodeSourcePosition()); |
43972 | 568 |
frameStateBuilder.push(returnKind, tos); |
46509 | 569 |
} else if (returnKind != JavaKind.Void) { |
54601 | 570 |
handleReturnMismatch(graph, frameState); |
46509 | 571 |
} else { |
572 |
// An intrinsic for a void method. |
|
573 |
FrameState newFrameState = frameStateBuilder.create(parser.stream.nextBCI(), null); |
|
574 |
newFrameState.setNodeSourcePosition(frameState.getNodeSourcePosition()); |
|
575 |
frameState.replaceAndDelete(newFrameState); |
|
43972 | 576 |
} |
577 |
} |
|
578 |
} else if (frameState.bci == BytecodeFrame.BEFORE_BCI) { |
|
579 |
if (stateBefore == null) { |
|
580 |
stateBefore = graph.start().stateAfter(); |
|
581 |
} |
|
582 |
if (stateBefore != frameState) { |
|
583 |
frameState.replaceAndDelete(stateBefore); |
|
584 |
} |
|
54601 | 585 |
} else if (frameState.bci == BytecodeFrame.AFTER_EXCEPTION_BCI || (frameState.bci == BytecodeFrame.UNWIND_BCI && !callee.isSynchronized())) { |
46509 | 586 |
// This is a frame state for the entry point to an exception |
587 |
// dispatcher in an intrinsic. For example, the invoke denoting |
|
588 |
// a partial intrinsic exit will have an edge to such a |
|
589 |
// dispatcher if the profile for the original invoke being |
|
590 |
// intrinsified indicates an exception was seen. As per JVM |
|
591 |
// bytecode semantics, the interpreter expects a single |
|
592 |
// value on the stack on entry to an exception handler, |
|
593 |
// namely the exception object. |
|
594 |
assert frameState.rethrowException(); |
|
48861 | 595 |
ValueNode exceptionValue = frameState.stackAt(0); |
46509 | 596 |
FrameStateBuilder dispatchState = parser.frameState.copy(); |
597 |
dispatchState.clearStack(); |
|
48861 | 598 |
dispatchState.push(JavaKind.Object, exceptionValue); |
46509 | 599 |
dispatchState.setRethrowException(true); |
54601 | 600 |
for (Node usage : frameState.usages()) { |
601 |
FrameState newFrameState = dispatchState.create(parser.bci(), (StateSplit) usage); |
|
602 |
frameState.replaceAndDelete(newFrameState); |
|
603 |
newFrameState.setNodeSourcePosition(frameState.getNodeSourcePosition()); |
|
604 |
} |
|
605 |
} else if (frameState.bci == BytecodeFrame.UNWIND_BCI) { |
|
606 |
if (graph.getGuardsStage().allowsFloatingGuards()) { |
|
607 |
throw GraalError.shouldNotReachHere("Cannot handle this UNWIND_BCI"); |
|
608 |
} |
|
609 |
// hope that by construction, there are no fixed guard after this unwind |
|
610 |
// and before an other state split |
|
43972 | 611 |
} else { |
54601 | 612 |
assert frameState.bci == BytecodeFrame.INVALID_FRAMESTATE_BCI : frameState.bci; |
43972 | 613 |
} |
614 |
} |
|
615 |
} |
|
616 |
} |
|
54601 | 617 |
graph.getDebug().dump(DebugContext.DETAILED_LEVEL, graph, "After processPlaceholderFrameStates in %s", parser.method); |
618 |
} |
|
619 |
||
620 |
@SuppressWarnings("unused") |
|
621 |
protected void handleReturnMismatch(StructuredGraph g, FrameState fs) { |
|
622 |
throw GraalError.shouldNotReachHere("Unexpected return kind mismatch in " + parser.method + " at FS " + fs); |
|
623 |
} |
|
624 |
} |
|
625 |
||
626 |
static class IntrinsicScope extends InliningScope { |
|
55509 | 627 |
StateSplit returnStateSplit; |
628 |
ArrayList<StateSplit> invalidStateUsers; |
|
54601 | 629 |
|
630 |
IntrinsicScope(BytecodeParser parser) { |
|
631 |
super(parser); |
|
632 |
} |
|
633 |
||
634 |
IntrinsicScope(BytecodeParser parser, ResolvedJavaMethod callee, ValueNode[] args) { |
|
635 |
super(parser, callee, args); |
|
636 |
} |
|
637 |
||
638 |
@Override |
|
639 |
public void close() { |
|
640 |
IntrinsicContext intrinsic = parser.intrinsicContext; |
|
641 |
boolean isRootCompilation; |
|
642 |
if (intrinsic != null) { |
|
643 |
if (intrinsic.isPostParseInlined()) { |
|
644 |
return; |
|
645 |
} |
|
646 |
isRootCompilation = intrinsic.isCompilationRoot(); |
|
647 |
} else { |
|
648 |
isRootCompilation = false; |
|
649 |
} |
|
650 |
processPlaceholderFrameStates(isRootCompilation); |
|
55509 | 651 |
if (invalidStateUsers != null) { |
46807 | 652 |
JavaKind returnKind = parser.getInvokeReturnType().getJavaKind(); |
55509 | 653 |
ValueNode returnValue = parser.frameState.pop(returnKind); |
654 |
if (invalidStateUsers.size() == 1 && invalidStateUsers.get(0) == parser.lastInstr) { |
|
655 |
updateSplitFrameState(invalidStateUsers.get(0), returnKind, returnValue); |
|
656 |
} else if (parser.lastInstr instanceof MergeNode) { |
|
657 |
ValuePhiNode returnValues = null; |
|
658 |
MergeNode merge = (MergeNode) parser.lastInstr; |
|
659 |
||
660 |
if (returnValue instanceof ValuePhiNode && ((ValuePhiNode) returnValue).merge() == parser.lastInstr) { |
|
661 |
returnValues = (ValuePhiNode) returnValue; |
|
662 |
} |
|
663 |
if (invalidStateUsers.remove(merge)) { |
|
664 |
updateSplitFrameState(merge, returnKind, returnValue); |
|
665 |
} |
|
666 |
for (EndNode pred : merge.cfgPredecessors()) { |
|
667 |
Node lastPred = pred.predecessor(); |
|
668 |
if (invalidStateUsers.remove(lastPred)) { |
|
669 |
ValueNode predReturnValue = returnValue; |
|
670 |
if (returnValues != null) { |
|
671 |
int index = merge.phiPredecessorIndex(pred); |
|
672 |
predReturnValue = ((ValuePhiNode) returnValue).valueAt(index); |
|
673 |
} |
|
674 |
updateSplitFrameState((StateSplit) lastPred, returnKind, predReturnValue); |
|
675 |
} |
|
676 |
} |
|
677 |
if (invalidStateUsers.size() != 0) { |
|
678 |
throw new GraalError("unexpected StateSplit above merge %s", invalidStateUsers); |
|
679 |
} |
|
680 |
} else { |
|
681 |
throw new GraalError("unexpected node between return StateSplit and last instruction %s", parser.lastInstr); |
|
682 |
} |
|
683 |
// Restore the original return value |
|
684 |
parser.frameState.push(returnKind, returnValue); |
|
685 |
} |
|
686 |
} |
|
687 |
||
688 |
private void updateSplitFrameState(StateSplit split, JavaKind returnKind, ValueNode returnValue) { |
|
689 |
parser.frameState.push(returnKind, returnValue); |
|
690 |
FrameState oldState = split.stateAfter(); |
|
691 |
split.setStateAfter(parser.createFrameState(parser.stream.nextBCI(), split)); |
|
692 |
parser.frameState.pop(returnKind); |
|
693 |
if (oldState.hasNoUsages()) { |
|
694 |
oldState.safeDelete(); |
|
46807 | 695 |
} |
54601 | 696 |
} |
697 |
||
698 |
@Override |
|
699 |
protected void handleReturnMismatch(StructuredGraph g, FrameState fs) { |
|
55509 | 700 |
if (invalidStateUsers == null) { |
701 |
invalidStateUsers = new ArrayList<>(); |
|
702 |
} |
|
703 |
for (Node use : fs.usages()) { |
|
704 |
if (!(use instanceof StateSplit)) { |
|
705 |
throw new GraalError("Expected StateSplit for return mismatch"); |
|
706 |
} |
|
707 |
invalidStateUsers.add((StateSplit) use); |
|
708 |
} |
|
43972 | 709 |
} |
710 |
} |
|
711 |
||
712 |
private static class Target { |
|
54601 | 713 |
final FixedNode entry; |
714 |
final FixedNode originalEntry; |
|
715 |
final FrameStateBuilder state; |
|
716 |
||
717 |
Target(FixedNode entry, FrameStateBuilder state) { |
|
718 |
this.entry = entry; |
|
43972 | 719 |
this.state = state; |
54601 | 720 |
this.originalEntry = null; |
721 |
} |
|
722 |
||
723 |
Target(FixedNode entry, FrameStateBuilder state, FixedNode originalEntry) { |
|
724 |
this.entry = entry; |
|
725 |
this.state = state; |
|
726 |
this.originalEntry = originalEntry; |
|
43972 | 727 |
} |
728 |
} |
|
729 |
||
730 |
@SuppressWarnings("serial") |
|
731 |
public static class BytecodeParserError extends GraalError { |
|
732 |
||
733 |
public BytecodeParserError(Throwable cause) { |
|
734 |
super(cause); |
|
735 |
} |
|
736 |
||
737 |
public BytecodeParserError(String msg, Object... args) { |
|
738 |
super(msg, args); |
|
739 |
} |
|
740 |
} |
|
741 |
||
46393 | 742 |
protected static class ReturnToCallerData { |
743 |
protected final ValueNode returnValue; |
|
744 |
protected final FixedWithNextNode beforeReturnNode; |
|
745 |
||
746 |
protected ReturnToCallerData(ValueNode returnValue, FixedWithNextNode beforeReturnNode) { |
|
747 |
this.returnValue = returnValue; |
|
748 |
this.beforeReturnNode = beforeReturnNode; |
|
749 |
} |
|
46509 | 750 |
|
751 |
static boolean containsReturnValue(List<ReturnToCallerData> list, ValueNode value) { |
|
752 |
for (ReturnToCallerData e : list) { |
|
753 |
if (e.returnValue == value) { |
|
754 |
return true; |
|
755 |
} |
|
756 |
} |
|
757 |
return false; |
|
758 |
} |
|
46393 | 759 |
} |
760 |
||
43972 | 761 |
private final GraphBuilderPhase.Instance graphBuilderInstance; |
762 |
protected final StructuredGraph graph; |
|
46344 | 763 |
protected final OptionValues options; |
46640 | 764 |
protected final DebugContext debug; |
43972 | 765 |
|
766 |
private BciBlockMapping blockMap; |
|
767 |
private LocalLiveness liveness; |
|
768 |
protected final int entryBCI; |
|
769 |
private final BytecodeParser parent; |
|
770 |
||
771 |
private LineNumberTable lnt; |
|
772 |
private int previousLineNumber; |
|
773 |
private int currentLineNumber; |
|
774 |
||
775 |
private ValueNode methodSynchronizedObject; |
|
776 |
||
46393 | 777 |
private List<ReturnToCallerData> returnDataList; |
43972 | 778 |
private ValueNode unwindValue; |
779 |
private FixedWithNextNode beforeUnwindNode; |
|
780 |
||
781 |
protected FixedWithNextNode lastInstr; // the last instruction added |
|
782 |
private boolean controlFlowSplit; |
|
783 |
private final InvocationPluginReceiver invocationPluginReceiver = new InvocationPluginReceiver(this); |
|
784 |
||
785 |
private FixedWithNextNode[] firstInstructionArray; |
|
786 |
private FrameStateBuilder[] entryStateArray; |
|
787 |
||
788 |
private boolean finalBarrierRequired; |
|
789 |
private ValueNode originalReceiver; |
|
49451 | 790 |
private final boolean eagerInitializing; |
791 |
private final boolean uninitializedIsError; |
|
49873 | 792 |
private final int traceLevel; |
43972 | 793 |
|
794 |
protected BytecodeParser(GraphBuilderPhase.Instance graphBuilderInstance, StructuredGraph graph, BytecodeParser parent, ResolvedJavaMethod method, |
|
795 |
int entryBCI, IntrinsicContext intrinsicContext) { |
|
796 |
this.bytecodeProvider = intrinsicContext == null ? new ResolvedJavaMethodBytecodeProvider() : intrinsicContext.getBytecodeProvider(); |
|
797 |
this.code = bytecodeProvider.getBytecode(method); |
|
798 |
this.method = code.getMethod(); |
|
799 |
this.graphBuilderInstance = graphBuilderInstance; |
|
800 |
this.graph = graph; |
|
46344 | 801 |
this.options = graph.getOptions(); |
46640 | 802 |
this.debug = graph.getDebug(); |
43972 | 803 |
this.graphBuilderConfig = graphBuilderInstance.graphBuilderConfig; |
804 |
this.optimisticOpts = graphBuilderInstance.optimisticOpts; |
|
54328 | 805 |
this.providers = graphBuilderInstance.providers; |
43972 | 806 |
this.stream = new BytecodeStream(code.getCode()); |
807 |
this.profilingInfo = graph.useProfilingInfo() ? code.getProfilingInfo() : null; |
|
808 |
this.constantPool = code.getConstantPool(); |
|
809 |
this.intrinsicContext = intrinsicContext; |
|
810 |
this.entryBCI = entryBCI; |
|
811 |
this.parent = parent; |
|
812 |
||
49451 | 813 |
ClassInitializationPlugin classInitializationPlugin = graphBuilderConfig.getPlugins().getClassInitializationPlugin(); |
814 |
if (classInitializationPlugin != null && graphBuilderConfig.eagerResolving()) { |
|
815 |
uninitializedIsError = eagerInitializing = !classInitializationPlugin.supportsLazyInitialization(constantPool); |
|
816 |
} else { |
|
817 |
eagerInitializing = graphBuilderConfig.eagerResolving(); |
|
818 |
uninitializedIsError = graphBuilderConfig.unresolvedIsError(); |
|
819 |
} |
|
820 |
||
43972 | 821 |
assert code.getCode() != null : "method must contain bytecodes: " + method; |
822 |
||
823 |
if (graphBuilderConfig.insertFullInfopoints() && !parsingIntrinsic()) { |
|
824 |
lnt = code.getLineNumberTable(); |
|
825 |
previousLineNumber = -1; |
|
826 |
} |
|
49451 | 827 |
|
828 |
assert !GraalOptions.TrackNodeSourcePosition.getValue(options) || graph.trackNodeSourcePosition(); |
|
829 |
if (graphBuilderConfig.trackNodeSourcePosition() || (parent != null && parent.graph.trackNodeSourcePosition())) { |
|
830 |
graph.setTrackNodeSourcePosition(); |
|
831 |
} |
|
49873 | 832 |
|
833 |
int level = TraceBytecodeParserLevel.getValue(options); |
|
834 |
this.traceLevel = level != 0 ? refineTraceLevel(level) : 0; |
|
835 |
} |
|
836 |
||
837 |
private int refineTraceLevel(int level) { |
|
838 |
ResolvedJavaMethod tmethod = graph.method(); |
|
839 |
if (tmethod == null) { |
|
840 |
tmethod = method; |
|
841 |
} |
|
842 |
String filterValue = DebugOptions.MethodFilter.getValue(options); |
|
843 |
if (filterValue != null) { |
|
844 |
MethodFilter[] filters = MethodFilter.parse(filterValue); |
|
845 |
if (!MethodFilter.matches(filters, tmethod)) { |
|
846 |
return 0; |
|
847 |
} |
|
848 |
} |
|
849 |
return level; |
|
43972 | 850 |
} |
851 |
||
852 |
protected GraphBuilderPhase.Instance getGraphBuilderInstance() { |
|
853 |
return graphBuilderInstance; |
|
854 |
} |
|
855 |
||
856 |
public ValueNode getUnwindValue() { |
|
857 |
return unwindValue; |
|
858 |
} |
|
859 |
||
860 |
public FixedWithNextNode getBeforeUnwindNode() { |
|
861 |
return this.beforeUnwindNode; |
|
862 |
} |
|
863 |
||
864 |
@SuppressWarnings("try") |
|
865 |
protected void buildRootMethod() { |
|
54328 | 866 |
FrameStateBuilder startFrameState = new FrameStateBuilder(this, code, graph, graphBuilderConfig.retainLocalVariables()); |
43972 | 867 |
startFrameState.initializeForMethodStart(graph.getAssumptions(), graphBuilderConfig.eagerResolving() || intrinsicContext != null, graphBuilderConfig.getPlugins()); |
868 |
||
869 |
try (IntrinsicScope s = intrinsicContext != null ? new IntrinsicScope(this) : null) { |
|
870 |
build(graph.start(), startFrameState); |
|
871 |
} |
|
872 |
||
873 |
cleanupFinalGraph(); |
|
874 |
ComputeLoopFrequenciesClosure.compute(graph); |
|
875 |
} |
|
876 |
||
877 |
@SuppressWarnings("try") |
|
878 |
protected void build(FixedWithNextNode startInstruction, FrameStateBuilder startFrameState) { |
|
46344 | 879 |
if (PrintProfilingInformation.getValue(options) && profilingInfo != null) { |
43972 | 880 |
TTY.println("Profiling info for " + method.format("%H.%n(%p)")); |
881 |
TTY.println(Util.indent(profilingInfo.toString(method, CodeUtil.NEW_LINE), " ")); |
|
882 |
} |
|
883 |
||
46640 | 884 |
try (Indent indent = debug.logAndIndent("build graph for %s", method)) { |
43972 | 885 |
if (bytecodeProvider.shouldRecordMethodDependencies()) { |
886 |
assert getParent() != null || method.equals(graph.method()); |
|
887 |
// Record method dependency in the graph |
|
888 |
graph.recordMethod(method); |
|
889 |
} |
|
890 |
||
891 |
// compute the block map, setup exception handlers and get the entrypoint(s) |
|
46640 | 892 |
BciBlockMapping newMapping = BciBlockMapping.create(stream, code, options, graph.getDebug()); |
43972 | 893 |
this.blockMap = newMapping; |
894 |
this.firstInstructionArray = new FixedWithNextNode[blockMap.getBlockCount()]; |
|
895 |
this.entryStateArray = new FrameStateBuilder[blockMap.getBlockCount()]; |
|
896 |
if (!method.isStatic()) { |
|
897 |
originalReceiver = startFrameState.loadLocal(0, JavaKind.Object); |
|
898 |
} |
|
899 |
||
900 |
/* |
|
901 |
* Configure the assertion checking behavior of the FrameStateBuilder. This needs to be |
|
902 |
* done only when assertions are enabled, so it is wrapped in an assertion itself. |
|
903 |
*/ |
|
904 |
assert computeKindVerification(startFrameState); |
|
905 |
||
46640 | 906 |
try (DebugContext.Scope s = debug.scope("LivenessAnalysis")) { |
43972 | 907 |
int maxLocals = method.getMaxLocals(); |
46640 | 908 |
liveness = LocalLiveness.compute(debug, stream, blockMap.getBlocks(), maxLocals, blockMap.getLoopCount()); |
43972 | 909 |
} catch (Throwable e) { |
46640 | 910 |
throw debug.handle(e); |
43972 | 911 |
} |
912 |
||
913 |
lastInstr = startInstruction; |
|
914 |
this.setCurrentFrameState(startFrameState); |
|
915 |
stream.setBCI(0); |
|
916 |
||
917 |
BciBlock startBlock = blockMap.getStartBlock(); |
|
918 |
if (this.parent == null) { |
|
919 |
StartNode startNode = graph.start(); |
|
920 |
if (method.isSynchronized()) { |
|
921 |
assert !parsingIntrinsic(); |
|
922 |
startNode.setStateAfter(createFrameState(BytecodeFrame.BEFORE_BCI, startNode)); |
|
923 |
} else { |
|
924 |
if (!parsingIntrinsic()) { |
|
925 |
if (graph.method() != null && graph.method().isJavaLangObjectInit()) { |
|
926 |
/* |
|
927 |
* Don't clear the receiver when Object.<init> is the compilation root. |
|
928 |
* The receiver is needed as input to RegisterFinalizerNode. |
|
929 |
*/ |
|
930 |
} else { |
|
931 |
frameState.clearNonLiveLocals(startBlock, liveness, true); |
|
932 |
} |
|
933 |
assert bci() == 0; |
|
934 |
startNode.setStateAfter(createFrameState(bci(), startNode)); |
|
935 |
} else { |
|
936 |
if (startNode.stateAfter() == null) { |
|
937 |
FrameState stateAfterStart = createStateAfterStartOfReplacementGraph(); |
|
938 |
startNode.setStateAfter(stateAfterStart); |
|
939 |
} |
|
940 |
} |
|
941 |
} |
|
942 |
} |
|
943 |
||
49451 | 944 |
try (DebugCloseable context = openNodeContext()) { |
945 |
if (method.isSynchronized()) { |
|
50609 | 946 |
finishPrepare(lastInstr, BytecodeFrame.BEFORE_BCI, frameState); |
49451 | 947 |
|
948 |
// add a monitor enter to the start block |
|
949 |
methodSynchronizedObject = synchronizedObject(frameState, method); |
|
950 |
frameState.clearNonLiveLocals(startBlock, liveness, true); |
|
951 |
assert bci() == 0; |
|
952 |
genMonitorEnter(methodSynchronizedObject, bci()); |
|
953 |
} |
|
954 |
||
955 |
ProfilingPlugin profilingPlugin = this.graphBuilderConfig.getPlugins().getProfilingPlugin(); |
|
956 |
if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) { |
|
52910 | 957 |
FrameState stateBefore = createCurrentFrameState(); |
49451 | 958 |
profilingPlugin.profileInvoke(this, method, stateBefore); |
959 |
} |
|
960 |
||
50609 | 961 |
finishPrepare(lastInstr, 0, frameState); |
49451 | 962 |
|
963 |
genInfoPointNode(InfopointReason.METHOD_START, null); |
|
43972 | 964 |
} |
965 |
||
966 |
currentBlock = blockMap.getStartBlock(); |
|
967 |
setEntryState(startBlock, frameState); |
|
49873 | 968 |
if (startBlock.isLoopHeader()) { |
43972 | 969 |
appendGoto(startBlock); |
970 |
} else { |
|
971 |
setFirstInstruction(startBlock, lastInstr); |
|
972 |
} |
|
973 |
||
974 |
BciBlock[] blocks = blockMap.getBlocks(); |
|
975 |
for (BciBlock block : blocks) { |
|
976 |
processBlock(block); |
|
977 |
} |
|
978 |
} |
|
979 |
} |
|
980 |
||
981 |
private boolean computeKindVerification(FrameStateBuilder startFrameState) { |
|
982 |
if (blockMap.hasJsrBytecodes) { |
|
983 |
/* |
|
984 |
* The JSR return address is an int value, but stored using the astore bytecode. Instead |
|
985 |
* of weakening the kind assertion checking for all methods, we disable it completely |
|
986 |
* for methods that contain a JSR bytecode. |
|
987 |
*/ |
|
988 |
startFrameState.disableKindVerification(); |
|
989 |
} |
|
990 |
||
991 |
for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) { |
|
992 |
if (plugin.canChangeStackKind(this)) { |
|
993 |
/* |
|
994 |
* We have a plugin that can change the kind of values, so no kind assertion |
|
995 |
* checking is possible. |
|
996 |
*/ |
|
997 |
startFrameState.disableKindVerification(); |
|
998 |
} |
|
999 |
} |
|
1000 |
return true; |
|
1001 |
} |
|
1002 |
||
1003 |
/** |
|
46344 | 1004 |
* Hook for subclasses to modify synthetic code (start nodes and unwind nodes). |
43972 | 1005 |
* |
46344 | 1006 |
* @param instruction the current last instruction |
1007 |
* @param bci the current bci |
|
50609 | 1008 |
* @param state The current frame state. |
43972 | 1009 |
*/ |
50609 | 1010 |
protected void finishPrepare(FixedWithNextNode instruction, int bci, FrameStateBuilder state) { |
43972 | 1011 |
} |
1012 |
||
1013 |
protected void cleanupFinalGraph() { |
|
1014 |
GraphUtil.normalizeLoops(graph); |
|
1015 |
||
1016 |
// Remove dead parameters. |
|
1017 |
for (ParameterNode param : graph.getNodes(ParameterNode.TYPE)) { |
|
1018 |
if (param.hasNoUsages()) { |
|
1019 |
assert param.inputs().isEmpty(); |
|
1020 |
param.safeDelete(); |
|
1021 |
} |
|
1022 |
} |
|
1023 |
||
1024 |
// Remove redundant begin nodes. |
|
1025 |
for (BeginNode beginNode : graph.getNodes(BeginNode.TYPE)) { |
|
1026 |
Node predecessor = beginNode.predecessor(); |
|
1027 |
if (predecessor instanceof ControlSplitNode) { |
|
1028 |
// The begin node is necessary. |
|
46344 | 1029 |
} else if (!beginNode.hasUsages()) { |
43972 | 1030 |
GraphUtil.unlinkFixedNode(beginNode); |
1031 |
beginNode.safeDelete(); |
|
1032 |
} |
|
1033 |
} |
|
55509 | 1034 |
if (graph.isOSR() && getParent() == null && graph.getNodes().filter(EntryMarkerNode.class).isEmpty()) { |
1035 |
// This should generally be a transient condition because of inconsistent profile |
|
1036 |
// information. |
|
1037 |
throw new RetryableBailoutException("OSR entry point wasn't parsed"); |
|
1038 |
} |
|
43972 | 1039 |
} |
1040 |
||
1041 |
/** |
|
1042 |
* Creates the frame state after the start node of a graph for an {@link IntrinsicContext |
|
1043 |
* intrinsic} that is the parse root (either for root compiling or for post-parse inlining). |
|
1044 |
*/ |
|
1045 |
private FrameState createStateAfterStartOfReplacementGraph() { |
|
1046 |
assert parent == null; |
|
1047 |
assert frameState.getMethod().equals(intrinsicContext.getIntrinsicMethod()); |
|
1048 |
assert bci() == 0; |
|
1049 |
assert frameState.stackSize() == 0; |
|
1050 |
FrameState stateAfterStart; |
|
1051 |
if (intrinsicContext.isPostParseInlined()) { |
|
1052 |
stateAfterStart = graph.add(new FrameState(BytecodeFrame.BEFORE_BCI)); |
|
1053 |
} else { |
|
1054 |
ResolvedJavaMethod original = intrinsicContext.getOriginalMethod(); |
|
1055 |
ValueNode[] locals; |
|
1056 |
if (original.getMaxLocals() == frameState.localsSize() || original.isNative()) { |
|
1057 |
locals = new ValueNode[original.getMaxLocals()]; |
|
1058 |
for (int i = 0; i < locals.length; i++) { |
|
1059 |
ValueNode node = frameState.locals[i]; |
|
1060 |
if (node == FrameState.TWO_SLOT_MARKER) { |
|
1061 |
node = null; |
|
1062 |
} |
|
1063 |
locals[i] = node; |
|
1064 |
} |
|
1065 |
} else { |
|
1066 |
locals = new ValueNode[original.getMaxLocals()]; |
|
1067 |
int parameterCount = original.getSignature().getParameterCount(!original.isStatic()); |
|
1068 |
for (int i = 0; i < parameterCount; i++) { |
|
1069 |
ValueNode param = frameState.locals[i]; |
|
1070 |
if (param == FrameState.TWO_SLOT_MARKER) { |
|
1071 |
param = null; |
|
1072 |
} |
|
1073 |
locals[i] = param; |
|
1074 |
assert param == null || param instanceof ParameterNode || param.isConstant(); |
|
1075 |
} |
|
1076 |
} |
|
1077 |
ValueNode[] stack = {}; |
|
1078 |
int stackSize = 0; |
|
1079 |
ValueNode[] locks = {}; |
|
1080 |
List<MonitorIdNode> monitorIds = Collections.emptyList(); |
|
1081 |
stateAfterStart = graph.add(new FrameState(null, new ResolvedJavaMethodBytecode(original), 0, locals, stack, stackSize, locks, monitorIds, false, false)); |
|
1082 |
} |
|
1083 |
return stateAfterStart; |
|
1084 |
} |
|
1085 |
||
1086 |
/** |
|
1087 |
* @param type the unresolved type of the constant |
|
1088 |
*/ |
|
1089 |
protected void handleUnresolvedLoadConstant(JavaType type) { |
|
47667 | 1090 |
assert !graphBuilderConfig.unresolvedIsError(); |
1091 |
DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved)); |
|
1092 |
/* |
|
1093 |
* Track source position for deopt nodes even if |
|
1094 |
* GraphBuilderConfiguration.trackNodeSourcePosition is not set. |
|
1095 |
*/ |
|
1096 |
deopt.updateNodeSourcePosition(() -> createBytecodePosition()); |
|
43972 | 1097 |
} |
1098 |
||
1099 |
/** |
|
1100 |
* @param type the unresolved type of the type check |
|
1101 |
* @param object the object value whose type is being checked against {@code type} |
|
1102 |
*/ |
|
1103 |
protected void handleUnresolvedCheckCast(JavaType type, ValueNode object) { |
|
47667 | 1104 |
assert !graphBuilderConfig.unresolvedIsError(); |
46371 | 1105 |
append(new FixedGuardNode(graph.addOrUniqueWithInputs(IsNullNode.create(object)), Unresolved, InvalidateRecompile)); |
43972 | 1106 |
frameState.push(JavaKind.Object, appendConstant(JavaConstant.NULL_POINTER)); |
1107 |
} |
|
1108 |
||
1109 |
/** |
|
1110 |
* @param type the unresolved type of the type check |
|
1111 |
* @param object the object value whose type is being checked against {@code type} |
|
1112 |
*/ |
|
1113 |
protected void handleUnresolvedInstanceOf(JavaType type, ValueNode object) { |
|
47667 | 1114 |
assert !graphBuilderConfig.unresolvedIsError(); |
43972 | 1115 |
AbstractBeginNode successor = graph.add(new BeginNode()); |
1116 |
DeoptimizeNode deopt = graph.add(new DeoptimizeNode(InvalidateRecompile, Unresolved)); |
|
47667 | 1117 |
deopt.updateNodeSourcePosition(() -> createBytecodePosition()); |
46371 | 1118 |
append(new IfNode(graph.addOrUniqueWithInputs(IsNullNode.create(object)), successor, deopt, 1)); |
43972 | 1119 |
lastInstr = successor; |
1120 |
frameState.push(JavaKind.Int, appendConstant(JavaConstant.INT_0)); |
|
1121 |
} |
|
1122 |
||
1123 |
/** |
|
1124 |
* @param type the type being instantiated |
|
1125 |
*/ |
|
1126 |
protected void handleUnresolvedNewInstance(JavaType type) { |
|
47667 | 1127 |
assert !graphBuilderConfig.unresolvedIsError(); |
1128 |
DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved)); |
|
1129 |
deopt.updateNodeSourcePosition(() -> createBytecodePosition()); |
|
43972 | 1130 |
} |
1131 |
||
1132 |
/** |
|
52578 | 1133 |
* @param type the type being instantiated |
1134 |
*/ |
|
1135 |
protected void handleIllegalNewInstance(JavaType type) { |
|
1136 |
assert !graphBuilderConfig.unresolvedIsError(); |
|
1137 |
DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved)); |
|
1138 |
deopt.updateNodeSourcePosition(() -> createBytecodePosition()); |
|
1139 |
} |
|
1140 |
||
1141 |
/** |
|
43972 | 1142 |
* @param type the type of the array being instantiated |
1143 |
* @param length the length of the array |
|
1144 |
*/ |
|
1145 |
protected void handleUnresolvedNewObjectArray(JavaType type, ValueNode length) { |
|
47667 | 1146 |
assert !graphBuilderConfig.unresolvedIsError(); |
1147 |
DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved)); |
|
1148 |
deopt.updateNodeSourcePosition(() -> createBytecodePosition()); |
|
43972 | 1149 |
} |
1150 |
||
1151 |
/** |
|
1152 |
* @param type the type being instantiated |
|
1153 |
* @param dims the dimensions for the multi-array |
|
1154 |
*/ |
|
1155 |
protected void handleUnresolvedNewMultiArray(JavaType type, ValueNode[] dims) { |
|
47667 | 1156 |
assert !graphBuilderConfig.unresolvedIsError(); |
1157 |
DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved)); |
|
1158 |
deopt.updateNodeSourcePosition(() -> createBytecodePosition()); |
|
43972 | 1159 |
} |
1160 |
||
1161 |
/** |
|
1162 |
* @param field the unresolved field |
|
1163 |
* @param receiver the object containing the field or {@code null} if {@code field} is static |
|
1164 |
*/ |
|
1165 |
protected void handleUnresolvedLoadField(JavaField field, ValueNode receiver) { |
|
47667 | 1166 |
assert !graphBuilderConfig.unresolvedIsError(); |
1167 |
DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved)); |
|
1168 |
deopt.updateNodeSourcePosition(() -> createBytecodePosition()); |
|
43972 | 1169 |
} |
1170 |
||
1171 |
/** |
|
1172 |
* @param field the unresolved field |
|
1173 |
* @param value the value being stored to the field |
|
1174 |
* @param receiver the object containing the field or {@code null} if {@code field} is static |
|
1175 |
*/ |
|
1176 |
protected void handleUnresolvedStoreField(JavaField field, ValueNode value, ValueNode receiver) { |
|
47667 | 1177 |
assert !graphBuilderConfig.unresolvedIsError(); |
1178 |
DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved)); |
|
1179 |
deopt.updateNodeSourcePosition(() -> createBytecodePosition()); |
|
43972 | 1180 |
} |
1181 |
||
1182 |
/** |
|
1183 |
* @param type |
|
1184 |
*/ |
|
1185 |
protected void handleUnresolvedExceptionType(JavaType type) { |
|
47667 | 1186 |
assert !graphBuilderConfig.unresolvedIsError(); |
1187 |
DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved)); |
|
1188 |
deopt.updateNodeSourcePosition(() -> createBytecodePosition()); |
|
43972 | 1189 |
} |
1190 |
||
1191 |
/** |
|
1192 |
* @param javaMethod |
|
1193 |
* @param invokeKind |
|
1194 |
*/ |
|
1195 |
protected void handleUnresolvedInvoke(JavaMethod javaMethod, InvokeKind invokeKind) { |
|
47667 | 1196 |
assert !graphBuilderConfig.unresolvedIsError(); |
1197 |
DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved)); |
|
1198 |
deopt.updateNodeSourcePosition(() -> createBytecodePosition()); |
|
43972 | 1199 |
} |
1200 |
||
53425
312880c38a7f
8215375: [Graal] jck:vm/jvmti/Exception/excp001/excp00101 fails in Graal as JIT mode and -Xcomp mode
dnsimon
parents:
53033
diff
changeset
|
1201 |
/** |
312880c38a7f
8215375: [Graal] jck:vm/jvmti/Exception/excp001/excp00101 fails in Graal as JIT mode and -Xcomp mode
dnsimon
parents:
53033
diff
changeset
|
1202 |
* @return the entry point to exception dispatch |
312880c38a7f
8215375: [Graal] jck:vm/jvmti/Exception/excp001/excp00101 fails in Graal as JIT mode and -Xcomp mode
dnsimon
parents:
53033
diff
changeset
|
1203 |
*/ |
47798 | 1204 |
private AbstractBeginNode handleException(ValueNode exceptionObject, int bci, boolean deoptimizeOnly) { |
53425
312880c38a7f
8215375: [Graal] jck:vm/jvmti/Exception/excp001/excp00101 fails in Graal as JIT mode and -Xcomp mode
dnsimon
parents:
53033
diff
changeset
|
1205 |
FixedWithNextNode currentLastInstr = lastInstr; |
43972 | 1206 |
assert bci == BytecodeFrame.BEFORE_BCI || bci == bci() : "invalid bci"; |
46640 | 1207 |
debug.log("Creating exception dispatch edges at %d, exception object=%s, exception seen=%s", bci, exceptionObject, (profilingInfo == null ? "" : profilingInfo.getExceptionSeen(bci))); |
43972 | 1208 |
|
1209 |
FrameStateBuilder dispatchState = frameState.copy(); |
|
1210 |
dispatchState.clearStack(); |
|
1211 |
||
1212 |
AbstractBeginNode dispatchBegin; |
|
1213 |
if (exceptionObject == null) { |
|
54328 | 1214 |
ExceptionObjectNode newExceptionObject = graph.add(new ExceptionObjectNode(getMetaAccess())); |
43972 | 1215 |
dispatchBegin = newExceptionObject; |
1216 |
dispatchState.push(JavaKind.Object, dispatchBegin); |
|
1217 |
dispatchState.setRethrowException(true); |
|
1218 |
newExceptionObject.setStateAfter(dispatchState.create(bci, newExceptionObject)); |
|
1219 |
} else { |
|
1220 |
dispatchBegin = graph.add(new BeginNode()); |
|
1221 |
dispatchState.push(JavaKind.Object, exceptionObject); |
|
1222 |
dispatchState.setRethrowException(true); |
|
1223 |
} |
|
1224 |
this.controlFlowSplit = true; |
|
53425
312880c38a7f
8215375: [Graal] jck:vm/jvmti/Exception/excp001/excp00101 fails in Graal as JIT mode and -Xcomp mode
dnsimon
parents:
53033
diff
changeset
|
1225 |
FixedWithNextNode afterExceptionLoaded = finishInstruction(dispatchBegin, dispatchState); |
43972 | 1226 |
|
47798 | 1227 |
if (deoptimizeOnly) { |
1228 |
DeoptimizeNode deoptimizeNode = graph.add(new DeoptimizeNode(DeoptimizationAction.None, DeoptimizationReason.TransferToInterpreter)); |
|
53425
312880c38a7f
8215375: [Graal] jck:vm/jvmti/Exception/excp001/excp00101 fails in Graal as JIT mode and -Xcomp mode
dnsimon
parents:
53033
diff
changeset
|
1229 |
afterExceptionLoaded.setNext(BeginNode.begin(deoptimizeNode)); |
47798 | 1230 |
} else { |
53425
312880c38a7f
8215375: [Graal] jck:vm/jvmti/Exception/excp001/excp00101 fails in Graal as JIT mode and -Xcomp mode
dnsimon
parents:
53033
diff
changeset
|
1231 |
createHandleExceptionTarget(afterExceptionLoaded, bci, dispatchState); |
312880c38a7f
8215375: [Graal] jck:vm/jvmti/Exception/excp001/excp00101 fails in Graal as JIT mode and -Xcomp mode
dnsimon
parents:
53033
diff
changeset
|
1232 |
} |
312880c38a7f
8215375: [Graal] jck:vm/jvmti/Exception/excp001/excp00101 fails in Graal as JIT mode and -Xcomp mode
dnsimon
parents:
53033
diff
changeset
|
1233 |
assert currentLastInstr == lastInstr; |
43972 | 1234 |
return dispatchBegin; |
1235 |
} |
|
1236 |
||
53425
312880c38a7f
8215375: [Graal] jck:vm/jvmti/Exception/excp001/excp00101 fails in Graal as JIT mode and -Xcomp mode
dnsimon
parents:
53033
diff
changeset
|
1237 |
protected void createHandleExceptionTarget(FixedWithNextNode afterExceptionLoaded, int bci, FrameStateBuilder dispatchState) { |
312880c38a7f
8215375: [Graal] jck:vm/jvmti/Exception/excp001/excp00101 fails in Graal as JIT mode and -Xcomp mode
dnsimon
parents:
53033
diff
changeset
|
1238 |
FixedWithNextNode afterInstrumentation = afterExceptionLoaded; |
312880c38a7f
8215375: [Graal] jck:vm/jvmti/Exception/excp001/excp00101 fails in Graal as JIT mode and -Xcomp mode
dnsimon
parents:
53033
diff
changeset
|
1239 |
for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) { |
312880c38a7f
8215375: [Graal] jck:vm/jvmti/Exception/excp001/excp00101 fails in Graal as JIT mode and -Xcomp mode
dnsimon
parents:
53033
diff
changeset
|
1240 |
afterInstrumentation = plugin.instrumentExceptionDispatch(graph, afterInstrumentation); |
312880c38a7f
8215375: [Graal] jck:vm/jvmti/Exception/excp001/excp00101 fails in Graal as JIT mode and -Xcomp mode
dnsimon
parents:
53033
diff
changeset
|
1241 |
assert afterInstrumentation.next() == null : "exception dispatch instrumentation will be linked to dispatch block"; |
312880c38a7f
8215375: [Graal] jck:vm/jvmti/Exception/excp001/excp00101 fails in Graal as JIT mode and -Xcomp mode
dnsimon
parents:
53033
diff
changeset
|
1242 |
} |
312880c38a7f
8215375: [Graal] jck:vm/jvmti/Exception/excp001/excp00101 fails in Graal as JIT mode and -Xcomp mode
dnsimon
parents:
53033
diff
changeset
|
1243 |
|
43972 | 1244 |
BciBlock dispatchBlock = currentBlock.exceptionDispatchBlock(); |
1245 |
/* |
|
1246 |
* The exception dispatch block is always for the last bytecode of a block, so if we are not |
|
1247 |
* at the endBci yet, there is no exception handler for this bci and we can unwind |
|
1248 |
* immediately. |
|
1249 |
*/ |
|
1250 |
if (bci != currentBlock.endBci || dispatchBlock == null) { |
|
1251 |
dispatchBlock = blockMap.getUnwindBlock(); |
|
1252 |
} |
|
1253 |
||
1254 |
FixedNode target = createTarget(dispatchBlock, dispatchState); |
|
53425
312880c38a7f
8215375: [Graal] jck:vm/jvmti/Exception/excp001/excp00101 fails in Graal as JIT mode and -Xcomp mode
dnsimon
parents:
53033
diff
changeset
|
1255 |
afterInstrumentation.setNext(target); |
43972 | 1256 |
} |
1257 |
||
50330 | 1258 |
protected ValueNode genLoadIndexed(ValueNode array, ValueNode index, GuardingNode boundsCheck, JavaKind kind) { |
54328 | 1259 |
return LoadIndexedNode.create(graph.getAssumptions(), array, index, boundsCheck, kind, getMetaAccess(), getConstantReflection()); |
50330 | 1260 |
} |
1261 |
||
1262 |
protected void genStoreIndexed(ValueNode array, ValueNode index, GuardingNode boundsCheck, GuardingNode storeCheck, JavaKind kind, ValueNode value) { |
|
1263 |
add(new StoreIndexedNode(array, index, boundsCheck, storeCheck, kind, value)); |
|
43972 | 1264 |
} |
1265 |
||
1266 |
protected ValueNode genIntegerAdd(ValueNode x, ValueNode y) { |
|
48190 | 1267 |
return AddNode.create(x, y, NodeView.DEFAULT); |
43972 | 1268 |
} |
1269 |
||
1270 |
protected ValueNode genIntegerSub(ValueNode x, ValueNode y) { |
|
48190 | 1271 |
return SubNode.create(x, y, NodeView.DEFAULT); |
43972 | 1272 |
} |
1273 |
||
1274 |
protected ValueNode genIntegerMul(ValueNode x, ValueNode y) { |
|
48190 | 1275 |
return MulNode.create(x, y, NodeView.DEFAULT); |
43972 | 1276 |
} |
1277 |
||
1278 |
protected ValueNode genFloatAdd(ValueNode x, ValueNode y) { |
|
48190 | 1279 |
return AddNode.create(x, y, NodeView.DEFAULT); |
43972 | 1280 |
} |
1281 |
||
1282 |
protected ValueNode genFloatSub(ValueNode x, ValueNode y) { |
|
48190 | 1283 |
return SubNode.create(x, y, NodeView.DEFAULT); |
43972 | 1284 |
} |
1285 |
||
1286 |
protected ValueNode genFloatMul(ValueNode x, ValueNode y) { |
|
48190 | 1287 |
return MulNode.create(x, y, NodeView.DEFAULT); |
43972 | 1288 |
} |
1289 |
||
1290 |
protected ValueNode genFloatDiv(ValueNode x, ValueNode y) { |
|
48190 | 1291 |
return FloatDivNode.create(x, y, NodeView.DEFAULT); |
43972 | 1292 |
} |
1293 |
||
1294 |
protected ValueNode genFloatRem(ValueNode x, ValueNode y) { |
|
48190 | 1295 |
return RemNode.create(x, y, NodeView.DEFAULT); |
43972 | 1296 |
} |
1297 |
||
50330 | 1298 |
protected ValueNode genIntegerDiv(ValueNode x, ValueNode y, GuardingNode zeroCheck) { |
1299 |
return SignedDivNode.create(x, y, zeroCheck, NodeView.DEFAULT); |
|
1300 |
} |
|
1301 |
||
1302 |
protected ValueNode genIntegerRem(ValueNode x, ValueNode y, GuardingNode zeroCheck) { |
|
1303 |
return SignedRemNode.create(x, y, zeroCheck, NodeView.DEFAULT); |
|
43972 | 1304 |
} |
1305 |
||
1306 |
protected ValueNode genNegateOp(ValueNode x) { |
|
48190 | 1307 |
return NegateNode.create(x, NodeView.DEFAULT); |
43972 | 1308 |
} |
1309 |
||
1310 |
protected ValueNode genLeftShift(ValueNode x, ValueNode y) { |
|
48190 | 1311 |
return LeftShiftNode.create(x, y, NodeView.DEFAULT); |
43972 | 1312 |
} |
1313 |
||
1314 |
protected ValueNode genRightShift(ValueNode x, ValueNode y) { |
|
48190 | 1315 |
return RightShiftNode.create(x, y, NodeView.DEFAULT); |
43972 | 1316 |
} |
1317 |
||
1318 |
protected ValueNode genUnsignedRightShift(ValueNode x, ValueNode y) { |
|
48190 | 1319 |
return UnsignedRightShiftNode.create(x, y, NodeView.DEFAULT); |
43972 | 1320 |
} |
1321 |
||
1322 |
protected ValueNode genAnd(ValueNode x, ValueNode y) { |
|
48190 | 1323 |
return AndNode.create(x, y, NodeView.DEFAULT); |
43972 | 1324 |
} |
1325 |
||
1326 |
protected ValueNode genOr(ValueNode x, ValueNode y) { |
|
48190 | 1327 |
return OrNode.create(x, y, NodeView.DEFAULT); |
43972 | 1328 |
} |
1329 |
||
1330 |
protected ValueNode genXor(ValueNode x, ValueNode y) { |
|
48190 | 1331 |
return XorNode.create(x, y, NodeView.DEFAULT); |
43972 | 1332 |
} |
1333 |
||
1334 |
protected ValueNode genNormalizeCompare(ValueNode x, ValueNode y, boolean isUnorderedLess) { |
|
54328 | 1335 |
return NormalizeCompareNode.create(x, y, isUnorderedLess, JavaKind.Int, getConstantReflection()); |
43972 | 1336 |
} |
1337 |
||
1338 |
protected ValueNode genFloatConvert(FloatConvert op, ValueNode input) { |
|
48190 | 1339 |
return FloatConvertNode.create(op, input, NodeView.DEFAULT); |
43972 | 1340 |
} |
1341 |
||
1342 |
protected ValueNode genNarrow(ValueNode input, int bitCount) { |
|
48190 | 1343 |
return NarrowNode.create(input, bitCount, NodeView.DEFAULT); |
43972 | 1344 |
} |
1345 |
||
1346 |
protected ValueNode genSignExtend(ValueNode input, int bitCount) { |
|
48190 | 1347 |
return SignExtendNode.create(input, bitCount, NodeView.DEFAULT); |
43972 | 1348 |
} |
1349 |
||
1350 |
protected ValueNode genZeroExtend(ValueNode input, int bitCount) { |
|
48190 | 1351 |
return ZeroExtendNode.create(input, bitCount, NodeView.DEFAULT); |
43972 | 1352 |
} |
1353 |
||
1354 |
protected void genGoto() { |
|
1355 |
ProfilingPlugin profilingPlugin = this.graphBuilderConfig.getPlugins().getProfilingPlugin(); |
|
1356 |
if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) { |
|
52910 | 1357 |
FrameState stateBefore = createCurrentFrameState(); |
43972 | 1358 |
int targetBci = currentBlock.getSuccessor(0).startBci; |
1359 |
profilingPlugin.profileGoto(this, method, bci(), targetBci, stateBefore); |
|
1360 |
} |
|
1361 |
appendGoto(currentBlock.getSuccessor(0)); |
|
1362 |
assert currentBlock.numNormalSuccessors() == 1; |
|
1363 |
} |
|
1364 |
||
1365 |
protected LogicNode genObjectEquals(ValueNode x, ValueNode y) { |
|
54328 | 1366 |
return ObjectEqualsNode.create(getConstantReflection(), getMetaAccess(), options, x, y, NodeView.DEFAULT); |
43972 | 1367 |
} |
1368 |
||
1369 |
protected LogicNode genIntegerEquals(ValueNode x, ValueNode y) { |
|
54328 | 1370 |
return IntegerEqualsNode.create(getConstantReflection(), getMetaAccess(), options, null, x, y, NodeView.DEFAULT); |
43972 | 1371 |
} |
1372 |
||
1373 |
protected LogicNode genIntegerLessThan(ValueNode x, ValueNode y) { |
|
54328 | 1374 |
return IntegerLessThanNode.create(getConstantReflection(), getMetaAccess(), options, null, x, y, NodeView.DEFAULT); |
43972 | 1375 |
} |
1376 |
||
1377 |
protected ValueNode genUnique(ValueNode x) { |
|
1378 |
return graph.addOrUniqueWithInputs(x); |
|
1379 |
} |
|
1380 |
||
1381 |
protected LogicNode genUnique(LogicNode x) { |
|
1382 |
return graph.addOrUniqueWithInputs(x); |
|
1383 |
} |
|
1384 |
||
54084 | 1385 |
protected ValueNode genIfNode(LogicNode condition, FixedNode trueSuccessor, FixedNode falseSuccessor, double d) { |
1386 |
return new IfNode(condition, trueSuccessor, falseSuccessor, d); |
|
43972 | 1387 |
} |
1388 |
||
1389 |
protected void genThrow() { |
|
1390 |
genInfoPointNode(InfopointReason.BYTECODE_POSITION, null); |
|
1391 |
||
50330 | 1392 |
ValueNode exception = maybeEmitExplicitNullCheck(frameState.pop(JavaKind.Object)); |
1393 |
if (!StampTool.isPointerNonNull(exception.stamp(NodeView.DEFAULT))) { |
|
1394 |
FixedGuardNode nullCheck = append(new FixedGuardNode(graph.addOrUniqueWithInputs(IsNullNode.create(exception)), NullCheckException, InvalidateReprofile, true)); |
|
1395 |
exception = graph.maybeAddOrUnique(PiNode.create(exception, exception.stamp(NodeView.DEFAULT).join(objectNonNull()), nullCheck)); |
|
1396 |
} |
|
1397 |
lastInstr.setNext(handleException(exception, bci(), false)); |
|
43972 | 1398 |
} |
1399 |
||
1400 |
protected LogicNode createInstanceOf(TypeReference type, ValueNode object) { |
|
1401 |
return InstanceOfNode.create(type, object); |
|
1402 |
} |
|
1403 |
||
1404 |
protected AnchoringNode createAnchor(JavaTypeProfile profile) { |
|
1405 |
if (profile == null || profile.getNotRecordedProbability() > 0.0) { |
|
1406 |
return null; |
|
1407 |
} else { |
|
1408 |
return append(new ValueAnchorNode(null)); |
|
1409 |
} |
|
1410 |
} |
|
1411 |
||
1412 |
protected LogicNode createInstanceOf(TypeReference type, ValueNode object, JavaTypeProfile profile) { |
|
1413 |
return InstanceOfNode.create(type, object, profile, createAnchor(profile)); |
|
1414 |
} |
|
1415 |
||
1416 |
protected LogicNode createInstanceOfAllowNull(TypeReference type, ValueNode object, JavaTypeProfile profile) { |
|
1417 |
return InstanceOfNode.createAllowNull(type, object, profile, createAnchor(profile)); |
|
1418 |
} |
|
1419 |
||
1420 |
protected ValueNode genConditional(ValueNode x) { |
|
48190 | 1421 |
return ConditionalNode.create((LogicNode) x, NodeView.DEFAULT); |
43972 | 1422 |
} |
1423 |
||
1424 |
protected NewInstanceNode createNewInstance(ResolvedJavaType type, boolean fillContents) { |
|
1425 |
return new NewInstanceNode(type, fillContents); |
|
1426 |
} |
|
1427 |
||
1428 |
protected NewArrayNode createNewArray(ResolvedJavaType elementType, ValueNode length, boolean fillContents) { |
|
1429 |
return new NewArrayNode(elementType, length, fillContents); |
|
1430 |
} |
|
1431 |
||
1432 |
protected NewMultiArrayNode createNewMultiArray(ResolvedJavaType type, ValueNode[] dimensions) { |
|
1433 |
return new NewMultiArrayNode(type, dimensions); |
|
1434 |
} |
|
1435 |
||
1436 |
protected ValueNode genLoadField(ValueNode receiver, ResolvedJavaField field) { |
|
1437 |
StampPair stamp = graphBuilderConfig.getPlugins().getOverridingStamp(this, field.getType(), false); |
|
1438 |
if (stamp == null) { |
|
46371 | 1439 |
return LoadFieldNode.create(getConstantFieldProvider(), getConstantReflection(), getMetaAccess(), getOptions(), |
1440 |
getAssumptions(), receiver, field, false, false); |
|
43972 | 1441 |
} else { |
46371 | 1442 |
return LoadFieldNode.createOverrideStamp(getConstantFieldProvider(), getConstantReflection(), getMetaAccess(), getOptions(), |
1443 |
stamp, receiver, field, false, false); |
|
43972 | 1444 |
} |
1445 |
} |
|
1446 |
||
46762 | 1447 |
protected StateSplitProxyNode genVolatileFieldReadProxy(ValueNode fieldRead) { |
1448 |
return new StateSplitProxyNode(fieldRead); |
|
1449 |
} |
|
1450 |
||
50330 | 1451 |
protected ValueNode maybeEmitExplicitNullCheck(ValueNode receiver) { |
1452 |
if (StampTool.isPointerNonNull(receiver.stamp(NodeView.DEFAULT)) || !needsExplicitNullCheckException(receiver)) { |
|
43972 | 1453 |
return receiver; |
1454 |
} |
|
50330 | 1455 |
LogicNode condition = genUnique(IsNullNode.create(receiver)); |
1456 |
AbstractBeginNode passingSuccessor = emitBytecodeExceptionCheck(condition, false, BytecodeExceptionKind.NULL_POINTER); |
|
1457 |
return genUnique(PiNode.create(receiver, objectNonNull(), passingSuccessor)); |
|
1458 |
} |
|
1459 |
||
1460 |
protected GuardingNode maybeEmitExplicitBoundsCheck(ValueNode receiver, ValueNode index) { |
|
1461 |
if (!needsExplicitBoundsCheckException(receiver, index)) { |
|
1462 |
return null; |
|
1463 |
} |
|
1464 |
ValueNode length = append(genArrayLength(receiver)); |
|
54328 | 1465 |
LogicNode condition = genUnique(IntegerBelowNode.create(getConstantReflection(), getMetaAccess(), options, null, index, length, NodeView.DEFAULT)); |
50330 | 1466 |
return emitBytecodeExceptionCheck(condition, true, BytecodeExceptionKind.OUT_OF_BOUNDS, index, length); |
1467 |
} |
|
1468 |
||
1469 |
protected GuardingNode maybeEmitExplicitStoreCheck(ValueNode array, JavaKind elementKind, ValueNode value) { |
|
1470 |
if (elementKind != JavaKind.Object || StampTool.isPointerAlwaysNull(value) || !needsExplicitStoreCheckException(array, value)) { |
|
1471 |
return null; |
|
1472 |
} |
|
54328 | 1473 |
ValueNode arrayClass = genUnique(LoadHubNode.create(array, getStampProvider(), getMetaAccess(), getConstantReflection())); |
1474 |
ValueNode componentHub = append(LoadArrayComponentHubNode.create(arrayClass, getStampProvider(), getMetaAccess(), getConstantReflection())); |
|
50330 | 1475 |
LogicNode condition = genUnique(InstanceOfDynamicNode.create(graph.getAssumptions(), getConstantReflection(), componentHub, value, true)); |
1476 |
return emitBytecodeExceptionCheck(condition, true, BytecodeExceptionKind.ARRAY_STORE, value); |
|
1477 |
} |
|
1478 |
||
1479 |
protected GuardingNode maybeEmitExplicitDivisionByZeroCheck(ValueNode y) { |
|
1480 |
if (!((IntegerStamp) y.stamp(NodeView.DEFAULT)).contains(0) || !needsExplicitDivisionByZeroException(y)) { |
|
1481 |
return null; |
|
1482 |
} |
|
1483 |
ConstantNode zero = ConstantNode.defaultForKind(y.getStackKind(), graph); |
|
54328 | 1484 |
LogicNode condition = genUnique(IntegerEqualsNode.create(getConstantReflection(), getMetaAccess(), options, null, y, zero, NodeView.DEFAULT)); |
50330 | 1485 |
return emitBytecodeExceptionCheck(condition, false, BytecodeExceptionKind.DIVISION_BY_ZERO); |
1486 |
} |
|
1487 |
||
1488 |
private AbstractBeginNode emitBytecodeExceptionCheck(LogicNode condition, boolean passingOnTrue, BytecodeExceptionKind exceptionKind, ValueNode... arguments) { |
|
1489 |
if (passingOnTrue ? condition.isTautology() : condition.isContradiction()) { |
|
1490 |
return null; |
|
1491 |
} |
|
1492 |
||
54328 | 1493 |
BytecodeExceptionNode exception = graph.add(new BytecodeExceptionNode(getMetaAccess(), exceptionKind, arguments)); |
50330 | 1494 |
AbstractBeginNode passingSuccessor = graph.add(new BeginNode()); |
1495 |
||
1496 |
FixedNode trueSuccessor = passingOnTrue ? passingSuccessor : exception; |
|
1497 |
FixedNode falseSuccessor = passingOnTrue ? exception : passingSuccessor; |
|
50858 | 1498 |
append(new IfNode(condition, trueSuccessor, falseSuccessor, passingOnTrue ? LUDICROUSLY_FAST_PATH_PROBABILITY : LUDICROUSLY_SLOW_PATH_PROBABILITY)); |
50330 | 1499 |
lastInstr = passingSuccessor; |
43972 | 1500 |
|
1501 |
exception.setStateAfter(createFrameState(bci(), exception)); |
|
47798 | 1502 |
exception.setNext(handleException(exception, bci(), false)); |
46640 | 1503 |
EXPLICIT_EXCEPTIONS.increment(debug); |
50330 | 1504 |
|
1505 |
return passingSuccessor; |
|
43972 | 1506 |
} |
1507 |
||
1508 |
protected ValueNode genArrayLength(ValueNode x) { |
|
54328 | 1509 |
return ArrayLengthNode.create(x, getConstantReflection()); |
43972 | 1510 |
} |
1511 |
||
1512 |
protected void genStoreField(ValueNode receiver, ResolvedJavaField field, ValueNode value) { |
|
50609 | 1513 |
StoreFieldNode storeFieldNode = new StoreFieldNode(receiver, field, maskSubWordValue(value, field.getJavaKind())); |
43972 | 1514 |
append(storeFieldNode); |
1515 |
storeFieldNode.setStateAfter(this.createFrameState(stream.nextBCI(), storeFieldNode)); |
|
1516 |
} |
|
1517 |
||
1518 |
/** |
|
1519 |
* Ensure that concrete classes are at least linked before generating an invoke. Interfaces may |
|
1520 |
* never be linked so simply return true for them. |
|
1521 |
* |
|
1522 |
* @param target |
|
1523 |
* @return true if the declared holder is an interface or is linked |
|
1524 |
*/ |
|
1525 |
private static boolean callTargetIsResolved(JavaMethod target) { |
|
1526 |
if (target instanceof ResolvedJavaMethod) { |
|
1527 |
ResolvedJavaMethod resolvedTarget = (ResolvedJavaMethod) target; |
|
1528 |
ResolvedJavaType resolvedType = resolvedTarget.getDeclaringClass(); |
|
1529 |
return resolvedType.isInterface() || resolvedType.isLinked(); |
|
1530 |
} |
|
1531 |
return false; |
|
1532 |
} |
|
1533 |
||
52578 | 1534 |
/** |
1535 |
* Check if a type is resolved. Can be overwritten by sub-classes to implement different type |
|
1536 |
* resolution rules. |
|
1537 |
*/ |
|
1538 |
protected boolean typeIsResolved(JavaType type) { |
|
1539 |
return type instanceof ResolvedJavaType; |
|
1540 |
} |
|
1541 |
||
47667 | 1542 |
protected void genInvokeStatic(int cpi, int opcode) { |
1543 |
JavaMethod target = lookupMethod(cpi, opcode); |
|
49451 | 1544 |
assert !uninitializedIsError || |
1545 |
(target instanceof ResolvedJavaMethod && ((ResolvedJavaMethod) target).getDeclaringClass().isInitialized()) : target; |
|
47667 | 1546 |
genInvokeStatic(target); |
1547 |
} |
|
1548 |
||
1549 |
void genInvokeStatic(JavaMethod target) { |
|
43972 | 1550 |
if (callTargetIsResolved(target)) { |
1551 |
ResolvedJavaMethod resolvedTarget = (ResolvedJavaMethod) target; |
|
1552 |
ResolvedJavaType holder = resolvedTarget.getDeclaringClass(); |
|
52910 | 1553 |
maybeEagerlyInitialize(holder); |
1554 |
ClassInitializationPlugin classInitializationPlugin = graphBuilderConfig.getPlugins().getClassInitializationPlugin(); |
|
1555 |
if (!holder.isInitialized() && classInitializationPlugin == null) { |
|
43972 | 1556 |
handleUnresolvedInvoke(target, InvokeKind.Static); |
52910 | 1557 |
return; |
1558 |
} |
|
1559 |
||
1560 |
ValueNode[] classInit = {null}; |
|
1561 |
if (classInitializationPlugin != null) { |
|
1562 |
classInitializationPlugin.apply(this, resolvedTarget.getDeclaringClass(), this::createCurrentFrameState, classInit); |
|
1563 |
} |
|
1564 |
||
1565 |
ValueNode[] args = frameState.popArguments(resolvedTarget.getSignature().getParameterCount(false)); |
|
1566 |
Invoke invoke = appendInvoke(InvokeKind.Static, resolvedTarget, args); |
|
1567 |
if (invoke != null && classInit[0] != null) { |
|
1568 |
invoke.setClassInit(classInit[0]); |
|
43972 | 1569 |
} |
1570 |
} else { |
|
1571 |
handleUnresolvedInvoke(target, InvokeKind.Static); |
|
1572 |
} |
|
1573 |
} |
|
1574 |
||
52910 | 1575 |
/** |
1576 |
* Creates a frame state for the current parse position. |
|
1577 |
*/ |
|
1578 |
private FrameState createCurrentFrameState() { |
|
1579 |
return frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null); |
|
1580 |
} |
|
1581 |
||
47667 | 1582 |
protected void genInvokeInterface(int cpi, int opcode) { |
1583 |
JavaMethod target = lookupMethod(cpi, opcode); |
|
1584 |
genInvokeInterface(target); |
|
1585 |
} |
|
1586 |
||
43972 | 1587 |
protected void genInvokeInterface(JavaMethod target) { |
1588 |
if (callTargetIsResolved(target)) { |
|
1589 |
ValueNode[] args = frameState.popArguments(target.getSignature().getParameterCount(true)); |
|
1590 |
appendInvoke(InvokeKind.Interface, (ResolvedJavaMethod) target, args); |
|
1591 |
} else { |
|
1592 |
handleUnresolvedInvoke(target, InvokeKind.Interface); |
|
1593 |
} |
|
1594 |
} |
|
1595 |
||
47667 | 1596 |
protected void genInvokeDynamic(int cpi, int opcode) { |
1597 |
JavaMethod target = lookupMethod(cpi, opcode); |
|
1598 |
genInvokeDynamic(target); |
|
1599 |
} |
|
1600 |
||
1601 |
void genInvokeDynamic(JavaMethod target) { |
|
1602 |
if (!(target instanceof ResolvedJavaMethod) || !genDynamicInvokeHelper((ResolvedJavaMethod) target, stream.readCPI4(), INVOKEDYNAMIC)) { |
|
43972 | 1603 |
handleUnresolvedInvoke(target, InvokeKind.Static); |
1604 |
} |
|
1605 |
} |
|
1606 |
||
47667 | 1607 |
protected void genInvokeVirtual(int cpi, int opcode) { |
1608 |
JavaMethod target = lookupMethod(cpi, opcode); |
|
52578 | 1609 |
if (callTargetIsResolved(target)) { |
1610 |
genInvokeVirtual((ResolvedJavaMethod) target); |
|
1611 |
} else { |
|
1612 |
handleUnresolvedInvoke(target, InvokeKind.Virtual); |
|
1613 |
} |
|
1614 |
} |
|
1615 |
||
1616 |
protected void genInvokeVirtual(ResolvedJavaMethod resolvedTarget) { |
|
1617 |
int cpi = stream.readCPI(); |
|
1618 |
||
1619 |
/* |
|
1620 |
* Special handling for runtimes that rewrite an invocation of MethodHandle.invoke(...) or |
|
1621 |
* MethodHandle.invokeExact(...) to a static adapter. HotSpot does this - see |
|
1622 |
* https://wiki.openjdk.java.net/display/HotSpot/Method+handles+and+invokedynamic |
|
1623 |
*/ |
|
1624 |
||
1625 |
if (genDynamicInvokeHelper(resolvedTarget, cpi, INVOKEVIRTUAL)) { |
|
1626 |
return; |
|
1627 |
} |
|
1628 |
||
1629 |
ValueNode[] args = frameState.popArguments(resolvedTarget.getSignature().getParameterCount(true)); |
|
1630 |
appendInvoke(InvokeKind.Virtual, resolvedTarget, args); |
|
47667 | 1631 |
} |
1632 |
||
1633 |
private boolean genDynamicInvokeHelper(ResolvedJavaMethod target, int cpi, int opcode) { |
|
1634 |
assert opcode == INVOKEDYNAMIC || opcode == INVOKEVIRTUAL; |
|
1635 |
||
1636 |
InvokeDynamicPlugin invokeDynamicPlugin = graphBuilderConfig.getPlugins().getInvokeDynamicPlugin(); |
|
1637 |
||
1638 |
if (opcode == INVOKEVIRTUAL && invokeDynamicPlugin != null && !invokeDynamicPlugin.isResolvedDynamicInvoke(this, cpi, opcode)) { |
|
1639 |
// regular invokevirtual, let caller handle it |
|
1640 |
return false; |
|
1641 |
} |
|
1642 |
||
1643 |
if (GeneratePIC.getValue(options) && (invokeDynamicPlugin == null || !invokeDynamicPlugin.supportsDynamicInvoke(this, cpi, opcode))) { |
|
1644 |
// bail out if static compiler and no dynamic type support |
|
1645 |
append(new DeoptimizeNode(InvalidateRecompile, Unresolved)); |
|
1646 |
return true; |
|
1647 |
} |
|
1648 |
||
1649 |
JavaConstant appendix = constantPool.lookupAppendix(cpi, opcode); |
|
1650 |
ValueNode appendixNode = null; |
|
1651 |
||
1652 |
if (appendix != null) { |
|
1653 |
if (invokeDynamicPlugin != null) { |
|
1654 |
invokeDynamicPlugin.recordDynamicMethod(this, cpi, opcode, target); |
|
1655 |
||
1656 |
// Will perform runtime type checks and static initialization |
|
52910 | 1657 |
FrameState stateBefore = createCurrentFrameState(); |
47667 | 1658 |
appendixNode = invokeDynamicPlugin.genAppendixNode(this, cpi, opcode, appendix, stateBefore); |
1659 |
} else { |
|
54328 | 1660 |
appendixNode = ConstantNode.forConstant(appendix, getMetaAccess(), graph); |
43972 | 1661 |
} |
47667 | 1662 |
|
1663 |
frameState.push(JavaKind.Object, appendixNode); |
|
1664 |
||
1665 |
} else if (GeneratePIC.getValue(options)) { |
|
1666 |
// Need to emit runtime guard and perform static initialization. |
|
1667 |
// Not implemented yet. |
|
1668 |
append(new DeoptimizeNode(InvalidateRecompile, Unresolved)); |
|
1669 |
return true; |
|
1670 |
} |
|
1671 |
||
1672 |
boolean hasReceiver = (opcode == INVOKEDYNAMIC) ? false : !target.isStatic(); |
|
1673 |
ValueNode[] args = frameState.popArguments(target.getSignature().getParameterCount(hasReceiver)); |
|
1674 |
if (hasReceiver) { |
|
1675 |
appendInvoke(InvokeKind.Virtual, target, args); |
|
43972 | 1676 |
} else { |
47667 | 1677 |
appendInvoke(InvokeKind.Static, target, args); |
1678 |
} |
|
1679 |
||
1680 |
return true; |
|
1681 |
} |
|
1682 |
||
1683 |
protected void genInvokeSpecial(int cpi, int opcode) { |
|
1684 |
JavaMethod target = lookupMethod(cpi, opcode); |
|
1685 |
genInvokeSpecial(target); |
|
1686 |
} |
|
1687 |
||
1688 |
void genInvokeSpecial(JavaMethod target) { |
|
43972 | 1689 |
if (callTargetIsResolved(target)) { |
1690 |
assert target != null; |
|
1691 |
assert target.getSignature() != null; |
|
1692 |
ValueNode[] args = frameState.popArguments(target.getSignature().getParameterCount(true)); |
|
1693 |
appendInvoke(InvokeKind.Special, (ResolvedJavaMethod) target, args); |
|
1694 |
} else { |
|
1695 |
handleUnresolvedInvoke(target, InvokeKind.Special); |
|
1696 |
} |
|
1697 |
} |
|
1698 |
||
46509 | 1699 |
static class CurrentInvoke { |
1700 |
final ValueNode[] args; |
|
1701 |
final InvokeKind kind; |
|
1702 |
final JavaType returnType; |
|
1703 |
||
1704 |
CurrentInvoke(ValueNode[] args, InvokeKind kind, JavaType returnType) { |
|
1705 |
this.args = args; |
|
1706 |
this.kind = kind; |
|
1707 |
this.returnType = returnType; |
|
1708 |
} |
|
1709 |
} |
|
1710 |
||
1711 |
private CurrentInvoke currentInvoke; |
|
43972 | 1712 |
protected FrameStateBuilder frameState; |
1713 |
protected BciBlock currentBlock; |
|
1714 |
protected final BytecodeStream stream; |
|
1715 |
protected final GraphBuilderConfiguration graphBuilderConfig; |
|
1716 |
protected final ResolvedJavaMethod method; |
|
1717 |
protected final Bytecode code; |
|
1718 |
protected final BytecodeProvider bytecodeProvider; |
|
1719 |
protected final ProfilingInfo profilingInfo; |
|
1720 |
protected final OptimisticOptimizations optimisticOpts; |
|
1721 |
protected final ConstantPool constantPool; |
|
54328 | 1722 |
protected final CoreProviders providers; |
43972 | 1723 |
protected final IntrinsicContext intrinsicContext; |
1724 |
||
1725 |
@Override |
|
1726 |
public InvokeKind getInvokeKind() { |
|
46509 | 1727 |
return currentInvoke == null ? null : currentInvoke.kind; |
43972 | 1728 |
} |
1729 |
||
1730 |
@Override |
|
1731 |
public JavaType getInvokeReturnType() { |
|
46509 | 1732 |
return currentInvoke == null ? null : currentInvoke.returnType; |
43972 | 1733 |
} |
1734 |
||
1735 |
private boolean forceInliningEverything; |
|
1736 |
||
1737 |
@Override |
|
54084 | 1738 |
public Invoke handleReplacedInvoke(InvokeKind invokeKind, ResolvedJavaMethod targetMethod, ValueNode[] args, boolean inlineEverything) { |
43972 | 1739 |
boolean previous = forceInliningEverything; |
1740 |
forceInliningEverything = previous || inlineEverything; |
|
1741 |
try { |
|
54084 | 1742 |
return appendInvoke(invokeKind, targetMethod, args); |
43972 | 1743 |
} finally { |
1744 |
forceInliningEverything = previous; |
|
1745 |
} |
|
1746 |
} |
|
1747 |
||
46344 | 1748 |
@Override |
1749 |
public void handleReplacedInvoke(CallTargetNode callTarget, JavaKind resultType) { |
|
46509 | 1750 |
BytecodeParser intrinsicCallSiteParser = getNonIntrinsicAncestor(); |
47798 | 1751 |
ExceptionEdgeAction exceptionEdgeAction = intrinsicCallSiteParser == null ? getActionForInvokeExceptionEdge(null) : intrinsicCallSiteParser.getActionForInvokeExceptionEdge(null); |
1752 |
createNonInlinedInvoke(exceptionEdgeAction, bci(), callTarget, resultType); |
|
46344 | 1753 |
} |
1754 |
||
46762 | 1755 |
protected Invoke appendInvoke(InvokeKind initialInvokeKind, ResolvedJavaMethod initialTargetMethod, ValueNode[] args) { |
43972 | 1756 |
ResolvedJavaMethod targetMethod = initialTargetMethod; |
1757 |
InvokeKind invokeKind = initialInvokeKind; |
|
1758 |
if (initialInvokeKind.isIndirect()) { |
|
1759 |
ResolvedJavaType contextType = this.frameState.getMethod().getDeclaringClass(); |
|
1760 |
ResolvedJavaMethod specialCallTarget = MethodCallTargetNode.findSpecialCallTarget(initialInvokeKind, args[0], initialTargetMethod, contextType); |
|
1761 |
if (specialCallTarget != null) { |
|
1762 |
invokeKind = InvokeKind.Special; |
|
1763 |
targetMethod = specialCallTarget; |
|
1764 |
} |
|
1765 |
} |
|
1766 |
||
1767 |
JavaKind resultType = targetMethod.getSignature().getReturnKind(); |
|
46344 | 1768 |
if (!parsingIntrinsic() && DeoptALot.getValue(options)) { |
43972 | 1769 |
append(new DeoptimizeNode(DeoptimizationAction.None, RuntimeConstraint)); |
1770 |
frameState.pushReturn(resultType, ConstantNode.defaultForKind(resultType, graph)); |
|
1771 |
return null; |
|
1772 |
} |
|
1773 |
||
55509 | 1774 |
JavaType returnType = maybeEagerlyResolve(targetMethod.getSignature().getReturnType(method.getDeclaringClass()), targetMethod.getDeclaringClass()); |
43972 | 1775 |
if (invokeKind.hasReceiver()) { |
50330 | 1776 |
args[0] = maybeEmitExplicitNullCheck(args[0]); |
43972 | 1777 |
} |
1778 |
||
46640 | 1779 |
if (initialInvokeKind == InvokeKind.Special && !targetMethod.isConstructor()) { |
1780 |
emitCheckForInvokeSuperSpecial(args); |
|
50823
accde81a0046
8202698: Update Graal for JEP 181 - Nest-based access control
iveresov
parents:
50609
diff
changeset
|
1781 |
} else if (initialInvokeKind == InvokeKind.Interface && targetMethod.isPrivate()) { |
accde81a0046
8202698: Update Graal for JEP 181 - Nest-based access control
iveresov
parents:
50609
diff
changeset
|
1782 |
emitCheckForDeclaringClassChange(targetMethod.getDeclaringClass(), args); |
46640 | 1783 |
} |
1784 |
||
43972 | 1785 |
InlineInfo inlineInfo = null; |
1786 |
try { |
|
46509 | 1787 |
currentInvoke = new CurrentInvoke(args, invokeKind, returnType); |
43972 | 1788 |
if (tryNodePluginForInvocation(args, targetMethod)) { |
46344 | 1789 |
if (TraceParserPlugins.getValue(options)) { |
43972 | 1790 |
traceWithContext("used node plugin for %s", targetMethod.format("%h.%n(%p)")); |
1791 |
} |
|
1792 |
return null; |
|
1793 |
} |
|
1794 |
||
46371 | 1795 |
if (invokeKind.hasReceiver() && args[0].isNullConstant()) { |
1796 |
append(new DeoptimizeNode(InvalidateRecompile, NullCheckException)); |
|
1797 |
return null; |
|
1798 |
} |
|
1799 |
||
55509 | 1800 |
if (!invokeKind.isIndirect()) { |
1801 |
if (tryInvocationPlugin(invokeKind, args, targetMethod, resultType)) { |
|
46344 | 1802 |
if (TraceParserPlugins.getValue(options)) { |
43972 | 1803 |
traceWithContext("used invocation plugin for %s", targetMethod.format("%h.%n(%p)")); |
1804 |
} |
|
1805 |
return null; |
|
1806 |
} |
|
1807 |
} |
|
1808 |
if (invokeKind.isDirect()) { |
|
1809 |
inlineInfo = tryInline(args, targetMethod); |
|
1810 |
if (inlineInfo == SUCCESSFULLY_INLINED) { |
|
1811 |
return null; |
|
1812 |
} |
|
1813 |
} |
|
1814 |
} finally { |
|
46509 | 1815 |
currentInvoke = null; |
43972 | 1816 |
} |
1817 |
||
46509 | 1818 |
int invokeBci = bci(); |
1819 |
JavaTypeProfile profile = getProfileForInvoke(invokeKind); |
|
47798 | 1820 |
ExceptionEdgeAction edgeAction = getActionForInvokeExceptionEdge(inlineInfo); |
46459 | 1821 |
boolean partialIntrinsicExit = false; |
1822 |
if (intrinsicContext != null && intrinsicContext.isCallToOriginal(targetMethod)) { |
|
1823 |
partialIntrinsicExit = true; |
|
1824 |
ResolvedJavaMethod originalMethod = intrinsicContext.getOriginalMethod(); |
|
46509 | 1825 |
BytecodeParser intrinsicCallSiteParser = getNonIntrinsicAncestor(); |
1826 |
if (intrinsicCallSiteParser != null) { |
|
1827 |
// When exiting a partial intrinsic, the invoke to the original |
|
1828 |
// must use the same context as the call to the intrinsic. |
|
1829 |
invokeBci = intrinsicCallSiteParser.bci(); |
|
1830 |
profile = intrinsicCallSiteParser.getProfileForInvoke(invokeKind); |
|
47798 | 1831 |
edgeAction = intrinsicCallSiteParser.getActionForInvokeExceptionEdge(inlineInfo); |
46509 | 1832 |
} else { |
1833 |
// We are parsing the intrinsic for the root compilation or for inlining, |
|
1834 |
// This call is a partial intrinsic exit, and we do not have profile information |
|
1835 |
// for this callsite. We also have to assume that the call needs an exception |
|
1836 |
// edge. Finally, we know that this intrinsic is parsed for late inlining, |
|
1837 |
// so the bci must be set to unknown, so that the inliner patches it later. |
|
1838 |
assert intrinsicContext.isPostParseInlined(); |
|
54601 | 1839 |
invokeBci = UNKNOWN_BCI; |
46509 | 1840 |
profile = null; |
47798 | 1841 |
edgeAction = graph.method().getAnnotation(Snippet.class) == null ? ExceptionEdgeAction.INCLUDE_AND_HANDLE : ExceptionEdgeAction.OMIT; |
46509 | 1842 |
} |
1843 |
||
46459 | 1844 |
if (originalMethod.isStatic()) { |
1845 |
invokeKind = InvokeKind.Static; |
|
1846 |
} else { |
|
1847 |
// The original call to the intrinsic must have been devirtualized |
|
1848 |
// otherwise we wouldn't be here. |
|
1849 |
invokeKind = InvokeKind.Special; |
|
1850 |
} |
|
1851 |
Signature sig = originalMethod.getSignature(); |
|
1852 |
returnType = sig.getReturnType(method.getDeclaringClass()); |
|
1853 |
resultType = sig.getReturnKind(); |
|
47798 | 1854 |
assert intrinsicContext.allowPartialIntrinsicArgumentMismatch() || checkPartialIntrinsicExit(intrinsicCallSiteParser == null ? null : intrinsicCallSiteParser.currentInvoke.args, args); |
46459 | 1855 |
targetMethod = originalMethod; |
1856 |
} |
|
47798 | 1857 |
Invoke invoke = createNonInlinedInvoke(edgeAction, invokeBci, args, targetMethod, invokeKind, resultType, returnType, profile); |
49873 | 1858 |
graph.getInliningLog().addDecision(invoke, false, "GraphBuilderPhase", null, null, "bytecode parser did not replace invoke"); |
46459 | 1859 |
if (partialIntrinsicExit) { |
1860 |
// This invoke must never be later inlined as it might select the intrinsic graph. |
|
1861 |
// Until there is a mechanism to guarantee that any late inlining will not select |
|
1862 |
// the intrinsic graph, prevent this invoke from being inlined. |
|
1863 |
invoke.setUseForInlining(false); |
|
1864 |
} |
|
1865 |
return invoke; |
|
43972 | 1866 |
} |
1867 |
||
46640 | 1868 |
/** |
50823
accde81a0046
8202698: Update Graal for JEP 181 - Nest-based access control
iveresov
parents:
50609
diff
changeset
|
1869 |
* Checks that the class of the receiver of an {@link Bytecodes#INVOKEINTERFACE} invocation of a |
accde81a0046
8202698: Update Graal for JEP 181 - Nest-based access control
iveresov
parents:
50609
diff
changeset
|
1870 |
* private method is assignable to the interface that declared the method. If not, then |
accde81a0046
8202698: Update Graal for JEP 181 - Nest-based access control
iveresov
parents:
50609
diff
changeset
|
1871 |
* deoptimize so that the interpreter can throw an {@link IllegalAccessError}. |
accde81a0046
8202698: Update Graal for JEP 181 - Nest-based access control
iveresov
parents:
50609
diff
changeset
|
1872 |
* |
accde81a0046
8202698: Update Graal for JEP 181 - Nest-based access control
iveresov
parents:
50609
diff
changeset
|
1873 |
* This is a check not performed by the verifier and so must be performed at runtime. |
accde81a0046
8202698: Update Graal for JEP 181 - Nest-based access control
iveresov
parents:
50609
diff
changeset
|
1874 |
* |
accde81a0046
8202698: Update Graal for JEP 181 - Nest-based access control
iveresov
parents:
50609
diff
changeset
|
1875 |
* @param declaringClass interface declaring the callee |
accde81a0046
8202698: Update Graal for JEP 181 - Nest-based access control
iveresov
parents:
50609
diff
changeset
|
1876 |
* @param args arguments to an {@link Bytecodes#INVOKEINTERFACE} call to a private method |
accde81a0046
8202698: Update Graal for JEP 181 - Nest-based access control
iveresov
parents:
50609
diff
changeset
|
1877 |
* declared in a interface |
accde81a0046
8202698: Update Graal for JEP 181 - Nest-based access control
iveresov
parents:
50609
diff
changeset
|
1878 |
*/ |
accde81a0046
8202698: Update Graal for JEP 181 - Nest-based access control
iveresov
parents:
50609
diff
changeset
|
1879 |
private void emitCheckForDeclaringClassChange(ResolvedJavaType declaringClass, ValueNode[] args) { |
accde81a0046
8202698: Update Graal for JEP 181 - Nest-based access control
iveresov
parents:
50609
diff
changeset
|
1880 |
ValueNode receiver = args[0]; |
accde81a0046
8202698: Update Graal for JEP 181 - Nest-based access control
iveresov
parents:
50609
diff
changeset
|
1881 |
TypeReference checkedType = TypeReference.createTrusted(graph.getAssumptions(), declaringClass); |
accde81a0046
8202698: Update Graal for JEP 181 - Nest-based access control
iveresov
parents:
50609
diff
changeset
|
1882 |
LogicNode condition = genUnique(createInstanceOf(checkedType, receiver, null)); |
accde81a0046
8202698: Update Graal for JEP 181 - Nest-based access control
iveresov
parents:
50609
diff
changeset
|
1883 |
FixedGuardNode fixedGuard = append(new FixedGuardNode(condition, ClassCastException, None, false)); |
accde81a0046
8202698: Update Graal for JEP 181 - Nest-based access control
iveresov
parents:
50609
diff
changeset
|
1884 |
args[0] = append(PiNode.create(receiver, StampFactory.object(checkedType, true), fixedGuard)); |
accde81a0046
8202698: Update Graal for JEP 181 - Nest-based access control
iveresov
parents:
50609
diff
changeset
|
1885 |
} |
accde81a0046
8202698: Update Graal for JEP 181 - Nest-based access control
iveresov
parents:
50609
diff
changeset
|
1886 |
|
accde81a0046
8202698: Update Graal for JEP 181 - Nest-based access control
iveresov
parents:
50609
diff
changeset
|
1887 |
/** |
46640 | 1888 |
* Checks that the class of the receiver of an {@link Bytecodes#INVOKESPECIAL} in a method |
1889 |
* declared in an interface (i.e., a default method) is assignable to the interface. If not, |
|
1890 |
* then deoptimize so that the interpreter can throw an {@link IllegalAccessError}. |
|
1891 |
* |
|
1892 |
* This is a check not performed by the verifier and so must be performed at runtime. |
|
1893 |
* |
|
1894 |
* @param args arguments to an {@link Bytecodes#INVOKESPECIAL} implementing a direct call to a |
|
1895 |
* method in a super class |
|
1896 |
*/ |
|
1897 |
protected void emitCheckForInvokeSuperSpecial(ValueNode[] args) { |
|
1898 |
ResolvedJavaType callingClass = method.getDeclaringClass(); |
|
1899 |
if (callingClass.getHostClass() != null) { |
|
1900 |
callingClass = callingClass.getHostClass(); |
|
1901 |
} |
|
1902 |
if (callingClass.isInterface()) { |
|
1903 |
ValueNode receiver = args[0]; |
|
1904 |
TypeReference checkedType = TypeReference.createTrusted(graph.getAssumptions(), callingClass); |
|
1905 |
LogicNode condition = genUnique(createInstanceOf(checkedType, receiver, null)); |
|
1906 |
FixedGuardNode fixedGuard = append(new FixedGuardNode(condition, ClassCastException, None, false)); |
|
1907 |
args[0] = append(PiNode.create(receiver, StampFactory.object(checkedType, true), fixedGuard)); |
|
1908 |
} |
|
1909 |
} |
|
1910 |
||
46509 | 1911 |
protected JavaTypeProfile getProfileForInvoke(InvokeKind invokeKind) { |
1912 |
if (invokeKind.isIndirect() && profilingInfo != null && this.optimisticOpts.useTypeCheckHints(getOptions())) { |
|
1913 |
return profilingInfo.getTypeProfile(bci()); |
|
1914 |
} |
|
1915 |
return null; |
|
1916 |
} |
|
1917 |
||
46459 | 1918 |
/** |
1919 |
* A partial intrinsic exits by (effectively) calling the intrinsified method. This call must |
|
1920 |
* use exactly the arguments to the call being intrinsified. |
|
1921 |
* |
|
46509 | 1922 |
* @param originalArgs arguments of original call to intrinsified method |
1923 |
* @param recursiveArgs arguments of recursive call to intrinsified method |
|
46459 | 1924 |
*/ |
46509 | 1925 |
private static boolean checkPartialIntrinsicExit(ValueNode[] originalArgs, ValueNode[] recursiveArgs) { |
1926 |
if (originalArgs != null) { |
|
1927 |
for (int i = 0; i < originalArgs.length; i++) { |
|
1928 |
ValueNode arg = GraphUtil.unproxify(recursiveArgs[i]); |
|
1929 |
ValueNode icArg = GraphUtil.unproxify(originalArgs[i]); |
|
46459 | 1930 |
assert arg == icArg : String.format("argument %d of call denoting partial intrinsic exit should be %s, not %s", i, icArg, arg); |
1931 |
} |
|
1932 |
} else { |
|
46509 | 1933 |
for (int i = 0; i < recursiveArgs.length; i++) { |
1934 |
ValueNode arg = GraphUtil.unproxify(recursiveArgs[i]); |
|
47798 | 1935 |
assert arg instanceof ParameterNode && ((ParameterNode) arg).index() == i : String.format("argument %d of call denoting partial intrinsic exit should be a %s with index %d, not %s", |
1936 |
i, ParameterNode.class.getSimpleName(), i, arg); |
|
46459 | 1937 |
} |
1938 |
} |
|
1939 |
return true; |
|
1940 |
} |
|
1941 |
||
47798 | 1942 |
protected Invoke createNonInlinedInvoke(ExceptionEdgeAction exceptionEdge, int invokeBci, ValueNode[] invokeArgs, ResolvedJavaMethod targetMethod, |
46509 | 1943 |
InvokeKind invokeKind, JavaKind resultType, JavaType returnType, JavaTypeProfile profile) { |
43972 | 1944 |
|
1945 |
StampPair returnStamp = graphBuilderConfig.getPlugins().getOverridingStamp(this, returnType, false); |
|
1946 |
if (returnStamp == null) { |
|
1947 |
returnStamp = StampFactory.forDeclaredType(graph.getAssumptions(), returnType, false); |
|
1948 |
} |
|
1949 |
||
46459 | 1950 |
MethodCallTargetNode callTarget = graph.add(createMethodCallTarget(invokeKind, targetMethod, invokeArgs, returnStamp, profile)); |
47798 | 1951 |
Invoke invoke = createNonInlinedInvoke(exceptionEdge, invokeBci, callTarget, resultType); |
43972 | 1952 |
|
1953 |
for (InlineInvokePlugin plugin : graphBuilderConfig.getPlugins().getInlineInvokePlugins()) { |
|
1954 |
plugin.notifyNotInlined(this, targetMethod, invoke); |
|
1955 |
} |
|
1956 |
||
1957 |
return invoke; |
|
1958 |
} |
|
1959 |
||
47798 | 1960 |
protected Invoke createNonInlinedInvoke(ExceptionEdgeAction exceptionEdge, int invokeBci, CallTargetNode callTarget, JavaKind resultType) { |
1961 |
if (exceptionEdge == ExceptionEdgeAction.OMIT) { |
|
46459 | 1962 |
return createInvoke(invokeBci, callTarget, resultType); |
46344 | 1963 |
} else { |
47798 | 1964 |
Invoke invoke = createInvokeWithException(invokeBci, callTarget, resultType, exceptionEdge); |
46344 | 1965 |
AbstractBeginNode beginNode = graph.add(KillingBeginNode.create(LocationIdentity.any())); |
1966 |
invoke.setNext(beginNode); |
|
1967 |
lastInstr = beginNode; |
|
1968 |
return invoke; |
|
1969 |
} |
|
1970 |
} |
|
1971 |
||
43972 | 1972 |
/** |
47798 | 1973 |
* Describes what should be done with the exception edge of an invocation. The edge can be |
1974 |
* omitted or included. An included edge can handle the exception or transfer execution to the |
|
1975 |
* interpreter for handling (deoptimize). |
|
43972 | 1976 |
*/ |
47798 | 1977 |
protected enum ExceptionEdgeAction { |
1978 |
OMIT, |
|
1979 |
INCLUDE_AND_HANDLE, |
|
1980 |
INCLUDE_AND_DEOPTIMIZE |
|
1981 |
} |
|
1982 |
||
1983 |
protected ExceptionEdgeAction getActionForInvokeExceptionEdge(InlineInfo lastInlineInfo) { |
|
43972 | 1984 |
if (lastInlineInfo == InlineInfo.DO_NOT_INLINE_WITH_EXCEPTION) { |
47798 | 1985 |
return ExceptionEdgeAction.INCLUDE_AND_HANDLE; |
43972 | 1986 |
} else if (lastInlineInfo == InlineInfo.DO_NOT_INLINE_NO_EXCEPTION) { |
47798 | 1987 |
return ExceptionEdgeAction.OMIT; |
1988 |
} else if (lastInlineInfo == InlineInfo.DO_NOT_INLINE_DEOPTIMIZE_ON_EXCEPTION) { |
|
1989 |
return ExceptionEdgeAction.INCLUDE_AND_DEOPTIMIZE; |
|
43972 | 1990 |
} else if (graphBuilderConfig.getBytecodeExceptionMode() == BytecodeExceptionMode.CheckAll) { |
47798 | 1991 |
return ExceptionEdgeAction.INCLUDE_AND_HANDLE; |
46344 | 1992 |
} else if (graphBuilderConfig.getBytecodeExceptionMode() == BytecodeExceptionMode.ExplicitOnly) { |
47798 | 1993 |
return ExceptionEdgeAction.INCLUDE_AND_HANDLE; |
43972 | 1994 |
} else if (graphBuilderConfig.getBytecodeExceptionMode() == BytecodeExceptionMode.OmitAll) { |
47798 | 1995 |
return ExceptionEdgeAction.OMIT; |
43972 | 1996 |
} else { |
1997 |
assert graphBuilderConfig.getBytecodeExceptionMode() == BytecodeExceptionMode.Profile; |
|
1998 |
// be conservative if information was not recorded (could result in endless |
|
1999 |
// recompiles otherwise) |
|
46509 | 2000 |
if (!StressInvokeWithExceptionNode.getValue(options)) { |
2001 |
if (optimisticOpts.useExceptionProbability(getOptions())) { |
|
2002 |
if (profilingInfo != null) { |
|
2003 |
TriState exceptionSeen = profilingInfo.getExceptionSeen(bci()); |
|
2004 |
if (exceptionSeen == TriState.FALSE) { |
|
47798 | 2005 |
return ExceptionEdgeAction.OMIT; |
46509 | 2006 |
} |
2007 |
} |
|
2008 |
} |
|
2009 |
} |
|
47798 | 2010 |
return ExceptionEdgeAction.INCLUDE_AND_HANDLE; |
43972 | 2011 |
} |
2012 |
} |
|
2013 |
||
2014 |
/** |
|
2015 |
* Contains all the assertion checking logic around the application of an |
|
2016 |
* {@link InvocationPlugin}. This class is only loaded when assertions are enabled. |
|
2017 |
*/ |
|
2018 |
class InvocationPluginAssertions { |
|
2019 |
final InvocationPlugin plugin; |
|
2020 |
final ValueNode[] args; |
|
2021 |
final ResolvedJavaMethod targetMethod; |
|
2022 |
final JavaKind resultType; |
|
2023 |
final int beforeStackSize; |
|
2024 |
final boolean needsNullCheck; |
|
2025 |
final int nodeCount; |
|
2026 |
final Mark mark; |
|
2027 |
||
2028 |
InvocationPluginAssertions(InvocationPlugin plugin, ValueNode[] args, ResolvedJavaMethod targetMethod, JavaKind resultType) { |
|
46762 | 2029 |
guarantee(Assertions.assertionsEnabled(), "%s should only be loaded and instantiated if assertions are enabled", getClass().getSimpleName()); |
43972 | 2030 |
this.plugin = plugin; |
2031 |
this.targetMethod = targetMethod; |
|
2032 |
this.args = args; |
|
2033 |
this.resultType = resultType; |
|
2034 |
this.beforeStackSize = frameState.stackSize(); |
|
48190 | 2035 |
this.needsNullCheck = !targetMethod.isStatic() && args[0].getStackKind() == JavaKind.Object && !StampTool.isPointerNonNull(args[0].stamp(NodeView.DEFAULT)); |
43972 | 2036 |
this.nodeCount = graph.getNodeCount(); |
2037 |
this.mark = graph.getMark(); |
|
2038 |
} |
|
2039 |
||
2040 |
String error(String format, Object... a) { |
|
54328 | 2041 |
return String.format(format, a) + String.format("%n\tplugin at %s", plugin.getApplySourceLocation(getMetaAccess())); |
43972 | 2042 |
} |
2043 |
||
2044 |
boolean check(boolean pluginResult) { |
|
51436 | 2045 |
if (pluginResult) { |
2046 |
/* |
|
2047 |
* If lastInstr is null, even if this method has a non-void return type, the method |
|
2048 |
* doesn't return a value, it probably throws an exception. |
|
2049 |
*/ |
|
43972 | 2050 |
int expectedStackSize = beforeStackSize + resultType.getSlotCount(); |
51436 | 2051 |
assert lastInstr == null || expectedStackSize == frameState.stackSize() : error("plugin manipulated the stack incorrectly: expected=%d, actual=%d", expectedStackSize, |
2052 |
frameState.stackSize()); |
|
2053 |
||
43972 | 2054 |
NodeIterable<Node> newNodes = graph.getNewNodes(mark); |
48190 | 2055 |
assert !needsNullCheck || isPointerNonNull(args[0].stamp(NodeView.DEFAULT)) : error("plugin needs to null check the receiver of %s: receiver=%s", targetMethod.format("%H.%n(%p)"), |
2056 |
args[0]); |
|
43972 | 2057 |
for (Node n : newNodes) { |
2058 |
if (n instanceof StateSplit) { |
|
2059 |
StateSplit stateSplit = (StateSplit) n; |
|
2060 |
assert stateSplit.stateAfter() != null || !stateSplit.hasSideEffect() : error("%s node added by plugin for %s need to have a non-null frame state: %s", |
|
2061 |
StateSplit.class.getSimpleName(), targetMethod.format("%H.%n(%p)"), stateSplit); |
|
2062 |
} |
|
2063 |
} |
|
2064 |
try { |
|
2065 |
graphBuilderConfig.getPlugins().getInvocationPlugins().checkNewNodes(BytecodeParser.this, plugin, newNodes); |
|
2066 |
} catch (Throwable t) { |
|
2067 |
throw new AssertionError(error("Error in plugin"), t); |
|
2068 |
} |
|
2069 |
} else { |
|
2070 |
assert nodeCount == graph.getNodeCount() : error("plugin that returns false must not create new nodes"); |
|
2071 |
assert beforeStackSize == frameState.stackSize() : error("plugin that returns false must not modify the stack"); |
|
2072 |
} |
|
2073 |
return true; |
|
2074 |
} |
|
2075 |
} |
|
2076 |
||
49451 | 2077 |
@SuppressWarnings("try") |
55509 | 2078 |
protected boolean tryInvocationPlugin(InvokeKind invokeKind, ValueNode[] args, ResolvedJavaMethod targetMethod, JavaKind resultType) { |
43972 | 2079 |
InvocationPlugin plugin = graphBuilderConfig.getPlugins().getInvocationPlugins().lookupInvocation(targetMethod); |
2080 |
if (plugin != null) { |
|
2081 |
||
2082 |
if (intrinsicContext != null && intrinsicContext.isCallToOriginal(targetMethod)) { |
|
50330 | 2083 |
// Self recursive intrinsic means the original method should be called. |
43972 | 2084 |
return false; |
2085 |
} |
|
2086 |
||
2087 |
InvocationPluginReceiver pluginReceiver = invocationPluginReceiver.init(targetMethod, args); |
|
55509 | 2088 |
assert invokeKind.isDirect() : "Cannot apply invocation plugin on an indirect call site."; |
43972 | 2089 |
|
46762 | 2090 |
InvocationPluginAssertions assertions = Assertions.assertionsEnabled() ? new InvocationPluginAssertions(plugin, args, targetMethod, resultType) : null; |
49451 | 2091 |
try (DebugCloseable context = openNodeContext(targetMethod)) { |
2092 |
if (plugin.execute(this, targetMethod, pluginReceiver, args)) { |
|
55509 | 2093 |
assert assertions.check(true); |
50330 | 2094 |
return !plugin.isDecorator(); |
49451 | 2095 |
} else { |
55509 | 2096 |
assert assertions.check(false); |
49451 | 2097 |
} |
43972 | 2098 |
} |
2099 |
} |
|
2100 |
return false; |
|
2101 |
} |
|
2102 |
||
2103 |
private boolean tryNodePluginForInvocation(ValueNode[] args, ResolvedJavaMethod targetMethod) { |
|
2104 |
for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) { |
|
2105 |
if (plugin.handleInvoke(this, targetMethod, args)) { |
|
2106 |
return true; |
|
2107 |
} |
|
2108 |
} |
|
2109 |
return false; |
|
2110 |
} |
|
2111 |
||
2112 |
private static final InlineInfo SUCCESSFULLY_INLINED = InlineInfo.createStandardInlineInfo(null); |
|
2113 |
||
2114 |
/** |
|
2115 |
* Try to inline a method. If the method was inlined, returns {@link #SUCCESSFULLY_INLINED}. |
|
2116 |
* Otherwise, it returns the {@link InlineInfo} that lead to the decision to not inline it, or |
|
2117 |
* {@code null} if there is no {@link InlineInfo} for this method. |
|
2118 |
*/ |
|
2119 |
private InlineInfo tryInline(ValueNode[] args, ResolvedJavaMethod targetMethod) { |
|
2120 |
boolean canBeInlined = forceInliningEverything || parsingIntrinsic() || targetMethod.canBeInlined(); |
|
2121 |
if (!canBeInlined) { |
|
2122 |
return null; |
|
2123 |
} |
|
2124 |
||
2125 |
if (forceInliningEverything) { |
|
2126 |
if (inline(targetMethod, targetMethod, null, args)) { |
|
2127 |
return SUCCESSFULLY_INLINED; |
|
2128 |
} else { |
|
2129 |
return null; |
|
2130 |
} |
|
2131 |
} |
|
2132 |
||
2133 |
for (InlineInvokePlugin plugin : graphBuilderConfig.getPlugins().getInlineInvokePlugins()) { |
|
2134 |
InlineInfo inlineInfo = plugin.shouldInlineInvoke(this, targetMethod, args); |
|
2135 |
if (inlineInfo != null) { |
|
54601 | 2136 |
if (inlineInfo.allowsInlining()) { |
43972 | 2137 |
if (inline(targetMethod, inlineInfo.getMethodToInline(), inlineInfo.getIntrinsicBytecodeProvider(), args)) { |
2138 |
return SUCCESSFULLY_INLINED; |
|
2139 |
} |
|
46509 | 2140 |
inlineInfo = null; |
43972 | 2141 |
} |
2142 |
/* Do not inline, and do not ask the remaining plugins. */ |
|
2143 |
return inlineInfo; |
|
2144 |
} |
|
2145 |
} |
|
46551 | 2146 |
|
2147 |
// There was no inline plugin with a definite answer to whether or not |
|
2148 |
// to inline. If we're parsing an intrinsic, then we need to enforce the |
|
2149 |
// invariant here that methods are always force inlined in intrinsics/snippets. |
|
2150 |
if (parsingIntrinsic()) { |
|
2151 |
if (inline(targetMethod, targetMethod, this.bytecodeProvider, args)) { |
|
2152 |
return SUCCESSFULLY_INLINED; |
|
2153 |
} |
|
2154 |
} |
|
43972 | 2155 |
return null; |
2156 |
} |
|
2157 |
||
46344 | 2158 |
private static final int ACCESSOR_BYTECODE_LENGTH = 5; |
2159 |
||
2160 |
/** |
|
2161 |
* Tries to inline {@code targetMethod} if it is an instance field accessor. This avoids the |
|
2162 |
* overhead of creating and using a nested {@link BytecodeParser} object. |
|
2163 |
*/ |
|
49451 | 2164 |
@SuppressWarnings("try") |
46344 | 2165 |
private boolean tryFastInlineAccessor(ValueNode[] args, ResolvedJavaMethod targetMethod) { |
2166 |
byte[] bytecode = targetMethod.getCode(); |
|
46807 | 2167 |
if (bytecode != null && bytecode.length == ACCESSOR_BYTECODE_LENGTH && |
46344 | 2168 |
Bytes.beU1(bytecode, 0) == ALOAD_0 && |
2169 |
Bytes.beU1(bytecode, 1) == GETFIELD) { |
|
2170 |
int b4 = Bytes.beU1(bytecode, 4); |
|
2171 |
if (b4 >= IRETURN && b4 <= ARETURN) { |
|
2172 |
int cpi = Bytes.beU2(bytecode, 2); |
|
2173 |
JavaField field = targetMethod.getConstantPool().lookupField(cpi, targetMethod, GETFIELD); |
|
2174 |
if (field instanceof ResolvedJavaField) { |
|
2175 |
ValueNode receiver = invocationPluginReceiver.init(targetMethod, args).get(); |
|
2176 |
ResolvedJavaField resolvedField = (ResolvedJavaField) field; |
|
49451 | 2177 |
try (DebugCloseable context = openNodeContext(targetMethod, 1)) { |
2178 |
genGetField(resolvedField, receiver); |
|
2179 |
notifyBeforeInline(targetMethod); |
|
2180 |
printInlining(targetMethod, targetMethod, true, "inline accessor method (bytecode parsing)"); |
|
2181 |
notifyAfterInline(targetMethod); |
|
2182 |
} |
|
46344 | 2183 |
return true; |
2184 |
} |
|
2185 |
} |
|
2186 |
} |
|
2187 |
return false; |
|
2188 |
} |
|
2189 |
||
54601 | 2190 |
/** |
2191 |
* Inline a method substitution graph. This is necessary for libgraal as substitutions only |
|
2192 |
* exist as encoded graphs and can't be parsed directly into the caller. |
|
2193 |
*/ |
|
2194 |
@Override |
|
2195 |
@SuppressWarnings("try") |
|
2196 |
public boolean intrinsify(ResolvedJavaMethod targetMethod, StructuredGraph substituteGraph, InvocationPlugin.Receiver receiver, ValueNode[] args) { |
|
2197 |
if (receiver != null) { |
|
2198 |
receiver.get(); |
|
2199 |
} |
|
2200 |
||
2201 |
InvokeWithExceptionNode withException = null; |
|
2202 |
FixedWithNextNode replacee = lastInstr; |
|
2203 |
try (DebugContext.Scope a = debug.scope("instantiate", substituteGraph)) { |
|
2204 |
// Inline the snippet nodes, replacing parameters with the given args in the process |
|
2205 |
StartNode entryPointNode = substituteGraph.start(); |
|
2206 |
FixedNode firstCFGNode = entryPointNode.next(); |
|
2207 |
StructuredGraph replaceeGraph = replacee.graph(); |
|
2208 |
Mark mark = replaceeGraph.getMark(); |
|
2209 |
try (InliningScope inlineScope = new IntrinsicScope(this, targetMethod, args)) { |
|
2210 |
||
2211 |
EconomicMap<Node, Node> replacementsMap = EconomicMap.create(Equivalence.IDENTITY); |
|
2212 |
for (ParameterNode param : substituteGraph.getNodes().filter(ParameterNode.class)) { |
|
2213 |
replacementsMap.put(param, args[param.index()]); |
|
2214 |
} |
|
2215 |
replacementsMap.put(entryPointNode, AbstractBeginNode.prevBegin(replacee)); |
|
2216 |
||
2217 |
debug.dump(DebugContext.DETAILED_LEVEL, replaceeGraph, "Before inlining method substitution %s", substituteGraph.method()); |
|
2218 |
UnmodifiableEconomicMap<Node, Node> duplicates = inlineMethodSubstitution(replaceeGraph, substituteGraph, replacementsMap); |
|
2219 |
||
2220 |
FixedNode firstCFGNodeDuplicate = (FixedNode) duplicates.get(firstCFGNode); |
|
2221 |
replacee.setNext(firstCFGNodeDuplicate); |
|
2222 |
debug.dump(DebugContext.DETAILED_LEVEL, replaceeGraph, "After inlining method substitution %s", substituteGraph.method()); |
|
2223 |
||
2224 |
// Handle partial intrinsic exits |
|
2225 |
for (Node node : graph.getNewNodes(mark)) { |
|
2226 |
if (node instanceof Invoke) { |
|
2227 |
Invoke invoke = (Invoke) node; |
|
2228 |
if (invoke.bci() == BytecodeFrame.UNKNOWN_BCI) { |
|
2229 |
invoke.replaceBci(bci()); |
|
2230 |
} |
|
2231 |
if (node instanceof InvokeWithExceptionNode) { |
|
2232 |
// The graphs for MethodSubsitutions are produced assuming that |
|
2233 |
// exceptions |
|
2234 |
// must be dispatched. If the calling context doesn't want exception |
|
2235 |
// then |
|
2236 |
// convert back into a normal InvokeNode. |
|
2237 |
assert withException == null : "only one invoke expected"; |
|
2238 |
withException = (InvokeWithExceptionNode) node; |
|
2239 |
BytecodeParser intrinsicCallSiteParser = getNonIntrinsicAncestor(); |
|
2240 |
if (intrinsicCallSiteParser != null && intrinsicCallSiteParser.getActionForInvokeExceptionEdge(null) == ExceptionEdgeAction.OMIT) { |
|
2241 |
InvokeNode newInvoke = graph.add(new InvokeNode(withException)); |
|
2242 |
newInvoke.setStateDuring(withException.stateDuring()); |
|
2243 |
newInvoke.setStateAfter(withException.stateAfter()); |
|
2244 |
withException.killExceptionEdge(); |
|
2245 |
AbstractBeginNode next = withException.killKillingBegin(); |
|
2246 |
FixedWithNextNode pred = (FixedWithNextNode) withException.predecessor(); |
|
2247 |
pred.setNext(newInvoke); |
|
2248 |
withException.setNext(null); |
|
2249 |
newInvoke.setNext(next); |
|
2250 |
withException.replaceAndDelete(newInvoke); |
|
2251 |
} else { |
|
2252 |
// Disconnnect exception edge |
|
2253 |
withException.killExceptionEdge(); |
|
2254 |
} |
|
2255 |
} |
|
2256 |
} else if (node instanceof ForeignCallNode) { |
|
2257 |
ForeignCallNode call = (ForeignCallNode) node; |
|
2258 |
if (call.getBci() == BytecodeFrame.UNKNOWN_BCI) { |
|
2259 |
call.setBci(bci()); |
|
2260 |
if (call.stateAfter() != null && call.stateAfter().bci == BytecodeFrame.INVALID_FRAMESTATE_BCI) { |
|
2261 |
call.setStateAfter(inlineScope.stateBefore); |
|
2262 |
} |
|
2263 |
} |
|
2264 |
} |
|
2265 |
} |
|
2266 |
||
2267 |
ArrayList<ReturnToCallerData> calleeReturnDataList = new ArrayList<>(); |
|
2268 |
for (ReturnNode n : substituteGraph.getNodes().filter(ReturnNode.class)) { |
|
2269 |
ReturnNode returnNode = (ReturnNode) duplicates.get(n); |
|
2270 |
FixedWithNextNode predecessor = (FixedWithNextNode) returnNode.predecessor(); |
|
2271 |
calleeReturnDataList.add(new ReturnToCallerData(returnNode.result(), predecessor)); |
|
2272 |
predecessor.setNext(null); |
|
2273 |
returnNode.safeDelete(); |
|
2274 |
} |
|
2275 |
||
2276 |
// Merge multiple returns |
|
2277 |
processCalleeReturn(targetMethod, inlineScope, calleeReturnDataList); |
|
2278 |
||
2279 |
// Exiting this scope causes processing of the placeholder frame states. |
|
2280 |
} |
|
2281 |
||
2282 |
if (withException != null && withException.isAlive()) { |
|
2283 |
// Connect exception edge into main graph |
|
2284 |
AbstractBeginNode exceptionEdge = handleException(null, bci(), false); |
|
2285 |
withException.setExceptionEdge(exceptionEdge); |
|
2286 |
} |
|
2287 |
||
2288 |
debug.dump(DebugContext.DETAILED_LEVEL, replaceeGraph, "After lowering %s with %s", replacee, this); |
|
2289 |
return true; |
|
2290 |
} catch (Throwable t) { |
|
2291 |
throw debug.handle(t); |
|
2292 |
} |
|
2293 |
} |
|
2294 |
||
2295 |
private static UnmodifiableEconomicMap<Node, Node> inlineMethodSubstitution(StructuredGraph replaceeGraph, StructuredGraph snippet, |
|
2296 |
EconomicMap<Node, Node> replacementsMap) { |
|
2297 |
try (InliningLog.UpdateScope scope = replaceeGraph.getInliningLog().openUpdateScope((oldNode, newNode) -> { |
|
2298 |
InliningLog log = replaceeGraph.getInliningLog(); |
|
2299 |
if (oldNode == null) { |
|
2300 |
log.trackNewCallsite(newNode); |
|
2301 |
} |
|
2302 |
})) { |
|
2303 |
StartNode entryPointNode = snippet.start(); |
|
2304 |
ArrayList<Node> nodes = new ArrayList<>(snippet.getNodeCount()); |
|
2305 |
for (Node node : snippet.getNodes()) { |
|
2306 |
if (node != entryPointNode && node != entryPointNode.stateAfter()) { |
|
2307 |
nodes.add(node); |
|
2308 |
} |
|
2309 |
} |
|
2310 |
UnmodifiableEconomicMap<Node, Node> duplicates = replaceeGraph.addDuplicates(nodes, snippet, snippet.getNodeCount(), replacementsMap); |
|
2311 |
if (scope != null) { |
|
2312 |
replaceeGraph.getInliningLog().addLog(duplicates, snippet.getInliningLog()); |
|
2313 |
} |
|
2314 |
return duplicates; |
|
2315 |
} |
|
2316 |
} |
|
2317 |
||
43972 | 2318 |
@Override |
2319 |
public boolean intrinsify(BytecodeProvider intrinsicBytecodeProvider, ResolvedJavaMethod targetMethod, ResolvedJavaMethod substitute, InvocationPlugin.Receiver receiver, ValueNode[] args) { |
|
2320 |
if (receiver != null) { |
|
2321 |
receiver.get(); |
|
2322 |
} |
|
2323 |
boolean res = inline(targetMethod, substitute, intrinsicBytecodeProvider, args); |
|
2324 |
assert res : "failed to inline " + substitute; |
|
2325 |
return res; |
|
2326 |
} |
|
2327 |
||
2328 |
private boolean inline(ResolvedJavaMethod targetMethod, ResolvedJavaMethod inlinedMethod, BytecodeProvider intrinsicBytecodeProvider, ValueNode[] args) { |
|
49873 | 2329 |
try (InliningLog.RootScope scope = graph.getInliningLog().openRootScope(targetMethod, bci())) { |
2330 |
IntrinsicContext intrinsic = this.intrinsicContext; |
|
2331 |
||
2332 |
if (intrinsic == null && !graphBuilderConfig.insertFullInfopoints() && |
|
2333 |
targetMethod.equals(inlinedMethod) && |
|
2334 |
(targetMethod.getModifiers() & (STATIC | SYNCHRONIZED)) == 0 && |
|
2335 |
tryFastInlineAccessor(args, targetMethod)) { |
|
43972 | 2336 |
return true; |
49873 | 2337 |
} |
2338 |
||
2339 |
if (intrinsic != null && intrinsic.isCallToOriginal(targetMethod)) { |
|
2340 |
if (intrinsic.isCompilationRoot()) { |
|
2341 |
// A root compiled intrinsic needs to deoptimize |
|
2342 |
// if the slow path is taken. During frame state |
|
2343 |
// assignment, the deopt node will get its stateBefore |
|
2344 |
// from the start node of the intrinsic |
|
2345 |
append(new DeoptimizeNode(InvalidateRecompile, RuntimeConstraint)); |
|
2346 |
printInlining(targetMethod, inlinedMethod, true, "compilation root (bytecode parsing)"); |
|
2347 |
if (scope != null) { |
|
2348 |
graph.getInliningLog().addDecision(scope.getInvoke(), true, "GraphBuilderPhase", null, null, "compilation root"); |
|
2349 |
} |
|
46459 | 2350 |
return true; |
2351 |
} else { |
|
49873 | 2352 |
if (intrinsic.getOriginalMethod().isNative()) { |
2353 |
printInlining(targetMethod, inlinedMethod, false, "native method (bytecode parsing)"); |
|
2354 |
if (scope != null) { |
|
2355 |
graph.getInliningLog().addDecision(scope.getInvoke(), false, "GraphBuilderPhase", null, null, "native method"); |
|
2356 |
} |
|
2357 |
return false; |
|
2358 |
} |
|
54328 | 2359 |
if (canInlinePartialIntrinsicExit()) { |
49873 | 2360 |
// Otherwise inline the original method. Any frame state created |
2361 |
// during the inlining will exclude frame(s) in the |
|
2362 |
// intrinsic method (see FrameStateBuilder.create(int bci)). |
|
2363 |
notifyBeforeInline(inlinedMethod); |
|
2364 |
printInlining(targetMethod, inlinedMethod, true, "partial intrinsic exit (bytecode parsing)"); |
|
2365 |
if (scope != null) { |
|
2366 |
graph.getInliningLog().addDecision(scope.getInvoke(), true, "GraphBuilderPhase", null, null, "partial intrinsic exit"); |
|
2367 |
} |
|
2368 |
parseAndInlineCallee(intrinsic.getOriginalMethod(), args, null); |
|
2369 |
notifyAfterInline(inlinedMethod); |
|
2370 |
return true; |
|
2371 |
} else { |
|
2372 |
printInlining(targetMethod, inlinedMethod, false, "partial intrinsic exit (bytecode parsing)"); |
|
2373 |
if (scope != null) { |
|
2374 |
graph.getInliningLog().addDecision(scope.getInvoke(), false, "GraphBuilderPhase", null, null, "partial intrinsic exit"); |
|
2375 |
} |
|
2376 |
return false; |
|
2377 |
} |
|
2378 |
} |
|
2379 |
} else { |
|
2380 |
boolean isIntrinsic = intrinsicBytecodeProvider != null; |
|
2381 |
if (intrinsic == null && isIntrinsic) { |
|
2382 |
assert !inlinedMethod.equals(targetMethod); |
|
2383 |
intrinsic = new IntrinsicContext(targetMethod, inlinedMethod, intrinsicBytecodeProvider, INLINE_DURING_PARSING); |
|
2384 |
} |
|
2385 |
if (inlinedMethod.hasBytecodes()) { |
|
2386 |
notifyBeforeInline(inlinedMethod); |
|
2387 |
printInlining(targetMethod, inlinedMethod, true, "inline method (bytecode parsing)"); |
|
2388 |
if (scope != null) { |
|
2389 |
graph.getInliningLog().addDecision(scope.getInvoke(), true, "GraphBuilderPhase", null, null, "inline method"); |
|
2390 |
} |
|
2391 |
parseAndInlineCallee(inlinedMethod, args, intrinsic); |
|
2392 |
notifyAfterInline(inlinedMethod); |
|
2393 |
} else { |
|
2394 |
printInlining(targetMethod, inlinedMethod, false, "no bytecodes (abstract or native) (bytecode parsing)"); |
|
2395 |
if (scope != null) { |
|
2396 |
graph.getInliningLog().addDecision(scope.getInvoke(), false, "GraphBuilderPhase", null, null, "no bytecodes (abstract or native)"); |
|
2397 |
} |
|
46459 | 2398 |
return false; |
2399 |
} |
|
43972 | 2400 |
} |
49873 | 2401 |
return true; |
2402 |
} |
|
43972 | 2403 |
} |
2404 |
||
46459 | 2405 |
protected void notifyBeforeInline(ResolvedJavaMethod inlinedMethod) { |
2406 |
for (InlineInvokePlugin plugin : graphBuilderConfig.getPlugins().getInlineInvokePlugins()) { |
|
2407 |
plugin.notifyBeforeInline(inlinedMethod); |
|
46344 | 2408 |
} |
2409 |
} |
|
2410 |
||
46459 | 2411 |
protected void notifyAfterInline(ResolvedJavaMethod inlinedMethod) { |
2412 |
for (InlineInvokePlugin plugin : graphBuilderConfig.getPlugins().getInlineInvokePlugins()) { |
|
2413 |
plugin.notifyAfterInline(inlinedMethod); |
|
2414 |
} |
|
2415 |
} |
|
2416 |
||
2417 |
/** |
|
2418 |
* Determines if a partial intrinsic exit (i.e., a call to the original method within an |
|
46509 | 2419 |
* intrinsic) can be inlined. |
46459 | 2420 |
*/ |
46509 | 2421 |
protected boolean canInlinePartialIntrinsicExit() { |
54328 | 2422 |
return InlinePartialIntrinsicExitDuringParsing.getValue(options) && !IS_BUILDING_NATIVE_IMAGE && method.getAnnotation(Snippet.class) == null; |
46459 | 2423 |
} |
2424 |
||
43972 | 2425 |
private void printInlining(ResolvedJavaMethod targetMethod, ResolvedJavaMethod inlinedMethod, boolean success, String msg) { |
46459 | 2426 |
if (success) { |
2427 |
if (TraceInlineDuringParsing.getValue(options) || TraceParserPlugins.getValue(options)) { |
|
2428 |
if (targetMethod.equals(inlinedMethod)) { |
|
2429 |
traceWithContext("inlining call to %s", inlinedMethod.format("%h.%n(%p)")); |
|
2430 |
} else { |
|
2431 |
traceWithContext("inlining call to %s as intrinsic for %s", inlinedMethod.format("%h.%n(%p)"), targetMethod.format("%h.%n(%p)")); |
|
2432 |
} |
|
2433 |
} |
|
2434 |
} |
|
46344 | 2435 |
if (HotSpotPrintInlining.getValue(options)) { |
43972 | 2436 |
if (targetMethod.equals(inlinedMethod)) { |
2437 |
Util.printInlining(inlinedMethod, bci(), getDepth(), success, "%s", msg); |
|
2438 |
} else { |
|
2439 |
Util.printInlining(inlinedMethod, bci(), getDepth(), success, "%s intrinsic for %s", msg, targetMethod.format("%h.%n(%p)")); |
|
2440 |
} |
|
2441 |
} |
|
2442 |
} |
|
2443 |
||
2444 |
/** |
|
2445 |
* Prints a line to {@link TTY} with a prefix indicating the current parse context. The prefix |
|
2446 |
* is of the form: |
|
2447 |
* |
|
2448 |
* <pre> |
|
2449 |
* {SPACE * n} {name of method being parsed} "(" {file name} ":" {line number} ")" |
|
2450 |
* </pre> |
|
2451 |
* |
|
2452 |
* where {@code n} is the current inlining depth. |
|
2453 |
* |
|
2454 |
* @param format a format string |
|
2455 |
* @param args arguments to the format string |
|
2456 |
*/ |
|
2457 |
||
2458 |
protected void traceWithContext(String format, Object... args) { |
|
2459 |
StackTraceElement where = code.asStackTraceElement(bci()); |
|
46459 | 2460 |
String s = format("%s%s (%s:%d) %s", nSpaces(getDepth()), method.isConstructor() ? method.format("%h.%n") : method.getName(), where.getFileName(), where.getLineNumber(), |
2461 |
format(format, args)); |
|
2462 |
TTY.println(s); |
|
43972 | 2463 |
} |
2464 |
||
47667 | 2465 |
protected RuntimeException throwParserError(Throwable e) { |
43972 | 2466 |
if (e instanceof BytecodeParserError) { |
47667 | 2467 |
throw (BytecodeParserError) e; |
43972 | 2468 |
} |
2469 |
BytecodeParser bp = this; |
|
2470 |
BytecodeParserError res = new BytecodeParserError(e); |
|
2471 |
while (bp != null) { |
|
2472 |
res.addContext("parsing " + bp.code.asStackTraceElement(bp.bci())); |
|
2473 |
bp = bp.parent; |
|
2474 |
} |
|
47667 | 2475 |
throw res; |
43972 | 2476 |
} |
2477 |
||
2478 |
protected void parseAndInlineCallee(ResolvedJavaMethod targetMethod, ValueNode[] args, IntrinsicContext calleeIntrinsicContext) { |
|
48861 | 2479 |
FixedWithNextNode calleeBeforeUnwindNode = null; |
2480 |
ValueNode calleeUnwindValue = null; |
|
2481 |
||
55509 | 2482 |
try (InliningScope s = parsingIntrinsic() ? null |
2483 |
: (calleeIntrinsicContext != null ? new IntrinsicScope(this, targetMethod, args) |
|
2484 |
: new InliningScope(this, targetMethod, args))) { |
|
43972 | 2485 |
BytecodeParser parser = graphBuilderInstance.createBytecodeParser(graph, this, targetMethod, INVOCATION_ENTRY_BCI, calleeIntrinsicContext); |
54328 | 2486 |
FrameStateBuilder startFrameState = new FrameStateBuilder(parser, parser.code, graph, graphBuilderConfig.retainLocalVariables()); |
43972 | 2487 |
if (!targetMethod.isStatic()) { |
2488 |
args[0] = nullCheckedValue(args[0]); |
|
2489 |
} |
|
2490 |
startFrameState.initializeFromArgumentsArray(args); |
|
2491 |
parser.build(this.lastInstr, startFrameState); |
|
2492 |
||
54601 | 2493 |
List<ReturnToCallerData> calleeReturnDataList = parser.returnDataList; |
2494 |
||
46807 | 2495 |
/* |
2496 |
* Propagate any side effects into the caller when parsing intrinsics. |
|
2497 |
*/ |
|
2498 |
if (parser.frameState.isAfterSideEffect() && parsingIntrinsic()) { |
|
2499 |
for (StateSplit sideEffect : parser.frameState.sideEffects()) { |
|
2500 |
frameState.addSideEffect(sideEffect); |
|
2501 |
} |
|
2502 |
} |
|
43972 | 2503 |
|
55509 | 2504 |
processCalleeReturn(targetMethod, s, calleeReturnDataList); |
2505 |
||
48861 | 2506 |
calleeBeforeUnwindNode = parser.getBeforeUnwindNode(); |
43972 | 2507 |
if (calleeBeforeUnwindNode != null) { |
48861 | 2508 |
calleeUnwindValue = parser.getUnwindValue(); |
43972 | 2509 |
assert calleeUnwindValue != null; |
2510 |
} |
|
2511 |
} |
|
48861 | 2512 |
|
2513 |
/* |
|
2514 |
* Method handleException will call createTarget, which wires this exception edge to the |
|
2515 |
* corresponding exception dispatch block in the caller. In the case where it wires to the |
|
2516 |
* caller's unwind block, any FrameState created meanwhile, e.g., FrameState for |
|
2517 |
* LoopExitNode, would be instantiated with AFTER_EXCEPTION_BCI. Such frame states should |
|
2518 |
* not be fixed by IntrinsicScope.close, as they denote the states of the caller. Thus, the |
|
2519 |
* following code should be placed outside the IntrinsicScope, so that correctly created |
|
2520 |
* FrameStates are not replaced. |
|
2521 |
*/ |
|
2522 |
if (calleeBeforeUnwindNode != null) { |
|
2523 |
calleeBeforeUnwindNode.setNext(handleException(calleeUnwindValue, bci(), false)); |
|
2524 |
} |
|
43972 | 2525 |
} |
2526 |
||
54601 | 2527 |
private ValueNode processCalleeReturn(ResolvedJavaMethod targetMethod, InliningScope inliningScope, List<ReturnToCallerData> calleeReturnDataList) { |
2528 |
if (calleeReturnDataList == null) { |
|
2529 |
/* Callee does not return. */ |
|
2530 |
lastInstr = null; |
|
2531 |
} else { |
|
2532 |
ValueNode calleeReturnValue; |
|
2533 |
MergeNode returnMergeNode = null; |
|
2534 |
if (inliningScope != null) { |
|
2535 |
inliningScope.returnDataList = calleeReturnDataList; |
|
2536 |
} |
|
2537 |
if (calleeReturnDataList.size() == 1) { |
|
2538 |
/* Callee has a single return, we can continue parsing at that point. */ |
|
2539 |
ReturnToCallerData singleReturnData = calleeReturnDataList.get(0); |
|
2540 |
lastInstr = singleReturnData.beforeReturnNode; |
|
2541 |
calleeReturnValue = singleReturnData.returnValue; |
|
2542 |
} else { |
|
2543 |
assert calleeReturnDataList.size() > 1; |
|
2544 |
/* Callee has multiple returns, we need to insert a control flow merge. */ |
|
2545 |
returnMergeNode = graph.add(new MergeNode()); |
|
2546 |
calleeReturnValue = ValueMergeUtil.mergeValueProducers(returnMergeNode, calleeReturnDataList, returnData -> returnData.beforeReturnNode, returnData -> returnData.returnValue); |
|
2547 |
} |
|
2548 |
||
2549 |
if (calleeReturnValue != null) { |
|
2550 |
frameState.push(targetMethod.getSignature().getReturnKind().getStackKind(), calleeReturnValue); |
|
2551 |
} |
|
2552 |
if (returnMergeNode != null) { |
|
2553 |
returnMergeNode.setStateAfter(createFrameState(stream.nextBCI(), returnMergeNode)); |
|
2554 |
lastInstr = finishInstruction(returnMergeNode, frameState); |
|
2555 |
} |
|
2556 |
return calleeReturnValue; |
|
2557 |
} |
|
2558 |
return null; |
|
2559 |
} |
|
2560 |
||
43972 | 2561 |
public MethodCallTargetNode createMethodCallTarget(InvokeKind invokeKind, ResolvedJavaMethod targetMethod, ValueNode[] args, StampPair returnStamp, JavaTypeProfile profile) { |
2562 |
return new MethodCallTargetNode(invokeKind, targetMethod, args, returnStamp, profile); |
|
2563 |
} |
|
2564 |
||
46459 | 2565 |
protected InvokeNode createInvoke(int invokeBci, CallTargetNode callTarget, JavaKind resultType) { |
2566 |
InvokeNode invoke = append(new InvokeNode(callTarget, invokeBci)); |
|
43972 | 2567 |
frameState.pushReturn(resultType, invoke); |
2568 |
invoke.setStateAfter(createFrameState(stream.nextBCI(), invoke)); |
|
2569 |
return invoke; |
|
2570 |
} |
|
2571 |
||
47798 | 2572 |
protected InvokeWithExceptionNode createInvokeWithException(int invokeBci, CallTargetNode callTarget, JavaKind resultType, ExceptionEdgeAction exceptionEdgeAction) { |
43972 | 2573 |
if (currentBlock != null && stream.nextBCI() > currentBlock.endBci) { |
2574 |
/* |
|
2575 |
* Clear non-live locals early so that the exception handler entry gets the cleared |
|
2576 |
* state. |
|
2577 |
*/ |
|
2578 |
frameState.clearNonLiveLocals(currentBlock, liveness, false); |
|
2579 |
} |
|
2580 |
||
47798 | 2581 |
AbstractBeginNode exceptionEdge = handleException(null, bci(), exceptionEdgeAction == ExceptionEdgeAction.INCLUDE_AND_DEOPTIMIZE); |
46509 | 2582 |
InvokeWithExceptionNode invoke = append(new InvokeWithExceptionNode(callTarget, exceptionEdge, invokeBci)); |
43972 | 2583 |
frameState.pushReturn(resultType, invoke); |
2584 |
invoke.setStateAfter(createFrameState(stream.nextBCI(), invoke)); |
|
2585 |
return invoke; |
|
2586 |
} |
|
2587 |
||
2588 |
protected void genReturn(ValueNode returnVal, JavaKind returnKind) { |
|
2589 |
if (parsingIntrinsic() && returnVal != null) { |
|
54084 | 2590 |
|
43972 | 2591 |
if (returnVal instanceof StateSplit) { |
2592 |
StateSplit stateSplit = (StateSplit) returnVal; |
|
2593 |
FrameState stateAfter = stateSplit.stateAfter(); |
|
2594 |
if (stateSplit.hasSideEffect()) { |
|
2595 |
assert stateSplit != null; |
|
2596 |
if (stateAfter.bci == BytecodeFrame.AFTER_BCI) { |
|
55509 | 2597 |
assert stateAfter.hasExactlyOneUsage(); |
43972 | 2598 |
assert stateAfter.usages().first() == stateSplit; |
54084 | 2599 |
FrameState state; |
2600 |
if (returnVal.getStackKind() == JavaKind.Illegal) { |
|
2601 |
// This should only occur when Fold and NodeIntrinsic plugins are |
|
2602 |
// deferred. Their return value might not be a Java type and in that |
|
2603 |
// case this can't be the final AFTER_BCI so just create a FrameState |
|
2604 |
// without a return value on the top of stack. |
|
2605 |
assert stateSplit instanceof Invoke; |
|
2606 |
ResolvedJavaMethod targetMethod = ((Invoke) stateSplit).getTargetMethod(); |
|
2607 |
assert targetMethod != null && (targetMethod.getAnnotation(Fold.class) != null || targetMethod.getAnnotation(Node.NodeIntrinsic.class) != null); |
|
2608 |
state = new FrameState(BytecodeFrame.AFTER_BCI); |
|
2609 |
} else { |
|
2610 |
state = new FrameState(BytecodeFrame.AFTER_BCI, returnVal); |
|
2611 |
} |
|
2612 |
stateAfter.replaceAtUsages(graph.add(state)); |
|
43972 | 2613 |
GraphUtil.killWithUnusedFloatingInputs(stateAfter); |
2614 |
} else { |
|
2615 |
/* |
|
2616 |
* This must be the return value from within a partial intrinsification. |
|
2617 |
*/ |
|
54601 | 2618 |
assert !BytecodeFrame.isPlaceholderBci(stateAfter.bci) || intrinsicContext.isDeferredInvoke(stateSplit); |
43972 | 2619 |
} |
2620 |
} else { |
|
2621 |
assert stateAfter == null; |
|
2622 |
} |
|
2623 |
} |
|
2624 |
} |
|
46393 | 2625 |
|
47798 | 2626 |
ValueNode realReturnVal = processReturnValue(returnVal, returnKind); |
2627 |
||
46393 | 2628 |
frameState.setRethrowException(false); |
2629 |
frameState.clearStack(); |
|
47798 | 2630 |
beforeReturn(realReturnVal, returnKind); |
43972 | 2631 |
if (parent == null) { |
47798 | 2632 |
append(new ReturnNode(realReturnVal)); |
43972 | 2633 |
} else { |
46393 | 2634 |
if (returnDataList == null) { |
2635 |
returnDataList = new ArrayList<>(); |
|
43972 | 2636 |
} |
47798 | 2637 |
returnDataList.add(new ReturnToCallerData(realReturnVal, lastInstr)); |
46393 | 2638 |
lastInstr = null; |
43972 | 2639 |
} |
2640 |
} |
|
2641 |
||
47798 | 2642 |
private ValueNode processReturnValue(ValueNode value, JavaKind kind) { |
2643 |
JavaKind returnKind = method.getSignature().getReturnKind(); |
|
2644 |
if (kind != returnKind) { |
|
2645 |
// sub-word integer |
|
2646 |
assert returnKind.isNumericInteger() && returnKind.getStackKind() == JavaKind.Int; |
|
48190 | 2647 |
IntegerStamp stamp = (IntegerStamp) value.stamp(NodeView.DEFAULT); |
47798 | 2648 |
|
2649 |
// the bytecode verifier doesn't check that the value is in the correct range |
|
2650 |
if (stamp.lowerBound() < returnKind.getMinValue() || returnKind.getMaxValue() < stamp.upperBound()) { |
|
50609 | 2651 |
return maskSubWordValue(value, returnKind); |
47798 | 2652 |
} |
2653 |
} |
|
2654 |
||
2655 |
return value; |
|
2656 |
} |
|
2657 |
||
43972 | 2658 |
private void beforeReturn(ValueNode x, JavaKind kind) { |
2659 |
if (graph.method() != null && graph.method().isJavaLangObjectInit()) { |
|
2660 |
/* |
|
2661 |
* Get the receiver from the initial state since bytecode rewriting could do arbitrary |
|
2662 |
* things to the state of the locals. |
|
2663 |
*/ |
|
2664 |
ValueNode receiver = graph.start().stateAfter().localAt(0); |
|
2665 |
assert receiver != null && receiver.getStackKind() == JavaKind.Object; |
|
2666 |
if (RegisterFinalizerNode.mayHaveFinalizer(receiver, graph.getAssumptions())) { |
|
2667 |
append(new RegisterFinalizerNode(receiver)); |
|
2668 |
} |
|
2669 |
} |
|
2670 |
genInfoPointNode(InfopointReason.METHOD_END, x); |
|
2671 |
if (finalBarrierRequired) { |
|
2672 |
assert originalReceiver != null; |
|
46344 | 2673 |
/* |
2674 |
* When compiling an OSR with a final field store, don't bother tracking the original |
|
2675 |
* receiver since the receiver cannot be EA'ed. |
|
2676 |
*/ |
|
2677 |
append(new FinalFieldBarrierNode(entryBCI == INVOCATION_ENTRY_BCI ? originalReceiver : null)); |
|
43972 | 2678 |
} |
2679 |
synchronizedEpilogue(BytecodeFrame.AFTER_BCI, x, kind); |
|
54601 | 2680 |
if (method.isSynchronized()) { |
2681 |
finishPrepare(lastInstr, BytecodeFrame.AFTER_BCI, frameState); |
|
2682 |
} |
|
43972 | 2683 |
} |
2684 |
||
2685 |
protected MonitorEnterNode createMonitorEnterNode(ValueNode x, MonitorIdNode monitorId) { |
|
2686 |
return new MonitorEnterNode(x, monitorId); |
|
2687 |
} |
|
2688 |
||
2689 |
protected void genMonitorEnter(ValueNode x, int bci) { |
|
2690 |
MonitorIdNode monitorId = graph.add(new MonitorIdNode(frameState.lockDepth(true))); |
|
2691 |
MonitorEnterNode monitorEnter = append(createMonitorEnterNode(x, monitorId)); |
|
2692 |
frameState.pushLock(x, monitorId); |
|
2693 |
monitorEnter.setStateAfter(createFrameState(bci, monitorEnter)); |
|
2694 |
} |
|
2695 |
||
54601 | 2696 |
protected void genMonitorExit(ValueNode x, ValueNode escapedValue, int bci) { |
43972 | 2697 |
if (frameState.lockDepth(false) == 0) { |
2698 |
throw bailout("unbalanced monitors: too many exits"); |
|
2699 |
} |
|
2700 |
MonitorIdNode monitorId = frameState.peekMonitorId(); |
|
2701 |
ValueNode lockedObject = frameState.popLock(); |
|
2702 |
if (GraphUtil.originalValue(lockedObject) != GraphUtil.originalValue(x)) { |
|
2703 |
throw bailout(String.format("unbalanced monitors: mismatch at monitorexit, %s != %s", GraphUtil.originalValue(x), GraphUtil.originalValue(lockedObject))); |
|
2704 |
} |
|
54601 | 2705 |
MonitorExitNode monitorExit = append(new MonitorExitNode(lockedObject, monitorId, escapedValue)); |
43972 | 2706 |
monitorExit.setStateAfter(createFrameState(bci, monitorExit)); |
2707 |
} |
|
2708 |
||
2709 |
protected void genJsr(int dest) { |
|
2710 |
BciBlock successor = currentBlock.getJsrSuccessor(); |
|
2711 |
assert successor.startBci == dest : successor.startBci + " != " + dest + " @" + bci(); |
|
2712 |
JsrScope scope = currentBlock.getJsrScope(); |
|
2713 |
int nextBci = getStream().nextBCI(); |
|
2714 |
if (!successor.getJsrScope().pop().equals(scope)) { |
|
2715 |
throw new JsrNotSupportedBailout("unstructured control flow (internal limitation)"); |
|
2716 |
} |
|
2717 |
if (successor.getJsrScope().nextReturnAddress() != nextBci) { |
|
2718 |
throw new JsrNotSupportedBailout("unstructured control flow (internal limitation)"); |
|
2719 |
} |
|
2720 |
ConstantNode nextBciNode = getJsrConstant(nextBci); |
|
2721 |
frameState.push(JavaKind.Object, nextBciNode); |
|
2722 |
appendGoto(successor); |
|
2723 |
} |
|
2724 |
||
2725 |
protected void genRet(int localIndex) { |
|
2726 |
BciBlock successor = currentBlock.getRetSuccessor(); |
|
2727 |
ValueNode local = frameState.loadLocal(localIndex, JavaKind.Object); |
|
2728 |
JsrScope scope = currentBlock.getJsrScope(); |
|
2729 |
int retAddress = scope.nextReturnAddress(); |
|
2730 |
ConstantNode returnBciNode = getJsrConstant(retAddress); |
|
54328 | 2731 |
LogicNode guard = IntegerEqualsNode.create(getConstantReflection(), getMetaAccess(), options, null, local, returnBciNode, NodeView.DEFAULT); |
46371 | 2732 |
guard = graph.addOrUniqueWithInputs(guard); |
43972 | 2733 |
append(new FixedGuardNode(guard, JavaSubroutineMismatch, InvalidateReprofile)); |
2734 |
if (!successor.getJsrScope().equals(scope.pop())) { |
|
2735 |
throw new JsrNotSupportedBailout("unstructured control flow (ret leaves more than one scope)"); |
|
2736 |
} |
|
2737 |
appendGoto(successor); |
|
2738 |
} |
|
2739 |
||
2740 |
private ConstantNode getJsrConstant(long bci) { |
|
2741 |
JavaConstant nextBciConstant = new RawConstant(bci); |
|
2742 |
Stamp nextBciStamp = StampFactory.forConstant(nextBciConstant); |
|
2743 |
ConstantNode nextBciNode = new ConstantNode(nextBciConstant, nextBciStamp); |
|
2744 |
return graph.unique(nextBciNode); |
|
2745 |
} |
|
2746 |
||
2747 |
protected void genIntegerSwitch(ValueNode value, ArrayList<BciBlock> actualSuccessors, int[] keys, double[] keyProbabilities, int[] keySuccessors) { |
|
2748 |
if (value.isConstant()) { |
|
2749 |
JavaConstant constant = (JavaConstant) value.asConstant(); |
|
2750 |
int constantValue = constant.asInt(); |
|
2751 |
for (int i = 0; i < keys.length; ++i) { |
|
2752 |
if (keys[i] == constantValue) { |
|
2753 |
appendGoto(actualSuccessors.get(keySuccessors[i])); |
|
2754 |
return; |
|
2755 |
} |
|
2756 |
} |
|
2757 |
appendGoto(actualSuccessors.get(keySuccessors[keys.length])); |
|
2758 |
} else { |
|
2759 |
this.controlFlowSplit = true; |
|
2760 |
double[] successorProbabilities = successorProbabilites(actualSuccessors.size(), keySuccessors, keyProbabilities); |
|
2761 |
IntegerSwitchNode switchNode = append(new IntegerSwitchNode(value, actualSuccessors.size(), keys, keyProbabilities, keySuccessors)); |
|
2762 |
for (int i = 0; i < actualSuccessors.size(); i++) { |
|
2763 |
switchNode.setBlockSuccessor(i, createBlockTarget(successorProbabilities[i], actualSuccessors.get(i), frameState)); |
|
2764 |
} |
|
2765 |
} |
|
2766 |
} |
|
2767 |
||
2768 |
/** |
|
2769 |
* Helper function that sums up the probabilities of all keys that lead to a specific successor. |
|
2770 |
* |
|
2771 |
* @return an array of size successorCount with the accumulated probability for each successor. |
|
2772 |
*/ |
|
2773 |
private static double[] successorProbabilites(int successorCount, int[] keySuccessors, double[] keyProbabilities) { |
|
2774 |
double[] probability = new double[successorCount]; |
|
2775 |
for (int i = 0; i < keySuccessors.length; i++) { |
|
2776 |
probability[keySuccessors[i]] += keyProbabilities[i]; |
|
2777 |
} |
|
2778 |
return probability; |
|
2779 |
} |
|
2780 |
||
2781 |
protected ConstantNode appendConstant(JavaConstant constant) { |
|
2782 |
assert constant != null; |
|
54328 | 2783 |
return ConstantNode.forConstant(constant, getMetaAccess(), graph); |
43972 | 2784 |
} |
2785 |
||
2786 |
@Override |
|
2787 |
public <T extends ValueNode> T append(T v) { |
|
49451 | 2788 |
assert !graph.trackNodeSourcePosition() || graph.currentNodeSourcePosition() != null || currentBlock == blockMap.getUnwindBlock() || currentBlock instanceof ExceptionDispatchBlock; |
43972 | 2789 |
if (v.graph() != null) { |
2790 |
return v; |
|
2791 |
} |
|
2792 |
T added = graph.addOrUniqueWithInputs(v); |
|
2793 |
if (added == v) { |
|
2794 |
updateLastInstruction(v); |
|
2795 |
} |
|
2796 |
return added; |
|
2797 |
} |
|
2798 |
||
2799 |
private <T extends ValueNode> void updateLastInstruction(T v) { |
|
2800 |
if (v instanceof FixedNode) { |
|
2801 |
FixedNode fixedNode = (FixedNode) v; |
|
50858 | 2802 |
if (lastInstr != null) { |
2803 |
lastInstr.setNext(fixedNode); |
|
2804 |
} |
|
43972 | 2805 |
if (fixedNode instanceof FixedWithNextNode) { |
2806 |
FixedWithNextNode fixedWithNextNode = (FixedWithNextNode) fixedNode; |
|
2807 |
assert fixedWithNextNode.next() == null : "cannot append instruction to instruction which isn't end"; |
|
2808 |
lastInstr = fixedWithNextNode; |
|
2809 |
} else { |
|
2810 |
lastInstr = null; |
|
2811 |
} |
|
2812 |
} |
|
2813 |
} |
|
2814 |
||
54601 | 2815 |
private Target checkLoopExit(Target target, BciBlock targetBlock) { |
43972 | 2816 |
if (currentBlock != null) { |
2817 |
long exits = currentBlock.loops & ~targetBlock.loops; |
|
2818 |
if (exits != 0) { |
|
2819 |
LoopExitNode firstLoopExit = null; |
|
2820 |
LoopExitNode lastLoopExit = null; |
|
2821 |
||
2822 |
int pos = 0; |
|
2823 |
ArrayList<BciBlock> exitLoops = new ArrayList<>(Long.bitCount(exits)); |
|
2824 |
do { |
|
2825 |
long lMask = 1L << pos; |
|
2826 |
if ((exits & lMask) != 0) { |
|
2827 |
exitLoops.add(blockMap.getLoopHeader(pos)); |
|
2828 |
exits &= ~lMask; |
|
2829 |
} |
|
2830 |
pos++; |
|
2831 |
} while (exits != 0); |
|
2832 |
||
2833 |
Collections.sort(exitLoops, new Comparator<BciBlock>() { |
|
2834 |
||
2835 |
@Override |
|
2836 |
public int compare(BciBlock o1, BciBlock o2) { |
|
2837 |
return Long.bitCount(o2.loops) - Long.bitCount(o1.loops); |
|
2838 |
} |
|
2839 |
}); |
|
2840 |
||
2841 |
int bci = targetBlock.startBci; |
|
2842 |
if (targetBlock instanceof ExceptionDispatchBlock) { |
|
2843 |
bci = ((ExceptionDispatchBlock) targetBlock).deoptBci; |
|
2844 |
} |
|
54601 | 2845 |
FrameStateBuilder newState = target.state.copy(); |
43972 | 2846 |
for (BciBlock loop : exitLoops) { |
2847 |
LoopBeginNode loopBegin = (LoopBeginNode) getFirstInstruction(loop); |
|
2848 |
LoopExitNode loopExit = graph.add(new LoopExitNode(loopBegin)); |
|
2849 |
if (lastLoopExit != null) { |
|
2850 |
lastLoopExit.setNext(loopExit); |
|
2851 |
} |
|
2852 |
if (firstLoopExit == null) { |
|
2853 |
firstLoopExit = loopExit; |
|
2854 |
} |
|
2855 |
lastLoopExit = loopExit; |
|
46640 | 2856 |
debug.log("Target %s Exits %s, scanning framestates...", targetBlock, loop); |
43972 | 2857 |
newState.clearNonLiveLocals(targetBlock, liveness, true); |
2858 |
newState.insertLoopProxies(loopExit, getEntryState(loop)); |
|
2859 |
loopExit.setStateAfter(newState.create(bci, loopExit)); |
|
2860 |
} |
|
2861 |
||
54601 | 2862 |
// Fortify: Suppress Null Dereference false positive |
2863 |
assert lastLoopExit != null; |
|
2864 |
||
2865 |
if (target.originalEntry == null) { |
|
2866 |
lastLoopExit.setNext(target.entry); |
|
2867 |
return new Target(firstLoopExit, newState, target.entry); |
|
2868 |
} else { |
|
2869 |
target.originalEntry.replaceAtPredecessor(firstLoopExit); |
|
2870 |
lastLoopExit.setNext(target.originalEntry); |
|
2871 |
return new Target(target.entry, newState, target.originalEntry); |
|
2872 |
} |
|
43972 | 2873 |
} |
2874 |
} |
|
54601 | 2875 |
return target; |
2876 |
} |
|
2877 |
||
2878 |
private Target checkUnwind(FixedNode target, BciBlock targetBlock, FrameStateBuilder state) { |
|
2879 |
if (targetBlock != blockMap.getUnwindBlock()) { |
|
2880 |
return new Target(target, state); |
|
2881 |
} |
|
2882 |
FrameStateBuilder newState = state; |
|
2883 |
newState = newState.copy(); |
|
2884 |
newState.setRethrowException(false); |
|
2885 |
if (!method.isSynchronized()) { |
|
2886 |
return new Target(target, newState); |
|
2887 |
} |
|
2888 |
FixedWithNextNode originalLast = lastInstr; |
|
2889 |
FrameStateBuilder originalState = frameState; |
|
2890 |
BeginNode holder = new BeginNode(); |
|
2891 |
lastInstr = graph.add(holder); |
|
2892 |
frameState = newState; |
|
2893 |
assert frameState.stackSize() == 1; |
|
2894 |
ValueNode exception = frameState.peekObject(); |
|
2895 |
synchronizedEpilogue(BytecodeFrame.AFTER_EXCEPTION_BCI, exception, JavaKind.Void); |
|
2896 |
lastInstr.setNext(target); |
|
2897 |
||
2898 |
lastInstr = originalLast; |
|
2899 |
frameState = originalState; |
|
2900 |
||
2901 |
FixedNode result = holder.next(); |
|
2902 |
holder.setNext(null); |
|
2903 |
holder.safeDelete(); |
|
2904 |
return new Target(result, newState, target); |
|
43972 | 2905 |
} |
2906 |
||
2907 |
private FrameStateBuilder getEntryState(BciBlock block) { |
|
2908 |
return entryStateArray[block.id]; |
|
2909 |
} |
|
2910 |
||
2911 |
private void setEntryState(BciBlock block, FrameStateBuilder entryState) { |
|
2912 |
this.entryStateArray[block.id] = entryState; |
|
2913 |
} |
|
2914 |
||
2915 |
private void setFirstInstruction(BciBlock block, FixedWithNextNode firstInstruction) { |
|
2916 |
this.firstInstructionArray[block.id] = firstInstruction; |
|
2917 |
} |
|
2918 |
||
2919 |
private FixedWithNextNode getFirstInstruction(BciBlock block) { |
|
2920 |
return firstInstructionArray[block.id]; |
|
2921 |
} |
|
2922 |
||
2923 |
private FixedNode createTarget(double probability, BciBlock block, FrameStateBuilder stateAfter) { |
|
2924 |
assert probability >= 0 && probability <= 1.01 : probability; |
|
2925 |
if (isNeverExecutedCode(probability)) { |
|
2926 |
return graph.add(new DeoptimizeNode(InvalidateReprofile, UnreachedCode)); |
|
2927 |
} else { |
|
2928 |
assert block != null; |
|
2929 |
return createTarget(block, stateAfter); |
|
2930 |
} |
|
2931 |
} |
|
2932 |
||
2933 |
private FixedNode createTarget(BciBlock block, FrameStateBuilder state) { |
|
2934 |
return createTarget(block, state, false, false); |
|
2935 |
} |
|
2936 |
||
49451 | 2937 |
@SuppressWarnings("try") |
43972 | 2938 |
private FixedNode createTarget(BciBlock block, FrameStateBuilder state, boolean canReuseInstruction, boolean canReuseState) { |
2939 |
assert block != null && state != null; |
|
49873 | 2940 |
assert !block.isExceptionEntry() || state.stackSize() == 1; |
43972 | 2941 |
|
49451 | 2942 |
try (DebugCloseable context = openNodeContext(state, block.startBci)) { |
2943 |
if (getFirstInstruction(block) == null) { |
|
2944 |
/* |
|
2945 |
* This is the first time we see this block as a branch target. Create and return a |
|
2946 |
* placeholder that later can be replaced with a MergeNode when we see this block |
|
2947 |
* again. |
|
2948 |
*/ |
|
49873 | 2949 |
if (canReuseInstruction && (block.getPredecessorCount() == 1 || !controlFlowSplit) && !block.isLoopHeader() && (currentBlock.loops & ~block.loops) == 0) { |
49451 | 2950 |
setFirstInstruction(block, lastInstr); |
2951 |
lastInstr = null; |
|
2952 |
} else { |
|
2953 |
setFirstInstruction(block, graph.add(new BeginNode())); |
|
2954 |
} |
|
54601 | 2955 |
Target target = checkUnwind(getFirstInstruction(block), block, state); |
2956 |
target = checkLoopExit(target, block); |
|
2957 |
FixedNode result = target.entry; |
|
49451 | 2958 |
FrameStateBuilder currentEntryState = target.state == state ? (canReuseState ? state : state.copy()) : target.state; |
2959 |
setEntryState(block, currentEntryState); |
|
2960 |
currentEntryState.clearNonLiveLocals(block, liveness, true); |
|
2961 |
||
54601 | 2962 |
debug.log("createTarget %s: first visit, result: %s", block, result); |
49451 | 2963 |
return result; |
2964 |
} |
|
2965 |
||
2966 |
if (getFirstInstruction(block) instanceof LoopBeginNode) { |
|
49873 | 2967 |
assert (block.isLoopHeader() && currentBlock.getId() >= block.getId()) : "must be backward branch"; |
49451 | 2968 |
/* |
2969 |
* Backward loop edge. We need to create a special LoopEndNode and merge with the |
|
2970 |
* loop begin node created before. |
|
2971 |
*/ |
|
2972 |
LoopBeginNode loopBegin = (LoopBeginNode) getFirstInstruction(block); |
|
2973 |
LoopEndNode loopEnd = graph.add(new LoopEndNode(loopBegin)); |
|
54601 | 2974 |
Target target = checkLoopExit(new Target(loopEnd, state), block); |
2975 |
FixedNode result = target.entry; |
|
49451 | 2976 |
getEntryState(block).merge(loopBegin, target.state); |
2977 |
||
2978 |
debug.log("createTarget %s: merging backward branch to loop header %s, result: %s", block, loopBegin, result); |
|
2979 |
return result; |
|
2980 |
} |
|
2981 |
assert currentBlock == null || currentBlock.getId() < block.getId() : "must not be backward branch"; |
|
2982 |
assert getFirstInstruction(block).next() == null : "bytecodes already parsed for block"; |
|
2983 |
||
2984 |
if (getFirstInstruction(block) instanceof AbstractBeginNode && !(getFirstInstruction(block) instanceof AbstractMergeNode)) { |
|
2985 |
/* |
|
2986 |
* This is the second time we see this block. Create the actual MergeNode and the |
|
2987 |
* End Node for the already existing edge. |
|
2988 |
*/ |
|
2989 |
AbstractBeginNode beginNode = (AbstractBeginNode) getFirstInstruction(block); |
|
2990 |
||
2991 |
// The EndNode for the already existing edge. |
|
2992 |
EndNode end = graph.add(new EndNode()); |
|
2993 |
// The MergeNode that replaces the placeholder. |
|
2994 |
AbstractMergeNode mergeNode = graph.add(new MergeNode()); |
|
2995 |
FixedNode next = beginNode.next(); |
|
2996 |
||
2997 |
if (beginNode.predecessor() instanceof ControlSplitNode) { |
|
2998 |
beginNode.setNext(end); |
|
2999 |
} else { |
|
3000 |
beginNode.replaceAtPredecessor(end); |
|
3001 |
beginNode.safeDelete(); |
|
3002 |
} |
|
3003 |
||
3004 |
mergeNode.addForwardEnd(end); |
|
3005 |
mergeNode.setNext(next); |
|
3006 |
||
3007 |
setFirstInstruction(block, mergeNode); |
|
3008 |
} |
|
3009 |
||
3010 |
AbstractMergeNode mergeNode = (AbstractMergeNode) getFirstInstruction(block); |
|
3011 |
||
3012 |
// The EndNode for the newly merged edge. |
|
3013 |
EndNode newEnd = graph.add(new EndNode()); |
|
54601 | 3014 |
Target target = checkLoopExit(checkUnwind(newEnd, block, state), block); |
3015 |
FixedNode result = target.entry; |
|
49451 | 3016 |
getEntryState(block).merge(mergeNode, target.state); |
3017 |
mergeNode.addForwardEnd(newEnd); |
|
3018 |
||
3019 |
debug.log("createTarget %s: merging state, result: %s", block, result); |
|
43972 | 3020 |
return result; |
3021 |
} |
|
3022 |
} |
|
3023 |
||
3024 |
/** |
|
3025 |
* Returns a block begin node with the specified state. If the specified probability is 0, the |
|
3026 |
* block deoptimizes immediately. |
|
3027 |
*/ |
|
3028 |
private AbstractBeginNode createBlockTarget(double probability, BciBlock block, FrameStateBuilder stateAfter) { |
|
3029 |
FixedNode target = createTarget(probability, block, stateAfter); |
|
3030 |
AbstractBeginNode begin = BeginNode.begin(target); |
|
3031 |
||
3032 |
assert !(target instanceof DeoptimizeNode && begin instanceof BeginStateSplitNode && |
|
3033 |
((BeginStateSplitNode) begin).stateAfter() != null) : "We are not allowed to set the stateAfter of the begin node," + |
|
3034 |
" because we have to deoptimize to a bci _before_ the actual if, so that the interpreter can update the profiling information."; |
|
3035 |
return begin; |
|
3036 |
} |
|
3037 |
||
3038 |
private ValueNode synchronizedObject(FrameStateBuilder state, ResolvedJavaMethod target) { |
|
3039 |
if (target.isStatic()) { |
|
3040 |
return appendConstant(getConstantReflection().asJavaClass(target.getDeclaringClass())); |
|
3041 |
} else { |
|
3042 |
return state.loadLocal(0, JavaKind.Object); |
|
3043 |
} |
|
3044 |
} |
|
3045 |
||
3046 |
@SuppressWarnings("try") |
|
3047 |
protected void processBlock(BciBlock block) { |
|
3048 |
// Ignore blocks that have no predecessors by the time their bytecodes are parsed |
|
3049 |
FixedWithNextNode firstInstruction = getFirstInstruction(block); |
|
3050 |
if (firstInstruction == null) { |
|
46640 | 3051 |
debug.log("Ignoring block %s", block); |
43972 | 3052 |
return; |
3053 |
} |
|
49873 | 3054 |
try (Indent indent = debug.logAndIndent("Parsing block %s firstInstruction: %s loopHeader: %b", block, firstInstruction, block.isLoopHeader())) { |
43972 | 3055 |
|
3056 |
lastInstr = firstInstruction; |
|
3057 |
frameState = getEntryState(block); |
|
3058 |
setCurrentFrameState(frameState); |
|
3059 |
currentBlock = block; |
|
3060 |
||
48861 | 3061 |
if (block != blockMap.getUnwindBlock() && !(block instanceof ExceptionDispatchBlock)) { |
3062 |
frameState.setRethrowException(false); |
|
3063 |
} |
|
3064 |
||
43972 | 3065 |
if (firstInstruction instanceof AbstractMergeNode) { |
3066 |
setMergeStateAfter(block, firstInstruction); |
|
3067 |
} |
|
3068 |
||
46393 | 3069 |
if (block == blockMap.getUnwindBlock()) { |
46344 | 3070 |
handleUnwindBlock((ExceptionDispatchBlock) block); |
43972 | 3071 |
} else if (block instanceof ExceptionDispatchBlock) { |
3072 |
createExceptionDispatch((ExceptionDispatchBlock) block); |
|
3073 |
} else { |
|
3074 |
iterateBytecodesForBlock(block); |
|
3075 |
} |
|
3076 |
} |
|
3077 |
} |
|
3078 |
||
46344 | 3079 |
private void handleUnwindBlock(ExceptionDispatchBlock block) { |
54601 | 3080 |
if (frameState.lockDepth(false) != 0) { |
3081 |
throw bailout("unbalanced monitors: too few exits exiting frame"); |
|
3082 |
} |
|
3083 |
assert !frameState.rethrowException(); |
|
3084 |
finishPrepare(lastInstr, block.deoptBci, frameState); |
|
43972 | 3085 |
if (parent == null) { |
3086 |
createUnwind(); |
|
3087 |
} else { |
|
54601 | 3088 |
this.unwindValue = frameState.pop(JavaKind.Object); |
43972 | 3089 |
this.beforeUnwindNode = this.lastInstr; |
3090 |
} |
|
3091 |
} |
|
3092 |
||
3093 |
private void setMergeStateAfter(BciBlock block, FixedWithNextNode firstInstruction) { |
|
3094 |
AbstractMergeNode abstractMergeNode = (AbstractMergeNode) firstInstruction; |
|
3095 |
if (abstractMergeNode.stateAfter() == null) { |
|
3096 |
int bci = block.startBci; |
|
3097 |
if (block instanceof ExceptionDispatchBlock) { |
|
3098 |
bci = ((ExceptionDispatchBlock) block).deoptBci; |
|
3099 |
} |
|
3100 |
abstractMergeNode.setStateAfter(createFrameState(bci, abstractMergeNode)); |
|
3101 |
} |
|
3102 |
} |
|
3103 |
||
50330 | 3104 |
@SuppressWarnings("try") |
43972 | 3105 |
private void createUnwind() { |
3106 |
assert frameState.stackSize() == 1 : frameState; |
|
50330 | 3107 |
try (DebugCloseable context = openNodeContext(frameState, BytecodeFrame.UNWIND_BCI)) { |
3108 |
ValueNode exception = frameState.pop(JavaKind.Object); |
|
3109 |
append(new UnwindNode(exception)); |
|
3110 |
} |
|
3111 |
} |
|
3112 |
||
3113 |
@SuppressWarnings("try") |
|
43972 | 3114 |
private void synchronizedEpilogue(int bci, ValueNode currentReturnValue, JavaKind currentReturnValueKind) { |
50330 | 3115 |
try (DebugCloseable context = openNodeContext(frameState, bci)) { |
3116 |
if (method.isSynchronized()) { |
|
54601 | 3117 |
if (currentReturnValueKind != JavaKind.Void) { |
3118 |
// we are making a state that should look like the state after the return: |
|
3119 |
// push the return value on the stack |
|
50330 | 3120 |
frameState.push(currentReturnValueKind, currentReturnValue); |
3121 |
} |
|
3122 |
genMonitorExit(methodSynchronizedObject, currentReturnValue, bci); |
|
3123 |
assert !frameState.rethrowException(); |
|
43972 | 3124 |
} |
50330 | 3125 |
if (frameState.lockDepth(false) != 0) { |
3126 |
throw bailout("unbalanced monitors: too few exits exiting frame"); |
|
3127 |
} |
|
3128 |
} |
|
3129 |
} |
|
3130 |
||
3131 |
@SuppressWarnings("try") |
|
43972 | 3132 |
private void createExceptionDispatch(ExceptionDispatchBlock block) { |
50330 | 3133 |
try (DebugCloseable context = openNodeContext(frameState, BytecodeFrame.AFTER_EXCEPTION_BCI)) { |
3134 |
lastInstr = finishInstruction(lastInstr, frameState); |
|
3135 |
||
3136 |
assert frameState.stackSize() == 1 : frameState; |
|
3137 |
if (block.handler.isCatchAll()) { |
|
3138 |
assert block.getSuccessorCount() == 1; |
|
3139 |
appendGoto(block.getSuccessor(0)); |
|
3140 |
return; |
|
3141 |
} |
|
3142 |
||
3143 |
JavaType catchType = block.handler.getCatchType(); |
|
3144 |
if (graphBuilderConfig.eagerResolving()) { |
|
3145 |
catchType = lookupType(block.handler.catchTypeCPI(), INSTANCEOF); |
|
3146 |
} |
|
52578 | 3147 |
if (typeIsResolved(catchType)) { |
50330 | 3148 |
TypeReference checkedCatchType = TypeReference.createTrusted(graph.getAssumptions(), (ResolvedJavaType) catchType); |
3149 |
||
3150 |
if (graphBuilderConfig.getSkippedExceptionTypes() != null) { |
|
3151 |
for (ResolvedJavaType skippedType : graphBuilderConfig.getSkippedExceptionTypes()) { |
|
3152 |
if (skippedType.isAssignableFrom(checkedCatchType.getType())) { |
|
3153 |
BciBlock nextBlock = block.getSuccessorCount() == 1 ? blockMap.getUnwindBlock() : block.getSuccessor(1); |
|
3154 |
ValueNode exception = frameState.stack[0]; |
|
3155 |
FixedNode trueSuccessor = graph.add(new DeoptimizeNode(InvalidateReprofile, UnreachedCode)); |
|
3156 |
FixedNode nextDispatch = createTarget(nextBlock, frameState); |
|
3157 |
append(new IfNode(graph.addOrUniqueWithInputs(createInstanceOf(checkedCatchType, exception)), trueSuccessor, nextDispatch, 0)); |
|
3158 |
return; |
|
3159 |
} |
|
43972 | 3160 |
} |
3161 |
} |
|
50330 | 3162 |
|
3163 |
BciBlock nextBlock = block.getSuccessorCount() == 1 ? blockMap.getUnwindBlock() : block.getSuccessor(1); |
|
3164 |
ValueNode exception = frameState.stack[0]; |
|
3165 |
/* |
|
3166 |
* Anchor for the piNode, which must be before any LoopExit inserted by |
|
3167 |
* createTarget. |
|
3168 |
*/ |
|
3169 |
BeginNode piNodeAnchor = graph.add(new BeginNode()); |
|
3170 |
ObjectStamp checkedStamp = StampFactory.objectNonNull(checkedCatchType); |
|
3171 |
PiNode piNode = graph.addWithoutUnique(new PiNode(exception, checkedStamp)); |
|
3172 |
frameState.pop(JavaKind.Object); |
|
3173 |
frameState.push(JavaKind.Object, piNode); |
|
3174 |
FixedNode catchSuccessor = createTarget(block.getSuccessor(0), frameState); |
|
3175 |
frameState.pop(JavaKind.Object); |
|
3176 |
frameState.push(JavaKind.Object, exception); |
|
3177 |
FixedNode nextDispatch = createTarget(nextBlock, frameState); |
|
3178 |
piNodeAnchor.setNext(catchSuccessor); |
|
3179 |
IfNode ifNode = append(new IfNode(graph.unique(createInstanceOf(checkedCatchType, exception)), piNodeAnchor, nextDispatch, 0.5)); |
|
3180 |
assert ifNode.trueSuccessor() == piNodeAnchor; |
|
3181 |
piNode.setGuard(ifNode.trueSuccessor()); |
|
3182 |
} else { |
|
3183 |
handleUnresolvedExceptionType(catchType); |
|
43972 | 3184 |
} |
3185 |
} |
|
3186 |
} |
|
3187 |
||
3188 |
private void appendGoto(BciBlock successor) { |
|
3189 |
FixedNode targetInstr = createTarget(successor, frameState, true, true); |
|
3190 |
if (lastInstr != null && lastInstr != targetInstr) { |
|
3191 |
lastInstr.setNext(targetInstr); |
|
3192 |
} |
|
3193 |
} |
|
3194 |
||
3195 |
@SuppressWarnings("try") |
|
3196 |
protected void iterateBytecodesForBlock(BciBlock block) { |
|
49873 | 3197 |
if (block.isLoopHeader()) { |
43972 | 3198 |
// Create the loop header block, which later will merge the backward branches of |
3199 |
// the loop. |
|
3200 |
controlFlowSplit = true; |
|
49873 | 3201 |
LoopBeginNode loopBegin = appendLoopBegin(this.lastInstr, block.startBci); |
43972 | 3202 |
lastInstr = loopBegin; |
3203 |
||
3204 |
// Create phi functions for all local variables and operand stack slots. |
|
3205 |
frameState.insertLoopPhis(liveness, block.loopId, loopBegin, forceLoopPhis(), stampFromValueForForcedPhis()); |
|
3206 |
loopBegin.setStateAfter(createFrameState(block.startBci, loopBegin)); |
|
3207 |
||
3208 |
/* |
|
3209 |
* We have seen all forward branches. All subsequent backward branches will merge to the |
|
3210 |
* loop header. This ensures that the loop header has exactly one non-loop predecessor. |
|
3211 |
*/ |
|
3212 |
setFirstInstruction(block, loopBegin); |
|
3213 |
/* |
|
3214 |
* We need to preserve the frame state builder of the loop header so that we can merge |
|
3215 |
* values for phi functions, so make a copy of it. |
|
3216 |
*/ |
|
3217 |
setEntryState(block, frameState.copy()); |
|
3218 |
||
46640 | 3219 |
debug.log(" created loop header %s", loopBegin); |
43972 | 3220 |
} else if (lastInstr instanceof MergeNode) { |
3221 |
/* |
|
3222 |
* All inputs of non-loop phi nodes are known by now. We can infer the stamp for the |
|
3223 |
* phi, so that parsing continues with more precise type information. |
|
3224 |
*/ |
|
3225 |
frameState.inferPhiStamps((AbstractMergeNode) lastInstr); |
|
3226 |
} |
|
3227 |
assert lastInstr.next() == null : "instructions already appended at block " + block; |
|
46640 | 3228 |
debug.log(" frameState: %s", frameState); |
43972 | 3229 |
|
3230 |
lastInstr = finishInstruction(lastInstr, frameState); |
|
3231 |
||
3232 |
int endBCI = stream.endBCI(); |
|
3233 |
||
3234 |
stream.setBCI(block.startBci); |
|
3235 |
int bci = block.startBci; |
|
46640 | 3236 |
BytecodesParsed.add(debug, block.endBci - bci); |
43972 | 3237 |
|
3238 |
/* Reset line number for new block */ |
|
3239 |
if (graphBuilderConfig.insertFullInfopoints()) { |
|
3240 |
previousLineNumber = -1; |
|
3241 |
} |
|
3242 |
||
3243 |
while (bci < endBCI) { |
|
49451 | 3244 |
try (DebugCloseable context = openNodeContext()) { |
3245 |
if (graphBuilderConfig.insertFullInfopoints() && !parsingIntrinsic()) { |
|
3246 |
currentLineNumber = lnt != null ? lnt.getLineNumber(bci) : -1; |
|
3247 |
if (currentLineNumber != previousLineNumber) { |
|
3248 |
genInfoPointNode(InfopointReason.BYTECODE_POSITION, null); |
|
3249 |
previousLineNumber = currentLineNumber; |
|
3250 |
} |
|
43972 | 3251 |
} |
49451 | 3252 |
|
3253 |
// read the opcode |
|
3254 |
int opcode = stream.currentBC(); |
|
49873 | 3255 |
if (traceLevel != 0) { |
3256 |
traceInstruction(bci, opcode, bci == block.startBci); |
|
3257 |
} |
|
49451 | 3258 |
if (parent == null && bci == entryBCI) { |
3259 |
if (block.getJsrScope() != JsrScope.EMPTY_SCOPE) { |
|
3260 |
throw new JsrNotSupportedBailout("OSR into a JSR scope is not supported"); |
|
3261 |
} |
|
3262 |
EntryMarkerNode x = append(new EntryMarkerNode()); |
|
3263 |
frameState.insertProxies(value -> graph.unique(new EntryProxyNode(value, x))); |
|
3264 |
x.setStateAfter(createFrameState(bci, x)); |
|
43972 | 3265 |
} |
49451 | 3266 |
|
43972 | 3267 |
processBytecode(bci, opcode); |
3268 |
} catch (BailoutException e) { |
|
3269 |
// Don't wrap bailouts as parser errors |
|
3270 |
throw e; |
|
3271 |
} catch (Throwable e) { |
|
47667 | 3272 |
throw throwParserError(e); |
43972 | 3273 |
} |
3274 |
||
3275 |
if (lastInstr == null || lastInstr.next() != null) { |
|
3276 |
break; |
|
3277 |
} |
|
3278 |
||
3279 |
stream.next(); |
|
3280 |
bci = stream.currentBCI(); |
|
3281 |
||
3282 |
assert block == currentBlock; |
|
3283 |
assert checkLastInstruction(); |
|
3284 |
lastInstr = finishInstruction(lastInstr, frameState); |
|
3285 |
if (bci < endBCI) { |
|
3286 |
if (bci > block.endBci) { |
|
49873 | 3287 |
assert !block.getSuccessor(0).isExceptionEntry(); |
43972 | 3288 |
assert block.numNormalSuccessors() == 1; |
3289 |
// we fell through to the next block, add a goto and break |
|
3290 |
appendGoto(block.getSuccessor(0)); |
|
3291 |
break; |
|
3292 |
} |
|
3293 |
} |
|
3294 |
} |
|
3295 |
} |
|
3296 |
||
49451 | 3297 |
private DebugCloseable openNodeContext(FrameStateBuilder state, int startBci) { |
3298 |
if (graph.trackNodeSourcePosition()) { |
|
3299 |
return graph.withNodeSourcePosition(state.createBytecodePosition(startBci)); |
|
43972 | 3300 |
} |
3301 |
return null; |
|
3302 |
} |
|
3303 |
||
49451 | 3304 |
private DebugCloseable openNodeContext(ResolvedJavaMethod targetMethod) { |
3305 |
return openNodeContext(targetMethod, -1); |
|
3306 |
} |
|
3307 |
||
3308 |
private DebugCloseable openNodeContext(ResolvedJavaMethod targetMethod, int bci) { |
|
3309 |
if (graph.trackNodeSourcePosition()) { |
|
3310 |
return graph.withNodeSourcePosition(new NodeSourcePosition(createBytecodePosition(), targetMethod, bci)); |
|
3311 |
} |
|
3312 |
return null; |
|
3313 |
} |
|
3314 |
||
3315 |
private DebugCloseable openNodeContext() { |
|
3316 |
return openNodeContext(frameState, bci()); |
|
3317 |
} |
|
3318 |
||
43972 | 3319 |
/* Also a hook for subclasses. */ |
3320 |
protected boolean forceLoopPhis() { |
|
3321 |
return graph.isOSR(); |
|
3322 |
} |
|
3323 |
||
3324 |
/* Hook for subclasses. */ |
|
3325 |
protected boolean stampFromValueForForcedPhis() { |
|
3326 |
return false; |
|
3327 |
} |
|
3328 |
||
3329 |
protected boolean checkLastInstruction() { |
|
3330 |
if (lastInstr instanceof BeginNode) { |
|
3331 |
// ignore |
|
3332 |
} else if (lastInstr instanceof StateSplit) { |
|
3333 |
StateSplit stateSplit = (StateSplit) lastInstr; |
|
3334 |
if (stateSplit.hasSideEffect()) { |
|
3335 |
assert stateSplit.stateAfter() != null : "side effect " + lastInstr + " requires a non-null stateAfter"; |
|
3336 |
} |
|
3337 |
} |
|
3338 |
return true; |
|
3339 |
} |
|
3340 |
||
3341 |
/* Also a hook for subclasses. */ |
|
3342 |
protected boolean disableLoopSafepoint() { |
|
3343 |
return parsingIntrinsic(); |
|
3344 |
} |
|
3345 |
||
49873 | 3346 |
@SuppressWarnings("try") |
3347 |
private LoopBeginNode appendLoopBegin(FixedWithNextNode fixedWithNext, int startBci) { |
|
3348 |
try (DebugCloseable context = openNodeContext(frameState, startBci)) { |
|
3349 |
EndNode preLoopEnd = graph.add(new EndNode()); |
|
3350 |
LoopBeginNode loopBegin = graph.add(new LoopBeginNode()); |
|
3351 |
if (disableLoopSafepoint()) { |
|
3352 |
loopBegin.disableSafepoint(); |
|
3353 |
} |
|
3354 |
fixedWithNext.setNext(preLoopEnd); |
|
3355 |
// Add the single non-loop predecessor of the loop header. |
|
3356 |
loopBegin.addForwardEnd(preLoopEnd); |
|
3357 |
return loopBegin; |
|
3358 |
} |
|
43972 | 3359 |
} |
3360 |
||
3361 |
/** |
|
3362 |
* Hook for subclasses to modify the last instruction or add other instructions. |
|
3363 |
* |
|
3364 |
* @param instr The last instruction (= fixed node) which was added. |
|
3365 |
* @param state The current frame state. |
|
3366 |
* @return Returns the (new) last instruction. |
|
3367 |
*/ |
|
3368 |
protected FixedWithNextNode finishInstruction(FixedWithNextNode instr, FrameStateBuilder state) { |
|
3369 |
return instr; |
|
3370 |
} |
|
3371 |
||
3372 |
private void genInfoPointNode(InfopointReason reason, ValueNode escapedReturnValue) { |
|
3373 |
if (!parsingIntrinsic() && graphBuilderConfig.insertFullInfopoints()) { |
|
3374 |
append(new FullInfopointNode(reason, createFrameState(bci(), null), escapedReturnValue)); |
|
3375 |
} |
|
3376 |
} |
|
3377 |
||
3378 |
protected void genIf(ValueNode x, Condition cond, ValueNode y) { |
|
3379 |
assert x.getStackKind() == y.getStackKind(); |
|
3380 |
assert currentBlock.getSuccessorCount() == 2; |
|
3381 |
BciBlock trueBlock = currentBlock.getSuccessor(0); |
|
3382 |
BciBlock falseBlock = currentBlock.getSuccessor(1); |
|
3383 |
||
3384 |
if (trueBlock == falseBlock) { |
|
3385 |
// The target block is the same independent of the condition. |
|
3386 |
appendGoto(trueBlock); |
|
3387 |
return; |
|
3388 |
} |
|
3389 |
||
3390 |
ValueNode a = x; |
|
3391 |
ValueNode b = y; |
|
48861 | 3392 |
BciBlock trueSuccessor = trueBlock; |
3393 |
BciBlock falseSuccessor = falseBlock; |
|
3394 |
||
3395 |
CanonicalizedCondition canonicalizedCondition = cond.canonicalize(); |
|
43972 | 3396 |
|
3397 |
// Check whether the condition needs to mirror the operands. |
|
48861 | 3398 |
if (canonicalizedCondition.mustMirror()) { |
43972 | 3399 |
a = y; |
3400 |
b = x; |
|
3401 |
} |
|
48861 | 3402 |
if (canonicalizedCondition.mustNegate()) { |
3403 |
trueSuccessor = falseBlock; |
|
3404 |
falseSuccessor = trueBlock; |
|
3405 |
} |
|
43972 | 3406 |
|
3407 |
// Create the logic node for the condition. |
|
48861 | 3408 |
LogicNode condition = createLogicNode(canonicalizedCondition.getCanonicalCondition(), a, b); |
3409 |
||
3410 |
double probability = -1; |
|
3411 |
if (condition instanceof IntegerEqualsNode) { |
|
3412 |
probability = extractInjectedProbability((IntegerEqualsNode) condition); |
|
3413 |
// the probability coming from here is about the actual condition |
|
3414 |
} |
|
3415 |
||
3416 |
if (probability == -1) { |
|
3417 |
probability = getProfileProbability(canonicalizedCondition.mustNegate()); |
|
3418 |
} |
|
3419 |
||
3420 |
probability = clampProbability(probability); |
|
3421 |
genIf(condition, trueSuccessor, falseSuccessor, probability); |
|
3422 |
} |
|
3423 |
||
49451 | 3424 |
protected double getProfileProbability(boolean negate) { |
48861 | 3425 |
if (profilingInfo == null) { |
50330 | 3426 |
return 0.5; |
3427 |
} |
|
3428 |
||
3429 |
assert assertAtIfBytecode(); |
|
3430 |
double probability = profilingInfo.getBranchTakenProbability(bci()); |
|
3431 |
||
3432 |
if (probability < 0) { |
|
3433 |
assert probability == -1 : "invalid probability"; |
|
3434 |
debug.log("missing probability in %s at bci %d", code, bci()); |
|
3435 |
return 0.5; |
|
3436 |
} |
|
3437 |
||
3438 |
if (negate && shouldComplementProbability()) { |
|
3439 |
// the probability coming from profile is about the original condition |
|
3440 |
probability = 1 - probability; |
|
48861 | 3441 |
} |
3442 |
return probability; |
|
3443 |
} |
|
3444 |
||
3445 |
private static double extractInjectedProbability(IntegerEqualsNode condition) { |
|
3446 |
// Propagate injected branch probability if any. |
|
3447 |
IntegerEqualsNode equalsNode = condition; |
|
3448 |
BranchProbabilityNode probabilityNode = null; |
|
3449 |
ValueNode other = null; |
|
3450 |
if (equalsNode.getX() instanceof BranchProbabilityNode) { |
|
3451 |
probabilityNode = (BranchProbabilityNode) equalsNode.getX(); |
|
3452 |
other = equalsNode.getY(); |
|
3453 |
} else if (equalsNode.getY() instanceof BranchProbabilityNode) { |
|
3454 |
probabilityNode = (BranchProbabilityNode) equalsNode.getY(); |
|
3455 |
other = equalsNode.getX(); |
|
3456 |
} |
|
3457 |
||
3458 |
if (probabilityNode != null && probabilityNode.getProbability().isConstant() && other != null && other.isConstant()) { |
|
3459 |
double probabilityValue = probabilityNode.getProbability().asJavaConstant().asDouble(); |
|
3460 |
return other.asJavaConstant().asInt() == 0 ? 1.0 - probabilityValue : probabilityValue; |
|
3461 |
} |
|
3462 |
return -1; |
|
3463 |
} |
|
3464 |
||
3465 |
protected void genIf(LogicNode conditionInput, BciBlock trueBlockInput, BciBlock falseBlockInput, double probabilityInput) { |
|
46344 | 3466 |
BciBlock trueBlock = trueBlockInput; |
3467 |
BciBlock falseBlock = falseBlockInput; |
|
3468 |
LogicNode condition = conditionInput; |
|
48861 | 3469 |
double probability = probabilityInput; |
46344 | 3470 |
FrameState stateBefore = null; |
3471 |
ProfilingPlugin profilingPlugin = this.graphBuilderConfig.getPlugins().getProfilingPlugin(); |
|
3472 |
if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) { |
|
52910 | 3473 |
stateBefore = createCurrentFrameState(); |
46344 | 3474 |
} |
43972 | 3475 |
|
48861 | 3476 |
// Remove a logic negation node. |
43972 | 3477 |
if (condition instanceof LogicNegationNode) { |
3478 |
LogicNegationNode logicNegationNode = (LogicNegationNode) condition; |
|
48861 | 3479 |
BciBlock tmpBlock = trueBlock; |
3480 |
trueBlock = falseBlock; |
|
3481 |
falseBlock = tmpBlock; |
|
50330 | 3482 |
if (shouldComplementProbability()) { |
3483 |
// the probability coming from profile is about the original condition |
|
3484 |
probability = 1 - probability; |
|
3485 |
} |
|
43972 | 3486 |
condition = logicNegationNode.getValue(); |
3487 |
} |
|
3488 |
||
3489 |
if (condition instanceof LogicConstantNode) { |
|
48861 | 3490 |
genConstantTargetIf(trueBlock, falseBlock, condition); |
43972 | 3491 |
} else { |
3492 |
if (condition.graph() == null) { |
|
46371 | 3493 |
condition = genUnique(condition); |
43972 | 3494 |
} |
3495 |
||
54084 | 3496 |
BciBlock deoptBlock = null; |
3497 |
BciBlock noDeoptBlock = null; |
|
43972 | 3498 |
if (isNeverExecutedCode(probability)) { |
54084 | 3499 |
deoptBlock = trueBlock; |
3500 |
noDeoptBlock = falseBlock; |
|
3501 |
} else if (isNeverExecutedCode(1 - probability)) { |
|
3502 |
deoptBlock = falseBlock; |
|
3503 |
noDeoptBlock = trueBlock; |
|
3504 |
} |
|
3505 |
||
3506 |
if (deoptBlock != null) { |
|
3507 |
NodeSourcePosition currentPosition = graph.currentNodeSourcePosition(); |
|
3508 |
NodeSourcePosition survivingSuccessorPosition = null; |
|
3509 |
if (graph.trackNodeSourcePosition()) { |
|
3510 |
survivingSuccessorPosition = new NodeSourcePosition(currentPosition.getCaller(), currentPosition.getMethod(), noDeoptBlock.startBci); |
|
43972 | 3511 |
} |
54084 | 3512 |
boolean negated = deoptBlock == trueBlock; |
3513 |
if (!isPotentialCountedLoopExit(condition, deoptBlock)) { |
|
3514 |
if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) { |
|
3515 |
profilingPlugin.profileGoto(this, method, bci(), noDeoptBlock.startBci, stateBefore); |
|
3516 |
} |
|
3517 |
append(new FixedGuardNode(condition, UnreachedCode, InvalidateReprofile, negated, survivingSuccessorPosition)); |
|
3518 |
appendGoto(noDeoptBlock); |
|
3519 |
} else { |
|
3520 |
this.controlFlowSplit = true; |
|
3521 |
FixedNode noDeoptSuccessor = createTarget(noDeoptBlock, frameState, false, true); |
|
3522 |
DeoptimizeNode deopt = graph.add(new DeoptimizeNode(InvalidateReprofile, UnreachedCode)); |
|
3523 |
/* |
|
3524 |
* We do not want to `checkLoopExit` here: otherwise the deopt will go to the |
|
3525 |
* deoptBlock's BCI, skipping the branch in the interpreter, and the profile |
|
3526 |
* will never see that the branch is taken. This can lead to deopt loops or OSR |
|
3527 |
* failure. |
|
3528 |
*/ |
|
3529 |
FixedNode deoptSuccessor = BeginNode.begin(deopt); |
|
3530 |
ValueNode ifNode = genIfNode(condition, negated ? deoptSuccessor : noDeoptSuccessor, negated ? noDeoptSuccessor : deoptSuccessor, negated ? 1 - probability : probability); |
|
3531 |
postProcessIfNode(ifNode); |
|
3532 |
append(ifNode); |
|
43972 | 3533 |
} |
51736 | 3534 |
return; |
43972 | 3535 |
} |
3536 |
||
3537 |
if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) { |
|
3538 |
profilingPlugin.profileIf(this, method, bci(), condition, trueBlock.startBci, falseBlock.startBci, stateBefore); |
|
3539 |
} |
|
3540 |
||
3541 |
int oldBci = stream.currentBCI(); |
|
3542 |
int trueBlockInt = checkPositiveIntConstantPushed(trueBlock); |
|
3543 |
if (trueBlockInt != -1) { |
|
3544 |
int falseBlockInt = checkPositiveIntConstantPushed(falseBlock); |
|
3545 |
if (falseBlockInt != -1) { |
|
3546 |
if (tryGenConditionalForIf(trueBlock, falseBlock, condition, oldBci, trueBlockInt, falseBlockInt)) { |
|
3547 |
return; |
|
3548 |
} |
|
3549 |
} |
|
3550 |
} |
|
3551 |
||
3552 |
this.controlFlowSplit = true; |
|
3553 |
FixedNode trueSuccessor = createTarget(trueBlock, frameState, false, false); |
|
3554 |
FixedNode falseSuccessor = createTarget(falseBlock, frameState, false, true); |
|
3555 |
ValueNode ifNode = genIfNode(condition, trueSuccessor, falseSuccessor, probability); |
|
3556 |
postProcessIfNode(ifNode); |
|
3557 |
append(ifNode); |
|
3558 |
} |
|
3559 |
} |
|
3560 |
||
54084 | 3561 |
public boolean isPotentialCountedLoopExit(LogicNode condition, BciBlock target) { |
3562 |
if (currentBlock != null) { |
|
3563 |
long exits = currentBlock.loops & ~target.loops; |
|
3564 |
if (exits != 0) { |
|
3565 |
return condition instanceof CompareNode; |
|
3566 |
} |
|
3567 |
} |
|
3568 |
return false; |
|
3569 |
} |
|
3570 |
||
43972 | 3571 |
/** |
50330 | 3572 |
* Hook for subclasses to decide whether the IfNode probability should be complemented during |
3573 |
* conversion to Graal IR. |
|
3574 |
*/ |
|
3575 |
protected boolean shouldComplementProbability() { |
|
3576 |
return true; |
|
3577 |
} |
|
3578 |
||
3579 |
/** |
|
43972 | 3580 |
* Hook for subclasses to generate custom nodes before an IfNode. |
3581 |
*/ |
|
3582 |
@SuppressWarnings("unused") |
|
3583 |
protected void postProcessIfNode(ValueNode node) { |
|
3584 |
} |
|
3585 |
||
3586 |
private boolean tryGenConditionalForIf(BciBlock trueBlock, BciBlock falseBlock, LogicNode condition, int oldBci, int trueBlockInt, int falseBlockInt) { |
|
3587 |
if (gotoOrFallThroughAfterConstant(trueBlock) && gotoOrFallThroughAfterConstant(falseBlock) && trueBlock.getSuccessor(0) == falseBlock.getSuccessor(0)) { |
|
3588 |
genConditionalForIf(trueBlock, condition, oldBci, trueBlockInt, falseBlockInt, false); |
|
3589 |
return true; |
|
3590 |
} else if (this.parent != null && returnAfterConstant(trueBlock) && returnAfterConstant(falseBlock)) { |
|
3591 |
genConditionalForIf(trueBlock, condition, oldBci, trueBlockInt, falseBlockInt, true); |
|
3592 |
return true; |
|
3593 |
} |
|
3594 |
return false; |
|
3595 |
} |
|
3596 |
||
3597 |
private void genConditionalForIf(BciBlock trueBlock, LogicNode condition, int oldBci, int trueBlockInt, int falseBlockInt, boolean genReturn) { |
|
3598 |
ConstantNode trueValue = graph.unique(ConstantNode.forInt(trueBlockInt)); |
|
3599 |
ConstantNode falseValue = graph.unique(ConstantNode.forInt(falseBlockInt)); |
|
48190 | 3600 |
ValueNode conditionalNode = ConditionalNode.create(condition, trueValue, falseValue, NodeView.DEFAULT); |
43972 | 3601 |
if (conditionalNode.graph() == null) { |
46807 | 3602 |
conditionalNode = graph.addOrUniqueWithInputs(conditionalNode); |
43972 | 3603 |
} |
3604 |
if (genReturn) { |
|
3605 |
JavaKind returnKind = method.getSignature().getReturnKind().getStackKind(); |
|
3606 |
this.genReturn(conditionalNode, returnKind); |
|
3607 |
} else { |
|
3608 |
frameState.push(JavaKind.Int, conditionalNode); |
|
3609 |
appendGoto(trueBlock.getSuccessor(0)); |
|
3610 |
stream.setBCI(oldBci); |
|
3611 |
} |
|
3612 |
} |
|
3613 |
||
48861 | 3614 |
private LogicNode createLogicNode(CanonicalCondition cond, ValueNode a, ValueNode b) { |
43972 | 3615 |
assert !a.getStackKind().isNumericFloat(); |
48861 | 3616 |
switch (cond) { |
3617 |
case EQ: |
|
3618 |
if (a.getStackKind() == JavaKind.Object) { |
|
3619 |
return genObjectEquals(a, b); |
|
3620 |
} else { |
|
3621 |
return genIntegerEquals(a, b); |
|
3622 |
} |
|
3623 |
case LT: |
|
3624 |
assert a.getStackKind() != JavaKind.Object; |
|
3625 |
return genIntegerLessThan(a, b); |
|
3626 |
default: |
|
3627 |
throw GraalError.shouldNotReachHere("Unexpected condition: " + cond); |
|
43972 | 3628 |
} |
48861 | 3629 |
} |
3630 |
||
3631 |
private void genConstantTargetIf(BciBlock trueBlock, BciBlock falseBlock, LogicNode condition) { |
|
43972 | 3632 |
LogicConstantNode constantLogicNode = (LogicConstantNode) condition; |
3633 |
boolean value = constantLogicNode.getValue(); |
|
3634 |
BciBlock nextBlock = falseBlock; |
|
3635 |
if (value) { |
|
3636 |
nextBlock = trueBlock; |
|
3637 |
} |
|
3638 |
int startBci = nextBlock.startBci; |
|
3639 |
int targetAtStart = stream.readUByte(startBci); |
|
3640 |
if (targetAtStart == Bytecodes.GOTO && nextBlock.getPredecessorCount() == 1) { |
|
3641 |
// This is an empty block. Skip it. |
|
3642 |
BciBlock successorBlock = nextBlock.successors.get(0); |
|
3643 |
ProfilingPlugin profilingPlugin = graphBuilderConfig.getPlugins().getProfilingPlugin(); |
|
3644 |
if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) { |
|
52910 | 3645 |
FrameState stateBefore = createCurrentFrameState(); |
43972 | 3646 |
profilingPlugin.profileGoto(this, method, bci(), successorBlock.startBci, stateBefore); |
3647 |
} |
|
3648 |
appendGoto(successorBlock); |
|
3649 |
assert nextBlock.numNormalSuccessors() == 1; |
|
3650 |
} else { |
|
3651 |
ProfilingPlugin profilingPlugin = graphBuilderConfig.getPlugins().getProfilingPlugin(); |
|
3652 |
if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) { |
|
52910 | 3653 |
FrameState stateBefore = createCurrentFrameState(); |
43972 | 3654 |
profilingPlugin.profileGoto(this, method, bci(), nextBlock.startBci, stateBefore); |
3655 |
} |
|
3656 |
appendGoto(nextBlock); |
|
3657 |
} |
|
3658 |
} |
|
3659 |
||
3660 |
private int checkPositiveIntConstantPushed(BciBlock block) { |
|
3661 |
stream.setBCI(block.startBci); |
|
3662 |
int currentBC = stream.currentBC(); |
|
3663 |
if (currentBC >= Bytecodes.ICONST_0 && currentBC <= Bytecodes.ICONST_5) { |
|
3664 |
int constValue = currentBC - Bytecodes.ICONST_0; |
|
3665 |
return constValue; |
|
3666 |
} |
|
3667 |
return -1; |
|
3668 |
} |
|
3669 |
||
3670 |
private boolean gotoOrFallThroughAfterConstant(BciBlock block) { |
|
3671 |
stream.setBCI(block.startBci); |
|
3672 |
int currentBCI = stream.nextBCI(); |
|
3673 |
stream.setBCI(currentBCI); |
|
3674 |
int currentBC = stream.currentBC(); |
|
3675 |
return stream.currentBCI() > block.endBci || currentBC == Bytecodes.GOTO || currentBC == Bytecodes.GOTO_W; |
|
3676 |
} |
|
3677 |
||
3678 |
private boolean returnAfterConstant(BciBlock block) { |
|
3679 |
stream.setBCI(block.startBci); |
|
3680 |
int currentBCI = stream.nextBCI(); |
|
3681 |
stream.setBCI(currentBCI); |
|
3682 |
int currentBC = stream.currentBC(); |
|
3683 |
return currentBC == Bytecodes.IRETURN; |
|
3684 |
} |
|
3685 |
||
3686 |
@Override |
|
3687 |
public StampProvider getStampProvider() { |
|
54328 | 3688 |
return providers.getStampProvider(); |
43972 | 3689 |
} |
3690 |
||
3691 |
@Override |
|
3692 |
public MetaAccessProvider getMetaAccess() { |
|
54328 | 3693 |
return providers.getMetaAccess(); |
3694 |
} |
|
3695 |
||
3696 |
@Override |
|
3697 |
public Replacements getReplacements() { |
|
3698 |
return providers.getReplacements(); |
|
43972 | 3699 |
} |
3700 |
||
3701 |
@Override |
|
3702 |
public void push(JavaKind slotKind, ValueNode value) { |
|
3703 |
assert value.isAlive(); |
|
3704 |
frameState.push(slotKind, value); |
|
3705 |
} |
|
3706 |
||
3707 |
@Override |
|
51436 | 3708 |
public ValueNode pop(JavaKind slotKind) { |
3709 |
return frameState.pop(slotKind); |
|
3710 |
} |
|
3711 |
||
3712 |
@Override |
|
43972 | 3713 |
public ConstantReflectionProvider getConstantReflection() { |
54328 | 3714 |
return providers.getConstantReflection(); |
43972 | 3715 |
} |
3716 |
||
3717 |
@Override |
|
3718 |
public ConstantFieldProvider getConstantFieldProvider() { |
|
54328 | 3719 |
return providers.getConstantFieldProvider(); |
43972 | 3720 |
} |
3721 |
||
3722 |
/** |
|
3723 |
* Gets the graph being processed by this builder. |
|
3724 |
*/ |
|
3725 |
@Override |
|
3726 |
public StructuredGraph getGraph() { |
|
3727 |
return graph; |
|
3728 |
} |
|
3729 |
||
3730 |
@Override |
|
3731 |
public BytecodeParser getParent() { |
|
3732 |
return parent; |
|
3733 |
} |
|
3734 |
||
3735 |
@Override |
|
3736 |
public IntrinsicContext getIntrinsic() { |
|
3737 |
return intrinsicContext; |
|
3738 |
} |
|
3739 |
||
3740 |
@Override |
|
3741 |
public String toString() { |
|
3742 |
Formatter fmt = new Formatter(); |
|
3743 |
BytecodeParser bp = this; |
|
3744 |
String indent = ""; |
|
3745 |
while (bp != null) { |
|
3746 |
if (bp != this) { |
|
3747 |
fmt.format("%n%s", indent); |
|
3748 |
} |
|
3749 |
fmt.format("%s [bci: %d, intrinsic: %s]", bp.code.asStackTraceElement(bp.bci()), bp.bci(), bp.parsingIntrinsic()); |
|
3750 |
fmt.format("%n%s", new BytecodeDisassembler().disassemble(bp.code, bp.bci(), bp.bci() + 10)); |
|
3751 |
bp = bp.parent; |
|
3752 |
indent += " "; |
|
3753 |
} |
|
3754 |
return fmt.toString(); |
|
3755 |
} |
|
3756 |
||
3757 |
@Override |
|
3758 |
public BailoutException bailout(String string) { |
|
3759 |
FrameState currentFrameState = createFrameState(bci(), null); |
|
3760 |
StackTraceElement[] elements = GraphUtil.approxSourceStackTraceElement(currentFrameState); |
|
3761 |
BailoutException bailout = new PermanentBailoutException(string); |
|
3762 |
throw GraphUtil.createBailoutException(string, bailout, elements); |
|
3763 |
} |
|
3764 |
||
3765 |
private FrameState createFrameState(int bci, StateSplit forStateSplit) { |
|
3766 |
if (currentBlock != null && bci > currentBlock.endBci) { |
|
3767 |
frameState.clearNonLiveLocals(currentBlock, liveness, false); |
|
3768 |
} |
|
3769 |
return frameState.create(bci, forStateSplit); |
|
3770 |
} |
|
3771 |
||
3772 |
@Override |
|
3773 |
public void setStateAfter(StateSplit sideEffect) { |
|
50858 | 3774 |
assert sideEffect.hasSideEffect() || sideEffect instanceof AbstractMergeNode; |
43972 | 3775 |
FrameState stateAfter = createFrameState(stream.nextBCI(), sideEffect); |
3776 |
sideEffect.setStateAfter(stateAfter); |
|
3777 |
} |
|
3778 |
||
3779 |
protected NodeSourcePosition createBytecodePosition() { |
|
49451 | 3780 |
NodeSourcePosition bytecodePosition = frameState.createBytecodePosition(bci()); |
3781 |
return bytecodePosition; |
|
43972 | 3782 |
} |
3783 |
||
3784 |
public void setCurrentFrameState(FrameStateBuilder frameState) { |
|
3785 |
this.frameState = frameState; |
|
3786 |
} |
|
3787 |
||
3788 |
protected final BytecodeStream getStream() { |
|
3789 |
return stream; |
|
3790 |
} |
|
3791 |
||
3792 |
@Override |
|
3793 |
public int bci() { |
|
3794 |
return stream.currentBCI(); |
|
3795 |
} |
|
3796 |
||
3797 |
public void loadLocal(int index, JavaKind kind) { |
|
3798 |
ValueNode value = frameState.loadLocal(index, kind); |
|
3799 |
frameState.push(kind, value); |
|
3800 |
} |
|
3801 |
||
49451 | 3802 |
@SuppressWarnings("try") |
46344 | 3803 |
public void loadLocalObject(int index) { |
3804 |
ValueNode value = frameState.loadLocal(index, JavaKind.Object); |
|
3805 |
||
3806 |
int nextBCI = stream.nextBCI(); |
|
3807 |
int nextBC = stream.readUByte(nextBCI); |
|
46371 | 3808 |
if (nextBCI <= currentBlock.endBci && nextBC == Bytecodes.GETFIELD) { |
46344 | 3809 |
stream.next(); |
49451 | 3810 |
try (DebugCloseable ignored = openNodeContext()) { |
3811 |
genGetField(stream.readCPI(), Bytecodes.GETFIELD, value); |
|
3812 |
} |
|
46344 | 3813 |
} else { |
3814 |
frameState.push(JavaKind.Object, value); |
|
3815 |
} |
|
3816 |
} |
|
3817 |
||
43972 | 3818 |
public void storeLocal(JavaKind kind, int index) { |
3819 |
ValueNode value = frameState.pop(kind); |
|
3820 |
frameState.storeLocal(index, kind, value); |
|
3821 |
} |
|
3822 |
||
50609 | 3823 |
protected void genLoadConstant(int cpi, int opcode) { |
43972 | 3824 |
Object con = lookupConstant(cpi, opcode); |
3825 |
||
3826 |
if (con instanceof JavaType) { |
|
3827 |
// this is a load of class constant which might be unresolved |
|
3828 |
JavaType type = (JavaType) con; |
|
52578 | 3829 |
if (typeIsResolved(type)) { |
43972 | 3830 |
frameState.push(JavaKind.Object, appendConstant(getConstantReflection().asJavaClass((ResolvedJavaType) type))); |
3831 |
} else { |
|
3832 |
handleUnresolvedLoadConstant(type); |
|
3833 |
} |
|
3834 |
} else if (con instanceof JavaConstant) { |
|
3835 |
JavaConstant constant = (JavaConstant) con; |
|
3836 |
frameState.push(constant.getJavaKind(), appendConstant(constant)); |
|
3837 |
} else { |
|
3838 |
throw new Error("lookupConstant returned an object of incorrect type"); |
|
3839 |
} |
|
3840 |
} |
|
3841 |
||
50609 | 3842 |
private JavaKind refineComponentType(ValueNode array, JavaKind kind) { |
3843 |
if (kind == JavaKind.Byte) { |
|
54328 | 3844 |
JavaType type = array.stamp(NodeView.DEFAULT).javaType(getMetaAccess()); |
50609 | 3845 |
if (type.isArray()) { |
3846 |
JavaType componentType = type.getComponentType(); |
|
3847 |
if (componentType != null) { |
|
3848 |
JavaKind refinedKind = componentType.getJavaKind(); |
|
3849 |
assert refinedKind == JavaKind.Byte || refinedKind == JavaKind.Boolean; |
|
3850 |
return refinedKind; |
|
3851 |
} |
|
3852 |
} |
|
3853 |
} |
|
3854 |
return kind; |
|
3855 |
} |
|
3856 |
||
43972 | 3857 |
private void genLoadIndexed(JavaKind kind) { |
3858 |
ValueNode index = frameState.pop(JavaKind.Int); |
|
50330 | 3859 |
ValueNode array = frameState.pop(JavaKind.Object); |
3860 |
||
3861 |
array = maybeEmitExplicitNullCheck(array); |
|
3862 |
GuardingNode boundsCheck = maybeEmitExplicitBoundsCheck(array, index); |
|
43972 | 3863 |
|
3864 |
for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) { |
|
50330 | 3865 |
if (plugin.handleLoadIndexed(this, array, index, boundsCheck, kind)) { |
43972 | 3866 |
return; |
3867 |
} |
|
3868 |
} |
|
3869 |
||
50609 | 3870 |
JavaKind actualKind = refineComponentType(array, kind); |
3871 |
frameState.push(actualKind, append(genLoadIndexed(array, index, boundsCheck, actualKind))); |
|
43972 | 3872 |
} |
3873 |
||
3874 |
private void genStoreIndexed(JavaKind kind) { |
|
3875 |
ValueNode value = frameState.pop(kind); |
|
3876 |
ValueNode index = frameState.pop(JavaKind.Int); |
|
50330 | 3877 |
ValueNode array = frameState.pop(JavaKind.Object); |
3878 |
||
3879 |
array = maybeEmitExplicitNullCheck(array); |
|
3880 |
GuardingNode boundsCheck = maybeEmitExplicitBoundsCheck(array, index); |
|
3881 |
GuardingNode storeCheck = maybeEmitExplicitStoreCheck(array, kind, value); |
|
43972 | 3882 |
|
3883 |
for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) { |
|
50330 | 3884 |
if (plugin.handleStoreIndexed(this, array, index, boundsCheck, storeCheck, kind, value)) { |
43972 | 3885 |
return; |
3886 |
} |
|
3887 |
} |
|
3888 |
||
50609 | 3889 |
JavaKind actualKind = refineComponentType(array, kind); |
3890 |
genStoreIndexed(array, index, boundsCheck, storeCheck, actualKind, maskSubWordValue(value, actualKind)); |
|
43972 | 3891 |
} |
3892 |
||
3893 |
private void genArithmeticOp(JavaKind kind, int opcode) { |
|
3894 |
ValueNode y = frameState.pop(kind); |
|
3895 |
ValueNode x = frameState.pop(kind); |
|
3896 |
ValueNode v; |
|
3897 |
switch (opcode) { |
|
3898 |
case IADD: |
|
3899 |
case LADD: |
|
3900 |
v = genIntegerAdd(x, y); |
|
3901 |
break; |
|
3902 |
case FADD: |
|
3903 |
case DADD: |
|
3904 |
v = genFloatAdd(x, y); |
|
3905 |
break; |
|
3906 |
case ISUB: |
|
3907 |
case LSUB: |
|
3908 |
v = genIntegerSub(x, y); |
|
3909 |
break; |
|
3910 |
case FSUB: |
|
3911 |
case DSUB: |
|
3912 |
v = genFloatSub(x, y); |
|
3913 |
break; |
|
3914 |
case IMUL: |
|
3915 |
case LMUL: |
|
3916 |
v = genIntegerMul(x, y); |
|
3917 |
break; |
|
3918 |
case FMUL: |
|
3919 |
case DMUL: |
|
3920 |
v = genFloatMul(x, y); |
|
3921 |
break; |
|
3922 |
case FDIV: |
|
3923 |
case DDIV: |
|
3924 |
v = genFloatDiv(x, y); |
|
3925 |
break; |
|
3926 |
case FREM: |
|
3927 |
case DREM: |
|
3928 |
v = genFloatRem(x, y); |
|
3929 |
break; |
|
3930 |
default: |
|
3931 |
throw shouldNotReachHere(); |
|
3932 |
} |
|
46393 | 3933 |
frameState.push(kind, append(v)); |
43972 | 3934 |
} |
3935 |
||
3936 |
private void genIntegerDivOp(JavaKind kind, int opcode) { |
|
3937 |
ValueNode y = frameState.pop(kind); |
|
3938 |
ValueNode x = frameState.pop(kind); |
|
50330 | 3939 |
|
3940 |
GuardingNode zeroCheck = maybeEmitExplicitDivisionByZeroCheck(y); |
|
3941 |
||
43972 | 3942 |
ValueNode v; |
3943 |
switch (opcode) { |
|
3944 |
case IDIV: |
|
3945 |
case LDIV: |
|
50330 | 3946 |
v = genIntegerDiv(x, y, zeroCheck); |
43972 | 3947 |
break; |
3948 |
case IREM: |
|
3949 |
case LREM: |
|
50330 | 3950 |
v = genIntegerRem(x, y, zeroCheck); |
43972 | 3951 |
break; |
3952 |
default: |
|
3953 |
throw shouldNotReachHere(); |
|
3954 |
} |
|
3955 |
frameState.push(kind, append(v)); |
|
3956 |
} |
|
3957 |
||
3958 |
private void genNegateOp(JavaKind kind) { |
|
3959 |
ValueNode x = frameState.pop(kind); |
|
3960 |
frameState.push(kind, append(genNegateOp(x))); |
|
3961 |
} |
|
3962 |
||
3963 |
private void genShiftOp(JavaKind kind, int opcode) { |
|
3964 |
ValueNode s = frameState.pop(JavaKind.Int); |
|
3965 |
ValueNode x = frameState.pop(kind); |
|
3966 |
ValueNode v; |
|
3967 |
switch (opcode) { |
|
3968 |
case ISHL: |
|
3969 |
case LSHL: |
|
3970 |
v = genLeftShift(x, s); |
|
3971 |
break; |
|
3972 |
case ISHR: |
|
3973 |
case LSHR: |
|
3974 |
v = genRightShift(x, s); |
|
3975 |
break; |
|
3976 |
case IUSHR: |
|
3977 |
case LUSHR: |
|
3978 |
v = genUnsignedRightShift(x, s); |
|
3979 |
break; |
|
3980 |
default: |
|
3981 |
throw shouldNotReachHere(); |
|
3982 |
} |
|
46393 | 3983 |
frameState.push(kind, append(v)); |
43972 | 3984 |
} |
3985 |
||
3986 |
private void genLogicOp(JavaKind kind, int opcode) { |
|
3987 |
ValueNode y = frameState.pop(kind); |
|
3988 |
ValueNode x = frameState.pop(kind); |
|
3989 |
ValueNode v; |
|
3990 |
switch (opcode) { |
|
3991 |
case IAND: |
|
3992 |
case LAND: |
|
3993 |
v = genAnd(x, y); |
|
3994 |
break; |
|
3995 |
case IOR: |
|
3996 |
case LOR: |
|
3997 |
v = genOr(x, y); |
|
3998 |
break; |
|
3999 |
case IXOR: |
|
4000 |
case LXOR: |
|
4001 |
v = genXor(x, y); |
|
4002 |
break; |
|
4003 |
default: |
|
4004 |
throw shouldNotReachHere(); |
|
4005 |
} |
|
46393 | 4006 |
frameState.push(kind, append(v)); |
43972 | 4007 |
} |
4008 |
||
4009 |
private void genCompareOp(JavaKind kind, boolean isUnorderedLess) { |
|
4010 |
ValueNode y = frameState.pop(kind); |
|
4011 |
ValueNode x = frameState.pop(kind); |
|
4012 |
frameState.push(JavaKind.Int, append(genNormalizeCompare(x, y, isUnorderedLess))); |
|
4013 |
} |
|
4014 |
||
4015 |
private void genFloatConvert(FloatConvert op, JavaKind from, JavaKind to) { |
|
4016 |
ValueNode input = frameState.pop(from); |
|
4017 |
frameState.push(to, append(genFloatConvert(op, input))); |
|
4018 |
} |
|
4019 |
||
4020 |
private void genSignExtend(JavaKind from, JavaKind to) { |
|
4021 |
ValueNode input = frameState.pop(from); |
|
4022 |
if (from != from.getStackKind()) { |
|
4023 |
input = append(genNarrow(input, from.getBitCount())); |
|
4024 |
} |
|
46393 | 4025 |
frameState.push(to, append(genSignExtend(input, to.getBitCount()))); |
43972 | 4026 |
} |
4027 |
||
4028 |
private void genZeroExtend(JavaKind from, JavaKind to) { |
|
4029 |
ValueNode input = frameState.pop(from); |
|
4030 |
if (from != from.getStackKind()) { |
|
4031 |
input = append(genNarrow(input, from.getBitCount())); |
|
4032 |
} |
|
4033 |
frameState.push(to, append(genZeroExtend(input, to.getBitCount()))); |
|
4034 |
} |
|
4035 |
||
4036 |
private void genNarrow(JavaKind from, JavaKind to) { |
|
4037 |
ValueNode input = frameState.pop(from); |
|
4038 |
frameState.push(to, append(genNarrow(input, to.getBitCount()))); |
|
4039 |
} |
|
4040 |
||
4041 |
private void genIncrement() { |
|
4042 |
int index = getStream().readLocalIndex(); |
|
4043 |
int delta = getStream().readIncrement(); |
|
4044 |
ValueNode x = frameState.loadLocal(index, JavaKind.Int); |
|
4045 |
ValueNode y = appendConstant(JavaConstant.forInt(delta)); |
|
46393 | 4046 |
frameState.storeLocal(index, JavaKind.Int, append(genIntegerAdd(x, y))); |
43972 | 4047 |
} |
4048 |
||
4049 |
private void genIfZero(Condition cond) { |
|
4050 |
ValueNode y = appendConstant(JavaConstant.INT_0); |
|
4051 |
ValueNode x = frameState.pop(JavaKind.Int); |
|
4052 |
genIf(x, cond, y); |
|
4053 |
} |
|
4054 |
||
4055 |
private void genIfNull(Condition cond) { |
|
4056 |
ValueNode y = appendConstant(JavaConstant.NULL_POINTER); |
|
4057 |
ValueNode x = frameState.pop(JavaKind.Object); |
|
4058 |
genIf(x, cond, y); |
|
4059 |
} |
|
4060 |
||
4061 |
private void genIfSame(JavaKind kind, Condition cond) { |
|
4062 |
ValueNode y = frameState.pop(kind); |
|
4063 |
ValueNode x = frameState.pop(kind); |
|
4064 |
genIf(x, cond, y); |
|
4065 |
} |
|
4066 |
||
49451 | 4067 |
private static void initialize(ResolvedJavaType resolvedType) { |
4068 |
/* |
|
4069 |
* Since we're potentially triggering class initialization here, we need synchronization to |
|
4070 |
* mitigate the potential for class initialization related deadlock being caused by the |
|
4071 |
* compiler (e.g., https://github.com/graalvm/graal-core/pull/232/files#r90788550). |
|
4072 |
*/ |
|
4073 |
synchronized (BytecodeParser.class) { |
|
4074 |
resolvedType.initialize(); |
|
4075 |
} |
|
4076 |
} |
|
4077 |
||
43972 | 4078 |
protected JavaType lookupType(int cpi, int bytecode) { |
4079 |
maybeEagerlyResolve(cpi, bytecode); |
|
4080 |
JavaType result = constantPool.lookupType(cpi, bytecode); |
|
4081 |
assert !graphBuilderConfig.unresolvedIsError() || result instanceof ResolvedJavaType; |
|
4082 |
return result; |
|
4083 |
} |
|
4084 |
||
52578 | 4085 |
private String unresolvedMethodAssertionMessage(JavaMethod result) { |
4086 |
String message = result.format("%H.%n(%P)%R"); |
|
55509 | 4087 |
if (JavaVersionUtil.JAVA_SPEC <= 8) { |
52578 | 4088 |
JavaType declaringClass = result.getDeclaringClass(); |
4089 |
String className = declaringClass.getName(); |
|
4090 |
switch (className) { |
|
4091 |
case "Ljava/nio/ByteBuffer;": |
|
4092 |
case "Ljava/nio/ShortBuffer;": |
|
4093 |
case "Ljava/nio/CharBuffer;": |
|
4094 |
case "Ljava/nio/IntBuffer;": |
|
4095 |
case "Ljava/nio/LongBuffer;": |
|
4096 |
case "Ljava/nio/FloatBuffer;": |
|
4097 |
case "Ljava/nio/DoubleBuffer;": |
|
4098 |
case "Ljava/nio/MappedByteBuffer;": { |
|
4099 |
switch (result.getName()) { |
|
4100 |
case "position": |
|
4101 |
case "limit": |
|
4102 |
case "mark": |
|
4103 |
case "reset": |
|
4104 |
case "clear": |
|
4105 |
case "flip": |
|
4106 |
case "rewind": { |
|
4107 |
String returnType = result.getSignature().getReturnType(null).toJavaName(); |
|
4108 |
if (returnType.equals(declaringClass.toJavaName())) { |
|
4109 |
message += String.format(" [Probably cause: %s was compiled with javac from JDK 9+ using " + |
|
4110 |
"`-target 8` and `-source 8` options. See https://bugs.openjdk.java.net/browse/JDK-4774077 for details.]", method.getDeclaringClass().toClassName()); |
|
4111 |
} |
|
4112 |
} |
|
4113 |
} |
|
4114 |
break; |
|
4115 |
} |
|
4116 |
} |
|
4117 |
} |
|
4118 |
return message; |
|
4119 |
} |
|
4120 |
||
43972 | 4121 |
private JavaMethod lookupMethod(int cpi, int opcode) { |
4122 |
maybeEagerlyResolve(cpi, opcode); |
|
4123 |
JavaMethod result = constantPool.lookupMethod(cpi, opcode); |
|
52578 | 4124 |
assert !graphBuilderConfig.unresolvedIsError() || result instanceof ResolvedJavaMethod : unresolvedMethodAssertionMessage(result); |
43972 | 4125 |
return result; |
4126 |
} |
|
4127 |
||
47667 | 4128 |
protected JavaField lookupField(int cpi, int opcode) { |
43972 | 4129 |
maybeEagerlyResolve(cpi, opcode); |
4130 |
JavaField result = constantPool.lookupField(cpi, method, opcode); |
|
52578 | 4131 |
return lookupField(result); |
4132 |
} |
|
4133 |
||
4134 |
protected JavaField lookupField(JavaField result) { |
|
49451 | 4135 |
assert !graphBuilderConfig.unresolvedIsError() || result instanceof ResolvedJavaField : "Not resolved: " + result; |
4136 |
if (parsingIntrinsic() || eagerInitializing) { |
|
47667 | 4137 |
if (result instanceof ResolvedJavaField) { |
4138 |
ResolvedJavaType declaringClass = ((ResolvedJavaField) result).getDeclaringClass(); |
|
4139 |
if (!declaringClass.isInitialized()) { |
|
49451 | 4140 |
// Even with eager initialization, superinterfaces are not always initialized. |
4141 |
// See StaticInterfaceFieldTest |
|
4142 |
assert !eagerInitializing || declaringClass.isInterface() : "Declaring class not initialized but not an interface? " + declaringClass; |
|
4143 |
initialize(declaringClass); |
|
47667 | 4144 |
} |
43972 | 4145 |
} |
4146 |
} |
|
49451 | 4147 |
assert !uninitializedIsError || (result instanceof ResolvedJavaField && ((ResolvedJavaField) result).getDeclaringClass().isInitialized()) : result; |
43972 | 4148 |
return result; |
4149 |
} |
|
4150 |
||
4151 |
private Object lookupConstant(int cpi, int opcode) { |
|
4152 |
maybeEagerlyResolve(cpi, opcode); |
|
4153 |
Object result = constantPool.lookupConstant(cpi); |
|
47667 | 4154 |
assert !graphBuilderConfig.unresolvedIsError() || !(result instanceof JavaType) || (result instanceof ResolvedJavaType) : result; |
43972 | 4155 |
return result; |
4156 |
} |
|
4157 |
||
47667 | 4158 |
protected void maybeEagerlyResolve(int cpi, int bytecode) { |
43972 | 4159 |
if (intrinsicContext != null) { |
4160 |
constantPool.loadReferencedType(cpi, bytecode); |
|
4161 |
} else if (graphBuilderConfig.eagerResolving()) { |
|
4162 |
/* |
|
4163 |
* Since we're potentially triggering class initialization here, we need synchronization |
|
4164 |
* to mitigate the potential for class initialization related deadlock being caused by |
|
4165 |
* the compiler (e.g., https://github.com/graalvm/graal-core/pull/232/files#r90788550). |
|
4166 |
*/ |
|
4167 |
synchronized (BytecodeParser.class) { |
|
49451 | 4168 |
ClassInitializationPlugin classInitializationPlugin = graphBuilderConfig.getPlugins().getClassInitializationPlugin(); |
4169 |
if (classInitializationPlugin != null) { |
|
4170 |
classInitializationPlugin.loadReferencedType(this, constantPool, cpi, bytecode); |
|
4171 |
} else { |
|
4172 |
constantPool.loadReferencedType(cpi, bytecode); |
|
4173 |
} |
|
43972 | 4174 |
} |
4175 |
} |
|
4176 |
} |
|
4177 |
||
55509 | 4178 |
protected JavaType maybeEagerlyResolve(JavaType type, ResolvedJavaType accessingClass) { |
4179 |
if (graphBuilderConfig.eagerResolving() || parsingIntrinsic()) { |
|
4180 |
return type.resolve(accessingClass); |
|
4181 |
} |
|
4182 |
return type; |
|
4183 |
} |
|
4184 |
||
52910 | 4185 |
protected void maybeEagerlyInitialize(ResolvedJavaType resolvedType) { |
4186 |
if (!resolvedType.isInitialized() && eagerInitializing) { |
|
4187 |
initialize(resolvedType); |
|
4188 |
} |
|
4189 |
} |
|
4190 |
||
43972 | 4191 |
private JavaTypeProfile getProfileForTypeCheck(TypeReference type) { |
46344 | 4192 |
if (parsingIntrinsic() || profilingInfo == null || !optimisticOpts.useTypeCheckHints(getOptions()) || type.isExact()) { |
43972 | 4193 |
return null; |
4194 |
} else { |
|
4195 |
return profilingInfo.getTypeProfile(bci()); |
|
4196 |
} |
|
4197 |
} |
|
4198 |
||
52578 | 4199 |
private void genCheckCast(int cpi) { |
43972 | 4200 |
JavaType type = lookupType(cpi, CHECKCAST); |
4201 |
ValueNode object = frameState.pop(JavaKind.Object); |
|
52578 | 4202 |
genCheckCast(type, object); |
4203 |
} |
|
4204 |
||
4205 |
protected void genCheckCast(JavaType type, ValueNode object) { |
|
4206 |
if (typeIsResolved(type)) { |
|
4207 |
genCheckCast((ResolvedJavaType) type, object); |
|
4208 |
} else { |
|
43972 | 4209 |
handleUnresolvedCheckCast(type, object); |
52578 | 4210 |
} |
4211 |
} |
|
4212 |
||
4213 |
protected void genCheckCast(ResolvedJavaType resolvedType, ValueNode objectIn) { |
|
4214 |
ValueNode object = objectIn; |
|
50330 | 4215 |
TypeReference checkedType = TypeReference.createTrusted(graph.getAssumptions(), resolvedType); |
43972 | 4216 |
JavaTypeProfile profile = getProfileForTypeCheck(checkedType); |
4217 |
||
4218 |
for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) { |
|
4219 |
if (plugin.handleCheckCast(this, object, checkedType.getType(), profile)) { |
|
4220 |
return; |
|
4221 |
} |
|
4222 |
} |
|
4223 |
||
4224 |
ValueNode castNode = null; |
|
4225 |
if (profile != null) { |
|
4226 |
if (profile.getNullSeen().isFalse()) { |
|
46344 | 4227 |
object = nullCheckedValue(object); |
43972 | 4228 |
ResolvedJavaType singleType = profile.asSingleType(); |
4229 |
if (singleType != null && checkedType.getType().isAssignableFrom(singleType)) { |
|
4230 |
LogicNode typeCheck = append(createInstanceOf(TypeReference.createExactTrusted(singleType), object, profile)); |
|
4231 |
if (typeCheck.isTautology()) { |
|
4232 |
castNode = object; |
|
4233 |
} else { |
|
4234 |
FixedGuardNode fixedGuard = append(new FixedGuardNode(typeCheck, DeoptimizationReason.TypeCheckedInliningViolated, DeoptimizationAction.InvalidateReprofile, false)); |
|
46371 | 4235 |
castNode = append(PiNode.create(object, StampFactory.objectNonNull(TypeReference.createExactTrusted(singleType)), fixedGuard)); |
43972 | 4236 |
} |
4237 |
} |
|
4238 |
} |
|
4239 |
} |
|
46344 | 4240 |
|
48190 | 4241 |
boolean nonNull = ((ObjectStamp) object.stamp(NodeView.DEFAULT)).nonNull(); |
43972 | 4242 |
if (castNode == null) { |
4243 |
LogicNode condition = genUnique(createInstanceOfAllowNull(checkedType, object, null)); |
|
4244 |
if (condition.isTautology()) { |
|
4245 |
castNode = object; |
|
4246 |
} else { |
|
50330 | 4247 |
GuardingNode guard; |
4248 |
if (needsExplicitClassCastException(object)) { |
|
4249 |
Constant hub = getConstantReflection().asObjectHub(resolvedType); |
|
4250 |
Stamp hubStamp = getStampProvider().createHubStamp(StampFactory.object(TypeReference.createExactTrusted(resolvedType))); |
|
4251 |
ConstantNode hubConstant = ConstantNode.forConstant(hubStamp, hub, getMetaAccess(), graph); |
|
4252 |
guard = emitBytecodeExceptionCheck(condition, true, BytecodeExceptionKind.CLASS_CAST, object, hubConstant); |
|
4253 |
} else { |
|
4254 |
guard = append(new FixedGuardNode(condition, DeoptimizationReason.ClassCastException, DeoptimizationAction.InvalidateReprofile, false)); |
|
4255 |
} |
|
4256 |
castNode = append(PiNode.create(object, StampFactory.object(checkedType, nonNull), guard.asNode())); |
|
43972 | 4257 |
} |
4258 |
} |
|
4259 |
frameState.push(JavaKind.Object, castNode); |
|
4260 |
} |
|
4261 |
||
52578 | 4262 |
private void genInstanceOf(int cpi) { |
43972 | 4263 |
JavaType type = lookupType(cpi, INSTANCEOF); |
4264 |
ValueNode object = frameState.pop(JavaKind.Object); |
|
52578 | 4265 |
genInstanceOf(type, object); |
4266 |
} |
|
4267 |
||
4268 |
protected void genInstanceOf(JavaType type, ValueNode object) { |
|
4269 |
if (typeIsResolved(type)) { |
|
4270 |
genInstanceOf((ResolvedJavaType) type, object); |
|
4271 |
} else { |
|
43972 | 4272 |
handleUnresolvedInstanceOf(type, object); |
52578 | 4273 |
} |
4274 |
} |
|
4275 |
||
4276 |
protected void genInstanceOf(ResolvedJavaType resolvedType, ValueNode objectIn) { |
|
4277 |
ValueNode object = objectIn; |
|
4278 |
TypeReference checkedType = TypeReference.createTrusted(graph.getAssumptions(), resolvedType); |
|
4279 |
JavaTypeProfile profile = getProfileForTypeCheck(checkedType); |
|
43972 | 4280 |
|
4281 |
for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) { |
|
52578 | 4282 |
if (plugin.handleInstanceOf(this, object, checkedType.getType(), profile)) { |
43972 | 4283 |
return; |
4284 |
} |
|
4285 |
} |
|
4286 |
||
4287 |
LogicNode instanceOfNode = null; |
|
4288 |
if (profile != null) { |
|
4289 |
if (profile.getNullSeen().isFalse()) { |
|
46344 | 4290 |
object = nullCheckedValue(object); |
43972 | 4291 |
ResolvedJavaType singleType = profile.asSingleType(); |
4292 |
if (singleType != null) { |
|
4293 |
LogicNode typeCheck = append(createInstanceOf(TypeReference.createExactTrusted(singleType), object, profile)); |
|
4294 |
if (!typeCheck.isTautology()) { |
|
4295 |
append(new FixedGuardNode(typeCheck, DeoptimizationReason.TypeCheckedInliningViolated, DeoptimizationAction.InvalidateReprofile)); |
|
4296 |
} |
|
52578 | 4297 |
instanceOfNode = LogicConstantNode.forBoolean(checkedType.getType().isAssignableFrom(singleType)); |
43972 | 4298 |
} |
4299 |
} |
|
4300 |
} |
|
4301 |
if (instanceOfNode == null) { |
|
52578 | 4302 |
instanceOfNode = createInstanceOf(checkedType, object, null); |
43972 | 4303 |
} |
46344 | 4304 |
LogicNode logicNode = genUnique(instanceOfNode); |
4305 |
||
4306 |
int next = getStream().nextBCI(); |
|
4307 |
int value = getStream().readUByte(next); |
|
46371 | 4308 |
if (next <= currentBlock.endBci && (value == Bytecodes.IFEQ || value == Bytecodes.IFNE)) { |
46344 | 4309 |
getStream().next(); |
4310 |
BciBlock firstSucc = currentBlock.getSuccessor(0); |
|
4311 |
BciBlock secondSucc = currentBlock.getSuccessor(1); |
|
4312 |
if (firstSucc != secondSucc) { |
|
48861 | 4313 |
boolean negate = value != Bytecodes.IFNE; |
4314 |
if (negate) { |
|
4315 |
BciBlock tmp = firstSucc; |
|
4316 |
firstSucc = secondSucc; |
|
4317 |
secondSucc = tmp; |
|
4318 |
} |
|
4319 |
genIf(instanceOfNode, firstSucc, secondSucc, getProfileProbability(negate)); |
|
46344 | 4320 |
} else { |
4321 |
appendGoto(firstSucc); |
|
4322 |
} |
|
4323 |
} else { |
|
4324 |
// Most frequent for value is IRETURN, followed by ISTORE. |
|
4325 |
frameState.push(JavaKind.Int, append(genConditional(logicNode))); |
|
4326 |
} |
|
43972 | 4327 |
} |
4328 |
||
47667 | 4329 |
protected void genNewInstance(int cpi) { |
43972 | 4330 |
JavaType type = lookupType(cpi, NEW); |
47667 | 4331 |
genNewInstance(type); |
4332 |
} |
|
4333 |
||
52578 | 4334 |
protected void genNewInstance(JavaType type) { |
4335 |
if (typeIsResolved(type)) { |
|
4336 |
genNewInstance((ResolvedJavaType) type); |
|
4337 |
} else { |
|
43972 | 4338 |
handleUnresolvedNewInstance(type); |
52578 | 4339 |
} |
4340 |
} |
|
4341 |
||
4342 |
protected void genNewInstance(ResolvedJavaType resolvedType) { |
|
51736 | 4343 |
if (resolvedType.isAbstract() || resolvedType.isInterface()) { |
52578 | 4344 |
handleIllegalNewInstance(resolvedType); |
51736 | 4345 |
return; |
4346 |
} |
|
52910 | 4347 |
maybeEagerlyInitialize(resolvedType); |
4348 |
||
49451 | 4349 |
ClassInitializationPlugin classInitializationPlugin = graphBuilderConfig.getPlugins().getClassInitializationPlugin(); |
4350 |
if (!resolvedType.isInitialized() && classInitializationPlugin == null) { |
|
52578 | 4351 |
handleIllegalNewInstance(resolvedType); |
49451 | 4352 |
return; |
4353 |
} |
|
43972 | 4354 |
|
54084 | 4355 |
for (ResolvedJavaType exceptionType : this.graphBuilderConfig.getSkippedExceptionTypes()) { |
4356 |
if (exceptionType.isAssignableFrom(resolvedType)) { |
|
4357 |
append(new DeoptimizeNode(DeoptimizationAction.InvalidateRecompile, RuntimeConstraint)); |
|
4358 |
return; |
|
43972 | 4359 |
} |
4360 |
} |
|
4361 |
||
52910 | 4362 |
if (classInitializationPlugin != null) { |
4363 |
classInitializationPlugin.apply(this, resolvedType, this::createCurrentFrameState); |
|
43972 | 4364 |
} |
4365 |
||
4366 |
for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) { |
|
4367 |
if (plugin.handleNewInstance(this, resolvedType)) { |
|
4368 |
return; |
|
4369 |
} |
|
4370 |
} |
|
4371 |
||
4372 |
frameState.push(JavaKind.Object, append(createNewInstance(resolvedType, true))); |
|
4373 |
} |
|
4374 |
||
4375 |
/** |
|
4376 |
* Gets the kind of array elements for the array type code that appears in a |
|
4377 |
* {@link Bytecodes#NEWARRAY} bytecode. |
|
4378 |
* |
|
4379 |
* @param code the array type code |
|
4380 |
* @return the kind from the array type code |
|
4381 |
*/ |
|
4382 |
private static Class<?> arrayTypeCodeToClass(int code) { |
|
4383 |
switch (code) { |
|
4384 |
case 4: |
|
4385 |
return boolean.class; |
|
4386 |
case 5: |
|
4387 |
return char.class; |
|
4388 |
case 6: |
|
4389 |
return float.class; |
|
4390 |
case 7: |
|
4391 |
return double.class; |
|
4392 |
case 8: |
|
4393 |
return byte.class; |
|
4394 |
case 9: |
|
4395 |
return short.class; |
|
4396 |
case 10: |
|
4397 |
return int.class; |
|
4398 |
case 11: |
|
4399 |
return long.class; |
|
4400 |
default: |
|
4401 |
throw new IllegalArgumentException("unknown array type code: " + code); |
|
4402 |
} |
|
4403 |
} |
|
4404 |
||
4405 |
private void genNewPrimitiveArray(int typeCode) { |
|
54328 | 4406 |
ResolvedJavaType elementType = getMetaAccess().lookupJavaType(arrayTypeCodeToClass(typeCode)); |
43972 | 4407 |
ValueNode length = frameState.pop(JavaKind.Int); |
4408 |
||
4409 |
for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) { |
|
4410 |
if (plugin.handleNewArray(this, elementType, length)) { |
|
4411 |
return; |
|
4412 |
} |
|
4413 |
} |
|
4414 |
||
4415 |
frameState.push(JavaKind.Object, append(createNewArray(elementType, length, true))); |
|
4416 |
} |
|
4417 |
||
4418 |
private void genNewObjectArray(int cpi) { |
|
4419 |
JavaType type = lookupType(cpi, ANEWARRAY); |
|
52578 | 4420 |
genNewObjectArray(type); |
4421 |
} |
|
4422 |
||
4423 |
private void genNewObjectArray(JavaType type) { |
|
4424 |
if (typeIsResolved(type)) { |
|
4425 |
genNewObjectArray((ResolvedJavaType) type); |
|
4426 |
} else { |
|
43972 | 4427 |
ValueNode length = frameState.pop(JavaKind.Int); |
4428 |
handleUnresolvedNewObjectArray(type, length); |
|
52578 | 4429 |
} |
4430 |
} |
|
4431 |
||
4432 |
private void genNewObjectArray(ResolvedJavaType resolvedType) { |
|
43972 | 4433 |
|
4434 |
ClassInitializationPlugin classInitializationPlugin = this.graphBuilderConfig.getPlugins().getClassInitializationPlugin(); |
|
52910 | 4435 |
if (classInitializationPlugin != null) { |
4436 |
classInitializationPlugin.apply(this, resolvedType.getArrayClass(), this::createCurrentFrameState); |
|
43972 | 4437 |
} |
4438 |
||
4439 |
ValueNode length = frameState.pop(JavaKind.Int); |
|
4440 |
for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) { |
|
4441 |
if (plugin.handleNewArray(this, resolvedType, length)) { |
|
4442 |
return; |
|
4443 |
} |
|
4444 |
} |
|
4445 |
||
4446 |
frameState.push(JavaKind.Object, append(createNewArray(resolvedType, length, true))); |
|
4447 |
} |
|
4448 |
||
4449 |
private void genNewMultiArray(int cpi) { |
|
4450 |
JavaType type = lookupType(cpi, MULTIANEWARRAY); |
|
4451 |
int rank = getStream().readUByte(bci() + 3); |
|
4452 |
ValueNode[] dims = new ValueNode[rank]; |
|
52578 | 4453 |
genNewMultiArray(type, rank, dims); |
4454 |
} |
|
4455 |
||
4456 |
private void genNewMultiArray(JavaType type, int rank, ValueNode[] dims) { |
|
4457 |
if (typeIsResolved(type)) { |
|
4458 |
genNewMultiArray((ResolvedJavaType) type, rank, dims); |
|
4459 |
} else { |
|
43972 | 4460 |
for (int i = rank - 1; i >= 0; i--) { |
4461 |
dims[i] = frameState.pop(JavaKind.Int); |
|
4462 |
} |
|
4463 |
handleUnresolvedNewMultiArray(type, dims); |
|
52578 | 4464 |
} |
4465 |
} |
|
4466 |
||
4467 |
private void genNewMultiArray(ResolvedJavaType resolvedType, int rank, ValueNode[] dims) { |
|
43972 | 4468 |
|
4469 |
ClassInitializationPlugin classInitializationPlugin = this.graphBuilderConfig.getPlugins().getClassInitializationPlugin(); |
|
52910 | 4470 |
if (classInitializationPlugin != null) { |
4471 |
classInitializationPlugin.apply(this, resolvedType, this::createCurrentFrameState); |
|
43972 | 4472 |
} |
4473 |
||
4474 |
for (int i = rank - 1; i >= 0; i--) { |
|
4475 |
dims[i] = frameState.pop(JavaKind.Int); |
|
4476 |
} |
|
4477 |
||
4478 |
for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) { |
|
4479 |
if (plugin.handleNewMultiArray(this, resolvedType, dims)) { |
|
4480 |
return; |
|
4481 |
} |
|
4482 |
} |
|
4483 |
||
4484 |
frameState.push(JavaKind.Object, append(createNewMultiArray(resolvedType, dims))); |
|
4485 |
} |
|
4486 |
||
47667 | 4487 |
protected void genGetField(int cpi, int opcode) { |
4488 |
genGetField(cpi, opcode, frameState.pop(JavaKind.Object)); |
|
4489 |
} |
|
4490 |
||
4491 |
protected void genGetField(int cpi, int opcode, ValueNode receiverInput) { |
|
4492 |
JavaField field = lookupField(cpi, opcode); |
|
4493 |
genGetField(field, receiverInput); |
|
46344 | 4494 |
} |
4495 |
||
4496 |
private void genGetField(JavaField field, ValueNode receiverInput) { |
|
4497 |
if (field instanceof ResolvedJavaField) { |
|
52578 | 4498 |
ValueNode receiver = maybeEmitExplicitNullCheck(receiverInput); |
46344 | 4499 |
ResolvedJavaField resolvedField = (ResolvedJavaField) field; |
4500 |
genGetField(resolvedField, receiver); |
|
4501 |
} else { |
|
52578 | 4502 |
handleUnresolvedLoadField(field, receiverInput); |
43972 | 4503 |
} |
46344 | 4504 |
} |
4505 |
||
4506 |
private void genGetField(ResolvedJavaField resolvedField, ValueNode receiver) { |
|
4507 |
if (!parsingIntrinsic() && GeneratePIC.getValue(getOptions())) { |
|
43972 | 4508 |
graph.recordField(resolvedField); |
4509 |
} |
|
4510 |
||
4511 |
for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) { |
|
4512 |
if (plugin.handleLoadField(this, receiver, resolvedField)) { |
|
4513 |
return; |
|
4514 |
} |
|
4515 |
} |
|
4516 |
||
46762 | 4517 |
ValueNode fieldRead = append(genLoadField(receiver, resolvedField)); |
4518 |
||
46344 | 4519 |
if (resolvedField.getDeclaringClass().getName().equals("Ljava/lang/ref/Reference;") && resolvedField.getName().equals("referent")) { |
43972 | 4520 |
LocationIdentity referentIdentity = new FieldLocationIdentity(resolvedField); |
4521 |
append(new MembarNode(0, referentIdentity)); |
|
4522 |
} |
|
46762 | 4523 |
|
4524 |
JavaKind fieldKind = resolvedField.getJavaKind(); |
|
4525 |
||
51436 | 4526 |
pushLoadField(resolvedField, fieldRead, fieldKind); |
43972 | 4527 |
} |
4528 |
||
4529 |
/** |
|
50330 | 4530 |
* Returns true if an explicit null check should be emitted for the given object. |
4531 |
* |
|
4532 |
* @param object The object that is accessed. |
|
4533 |
*/ |
|
4534 |
protected boolean needsExplicitNullCheckException(ValueNode object) { |
|
4535 |
return needsExplicitException(); |
|
4536 |
} |
|
4537 |
||
4538 |
/** |
|
4539 |
* Returns true if an explicit null check should be emitted for the given object. |
|
4540 |
* |
|
4541 |
* @param array The array that is accessed. |
|
4542 |
* @param index The array index that is accessed. |
|
4543 |
*/ |
|
4544 |
protected boolean needsExplicitBoundsCheckException(ValueNode array, ValueNode index) { |
|
4545 |
return needsExplicitException(); |
|
4546 |
} |
|
4547 |
||
4548 |
/** |
|
4549 |
* Returns true if an explicit check for a {@link ClassCastException} should be emitted for the |
|
4550 |
* given object. |
|
4551 |
* |
|
4552 |
* @param object The object that is accessed. |
|
43972 | 4553 |
*/ |
50330 | 4554 |
protected boolean needsExplicitClassCastException(ValueNode object) { |
4555 |
return needsExplicitException(); |
|
4556 |
} |
|
4557 |
||
4558 |
/** |
|
4559 |
* Returns true if an explicit null check should be emitted for the given object. |
|
4560 |
* |
|
4561 |
* @param array The array that is accessed. |
|
4562 |
* @param value The value that is stored into the array. |
|
4563 |
*/ |
|
4564 |
protected boolean needsExplicitStoreCheckException(ValueNode array, ValueNode value) { |
|
4565 |
return needsExplicitException(); |
|
4566 |
} |
|
4567 |
||
4568 |
/** |
|
4569 |
* Returns true if an explicit null check should be emitted for the given object. |
|
4570 |
* |
|
4571 |
* @param y The dividend. |
|
4572 |
*/ |
|
4573 |
protected boolean needsExplicitDivisionByZeroException(ValueNode y) { |
|
4574 |
return needsExplicitException(); |
|
4575 |
} |
|
4576 |
||
51436 | 4577 |
@Override |
4578 |
public boolean needsExplicitException() { |
|
46344 | 4579 |
BytecodeExceptionMode exceptionMode = graphBuilderConfig.getBytecodeExceptionMode(); |
4580 |
if (exceptionMode == BytecodeExceptionMode.CheckAll || StressExplicitExceptionCode.getValue(options)) { |
|
4581 |
return true; |
|
4582 |
} else if (exceptionMode == BytecodeExceptionMode.Profile && profilingInfo != null) { |
|
4583 |
return profilingInfo.getExceptionSeen(bci()) == TriState.TRUE; |
|
4584 |
} |
|
4585 |
return false; |
|
43972 | 4586 |
} |
4587 |
||
51436 | 4588 |
@Override |
4589 |
public AbstractBeginNode genExplicitExceptionEdge(BytecodeExceptionKind exceptionKind) { |
|
54328 | 4590 |
BytecodeExceptionNode exceptionNode = graph.add(new BytecodeExceptionNode(getMetaAccess(), exceptionKind)); |
51436 | 4591 |
exceptionNode.setStateAfter(createFrameState(bci(), exceptionNode)); |
4592 |
AbstractBeginNode exceptionDispatch = handleException(exceptionNode, bci(), false); |
|
4593 |
exceptionNode.setNext(exceptionDispatch); |
|
4594 |
return BeginNode.begin(exceptionNode); |
|
4595 |
} |
|
4596 |
||
47667 | 4597 |
protected void genPutField(int cpi, int opcode) { |
4598 |
JavaField field = lookupField(cpi, opcode); |
|
4599 |
genPutField(field); |
|
4600 |
} |
|
4601 |
||
4602 |
protected void genPutField(JavaField field) { |
|
46344 | 4603 |
genPutField(field, frameState.pop(field.getJavaKind())); |
4604 |
} |
|
4605 |
||
4606 |
private void genPutField(JavaField field, ValueNode value) { |
|
52578 | 4607 |
ValueNode receiverInput = frameState.pop(JavaKind.Object); |
50330 | 4608 |
|
46344 | 4609 |
if (field instanceof ResolvedJavaField) { |
52578 | 4610 |
ValueNode receiver = maybeEmitExplicitNullCheck(receiverInput); |
46344 | 4611 |
ResolvedJavaField resolvedField = (ResolvedJavaField) field; |
4612 |
||
4613 |
if (!parsingIntrinsic() && GeneratePIC.getValue(getOptions())) { |
|
4614 |
graph.recordField(resolvedField); |
|
4615 |
} |
|
4616 |
||
4617 |
for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) { |
|
4618 |
if (plugin.handleStoreField(this, receiver, resolvedField, value)) { |
|
4619 |
return; |
|
4620 |
} |
|
4621 |
} |
|
4622 |
||
4623 |
if (resolvedField.isFinal() && method.isConstructor()) { |
|
4624 |
finalBarrierRequired = true; |
|
4625 |
} |
|
4626 |
genStoreField(receiver, resolvedField, value); |
|
4627 |
} else { |
|
52578 | 4628 |
handleUnresolvedStoreField(field, value, receiverInput); |
43972 | 4629 |
} |
4630 |
} |
|
4631 |
||
47667 | 4632 |
protected void genGetStatic(int cpi, int opcode) { |
4633 |
JavaField field = lookupField(cpi, opcode); |
|
4634 |
genGetStatic(field); |
|
4635 |
} |
|
4636 |
||
43972 | 4637 |
private void genGetStatic(JavaField field) { |
46371 | 4638 |
ResolvedJavaField resolvedField = resolveStaticFieldAccess(field, null); |
4639 |
if (resolvedField == null) { |
|
43972 | 4640 |
return; |
4641 |
} |
|
4642 |
||
46344 | 4643 |
if (!parsingIntrinsic() && GeneratePIC.getValue(getOptions())) { |
43972 | 4644 |
graph.recordField(resolvedField); |
4645 |
} |
|
4646 |
||
4647 |
/* |
|
4648 |
* Javac does not allow use of "$assertionsDisabled" for a field name but Eclipse does, in |
|
4649 |
* which case a suffix is added to the generated field. |
|
4650 |
*/ |
|
54084 | 4651 |
if (resolvedField.isSynthetic() && resolvedField.getName().startsWith("$assertionsDisabled")) { |
4652 |
if (parsingIntrinsic()) { |
|
54601 | 4653 |
throw new GraalError("Cannot use an assertion within the context of an intrinsic: " + resolvedField); |
54084 | 4654 |
} else if (graphBuilderConfig.omitAssertions()) { |
4655 |
frameState.push(field.getJavaKind(), ConstantNode.forBoolean(true, graph)); |
|
4656 |
return; |
|
4657 |
} |
|
43972 | 4658 |
} |
4659 |
||
52910 | 4660 |
ResolvedJavaType holder = resolvedField.getDeclaringClass(); |
43972 | 4661 |
ClassInitializationPlugin classInitializationPlugin = this.graphBuilderConfig.getPlugins().getClassInitializationPlugin(); |
52910 | 4662 |
if (classInitializationPlugin != null) { |
4663 |
classInitializationPlugin.apply(this, holder, this::createCurrentFrameState); |
|
43972 | 4664 |
} |
4665 |
||
4666 |
for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) { |
|
4667 |
if (plugin.handleLoadStaticField(this, resolvedField)) { |
|
4668 |
return; |
|
4669 |
} |
|
4670 |
} |
|
4671 |
||
51436 | 4672 |
ValueNode fieldRead = append(genLoadField(null, resolvedField)); |
4673 |
JavaKind fieldKind = resolvedField.getJavaKind(); |
|
4674 |
||
4675 |
pushLoadField(resolvedField, fieldRead, fieldKind); |
|
4676 |
} |
|
4677 |
||
4678 |
/** |
|
4679 |
* Pushes a loaded field onto the stack. If the loaded field is volatile, a |
|
4680 |
* {@link StateSplitProxyNode} is appended so that deoptimization does not deoptimize to a point |
|
4681 |
* before the field load. |
|
4682 |
*/ |
|
4683 |
private void pushLoadField(ResolvedJavaField resolvedField, ValueNode fieldRead, JavaKind fieldKind) { |
|
4684 |
if (resolvedField.isVolatile() && fieldRead instanceof LoadFieldNode) { |
|
4685 |
StateSplitProxyNode readProxy = append(genVolatileFieldReadProxy(fieldRead)); |
|
4686 |
frameState.push(fieldKind, readProxy); |
|
4687 |
readProxy.setStateAfter(frameState.create(stream.nextBCI(), readProxy)); |
|
4688 |
} else { |
|
4689 |
frameState.push(fieldKind, fieldRead); |
|
4690 |
} |
|
43972 | 4691 |
} |
4692 |
||
46371 | 4693 |
private ResolvedJavaField resolveStaticFieldAccess(JavaField field, ValueNode value) { |
4694 |
if (field instanceof ResolvedJavaField) { |
|
4695 |
ResolvedJavaField resolvedField = (ResolvedJavaField) field; |
|
53033
dcbb71b9e7c0
8215319: jck lang/INTF/intf049/intf04901 fails in Graal as JIT mode with -Xcomp and AOTed Graal
dnsimon
parents:
52910
diff
changeset
|
4696 |
ResolvedJavaType resolvedType = resolvedField.getDeclaringClass(); |
dcbb71b9e7c0
8215319: jck lang/INTF/intf049/intf04901 fails in Graal as JIT mode with -Xcomp and AOTed Graal
dnsimon
parents:
52910
diff
changeset
|
4697 |
maybeEagerlyInitialize(resolvedType); |
dcbb71b9e7c0
8215319: jck lang/INTF/intf049/intf04901 fails in Graal as JIT mode with -Xcomp and AOTed Graal
dnsimon
parents:
52910
diff
changeset
|
4698 |
|
dcbb71b9e7c0
8215319: jck lang/INTF/intf049/intf04901 fails in Graal as JIT mode with -Xcomp and AOTed Graal
dnsimon
parents:
52910
diff
changeset
|
4699 |
if (resolvedType.isInitialized() || graphBuilderConfig.getPlugins().getClassInitializationPlugin() != null) { |
46371 | 4700 |
return resolvedField; |
4701 |
} |
|
53033
dcbb71b9e7c0
8215319: jck lang/INTF/intf049/intf04901 fails in Graal as JIT mode with -Xcomp and AOTed Graal
dnsimon
parents:
52910
diff
changeset
|
4702 |
|
46371 | 4703 |
/* |
4704 |
* Static fields have initialization semantics but may be safely accessed under certain |
|
4705 |
* conditions while the class is being initialized. Executing in the clinit or init of |
|
53033
dcbb71b9e7c0
8215319: jck lang/INTF/intf049/intf04901 fails in Graal as JIT mode with -Xcomp and AOTed Graal
dnsimon
parents:
52910
diff
changeset
|
4706 |
* subclasses (but not implementers) of the field holder are sure to be running in a |
dcbb71b9e7c0
8215319: jck lang/INTF/intf049/intf04901 fails in Graal as JIT mode with -Xcomp and AOTed Graal
dnsimon
parents:
52910
diff
changeset
|
4707 |
* context where the access is safe. |
46371 | 4708 |
*/ |
53033
dcbb71b9e7c0
8215319: jck lang/INTF/intf049/intf04901 fails in Graal as JIT mode with -Xcomp and AOTed Graal
dnsimon
parents:
52910
diff
changeset
|
4709 |
if (!resolvedType.isInterface() && resolvedType.isAssignableFrom(method.getDeclaringClass())) { |
46371 | 4710 |
if (method.isClassInitializer() || method.isConstructor()) { |
4711 |
return resolvedField; |
|
4712 |
} |
|
4713 |
} |
|
4714 |
} |
|
4715 |
if (value == null) { |
|
4716 |
handleUnresolvedLoadField(field, null); |
|
4717 |
} else { |
|
4718 |
handleUnresolvedStoreField(field, value, null); |
|
4719 |
||
4720 |
} |
|
4721 |
return null; |
|
4722 |
} |
|
4723 |
||
47667 | 4724 |
protected void genPutStatic(int cpi, int opcode) { |
4725 |
JavaField field = lookupField(cpi, opcode); |
|
4726 |
genPutStatic(field); |
|
4727 |
} |
|
4728 |
||
4729 |
protected void genPutStatic(JavaField field) { |
|
52578 | 4730 |
int stackSizeBefore = frameState.stackSize(); |
43972 | 4731 |
ValueNode value = frameState.pop(field.getJavaKind()); |
46371 | 4732 |
ResolvedJavaField resolvedField = resolveStaticFieldAccess(field, value); |
4733 |
if (resolvedField == null) { |
|
43972 | 4734 |
return; |
4735 |
} |
|
4736 |
||
46344 | 4737 |
if (!parsingIntrinsic() && GeneratePIC.getValue(getOptions())) { |
43972 | 4738 |
graph.recordField(resolvedField); |
4739 |
} |
|
4740 |
||
4741 |
ClassInitializationPlugin classInitializationPlugin = this.graphBuilderConfig.getPlugins().getClassInitializationPlugin(); |
|
52910 | 4742 |
ResolvedJavaType holder = resolvedField.getDeclaringClass(); |
4743 |
if (classInitializationPlugin != null) { |
|
4744 |
Supplier<FrameState> stateBefore = () -> { |
|
4745 |
JavaKind[] pushedSlotKinds = {field.getJavaKind()}; |
|
4746 |
ValueNode[] pushedValues = {value}; |
|
4747 |
FrameState fs = frameState.create(bci(), getNonIntrinsicAncestor(), false, pushedSlotKinds, pushedValues); |
|
4748 |
assert stackSizeBefore == fs.stackSize(); |
|
4749 |
return fs; |
|
4750 |
}; |
|
4751 |
classInitializationPlugin.apply(this, holder, stateBefore); |
|
43972 | 4752 |
} |
4753 |
||
4754 |
for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) { |
|
4755 |
if (plugin.handleStoreStaticField(this, resolvedField, value)) { |
|
4756 |
return; |
|
4757 |
} |
|
4758 |
} |
|
4759 |
||
4760 |
genStoreField(null, resolvedField, value); |
|
4761 |
} |
|
4762 |
||
4763 |
private double[] switchProbability(int numberOfCases, int bci) { |
|
4764 |
double[] prob = (profilingInfo == null ? null : profilingInfo.getSwitchProbabilities(bci)); |
|
4765 |
if (prob != null) { |
|
4766 |
assert prob.length == numberOfCases; |
|
4767 |
} else { |
|
46640 | 4768 |
debug.log("Missing probability (switch) in %s at bci %d", method, bci); |
43972 | 4769 |
prob = new double[numberOfCases]; |
4770 |
for (int i = 0; i < numberOfCases; i++) { |
|
4771 |
prob[i] = 1.0d / numberOfCases; |
|
4772 |
} |
|
4773 |
} |
|
4774 |
assert allPositive(prob); |
|
4775 |
return prob; |
|
4776 |
} |
|
4777 |
||
4778 |
private static boolean allPositive(double[] a) { |
|
4779 |
for (double d : a) { |
|
4780 |
if (d < 0) { |
|
4781 |
return false; |
|
4782 |
} |
|
4783 |
} |
|
4784 |
return true; |
|
4785 |
} |
|
4786 |
||
4787 |
static class SuccessorInfo { |
|
4788 |
final int blockIndex; |
|
4789 |
int actualIndex; |
|
4790 |
||
4791 |
SuccessorInfo(int blockSuccessorIndex) { |
|
4792 |
this.blockIndex = blockSuccessorIndex; |
|
4793 |
actualIndex = -1; |
|
4794 |
} |
|
4795 |
} |
|
4796 |
||
4797 |
private void genSwitch(BytecodeSwitch bs) { |
|
4798 |
int bci = bci(); |
|
4799 |
ValueNode value = frameState.pop(JavaKind.Int); |
|
4800 |
||
4801 |
int nofCases = bs.numberOfCases(); |
|
48190 | 4802 |
int nofCasesPlusDefault = nofCases + 1; |
4803 |
double[] keyProbabilities = switchProbability(nofCasesPlusDefault, bci); |
|
43972 | 4804 |
|
46344 | 4805 |
EconomicMap<Integer, SuccessorInfo> bciToBlockSuccessorIndex = EconomicMap.create(Equivalence.DEFAULT); |
43972 | 4806 |
for (int i = 0; i < currentBlock.getSuccessorCount(); i++) { |
4807 |
assert !bciToBlockSuccessorIndex.containsKey(currentBlock.getSuccessor(i).startBci); |
|
46344 | 4808 |
bciToBlockSuccessorIndex.put(currentBlock.getSuccessor(i).startBci, new SuccessorInfo(i)); |
43972 | 4809 |
} |
4810 |
||
4811 |
ArrayList<BciBlock> actualSuccessors = new ArrayList<>(); |
|
4812 |
int[] keys = new int[nofCases]; |
|
48190 | 4813 |
int[] keySuccessors = new int[nofCasesPlusDefault]; |
43972 | 4814 |
int deoptSuccessorIndex = -1; |
4815 |
int nextSuccessorIndex = 0; |
|
4816 |
boolean constantValue = value.isConstant(); |
|
48190 | 4817 |
for (int i = 0; i < nofCasesPlusDefault; i++) { |
43972 | 4818 |
if (i < nofCases) { |
4819 |
keys[i] = bs.keyAt(i); |
|
4820 |
} |
|
4821 |
||
4822 |
if (!constantValue && isNeverExecutedCode(keyProbabilities[i])) { |
|
4823 |
if (deoptSuccessorIndex < 0) { |
|
4824 |
deoptSuccessorIndex = nextSuccessorIndex++; |
|
4825 |
actualSuccessors.add(null); |
|
4826 |
} |
|
4827 |
keySuccessors[i] = deoptSuccessorIndex; |
|
4828 |
} else { |
|
48190 | 4829 |
int targetBci = i < nofCases ? bs.targetAt(i) : bs.defaultTarget(); |
43972 | 4830 |
SuccessorInfo info = bciToBlockSuccessorIndex.get(targetBci); |
4831 |
if (info.actualIndex < 0) { |
|
4832 |
info.actualIndex = nextSuccessorIndex++; |
|
4833 |
actualSuccessors.add(currentBlock.getSuccessor(info.blockIndex)); |
|
4834 |
} |
|
4835 |
keySuccessors[i] = info.actualIndex; |
|
4836 |
} |
|
4837 |
} |
|
48190 | 4838 |
/* |
4839 |
* When the profile indicates a case is never taken, the above code will cause the case to |
|
4840 |
* deopt should it be subsequently encountered. However, the case may share code with |
|
4841 |
* another case that is taken according to the profile. |
|
4842 |
* |
|
4843 |
* For example: |
|
4844 |
* // @formatter:off |
|
4845 |
* switch (opcode) { |
|
4846 |
* case GOTO: |
|
4847 |
* case GOTO_W: { |
|
4848 |
* // emit goto code |
|
4849 |
* break; |
|
4850 |
* } |
|
4851 |
* } |
|
4852 |
* // @formatter:on |
|
4853 |
* |
|
4854 |
* The profile may indicate the GOTO_W case is never taken, and thus a deoptimization stub |
|
4855 |
* will be emitted. There might be optimization opportunity if additional branching based |
|
4856 |
* on opcode is within the case block. Specially, if there is only single case that |
|
4857 |
* reaches a target, we have better chance cutting out unused branches. Otherwise, |
|
4858 |
* it might be beneficial routing to the same code instead of deopting. |
|
4859 |
* |
|
4860 |
* The following code rewires deoptimization stub to existing resolved branch target if |
|
4861 |
* the target is connected by more than 1 cases. |
|
4862 |
*/ |
|
4863 |
if (deoptSuccessorIndex >= 0) { |
|
4864 |
int[] connectedCases = new int[nextSuccessorIndex]; |
|
4865 |
for (int i = 0; i < nofCasesPlusDefault; i++) { |
|
4866 |
connectedCases[keySuccessors[i]]++; |
|
4867 |
} |
|
4868 |
||
4869 |
for (int i = 0; i < nofCasesPlusDefault; i++) { |
|
4870 |
if (keySuccessors[i] == deoptSuccessorIndex) { |
|
4871 |
int targetBci = i < nofCases ? bs.targetAt(i) : bs.defaultTarget(); |
|
4872 |
SuccessorInfo info = bciToBlockSuccessorIndex.get(targetBci); |
|
4873 |
int rewiredIndex = info.actualIndex; |
|
4874 |
if (rewiredIndex >= 0 && connectedCases[rewiredIndex] > 1) { |
|
4875 |
keySuccessors[i] = info.actualIndex; |
|
4876 |
} |
|
4877 |
} |
|
4878 |
} |
|
4879 |
} |
|
43972 | 4880 |
|
4881 |
genIntegerSwitch(value, actualSuccessors, keys, keyProbabilities, keySuccessors); |
|
4882 |
||
4883 |
} |
|
4884 |
||
4885 |
protected boolean isNeverExecutedCode(double probability) { |
|
46344 | 4886 |
return probability == 0 && optimisticOpts.removeNeverExecutedCode(getOptions()); |
43972 | 4887 |
} |
4888 |
||
48861 | 4889 |
private double clampProbability(double probability) { |
46344 | 4890 |
if (!optimisticOpts.removeNeverExecutedCode(getOptions())) { |
43972 | 4891 |
if (probability == 0) { |
50858 | 4892 |
return LUDICROUSLY_SLOW_PATH_PROBABILITY; |
43972 | 4893 |
} else if (probability == 1) { |
50858 | 4894 |
return LUDICROUSLY_FAST_PATH_PROBABILITY; |
43972 | 4895 |
} |
4896 |
} |
|
4897 |
return probability; |
|
4898 |
} |
|
4899 |
||
4900 |
private boolean assertAtIfBytecode() { |
|
4901 |
int bytecode = stream.currentBC(); |
|
4902 |
switch (bytecode) { |
|
4903 |
case IFEQ: |
|
4904 |
case IFNE: |
|
4905 |
case IFLT: |
|
4906 |
case IFGE: |
|
4907 |
case IFGT: |
|
4908 |
case IFLE: |
|
4909 |
case IF_ICMPEQ: |
|
4910 |
case IF_ICMPNE: |
|
4911 |
case IF_ICMPLT: |
|
4912 |
case IF_ICMPGE: |
|
4913 |
case IF_ICMPGT: |
|
4914 |
case IF_ICMPLE: |
|
4915 |
case IF_ACMPEQ: |
|
4916 |
case IF_ACMPNE: |
|
4917 |
case IFNULL: |
|
4918 |
case IFNONNULL: |
|
4919 |
return true; |
|
4920 |
} |
|
4921 |
assert false : String.format("%x is not an if bytecode", bytecode); |
|
4922 |
return true; |
|
4923 |
} |
|
4924 |
||
4925 |
public final void processBytecode(int bci, int opcode) { |
|
4926 |
int cpi; |
|
4927 |
||
4928 |
// @formatter:off |
|
4929 |
// Checkstyle: stop |
|
4930 |
switch (opcode) { |
|
4931 |
case NOP : /* nothing to do */ break; |
|
4932 |
case ACONST_NULL : frameState.push(JavaKind.Object, appendConstant(JavaConstant.NULL_POINTER)); break; |
|
4933 |
case ICONST_M1 : // fall through |
|
4934 |
case ICONST_0 : // fall through |
|
4935 |
case ICONST_1 : // fall through |
|
4936 |
case ICONST_2 : // fall through |
|
4937 |
case ICONST_3 : // fall through |
|
4938 |
case ICONST_4 : // fall through |
|
4939 |
case ICONST_5 : frameState.push(JavaKind.Int, appendConstant(JavaConstant.forInt(opcode - ICONST_0))); break; |
|
4940 |
case LCONST_0 : // fall through |
|
4941 |
case LCONST_1 : frameState.push(JavaKind.Long, appendConstant(JavaConstant.forLong(opcode - LCONST_0))); break; |
|
4942 |
case FCONST_0 : // fall through |
|
4943 |
case FCONST_1 : // fall through |
|
4944 |
case FCONST_2 : frameState.push(JavaKind.Float, appendConstant(JavaConstant.forFloat(opcode - FCONST_0))); break; |
|
4945 |
case DCONST_0 : // fall through |
|
4946 |
case DCONST_1 : frameState.push(JavaKind.Double, appendConstant(JavaConstant.forDouble(opcode - DCONST_0))); break; |
|
4947 |
case BIPUSH : frameState.push(JavaKind.Int, appendConstant(JavaConstant.forInt(stream.readByte()))); break; |
|
4948 |
case SIPUSH : frameState.push(JavaKind.Int, appendConstant(JavaConstant.forInt(stream.readShort()))); break; |
|
4949 |
case LDC : // fall through |
|
4950 |
case LDC_W : // fall through |
|
4951 |
case LDC2_W : genLoadConstant(stream.readCPI(), opcode); break; |
|
4952 |
case ILOAD : loadLocal(stream.readLocalIndex(), JavaKind.Int); break; |
|
4953 |
case LLOAD : loadLocal(stream.readLocalIndex(), JavaKind.Long); break; |
|
4954 |
case FLOAD : loadLocal(stream.readLocalIndex(), JavaKind.Float); break; |
|
4955 |
case DLOAD : loadLocal(stream.readLocalIndex(), JavaKind.Double); break; |
|
46344 | 4956 |
case ALOAD : loadLocalObject(stream.readLocalIndex()); break; |
43972 | 4957 |
case ILOAD_0 : // fall through |
4958 |
case ILOAD_1 : // fall through |
|
4959 |
case ILOAD_2 : // fall through |
|
4960 |
case ILOAD_3 : loadLocal(opcode - ILOAD_0, JavaKind.Int); break; |
|
4961 |
case LLOAD_0 : // fall through |
|
4962 |
case LLOAD_1 : // fall through |
|
4963 |
case LLOAD_2 : // fall through |
|
4964 |
case LLOAD_3 : loadLocal(opcode - LLOAD_0, JavaKind.Long); break; |
|
4965 |
case FLOAD_0 : // fall through |
|
4966 |
case FLOAD_1 : // fall through |
|
4967 |
case FLOAD_2 : // fall through |
|
4968 |
case FLOAD_3 : loadLocal(opcode - FLOAD_0, JavaKind.Float); break; |
|
4969 |
case DLOAD_0 : // fall through |
|
4970 |
case DLOAD_1 : // fall through |
|
4971 |
case DLOAD_2 : // fall through |
|
4972 |
case DLOAD_3 : loadLocal(opcode - DLOAD_0, JavaKind.Double); break; |
|
4973 |
case ALOAD_0 : // fall through |
|
4974 |
case ALOAD_1 : // fall through |
|
4975 |
case ALOAD_2 : // fall through |
|
46344 | 4976 |
case ALOAD_3 : loadLocalObject(opcode - ALOAD_0); break; |
43972 | 4977 |
case IALOAD : genLoadIndexed(JavaKind.Int ); break; |
4978 |
case LALOAD : genLoadIndexed(JavaKind.Long ); break; |
|
4979 |
case FALOAD : genLoadIndexed(JavaKind.Float ); break; |
|
4980 |
case DALOAD : genLoadIndexed(JavaKind.Double); break; |
|
4981 |
case AALOAD : genLoadIndexed(JavaKind.Object); break; |
|
4982 |
case BALOAD : genLoadIndexed(JavaKind.Byte ); break; |
|
4983 |
case CALOAD : genLoadIndexed(JavaKind.Char ); break; |
|
4984 |
case SALOAD : genLoadIndexed(JavaKind.Short ); break; |
|
4985 |
case ISTORE : storeLocal(JavaKind.Int, stream.readLocalIndex()); break; |
|
4986 |
case LSTORE : storeLocal(JavaKind.Long, stream.readLocalIndex()); break; |
|
4987 |
case FSTORE : storeLocal(JavaKind.Float, stream.readLocalIndex()); break; |
|
4988 |
case DSTORE : storeLocal(JavaKind.Double, stream.readLocalIndex()); break; |
|
4989 |
case ASTORE : storeLocal(JavaKind.Object, stream.readLocalIndex()); break; |
|
4990 |
case ISTORE_0 : // fall through |
|
4991 |
case ISTORE_1 : // fall through |
|
4992 |
case ISTORE_2 : // fall through |
|
4993 |
case ISTORE_3 : storeLocal(JavaKind.Int, opcode - ISTORE_0); break; |
|
4994 |
case LSTORE_0 : // fall through |
|
4995 |
case LSTORE_1 : // fall through |
|
4996 |
case LSTORE_2 : // fall through |
|
4997 |
case LSTORE_3 : storeLocal(JavaKind.Long, opcode - LSTORE_0); break; |
|
4998 |
case FSTORE_0 : // fall through |
|
4999 |
case FSTORE_1 : // fall through |
|
5000 |
case FSTORE_2 : // fall through |
|
5001 |
case FSTORE_3 : storeLocal(JavaKind.Float, opcode - FSTORE_0); break; |
|
5002 |
case DSTORE_0 : // fall through |
|
5003 |
case DSTORE_1 : // fall through |
|
5004 |
case DSTORE_2 : // fall through |
|
5005 |
case DSTORE_3 : storeLocal(JavaKind.Double, opcode - DSTORE_0); break; |
|
5006 |
case ASTORE_0 : // fall through |
|
5007 |
case ASTORE_1 : // fall through |
|
5008 |
case ASTORE_2 : // fall through |
|
5009 |
case ASTORE_3 : storeLocal(JavaKind.Object, opcode - ASTORE_0); break; |
|
5010 |
case IASTORE : genStoreIndexed(JavaKind.Int ); break; |
|
5011 |
case LASTORE : genStoreIndexed(JavaKind.Long ); break; |
|
5012 |
case FASTORE : genStoreIndexed(JavaKind.Float ); break; |
|
5013 |
case DASTORE : genStoreIndexed(JavaKind.Double); break; |
|
5014 |
case AASTORE : genStoreIndexed(JavaKind.Object); break; |
|
5015 |
case BASTORE : genStoreIndexed(JavaKind.Byte ); break; |
|
5016 |
case CASTORE : genStoreIndexed(JavaKind.Char ); break; |
|
5017 |
case SASTORE : genStoreIndexed(JavaKind.Short ); break; |
|
5018 |
case POP : // fall through |
|
5019 |
case POP2 : // fall through |
|
5020 |
case DUP : // fall through |
|
5021 |
case DUP_X1 : // fall through |
|
5022 |
case DUP_X2 : // fall through |
|
5023 |
case DUP2 : // fall through |
|
5024 |
case DUP2_X1 : // fall through |
|
5025 |
case DUP2_X2 : // fall through |
|
5026 |
case SWAP : frameState.stackOp(opcode); break; |
|
5027 |
case IADD : // fall through |
|
5028 |
case ISUB : // fall through |
|
5029 |
case IMUL : genArithmeticOp(JavaKind.Int, opcode); break; |
|
5030 |
case IDIV : // fall through |
|
5031 |
case IREM : genIntegerDivOp(JavaKind.Int, opcode); break; |
|
5032 |
case LADD : // fall through |
|
5033 |
case LSUB : // fall through |
|
5034 |
case LMUL : genArithmeticOp(JavaKind.Long, opcode); break; |
|
5035 |
case LDIV : // fall through |
|
5036 |
case LREM : genIntegerDivOp(JavaKind.Long, opcode); break; |
|
5037 |
case FADD : // fall through |
|
5038 |
case FSUB : // fall through |
|
5039 |
case FMUL : // fall through |
|
5040 |
case FDIV : // fall through |
|
5041 |
case FREM : genArithmeticOp(JavaKind.Float, opcode); break; |
|
5042 |
case DADD : // fall through |
|
5043 |
case DSUB : // fall through |
|
5044 |
case DMUL : // fall through |
|
5045 |
case DDIV : // fall through |
|
5046 |
case DREM : genArithmeticOp(JavaKind.Double, opcode); break; |
|
5047 |
case INEG : genNegateOp(JavaKind.Int); break; |
|
5048 |
case LNEG : genNegateOp(JavaKind.Long); break; |
|
5049 |
case FNEG : genNegateOp(JavaKind.Float); break; |
|
5050 |
case DNEG : genNegateOp(JavaKind.Double); break; |
|
5051 |
case ISHL : // fall through |
|
5052 |
case ISHR : // fall through |
|
5053 |
case IUSHR : genShiftOp(JavaKind.Int, opcode); break; |
|
5054 |
case IAND : // fall through |
|
5055 |
case IOR : // fall through |
|
5056 |
case IXOR : genLogicOp(JavaKind.Int, opcode); break; |
|
5057 |
case LSHL : // fall through |
|
5058 |
case LSHR : // fall through |
|
5059 |
case LUSHR : genShiftOp(JavaKind.Long, opcode); break; |
|
5060 |
case LAND : // fall through |
|
5061 |
case LOR : // fall through |
|
5062 |
case LXOR : genLogicOp(JavaKind.Long, opcode); break; |
|
5063 |
case IINC : genIncrement(); break; |
|
5064 |
case I2F : genFloatConvert(FloatConvert.I2F, JavaKind.Int, JavaKind.Float); break; |
|
5065 |
case I2D : genFloatConvert(FloatConvert.I2D, JavaKind.Int, JavaKind.Double); break; |
|
5066 |
case L2F : genFloatConvert(FloatConvert.L2F, JavaKind.Long, JavaKind.Float); break; |
|
5067 |
case L2D : genFloatConvert(FloatConvert.L2D, JavaKind.Long, JavaKind.Double); break; |
|
5068 |
case F2I : genFloatConvert(FloatConvert.F2I, JavaKind.Float, JavaKind.Int); break; |
|
5069 |
case F2L : genFloatConvert(FloatConvert.F2L, JavaKind.Float, JavaKind.Long); break; |
|
5070 |
case F2D : genFloatConvert(FloatConvert.F2D, JavaKind.Float, JavaKind.Double); break; |
|
5071 |
case D2I : genFloatConvert(FloatConvert.D2I, JavaKind.Double, JavaKind.Int); break; |
|
5072 |
case D2L : genFloatConvert(FloatConvert.D2L, JavaKind.Double, JavaKind.Long); break; |
|
5073 |
case D2F : genFloatConvert(FloatConvert.D2F, JavaKind.Double, JavaKind.Float); break; |
|
5074 |
case L2I : genNarrow(JavaKind.Long, JavaKind.Int); break; |
|
5075 |
case I2L : genSignExtend(JavaKind.Int, JavaKind.Long); break; |
|
5076 |
case I2B : genSignExtend(JavaKind.Byte, JavaKind.Int); break; |
|
5077 |
case I2S : genSignExtend(JavaKind.Short, JavaKind.Int); break; |
|
5078 |
case I2C : genZeroExtend(JavaKind.Char, JavaKind.Int); break; |
|
5079 |
case LCMP : genCompareOp(JavaKind.Long, false); break; |
|
5080 |
case FCMPL : genCompareOp(JavaKind.Float, true); break; |
|
5081 |
case FCMPG : genCompareOp(JavaKind.Float, false); break; |
|
5082 |
case DCMPL : genCompareOp(JavaKind.Double, true); break; |
|
5083 |
case DCMPG : genCompareOp(JavaKind.Double, false); break; |
|
5084 |
case IFEQ : genIfZero(Condition.EQ); break; |
|
5085 |
case IFNE : genIfZero(Condition.NE); break; |
|
5086 |
case IFLT : genIfZero(Condition.LT); break; |
|
5087 |
case IFGE : genIfZero(Condition.GE); break; |
|
5088 |
case IFGT : genIfZero(Condition.GT); break; |
|
5089 |
case IFLE : genIfZero(Condition.LE); break; |
|
5090 |
case IF_ICMPEQ : genIfSame(JavaKind.Int, Condition.EQ); break; |
|
5091 |
case IF_ICMPNE : genIfSame(JavaKind.Int, Condition.NE); break; |
|
5092 |
case IF_ICMPLT : genIfSame(JavaKind.Int, Condition.LT); break; |
|
5093 |
case IF_ICMPGE : genIfSame(JavaKind.Int, Condition.GE); break; |
|
5094 |
case IF_ICMPGT : genIfSame(JavaKind.Int, Condition.GT); break; |
|
5095 |
case IF_ICMPLE : genIfSame(JavaKind.Int, Condition.LE); break; |
|
5096 |
case IF_ACMPEQ : genIfSame(JavaKind.Object, Condition.EQ); break; |
|
5097 |
case IF_ACMPNE : genIfSame(JavaKind.Object, Condition.NE); break; |
|
5098 |
case GOTO : genGoto(); break; |
|
5099 |
case JSR : genJsr(stream.readBranchDest()); break; |
|
5100 |
case RET : genRet(stream.readLocalIndex()); break; |
|
5101 |
case TABLESWITCH : genSwitch(new BytecodeTableSwitch(getStream(), bci())); break; |
|
5102 |
case LOOKUPSWITCH : genSwitch(new BytecodeLookupSwitch(getStream(), bci())); break; |
|
5103 |
case IRETURN : genReturn(frameState.pop(JavaKind.Int), JavaKind.Int); break; |
|
5104 |
case LRETURN : genReturn(frameState.pop(JavaKind.Long), JavaKind.Long); break; |
|
5105 |
case FRETURN : genReturn(frameState.pop(JavaKind.Float), JavaKind.Float); break; |
|
5106 |
case DRETURN : genReturn(frameState.pop(JavaKind.Double), JavaKind.Double); break; |
|
5107 |
case ARETURN : genReturn(frameState.pop(JavaKind.Object), JavaKind.Object); break; |
|
5108 |
case RETURN : genReturn(null, JavaKind.Void); break; |
|
47667 | 5109 |
case GETSTATIC : cpi = stream.readCPI(); genGetStatic(cpi, opcode); break; |
5110 |
case PUTSTATIC : cpi = stream.readCPI(); genPutStatic(cpi, opcode); break; |
|
5111 |
case GETFIELD : cpi = stream.readCPI(); genGetField(cpi, opcode); break; |
|
5112 |
case PUTFIELD : cpi = stream.readCPI(); genPutField(cpi, opcode); break; |
|
5113 |
case INVOKEVIRTUAL : cpi = stream.readCPI(); genInvokeVirtual(cpi, opcode); break; |
|
5114 |
case INVOKESPECIAL : cpi = stream.readCPI(); genInvokeSpecial(cpi, opcode); break; |
|
5115 |
case INVOKESTATIC : cpi = stream.readCPI(); genInvokeStatic(cpi, opcode); break; |
|
5116 |
case INVOKEINTERFACE: cpi = stream.readCPI(); genInvokeInterface(cpi, opcode); break; |
|
5117 |
case INVOKEDYNAMIC : cpi = stream.readCPI4(); genInvokeDynamic(cpi, opcode); break; |
|
43972 | 5118 |
case NEW : genNewInstance(stream.readCPI()); break; |
5119 |
case NEWARRAY : genNewPrimitiveArray(stream.readLocalIndex()); break; |
|
5120 |
case ANEWARRAY : genNewObjectArray(stream.readCPI()); break; |
|
5121 |
case ARRAYLENGTH : genArrayLength(); break; |
|
5122 |
case ATHROW : genThrow(); break; |
|
52578 | 5123 |
case CHECKCAST : genCheckCast(stream.readCPI()); break; |
5124 |
case INSTANCEOF : genInstanceOf(stream.readCPI()); break; |
|
43972 | 5125 |
case MONITORENTER : genMonitorEnter(frameState.pop(JavaKind.Object), stream.nextBCI()); break; |
5126 |
case MONITOREXIT : genMonitorExit(frameState.pop(JavaKind.Object), null, stream.nextBCI()); break; |
|
5127 |
case MULTIANEWARRAY : genNewMultiArray(stream.readCPI()); break; |
|
5128 |
case IFNULL : genIfNull(Condition.EQ); break; |
|
5129 |
case IFNONNULL : genIfNull(Condition.NE); break; |
|
5130 |
case GOTO_W : genGoto(); break; |
|
5131 |
case JSR_W : genJsr(stream.readBranchDest()); break; |
|
5132 |
case BREAKPOINT : throw new PermanentBailoutException("concurrent setting of breakpoint"); |
|
5133 |
default : throw new PermanentBailoutException("Unsupported opcode %d (%s) [bci=%d]", opcode, nameOf(opcode), bci); |
|
5134 |
} |
|
5135 |
// @formatter:on |
|
5136 |
// Checkstyle: resume |
|
5137 |
} |
|
5138 |
||
5139 |
private void genArrayLength() { |
|
50330 | 5140 |
ValueNode array = maybeEmitExplicitNullCheck(frameState.pop(JavaKind.Object)); |
43972 | 5141 |
frameState.push(JavaKind.Int, append(genArrayLength(array))); |
5142 |
} |
|
5143 |
||
5144 |
@Override |
|
5145 |
public ResolvedJavaMethod getMethod() { |
|
5146 |
return method; |
|
5147 |
} |
|
5148 |
||
5149 |
@Override |
|
5150 |
public Bytecode getCode() { |
|
5151 |
return code; |
|
5152 |
} |
|
5153 |
||
5154 |
public FrameStateBuilder getFrameStateBuilder() { |
|
5155 |
return frameState; |
|
5156 |
} |
|
5157 |
||
49873 | 5158 |
private boolean firstTraceEmitted; |
5159 |
||
5160 |
protected void traceInstruction(int bci, int opcode, boolean blockStart) { |
|
5161 |
String indent = new String(new char[getDepth() * 2]).replace('\0', ' '); |
|
43972 | 5162 |
StringBuilder sb = new StringBuilder(40); |
49873 | 5163 |
String nl = System.lineSeparator(); |
5164 |
if (!firstTraceEmitted) { |
|
5165 |
sb.append(indent).append(method.format("Parsing %H.%n(%p)%r")).append(nl); |
|
5166 |
if (traceLevel >= TRACELEVEL_BLOCKMAP) { |
|
5167 |
sb.append(indent).append("Blocks:").append(nl); |
|
5168 |
String bm = blockMap.toString().replace(nl, nl + indent + " "); |
|
5169 |
sb.append(indent).append(" ").append(bm).append(nl); |
|
5170 |
} |
|
5171 |
firstTraceEmitted = true; |
|
5172 |
} |
|
5173 |
if (traceLevel >= TRACELEVEL_STATE) { |
|
5174 |
sb.append(indent).append(frameState).append(nl); |
|
5175 |
} |
|
5176 |
sb.append(indent); |
|
43972 | 5177 |
sb.append(blockStart ? '+' : '|'); |
5178 |
if (bci < 10) { |
|
5179 |
sb.append(" "); |
|
5180 |
} else if (bci < 100) { |
|
5181 |
sb.append(' '); |
|
5182 |
} |
|
5183 |
sb.append(bci).append(": ").append(Bytecodes.nameOf(opcode)); |
|
5184 |
for (int i = bci + 1; i < stream.nextBCI(); ++i) { |
|
5185 |
sb.append(' ').append(stream.readUByte(i)); |
|
5186 |
} |
|
5187 |
if (!currentBlock.getJsrScope().isEmpty()) { |
|
5188 |
sb.append(' ').append(currentBlock.getJsrScope()); |
|
5189 |
} |
|
48861 | 5190 |
TTY.println("%s", sb); |
43972 | 5191 |
} |
5192 |
||
5193 |
@Override |
|
5194 |
public boolean parsingIntrinsic() { |
|
5195 |
return intrinsicContext != null; |
|
5196 |
} |
|
5197 |
||
5198 |
@Override |
|
5199 |
public BytecodeParser getNonIntrinsicAncestor() { |
|
5200 |
BytecodeParser ancestor = parent; |
|
5201 |
while (ancestor != null && ancestor.parsingIntrinsic()) { |
|
5202 |
ancestor = ancestor.parent; |
|
5203 |
} |
|
5204 |
return ancestor; |
|
5205 |
} |
|
5206 |
||
5207 |
static String nSpaces(int n) { |
|
5208 |
return n == 0 ? "" : format("%" + n + "s", ""); |
|
5209 |
} |
|
5210 |
} |