Skip to content

Commit 03559ae

Browse files
committed
Reduce notRecordedProbability for artificial invoke profiles.
1 parent ece13fc commit 03559ae

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/results/StrengthenGraphs.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import jdk.graal.compiler.nodes.calc.IntegerEqualsNode;
6161
import jdk.graal.compiler.nodes.calc.IntegerLowerThanNode;
6262
import jdk.graal.compiler.nodes.calc.IsNullNode;
63+
import jdk.graal.compiler.nodes.extended.BranchProbabilityNode;
6364
import jdk.graal.compiler.nodes.extended.ValueAnchorNode;
6465
import jdk.graal.compiler.nodes.java.InstanceOfNode;
6566
import jdk.graal.compiler.nodes.java.LoadFieldNode;
@@ -322,7 +323,8 @@ protected JavaTypeProfile makeTypeProfile(TypeState typeState, boolean injectNot
322323
}
323324

324325
private JavaTypeProfile createTypeProfile(TypeState typeState, boolean injectNotRecordedProbability) {
325-
double probability = 1d / (typeState.typesCount() + (injectNotRecordedProbability ? 1 : 0));
326+
final double notRecordedProb = injectNotRecordedProbability ? BranchProbabilityNode.EXTREMELY_SLOW_PATH_PROBABILITY : 0.0d;
327+
final double probability = (1.0 - notRecordedProb) / typeState.typesCount();
326328

327329
Stream<? extends ResolvedJavaType> stream = typeState.typesStream(bb);
328330
if (converter != null) {
@@ -332,7 +334,7 @@ private JavaTypeProfile createTypeProfile(TypeState typeState, boolean injectNot
332334
.map(type -> new JavaTypeProfile.ProfiledType(type, probability))
333335
.toArray(JavaTypeProfile.ProfiledType[]::new);
334336

335-
return new JavaTypeProfile(TriState.get(typeState.canBeNull()), injectNotRecordedProbability ? probability : 0, pitems);
337+
return new JavaTypeProfile(TriState.get(typeState.canBeNull()), notRecordedProb, pitems);
336338
}
337339

338340
protected JavaMethodProfile makeMethodProfile(Collection<AnalysisMethod> callees, boolean injectNotRecordedProbability) {
@@ -347,15 +349,16 @@ protected JavaMethodProfile makeMethodProfile(Collection<AnalysisMethod> callees
347349
private CachedJavaMethodProfile createMethodProfile(Collection<AnalysisMethod> callees, boolean injectNotRecordedProbability) {
348350
JavaMethodProfile.ProfiledMethod[] pitems = new JavaMethodProfile.ProfiledMethod[callees.size()];
349351
int hashCode = 0;
350-
double probability = 1d / (pitems.length + (injectNotRecordedProbability ? 1 : 0));
352+
final double notRecordedProb = injectNotRecordedProbability ? BranchProbabilityNode.EXTREMELY_SLOW_PATH_PROBABILITY : 0.0d;
353+
final double probability = (1.0 - notRecordedProb) / pitems.length;
351354

352355
int idx = 0;
353356
for (AnalysisMethod aMethod : callees) {
354357
ResolvedJavaMethod convertedMethod = converter == null ? aMethod : converter.lookup(aMethod);
355358
pitems[idx++] = new JavaMethodProfile.ProfiledMethod(convertedMethod, probability);
356359
hashCode = hashCode * 31 + convertedMethod.hashCode();
357360
}
358-
return new CachedJavaMethodProfile(new JavaMethodProfile(injectNotRecordedProbability ? probability : 0, pitems), hashCode);
361+
return new CachedJavaMethodProfile(new JavaMethodProfile(notRecordedProb, pitems), hashCode);
359362
}
360363
}
361364

0 commit comments

Comments
 (0)