Why we can't use Unsafe.copyMemory() with Objects as dest ?
Andrew Kondratovich
andrew.kondratovich at gmail.com
Mon Mar 12 06:09:25 PDT 2012
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 ?
Thanks.
-- Andrew
More information about the hotspot-runtime-dev
mailing list