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