Skip to content

Commit

Permalink
Make methods in OptimizedCallTarget final where possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
chumer committed Nov 5, 2019
1 parent a84c704 commit c290f73
Showing 1 changed file with 37 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ protected static boolean inInlinedCode() {
return false;
}

public Assumption getNodeRewritingAssumption() {
public final Assumption getNodeRewritingAssumption() {
Assumption assumption = nodeRewritingAssumption;
if (assumption == null) {
assumption = initializeNodeRewritingAssumption();
Expand Down Expand Up @@ -227,15 +227,15 @@ public final void resetCompilationProfile() {
this.compilationProfile = createCompilationProfile();
}

protected List<OptimizedAssumption> getProfiledTypesAssumptions() {
protected final List<OptimizedAssumption> getProfiledTypesAssumptions() {
return getCompilationProfile().getProfiledTypesAssumptions();
}

protected Class<?>[] getProfiledArgumentTypes() {
protected final Class<?>[] getProfiledArgumentTypes() {
return getCompilationProfile().getProfiledArgumentTypes();
}

protected Class<?> getProfiledReturnType() {
protected final Class<?> getProfiledReturnType() {
return getCompilationProfile().getProfiledReturnType();
}

Expand Down Expand Up @@ -318,6 +318,9 @@ public final Object callInlinedForced(Node location, Object... arguments) {
}
}

/*
* Overridden by SVM.
*/
protected Object doInvoke(Object[] args) {
return callBoundary(args);
}
Expand Down Expand Up @@ -410,7 +413,7 @@ public final OptionValues getOptionValues() {
return engine.engineOptions;
}

public <T> T getOptionValue(OptionKey<T> key) {
public final <T> T getOptionValue(OptionKey<T> key) {
return PolyglotCompilerOptions.getValue(getOptionValues(), key);
}

Expand Down Expand Up @@ -510,7 +513,7 @@ public final boolean isCompiling() {
* @param reason a textual description of the reason why the machine code was invalidated. May
* be {@code null}.
*/
public void invalidate(Object source, CharSequence reason) {
public final void invalidate(Object source, CharSequence reason) {
cachedNonTrivialNodeCount = -1;
if (isValid()) {
invalidateCode();
Expand All @@ -519,7 +522,7 @@ public void invalidate(Object source, CharSequence reason) {
runtime().cancelInstalledTask(this, source, reason);
}

OptimizedCallTarget cloneUninitialized() {
final OptimizedCallTarget cloneUninitialized() {
assert sourceCallTarget == null;
if (compilationProfile == null) {
initialize();
Expand Down Expand Up @@ -547,12 +550,12 @@ public SpeculationLog getSpeculationLog() {
return speculationLog;
}

void setSpeculationLog(SpeculationLog speculationLog) {
final void setSpeculationLog(SpeculationLog speculationLog) {
this.speculationLog = speculationLog;
}

@Override
public JavaConstant asJavaConstant() {
public final JavaConstant asJavaConstant() {
return GraalTruffleRuntime.getRuntime().forObject(this);
}

Expand All @@ -562,12 +565,12 @@ static <E extends Throwable> RuntimeException rethrow(Throwable ex) throws E {
}

@Override
public void cancelInstalledTask() {
public final void cancelInstalledTask() {
runtime().cancelInstalledTask(this, null, "got inlined. callsite count: " + getKnownCallSiteCount());
}

@Override
public boolean isSameOrSplit(CompilableTruffleAST ast) {
public final boolean isSameOrSplit(CompilableTruffleAST ast) {
if (!(ast instanceof OptimizedCallTarget)) {
return false;
}
Expand All @@ -576,12 +579,12 @@ public boolean isSameOrSplit(CompilableTruffleAST ast) {
(this.sourceCallTarget != null && other.sourceCallTarget != null && this.sourceCallTarget == other.sourceCallTarget);
}

boolean cancelInstalledTask(Node source, CharSequence reason) {
final boolean cancelInstalledTask(Node source, CharSequence reason) {
return runtime().cancelInstalledTask(this, source, reason);
}

@Override
public void onCompilationFailed(Supplier<String> reasonAndStackTrace, boolean bailout, boolean permanentBailout) {
public final void onCompilationFailed(Supplier<String> reasonAndStackTrace, boolean bailout, boolean permanentBailout) {
if (bailout && !permanentBailout) {
/*
* Non-permanent bailouts are expected cases. A non-permanent bailout would be for
Expand Down Expand Up @@ -622,7 +625,7 @@ public final OptimizedCallTarget getSourceCallTarget() {
}

@Override
public String getName() {
public final String getName() {
CompilerAsserts.neverPartOfCompilation();
String result = nameCache;
if (result == null) {
Expand All @@ -633,7 +636,7 @@ public String getName() {
}

@Override
public String toString() {
public final String toString() {
CompilerAsserts.neverPartOfCompilation();
String superString = rootNode.toString();
if (isValid()) {
Expand All @@ -650,7 +653,7 @@ public String toString() {
*
* @param length the length of {@code args} that is guaranteed to be final at compile time
*/
static Object[] castArrayFixedLength(Object[] args, int length) {
static final Object[] castArrayFixedLength(Object[] args, int length) {
return args;
}

Expand Down Expand Up @@ -679,7 +682,7 @@ final void onLoopCount(int count) {
}

@Override
public boolean nodeReplaced(Node oldNode, Node newNode, CharSequence reason) {
public final boolean nodeReplaced(Node oldNode, Node newNode, CharSequence reason) {
CompilerAsserts.neverPartOfCompilation();
invalidate(newNode, reason);
/* Notify compiled method that have inlined this call target that the tree changed. */
Expand All @@ -689,20 +692,20 @@ public boolean nodeReplaced(Node oldNode, Node newNode, CharSequence reason) {
return false;
}

public void accept(NodeVisitor visitor, TruffleInlining inlingDecision) {
public final void accept(NodeVisitor visitor, TruffleInlining inlingDecision) {
if (inlingDecision != null) {
inlingDecision.accept(this, visitor);
} else {
getRootNode().accept(visitor);
}
}

public Iterable<Node> nodeIterable(TruffleInlining inliningDecision) {
public final Iterable<Node> nodeIterable(TruffleInlining inliningDecision) {
Iterator<Node> iterator = nodeIterator(inliningDecision);
return () -> iterator;
}

public Iterator<Node> nodeIterator(TruffleInlining inliningDecision) {
public final Iterator<Node> nodeIterator(TruffleInlining inliningDecision) {
Iterator<Node> iterator;
if (inliningDecision != null) {
iterator = inliningDecision.makeNodeIterator(this);
Expand All @@ -721,7 +724,7 @@ public final int getNonTrivialNodeCount() {
}

@Override
public int getCallCount() {
public final int getCallCount() {
OptimizedCompilationProfile profile = compilationProfile;
return profile == null ? 0 : profile.getCallCount(this);
}
Expand All @@ -732,15 +735,15 @@ public static int calculateNonTrivialNodes(Node node) {
return visitor.nodeCount;
}

public Map<String, Object> getDebugProperties(TruffleInlining inlining) {
public final Map<String, Object> getDebugProperties(TruffleInlining inlining) {
Map<String, Object> properties = new LinkedHashMap<>();
GraalTruffleRuntimeListener.addASTSizeProperty(this, inlining, properties);
properties.putAll(getCompilationProfile().getDebugProperties(this));
return properties;
}

@Override
public TruffleCallNode[] getCallNodes() {
public final TruffleCallNode[] getCallNodes() {
final List<OptimizedDirectCallNode> callNodes = new ArrayList<>();
getRootNode().accept(new NodeVisitor() {
@Override
Expand All @@ -754,7 +757,7 @@ public boolean visit(Node node) {
return callNodes.toArray(new TruffleCallNode[0]);
}

public CompilerOptions getCompilerOptions() {
public final CompilerOptions getCompilerOptions() {
final CompilerOptions options = rootNode.getCompilerOptions();
if (options != null) {
return options;
Expand All @@ -766,7 +769,7 @@ public final boolean isSplit() {
return sourceCallTarget != null;
}

public OptimizedDirectCallNode getCallSiteForSplit() {
public final OptimizedDirectCallNode getCallSiteForSplit() {
if (isSplit()) {
OptimizedDirectCallNode callNode = getSingleCallNode();
assert callNode != null;
Expand All @@ -776,7 +779,7 @@ public OptimizedDirectCallNode getCallSiteForSplit() {
}
}

int getUninitializedNodeCount() {
final int getUninitializedNodeCount() {
assert uninitializedNodeCount >= 0;
return uninitializedNodeCount;
}
Expand All @@ -803,7 +806,7 @@ public final int hashCode() {
return System.identityHashCode(this);
}

CancellableCompileTask getCompilationTask() {
final CancellableCompileTask getCompilationTask() {
return compilationTask;
}

Expand All @@ -813,7 +816,7 @@ CancellableCompileTask getCompilationTask() {
* It may only ever be called by the thread that performed the compilation, and after the
* compilation is completely done (either successfully or not successfully).
*/
public void resetCompilationTask() {
public final void resetCompilationTask() {
/*
* We synchronize because this is called from the compilation threads so we want to make
* sure we have finished setting the compilationTask in #compile. Otherwise
Expand All @@ -827,7 +830,7 @@ public void resetCompilationTask() {
}

@SuppressFBWarnings(value = "VO_VOLATILE_INCREMENT", justification = "All increments and decrements are synchronized.")
synchronized void addDirectCallNode(OptimizedDirectCallNode directCallNode) {
final synchronized void addDirectCallNode(OptimizedDirectCallNode directCallNode) {
Objects.requireNonNull(directCallNode);
WeakReference<OptimizedDirectCallNode> nodeRef = singleCallNode;
if (nodeRef != null) {
Expand All @@ -845,7 +848,7 @@ synchronized void addDirectCallNode(OptimizedDirectCallNode directCallNode) {
}

@SuppressFBWarnings(value = "VO_VOLATILE_INCREMENT", justification = "All increments and decrements are synchronized.")
synchronized void removeDirectCallNode(OptimizedDirectCallNode directCallNode) {
final synchronized void removeDirectCallNode(OptimizedDirectCallNode directCallNode) {
Objects.requireNonNull(directCallNode);
WeakReference<OptimizedDirectCallNode> nodeRef = singleCallNode;
if (nodeRef != null) {
Expand All @@ -863,27 +866,27 @@ synchronized void removeDirectCallNode(OptimizedDirectCallNode directCallNode) {
callSitesKnown--;
}

public boolean isSingleCaller() {
public final boolean isSingleCaller() {
WeakReference<OptimizedDirectCallNode> nodeRef = singleCallNode;
if (nodeRef != null) {
return nodeRef.get() != null;
}
return false;
}

public OptimizedDirectCallNode getSingleCallNode() {
public final OptimizedDirectCallNode getSingleCallNode() {
WeakReference<OptimizedDirectCallNode> nodeRef = singleCallNode;
if (nodeRef != null) {
return nodeRef.get();
}
return null;
}

boolean isNeedsSplit() {
final boolean isNeedsSplit() {
return needsSplit;
}

void polymorphicSpecialize(Node source) {
final void polymorphicSpecialize(Node source) {
List<Node> toDump = null;
if (engine.splittingDumpDecisions) {
toDump = new ArrayList<>();
Expand Down

0 comments on commit c290f73

Please sign in to comment.