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