use of com.oracle.svm.hosted.meta.HostedType in project graal by oracle.
the class StrengthenStampsPhase method strengthenStamp.
private Stamp strengthenStamp(ValueNode node, JavaTypeProfile typeProfile) {
ObjectStamp oldStamp = (ObjectStamp) node.stamp(NodeView.DEFAULT);
HostedType oldType = toHosted(oldStamp.type());
if (oldStamp.alwaysNull()) {
/* We cannot make that more precise. */
return oldStamp;
}
boolean nonNull = oldStamp.nonNull() || typeProfile.getNullSeen() == TriState.FALSE;
ProfiledType[] exactTypes = typeProfile.getTypes();
if (exactTypes.length == 1) {
ResolvedJavaType exactType = exactTypes[0].getType();
assert oldType == null || oldType.isAssignableFrom(exactType);
if (!oldStamp.isExactType() || !exactType.equals(oldType) || nonNull != oldStamp.nonNull()) {
TypeReference typeRef = TypeReference.createExactTrusted(toTarget(exactType));
return nonNull ? StampFactory.objectNonNull(typeRef) : StampFactory.object(typeRef);
} else {
return oldStamp;
}
}
if (exactTypes.length == 0) {
if (!nonNull) {
return StampFactory.alwaysNull();
} else {
/*
* The code after the node is unreachable. We just insert a always-failing guard
* after the node and let dead code elimination remove everything after the node.
*/
StructuredGraph graph = node.graph();
FixedWithNextNode insertionPoint;
if (node instanceof ParameterNode) {
/* The whole method is unreachable. */
insertionPoint = graph.start();
} else if (node instanceof InvokeWithExceptionNode) {
/* The invoked method never returns normally (but can throw an exception). */
insertionPoint = ((InvokeWithExceptionNode) node).next();
} else {
insertionPoint = (FixedWithNextNode) node;
}
graph.addAfterFixed(insertionPoint, graph.add(new FixedGuardNode(LogicConstantNode.forBoolean(true, graph), DeoptimizationReason.UnreachedCode, DeoptimizationAction.None, true)));
return oldStamp;
}
}
ResolvedJavaType baseType;
if (oldStamp.isExactType()) {
/* Base type cannot be more precise. */
baseType = oldType;
} else {
assert exactTypes.length > 1;
assert oldType == null || oldType.isAssignableFrom(exactTypes[0].getType());
baseType = exactTypes[0].getType();
for (int i = 1; i < exactTypes.length; i++) {
assert oldType == null || oldType.isAssignableFrom(exactTypes[i].getType());
baseType = baseType.findLeastCommonAncestor(exactTypes[i].getType());
}
if (oldType != null && !oldType.isAssignableFrom(baseType)) {
/*
* When the original stamp is an interface type, we do not want to weaken that type
* with the common base class of all implementation types (which could even be
* java.lang.Object).
*/
baseType = oldType;
}
}
if (!baseType.equals(oldType) || nonNull != oldStamp.nonNull()) {
TypeReference typeRef = TypeReference.createTrustedWithoutAssumptions(toTarget(baseType));
return nonNull ? StampFactory.objectNonNull(typeRef) : StampFactory.object(typeRef);
}
return oldStamp;
}
use of com.oracle.svm.hosted.meta.HostedType in project graal by oracle.
the class StrengthenStampsPhase method strengthen.
private Stamp strengthen(Stamp s) {
if (!(s instanceof AbstractObjectStamp)) {
return null;
}
AbstractObjectStamp stamp = (AbstractObjectStamp) s;
HostedType originalType = toHosted(stamp.type());
if (originalType == null) {
return null;
}
HostedType strengthenType = originalType.getStrengthenStampType();
if (originalType.equals(strengthenType)) {
/* Nothing to strengthen. */
return null;
}
Stamp newStamp;
if (strengthenType == null) {
if (stamp.nonNull()) {
/* We must be in dead code. */
newStamp = StampFactory.empty(JavaKind.Object);
} else {
/* The type its subtypes are not instantiated, the only possible value is null. */
newStamp = StampFactory.alwaysNull();
}
} else {
if (stamp.isExactType()) {
/* We must be in dead code. */
newStamp = StampFactory.empty(JavaKind.Object);
} else {
TypeReference typeRef = TypeReference.createTrustedWithoutAssumptions(toTarget(strengthenType));
newStamp = StampFactory.object(typeRef, stamp.nonNull());
}
}
return newStamp;
}
use of com.oracle.svm.hosted.meta.HostedType in project graal by oracle.
the class NativeImageCodeCache method printCompilationResults.
public void printCompilationResults() {
System.out.println("--- compiled methods");
for (Entry<HostedMethod, CompilationResult> entry : compilations.entrySet()) {
HostedMethod method = entry.getKey();
System.out.format("%8d %5d %s: frame %d\n", method.getCodeAddressOffset(), entry.getValue().getTargetCodeSize(), method.format("%H.%n(%p)"), entry.getValue().getTotalFrameSize());
}
System.out.println("--- vtables:");
for (HostedType type : imageHeap.getUniverse().getTypes()) {
for (int i = 0; i < type.getVTable().length; i++) {
HostedMethod method = type.getVTable()[i];
if (method != null) {
CompilationResult comp = compilations.get(type.getVTable()[i]);
if (comp != null) {
System.out.format("%d %s @ %d: %s = 0x%x\n", type.getTypeID(), type.toJavaName(false), i, method.format("%r %n(%p)"), method.getCodeAddressOffset());
}
}
}
}
}
use of com.oracle.svm.hosted.meta.HostedType in project graal by oracle.
the class NativeImageHeap method choosePartition.
/**
* Choose a partition of the native image heap for the given object.
*/
private HeapPartition choosePartition(final Object candidate, final boolean immutableArg) {
final HostedType type = getMetaAccess().lookupJavaType(candidate.getClass());
assert type.getWrapped().isInstantiated() : type;
boolean written = false;
boolean references = false;
boolean immutable = immutableArg;
if (type.isInstanceClass()) {
final HostedInstanceClass clazz = (HostedInstanceClass) type;
if (HybridLayout.isHybrid(clazz)) {
final HybridLayout<?> hybridLayout = new HybridLayout<>(clazz, layout);
final HostedField arrayField = hybridLayout.getArrayField();
written |= arrayField.isWritten();
final JavaKind arrayKind = hybridLayout.getArrayElementKind();
references |= arrayKind.isObject();
}
// Aggregate over all the fields of the instance.
for (HostedField field : clazz.getInstanceFields(true)) {
/*
* Any field that is written says the instance is written. Except that if the field
* is final, it will only be written during initialization during native image
* construction, but will not be written in the running image.
*/
written |= field.isWritten() && !field.isFinal();
references |= field.getType().getStorageKind().isObject();
}
// If the type has a monitor field, it has a reference field that is written.
if (clazz.getMonitorFieldOffset() != 0) {
written = true;
references = true;
immutable = false;
}
} else if (type.isArray()) {
HostedArrayClass clazz = (HostedArrayClass) type;
// TODO: How to know if any of the array elements are written?
written = true;
JavaKind kind = clazz.getComponentType().getJavaKind();
references = kind.isObject();
} else {
throw shouldNotReachHere();
}
if (SubstrateOptions.UseOnlyWritableBootImageHeap.getValue()) {
assert !spawnIsolates();
// Emergency use only! Alarms will sound!
return writableReference;
}
if (!written || immutable) {
return references ? readOnlyReference : readOnlyPrimitive;
} else {
return references ? writableReference : writablePrimitive;
}
}
use of com.oracle.svm.hosted.meta.HostedType in project graal by oracle.
the class NativeImageGenerator method printTypes.
private void printTypes() {
for (HostedType type : hUniverse.getTypes()) {
System.out.format("%8d %s ", type.getTypeID(), type.toJavaName(true));
if (type.getSuperclass() != null) {
System.out.format("extends %d %s ", type.getSuperclass().getTypeID(), type.getSuperclass().toJavaName(false));
}
if (type.getInterfaces().length > 0) {
System.out.print("implements ");
String sep = "";
for (HostedInterface interf : type.getInterfaces()) {
System.out.format("%s%d %s", sep, interf.getTypeID(), interf.toJavaName(false));
sep = ", ";
}
System.out.print(" ");
}
if (type.getWrapped().isInstantiated()) {
System.out.print("instantiated ");
}
if (type.getWrapped().isInTypeCheck()) {
System.out.print("inTypeCheck ");
}
System.out.format("assignableFrom %s ", matchesToString(type.getAssignableFromMatches()));
System.out.format("instanceOf typeID %d, # %d ", type.getInstanceOfFromTypeID(), type.getInstanceOfNumTypeIDs());
// if (type.findLeafConcreteSubtype() != null) {
// System.out.format("unique %d %s ", type.findLeafConcreteSubtype().getTypeID(),
// type.findLeafConcreteSubtype().toJavaName(false));
// }
int le = type.getHub().getLayoutEncoding();
if (LayoutEncoding.isPrimitive(le)) {
System.out.print("primitive ");
} else if (LayoutEncoding.isInterface(le)) {
System.out.print("interface ");
} else if (LayoutEncoding.isAbstract(le)) {
System.out.print("abstract ");
} else if (LayoutEncoding.isInstance(le)) {
System.out.format("instance size %d ", LayoutEncoding.getInstanceSize(le).rawValue());
} else if (LayoutEncoding.isObjectArray(le)) {
System.out.format("object array base %d shift %d scale %d ", LayoutEncoding.getArrayBaseOffset(le).rawValue(), LayoutEncoding.getArrayIndexShift(le), LayoutEncoding.getArrayIndexScale(le));
} else if (LayoutEncoding.isPrimitiveArray(le)) {
System.out.format("primitive array base %d shift %d scale %d ", LayoutEncoding.getArrayBaseOffset(le).rawValue(), LayoutEncoding.getArrayIndexShift(le), LayoutEncoding.getArrayIndexScale(le));
} else {
throw VMError.shouldNotReachHere();
}
System.out.println();
for (HostedType sub : type.getSubTypes()) {
System.out.format(" s %d %s\n", sub.getTypeID(), sub.toJavaName(false));
}
if (type.isInterface()) {
for (HostedMethod method : hUniverse.getMethods()) {
if (method.getDeclaringClass() == type) {
printMethod(method, -1);
}
}
} else if (type.isInstanceClass()) {
HostedField[] fields = type.getInstanceFields(false);
fields = Arrays.copyOf(fields, fields.length);
Arrays.sort(fields, Comparator.comparing(HostedField::toString));
for (HostedField field : fields) {
System.out.println(" f " + field.getLocation() + ": " + field.format("%T %n"));
}
HostedMethod[] vtable = type.getVTable();
for (int i = 0; i < vtable.length; i++) {
if (vtable[i] != null) {
printMethod(vtable[i], i);
}
}
for (HostedMethod method : hUniverse.getMethods()) {
if (method.getDeclaringClass() == type && !method.hasVTableIndex()) {
printMethod(method, -1);
}
}
}
}
}
Aggregations