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