use of org.graalvm.compiler.core.common.type.AbstractObjectStamp in project graal by oracle.
the class LoadJavaMirrorWithKlassPhase method getClassConstantReplacement.
private ValueNode getClassConstantReplacement(StructuredGraph graph, PhaseContext context, JavaConstant constant) {
if (constant instanceof HotSpotObjectConstant) {
ConstantReflectionProvider constantReflection = context.getConstantReflection();
ResolvedJavaType type = constantReflection.asJavaType(constant);
if (type != null) {
MetaAccessProvider metaAccess = context.getMetaAccess();
Stamp stamp = StampFactory.objectNonNull(TypeReference.createExactTrusted(metaAccess.lookupJavaType(Class.class)));
if (type instanceof HotSpotResolvedObjectType) {
ConstantNode klass = ConstantNode.forConstant(KlassPointerStamp.klassNonNull(), ((HotSpotResolvedObjectType) type).klass(), metaAccess, graph);
ValueNode getClass = graph.unique(new HubGetClassNode(metaAccess, klass));
if (((HotSpotObjectConstant) constant).isCompressed()) {
return HotSpotCompressionNode.compress(getClass, oopEncoding);
} else {
return getClass;
}
} else {
/*
* Primitive classes are more difficult since they don't have a corresponding
* Klass* so get them from Class.TYPE for the java box type.
*/
HotSpotResolvedPrimitiveType primitive = (HotSpotResolvedPrimitiveType) type;
ResolvedJavaType boxingClass = metaAccess.lookupJavaType(primitive.getJavaKind().toBoxedJavaClass());
ConstantNode clazz = ConstantNode.forConstant(context.getConstantReflection().asJavaClass(boxingClass), metaAccess, graph);
HotSpotResolvedJavaField[] a = (HotSpotResolvedJavaField[]) boxingClass.getStaticFields();
HotSpotResolvedJavaField typeField = null;
for (HotSpotResolvedJavaField f : a) {
if (f.getName().equals("TYPE")) {
typeField = f;
break;
}
}
if (typeField == null) {
throw new GraalError("Can't find TYPE field in class");
}
if (oopEncoding != null) {
stamp = HotSpotNarrowOopStamp.compressed((AbstractObjectStamp) stamp, oopEncoding);
}
AddressNode address = graph.unique(new OffsetAddressNode(clazz, ConstantNode.forLong(typeField.offset(), graph)));
ValueNode read = graph.unique(new FloatingReadNode(address, FINAL_LOCATION, null, stamp));
if (oopEncoding == null || ((HotSpotObjectConstant) constant).isCompressed()) {
return read;
} else {
return HotSpotCompressionNode.uncompress(read, oopEncoding);
}
}
}
}
return null;
}
use of org.graalvm.compiler.core.common.type.AbstractObjectStamp in project graal by oracle.
the class StampTool method typeOrNull.
public static ResolvedJavaType typeOrNull(Stamp stamp, MetaAccessProvider metaAccess) {
if (stamp instanceof AbstractObjectStamp && stamp.hasValues()) {
AbstractObjectStamp abstractObjectStamp = (AbstractObjectStamp) stamp;
ResolvedJavaType type = abstractObjectStamp.type();
if (type == null) {
return metaAccess.lookupJavaType(Object.class);
} else {
return type;
}
}
return null;
}
use of org.graalvm.compiler.core.common.type.AbstractObjectStamp in project graal by oracle.
the class CompressionNode method generate.
@Override
public void generate(NodeLIRBuilderTool gen) {
boolean nonNull;
if (value.stamp(NodeView.DEFAULT) instanceof AbstractObjectStamp) {
nonNull = StampTool.isPointerNonNull(value.stamp(NodeView.DEFAULT));
} else {
// metaspace pointers are never null
nonNull = true;
}
LIRGeneratorTool tool = gen.getLIRGeneratorTool();
Value result;
switch(op) {
case Compress:
result = tool.emitCompress(gen.operand(value), encoding, nonNull);
break;
case Uncompress:
result = tool.emitUncompress(gen.operand(value), encoding, nonNull);
break;
default:
throw GraalError.shouldNotReachHere();
}
gen.setResult(this, result);
}
use of org.graalvm.compiler.core.common.type.AbstractObjectStamp in project graal by oracle.
the class ConstantNode method forPrimitive.
/**
* Returns a node for a primitive of a given type.
*/
public static ConstantNode forPrimitive(Stamp stamp, Constant constant) {
if (stamp instanceof IntegerStamp) {
PrimitiveConstant primitive = (PrimitiveConstant) constant;
assert primitive.getJavaKind().isNumericInteger() && stamp.getStackKind() == primitive.getJavaKind().getStackKind();
IntegerStamp istamp = (IntegerStamp) stamp;
return forIntegerBits(istamp.getBits(), primitive);
} else if (stamp instanceof FloatStamp) {
PrimitiveConstant primitive = (PrimitiveConstant) constant;
assert primitive.getJavaKind().isNumericFloat() && stamp.getStackKind() == primitive.getJavaKind();
return forConstant(primitive, null);
} else {
assert !(stamp instanceof AbstractObjectStamp);
return new ConstantNode(constant, stamp.constant(constant, null));
}
}
use of org.graalvm.compiler.core.common.type.AbstractObjectStamp in project graal by oracle.
the class StrengthenStampsPhase method strengthen.
private Stamp strengthen(Stamp s) {
if (!(s instanceof AbstractObjectStamp)) {
return null;
}
AbstractObjectStamp stamp = (AbstractObjectStamp) s;
HostedType originalType = toHosted(stamp.type());
if (originalType == null) {
return null;
}
HostedType strengthenType = originalType.getStrengthenStampType();
if (originalType.equals(strengthenType)) {
/* Nothing to strengthen. */
return null;
}
Stamp newStamp;
if (strengthenType == null) {
if (stamp.nonNull()) {
/* We must be in dead code. */
newStamp = StampFactory.empty(JavaKind.Object);
} else {
/* The type its subtypes are not instantiated, the only possible value is null. */
newStamp = StampFactory.alwaysNull();
}
} else {
if (stamp.isExactType()) {
/* We must be in dead code. */
newStamp = StampFactory.empty(JavaKind.Object);
} else {
TypeReference typeRef = TypeReference.createTrustedWithoutAssumptions(toTarget(strengthenType));
newStamp = StampFactory.object(typeRef, stamp.nonNull());
}
}
return newStamp;
}
Aggregations