Skip to content

Commit

Permalink
[GR-58924] Make sure onInputSaturated and onObservedSaturated are exe…
Browse files Browse the repository at this point in the history
…cuted only once

PullRequest: graal/18982
  • Loading branch information
d-kozak committed Oct 9, 2024
2 parents ecbac71 + 1f9c54f commit d7e017c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,6 @@ public void addPredicated(PointsToAnalysis bb, TypeFlow<?> predicatedFlow) {

@Override
protected void onInputSaturated(PointsToAnalysis bb, TypeFlow<?> input) {
if (!isFlowEnabled()) {
inputSaturated = true;
/* Another thread could enable the flow in the meantime, so check again. */
if (!isFlowEnabled()) {
return;
}
}
if (!setSaturated()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,6 @@ public void addPredicated(PointsToAnalysis bb, TypeFlow<?> predicatedFlow) {
@Override
protected void onInputSaturated(PointsToAnalysis bb, TypeFlow<?> input) {
if (isAssignable) {
if (!isFlowEnabled()) {
inputSaturated = true;
/* Another thread could enable the flow in the meantime, so check again. */
if (!isFlowEnabled()) {
return;
}
}
if (!setSaturated()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ public boolean addUse(PointsToAnalysis bb, TypeFlow<?> use, boolean propagateTyp
}

protected void notifyUseOfSaturation(PointsToAnalysis bb, TypeFlow<?> use) {
use.onInputSaturated(bb, this);
use.markInputSaturated(bb, this);
}

protected boolean doAddUse(PointsToAnalysis bb, TypeFlow<?> use) {
Expand Down Expand Up @@ -671,7 +671,7 @@ public boolean addObserver(PointsToAnalysis bb, TypeFlow<?> observer, boolean tr
}

protected void notifyObserverOfSaturation(PointsToAnalysis bb, TypeFlow<?> observer) {
observer.onObservedSaturated(bb, this);
observer.markObservedSaturated(bb, this);
}

private boolean doAddObserver(PointsToAnalysis bb, TypeFlow<?> observer) {
Expand Down Expand Up @@ -925,6 +925,22 @@ private void swapAtPredicated(PointsToAnalysis bb, TypeFlow<?> newFlow, TypeFlow
newFlow.addPredicated(bb, predicatedFlow);
}

/**
* Notifies this flow that its input has saturated, but only runs the
* {@link TypeFlow#onInputSaturated}} if this flow is enabled. Otherwise, the execution of
* callback is delayed to {@link TypeFlow#enableFlow}.
*/
private void markInputSaturated(PointsToAnalysis bb, TypeFlow<?> input) {
if (!isFlowEnabled()) {
inputSaturated = true;
/* Another thread could enable the flow in the meantime, so check again. */
if (!isFlowEnabled()) {
return;
}
}
onInputSaturated(bb, input);
}

/**
* Notified by an input that it is saturated and it will stop sending updates.
*/
Expand All @@ -935,13 +951,6 @@ protected void onInputSaturated(PointsToAnalysis bb, @SuppressWarnings("unused")
return;
}

if (!isFlowEnabled()) {
inputSaturated = true;
/* Another thread could enable the flow in the meantime, so check again. */
if (!isFlowEnabled()) {
return;
}
}
/*
* By default when a type flow is notified that one of its inputs is saturated it will just
* pass this information to its uses and observers and unlink them. Subclases should
Expand All @@ -950,6 +959,22 @@ protected void onInputSaturated(PointsToAnalysis bb, @SuppressWarnings("unused")
onSaturated(bb);
}

/**
* Notifies this flow that its observed flow has saturated, but only runs the
* {@link TypeFlow#onObservedSaturated}} if this flow is enabled. Otherwise, the execution of
* callback is delayed to {@link TypeFlow#enableFlow}.
*/
private void markObservedSaturated(PointsToAnalysis bb, TypeFlow<?> observed) {
if (!isFlowEnabled()) {
observedSaturated = true;
/* Another thread could enable the flow in the meantime, so check again. */
if (!isFlowEnabled()) {
return;
}
}
onObservedSaturated(bb, observed);
}

/**
* Notified by an observed flow that it is saturated.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,6 @@ public void onObservedUpdate(PointsToAnalysis bb) {

@Override
public void onObservedSaturated(PointsToAnalysis bb, TypeFlow<?> observed) {
if (!isFlowEnabled()) {
observedSaturated = true;
/* Another thread could enable the flow in the meantime, so check again. */
if (!isFlowEnabled()) {
return;
}
}

if (!setSaturated()) {
return;
}
Expand Down

0 comments on commit d7e017c

Please sign in to comment.