< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.java/src/org/graalvm/compiler/java/BytecodeParser.java

Print this page


   1 /*
   2  * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 357 import org.graalvm.compiler.nodes.calc.OrNode;
 358 import org.graalvm.compiler.nodes.calc.RemNode;
 359 import org.graalvm.compiler.nodes.calc.RightShiftNode;
 360 import org.graalvm.compiler.nodes.calc.SignExtendNode;
 361 import org.graalvm.compiler.nodes.calc.SignedDivNode;
 362 import org.graalvm.compiler.nodes.calc.SignedRemNode;
 363 import org.graalvm.compiler.nodes.calc.SubNode;
 364 import org.graalvm.compiler.nodes.calc.UnsignedRightShiftNode;
 365 import org.graalvm.compiler.nodes.calc.XorNode;
 366 import org.graalvm.compiler.nodes.calc.ZeroExtendNode;
 367 import org.graalvm.compiler.nodes.extended.AnchoringNode;
 368 import org.graalvm.compiler.nodes.extended.BranchProbabilityNode;
 369 import org.graalvm.compiler.nodes.extended.BytecodeExceptionNode;
 370 import org.graalvm.compiler.nodes.extended.IntegerSwitchNode;
 371 import org.graalvm.compiler.nodes.extended.LoadHubNode;
 372 import org.graalvm.compiler.nodes.extended.LoadMethodNode;
 373 import org.graalvm.compiler.nodes.extended.MembarNode;
 374 import org.graalvm.compiler.nodes.extended.StateSplitProxyNode;
 375 import org.graalvm.compiler.nodes.extended.ValueAnchorNode;
 376 import org.graalvm.compiler.nodes.graphbuilderconf.ClassInitializationPlugin;

 377 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
 378 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.BytecodeExceptionMode;
 379 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
 380 import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
 381 import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo;
 382 import org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext;
 383 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
 384 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.InvocationPluginReceiver;
 385 import org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin;
 386 import org.graalvm.compiler.nodes.graphbuilderconf.ProfilingPlugin;
 387 import org.graalvm.compiler.nodes.java.ArrayLengthNode;
 388 import org.graalvm.compiler.nodes.java.ExceptionObjectNode;
 389 import org.graalvm.compiler.nodes.java.FinalFieldBarrierNode;
 390 import org.graalvm.compiler.nodes.java.InstanceOfNode;
 391 import org.graalvm.compiler.nodes.java.LoadFieldNode;
 392 import org.graalvm.compiler.nodes.java.LoadIndexedNode;
 393 import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
 394 import org.graalvm.compiler.nodes.java.MonitorEnterNode;
 395 import org.graalvm.compiler.nodes.java.MonitorExitNode;
 396 import org.graalvm.compiler.nodes.java.MonitorIdNode;


 916                     if (param == FrameState.TWO_SLOT_MARKER) {
 917                         param = null;
 918                     }
 919                     locals[i] = param;
 920                     assert param == null || param instanceof ParameterNode || param.isConstant();
 921                 }
 922             }
 923             ValueNode[] stack = {};
 924             int stackSize = 0;
 925             ValueNode[] locks = {};
 926             List<MonitorIdNode> monitorIds = Collections.emptyList();
 927             stateAfterStart = graph.add(new FrameState(null, new ResolvedJavaMethodBytecode(original), 0, locals, stack, stackSize, locks, monitorIds, false, false));
 928         }
 929         return stateAfterStart;
 930     }
 931 
 932     /**
 933      * @param type the unresolved type of the constant
 934      */
 935     protected void handleUnresolvedLoadConstant(JavaType type) {
 936         assert !graphBuilderConfig.eagerResolving();
 937         append(new DeoptimizeNode(InvalidateRecompile, Unresolved));





 938     }
 939 
 940     /**
 941      * @param type the unresolved type of the type check
 942      * @param object the object value whose type is being checked against {@code type}
 943      */
 944     protected void handleUnresolvedCheckCast(JavaType type, ValueNode object) {
 945         assert !graphBuilderConfig.eagerResolving();
 946         append(new FixedGuardNode(graph.addOrUniqueWithInputs(IsNullNode.create(object)), Unresolved, InvalidateRecompile));
 947         frameState.push(JavaKind.Object, appendConstant(JavaConstant.NULL_POINTER));
 948     }
 949 
 950     /**
 951      * @param type the unresolved type of the type check
 952      * @param object the object value whose type is being checked against {@code type}
 953      */
 954     protected void handleUnresolvedInstanceOf(JavaType type, ValueNode object) {
 955         assert !graphBuilderConfig.eagerResolving();
 956         AbstractBeginNode successor = graph.add(new BeginNode());
 957         DeoptimizeNode deopt = graph.add(new DeoptimizeNode(InvalidateRecompile, Unresolved));

 958         append(new IfNode(graph.addOrUniqueWithInputs(IsNullNode.create(object)), successor, deopt, 1));
 959         lastInstr = successor;
 960         frameState.push(JavaKind.Int, appendConstant(JavaConstant.INT_0));
 961     }
 962 
 963     /**
 964      * @param type the type being instantiated
 965      */
 966     protected void handleUnresolvedNewInstance(JavaType type) {
 967         assert !graphBuilderConfig.eagerResolving();
 968         append(new DeoptimizeNode(InvalidateRecompile, Unresolved));

 969     }
 970 
 971     /**
 972      * @param type the type of the array being instantiated
 973      * @param length the length of the array
 974      */
 975     protected void handleUnresolvedNewObjectArray(JavaType type, ValueNode length) {
 976         assert !graphBuilderConfig.eagerResolving();
 977         append(new DeoptimizeNode(InvalidateRecompile, Unresolved));

 978     }
 979 
 980     /**
 981      * @param type the type being instantiated
 982      * @param dims the dimensions for the multi-array
 983      */
 984     protected void handleUnresolvedNewMultiArray(JavaType type, ValueNode[] dims) {
 985         assert !graphBuilderConfig.eagerResolving();
 986         append(new DeoptimizeNode(InvalidateRecompile, Unresolved));

 987     }
 988 
 989     /**
 990      * @param field the unresolved field
 991      * @param receiver the object containing the field or {@code null} if {@code field} is static
 992      */
 993     protected void handleUnresolvedLoadField(JavaField field, ValueNode receiver) {
 994         assert !graphBuilderConfig.eagerResolving();
 995         append(new DeoptimizeNode(InvalidateRecompile, Unresolved));

 996     }
 997 
 998     /**
 999      * @param field the unresolved field
1000      * @param value the value being stored to the field
1001      * @param receiver the object containing the field or {@code null} if {@code field} is static
1002      */
1003     protected void handleUnresolvedStoreField(JavaField field, ValueNode value, ValueNode receiver) {
1004         assert !graphBuilderConfig.eagerResolving();
1005         append(new DeoptimizeNode(InvalidateRecompile, Unresolved));

1006     }
1007 
1008     /**
1009      * @param type
1010      */
1011     protected void handleUnresolvedExceptionType(JavaType type) {
1012         assert !graphBuilderConfig.eagerResolving();
1013         append(new DeoptimizeNode(InvalidateRecompile, Unresolved));

1014     }
1015 
1016     /**
1017      * @param javaMethod
1018      * @param invokeKind
1019      */
1020     protected void handleUnresolvedInvoke(JavaMethod javaMethod, InvokeKind invokeKind) {
1021         assert !graphBuilderConfig.eagerResolving();
1022         append(new DeoptimizeNode(InvalidateRecompile, Unresolved));

1023     }
1024 
1025     private AbstractBeginNode handleException(ValueNode exceptionObject, int bci) {
1026         assert bci == BytecodeFrame.BEFORE_BCI || bci == bci() : "invalid bci";
1027         debug.log("Creating exception dispatch edges at %d, exception object=%s, exception seen=%s", bci, exceptionObject, (profilingInfo == null ? "" : profilingInfo.getExceptionSeen(bci)));
1028 
1029         FrameStateBuilder dispatchState = frameState.copy();
1030         dispatchState.clearStack();
1031 
1032         AbstractBeginNode dispatchBegin;
1033         if (exceptionObject == null) {
1034             ExceptionObjectNode newExceptionObject = graph.add(new ExceptionObjectNode(metaAccess));
1035             dispatchBegin = newExceptionObject;
1036             dispatchState.push(JavaKind.Object, dispatchBegin);
1037             dispatchState.setRethrowException(true);
1038             newExceptionObject.setStateAfter(dispatchState.create(bci, newExceptionObject));
1039         } else {
1040             dispatchBegin = graph.add(new BeginNode());
1041             dispatchState.push(JavaKind.Object, exceptionObject);
1042             dispatchState.setRethrowException(true);


1290         append(storeFieldNode);
1291         storeFieldNode.setStateAfter(this.createFrameState(stream.nextBCI(), storeFieldNode));
1292     }
1293 
1294     /**
1295      * Ensure that concrete classes are at least linked before generating an invoke. Interfaces may
1296      * never be linked so simply return true for them.
1297      *
1298      * @param target
1299      * @return true if the declared holder is an interface or is linked
1300      */
1301     private static boolean callTargetIsResolved(JavaMethod target) {
1302         if (target instanceof ResolvedJavaMethod) {
1303             ResolvedJavaMethod resolvedTarget = (ResolvedJavaMethod) target;
1304             ResolvedJavaType resolvedType = resolvedTarget.getDeclaringClass();
1305             return resolvedType.isInterface() || resolvedType.isLinked();
1306         }
1307         return false;
1308     }
1309 
1310     protected void genInvokeStatic(JavaMethod target) {





1311         if (callTargetIsResolved(target)) {
1312             ResolvedJavaMethod resolvedTarget = (ResolvedJavaMethod) target;
1313             ResolvedJavaType holder = resolvedTarget.getDeclaringClass();
1314             if (!holder.isInitialized() && ResolveClassBeforeStaticInvoke.getValue(options)) {
1315                 handleUnresolvedInvoke(target, InvokeKind.Static);
1316             } else {
1317                 ValueNode classInit = null;
1318                 ClassInitializationPlugin classInitializationPlugin = graphBuilderConfig.getPlugins().getClassInitializationPlugin();
1319                 if (classInitializationPlugin != null && classInitializationPlugin.shouldApply(this, resolvedTarget.getDeclaringClass())) {
1320                     FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
1321                     classInit = classInitializationPlugin.apply(this, resolvedTarget.getDeclaringClass(), stateBefore);
1322                 }
1323 
1324                 ValueNode[] args = frameState.popArguments(resolvedTarget.getSignature().getParameterCount(false));
1325                 Invoke invoke = appendInvoke(InvokeKind.Static, resolvedTarget, args);
1326                 if (invoke != null) {
1327                     invoke.setClassInit(classInit);
1328                 }
1329             }
1330         } else {
1331             handleUnresolvedInvoke(target, InvokeKind.Static);
1332         }
1333     }
1334 





1335     protected void genInvokeInterface(JavaMethod target) {
1336         if (callTargetIsResolved(target)) {
1337             ValueNode[] args = frameState.popArguments(target.getSignature().getParameterCount(true));
1338             appendInvoke(InvokeKind.Interface, (ResolvedJavaMethod) target, args);
1339         } else {
1340             handleUnresolvedInvoke(target, InvokeKind.Interface);
1341         }
1342     }
1343 
1344     protected void genInvokeDynamic(JavaMethod target) {
1345         if (target instanceof ResolvedJavaMethod) {
1346             JavaConstant appendix = constantPool.lookupAppendix(stream.readCPI4(), Bytecodes.INVOKEDYNAMIC);
1347             if (appendix != null) {
1348                 frameState.push(JavaKind.Object, ConstantNode.forConstant(appendix, metaAccess, graph));
1349             }
1350             ValueNode[] args = frameState.popArguments(target.getSignature().getParameterCount(false));
1351             appendInvoke(InvokeKind.Static, (ResolvedJavaMethod) target, args);
1352         } else {
1353             handleUnresolvedInvoke(target, InvokeKind.Static);
1354         }
1355     }
1356 
1357     protected void genInvokeVirtual(JavaMethod target) {
1358         if (callTargetIsResolved(target)) {
1359             /*
1360              * Special handling for runtimes that rewrite an invocation of MethodHandle.invoke(...)
1361              * or MethodHandle.invokeExact(...) to a static adapter. HotSpot does this - see
1362              * https://wikis.oracle.com/display/HotSpotInternals/Method+handles +and+invokedynamic
1363              */
1364             boolean hasReceiver = !((ResolvedJavaMethod) target).isStatic();
1365             JavaConstant appendix = constantPool.lookupAppendix(stream.readCPI(), Bytecodes.INVOKEVIRTUAL);















1366             if (appendix != null) {
1367                 frameState.push(JavaKind.Object, ConstantNode.forConstant(appendix, metaAccess, graph));
















1368             }


1369             ValueNode[] args = frameState.popArguments(target.getSignature().getParameterCount(hasReceiver));
1370             if (hasReceiver) {
1371                 appendInvoke(InvokeKind.Virtual, (ResolvedJavaMethod) target, args);
1372             } else {
1373                 appendInvoke(InvokeKind.Static, (ResolvedJavaMethod) target, args);
1374             }
1375         } else {





1376             handleUnresolvedInvoke(target, InvokeKind.Virtual);
1377         }

1378 
















1379     }
1380 
1381     protected void genInvokeSpecial(JavaMethod target) {











1382         if (callTargetIsResolved(target)) {
1383             assert target != null;
1384             assert target.getSignature() != null;
1385             ValueNode[] args = frameState.popArguments(target.getSignature().getParameterCount(true));
1386             appendInvoke(InvokeKind.Special, (ResolvedJavaMethod) target, args);
1387         } else {
1388             handleUnresolvedInvoke(target, InvokeKind.Special);
1389         }
1390     }
1391 
1392     static class CurrentInvoke {
1393         final ValueNode[] args;
1394         final InvokeKind kind;
1395         final JavaType returnType;
1396 
1397         CurrentInvoke(ValueNode[] args, InvokeKind kind, JavaType returnType) {
1398             this.args = args;
1399             this.kind = kind;
1400             this.returnType = returnType;
1401         }


2132      * Prints a line to {@link TTY} with a prefix indicating the current parse context. The prefix
2133      * is of the form:
2134      *
2135      * <pre>
2136      * {SPACE * n} {name of method being parsed} "(" {file name} ":" {line number} ")"
2137      * </pre>
2138      *
2139      * where {@code n} is the current inlining depth.
2140      *
2141      * @param format a format string
2142      * @param args arguments to the format string
2143      */
2144 
2145     protected void traceWithContext(String format, Object... args) {
2146         StackTraceElement where = code.asStackTraceElement(bci());
2147         String s = format("%s%s (%s:%d) %s", nSpaces(getDepth()), method.isConstructor() ? method.format("%h.%n") : method.getName(), where.getFileName(), where.getLineNumber(),
2148                         format(format, args));
2149         TTY.println(s);
2150     }
2151 
2152     protected BytecodeParserError asParserError(Throwable e) {
2153         if (e instanceof BytecodeParserError) {
2154             return (BytecodeParserError) e;
2155         }
2156         BytecodeParser bp = this;
2157         BytecodeParserError res = new BytecodeParserError(e);
2158         while (bp != null) {
2159             res.addContext("parsing " + bp.code.asStackTraceElement(bp.bci()));
2160             bp = bp.parent;
2161         }
2162         return res;
2163     }
2164 
2165     protected void parseAndInlineCallee(ResolvedJavaMethod targetMethod, ValueNode[] args, IntrinsicContext calleeIntrinsicContext) {
2166         try (IntrinsicScope s = calleeIntrinsicContext != null && !parsingIntrinsic() ? new IntrinsicScope(this, targetMethod.getSignature().toParameterKinds(!targetMethod.isStatic()), args) : null) {
2167 
2168             BytecodeParser parser = graphBuilderInstance.createBytecodeParser(graph, this, targetMethod, INVOCATION_ENTRY_BCI, calleeIntrinsicContext);
2169             FrameStateBuilder startFrameState = new FrameStateBuilder(parser, parser.code, graph);
2170             if (!targetMethod.isStatic()) {
2171                 args[0] = nullCheckedValue(args[0]);
2172             }
2173             startFrameState.initializeFromArgumentsArray(args);
2174             parser.build(this.lastInstr, startFrameState);
2175 
2176             if (parser.returnDataList == null) {
2177                 /* Callee does not return. */
2178                 lastInstr = null;
2179             } else {
2180                 ValueNode calleeReturnValue;
2181                 MergeNode returnMergeNode = null;
2182                 if (s != null) {


2820 
2821             // read the opcode
2822             int opcode = stream.currentBC();
2823             assert traceState();
2824             assert traceInstruction(bci, opcode, bci == block.startBci);
2825             if (parent == null && bci == entryBCI) {
2826                 if (block.getJsrScope() != JsrScope.EMPTY_SCOPE) {
2827                     throw new JsrNotSupportedBailout("OSR into a JSR scope is not supported");
2828                 }
2829                 EntryMarkerNode x = append(new EntryMarkerNode());
2830                 frameState.insertProxies(value -> graph.unique(new EntryProxyNode(value, x)));
2831                 x.setStateAfter(createFrameState(bci, x));
2832             }
2833 
2834             try (DebugCloseable context = openNodeContext()) {
2835                 processBytecode(bci, opcode);
2836             } catch (BailoutException e) {
2837                 // Don't wrap bailouts as parser errors
2838                 throw e;
2839             } catch (Throwable e) {
2840                 throw asParserError(e);
2841             }
2842 
2843             if (lastInstr == null || lastInstr.next() != null) {
2844                 break;
2845             }
2846 
2847             stream.next();
2848             bci = stream.currentBCI();
2849 
2850             assert block == currentBlock;
2851             assert checkLastInstruction();
2852             lastInstr = finishInstruction(lastInstr, frameState);
2853             if (bci < endBCI) {
2854                 if (bci > block.endBci) {
2855                     assert !block.getSuccessor(0).isExceptionEntry;
2856                     assert block.numNormalSuccessors() == 1;
2857                     // we fell through to the next block, add a goto and break
2858                     appendGoto(block.getSuccessor(0));
2859                     break;
2860                 }


3240         return stream;
3241     }
3242 
3243     @Override
3244     public int bci() {
3245         return stream.currentBCI();
3246     }
3247 
3248     public void loadLocal(int index, JavaKind kind) {
3249         ValueNode value = frameState.loadLocal(index, kind);
3250         frameState.push(kind, value);
3251     }
3252 
3253     public void loadLocalObject(int index) {
3254         ValueNode value = frameState.loadLocal(index, JavaKind.Object);
3255 
3256         int nextBCI = stream.nextBCI();
3257         int nextBC = stream.readUByte(nextBCI);
3258         if (nextBCI <= currentBlock.endBci && nextBC == Bytecodes.GETFIELD) {
3259             stream.next();
3260             genGetField(lookupField(stream.readCPI(), Bytecodes.GETFIELD), value);
3261         } else {
3262             frameState.push(JavaKind.Object, value);
3263         }
3264     }
3265 
3266     public void storeLocal(JavaKind kind, int index) {
3267         ValueNode value = frameState.pop(kind);
3268         frameState.storeLocal(index, kind, value);
3269     }
3270 
3271     private void genLoadConstant(int cpi, int opcode) {
3272         Object con = lookupConstant(cpi, opcode);
3273 
3274         if (con instanceof JavaType) {
3275             // this is a load of class constant which might be unresolved
3276             JavaType type = (JavaType) con;
3277             if (type instanceof ResolvedJavaType) {
3278                 frameState.push(JavaKind.Object, appendConstant(getConstantReflection().asJavaClass((ResolvedJavaType) type)));
3279             } else {
3280                 handleUnresolvedLoadConstant(type);


3489         maybeEagerlyResolve(cpi, bytecode);
3490         JavaType result = constantPool.lookupType(cpi, bytecode);
3491         assert !graphBuilderConfig.unresolvedIsError() || result instanceof ResolvedJavaType;
3492         return result;
3493     }
3494 
3495     private JavaMethod lookupMethod(int cpi, int opcode) {
3496         maybeEagerlyResolve(cpi, opcode);
3497         JavaMethod result = constantPool.lookupMethod(cpi, opcode);
3498         /*
3499          * In general, one cannot assume that the declaring class being initialized is useful, since
3500          * the actual concrete receiver may be a different class (except for static calls). Also,
3501          * interfaces are initialized only under special circumstances, so that this assertion would
3502          * often fail for interface calls.
3503          */
3504         assert !graphBuilderConfig.unresolvedIsError() ||
3505                         (result instanceof ResolvedJavaMethod && (opcode != INVOKESTATIC || ((ResolvedJavaMethod) result).getDeclaringClass().isInitialized())) : result;
3506         return result;
3507     }
3508 
3509     private JavaField lookupField(int cpi, int opcode) {
3510         maybeEagerlyResolve(cpi, opcode);
3511         JavaField result = constantPool.lookupField(cpi, method, opcode);

3512         if (graphBuilderConfig.eagerResolving()) {
3513             assert result instanceof ResolvedJavaField : "Not resolved: " + result;

3514             ResolvedJavaType declaringClass = ((ResolvedJavaField) result).getDeclaringClass();
3515             if (!declaringClass.isInitialized()) {
3516                 assert declaringClass.isInterface() : "Declaring class not initialized but not an interface? " + declaringClass;
3517                 declaringClass.initialize();
3518             }
3519         }

3520         assert !graphBuilderConfig.unresolvedIsError() || (result instanceof ResolvedJavaField && ((ResolvedJavaField) result).getDeclaringClass().isInitialized()) : result;
3521         return result;
3522     }
3523 
3524     private Object lookupConstant(int cpi, int opcode) {
3525         maybeEagerlyResolve(cpi, opcode);
3526         Object result = constantPool.lookupConstant(cpi);
3527         assert !graphBuilderConfig.eagerResolving() || !(result instanceof JavaType) || (result instanceof ResolvedJavaType) : result;
3528         return result;
3529     }
3530 
3531     private void maybeEagerlyResolve(int cpi, int bytecode) {
3532         if (intrinsicContext != null) {
3533             constantPool.loadReferencedType(cpi, bytecode);
3534         } else if (graphBuilderConfig.eagerResolving()) {
3535             /*
3536              * Since we're potentially triggering class initialization here, we need synchronization
3537              * to mitigate the potential for class initialization related deadlock being caused by
3538              * the compiler (e.g., https://github.com/graalvm/graal-core/pull/232/files#r90788550).
3539              */
3540             synchronized (BytecodeParser.class) {
3541                 constantPool.loadReferencedType(cpi, bytecode);
3542             }
3543         }
3544     }
3545 
3546     private JavaTypeProfile getProfileForTypeCheck(TypeReference type) {
3547         if (parsingIntrinsic() || profilingInfo == null || !optimisticOpts.useTypeCheckHints(getOptions()) || type.isExact()) {
3548             return null;
3549         } else {
3550             return profilingInfo.getTypeProfile(bci());
3551         }


3636         }
3637         LogicNode logicNode = genUnique(instanceOfNode);
3638 
3639         int next = getStream().nextBCI();
3640         int value = getStream().readUByte(next);
3641         if (next <= currentBlock.endBci && (value == Bytecodes.IFEQ || value == Bytecodes.IFNE)) {
3642             getStream().next();
3643             BciBlock firstSucc = currentBlock.getSuccessor(0);
3644             BciBlock secondSucc = currentBlock.getSuccessor(1);
3645             if (firstSucc != secondSucc) {
3646                 genIf(instanceOfNode, value != Bytecodes.IFNE, firstSucc, secondSucc);
3647             } else {
3648                 appendGoto(firstSucc);
3649             }
3650         } else {
3651             // Most frequent for value is IRETURN, followed by ISTORE.
3652             frameState.push(JavaKind.Int, append(genConditional(logicNode)));
3653         }
3654     }
3655 
3656     void genNewInstance(int cpi) {
3657         JavaType type = lookupType(cpi, NEW);


3658 

3659         if (!(type instanceof ResolvedJavaType) || !((ResolvedJavaType) type).isInitialized()) {
3660             handleUnresolvedNewInstance(type);
3661             return;
3662         }
3663         ResolvedJavaType resolvedType = (ResolvedJavaType) type;
3664 
3665         ResolvedJavaType[] skippedExceptionTypes = this.graphBuilderConfig.getSkippedExceptionTypes();
3666         if (skippedExceptionTypes != null) {
3667             for (ResolvedJavaType exceptionType : skippedExceptionTypes) {
3668                 if (exceptionType.isAssignableFrom(resolvedType)) {
3669                     append(new DeoptimizeNode(DeoptimizationAction.InvalidateRecompile, RuntimeConstraint));
3670                     return;
3671                 }
3672             }
3673         }
3674 
3675         ClassInitializationPlugin classInitializationPlugin = graphBuilderConfig.getPlugins().getClassInitializationPlugin();
3676         if (classInitializationPlugin != null && classInitializationPlugin.shouldApply(this, resolvedType)) {
3677             FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
3678             classInitializationPlugin.apply(this, resolvedType, stateBefore);


3773 
3774         ClassInitializationPlugin classInitializationPlugin = this.graphBuilderConfig.getPlugins().getClassInitializationPlugin();
3775         if (classInitializationPlugin != null && classInitializationPlugin.shouldApply(this, resolvedType)) {
3776             FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
3777             classInitializationPlugin.apply(this, resolvedType, stateBefore);
3778         }
3779 
3780         for (int i = rank - 1; i >= 0; i--) {
3781             dims[i] = frameState.pop(JavaKind.Int);
3782         }
3783 
3784         for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) {
3785             if (plugin.handleNewMultiArray(this, resolvedType, dims)) {
3786                 return;
3787             }
3788         }
3789 
3790         frameState.push(JavaKind.Object, append(createNewMultiArray(resolvedType, dims)));
3791     }
3792 
3793     private void genGetField(JavaField field) {
3794         genGetField(field, frameState.pop(JavaKind.Object));





3795     }
3796 
3797     private void genGetField(JavaField field, ValueNode receiverInput) {
3798         ValueNode receiver = emitExplicitExceptions(receiverInput);
3799         if (field instanceof ResolvedJavaField) {
3800             ResolvedJavaField resolvedField = (ResolvedJavaField) field;
3801             genGetField(resolvedField, receiver);
3802         } else {
3803             handleUnresolvedLoadField(field, receiver);
3804         }
3805     }
3806 
3807     private void genGetField(ResolvedJavaField resolvedField, ValueNode receiver) {
3808         if (!parsingIntrinsic() && GeneratePIC.getValue(getOptions())) {
3809             graph.recordField(resolvedField);
3810         }
3811 
3812         for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) {
3813             if (plugin.handleLoadField(this, receiver, resolvedField)) {
3814                 return;


3850     }
3851 
3852     protected ValueNode emitExplicitExceptions(ValueNode receiver) {
3853         if (StampTool.isPointerNonNull(receiver) || !needsExplicitException()) {
3854             return receiver;
3855         } else {
3856             return emitExplicitNullCheck(receiver);
3857         }
3858     }
3859 
3860     private boolean needsExplicitException() {
3861         BytecodeExceptionMode exceptionMode = graphBuilderConfig.getBytecodeExceptionMode();
3862         if (exceptionMode == BytecodeExceptionMode.CheckAll || StressExplicitExceptionCode.getValue(options)) {
3863             return true;
3864         } else if (exceptionMode == BytecodeExceptionMode.Profile && profilingInfo != null) {
3865             return profilingInfo.getExceptionSeen(bci()) == TriState.TRUE;
3866         }
3867         return false;
3868     }
3869 
3870     private void genPutField(JavaField field) {





3871         genPutField(field, frameState.pop(field.getJavaKind()));
3872     }
3873 
3874     private void genPutField(JavaField field, ValueNode value) {
3875         ValueNode receiver = emitExplicitExceptions(frameState.pop(JavaKind.Object));
3876         if (field instanceof ResolvedJavaField) {
3877             ResolvedJavaField resolvedField = (ResolvedJavaField) field;
3878 
3879             if (!parsingIntrinsic() && GeneratePIC.getValue(getOptions())) {
3880                 graph.recordField(resolvedField);
3881             }
3882 
3883             for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) {
3884                 if (plugin.handleStoreField(this, receiver, resolvedField, value)) {
3885                     return;
3886                 }
3887             }
3888 
3889             if (resolvedField.isFinal() && method.isConstructor()) {
3890                 finalBarrierRequired = true;
3891             }
3892             genStoreField(receiver, resolvedField, value);
3893         } else {
3894             handleUnresolvedStoreField(field, value, receiver);
3895         }
3896     }
3897 





3898     private void genGetStatic(JavaField field) {
3899         ResolvedJavaField resolvedField = resolveStaticFieldAccess(field, null);
3900         if (resolvedField == null) {
3901             return;
3902         }
3903 
3904         if (!parsingIntrinsic() && GeneratePIC.getValue(getOptions())) {
3905             graph.recordField(resolvedField);
3906         }
3907 
3908         /*
3909          * Javac does not allow use of "$assertionsDisabled" for a field name but Eclipse does, in
3910          * which case a suffix is added to the generated field.
3911          */
3912         if ((parsingIntrinsic() || graphBuilderConfig.omitAssertions()) && resolvedField.isSynthetic() && resolvedField.getName().startsWith("$assertionsDisabled")) {
3913             frameState.push(field.getJavaKind(), ConstantNode.forBoolean(true, graph));
3914             return;
3915         }
3916 
3917         ClassInitializationPlugin classInitializationPlugin = this.graphBuilderConfig.getPlugins().getClassInitializationPlugin();


3939              * Static fields have initialization semantics but may be safely accessed under certain
3940              * conditions while the class is being initialized. Executing in the clinit or init of
3941              * classes which are subtypes of the field holder are sure to be running in a context
3942              * where the access is safe.
3943              */
3944             if (resolvedField.getDeclaringClass().isAssignableFrom(method.getDeclaringClass())) {
3945                 if (method.isClassInitializer() || method.isConstructor()) {
3946                     return resolvedField;
3947                 }
3948             }
3949         }
3950         if (value == null) {
3951             handleUnresolvedLoadField(field, null);
3952         } else {
3953             handleUnresolvedStoreField(field, value, null);
3954 
3955         }
3956         return null;
3957     }
3958 
3959     private void genPutStatic(JavaField field) {





3960         ValueNode value = frameState.pop(field.getJavaKind());
3961         ResolvedJavaField resolvedField = resolveStaticFieldAccess(field, value);
3962         if (resolvedField == null) {
3963             return;
3964         }
3965 
3966         if (!parsingIntrinsic() && GeneratePIC.getValue(getOptions())) {
3967             graph.recordField(resolvedField);
3968         }
3969 
3970         ClassInitializationPlugin classInitializationPlugin = this.graphBuilderConfig.getPlugins().getClassInitializationPlugin();
3971         if (classInitializationPlugin != null && classInitializationPlugin.shouldApply(this, resolvedField.getDeclaringClass())) {
3972             FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
3973             classInitializationPlugin.apply(this, resolvedField.getDeclaringClass(), stateBefore);
3974         }
3975 
3976         for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) {
3977             if (plugin.handleStoreStaticField(this, resolvedField, value)) {
3978                 return;
3979             }


4303             case IFLE           : genIfZero(Condition.LE); break;
4304             case IF_ICMPEQ      : genIfSame(JavaKind.Int, Condition.EQ); break;
4305             case IF_ICMPNE      : genIfSame(JavaKind.Int, Condition.NE); break;
4306             case IF_ICMPLT      : genIfSame(JavaKind.Int, Condition.LT); break;
4307             case IF_ICMPGE      : genIfSame(JavaKind.Int, Condition.GE); break;
4308             case IF_ICMPGT      : genIfSame(JavaKind.Int, Condition.GT); break;
4309             case IF_ICMPLE      : genIfSame(JavaKind.Int, Condition.LE); break;
4310             case IF_ACMPEQ      : genIfSame(JavaKind.Object, Condition.EQ); break;
4311             case IF_ACMPNE      : genIfSame(JavaKind.Object, Condition.NE); break;
4312             case GOTO           : genGoto(); break;
4313             case JSR            : genJsr(stream.readBranchDest()); break;
4314             case RET            : genRet(stream.readLocalIndex()); break;
4315             case TABLESWITCH    : genSwitch(new BytecodeTableSwitch(getStream(), bci())); break;
4316             case LOOKUPSWITCH   : genSwitch(new BytecodeLookupSwitch(getStream(), bci())); break;
4317             case IRETURN        : genReturn(frameState.pop(JavaKind.Int), JavaKind.Int); break;
4318             case LRETURN        : genReturn(frameState.pop(JavaKind.Long), JavaKind.Long); break;
4319             case FRETURN        : genReturn(frameState.pop(JavaKind.Float), JavaKind.Float); break;
4320             case DRETURN        : genReturn(frameState.pop(JavaKind.Double), JavaKind.Double); break;
4321             case ARETURN        : genReturn(frameState.pop(JavaKind.Object), JavaKind.Object); break;
4322             case RETURN         : genReturn(null, JavaKind.Void); break;
4323             case GETSTATIC      : cpi = stream.readCPI(); genGetStatic(lookupField(cpi, opcode)); break;
4324             case PUTSTATIC      : cpi = stream.readCPI(); genPutStatic(lookupField(cpi, opcode)); break;
4325             case GETFIELD       : cpi = stream.readCPI(); genGetField(lookupField(cpi, opcode)); break;
4326             case PUTFIELD       : cpi = stream.readCPI(); genPutField(lookupField(cpi, opcode)); break;
4327             case INVOKEVIRTUAL  : cpi = stream.readCPI(); genInvokeVirtual(lookupMethod(cpi, opcode)); break;
4328             case INVOKESPECIAL  : cpi = stream.readCPI(); genInvokeSpecial(lookupMethod(cpi, opcode)); break;
4329             case INVOKESTATIC   : cpi = stream.readCPI(); genInvokeStatic(lookupMethod(cpi, opcode)); break;
4330             case INVOKEINTERFACE: cpi = stream.readCPI(); genInvokeInterface(lookupMethod(cpi, opcode)); break;
4331             case INVOKEDYNAMIC  : cpi = stream.readCPI4(); genInvokeDynamic(lookupMethod(cpi, opcode)); break;
4332             case NEW            : genNewInstance(stream.readCPI()); break;
4333             case NEWARRAY       : genNewPrimitiveArray(stream.readLocalIndex()); break;
4334             case ANEWARRAY      : genNewObjectArray(stream.readCPI()); break;
4335             case ARRAYLENGTH    : genArrayLength(); break;
4336             case ATHROW         : genThrow(); break;
4337             case CHECKCAST      : genCheckCast(); break;
4338             case INSTANCEOF     : genInstanceOf(); break;
4339             case MONITORENTER   : genMonitorEnter(frameState.pop(JavaKind.Object), stream.nextBCI()); break;
4340             case MONITOREXIT    : genMonitorExit(frameState.pop(JavaKind.Object), null, stream.nextBCI()); break;
4341             case MULTIANEWARRAY : genNewMultiArray(stream.readCPI()); break;
4342             case IFNULL         : genIfNull(Condition.EQ); break;
4343             case IFNONNULL      : genIfNull(Condition.NE); break;
4344             case GOTO_W         : genGoto(); break;
4345             case JSR_W          : genJsr(stream.readBranchDest()); break;
4346             case BREAKPOINT     : throw new PermanentBailoutException("concurrent setting of breakpoint");
4347             default             : throw new PermanentBailoutException("Unsupported opcode %d (%s) [bci=%d]", opcode, nameOf(opcode), bci);
4348         }
4349         // @formatter:on
4350         // Checkstyle: resume
4351     }


   1 /*
   2  * Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 357 import org.graalvm.compiler.nodes.calc.OrNode;
 358 import org.graalvm.compiler.nodes.calc.RemNode;
 359 import org.graalvm.compiler.nodes.calc.RightShiftNode;
 360 import org.graalvm.compiler.nodes.calc.SignExtendNode;
 361 import org.graalvm.compiler.nodes.calc.SignedDivNode;
 362 import org.graalvm.compiler.nodes.calc.SignedRemNode;
 363 import org.graalvm.compiler.nodes.calc.SubNode;
 364 import org.graalvm.compiler.nodes.calc.UnsignedRightShiftNode;
 365 import org.graalvm.compiler.nodes.calc.XorNode;
 366 import org.graalvm.compiler.nodes.calc.ZeroExtendNode;
 367 import org.graalvm.compiler.nodes.extended.AnchoringNode;
 368 import org.graalvm.compiler.nodes.extended.BranchProbabilityNode;
 369 import org.graalvm.compiler.nodes.extended.BytecodeExceptionNode;
 370 import org.graalvm.compiler.nodes.extended.IntegerSwitchNode;
 371 import org.graalvm.compiler.nodes.extended.LoadHubNode;
 372 import org.graalvm.compiler.nodes.extended.LoadMethodNode;
 373 import org.graalvm.compiler.nodes.extended.MembarNode;
 374 import org.graalvm.compiler.nodes.extended.StateSplitProxyNode;
 375 import org.graalvm.compiler.nodes.extended.ValueAnchorNode;
 376 import org.graalvm.compiler.nodes.graphbuilderconf.ClassInitializationPlugin;
 377 import org.graalvm.compiler.nodes.graphbuilderconf.InvokeDynamicPlugin;
 378 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
 379 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.BytecodeExceptionMode;
 380 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
 381 import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
 382 import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo;
 383 import org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext;
 384 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
 385 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.InvocationPluginReceiver;
 386 import org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin;
 387 import org.graalvm.compiler.nodes.graphbuilderconf.ProfilingPlugin;
 388 import org.graalvm.compiler.nodes.java.ArrayLengthNode;
 389 import org.graalvm.compiler.nodes.java.ExceptionObjectNode;
 390 import org.graalvm.compiler.nodes.java.FinalFieldBarrierNode;
 391 import org.graalvm.compiler.nodes.java.InstanceOfNode;
 392 import org.graalvm.compiler.nodes.java.LoadFieldNode;
 393 import org.graalvm.compiler.nodes.java.LoadIndexedNode;
 394 import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
 395 import org.graalvm.compiler.nodes.java.MonitorEnterNode;
 396 import org.graalvm.compiler.nodes.java.MonitorExitNode;
 397 import org.graalvm.compiler.nodes.java.MonitorIdNode;


 917                     if (param == FrameState.TWO_SLOT_MARKER) {
 918                         param = null;
 919                     }
 920                     locals[i] = param;
 921                     assert param == null || param instanceof ParameterNode || param.isConstant();
 922                 }
 923             }
 924             ValueNode[] stack = {};
 925             int stackSize = 0;
 926             ValueNode[] locks = {};
 927             List<MonitorIdNode> monitorIds = Collections.emptyList();
 928             stateAfterStart = graph.add(new FrameState(null, new ResolvedJavaMethodBytecode(original), 0, locals, stack, stackSize, locks, monitorIds, false, false));
 929         }
 930         return stateAfterStart;
 931     }
 932 
 933     /**
 934      * @param type the unresolved type of the constant
 935      */
 936     protected void handleUnresolvedLoadConstant(JavaType type) {
 937         assert !graphBuilderConfig.unresolvedIsError();
 938         DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
 939         /*
 940          * Track source position for deopt nodes even if
 941          * GraphBuilderConfiguration.trackNodeSourcePosition is not set.
 942          */
 943         deopt.updateNodeSourcePosition(() -> createBytecodePosition());
 944     }
 945 
 946     /**
 947      * @param type the unresolved type of the type check
 948      * @param object the object value whose type is being checked against {@code type}
 949      */
 950     protected void handleUnresolvedCheckCast(JavaType type, ValueNode object) {
 951         assert !graphBuilderConfig.unresolvedIsError();
 952         append(new FixedGuardNode(graph.addOrUniqueWithInputs(IsNullNode.create(object)), Unresolved, InvalidateRecompile));
 953         frameState.push(JavaKind.Object, appendConstant(JavaConstant.NULL_POINTER));
 954     }
 955 
 956     /**
 957      * @param type the unresolved type of the type check
 958      * @param object the object value whose type is being checked against {@code type}
 959      */
 960     protected void handleUnresolvedInstanceOf(JavaType type, ValueNode object) {
 961         assert !graphBuilderConfig.unresolvedIsError();
 962         AbstractBeginNode successor = graph.add(new BeginNode());
 963         DeoptimizeNode deopt = graph.add(new DeoptimizeNode(InvalidateRecompile, Unresolved));
 964         deopt.updateNodeSourcePosition(() -> createBytecodePosition());
 965         append(new IfNode(graph.addOrUniqueWithInputs(IsNullNode.create(object)), successor, deopt, 1));
 966         lastInstr = successor;
 967         frameState.push(JavaKind.Int, appendConstant(JavaConstant.INT_0));
 968     }
 969 
 970     /**
 971      * @param type the type being instantiated
 972      */
 973     protected void handleUnresolvedNewInstance(JavaType type) {
 974         assert !graphBuilderConfig.unresolvedIsError();
 975         DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
 976         deopt.updateNodeSourcePosition(() -> createBytecodePosition());
 977     }
 978 
 979     /**
 980      * @param type the type of the array being instantiated
 981      * @param length the length of the array
 982      */
 983     protected void handleUnresolvedNewObjectArray(JavaType type, ValueNode length) {
 984         assert !graphBuilderConfig.unresolvedIsError();
 985         DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
 986         deopt.updateNodeSourcePosition(() -> createBytecodePosition());
 987     }
 988 
 989     /**
 990      * @param type the type being instantiated
 991      * @param dims the dimensions for the multi-array
 992      */
 993     protected void handleUnresolvedNewMultiArray(JavaType type, ValueNode[] dims) {
 994         assert !graphBuilderConfig.unresolvedIsError();
 995         DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
 996         deopt.updateNodeSourcePosition(() -> createBytecodePosition());
 997     }
 998 
 999     /**
1000      * @param field the unresolved field
1001      * @param receiver the object containing the field or {@code null} if {@code field} is static
1002      */
1003     protected void handleUnresolvedLoadField(JavaField field, ValueNode receiver) {
1004         assert !graphBuilderConfig.unresolvedIsError();
1005         DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
1006         deopt.updateNodeSourcePosition(() -> createBytecodePosition());
1007     }
1008 
1009     /**
1010      * @param field the unresolved field
1011      * @param value the value being stored to the field
1012      * @param receiver the object containing the field or {@code null} if {@code field} is static
1013      */
1014     protected void handleUnresolvedStoreField(JavaField field, ValueNode value, ValueNode receiver) {
1015         assert !graphBuilderConfig.unresolvedIsError();
1016         DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
1017         deopt.updateNodeSourcePosition(() -> createBytecodePosition());
1018     }
1019 
1020     /**
1021      * @param type
1022      */
1023     protected void handleUnresolvedExceptionType(JavaType type) {
1024         assert !graphBuilderConfig.unresolvedIsError();
1025         DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
1026         deopt.updateNodeSourcePosition(() -> createBytecodePosition());
1027     }
1028 
1029     /**
1030      * @param javaMethod
1031      * @param invokeKind
1032      */
1033     protected void handleUnresolvedInvoke(JavaMethod javaMethod, InvokeKind invokeKind) {
1034         assert !graphBuilderConfig.unresolvedIsError();
1035         DeoptimizeNode deopt = append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
1036         deopt.updateNodeSourcePosition(() -> createBytecodePosition());
1037     }
1038 
1039     private AbstractBeginNode handleException(ValueNode exceptionObject, int bci) {
1040         assert bci == BytecodeFrame.BEFORE_BCI || bci == bci() : "invalid bci";
1041         debug.log("Creating exception dispatch edges at %d, exception object=%s, exception seen=%s", bci, exceptionObject, (profilingInfo == null ? "" : profilingInfo.getExceptionSeen(bci)));
1042 
1043         FrameStateBuilder dispatchState = frameState.copy();
1044         dispatchState.clearStack();
1045 
1046         AbstractBeginNode dispatchBegin;
1047         if (exceptionObject == null) {
1048             ExceptionObjectNode newExceptionObject = graph.add(new ExceptionObjectNode(metaAccess));
1049             dispatchBegin = newExceptionObject;
1050             dispatchState.push(JavaKind.Object, dispatchBegin);
1051             dispatchState.setRethrowException(true);
1052             newExceptionObject.setStateAfter(dispatchState.create(bci, newExceptionObject));
1053         } else {
1054             dispatchBegin = graph.add(new BeginNode());
1055             dispatchState.push(JavaKind.Object, exceptionObject);
1056             dispatchState.setRethrowException(true);


1304         append(storeFieldNode);
1305         storeFieldNode.setStateAfter(this.createFrameState(stream.nextBCI(), storeFieldNode));
1306     }
1307 
1308     /**
1309      * Ensure that concrete classes are at least linked before generating an invoke. Interfaces may
1310      * never be linked so simply return true for them.
1311      *
1312      * @param target
1313      * @return true if the declared holder is an interface or is linked
1314      */
1315     private static boolean callTargetIsResolved(JavaMethod target) {
1316         if (target instanceof ResolvedJavaMethod) {
1317             ResolvedJavaMethod resolvedTarget = (ResolvedJavaMethod) target;
1318             ResolvedJavaType resolvedType = resolvedTarget.getDeclaringClass();
1319             return resolvedType.isInterface() || resolvedType.isLinked();
1320         }
1321         return false;
1322     }
1323 
1324     protected void genInvokeStatic(int cpi, int opcode) {
1325         JavaMethod target = lookupMethod(cpi, opcode);
1326         genInvokeStatic(target);
1327     }
1328 
1329     void genInvokeStatic(JavaMethod target) {
1330         if (callTargetIsResolved(target)) {
1331             ResolvedJavaMethod resolvedTarget = (ResolvedJavaMethod) target;
1332             ResolvedJavaType holder = resolvedTarget.getDeclaringClass();
1333             if (!holder.isInitialized() && ResolveClassBeforeStaticInvoke.getValue(options)) {
1334                 handleUnresolvedInvoke(target, InvokeKind.Static);
1335             } else {
1336                 ValueNode classInit = null;
1337                 ClassInitializationPlugin classInitializationPlugin = graphBuilderConfig.getPlugins().getClassInitializationPlugin();
1338                 if (classInitializationPlugin != null && classInitializationPlugin.shouldApply(this, resolvedTarget.getDeclaringClass())) {
1339                     FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
1340                     classInit = classInitializationPlugin.apply(this, resolvedTarget.getDeclaringClass(), stateBefore);
1341                 }
1342 
1343                 ValueNode[] args = frameState.popArguments(resolvedTarget.getSignature().getParameterCount(false));
1344                 Invoke invoke = appendInvoke(InvokeKind.Static, resolvedTarget, args);
1345                 if (invoke != null) {
1346                     invoke.setClassInit(classInit);
1347                 }
1348             }
1349         } else {
1350             handleUnresolvedInvoke(target, InvokeKind.Static);
1351         }
1352     }
1353 
1354     protected void genInvokeInterface(int cpi, int opcode) {
1355         JavaMethod target = lookupMethod(cpi, opcode);
1356         genInvokeInterface(target);
1357     }
1358 
1359     protected void genInvokeInterface(JavaMethod target) {
1360         if (callTargetIsResolved(target)) {
1361             ValueNode[] args = frameState.popArguments(target.getSignature().getParameterCount(true));
1362             appendInvoke(InvokeKind.Interface, (ResolvedJavaMethod) target, args);
1363         } else {
1364             handleUnresolvedInvoke(target, InvokeKind.Interface);
1365         }
1366     }
1367 
1368     protected void genInvokeDynamic(int cpi, int opcode) {
1369         JavaMethod target = lookupMethod(cpi, opcode);
1370         genInvokeDynamic(target);


1371     }
1372 
1373     void genInvokeDynamic(JavaMethod target) {
1374         if (!(target instanceof ResolvedJavaMethod) || !genDynamicInvokeHelper((ResolvedJavaMethod) target, stream.readCPI4(), INVOKEDYNAMIC)) {
1375             handleUnresolvedInvoke(target, InvokeKind.Static);
1376         }
1377     }
1378 
1379     protected void genInvokeVirtual(int cpi, int opcode) {
1380         JavaMethod target = lookupMethod(cpi, opcode);
1381         genInvokeVirtual(target);
1382     }
1383 
1384     private boolean genDynamicInvokeHelper(ResolvedJavaMethod target, int cpi, int opcode) {
1385         assert opcode == INVOKEDYNAMIC || opcode == INVOKEVIRTUAL;
1386 
1387         InvokeDynamicPlugin invokeDynamicPlugin = graphBuilderConfig.getPlugins().getInvokeDynamicPlugin();
1388 
1389         if (opcode == INVOKEVIRTUAL && invokeDynamicPlugin != null && !invokeDynamicPlugin.isResolvedDynamicInvoke(this, cpi, opcode)) {
1390             // regular invokevirtual, let caller handle it
1391             return false;
1392         }
1393 
1394         if (GeneratePIC.getValue(options) && (invokeDynamicPlugin == null || !invokeDynamicPlugin.supportsDynamicInvoke(this, cpi, opcode))) {
1395             // bail out if static compiler and no dynamic type support
1396             append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
1397             return true;
1398         }
1399 
1400         JavaConstant appendix = constantPool.lookupAppendix(cpi, opcode);
1401         ValueNode appendixNode = null;
1402 
1403         if (appendix != null) {
1404             if (invokeDynamicPlugin != null) {
1405                 invokeDynamicPlugin.recordDynamicMethod(this, cpi, opcode, target);
1406 
1407                 // Will perform runtime type checks and static initialization
1408                 FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
1409                 appendixNode = invokeDynamicPlugin.genAppendixNode(this, cpi, opcode, appendix, stateBefore);
1410             } else {
1411                 appendixNode = ConstantNode.forConstant(appendix, metaAccess, graph);
1412             }
1413 
1414             frameState.push(JavaKind.Object, appendixNode);
1415 
1416         } else if (GeneratePIC.getValue(options)) {
1417             // Need to emit runtime guard and perform static initialization.
1418             // Not implemented yet.
1419             append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
1420             return true;
1421         }
1422 
1423         boolean hasReceiver = (opcode == INVOKEDYNAMIC) ? false : !target.isStatic();
1424         ValueNode[] args = frameState.popArguments(target.getSignature().getParameterCount(hasReceiver));
1425         if (hasReceiver) {
1426             appendInvoke(InvokeKind.Virtual, target, args);
1427         } else {
1428             appendInvoke(InvokeKind.Static, target, args);
1429         }
1430 
1431         return true;
1432     }
1433 
1434     void genInvokeVirtual(JavaMethod target) {
1435         if (!genInvokeVirtualHelper(target)) {
1436             handleUnresolvedInvoke(target, InvokeKind.Virtual);
1437         }
1438     }
1439 
1440     private boolean genInvokeVirtualHelper(JavaMethod target) {
1441         if (!callTargetIsResolved(target)) {
1442             return false;
1443         }
1444 
1445         ResolvedJavaMethod resolvedTarget = (ResolvedJavaMethod) target;
1446         int cpi = stream.readCPI();
1447 
1448         /*
1449          * Special handling for runtimes that rewrite an invocation of MethodHandle.invoke(...) or
1450          * MethodHandle.invokeExact(...) to a static adapter. HotSpot does this - see
1451          * https://wiki.openjdk.java.net/display/HotSpot/Method+handles+and+invokedynamic
1452          */
1453 
1454         if (genDynamicInvokeHelper(resolvedTarget, cpi, INVOKEVIRTUAL)) {
1455             return true;
1456         }
1457 
1458         ValueNode[] args = frameState.popArguments(target.getSignature().getParameterCount(true));
1459         appendInvoke(InvokeKind.Virtual, (ResolvedJavaMethod) target, args);
1460 
1461         return true;
1462     }
1463 
1464     protected void genInvokeSpecial(int cpi, int opcode) {
1465         JavaMethod target = lookupMethod(cpi, opcode);
1466         genInvokeSpecial(target);
1467     }
1468 
1469     void genInvokeSpecial(JavaMethod target) {
1470         if (callTargetIsResolved(target)) {
1471             assert target != null;
1472             assert target.getSignature() != null;
1473             ValueNode[] args = frameState.popArguments(target.getSignature().getParameterCount(true));
1474             appendInvoke(InvokeKind.Special, (ResolvedJavaMethod) target, args);
1475         } else {
1476             handleUnresolvedInvoke(target, InvokeKind.Special);
1477         }
1478     }
1479 
1480     static class CurrentInvoke {
1481         final ValueNode[] args;
1482         final InvokeKind kind;
1483         final JavaType returnType;
1484 
1485         CurrentInvoke(ValueNode[] args, InvokeKind kind, JavaType returnType) {
1486             this.args = args;
1487             this.kind = kind;
1488             this.returnType = returnType;
1489         }


2220      * Prints a line to {@link TTY} with a prefix indicating the current parse context. The prefix
2221      * is of the form:
2222      *
2223      * <pre>
2224      * {SPACE * n} {name of method being parsed} "(" {file name} ":" {line number} ")"
2225      * </pre>
2226      *
2227      * where {@code n} is the current inlining depth.
2228      *
2229      * @param format a format string
2230      * @param args arguments to the format string
2231      */
2232 
2233     protected void traceWithContext(String format, Object... args) {
2234         StackTraceElement where = code.asStackTraceElement(bci());
2235         String s = format("%s%s (%s:%d) %s", nSpaces(getDepth()), method.isConstructor() ? method.format("%h.%n") : method.getName(), where.getFileName(), where.getLineNumber(),
2236                         format(format, args));
2237         TTY.println(s);
2238     }
2239 
2240     protected RuntimeException throwParserError(Throwable e) {
2241         if (e instanceof BytecodeParserError) {
2242             throw (BytecodeParserError) e;
2243         }
2244         BytecodeParser bp = this;
2245         BytecodeParserError res = new BytecodeParserError(e);
2246         while (bp != null) {
2247             res.addContext("parsing " + bp.code.asStackTraceElement(bp.bci()));
2248             bp = bp.parent;
2249         }
2250         throw res;
2251     }
2252 
2253     protected void parseAndInlineCallee(ResolvedJavaMethod targetMethod, ValueNode[] args, IntrinsicContext calleeIntrinsicContext) {
2254         try (IntrinsicScope s = calleeIntrinsicContext != null && !parsingIntrinsic() ? new IntrinsicScope(this, targetMethod.getSignature().toParameterKinds(!targetMethod.isStatic()), args) : null) {
2255 
2256             BytecodeParser parser = graphBuilderInstance.createBytecodeParser(graph, this, targetMethod, INVOCATION_ENTRY_BCI, calleeIntrinsicContext);
2257             FrameStateBuilder startFrameState = new FrameStateBuilder(parser, parser.code, graph);
2258             if (!targetMethod.isStatic()) {
2259                 args[0] = nullCheckedValue(args[0]);
2260             }
2261             startFrameState.initializeFromArgumentsArray(args);
2262             parser.build(this.lastInstr, startFrameState);
2263 
2264             if (parser.returnDataList == null) {
2265                 /* Callee does not return. */
2266                 lastInstr = null;
2267             } else {
2268                 ValueNode calleeReturnValue;
2269                 MergeNode returnMergeNode = null;
2270                 if (s != null) {


2908 
2909             // read the opcode
2910             int opcode = stream.currentBC();
2911             assert traceState();
2912             assert traceInstruction(bci, opcode, bci == block.startBci);
2913             if (parent == null && bci == entryBCI) {
2914                 if (block.getJsrScope() != JsrScope.EMPTY_SCOPE) {
2915                     throw new JsrNotSupportedBailout("OSR into a JSR scope is not supported");
2916                 }
2917                 EntryMarkerNode x = append(new EntryMarkerNode());
2918                 frameState.insertProxies(value -> graph.unique(new EntryProxyNode(value, x)));
2919                 x.setStateAfter(createFrameState(bci, x));
2920             }
2921 
2922             try (DebugCloseable context = openNodeContext()) {
2923                 processBytecode(bci, opcode);
2924             } catch (BailoutException e) {
2925                 // Don't wrap bailouts as parser errors
2926                 throw e;
2927             } catch (Throwable e) {
2928                 throw throwParserError(e);
2929             }
2930 
2931             if (lastInstr == null || lastInstr.next() != null) {
2932                 break;
2933             }
2934 
2935             stream.next();
2936             bci = stream.currentBCI();
2937 
2938             assert block == currentBlock;
2939             assert checkLastInstruction();
2940             lastInstr = finishInstruction(lastInstr, frameState);
2941             if (bci < endBCI) {
2942                 if (bci > block.endBci) {
2943                     assert !block.getSuccessor(0).isExceptionEntry;
2944                     assert block.numNormalSuccessors() == 1;
2945                     // we fell through to the next block, add a goto and break
2946                     appendGoto(block.getSuccessor(0));
2947                     break;
2948                 }


3328         return stream;
3329     }
3330 
3331     @Override
3332     public int bci() {
3333         return stream.currentBCI();
3334     }
3335 
3336     public void loadLocal(int index, JavaKind kind) {
3337         ValueNode value = frameState.loadLocal(index, kind);
3338         frameState.push(kind, value);
3339     }
3340 
3341     public void loadLocalObject(int index) {
3342         ValueNode value = frameState.loadLocal(index, JavaKind.Object);
3343 
3344         int nextBCI = stream.nextBCI();
3345         int nextBC = stream.readUByte(nextBCI);
3346         if (nextBCI <= currentBlock.endBci && nextBC == Bytecodes.GETFIELD) {
3347             stream.next();
3348             genGetField(stream.readCPI(), Bytecodes.GETFIELD, value);
3349         } else {
3350             frameState.push(JavaKind.Object, value);
3351         }
3352     }
3353 
3354     public void storeLocal(JavaKind kind, int index) {
3355         ValueNode value = frameState.pop(kind);
3356         frameState.storeLocal(index, kind, value);
3357     }
3358 
3359     private void genLoadConstant(int cpi, int opcode) {
3360         Object con = lookupConstant(cpi, opcode);
3361 
3362         if (con instanceof JavaType) {
3363             // this is a load of class constant which might be unresolved
3364             JavaType type = (JavaType) con;
3365             if (type instanceof ResolvedJavaType) {
3366                 frameState.push(JavaKind.Object, appendConstant(getConstantReflection().asJavaClass((ResolvedJavaType) type)));
3367             } else {
3368                 handleUnresolvedLoadConstant(type);


3577         maybeEagerlyResolve(cpi, bytecode);
3578         JavaType result = constantPool.lookupType(cpi, bytecode);
3579         assert !graphBuilderConfig.unresolvedIsError() || result instanceof ResolvedJavaType;
3580         return result;
3581     }
3582 
3583     private JavaMethod lookupMethod(int cpi, int opcode) {
3584         maybeEagerlyResolve(cpi, opcode);
3585         JavaMethod result = constantPool.lookupMethod(cpi, opcode);
3586         /*
3587          * In general, one cannot assume that the declaring class being initialized is useful, since
3588          * the actual concrete receiver may be a different class (except for static calls). Also,
3589          * interfaces are initialized only under special circumstances, so that this assertion would
3590          * often fail for interface calls.
3591          */
3592         assert !graphBuilderConfig.unresolvedIsError() ||
3593                         (result instanceof ResolvedJavaMethod && (opcode != INVOKESTATIC || ((ResolvedJavaMethod) result).getDeclaringClass().isInitialized())) : result;
3594         return result;
3595     }
3596 
3597     protected JavaField lookupField(int cpi, int opcode) {
3598         maybeEagerlyResolve(cpi, opcode);
3599         JavaField result = constantPool.lookupField(cpi, method, opcode);
3600 
3601         if (graphBuilderConfig.eagerResolving()) {
3602             assert !graphBuilderConfig.unresolvedIsError() || result instanceof ResolvedJavaField : "Not resolved: " + result;
3603             if (result instanceof ResolvedJavaField) {
3604                 ResolvedJavaType declaringClass = ((ResolvedJavaField) result).getDeclaringClass();
3605                 if (!declaringClass.isInitialized()) {
3606                     assert declaringClass.isInterface() : "Declaring class not initialized but not an interface? " + declaringClass;
3607                     declaringClass.initialize();
3608                 }
3609             }
3610         }
3611         assert !graphBuilderConfig.unresolvedIsError() || (result instanceof ResolvedJavaField && ((ResolvedJavaField) result).getDeclaringClass().isInitialized()) : result;
3612         return result;
3613     }
3614 
3615     private Object lookupConstant(int cpi, int opcode) {
3616         maybeEagerlyResolve(cpi, opcode);
3617         Object result = constantPool.lookupConstant(cpi);
3618         assert !graphBuilderConfig.unresolvedIsError() || !(result instanceof JavaType) || (result instanceof ResolvedJavaType) : result;
3619         return result;
3620     }
3621 
3622     protected void maybeEagerlyResolve(int cpi, int bytecode) {
3623         if (intrinsicContext != null) {
3624             constantPool.loadReferencedType(cpi, bytecode);
3625         } else if (graphBuilderConfig.eagerResolving()) {
3626             /*
3627              * Since we're potentially triggering class initialization here, we need synchronization
3628              * to mitigate the potential for class initialization related deadlock being caused by
3629              * the compiler (e.g., https://github.com/graalvm/graal-core/pull/232/files#r90788550).
3630              */
3631             synchronized (BytecodeParser.class) {
3632                 constantPool.loadReferencedType(cpi, bytecode);
3633             }
3634         }
3635     }
3636 
3637     private JavaTypeProfile getProfileForTypeCheck(TypeReference type) {
3638         if (parsingIntrinsic() || profilingInfo == null || !optimisticOpts.useTypeCheckHints(getOptions()) || type.isExact()) {
3639             return null;
3640         } else {
3641             return profilingInfo.getTypeProfile(bci());
3642         }


3727         }
3728         LogicNode logicNode = genUnique(instanceOfNode);
3729 
3730         int next = getStream().nextBCI();
3731         int value = getStream().readUByte(next);
3732         if (next <= currentBlock.endBci && (value == Bytecodes.IFEQ || value == Bytecodes.IFNE)) {
3733             getStream().next();
3734             BciBlock firstSucc = currentBlock.getSuccessor(0);
3735             BciBlock secondSucc = currentBlock.getSuccessor(1);
3736             if (firstSucc != secondSucc) {
3737                 genIf(instanceOfNode, value != Bytecodes.IFNE, firstSucc, secondSucc);
3738             } else {
3739                 appendGoto(firstSucc);
3740             }
3741         } else {
3742             // Most frequent for value is IRETURN, followed by ISTORE.
3743             frameState.push(JavaKind.Int, append(genConditional(logicNode)));
3744         }
3745     }
3746 
3747     protected void genNewInstance(int cpi) {
3748         JavaType type = lookupType(cpi, NEW);
3749         genNewInstance(type);
3750     }
3751 
3752     void genNewInstance(JavaType type) {
3753         if (!(type instanceof ResolvedJavaType) || !((ResolvedJavaType) type).isInitialized()) {
3754             handleUnresolvedNewInstance(type);
3755             return;
3756         }
3757         ResolvedJavaType resolvedType = (ResolvedJavaType) type;
3758 
3759         ResolvedJavaType[] skippedExceptionTypes = this.graphBuilderConfig.getSkippedExceptionTypes();
3760         if (skippedExceptionTypes != null) {
3761             for (ResolvedJavaType exceptionType : skippedExceptionTypes) {
3762                 if (exceptionType.isAssignableFrom(resolvedType)) {
3763                     append(new DeoptimizeNode(DeoptimizationAction.InvalidateRecompile, RuntimeConstraint));
3764                     return;
3765                 }
3766             }
3767         }
3768 
3769         ClassInitializationPlugin classInitializationPlugin = graphBuilderConfig.getPlugins().getClassInitializationPlugin();
3770         if (classInitializationPlugin != null && classInitializationPlugin.shouldApply(this, resolvedType)) {
3771             FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
3772             classInitializationPlugin.apply(this, resolvedType, stateBefore);


3867 
3868         ClassInitializationPlugin classInitializationPlugin = this.graphBuilderConfig.getPlugins().getClassInitializationPlugin();
3869         if (classInitializationPlugin != null && classInitializationPlugin.shouldApply(this, resolvedType)) {
3870             FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
3871             classInitializationPlugin.apply(this, resolvedType, stateBefore);
3872         }
3873 
3874         for (int i = rank - 1; i >= 0; i--) {
3875             dims[i] = frameState.pop(JavaKind.Int);
3876         }
3877 
3878         for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) {
3879             if (plugin.handleNewMultiArray(this, resolvedType, dims)) {
3880                 return;
3881             }
3882         }
3883 
3884         frameState.push(JavaKind.Object, append(createNewMultiArray(resolvedType, dims)));
3885     }
3886 
3887     protected void genGetField(int cpi, int opcode) {
3888         genGetField(cpi, opcode, frameState.pop(JavaKind.Object));
3889     }
3890 
3891     protected void genGetField(int cpi, int opcode, ValueNode receiverInput) {
3892         JavaField field = lookupField(cpi, opcode);
3893         genGetField(field, receiverInput);
3894     }
3895 
3896     private void genGetField(JavaField field, ValueNode receiverInput) {
3897         ValueNode receiver = emitExplicitExceptions(receiverInput);
3898         if (field instanceof ResolvedJavaField) {
3899             ResolvedJavaField resolvedField = (ResolvedJavaField) field;
3900             genGetField(resolvedField, receiver);
3901         } else {
3902             handleUnresolvedLoadField(field, receiver);
3903         }
3904     }
3905 
3906     private void genGetField(ResolvedJavaField resolvedField, ValueNode receiver) {
3907         if (!parsingIntrinsic() && GeneratePIC.getValue(getOptions())) {
3908             graph.recordField(resolvedField);
3909         }
3910 
3911         for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) {
3912             if (plugin.handleLoadField(this, receiver, resolvedField)) {
3913                 return;


3949     }
3950 
3951     protected ValueNode emitExplicitExceptions(ValueNode receiver) {
3952         if (StampTool.isPointerNonNull(receiver) || !needsExplicitException()) {
3953             return receiver;
3954         } else {
3955             return emitExplicitNullCheck(receiver);
3956         }
3957     }
3958 
3959     private boolean needsExplicitException() {
3960         BytecodeExceptionMode exceptionMode = graphBuilderConfig.getBytecodeExceptionMode();
3961         if (exceptionMode == BytecodeExceptionMode.CheckAll || StressExplicitExceptionCode.getValue(options)) {
3962             return true;
3963         } else if (exceptionMode == BytecodeExceptionMode.Profile && profilingInfo != null) {
3964             return profilingInfo.getExceptionSeen(bci()) == TriState.TRUE;
3965         }
3966         return false;
3967     }
3968 
3969     protected void genPutField(int cpi, int opcode) {
3970         JavaField field = lookupField(cpi, opcode);
3971         genPutField(field);
3972     }
3973 
3974     protected void genPutField(JavaField field) {
3975         genPutField(field, frameState.pop(field.getJavaKind()));
3976     }
3977 
3978     private void genPutField(JavaField field, ValueNode value) {
3979         ValueNode receiver = emitExplicitExceptions(frameState.pop(JavaKind.Object));
3980         if (field instanceof ResolvedJavaField) {
3981             ResolvedJavaField resolvedField = (ResolvedJavaField) field;
3982 
3983             if (!parsingIntrinsic() && GeneratePIC.getValue(getOptions())) {
3984                 graph.recordField(resolvedField);
3985             }
3986 
3987             for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) {
3988                 if (plugin.handleStoreField(this, receiver, resolvedField, value)) {
3989                     return;
3990                 }
3991             }
3992 
3993             if (resolvedField.isFinal() && method.isConstructor()) {
3994                 finalBarrierRequired = true;
3995             }
3996             genStoreField(receiver, resolvedField, value);
3997         } else {
3998             handleUnresolvedStoreField(field, value, receiver);
3999         }
4000     }
4001 
4002     protected void genGetStatic(int cpi, int opcode) {
4003         JavaField field = lookupField(cpi, opcode);
4004         genGetStatic(field);
4005     }
4006 
4007     private void genGetStatic(JavaField field) {
4008         ResolvedJavaField resolvedField = resolveStaticFieldAccess(field, null);
4009         if (resolvedField == null) {
4010             return;
4011         }
4012 
4013         if (!parsingIntrinsic() && GeneratePIC.getValue(getOptions())) {
4014             graph.recordField(resolvedField);
4015         }
4016 
4017         /*
4018          * Javac does not allow use of "$assertionsDisabled" for a field name but Eclipse does, in
4019          * which case a suffix is added to the generated field.
4020          */
4021         if ((parsingIntrinsic() || graphBuilderConfig.omitAssertions()) && resolvedField.isSynthetic() && resolvedField.getName().startsWith("$assertionsDisabled")) {
4022             frameState.push(field.getJavaKind(), ConstantNode.forBoolean(true, graph));
4023             return;
4024         }
4025 
4026         ClassInitializationPlugin classInitializationPlugin = this.graphBuilderConfig.getPlugins().getClassInitializationPlugin();


4048              * Static fields have initialization semantics but may be safely accessed under certain
4049              * conditions while the class is being initialized. Executing in the clinit or init of
4050              * classes which are subtypes of the field holder are sure to be running in a context
4051              * where the access is safe.
4052              */
4053             if (resolvedField.getDeclaringClass().isAssignableFrom(method.getDeclaringClass())) {
4054                 if (method.isClassInitializer() || method.isConstructor()) {
4055                     return resolvedField;
4056                 }
4057             }
4058         }
4059         if (value == null) {
4060             handleUnresolvedLoadField(field, null);
4061         } else {
4062             handleUnresolvedStoreField(field, value, null);
4063 
4064         }
4065         return null;
4066     }
4067 
4068     protected void genPutStatic(int cpi, int opcode) {
4069         JavaField field = lookupField(cpi, opcode);
4070         genPutStatic(field);
4071     }
4072 
4073     protected void genPutStatic(JavaField field) {
4074         ValueNode value = frameState.pop(field.getJavaKind());
4075         ResolvedJavaField resolvedField = resolveStaticFieldAccess(field, value);
4076         if (resolvedField == null) {
4077             return;
4078         }
4079 
4080         if (!parsingIntrinsic() && GeneratePIC.getValue(getOptions())) {
4081             graph.recordField(resolvedField);
4082         }
4083 
4084         ClassInitializationPlugin classInitializationPlugin = this.graphBuilderConfig.getPlugins().getClassInitializationPlugin();
4085         if (classInitializationPlugin != null && classInitializationPlugin.shouldApply(this, resolvedField.getDeclaringClass())) {
4086             FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
4087             classInitializationPlugin.apply(this, resolvedField.getDeclaringClass(), stateBefore);
4088         }
4089 
4090         for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) {
4091             if (plugin.handleStoreStaticField(this, resolvedField, value)) {
4092                 return;
4093             }


4417             case IFLE           : genIfZero(Condition.LE); break;
4418             case IF_ICMPEQ      : genIfSame(JavaKind.Int, Condition.EQ); break;
4419             case IF_ICMPNE      : genIfSame(JavaKind.Int, Condition.NE); break;
4420             case IF_ICMPLT      : genIfSame(JavaKind.Int, Condition.LT); break;
4421             case IF_ICMPGE      : genIfSame(JavaKind.Int, Condition.GE); break;
4422             case IF_ICMPGT      : genIfSame(JavaKind.Int, Condition.GT); break;
4423             case IF_ICMPLE      : genIfSame(JavaKind.Int, Condition.LE); break;
4424             case IF_ACMPEQ      : genIfSame(JavaKind.Object, Condition.EQ); break;
4425             case IF_ACMPNE      : genIfSame(JavaKind.Object, Condition.NE); break;
4426             case GOTO           : genGoto(); break;
4427             case JSR            : genJsr(stream.readBranchDest()); break;
4428             case RET            : genRet(stream.readLocalIndex()); break;
4429             case TABLESWITCH    : genSwitch(new BytecodeTableSwitch(getStream(), bci())); break;
4430             case LOOKUPSWITCH   : genSwitch(new BytecodeLookupSwitch(getStream(), bci())); break;
4431             case IRETURN        : genReturn(frameState.pop(JavaKind.Int), JavaKind.Int); break;
4432             case LRETURN        : genReturn(frameState.pop(JavaKind.Long), JavaKind.Long); break;
4433             case FRETURN        : genReturn(frameState.pop(JavaKind.Float), JavaKind.Float); break;
4434             case DRETURN        : genReturn(frameState.pop(JavaKind.Double), JavaKind.Double); break;
4435             case ARETURN        : genReturn(frameState.pop(JavaKind.Object), JavaKind.Object); break;
4436             case RETURN         : genReturn(null, JavaKind.Void); break;
4437             case GETSTATIC      : cpi = stream.readCPI(); genGetStatic(cpi, opcode); break;
4438             case PUTSTATIC      : cpi = stream.readCPI(); genPutStatic(cpi, opcode); break;
4439             case GETFIELD       : cpi = stream.readCPI(); genGetField(cpi, opcode); break;
4440             case PUTFIELD       : cpi = stream.readCPI(); genPutField(cpi, opcode); break;
4441             case INVOKEVIRTUAL  : cpi = stream.readCPI(); genInvokeVirtual(cpi, opcode); break;
4442             case INVOKESPECIAL  : cpi = stream.readCPI(); genInvokeSpecial(cpi, opcode); break;
4443             case INVOKESTATIC   : cpi = stream.readCPI(); genInvokeStatic(cpi, opcode); break;
4444             case INVOKEINTERFACE: cpi = stream.readCPI(); genInvokeInterface(cpi, opcode); break;
4445             case INVOKEDYNAMIC  : cpi = stream.readCPI4(); genInvokeDynamic(cpi, opcode); break;
4446             case NEW            : genNewInstance(stream.readCPI()); break;
4447             case NEWARRAY       : genNewPrimitiveArray(stream.readLocalIndex()); break;
4448             case ANEWARRAY      : genNewObjectArray(stream.readCPI()); break;
4449             case ARRAYLENGTH    : genArrayLength(); break;
4450             case ATHROW         : genThrow(); break;
4451             case CHECKCAST      : genCheckCast(); break;
4452             case INSTANCEOF     : genInstanceOf(); break;
4453             case MONITORENTER   : genMonitorEnter(frameState.pop(JavaKind.Object), stream.nextBCI()); break;
4454             case MONITOREXIT    : genMonitorExit(frameState.pop(JavaKind.Object), null, stream.nextBCI()); break;
4455             case MULTIANEWARRAY : genNewMultiArray(stream.readCPI()); break;
4456             case IFNULL         : genIfNull(Condition.EQ); break;
4457             case IFNONNULL      : genIfNull(Condition.NE); break;
4458             case GOTO_W         : genGoto(); break;
4459             case JSR_W          : genJsr(stream.readBranchDest()); break;
4460             case BREAKPOINT     : throw new PermanentBailoutException("concurrent setting of breakpoint");
4461             default             : throw new PermanentBailoutException("Unsupported opcode %d (%s) [bci=%d]", opcode, nameOf(opcode), bci);
4462         }
4463         // @formatter:on
4464         // Checkstyle: resume
4465     }


< prev index next >