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