use of com.oracle.svm.core.meta.MethodPointer in project graal by oracle.
the class CompileQueue method ensureCalleesCompiled.
protected void ensureCalleesCompiled(HostedMethod method, CompileReason reason, CompilationResult result) {
for (Infopoint infopoint : result.getInfopoints()) {
if (infopoint instanceof Call) {
Call call = (Call) infopoint;
HostedMethod callTarget = (HostedMethod) call.target;
if (call.direct) {
ensureCompiled(callTarget, new DirectCallReason(method, reason));
} else if (callTarget != null && callTarget.getImplementations() != null) {
for (HostedMethod impl : callTarget.getImplementations()) {
ensureCompiled(impl, new VirtualCallReason(method, callTarget, reason));
}
}
}
}
for (DataPatch dataPatch : result.getDataPatches()) {
Reference reference = dataPatch.reference;
if (reference instanceof ConstantReference) {
VMConstant constant = ((ConstantReference) reference).getConstant();
if (constant instanceof SubstrateMethodPointerConstant) {
MethodPointer pointer = ((SubstrateMethodPointerConstant) constant).pointer();
final ResolvedJavaMethod method1 = pointer.getMethod();
HostedMethod hMethod = (HostedMethod) method1;
ensureCompiled(hMethod, new MethodPointerConstantReason(method, hMethod, reason));
}
}
}
}
use of com.oracle.svm.core.meta.MethodPointer in project graal by oracle.
the class CompileQueue method replaceAnalysisObjects.
public static Object replaceAnalysisObjects(Object obj, Node node, IdentityHashMap<Object, Object> replacements, HostedUniverse hUniverse) {
if (obj == null) {
return obj;
}
Object existingReplacement = replacements.get(obj);
if (existingReplacement != null) {
return existingReplacement;
}
Object newReplacement;
if (obj instanceof Node) {
throw VMError.shouldNotReachHere("Must not replace a Graal graph nodes, only data objects referenced from a node");
} else if (obj instanceof AnalysisType) {
newReplacement = hUniverse.lookup((AnalysisType) obj);
} else if (obj instanceof AnalysisMethod) {
newReplacement = hUniverse.lookup((AnalysisMethod) obj);
} else if (obj instanceof AnalysisField) {
newReplacement = hUniverse.lookup((AnalysisField) obj);
} else if (obj.getClass() == ObjectStamp.class) {
ObjectStamp stamp = (ObjectStamp) obj;
if (stamp.type() == null) {
/* No actual type referenced, so we can keep the original object. */
newReplacement = obj;
} else {
/*
* ObjectStamp references a type indirectly, so we need to provide a new stamp with
* a modified type.
*/
newReplacement = new ObjectStamp((ResolvedJavaType) replaceAnalysisObjects(stamp.type(), node, replacements, hUniverse), stamp.isExactType(), stamp.nonNull(), stamp.alwaysNull(), stamp.isAlwaysArray());
}
} else if (obj.getClass() == SubstrateNarrowOopStamp.class) {
SubstrateNarrowOopStamp stamp = (SubstrateNarrowOopStamp) obj;
if (stamp.type() == null) {
newReplacement = obj;
} else {
newReplacement = new SubstrateNarrowOopStamp((ResolvedJavaType) replaceAnalysisObjects(stamp.type(), node, replacements, hUniverse), stamp.isExactType(), stamp.nonNull(), stamp.alwaysNull(), stamp.isAlwaysArray(), stamp.getEncoding());
}
} else if (obj.getClass() == PiNode.PlaceholderStamp.class) {
assert ((PiNode.PlaceholderStamp) obj).type() == null : "PlaceholderStamp never references a type";
newReplacement = obj;
} else if (obj instanceof AbstractObjectStamp) {
throw VMError.shouldNotReachHere("missing replacement of a subclass of AbstractObjectStamp: " + obj.getClass().getTypeName());
} else if (obj.getClass() == StampPair.class) {
StampPair pair = (StampPair) obj;
Stamp trustedStamp = (Stamp) replaceAnalysisObjects(pair.getTrustedStamp(), node, replacements, hUniverse);
Stamp uncheckedStamp = (Stamp) replaceAnalysisObjects(pair.getUncheckedStamp(), node, replacements, hUniverse);
if (trustedStamp != pair.getTrustedStamp() || uncheckedStamp != pair.getUncheckedStamp()) {
newReplacement = StampPair.create(trustedStamp, uncheckedStamp);
} else {
newReplacement = pair;
}
} else if (obj.getClass() == ResolvedJavaMethodBytecode.class) {
ResolvedJavaMethodBytecode bc = (ResolvedJavaMethodBytecode) obj;
newReplacement = new ResolvedJavaMethodBytecode(hUniverse.lookup(bc.getMethod()), bc.getOrigin());
} else if (obj instanceof Object[]) {
Object[] originalArray = (Object[]) obj;
Object[] copyArray = null;
for (int i = 0; i < originalArray.length; i++) {
Object original = originalArray[i];
Object replaced = replaceAnalysisObjects(original, node, replacements, hUniverse);
if (replaced != original) {
if (copyArray == null) {
copyArray = Arrays.copyOf(originalArray, originalArray.length);
}
copyArray[i] = replaced;
}
}
newReplacement = copyArray != null ? copyArray : originalArray;
} else if (obj.getClass() == NodeSourcePosition.class) {
NodeSourcePosition nsp = (NodeSourcePosition) obj;
NodeSourcePosition replacedCaller = (NodeSourcePosition) replaceAnalysisObjects(nsp.getCaller(), node, replacements, hUniverse);
ResolvedJavaMethod replacedMethod = (ResolvedJavaMethod) replaceAnalysisObjects(nsp.getMethod(), node, replacements, hUniverse);
newReplacement = new NodeSourcePosition(nsp.getSourceLanguage(), replacedCaller, replacedMethod, nsp.getBCI(), nsp.getMarker());
} else if (obj.getClass() == BytecodePosition.class) {
BytecodePosition nsp = (BytecodePosition) obj;
BytecodePosition replacedCaller = (BytecodePosition) replaceAnalysisObjects(nsp.getCaller(), node, replacements, hUniverse);
ResolvedJavaMethod replacedMethod = (ResolvedJavaMethod) replaceAnalysisObjects(nsp.getMethod(), node, replacements, hUniverse);
newReplacement = new BytecodePosition(replacedCaller, replacedMethod, nsp.getBCI());
} else if (obj.getClass() == SubstrateMethodPointerConstant.class) {
SubstrateMethodPointerConstant methodPointerConstant = (SubstrateMethodPointerConstant) obj;
MethodPointer methodPointer = methodPointerConstant.pointer();
ResolvedJavaMethod method = methodPointer.getMethod();
ResolvedJavaMethod replacedMethod = (ResolvedJavaMethod) replaceAnalysisObjects(method, node, replacements, hUniverse);
newReplacement = new SubstrateMethodPointerConstant(new MethodPointer(replacedMethod));
} else {
/* Check that we do not have a class or package name that relates to the analysis. */
assert !obj.getClass().getName().toLowerCase().contains("analysis") : "Object " + obj + " of " + obj.getClass() + " in node " + node;
assert !obj.getClass().getName().toLowerCase().contains("pointsto") : "Object " + obj + " of " + obj.getClass() + " in node " + node;
newReplacement = obj;
}
replacements.put(obj, newReplacement);
return newReplacement;
}
use of com.oracle.svm.core.meta.MethodPointer in project graal by oracle.
the class InvalidVTableEntryFeature method buildHubs.
private void buildHubs() {
InstanceReferenceMapEncoder referenceMapEncoder = new InstanceReferenceMapEncoder();
Map<HostedType, ReferenceMapEncoder.Input> referenceMaps = new HashMap<>();
for (HostedType type : hUniverse.getTypes()) {
ReferenceMapEncoder.Input referenceMap = createReferenceMap(type);
assert ((SubstrateReferenceMap) referenceMap).hasNoDerivedOffsets();
referenceMaps.put(type, referenceMap);
referenceMapEncoder.add(referenceMap);
}
ImageSingletons.lookup(DynamicHubSupport.class).setData(referenceMapEncoder.encodeAll());
ObjectLayout ol = ConfigurationValues.getObjectLayout();
for (HostedType type : hUniverse.getTypes()) {
hUniverse.bb.getHeartbeatCallback().run();
int layoutHelper;
int monitorOffset = 0;
if (type.isInstanceClass()) {
HostedInstanceClass instanceClass = (HostedInstanceClass) type;
if (instanceClass.isAbstract()) {
layoutHelper = LayoutEncoding.forAbstract();
} else if (HybridLayout.isHybrid(type)) {
HybridLayout<?> hybridLayout = new HybridLayout<>(instanceClass, ol);
JavaKind storageKind = hybridLayout.getArrayElementStorageKind();
boolean isObject = (storageKind == JavaKind.Object);
layoutHelper = LayoutEncoding.forArray(type, isObject, hybridLayout.getArrayBaseOffset(), ol.getArrayIndexShift(storageKind));
} else if (instanceClass.getJavaClass().equals(StoredContinuation.class)) {
layoutHelper = LayoutEncoding.forStoredContinuation();
} else {
layoutHelper = LayoutEncoding.forInstance(type, ConfigurationValues.getObjectLayout().alignUp(instanceClass.getInstanceSize()));
}
monitorOffset = instanceClass.getMonitorFieldOffset();
} else if (type.isArray()) {
JavaKind storageKind = type.getComponentType().getStorageKind();
boolean isObject = (storageKind == JavaKind.Object);
layoutHelper = LayoutEncoding.forArray(type, isObject, ol.getArrayBaseOffset(storageKind), ol.getArrayIndexShift(storageKind));
} else if (type.isInterface()) {
layoutHelper = LayoutEncoding.forInterface();
} else if (type.isPrimitive()) {
layoutHelper = LayoutEncoding.forPrimitive();
} else {
throw VMError.shouldNotReachHere();
}
/*
* The vtable entry values are available only after the code cache layout is fixed, so
* leave them 0.
*/
CFunctionPointer[] vtable = new CFunctionPointer[type.vtable.length];
for (int idx = 0; idx < type.vtable.length; idx++) {
/*
* We install a CodePointer in the vtable; when generating relocation info, we will
* know these point into .text
*/
vtable[idx] = new MethodPointer(type.vtable[idx]);
}
// pointer maps in Dynamic Hub
ReferenceMapEncoder.Input referenceMap = referenceMaps.get(type);
assert referenceMap != null;
assert ((SubstrateReferenceMap) referenceMap).hasNoDerivedOffsets();
long referenceMapIndex;
if (referenceMap == SubstrateReferenceMap.STORED_CONTINUATION_REFERENCE_MAP) {
referenceMapIndex = ReferenceMapIndex.STORED_CONTINUATION;
} else {
referenceMapIndex = referenceMapEncoder.lookupEncoding(referenceMap);
}
DynamicHub hub = type.getHub();
hub.setData(layoutHelper, type.getTypeID(), monitorOffset, type.getTypeCheckStart(), type.getTypeCheckRange(), type.getTypeCheckSlot(), type.getTypeCheckSlots(), vtable, referenceMapIndex, type.isInstantiated());
}
}
Aggregations