Merged with tip.
[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, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
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.
12
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.
17
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
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include <stdint.h>
29 #include <unistd.h>
30
31 #include "machine-instr.h"
32
33 #include "mm/memory.h"
34
35 #include "native/jni.h"
36 #include "native/llni.h"
37 #include "native/native.h"
38
39 #include "native/include/java_lang_Object.h"                  /* before c.l.C */
40 #include "native/include/java_lang_String.h"            /* required by j.l.CL */
41
42 #if defined(WITH_CLASSPATH_SUN)
43 # include "native/include/java_nio_ByteBuffer.h"        /* required by j.l.CL */
44 #endif
45
46 #include "native/include/java_lang_ClassLoader.h"        /* required by j.l.C */
47 #include "native/include/java_lang_Class.h"
48 #include "native/include/java_lang_reflect_Field.h"
49 #include "native/include/java_lang_Thread.h"             /* required by s.m.U */
50 #include "native/include/java_lang_Throwable.h"
51
52 #if defined(WITH_CLASSPATH_GNU)
53 # include "native/include/java_lang_reflect_VMField.h"
54 #endif
55
56 #include "native/include/java_security_ProtectionDomain.h" /* required by smU */
57
58 #include "native/include/sun_misc_Unsafe.h"
59
60 #include "vm/builtin.h"
61 #include "vm/exceptions.h"
62 #include "vm/initialize.h"
63 #include "vm/stringlocal.h"
64
65 #include "vmcore/system.h"
66 #include "vmcore/utf8.h"
67
68
69 /* native methods implemented by this file ************************************/
70
71 static JNINativeMethod methods[] = {
72         { "registerNatives",        "()V",                                                        (void *) (intptr_t) &Java_sun_misc_Unsafe_registerNatives                },
73         { "getInt",                 "(Ljava/lang/Object;J)I",                                     (void *) (intptr_t) &Java_sun_misc_Unsafe_getInt__Ljava_lang_Object_2J   },
74         { "putInt",                 "(Ljava/lang/Object;JI)V",                                    (void *) (intptr_t) &Java_sun_misc_Unsafe_putInt__Ljava_lang_Object_2JI  },
75         { "getObject",              "(Ljava/lang/Object;J)Ljava/lang/Object;",                    (void *) (intptr_t) &Java_sun_misc_Unsafe_getObject                      },
76         { "putObject",              "(Ljava/lang/Object;JLjava/lang/Object;)V",                   (void *) (intptr_t) &Java_sun_misc_Unsafe_putObject                      },
77         { "getBoolean",             "(Ljava/lang/Object;J)Z",                                     (void *) (intptr_t) &Java_sun_misc_Unsafe_getBoolean                     },
78         { "putBoolean",             "(Ljava/lang/Object;JZ)V",                                    (void *) (intptr_t) &Java_sun_misc_Unsafe_putBoolean                     },
79         { "getByte",                "(Ljava/lang/Object;J)B",                                     (void *) (intptr_t) &Java_sun_misc_Unsafe_getByte__Ljava_lang_Object_2J  },
80         { "putByte",                "(Ljava/lang/Object;JB)V",                                    (void *) (intptr_t) &Java_sun_misc_Unsafe_putByte__Ljava_lang_Object_2JB },
81         { "getShort",               "(Ljava/lang/Object;J)S",                                     (void *) (intptr_t) &Java_sun_misc_Unsafe_getShort__Ljava_lang_Object_2J },
82         { "putShort",               "(Ljava/lang/Object;JS)V",                                    (void *) (intptr_t) &Java_sun_misc_Unsafe_putShort__Ljava_lang_Object_2JS },
83         { "getChar",                "(Ljava/lang/Object;J)C",                                     (void *) (intptr_t) &Java_sun_misc_Unsafe_getChar__Ljava_lang_Object_2J  },
84         { "putChar",                "(Ljava/lang/Object;JC)V",                                    (void *) (intptr_t) &Java_sun_misc_Unsafe_putChar__Ljava_lang_Object_2JC },
85         { "getLong",                "(Ljava/lang/Object;J)J",                                     (void *) (intptr_t) &Java_sun_misc_Unsafe_getLong__Ljava_lang_Object_2J  },
86         { "putLong",                "(Ljava/lang/Object;JJ)V",                                    (void *) (intptr_t) &Java_sun_misc_Unsafe_putLong__Ljava_lang_Object_2JJ },
87         { "getFloat",               "(Ljava/lang/Object;J)F",                                     (void *) (intptr_t) &Java_sun_misc_Unsafe_getFloat__Ljava_lang_Object_2J },
88         { "putFloat",               "(Ljava/lang/Object;JF)V",                                    (void *) (intptr_t) &Java_sun_misc_Unsafe_putFloat__Ljava_lang_Object_2JF },
89         { "getDouble",              "(Ljava/lang/Object;J)D",                                     (void *) (intptr_t) &Java_sun_misc_Unsafe_getDouble__Ljava_lang_Object_2J },
90         { "putDouble",              "(Ljava/lang/Object;JD)V",                                    (void *) (intptr_t) &Java_sun_misc_Unsafe_putDouble__Ljava_lang_Object_2JD },
91         { "getByte",                "(J)B",                                                       (void *) (intptr_t) &Java_sun_misc_Unsafe_getByte__J                     },
92         { "putByte",                "(JB)V",                                                      (void *) (intptr_t) &Java_sun_misc_Unsafe_putByte__JB                    },
93         { "getShort",               "(J)S",                                                       (void *) (intptr_t) &Java_sun_misc_Unsafe_getShort__J                    },
94         { "putShort",               "(JS)V",                                                      (void *) (intptr_t) &Java_sun_misc_Unsafe_putShort__JS                   },
95         { "getChar",                "(J)C",                                                       (void *) (intptr_t) &Java_sun_misc_Unsafe_getChar__J                     },
96         { "putChar",                "(JC)V",                                                      (void *) (intptr_t) &Java_sun_misc_Unsafe_putChar__JC                    },
97         { "getInt",                 "(J)I",                                                       (void *) (intptr_t) &Java_sun_misc_Unsafe_getInt__J                      },
98         { "putInt",                 "(JI)V",                                                      (void *) (intptr_t) &Java_sun_misc_Unsafe_putInt__JI                     },
99         { "getLong",                "(J)J",                                                       (void *) (intptr_t) &Java_sun_misc_Unsafe_getLong__J                     },
100         { "putLong",                "(JJ)V",                                                      (void *) (intptr_t) &Java_sun_misc_Unsafe_putLong__JJ                    },
101         { "getFloat",               "(J)F",                                                       (void *) (intptr_t) &Java_sun_misc_Unsafe_getFloat__J                    },
102         { "objectFieldOffset",      "(Ljava/lang/reflect/Field;)J",                               (void *) (intptr_t) &Java_sun_misc_Unsafe_objectFieldOffset              },
103         { "allocateMemory",         "(J)J",                                                       (void *) (intptr_t) &Java_sun_misc_Unsafe_allocateMemory                 },
104 #if 0
105         /* OpenJDK 7 */
106         { "setMemory",              "(Ljava/lang/Object;JJB)V",                                   (void *) (intptr_t) &Java_sun_misc_Unsafe_setMemory                      },
107         { "copyMemory",             "(Ljava/lang/Object;JLjava/lang/Object;JJ)V",                 (void *) (intptr_t) &Java_sun_misc_Unsafe_copyMemory                     },
108 #else
109         { "setMemory",              "(JJB)V",                                                     (void *) (intptr_t) &Java_sun_misc_Unsafe_setMemory                      },
110         { "copyMemory",             "(JJJ)V",                                                     (void *) (intptr_t) &Java_sun_misc_Unsafe_copyMemory                     },
111 #endif
112         { "freeMemory",             "(J)V",                                                       (void *) (intptr_t) &Java_sun_misc_Unsafe_freeMemory                     },
113         { "staticFieldOffset",      "(Ljava/lang/reflect/Field;)J",                               (void *) (intptr_t) &Java_sun_misc_Unsafe_staticFieldOffset              },
114         { "staticFieldBase",        "(Ljava/lang/reflect/Field;)Ljava/lang/Object;",              (void *) (intptr_t) &Java_sun_misc_Unsafe_staticFieldBase                },
115         { "ensureClassInitialized", "(Ljava/lang/Class;)V",                                       (void *) (intptr_t) &Java_sun_misc_Unsafe_ensureClassInitialized         },
116         { "arrayBaseOffset",        "(Ljava/lang/Class;)I",                                       (void *) (intptr_t) &Java_sun_misc_Unsafe_arrayBaseOffset                },
117         { "arrayIndexScale",        "(Ljava/lang/Class;)I",                                       (void *) (intptr_t) &Java_sun_misc_Unsafe_arrayIndexScale                },
118         { "addressSize",            "()I",                                                        (void *) (intptr_t) &Java_sun_misc_Unsafe_addressSize                    },
119         { "pageSize",               "()I",                                                        (void *) (intptr_t) &Java_sun_misc_Unsafe_pageSize                       },
120         { "defineClass",            "(Ljava/lang/String;[BIILjava/lang/ClassLoader;Ljava/security/ProtectionDomain;)Ljava/lang/Class;", (void *) (intptr_t) &Java_sun_misc_Unsafe_defineClass__Ljava_lang_String_2_3BIILjava_lang_ClassLoader_2Ljava_security_ProtectionDomain_2 },
121         { "allocateInstance",       "(Ljava/lang/Class;)Ljava/lang/Object;",                      (void *) (intptr_t) &Java_sun_misc_Unsafe_allocateInstance               },
122         { "throwException",         "(Ljava/lang/Throwable;)V",                                   (void *) (intptr_t) &Java_sun_misc_Unsafe_throwException                 },
123         { "compareAndSwapObject",   "(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z", (void *) (intptr_t) &Java_sun_misc_Unsafe_compareAndSwapObject           },
124         { "compareAndSwapInt",      "(Ljava/lang/Object;JII)Z",                                   (void *) (intptr_t) &Java_sun_misc_Unsafe_compareAndSwapInt              },
125         { "compareAndSwapLong",     "(Ljava/lang/Object;JJJ)Z",                                   (void *) (intptr_t) &Java_sun_misc_Unsafe_compareAndSwapLong             },
126         { "getObjectVolatile",      "(Ljava/lang/Object;J)Ljava/lang/Object;",                    (void *) (intptr_t) &Java_sun_misc_Unsafe_getObjectVolatile              },
127         { "putObjectVolatile",      "(Ljava/lang/Object;JLjava/lang/Object;)V",                   (void *) (intptr_t) &Java_sun_misc_Unsafe_putObjectVolatile              },
128         { "getIntVolatile",         "(Ljava/lang/Object;J)I",                                     (void *) (intptr_t) &Java_sun_misc_Unsafe_getIntVolatile                 },
129         { "putIntVolatile",         "(Ljava/lang/Object;JI)V",                                    (void *) (intptr_t) &Java_sun_misc_Unsafe_putIntVolatile                 },
130         { "getLongVolatile",        "(Ljava/lang/Object;J)J",                                     (void *) (intptr_t) &Java_sun_misc_Unsafe_getLongVolatile                },
131         { "putLongVolatile",        "(Ljava/lang/Object;JJ)V",                                    (void *) (intptr_t) &Java_sun_misc_Unsafe_putLongVolatile                },
132         { "putOrderedObject",       "(Ljava/lang/Object;JLjava/lang/Object;)V",                   (void *) (intptr_t) &Java_sun_misc_Unsafe_putOrderedObject               },
133         { "putOrderedInt",          "(Ljava/lang/Object;JI)V",                                    (void *) (intptr_t) &Java_sun_misc_Unsafe_putOrderedInt                  },
134         { "putOrderedLong",         "(Ljava/lang/Object;JJ)V",                                    (void *) (intptr_t) &Java_sun_misc_Unsafe_putOrderedLong                 },
135         { "unpark",                 "(Ljava/lang/Object;)V",                                      (void *) (intptr_t) &Java_sun_misc_Unsafe_unpark                         },
136         { "park",                   "(ZJ)V",                                                      (void *) (intptr_t) &Java_sun_misc_Unsafe_park                           },
137 };
138
139
140 /* _Jv_sun_misc_Unsafe_init ****************************************************
141
142    Register native functions.
143
144 *******************************************************************************/
145
146 void _Jv_sun_misc_Unsafe_init(void)
147 {
148         utf *u;
149
150         u = utf_new_char("sun/misc/Unsafe");
151
152         native_method_register(u, methods, NATIVE_METHODS_COUNT);
153 }
154
155
156 /*
157  * Class:     sun/misc/Unsafe
158  * Method:    registerNatives
159  * Signature: ()V
160  */
161 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_registerNatives(JNIEnv *env, jclass clazz)
162 {
163         /* The native methods of this function are already registered in
164            _Jv_sun_misc_Unsafe_init() which is called during VM
165            startup. */
166 }
167
168
169 /*
170  * Class:     sun/misc/Unsafe
171  * Method:    getInt
172  * Signature: (Ljava/lang/Object;J)I
173  */
174 JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getInt__Ljava_lang_Object_2J(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset)
175 {
176         int32_t *p;
177         int32_t  value;
178
179         p = (int32_t *) (((uint8_t *) o) + offset);
180
181         value = *p;
182
183         return value;
184 }
185
186
187 /*
188  * Class:     sun/misc/Unsafe
189  * Method:    putInt
190  * Signature: (Ljava/lang/Object;JI)V
191  */
192 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putInt__Ljava_lang_Object_2JI(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset, int32_t x)
193 {
194         int32_t *p;
195
196         p = (int32_t *) (((uint8_t *) o) + offset);
197
198         *p = x;
199 }
200
201
202 /*
203  * Class:     sun/misc/Unsafe
204  * Method:    getObject
205  * Signature: (Ljava/lang/Object;J)Ljava/lang/Object;
206  */
207 JNIEXPORT java_lang_Object* JNICALL Java_sun_misc_Unsafe_getObject(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset)
208 {
209         void **p;
210         void  *value;
211
212         p = (void **) (((uint8_t *) o) + offset);
213
214         value = *p;
215
216         return value;
217 }
218
219
220 /*
221  * Class:     sun/misc/Unsafe
222  * Method:    putObject
223  * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
224  */
225 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putObject(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset, java_lang_Object *x)
226 {
227         void **p;
228
229         p = (void **) (((uint8_t *) o) + offset);
230
231         *p = (void *) x;
232 }
233
234
235 /*
236  * Class:     sun/misc/Unsafe
237  * Method:    getBoolean
238  * Signature: (Ljava/lang/Object;J)Z
239  */
240 JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getBoolean(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset)
241 {
242         int32_t *p;
243         int32_t  value;
244
245         p = (int32_t *) (((uint8_t *) o) + offset);
246
247         value = *p;
248
249         return value;
250 }
251
252
253 /*
254  * Class:     sun/misc/Unsafe
255  * Method:    putBoolean
256  * Signature: (Ljava/lang/Object;JZ)V
257  */
258 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putBoolean(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset, int32_t x)
259 {
260         int32_t *p;
261
262         p = (int32_t *) (((uint8_t *) o) + offset);
263
264         *p = x;
265 }
266
267
268 /*
269  * Class:     sun/misc/Unsafe
270  * Method:    getByte
271  * Signature: (Ljava/lang/Object;J)B
272  */
273 JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getByte__Ljava_lang_Object_2J(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset)
274 {
275         int32_t *p;
276         int32_t  value;
277
278         p = (int32_t *) (((uint8_t *) o) + offset);
279
280         value = *p;
281
282         return value;
283 }
284
285
286 /*
287  * Class:     sun/misc/Unsafe
288  * Method:    putByte
289  * Signature: (Ljava/lang/Object;JB)V
290  */
291 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putByte__Ljava_lang_Object_2JB(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset, int32_t x)
292 {
293         int32_t *p;
294
295         p = (int32_t *) (((uint8_t *) o) + offset);
296
297         *p = x;
298 }
299
300
301 /*
302  * Class:     sun/misc/Unsafe
303  * Method:    getShort
304  * Signature: (Ljava/lang/Object;J)S
305  */
306 JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getShort__Ljava_lang_Object_2J(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset)
307 {
308         int32_t *p;
309         int32_t  value;
310
311         p = (int32_t *) (((uint8_t *) o) + offset);
312
313         value = *p;
314
315         return value;
316 }
317
318
319 /*
320  * Class:     sun/misc/Unsafe
321  * Method:    putShort
322  * Signature: (Ljava/lang/Object;JS)V
323  */
324 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putShort__Ljava_lang_Object_2JS(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset, int32_t x)
325 {
326         int32_t *p;
327
328         p = (int32_t *) (((uint8_t *) o) + offset);
329
330         *p = x;
331 }
332
333
334 /*
335  * Class:     sun/misc/Unsafe
336  * Method:    getChar
337  * Signature: (Ljava/lang/Object;J)C
338  */
339 JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getChar__Ljava_lang_Object_2J(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset)
340 {
341         int32_t *p;
342         int32_t  value;
343
344         p = (int32_t *) (((uint8_t *) o) + offset);
345
346         value = *p;
347
348         return value;
349 }
350
351
352 /*
353  * Class:     sun/misc/Unsafe
354  * Method:    putChar
355  * Signature: (Ljava/lang/Object;JC)V
356  */
357 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putChar__Ljava_lang_Object_2JC(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset, int32_t x)
358 {
359         int32_t *p;
360
361         p = (int32_t *) (((uint8_t *) o) + offset);
362
363         *p = x;
364 }
365
366
367 /*
368  * Class:     sun/misc/Unsafe
369  * Method:    getLong
370  * Signature: (Ljava/lang/Object;J)J
371  */
372 JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_getLong__Ljava_lang_Object_2J(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset)
373 {
374         int64_t *p;
375         int64_t  value;
376
377         p = (int64_t *) (((uint8_t *) o) + offset);
378
379         value = *p;
380
381         return value;
382 }
383
384
385 /*
386  * Class:     sun/misc/Unsafe
387  * Method:    putLong
388  * Signature: (Ljava/lang/Object;JJ)V
389  */
390 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLong__Ljava_lang_Object_2JJ(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset, int64_t x)
391 {
392         int64_t *p;
393
394         p = (int64_t *) (((uint8_t *) o) + offset);
395
396         *p = x;
397 }
398
399
400 /*
401  * Class:     sun/misc/Unsafe
402  * Method:    getFloat
403  * Signature: (Ljava/lang/Object;J)F
404  */
405 JNIEXPORT float JNICALL Java_sun_misc_Unsafe_getFloat__Ljava_lang_Object_2J(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset)
406 {
407         float *p;
408         float  value;
409
410         p = (float *) (((uint8_t *) o) + offset);
411
412         value = *p;
413
414         return value;
415 }
416
417
418 /*
419  * Class:     sun/misc/Unsafe
420  * Method:    putFloat
421  * Signature: (Ljava/lang/Object;JF)V
422  */
423 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putFloat__Ljava_lang_Object_2JF(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset, float x)
424 {
425         float *p;
426
427         p = (float *) (((uint8_t *) o) + offset);
428
429         *p = x;
430 }
431
432
433 /*
434  * Class:     sun/misc/Unsafe
435  * Method:    getDouble
436  * Signature: (Ljava/lang/Object;J)D
437  */
438 JNIEXPORT double JNICALL Java_sun_misc_Unsafe_getDouble__Ljava_lang_Object_2J(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset)
439 {
440         double *p;
441         double  value;
442
443         p = (double *) (((uint8_t *) o) + offset);
444
445         value = *p;
446
447         return value;
448 }
449
450
451 /*
452  * Class:     sun/misc/Unsafe
453  * Method:    putDouble
454  * Signature: (Ljava/lang/Object;JD)V
455  */
456 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putDouble__Ljava_lang_Object_2JD(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset, double x)
457 {
458         double *p;
459
460         p = (double *) (((uint8_t *) o) + offset);
461
462         *p = x;
463 }
464
465
466 /*
467  * Class:     sun/misc/Unsafe
468  * Method:    getByte
469  * Signature: (J)B
470  */
471 JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getByte__J(JNIEnv *env, sun_misc_Unsafe *this, int64_t address)
472 {
473         int8_t *p;
474         int8_t  value;
475
476         p = (int8_t *) (intptr_t) address;
477
478         value = *p;
479
480         return (int32_t) value;
481 }
482
483
484 /*
485  * Class:     sun/misc/Unsafe
486  * Method:    putByte
487  * Signature: (JB)V
488  */
489 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putByte__JB(JNIEnv *env, sun_misc_Unsafe *this, int64_t address, int32_t value)
490 {
491         int8_t *p;
492
493         p = (int8_t *) (intptr_t) address;
494
495         *p = (int8_t) value;
496 }
497
498
499 /*
500  * Class:     sun/misc/Unsafe
501  * Method:    getShort
502  * Signature: (J)S
503  */
504 JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getShort__J(JNIEnv *env, sun_misc_Unsafe *this, int64_t address)
505 {
506         int16_t *p;
507         int16_t  value;
508
509         p = (int16_t *) (intptr_t) address;
510
511         value = *p;
512
513         return (int32_t) value;
514 }
515
516
517 /*
518  * Class:     sun/misc/Unsafe
519  * Method:    putShort
520  * Signature: (JS)V
521  */
522 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putShort__JS(JNIEnv *env, sun_misc_Unsafe *this, int64_t address, int32_t value)
523 {
524         int16_t *p;
525
526         p = (int16_t *) (intptr_t) address;
527
528         *p = (int16_t) value;
529 }
530
531
532 /*
533  * Class:     sun/misc/Unsafe
534  * Method:    getChar
535  * Signature: (J)C
536  */
537 JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getChar__J(JNIEnv *env, sun_misc_Unsafe *this, int64_t address)
538 {
539         uint16_t *p;
540         uint16_t  value;
541
542         p = (uint16_t *) (intptr_t) address;
543
544         value = *p;
545
546         return (int32_t) value;
547 }
548
549
550 /*
551  * Class:     sun/misc/Unsafe
552  * Method:    putChar
553  * Signature: (JC)V
554  */
555 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putChar__JC(JNIEnv *env, sun_misc_Unsafe *this, int64_t address, int32_t value)
556 {
557         uint16_t *p;
558
559         p = (uint16_t *) (intptr_t) address;
560
561         *p = (uint16_t) value;
562 }
563
564
565 /*
566  * Class:     sun/misc/Unsafe
567  * Method:    getInt
568  * Signature: (J)I
569  */
570 JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getInt__J(JNIEnv *env, sun_misc_Unsafe *this, int64_t address)
571 {
572         int32_t *p;
573         int32_t  value;
574
575         p = (int32_t *) (intptr_t) address;
576
577         value = *p;
578
579         return value;
580 }
581
582
583 /*
584  * Class:     sun/misc/Unsafe
585  * Method:    putInt
586  * Signature: (JI)V
587  */
588 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putInt__JI(JNIEnv *env, struct sun_misc_Unsafe* this, int64_t address, int32_t value)
589 {
590         int32_t *p;
591
592         p = (int32_t *) (intptr_t) address;
593
594         *p = value;
595 }
596
597
598 /*
599  * Class:     sun/misc/Unsafe
600  * Method:    getLong
601  * Signature: (J)J
602  */
603 JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_getLong__J(JNIEnv *env, sun_misc_Unsafe *this, int64_t address)
604 {
605         int64_t *p;
606         int64_t  value;
607
608         p = (int64_t *) (intptr_t) address;
609
610         value = *p;
611
612         return value;
613 }
614
615
616 /*
617  * Class:     sun/misc/Unsafe
618  * Method:    putLong
619  * Signature: (JJ)V
620  */
621 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLong__JJ(JNIEnv *env, sun_misc_Unsafe *this, int64_t address, int64_t value)
622 {
623         int64_t *p;
624
625         p = (int64_t *) (intptr_t) address;
626
627         *p = value;
628 }
629
630
631 /*
632  * Class:     sun/misc/Unsafe
633  * Method:    getFloat
634  * Signature: (J)F
635  */
636 JNIEXPORT float JNICALL Java_sun_misc_Unsafe_getFloat__J(JNIEnv *env, sun_misc_Unsafe *this, int64_t address)
637 {
638         float *p;
639         float  value;
640
641         p = (float *) (intptr_t) address;
642
643         value = *p;
644
645         return value;
646 }
647
648
649 /*
650  * Class:     sun/misc/Unsafe
651  * Method:    objectFieldOffset
652  * Signature: (Ljava/lang/reflect/Field;)J
653  */
654 JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_objectFieldOffset(JNIEnv *env, sun_misc_Unsafe *this, java_lang_reflect_Field *field)
655 {
656         classinfo *c;
657         fieldinfo *f;
658         int32_t    slot;
659
660 #if defined(WITH_CLASSPATH_GNU)
661         java_lang_reflect_VMField *rvmf;
662 #endif
663
664 #if defined(WITH_CLASSPATH_GNU)
665
666         LLNI_field_get_ref(field, f,     rvmf);
667         LLNI_field_get_cls(rvmf,  clazz, c);
668         LLNI_field_get_val(rvmf,  slot , slot);
669
670 #elif defined(WITH_CLASSPATH_SUN)
671
672         LLNI_field_get_cls(field, clazz, c);
673         LLNI_field_get_val(field, slot , slot);
674
675 #else
676 # error unknown configuration
677 #endif
678
679         f = &(c->fields[slot]);
680
681         return (int64_t) f->offset;
682 }
683
684
685 /*
686  * Class:     sun/misc/Unsafe
687  * Method:    allocateMemory
688  * Signature: (J)J
689  */
690 JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_allocateMemory(JNIEnv *env, sun_misc_Unsafe *this, int64_t bytes)
691 {
692         size_t  length;
693         void   *p;
694
695         length = (size_t) bytes;
696
697         if ((length != (uint64_t) bytes) || (bytes < 0)) {
698                 exceptions_throw_illegalargumentexception();
699                 return 0;
700         }
701
702         p = MNEW(uint8_t, length);
703
704         return (int64_t) (intptr_t) p;
705 }
706
707
708 #if 0
709 /* OpenJDK 7 */
710
711 /*
712  * Class:     sun/misc/Unsafe
713  * Method:    setMemory
714  * Signature: (Ljava/lang/Object;JJB)V
715  */
716 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_setMemory(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset, int64_t bytes, int32_t value)
717 {
718         size_t  length;
719         void   *p;
720
721         length = (size_t) bytes;
722
723         if ((length != (uint64_t) bytes) || (bytes < 0)) {
724                 exceptions_throw_illegalargumentexception();
725                 return;
726         }
727
728         /* XXX Missing LLNI: we need to unwrap this object. */
729
730         p = (void *) (((uint8_t *) o) + offset);
731
732         /* XXX Not sure this is correct. */
733
734         system_memset(p, value, length);
735 }
736
737
738 /*
739  * Class:     sun/misc/Unsafe
740  * Method:    copyMemory
741  * Signature: (Ljava/lang/Object;JLjava/lang/Object;JJ)V
742  */
743 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_copyMemory(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *srcBase, int64_t srcOffset, java_lang_Object *destBase, int64_t destOffset, int64_t bytes)
744 {
745         size_t  length;
746         void   *src;
747         void   *dest;
748
749         if (bytes == 0)
750                 return;
751
752         length = (size_t) bytes;
753
754         if ((length != (uint64_t) bytes) || (bytes < 0)) {
755                 exceptions_throw_illegalargumentexception();
756                 return;
757         }
758
759         /* XXX Missing LLNI: We need to unwrap these objects. */
760
761         src  = (void *) (((uint8_t *) srcBase) + srcOffset);
762         dest = (void *) (((uint8_t *) destBase) + destOffset);
763
764         system_memcpy(dest, src, length);
765 }
766 #else
767 /*
768  * Class:     sun/misc/Unsafe
769  * Method:    setMemory
770  * Signature: (JJB)V
771  */
772 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_setMemory(JNIEnv *env, sun_misc_Unsafe *this, int64_t address, int64_t bytes, int32_t value)
773 {
774         size_t  length;
775         void   *p;
776
777         length = (size_t) bytes;
778
779         if ((length != (uint64_t) bytes) || (bytes < 0)) {
780                 exceptions_throw_illegalargumentexception();
781                 return;
782         }
783
784         p = (void *) (intptr_t) address;
785
786         /* XXX Not sure this is correct. */
787
788         system_memset(p, value, length);
789 }
790
791
792 /*
793  * Class:     sun/misc/Unsafe
794  * Method:    copyMemory
795  * Signature: (JJJ)V
796  */
797 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_copyMemory(JNIEnv *env, sun_misc_Unsafe *this, int64_t srcAddress, int64_t destAddress, int64_t bytes)
798 {
799         size_t  length;
800         void   *src;
801         void   *dest;
802
803         if (bytes == 0)
804                 return;
805
806         length = (size_t) bytes;
807
808         if ((length != (uint64_t) bytes) || (bytes < 0)) {
809                 exceptions_throw_illegalargumentexception();
810                 return;
811         }
812
813         src  = (void *) (intptr_t) srcAddress;
814         dest = (void *) (intptr_t) destAddress;
815
816         system_memcpy(dest, src, length);
817 }
818 #endif
819
820
821 /*
822  * Class:     sun/misc/Unsafe
823  * Method:    freeMemory
824  * Signature: (J)V
825  */
826 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_freeMemory(JNIEnv *env, sun_misc_Unsafe *this, int64_t address)
827 {
828         void *p;
829
830         p = (void *) (intptr_t) address;
831
832         if (p == NULL)
833                 return;
834
835         /* we pass length 1 to trick the free function */
836
837         MFREE(p, uint8_t, 1);
838 }
839
840
841 /*
842  * Class:     sun/misc/Unsafe
843  * Method:    staticFieldOffset
844  * Signature: (Ljava/lang/reflect/Field;)J
845  */
846 JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_staticFieldOffset(JNIEnv *env, sun_misc_Unsafe *this, java_lang_reflect_Field *f)
847 {
848         /* The offset of static fields is 0. */
849
850         return 0;
851 }
852
853
854 /*
855  * Class:     sun/misc/Unsafe
856  * Method:    staticFieldBase
857  * Signature: (Ljava/lang/reflect/Field;)Ljava/lang/Object;
858  */
859 JNIEXPORT java_lang_Object* JNICALL Java_sun_misc_Unsafe_staticFieldBase(JNIEnv *env, sun_misc_Unsafe *this, java_lang_reflect_Field *rf)
860 {
861         classinfo *c;
862         fieldinfo *f;
863         int32_t    slot;
864
865 #if defined(WITH_CLASSPATH_GNU)
866         java_lang_reflect_VMField *rvmf;
867 #endif
868
869 #if defined(WITH_CLASSPATH_GNU)
870
871         LLNI_field_get_ref(rf,   f,     rvmf);
872         LLNI_field_get_cls(rvmf, clazz, c);
873         LLNI_field_get_val(rvmf, slot , slot);
874
875 #elif defined(WITH_CLASSPATH_SUN)
876
877         LLNI_field_get_cls(rf, clazz, c);
878         LLNI_field_get_val(rf, slot , slot);
879
880 #else
881 # error unknown configuration
882 #endif
883
884         f = &(c->fields[slot]);
885
886         return (java_lang_Object *) (f->value);
887 }
888
889
890 /*
891  * Class:     sun/misc/Unsafe
892  * Method:    ensureClassInitialized
893  * Signature: (Ljava/lang/Class;)V
894  */
895 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_ensureClassInitialized(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Class *class)
896 {
897         classinfo *c;
898
899         c = LLNI_classinfo_unwrap(class);
900
901         if (!(c->state & CLASS_INITIALIZED))
902                 initialize_class(c);
903 }
904
905
906 /*
907  * Class:     sun/misc/Unsafe
908  * Method:    arrayBaseOffset
909  * Signature: (Ljava/lang/Class;)I
910  */
911 JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_arrayBaseOffset(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Class *arrayClass)
912 {
913         classinfo       *c;
914         arraydescriptor *ad;
915
916         c  = LLNI_classinfo_unwrap(arrayClass);
917         ad = c->vftbl->arraydesc;
918
919         if (ad == NULL) {
920                 /* XXX does that exception exist? */
921                 exceptions_throw_internalerror("java/lang/InvalidClassException");
922                 return 0;
923         }
924
925         return ad->dataoffset;
926 }
927
928
929 /*
930  * Class:     sun/misc/Unsafe
931  * Method:    arrayIndexScale
932  * Signature: (Ljava/lang/Class;)I
933  */
934 JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_arrayIndexScale(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Class *arrayClass)
935 {
936         classinfo       *c;
937         arraydescriptor *ad;
938
939         c  = LLNI_classinfo_unwrap(arrayClass);
940         ad = c->vftbl->arraydesc;
941
942         if (ad == NULL) {
943                 /* XXX does that exception exist? */
944                 exceptions_throw_internalerror("java/lang/InvalidClassException");
945                 return 0;
946         }
947
948         return ad->componentsize;
949 }
950
951
952 /*
953  * Class:     sun/misc/Unsafe
954  * Method:    addressSize
955  * Signature: ()I
956  */
957 JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_addressSize(JNIEnv *env, sun_misc_Unsafe *this)
958 {
959         return SIZEOF_VOID_P;
960 }
961
962
963 /*
964  * Class:     sun/misc/Unsafe
965  * Method:    pageSize
966  * Signature: ()I
967  */
968 JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_pageSize(JNIEnv *env, sun_misc_Unsafe *this)
969 {
970         int sz;
971
972         sz = getpagesize();
973
974         return sz;
975 }
976
977
978 /*
979  * Class:     sun/misc/Unsafe
980  * Method:    defineClass
981  * Signature: (Ljava/lang/String;[BIILjava/lang/ClassLoader;Ljava/security/ProtectionDomain;)Ljava/lang/Class;
982  */
983 JNIEXPORT java_lang_Class* JNICALL Java_sun_misc_Unsafe_defineClass__Ljava_lang_String_2_3BIILjava_lang_ClassLoader_2Ljava_security_ProtectionDomain_2(JNIEnv *env, sun_misc_Unsafe *this, java_lang_String *name, java_handle_bytearray_t *b, int32_t off, int32_t len, java_lang_ClassLoader *loader, java_security_ProtectionDomain *protectionDomain)
984 {
985         classloader_t   *cl;
986         utf             *utfname;
987         classinfo       *c;
988         java_lang_Class *o;
989
990         cl = loader_hashtable_classloader_add((java_handle_t *) loader);
991
992         /* check if data was passed */
993
994         if (b == NULL) {
995                 exceptions_throw_nullpointerexception();
996                 return NULL;
997         }
998
999         /* check the indexes passed */
1000
1001         if ((off < 0) || (len < 0) || ((off + len) > LLNI_array_size(b))) {
1002                 exceptions_throw_arrayindexoutofboundsexception();
1003                 return NULL;
1004         }
1005
1006         if (name != NULL) {
1007                 /* convert '.' to '/' in java string */
1008
1009                 utfname = javastring_toutf((java_handle_t *) name, true);
1010         } 
1011         else {
1012                 utfname = NULL;
1013         }
1014
1015         /* define the class */
1016
1017         c = class_define(utfname, cl, len, (uint8_t *) &(LLNI_array_direct(b, off)),
1018                                          (java_handle_t *) protectionDomain);
1019
1020         if (c == NULL)
1021                 return NULL;
1022
1023         /* for convenience */
1024
1025         o = LLNI_classinfo_wrap(c);
1026
1027 #if defined(WITH_CLASSPATH_GNU)
1028         /* set ProtectionDomain */
1029
1030         LLNI_field_set_ref(o, pd, protectionDomain);
1031 #endif
1032
1033         return o;
1034 }
1035
1036
1037 /*
1038  * Class:     sun/misc/Unsafe
1039  * Method:    allocateInstance
1040  * Signature: (Ljava/lang/Class;)Ljava/lang/Object;
1041  */
1042 JNIEXPORT java_lang_Object* JNICALL Java_sun_misc_Unsafe_allocateInstance(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Class *cls)
1043 {
1044         classinfo     *c;
1045         java_handle_t *o;
1046
1047         c = LLNI_classinfo_unwrap(cls);
1048
1049         o = builtin_new(c);
1050
1051         return (java_lang_Object *) o;
1052 }
1053
1054
1055 /*
1056  * Class:     sun/misc/Unsafe
1057  * Method:    throwException
1058  * Signature: (Ljava/lang/Throwable;)V
1059  */
1060 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_throwException(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Throwable *ee)
1061 {
1062         java_handle_t *o;
1063
1064         o = (java_handle_t *) ee;
1065
1066         exceptions_set_exception(o);
1067 }
1068
1069
1070 /*
1071  * Class:     sun/misc/Unsafe
1072  * Method:    compareAndSwapObject
1073  * Signature: (Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z
1074  */
1075 JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_compareAndSwapObject(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset, java_lang_Object *expected, java_lang_Object *x)
1076 {
1077 #if 1
1078         void **p;
1079         void  *value;
1080
1081         p = (void **) (((uint8_t *) o) + offset);
1082
1083         /* XXX this should be atomic */
1084
1085         value = *p;
1086
1087         if (value == expected) {
1088                 *p = x;
1089
1090                 return true;
1091         }
1092
1093         return false;
1094 #else
1095         volatile void **p;
1096         void           *result;
1097
1098         /* XXX Use LLNI */
1099
1100         p = (volatile void **) (((uint8_t *) o) + offset);
1101
1102         result = atomic_compare_and_swap_address(p, expected, x);
1103
1104         if (result == expected)
1105                 return true;
1106
1107         return false;
1108 #endif
1109 }
1110
1111
1112 /*
1113  * Class:     sun/misc/Unsafe
1114  * Method:    compareAndSwapInt
1115  * Signature: (Ljava/lang/Object;JII)Z
1116  */
1117 JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_compareAndSwapInt(JNIEnv *env, sun_misc_Unsafe* this, java_lang_Object* o, int64_t offset, int32_t expected, int32_t x)
1118 {
1119 #if 1
1120         int32_t *p;
1121         int32_t  value;
1122
1123         p = (int32_t *) (((uint8_t *) o) + offset);
1124
1125         /* XXX this should be atomic */
1126
1127         value = *p;
1128
1129         if (value == expected) {
1130                 *p = x;
1131
1132                 return true;
1133         }
1134
1135         return false;
1136 #else
1137         int32_t *p;
1138         int32_t  result;
1139
1140         /* XXX Use LLNI */
1141
1142         p = (int32_t *) (((uint8_t *) o) + offset);
1143
1144         result = atomic_compare_and_swap_int(p, expected, x);
1145
1146         if (result == expected)
1147                 return true;
1148
1149         return false;
1150 #endif
1151 }
1152
1153
1154 /*
1155  * Class:     sun/misc/Unsafe
1156  * Method:    compareAndSwapLong
1157  * Signature: (Ljava/lang/Object;JJJ)Z
1158  */
1159 JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_compareAndSwapLong(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset, int64_t expected, int64_t x)
1160 {
1161         int64_t *p;
1162         int64_t  value;
1163
1164         p = (int64_t *) (((uint8_t *) o) + offset);
1165
1166         /* XXX this should be atomic */
1167
1168         value = *p;
1169
1170         if (value == expected) {
1171                 *p = x;
1172
1173                 return true;
1174         }
1175
1176         return false;
1177 }
1178
1179
1180 /*
1181  * Class:     sun/misc/Unsafe
1182  * Method:    getObjectVolatile
1183  * Signature: (Ljava/lang/Object;J)Ljava/lang/Object;
1184  */
1185 JNIEXPORT java_lang_Object* JNICALL Java_sun_misc_Unsafe_getObjectVolatile(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset)
1186 {
1187         volatile void **p;
1188         volatile void  *value;
1189
1190         p = (volatile void **) (((uint8_t *) o) + offset);
1191
1192         value = *p;
1193
1194         return (java_lang_Object *) value;
1195 }
1196
1197
1198 /*
1199  * Class:     sun/misc/Unsafe
1200  * Method:    putObjectVolatile
1201  * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
1202  */
1203 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putObjectVolatile(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset, java_lang_Object *x)
1204 {
1205         volatile void **p;
1206
1207         p = (volatile void **) (((uint8_t *) o) + offset);
1208
1209         *p = x;
1210 }
1211
1212
1213 #define UNSAFE_GET_VOLATILE(type)                                                       \
1214         java_handle_t *_h;                                                                              \
1215         java_object_t *_o;                                                                              \
1216         volatile type *_p;                                                                              \
1217         volatile type  _x;                                                                              \
1218                                                                                                                         \
1219         _h = (java_handle_t *) o;                                                               \
1220                                                                                                                         \
1221         LLNI_CRITICAL_START;                                                                    \
1222                                                                                                                         \
1223         _o = LLNI_UNWRAP(_h);                                                                   \
1224         _p = (volatile type *) (((uint8_t *) _o) + offset);             \
1225                                                                                                                         \
1226         _x = *_p;                                                                                               \
1227                                                                                                                         \
1228         LLNI_CRITICAL_END;                                                                              \
1229                                                                                                                         \
1230         return _x;
1231
1232
1233 #define UNSAFE_PUT_VOLATILE(type)                                                       \
1234         java_handle_t *_h;                                                                              \
1235         java_object_t *_o;                                                                              \
1236         volatile type *_p;                                                                              \
1237                                                                                                                         \
1238         _h = (java_handle_t *) o;                                                               \
1239                                                                                                                         \
1240         LLNI_CRITICAL_START;                                                                    \
1241                                                                                                                         \
1242         _o = LLNI_UNWRAP(_h);                                                                   \
1243         _p = (volatile type *) (((uint8_t *) _o) + offset);             \
1244                                                                                                                         \
1245         *_p = x;                                                                                                \
1246                                                                                                                         \
1247         MEMORY_BARRIER();                                                                               \
1248                                                                                                                         \
1249         LLNI_CRITICAL_END;
1250
1251
1252 /*
1253  * Class:     sun/misc/Unsafe
1254  * Method:    getIntVolatile
1255  * Signature: (Ljava/lang/Object;J)I
1256  */
1257 JNIEXPORT int32_t JNICALL Java_sun_misc_Unsafe_getIntVolatile(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset)
1258 {
1259         UNSAFE_GET_VOLATILE(int32_t);
1260 }
1261
1262
1263 /*
1264  * Class:     sun/misc/Unsafe
1265  * Method:    putIntVolatile
1266  * Signature: (Ljava/lang/Object;JI)V
1267  */
1268 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putIntVolatile(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset, int32_t x)
1269 {
1270         UNSAFE_PUT_VOLATILE(int32_t);
1271 }
1272
1273
1274 /*
1275  * Class:     sun/misc/Unsafe
1276  * Method:    getLongVolatile
1277  * Signature: (Ljava/lang/Object;J)J
1278  */
1279 JNIEXPORT int64_t JNICALL Java_sun_misc_Unsafe_getLongVolatile(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset)
1280 {
1281         UNSAFE_GET_VOLATILE(int64_t);
1282 }
1283
1284
1285 /*
1286  * Class:     sun/misc/Unsafe
1287  * Method:    putLongVolatile
1288  * Signature: (Ljava/lang/Object;JJ)V
1289  */
1290 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLongVolatile(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset, int64_t x)
1291 {
1292         UNSAFE_PUT_VOLATILE(int64_t);
1293 }
1294
1295
1296 /*
1297  * Class:     sun/misc/Unsafe
1298  * Method:    putOrderedObject
1299  * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
1300  */
1301 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedObject(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset, java_lang_Object *x)
1302 {
1303         java_handle_t  *_h;
1304         java_handle_t  *_hx;
1305         java_object_t  *_o;
1306         java_object_t  *_x;
1307         volatile void **_p;
1308
1309         _h  = (java_handle_t *) o;
1310         _hx = (java_handle_t *) x;
1311
1312         LLNI_CRITICAL_START;
1313
1314         _o = LLNI_UNWRAP(_h);
1315         _x = LLNI_UNWRAP(_hx);
1316         _p = (volatile void **) (((uint8_t *) _o) + offset);
1317
1318         *_p = _x;
1319
1320         MEMORY_BARRIER();
1321
1322         LLNI_CRITICAL_END;
1323 }
1324
1325
1326 /*
1327  * Class:     sun/misc/Unsafe
1328  * Method:    putOrderedInt
1329  * Signature: (Ljava/lang/Object;JI)V
1330  */
1331 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedInt(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset, int32_t x)
1332 {
1333         UNSAFE_PUT_VOLATILE(int32_t);
1334 }
1335
1336
1337 /*
1338  * Class:     sun/misc/Unsafe
1339  * Method:    putOrderedLong
1340  * Signature: (Ljava/lang/Object;JJ)V
1341  */
1342 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedLong(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *o, int64_t offset, int64_t x)
1343 {
1344         UNSAFE_PUT_VOLATILE(int64_t);
1345 }
1346
1347
1348 /*
1349  * Class:     sun/misc/Unsafe
1350  * Method:    unpark
1351  * Signature: (Ljava/lang/Object;)V
1352  */
1353 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_unpark(JNIEnv *env, sun_misc_Unsafe *this, java_lang_Object *thread)
1354 {
1355         /* XXX IMPLEMENT ME */
1356 }
1357
1358
1359 /*
1360  * Class:     sun/misc/Unsafe
1361  * Method:    park
1362  * Signature: (ZJ)V
1363  */
1364 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_park(JNIEnv *env, sun_misc_Unsafe *this, int32_t isAbsolute, int64_t time)
1365 {
1366         /* XXX IMPLEMENT ME */
1367 }
1368
1369
1370 /*
1371  * These are local overrides for various environment variables in Emacs.
1372  * Please do not remove this and leave it at the end of the file, where
1373  * Emacs will automagically detect them.
1374  * ---------------------------------------------------------------------
1375  * Local variables:
1376  * mode: c
1377  * indent-tabs-mode: t
1378  * c-basic-offset: 4
1379  * tab-width: 4
1380  * End:
1381  */