1 /* src/native/vm/gnu/sun_misc_Unsafe.c - sun/misc/Unsafe
3 Copyright (C) 2006, 2007 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 $Id: java_lang_VMObject.c 5153 2006-07-18 08:19:24Z twisti $
33 #include "native/jni.h"
34 #include "native/native.h"
36 #include "native/include/java_lang_Object.h"
37 #include "native/include/java_lang_reflect_Field.h"
38 #include "native/include/java_lang_Thread.h" /* required by s.m.U */
40 #include "native/include/sun_misc_Unsafe.h"
43 /* native methods implemented by this file ************************************/
45 static JNINativeMethod methods[] = {
46 { "objectFieldOffset", "(Ljava/lang/reflect/Field;)J", (void *) (ptrint) &Java_sun_misc_Unsafe_objectFieldOffset },
47 { "compareAndSwapInt", "(Ljava/lang/Object;JII)Z", (void *) (ptrint) &Java_sun_misc_Unsafe_compareAndSwapInt },
49 { "compareAndSwapLong", "(Ljava/lang/Object;JJJ)Z", (void *) (ptrint) &Java_sun_misc_Unsafe_compareAndSwapLong },
50 { "compareAndSwapObject", "(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z", (void *) (ptrint) &Java_sun_misc_Unsafe_compareAndSwapObject },
51 { "putOrderedInt", "(Ljava/lang/Object;JI)V", (void *) (ptrint) &Java_sun_misc_Unsafe_putOrderedInt },
52 { "putOrderedLong", "(Ljava/lang/Object;JJ)V", (void *) (ptrint) &Java_sun_misc_Unsafe_putOrderedLong },
53 { "putOrderedObject", "(Ljava/lang/Object;JLjava/lang/Object;)V", (void *) (ptrint) &Java_sun_misc_Unsafe_putOrderedObject },
54 { "putIntVolatile", "(Ljava/lang/Object;JI)V", (void *) (ptrint) &Java_sun_misc_Unsafe_putIntVolatile },
55 { "getIntVolatile", "(Ljava/lang/Object;J)I", (void *) (ptrint) &Java_sun_misc_Unsafe_getIntVolatile },
56 { "putLongVolatile", "(Ljava/lang/Object;JJ)V", (void *) (ptrint) &Java_sun_misc_Unsafe_putLongVolatile },
57 { "putLong", "(Ljava/lang/Object;JJ)V", (void *) (ptrint) &Java_sun_misc_Unsafe_putLong },
58 { "getLongVolatile", "(Ljava/lang/Object;J)J", (void *) (ptrint) &Java_sun_misc_Unsafe_getLongVolatile },
59 { "getLong", "(Ljava/lang/Object;J)J", (void *) (ptrint) &Java_sun_misc_Unsafe_getLong },
60 { "putObjectVolatile", "(Ljava/lang/Object;JLjava/lang/Object;)V", (void *) (ptrint) &Java_sun_misc_Unsafe_putObjectVolatile },
61 { "putObject", "(Ljava/lang/Object;JLjava/lang/Object;)V", (void *) (ptrint) &Java_sun_misc_Unsafe_putObject },
62 { "getObjectVolatile", "(Ljava/lang/Object;J)Ljava/lang/Object;", (void *) (ptrint) &Java_sun_misc_Unsafe_getObjectVolatile },
63 { "arrayBaseOffset", "(Ljava/lang/Class;)I", (void *) (ptrint) &Java_sun_misc_Unsafe_arrayBaseOffset },
64 { "arrayIndexScale", "(Ljava/lang/Class;)I", (void *) (ptrint) &Java_sun_misc_Unsafe_arrayIndexScale },
65 { "unpark", "(Ljava/lang/Thread;)V", (void *) (ptrint) &Java_sun_misc_Unsafe_unpark },
66 { "park", "(ZJ)V", (void *) (ptrint) &Java_sun_misc_Unsafe_park },
71 /* _Jv_sun_misc_Unsafe_init ****************************************************
73 Register native functions.
75 *******************************************************************************/
77 void _Jv_sun_misc_Unsafe_init(void)
81 u = utf_new_char("sun/misc/Unsafe");
83 native_method_register(u, methods, NATIVE_METHODS_COUNT);
88 * Class: sun/misc/Unsafe
89 * Method: objectFieldOffset
90 * Signature: (Ljava/lang/reflect/Field;)J
92 JNIEXPORT s8 JNICALL Java_sun_misc_Unsafe_objectFieldOffset(JNIEnv *env, sun_misc_Unsafe* this, java_lang_reflect_Field* field)
97 c = (classinfo *) field->declaringClass;
98 f = &c->fields[field->slot];
100 return (s8) f->offset;
105 * Class: sun/misc/Unsafe
106 * Method: compareAndSwapInt
107 * Signature: (Ljava/lang/Object;JII)Z
109 JNIEXPORT s4 JNICALL Java_sun_misc_Unsafe_compareAndSwapInt(JNIEnv *env, sun_misc_Unsafe* this, java_lang_Object* obj, s8 offset, s4 expect, s4 update)
114 p = (s4 *) (((u1 *) obj) + offset);
116 /* XXX this should be atomic */
120 if (value == expect) {
132 * Class: sun/misc/Unsafe
133 * Method: compareAndSwapLong
134 * Signature: (Ljava/lang/Object;JJJ)Z
136 JNIEXPORT s4 JNICALL Java_sun_misc_Unsafe_compareAndSwapLong(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, s8 par2, s8 par3, s8 par4)
142 * Class: sun/misc/Unsafe
143 * Method: compareAndSwapObject
144 * Signature: (Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z
146 JNIEXPORT s4 JNICALL Java_sun_misc_Unsafe_compareAndSwapObject(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, s8 par2, struct java_lang_Object* par3, struct java_lang_Object* par4)
152 * Class: sun/misc/Unsafe
153 * Method: putOrderedInt
154 * Signature: (Ljava/lang/Object;JI)V
156 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedInt(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, s8 par2, s4 par3)
162 * Class: sun/misc/Unsafe
163 * Method: putOrderedLong
164 * Signature: (Ljava/lang/Object;JJ)V
166 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedLong(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, s8 par2, s8 par3)
172 * Class: sun/misc/Unsafe
173 * Method: putOrderedObject
174 * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
176 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedObject(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, s8 par2, struct java_lang_Object* par3)
182 * Class: sun/misc/Unsafe
183 * Method: putIntVolatile
184 * Signature: (Ljava/lang/Object;JI)V
186 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putIntVolatile(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, s8 par2, s4 par3)
192 * Class: sun/misc/Unsafe
193 * Method: getIntVolatile
194 * Signature: (Ljava/lang/Object;J)I
196 JNIEXPORT s4 JNICALL Java_sun_misc_Unsafe_getIntVolatile(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, s8 par2)
202 * Class: sun/misc/Unsafe
203 * Method: putLongVolatile
204 * Signature: (Ljava/lang/Object;JJ)V
206 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLongVolatile(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, s8 par2, s8 par3)
212 * Class: sun/misc/Unsafe
214 * Signature: (Ljava/lang/Object;JJ)V
216 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLong(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, s8 par2, s8 par3)
222 * Class: sun/misc/Unsafe
223 * Method: getLongVolatile
224 * Signature: (Ljava/lang/Object;J)J
226 JNIEXPORT s8 JNICALL Java_sun_misc_Unsafe_getLongVolatile(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, s8 par2)
232 * Class: sun/misc/Unsafe
234 * Signature: (Ljava/lang/Object;J)J
236 JNIEXPORT s8 JNICALL Java_sun_misc_Unsafe_getLong(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, s8 par2)
242 * Class: sun/misc/Unsafe
243 * Method: putObjectVolatile
244 * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
246 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putObjectVolatile(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, s8 par2, struct java_lang_Object* par3)
252 * Class: sun/misc/Unsafe
254 * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
256 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putObject(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, s8 par2, struct java_lang_Object* par3)
262 * Class: sun/misc/Unsafe
263 * Method: getObjectVolatile
264 * Signature: (Ljava/lang/Object;J)Ljava/lang/Object;
266 JNIEXPORT struct java_lang_Object* JNICALL Java_sun_misc_Unsafe_getObjectVolatile(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, s8 par2)
272 * Class: sun/misc/Unsafe
273 * Method: arrayBaseOffset
274 * Signature: (Ljava/lang/Class;)I
276 JNIEXPORT s4 JNICALL Java_sun_misc_Unsafe_arrayBaseOffset(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Class* par1)
282 * Class: sun/misc/Unsafe
283 * Method: arrayIndexScale
284 * Signature: (Ljava/lang/Class;)I
286 JNIEXPORT s4 JNICALL Java_sun_misc_Unsafe_arrayIndexScale(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Class* par1)
292 * Class: sun/misc/Unsafe
294 * Signature: (Ljava/lang/Thread;)V
296 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_unpark(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Thread* par1)
302 * Class: sun/misc/Unsafe
306 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_park(JNIEnv *env, struct sun_misc_Unsafe* this, s4 par1, s8 par2)
313 * These are local overrides for various environment variables in Emacs.
314 * Please do not remove this and leave it at the end of the file, where
315 * Emacs will automagically detect them.
316 * ---------------------------------------------------------------------
319 * indent-tabs-mode: t