public static Object copyIfNeeded(@Unretained Object v, InternalCache cache) {
    if (v instanceof StoredObject) {
      @Unretained
      StoredObject ohv = (StoredObject) v;
      if (ohv.isSerialized()) {
        v = CachedDeserializableFactory.create(ohv.getSerializedValue(), cache);
      } else {
        // it is a byte[]
        v = ohv.getDeserializedForReading();
      }
    }
    return v;
  }
If v is on heap then just return v; no copy needed. Else v is off-heap so copy it to heap and
return a reference to the heap copy. Note that unlike {@link #getHeapForm(Object)} if v is a
serialized off-heap object it will be copied to the heap as a CachedDeserializable. If you
prefer to have the serialized object also deserialized and copied to the heap use
{@link #getHeapForm(Object)}.

@param v possible OFF_HEAP_REFERENCE
@return v or a heap copy of v
geode-core/src/main/java/org/apache/geode/internal/offheap/OffHeapHelper.java