Skip to content

Commit

Permalink
Initialize some assumptions lazily
Browse files Browse the repository at this point in the history
This reduces the number of assumptions created at run-time noticeably.
  • Loading branch information
fniephaus committed May 1, 2022
1 parent a469f74 commit d68f905
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
*/
@SuppressWarnings("static-method")
public final class ClassObject extends AbstractSqueakObjectWithClassAndHash {
private final CyclicAssumption classHierarchyStable = new CyclicAssumption("Class hierarchy stability");
private final CyclicAssumption methodDictStable = new CyclicAssumption("Method dictionary stability");
private final CyclicAssumption classFormatStable = new CyclicAssumption("Class format stability");
@CompilationFinal private CyclicAssumption classHierarchyStable;
@CompilationFinal private CyclicAssumption methodDictStable;
@CompilationFinal private CyclicAssumption classFormatStable;

private final SqueakImageContext image;
@CompilationFinal private boolean instancesAreClasses;
Expand Down Expand Up @@ -281,7 +281,7 @@ public void fillin(final SqueakImageChunk chunk) {
}

public void setFormat(final long format) {
classFormatStable.invalidate();
classFormatStable().invalidate();
this.format = format;
}

Expand Down Expand Up @@ -380,12 +380,12 @@ public long getFormat() {
}

public void setSuperclass(final ClassObject superclass) {
classHierarchyStable.invalidate();
classHierarchyStable().invalidate();
this.superclass = superclass;
}

public void setMethodDict(final VariablePointersObject methodDict) {
methodDictStable.invalidate();
methodDictStable().invalidate();
this.methodDict = methodDict;
}

Expand Down Expand Up @@ -473,20 +473,44 @@ public void become(final ClassObject other) {
setOtherPointers(otherPointers);
}

private CyclicAssumption classHierarchyStable() {
if (classHierarchyStable == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
classHierarchyStable = new CyclicAssumption("Class hierarchy stability");
}
return classHierarchyStable;
}

public Assumption getClassHierarchyStable() {
return classHierarchyStable.getAssumption();
return classHierarchyStable().getAssumption();
}

private CyclicAssumption methodDictStable() {
if (methodDictStable == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
methodDictStable = new CyclicAssumption("Method dictionary stability");
}
return methodDictStable;
}

public Assumption getMethodDictStable() {
return methodDictStable.getAssumption();
return methodDictStable().getAssumption();
}

public void invalidateMethodDictStableAssumption() {
methodDictStable.invalidate();
methodDictStable().invalidate();
}

private CyclicAssumption classFormatStable() {
if (classFormatStable == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
classFormatStable = new CyclicAssumption("Class format stability");
}
return classFormatStable;
}

public Assumption getClassFormatStable() {
return classFormatStable.getAssumption();
return classFormatStable().getAssumption();
}

public String getClassComment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public final class CompiledCodeObject extends AbstractSqueakObjectWithClassAndHa
private Source source;

@CompilationFinal private RootCallTarget callTarget;
private final CyclicAssumption callTargetStable = new CyclicAssumption("CompiledCodeObject callTargetStable assumption");
private final Assumption doesNotNeedSender = Truffle.getRuntime().createAssumption("CompiledCodeObject doesNotNeedSender assumption");
@CompilationFinal private CyclicAssumption callTargetStable;
@CompilationFinal private Assumption doesNotNeedSender;
@CompilationFinal private RootCallTarget resumptionCallTarget;

@TruffleBoundary
Expand Down Expand Up @@ -211,14 +211,14 @@ public RootCallTarget getCallTarget() {
private void invalidateCallTarget() {
if (callTarget != null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
callTargetStable.invalidate();
callTargetStable().invalidate();
callTarget = null;
}
}

private void renewCallTarget() {
CompilerDirectives.transferToInterpreterAndInvalidate();
callTargetStable.invalidate();
callTargetStable().invalidate();
initializeCallTargetUnsafe();
}

Expand All @@ -238,11 +238,27 @@ private void initializeCallTargetUnsafe() {

public void flushCache() {
/* Invalidate callTargetStable assumption to ensure this method is released from caches. */
callTargetStable.invalidate("primitive 116");
callTargetStable().invalidate("primitive 116");
}

private CyclicAssumption callTargetStable() {
if (callTargetStable == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
callTargetStable = new CyclicAssumption("CompiledCodeObject callTargetStable assumption");
}
return callTargetStable;
}

public Assumption getCallTargetStable() {
return callTargetStable.getAssumption();
return callTargetStable().getAssumption();
}

public Assumption getDoesNotNeedSenderAssumption() {
if (doesNotNeedSender == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
doesNotNeedSender = Truffle.getRuntime().createAssumption("CompiledCodeObject doesNotNeedSender assumption");
}
return doesNotNeedSender;
}

@TruffleBoundary
Expand All @@ -263,10 +279,6 @@ public RootCallTarget getResumptionCallTarget(final ContextObject context) {
return resumptionCallTarget;
}

public Assumption getDoesNotNeedSenderAssumption() {
return doesNotNeedSender;
}

public FrameDescriptor getFrameDescriptor() {
if (frameDescriptor == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
Expand Down Expand Up @@ -342,11 +354,11 @@ public void become(final CompiledCodeObject other) {
other.setLiteralsAndBytes(literals, bytes);
other.shadowBlocks = shadowBlocks;
other.outerMethod = outerMethod;
other.callTargetStable.invalidate();
other.callTargetStable().invalidate();
setLiteralsAndBytes(literals2, bytes2);
shadowBlocks = shadowBlocks2;
outerMethod = outerMethod2;
callTargetStable.invalidate();
callTargetStable().invalidate();
}

public int getBytecodeOffset() {
Expand Down

0 comments on commit d68f905

Please sign in to comment.