1 /*
2 * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
643 if (size == 0) {
644 return;
645 }
646 size_t sz = (size_t)size;
647 if (sz != (julong)size || size < 0) {
648 THROW(vmSymbols::java_lang_IllegalArgumentException());
649 }
650 oop srcp = JNIHandles::resolve(srcObj);
651 oop dstp = JNIHandles::resolve(dstObj);
652 if (dstp != NULL && !dstp->is_typeArray()) {
653 // NYI: This works only for non-oop arrays at present.
654 // Generalizing it would be reasonable, but requires card marking.
655 // Also, autoboxing a Long from 0L in copyMemory(x,y, 0L,z, n) would be bad.
656 THROW(vmSymbols::java_lang_IllegalArgumentException());
657 }
658 void* src = index_oop_from_field_offset_long(srcp, srcOffset);
659 void* dst = index_oop_from_field_offset_long(dstp, dstOffset);
660 Copy::conjoint_memory_atomic(src, dst, sz);
661 UNSAFE_END
662
663
664 ////// Random queries
665
666 // See comment at file start about UNSAFE_LEAF
667 //UNSAFE_LEAF(jint, Unsafe_AddressSize())
668 UNSAFE_ENTRY(jint, Unsafe_AddressSize(JNIEnv *env, jobject unsafe))
669 UnsafeWrapper("Unsafe_AddressSize");
670 return sizeof(void*);
671 UNSAFE_END
672
673 // See comment at file start about UNSAFE_LEAF
674 //UNSAFE_LEAF(jint, Unsafe_PageSize())
675 UNSAFE_ENTRY(jint, Unsafe_PageSize(JNIEnv *env, jobject unsafe))
676 UnsafeWrapper("Unsafe_PageSize");
677 return os::vm_page_size();
678 UNSAFE_END
679
680 jint find_field_offset(jobject field, int must_be_static, TRAPS) {
681 if (field == NULL) {
682 THROW_0(vmSymbols::java_lang_NullPointerException());
1346 {CC "arrayBaseOffset", CC "(" CLS ")I", FN_PTR(Unsafe_ArrayBaseOffset)},
1347 {CC "arrayIndexScale", CC "(" CLS ")I", FN_PTR(Unsafe_ArrayIndexScale)},
1348 {CC "addressSize", CC "()I", FN_PTR(Unsafe_AddressSize)},
1349 {CC "pageSize", CC "()I", FN_PTR(Unsafe_PageSize)},
1350
1351 {CC "defineClass", CC "(" DC_Args ")" CLS, FN_PTR(Unsafe_DefineClass)},
1352 {CC "allocateInstance", CC "(" CLS ")" OBJ, FN_PTR(Unsafe_AllocateInstance)},
1353 {CC "throwException", CC "(" THR ")V", FN_PTR(Unsafe_ThrowException)},
1354 {CC "compareAndSwapObject", CC "(" OBJ "J" OBJ "" OBJ ")Z", FN_PTR(Unsafe_CompareAndSwapObject)},
1355 {CC "compareAndSwapInt", CC "(" OBJ "J""I""I"")Z", FN_PTR(Unsafe_CompareAndSwapInt)},
1356 {CC "compareAndSwapLong", CC "(" OBJ "J""J""J"")Z", FN_PTR(Unsafe_CompareAndSwapLong)},
1357 {CC "putOrderedObject", CC "(" OBJ "J" OBJ ")V", FN_PTR(Unsafe_SetOrderedObject)},
1358 {CC "putOrderedInt", CC "(" OBJ "JI)V", FN_PTR(Unsafe_SetOrderedInt)},
1359 {CC "putOrderedLong", CC "(" OBJ "JJ)V", FN_PTR(Unsafe_SetOrderedLong)},
1360 {CC "park", CC "(ZJ)V", FN_PTR(Unsafe_Park)},
1361 {CC "unpark", CC "(" OBJ ")V", FN_PTR(Unsafe_Unpark)},
1362
1363 {CC "getLoadAverage", CC "([DI)I", FN_PTR(Unsafe_Loadavg)},
1364
1365 {CC "copyMemory", CC "(" OBJ "J" OBJ "JJ)V", FN_PTR(Unsafe_CopyMemory)},
1366 {CC "setMemory", CC "(" OBJ "JJB)V", FN_PTR(Unsafe_SetMemory)},
1367
1368 {CC "defineAnonymousClass", CC "(" DAC_Args ")" CLS, FN_PTR(Unsafe_DefineAnonymousClass)},
1369
1370 {CC "shouldBeInitialized",CC "(" CLS ")Z", FN_PTR(Unsafe_ShouldBeInitialized)},
1371
1372 {CC "loadFence", CC "()V", FN_PTR(Unsafe_LoadFence)},
1373 {CC "storeFence", CC "()V", FN_PTR(Unsafe_StoreFence)},
1374 {CC "fullFence", CC "()V", FN_PTR(Unsafe_FullFence)},
1375
1376 {CC "isBigEndian0", CC "()Z", FN_PTR(Unsafe_isBigEndian0)},
1377 {CC "unalignedAccess0", CC "()Z", FN_PTR(Unsafe_unalignedAccess0)}
1378 };
1379
1380 #undef CC
1381 #undef FN_PTR
1382
1383 #undef ADR
1384 #undef LANG
1385 #undef OBJ
|
1 /*
2 * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
643 if (size == 0) {
644 return;
645 }
646 size_t sz = (size_t)size;
647 if (sz != (julong)size || size < 0) {
648 THROW(vmSymbols::java_lang_IllegalArgumentException());
649 }
650 oop srcp = JNIHandles::resolve(srcObj);
651 oop dstp = JNIHandles::resolve(dstObj);
652 if (dstp != NULL && !dstp->is_typeArray()) {
653 // NYI: This works only for non-oop arrays at present.
654 // Generalizing it would be reasonable, but requires card marking.
655 // Also, autoboxing a Long from 0L in copyMemory(x,y, 0L,z, n) would be bad.
656 THROW(vmSymbols::java_lang_IllegalArgumentException());
657 }
658 void* src = index_oop_from_field_offset_long(srcp, srcOffset);
659 void* dst = index_oop_from_field_offset_long(dstp, dstOffset);
660 Copy::conjoint_memory_atomic(src, dst, sz);
661 UNSAFE_END
662
663 // This function is a leaf since if the source and destination are both in native memory
664 // the copy may potentially be very large, and we don't want to disable GC if we can avoid it.
665 // If either source or destination (or both) are on the heap, the function will enter VM using
666 // JVM_ENTRY_FROM_LEAF
667 JVM_LEAF(void, Unsafe_CopySwapMemory0(JNIEnv *env, jobject unsafe, jobject srcObj, jlong srcOffset, jobject dstObj, jlong dstOffset, jlong size, jlong elemSize)) {
668 UnsafeWrapper("Unsafe_CopySwapMemory0");
669
670 size_t sz = (size_t)size;
671 size_t esz = (size_t)elemSize;
672
673 if (srcObj == NULL && dstObj == NULL) {
674 // Both src & dst are in native memory
675 address src = (address)srcOffset;
676 address dst = (address)dstOffset;
677
678 Copy::conjoint_swap(src, dst, sz, esz);
679 } else {
680 // At least one of src/dst are on heap, transition to VM to access raw pointers
681
682 JVM_ENTRY_FROM_LEAF(env, void, Unsafe_CopySwapMemory0) {
683 oop srcp = JNIHandles::resolve(srcObj);
684 oop dstp = JNIHandles::resolve(dstObj);
685
686 address src = (address)index_oop_from_field_offset_long(srcp, srcOffset);
687 address dst = (address)index_oop_from_field_offset_long(dstp, dstOffset);
688
689 Copy::conjoint_swap(src, dst, sz, esz);
690 } JVM_END
691 }
692 } JVM_END
693
694 ////// Random queries
695
696 // See comment at file start about UNSAFE_LEAF
697 //UNSAFE_LEAF(jint, Unsafe_AddressSize())
698 UNSAFE_ENTRY(jint, Unsafe_AddressSize(JNIEnv *env, jobject unsafe))
699 UnsafeWrapper("Unsafe_AddressSize");
700 return sizeof(void*);
701 UNSAFE_END
702
703 // See comment at file start about UNSAFE_LEAF
704 //UNSAFE_LEAF(jint, Unsafe_PageSize())
705 UNSAFE_ENTRY(jint, Unsafe_PageSize(JNIEnv *env, jobject unsafe))
706 UnsafeWrapper("Unsafe_PageSize");
707 return os::vm_page_size();
708 UNSAFE_END
709
710 jint find_field_offset(jobject field, int must_be_static, TRAPS) {
711 if (field == NULL) {
712 THROW_0(vmSymbols::java_lang_NullPointerException());
1376 {CC "arrayBaseOffset", CC "(" CLS ")I", FN_PTR(Unsafe_ArrayBaseOffset)},
1377 {CC "arrayIndexScale", CC "(" CLS ")I", FN_PTR(Unsafe_ArrayIndexScale)},
1378 {CC "addressSize", CC "()I", FN_PTR(Unsafe_AddressSize)},
1379 {CC "pageSize", CC "()I", FN_PTR(Unsafe_PageSize)},
1380
1381 {CC "defineClass", CC "(" DC_Args ")" CLS, FN_PTR(Unsafe_DefineClass)},
1382 {CC "allocateInstance", CC "(" CLS ")" OBJ, FN_PTR(Unsafe_AllocateInstance)},
1383 {CC "throwException", CC "(" THR ")V", FN_PTR(Unsafe_ThrowException)},
1384 {CC "compareAndSwapObject", CC "(" OBJ "J" OBJ "" OBJ ")Z", FN_PTR(Unsafe_CompareAndSwapObject)},
1385 {CC "compareAndSwapInt", CC "(" OBJ "J""I""I"")Z", FN_PTR(Unsafe_CompareAndSwapInt)},
1386 {CC "compareAndSwapLong", CC "(" OBJ "J""J""J"")Z", FN_PTR(Unsafe_CompareAndSwapLong)},
1387 {CC "putOrderedObject", CC "(" OBJ "J" OBJ ")V", FN_PTR(Unsafe_SetOrderedObject)},
1388 {CC "putOrderedInt", CC "(" OBJ "JI)V", FN_PTR(Unsafe_SetOrderedInt)},
1389 {CC "putOrderedLong", CC "(" OBJ "JJ)V", FN_PTR(Unsafe_SetOrderedLong)},
1390 {CC "park", CC "(ZJ)V", FN_PTR(Unsafe_Park)},
1391 {CC "unpark", CC "(" OBJ ")V", FN_PTR(Unsafe_Unpark)},
1392
1393 {CC "getLoadAverage", CC "([DI)I", FN_PTR(Unsafe_Loadavg)},
1394
1395 {CC "copyMemory", CC "(" OBJ "J" OBJ "JJ)V", FN_PTR(Unsafe_CopyMemory)},
1396 {CC "copySwapMemory0", CC "(" OBJ "J" OBJ "JJJ)V", FN_PTR(Unsafe_CopySwapMemory0)},
1397 {CC "setMemory", CC "(" OBJ "JJB)V", FN_PTR(Unsafe_SetMemory)},
1398
1399 {CC "defineAnonymousClass", CC "(" DAC_Args ")" CLS, FN_PTR(Unsafe_DefineAnonymousClass)},
1400
1401 {CC "shouldBeInitialized",CC "(" CLS ")Z", FN_PTR(Unsafe_ShouldBeInitialized)},
1402
1403 {CC "loadFence", CC "()V", FN_PTR(Unsafe_LoadFence)},
1404 {CC "storeFence", CC "()V", FN_PTR(Unsafe_StoreFence)},
1405 {CC "fullFence", CC "()V", FN_PTR(Unsafe_FullFence)},
1406
1407 {CC "isBigEndian0", CC "()Z", FN_PTR(Unsafe_isBigEndian0)},
1408 {CC "unalignedAccess0", CC "()Z", FN_PTR(Unsafe_unalignedAccess0)}
1409 };
1410
1411 #undef CC
1412 #undef FN_PTR
1413
1414 #undef ADR
1415 #undef LANG
1416 #undef OBJ
|