Skip to content

Commit

Permalink
[GR-28768] [GR-28731] Ensure globals' state is not constant propagate…
Browse files Browse the repository at this point in the history
…d during writes.

PullRequest: graal/8351
  • Loading branch information
fmorcos committed Feb 24, 2021
2 parents 889756f + 1d45af8 commit 65b2512
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2020, Oracle and/or its affiliates.
* Copyright (c) 2016, 2021, Oracle and/or its affiliates.
*
* All rights reserved.
*
Expand Down Expand Up @@ -77,11 +77,19 @@ private static final class State {

private long address;

// Only constant-propagate a globals' state when reading. See {@link get()} and {@link set()}
// below. This essentially means we need two copies of {@link contents}, one for reading from
// (which is effectively final, i.e. @CompilationFinal) and one for using when updating ({@link
// contentsNotFinal}).
@CompilationFinal private State contents;
private State contentsNotFinal;

private Object fallbackContents;

public LLVMGlobalContainer() {
contents = new State(0L, 0);
State state = new State(0L, 0);
contents = state;
contentsNotFinal = state;
}

public Object get() {
Expand All @@ -103,10 +111,12 @@ public Object getFallback() {
}

public void set(Object value, BranchProfile needsInitialize, BranchProfile needsInvalidation) {
State c = contents;
State c = contentsNotFinal;
if (c.writeCount < MAX_CACHED_WRITES) {
needsInitialize.enter();
contents = new State(value, c.writeCount + 1);
State state = new State(value, c.writeCount + 1);
contents = state;
contentsNotFinal = state;
c.assumption.invalidate();
} else {
if (c.assumption.isValid()) {
Expand Down

0 comments on commit 65b2512

Please sign in to comment.