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