60
60
import jdk .graal .compiler .nodes .calc .IntegerEqualsNode ;
61
61
import jdk .graal .compiler .nodes .calc .IntegerLowerThanNode ;
62
62
import jdk .graal .compiler .nodes .calc .IsNullNode ;
63
+ import jdk .graal .compiler .nodes .extended .BranchProbabilityNode ;
63
64
import jdk .graal .compiler .nodes .extended .ValueAnchorNode ;
64
65
import jdk .graal .compiler .nodes .java .InstanceOfNode ;
65
66
import jdk .graal .compiler .nodes .java .LoadFieldNode ;
@@ -322,7 +323,8 @@ protected JavaTypeProfile makeTypeProfile(TypeState typeState, boolean injectNot
322
323
}
323
324
324
325
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 ();
326
328
327
329
Stream <? extends ResolvedJavaType > stream = typeState .typesStream (bb );
328
330
if (converter != null ) {
@@ -332,7 +334,7 @@ private JavaTypeProfile createTypeProfile(TypeState typeState, boolean injectNot
332
334
.map (type -> new JavaTypeProfile .ProfiledType (type , probability ))
333
335
.toArray (JavaTypeProfile .ProfiledType []::new );
334
336
335
- return new JavaTypeProfile (TriState .get (typeState .canBeNull ()), injectNotRecordedProbability ? probability : 0 , pitems );
337
+ return new JavaTypeProfile (TriState .get (typeState .canBeNull ()), notRecordedProb , pitems );
336
338
}
337
339
338
340
protected JavaMethodProfile makeMethodProfile (Collection <AnalysisMethod > callees , boolean injectNotRecordedProbability ) {
@@ -347,15 +349,16 @@ protected JavaMethodProfile makeMethodProfile(Collection<AnalysisMethod> callees
347
349
private CachedJavaMethodProfile createMethodProfile (Collection <AnalysisMethod > callees , boolean injectNotRecordedProbability ) {
348
350
JavaMethodProfile .ProfiledMethod [] pitems = new JavaMethodProfile .ProfiledMethod [callees .size ()];
349
351
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 ;
351
354
352
355
int idx = 0 ;
353
356
for (AnalysisMethod aMethod : callees ) {
354
357
ResolvedJavaMethod convertedMethod = converter == null ? aMethod : converter .lookup (aMethod );
355
358
pitems [idx ++] = new JavaMethodProfile .ProfiledMethod (convertedMethod , probability );
356
359
hashCode = hashCode * 31 + convertedMethod .hashCode ();
357
360
}
358
- return new CachedJavaMethodProfile (new JavaMethodProfile (injectNotRecordedProbability ? probability : 0 , pitems ), hashCode );
361
+ return new CachedJavaMethodProfile (new JavaMethodProfile (notRecordedProb , pitems ), hashCode );
359
362
}
360
363
}
361
364
0 commit comments