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