Merged revisions 7797-7917 via svnmerge from
[cacao.git] / src / native / vm / gnu / sun_misc_Unsafe.c
1 /* src/native/vm/gnu/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 #include "vm/types.h"
32
33 #include "native/jni.h"
34 #include "native/native.h"
35
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 */
39
40 #include "native/include/sun_misc_Unsafe.h"
41
42
43 /* native methods implemented by this file ************************************/
44
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    },
48 #if 0
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                 },
67 #endif
68 };
69
70
71 /* _Jv_sun_misc_Unsafe_init ****************************************************
72
73    Register native functions.
74
75 *******************************************************************************/
76
77 void _Jv_sun_misc_Unsafe_init(void)
78 {
79         utf *u;
80
81         u = utf_new_char("sun/misc/Unsafe");
82
83         native_method_register(u, methods, NATIVE_METHODS_COUNT);
84 }
85
86
87 /*
88  * Class:     sun/misc/Unsafe
89  * Method:    objectFieldOffset
90  * Signature: (Ljava/lang/reflect/Field;)J
91  */
92 JNIEXPORT s8 JNICALL Java_sun_misc_Unsafe_objectFieldOffset(JNIEnv *env, sun_misc_Unsafe* this, java_lang_reflect_Field* field)
93 {
94         classinfo *c;
95         fieldinfo *f;
96
97         c = (classinfo *) field->declaringClass;
98         f = &c->fields[field->slot];
99
100         return (s8) f->offset;
101 }
102
103
104 /*
105  * Class:     sun/misc/Unsafe
106  * Method:    compareAndSwapInt
107  * Signature: (Ljava/lang/Object;JII)Z
108  */
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)
110 {
111         s4 *p;
112         s4  value;
113
114         p = (s4 *) (((u1 *) obj) + offset);
115
116         /* XXX this should be atomic */
117
118         value = *p;
119
120         if (value == expect) {
121                 *p = update;
122
123                 return true;
124         }
125
126         return false;
127 }
128
129
130 #if 0
131 /*
132  * Class:     sun/misc/Unsafe
133  * Method:    compareAndSwapLong
134  * Signature: (Ljava/lang/Object;JJJ)Z
135  */
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)
137 {
138 }
139
140
141 /*
142  * Class:     sun/misc/Unsafe
143  * Method:    compareAndSwapObject
144  * Signature: (Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z
145  */
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)
147 {
148 }
149
150
151 /*
152  * Class:     sun/misc/Unsafe
153  * Method:    putOrderedInt
154  * Signature: (Ljava/lang/Object;JI)V
155  */
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)
157 {
158 }
159
160
161 /*
162  * Class:     sun/misc/Unsafe
163  * Method:    putOrderedLong
164  * Signature: (Ljava/lang/Object;JJ)V
165  */
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)
167 {
168 }
169
170
171 /*
172  * Class:     sun/misc/Unsafe
173  * Method:    putOrderedObject
174  * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
175  */
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)
177 {
178 }
179
180
181 /*
182  * Class:     sun/misc/Unsafe
183  * Method:    putIntVolatile
184  * Signature: (Ljava/lang/Object;JI)V
185  */
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)
187 {
188 }
189
190
191 /*
192  * Class:     sun/misc/Unsafe
193  * Method:    getIntVolatile
194  * Signature: (Ljava/lang/Object;J)I
195  */
196 JNIEXPORT s4 JNICALL Java_sun_misc_Unsafe_getIntVolatile(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, s8 par2)
197 {
198 }
199
200
201 /*
202  * Class:     sun/misc/Unsafe
203  * Method:    putLongVolatile
204  * Signature: (Ljava/lang/Object;JJ)V
205  */
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)
207 {
208 }
209
210
211 /*
212  * Class:     sun/misc/Unsafe
213  * Method:    putLong
214  * Signature: (Ljava/lang/Object;JJ)V
215  */
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)
217 {
218 }
219
220
221 /*
222  * Class:     sun/misc/Unsafe
223  * Method:    getLongVolatile
224  * Signature: (Ljava/lang/Object;J)J
225  */
226 JNIEXPORT s8 JNICALL Java_sun_misc_Unsafe_getLongVolatile(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, s8 par2)
227 {
228 }
229
230
231 /*
232  * Class:     sun/misc/Unsafe
233  * Method:    getLong
234  * Signature: (Ljava/lang/Object;J)J
235  */
236 JNIEXPORT s8 JNICALL Java_sun_misc_Unsafe_getLong(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Object* par1, s8 par2)
237 {
238 }
239
240
241 /*
242  * Class:     sun/misc/Unsafe
243  * Method:    putObjectVolatile
244  * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
245  */
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)
247 {
248 }
249
250
251 /*
252  * Class:     sun/misc/Unsafe
253  * Method:    putObject
254  * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
255  */
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)
257 {
258 }
259
260
261 /*
262  * Class:     sun/misc/Unsafe
263  * Method:    getObjectVolatile
264  * Signature: (Ljava/lang/Object;J)Ljava/lang/Object;
265  */
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)
267 {
268 }
269
270
271 /*
272  * Class:     sun/misc/Unsafe
273  * Method:    arrayBaseOffset
274  * Signature: (Ljava/lang/Class;)I
275  */
276 JNIEXPORT s4 JNICALL Java_sun_misc_Unsafe_arrayBaseOffset(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Class* par1)
277 {
278 }
279
280
281 /*
282  * Class:     sun/misc/Unsafe
283  * Method:    arrayIndexScale
284  * Signature: (Ljava/lang/Class;)I
285  */
286 JNIEXPORT s4 JNICALL Java_sun_misc_Unsafe_arrayIndexScale(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Class* par1)
287 {
288 }
289
290
291 /*
292  * Class:     sun/misc/Unsafe
293  * Method:    unpark
294  * Signature: (Ljava/lang/Thread;)V
295  */
296 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_unpark(JNIEnv *env, struct sun_misc_Unsafe* this, struct java_lang_Thread* par1)
297 {
298 }
299
300
301 /*
302  * Class:     sun/misc/Unsafe
303  * Method:    park
304  * Signature: (ZJ)V
305  */
306 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_park(JNIEnv *env, struct sun_misc_Unsafe* this, s4 par1, s8 par2)
307 {
308 }
309 #endif
310
311
312 /*
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  * ---------------------------------------------------------------------
317  * Local variables:
318  * mode: c
319  * indent-tabs-mode: t
320  * c-basic-offset: 4
321  * tab-width: 4
322  * End:
323  */