use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class TruffleGraphBuilderPlugins method registerOptimizedAssumptionPlugins.
public static void registerOptimizedAssumptionPlugins(InvocationPlugins plugins, MetaAccessProvider metaAccess, KnownTruffleTypes types) {
ResolvedJavaType optimizedAssumptionType = getRuntime().resolveType(metaAccess, "org.graalvm.compiler.truffle.runtime.OptimizedAssumption");
Registration r = new Registration(plugins, new ResolvedJavaSymbol(optimizedAssumptionType), null);
InvocationPlugin plugin = new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
if (receiver.isConstant() && b.getAssumptions() != null) {
JavaConstant assumption = (JavaConstant) receiver.get().asConstant();
if (b.getConstantReflection().readFieldValue(types.fieldOptimizedAssumptionIsValid, assumption).asBoolean()) {
if (targetMethod.getName().equals("isValid")) {
b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(true));
} else {
assert targetMethod.getName().equals("check") : targetMethod;
}
b.getAssumptions().record(new TruffleAssumption(assumption));
} else {
if (targetMethod.getName().equals("isValid")) {
b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(false));
} else {
assert targetMethod.getName().equals("check") : targetMethod;
b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.None));
}
}
return true;
} else {
return false;
}
}
};
r.register1("isValid", Receiver.class, plugin);
r.register1("check", Receiver.class, plugin);
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class HotSpotTruffleGraphBuilderPlugins method registerCompilationFinalReferencePlugins.
static void registerCompilationFinalReferencePlugins(InvocationPlugins plugins, boolean canDelayIntrinsification, HotSpotKnownTruffleTypes types) {
InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, Reference.class);
r.register1("get", InvocationPlugin.Receiver.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
if (!canDelayIntrinsification && receiver.isConstant()) {
JavaConstant constant = (JavaConstant) receiver.get().asConstant();
if (constant.isNonNull()) {
if (types.classWeakReference.isInstance(constant) || types.classSoftReference.isInstance(constant)) {
JavaConstant referent = b.getConstantReflection().readFieldValue(types.referenceReferent, constant);
b.addPush(JavaKind.Object, ConstantNode.forConstant(referent, b.getMetaAccess()));
return true;
}
}
}
return false;
}
});
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class NativeImageCodeCache method addConstantsToHeap.
public void addConstantsToHeap(DebugContext debug) {
for (DataSection.Data data : dataSection) {
if (data instanceof SubstrateDataBuilder.ObjectData) {
JavaConstant constant = ((SubstrateDataBuilder.ObjectData) data).getConstant();
Object obj = SubstrateObjectConstant.asObject(constant);
if (!imageHeap.getMetaAccess().lookupJavaType(obj.getClass()).getWrapped().isInstantiated()) {
throw VMError.shouldNotReachHere("Non-instantiated type referenced by a compiled method: " + obj.getClass().getName());
}
imageHeap.addObject(debug, obj, false, false, constantReasons.get(constant));
}
}
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class NativeImageHeap method writeField.
private void writeField(RelocatableBuffer buffer, ObjectInfo fields, HostedField field, JavaConstant receiver, ObjectInfo info) {
int index = fields.getIntIndexInSection(field.getLocation());
JavaConstant value = field.readValue(receiver);
if (value.getJavaKind() == JavaKind.Object && SubstrateObjectConstant.asObject(value) instanceof RelocatedPointer) {
addNonDataRelocation(buffer, index, (RelocatedPointer) SubstrateObjectConstant.asObject(value));
} else {
write(buffer, index, value, info != null ? info : field);
}
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class HostedMemoryAccessProvider method readPrimitiveConstant.
@Override
public JavaConstant readPrimitiveConstant(JavaKind stackKind, Constant base, long displacement, int bits) {
JavaConstant result = doRead(stackKind, (JavaConstant) base, displacement);
if (result == null) {
return null;
}
/* Wrap the result in the expected stack kind. */
JavaConstant wrappedResult;
switch(stackKind) {
case Int:
wrappedResult = JavaConstant.forInt(result.asInt());
break;
case Long:
case Float:
case Double:
assert result.getJavaKind() == stackKind;
wrappedResult = result;
break;
default:
throw VMError.shouldNotReachHere();
}
return wrappedResult;
}
Aggregations