25
25
package com .oracle .svm .core .identityhashcode ;
26
26
27
27
import static org .graalvm .compiler .nodes .extended .BranchProbabilityNode .LIKELY_PROBABILITY ;
28
- import static org .graalvm .compiler .nodes .extended .BranchProbabilityNode .NOT_FREQUENT_PROBABILITY ;
29
28
import static org .graalvm .compiler .nodes .extended .BranchProbabilityNode .SLOW_PATH_PROBABILITY ;
30
29
import static org .graalvm .compiler .nodes .extended .BranchProbabilityNode .probability ;
31
30
@@ -52,6 +51,9 @@ final class SubstrateIdentityHashCodeSnippets extends IdentityHashCodeSnippets {
52
51
static final SubstrateForeignCallDescriptor GENERATE_IDENTITY_HASH_CODE = SnippetRuntime .findForeignCall (
53
52
IdentityHashCodeSupport .class , "generateIdentityHashCode" , true , IdentityHashCodeSupport .IDENTITY_HASHCODE_LOCATION );
54
53
54
+ static final SubstrateForeignCallDescriptor COMPUTE_ABSENT_IDENTITY_HASH_CODE = SnippetRuntime .findForeignCall (
55
+ IdentityHashCodeSupport .class , "computeAbsentIdentityHashCode" , true );
56
+
55
57
static Templates createTemplates (OptionValues options , Providers providers ) {
56
58
return new Templates (new SubstrateIdentityHashCodeSnippets (), options , providers , IdentityHashCodeSupport .IDENTITY_HASHCODE_LOCATION );
57
59
}
@@ -64,26 +66,21 @@ protected int computeIdentityHashCode(Object obj) {
64
66
int offset = ol .getFixedIdentityHashOffset ();
65
67
identityHashCode = ObjectAccess .readInt (obj , offset , IdentityHashCodeSupport .IDENTITY_HASHCODE_LOCATION );
66
68
if (probability (SLOW_PATH_PROBABILITY , identityHashCode == 0 )) {
67
- identityHashCode = generateIdentityHashCode (GENERATE_IDENTITY_HASH_CODE , obj );
69
+ identityHashCode = foreignCall (GENERATE_IDENTITY_HASH_CODE , obj );
68
70
}
69
71
return identityHashCode ;
70
72
}
71
73
ObjectHeader oh = Heap .getHeap ().getObjectHeader ();
72
- Word objPtr = Word .objectToUntrackedPointer (obj );
73
- Word header = ObjectHeader .readHeaderFromPointer (objPtr );
74
+ Word header = ObjectHeader .readHeaderFromObject (obj );
74
75
if (probability (LIKELY_PROBABILITY , oh .hasOptionalIdentityHashField (header ))) {
75
76
int offset = LayoutEncoding .getOptionalIdentityHashOffset (obj );
76
77
identityHashCode = ObjectAccess .readInt (obj , offset , IdentityHashCodeSupport .IDENTITY_HASHCODE_LOCATION );
77
78
} else {
78
- identityHashCode = IdentityHashCodeSupport .computeHashCodeFromAddress (obj );
79
- if (probability (NOT_FREQUENT_PROBABILITY , !oh .hasIdentityHashFromAddress (header ))) {
80
- // Note this write leads to frame state issues that break scheduling if done earlier
81
- oh .setIdentityHashFromAddress (objPtr , header );
82
- }
79
+ identityHashCode = foreignCall (COMPUTE_ABSENT_IDENTITY_HASH_CODE , obj );
83
80
}
84
81
return identityHashCode ;
85
82
}
86
83
87
84
@ NodeIntrinsic (ForeignCallNode .class )
88
- private static native int generateIdentityHashCode (@ ConstantNodeParameter ForeignCallDescriptor descriptor , Object obj );
85
+ private static native int foreignCall (@ ConstantNodeParameter ForeignCallDescriptor descriptor , Object obj );
89
86
}
0 commit comments