< prev index next >
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.java/src/org/graalvm/compiler/java/BytecodeParser.java
Print this page
@@ -418,10 +418,12 @@
import org.graalvm.compiler.nodes.java.NewInstanceNode;
import org.graalvm.compiler.nodes.java.NewMultiArrayNode;
import org.graalvm.compiler.nodes.java.RegisterFinalizerNode;
import org.graalvm.compiler.nodes.java.StoreFieldNode;
import org.graalvm.compiler.nodes.java.StoreIndexedNode;
+import org.graalvm.compiler.nodes.spi.CoreProviders;
+import org.graalvm.compiler.nodes.spi.Replacements;
import org.graalvm.compiler.nodes.spi.StampProvider;
import org.graalvm.compiler.nodes.type.StampTool;
import org.graalvm.compiler.nodes.util.GraphUtil;
import org.graalvm.compiler.options.OptionValues;
import org.graalvm.compiler.phases.OptimisticOptimizations;
@@ -712,14 +714,11 @@
this.graph = graph;
this.options = graph.getOptions();
this.debug = graph.getDebug();
this.graphBuilderConfig = graphBuilderInstance.graphBuilderConfig;
this.optimisticOpts = graphBuilderInstance.optimisticOpts;
- this.metaAccess = graphBuilderInstance.metaAccess;
- this.stampProvider = graphBuilderInstance.stampProvider;
- this.constantReflection = graphBuilderInstance.constantReflection;
- this.constantFieldProvider = graphBuilderInstance.constantFieldProvider;
+ this.providers = graphBuilderInstance.providers;
this.stream = new BytecodeStream(code.getCode());
this.profilingInfo = graph.useProfilingInfo() ? code.getProfilingInfo() : null;
this.constantPool = code.getConstantPool();
this.intrinsicContext = intrinsicContext;
this.entryBCI = entryBCI;
@@ -776,11 +775,11 @@
return this.beforeUnwindNode;
}
@SuppressWarnings("try")
protected void buildRootMethod() {
- FrameStateBuilder startFrameState = new FrameStateBuilder(this, code, graph);
+ FrameStateBuilder startFrameState = new FrameStateBuilder(this, code, graph, graphBuilderConfig.retainLocalVariables());
startFrameState.initializeForMethodStart(graph.getAssumptions(), graphBuilderConfig.eagerResolving() || intrinsicContext != null, graphBuilderConfig.getPlugins());
try (IntrinsicScope s = intrinsicContext != null ? new IntrinsicScope(this) : null) {
build(graph.start(), startFrameState);
}
@@ -1119,11 +1118,11 @@
FrameStateBuilder dispatchState = frameState.copy();
dispatchState.clearStack();
AbstractBeginNode dispatchBegin;
if (exceptionObject == null) {
- ExceptionObjectNode newExceptionObject = graph.add(new ExceptionObjectNode(metaAccess));
+ ExceptionObjectNode newExceptionObject = graph.add(new ExceptionObjectNode(getMetaAccess()));
dispatchBegin = newExceptionObject;
dispatchState.push(JavaKind.Object, dispatchBegin);
dispatchState.setRethrowException(true);
newExceptionObject.setStateAfter(dispatchState.create(bci, newExceptionObject));
} else {
@@ -1164,11 +1163,11 @@
FixedNode target = createTarget(dispatchBlock, dispatchState);
afterInstrumentation.setNext(target);
}
protected ValueNode genLoadIndexed(ValueNode array, ValueNode index, GuardingNode boundsCheck, JavaKind kind) {
- return LoadIndexedNode.create(graph.getAssumptions(), array, index, boundsCheck, kind, metaAccess, constantReflection);
+ return LoadIndexedNode.create(graph.getAssumptions(), array, index, boundsCheck, kind, getMetaAccess(), getConstantReflection());
}
protected void genStoreIndexed(ValueNode array, ValueNode index, GuardingNode boundsCheck, GuardingNode storeCheck, JavaKind kind, ValueNode value) {
add(new StoreIndexedNode(array, index, boundsCheck, storeCheck, kind, value));
}
@@ -1240,11 +1239,11 @@
protected ValueNode genXor(ValueNode x, ValueNode y) {
return XorNode.create(x, y, NodeView.DEFAULT);
}
protected ValueNode genNormalizeCompare(ValueNode x, ValueNode y, boolean isUnorderedLess) {
- return NormalizeCompareNode.create(x, y, isUnorderedLess, JavaKind.Int, constantReflection);
+ return NormalizeCompareNode.create(x, y, isUnorderedLess, JavaKind.Int, getConstantReflection());
}
protected ValueNode genFloatConvert(FloatConvert op, ValueNode input) {
return FloatConvertNode.create(op, input, NodeView.DEFAULT);
}
@@ -1271,19 +1270,19 @@
appendGoto(currentBlock.getSuccessor(0));
assert currentBlock.numNormalSuccessors() == 1;
}
protected LogicNode genObjectEquals(ValueNode x, ValueNode y) {
- return ObjectEqualsNode.create(constantReflection, metaAccess, options, x, y, NodeView.DEFAULT);
+ return ObjectEqualsNode.create(getConstantReflection(), getMetaAccess(), options, x, y, NodeView.DEFAULT);
}
protected LogicNode genIntegerEquals(ValueNode x, ValueNode y) {
- return IntegerEqualsNode.create(constantReflection, metaAccess, options, null, x, y, NodeView.DEFAULT);
+ return IntegerEqualsNode.create(getConstantReflection(), getMetaAccess(), options, null, x, y, NodeView.DEFAULT);
}
protected LogicNode genIntegerLessThan(ValueNode x, ValueNode y) {
- return IntegerLessThanNode.create(constantReflection, metaAccess, options, null, x, y, NodeView.DEFAULT);
+ return IntegerLessThanNode.create(getConstantReflection(), getMetaAccess(), options, null, x, y, NodeView.DEFAULT);
}
protected ValueNode genUnique(ValueNode x) {
return graph.addOrUniqueWithInputs(x);
}
@@ -1370,39 +1369,39 @@
protected GuardingNode maybeEmitExplicitBoundsCheck(ValueNode receiver, ValueNode index) {
if (!needsExplicitBoundsCheckException(receiver, index)) {
return null;
}
ValueNode length = append(genArrayLength(receiver));
- LogicNode condition = genUnique(IntegerBelowNode.create(constantReflection, metaAccess, options, null, index, length, NodeView.DEFAULT));
+ LogicNode condition = genUnique(IntegerBelowNode.create(getConstantReflection(), getMetaAccess(), options, null, index, length, NodeView.DEFAULT));
return emitBytecodeExceptionCheck(condition, true, BytecodeExceptionKind.OUT_OF_BOUNDS, index, length);
}
protected GuardingNode maybeEmitExplicitStoreCheck(ValueNode array, JavaKind elementKind, ValueNode value) {
if (elementKind != JavaKind.Object || StampTool.isPointerAlwaysNull(value) || !needsExplicitStoreCheckException(array, value)) {
return null;
}
- ValueNode arrayClass = genUnique(LoadHubNode.create(array, stampProvider, metaAccess, constantReflection));
- ValueNode componentHub = append(LoadArrayComponentHubNode.create(arrayClass, stampProvider, metaAccess, constantReflection));
+ ValueNode arrayClass = genUnique(LoadHubNode.create(array, getStampProvider(), getMetaAccess(), getConstantReflection()));
+ ValueNode componentHub = append(LoadArrayComponentHubNode.create(arrayClass, getStampProvider(), getMetaAccess(), getConstantReflection()));
LogicNode condition = genUnique(InstanceOfDynamicNode.create(graph.getAssumptions(), getConstantReflection(), componentHub, value, true));
return emitBytecodeExceptionCheck(condition, true, BytecodeExceptionKind.ARRAY_STORE, value);
}
protected GuardingNode maybeEmitExplicitDivisionByZeroCheck(ValueNode y) {
if (!((IntegerStamp) y.stamp(NodeView.DEFAULT)).contains(0) || !needsExplicitDivisionByZeroException(y)) {
return null;
}
ConstantNode zero = ConstantNode.defaultForKind(y.getStackKind(), graph);
- LogicNode condition = genUnique(IntegerEqualsNode.create(constantReflection, metaAccess, options, null, y, zero, NodeView.DEFAULT));
+ LogicNode condition = genUnique(IntegerEqualsNode.create(getConstantReflection(), getMetaAccess(), options, null, y, zero, NodeView.DEFAULT));
return emitBytecodeExceptionCheck(condition, false, BytecodeExceptionKind.DIVISION_BY_ZERO);
}
private AbstractBeginNode emitBytecodeExceptionCheck(LogicNode condition, boolean passingOnTrue, BytecodeExceptionKind exceptionKind, ValueNode... arguments) {
if (passingOnTrue ? condition.isTautology() : condition.isContradiction()) {
return null;
}
- BytecodeExceptionNode exception = graph.add(new BytecodeExceptionNode(metaAccess, exceptionKind, arguments));
+ BytecodeExceptionNode exception = graph.add(new BytecodeExceptionNode(getMetaAccess(), exceptionKind, arguments));
AbstractBeginNode passingSuccessor = graph.add(new BeginNode());
FixedNode trueSuccessor = passingOnTrue ? passingSuccessor : exception;
FixedNode falseSuccessor = passingOnTrue ? exception : passingSuccessor;
append(new IfNode(condition, trueSuccessor, falseSuccessor, passingOnTrue ? LUDICROUSLY_FAST_PATH_PROBABILITY : LUDICROUSLY_SLOW_PATH_PROBABILITY));
@@ -1414,11 +1413,11 @@
return passingSuccessor;
}
protected ValueNode genArrayLength(ValueNode x) {
- return ArrayLengthNode.create(x, constantReflection);
+ return ArrayLengthNode.create(x, getConstantReflection());
}
protected void genStoreField(ValueNode receiver, ResolvedJavaField field, ValueNode value) {
StoreFieldNode storeFieldNode = new StoreFieldNode(receiver, field, maskSubWordValue(value, field.getJavaKind()));
append(storeFieldNode);
@@ -1565,11 +1564,11 @@
// Will perform runtime type checks and static initialization
FrameState stateBefore = createCurrentFrameState();
appendixNode = invokeDynamicPlugin.genAppendixNode(this, cpi, opcode, appendix, stateBefore);
} else {
- appendixNode = ConstantNode.forConstant(appendix, metaAccess, graph);
+ appendixNode = ConstantNode.forConstant(appendix, getMetaAccess(), graph);
}
frameState.push(JavaKind.Object, appendixNode);
} else if (GeneratePIC.getValue(options)) {
@@ -1627,14 +1626,11 @@
protected final Bytecode code;
protected final BytecodeProvider bytecodeProvider;
protected final ProfilingInfo profilingInfo;
protected final OptimisticOptimizations optimisticOpts;
protected final ConstantPool constantPool;
- protected final MetaAccessProvider metaAccess;
- private final ConstantReflectionProvider constantReflection;
- private final ConstantFieldProvider constantFieldProvider;
- private final StampProvider stampProvider;
+ protected final CoreProviders providers;
protected final IntrinsicContext intrinsicContext;
@Override
public InvokeKind getInvokeKind() {
return currentInvoke == null ? null : currentInvoke.kind;
@@ -1952,11 +1948,11 @@
this.nodeCount = graph.getNodeCount();
this.mark = graph.getMark();
}
String error(String format, Object... a) {
- return String.format(format, a) + String.format("%n\tplugin at %s", plugin.getApplySourceLocation(metaAccess));
+ return String.format(format, a) + String.format("%n\tplugin at %s", plugin.getApplySourceLocation(getMetaAccess()));
}
boolean check(boolean pluginResult) {
if (pluginResult) {
/*
@@ -2037,15 +2033,16 @@
if (resolvedMethod == null || resolvedMethod.equals(targetMethod)) {
assert resolvedMethod == null || targetMethod.getDeclaringClass().isAssignableFrom(resolvedMethod.getDeclaringClass());
Mark mark = graph.getMark();
FixedWithNextNode currentLastInstr = lastInstr;
ValueNode nonNullReceiver = pluginReceiver.get();
- Stamp methodStamp = stampProvider.createMethodStamp();
- LoadHubNode hub = graph.unique(new LoadHubNode(stampProvider, nonNullReceiver));
+ Stamp methodStamp = getStampProvider().createMethodStamp();
+ LoadHubNode hub = graph.unique(new LoadHubNode(getStampProvider(), nonNullReceiver));
LoadMethodNode actual = append(new LoadMethodNode(methodStamp, targetMethod, receiverType, method.getDeclaringClass(), hub));
ConstantNode expected = graph.unique(ConstantNode.forConstant(methodStamp, targetMethod.getEncoding(), getMetaAccess()));
- LogicNode compare = graph.addOrUniqueWithInputs(CompareNode.createCompareNode(constantReflection, metaAccess, options, null, CanonicalCondition.EQ, actual, expected, NodeView.DEFAULT));
+ LogicNode compare = graph.addOrUniqueWithInputs(
+ CompareNode.createCompareNode(getConstantReflection(), getMetaAccess(), options, null, CanonicalCondition.EQ, actual, expected, NodeView.DEFAULT));
JavaTypeProfile profile = null;
if (profilingInfo != null && this.optimisticOpts.useTypeCheckHints(getOptions())) {
profile = profilingInfo.getTypeProfile(bci());
if (profile != null) {
@@ -2319,11 +2316,11 @@
if (scope != null) {
graph.getInliningLog().addDecision(scope.getInvoke(), false, "GraphBuilderPhase", null, null, "native method");
}
return false;
}
- if (canInlinePartialIntrinsicExit() && InlinePartialIntrinsicExitDuringParsing.getValue(options) && !IS_BUILDING_NATIVE_IMAGE) {
+ if (canInlinePartialIntrinsicExit()) {
// Otherwise inline the original method. Any frame state created
// during the inlining will exclude frame(s) in the
// intrinsic method (see FrameStateBuilder.create(int bci)).
notifyBeforeInline(inlinedMethod);
printInlining(targetMethod, inlinedMethod, true, "partial intrinsic exit (bytecode parsing)");
@@ -2382,11 +2379,11 @@
/**
* Determines if a partial intrinsic exit (i.e., a call to the original method within an
* intrinsic) can be inlined.
*/
protected boolean canInlinePartialIntrinsicExit() {
- return true;
+ return InlinePartialIntrinsicExitDuringParsing.getValue(options) && !IS_BUILDING_NATIVE_IMAGE && method.getAnnotation(Snippet.class) == null;
}
private void printInlining(ResolvedJavaMethod targetMethod, ResolvedJavaMethod inlinedMethod, boolean success, String msg) {
if (success) {
if (TraceInlineDuringParsing.getValue(options) || TraceParserPlugins.getValue(options)) {
@@ -2444,11 +2441,11 @@
FixedWithNextNode calleeBeforeUnwindNode = null;
ValueNode calleeUnwindValue = null;
try (IntrinsicScope s = calleeIntrinsicContext != null && !parsingIntrinsic() ? new IntrinsicScope(this, targetMethod.getSignature().toParameterKinds(!targetMethod.isStatic()), args) : null) {
BytecodeParser parser = graphBuilderInstance.createBytecodeParser(graph, this, targetMethod, INVOCATION_ENTRY_BCI, calleeIntrinsicContext);
- FrameStateBuilder startFrameState = new FrameStateBuilder(parser, parser.code, graph);
+ FrameStateBuilder startFrameState = new FrameStateBuilder(parser, parser.code, graph, graphBuilderConfig.retainLocalVariables());
if (!targetMethod.isStatic()) {
args[0] = nullCheckedValue(args[0]);
}
startFrameState.initializeFromArgumentsArray(args);
parser.build(this.lastInstr, startFrameState);
@@ -2677,11 +2674,11 @@
BciBlock successor = currentBlock.getRetSuccessor();
ValueNode local = frameState.loadLocal(localIndex, JavaKind.Object);
JsrScope scope = currentBlock.getJsrScope();
int retAddress = scope.nextReturnAddress();
ConstantNode returnBciNode = getJsrConstant(retAddress);
- LogicNode guard = IntegerEqualsNode.create(constantReflection, metaAccess, options, null, local, returnBciNode, NodeView.DEFAULT);
+ LogicNode guard = IntegerEqualsNode.create(getConstantReflection(), getMetaAccess(), options, null, local, returnBciNode, NodeView.DEFAULT);
guard = graph.addOrUniqueWithInputs(guard);
append(new FixedGuardNode(guard, JavaSubroutineMismatch, InvalidateReprofile));
if (!successor.getJsrScope().equals(scope.pop())) {
throw new JsrNotSupportedBailout("unstructured control flow (ret leaves more than one scope)");
}
@@ -2729,11 +2726,11 @@
return probability;
}
protected ConstantNode appendConstant(JavaConstant constant) {
assert constant != null;
- return ConstantNode.forConstant(constant, metaAccess, graph);
+ return ConstantNode.forConstant(constant, getMetaAccess(), graph);
}
@Override
public <T extends ValueNode> T append(T v) {
assert !graph.trackNodeSourcePosition() || graph.currentNodeSourcePosition() != null || currentBlock == blockMap.getUnwindBlock() || currentBlock instanceof ExceptionDispatchBlock;
@@ -3600,16 +3597,21 @@
return currentBC == Bytecodes.IRETURN;
}
@Override
public StampProvider getStampProvider() {
- return stampProvider;
+ return providers.getStampProvider();
}
@Override
public MetaAccessProvider getMetaAccess() {
- return metaAccess;
+ return providers.getMetaAccess();
+ }
+
+ @Override
+ public Replacements getReplacements() {
+ return providers.getReplacements();
}
@Override
public void push(JavaKind slotKind, ValueNode value) {
assert value.isAlive();
@@ -3621,16 +3623,16 @@
return frameState.pop(slotKind);
}
@Override
public ConstantReflectionProvider getConstantReflection() {
- return constantReflection;
+ return providers.getConstantReflection();
}
@Override
public ConstantFieldProvider getConstantFieldProvider() {
- return constantFieldProvider;
+ return providers.getConstantFieldProvider();
}
/**
* Gets the graph being processed by this builder.
*/
@@ -3751,11 +3753,11 @@
}
}
private JavaKind refineComponentType(ValueNode array, JavaKind kind) {
if (kind == JavaKind.Byte) {
- JavaType type = array.stamp(NodeView.DEFAULT).javaType(metaAccess);
+ JavaType type = array.stamp(NodeView.DEFAULT).javaType(getMetaAccess());
if (type.isArray()) {
JavaType componentType = type.getComponentType();
if (componentType != null) {
JavaKind refinedKind = componentType.getJavaKind();
assert refinedKind == JavaKind.Byte || refinedKind == JavaKind.Boolean;
@@ -4306,11 +4308,11 @@
throw new IllegalArgumentException("unknown array type code: " + code);
}
}
private void genNewPrimitiveArray(int typeCode) {
- ResolvedJavaType elementType = metaAccess.lookupJavaType(arrayTypeCodeToClass(typeCode));
+ ResolvedJavaType elementType = getMetaAccess().lookupJavaType(arrayTypeCodeToClass(typeCode));
ValueNode length = frameState.pop(JavaKind.Int);
for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) {
if (plugin.handleNewArray(this, elementType, length)) {
return;
@@ -4490,11 +4492,11 @@
return false;
}
@Override
public AbstractBeginNode genExplicitExceptionEdge(BytecodeExceptionKind exceptionKind) {
- BytecodeExceptionNode exceptionNode = graph.add(new BytecodeExceptionNode(metaAccess, exceptionKind));
+ BytecodeExceptionNode exceptionNode = graph.add(new BytecodeExceptionNode(getMetaAccess(), exceptionKind));
exceptionNode.setStateAfter(createFrameState(bci(), exceptionNode));
AbstractBeginNode exceptionDispatch = handleException(exceptionNode, bci(), false);
exceptionNode.setNext(exceptionDispatch);
return BeginNode.begin(exceptionNode);
}
@@ -5111,5 +5113,6 @@
static String nSpaces(int n) {
return n == 0 ? "" : format("%" + n + "s", "");
}
}
+
< prev index next >