@@ -1186,30 +1186,34 @@ protected T rewriteCached(T currentHead, T newHead) {
11861186 }
11871187
11881188 /**
1189- * Does the given map relate to any of the cached maps by upcasting? If so, obsolete the
1190- * downcast map.
1189+ * Tries to merge the object's shape with any related shape in the cache to a more general shape
1190+ * that has the same properties but can store the values of both shapes. For example, a shape
1191+ * {@code {x: int}} could be merged with, and obsoleted by, a shape {@code {x: Object}}.
11911192 *
1192- * @param cacheShape The new map to check against
1193- * @return true if a map was obsoleted
1193+ * @param objShape the new shape that would be inserted into the cache
1194+ * @return true if a shape was obsoleted
11941195 */
1195- protected static <T extends CacheNode <T >> boolean tryMergeShapes (Shape cacheShape , T head ) {
1196- assert cacheShape .isValid ();
1197- boolean result = false ;
1198-
1196+ protected static <T extends CacheNode <T >> boolean tryMergeShapes (Shape objShape , T head ) {
1197+ if (!objShape .isValid ()) {
1198+ return false ;
1199+ }
1200+ boolean merged = false ;
11991201 for (T cur = head ; cur != null ; cur = cur .getNext ()) {
12001202 if (cur .receiverCheck == null ) {
12011203 continue ;
12021204 }
12031205 Shape other = cur .receiverCheck .getShape ();
1204- if (cacheShape != other && other != null && other .isValid ()) {
1205- assert cacheShape .isValid ();
1206- result |= cacheShape .tryMerge (other ) != null ;
1207- if (!cacheShape .isValid ()) {
1208- break ;
1206+ if (objShape != other && other != null && other .isValid ()) {
1207+ Shape mergedShape = objShape .tryMerge (other );
1208+ if (mergedShape != null ) {
1209+ merged = true ;
1210+ if (!objShape .isValid ()) {
1211+ break ;
1212+ }
12091213 }
12101214 }
12111215 }
1212- return result ;
1216+ return merged ;
12131217 }
12141218
12151219 protected void checkForUnstableAssumption (T head , Object thisObj ) {
0 commit comments