src/share/vm/prims/unsafe.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Cdiff src/share/vm/prims/unsafe.cpp

src/share/vm/prims/unsafe.cpp

Print this page
rev 9908 : [mq]: unsafecopyswap

*** 1,7 **** /* ! * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 658,667 **** --- 658,731 ---- 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 + // This function is a leaf since if the source and destination are both in native memory + // the copy may potentially be very large, and we don't want to disable GC if we can avoid it. + // If either source or destination (or both) are on the heap, the function will enter VM using + // JVM_ENTRY_FROM_LEAF + JVM_LEAF(void, Unsafe_CopySwapMemory(JNIEnv *env, jobject unsafe, jobject srcObj, jlong srcOffset, jobject dstObj, jlong dstOffset, jlong size, jlong elemSize)) + UnsafeWrapper("Unsafe_CopySwapMemory"); + if (size == 0) { + return; + } + + size_t sz = (size_t)size; + if (sz != (julong)size || size < 0) { + JVM_ENTRY_FROM_LEAF(env, void, Unsafe_CopySwapMemory) { + THROW(vmSymbols::java_lang_IllegalArgumentException()); + } JVM_END + } + + size_t esz = (size_t)elemSize; + if (esz != 2 && esz != 4 && esz != 8) { + JVM_ENTRY_FROM_LEAF(env, void, Unsafe_CopySwapMemory) { + THROW(vmSymbols::java_lang_IllegalArgumentException()); + } JVM_END + } + + if (!is_size_aligned(sz, esz)) { + JVM_ENTRY_FROM_LEAF(env, void, Unsafe_CopySwapMemory) { + THROW(vmSymbols::java_lang_IllegalArgumentException()); + } JVM_END + } + + if (srcObj == NULL && dstObj == NULL) { + // Both src & dst are in native memory + address src = (address)srcOffset; + address dst = (address)dstOffset; + + if (src == NULL || dst == NULL) { + JVM_ENTRY_FROM_LEAF(env, void, Unsafe_CopySwapMemory) { + THROW(vmSymbols::java_lang_NullPointerException()); + } JVM_END + } + + Copy::conjoint_swap(src, dst, sz, esz); + } else { + // At least one of src/dst are on heap, transition to VM to access raw pointers + + JVM_ENTRY_FROM_LEAF(env, void, Unsafe_CopySwapMemory) { + 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()); + } + + address src = (address)index_oop_from_field_offset_long(srcp, srcOffset); + address dst = (address)index_oop_from_field_offset_long(dstp, dstOffset); + + Copy::conjoint_swap(src, dst, sz, esz); + } JVM_END + } + JVM_END + ////// Random queries // See comment at file start about UNSAFE_LEAF //UNSAFE_LEAF(jint, Unsafe_AddressSize())
*** 1361,1370 **** --- 1425,1435 ---- {CC "unpark", CC "(" OBJ ")V", FN_PTR(Unsafe_Unpark)}, {CC "getLoadAverage", CC "([DI)I", FN_PTR(Unsafe_Loadavg)}, {CC "copyMemory", CC "(" OBJ "J" OBJ "JJ)V", FN_PTR(Unsafe_CopyMemory)}, + {CC "copySwapMemory", CC "(" OBJ "J" OBJ "JJJ)V", FN_PTR(Unsafe_CopySwapMemory)}, {CC "setMemory", CC "(" OBJ "JJB)V", FN_PTR(Unsafe_SetMemory)}, {CC "defineAnonymousClass", CC "(" DAC_Args ")" CLS, FN_PTR(Unsafe_DefineAnonymousClass)}, {CC "shouldBeInitialized",CC "(" CLS ")Z", FN_PTR(Unsafe_ShouldBeInitialized)},
src/share/vm/prims/unsafe.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File