82c54860ec76022bf9aa27f75891bdb8887c0e0c
[cacao.git] / src / native / vm / sun_misc_Unsafe.c
1 /* src/native/vm/sun_misc_Unsafe.c - sun/misc/Unsafe
2
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
7
8    This file is part of CACAO.
9
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.
14
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.
19
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
23    02110-1301, USA.
24
25    $Id: java_lang_VMObject.c 5153 2006-07-18 08:19:24Z twisti $
26
27 */
28
29
30 #include "config.h"
31
32 #include <stdint.h>
33
34 #include "native/jni.h"
35 #include "native/native.h"
36
37 #include "native/include/java_lang_Object.h"
38 #include "native/include/java_lang_reflect_Field.h"
39 #include "native/include/java_lang_Thread.h"             /* required by s.m.U */
40
41 #include "native/include/sun_misc_Unsafe.h"
42
43 #include "vmcore/utf8.h"
44
45
46 /* native methods implemented by this file ************************************/
47
48 static JNINativeMethod methods[] = {
49         { "objectFieldOffset",    "(Ljava/lang/reflect/Field;)J",                               (void *) (intptr_t) &Java_sun_misc_Unsafe_objectFieldOffset    },
50         { "compareAndSwapInt",    "(Ljava/lang/Object;JII)Z",                                   (void *) (intptr_t) &Java_sun_misc_Unsafe_compareAndSwapInt    },
51 #if 0
52         { "compareAndSwapLong",   "(Ljava/lang/Object;JJJ)Z",                                   (void *) (intptr_t) &Java_sun_misc_Unsafe_compareAndSwapLong   },
53         { "compareAndSwapObject", "(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z", (void *) (intptr_t) &Java_sun_misc_Unsafe_compareAndSwapObject },
54         { "putOrderedInt",        "(Ljava/lang/Object;JI)V",                                    (void *) (intptr_t) &Java_sun_misc_Unsafe_putOrderedInt        },
55         { "putOrderedLong",       "(Ljava/lang/Object;JJ)V",                                    (void *) (intptr_t) &Java_sun_misc_Unsafe_putOrderedLong       },
56         { "putOrderedObject",     "(Ljava/lang/Object;JLjava/lang/Object;)V",                   (void *) (intptr_t) &Java_sun_misc_Unsafe_putOrderedObject     },
57         { "putIntVolatile",       "(Ljava/lang/Object;JI)V",                                    (void *) (intptr_t) &Java_sun_misc_Unsafe_putIntVolatile       },
58         { "getIntVolatile",       "(Ljava/lang/Object;J)I",                                     (void *) (intptr_t) &Java_sun_misc_Unsafe_getIntVolatile       },
59         { "putLongVolatile",      "(Ljava/lang/Object;JJ)V",                                    (void *) (intptr_t) &Java_sun_misc_Unsafe_putLongVolatile      },
60         { "putLong",              "(Ljava/lang/Object;JJ)V",                                    (void *) (intptr_t) &Java_sun_misc_Unsafe_putLong              },
61         { "getLongVolatile",      "(Ljava/lang/Object;J)J",                                     (void *) (intptr_t) &Java_sun_misc_Unsafe_getLongVolatile      },
62         { "getLong",              "(Ljava/lang/Object;J)J",                                     (void *) (intptr_t) &Java_sun_misc_Unsafe_getLong              },
63         { "putObjectVolatile",    "(Ljava/lang/Object;JLjava/lang/Object;)V",                   (void *) (intptr_t) &Java_sun_misc_Unsafe_putObjectVolatile    },
64         { "putObject",            "(Ljava/lang/Object;JLjava/lang/Object;)V",                   (void *) (intptr_t) &Java_sun_misc_Unsafe_putObject            },
65         { "getObjectVolatile",    "(Ljava/lang/Object;J)Ljava/lang/Object;",                    (void *) (intptr_t) &Java_sun_misc_Unsafe_getObjectVolatile    },
66         { "arrayBaseOffset",      "(Ljava/lang/Class;)I",                                       (void *) (intptr_t) &Java_sun_misc_Unsafe_arrayBaseOffset      },
67         { "arrayIndexScale",      "(Ljava/lang/Class;)I",                                       (void *) (intptr_t) &Java_sun_misc_Unsafe_arrayIndexScale      },
68         { "unpark",               "(Ljava/lang/Thread;)V",                                      (void *) (intptr_t) &Java_sun_misc_Unsafe_unpark               },
69         { "park",                 "(ZJ)V",                                                      (void *) (intptr_t) &Java_sun_misc_Unsafe_park                 },
70 #endif
71 };
72
73
74 /* _Jv_sun_misc_Unsafe_init ****************************************************
75
76    Register native functions.
77
78 *******************************************************************************/
79
80 void _Jv_sun_misc_Unsafe_init(void)
81 {
82         utf *u;
83
84         u = utf_new_char("sun/misc/Unsafe");
85
86         native_method_register(u, methods, NATIVE_METHODS_COUNT);
87 }
88
89
90 /*
91  * Class:     sun/misc/Unsafe
92  * Method:    objectFieldOffset
93  * Signature: (Ljava/lang/reflect/Field;)J
94  */
95 JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_objectFieldOffset(JNIEnv *env, sun_misc_Unsafe* this, java_lang_reflect_Field* field)
96 {
97         classinfo *c;
98         fieldinfo *f;
99
100         c = (classinfo *) field->declaringClass;
101         f = &c->fields[field->slot];
102
103         return (int64_t) f->offset;
104 }
105
106
107 /*
108  * Class:     sun/misc/Unsafe
109  * Method:    compareAndSwapInt
110  * Signature: (Ljava/lang/Object;JII)Z
111  */
112 JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_compareAndSwapInt(JNIEnv *env, sun_misc_Unsafe* this, java_lang_Object* obj, int64_t offset, int32_t expect, int32_t update)
113 {
114         int32_t *p;
115         int32_t  value;
116
117         p = (int32_t *) (((u1 *) obj) + offset);
118
119         /* XXX this should be atomic */
120
121         value = *p;
122
123         if (value == expect) {
124                 *p = update;
125
126                 return true;
127         }
128
129         return false;
130 }
131
132
133 #if 0
134 /*
135  * Class:     sun/misc/Unsafe
136  * Method:    compareAndSwapLong
137  * Signature: (Ljava/lang/Object;JJJ)Z
138  */
139 JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_compareAndSwapLong(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, int64_t par2, int64_t par3, int64_t par4)
140 {
141 }
142
143
144 /*
145  * Class:     sun/misc/Unsafe
146  * Method:    compareAndSwapObject
147  * Signature: (Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z
148  */
149 JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_compareAndSwapObject(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, int64_t par2, struct java_lang_Object* par3, struct java_lang_Object* par4)
150 {
151 }
152
153
154 /*
155  * Class:     sun/misc/Unsafe
156  * Method:    putOrderedInt
157  * Signature: (Ljava/lang/Object;JI)V
158  */
159 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedInt(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, int64_t par2, int32_t par3)
160 {
161 }
162
163
164 /*
165  * Class:     sun/misc/Unsafe
166  * Method:    putOrderedLong
167  * Signature: (Ljava/lang/Object;JJ)V
168  */
169 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedLong(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, int64_t par2, int64_t par3)
170 {
171 }
172
173
174 /*
175  * Class:     sun/misc/Unsafe
176  * Method:    putOrderedObject
177  * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
178  */
179 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedObject(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, int64_t par2, struct java_lang_Object* par3)
180 {
181 }
182
183
184 /*
185  * Class:     sun/misc/Unsafe
186  * Method:    putIntVolatile
187  * Signature: (Ljava/lang/Object;JI)V
188  */
189 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putIntVolatile(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, int64_t par2, int32_t par3)
190 {
191 }
192
193
194 /*
195  * Class:     sun/misc/Unsafe
196  * Method:    getIntVolatile
197  * Signature: (Ljava/lang/Object;J)I
198  */
199 JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getIntVolatile(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, int64_t par2)
200 {
201 }
202
203
204 /*
205  * Class:     sun/misc/Unsafe
206  * Method:    putLongVolatile
207  * Signature: (Ljava/lang/Object;JJ)V
208  */
209 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLongVolatile(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, int64_t par2, int64_t par3)
210 {
211 }
212
213
214 /*
215  * Class:     sun/misc/Unsafe
216  * Method:    putLong
217  * Signature: (Ljava/lang/Object;JJ)V
218  */
219 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLong(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, int64_t par2, int64_t par3)
220 {
221 }
222
223
224 /*
225  * Class:     sun/misc/Unsafe
226  * Method:    getLongVolatile
227  * Signature: (Ljava/lang/Object;J)J
228  */
229 JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_getLongVolatile(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, int64_t par2)
230 {
231 }
232
233
234 /*
235  * Class:     sun/misc/Unsafe
236  * Method:    getLong
237  * Signature: (Ljava/lang/Object;J)J
238  */
239 JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_getLong(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, int64_t par2)
240 {
241 }
242
243
244 /*
245  * Class:     sun/misc/Unsafe
246  * Method:    putObjectVolatile
247  * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
248  */
249 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putObjectVolatile(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, int64_t par2, struct java_lang_Object* par3)
250 {
251 }
252
253
254 /*
255  * Class:     sun/misc/Unsafe
256  * Method:    putObject
257  * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
258  */
259 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putObject(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, int64_t par2, struct java_lang_Object* par3)
260 {
261 }
262
263
264 /*
265  * Class:     sun/misc/Unsafe
266  * Method:    getObjectVolatile
267  * Signature: (Ljava/lang/Object;J)Ljava/lang/Object;
268  */
269 JNIEXPORT struct java_lang_Object* JNICALL Java_sun_misc_Unsafe_getObjectVolatile(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, int64_t par2)
270 {
271 }
272
273
274 /*
275  * Class:     sun/misc/Unsafe
276  * Method:    arrayBaseOffset
277  * Signature: (Ljava/lang/Class;)I
278  */
279 JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_arrayBaseOffset(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Class* par1)
280 {
281 }
282
283
284 /*
285  * Class:     sun/misc/Unsafe
286  * Method:    arrayIndexScale
287  * Signature: (Ljava/lang/Class;)I
288  */
289 JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_arrayIndexScale(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Class* par1)
290 {
291 }
292
293
294 /*
295  * Class:     sun/misc/Unsafe
296  * Method:    unpark
297  * Signature: (Ljava/lang/Thread;)V
298  */
299 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_unpark(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Thread* par1)
300 {
301 }
302
303
304 /*
305  * Class:     sun/misc/Unsafe
306  * Method:    park
307  * Signature: (ZJ)V
308  */
309 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_park(JNIEnv *env, struct sun_misc_Unsafe* this, int32_t par1, int64_t par2)
310 {
311 }
312 #endif
313
314
315 /*
316  * These are local overrides for various environment variables in Emacs.
317  * Please do not remove this and leave it at the end of the file, where
318  * Emacs will automagically detect them.
319  * ---------------------------------------------------------------------
320  * Local variables:
321  * mode: c
322  * indent-tabs-mode: t
323  * c-basic-offset: 4
324  * tab-width: 4
325  * End:
326  */