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