@Override
    public CopyOnWriteContent clone() {
        if (isEmpty()) return new CopyOnWriteContent(); // No referencing is necessary in this case
        if (isDeepUnmodifiable(unmodifiableMap())) {
            // Create an instance pointing to this and put both in the COPYONWRITE state
            unmodifiableMap(); // Make sure we have an unmodifiable reference to the map below
            map=null; // Put this into the COPYONWRITE state (unless it is already frozen, in which case this is a noop)
            return createInCopyOnWriteState(unmodifiableMap());
        }
        else {
            // This contains query profiles, don't try to defer copying
            return createInWritableState(deepClone(map));
        }
    }
Create a WRITABLE instance with some initial state
container-search/src/main/java/com/yahoo/search/query/profile/CopyOnWriteContent.java