Skip to content

Commit

Permalink
Avoid reinitialization by publishing node only after full initialization
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Marr <git@stefan-marr.de>
  • Loading branch information
smarr committed Apr 16, 2020
1 parent 3492657 commit 4bff397
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/som/interpreter/actors/ReceivedRootNode.java
Expand Up @@ -104,13 +104,17 @@ protected final void resolvePromise(final VirtualFrame frame,
// lazy initialization of resolution node
if (resolve == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
// Warning: this is racy, thus, we do everything on a local,
// and only publish the result at the end
AbstractPromiseResolutionNode resolve;
if (resolver == null) {
this.resolve = insert(new NullResolver());
resolve = insert(new NullResolver());
} else {
this.resolve = insert(
resolve = insert(
ResolvePromiseNodeFactory.create(null, null, null, null).initialize(vm));
}
this.resolve.initialize(sourceSection);
resolve.initialize(sourceSection);
this.resolve = resolve;
notifyInserted(this.resolve);
}

Expand All @@ -124,12 +128,16 @@ protected final void errorPromise(final VirtualFrame frame,
// lazy initialization of resolution node
if (error == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
// Warning: this is racy, thus, we do everything on a local,
// and only publish the result at the end
AbstractPromiseResolutionNode error;
if (resolver == null) {
this.error = insert(new NullResolver());
error = insert(new NullResolver());
} else {
this.error = insert(
error = insert(
ErrorPromiseNodeFactory.create(null, null, null, null).initialize(vm));
}
this.error = error;
this.error.initialize(sourceSection);
notifyInserted(this.error);
}
Expand Down

0 comments on commit 4bff397

Please sign in to comment.