1 /* src/native/vm/sun_misc_Unsafe.cpp - sun/misc/Unsafe
3 Copyright (C) 2006, 2007, 2008, 2009
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
31 #include "threads/atomic.hpp"
33 #include "mm/memory.hpp"
35 #include "native/jni.hpp"
36 #include "native/llni.h"
37 #include "native/native.hpp"
39 #if defined(ENABLE_JNI_HEADERS)
40 # include "native/include/sun_misc_Unsafe.h"
43 #include "vm/array.hpp"
44 #include "vm/jit/builtin.hpp"
45 #include "vm/exceptions.hpp"
46 #include "vm/initialize.hpp"
47 #include "vm/javaobjects.hpp"
49 #include "vm/string.hpp"
53 // Native functions are exported as C functions.
57 * Class: sun/misc/Unsafe
58 * Method: registerNatives
61 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_registerNatives(JNIEnv *env, jclass clazz)
63 /* The native methods of this function are already registered in
64 _Jv_sun_misc_Unsafe_init() which is called during VM
70 * Class: sun/misc/Unsafe
72 * Signature: (Ljava/lang/Object;J)I
74 JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_getInt__Ljava_lang_Object_2J(JNIEnv *env, jobject _this, jobject o, jlong offset)
76 return FieldAccess::get<int32_t>(o, offset);
81 * Class: sun/misc/Unsafe
83 * Signature: (Ljava/lang/Object;JI)V
85 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putInt__Ljava_lang_Object_2JI(JNIEnv *env, jobject _this, jobject o, jlong offset, jint x)
87 FieldAccess::set(o, offset, x);
92 * Class: sun/misc/Unsafe
94 * Signature: (Ljava/lang/Object;J)Ljava/lang/Object;
96 JNIEXPORT jobject JNICALL Java_sun_misc_Unsafe_getObject(JNIEnv *env, jobject _this, jobject o, jlong offset)
98 return FieldAccess::get<jobject>(o, offset);
103 * Class: sun/misc/Unsafe
105 * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
107 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putObject(JNIEnv *env, jobject _this, jobject o, jlong offset, jobject x)
109 FieldAccess::set(o, offset, x);
114 * Class: sun/misc/Unsafe
116 * Signature: (Ljava/lang/Object;J)Z
118 JNIEXPORT jboolean JNICALL Java_sun_misc_Unsafe_getBoolean(JNIEnv *env, jobject _this, jobject o, jlong offset)
120 return FieldAccess::get<int32_t>(o, offset);
125 * Class: sun/misc/Unsafe
127 * Signature: (Ljava/lang/Object;JZ)V
129 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putBoolean(JNIEnv *env, jobject _this, jobject o, jlong offset, jboolean x)
131 FieldAccess::set(o, offset, (int32_t) x);
136 * Class: sun/misc/Unsafe
138 * Signature: (Ljava/lang/Object;J)B
140 JNIEXPORT jbyte JNICALL Java_sun_misc_Unsafe_getByte__Ljava_lang_Object_2J(JNIEnv *env, jobject _this, jobject o, jlong offset)
142 return FieldAccess::get<int32_t>(o, offset);
147 * Class: sun/misc/Unsafe
149 * Signature: (Ljava/lang/Object;JB)V
151 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putByte__Ljava_lang_Object_2JB(JNIEnv *env, jobject _this, jobject o, jlong offset, jbyte x)
153 FieldAccess::set(o, offset, (int32_t) x);
158 * Class: sun/misc/Unsafe
160 * Signature: (Ljava/lang/Object;J)S
162 JNIEXPORT jshort JNICALL Java_sun_misc_Unsafe_getShort__Ljava_lang_Object_2J(JNIEnv *env, jobject _this, jobject o, jlong offset)
164 return FieldAccess::get<int32_t>(o, offset);
169 * Class: sun/misc/Unsafe
171 * Signature: (Ljava/lang/Object;JS)V
173 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putShort__Ljava_lang_Object_2JS(JNIEnv *env, jobject _this, jobject o, jlong offset, jshort x)
175 FieldAccess::set(o, offset, (int32_t) x);
180 * Class: sun/misc/Unsafe
182 * Signature: (Ljava/lang/Object;J)C
184 JNIEXPORT jchar JNICALL Java_sun_misc_Unsafe_getChar__Ljava_lang_Object_2J(JNIEnv *env, jobject _this, jobject o, jlong offset)
186 return FieldAccess::get<int32_t>(o, offset);
191 * Class: sun/misc/Unsafe
193 * Signature: (Ljava/lang/Object;JC)V
195 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putChar__Ljava_lang_Object_2JC(JNIEnv *env, jobject _this, jobject o, jlong offset, jchar x)
197 FieldAccess::set(o, offset, (int32_t) x);
202 * Class: sun/misc/Unsafe
204 * Signature: (Ljava/lang/Object;J)J
206 JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_getLong__Ljava_lang_Object_2J(JNIEnv *env, jobject _this, jobject o, jlong offset)
208 return FieldAccess::get<int64_t>(o, offset);
213 * Class: sun/misc/Unsafe
215 * Signature: (Ljava/lang/Object;JJ)V
217 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLong__Ljava_lang_Object_2JJ(JNIEnv *env, jobject _this, jobject o, jlong offset, jlong x)
219 FieldAccess::set(o, offset, x);
224 * Class: sun/misc/Unsafe
226 * Signature: (Ljava/lang/Object;J)F
228 JNIEXPORT jfloat JNICALL Java_sun_misc_Unsafe_getFloat__Ljava_lang_Object_2J(JNIEnv *env, jobject _this, jobject o, jlong offset)
230 return FieldAccess::get<float>(o, offset);
235 * Class: sun/misc/Unsafe
237 * Signature: (Ljava/lang/Object;JF)V
239 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putFloat__Ljava_lang_Object_2JF(JNIEnv *env, jobject _this, jobject o, jlong offset, jfloat x)
241 FieldAccess::set(o, offset, x);
246 * Class: sun/misc/Unsafe
248 * Signature: (Ljava/lang/Object;J)D
250 JNIEXPORT jdouble JNICALL Java_sun_misc_Unsafe_getDouble__Ljava_lang_Object_2J(JNIEnv *env, jobject _this, jobject o, jlong offset)
252 return FieldAccess::get<double>(o, offset);
257 * Class: sun/misc/Unsafe
259 * Signature: (Ljava/lang/Object;JD)V
261 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putDouble__Ljava_lang_Object_2JD(JNIEnv *env, jobject _this, jobject o, jlong offset, jdouble x)
263 FieldAccess::set(o, offset, x);
268 * Class: sun/misc/Unsafe
272 JNIEXPORT jbyte JNICALL Java_sun_misc_Unsafe_getByte__J(JNIEnv *env, jobject _this, jlong address)
277 p = (int8_t *) (intptr_t) address;
281 return (int32_t) value;
286 * Class: sun/misc/Unsafe
290 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putByte__JB(JNIEnv *env, jobject _this, jlong address, jbyte value)
294 p = (int8_t *) (intptr_t) address;
301 * Class: sun/misc/Unsafe
305 JNIEXPORT jshort JNICALL Java_sun_misc_Unsafe_getShort__J(JNIEnv *env, jobject _this, jlong address)
310 p = (int16_t *) (intptr_t) address;
314 return (int32_t) value;
319 * Class: sun/misc/Unsafe
323 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putShort__JS(JNIEnv *env, jobject _this, jlong address, jshort value)
327 p = (int16_t *) (intptr_t) address;
329 *p = (int16_t) value;
334 * Class: sun/misc/Unsafe
338 JNIEXPORT jchar JNICALL Java_sun_misc_Unsafe_getChar__J(JNIEnv *env, jobject _this, jlong address)
343 p = (uint16_t *) (intptr_t) address;
347 return (int32_t) value;
352 * Class: sun/misc/Unsafe
356 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putChar__JC(JNIEnv *env, jobject _this, jlong address, jchar value)
360 p = (uint16_t *) (intptr_t) address;
362 *p = (uint16_t) value;
367 * Class: sun/misc/Unsafe
371 JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_getInt__J(JNIEnv *env, jobject _this, jlong address)
376 p = (int32_t *) (intptr_t) address;
385 * Class: sun/misc/Unsafe
389 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putInt__JI(JNIEnv *env, jobject _this, jlong address, jint value)
393 p = (int32_t *) (intptr_t) address;
400 * Class: sun/misc/Unsafe
404 JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_getLong__J(JNIEnv *env, jobject _this, jlong address)
409 p = (int64_t *) (intptr_t) address;
418 * Class: sun/misc/Unsafe
422 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLong__JJ(JNIEnv *env, jobject _this, jlong address, jlong value)
426 p = (int64_t *) (intptr_t) address;
433 * Class: sun/misc/Unsafe
437 JNIEXPORT jfloat JNICALL Java_sun_misc_Unsafe_getFloat__J(JNIEnv *env, jobject _this, jlong address)
442 p = (float *) (intptr_t) address;
451 * Class: sun/misc/Unsafe
455 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putFloat__JF(JNIEnv *env, jobject _this, jlong address, jfloat value)
459 p = (float*) (intptr_t) address;
466 * Class: sun/misc/Unsafe
470 JNIEXPORT jdouble JNICALL Java_sun_misc_Unsafe_getDouble__J(JNIEnv *env, jobject _this, jlong address)
475 p = (double*) (intptr_t) address;
484 * Class: sun/misc/Unsafe
488 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putDouble__JD(JNIEnv *env, jobject _this, jlong address, jdouble value)
492 p = (double*) (intptr_t) address;
499 * Class: sun/misc/Unsafe
500 * Method: objectFieldOffset
501 * Signature: (Ljava/lang/reflect/Field;)J
503 JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_objectFieldOffset(JNIEnv *env, jobject _this, jobject field)
505 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
507 java_lang_reflect_Field rf(field);
508 java_lang_reflect_VMField rvmf(rf.get_f());
509 fieldinfo* f = rvmf.get_field();
511 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
513 java_lang_reflect_Field rf(field);
514 fieldinfo* f = rf.get_field();
517 # error unknown configuration
520 return (jlong) f->offset;
525 * Class: sun/misc/Unsafe
526 * Method: allocateMemory
529 JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_allocateMemory(JNIEnv *env, jobject _this, jlong bytes)
534 length = (size_t) bytes;
536 if ((length != (uint64_t) bytes) || (bytes < 0)) {
537 exceptions_throw_illegalargumentexception();
541 p = MNEW(uint8_t, length);
543 return (int64_t) (intptr_t) p;
550 * Class: sun/misc/Unsafe
552 * Signature: (Ljava/lang/Object;JJB)V
554 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_setMemory_jdk7(JNIEnv *env, jobject _this, jobject o, jlong offset, jlong bytes, jbyte value)
559 length = (size_t) bytes;
561 if ((length != (uint64_t) bytes) || (bytes < 0)) {
562 exceptions_throw_illegalargumentexception();
566 /* XXX Missing LLNI: we need to unwrap _this object. */
568 p = (void *) (((uint8_t *) o) + offset);
570 /* XXX Not sure this is correct. */
572 os::memset(p, value, length);
577 * Class: sun/misc/Unsafe
579 * Signature: (Ljava/lang/Object;JLjava/lang/Object;JJ)V
581 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_copyMemory_jdk7(JNIEnv *env, jobject _this, jobject srcBase, jlong srcOffset, jobject destBase, jlong destOffset, jlong bytes)
590 length = (size_t) bytes;
592 if ((length != (uint64_t) bytes) || (bytes < 0)) {
593 exceptions_throw_illegalargumentexception();
597 /* XXX Missing LLNI: We need to unwrap these objects. */
599 src = (void *) (((uint8_t *) srcBase) + srcOffset);
600 dest = (void *) (((uint8_t *) destBase) + destOffset);
602 os::memcpy(dest, src, length);
606 * Class: sun/misc/Unsafe
610 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_setMemory_jdk6(JNIEnv *env, jobject _this, jlong address, jlong bytes, jbyte value)
615 length = (size_t) bytes;
617 if ((length != (uint64_t) bytes) || (bytes < 0)) {
618 exceptions_throw_illegalargumentexception();
622 p = (void *) (intptr_t) address;
624 /* XXX Not sure this is correct. */
626 os::memset(p, value, length);
631 * Class: sun/misc/Unsafe
635 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_copyMemory_jdk6(JNIEnv *env, jobject _this, jlong srcAddress, jlong destAddress, jlong bytes)
644 length = (size_t) bytes;
646 if ((length != (uint64_t) bytes) || (bytes < 0)) {
647 exceptions_throw_illegalargumentexception();
651 src = (void *) (intptr_t) srcAddress;
652 dest = (void *) (intptr_t) destAddress;
654 os::memcpy(dest, src, length);
659 * Class: sun/misc/Unsafe
663 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_freeMemory(JNIEnv *env, jobject _this, jlong address)
667 p = (void *) (intptr_t) address;
672 /* we pass length 1 to trick the free function */
674 MFREE(p, uint8_t, 1);
679 * Class: sun/misc/Unsafe
680 * Method: staticFieldOffset
681 * Signature: (Ljava/lang/reflect/Field;)J
683 JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_staticFieldOffset(JNIEnv *env, jobject _this, jobject f)
685 /* The offset of static fields is 0. */
692 * Class: sun/misc/Unsafe
693 * Method: staticFieldBase
694 * Signature: (Ljava/lang/reflect/Field;)Ljava/lang/Object;
696 JNIEXPORT jobject JNICALL Java_sun_misc_Unsafe_staticFieldBase(JNIEnv *env, jobject _this, jobject field)
698 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
700 java_lang_reflect_Field rf(field);
701 java_lang_reflect_VMField rvmf(rf.get_f());
702 fieldinfo* f = rvmf.get_field();
704 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
706 java_lang_reflect_Field rf(field);
707 fieldinfo* f = rf.get_field();
710 # error unknown configuration
713 return (jobject) (f->value);
718 * Class: sun/misc/Unsafe
719 * Method: ensureClassInitialized
720 * Signature: (Ljava/lang/Class;)V
722 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_ensureClassInitialized(JNIEnv *env, jobject _this, jclass clazz)
726 c = LLNI_classinfo_unwrap(clazz);
728 if (!(c->state & CLASS_INITIALIZED))
734 * Class: sun/misc/Unsafe
735 * Method: arrayBaseOffset
736 * Signature: (Ljava/lang/Class;)I
738 JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_arrayBaseOffset(JNIEnv *env, jobject _this, jclass arrayClass)
743 c = LLNI_classinfo_unwrap(arrayClass);
744 ad = c->vftbl->arraydesc;
747 /* XXX does that exception exist? */
748 exceptions_throw_internalerror("java/lang/InvalidClassException");
752 return ad->dataoffset;
757 * Class: sun/misc/Unsafe
758 * Method: arrayIndexScale
759 * Signature: (Ljava/lang/Class;)I
761 JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_arrayIndexScale(JNIEnv *env, jobject _this, jclass arrayClass)
766 c = LLNI_classinfo_unwrap(arrayClass);
767 ad = c->vftbl->arraydesc;
770 /* XXX does that exception exist? */
771 exceptions_throw_internalerror("java/lang/InvalidClassException");
775 return ad->componentsize;
780 * Class: sun/misc/Unsafe
781 * Method: addressSize
784 JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_addressSize(JNIEnv *env, jobject _this)
786 return SIZEOF_VOID_P;
791 * Class: sun/misc/Unsafe
795 JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_pageSize(JNIEnv *env, jobject _this)
806 * Class: sun/misc/Unsafe
807 * Method: defineClass
808 * Signature: (Ljava/lang/String;[BIILjava/lang/ClassLoader;Ljava/security/ProtectionDomain;)Ljava/lang/Class;
810 JNIEXPORT jclass JNICALL Java_sun_misc_Unsafe_defineClass__Ljava_lang_String_2_3BIILjava_lang_ClassLoader_2Ljava_security_ProtectionDomain_2(JNIEnv *env, jobject _this, jstring name, jbyteArray b, jint off, jint len, jobject loader, jobject protectionDomain)
816 cl = loader_hashtable_classloader_add((java_handle_t *) loader);
818 /* check if data was passed */
821 exceptions_throw_nullpointerexception();
825 /* check the indexes passed */
829 if ((off < 0) || (len < 0) || ((off + len) > ba.get_length())) {
830 exceptions_throw_arrayindexoutofboundsexception();
835 /* convert '.' to '/' in java string */
837 utfname = javastring_toutf((java_handle_t *) name, true);
843 /* define the class */
845 uint8_t* ptr = ((uint8_t*) ba.get_raw_data_ptr()) + off;
846 c = class_define(utfname, cl, len, ptr,
847 (java_handle_t *) protectionDomain);
852 java_handle_t* h = LLNI_classinfo_wrap(c);
854 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
855 // Set ProtectionDomain.
856 java_lang_Class jlc(h);
857 jlc.set_pd(protectionDomain);
865 * Class: sun/misc/Unsafe
866 * Method: allocateInstance
867 * Signature: (Ljava/lang/Class;)Ljava/lang/Object;
869 JNIEXPORT jobject JNICALL Java_sun_misc_Unsafe_allocateInstance(JNIEnv *env, jobject _this, jclass cls)
874 c = LLNI_classinfo_unwrap(cls);
883 * Class: sun/misc/Unsafe
884 * Method: throwException
885 * Signature: (Ljava/lang/Throwable;)V
887 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_throwException(JNIEnv *env, jobject _this, jobject ee)
891 o = (java_handle_t *) ee;
893 exceptions_set_exception(o);
898 * Class: sun/misc/Unsafe
899 * Method: compareAndSwapObject
900 * Signature: (Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z
902 JNIEXPORT jboolean JNICALL Java_sun_misc_Unsafe_compareAndSwapObject(JNIEnv *env, jobject _this, jobject o, jlong offset, jobject expected, jobject x)
909 p = (void **) (((uint8_t *) o) + offset);
911 result = Atomic::compare_and_swap(p, (void *) expected, (void *) x);
913 if (result == expected)
921 * Class: sun/misc/Unsafe
922 * Method: compareAndSwapInt
923 * Signature: (Ljava/lang/Object;JII)Z
925 JNIEXPORT jboolean JNICALL Java_sun_misc_Unsafe_compareAndSwapInt(JNIEnv *env, jobject _this, jobject o, jlong offset, jint expected, jint x)
932 p = (uint32_t *) (((uint8_t *) o) + offset);
934 result = Atomic::compare_and_swap(p, (uint32_t) expected, (uint32_t) x);
936 if (result == (uint32_t) expected)
944 * Class: sun/misc/Unsafe
945 * Method: compareAndSwapLong
946 * Signature: (Ljava/lang/Object;JJJ)Z
948 JNIEXPORT jboolean JNICALL Java_sun_misc_Unsafe_compareAndSwapLong(JNIEnv *env, jobject _this, jobject o, jlong offset, jlong expected, jlong x)
955 p = (uint64_t *) (((uint8_t *) o) + offset);
957 result = Atomic::compare_and_swap(p, (uint64_t) expected, (uint64_t) x);
959 if (result == (uint64_t) expected)
967 * Class: sun/misc/Unsafe
968 * Method: getObjectVolatile
969 * Signature: (Ljava/lang/Object;J)Ljava/lang/Object;
971 JNIEXPORT jobject JNICALL Java_sun_misc_Unsafe_getObjectVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset)
973 return FieldAccess::get_volatile<jobject>(o, offset);
978 * Class: sun/misc/Unsafe
979 * Method: putObjectVolatile
980 * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
982 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putObjectVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset, jobject x)
984 FieldAccess::set_volatile(o, offset, x);
989 * Class: sun/misc/Unsafe
990 * Method: getBooleanVolatile
991 * Signature: (Ljava/lang/Object;J)Z
993 JNIEXPORT jboolean JNICALL Java_sun_misc_Unsafe_getBooleanVolatile(JNIEnv* env, jobject _this, jobject o, jlong offset)
995 return FieldAccess::get_volatile<int32_t>(o, offset);
1000 * Class: sun/misc/Unsafe
1001 * Method: getByteVolatile
1002 * Signature: (Ljava/lang/Object;J)B
1004 JNIEXPORT jbyte JNICALL Java_sun_misc_Unsafe_getByteVolatile(JNIEnv* env, jobject _this, jobject o, jlong offset)
1006 return FieldAccess::get_volatile<int32_t>(o, offset);
1011 * Class: sun/misc/Unsafe
1012 * Method: getShortVolatile
1013 * Signature: (Ljava/lang/Object;J)S
1015 JNIEXPORT jshort JNICALL Java_sun_misc_Unsafe_getShortVolatile(JNIEnv* env, jobject _this, jobject o, jlong offset)
1017 return FieldAccess::get_volatile<int32_t>(o, offset);
1022 * Class: sun/misc/Unsafe
1023 * Method: getCharVolatile
1024 * Signature: (Ljava/lang/Object;J)C
1026 JNIEXPORT jchar JNICALL Java_sun_misc_Unsafe_getCharVolatile(JNIEnv* env, jobject _this, jobject o, jlong offset)
1028 return FieldAccess::get_volatile<int32_t>(o, offset);
1033 * Class: sun/misc/Unsafe
1034 * Method: getIntVolatile
1035 * Signature: (Ljava/lang/Object;J)I
1037 JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_getIntVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset)
1039 return FieldAccess::get_volatile<int32_t>(o, offset);
1044 * Class: sun/misc/Unsafe
1045 * Method: putIntVolatile
1046 * Signature: (Ljava/lang/Object;JI)V
1048 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putIntVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset, jint x)
1050 FieldAccess::set_volatile(o, offset, x);
1055 * Class: sun/misc/Unsafe
1056 * Method: getLongVolatile
1057 * Signature: (Ljava/lang/Object;J)J
1059 JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_getLongVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset)
1061 return FieldAccess::get_volatile<int64_t>(o, offset);
1066 * Class: sun/misc/Unsafe
1067 * Method: putLongVolatile
1068 * Signature: (Ljava/lang/Object;JJ)V
1070 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLongVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset, jlong x)
1072 FieldAccess::set_volatile(o, offset, x);
1077 * Class: sun/misc/Unsafe
1078 * Method: getFloatVolatile
1079 * Signature: (Ljava/lang/Object;J)F
1081 JNIEXPORT jfloat JNICALL Java_sun_misc_Unsafe_getFloatVolatile(JNIEnv* env, jobject _this, jobject o, jlong offset)
1083 return FieldAccess::get_volatile<float>(o, offset);
1088 * Class: sun/misc/Unsafe
1089 * Method: getDoubleVolatile
1090 * Signature: (Ljava/lang/Object;J)D
1092 JNIEXPORT jdouble JNICALL Java_sun_misc_Unsafe_getDoubleVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset)
1094 return FieldAccess::get_volatile<double>(o, offset);
1099 * Class: sun/misc/Unsafe
1100 * Method: putOrderedObject
1101 * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
1103 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedObject(JNIEnv *env, jobject _this, jobject o, jlong offset, jobject x)
1105 FieldAccess::set_volatile(o, offset, x);
1110 * Class: sun/misc/Unsafe
1111 * Method: putOrderedInt
1112 * Signature: (Ljava/lang/Object;JI)V
1114 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedInt(JNIEnv *env, jobject _this, jobject o, jlong offset, jint x)
1116 FieldAccess::set_volatile(o, offset, x);
1121 * Class: sun/misc/Unsafe
1122 * Method: putOrderedLong
1123 * Signature: (Ljava/lang/Object;JJ)V
1125 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedLong(JNIEnv *env, jobject _this, jobject o, jlong offset, jlong x)
1127 FieldAccess::set_volatile(o, offset, x);
1132 * Class: sun/misc/Unsafe
1134 * Signature: (Ljava/lang/Object;)V
1136 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_unpark(JNIEnv *env, jobject _this, jobject thread)
1138 java_handle_t *h = (java_handle_t *) thread;
1141 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1142 h = java_lang_Thread(h).get_vmThread();
1144 t = thread_get_thread(h);
1151 * Class: sun/misc/Unsafe
1155 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_park(JNIEnv *env, jobject _this, jboolean isAbsolute, jlong time)
1157 threads_park(isAbsolute, time);
1163 /* native methods implemented by this file ************************************/
1165 static JNINativeMethod methods[] = {
1166 { (char*) "registerNatives", (char*) "()V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_registerNatives },
1167 { (char*) "getInt", (char*) "(Ljava/lang/Object;J)I", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getInt__Ljava_lang_Object_2J },
1168 { (char*) "putInt", (char*) "(Ljava/lang/Object;JI)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putInt__Ljava_lang_Object_2JI },
1169 { (char*) "getObject", (char*) "(Ljava/lang/Object;J)Ljava/lang/Object;", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getObject },
1170 { (char*) "putObject", (char*) "(Ljava/lang/Object;JLjava/lang/Object;)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putObject },
1171 { (char*) "getBoolean", (char*) "(Ljava/lang/Object;J)Z", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getBoolean },
1172 { (char*) "putBoolean", (char*) "(Ljava/lang/Object;JZ)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putBoolean },
1173 { (char*) "getByte", (char*) "(Ljava/lang/Object;J)B", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getByte__Ljava_lang_Object_2J },
1174 { (char*) "putByte", (char*) "(Ljava/lang/Object;JB)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putByte__Ljava_lang_Object_2JB },
1175 { (char*) "getShort", (char*) "(Ljava/lang/Object;J)S", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getShort__Ljava_lang_Object_2J },
1176 { (char*) "putShort", (char*) "(Ljava/lang/Object;JS)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putShort__Ljava_lang_Object_2JS },
1177 { (char*) "getChar", (char*) "(Ljava/lang/Object;J)C", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getChar__Ljava_lang_Object_2J },
1178 { (char*) "putChar", (char*) "(Ljava/lang/Object;JC)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putChar__Ljava_lang_Object_2JC },
1179 { (char*) "getLong", (char*) "(Ljava/lang/Object;J)J", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getLong__Ljava_lang_Object_2J },
1180 { (char*) "putLong", (char*) "(Ljava/lang/Object;JJ)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putLong__Ljava_lang_Object_2JJ },
1181 { (char*) "getFloat", (char*) "(Ljava/lang/Object;J)F", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getFloat__Ljava_lang_Object_2J },
1182 { (char*) "putFloat", (char*) "(Ljava/lang/Object;JF)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putFloat__Ljava_lang_Object_2JF },
1183 { (char*) "getDouble", (char*) "(Ljava/lang/Object;J)D", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getDouble__Ljava_lang_Object_2J },
1184 { (char*) "putDouble", (char*) "(Ljava/lang/Object;JD)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putDouble__Ljava_lang_Object_2JD },
1185 { (char*) "getByte", (char*) "(J)B", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getByte__J },
1186 { (char*) "putByte", (char*) "(JB)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putByte__JB },
1187 { (char*) "getShort", (char*) "(J)S", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getShort__J },
1188 { (char*) "putShort", (char*) "(JS)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putShort__JS },
1189 { (char*) "getChar", (char*) "(J)C", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getChar__J },
1190 { (char*) "putChar", (char*) "(JC)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putChar__JC },
1191 { (char*) "getInt", (char*) "(J)I", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getInt__J },
1192 { (char*) "putInt", (char*) "(JI)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putInt__JI },
1193 { (char*) "getLong", (char*) "(J)J", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getLong__J },
1194 { (char*) "putLong", (char*) "(JJ)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putLong__JJ },
1195 { (char*) "getFloat", (char*) "(J)F", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getFloat__J },
1196 { (char*) "putFloat", (char*) "(JF)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putFloat__JF },
1197 { (char*) "getDouble", (char*) "(J)D", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getDouble__J },
1198 { (char*) "putDouble", (char*) "(JD)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putDouble__JD },
1199 { (char*) "objectFieldOffset", (char*) "(Ljava/lang/reflect/Field;)J", (void*) (uintptr_t) &Java_sun_misc_Unsafe_objectFieldOffset },
1200 { (char*) "allocateMemory", (char*) "(J)J", (void*) (uintptr_t) &Java_sun_misc_Unsafe_allocateMemory },
1201 // next two methods: OpenJDK 7
1202 { (char*) "setMemory", (char*) "(Ljava/lang/Object;JJB)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_setMemory_jdk7 },
1203 { (char*) "copyMemory", (char*) "(Ljava/lang/Object;JLjava/lang/Object;JJ)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_copyMemory_jdk7 },
1204 // next two methods: OpenJDK 6
1205 { (char*) "setMemory", (char*) "(JJB)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_setMemory_jdk6 },
1206 { (char*) "copyMemory", (char*) "(JJJ)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_copyMemory_jdk6 },
1207 { (char*) "freeMemory", (char*) "(J)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_freeMemory },
1208 { (char*) "staticFieldOffset", (char*) "(Ljava/lang/reflect/Field;)J", (void*) (uintptr_t) &Java_sun_misc_Unsafe_staticFieldOffset },
1209 { (char*) "staticFieldBase", (char*) "(Ljava/lang/reflect/Field;)Ljava/lang/Object;", (void*) (uintptr_t) &Java_sun_misc_Unsafe_staticFieldBase },
1210 { (char*) "ensureClassInitialized", (char*) "(Ljava/lang/Class;)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_ensureClassInitialized },
1211 { (char*) "arrayBaseOffset", (char*) "(Ljava/lang/Class;)I", (void*) (uintptr_t) &Java_sun_misc_Unsafe_arrayBaseOffset },
1212 { (char*) "arrayIndexScale", (char*) "(Ljava/lang/Class;)I", (void*) (uintptr_t) &Java_sun_misc_Unsafe_arrayIndexScale },
1213 { (char*) "addressSize", (char*) "()I", (void*) (uintptr_t) &Java_sun_misc_Unsafe_addressSize },
1214 { (char*) "pageSize", (char*) "()I", (void*) (uintptr_t) &Java_sun_misc_Unsafe_pageSize },
1215 { (char*) "defineClass", (char*) "(Ljava/lang/String;[BIILjava/lang/ClassLoader;Ljava/security/ProtectionDomain;)Ljava/lang/Class;", (void*) (uintptr_t) &Java_sun_misc_Unsafe_defineClass__Ljava_lang_String_2_3BIILjava_lang_ClassLoader_2Ljava_security_ProtectionDomain_2 },
1216 { (char*) "allocateInstance", (char*) "(Ljava/lang/Class;)Ljava/lang/Object;", (void*) (uintptr_t) &Java_sun_misc_Unsafe_allocateInstance },
1217 { (char*) "throwException", (char*) "(Ljava/lang/Throwable;)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_throwException },
1218 { (char*) "compareAndSwapObject", (char*) "(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z", (void*) (uintptr_t) &Java_sun_misc_Unsafe_compareAndSwapObject },
1219 { (char*) "compareAndSwapInt", (char*) "(Ljava/lang/Object;JII)Z", (void*) (uintptr_t) &Java_sun_misc_Unsafe_compareAndSwapInt },
1220 { (char*) "compareAndSwapLong", (char*) "(Ljava/lang/Object;JJJ)Z", (void*) (uintptr_t) &Java_sun_misc_Unsafe_compareAndSwapLong },
1221 { (char*) "getObjectVolatile", (char*) "(Ljava/lang/Object;J)Ljava/lang/Object;", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getObjectVolatile },
1222 { (char*) "putObjectVolatile", (char*) "(Ljava/lang/Object;JLjava/lang/Object;)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putObjectVolatile },
1223 { (char*) "getBooleanVolatile", (char*) "(Ljava/lang/Object;J)Z", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getBooleanVolatile },
1224 { (char*) "getByteVolatile", (char*) "(Ljava/lang/Object;J)B", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getByteVolatile },
1225 { (char*) "getShortVolatile", (char*) "(Ljava/lang/Object;J)S", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getShortVolatile },
1226 { (char*) "getCharVolatile", (char*) "(Ljava/lang/Object;J)C", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getCharVolatile },
1227 { (char*) "getIntVolatile", (char*) "(Ljava/lang/Object;J)I", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getIntVolatile },
1228 { (char*) "putIntVolatile", (char*) "(Ljava/lang/Object;JI)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putIntVolatile },
1229 { (char*) "getLongVolatile", (char*) "(Ljava/lang/Object;J)J", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getLongVolatile },
1230 { (char*) "putLongVolatile", (char*) "(Ljava/lang/Object;JJ)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putLongVolatile },
1231 { (char*) "getFloatVolatile", (char*) "(Ljava/lang/Object;J)F", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getFloatVolatile },
1232 { (char*) "getDoubleVolatile", (char*) "(Ljava/lang/Object;J)D", (void*) (uintptr_t) &Java_sun_misc_Unsafe_getDoubleVolatile },
1233 { (char*) "putOrderedObject", (char*) "(Ljava/lang/Object;JLjava/lang/Object;)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putOrderedObject },
1234 { (char*) "putOrderedInt", (char*) "(Ljava/lang/Object;JI)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putOrderedInt },
1235 { (char*) "putOrderedLong", (char*) "(Ljava/lang/Object;JJ)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_putOrderedLong },
1236 { (char*) "unpark", (char*) "(Ljava/lang/Object;)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_unpark },
1237 { (char*) "park", (char*) "(ZJ)V", (void*) (uintptr_t) &Java_sun_misc_Unsafe_park },
1241 /* _Jv_sun_misc_Unsafe_init ****************************************************
1243 Register native functions.
1245 *******************************************************************************/
1247 void _Jv_sun_misc_Unsafe_init(void)
1249 utf* u = utf_new_char("sun/misc/Unsafe");
1251 NativeMethods& nm = VM::get_current()->get_nativemethods();
1252 nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
1257 * These are local overrides for various environment variables in Emacs.
1258 * Please do not remove this and leave it at the end of the file, where
1259 * Emacs will automagically detect them.
1260 * ---------------------------------------------------------------------
1263 * indent-tabs-mode: t
1267 * vim:noexpandtab:sw=4:ts=4: