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