6969import com .oracle .truffle .api .nodes .ExplodeLoop ;
7070import com .oracle .truffle .api .nodes .Node ;
7171import com .oracle .truffle .api .nodes .UnexpectedResultException ;
72- import com .oracle .truffle .api .object .DynamicObjectLibraryImpl .RemovePlan ;
7372import com .oracle .truffle .api .object .DynamicObjectFactory .GetNodeGen ;
7473import com .oracle .truffle .api .object .DynamicObjectFactory .PutConstantNodeGen ;
7574import com .oracle .truffle .api .object .DynamicObjectFactory .PutNodeGen ;
75+ import com .oracle .truffle .api .object .DynamicObjectLibraryImpl .RemovePlan ;
7676
7777import sun .misc .Unsafe ;
7878
@@ -477,7 +477,7 @@ static long doCachedLong(DynamicObject receiver, Object key, Object defaultValue
477477 @ Cached ("key" ) Object cachedKey ,
478478 @ Cached ("cachedShape.getLocation(key)" ) Location cachedLocation ) throws UnexpectedResultException {
479479 if (cachedLocation != null ) {
480- return cachedLocation .getLong (receiver , guard );
480+ return cachedLocation .getLongInternal (receiver , cachedShape , guard );
481481 } else {
482482 return Location .expectLong (defaultValue );
483483 }
@@ -492,11 +492,7 @@ static int doCachedInt(DynamicObject receiver, Object key, Object defaultValue,
492492 @ Cached ("key" ) Object cachedKey ,
493493 @ Cached ("cachedShape.getLocation(key)" ) Location cachedLocation ) throws UnexpectedResultException {
494494 if (cachedLocation != null ) {
495- if (cachedLocation instanceof ExtLocations .IntArrayLocation intArrayLocation ) {
496- return intArrayLocation .getInt (receiver , guard );
497- } else {
498- return cachedLocation .getInt (receiver , guard );
499- }
495+ return cachedLocation .getIntInternal (receiver , cachedShape , guard );
500496 } else {
501497 return Location .expectInteger (defaultValue );
502498 }
@@ -511,7 +507,7 @@ static double doCachedDouble(DynamicObject receiver, Object key, Object defaultV
511507 @ Cached ("key" ) Object cachedKey ,
512508 @ Cached ("cachedShape.getLocation(key)" ) Location cachedLocation ) throws UnexpectedResultException {
513509 if (cachedLocation != null ) {
514- return cachedLocation .getDouble (receiver , guard );
510+ return cachedLocation .getDoubleInternal (receiver , cachedShape , guard );
515511 } else {
516512 return Location .expectDouble (defaultValue );
517513 }
@@ -526,43 +522,40 @@ static Object doCached(DynamicObject receiver, Object key, Object defaultValue,
526522 @ Cached ("key" ) Object cachedKey ,
527523 @ Cached ("cachedShape.getLocation(key)" ) Location cachedLocation ) {
528524 if (cachedLocation != null ) {
529- if (cachedLocation instanceof ExtLocations .ObjectArrayLocation objectArrayLocation ) {
530- return objectArrayLocation .get (receiver , guard );
531- } else if (cachedLocation instanceof ExtLocations .IntArrayLocation intArrayLocation ) {
532- return intArrayLocation .get (receiver , guard );
533- } else {
534- return cachedLocation .get (receiver , guard );
535- }
525+ return cachedLocation .getInternal (receiver , cachedShape , guard );
536526 } else {
537527 return defaultValue ;
538528 }
539529 }
540530
541531 @ Specialization (replaces = {"doCachedLong" , "doCachedInt" , "doCachedDouble" , "doCached" }, rewriteOn = UnexpectedResultException .class )
542532 static long doGenericLong (DynamicObject receiver , Object key , Object defaultValue ) throws UnexpectedResultException {
543- Location location = receiver .getShape ().getLocation (key );
533+ Shape shape = receiver .getShape ();
534+ Location location = shape .getLocation (key );
544535 if (location != null ) {
545- return location .getLong (receiver , false );
536+ return location .getLongInternal (receiver , shape , false );
546537 } else {
547538 return Location .expectLong (defaultValue );
548539 }
549540 }
550541
551542 @ Specialization (replaces = {"doCachedLong" , "doCachedInt" , "doCachedDouble" , "doCached" }, rewriteOn = UnexpectedResultException .class )
552543 static int doGenericInt (DynamicObject receiver , Object key , Object defaultValue ) throws UnexpectedResultException {
553- Location location = receiver .getShape ().getLocation (key );
544+ Shape shape = receiver .getShape ();
545+ Location location = shape .getLocation (key );
554546 if (location != null ) {
555- return location .getInt (receiver , false );
547+ return location .getIntInternal (receiver , shape , false );
556548 } else {
557549 return Location .expectInteger (defaultValue );
558550 }
559551 }
560552
561553 @ Specialization (replaces = {"doCachedLong" , "doCachedInt" , "doCachedDouble" , "doCached" }, rewriteOn = UnexpectedResultException .class )
562554 static double doGenericDouble (DynamicObject receiver , Object key , Object defaultValue ) throws UnexpectedResultException {
563- Location location = receiver .getShape ().getLocation (key );
555+ Shape shape = receiver .getShape ();
556+ Location location = shape .getLocation (key );
564557 if (location != null ) {
565- return location .getDouble (receiver , false );
558+ return location .getDoubleInternal (receiver , shape , false );
566559 } else {
567560 return Location .expectDouble (defaultValue );
568561 }
@@ -571,9 +564,10 @@ static double doGenericDouble(DynamicObject receiver, Object key, Object default
571564 @ TruffleBoundary
572565 @ Specialization (replaces = {"doCachedLong" , "doCachedInt" , "doCachedDouble" , "doCached" , "doGenericLong" , "doGenericInt" , "doGenericDouble" })
573566 static Object doGeneric (DynamicObject receiver , Object key , Object defaultValue ) {
574- Location location = receiver .getShape ().getLocation (key );
567+ Shape shape = receiver .getShape ();
568+ Location location = shape .getLocation (key );
575569 if (location != null ) {
576- return location .get (receiver , false );
570+ return location .getInternal (receiver , shape , false );
577571 } else {
578572 return defaultValue ;
579573 }
@@ -712,7 +706,7 @@ public final boolean putWithFlagsIfAbsent(DynamicObject receiver, Object key, Ob
712706 "key == cachedKey" ,
713707 "mode == cachedMode" ,
714708 "propertyFlags == cachedPropertyFlags" ,
715- "newLocation == null || canStore( newLocation, value)" ,
709+ "newLocation == null || newLocation.canStoreValue( value)" ,
716710 }, assumptions = "newShapeValidAssumption" , limit = "SHAPE_CACHE_LIMIT" )
717711 static boolean doCached (DynamicObject receiver , Object key , Object value , int mode , int propertyFlags ,
718712 @ Bind ("receiver.getShape()" ) Shape shape ,
@@ -734,18 +728,9 @@ static boolean doCached(DynamicObject receiver, Object key, Object value, int mo
734728 if ((mode & Flags .IF_ABSENT ) != 0 ) {
735729 return true ;
736730 } else {
737- boolean addingNewProperty = newShape != oldShape ;
738- if (addingNewProperty ) {
739- DynamicObjectSupport .grow (receiver , oldShape , newShape );
740- }
731+ newLocation .setInternal (receiver , value , guard , oldShape , newShape );
741732
742- if (newLocation instanceof ExtLocations .ObjectArrayLocation objectArrayLocation ) {
743- objectArrayLocation .set (receiver , value , guard , addingNewProperty );
744- } else {
745- newLocation .set (receiver , value , guard , addingNewProperty );
746- }
747-
748- if (addingNewProperty ) {
733+ if (newShape != oldShape ) {
749734 DynamicObjectSupport .setShapeWithStoreFence (receiver , newShape );
750735 }
751736 return true ;
@@ -903,7 +888,7 @@ public final boolean putConstantWithFlagsIfAbsent(DynamicObject receiver, Object
903888 "key == cachedKey" ,
904889 "mode == cachedMode" ,
905890 "propertyFlags == cachedPropertyFlags" ,
906- "newLocation == null || canStore( newLocation, value)" ,
891+ "newLocation == null || newLocation.canStoreConstant( value)" ,
907892 }, assumptions = "newShapeValidAssumption" , limit = "SHAPE_CACHE_LIMIT" )
908893 static boolean doCached (DynamicObject receiver , Object key , Object value , int mode , int propertyFlags ,
909894 @ Bind ("receiver.getShape()" ) Shape shape ,
@@ -925,18 +910,7 @@ static boolean doCached(DynamicObject receiver, Object key, Object value, int mo
925910 if ((mode & Flags .IF_ABSENT ) != 0 ) {
926911 return true ;
927912 } else {
928- boolean addingNewProperty = newShape != oldShape ;
929- if (addingNewProperty ) {
930- DynamicObjectSupport .grow (receiver , oldShape , newShape );
931- }
932-
933- if (newLocation instanceof ExtLocations .ObjectArrayLocation objectArrayLocation ) {
934- objectArrayLocation .set (receiver , value , guard , addingNewProperty );
935- } else {
936- newLocation .set (receiver , value , guard , addingNewProperty );
937- }
938-
939- if (addingNewProperty ) {
913+ if (newShape != oldShape ) {
940914 DynamicObjectSupport .setShapeWithStoreFence (receiver , newShape );
941915 }
942916 return true ;
@@ -962,10 +936,6 @@ static boolean doGeneric(DynamicObject receiver, Object key, Object value, int m
962936
963937 }
964938
965- static boolean canStore (Location newLocation , Object value ) {
966- return newLocation instanceof ExtLocations .AbstractObjectLocation || newLocation .canStore (value );
967- }
968-
969939 static Shape getNewShape (Object cachedKey , Object value , int newPropertyFlags , int putFlags , Property existingProperty , Shape oldShape ) {
970940 if (existingProperty == null ) {
971941 if ((putFlags & Flags .IF_PRESENT ) != 0 ) {
0 commit comments