Why we can't use Unsafe.copyMemory() with Objects as dest ?

Rémi Forax forax at univ-mlv.fr
Mon Mar 12 07:37:18 PDT 2012


On 03/12/2012 02:09 PM, Andrew Kondratovich wrote:
> This is source of unsafe.cpp:
>
> UNSAFE_ENTRY(void, Unsafe_CopyMemory2(JNIEnv *env, jobject unsafe,
> jobject srcObj, jlong srcOffset, jobject dstObj, jlong dstOffset,
> jlong size))
>    UnsafeWrapper("Unsafe_CopyMemory");
>    if (size == 0) {
>      return;
>    }
>    size_t sz = (size_t)size;
>    if (sz != (julong)size || size<  0) {
>      THROW(vmSymbols::java_lang_IllegalArgumentException());
>    }
>    oop srcp = JNIHandles::resolve(srcObj);
>    oop dstp = JNIHandles::resolve(dstObj);
>    if (dstp != NULL&&  !dstp->is_typeArray()) {
>      // NYI:  This works only for non-oop arrays at present.
>      // Generalizing it would be reasonable, but requires card marking.
>      // Also, autoboxing a Long from 0L in copyMemory(x,y, 0L,z, n) would be bad.
>      THROW(vmSymbols::java_lang_IllegalArgumentException());
>    }
>    void* src = index_oop_from_field_offset_long(srcp, srcOffset);
>    void* dst = index_oop_from_field_offset_long(dstp, dstOffset);
>    Copy::conjoint_memory_atomic(src, dst, sz);
> UNSAFE_END
>
> Why is it allowed to copy memory only to primitive arrays as destination ?

See the comment that starts with NIY (not yet implemented),
basically a generational GC needs to keep references between generations
which is know as card marking in Hotspot.

see this link for some basic intro:
http://www.ibm.com/developerworks/java/library/j-jtp11253/

>
> Thanks.
>
> -- Andrew


cheers,
Rémi



More information about the hotspot-runtime-dev mailing list