merged volatile memory barriers
[cacao.git] / src / vm / javaobjects.hpp
1 /* src/vm/javaobjects.hpp - functions to create and access Java objects
2
3    Copyright (C) 2008, 2009 Theobroma Systems Ltd.
4
5    This file is part of CACAO.
6
7    This program is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License as
9    published by the Free Software Foundation; either version 2, or (at
10    your option) any later version.
11
12    This program is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20    02110-1301, USA.
21
22 */
23
24
25 #ifndef _JAVAOBJECTS_HPP
26 #define _JAVAOBJECTS_HPP
27
28 #include "config.h"
29
30 #include <stdint.h>
31
32 #include "mm/memory.hpp"
33
34 #include "native/llni.h"
35
36 #include "threads/atomic.hpp"
37
38 #include "vm/class.hpp"
39 #include "vm/field.hpp"
40 #include "vm/global.h"
41 #include "vm/globals.hpp"
42 #include "vm/method.hpp"
43
44
45 #ifdef __cplusplus
46
47 /**
48  * This class provides low-level functions to access Java object
49  * instance fields.
50  *
51  * These functions do NOT take care about the GC critical section!
52  * Please use FieldAccess wherever possible.
53  */
54 class RawFieldAccess {
55 protected:
56         template<class T> static inline T    raw_get(void* address, const off_t offset);
57         template<class T> static inline void raw_set(void* address, const off_t offset, T value);
58 };
59
60
61 template<class T> inline T RawFieldAccess::raw_get(void* address, const off_t offset)
62 {
63         T* p = (T*) (((uintptr_t) address) + offset);
64         return *p;
65 }
66
67
68 template<class T> inline void RawFieldAccess::raw_set(void* address, const off_t offset, T value)
69 {
70         T* p = (T*) (((uintptr_t) address) + offset);
71         *p = value;
72 }
73
74
75 /**
76  * This classes provides functions to access Java object instance
77  * fields.  These functions enter a critical GC section before
78  * accessing the Java object throught the handle and leave it
79  * afterwards.
80  */
81 class FieldAccess : private RawFieldAccess {
82 public:
83         // Normal field accessors.
84         template<class T> static inline T    get(java_handle_t* h, const off_t offset);
85         template<class T> static inline void set(java_handle_t* h, const off_t offset, T value);
86
87         // Volatile field accessors.
88         template<class T> static inline T    get_volatile(java_handle_t* h, const off_t offset);
89         template<class T> static inline void set_volatile(java_handle_t* h, const off_t offset, T value);
90 };
91
92
93 template<class T> inline T FieldAccess::get(java_handle_t* h, const off_t offset)
94 {
95         // This function is inside a critical section.
96         GCCriticalSection cs;
97
98         // XXX This should be _handle->get_object();
99         java_object_t* ho = LLNI_UNWRAP(h);
100         return raw_get<T>(ho, offset);
101 }
102
103 template<> inline java_handle_t* FieldAccess::get(java_handle_t* h, const off_t offset)
104 {
105         // This function is inside a critical section.
106         GCCriticalSection cs;
107
108         // XXX This should be _handle->get_object();
109         java_object_t* o = LLNI_UNWRAP(h);
110         java_object_t* result = raw_get<java_object_t*>(o, offset);
111         return LLNI_WRAP(result);
112 }       
113
114
115 template<class T> inline void FieldAccess::set(java_handle_t* h, const off_t offset, T value)
116 {
117         // This function is inside a critical section.
118         GCCriticalSection cs;
119
120         java_object_t* ho = LLNI_UNWRAP(h);
121         raw_set(ho, offset, value);
122 }
123
124 template<> inline void FieldAccess::set<java_handle_t*>(java_handle_t* h, const off_t offset, java_handle_t* value)
125 {
126         // This function is inside a critical section.
127         GCCriticalSection cs;
128
129         // XXX This should be h->get_object();
130         java_object_t* o      = LLNI_UNWRAP(h);
131         java_object_t* ovalue = LLNI_UNWRAP(value);
132         raw_set(o, offset, ovalue);
133 }
134
135
136 template<class T> inline T FieldAccess::get_volatile(java_handle_t* h, const off_t offset)
137 {
138         // This function is inside a critical section.
139         GCCriticalSection cs;
140
141         // XXX This should be _handle->get_object();
142         java_object_t* ho = LLNI_UNWRAP(h);
143         return raw_get<volatile T>(ho, offset);
144 }
145
146 template<> inline java_handle_t* FieldAccess::get_volatile(java_handle_t* h, const off_t offset)
147 {
148         // This function is inside a critical section.
149         GCCriticalSection cs;
150
151         // XXX This should be _handle->get_object();
152         java_object_t* o = LLNI_UNWRAP(h);
153         java_object_t* result = (java_object_t*) raw_get<volatile java_object_t*>(o, offset);
154         return LLNI_WRAP(result);
155 }       
156
157
158 template<class T> inline void FieldAccess::set_volatile(java_handle_t* h, const off_t offset, T value)
159 {
160         // This function is inside a critical section.
161         GCCriticalSection cs;
162
163         java_object_t* ho = LLNI_UNWRAP(h);
164         raw_set(ho, offset, (volatile T) value);
165
166         // Memory barrier for the Java Memory Model.
167         Atomic::memory_barrier();
168 }
169
170 template<> inline void FieldAccess::set_volatile<java_handle_t*>(java_handle_t* h, const off_t offset, java_handle_t* value)
171 {
172         // This function is inside a critical section.
173         GCCriticalSection cs;
174
175         // XXX This should be h->get_object();
176         java_object_t* o      = LLNI_UNWRAP(h);
177         java_object_t* ovalue = LLNI_UNWRAP(value);
178         raw_set(o, offset, (volatile java_object_t*) ovalue);
179
180         // Memory barrier for the Java Memory Model.
181         Atomic::memory_barrier();
182 }
183
184
185 /**
186  * java/lang/Object
187  *
188  * Object layout:
189  *
190  * 0. object header
191  */
192 class java_lang_Object {
193 protected:
194         // Handle of Java object.
195         java_handle_t* _handle;
196
197 public:
198         java_lang_Object() : _handle(NULL) {}
199         java_lang_Object(java_handle_t* h) : _handle(h) {}
200         virtual ~java_lang_Object() {}
201
202         // Getters.
203         virtual java_handle_t* get_handle  () const { return _handle; }
204         vftbl_t*               get_vftbl   () const;
205         classinfo*             get_Class   () const;
206         int32_t                get_hashcode() const;
207
208         bool is_null    () const;
209         bool is_non_null() const;
210 };
211
212
213 inline vftbl_t* java_lang_Object::get_vftbl() const
214 {
215         // This function is inside a critical section.
216         GCCriticalSection cs;
217
218         // XXX This should be h->get_object();
219         java_object_t* o = LLNI_UNWRAP(_handle);
220         return o->vftbl;
221 }
222
223 inline classinfo* java_lang_Object::get_Class() const
224 {
225         return get_vftbl()->clazz;
226 }
227
228 inline int32_t java_lang_Object::get_hashcode() const
229 {
230 #if defined(ENABLE_GC_CACAO)
231         return heap_get_hashcode(_handle);
232 #else
233         // This function is inside a critical section.
234         GCCriticalSection cs;
235
236         // XXX This should be h->get_object();
237         java_object_t* o = LLNI_UNWRAP(_handle);
238         return (int32_t) (intptr_t) o;
239 #endif
240 }
241
242
243 inline bool java_lang_Object::is_null() const
244 {
245         return (_handle == NULL);
246 }
247
248 inline bool java_lang_Object::is_non_null() const
249 {
250         return (_handle != NULL);
251 }
252
253
254 /**
255  * java/lang/Boolean
256  *
257  * Object layout:
258  *
259  * 0. object header
260  * 1. boolean value;
261  */
262 class java_lang_Boolean : public java_lang_Object, private FieldAccess {
263 private:
264         // Static offsets of the object's instance fields.
265         // TODO These offsets need to be checked on VM startup.
266         static const off_t offset_value = MEMORY_ALIGN(sizeof(java_object_t), sizeof(int32_t));
267
268 public:
269         java_lang_Boolean(java_handle_t* h) : java_lang_Object(h) {}
270
271         uint8_t get_value();
272         void    set_value(uint8_t value);
273 };
274
275 inline uint8_t java_lang_Boolean::get_value()
276 {
277         return get<int32_t>(_handle, offset_value);
278 }
279
280 inline void java_lang_Boolean::set_value(uint8_t value)
281 {
282         set(_handle, offset_value, (uint32_t) value);
283 }
284
285
286 /**
287  * java/lang/Byte
288  *
289  * Object layout:
290  *
291  * 0. object header
292  * 1. byte value;
293  */
294 class java_lang_Byte : public java_lang_Object, private FieldAccess {
295 private:
296         // Static offsets of the object's instance fields.
297         // TODO These offsets need to be checked on VM startup.
298         static const off_t offset_value = MEMORY_ALIGN(sizeof(java_object_t), sizeof(int32_t));
299
300 public:
301         java_lang_Byte(java_handle_t* h) : java_lang_Object(h) {}
302
303         int8_t get_value();
304         void   set_value(int8_t value);
305 };
306
307 inline int8_t java_lang_Byte::get_value()
308 {
309         return get<int32_t>(_handle, offset_value);
310 }
311
312 inline void java_lang_Byte::set_value(int8_t value)
313 {
314         set(_handle, offset_value, (int32_t) value);
315 }
316
317
318 /**
319  * java/lang/Character
320  *
321  * Object layout:
322  *
323  * 0. object header
324  * 1. char value;
325  */
326 class java_lang_Character : public java_lang_Object, private FieldAccess {
327 private:
328         // Static offsets of the object's instance fields.
329         // TODO These offsets need to be checked on VM startup.
330         static const off_t offset_value = MEMORY_ALIGN(sizeof(java_object_t), sizeof(int32_t));
331
332 public:
333         java_lang_Character(java_handle_t* h) : java_lang_Object(h) {}
334
335         uint16_t get_value();
336         void     set_value(uint16_t value);
337 };
338
339 inline uint16_t java_lang_Character::get_value()
340 {
341         return get<int32_t>(_handle, offset_value);
342 }
343
344 inline void java_lang_Character::set_value(uint16_t value)
345 {
346         set(_handle, offset_value, (uint32_t) value);
347 }
348
349
350 /**
351  * java/lang/Short
352  *
353  * Object layout:
354  *
355  * 0. object header
356  * 1. short value;
357  */
358 class java_lang_Short : public java_lang_Object, private FieldAccess {
359 private:
360         // Static offsets of the object's instance fields.
361         // TODO These offsets need to be checked on VM startup.
362         static const off_t offset_value = MEMORY_ALIGN(sizeof(java_object_t), sizeof(int32_t));
363
364 public:
365         java_lang_Short(java_handle_t* h) : java_lang_Object(h) {}
366
367         int16_t get_value();
368         void    set_value(int16_t value);
369 };
370
371 inline int16_t java_lang_Short::get_value()
372 {
373         return get<int32_t>(_handle, offset_value);
374 }
375
376 inline void java_lang_Short::set_value(int16_t value)
377 {
378         set(_handle, offset_value, (int32_t) value);
379 }
380
381
382 /**
383  * java/lang/Integer
384  *
385  * Object layout:
386  *
387  * 0. object header
388  * 1. int value;
389  */
390 class java_lang_Integer : public java_lang_Object, private FieldAccess {
391 private:
392         // Static offsets of the object's instance fields.
393         // TODO These offsets need to be checked on VM startup.
394         static const off_t offset_value = MEMORY_ALIGN(sizeof(java_object_t), sizeof(int32_t));
395
396 public:
397         java_lang_Integer(java_handle_t* h) : java_lang_Object(h) {}
398
399         int32_t get_value();
400         void    set_value(int32_t value);
401 };
402
403 inline int32_t java_lang_Integer::get_value()
404 {
405         return get<int32_t>(_handle, offset_value);
406 }
407
408 inline void java_lang_Integer::set_value(int32_t value)
409 {
410         set(_handle, offset_value, value);
411 }
412
413
414 /**
415  * java/lang/Long
416  *
417  * Object layout:
418  *
419  * 0. object header
420  * 1. long value;
421  */
422 class java_lang_Long : public java_lang_Object, private FieldAccess {
423 private:
424         // Static offsets of the object's instance fields.
425         // TODO These offsets need to be checked on VM startup.
426         static const off_t offset_value = MEMORY_ALIGN(sizeof(java_object_t), sizeof(int64_t));
427
428 public:
429         java_lang_Long(java_handle_t* h) : java_lang_Object(h) {}
430
431         int64_t get_value();
432         void    set_value(int64_t value);
433 };
434
435 inline int64_t java_lang_Long::get_value()
436 {
437         return get<int64_t>(_handle, offset_value);
438 }
439
440 inline void java_lang_Long::set_value(int64_t value)
441 {
442         set(_handle, offset_value, value);
443 }
444
445
446 /**
447  * java/lang/Float
448  *
449  * Object layout:
450  *
451  * 0. object header
452  * 1. float value;
453  */
454 class java_lang_Float : public java_lang_Object, private FieldAccess {
455 private:
456         // Static offsets of the object's instance fields.
457         // TODO These offsets need to be checked on VM startup.
458         static const off_t offset_value = MEMORY_ALIGN(sizeof(java_object_t), sizeof(float));
459
460 public:
461         java_lang_Float(java_handle_t* h) : java_lang_Object(h) {}
462
463         float get_value();
464         void  set_value(float value);
465 };
466
467 inline float java_lang_Float::get_value()
468 {
469         return get<float>(_handle, offset_value);
470 }
471
472 inline void java_lang_Float::set_value(float value)
473 {
474         set(_handle, offset_value, value);
475 }
476
477
478 /**
479  * java/lang/Double
480  *
481  * Object layout:
482  *
483  * 0. object header
484  * 1. double value;
485  */
486 class java_lang_Double : public java_lang_Object, private FieldAccess {
487 private:
488         // Static offsets of the object's instance fields.
489         // TODO These offsets need to be checked on VM startup.
490         static const off_t offset_value = MEMORY_ALIGN(sizeof(java_object_t), sizeof(double));
491
492 public:
493         java_lang_Double(java_handle_t* h) : java_lang_Object(h) {}
494
495         double get_value();
496         void   set_value(double value);
497 };
498
499 inline double java_lang_Double::get_value()
500 {
501         return get<double>(_handle, offset_value);
502 }
503
504 inline void java_lang_Double::set_value(double value)
505 {
506         set(_handle, offset_value, value);
507 }
508
509
510 #if defined(ENABLE_JAVASE)
511
512 /**
513  * java/lang/management/MemoryUsage
514  *
515  * Object layout:
516  *
517  * 0. object header
518  * [other fields are not used]
519  */
520 class java_lang_management_MemoryUsage : public java_lang_Object, private FieldAccess {
521 public:
522         java_lang_management_MemoryUsage(java_handle_t* h) : java_lang_Object(h) {}
523         java_lang_management_MemoryUsage(int64_t init, int64_t used, int64_t commited, int64_t maximum);
524 };
525
526
527 # if defined(ENABLE_ANNOTATIONS)
528 /**
529  * OpenJDK sun/reflect/ConstantPool
530  *
531  * Object layout:
532  *
533  * 0. object header
534  * 1. java.lang.Object constantPoolOop;
535  */
536 class sun_reflect_ConstantPool : public java_lang_Object, private FieldAccess {
537 private:
538         // Static offsets of the object's instance fields.
539         // TODO These offsets need to be checked on VM startup.
540         static const off_t offset_constantPoolOop = MEMORY_ALIGN(sizeof(java_object_t), SIZEOF_VOID_P);
541
542 public:
543         sun_reflect_ConstantPool(java_handle_t* h) : java_lang_Object(h) {}
544         sun_reflect_ConstantPool(java_handle_t* h, jclass constantPoolOop);
545
546         // Setters.
547         void set_constantPoolOop(classinfo* value);
548         void set_constantPoolOop(jclass value);
549 };
550
551
552 inline sun_reflect_ConstantPool::sun_reflect_ConstantPool(java_handle_t* h, jclass constantPoolOop) : java_lang_Object(h)
553 {
554         set_constantPoolOop(constantPoolOop);
555 }
556
557
558 inline void sun_reflect_ConstantPool::set_constantPoolOop(classinfo* value)
559 {
560         set(_handle, offset_constantPoolOop, value);
561 }
562
563 inline void sun_reflect_ConstantPool::set_constantPoolOop(jclass value)
564 {
565         // XXX jclass is a boxed object.
566         set_constantPoolOop(LLNI_classinfo_unwrap(value));
567 }
568 # endif // ENABLE_ANNOTATIONS
569
570 #endif // ENABLE_JAVASE
571
572
573 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
574
575 /**
576  * GNU Classpath java/lang/Class
577  *
578  * Object layout:
579  *
580  * 0. object header
581  * 1. java.lang.Object[]             signers;
582  * 2. java.security.ProtectionDomain pd;
583  * 3. java.lang.Object               vmdata;
584  * 4. java.lang.reflect.Constructor  constructor;
585  */
586 class java_lang_Class : public java_lang_Object, private FieldAccess {
587 private:
588         // Static offsets of the object's instance fields.
589         // TODO These offsets need to be checked on VM startup.
590         static const off_t offset_signers     = MEMORY_ALIGN(sizeof(java_object_t),          SIZEOF_VOID_P);
591         static const off_t offset_pd          = MEMORY_ALIGN(offset_signers + SIZEOF_VOID_P, SIZEOF_VOID_P);
592         static const off_t offset_vmdata      = MEMORY_ALIGN(offset_pd      + SIZEOF_VOID_P, SIZEOF_VOID_P);
593         static const off_t offset_constructor = MEMORY_ALIGN(offset_vmdata  + SIZEOF_VOID_P, SIZEOF_VOID_P);
594
595 public:
596         java_lang_Class(java_handle_t* h) : java_lang_Object(h) {}
597
598         // Setters.
599         void set_pd(java_handle_t* value);
600 };
601
602 inline void java_lang_Class::set_pd(java_handle_t* value)
603 {
604         set(_handle, offset_pd, value);
605 }
606
607
608 /**
609  * GNU Classpath java/lang/ClassLoader
610  *
611  * Object layout:
612  *
613  * 0. object header
614  * 1. java.util.HashMap     definedPackages
615  * 2. java.lang.ClassLoader parent
616  * [other fields are not used]
617  */
618 class java_lang_ClassLoader : public java_lang_Object, private FieldAccess {
619 private:
620         // Static offsets of the object's instance fields.
621         // TODO These offsets need to be checked on VM startup.
622         static const off_t offset_definedPackages = MEMORY_ALIGN(sizeof(java_object_t),                  SIZEOF_VOID_P);
623         static const off_t offset_parent          = MEMORY_ALIGN(offset_definedPackages + SIZEOF_VOID_P, SIZEOF_VOID_P);
624
625 public:
626         java_lang_ClassLoader(java_handle_t* h) : java_lang_Object(h) {}
627
628         // Getters.
629         java_handle_t* get_parent() const;
630
631         // Invocation wrappers for static methods.
632         static java_handle_t* invoke_getSystemClassLoader();
633 };
634
635 inline java_handle_t* java_lang_ClassLoader::get_parent() const
636 {
637         return get<java_handle_t*>(_handle, offset_parent);
638 }
639
640
641 /**
642  * GNU Classpath java/lang/StackTraceElement
643  *
644  * Object layout:
645  *
646  * 0. object header
647  * 1. java.lang.String fileName;
648  * 2. int              lineNumber;
649  * 3. java.lang.String declaringClass;
650  * 4. java.lang.String methodName;
651  * 5. boolean          isNative;
652  */
653 class java_lang_StackTraceElement : public java_lang_Object, private FieldAccess {
654 private:
655         // Static offsets of the object's instance fields.
656         // TODO These offsets need to be checked on VM startup.
657         static const off_t offset_fileName       = MEMORY_ALIGN(sizeof(java_object_t),                   SIZEOF_VOID_P);
658         static const off_t offset_lineNumber     = MEMORY_ALIGN(offset_fileName       + SIZEOF_VOID_P,   sizeof(int32_t));
659         static const off_t offset_declaringClass = MEMORY_ALIGN(offset_lineNumber     + sizeof(int32_t), SIZEOF_VOID_P);
660         static const off_t offset_methodName     = MEMORY_ALIGN(offset_declaringClass + SIZEOF_VOID_P,   SIZEOF_VOID_P);
661         static const off_t offset_isNative       = MEMORY_ALIGN(offset_methodName     + SIZEOF_VOID_P,   SIZEOF_VOID_P);
662
663 public:
664         java_lang_StackTraceElement(java_handle_t* h) : java_lang_Object(h) {}
665         java_lang_StackTraceElement(java_handle_t* h, java_handle_t* fileName, int32_t lineNumber, java_handle_t* declaringClass, java_handle_t* methodName, uint8_t isNative);
666 };
667
668 inline java_lang_StackTraceElement::java_lang_StackTraceElement(java_handle_t* h, java_handle_t* fileName, int32_t lineNumber, java_handle_t* declaringClass, java_handle_t* methodName, uint8_t isNative) : java_lang_Object(h)
669 {
670         java_lang_StackTraceElement((java_handle_t*) h);
671
672         set(_handle, offset_fileName,       fileName);
673         set(_handle, offset_lineNumber,     lineNumber);
674         set(_handle, offset_declaringClass, declaringClass);
675         set(_handle, offset_methodName,     methodName);
676         set(_handle, offset_isNative,       isNative);
677 }
678
679
680 /**
681  * GNU Classpath java/lang/String
682  *
683  * Object layout:
684  *
685  * 0. object header
686  * 1. char[] value;
687  * 2. int    count;
688  * 3. int    cachedHashCode;
689  * 4. int    offset;
690  */
691 class java_lang_String : public java_lang_Object, private FieldAccess {
692 private:
693         // Static offsets of the object's instance fields.
694         // TODO These offsets need to be checked on VM startup.
695         static const off_t offset_value          = MEMORY_ALIGN(sizeof(java_object_t),                   SIZEOF_VOID_P);
696         static const off_t offset_count          = MEMORY_ALIGN(offset_value          + SIZEOF_VOID_P,   sizeof(int32_t));
697         static const off_t offset_cachedHashCode = MEMORY_ALIGN(offset_count          + sizeof(int32_t), sizeof(int32_t));
698         static const off_t offset_offset         = MEMORY_ALIGN(offset_cachedHashCode + sizeof(int32_t), sizeof(int32_t));
699
700 public:
701         java_lang_String(java_handle_t* h) : java_lang_Object(h) {}
702         java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset = 0);
703
704         // Getters.
705         java_handle_chararray_t* get_value () const;
706         int32_t                  get_count () const;
707         int32_t                  get_offset() const;
708
709         // Setters.
710         void set_value (java_handle_chararray_t* value);
711         void set_count (int32_t value);
712         void set_offset(int32_t value);
713 };
714
715 inline java_lang_String::java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset) : java_lang_Object(h)
716 {
717         set_value(value);
718         set_count(count);
719         set_offset(offset);
720 }
721
722 inline java_handle_chararray_t* java_lang_String::get_value() const
723 {
724         return get<java_handle_chararray_t*>(_handle, offset_value);
725 }
726
727 inline int32_t java_lang_String::get_count() const
728 {
729         return get<int32_t>(_handle, offset_count);
730 }
731
732 inline int32_t java_lang_String::get_offset() const
733 {
734         return get<int32_t>(_handle, offset_offset);
735 }
736
737 inline void java_lang_String::set_value(java_handle_chararray_t* value)
738 {
739         set(_handle, offset_value, value);
740 }
741
742 inline void java_lang_String::set_count(int32_t value)
743 {
744         set(_handle, offset_count, value);
745 }
746
747 inline void java_lang_String::set_offset(int32_t value)
748 {
749         set(_handle, offset_offset, value);
750 }
751
752
753 /**
754  * GNU Classpath java/lang/Thread
755  *
756  * Object layout:
757  *
758  *  0. object header
759  *  1. java.lang.VMThread                        vmThread;
760  *  2. java.lang.ThreadGroup                     group;
761  *  3. java.lang.Runnable                        runnable;
762  *  4. java.lang.String                          name;
763  *  5. boolean                                   daemon;
764  *  6. int                                       priority;
765  *  7. long                                      stacksize;
766  *  8. java.lang.Throwable                       stillborn;
767  *  9. java.lang.ClassLoader                     contextClassLoader;
768  * 10. boolean                                   contextClassLoaderIsSystemClassLoader;
769  * 11. long                                      threadId;
770  * 12. java.lang.Object                          parkBlocker;
771  * 13. gnu.java.util.WeakIdentityHashMap         locals;
772  * 14. java_lang_Thread_UncaughtExceptionHandler exceptionHandler;
773  */
774 class java_lang_Thread : public java_lang_Object, private FieldAccess {
775 private:
776         // Static offsets of the object's instance fields.
777         // TODO These offsets need to be checked on VM startup.
778         static const off_t offset_vmThread                              = MEMORY_ALIGN(sizeof(java_object_t),                                          SIZEOF_VOID_P);
779         static const off_t offset_group                                 = MEMORY_ALIGN(offset_vmThread                              + SIZEOF_VOID_P,   SIZEOF_VOID_P);
780         static const off_t offset_runnable                              = MEMORY_ALIGN(offset_group                                 + SIZEOF_VOID_P,   SIZEOF_VOID_P);
781         static const off_t offset_name                                  = MEMORY_ALIGN(offset_runnable                              + SIZEOF_VOID_P,   SIZEOF_VOID_P);
782         static const off_t offset_daemon                                = MEMORY_ALIGN(offset_name                                  + SIZEOF_VOID_P,   sizeof(int32_t));
783         static const off_t offset_priority                              = MEMORY_ALIGN(offset_daemon                                + sizeof(int32_t), sizeof(int32_t));
784         static const off_t offset_stacksize                             = MEMORY_ALIGN(offset_priority                              + sizeof(int32_t), sizeof(int64_t));
785         static const off_t offset_stillborn                             = MEMORY_ALIGN(offset_stacksize                             + sizeof(int64_t), SIZEOF_VOID_P);
786         static const off_t offset_contextClassLoader                    = MEMORY_ALIGN(offset_stillborn                             + SIZEOF_VOID_P,   SIZEOF_VOID_P);
787         static const off_t offset_contextClassLoaderIsSystemClassLoader = MEMORY_ALIGN(offset_contextClassLoader                    + SIZEOF_VOID_P,   SIZEOF_VOID_P);
788         static const off_t offset_threadId                              = MEMORY_ALIGN(offset_contextClassLoaderIsSystemClassLoader + sizeof(int32_t), sizeof(int64_t));
789         static const off_t offset_parkBlocker                           = MEMORY_ALIGN(offset_threadId                              + sizeof(int64_t), SIZEOF_VOID_P);
790         static const off_t offset_locals                                = MEMORY_ALIGN(offset_parkBlocker                           + SIZEOF_VOID_P,   SIZEOF_VOID_P);
791         static const off_t offset_exceptionHandler                      = MEMORY_ALIGN(offset_locals                                + SIZEOF_VOID_P,   SIZEOF_VOID_P);
792
793 public:
794         java_lang_Thread(java_handle_t* h) : java_lang_Object(h) {}
795 //      java_lang_Thread(threadobject* t);
796
797         // Getters.
798         java_handle_t* get_vmThread        () const;
799         java_handle_t* get_group           () const;
800         java_handle_t* get_name            () const;
801         int32_t        get_daemon          () const;
802         int32_t        get_priority        () const;
803         java_handle_t* get_exceptionHandler() const;
804
805         // Setters.
806         void set_group(java_handle_t* value);
807 };
808
809
810 // inline java_lang_Thread::java_lang_Thread(threadobject* t) : java_lang_Object(h)
811 // {
812 //      java_lang_Thread(thread_get_object(t));
813 // }
814
815
816 inline java_handle_t* java_lang_Thread::get_vmThread() const
817 {
818         return get<java_handle_t*>(_handle, offset_vmThread);
819 }
820
821 inline java_handle_t* java_lang_Thread::get_group() const
822 {
823         return get<java_handle_t*>(_handle, offset_group);
824 }
825
826 inline java_handle_t* java_lang_Thread::get_name() const
827 {
828         return get<java_handle_t*>(_handle, offset_name);
829 }
830
831 inline int32_t java_lang_Thread::get_daemon() const
832 {
833         return get<int32_t>(_handle, offset_daemon);
834 }
835
836 inline int32_t java_lang_Thread::get_priority() const
837 {
838         return get<int32_t>(_handle, offset_priority);
839 }
840
841 inline java_handle_t* java_lang_Thread::get_exceptionHandler() const
842 {
843         return get<java_handle_t*>(_handle, offset_exceptionHandler);
844 }
845
846
847 inline void java_lang_Thread::set_group(java_handle_t* value)
848 {
849         set(_handle, offset_group, value);
850 }
851
852
853 /**
854  * GNU Classpath java/lang/VMThread
855  *
856  * Object layout:
857  *
858  * 0. object header
859  * 1. java.lang.Thread   thread;
860  * 2. boolean            running;
861  * 3. java.lang.VMThread vmdata;
862  */
863 class java_lang_VMThread : public java_lang_Object, private FieldAccess {
864 private:
865         // Static offsets of the object's instance fields.
866         // TODO These offsets need to be checked on VM startup.
867         static const off_t offset_thread  = MEMORY_ALIGN(sizeof(java_object_t),            SIZEOF_VOID_P);
868         static const off_t offset_running = MEMORY_ALIGN(offset_thread  + SIZEOF_VOID_P,   sizeof(int32_t));
869         static const off_t offset_vmdata  = MEMORY_ALIGN(offset_running + sizeof(int32_t), SIZEOF_VOID_P);
870
871 public:
872         java_lang_VMThread(java_handle_t* h) : java_lang_Object(h) {}
873         java_lang_VMThread(java_handle_t* h, java_handle_t* thread, threadobject* vmdata);
874
875         // Getters.
876         java_handle_t* get_thread() const;
877         threadobject*  get_vmdata() const;
878
879         // Setters.
880         void set_thread(java_handle_t* value);
881         void set_vmdata(threadobject* value);
882 };
883
884
885 inline java_lang_VMThread::java_lang_VMThread(java_handle_t* h, java_handle_t* thread, threadobject* vmdata) : java_lang_Object(h)
886 {
887         set_thread(thread);
888         set_vmdata(vmdata);
889 }
890
891
892 inline java_handle_t* java_lang_VMThread::get_thread() const
893 {
894         return get<java_handle_t*>(_handle, offset_thread);
895 }
896
897 inline threadobject* java_lang_VMThread::get_vmdata() const
898 {
899         return get<threadobject*>(_handle, offset_vmdata);
900 }
901
902
903 inline void java_lang_VMThread::set_thread(java_handle_t* value)
904 {
905         set(_handle, offset_thread, value);
906 }
907
908 inline void java_lang_VMThread::set_vmdata(threadobject* value)
909 {
910         set(_handle, offset_vmdata, value);
911 }
912
913
914 /**
915  * GNU Classpath java/lang/Throwable
916  *
917  * Object layout:
918  *
919  * 0. object header
920  * 1. java.lang.String              detailMessage;
921  * 2. java.lang.Throwable           cause;
922  * 3. java.lang.StackTraceElement[] stackTrace;
923  * 4. java.lang.VMThrowable         vmState;
924  */
925 class java_lang_Throwable : public java_lang_Object, private FieldAccess {
926 private:
927         // Static offsets of the object's instance fields.
928         // TODO These offsets need to be checked on VM startup.
929         static const off_t offset_detailMessage = MEMORY_ALIGN(sizeof(java_object_t),                SIZEOF_VOID_P);
930         static const off_t offset_cause         = MEMORY_ALIGN(offset_detailMessage + SIZEOF_VOID_P, SIZEOF_VOID_P);
931         static const off_t offset_stackTrace    = MEMORY_ALIGN(offset_cause         + SIZEOF_VOID_P, SIZEOF_VOID_P);
932         static const off_t offset_vmState       = MEMORY_ALIGN(offset_stackTrace    + SIZEOF_VOID_P, SIZEOF_VOID_P);
933
934 public:
935         java_lang_Throwable(java_handle_t* h) : java_lang_Object(h) {}
936
937         // Getters.
938         java_handle_t* get_detailMessage() const;
939         java_handle_t* get_cause        () const;
940         java_handle_t* get_vmState      () const;
941 };
942
943
944 inline java_handle_t* java_lang_Throwable::get_detailMessage() const
945 {
946         return get<java_handle_t*>(_handle, offset_detailMessage);
947 }
948
949 inline java_handle_t* java_lang_Throwable::get_cause() const
950 {
951         return get<java_handle_t*>(_handle, offset_cause);
952 }
953
954 inline java_handle_t* java_lang_Throwable::get_vmState() const
955 {
956         return get<java_handle_t*>(_handle, offset_vmState);
957 }
958
959
960 /**
961  * GNU Classpath java/lang/VMThrowable
962  *
963  * Object layout:
964  *
965  * 0. object header
966  * 1. java.lang.Object vmdata;
967  */
968 class java_lang_VMThrowable : public java_lang_Object, private FieldAccess {
969 private:
970         // Static offsets of the object's instance fields.
971         // TODO These offsets need to be checked on VM startup.
972         static const off_t offset_vmdata = MEMORY_ALIGN(sizeof(java_object_t), SIZEOF_VOID_P);
973
974 public:
975         java_lang_VMThrowable(java_handle_t* h) : java_lang_Object(h) {}
976
977         java_handle_bytearray_t* get_vmdata() const;
978         void                     set_vmdata(java_handle_bytearray_t* value);
979 };
980
981
982 inline java_handle_bytearray_t* java_lang_VMThrowable::get_vmdata() const
983 {
984         return get<java_handle_bytearray_t*>(_handle, offset_vmdata);
985 }
986
987 inline void java_lang_VMThrowable::set_vmdata(java_handle_bytearray_t* value)
988 {
989         set(_handle, offset_vmdata, value);
990 }
991
992
993 /**
994  * GNU Classpath java/lang/reflect/VMConstructor
995  *
996  * Object layout:
997  *
998  * 0. object header
999  * 1. java.lang.Class               clazz;
1000  * 2. int                           slot;
1001  * 3. byte[]                        annotations;
1002  * 4. byte[]                        parameterAnnotations;
1003  * 5. java.util.Map                 declaredAnnotations;
1004  * 6. java.lang.reflect.Constructor cons;
1005  */
1006 class java_lang_reflect_VMConstructor : public java_lang_Object, private FieldAccess {
1007 private:
1008         // Static offsets of the object's instance fields.
1009         // TODO These offsets need to be checked on VM startup.
1010         static const off_t offset_clazz                = MEMORY_ALIGN(sizeof(java_object_t),                         SIZEOF_VOID_P);
1011         static const off_t offset_slot                 = MEMORY_ALIGN(offset_clazz                + SIZEOF_VOID_P,   sizeof(int32_t));
1012         static const off_t offset_annotations          = MEMORY_ALIGN(offset_slot                 + sizeof(int32_t), SIZEOF_VOID_P);
1013         static const off_t offset_parameterAnnotations = MEMORY_ALIGN(offset_annotations          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1014         static const off_t offset_declaredAnnotations  = MEMORY_ALIGN(offset_parameterAnnotations + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1015         static const off_t offset_cons                 = MEMORY_ALIGN(offset_declaredAnnotations  + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1016
1017 public:
1018         java_lang_reflect_VMConstructor(java_handle_t* h) : java_lang_Object(h) {}
1019         java_lang_reflect_VMConstructor(methodinfo* m);
1020
1021         // Getters.
1022         classinfo*               get_clazz               () const;
1023         int32_t                  get_slot                () const;
1024         java_handle_bytearray_t* get_annotations         () const;
1025         java_handle_bytearray_t* get_parameterAnnotations() const;
1026         java_handle_t*           get_declaredAnnotations () const;
1027         java_handle_t*           get_cons                () const;
1028
1029         // Setters.
1030         void set_clazz               (classinfo* value);
1031         void set_slot                (int32_t value);
1032         void set_annotations         (java_handle_bytearray_t* value);
1033         void set_parameterAnnotations(java_handle_bytearray_t* value);
1034         void set_declaredAnnotations (java_handle_t* value);
1035         void set_cons                (java_handle_t* value);
1036
1037         // Convenience functions.
1038         methodinfo* get_method();
1039 };
1040
1041
1042 inline java_lang_reflect_VMConstructor::java_lang_reflect_VMConstructor(methodinfo* m)
1043 {
1044         _handle = builtin_new(class_java_lang_reflect_VMConstructor);
1045
1046         if (is_null())
1047                 return;
1048
1049         int                      slot                 = m - m->clazz->methods;
1050         java_handle_bytearray_t* annotations          = method_get_annotations(m);
1051         java_handle_bytearray_t* parameterAnnotations = method_get_parameterannotations(m);
1052
1053         set_clazz(m->clazz);
1054         set_slot(slot);
1055         set_annotations(annotations);
1056         set_parameterAnnotations(parameterAnnotations);
1057 }
1058
1059
1060 inline classinfo* java_lang_reflect_VMConstructor::get_clazz() const
1061 {
1062         return get<classinfo*>(_handle, offset_clazz);
1063 }
1064
1065 inline int32_t java_lang_reflect_VMConstructor::get_slot() const
1066 {
1067         return get<int32_t>(_handle, offset_slot);
1068 }
1069
1070 inline java_handle_bytearray_t* java_lang_reflect_VMConstructor::get_annotations() const
1071 {
1072         return get<java_handle_bytearray_t*>(_handle, offset_annotations);
1073 }
1074
1075 inline java_handle_bytearray_t* java_lang_reflect_VMConstructor::get_parameterAnnotations() const
1076 {
1077         return get<java_handle_bytearray_t*>(_handle, offset_parameterAnnotations);
1078 }
1079
1080 inline java_handle_t* java_lang_reflect_VMConstructor::get_declaredAnnotations() const
1081 {
1082         return get<java_handle_t*>(_handle, offset_declaredAnnotations);
1083 }
1084
1085 inline java_handle_t* java_lang_reflect_VMConstructor::get_cons() const
1086 {
1087         return get<java_handle_t*>(_handle, offset_cons);
1088 }
1089
1090 inline void java_lang_reflect_VMConstructor::set_clazz(classinfo* value)
1091 {
1092         set(_handle, offset_clazz, value);
1093 }
1094
1095 inline void java_lang_reflect_VMConstructor::set_slot(int32_t value)
1096 {
1097         set(_handle, offset_slot, value);
1098 }
1099
1100 inline void java_lang_reflect_VMConstructor::set_annotations(java_handle_bytearray_t* value)
1101 {
1102         set(_handle, offset_annotations, value);
1103 }
1104
1105 inline void java_lang_reflect_VMConstructor::set_parameterAnnotations(java_handle_bytearray_t* value)
1106 {
1107         set(_handle, offset_parameterAnnotations, value);
1108 }
1109
1110 inline void java_lang_reflect_VMConstructor::set_declaredAnnotations(java_handle_t* value)
1111 {
1112         set(_handle, offset_declaredAnnotations, value);
1113 }
1114
1115 inline void java_lang_reflect_VMConstructor::set_cons(java_handle_t* value)
1116 {
1117         set(_handle, offset_cons, value);
1118 }
1119
1120 inline methodinfo* java_lang_reflect_VMConstructor::get_method()
1121 {
1122         classinfo*  c    = get_clazz();
1123         int32_t     slot = get_slot();
1124         methodinfo* m    = &(c->methods[slot]);
1125         return m;
1126 }
1127
1128
1129 /**
1130  * GNU Classpath java/lang/reflect/Constructor
1131  *
1132  * Object layout:
1133  *
1134  * 0. object header
1135  * 1. boolean                                     flag;
1136  * 2. gnu.java.lang.reflect.MethodSignatureParser p;
1137  * 3. java.lang.reflect.VMConstructor             cons;
1138  */
1139 class java_lang_reflect_Constructor : public java_lang_Object, private FieldAccess {
1140 private:
1141         // Static offsets of the object's instance fields.
1142         // TODO These offsets need to be checked on VM startup.
1143         static const off_t offset_flag = MEMORY_ALIGN(sizeof(java_object_t),         sizeof(int32_t));
1144         static const off_t offset_p    = MEMORY_ALIGN(offset_flag + sizeof(int32_t), SIZEOF_VOID_P);
1145         static const off_t offset_cons = MEMORY_ALIGN(offset_p    + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1146
1147 public:
1148         java_lang_reflect_Constructor(java_handle_t* h) : java_lang_Object(h) {}
1149         java_lang_reflect_Constructor(methodinfo* m);
1150
1151         java_handle_t* new_instance(java_handle_objectarray_t* args);
1152
1153         // Getters.
1154         int32_t        get_flag() const;
1155         java_handle_t* get_cons() const;
1156
1157         // Setters.
1158         void set_cons(java_handle_t* value);
1159
1160         // Convenience functions.
1161         methodinfo* get_method  () const;
1162         int32_t     get_override() const;
1163 };
1164
1165
1166 inline java_lang_reflect_Constructor::java_lang_reflect_Constructor(methodinfo* m)
1167 {
1168         java_lang_reflect_VMConstructor jlrvmc(m);
1169
1170         if (jlrvmc.is_null())
1171                 return;
1172
1173         _handle = builtin_new(class_java_lang_reflect_Constructor);
1174
1175         if (is_null())
1176                 return;
1177
1178         // Link the two Java objects.
1179         set_cons(jlrvmc.get_handle());
1180         jlrvmc.set_cons(get_handle());
1181 }
1182
1183
1184 inline int32_t java_lang_reflect_Constructor::get_flag() const
1185 {
1186         return get<int32_t>(_handle, offset_flag);
1187 }
1188
1189 inline java_handle_t* java_lang_reflect_Constructor::get_cons() const
1190 {
1191         return get<java_handle_t*>(_handle, offset_cons);
1192 }
1193
1194
1195 inline void java_lang_reflect_Constructor::set_cons(java_handle_t* value)
1196 {
1197         set(_handle, offset_cons, value);
1198 }
1199
1200
1201 inline methodinfo* java_lang_reflect_Constructor::get_method() const
1202 {
1203         java_lang_reflect_VMConstructor jlrvmc(get_cons());
1204         return jlrvmc.get_method();
1205 }
1206
1207 inline int32_t java_lang_reflect_Constructor::get_override() const
1208 {
1209         return get_flag();
1210 }
1211
1212
1213 /**
1214  * GNU Classpath java/lang/reflect/VMField
1215  *
1216  * Object layout:
1217  *
1218  * 0. object header
1219  * 1. java.lang.Class         clazz;
1220  * 2. java.lang.String        name;
1221  * 3. int                     slot;
1222  * 4. byte[]                  annotations;
1223  * 5. java.lang.Map           declaredAnnotations;
1224  * 6. java.lang.reflect.Field f;
1225  */
1226 class java_lang_reflect_VMField : public java_lang_Object, private FieldAccess {
1227 private:
1228         // Static offsets of the object's instance fields.
1229         // TODO These offsets need to be checked on VM startup.
1230         static const off_t offset_clazz               = MEMORY_ALIGN(sizeof(java_object_t),                        SIZEOF_VOID_P);
1231         static const off_t offset_name                = MEMORY_ALIGN(offset_clazz               + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1232         static const off_t offset_slot                = MEMORY_ALIGN(offset_name                + SIZEOF_VOID_P,   sizeof(int32_t));
1233         static const off_t offset_annotations         = MEMORY_ALIGN(offset_slot                + sizeof(int32_t), SIZEOF_VOID_P);
1234         static const off_t offset_declaredAnnotations = MEMORY_ALIGN(offset_annotations         + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1235         static const off_t offset_f                   = MEMORY_ALIGN(offset_declaredAnnotations + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1236
1237 public:
1238         java_lang_reflect_VMField(java_handle_t* h) : java_lang_Object(h) {}
1239         java_lang_reflect_VMField(fieldinfo* f);
1240
1241         // Getters.
1242         classinfo*               get_clazz              () const;
1243         int32_t                  get_slot               () const;
1244         java_handle_bytearray_t* get_annotations        () const;
1245         java_handle_t*           get_declaredAnnotations() const;
1246         java_handle_t*           get_f                  () const;
1247
1248         // Setters.
1249         void set_clazz              (classinfo* value);
1250         void set_name               (java_handle_t* value);
1251         void set_slot               (int32_t value);
1252         void set_annotations        (java_handle_bytearray_t* value);
1253         void set_declaredAnnotations(java_handle_t* value);
1254         void set_f                  (java_handle_t* value);
1255
1256         // Convenience functions.
1257         fieldinfo* get_field() const;
1258 };
1259
1260
1261 inline java_lang_reflect_VMField::java_lang_reflect_VMField(fieldinfo* f)
1262 {
1263         _handle = builtin_new(class_java_lang_reflect_VMField);
1264
1265         if (is_null())
1266                 return;
1267
1268         java_handle_t*           name        = javastring_intern(javastring_new(f->name));
1269         int                      slot        = f - f->clazz->fields;
1270         java_handle_bytearray_t* annotations = field_get_annotations(f);
1271
1272         set_clazz(f->clazz);
1273         set_name(name);
1274         set_slot(slot);
1275         set_annotations(annotations);
1276 }
1277
1278
1279 inline classinfo* java_lang_reflect_VMField::get_clazz() const
1280 {
1281         return get<classinfo*>(_handle, offset_clazz);
1282 }
1283
1284 inline int32_t java_lang_reflect_VMField::get_slot() const
1285 {
1286         return get<int32_t>(_handle, offset_slot);
1287 }
1288
1289 inline java_handle_bytearray_t* java_lang_reflect_VMField::get_annotations() const
1290 {
1291         return get<java_handle_bytearray_t*>(_handle, offset_annotations);
1292 }
1293
1294 inline java_handle_t* java_lang_reflect_VMField::get_declaredAnnotations() const
1295 {
1296         return get<java_handle_t*>(_handle, offset_declaredAnnotations);
1297 }
1298
1299 inline java_handle_t* java_lang_reflect_VMField::get_f() const
1300 {
1301         return get<java_handle_t*>(_handle, offset_f);
1302 }
1303
1304
1305 inline void java_lang_reflect_VMField::set_clazz(classinfo* value)
1306 {
1307         set(_handle, offset_clazz, value);
1308 }
1309
1310 inline void java_lang_reflect_VMField::set_name(java_handle_t* value)
1311 {
1312         set(_handle, offset_name, value);
1313 }
1314
1315 inline void java_lang_reflect_VMField::set_slot(int32_t value)
1316 {
1317         set(_handle, offset_slot, value);
1318 }
1319
1320 inline void java_lang_reflect_VMField::set_annotations(java_handle_bytearray_t* value)
1321 {
1322         set(_handle, offset_annotations, value);
1323 }
1324
1325 inline void java_lang_reflect_VMField::set_declaredAnnotations(java_handle_t* value)
1326 {
1327         set(_handle, offset_declaredAnnotations, value);
1328 }
1329
1330 inline void java_lang_reflect_VMField::set_f(java_handle_t* value)
1331 {
1332         set(_handle, offset_f, value);
1333 }
1334
1335 inline fieldinfo* java_lang_reflect_VMField::get_field() const
1336 {
1337         classinfo* c    = get_clazz();
1338         int32_t    slot = get_slot();
1339         fieldinfo* f    = &(c->fields[slot]);
1340         return f;
1341 }
1342
1343
1344 /**
1345  * GNU Classpath java/lang/reflect/Field
1346  *
1347  * Object layout:
1348  *
1349  * 0. object header
1350  * 1. boolean                                    flag;
1351  * 2. gnu.java.lang.reflect.FieldSignatureParser p;
1352  * 3. java.lang.reflect.VMField                  f;
1353  */
1354 class java_lang_reflect_Field : public java_lang_Object, private FieldAccess {
1355 private:
1356         // Static offsets of the object's instance fields.
1357         // TODO These offsets need to be checked on VM startup.
1358         static const off_t offset_flag = MEMORY_ALIGN(sizeof(java_object_t),         sizeof(int32_t));
1359         static const off_t offset_p    = MEMORY_ALIGN(offset_flag + sizeof(int32_t), SIZEOF_VOID_P);
1360         static const off_t offset_f    = MEMORY_ALIGN(offset_p    + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1361
1362 public:
1363         java_lang_reflect_Field(java_handle_t* h) : java_lang_Object(h) {}
1364         java_lang_reflect_Field(fieldinfo* f);
1365
1366         // Getters.
1367         int32_t        get_flag() const;
1368         java_handle_t* get_f() const;
1369
1370         // Setters.
1371         void set_f(java_handle_t* value);
1372
1373         // Convenience functions.
1374         fieldinfo* get_field() const;
1375 };
1376
1377
1378 inline java_lang_reflect_Field::java_lang_reflect_Field(fieldinfo* f)
1379 {
1380         java_lang_reflect_VMField jlrvmf(f);
1381
1382         if (jlrvmf.is_null())
1383                 return;
1384
1385         _handle = builtin_new(class_java_lang_reflect_Field);
1386
1387         if (is_null())
1388                 return;
1389
1390         // Link the two Java objects.
1391         set_f(jlrvmf.get_handle());
1392         jlrvmf.set_f(get_handle());
1393 }
1394
1395
1396 inline int32_t java_lang_reflect_Field::get_flag() const
1397 {
1398         return get<int32_t>(_handle, offset_flag);
1399 }
1400
1401 inline java_handle_t* java_lang_reflect_Field::get_f() const
1402 {
1403         return get<java_handle_t*>(_handle, offset_f);
1404 }
1405
1406
1407 inline void java_lang_reflect_Field::set_f(java_handle_t* value)
1408 {
1409         set(_handle, offset_f, value);
1410 }
1411
1412
1413 inline fieldinfo* java_lang_reflect_Field::get_field() const
1414 {
1415         java_lang_reflect_VMField jlrvmf(get_f());
1416         return jlrvmf.get_field();
1417 }
1418
1419
1420 /**
1421  * GNU Classpath java/lang/reflect/VMMethod
1422  *
1423  * Object layout:
1424  *
1425  * 0. object header
1426  * 1. java.lang.Class          clazz;
1427  * 2. java.lang.String         name;
1428  * 3. int                      slot;
1429  * 4. byte[]                   annotations;
1430  * 5. byte[]                   parameterAnnotations;
1431  * 6. byte[]                   annotationDefault;
1432  * 7. java.lang.Map            declaredAnnotations;
1433  * 8. java.lang.reflect.Method m;
1434  */
1435 class java_lang_reflect_VMMethod : public java_lang_Object, private FieldAccess {
1436 private:
1437         // Static offsets of the object's instance fields.
1438         // TODO These offsets need to be checked on VM startup.
1439         static const off_t offset_clazz                = MEMORY_ALIGN(sizeof(java_object_t),                         SIZEOF_VOID_P);
1440         static const off_t offset_name                 = MEMORY_ALIGN(offset_clazz                + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1441         static const off_t offset_slot                 = MEMORY_ALIGN(offset_name                 + SIZEOF_VOID_P,   sizeof(int32_t));
1442         static const off_t offset_annotations          = MEMORY_ALIGN(offset_slot                 + sizeof(int32_t), SIZEOF_VOID_P);
1443         static const off_t offset_parameterAnnotations = MEMORY_ALIGN(offset_annotations          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1444         static const off_t offset_annotationDefault    = MEMORY_ALIGN(offset_parameterAnnotations + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1445         static const off_t offset_declaredAnnotations  = MEMORY_ALIGN(offset_annotationDefault    + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1446         static const off_t offset_m                    = MEMORY_ALIGN(offset_declaredAnnotations  + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1447
1448 public:
1449         java_lang_reflect_VMMethod(java_handle_t* h) : java_lang_Object(h) {}
1450         java_lang_reflect_VMMethod(methodinfo* m);
1451
1452         // Getters.
1453         classinfo*               get_clazz               () const;
1454         int32_t                  get_slot                () const;
1455         java_handle_bytearray_t* get_annotations         () const;
1456         java_handle_bytearray_t* get_parameterAnnotations() const;
1457         java_handle_bytearray_t* get_annotationDefault   () const;
1458         java_handle_t*           get_declaredAnnotations () const;
1459         java_handle_t*           get_m                   () const;
1460
1461         // Setters.
1462         void set_clazz               (classinfo* value);
1463         void set_name                (java_handle_t* value);
1464         void set_slot                (int32_t value);
1465         void set_annotations         (java_handle_bytearray_t* value);
1466         void set_parameterAnnotations(java_handle_bytearray_t* value);
1467         void set_annotationDefault   (java_handle_bytearray_t* value);
1468         void set_declaredAnnotations (java_handle_t* value);
1469         void set_m                   (java_handle_t* value);
1470
1471         // Convenience functions.
1472         methodinfo* get_method() const;
1473 };
1474
1475
1476 inline java_lang_reflect_VMMethod::java_lang_reflect_VMMethod(methodinfo* m)
1477 {
1478         _handle = builtin_new(class_java_lang_reflect_VMMethod);
1479
1480         if (is_null())
1481                 return;
1482
1483         java_handle_t*           name                 = javastring_intern(javastring_new(m->name));
1484         int                      slot                 = m - m->clazz->methods;
1485         java_handle_bytearray_t* annotations          = method_get_annotations(m);
1486         java_handle_bytearray_t* parameterAnnotations = method_get_parameterannotations(m);
1487         java_handle_bytearray_t* annotationDefault    = method_get_annotationdefault(m);
1488
1489         set_clazz(m->clazz);
1490         set_name(name);
1491         set_slot(slot);
1492         set_annotations(annotations);
1493         set_parameterAnnotations(parameterAnnotations);
1494         set_annotationDefault(annotationDefault);
1495 }
1496
1497 inline classinfo* java_lang_reflect_VMMethod::get_clazz() const
1498 {
1499         return get<classinfo*>(_handle, offset_clazz);
1500 }
1501
1502 inline int32_t java_lang_reflect_VMMethod::get_slot() const
1503 {
1504         return get<int32_t>(_handle, offset_slot);
1505 }
1506
1507 inline java_handle_bytearray_t* java_lang_reflect_VMMethod::get_annotations() const
1508 {
1509         return get<java_handle_bytearray_t*>(_handle, offset_annotations);
1510 }
1511
1512 inline java_handle_bytearray_t* java_lang_reflect_VMMethod::get_parameterAnnotations() const
1513 {
1514         return get<java_handle_bytearray_t*>(_handle, offset_parameterAnnotations);
1515 }
1516
1517 inline java_handle_bytearray_t* java_lang_reflect_VMMethod::get_annotationDefault() const
1518 {
1519         return get<java_handle_bytearray_t*>(_handle, offset_annotationDefault);
1520 }
1521
1522 inline java_handle_t* java_lang_reflect_VMMethod::get_declaredAnnotations() const
1523 {
1524         return get<java_handle_t*>(_handle, offset_declaredAnnotations);
1525 }
1526
1527 inline java_handle_t* java_lang_reflect_VMMethod::get_m() const
1528 {
1529         return get<java_handle_t*>(_handle, offset_m);
1530 }
1531
1532 inline void java_lang_reflect_VMMethod::set_clazz(classinfo* value)
1533 {
1534         set(_handle, offset_clazz, value);
1535 }
1536
1537 inline void java_lang_reflect_VMMethod::set_name(java_handle_t* value)
1538 {
1539         set(_handle, offset_name, value);
1540 }
1541
1542 inline void java_lang_reflect_VMMethod::set_slot(int32_t value)
1543 {
1544         set(_handle, offset_slot, value);
1545 }
1546
1547 inline void java_lang_reflect_VMMethod::set_annotations(java_handle_bytearray_t* value)
1548 {
1549         set(_handle, offset_annotations, value);
1550 }
1551
1552 inline void java_lang_reflect_VMMethod::set_parameterAnnotations(java_handle_bytearray_t* value)
1553 {
1554         set(_handle, offset_parameterAnnotations, value);
1555 }
1556
1557 inline void java_lang_reflect_VMMethod::set_annotationDefault(java_handle_bytearray_t* value)
1558 {
1559         set(_handle, offset_annotationDefault, value);
1560 }
1561
1562 inline void java_lang_reflect_VMMethod::set_declaredAnnotations(java_handle_t* value)
1563 {
1564         set(_handle, offset_declaredAnnotations, value);
1565 }
1566
1567 inline void java_lang_reflect_VMMethod::set_m(java_handle_t* value)
1568 {
1569         set(_handle, offset_m, value);
1570 }
1571
1572 inline methodinfo* java_lang_reflect_VMMethod::get_method() const
1573 {
1574         classinfo*  c    = get_clazz();
1575         int32_t     slot = get_slot();
1576         methodinfo* m    = &(c->methods[slot]);
1577         return m;
1578 }
1579
1580
1581 /**
1582  * GNU Classpath java/lang/reflect/Method
1583  *
1584  * Object layout:
1585  *
1586  * 0. object header
1587  * 1. boolean                                     flag;
1588  * 2. gnu.java.lang.reflect.MethodSignatureParser p;
1589  * 3. java.lang.reflect.VMMethod                  m;
1590  */
1591 class java_lang_reflect_Method : public java_lang_Object, private FieldAccess {
1592 private:
1593         // Static offsets of the object's instance fields.
1594         // TODO These offsets need to be checked on VM startup.
1595         static const off_t offset_flag = MEMORY_ALIGN(sizeof(java_object_t),         sizeof(int32_t));
1596         static const off_t offset_p    = MEMORY_ALIGN(offset_flag + sizeof(int32_t), SIZEOF_VOID_P);
1597         static const off_t offset_m    = MEMORY_ALIGN(offset_p    + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1598
1599 public:
1600         java_lang_reflect_Method(java_handle_t* h) : java_lang_Object(h) {}
1601         java_lang_reflect_Method(methodinfo* m);
1602
1603         java_handle_t* invoke(java_handle_t* o, java_handle_objectarray_t* args);
1604
1605         // Getters.
1606         int32_t        get_flag() const;
1607         java_handle_t* get_m() const;
1608
1609         // Setters.
1610         void set_m(java_handle_t* value);
1611
1612         // Convenience functions.
1613         methodinfo* get_method  () const;
1614         int32_t     get_override() const;
1615 };
1616
1617
1618 inline java_lang_reflect_Method::java_lang_reflect_Method(methodinfo* m)
1619 {
1620         java_lang_reflect_VMMethod jlrvmm(m);
1621
1622         if (jlrvmm.is_null())
1623                 return;
1624
1625         _handle = builtin_new(class_java_lang_reflect_Method);
1626
1627         if (is_null())
1628                 return;
1629
1630         // Link the two Java objects.
1631         set_m(jlrvmm.get_handle());
1632         jlrvmm.set_m(get_handle());
1633 }
1634
1635
1636 inline int32_t java_lang_reflect_Method::get_flag() const
1637 {
1638         return get<int32_t>(_handle, offset_flag);
1639 }
1640
1641 inline java_handle_t* java_lang_reflect_Method::get_m() const
1642 {
1643         return get<java_handle_t*>(_handle, offset_m);
1644 }
1645
1646
1647 inline void java_lang_reflect_Method::set_m(java_handle_t* value)
1648 {
1649         set(_handle, offset_m, value);
1650 }
1651
1652
1653 inline methodinfo* java_lang_reflect_Method::get_method() const
1654 {
1655         java_lang_reflect_VMMethod jlrvmm(get_m());
1656         return jlrvmm.get_method();
1657 }
1658
1659 inline int32_t java_lang_reflect_Method::get_override() const
1660 {
1661         return get_flag();
1662 }
1663
1664
1665 /**
1666  * GNU Classpath java/nio/Buffer
1667  *
1668  * Object layout:
1669  *
1670  * 0. object header
1671  * 1. int                   cap;
1672  * 2. int                   limit;
1673  * 3. int                   pos;
1674  * 4. int                   mark;
1675  * 5. gnu.classpath.Pointer address;
1676  */
1677 class java_nio_Buffer : public java_lang_Object, private FieldAccess {
1678 private:
1679         // Static offsets of the object's instance fields.
1680         // TODO These offsets need to be checked on VM startup.
1681         static const off_t offset_cap     = MEMORY_ALIGN(sizeof(java_object_t),          sizeof(int32_t));
1682         static const off_t offset_limit   = MEMORY_ALIGN(offset_cap   + sizeof(int32_t), sizeof(int32_t));
1683         static const off_t offset_pos     = MEMORY_ALIGN(offset_limit + sizeof(int32_t), sizeof(int32_t));
1684         static const off_t offset_mark    = MEMORY_ALIGN(offset_pos   + sizeof(int32_t), sizeof(int32_t));
1685         static const off_t offset_address = MEMORY_ALIGN(offset_mark  + sizeof(int32_t), SIZEOF_VOID_P);
1686
1687 public:
1688         java_nio_Buffer(java_handle_t* h) : java_lang_Object(h) {}
1689
1690         // Getters.
1691         int32_t get_cap() const;
1692 };
1693
1694 inline int32_t java_nio_Buffer::get_cap() const
1695 {
1696         return get<int32_t>(_handle, offset_cap);
1697 }
1698
1699
1700 /**
1701  * GNU Classpath java/nio/DirectByteBufferImpl
1702  *
1703  * Object layout:
1704  *
1705  * 0. object header
1706  * 1. int                   cap;
1707  * 2. int                   limit;
1708  * 3. int                   pos;
1709  * 4. int                   mark;
1710  * 5. gnu.classpath.Pointer address;
1711  * 6. java.nio.ByteOrder    endian;
1712  * 7. byte[]                backing_buffer;
1713  * 8. int                   array_offset;
1714  * 9. java.lang.Object      owner;
1715  */
1716 class java_nio_DirectByteBufferImpl : public java_lang_Object, private FieldAccess {
1717 private:
1718         // Static offsets of the object's instance fields.
1719         // TODO These offsets need to be checked on VM startup.
1720         static const off_t offset_cap            = MEMORY_ALIGN(sizeof(java_object_t),                   sizeof(int32_t));
1721         static const off_t offset_limit          = MEMORY_ALIGN(offset_cap            + sizeof(int32_t), sizeof(int32_t));
1722         static const off_t offset_pos            = MEMORY_ALIGN(offset_limit          + sizeof(int32_t), sizeof(int32_t));
1723         static const off_t offset_mark           = MEMORY_ALIGN(offset_pos            + sizeof(int32_t), sizeof(int32_t));
1724         static const off_t offset_address        = MEMORY_ALIGN(offset_mark           + sizeof(int32_t), SIZEOF_VOID_P);
1725         static const off_t offset_endian         = MEMORY_ALIGN(offset_address        + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1726         static const off_t offset_backing_buffer = MEMORY_ALIGN(offset_endian         + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1727         static const off_t offset_array_offset   = MEMORY_ALIGN(offset_backing_buffer + SIZEOF_VOID_P,   sizeof(int32_t));
1728         static const off_t offset_owner          = MEMORY_ALIGN(offset_array_offset   + sizeof(int32_t), SIZEOF_VOID_P);
1729
1730 public:
1731         java_nio_DirectByteBufferImpl(java_handle_t* h) : java_lang_Object(h) {}
1732
1733         // Getters.
1734         java_handle_t* get_address() const;
1735 };
1736
1737
1738 inline java_handle_t* java_nio_DirectByteBufferImpl::get_address() const
1739 {
1740         return get<java_handle_t*>(_handle, offset_address);
1741 }
1742
1743
1744 /**
1745  * GNU Classpath gnu/classpath/Pointer
1746  *
1747  * Actually there are two classes, gnu.classpath.Pointer32 and
1748  * gnu.classpath.Pointer64, but we only define the abstract super
1749  * class and use the int/long field as void* type.
1750  *
1751  * Object layout:
1752  *
1753  * 0. object header
1754  * 1. int/long data;
1755  */
1756 class gnu_classpath_Pointer : public java_lang_Object, private FieldAccess {
1757 private:
1758         // Static offsets of the object's instance fields.
1759         // TODO These offsets need to be checked on VM startup.
1760         static const off_t offset_data = MEMORY_ALIGN(sizeof(java_object_t), SIZEOF_VOID_P);
1761
1762 public:
1763         gnu_classpath_Pointer(java_handle_t* h) : java_lang_Object(h) {}
1764         gnu_classpath_Pointer(java_handle_t* h, void* data);
1765
1766         // Getters.
1767         void* get_data() const;
1768
1769         // Setters.
1770         void set_data(void* value);
1771 };
1772
1773 inline gnu_classpath_Pointer::gnu_classpath_Pointer(java_handle_t* h, void* data) : java_lang_Object(h)
1774 {
1775         set_data(data);
1776 }
1777
1778 inline void* gnu_classpath_Pointer::get_data() const
1779 {
1780         return get<void*>(_handle, offset_data);
1781 }
1782
1783 inline void gnu_classpath_Pointer::set_data(void* value)
1784 {
1785         set(_handle, offset_data, value);
1786 }
1787
1788 #endif // WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH
1789
1790
1791 #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1792
1793 /**
1794  * OpenJDK java/lang/AssertionStatusDirectives
1795  *
1796  * Object layout:
1797  *
1798  * 0. object header
1799  * 1. java.lang.String[] classes;
1800  * 2. boolean[]          classEnabled;
1801  * 3. java.lang.String[] packages;
1802  * 4. boolean[]          packageEnabled;
1803  * 5. boolean            deflt;
1804  */
1805 class java_lang_AssertionStatusDirectives : public java_lang_Object, private FieldAccess {
1806 private:
1807         // Static offsets of the object's instance fields.
1808         // TODO These offsets need to be checked on VM startup.
1809         static const off_t offset_classes        = MEMORY_ALIGN(sizeof(java_object_t),                 SIZEOF_VOID_P);
1810         static const off_t offset_classEnabled   = MEMORY_ALIGN(offset_classes        + SIZEOF_VOID_P, SIZEOF_VOID_P);
1811         static const off_t offset_packages       = MEMORY_ALIGN(offset_classEnabled   + SIZEOF_VOID_P, SIZEOF_VOID_P);
1812         static const off_t offset_packageEnabled = MEMORY_ALIGN(offset_packages       + SIZEOF_VOID_P, SIZEOF_VOID_P);
1813         static const off_t offset_deflt          = MEMORY_ALIGN(offset_packageEnabled + SIZEOF_VOID_P, sizeof(int32_t));
1814
1815 public:
1816         java_lang_AssertionStatusDirectives(java_handle_objectarray_t* classes, java_handle_booleanarray_t* classEnabled, java_handle_objectarray_t* packages, java_handle_booleanarray_t* packageEnabled);
1817 };
1818
1819 inline java_lang_AssertionStatusDirectives::java_lang_AssertionStatusDirectives(java_handle_objectarray_t* classes, java_handle_booleanarray_t* classEnabled, java_handle_objectarray_t* packages, java_handle_booleanarray_t* packageEnabled)
1820 {
1821         classinfo* c = load_class_bootstrap(utf_new_char("java/lang/AssertionStatusDirectives"));
1822
1823         // FIXME Load the class at VM startup.
1824         if (c == NULL)
1825                 return;
1826
1827         _handle = builtin_new(c);
1828
1829         if (is_null())
1830                 return;
1831
1832         set(_handle, offset_classes,        classes);
1833         set(_handle, offset_classEnabled,   classEnabled);
1834         set(_handle, offset_packages,       packages);
1835         set(_handle, offset_packageEnabled, packageEnabled);
1836 }
1837
1838
1839 /**
1840  * OpenJDK java/lang/ClassLoader
1841  *
1842  * Object layout:
1843  *
1844  * 0. object header
1845  * 1. boolean               initialized
1846  * 2. java.lang.ClassLoader parent
1847  * [other fields are not used]
1848  */
1849 class java_lang_ClassLoader : public java_lang_Object, private FieldAccess {
1850 private:
1851         // Static offsets of the object's instance fields.
1852         // TODO These offsets need to be checked on VM startup.
1853         static const off_t offset_initialized = MEMORY_ALIGN(sizeof(java_object_t),                sizeof(int32_t));
1854         static const off_t offset_parent      = MEMORY_ALIGN(offset_initialized + sizeof(int32_t), SIZEOF_VOID_P);
1855
1856 public:
1857         java_lang_ClassLoader(java_handle_t* h) : java_lang_Object(h) {}
1858
1859         // Getters.
1860         java_handle_t* get_parent() const;
1861
1862         // Invocation wrappers for static methods.
1863         static java_handle_t* invoke_getSystemClassLoader();
1864 };
1865
1866 inline java_handle_t* java_lang_ClassLoader::get_parent() const
1867 {
1868         return get<java_handle_t*>(_handle, offset_parent);
1869 }
1870
1871
1872 /**
1873  * OpenJDK java/lang/StackTraceElement
1874  *
1875  * Object layout:
1876  *
1877  * 0. object header
1878  * 1. java.lang.String declaringClass;
1879  * 2. java.lang.String methodName;
1880  * 3. java.lang.String fileName;
1881  * 4. int              lineNumber;
1882  */
1883 class java_lang_StackTraceElement : public java_lang_Object, private FieldAccess {
1884 private:
1885         // Static offsets of the object's instance fields.
1886         // TODO These offsets need to be checked on VM startup.
1887         static const off_t offset_declaringClass = MEMORY_ALIGN(sizeof(java_object_t),                 SIZEOF_VOID_P);
1888         static const off_t offset_methodName     = MEMORY_ALIGN(offset_declaringClass + SIZEOF_VOID_P, SIZEOF_VOID_P);
1889         static const off_t offset_fileName       = MEMORY_ALIGN(offset_methodName     + SIZEOF_VOID_P, SIZEOF_VOID_P);
1890         static const off_t offset_lineNumber     = MEMORY_ALIGN(offset_fileName       + SIZEOF_VOID_P, sizeof(int32_t));
1891
1892 public:
1893         java_lang_StackTraceElement(java_handle_t* h) : java_lang_Object(h) {}
1894         java_lang_StackTraceElement(java_handle_t* declaringClass, java_handle_t* methodName, java_handle_t* fileName, int32_t lineNumber);
1895 };
1896
1897 inline java_lang_StackTraceElement::java_lang_StackTraceElement(java_handle_t* declaringClass, java_handle_t* methodName, java_handle_t* fileName, int32_t lineNumber)
1898 {
1899         _handle = builtin_new(class_java_lang_StackTraceElement);
1900
1901         if (is_null())
1902                 return;
1903
1904         set(_handle, offset_declaringClass, declaringClass);
1905         set(_handle, offset_methodName,     methodName);
1906         set(_handle, offset_fileName,       fileName);
1907         set(_handle, offset_lineNumber,     lineNumber);
1908 }
1909
1910
1911 /**
1912  * OpenJDK java/lang/String
1913  *
1914  * Object layout:
1915  *
1916  * 0. object header
1917  * 1. char[] value;
1918  * 2. int    offset;
1919  * 3. int    count;
1920  * 4. int    hash;
1921  */
1922 class java_lang_String : public java_lang_Object, private FieldAccess {
1923 private:
1924         // Static offsets of the object's instance fields.
1925         // TODO These offsets need to be checked on VM startup.
1926         static const off_t offset_value  = MEMORY_ALIGN(sizeof(java_object_t),           SIZEOF_VOID_P);
1927         static const off_t offset_offset = MEMORY_ALIGN(offset_value  + SIZEOF_VOID_P,   sizeof(int32_t));
1928         static const off_t offset_count  = MEMORY_ALIGN(offset_offset + sizeof(int32_t), sizeof(int32_t));
1929         static const off_t offset_hash   = MEMORY_ALIGN(offset_count  + sizeof(int32_t), sizeof(int32_t));
1930
1931 public:
1932         java_lang_String(java_handle_t* h) : java_lang_Object(h) {}
1933         java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset = 0);
1934
1935         // Getters.
1936         java_handle_chararray_t* get_value () const;
1937         int32_t                  get_offset() const;
1938         int32_t                  get_count () const;
1939
1940         // Setters.
1941         void set_value (java_handle_chararray_t* value);
1942         void set_offset(int32_t value);
1943         void set_count (int32_t value);
1944 };
1945
1946 inline java_lang_String::java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset) : java_lang_Object(h)
1947 {
1948         set_value(value);
1949         set_offset(offset);
1950         set_count(count);
1951 }
1952
1953 inline java_handle_chararray_t* java_lang_String::get_value() const
1954 {
1955         return get<java_handle_chararray_t*>(_handle, offset_value);
1956 }
1957
1958 inline int32_t java_lang_String::get_offset() const
1959 {
1960         return get<int32_t>(_handle, offset_offset);
1961 }
1962
1963 inline int32_t java_lang_String::get_count() const
1964 {
1965         return get<int32_t>(_handle, offset_count);
1966 }
1967
1968 inline void java_lang_String::set_value(java_handle_chararray_t* value)
1969 {
1970         set(_handle, offset_value, value);
1971 }
1972
1973 inline void java_lang_String::set_offset(int32_t value)
1974 {
1975         set(_handle, offset_offset, value);
1976 }
1977
1978 inline void java_lang_String::set_count(int32_t value)
1979 {
1980         set(_handle, offset_count, value);
1981 }
1982
1983
1984 /**
1985  * OpenJDK java/lang/Thread
1986  *
1987  * Object layout:
1988  *
1989  * 0.  object header
1990  * 1.  char[]                                    name;
1991  * 2.  int                                       priority;
1992  * 3.  java_lang_Thread                          threadQ;
1993  * 4.  long                                      eetop;
1994  * 5.  boolean                                   single_step;
1995  * 6.  boolean                                   daemon;
1996  * 7.  boolean                                   stillborn;
1997  * 8.  java_lang_Runnable                        target;
1998  * 9.  java_lang_ThreadGroup                     group;
1999  * 10. java_lang_ClassLoader                     contextClassLoader;
2000  * 11. java_security_AccessControlContext        inheritedAccessControlContext;
2001  * 12. java_lang_ThreadLocal_ThreadLocalMap      threadLocals;
2002  * 13. java_lang_ThreadLocal_ThreadLocalMap      inheritableThreadLocals;
2003  * 14. long                                      stackSize;
2004  * 15. long                                      nativeParkEventPointer;
2005  * 16. long                                      tid;
2006  * 17. int                                       threadStatus;
2007  * 18. java_lang_Object                          parkBlocker;
2008  * 19. sun_nio_ch_Interruptible                  blocker;
2009  * 20. java_lang_Object                          blockerLock;
2010  * 21. boolean                                   stopBeforeStart;
2011  * 22. java_lang_Throwable                       throwableFromStop;
2012  * 23. java.lang.Thread.UncaughtExceptionHandler uncaughtExceptionHandler;
2013  */
2014 class java_lang_Thread : public java_lang_Object, private FieldAccess {
2015 private:
2016         // Static offsets of the object's instance fields.
2017         // TODO These offsets need to be checked on VM startup.
2018         static const off_t offset_name                          = MEMORY_ALIGN(sizeof(java_object_t),                                  SIZEOF_VOID_P);
2019         static const off_t offset_priority                      = MEMORY_ALIGN(offset_name                          + SIZEOF_VOID_P,   sizeof(int32_t));
2020         static const off_t offset_threadQ                       = MEMORY_ALIGN(offset_priority                      + sizeof(int32_t), SIZEOF_VOID_P);
2021         static const off_t offset_eetop                         = MEMORY_ALIGN(offset_threadQ                       + SIZEOF_VOID_P,   sizeof(int64_t));
2022         static const off_t offset_single_step                   = MEMORY_ALIGN(offset_eetop                         + sizeof(int64_t), sizeof(int32_t));
2023         static const off_t offset_daemon                        = MEMORY_ALIGN(offset_single_step                   + sizeof(int32_t), sizeof(int32_t));
2024         static const off_t offset_stillborn                     = MEMORY_ALIGN(offset_daemon                        + sizeof(int32_t), sizeof(int32_t));
2025         static const off_t offset_target                        = MEMORY_ALIGN(offset_stillborn                     + sizeof(int32_t), SIZEOF_VOID_P);
2026         static const off_t offset_group                         = MEMORY_ALIGN(offset_target                        + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2027         static const off_t offset_contextClassLoader            = MEMORY_ALIGN(offset_group                         + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2028         static const off_t offset_inheritedAccessControlContext = MEMORY_ALIGN(offset_contextClassLoader            + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2029         static const off_t offset_threadLocals                  = MEMORY_ALIGN(offset_inheritedAccessControlContext + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2030         static const off_t offset_inheritableThreadLocals       = MEMORY_ALIGN(offset_threadLocals                  + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2031         static const off_t offset_stackSize                     = MEMORY_ALIGN(offset_inheritableThreadLocals       + SIZEOF_VOID_P,   sizeof(int64_t));
2032         static const off_t offset_nativeParkEventPointer        = MEMORY_ALIGN(offset_stackSize                     + sizeof(int64_t), sizeof(int64_t));
2033         static const off_t offset_tid                           = MEMORY_ALIGN(offset_nativeParkEventPointer        + sizeof(int64_t), sizeof(int64_t));
2034         static const off_t offset_threadStatus                  = MEMORY_ALIGN(offset_tid                           + sizeof(int64_t), sizeof(int32_t));
2035         static const off_t offset_parkBlocker                   = MEMORY_ALIGN(offset_threadStatus                  + sizeof(int32_t), SIZEOF_VOID_P);
2036         static const off_t offset_blocker                       = MEMORY_ALIGN(offset_parkBlocker                   + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2037         static const off_t offset_blockerLock                   = MEMORY_ALIGN(offset_blocker                       + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2038         static const off_t offset_stopBeforeStart               = MEMORY_ALIGN(offset_blockerLock                   + SIZEOF_VOID_P,   sizeof(int32_t));
2039         static const off_t offset_throwableFromStop             = MEMORY_ALIGN(offset_stopBeforeStart               + sizeof(int32_t), SIZEOF_VOID_P);
2040         static const off_t offset_uncaughtExceptionHandler      = MEMORY_ALIGN(offset_throwableFromStop             + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2041
2042 public:
2043         java_lang_Thread(java_handle_t* h) : java_lang_Object(h) {}
2044 //      java_lang_Thread(threadobject* t);
2045
2046         // Getters.
2047         int32_t        get_priority                () const;
2048         int32_t        get_daemon                  () const;
2049         java_handle_t* get_group                   () const;
2050         java_handle_t* get_uncaughtExceptionHandler() const;
2051
2052         // Setters.
2053         void set_priority    (int32_t value);
2054         void set_group       (java_handle_t* value);
2055         void set_threadStatus(int32_t value);
2056 };
2057
2058
2059 inline int32_t java_lang_Thread::get_priority() const
2060 {
2061         return get<int32_t>(_handle, offset_priority);
2062 }
2063
2064 inline int32_t java_lang_Thread::get_daemon() const
2065 {
2066         return get<int32_t>(_handle, offset_daemon);
2067 }
2068
2069 inline java_handle_t* java_lang_Thread::get_group() const
2070 {
2071         return get<java_handle_t*>(_handle, offset_group);
2072 }
2073
2074 inline java_handle_t* java_lang_Thread::get_uncaughtExceptionHandler() const
2075 {
2076         return get<java_handle_t*>(_handle, offset_uncaughtExceptionHandler);
2077 }
2078
2079
2080 inline void java_lang_Thread::set_priority(int32_t value)
2081 {
2082         set(_handle, offset_priority, value);
2083 }
2084
2085 inline void java_lang_Thread::set_group(java_handle_t* value)
2086 {
2087         set(_handle, offset_group, value);
2088 }
2089
2090 inline void java_lang_Thread::set_threadStatus(int32_t value)
2091 {
2092         set(_handle, offset_threadStatus, value);
2093 }
2094
2095
2096
2097 /**
2098  * OpenJDK java/lang/Throwable
2099  *
2100  * Object layout:
2101  *
2102  * 0. object header
2103  * 1. java.lang.Object              backtrace;
2104  * 2. java.lang.String              detailMessage;
2105  * 3. java.lang.Throwable           cause;
2106  * 4. java.lang.StackTraceElement[] stackTrace;
2107  */
2108 class java_lang_Throwable : public java_lang_Object, private FieldAccess {
2109 private:
2110         // Static offsets of the object's instance fields.
2111         // TODO These offsets need to be checked on VM startup.
2112         static const off_t offset_backtrace     = MEMORY_ALIGN(sizeof(java_object_t),                SIZEOF_VOID_P);
2113         static const off_t offset_detailMessage = MEMORY_ALIGN(offset_backtrace     + SIZEOF_VOID_P, SIZEOF_VOID_P);
2114         static const off_t offset_cause         = MEMORY_ALIGN(offset_detailMessage + SIZEOF_VOID_P, SIZEOF_VOID_P);
2115         static const off_t offset_stackTrace    = MEMORY_ALIGN(offset_cause         + SIZEOF_VOID_P, SIZEOF_VOID_P);
2116
2117 public:
2118         java_lang_Throwable(java_handle_t* h) : java_lang_Object(h) {}
2119         java_lang_Throwable(java_handle_t* h, java_handle_bytearray_t* backtrace);
2120
2121         // Getters.
2122         java_handle_bytearray_t* get_backtrace    () const;
2123         java_handle_t*           get_detailMessage() const;
2124         java_handle_t*           get_cause        () const;
2125
2126         // Setters.
2127         void set_backtrace(java_handle_bytearray_t* value);
2128 };
2129
2130
2131 inline java_lang_Throwable::java_lang_Throwable(java_handle_t* h, java_handle_bytearray_t* backtrace) : java_lang_Object(h)
2132 {
2133         set_backtrace(backtrace);
2134 }
2135
2136
2137 inline java_handle_bytearray_t* java_lang_Throwable::get_backtrace() const
2138 {
2139         return get<java_handle_bytearray_t*>(_handle, offset_backtrace);
2140 }
2141
2142 inline java_handle_t* java_lang_Throwable::get_detailMessage() const
2143 {
2144         return get<java_handle_t*>(_handle, offset_detailMessage);
2145 }
2146
2147 inline java_handle_t* java_lang_Throwable::get_cause() const
2148 {
2149         return get<java_handle_t*>(_handle, offset_cause);
2150 }
2151
2152
2153 inline void java_lang_Throwable::set_backtrace(java_handle_bytearray_t* value)
2154 {
2155         set(_handle, offset_backtrace, value);
2156 }
2157
2158
2159 /**
2160  * OpenJDK java/lang/reflect/Constructor
2161  *
2162  * Object layout:
2163  *
2164  * 0.  object header
2165  * 1.  boolean                                               override;
2166  * 2.  java.lang.Class                                       clazz;
2167  * 3.  int                                                   slot;
2168  * 4.  java.lang.Class[]                                     parameterTypes;
2169  * 5.  java.lang.Class[]                                     exceptionTypes;
2170  * 6.  int                                                   modifiers;
2171  * 7.  java.lang.String                                      signature;
2172  * 8.  sun.reflect.generics.repository.ConstructorRepository genericInfo;
2173  * 9.  byte[]                                                annotations;
2174  * 10. byte[]                                                parameterAnnotations;
2175  * 11. java.lang.Class                                       securityCheckCache;
2176  * 12. sun.reflect.ConstructorAccessor                       constructorAccessor;
2177  * 13. java.lang.reflect.Constructor                         root;
2178  * 14. java.util.Map                                         declaredAnnotations;
2179  */
2180 class java_lang_reflect_Constructor : public java_lang_Object, private FieldAccess {
2181 private:
2182         // Static offsets of the object's instance fields.
2183         // TODO These offsets need to be checked on VM startup.
2184         static const off_t offset_override             = MEMORY_ALIGN(sizeof(java_object_t),                         sizeof(int32_t));
2185         static const off_t offset_clazz                = MEMORY_ALIGN(offset_override             + sizeof(int32_t), SIZEOF_VOID_P);
2186         static const off_t offset_slot                 = MEMORY_ALIGN(offset_clazz                + SIZEOF_VOID_P,   sizeof(int32_t));
2187         static const off_t offset_parameterTypes       = MEMORY_ALIGN(offset_slot                 + sizeof(int32_t), SIZEOF_VOID_P);
2188         static const off_t offset_exceptionTypes       = MEMORY_ALIGN(offset_parameterTypes       + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2189         static const off_t offset_modifiers            = MEMORY_ALIGN(offset_exceptionTypes       + SIZEOF_VOID_P,   sizeof(int32_t));
2190         static const off_t offset_signature            = MEMORY_ALIGN(offset_modifiers            + sizeof(int32_t), SIZEOF_VOID_P);
2191         static const off_t offset_genericInfo          = MEMORY_ALIGN(offset_signature            + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2192         static const off_t offset_annotations          = MEMORY_ALIGN(offset_genericInfo          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2193         static const off_t offset_parameterAnnotations = MEMORY_ALIGN(offset_annotations          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2194         static const off_t offset_securityCheckCache   = MEMORY_ALIGN(offset_parameterAnnotations + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2195         static const off_t offset_constructorAccessor  = MEMORY_ALIGN(offset_securityCheckCache   + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2196         static const off_t offset_root                 = MEMORY_ALIGN(offset_constructorAccessor  + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2197         static const off_t offset_declaredAnnotations  = MEMORY_ALIGN(offset_root                 + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2198
2199 public:
2200         java_lang_reflect_Constructor(java_handle_t* h) : java_lang_Object(h) {}
2201         java_lang_reflect_Constructor(methodinfo* m);
2202
2203         java_handle_t* new_instance(java_handle_objectarray_t* args);
2204
2205         // Getters.
2206         int32_t                  get_override   () const;
2207         classinfo*               get_clazz      () const;
2208         int32_t                  get_slot       () const;
2209         java_handle_bytearray_t* get_annotations() const;
2210
2211         // Setters.
2212         void set_clazz               (classinfo* value);
2213         void set_slot                (int32_t value);
2214         void set_parameterTypes      (java_handle_objectarray_t* value);
2215         void set_exceptionTypes      (java_handle_objectarray_t* value);
2216         void set_modifiers           (int32_t value);
2217         void set_signature           (java_handle_t* value);
2218         void set_annotations         (java_handle_bytearray_t* value);
2219         void set_parameterAnnotations(java_handle_bytearray_t* value);
2220
2221         // Convenience functions.
2222         methodinfo* get_method();
2223 };
2224
2225
2226 inline java_lang_reflect_Constructor::java_lang_reflect_Constructor(methodinfo* m)
2227 {
2228         _handle = builtin_new(class_java_lang_reflect_Constructor);
2229
2230         if (is_null())
2231                 return;
2232
2233         int                        slot                 = m - m->clazz->methods;
2234         java_handle_objectarray_t* parameterTypes       = method_get_parametertypearray(m);
2235         java_handle_objectarray_t* exceptionTypes       = method_get_exceptionarray(m);
2236         java_handle_bytearray_t*   annotations          = method_get_annotations(m);
2237         java_handle_bytearray_t*   parameterAnnotations = method_get_parameterannotations(m);
2238
2239         set_clazz(m->clazz);
2240         set_slot(slot);
2241         set_parameterTypes(parameterTypes);
2242         set_exceptionTypes(exceptionTypes);
2243         set_modifiers(m->flags & ACC_CLASS_REFLECT_MASK);
2244         set_signature(m->signature ? javastring_new(m->signature) : NULL);
2245         set_annotations(annotations);
2246         set_parameterAnnotations(parameterAnnotations);
2247 }
2248
2249
2250 inline int32_t java_lang_reflect_Constructor::get_override() const
2251 {
2252         return get<int32_t>(_handle, offset_override);
2253 }
2254
2255 inline classinfo* java_lang_reflect_Constructor::get_clazz() const
2256 {
2257         return get<classinfo*>(_handle, offset_clazz);
2258 }
2259
2260 inline int32_t java_lang_reflect_Constructor::get_slot() const
2261 {
2262         return get<int32_t>(_handle, offset_slot);
2263 }
2264
2265 inline java_handle_bytearray_t* java_lang_reflect_Constructor::get_annotations() const
2266 {
2267         return get<java_handle_bytearray_t*>(_handle, offset_annotations);
2268 }
2269
2270
2271 inline void java_lang_reflect_Constructor::set_clazz(classinfo* value)
2272 {
2273         set(_handle, offset_clazz, value);
2274 }
2275
2276 inline void java_lang_reflect_Constructor::set_slot(int32_t value)
2277 {
2278         set(_handle, offset_slot, value);
2279 }
2280
2281 inline void java_lang_reflect_Constructor::set_parameterTypes(java_handle_objectarray_t* value)
2282 {
2283         set(_handle, offset_parameterTypes, value);
2284 }
2285
2286 inline void java_lang_reflect_Constructor::set_exceptionTypes(java_handle_objectarray_t* value)
2287 {
2288         set(_handle, offset_exceptionTypes, value);
2289 }
2290
2291 inline void java_lang_reflect_Constructor::set_modifiers(int32_t value)
2292 {
2293         set(_handle, offset_modifiers, value);
2294 }
2295
2296 inline void java_lang_reflect_Constructor::set_signature(java_handle_t* value)
2297 {
2298         set(_handle, offset_signature, value);
2299 }
2300
2301 inline void java_lang_reflect_Constructor::set_annotations(java_handle_bytearray_t* value)
2302 {
2303         set(_handle, offset_annotations, value);
2304 }
2305
2306 inline void java_lang_reflect_Constructor::set_parameterAnnotations(java_handle_bytearray_t* value)
2307 {
2308         set(_handle, offset_parameterAnnotations, value);
2309 }
2310
2311
2312 inline methodinfo* java_lang_reflect_Constructor::get_method()
2313 {
2314         classinfo*  c    = get_clazz();
2315         int32_t     slot = get_slot();
2316         methodinfo* m    = &(c->methods[slot]);
2317         return m;
2318 }
2319
2320
2321 /**
2322  * OpenJDK java/lang/reflect/Field
2323  *
2324  * Object layout:
2325  *
2326  * 0.  object header
2327  * 1.  boolean                                         override;
2328  * 2.  java.lang.Class                                 clazz;
2329  * 3.  int                                             slot;
2330  * 4.  java.lang.String                                name;
2331  * 5.  java.lang.Class                                 type;
2332  * 6.  int                                             modifiers;
2333  * 7.  java.lang.String                                signature;
2334  * 8.  sun.reflect.generics.repository.FieldRepository genericInfo;
2335  * 9.  byte[]                                          annotations;
2336  * 10. sun.reflect.FieldAccessor                       fieldAccessor;
2337  * 11. sun.reflect.FieldAccessor                       overrideFieldAccessor;
2338  * 12. java.lang.reflect.Field                         root;
2339  * 13. java.lang.Class                                 securityCheckCache;
2340  * 14. java.lang.Class                                 securityCheckTargetClassCache;
2341  * 15. java.util.Map                                   declaredAnnotations;
2342  */
2343 class java_lang_reflect_Field : public java_lang_Object, private FieldAccess {
2344 private:
2345         // Static offsets of the object's instance fields.
2346         // TODO These offsets need to be checked on VM startup.
2347         static const off_t offset_override                      = MEMORY_ALIGN(sizeof(java_object_t),                                  sizeof(int32_t));
2348         static const off_t offset_clazz                         = MEMORY_ALIGN(offset_override                      + sizeof(int32_t), SIZEOF_VOID_P);
2349         static const off_t offset_slot                          = MEMORY_ALIGN(offset_clazz                         + SIZEOF_VOID_P,   sizeof(int32_t));
2350         static const off_t offset_name                          = MEMORY_ALIGN(offset_slot                          + sizeof(int32_t), SIZEOF_VOID_P);
2351         static const off_t offset_type                          = MEMORY_ALIGN(offset_name                          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2352         static const off_t offset_modifiers                     = MEMORY_ALIGN(offset_type                          + SIZEOF_VOID_P,   sizeof(int32_t));
2353         static const off_t offset_signature                     = MEMORY_ALIGN(offset_modifiers                     + sizeof(int32_t), SIZEOF_VOID_P);
2354         static const off_t offset_genericInfo                   = MEMORY_ALIGN(offset_signature                     + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2355         static const off_t offset_annotations                   = MEMORY_ALIGN(offset_genericInfo                   + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2356         static const off_t offset_fieldAccessor                 = MEMORY_ALIGN(offset_annotations                   + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2357         static const off_t offset_overrideFieldAccessor         = MEMORY_ALIGN(offset_fieldAccessor                 + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2358         static const off_t offset_root                          = MEMORY_ALIGN(offset_overrideFieldAccessor         + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2359         static const off_t offset_securityCheckCache            = MEMORY_ALIGN(offset_root                          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2360         static const off_t offset_securityCheckTargetClassCache = MEMORY_ALIGN(offset_securityCheckCache            + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2361         static const off_t offset_declaredAnnotations           = MEMORY_ALIGN(offset_securityCheckTargetClassCache + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2362
2363 public:
2364         java_lang_reflect_Field(java_handle_t* h) : java_lang_Object(h) {}
2365         java_lang_reflect_Field(fieldinfo* f);
2366
2367         // Getters.
2368         int32_t                  get_override   () const;
2369         classinfo*               get_clazz      () const;
2370         int32_t                  get_slot       () const;
2371         java_handle_bytearray_t* get_annotations() const;
2372
2373         // Setters.
2374         void set_clazz      (classinfo* value);
2375         void set_slot       (int32_t value);
2376         void set_name       (java_handle_t* value);
2377         void set_type       (classinfo* value);
2378         void set_modifiers  (int32_t value);
2379         void set_signature  (java_handle_t* value);
2380         void set_annotations(java_handle_bytearray_t* value);
2381
2382         // Convenience functions.
2383         fieldinfo* get_field() const;
2384 };
2385
2386
2387 inline java_lang_reflect_Field::java_lang_reflect_Field(fieldinfo* f)
2388 {
2389         _handle = builtin_new(class_java_lang_reflect_Field);
2390
2391         // OOME.
2392         if (is_null())
2393                 return;
2394
2395         set_clazz(f->clazz);
2396         set_slot(f - f->clazz->fields);
2397         set_name(javastring_intern(javastring_new(f->name)));
2398         set_type(field_get_type(f));
2399         set_modifiers(f->flags);
2400         set_signature(f->signature ? javastring_new(f->signature) : NULL);
2401         set_annotations(field_get_annotations(f));
2402 }
2403
2404
2405 inline int32_t java_lang_reflect_Field::get_override() const
2406 {
2407         return get<int32_t>(_handle, offset_override);
2408 }
2409
2410 inline classinfo* java_lang_reflect_Field::get_clazz() const
2411 {
2412         return get<classinfo*>(_handle, offset_clazz);
2413 }
2414
2415 inline int32_t java_lang_reflect_Field::get_slot() const
2416 {
2417         return get<int32_t>(_handle, offset_slot);
2418 }
2419
2420 inline java_handle_bytearray_t* java_lang_reflect_Field::get_annotations() const
2421 {
2422         return get<java_handle_bytearray_t*>(_handle, offset_annotations);
2423 }
2424
2425
2426 inline void java_lang_reflect_Field::set_clazz(classinfo* value)
2427 {
2428         set(_handle, offset_clazz, value);
2429 }
2430
2431 inline void java_lang_reflect_Field::set_slot(int32_t value)
2432 {
2433         set(_handle, offset_slot, value);
2434 }
2435
2436 inline void java_lang_reflect_Field::set_name(java_handle_t* value)
2437 {
2438         set(_handle, offset_name, value);
2439 }
2440
2441 inline void java_lang_reflect_Field::set_type(classinfo* value)
2442 {
2443         set(_handle, offset_type, value);
2444 }
2445
2446 inline void java_lang_reflect_Field::set_modifiers(int32_t value)
2447 {
2448         set(_handle, offset_modifiers, value);
2449 }
2450
2451 inline void java_lang_reflect_Field::set_signature(java_handle_t* value)
2452 {
2453         set(_handle, offset_signature, value);
2454 }
2455
2456 inline void java_lang_reflect_Field::set_annotations(java_handle_bytearray_t* value)
2457 {
2458         set(_handle, offset_annotations, value);
2459 }
2460
2461
2462 inline fieldinfo* java_lang_reflect_Field::get_field() const
2463 {
2464         classinfo* c    = get_clazz();
2465         int32_t    slot = get_slot();
2466         fieldinfo* f    = &(c->fields[slot]);
2467         return f;
2468 }
2469
2470
2471 /**
2472  * OpenJDK java/lang/reflect/Method
2473  *
2474  * Object layout:
2475  *
2476  * 0.  object header
2477  * 1.  boolean                                               override;
2478  * 2.  java.lang.Class                                       clazz;
2479  * 3.  int                                                   slot;
2480  * 4.  java.lang.String                                      name;
2481  * 5.  java.lang.Class                                       returnType;
2482  * 6.  java.lang.Class[]                                     parameterTypes;
2483  * 7.  java.lang.Class[]                                     exceptionTypes;
2484  * 8.  int                                                   modifiers;
2485  * 9.  java.lang.String                                      signature;
2486  * 10  sun.reflect.generics.repository.ConstructorRepository genericInfo;
2487  * 11. byte[]                                                annotations;
2488  * 12. byte[]                                                parameterAnnotations;
2489  * 13. byte[]                                                annotationDefault;
2490  * 14. sun.reflect.MethodAccessor                            methodAccessor;
2491  * 15. java.lang.reflect.Method                              root;
2492  * 16. java.lang.Class                                       securityCheckCache;
2493  * 17. java.lang.Class                                       securityCheckTargetClassCache;
2494  * 18. java.util.Map                                         declaredAnnotations;
2495  */
2496 class java_lang_reflect_Method : public java_lang_Object, private FieldAccess {
2497 private:
2498         // Static offsets of the object's instance fields.
2499         // TODO These offsets need to be checked on VM startup.
2500         static const off_t offset_override                      = MEMORY_ALIGN(sizeof(java_object_t),                                  sizeof(int32_t));
2501         static const off_t offset_clazz                         = MEMORY_ALIGN(offset_override                      + sizeof(int32_t), SIZEOF_VOID_P);
2502         static const off_t offset_slot                          = MEMORY_ALIGN(offset_clazz                         + SIZEOF_VOID_P,   sizeof(int32_t));
2503         static const off_t offset_name                          = MEMORY_ALIGN(offset_slot                          + sizeof(int32_t), SIZEOF_VOID_P);
2504         static const off_t offset_returnType                    = MEMORY_ALIGN(offset_name                          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2505         static const off_t offset_parameterTypes                = MEMORY_ALIGN(offset_returnType                    + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2506         static const off_t offset_exceptionTypes                = MEMORY_ALIGN(offset_parameterTypes                + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2507         static const off_t offset_modifiers                     = MEMORY_ALIGN(offset_exceptionTypes                + SIZEOF_VOID_P,   sizeof(int32_t));
2508         static const off_t offset_signature                     = MEMORY_ALIGN(offset_modifiers                     + sizeof(int32_t), SIZEOF_VOID_P);
2509         static const off_t offset_genericInfo                   = MEMORY_ALIGN(offset_signature                     + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2510         static const off_t offset_annotations                   = MEMORY_ALIGN(offset_genericInfo                   + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2511         static const off_t offset_parameterAnnotations          = MEMORY_ALIGN(offset_annotations                   + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2512         static const off_t offset_annotationDefault             = MEMORY_ALIGN(offset_parameterAnnotations          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2513         static const off_t offset_methodAccessor                = MEMORY_ALIGN(offset_annotationDefault             + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2514         static const off_t offset_root                          = MEMORY_ALIGN(offset_methodAccessor                + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2515         static const off_t offset_securityCheckCache            = MEMORY_ALIGN(offset_root                          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2516         static const off_t offset_securityCheckTargetClassCache = MEMORY_ALIGN(offset_securityCheckCache            + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2517         static const off_t offset_declaredAnnotations           = MEMORY_ALIGN(offset_securityCheckTargetClassCache + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2518
2519 public:
2520         java_lang_reflect_Method(java_handle_t* h) : java_lang_Object(h) {}
2521         java_lang_reflect_Method(methodinfo* m);
2522
2523         java_handle_t* invoke(java_handle_t* o, java_handle_objectarray_t* args);
2524
2525         // Getters.
2526         int32_t                  get_override            () const;
2527         classinfo*               get_clazz               () const;
2528         int32_t                  get_slot                () const;
2529         java_handle_bytearray_t* get_annotations         () const;
2530         java_handle_bytearray_t* get_parameterAnnotations() const;
2531         java_handle_bytearray_t* get_annotationDefault   () const;
2532
2533         // Setters.
2534
2535         // Convenience functions.
2536         methodinfo* get_method() const;
2537 };
2538
2539
2540 inline java_lang_reflect_Method::java_lang_reflect_Method(methodinfo* m)
2541 {
2542         _handle = builtin_new(class_java_lang_reflect_Method);
2543
2544         if (is_null())
2545                 return;
2546
2547         set(_handle, offset_clazz,                m->clazz);
2548         set(_handle, offset_slot,                 (int32_t) (m - m->clazz->methods)); // This cast is important (see PR100).
2549         set(_handle, offset_name,                 javastring_intern(javastring_new(m->name)));
2550         set(_handle, offset_returnType,           method_returntype_get(m));
2551         set(_handle, offset_parameterTypes,       method_get_parametertypearray(m));
2552         set(_handle, offset_exceptionTypes,       method_get_exceptionarray(m));
2553         set(_handle, offset_modifiers,            (int32_t) (m->flags & ACC_CLASS_REFLECT_MASK));
2554         set(_handle, offset_signature,            m->signature ? javastring_new(m->signature) : NULL);
2555         set(_handle, offset_annotations,          method_get_annotations(m));
2556         set(_handle, offset_parameterAnnotations, method_get_parameterannotations(m));
2557         set(_handle, offset_annotationDefault,    method_get_annotationdefault(m));
2558 }
2559
2560
2561 inline int32_t java_lang_reflect_Method::get_override() const
2562 {
2563         return get<int32_t>(_handle, offset_override);
2564 }
2565
2566 inline classinfo* java_lang_reflect_Method::get_clazz() const
2567 {
2568         return get<classinfo*>(_handle, offset_clazz);
2569 }
2570
2571 inline int32_t java_lang_reflect_Method::get_slot() const
2572 {
2573         return get<int32_t>(_handle, offset_slot);
2574 }
2575
2576 inline java_handle_bytearray_t* java_lang_reflect_Method::get_annotations() const
2577 {
2578         return get<java_handle_bytearray_t*>(_handle, offset_annotations);
2579 }
2580
2581 inline java_handle_bytearray_t* java_lang_reflect_Method::get_parameterAnnotations() const
2582 {
2583         return get<java_handle_bytearray_t*>(_handle, offset_parameterAnnotations);
2584 }
2585
2586 inline java_handle_bytearray_t* java_lang_reflect_Method::get_annotationDefault() const
2587 {
2588         return get<java_handle_bytearray_t*>(_handle, offset_annotationDefault);
2589 }
2590
2591
2592 inline methodinfo* java_lang_reflect_Method::get_method() const
2593 {
2594         classinfo*  c    = get_clazz();
2595         int32_t     slot = get_slot();
2596         methodinfo* m    = &(c->methods[slot]);
2597         return m;
2598 }
2599
2600
2601 /**
2602  * OpenJDK java/nio/Buffer
2603  *
2604  * Object layout:
2605  *
2606  * 0. object header
2607  * 1. int  mark;
2608  * 2. int  position;
2609  * 3. int  limit;
2610  * 4. int  capacity;
2611  * 5. long address;
2612  */
2613 class java_nio_Buffer : public java_lang_Object, private FieldAccess {
2614 private:
2615         // Static offsets of the object's instance fields.
2616         // TODO These offsets need to be checked on VM startup.
2617         static const off_t offset_mark     = MEMORY_ALIGN(sizeof(java_object_t),          sizeof(int32_t));
2618         static const off_t offset_position = MEMORY_ALIGN(offset_mark     + sizeof(int32_t), sizeof(int32_t));
2619         static const off_t offset_limit    = MEMORY_ALIGN(offset_position + sizeof(int32_t), sizeof(int32_t));
2620         static const off_t offset_capacity = MEMORY_ALIGN(offset_limit    + sizeof(int32_t), sizeof(int32_t));
2621         static const off_t offset_address  = MEMORY_ALIGN(offset_capacity + sizeof(int32_t), sizeof(int64_t));
2622
2623 public:
2624         java_nio_Buffer(java_handle_t* h) : java_lang_Object(h) {}
2625
2626         // Getters.
2627         void* get_address() const;
2628 };
2629
2630
2631 inline void* java_nio_Buffer::get_address() const
2632 {
2633         return get<void*>(_handle, offset_address);
2634 }
2635
2636 #endif // WITH_JAVA_RUNTIME_LIBRARY_OPENJDK
2637
2638
2639 #if defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
2640
2641 /**
2642  * CLDC 1.1 com/sun/cldchi/jvm/FileDescriptor
2643  *
2644  * Object layout:
2645  *
2646  * 0. object header
2647  * 1. long   pointer;
2648  * 2. int    position;
2649  * 3. int    length;
2650  */
2651 class com_sun_cldchi_jvm_FileDescriptor : public java_lang_Object, private FieldAccess {
2652 private:
2653         // Static offsets of the object's instance fields.
2654         // TODO These offsets need to be checked on VM startup.
2655         static const off_t offset_pointer  = MEMORY_ALIGN(sizeof(java_object_t),             sizeof(int64_t));
2656         static const off_t offset_position = MEMORY_ALIGN(offset_pointer  + sizeof(int64_t), sizeof(int32_t));
2657         static const off_t offset_length   = MEMORY_ALIGN(offset_position + sizeof(int32_t), sizeof(int32_t));
2658
2659 public:
2660         com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h) : java_lang_Object(h) {}
2661         com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h, int64_t pointer, int32_t position, int32_t length);
2662         com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h, com_sun_cldchi_jvm_FileDescriptor& fd);
2663
2664         // Getters.
2665         int64_t get_pointer () const;
2666         int32_t get_position() const;
2667         int32_t get_length  () const;
2668
2669         // Setters.
2670         void set_pointer (int64_t value);
2671         void set_position(int32_t value);
2672         void set_length  (int32_t value);
2673 };
2674
2675
2676 inline com_sun_cldchi_jvm_FileDescriptor::com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h, int64_t pointer, int32_t position, int32_t length) : java_lang_Object(h)
2677 {
2678         set_pointer(pointer);
2679         set_position(position);
2680         set_length(length);
2681 }
2682
2683 inline com_sun_cldchi_jvm_FileDescriptor::com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h, com_sun_cldchi_jvm_FileDescriptor& fd) : java_lang_Object(h)
2684 {
2685         com_sun_cldchi_jvm_FileDescriptor(h, fd.get_pointer(), fd.get_position(), fd.get_length());
2686 }
2687
2688
2689 inline int64_t com_sun_cldchi_jvm_FileDescriptor::get_pointer() const
2690 {
2691         return get<int64_t>(_handle, offset_pointer);
2692 }
2693
2694 inline int32_t com_sun_cldchi_jvm_FileDescriptor::get_position() const
2695 {
2696         return get<int32_t>(_handle, offset_position);
2697 }
2698
2699 inline int32_t com_sun_cldchi_jvm_FileDescriptor::get_length() const
2700 {
2701         return get<int32_t>(_handle, offset_length);
2702 }
2703
2704
2705 inline void com_sun_cldchi_jvm_FileDescriptor::set_pointer(int64_t value)
2706 {
2707         set(_handle, offset_pointer, value);
2708 }
2709
2710 inline void com_sun_cldchi_jvm_FileDescriptor::set_position(int32_t value)
2711 {
2712         set(_handle, offset_position, value);
2713 }
2714
2715 inline void com_sun_cldchi_jvm_FileDescriptor::set_length(int32_t value)
2716 {
2717         set(_handle, offset_length, value);
2718 }
2719
2720
2721 /**
2722  * CLDC 1.1 java/lang/String
2723  *
2724  * Object layout:
2725  *
2726  * 0. object header
2727  * 1. char[] value;
2728  * 2. int    offset;
2729  * 3. int    count;
2730  */
2731 class java_lang_String : public java_lang_Object, private FieldAccess {
2732 private:
2733         // Static offsets of the object's instance fields.
2734         // TODO These offsets need to be checked on VM startup.
2735         static const off_t offset_value  = MEMORY_ALIGN(sizeof(java_object_t),           SIZEOF_VOID_P);
2736         static const off_t offset_offset = MEMORY_ALIGN(offset_value  + SIZEOF_VOID_P,   sizeof(int32_t));
2737         static const off_t offset_count  = MEMORY_ALIGN(offset_offset + sizeof(int32_t), sizeof(int32_t));
2738
2739 public:
2740         java_lang_String(java_handle_t* h) : java_lang_Object(h) {}
2741         java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset = 0);
2742
2743         // Getters.
2744         java_handle_chararray_t* get_value () const;
2745         int32_t                  get_offset() const;
2746         int32_t                  get_count () const;
2747
2748         // Setters.
2749         void set_value (java_handle_chararray_t* value);
2750         void set_offset(int32_t value);
2751         void set_count (int32_t value);
2752 };
2753
2754
2755 inline java_lang_String::java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset) : java_lang_Object(h)
2756 {
2757         set_value(value);
2758         set_offset(offset);
2759         set_count(count);
2760 }
2761
2762 inline java_handle_chararray_t* java_lang_String::get_value() const
2763 {
2764         return get<java_handle_chararray_t*>(_handle, offset_value);
2765 }
2766
2767 inline int32_t java_lang_String::get_offset() const
2768 {
2769         return get<int32_t>(_handle, offset_offset);
2770 }
2771
2772 inline int32_t java_lang_String::get_count() const
2773 {
2774         return get<int32_t>(_handle, offset_count);
2775 }
2776
2777 inline void java_lang_String::set_value(java_handle_chararray_t* value)
2778 {
2779         set(_handle, offset_value, value);
2780 }
2781
2782 inline void java_lang_String::set_offset(int32_t value)
2783 {
2784         set(_handle, offset_offset, value);
2785 }
2786
2787 inline void java_lang_String::set_count(int32_t value)
2788 {
2789         set(_handle, offset_count, value);
2790 }
2791
2792
2793 /**
2794  * CLDC 1.1 java/lang/Thread
2795  *
2796  * Object layout:
2797  *
2798  * 0. object header
2799  * 1. int                priority;
2800  * 2. java.lang.Runnable runnable;
2801  * 3. java.lang.Object   vm_thread;
2802  * 4. int                is_terminated;
2803  * 5. int                is_stillborn;
2804  * 6. char[]             name;
2805  */
2806 class java_lang_Thread : public java_lang_Object, private FieldAccess {
2807 private:
2808         // Static offsets of the object's instance fields.
2809         // TODO These offsets need to be checked on VM startup.
2810         static const off_t offset_priority      = MEMORY_ALIGN(sizeof(java_object_t),              sizeof(int32_t));
2811         static const off_t offset_runnable      = MEMORY_ALIGN(offset_priority      + sizeof(int32_t), SIZEOF_VOID_P);
2812         static const off_t offset_vm_thread     = MEMORY_ALIGN(offset_runnable      + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2813         static const off_t offset_is_terminated = MEMORY_ALIGN(offset_vm_thread     + SIZEOF_VOID_P,   sizeof(int32_t));
2814         static const off_t offset_is_stillborn  = MEMORY_ALIGN(offset_is_terminated + sizeof(int32_t), sizeof(int32_t));
2815         static const off_t offset_name          = MEMORY_ALIGN(offset_is_stillborn  + sizeof(int32_t), SIZEOF_VOID_P);
2816
2817 public:
2818         java_lang_Thread(java_handle_t* h) : java_lang_Object(h) {}
2819 //      java_lang_Thread(threadobject* t);
2820
2821         // Getters.
2822         int32_t                  get_priority () const;
2823         threadobject*            get_vm_thread() const;
2824         java_handle_chararray_t* get_name     () const;
2825
2826         // Setters.
2827         void set_vm_thread(threadobject* value);
2828 };
2829
2830
2831 // inline java_lang_Thread::java_lang_Thread(threadobject* t) : java_lang_Object(h)
2832 // {
2833 //      java_lang_Thread(thread_get_object(t));
2834 // }
2835
2836
2837 inline int32_t java_lang_Thread::get_priority() const
2838 {
2839         return get<int32_t>(_handle, offset_priority);
2840 }
2841
2842 inline threadobject* java_lang_Thread::get_vm_thread() const
2843 {
2844         return get<threadobject*>(_handle, offset_vm_thread);
2845 }
2846
2847 inline java_handle_chararray_t* java_lang_Thread::get_name() const
2848 {
2849         return get<java_handle_chararray_t*>(_handle, offset_name);
2850 }
2851
2852
2853 inline void java_lang_Thread::set_vm_thread(threadobject* value)
2854 {
2855         set(_handle, offset_vm_thread, value);
2856 }
2857
2858
2859 /**
2860  * CLDC 1.1 java/lang/Throwable
2861  *
2862  * Object layout:
2863  *
2864  * 0. object header
2865  * 1. java.lang.String detailMessage;
2866  * 2. java.lang.Object backtrace;
2867  */
2868 class java_lang_Throwable : public java_lang_Object, private FieldAccess {
2869 private:
2870         // Static offsets of the object's instance fields.
2871         // TODO These offsets need to be checked on VM startup.
2872         static const off_t offset_detailMessage = MEMORY_ALIGN(sizeof(java_object_t),                SIZEOF_VOID_P);
2873         static const off_t offset_backtrace     = MEMORY_ALIGN(offset_detailMessage + SIZEOF_VOID_P, SIZEOF_VOID_P);
2874
2875 public:
2876         java_lang_Throwable(java_handle_t* h) : java_lang_Object(h) {}
2877
2878         // Getters.
2879         java_handle_t*           get_detailMessage() const;
2880         java_handle_bytearray_t* get_backtrace    () const;
2881
2882         // Setters.
2883         void set_backtrace(java_handle_bytearray_t* value);
2884 };
2885
2886
2887 inline java_handle_t* java_lang_Throwable::get_detailMessage() const
2888 {
2889         return get<java_handle_t*>(_handle, offset_detailMessage);
2890 }
2891
2892 inline java_handle_bytearray_t* java_lang_Throwable::get_backtrace() const
2893 {
2894         return get<java_handle_bytearray_t*>(_handle, offset_backtrace);
2895 }
2896
2897
2898 inline void java_lang_Throwable::set_backtrace(java_handle_bytearray_t* value)
2899 {
2900         set(_handle, offset_backtrace, value);
2901 }
2902
2903 #endif // WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1
2904
2905 #endif
2906
2907 #endif // _JAVAOBJECTS_HPP
2908
2909
2910 /*
2911  * These are local overrides for various environment variables in Emacs.
2912  * Please do not remove this and leave it at the end of the file, where
2913  * Emacs will automagically detect them.
2914  * ---------------------------------------------------------------------
2915  * Local variables:
2916  * mode: c++
2917  * indent-tabs-mode: t
2918  * c-basic-offset: 4
2919  * tab-width: 4
2920  * End:
2921  */