6868import com .oracle .truffle .api .dsl .GenerateInline ;
6969import com .oracle .truffle .api .dsl .GenerateUncached ;
7070import com .oracle .truffle .api .dsl .ImportStatic ;
71- import com .oracle .truffle .api .dsl .NeverDefault ;
7271import com .oracle .truffle .api .dsl .Specialization ;
7372import com .oracle .truffle .api .frame .Frame ;
74- import com .oracle .truffle .api .library .CachedLibrary ;
7573import com .oracle .truffle .api .nodes .ExplodeLoop ;
7674import com .oracle .truffle .api .nodes .ExplodeLoop .LoopExplosionKind ;
7775import com .oracle .truffle .api .nodes .Node ;
7876import com .oracle .truffle .api .object .DynamicObject ;
79- import com .oracle .truffle .api .object .DynamicObjectLibrary ;
8077import com .oracle .truffle .api .object .Shape ;
78+ import com .oracle .truffle .api .profiles .InlinedBranchProfile ;
8179import com .oracle .truffle .api .profiles .InlinedConditionProfile ;
8280import com .oracle .truffle .api .strings .TruffleString ;
8381
@@ -277,8 +275,8 @@ private static boolean hasNext(Iterator<Object> keys) {
277275 }
278276 }
279277
280- void setStringKey (TruffleString key , Object value , DynamicObjectLibrary dylib ) {
281- dylib . put (store , key , assertNoJavaString (value ));
278+ void setStringKey (TruffleString key , Object value , DynamicObject . PutNode putNode ) {
279+ putNode . execute (store , key , assertNoJavaString (value ));
282280 }
283281
284282 boolean shouldTransitionOnPut () {
@@ -298,8 +296,8 @@ abstract static class ClearNode extends Node {
298296
299297 @ Specialization (guards = "!isPythonObject(receiver.getStore())" )
300298 static HashingStorage clearPlain (DynamicObjectStorage receiver ,
301- @ CachedLibrary ( limit = "3" ) DynamicObjectLibrary dylib ) {
302- dylib . resetShape (receiver .getStore (), PythonLanguage .get (dylib ).getEmptyShape ());
299+ @ Cached DynamicObject . ResetShapeNode resetShapeNode ) {
300+ resetShapeNode . execute (receiver .getStore (), PythonLanguage .get (resetShapeNode ).getEmptyShape ());
303301 return receiver ;
304302 }
305303
@@ -327,39 +325,12 @@ static HashingStorage clearObjectBacked(Node inliningTarget, DynamicObjectStorag
327325 abstract static class Copy extends Node {
328326 abstract DynamicObjectStorage execute (Node node , DynamicObjectStorage receiver );
329327
330- @ NeverDefault
331- static DynamicObjectLibrary [] createAccess (int length ) {
332- DynamicObjectLibrary [] result = new DynamicObjectLibrary [length ];
333- for (int i = 0 ; i < length ; i ++) {
334- result [i ] = DynamicObjectLibrary .getFactory ().createDispatched (1 );
335- }
336- return result ;
337- }
338-
339- @ ExplodeLoop
340- @ Specialization (limit = "1" , guards = {"cachedLength < EXPLODE_LOOP_SIZE_LIMIT" , "keys.length == cachedLength" })
328+ @ Specialization
341329 public static DynamicObjectStorage copy (DynamicObjectStorage receiver ,
342- @ SuppressWarnings ("unused" ) @ Bind ("receiver.store" ) DynamicObject store ,
343- @ SuppressWarnings ("unused" ) @ CachedLibrary ("store" ) DynamicObjectLibrary dylib ,
344- @ Bind ("dylib.getKeyArray(store)" ) Object [] keys ,
345- @ Cached (value = "keys.length" ) int cachedLength ,
346- @ Cached ("createAccess(cachedLength)" ) DynamicObjectLibrary [] readLib ,
347- @ Cached ("createAccess(cachedLength)" ) DynamicObjectLibrary [] writeLib ) {
348- DynamicObject copy = new Store (PythonLanguage .get (dylib ).getEmptyShape ());
349- for (int i = 0 ; i < cachedLength ; i ++) {
350- writeLib [i ].put (copy , keys [i ], readLib [i ].getOrDefault (receiver .store , keys [i ], PNone .NO_VALUE ));
351- }
352- return new DynamicObjectStorage (copy );
353- }
354-
355- @ Specialization (replaces = "copy" )
356- public static DynamicObjectStorage copyGeneric (DynamicObjectStorage receiver ,
357- @ CachedLibrary (limit = "3" ) DynamicObjectLibrary dylib ) {
358- DynamicObject copy = new Store (PythonLanguage .get (dylib ).getEmptyShape ());
359- Object [] keys = dylib .getKeyArray (receiver .store );
360- for (Object key : keys ) {
361- dylib .put (copy , key , dylib .getOrDefault (receiver .store , key , PNone .NO_VALUE ));
362- }
330+ @ Bind Node inliningTarget ,
331+ @ Cached DynamicObject .CopyPropertiesNode copyPropertiesNode ) {
332+ DynamicObject copy = new Store (PythonLanguage .get (inliningTarget ).getEmptyShape ());
333+ copyPropertiesNode .execute (receiver .store , copy );
363334 return new DynamicObjectStorage (copy );
364335 }
365336 }
@@ -369,9 +340,10 @@ public static DynamicObjectStorage copyGeneric(DynamicObjectStorage receiver,
369340 @ GenerateCached (false )
370341 public abstract static class DynamicObjectStorageSetStringKey extends SpecializedSetStringKey {
371342 @ Specialization
372- static void doIt (HashingStorage self , TruffleString key , Object value ,
373- @ CachedLibrary (limit = "3" ) DynamicObjectLibrary dylib ) {
374- ((DynamicObjectStorage ) self ).setStringKey (key , value , dylib );
343+ static void doIt (Node inliningTarget , HashingStorage self , TruffleString key , Object value ,
344+ @ Cached DynamicObject .PutNode putNode ,
345+ @ Cached InlinedBranchProfile invalidateMro ) {
346+ ((DynamicObjectStorage ) self ).setStringKey (key , value , putNode );
375347 }
376348 }
377349}
0 commit comments