10
10
package org .truffleruby .extra ;
11
11
12
12
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
13
- import com .oracle .truffle .api .dsl .Bind ;
14
13
import com .oracle .truffle .api .dsl .Cached ;
15
- import com .oracle .truffle .api .dsl .Cached .Exclusive ;
16
14
import com .oracle .truffle .api .dsl .Specialization ;
17
- import com .oracle .truffle .api .nodes .Node ;
18
15
import com .oracle .truffle .api .object .Shape ;
19
16
import com .oracle .truffle .api .profiles .InlinedConditionProfile ;
20
17
import org .truffleruby .annotations .CoreMethod ;
31
28
import org .truffleruby .extra .AtomicReferenceNodes .CompareAndSetReferenceNode ;
32
29
import org .truffleruby .extra .RubyConcurrentMap .Key ;
33
30
import org .truffleruby .annotations .Visibility ;
31
+ import org .truffleruby .language .RubyGuards ;
34
32
import org .truffleruby .language .objects .AllocationTracing ;
35
33
import org .truffleruby .language .yield .CallBlockNode ;
36
34
39
37
import java .util .concurrent .ConcurrentHashMap ;
40
38
import java .util .function .BiFunction ;
41
39
42
- import static org .truffleruby .language .RubyGuards .isPrimitive ;
43
-
44
40
@ CoreModule (value = "TruffleRuby::ConcurrentMap" , isClass = true )
45
41
public class ConcurrentMapNodes {
46
42
@@ -202,7 +198,7 @@ protected boolean replacePair(RubyConcurrentMap self, Object key, Object expecte
202
198
@ Cached InlinedConditionProfile isPrimitiveProfile ) {
203
199
final int hashCode = hashNode .execute (this , key );
204
200
205
- if (isPrimitiveProfile .profile (this , isPrimitive (expectedValue ))) {
201
+ if (isPrimitiveProfile .profile (this , RubyGuards . isPrimitive (expectedValue ))) {
206
202
return replacePairPrimitive (self , key , expectedValue , newValue , hashCode , equalNode );
207
203
} else {
208
204
return replace (self .getMap (), new Key (key , hashCode ), expectedValue , newValue );
@@ -216,7 +212,7 @@ private boolean replacePairPrimitive(RubyConcurrentMap self, Object key, Object
216
212
while (true ) {
217
213
final Object currentValue = get (self .getMap (), keyWrapper );
218
214
219
- if (isPrimitive (currentValue ) &&
215
+ if (RubyGuards . isPrimitive (currentValue ) &&
220
216
equalNode .execute (expectedValue , currentValue )) {
221
217
if (replace (self .getMap (), keyWrapper , currentValue , newValue )) {
222
218
return true ;
@@ -236,11 +232,23 @@ private static boolean replace(ConcurrentHashMap<Key, Object> map, Key key, Obje
236
232
@ CoreMethod (names = "delete_pair" , required = 2 )
237
233
public abstract static class DeletePairNode extends CoreMethodArrayArgumentsNode {
238
234
/** See {@link CompareAndSetReferenceNode} */
239
- @ Specialization (guards = "isPrimitive(expectedValue)" )
240
- protected boolean deletePairPrimitive (RubyConcurrentMap self , Object key , Object expectedValue ,
241
- @ Exclusive @ Cached ToHashByHashCode hashNode ,
242
- @ Cached ReferenceEqualNode equalNode ) {
235
+ @ Specialization
236
+ protected boolean deletePair (RubyConcurrentMap self , Object key , Object expectedValue ,
237
+ @ Cached ToHashByHashCode hashNode ,
238
+ @ Cached ReferenceEqualNode equalNode ,
239
+ @ Cached InlinedConditionProfile isPrimitiveProfile ) {
240
+
243
241
final int hashCode = hashNode .execute (this , key );
242
+
243
+ if (isPrimitiveProfile .profile (this , RubyGuards .isPrimitive (expectedValue ))) {
244
+ return deletePairPrimitive (self , key , expectedValue , hashCode , equalNode );
245
+ } else {
246
+ return remove (self .getMap (), new Key (key , hashCode ), expectedValue );
247
+ }
248
+ }
249
+
250
+ private boolean deletePairPrimitive (RubyConcurrentMap self , Object key , Object expectedValue , int hashCode ,
251
+ ReferenceEqualNode equalNode ) {
244
252
final Key keyWrapper = new Key (key , hashCode );
245
253
246
254
while (true ) {
@@ -257,14 +265,6 @@ protected boolean deletePairPrimitive(RubyConcurrentMap self, Object key, Object
257
265
}
258
266
}
259
267
260
- @ Specialization (guards = "!isPrimitive(expectedValue)" )
261
- protected static boolean deletePair (RubyConcurrentMap self , Object key , Object expectedValue ,
262
- @ Exclusive @ Cached ToHashByHashCode hashNode ,
263
- @ Bind ("this" ) Node node ) {
264
- final int hashCode = hashNode .execute (node , key );
265
- return remove (self .getMap (), new Key (key , hashCode ), expectedValue );
266
- }
267
-
268
268
@ TruffleBoundary
269
269
private static boolean remove (ConcurrentHashMap <Key , Object > map , Key key , Object expectedValue ) {
270
270
return map .remove (key , expectedValue );
0 commit comments