use of org.graalvm.compiler.nodes.extended.LoadHubNode in project graal by oracle.
the class DefaultHotSpotLoweringProvider method lowerGetClassNode.
private static void lowerGetClassNode(GetClassNode getClass, LoweringTool tool, StructuredGraph graph) {
StampProvider stampProvider = tool.getStampProvider();
LoadHubNode hub = graph.unique(new LoadHubNode(stampProvider, getClass.getObject()));
HubGetClassNode hubGetClass = graph.unique(new HubGetClassNode(tool.getMetaAccess(), hub));
getClass.replaceAtUsagesAndDelete(hubGetClass);
hub.lower(tool);
hubGetClass.lower(tool);
}
use of org.graalvm.compiler.nodes.extended.LoadHubNode in project graal by oracle.
the class KlassLayoutHelperNode method inferStamp.
@Override
public boolean inferStamp() {
if (klass instanceof LoadHubNode) {
LoadHubNode hub = (LoadHubNode) klass;
Stamp hubStamp = hub.getValue().stamp(NodeView.DEFAULT);
if (hubStamp instanceof ObjectStamp) {
ObjectStamp objectStamp = (ObjectStamp) hubStamp;
ResolvedJavaType type = objectStamp.type();
if (type != null && !type.isJavaLangObject()) {
if (!type.isArray() && !type.isInterface()) {
/*
* Definitely some form of instance type.
*/
return updateStamp(StampFactory.forInteger(JavaKind.Int, config.klassLayoutHelperNeutralValue, Integer.MAX_VALUE));
}
if (type.isArray()) {
return updateStamp(StampFactory.forInteger(JavaKind.Int, Integer.MIN_VALUE, config.klassLayoutHelperNeutralValue - 1));
}
}
}
}
return false;
}
use of org.graalvm.compiler.nodes.extended.LoadHubNode in project graal by oracle.
the class KlassLayoutHelperNode method canonical.
private static ValueNode canonical(KlassLayoutHelperNode klassLayoutHelperNode, GraalHotSpotVMConfig config, ValueNode klass, Stamp stamp, ConstantReflectionProvider constantReflection, MetaAccessProvider metaAccess) {
KlassLayoutHelperNode self = klassLayoutHelperNode;
if (klass.isConstant()) {
if (!klass.asConstant().isDefaultForKind()) {
Constant constant = stamp.readConstant(constantReflection.getMemoryAccessProvider(), klass.asConstant(), config.klassLayoutHelperOffset);
return ConstantNode.forConstant(stamp, constant, metaAccess);
}
}
if (klass instanceof LoadHubNode) {
LoadHubNode hub = (LoadHubNode) klass;
Stamp hubStamp = hub.getValue().stamp(NodeView.DEFAULT);
if (hubStamp instanceof ObjectStamp) {
ObjectStamp ostamp = (ObjectStamp) hubStamp;
HotSpotResolvedObjectType type = (HotSpotResolvedObjectType) ostamp.type();
if (type != null && type.isArray() && !type.getComponentType().isPrimitive()) {
// The layout for all object arrays is the same.
Constant constant = stamp.readConstant(constantReflection.getMemoryAccessProvider(), type.klass(), config.klassLayoutHelperOffset);
return ConstantNode.forConstant(stamp, constant, metaAccess);
}
}
}
if (self == null) {
self = new KlassLayoutHelperNode(config, klass);
}
return self;
}
use of org.graalvm.compiler.nodes.extended.LoadHubNode in project graal by oracle.
the class TypeSwitchNode method simplify.
@Override
public void simplify(SimplifierTool tool) {
NodeView view = NodeView.from(tool);
if (value() instanceof ConstantNode) {
Constant constant = value().asConstant();
int survivingEdge = keySuccessorIndex(keyCount());
for (int i = 0; i < keyCount(); i++) {
Constant typeHub = keyAt(i);
Boolean equal = tool.getConstantReflection().constantEquals(constant, typeHub);
if (equal == null) {
/* We don't know if this key is a match or not, so we cannot simplify. */
return;
} else if (equal.booleanValue()) {
survivingEdge = keySuccessorIndex(i);
}
}
killOtherSuccessors(tool, survivingEdge);
}
if (value() instanceof LoadHubNode && ((LoadHubNode) value()).getValue().stamp(view) instanceof ObjectStamp) {
ObjectStamp objectStamp = (ObjectStamp) ((LoadHubNode) value()).getValue().stamp(view);
if (objectStamp.type() != null) {
int validKeys = 0;
for (int i = 0; i < keyCount(); i++) {
if (objectStamp.type().isAssignableFrom(keys[i])) {
validKeys++;
}
}
if (validKeys == 0) {
tool.addToWorkList(defaultSuccessor());
graph().removeSplitPropagate(this, defaultSuccessor());
} else if (validKeys != keys.length) {
ArrayList<AbstractBeginNode> newSuccessors = new ArrayList<>(blockSuccessorCount());
ResolvedJavaType[] newKeys = new ResolvedJavaType[validKeys];
int[] newKeySuccessors = new int[validKeys + 1];
double[] newKeyProbabilities = new double[validKeys + 1];
double totalProbability = 0;
int current = 0;
for (int i = 0; i < keyCount() + 1; i++) {
if (i == keyCount() || objectStamp.type().isAssignableFrom(keys[i])) {
int index = newSuccessors.indexOf(keySuccessor(i));
if (index == -1) {
index = newSuccessors.size();
newSuccessors.add(keySuccessor(i));
}
newKeySuccessors[current] = index;
if (i < keyCount()) {
newKeys[current] = keys[i];
}
newKeyProbabilities[current] = keyProbability(i);
totalProbability += keyProbability(i);
current++;
}
}
if (totalProbability > 0) {
for (int i = 0; i < current; i++) {
newKeyProbabilities[i] /= totalProbability;
}
} else {
for (int i = 0; i < current; i++) {
newKeyProbabilities[i] = 1.0 / current;
}
}
for (int i = 0; i < blockSuccessorCount(); i++) {
AbstractBeginNode successor = blockSuccessor(i);
if (!newSuccessors.contains(successor)) {
tool.deleteBranch(successor);
}
setBlockSuccessor(i, null);
}
AbstractBeginNode[] successorsArray = newSuccessors.toArray(new AbstractBeginNode[newSuccessors.size()]);
TypeSwitchNode newSwitch = graph().add(new TypeSwitchNode(value(), successorsArray, newKeys, newKeyProbabilities, newKeySuccessors, tool.getConstantReflection()));
((FixedWithNextNode) predecessor()).setNext(newSwitch);
GraphUtil.killWithUnusedFloatingInputs(this);
}
}
}
}
use of org.graalvm.compiler.nodes.extended.LoadHubNode in project graal by oracle.
the class TypeGuardInlineInfo method createGuard.
@SuppressWarnings("try")
private void createGuard(StructuredGraph graph, Providers providers) {
try (DebugCloseable context = invoke.asNode().withNodeSourcePosition()) {
ValueNode nonNullReceiver = InliningUtil.nonNullReceiver(invoke);
LoadHubNode receiverHub = graph.unique(new LoadHubNode(providers.getStampProvider(), nonNullReceiver));
ConstantNode typeHub = ConstantNode.forConstant(receiverHub.stamp(NodeView.DEFAULT), providers.getConstantReflection().asObjectHub(type), providers.getMetaAccess(), graph);
LogicNode typeCheck = CompareNode.createCompareNode(graph, CanonicalCondition.EQ, receiverHub, typeHub, providers.getConstantReflection(), NodeView.DEFAULT);
FixedGuardNode guard = graph.add(new FixedGuardNode(typeCheck, DeoptimizationReason.TypeCheckedInliningViolated, DeoptimizationAction.InvalidateReprofile));
assert invoke.predecessor() != null;
ValueNode anchoredReceiver = InliningUtil.createAnchoredReceiver(graph, guard, type, nonNullReceiver, true);
invoke.callTarget().replaceFirstInput(nonNullReceiver, anchoredReceiver);
graph.addBeforeFixed(invoke.asNode(), guard);
}
}
Aggregations