5050import com .oracle .truffle .api .library .ExportMessage ;
5151import com .oracle .truffle .api .nodes .Node ;
5252import com .oracle .truffle .api .object .Shape ;
53+ import com .oracle .truffle .api .profiles .InlinedBranchProfile ;
5354import com .oracle .truffle .api .source .SourceSection ;
5455
5556@ SuppressWarnings ("truffle-abstract-export" )
@@ -115,7 +116,7 @@ public boolean hasSourceLocation() {
115116
116117 @ ExportMessage
117118 public boolean isArrayElementModifiable (long index ,
118- @ Cached . Exclusive @ Cached IndexNodes .NormalizeIndexCustomMessageNode normalize ,
119+ @ Exclusive @ Cached IndexNodes .NormalizeIndexCustomMessageNode normalize ,
119120 @ Exclusive @ Cached GilNode gil ) {
120121 boolean mustRelease = gil .acquire ();
121122 try {
@@ -145,7 +146,7 @@ public boolean isArrayElementInsertable(long index,
145146
146147 @ ExportMessage
147148 public boolean isArrayElementRemovable (long index ,
148- @ Cached . Exclusive @ Cached IndexNodes .NormalizeIndexCustomMessageNode normalize ,
149+ @ Exclusive @ Cached IndexNodes .NormalizeIndexCustomMessageNode normalize ,
149150 @ Exclusive @ Cached GilNode gil ) {
150151 boolean mustRelease = gil .acquire ();
151152 try {
@@ -165,17 +166,24 @@ public boolean isArrayElementRemovable(long index,
165166 public void writeArrayElement (long index , Object value ,
166167 @ Bind ("$node" ) Node inliningTarget ,
167168 @ Cached PForeignToPTypeNode convert ,
168- @ Cached . Exclusive @ Cached SequenceStorageNodes .SetItemScalarNode setItem ,
169+ @ Exclusive @ Cached SequenceStorageNodes .SetItemScalarGeneralizingNode setItem ,
169170 @ Cached SequenceStorageNodes .AppendNode appendNode ,
171+ @ Cached InlinedBranchProfile generalizedProfile ,
170172 @ Exclusive @ Cached GilNode gil ) throws InvalidArrayIndexException {
171173 boolean mustRelease = gil .acquire ();
172174 try {
173175 final int len = store .length ();
176+ value = convert .executeConvert (value );
174177 try {
178+ SequenceStorage newStorage ;
175179 if (index == len ) {
176- appendNode .execute (inliningTarget , store , convert . executeConvert ( value ) , SequenceStorageNodes .ListGeneralizationNode .SUPPLIER );
180+ newStorage = appendNode .execute (inliningTarget , store , value , SequenceStorageNodes .ListGeneralizationNode .SUPPLIER );
177181 } else {
178- setItem .execute (inliningTarget , store , PInt .intValueExact (index ), convert .executeConvert (value ));
182+ newStorage = setItem .execute (inliningTarget , store , PInt .intValueExact (index ), value , SequenceStorageNodes .ListGeneralizationNode .SUPPLIER );
183+ }
184+ if (newStorage != store ) {
185+ generalizedProfile .enter (inliningTarget );
186+ store = newStorage ;
179187 }
180188 } catch (OverflowException e ) {
181189 CompilerDirectives .transferToInterpreterAndInvalidate ();
0 commit comments