use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class Deoptimizer method verifyConstant.
private boolean verifyConstant(FrameInfoQueryResult targetFrame, ValueInfo targetValue, JavaConstant source) {
boolean equal;
JavaConstant target = readValue(targetValue, targetFrame);
if (source.getJavaKind() == JavaKind.Object && target.getJavaKind() == JavaKind.Object) {
// Differences in compression are irrelevant, compare only object identities
equal = (SubstrateObjectConstant.asObject(target) == SubstrateObjectConstant.asObject(source));
} else {
equal = source.equals(target);
}
if (!equal) {
Log.log().string("source: ").string(source.toString()).string(" target: ").string(target.toString()).newline();
}
return equal;
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class Deoptimizer method constructTargetFrame.
/**
* Constructs the frame entries for the deopimization target method.
*
* @param targetInfo The bytecode frame (+ some other info) of the target.
* @param sourceFrame The bytecode frame of the source.
*/
private VirtualFrame constructTargetFrame(CodeInfoQueryResult targetInfo, FrameInfoQueryResult sourceFrame) {
FrameInfoQueryResult targetFrame = targetInfo.getFrameInfo();
long targetFrameSize = targetInfo.getTotalFrameSize() - FrameAccess.returnAddressSize();
VirtualFrame result = new VirtualFrame(targetFrame);
/* The first word of the new content is the return address into the target method. */
result.returnAddress = new DeoptimizedFrame.ReturnAddress(targetContentSize, targetInfo.getIP().rawValue());
targetContentSize += FrameAccess.returnAddressSize();
/* The source and target bytecode frame must match (as they stem from the same BCI). */
assert sourceFrame.getNumLocals() == targetFrame.getNumLocals();
assert sourceFrame.getNumStack() == targetFrame.getNumStack();
assert sourceFrame.getNumLocks() == targetFrame.getNumLocks();
assert targetFrame.getVirtualObjects().length == 0;
assert sourceFrame.getValueInfos().length >= targetFrame.getValueInfos().length;
int numValues = targetFrame.getValueInfos().length;
/*
* Create stack entries for all values of the source frame.
*/
int newEndOfParams = endOfParams;
for (int idx = 0; idx < numValues; idx++) {
ValueInfo targetValue = targetFrame.getValueInfos()[idx];
if (targetValue.getKind() == JavaKind.Illegal) {
/*
* The target value is optimized out, e.g. at a position after the lifetime of a
* local variable. Actually we don't care what's the source value in this case, but
* most likely it's also "illegal".
*/
} else {
JavaConstant con = readValue(sourceFrame.getValueInfos()[idx], sourceFrame);
assert con.getJavaKind() != JavaKind.Illegal;
if (con.getJavaKind().isObject() && SubstrateObjectConstant.isCompressed(con) != targetValue.isCompressedReference()) {
// rewrap in constant with the appropriate compression for the target value
Object obj = SubstrateObjectConstant.asObject(con);
con = SubstrateObjectConstant.forObject(obj, targetValue.isCompressedReference());
}
relockVirtualObject(sourceFrame, idx, con);
switch(targetValue.getType()) {
case StackSlot:
/*
* The target value is on the stack
*/
DeoptimizationCounters.counters().stackValueCount.inc();
int targetOffset = TypeConversion.asS4(targetValue.getData());
assert targetOffset != targetFrameSize : "stack slot would overwrite return address";
int totalOffset = targetContentSize + targetOffset;
assert totalOffset >= endOfParams : "stack location overwrites param area";
if (targetOffset < targetFrameSize) {
/*
* This is the most common case: a regular slot in the stack frame,
* which e.g. holds a variable.
*/
assert totalOffset >= targetContentSize;
result.values[idx] = DeoptimizedFrame.ConstantEntry.factory(totalOffset, con);
} else if (sourceFrame.getCaller() != null) {
/*
* Handle stack parameters for inlined calls: write the value to the
* outgoing parameter area of the caller frame.
*/
assert totalOffset >= targetContentSize;
result.values[idx] = DeoptimizedFrame.ConstantEntry.factory(totalOffset, con);
int endOffset = totalOffset + ConfigurationValues.getObjectLayout().sizeInBytes(con.getJavaKind(), targetValue.isCompressedReference());
if (endOffset > newEndOfParams) {
newEndOfParams = endOffset;
}
}
break;
case DefaultConstant:
case Constant:
/*
* The target value was constant propagated. Check that source and target
* performed the same constant propagation
*/
assert verifyConstant(targetFrame, targetValue, con);
DeoptimizationCounters.counters().constantValueCount.inc();
break;
default:
/*
* There must not be any other target value types because deoptimization
* target methods are only optimized in a limited way. Especially there must
* not be Register values because registers cannot be alive across method
* calls; and there must not be virtual objects because no escape analysis
* is performed.
*/
throw VMError.shouldNotReachHere("unknown deopt target value " + targetValue);
}
}
}
targetContentSize += targetFrameSize;
endOfParams = newEndOfParams;
return result;
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class StampMemoryAccessTest method testReadObject.
@Ignore("not all JVMCI versions are safe yet")
@Test
public void testReadObject() {
MemoryAccessProvider memory = getConstantReflection().getMemoryAccessProvider();
JavaConstant base = getSnippetReflection().forObject("");
Stamp stamp = StampFactory.forKind(JavaKind.Object);
assertTrue(stamp.readConstant(memory, base, 128) == null);
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class StampMemoryAccessTest method testReadPrimitive.
@Ignore("not all JVMCI versions are safe yet")
@Test
public void testReadPrimitive() {
MemoryAccessProvider memory = getConstantReflection().getMemoryAccessProvider();
JavaConstant base = getSnippetReflection().forObject("");
Stamp stamp = StampFactory.forKind(JavaKind.Long);
assertTrue(stamp.readConstant(memory, base, 128) == null);
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class LongNodeChainTest method longAddChain.
private void longAddChain(boolean reverse) {
HighTierContext context = getDefaultHighTierContext();
OptionValues options = getInitialOptions();
StructuredGraph graph = new StructuredGraph.Builder(options, DebugContext.create(options, DebugHandlersFactory.LOADER)).build();
ValueNode constant = graph.unique(ConstantNode.forPrimitive(JavaConstant.INT_1));
ValueNode value = null;
if (reverse) {
// Make sure the constant's stamp is not used to infer the add node's stamp.
OpaqueNode opaque = graph.unique(new OpaqueNode(constant));
constant = opaque;
AddNode addNode = graph.unique(new AddNode(constant, constant));
value = addNode;
for (int i = 1; i < N; ++i) {
AddNode newAddNode = graph.addWithoutUnique(new AddNode(constant, constant));
addNode.setY(newAddNode);
addNode = newAddNode;
}
opaque.replaceAndDelete(opaque.getValue());
} else {
value = constant;
for (int i = 0; i < N; ++i) {
value = graph.unique(new AddNode(constant, value));
}
}
ReturnNode returnNode = graph.add(new ReturnNode(value));
graph.start().setNext(returnNode);
for (SchedulingStrategy s : Strategies) {
new SchedulePhase(s).apply(graph);
}
new CanonicalizerPhase().apply(graph, context);
JavaConstant asConstant = (JavaConstant) returnNode.result().asConstant();
Assert.assertEquals(N + 1, asConstant.asInt());
}
Aggregations