use of com.oracle.svm.core.config.ObjectLayout in project graal by oracle.
the class Deoptimizer method materializeObject.
/**
* Materializes a virtual object.
*
* @param virtualObjectId the id of the virtual object to materialize
* @return the materialized object
*/
private Object materializeObject(int virtualObjectId, FrameInfoQueryResult sourceFrame) {
if (materializedObjects == null) {
materializedObjects = new Object[sourceFrame.getVirtualObjects().length];
}
assert materializedObjects.length == sourceFrame.getVirtualObjects().length;
Object obj = materializedObjects[virtualObjectId];
if (obj != null) {
return obj;
}
DeoptimizationCounters.counters().virtualObjectsCount.inc();
ValueInfo[] encodings = sourceFrame.getVirtualObjects()[virtualObjectId];
DynamicHub hub = KnownIntrinsics.convertUnknownValue(SubstrateObjectConstant.asObject(readValue(encodings[0], sourceFrame)), DynamicHub.class);
ObjectLayout objectLayout = ConfigurationValues.getObjectLayout();
int curIdx;
UnsignedWord curOffset;
if (LayoutEncoding.isArray(hub.getLayoutEncoding())) {
/* For arrays, the second encoded value is the array length. */
int length = readValue(encodings[1], sourceFrame).asInt();
obj = Array.newInstance(hub.getComponentHub().asClass(), length);
curOffset = LayoutEncoding.getArrayBaseOffset(hub.getLayoutEncoding());
curIdx = 2;
} else {
try {
obj = UnsafeAccess.UNSAFE.allocateInstance(hub.asClass());
} catch (InstantiationException ex) {
throw VMError.shouldNotReachHere(ex);
}
curOffset = WordFactory.unsigned(objectLayout.getFirstFieldOffset());
curIdx = 1;
}
materializedObjects[virtualObjectId] = obj;
if (testGCinDeoptimizer) {
Heap.getHeap().getGC().collect("from Deoptimizer.materializeObject because of testGCinDeoptimizer");
}
/* Objects must contain only compressed references when compression is enabled */
boolean useCompressedReferences = ReferenceAccess.singleton().haveCompressedReferences();
while (curIdx < encodings.length) {
ValueInfo value = encodings[curIdx];
JavaKind kind = value.getKind();
JavaConstant con = readValue(value, sourceFrame);
writeValueInMaterializedObj(obj, curOffset, con);
curOffset = curOffset.add(objectLayout.sizeInBytes(kind, useCompressedReferences));
curIdx++;
}
return obj;
}
Aggregations