diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RAttributesLayout.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RAttributesLayout.java index ef5fb88f7cb06c6a13dc38ee7dccb3fecb069b6f..6245346502eefc5ea5f4f06ac514c3bfb18b58f1 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RAttributesLayout.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RAttributesLayout.java @@ -146,7 +146,21 @@ public final class RAttributesLayout { public static DynamicObject copy(DynamicObject attrs) { assert isRAttributes(attrs); - return attrs.copy(attrs.getShape()); + DynamicObject result = attrs.copy(attrs.getShape()); + Shape shape = result.getShape(); + Property prop = shape.getLastProperty(); + while (prop != null) { + Object value = result.get(prop.getKey()); + if (value instanceof RSharingAttributeStorage) { + // There is no simple way to determine the correct reference count here and since + // the value will end up in two attributes collections, it will end up being shared + // most likely anyway. + ((RSharingAttributeStorage) value).makeSharedPermanent(); + } + shape = shape.getParent(); + prop = shape.getLastProperty(); + } + return result; } @TruffleBoundary