Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ abstract static class ConstantData {
*/
private boolean isInBaseLayer;

ConstantData(AnalysisType type, JavaConstant hostedObject, int identityHashCode) {
ConstantData(AnalysisType type, JavaConstant hostedObject, int identityHashCode, int id) {
Objects.requireNonNull(type);
this.type = type;
this.hostedObject = CompressibleConstant.uncompress(hostedObject);
Expand All @@ -117,7 +117,7 @@ abstract static class ConstantData {
/* This value must never be used later on. */
this.identityHashCode = -1;
}
this.id = currentId.getAndIncrement();
this.id = id == -1 ? currentId.getAndIncrement() : id;
}

@Override
Expand Down Expand Up @@ -206,6 +206,14 @@ public boolean isBackedByHostedObject() {
return constantData.hostedObject != null;
}

public static int getCurrentId() {
return currentId.get();
}

public static void setCurrentId(int id) {
currentId.set(id);
}

public static int getConstantID(ImageHeapConstant constant) {
return constant.getConstantData().id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,23 @@ private static final class InstanceData extends ConstantData {
*/
private Object[] fieldValues;

private InstanceData(AnalysisType type, JavaConstant hostedObject, Object[] fieldValues, int identityHashCode) {
super(type, hostedObject, identityHashCode);
private InstanceData(AnalysisType type, JavaConstant hostedObject, Object[] fieldValues, int identityHashCode, int id) {
super(type, hostedObject, identityHashCode, id);
this.fieldValues = fieldValues;
assert !type.isArray() : type;
}
}

ImageHeapInstance(AnalysisType type, JavaConstant hostedObject) {
this(type, hostedObject, -1);
this(type, hostedObject, -1, -1);
}

ImageHeapInstance(AnalysisType type, JavaConstant hostedObject, int identityHashCode) {
super(new InstanceData(type, hostedObject, null, identityHashCode), false);
ImageHeapInstance(AnalysisType type, JavaConstant hostedObject, int identityHashCode, int id) {
super(new InstanceData(type, hostedObject, null, identityHashCode, id), false);
}

public ImageHeapInstance(AnalysisType type) {
super(new InstanceData(type, null, new Object[type.getInstanceFields(true).length], -1), false);
super(new InstanceData(type, null, new Object[type.getInstanceFields(true).length], -1, -1), false);
}

private ImageHeapInstance(ConstantData data, boolean compressed) {
Expand Down Expand Up @@ -184,6 +184,6 @@ public ImageHeapConstant forObjectClone() {
Objects.requireNonNull(fieldValues, "Cannot clone an instance before the field values are set.");
Object[] newFieldValues = Arrays.copyOf(fieldValues, fieldValues.length);
/* The new constant is never backed by a hosted object, regardless of the input object. */
return new ImageHeapInstance(new InstanceData(constantData.type, null, newFieldValues, -1), compressed);
return new ImageHeapInstance(new InstanceData(constantData.type, null, newFieldValues, -1, -1), compressed);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,28 @@ private static final class ObjectArrayData extends ConstantData {

final int length;

private ObjectArrayData(AnalysisType type, JavaConstant hostedObject, Object[] arrayElementValues, int length, int identityHashCode) {
super(type, hostedObject, identityHashCode);
private ObjectArrayData(AnalysisType type, JavaConstant hostedObject, Object[] arrayElementValues, int length, int identityHashCode, int id) {
super(type, hostedObject, identityHashCode, id);
this.arrayElementValues = arrayElementValues;
this.length = length;
assert type.isArray() && !type.getComponentType().isPrimitive() : type;
}
}

ImageHeapObjectArray(AnalysisType type, JavaConstant hostedObject, int length) {
this(type, hostedObject, length, -1);
this(type, hostedObject, length, -1, -1);
}

ImageHeapObjectArray(AnalysisType type, JavaConstant hostedObject, int length, int identityHashCode) {
super(new ObjectArrayData(type, hostedObject, null, length, identityHashCode), false);
ImageHeapObjectArray(AnalysisType type, JavaConstant hostedObject, int length, int identityHashCode, int id) {
super(new ObjectArrayData(type, hostedObject, null, length, identityHashCode, id), false);
}

ImageHeapObjectArray(AnalysisType type, JavaConstant hostedObject, Object[] arrayElementValues, int identityHashCode) {
super(new ObjectArrayData(type, hostedObject, arrayElementValues, arrayElementValues.length, identityHashCode), false);
ImageHeapObjectArray(AnalysisType type, JavaConstant hostedObject, Object[] arrayElementValues, int identityHashCode, int id) {
super(new ObjectArrayData(type, hostedObject, arrayElementValues, arrayElementValues.length, identityHashCode, id), false);
}

ImageHeapObjectArray(AnalysisType type, int length) {
super(new ObjectArrayData(type, null, new Object[length], length, -1), false);
super(new ObjectArrayData(type, null, new Object[length], length, -1, -1), false);
}

private ImageHeapObjectArray(ConstantData data, boolean compressed) {
Expand All @@ -98,7 +98,7 @@ void setElementValues(Object[] elementValues) {
}

public static ImageHeapObjectArray createUnbackedImageHeapArray(AnalysisType type, Object[] elementValues) {
return new ImageHeapObjectArray(type, null, elementValues, -1);
return new ImageHeapObjectArray(type, null, elementValues, -1, -1);
}

/**
Expand Down Expand Up @@ -168,6 +168,6 @@ public ImageHeapConstant forObjectClone() {
Objects.requireNonNull(arrayElements, "Cannot clone an array before the element values are set.");
Object[] newArrayElementValues = Arrays.copyOf(arrayElements, arrayElements.length);
/* The new constant is never backed by a hosted object, regardless of the input object. */
return new ImageHeapObjectArray(new ObjectArrayData(constantData.type, null, newArrayElementValues, arrayElements.length, -1), compressed);
return new ImageHeapObjectArray(new ObjectArrayData(constantData.type, null, newArrayElementValues, arrayElements.length, -1, -1), compressed);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ private static final class PrimitiveArrayData extends ConstantData {
private final Object array;
private final int length;

private PrimitiveArrayData(AnalysisType type, JavaConstant hostedObject, Object array, int length, int identityHashCode) {
super(type, hostedObject, identityHashCode);
private PrimitiveArrayData(AnalysisType type, JavaConstant hostedObject, Object array, int length, int identityHashCode, int id) {
super(type, hostedObject, identityHashCode, id);
this.array = array;
this.length = length;
assert type.isArray() && type.getComponentType().isPrimitive() : type;
Expand All @@ -53,18 +53,18 @@ private PrimitiveArrayData(AnalysisType type, JavaConstant hostedObject, Object
super(new PrimitiveArrayData(type, null,
/* Without a hosted object, we need to create a backing primitive array. */
Array.newInstance(type.getComponentType().getStorageKind().toJavaClass(), length),
length, -1), false);
length, -1, -1), false);
}

ImageHeapPrimitiveArray(AnalysisType type, JavaConstant hostedObject, Object array, int length) {
this(type, hostedObject, array, length, -1);
this(type, hostedObject, array, length, -1, -1);
}

ImageHeapPrimitiveArray(AnalysisType type, JavaConstant hostedObject, Object array, int length, int identityHashCode) {
ImageHeapPrimitiveArray(AnalysisType type, JavaConstant hostedObject, Object array, int length, int identityHashCode, int id) {
super(new PrimitiveArrayData(type, hostedObject,
/* We need a clone of the hosted array so that we have a stable snapshot. */
getClone(type.getComponentType().getJavaKind(), array),
length, identityHashCode), false);
length, identityHashCode, id), false);
}

private ImageHeapPrimitiveArray(ConstantData constantData, boolean compressed) {
Expand Down Expand Up @@ -140,6 +140,6 @@ public ImageHeapConstant forObjectClone() {
PrimitiveArrayData data = getConstantData();
Object newArray = getClone(data.type.getComponentType().getJavaKind(), data.array);
/* The new constant is never backed by a hosted object, regardless of the input object. */
return new ImageHeapPrimitiveArray(new PrimitiveArrayData(data.type, null, newArray, data.length, -1), compressed);
return new ImageHeapPrimitiveArray(new PrimitiveArrayData(data.type, null, newArray, data.length, -1, -1), compressed);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public final class ImageHeapRelocatableConstant extends ImageHeapConstant {
public static final class RelocatableConstantData extends ConstantData {
public final String key;

RelocatableConstantData(AnalysisType type, String key) {
super(type, null, -1);
RelocatableConstantData(AnalysisType type, String key, int id) {
super(type, null, -1, id);
this.key = key;
}
}
Expand All @@ -54,11 +54,15 @@ public RelocatableConstantData getConstantData() {
return (RelocatableConstantData) constantData;
}

public static ImageHeapRelocatableConstant create(AnalysisType type, String key) {
var data = new RelocatableConstantData(type, key);
public static ImageHeapRelocatableConstant create(AnalysisType type, String key, int id) {
var data = new RelocatableConstantData(type, key, id);
return new ImageHeapRelocatableConstant(data, false);
}

public static ImageHeapRelocatableConstant create(AnalysisType type, String key) {
return create(type, key, -1);
}

@Override
public JavaConstant compress() {
throw AnalysisError.shouldNotReachHere("Unsupported in ImageHeapRelocatableConstant");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.METHOD_HANDLE_INTRINSIC_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.MODIFIERS_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.NAME_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.NEXT_CONSTANT_ID_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.NEXT_FIELD_ID_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.NEXT_METHOD_ID_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.NEXT_TYPE_ID_TAG;
Expand Down Expand Up @@ -425,6 +426,9 @@ private void loadLayerAnalysis0() {
int nextFieldId = get(jsonMap, NEXT_FIELD_ID_TAG);
universe.setStartFieldId(nextFieldId);

int nextConstantId = get(jsonMap, NEXT_CONSTANT_ID_TAG);
ImageHeapConstant.setCurrentId(nextConstantId);

imageHeapSize = Long.parseLong(get(jsonMap, IMAGE_HEAP_SIZE_TAG));

storeIdToIdentifier(TYPES_TAG, typeIdToIdentifier);
Expand Down Expand Up @@ -1115,7 +1119,7 @@ protected ImageHeapConstant getOrCreateConstant(EconomicMap<String, Object> cons
}

addBaseLayerObject(id, objectOffset, () -> {
ImageHeapInstance imageHeapInstance = new ImageHeapInstance(type, foundHostedObject == null ? parentReachableHostedObject : foundHostedObject, identityHashCode);
ImageHeapInstance imageHeapInstance = new ImageHeapInstance(type, foundHostedObject == null ? parentReachableHostedObject : foundHostedObject, identityHashCode, id);
if (instanceData != null) {
Object[] fieldValues = getReferencedValues(constantsMap, imageHeapInstance, instanceData, imageLayerSnapshotUtil.getRelinkedFields(type, metaAccess));
imageHeapInstance.setFieldValues(fieldValues);
Expand All @@ -1126,7 +1130,7 @@ protected ImageHeapConstant getOrCreateConstant(EconomicMap<String, Object> cons
case ARRAY_TAG -> {
List<List<Object>> arrayData = get(baseLayerConstant, DATA_TAG);
addBaseLayerObject(id, objectOffset, () -> {
ImageHeapObjectArray imageHeapObjectArray = new ImageHeapObjectArray(type, null, arrayData.size(), identityHashCode);
ImageHeapObjectArray imageHeapObjectArray = new ImageHeapObjectArray(type, null, arrayData.size(), identityHashCode, id);
Object[] elementsValues = getReferencedValues(constantsMap, imageHeapObjectArray, arrayData, Set.of());
imageHeapObjectArray.setElementValues(elementsValues);
return imageHeapObjectArray;
Expand All @@ -1135,11 +1139,11 @@ protected ImageHeapConstant getOrCreateConstant(EconomicMap<String, Object> cons
case PRIMITIVE_ARRAY_TAG -> {
List<Object> primitiveData = get(baseLayerConstant, DATA_TAG);
Object array = getArray(type.getComponentType().getJavaKind(), primitiveData);
addBaseLayerObject(id, objectOffset, () -> new ImageHeapPrimitiveArray(type, null, array, primitiveData.size(), identityHashCode));
addBaseLayerObject(id, objectOffset, () -> new ImageHeapPrimitiveArray(type, null, array, primitiveData.size(), identityHashCode, id));
}
case RELOCATED_CONSTANT_TAG -> {
String key = get(baseLayerConstant, DATA_TAG);
addBaseLayerObject(id, objectOffset, () -> ImageHeapRelocatableConstant.create(type, key));
addBaseLayerObject(id, objectOffset, () -> ImageHeapRelocatableConstant.create(type, key, id));
}
default -> throw GraalError.shouldNotReachHere("Unknown constant type: " + constantType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public class ImageLayerSnapshotUtil {
public static final String NEXT_TYPE_ID_TAG = "next type id";
public static final String NEXT_METHOD_ID_TAG = "next method id";
public static final String NEXT_FIELD_ID_TAG = "next field id";
public static final String NEXT_CONSTANT_ID_TAG = "next constant id";
public static final String IMAGE_HEAP_SIZE_TAG = "image heap size";
public static final String VALUE_TAG = "value";
public static final String ENUM_CLASS_TAG = "enum class";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.METHOD_HANDLE_INTRINSIC_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.MODIFIERS_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.NAME_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.NEXT_CONSTANT_ID_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.NEXT_FIELD_ID_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.NEXT_METHOD_ID_TAG;
import static com.oracle.graal.pointsto.heap.ImageLayerSnapshotUtil.NEXT_TYPE_ID_TAG;
Expand Down Expand Up @@ -281,6 +282,7 @@ public void persistAnalysisInfo() {
jsonMap.put(NEXT_TYPE_ID_TAG, aUniverse.getNextTypeId());
jsonMap.put(NEXT_METHOD_ID_TAG, aUniverse.getNextMethodId());
jsonMap.put(NEXT_FIELD_ID_TAG, aUniverse.getNextFieldId());
jsonMap.put(NEXT_CONSTANT_ID_TAG, ImageHeapConstant.getCurrentId());

for (AnalysisType type : aUniverse.getTypes().stream().filter(AnalysisType::isTrackedAcrossLayers).toList()) {
checkTypeStability(type);
Expand Down