Skip to content

Commit

Permalink
Set promise data fields to null on resolution
Browse files Browse the repository at this point in the history
On resolution, we consume all the data, and the fields are no longer used, because future callbacks/messages are scheduled directly without being registered on the promise.

Signed-off-by: Stefan Marr <git@stefan-marr.de>
  • Loading branch information
smarr committed Jul 2, 2019
1 parent 3900469 commit 8e49d65
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/som/interpreter/actors/SPromise.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,12 @@ protected static void resolveChainedPromisesUnsync(final Resolution type,
// lead to a stack overflow.
// TODO: restore 10000 as parameter in testAsyncDeeplyChainedResolution
if (promise.chainedPromise != null) {
Object wrapped = promise.chainedPromise.owner.wrapForUse(result, current, null);
SPromise chainedPromise = promise.chainedPromise;
promise.chainedPromise = null;
Object wrapped = chainedPromise.owner.wrapForUse(result, current, null);
resolveAndTriggerListenersUnsynced(type, result, wrapped,
promise.chainedPromise, current, actorPool,
promise.chainedPromise.haltOnResolution, whenResolvedProfile);
chainedPromise, current, actorPool,
chainedPromise.haltOnResolution, whenResolvedProfile);
resolveMoreChainedPromisesUnsynced(type, promise, result, current,
actorPool, haltOnResolution, whenResolvedProfile);
}
Expand All @@ -429,8 +431,10 @@ private static void resolveMoreChainedPromisesUnsynced(final Resolution type,
final ForkJoinPool actorPool, final boolean haltOnResolution,
final ValueProfile whenResolvedProfile) {
if (promise.chainedPromiseExt != null) {
ArrayList<SPromise> chainedPromiseExt = promise.chainedPromiseExt;
promise.chainedPromiseExt = null;

for (SPromise p : promise.chainedPromiseExt) {
for (SPromise p : chainedPromiseExt) {
Object wrapped = p.owner.wrapForUse(result, current, null);
resolveAndTriggerListenersUnsynced(type, result, wrapped, p, current,
actorPool, haltOnResolution, whenResolvedProfile);
Expand Down Expand Up @@ -498,11 +502,15 @@ protected static void scheduleAllWhenResolvedUnsync(final SPromise promise,
final Object result, final Actor current, final ForkJoinPool actorPool,
final boolean haltOnResolution, final ValueProfile whenResolvedProfile) {
if (promise.whenResolved != null) {
PromiseMessage whenResolved = promise.whenResolved;
ArrayList<PromiseMessage> whenResolvedExt = promise.whenResolvedExt;
promise.whenResolved = null;
promise.whenResolvedExt = null;

promise.scheduleCallbacksOnResolution(result,
whenResolvedProfile.profile(promise.whenResolved), current, actorPool,
whenResolvedProfile.profile(whenResolved), current, actorPool, haltOnResolution);
scheduleExtensions(promise, whenResolvedExt, result, current, actorPool,
haltOnResolution);
scheduleExtensions(promise, promise.whenResolvedExt, result, current,
actorPool, haltOnResolution);
}
}

Expand Down Expand Up @@ -530,10 +538,14 @@ protected static void scheduleAllOnErrorUnsync(final SPromise promise,
final Object result, final Actor current,
final ForkJoinPool actorPool, final boolean haltOnResolution) {
if (promise.onError != null) {
promise.scheduleCallbacksOnResolution(result, promise.onError, current,
actorPool, haltOnResolution);
scheduleExtensions(promise, promise.onErrorExt, result, current,
actorPool, haltOnResolution);
PromiseMessage onError = promise.onError;
ArrayList<PromiseMessage> onErrorExt = promise.onErrorExt;
promise.onError = null;
promise.onErrorExt = null;

promise.scheduleCallbacksOnResolution(result, onError, current, actorPool,
haltOnResolution);
scheduleExtensions(promise, onErrorExt, result, current, actorPool, haltOnResolution);
}
}
}
Expand Down

0 comments on commit 8e49d65

Please sign in to comment.