Skip to content

Commit

Permalink
[GR-58056] More detailed assertions when FrequencyEncoder doesn't con…
Browse files Browse the repository at this point in the history
…tain an object.

PullRequest: graal/18843
  • Loading branch information
peter-hofer committed Sep 20, 2024
2 parents 8d7ea9e + e298dff commit cacd919
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public int getIndex(T object) {
return 0;
}
Entry<T> entry = map.get(object);
assert entry != null && entry.index >= 0 : Assertions.errorMessageContext("entry", entry);
assert entry != null && entry.index >= 0 : Assertions.errorMessageContext("object", object, "entry", entry);
return entry.index;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,12 @@ public void prepare(StructuredGraph graph) {
}
}

protected Object replaceObjectForEncoding(Object object) {
return object;
}

protected void addObject(Object object) {
objects.addObject(object);
objects.addObject(replaceObjectForEncoding(object));
}

public void finishPrepare() {
Expand Down Expand Up @@ -448,8 +452,7 @@ protected void writeProperties(Node node, Fields fields) {
long primitive = fields.getRawPrimitive(node, idx);
writer.putSV(primitive);
} else {
Object property = fields.get(node, idx);
writeObjectId(property);
writeObjectId(node, fields, idx);
}
}
}
Expand Down Expand Up @@ -498,10 +501,19 @@ protected void writeOrderId(Node node, NodeOrder nodeOrder) {
}
}

protected void writeObjectId(Object object) {
private void writeObjectId(Object value) {
Object object = replaceObjectForEncoding(value);
writer.putUV(objects.getIndex(object));
}

private void writeObjectId(Node node, Fields fields, int fieldIndex) {
Object value = fields.get(node, fieldIndex);
Object object = replaceObjectForEncoding(value);
int index = objects.findIndex(object);
assert index >= 0 : Assertions.errorMessageContext("node", node, "field", fields.getName(fieldIndex), "object", object);
writer.putUV(index);
}

/**
* Verification code that checks that the decoding of an encoded graph is the same as the
* original graph.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,22 +391,13 @@ public RuntimeCompilationGraphEncoder(Architecture architecture, ImageHeapScanne
this.locationIdentityCache = new ConcurrentHashMap<>();
}

@Override
protected void addObject(Object object) {
super.addObject(hostedToRuntime(object));
}

@Override
protected void writeObjectId(Object object) {
super.writeObjectId(hostedToRuntime(object));
}

@Override
protected GraphDecoder graphDecoderForVerification(StructuredGraph decodedGraph) {
return new RuntimeCompilationGraphDecoder(architecture, decodedGraph, heapScanner);
}

private Object hostedToRuntime(Object object) {
@Override
protected Object replaceObjectForEncoding(Object object) {
if (object instanceof ImageHeapConstant heapConstant) {
return SubstrateGraalUtils.hostedToRuntime(heapConstant, heapScanner.getConstantReflection());
} else if (object instanceof ObjectLocationIdentity oli && oli.getObject() instanceof ImageHeapConstant heapConstant) {
Expand Down

0 comments on commit cacd919

Please sign in to comment.