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