use of com.oracle.svm.core.meta.SubstrateObjectConstant in project graal by oracle.
the class SubstrateMemoryAccessProviderImpl method readPrimitiveConstant.
@Override
public JavaConstant readPrimitiveConstant(JavaKind kind, Constant baseConstant, long displacement, int bits) {
SignedWord offset = WordFactory.signed(displacement);
long rawValue;
if (baseConstant instanceof SubstrateObjectConstant) {
Object baseObject = ((SubstrateObjectConstant) baseConstant).getObject();
assert baseObject != null : "SubstrateObjectConstant does not wrap null value";
switch(bits) {
case Byte.SIZE:
rawValue = BarrieredAccess.readByte(baseObject, offset);
break;
case Short.SIZE:
rawValue = BarrieredAccess.readShort(baseObject, offset);
break;
case Integer.SIZE:
rawValue = BarrieredAccess.readInt(baseObject, offset);
break;
case Long.SIZE:
rawValue = BarrieredAccess.readLong(baseObject, offset);
break;
default:
throw shouldNotReachHere();
}
} else if (baseConstant instanceof PrimitiveConstant) {
PrimitiveConstant prim = (PrimitiveConstant) baseConstant;
if (!prim.getJavaKind().isNumericInteger()) {
return null;
}
Pointer basePointer = WordFactory.unsigned(prim.asLong());
if (basePointer.equal(0)) {
return null;
}
switch(bits) {
case Byte.SIZE:
rawValue = basePointer.readByte(offset);
break;
case Short.SIZE:
rawValue = basePointer.readShort(offset);
break;
case Integer.SIZE:
rawValue = basePointer.readInt(offset);
break;
case Long.SIZE:
rawValue = basePointer.readLong(offset);
break;
default:
throw shouldNotReachHere();
}
} else {
return null;
}
return toConstant(kind, rawValue);
}
use of com.oracle.svm.core.meta.SubstrateObjectConstant in project graal by oracle.
the class ConstantFoldLoadFieldPlugin method tryConstantFold.
private static boolean tryConstantFold(GraphBuilderContext b, ResolvedJavaField field, JavaConstant receiver) {
ConstantNode result = ConstantFoldUtil.tryConstantFold(b.getConstantFieldProvider(), b.getConstantReflection(), b.getMetaAccess(), field, receiver, b.getOptions());
if (result != null) {
JavaConstant value = result.asJavaConstant();
if (b.getMetaAccess() instanceof AnalysisMetaAccess && value.getJavaKind() == JavaKind.Object && value.isNonNull()) {
SubstrateObjectConstant sValue = (SubstrateObjectConstant) value;
SubstrateObjectConstant sReceiver = (SubstrateObjectConstant) receiver;
Object root;
if (receiver == null) {
/* Found a root, map the constant value to the root field. */
root = field;
} else {
/* Map the constant value to the root field of it's receiver. */
root = sReceiver.getRoot();
assert root != null : receiver.toValueString() + " : " + field + " : " + b.getGraph();
}
sValue.setRoot(root);
}
result = b.getGraph().unique(result);
b.push(field.getJavaKind(), result);
return true;
}
return false;
}
use of com.oracle.svm.core.meta.SubstrateObjectConstant in project graal by oracle.
the class SubstrateMemoryAccessProviderImpl method readObjectConstant.
private static JavaConstant readObjectConstant(Constant baseConstant, long displacement, boolean requireCompressed) {
SignedWord offset = WordFactory.signed(displacement);
if (baseConstant instanceof SubstrateObjectConstant) {
// always compressed (if enabled)
assert !requireCompressed || ReferenceAccess.singleton().haveCompressedReferences();
Object baseObject = ((SubstrateObjectConstant) baseConstant).getObject();
assert baseObject != null : "SubstrateObjectConstant does not wrap null value";
Object rawValue = BarrieredAccess.readObject(baseObject, offset);
return SubstrateObjectConstant.forObject(rawValue, requireCompressed);
}
if (baseConstant instanceof PrimitiveConstant) {
// never compressed
assert !requireCompressed;
PrimitiveConstant prim = (PrimitiveConstant) baseConstant;
if (!prim.getJavaKind().isNumericInteger()) {
return null;
}
Word baseAddress = WordFactory.unsigned(prim.asLong());
if (baseAddress.equal(0)) {
return null;
}
Word address = baseAddress.add(offset);
Object rawValue = ReferenceAccess.singleton().readObjectAt(address, false);
return SubstrateObjectConstant.forObject(rawValue, false);
}
return null;
}
Aggregations