use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class HotSpotGraphBuilderPlugins method getMetaspaceConstantPool.
/**
* Emits a node to get the metaspace {@code ConstantPool} pointer given the value of the
* {@code constantPoolOop} field in a ConstantPool value.
*
* @param constantPoolOop value of the {@code constantPoolOop} field in a ConstantPool value
* @return a node representing the metaspace {@code ConstantPool} pointer associated with
* {@code constantPoolOop}
*/
private static ValueNode getMetaspaceConstantPool(GraphBuilderContext b, ValueNode constantPoolOop, WordTypes wordTypes, GraalHotSpotVMConfig config) {
// ConstantPool.constantPoolOop is in fact the holder class.
ValueNode value = b.nullCheckedValue(constantPoolOop, DeoptimizationAction.None);
ValueNode klass = b.add(ClassGetHubNode.create(value, b.getMetaAccess(), b.getConstantReflection(), false));
boolean notCompressible = false;
AddressNode constantsAddress = b.add(new OffsetAddressNode(klass, b.add(ConstantNode.forLong(config.instanceKlassConstantsOffset))));
return WordOperationPlugin.readOp(b, wordTypes.getWordKind(), constantsAddress, INSTANCE_KLASS_CONSTANTS, BarrierType.NONE, notCompressible);
}
use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class HotSpotGraphBuilderPlugins method registerClassPlugins.
private static void registerClassPlugins(Plugins plugins, GraalHotSpotVMConfig config, BytecodeProvider bytecodeProvider) {
Registration r = new Registration(plugins.getInvocationPlugins(), Class.class, bytecodeProvider);
r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "getModifiers", Receiver.class);
r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "isInterface", Receiver.class);
r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "isArray", Receiver.class);
r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "isPrimitive", Receiver.class);
r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "getSuperclass", Receiver.class);
if (config.getFieldOffset("ArrayKlass::_component_mirror", Integer.class, "oop", Integer.MAX_VALUE) != Integer.MAX_VALUE) {
r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "getComponentType", Receiver.class);
}
r.register2("cast", Receiver.class, Object.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
ValueNode javaClass = receiver.get();
LogicNode condition = b.append(InstanceOfDynamicNode.create(b.getAssumptions(), b.getConstantReflection(), javaClass, object, true));
if (condition.isTautology()) {
b.addPush(JavaKind.Object, object);
} else {
FixedGuardNode fixedGuard = b.add(new FixedGuardNode(condition, DeoptimizationReason.ClassCastException, DeoptimizationAction.InvalidateReprofile, false));
b.addPush(JavaKind.Object, DynamicPiNode.create(b.getAssumptions(), b.getConstantReflection(), object, fixedGuard, javaClass));
}
return true;
}
@Override
public boolean inlineOnly() {
return true;
}
});
}
use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class HotSpotGraphBuilderPlugins method registerThreadPlugins.
private static void registerThreadPlugins(InvocationPlugins plugins, MetaAccessProvider metaAccess, WordTypes wordTypes, GraalHotSpotVMConfig config, BytecodeProvider bytecodeProvider) {
Registration r = new Registration(plugins, Thread.class, bytecodeProvider);
r.register0("currentThread", new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
CurrentJavaThreadNode thread = b.add(new CurrentJavaThreadNode(wordTypes.getWordKind()));
ValueNode offset = b.add(ConstantNode.forLong(config.threadObjectOffset));
AddressNode address = b.add(new OffsetAddressNode(thread, offset));
// JavaThread::_threadObj is never compressed
ObjectStamp stamp = StampFactory.objectNonNull(TypeReference.create(b.getAssumptions(), metaAccess.lookupJavaType(Thread.class)));
b.addPush(JavaKind.Object, new ReadNode(address, JAVA_THREAD_THREAD_OBJECT_LOCATION, stamp, BarrierType.NONE));
return true;
}
});
r.registerMethodSubstitution(ThreadSubstitutions.class, "isInterrupted", Receiver.class, boolean.class);
}
use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class HotSpotDebugInfoBuilder method computeLockValue.
@Override
protected JavaValue computeLockValue(FrameState state, int lockIndex) {
int lockDepth = lockIndex;
if (state.outerFrameState() != null) {
lockDepth += state.outerFrameState().nestedLockDepth();
}
VirtualStackSlot slot = lockStack.makeLockSlot(lockDepth);
ValueNode lock = state.lockAt(lockIndex);
JavaValue object = toJavaValue(lock);
boolean eliminated = object instanceof VirtualObject || state.monitorIdAt(lockIndex).isEliminated();
assert state.monitorIdAt(lockIndex).getLockDepth() == lockDepth;
return new StackLockValue(object, slot, eliminated);
}
use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class SnippetTemplate method instantiate.
/**
* Replaces a given fixed node with this specialized snippet.
*
* @param metaAccess
* @param replacee the node that will be replaced
* @param replacer object that replaces the usages of {@code replacee}
* @param args the arguments to be bound to the flattened positional parameters of the snippet
* @param killReplacee is true, the replacee node is deleted
* @return the map of duplicated nodes (original -> duplicate)
*/
@SuppressWarnings("try")
public UnmodifiableEconomicMap<Node, Node> instantiate(MetaAccessProvider metaAccess, FixedNode replacee, UsageReplacer replacer, Arguments args, boolean killReplacee) {
DebugContext debug = replacee.getDebug();
assert assertSnippetKills(replacee);
try (DebugCloseable a = args.info.instantiationTimer.start(debug)) {
args.info.instantiationCounter.increment(debug);
// Inline the snippet nodes, replacing parameters with the given args in the process
StartNode entryPointNode = snippet.start();
FixedNode firstCFGNode = entryPointNode.next();
StructuredGraph replaceeGraph = replacee.graph();
EconomicMap<Node, Node> replacements = bind(replaceeGraph, metaAccess, args);
replacements.put(entryPointNode, AbstractBeginNode.prevBegin(replacee));
UnmodifiableEconomicMap<Node, Node> duplicates = inlineSnippet(replacee, debug, replaceeGraph, replacements);
// Re-wire the control flow graph around the replacee
FixedNode firstCFGNodeDuplicate = (FixedNode) duplicates.get(firstCFGNode);
replacee.replaceAtPredecessor(firstCFGNodeDuplicate);
rewireFrameStates(replacee, duplicates);
if (replacee instanceof DeoptimizingNode) {
DeoptimizingNode replaceeDeopt = (DeoptimizingNode) replacee;
FrameState stateBefore = null;
FrameState stateDuring = null;
FrameState stateAfter = null;
if (replaceeDeopt.canDeoptimize()) {
if (replaceeDeopt instanceof DeoptimizingNode.DeoptBefore) {
stateBefore = ((DeoptimizingNode.DeoptBefore) replaceeDeopt).stateBefore();
}
if (replaceeDeopt instanceof DeoptimizingNode.DeoptDuring) {
stateDuring = ((DeoptimizingNode.DeoptDuring) replaceeDeopt).stateDuring();
}
if (replaceeDeopt instanceof DeoptimizingNode.DeoptAfter) {
stateAfter = ((DeoptimizingNode.DeoptAfter) replaceeDeopt).stateAfter();
}
}
for (DeoptimizingNode deoptNode : deoptNodes) {
DeoptimizingNode deoptDup = (DeoptimizingNode) duplicates.get(deoptNode.asNode());
if (deoptDup.canDeoptimize()) {
if (deoptDup instanceof DeoptimizingNode.DeoptBefore) {
((DeoptimizingNode.DeoptBefore) deoptDup).setStateBefore(stateBefore);
}
if (deoptDup instanceof DeoptimizingNode.DeoptDuring) {
DeoptimizingNode.DeoptDuring deoptDupDuring = (DeoptimizingNode.DeoptDuring) deoptDup;
if (stateDuring != null) {
deoptDupDuring.setStateDuring(stateDuring);
} else if (stateAfter != null) {
deoptDupDuring.computeStateDuring(stateAfter);
} else if (stateBefore != null) {
assert !deoptDupDuring.hasSideEffect() : "can't use stateBefore as stateDuring for state split " + deoptDupDuring;
deoptDupDuring.setStateDuring(stateBefore);
}
}
if (deoptDup instanceof DeoptimizingNode.DeoptAfter) {
DeoptimizingNode.DeoptAfter deoptDupAfter = (DeoptimizingNode.DeoptAfter) deoptDup;
if (stateAfter != null) {
deoptDupAfter.setStateAfter(stateAfter);
} else {
assert !deoptDupAfter.hasSideEffect() : "can't use stateBefore as stateAfter for state split " + deoptDupAfter;
deoptDupAfter.setStateAfter(stateBefore);
}
}
}
}
}
updateStamps(replacee, duplicates);
rewireMemoryGraph(replacee, duplicates);
// Replace all usages of the replacee with the value returned by the snippet
ValueNode returnValue = null;
if (returnNode != null && !(replacee instanceof ControlSinkNode)) {
ReturnNode returnDuplicate = (ReturnNode) duplicates.get(returnNode);
returnValue = returnDuplicate.result();
if (returnValue == null && replacee.usages().isNotEmpty() && replacee instanceof MemoryCheckpoint) {
replacer.replace(replacee, null);
} else {
assert returnValue != null || replacee.hasNoUsages();
replacer.replace(replacee, returnValue);
}
if (returnDuplicate.isAlive()) {
FixedNode next = null;
if (replacee instanceof FixedWithNextNode) {
FixedWithNextNode fwn = (FixedWithNextNode) replacee;
next = fwn.next();
fwn.setNext(null);
}
returnDuplicate.replaceAndDelete(next);
}
}
if (killReplacee) {
// Remove the replacee from its graph
GraphUtil.killCFG(replacee);
}
debug.dump(DebugContext.DETAILED_LEVEL, replaceeGraph, "After lowering %s with %s", replacee, this);
return duplicates;
}
}
Aggregations