Skip to content

Commit

Permalink
Readability improvements to PublishWritesNode
Browse files Browse the repository at this point in the history
  • Loading branch information
c-refice committed Sep 6, 2024
1 parent f871dd9 commit d35ad51
Showing 1 changed file with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@
* <p>
* Operations on {@linkplain org.graalvm.word.LocationIdentity#INIT_LOCATION init} memory, such as
* initializing an allocated object's header and fields, are not considered side effecting, because
* the work of an allocation should never interact with the memory graph. However, this lack of
* explicit memory ordering could cause {@linkplain jdk.graal.compiler.nodes.memory.FloatingReadNode
* floating reads} on a newly allocated object be scheduled before its initializing writes.
* the work of an allocation should never interact with the memory graph before the object is
* initialized and visible to other code. However, this lack of explicit memory ordering could cause
* {@linkplain jdk.graal.compiler.nodes.memory.FloatingReadNode floating reads} on a newly allocated
* object be scheduled before its initializing writes.
* <p>
* In order to maintain object safety while still allowing reads to float, we require
* non-initializing uses of the newly allocated object to have a data dependence on a fixed
Expand Down Expand Up @@ -81,21 +82,18 @@ public PublishWritesNode(ValueNode newObject) {

@Override
public boolean inferStamp() {
if (allocation != null) {
return updateStamp(stamp.join(allocation.stamp(NodeView.DEFAULT)));
} else {
return false;
}
return updateStamp(stamp.join(allocation.stamp(NodeView.DEFAULT)));
}

@Override
public boolean verifyNode() {
// Check that the published allocation node is not used by reads directly.
for (AddressNode address : allocation.usages().filter(AddressNode.class)) {
assertTrue(address.usages().filter(n ->
// n is a non-writing access (a.k.a. a read)
n instanceof MemoryAccess && !MemoryKill.isMemoryKill(n)).isEmpty(),
"%s has unpublished reads", allocation);
var readUsages = address.usages().filter(n -> {
// n is a non-writing access (a.k.a. a read)
return n instanceof MemoryAccess && !MemoryKill.isMemoryKill(n);
});
assertTrue(readUsages.isEmpty(), "%s has unpublished reads", allocation);
}
return true;
}
Expand Down

0 comments on commit d35ad51

Please sign in to comment.