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