IcedTea/PR585
[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, 2009, 2010
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 /* OpenJDK 7 */
548
549 /*
550  * Class:     sun/misc/Unsafe
551  * Method:    setMemory
552  * Signature: (Ljava/lang/Object;JJB)V
553  */
554 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_setMemory_jdk7(JNIEnv *env, jobject _this, jobject o, jlong offset, jlong bytes, jbyte value)
555 {
556         size_t  length;
557         void   *p;
558
559         length = (size_t) bytes;
560
561         if ((length != (uint64_t) bytes) || (bytes < 0)) {
562                 exceptions_throw_illegalargumentexception();
563                 return;
564         }
565
566         /* XXX Missing LLNI: we need to unwrap _this object. */
567
568         p = (void *) (((uint8_t *) o) + offset);
569
570         /* XXX Not sure this is correct. */
571
572         os::memset(p, value, length);
573 }
574
575
576 /*
577  * Class:     sun/misc/Unsafe
578  * Method:    copyMemory
579  * Signature: (Ljava/lang/Object;JLjava/lang/Object;JJ)V
580  */
581 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_copyMemory_jdk7(JNIEnv *env, jobject _this, jobject srcBase, jlong srcOffset, jobject destBase, jlong destOffset, jlong bytes)
582 {
583         size_t  length;
584         void   *src;
585         void   *dest;
586
587         if (bytes == 0)
588                 return;
589
590         length = (size_t) bytes;
591
592         if ((length != (uint64_t) bytes) || (bytes < 0)) {
593                 exceptions_throw_illegalargumentexception();
594                 return;
595         }
596
597         /* XXX Missing LLNI: We need to unwrap these objects. */
598
599         src  = (void *) (((uint8_t *) srcBase) + srcOffset);
600         dest = (void *) (((uint8_t *) destBase) + destOffset);
601
602         os::memcpy(dest, src, length);
603 }
604
605 /*
606  * Class:     sun/misc/Unsafe
607  * Method:    setMemory
608  * Signature: (JJB)V
609  */
610 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_setMemory_jdk6(JNIEnv *env, jobject _this, jlong address, jlong bytes, jbyte value)
611 {
612         size_t  length;
613         void   *p;
614
615         length = (size_t) bytes;
616
617         if ((length != (uint64_t) bytes) || (bytes < 0)) {
618                 exceptions_throw_illegalargumentexception();
619                 return;
620         }
621
622         p = (void *) (intptr_t) address;
623
624         /* XXX Not sure this is correct. */
625
626         os::memset(p, value, length);
627 }
628
629
630 /*
631  * Class:     sun/misc/Unsafe
632  * Method:    copyMemory
633  * Signature: (JJJ)V
634  */
635 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_copyMemory_jdk6(JNIEnv *env, jobject _this, jlong srcAddress, jlong destAddress, jlong bytes)
636 {
637         size_t  length;
638         void   *src;
639         void   *dest;
640
641         if (bytes == 0)
642                 return;
643
644         length = (size_t) bytes;
645
646         if ((length != (uint64_t) bytes) || (bytes < 0)) {
647                 exceptions_throw_illegalargumentexception();
648                 return;
649         }
650
651         src  = (void *) (intptr_t) srcAddress;
652         dest = (void *) (intptr_t) destAddress;
653
654         os::memcpy(dest, src, length);
655 }
656
657
658 /*
659  * Class:     sun/misc/Unsafe
660  * Method:    freeMemory
661  * Signature: (J)V
662  */
663 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_freeMemory(JNIEnv *env, jobject _this, jlong address)
664 {
665         void *p;
666
667         p = (void *) (intptr_t) address;
668
669         if (p == NULL)
670                 return;
671
672         /* we pass length 1 to trick the free function */
673
674         MFREE(p, uint8_t, 1);
675 }
676
677
678 /*
679  * Class:     sun/misc/Unsafe
680  * Method:    staticFieldOffset
681  * Signature: (Ljava/lang/reflect/Field;)J
682  */
683 JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_staticFieldOffset(JNIEnv *env, jobject _this, jobject f)
684 {
685         /* The offset of static fields is 0. */
686
687         return 0;
688 }
689
690
691 /*
692  * Class:     sun/misc/Unsafe
693  * Method:    staticFieldBase
694  * Signature: (Ljava/lang/reflect/Field;)Ljava/lang/Object;
695  */
696 JNIEXPORT jobject JNICALL Java_sun_misc_Unsafe_staticFieldBase(JNIEnv *env, jobject _this, jobject field)
697 {
698 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
699
700         java_lang_reflect_Field rf(field);
701         java_lang_reflect_VMField rvmf(rf.get_f());
702         fieldinfo* f = rvmf.get_field();
703
704 #elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
705
706         java_lang_reflect_Field rf(field);
707         fieldinfo* f = rf.get_field();
708
709 #else
710 # error unknown configuration
711 #endif
712
713         return (jobject) (f->value);
714 }
715
716
717 /*
718  * Class:     sun/misc/Unsafe
719  * Method:    ensureClassInitialized
720  * Signature: (Ljava/lang/Class;)V
721  */
722 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_ensureClassInitialized(JNIEnv *env, jobject _this, jclass clazz)
723 {
724         classinfo *c;
725
726         c = LLNI_classinfo_unwrap(clazz);
727
728         if (!(c->state & CLASS_INITIALIZED))
729                 initialize_class(c);
730 }
731
732
733 /*
734  * Class:     sun/misc/Unsafe
735  * Method:    arrayBaseOffset
736  * Signature: (Ljava/lang/Class;)I
737  */
738 JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_arrayBaseOffset(JNIEnv *env, jobject _this, jclass arrayClass)
739 {
740         classinfo       *c;
741         arraydescriptor *ad;
742
743         c  = LLNI_classinfo_unwrap(arrayClass);
744         ad = c->vftbl->arraydesc;
745
746         if (ad == NULL) {
747                 /* XXX does that exception exist? */
748                 exceptions_throw_internalerror("java/lang/InvalidClassException");
749                 return 0;
750         }
751
752         return ad->dataoffset;
753 }
754
755
756 /*
757  * Class:     sun/misc/Unsafe
758  * Method:    arrayIndexScale
759  * Signature: (Ljava/lang/Class;)I
760  */
761 JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_arrayIndexScale(JNIEnv *env, jobject _this, jclass arrayClass)
762 {
763         classinfo       *c;
764         arraydescriptor *ad;
765
766         c  = LLNI_classinfo_unwrap(arrayClass);
767         ad = c->vftbl->arraydesc;
768
769         if (ad == NULL) {
770                 /* XXX does that exception exist? */
771                 exceptions_throw_internalerror("java/lang/InvalidClassException");
772                 return 0;
773         }
774
775         return ad->componentsize;
776 }
777
778
779 /*
780  * Class:     sun/misc/Unsafe
781  * Method:    addressSize
782  * Signature: ()I
783  */
784 JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_addressSize(JNIEnv *env, jobject _this)
785 {
786         return SIZEOF_VOID_P;
787 }
788
789
790 /*
791  * Class:     sun/misc/Unsafe
792  * Method:    pageSize
793  * Signature: ()I
794  */
795 JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_pageSize(JNIEnv *env, jobject _this)
796 {
797         int sz;
798
799         sz = getpagesize();
800
801         return sz;
802 }
803
804
805 /*
806  * Class:     sun/misc/Unsafe
807  * Method:    defineClass
808  * Signature: (Ljava/lang/String;[BIILjava/lang/ClassLoader;Ljava/security/ProtectionDomain;)Ljava/lang/Class;
809  */
810 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)
811 {
812         classloader_t   *cl;
813         utf             *utfname;
814         classinfo       *c;
815
816         cl = loader_hashtable_classloader_add((java_handle_t *) loader);
817
818         /* check if data was passed */
819
820         if (b == NULL) {
821                 exceptions_throw_nullpointerexception();
822                 return NULL;
823         }
824
825         /* check the indexes passed */
826
827         ByteArray ba(b);
828
829         if ((off < 0) || (len < 0) || ((off + len) > ba.get_length())) {
830                 exceptions_throw_arrayindexoutofboundsexception();
831                 return NULL;
832         }
833
834         if (name != NULL) {
835                 /* convert '.' to '/' in java string */
836
837                 utfname = javastring_toutf((java_handle_t *) name, true);
838         } 
839         else {
840                 utfname = NULL;
841         }
842
843         /* define the class */
844
845         uint8_t* ptr = ((uint8_t*) ba.get_raw_data_ptr()) + off;
846         c = class_define(utfname, cl, len, ptr,
847                                          (java_handle_t *) protectionDomain);
848
849         if (c == NULL)
850                 return NULL;
851
852         java_handle_t* h = LLNI_classinfo_wrap(c);
853
854 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
855         // Set ProtectionDomain.
856         java_lang_Class jlc(h);
857         jlc.set_pd(protectionDomain);
858 #endif
859
860         return (jclass) h;
861 }
862
863
864 /*
865  * Class:     sun/misc/Unsafe
866  * Method:    allocateInstance
867  * Signature: (Ljava/lang/Class;)Ljava/lang/Object;
868  */
869 JNIEXPORT jobject JNICALL Java_sun_misc_Unsafe_allocateInstance(JNIEnv *env, jobject _this, jclass cls)
870 {
871         classinfo     *c;
872         java_handle_t *o;
873
874         c = LLNI_classinfo_unwrap(cls);
875
876         o = builtin_new(c);
877
878         return (jobject ) o;
879 }
880
881
882 /*
883  * Class:     sun/misc/Unsafe
884  * Method:    throwException
885  * Signature: (Ljava/lang/Throwable;)V
886  */
887 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_throwException(JNIEnv *env, jobject _this, jobject ee)
888 {
889         java_handle_t *o;
890
891         o = (java_handle_t *) ee;
892
893         exceptions_set_exception(o);
894 }
895
896
897 /*
898  * Class:     sun/misc/Unsafe
899  * Method:    compareAndSwapObject
900  * Signature: (Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z
901  */
902 JNIEXPORT jboolean JNICALL Java_sun_misc_Unsafe_compareAndSwapObject(JNIEnv *env, jobject _this, jobject o, jlong offset, jobject expected, jobject x)
903 {
904         void **p;
905         void           *result;
906
907         /* XXX Use LLNI */
908
909         p = (void **) (((uint8_t *) o) + offset);
910
911         result = Atomic::compare_and_swap(p, (void *) expected, (void *) x);
912 #if defined(CAS_PROVIDES_FULL_BARRIER) && CAS_PROVIDES_FULL_BARRIER
913         Atomic::instruction_barrier();
914 #else
915         Atomic::memory_barrier();
916 #endif
917
918         if (result == expected)
919                 return true;
920
921         return false;
922 }
923
924
925 /*
926  * Class:     sun/misc/Unsafe
927  * Method:    compareAndSwapInt
928  * Signature: (Ljava/lang/Object;JII)Z
929  */
930 JNIEXPORT jboolean JNICALL Java_sun_misc_Unsafe_compareAndSwapInt(JNIEnv *env, jobject _this, jobject o, jlong offset, jint expected, jint x)
931 {
932         uint32_t *p;
933         uint32_t  result;
934
935         /* XXX Use LLNI */
936
937         p = (uint32_t *) (((uint8_t *) o) + offset);
938
939         result = Atomic::compare_and_swap(p, (uint32_t) expected, (uint32_t) x);
940 #if defined(CAS_PROVIDES_FULL_BARRIER) && CAS_PROVIDES_FULL_BARRIER
941         Atomic::instruction_barrier();
942 #else
943         Atomic::memory_barrier();
944 #endif
945
946         if (result == (uint32_t) expected)
947                 return true;
948
949         return false;
950 }
951
952
953 /*
954  * Class:     sun/misc/Unsafe
955  * Method:    compareAndSwapLong
956  * Signature: (Ljava/lang/Object;JJJ)Z
957  */
958 JNIEXPORT jboolean JNICALL Java_sun_misc_Unsafe_compareAndSwapLong(JNIEnv *env, jobject _this, jobject o, jlong offset, jlong expected, jlong x)
959 {
960         uint64_t *p;
961         uint64_t  result;
962
963         /* XXX Use LLNI */
964
965         p = (uint64_t *) (((uint8_t *) o) + offset);
966
967         result = Atomic::compare_and_swap(p, (uint64_t) expected, (uint64_t) x);
968 #if defined(CAS_PROVIDES_FULL_BARRIER) && CAS_PROVIDES_FULL_BARRIER
969         Atomic::instruction_barrier();
970 #else
971         Atomic::memory_barrier();
972 #endif
973
974         if (result == (uint64_t) expected)
975                 return true;
976
977         return false;
978 }
979
980
981 /*
982  * Class:     sun/misc/Unsafe
983  * Method:    getObjectVolatile
984  * Signature: (Ljava/lang/Object;J)Ljava/lang/Object;
985  */
986 JNIEXPORT jobject JNICALL Java_sun_misc_Unsafe_getObjectVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset)
987 {
988         return FieldAccess::get_volatile<jobject>(o, offset);
989 }
990
991
992 /*
993  * Class:     sun/misc/Unsafe
994  * Method:    putObjectVolatile
995  * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
996  */
997 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putObjectVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset, jobject x)
998 {
999         FieldAccess::set_volatile(o, offset, x);
1000 }
1001
1002
1003 /*
1004  * Class:     sun/misc/Unsafe
1005  * Method:    getBooleanVolatile
1006  * Signature: (Ljava/lang/Object;J)Z
1007  */
1008 JNIEXPORT jboolean JNICALL Java_sun_misc_Unsafe_getBooleanVolatile(JNIEnv* env, jobject _this, jobject o, jlong offset)
1009 {
1010         return FieldAccess::get_volatile<int32_t>(o, offset);
1011 }
1012
1013
1014 /*
1015  * Class:     sun/misc/Unsafe
1016  * Method:    putBooleanVolatile
1017  * Signature: (Ljava/lang/Object;JZ)V
1018  */
1019 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putBooleanVolatile (JNIEnv *env, jobject _this, jobject o, jlong offset, jboolean x)
1020 {
1021         FieldAccess::set_volatile(o, offset, x);
1022 }
1023
1024
1025 /*
1026  * Class:     sun/misc/Unsafe
1027  * Method:    getByteVolatile
1028  * Signature: (Ljava/lang/Object;J)B
1029  */
1030 JNIEXPORT jbyte JNICALL Java_sun_misc_Unsafe_getByteVolatile(JNIEnv* env, jobject _this, jobject o, jlong offset)
1031 {
1032         return FieldAccess::get_volatile<int32_t>(o, offset);
1033 }
1034
1035
1036 /*
1037  * Class:     sun/misc/Unsafe
1038  * Method:    putByteVolatile
1039  * Signature: (Ljava/lang/Object;JB)V
1040  */
1041 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putByteVolatile (JNIEnv *env, jobject _this, jobject o, jlong offset, jbyte x)
1042 {
1043         FieldAccess::set_volatile(o, offset, x);
1044 }
1045
1046
1047 /*
1048  * Class:     sun/misc/Unsafe
1049  * Method:    getShortVolatile
1050  * Signature: (Ljava/lang/Object;J)S
1051  */
1052 JNIEXPORT jshort JNICALL Java_sun_misc_Unsafe_getShortVolatile(JNIEnv* env, jobject _this, jobject o, jlong offset)
1053 {
1054         return FieldAccess::get_volatile<int32_t>(o, offset);
1055 }
1056
1057
1058 /*
1059  * Class:     sun/misc/Unsafe
1060  * Method:    putShortVolatile
1061  * Signature: (Ljava/lang/Object;JS)V
1062  */
1063 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putShortVolatile (JNIEnv *env, jobject _this, jobject o, jlong offset, jshort x)
1064 {
1065         FieldAccess::set_volatile(o, offset, x);
1066 }
1067
1068
1069 /*
1070  * Class:     sun/misc/Unsafe
1071  * Method:    getCharVolatile
1072  * Signature: (Ljava/lang/Object;J)C
1073  */
1074 JNIEXPORT jchar JNICALL Java_sun_misc_Unsafe_getCharVolatile(JNIEnv* env, jobject _this, jobject o, jlong offset)
1075 {
1076         return FieldAccess::get_volatile<int32_t>(o, offset);
1077 }
1078
1079
1080 /*
1081  * Class:     sun/misc/Unsafe
1082  * Method:    putCharVolatile
1083  * Signature: (Ljava/lang/Object;JC)V
1084  */
1085 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putCharVolatile (JNIEnv *env, jobject _this, jobject o, jlong offset, jchar x)
1086 {
1087         FieldAccess::set_volatile(o, offset, x);
1088 }
1089
1090
1091 /*
1092  * Class:     sun/misc/Unsafe
1093  * Method:    getIntVolatile
1094  * Signature: (Ljava/lang/Object;J)I
1095  */
1096 JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_getIntVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset)
1097 {
1098         return FieldAccess::get_volatile<int32_t>(o, offset);
1099 }
1100
1101
1102 /*
1103  * Class:     sun/misc/Unsafe
1104  * Method:    putIntVolatile
1105  * Signature: (Ljava/lang/Object;JI)V
1106  */
1107 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putIntVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset, jint x)
1108 {
1109         FieldAccess::set_volatile(o, offset, x);
1110 }
1111
1112
1113 /*
1114  * Class:     sun/misc/Unsafe
1115  * Method:    getLongVolatile
1116  * Signature: (Ljava/lang/Object;J)J
1117  */
1118 JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_getLongVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset)
1119 {
1120         return FieldAccess::get_volatile<int64_t>(o, offset);
1121 }
1122
1123
1124 /*
1125  * Class:     sun/misc/Unsafe
1126  * Method:    putLongVolatile
1127  * Signature: (Ljava/lang/Object;JJ)V
1128  */
1129 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putLongVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset, jlong x)
1130 {
1131         FieldAccess::set_volatile(o, offset, x);
1132 }
1133
1134
1135 /*
1136  * Class:     sun/misc/Unsafe
1137  * Method:    getFloatVolatile
1138  * Signature: (Ljava/lang/Object;J)F
1139  */
1140 JNIEXPORT jfloat JNICALL Java_sun_misc_Unsafe_getFloatVolatile(JNIEnv* env, jobject _this, jobject o, jlong offset)
1141 {
1142         return FieldAccess::get_volatile<float>(o, offset);
1143 }
1144
1145
1146 /*
1147  * Class:     sun/misc/Unsafe
1148  * Method:    putFloatVolatile
1149  * Signature: (Ljava/lang/Object;JF)V
1150  */
1151 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putFloatVolatile (JNIEnv *env, jobject _this, jobject o, jlong offset, jfloat x)
1152 {
1153         FieldAccess::set_volatile(o, offset, x);
1154 }
1155
1156
1157 /*
1158  * Class:     sun/misc/Unsafe
1159  * Method:    getDoubleVolatile
1160  * Signature: (Ljava/lang/Object;J)D
1161  */
1162 JNIEXPORT jdouble JNICALL Java_sun_misc_Unsafe_getDoubleVolatile(JNIEnv *env, jobject _this, jobject o, jlong offset)
1163 {
1164         return FieldAccess::get_volatile<double>(o, offset);
1165 }
1166
1167
1168 /*
1169  * Class:     sun/misc/Unsafe
1170  * Method:    putDoubleVolatile
1171  * Signature: (Ljava/lang/Object;JD)V
1172  */
1173 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putDoubleVolatile (JNIEnv *env, jobject _this, jobject o, jlong offset, jdouble x)
1174 {
1175         FieldAccess::set_volatile(o, offset, x);
1176 }
1177
1178
1179 /*
1180  * Class:     sun/misc/Unsafe
1181  * Method:    putOrderedObject
1182  * Signature: (Ljava/lang/Object;JLjava/lang/Object;)V
1183  */
1184 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedObject(JNIEnv *env, jobject _this, jobject o, jlong offset, jobject x)
1185 {
1186         FieldAccess::set_volatile(o, offset, x);
1187 }
1188
1189
1190 /*
1191  * Class:     sun/misc/Unsafe
1192  * Method:    putOrderedInt
1193  * Signature: (Ljava/lang/Object;JI)V
1194  */
1195 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedInt(JNIEnv *env, jobject _this, jobject o, jlong offset, jint x)
1196 {
1197         FieldAccess::set_volatile(o, offset, x);
1198 }
1199
1200
1201 /*
1202  * Class:     sun/misc/Unsafe
1203  * Method:    putOrderedLong
1204  * Signature: (Ljava/lang/Object;JJ)V
1205  */
1206 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_putOrderedLong(JNIEnv *env, jobject _this, jobject o, jlong offset, jlong x)
1207 {
1208         FieldAccess::set_volatile(o, offset, x);
1209 }
1210
1211
1212 /*
1213  * Class:     sun/misc/Unsafe
1214  * Method:    unpark
1215  * Signature: (Ljava/lang/Object;)V
1216  */
1217 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_unpark(JNIEnv *env, jobject _this, jobject thread)
1218 {
1219         java_handle_t *h = (java_handle_t *) thread;
1220         threadobject *t;
1221
1222 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
1223         h = java_lang_Thread(h).get_vmThread();
1224 #endif
1225         t = thread_get_thread(h);
1226
1227         threads_unpark(t);
1228 }
1229
1230
1231 /*
1232  * Class:     sun/misc/Unsafe
1233  * Method:    park
1234  * Signature: (ZJ)V
1235  */
1236 JNIEXPORT void JNICALL Java_sun_misc_Unsafe_park(JNIEnv *env, jobject _this, jboolean isAbsolute, jlong time)
1237 {
1238         threads_park(isAbsolute, time);
1239 }
1240
1241
1242 /*
1243  * Class:     sun/misc/Unsafe
1244  * Method:    getLoadAverage
1245  * Signature: ([DI)I
1246  */
1247 JNIEXPORT jint JNICALL Java_sun_misc_Unsafe_getLoadAverage(JNIEnv *env, jobject _this, jdoubleArray loadavg, jint nelem)
1248 {
1249         DoubleArray da(loadavg);
1250
1251 #define MAX_SAMPLES 3
1252
1253         // Check the passed number of samples.
1254         if ((nelem < 0) || (nelem > da.get_length()) || nelem > MAX_SAMPLES) {
1255                 exceptions_throw_arrayindexoutofboundsexception();
1256                 return -1;
1257         }
1258
1259         // Actually retrieve samples.
1260         double values[MAX_SAMPLES];
1261         int result = os::getloadavg(values, nelem);
1262
1263         // Save samples into the given array.
1264         for (int i = 0; i < result; i++) {
1265                 da.set_element(i, values[i]);
1266         }
1267
1268         return result;
1269 }
1270
1271 } // extern "C"
1272
1273
1274 /* native methods implemented by this file ************************************/
1275
1276 static JNINativeMethod methods[] = {
1277         { (char*) "registerNatives",        (char*) "()V",                                                        (void*) (uintptr_t) &Java_sun_misc_Unsafe_registerNatives                  },
1278         { (char*) "getInt",                 (char*) "(Ljava/lang/Object;J)I",                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_getInt__Ljava_lang_Object_2J     },
1279         { (char*) "putInt",                 (char*) "(Ljava/lang/Object;JI)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putInt__Ljava_lang_Object_2JI    },
1280         { (char*) "getObject",              (char*) "(Ljava/lang/Object;J)Ljava/lang/Object;",                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_getObject                        },
1281         { (char*) "putObject",              (char*) "(Ljava/lang/Object;JLjava/lang/Object;)V",                   (void*) (uintptr_t) &Java_sun_misc_Unsafe_putObject                        },
1282         { (char*) "getBoolean",             (char*) "(Ljava/lang/Object;J)Z",                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_getBoolean                       },
1283         { (char*) "putBoolean",             (char*) "(Ljava/lang/Object;JZ)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putBoolean                       },
1284         { (char*) "getByte",                (char*) "(Ljava/lang/Object;J)B",                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_getByte__Ljava_lang_Object_2J    },
1285         { (char*) "putByte",                (char*) "(Ljava/lang/Object;JB)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putByte__Ljava_lang_Object_2JB   },
1286         { (char*) "getShort",               (char*) "(Ljava/lang/Object;J)S",                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_getShort__Ljava_lang_Object_2J   },
1287         { (char*) "putShort",               (char*) "(Ljava/lang/Object;JS)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putShort__Ljava_lang_Object_2JS  },
1288         { (char*) "getChar",                (char*) "(Ljava/lang/Object;J)C",                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_getChar__Ljava_lang_Object_2J    },
1289         { (char*) "putChar",                (char*) "(Ljava/lang/Object;JC)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putChar__Ljava_lang_Object_2JC   },
1290         { (char*) "getLong",                (char*) "(Ljava/lang/Object;J)J",                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_getLong__Ljava_lang_Object_2J    },
1291         { (char*) "putLong",                (char*) "(Ljava/lang/Object;JJ)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putLong__Ljava_lang_Object_2JJ   },
1292         { (char*) "getFloat",               (char*) "(Ljava/lang/Object;J)F",                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_getFloat__Ljava_lang_Object_2J   },
1293         { (char*) "putFloat",               (char*) "(Ljava/lang/Object;JF)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putFloat__Ljava_lang_Object_2JF  },
1294         { (char*) "getDouble",              (char*) "(Ljava/lang/Object;J)D",                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_getDouble__Ljava_lang_Object_2J  },
1295         { (char*) "putDouble",              (char*) "(Ljava/lang/Object;JD)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putDouble__Ljava_lang_Object_2JD },
1296         { (char*) "getByte",                (char*) "(J)B",                                                       (void*) (uintptr_t) &Java_sun_misc_Unsafe_getByte__J                       },
1297         { (char*) "putByte",                (char*) "(JB)V",                                                      (void*) (uintptr_t) &Java_sun_misc_Unsafe_putByte__JB                      },
1298         { (char*) "getShort",               (char*) "(J)S",                                                       (void*) (uintptr_t) &Java_sun_misc_Unsafe_getShort__J                      },
1299         { (char*) "putShort",               (char*) "(JS)V",                                                      (void*) (uintptr_t) &Java_sun_misc_Unsafe_putShort__JS                     },
1300         { (char*) "getChar",                (char*) "(J)C",                                                       (void*) (uintptr_t) &Java_sun_misc_Unsafe_getChar__J                       },
1301         { (char*) "putChar",                (char*) "(JC)V",                                                      (void*) (uintptr_t) &Java_sun_misc_Unsafe_putChar__JC                      },
1302         { (char*) "getInt",                 (char*) "(J)I",                                                       (void*) (uintptr_t) &Java_sun_misc_Unsafe_getInt__J                        },
1303         { (char*) "putInt",                 (char*) "(JI)V",                                                      (void*) (uintptr_t) &Java_sun_misc_Unsafe_putInt__JI                       },
1304         { (char*) "getLong",                (char*) "(J)J",                                                       (void*) (uintptr_t) &Java_sun_misc_Unsafe_getLong__J                       },
1305         { (char*) "putLong",                (char*) "(JJ)V",                                                      (void*) (uintptr_t) &Java_sun_misc_Unsafe_putLong__JJ                      },
1306         { (char*) "getFloat",               (char*) "(J)F",                                                       (void*) (uintptr_t) &Java_sun_misc_Unsafe_getFloat__J                      },
1307         { (char*) "putFloat",               (char*) "(JF)V",                                                      (void*) (uintptr_t) &Java_sun_misc_Unsafe_putFloat__JF                     },
1308         { (char*) "getDouble",              (char*) "(J)D",                                                       (void*) (uintptr_t) &Java_sun_misc_Unsafe_getDouble__J                     },
1309         { (char*) "putDouble",              (char*) "(JD)V",                                                      (void*) (uintptr_t) &Java_sun_misc_Unsafe_putDouble__JD                    },
1310         { (char*) "objectFieldOffset",      (char*) "(Ljava/lang/reflect/Field;)J",                               (void*) (uintptr_t) &Java_sun_misc_Unsafe_objectFieldOffset                },
1311         { (char*) "allocateMemory",         (char*) "(J)J",                                                       (void*) (uintptr_t) &Java_sun_misc_Unsafe_allocateMemory                   },
1312         // next two methods: OpenJDK 7
1313         { (char*) "setMemory",              (char*) "(Ljava/lang/Object;JJB)V",                                   (void*) (uintptr_t) &Java_sun_misc_Unsafe_setMemory_jdk7                   },
1314         { (char*) "copyMemory",             (char*) "(Ljava/lang/Object;JLjava/lang/Object;JJ)V",                 (void*) (uintptr_t) &Java_sun_misc_Unsafe_copyMemory_jdk7                  },
1315         // next two methods: OpenJDK 6
1316         { (char*) "setMemory",              (char*) "(JJB)V",                                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_setMemory_jdk6                   },
1317         { (char*) "copyMemory",             (char*) "(JJJ)V",                                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_copyMemory_jdk6                  },
1318         { (char*) "freeMemory",             (char*) "(J)V",                                                       (void*) (uintptr_t) &Java_sun_misc_Unsafe_freeMemory                       },
1319         { (char*) "staticFieldOffset",      (char*) "(Ljava/lang/reflect/Field;)J",                               (void*) (uintptr_t) &Java_sun_misc_Unsafe_staticFieldOffset                },
1320         { (char*) "staticFieldBase",        (char*) "(Ljava/lang/reflect/Field;)Ljava/lang/Object;",              (void*) (uintptr_t) &Java_sun_misc_Unsafe_staticFieldBase                  },
1321         { (char*) "ensureClassInitialized", (char*) "(Ljava/lang/Class;)V",                                       (void*) (uintptr_t) &Java_sun_misc_Unsafe_ensureClassInitialized           },
1322         { (char*) "arrayBaseOffset",        (char*) "(Ljava/lang/Class;)I",                                       (void*) (uintptr_t) &Java_sun_misc_Unsafe_arrayBaseOffset                  },
1323         { (char*) "arrayIndexScale",        (char*) "(Ljava/lang/Class;)I",                                       (void*) (uintptr_t) &Java_sun_misc_Unsafe_arrayIndexScale                  },
1324         { (char*) "addressSize",            (char*) "()I",                                                        (void*) (uintptr_t) &Java_sun_misc_Unsafe_addressSize                      },
1325         { (char*) "pageSize",               (char*) "()I",                                                        (void*) (uintptr_t) &Java_sun_misc_Unsafe_pageSize                         },
1326         { (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 },
1327         { (char*) "allocateInstance",       (char*) "(Ljava/lang/Class;)Ljava/lang/Object;",                      (void*) (uintptr_t) &Java_sun_misc_Unsafe_allocateInstance                 },
1328         { (char*) "throwException",         (char*) "(Ljava/lang/Throwable;)V",                                   (void*) (uintptr_t) &Java_sun_misc_Unsafe_throwException                   },
1329         { (char*) "compareAndSwapObject",   (char*) "(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z", (void*) (uintptr_t) &Java_sun_misc_Unsafe_compareAndSwapObject             },
1330         { (char*) "compareAndSwapInt",      (char*) "(Ljava/lang/Object;JII)Z",                                   (void*) (uintptr_t) &Java_sun_misc_Unsafe_compareAndSwapInt                },
1331         { (char*) "compareAndSwapLong",     (char*) "(Ljava/lang/Object;JJJ)Z",                                   (void*) (uintptr_t) &Java_sun_misc_Unsafe_compareAndSwapLong               },
1332         { (char*) "getObjectVolatile",      (char*) "(Ljava/lang/Object;J)Ljava/lang/Object;",                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_getObjectVolatile                },
1333         { (char*) "putObjectVolatile",      (char*) "(Ljava/lang/Object;JLjava/lang/Object;)V",                   (void*) (uintptr_t) &Java_sun_misc_Unsafe_putObjectVolatile                },
1334         { (char*) "getBooleanVolatile",     (char*) "(Ljava/lang/Object;J)Z",                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_getBooleanVolatile               },
1335         { (char*) "putBooleanVolatile",     (char*) "(Ljava/lang/Object;JZ)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putBooleanVolatile               },
1336         { (char*) "getByteVolatile",        (char*) "(Ljava/lang/Object;J)B",                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_getByteVolatile                  },
1337         { (char*) "putByteVolatile",        (char*) "(Ljava/lang/Object;JB)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putByteVolatile                  },
1338         { (char*) "getShortVolatile",       (char*) "(Ljava/lang/Object;J)S",                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_getShortVolatile                 },
1339         { (char*) "putShortVolatile",       (char*) "(Ljava/lang/Object;JS)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putShortVolatile                 },
1340         { (char*) "getCharVolatile",        (char*) "(Ljava/lang/Object;J)C",                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_getCharVolatile                  },
1341         { (char*) "putCharVolatile",        (char*) "(Ljava/lang/Object;JC)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putCharVolatile                  },
1342         { (char*) "getIntVolatile",         (char*) "(Ljava/lang/Object;J)I",                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_getIntVolatile                   },
1343         { (char*) "putIntVolatile",         (char*) "(Ljava/lang/Object;JI)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putIntVolatile                   },
1344         { (char*) "getLongVolatile",        (char*) "(Ljava/lang/Object;J)J",                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_getLongVolatile                  },
1345         { (char*) "putLongVolatile",        (char*) "(Ljava/lang/Object;JJ)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putLongVolatile                  },
1346         { (char*) "getFloatVolatile",       (char*) "(Ljava/lang/Object;J)F",                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_getFloatVolatile                 },
1347         { (char*) "putFloatVolatile",       (char*) "(Ljava/lang/Object;JF)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putFloatVolatile                 },
1348         { (char*) "getDoubleVolatile",      (char*) "(Ljava/lang/Object;J)D",                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_getDoubleVolatile                },
1349         { (char*) "putDoubleVolatile",      (char*) "(Ljava/lang/Object;JD)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putDoubleVolatile                },
1350         { (char*) "putOrderedObject",       (char*) "(Ljava/lang/Object;JLjava/lang/Object;)V",                   (void*) (uintptr_t) &Java_sun_misc_Unsafe_putOrderedObject                 },
1351         { (char*) "putOrderedInt",          (char*) "(Ljava/lang/Object;JI)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putOrderedInt                    },
1352         { (char*) "putOrderedLong",         (char*) "(Ljava/lang/Object;JJ)V",                                    (void*) (uintptr_t) &Java_sun_misc_Unsafe_putOrderedLong                   },
1353         { (char*) "unpark",                 (char*) "(Ljava/lang/Object;)V",                                      (void*) (uintptr_t) &Java_sun_misc_Unsafe_unpark                           },
1354         { (char*) "park",                   (char*) "(ZJ)V",                                                      (void*) (uintptr_t) &Java_sun_misc_Unsafe_park                             },
1355         { (char*) "getLoadAverage",         (char*) "([DI)I",                                                     (void*) (uintptr_t) &Java_sun_misc_Unsafe_getLoadAverage                   },
1356 };
1357
1358
1359 /* _Jv_sun_misc_Unsafe_init ****************************************************
1360
1361    Register native functions.
1362
1363 *******************************************************************************/
1364
1365 void _Jv_sun_misc_Unsafe_init(void)
1366 {
1367         utf* u = utf_new_char("sun/misc/Unsafe");
1368
1369         NativeMethods& nm = VM::get_current()->get_nativemethods();
1370         nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
1371 }
1372
1373
1374 /*
1375  * These are local overrides for various environment variables in Emacs.
1376  * Please do not remove this and leave it at the end of the file, where
1377  * Emacs will automagically detect them.
1378  * ---------------------------------------------------------------------
1379  * Local variables:
1380  * mode: c++
1381  * indent-tabs-mode: t
1382  * c-basic-offset: 4
1383  * tab-width: 4
1384  * End:
1385  * vim:noexpandtab:sw=4:ts=4:
1386  */