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