* src/vm/javaobjects.hpp: Removed lots of superfluous inline keywords.
[cacao.git] / src / vm / javaobjects.hpp
1 /* src/vm/javaobjects.hpp - functions to create and access Java objects
2
3    Copyright (C) 2008 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 # if defined(ENABLE_ANNOTATIONS)
513 /**
514  * OpenJDK sun/reflect/ConstantPool
515  *
516  * Object layout:
517  *
518  * 0. object header
519  * 1. java.lang.Object constantPoolOop;
520  */
521 class sun_reflect_ConstantPool : public java_lang_Object, private FieldAccess {
522 private:
523         // Static offsets of the object's instance fields.
524         // TODO These offsets need to be checked on VM startup.
525         static const off_t offset_constantPoolOop = MEMORY_ALIGN(sizeof(java_object_t), SIZEOF_VOID_P);
526
527 public:
528         sun_reflect_ConstantPool(java_handle_t* h) : java_lang_Object(h) {}
529         sun_reflect_ConstantPool(java_handle_t* h, jclass constantPoolOop);
530
531         // Setters.
532         void set_constantPoolOop(classinfo* value);
533         void set_constantPoolOop(jclass value);
534 };
535
536
537 inline sun_reflect_ConstantPool::sun_reflect_ConstantPool(java_handle_t* h, jclass constantPoolOop) : java_lang_Object(h)
538 {
539         set_constantPoolOop(constantPoolOop);
540 }
541
542
543 inline void sun_reflect_ConstantPool::set_constantPoolOop(classinfo* value)
544 {
545         set(_handle, offset_constantPoolOop, value);
546 }
547
548 inline void sun_reflect_ConstantPool::set_constantPoolOop(jclass value)
549 {
550         // XXX jclass is a boxed object.
551         set_constantPoolOop(LLNI_classinfo_unwrap(value));
552 }
553 # endif // ENABLE_ANNOTATIONS
554
555 #endif // ENABLE_JAVASE
556
557
558 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
559
560 /**
561  * GNU Classpath java/lang/Class
562  *
563  * Object layout:
564  *
565  * 0. object header
566  * 1. java.lang.Object[]             signers;
567  * 2. java.security.ProtectionDomain pd;
568  * 3. java.lang.Object               vmdata;
569  * 4. java.lang.reflect.Constructor  constructor;
570  */
571 class java_lang_Class : public java_lang_Object, private FieldAccess {
572 private:
573         // Static offsets of the object's instance fields.
574         // TODO These offsets need to be checked on VM startup.
575         static const off_t offset_signers     = MEMORY_ALIGN(sizeof(java_object_t),          SIZEOF_VOID_P);
576         static const off_t offset_pd          = MEMORY_ALIGN(offset_signers + SIZEOF_VOID_P, SIZEOF_VOID_P);
577         static const off_t offset_vmdata      = MEMORY_ALIGN(offset_pd      + SIZEOF_VOID_P, SIZEOF_VOID_P);
578         static const off_t offset_constructor = MEMORY_ALIGN(offset_vmdata  + SIZEOF_VOID_P, SIZEOF_VOID_P);
579
580 public:
581         java_lang_Class(java_handle_t* h) : java_lang_Object(h) {}
582
583         // Setters.
584         void set_pd(java_handle_t* value);
585 };
586
587 inline void java_lang_Class::set_pd(java_handle_t* value)
588 {
589         set(_handle, offset_pd, value);
590 }
591
592
593 /**
594  * GNU Classpath java/lang/StackTraceElement
595  *
596  * Object layout:
597  *
598  * 0. object header
599  * 1. java.lang.String fileName;
600  * 2. int              lineNumber;
601  * 3. java.lang.String declaringClass;
602  * 4. java.lang.String methodName;
603  * 5. boolean          isNative;
604  */
605 class java_lang_StackTraceElement : public java_lang_Object, private FieldAccess {
606 private:
607         // Static offsets of the object's instance fields.
608         // TODO These offsets need to be checked on VM startup.
609         static const off_t offset_fileName       = MEMORY_ALIGN(sizeof(java_object_t),                   SIZEOF_VOID_P);
610         static const off_t offset_lineNumber     = MEMORY_ALIGN(offset_fileName       + SIZEOF_VOID_P,   sizeof(int32_t));
611         static const off_t offset_declaringClass = MEMORY_ALIGN(offset_lineNumber     + sizeof(int32_t), SIZEOF_VOID_P);
612         static const off_t offset_methodName     = MEMORY_ALIGN(offset_declaringClass + SIZEOF_VOID_P,   SIZEOF_VOID_P);
613         static const off_t offset_isNative       = MEMORY_ALIGN(offset_methodName     + SIZEOF_VOID_P,   SIZEOF_VOID_P);
614
615 public:
616         java_lang_StackTraceElement(java_handle_t* h) : java_lang_Object(h) {}
617         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);
618 };
619
620 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)
621 {
622         java_lang_StackTraceElement((java_handle_t*) h);
623
624         set(_handle, offset_fileName,       fileName);
625         set(_handle, offset_lineNumber,     lineNumber);
626         set(_handle, offset_declaringClass, declaringClass);
627         set(_handle, offset_methodName,     methodName);
628         set(_handle, offset_isNative,       isNative);
629 }
630
631
632 /**
633  * GNU Classpath java/lang/String
634  *
635  * Object layout:
636  *
637  * 0. object header
638  * 1. char[] value;
639  * 2. int    count;
640  * 3. int    cachedHashCode;
641  * 4. int    offset;
642  */
643 class java_lang_String : public java_lang_Object, private FieldAccess {
644 private:
645         // Static offsets of the object's instance fields.
646         // TODO These offsets need to be checked on VM startup.
647         static const off_t offset_value          = MEMORY_ALIGN(sizeof(java_object_t),                   SIZEOF_VOID_P);
648         static const off_t offset_count          = MEMORY_ALIGN(offset_value          + SIZEOF_VOID_P,   sizeof(int32_t));
649         static const off_t offset_cachedHashCode = MEMORY_ALIGN(offset_count          + sizeof(int32_t), sizeof(int32_t));
650         static const off_t offset_offset         = MEMORY_ALIGN(offset_cachedHashCode + sizeof(int32_t), sizeof(int32_t));
651
652 public:
653         java_lang_String(java_handle_t* h) : java_lang_Object(h) {}
654         java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset = 0);
655
656         // Getters.
657         java_handle_chararray_t* get_value () const;
658         int32_t                  get_count () const;
659         int32_t                  get_offset() const;
660
661         // Setters.
662         void set_value (java_handle_chararray_t* value);
663         void set_count (int32_t value);
664         void set_offset(int32_t value);
665 };
666
667 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)
668 {
669         set_value(value);
670         set_count(count);
671         set_offset(offset);
672 }
673
674 inline java_handle_chararray_t* java_lang_String::get_value() const
675 {
676         return get<java_handle_chararray_t*>(_handle, offset_value);
677 }
678
679 inline int32_t java_lang_String::get_count() const
680 {
681         return get<int32_t>(_handle, offset_count);
682 }
683
684 inline int32_t java_lang_String::get_offset() const
685 {
686         return get<int32_t>(_handle, offset_offset);
687 }
688
689 inline void java_lang_String::set_value(java_handle_chararray_t* value)
690 {
691         set(_handle, offset_value, value);
692 }
693
694 inline void java_lang_String::set_count(int32_t value)
695 {
696         set(_handle, offset_count, value);
697 }
698
699 inline void java_lang_String::set_offset(int32_t value)
700 {
701         set(_handle, offset_offset, value);
702 }
703
704
705 /**
706  * GNU Classpath java/lang/Thread
707  *
708  * Object layout:
709  *
710  *  0. object header
711  *  1. java.lang.VMThread                        vmThread;
712  *  2. java.lang.ThreadGroup                     group;
713  *  3. java.lang.Runnable                        runnable;
714  *  4. java.lang.String                          name;
715  *  5. boolean                                   daemon;
716  *  6. int                                       priority;
717  *  7. long                                      stacksize;
718  *  8. java.lang.Throwable                       stillborn;
719  *  9. java.lang.ClassLoader                     contextClassLoader;
720  * 10. boolean                                   contextClassLoaderIsSystemClassLoader;
721  * 11. long                                      threadId;
722  * 12. java.lang.Object                          parkBlocker;
723  * 13. gnu.java.util.WeakIdentityHashMap         locals;
724  * 14. java_lang_Thread_UncaughtExceptionHandler exceptionHandler;
725  */
726 class java_lang_Thread : public java_lang_Object, private FieldAccess {
727 private:
728         // Static offsets of the object's instance fields.
729         // TODO These offsets need to be checked on VM startup.
730         static const off_t offset_vmThread                              = MEMORY_ALIGN(sizeof(java_object_t),                                          SIZEOF_VOID_P);
731         static const off_t offset_group                                 = MEMORY_ALIGN(offset_vmThread                              + SIZEOF_VOID_P,   SIZEOF_VOID_P);
732         static const off_t offset_runnable                              = MEMORY_ALIGN(offset_group                                 + SIZEOF_VOID_P,   SIZEOF_VOID_P);
733         static const off_t offset_name                                  = MEMORY_ALIGN(offset_runnable                              + SIZEOF_VOID_P,   SIZEOF_VOID_P);
734         static const off_t offset_daemon                                = MEMORY_ALIGN(offset_name                                  + SIZEOF_VOID_P,   sizeof(int32_t));
735         static const off_t offset_priority                              = MEMORY_ALIGN(offset_daemon                                + sizeof(int32_t), sizeof(int32_t));
736         static const off_t offset_stacksize                             = MEMORY_ALIGN(offset_priority                              + sizeof(int32_t), sizeof(int64_t));
737         static const off_t offset_stillborn                             = MEMORY_ALIGN(offset_stacksize                             + sizeof(int64_t), SIZEOF_VOID_P);
738         static const off_t offset_contextClassLoader                    = MEMORY_ALIGN(offset_stillborn                             + SIZEOF_VOID_P,   SIZEOF_VOID_P);
739         static const off_t offset_contextClassLoaderIsSystemClassLoader = MEMORY_ALIGN(offset_contextClassLoader                    + SIZEOF_VOID_P,   SIZEOF_VOID_P);
740         static const off_t offset_threadId                              = MEMORY_ALIGN(offset_contextClassLoaderIsSystemClassLoader + sizeof(int32_t), sizeof(int64_t));
741         static const off_t offset_parkBlocker                           = MEMORY_ALIGN(offset_threadId                              + sizeof(int64_t), SIZEOF_VOID_P);
742         static const off_t offset_locals                                = MEMORY_ALIGN(offset_parkBlocker                           + SIZEOF_VOID_P,   SIZEOF_VOID_P);
743         static const off_t offset_exceptionHandler                      = MEMORY_ALIGN(offset_locals                                + SIZEOF_VOID_P,   SIZEOF_VOID_P);
744
745 public:
746         java_lang_Thread(java_handle_t* h) : java_lang_Object(h) {}
747 //      java_lang_Thread(threadobject* t);
748
749         // Getters.
750         java_handle_t* get_vmThread        () const;
751         java_handle_t* get_group           () const;
752         java_handle_t* get_name            () const;
753         int32_t        get_daemon          () const;
754         int32_t        get_priority        () const;
755         java_handle_t* get_exceptionHandler() const;
756
757         // Setters.
758         void set_group(java_handle_t* value);
759 };
760
761
762 // inline java_lang_Thread::java_lang_Thread(threadobject* t) : java_lang_Object(h)
763 // {
764 //      java_lang_Thread(thread_get_object(t));
765 // }
766
767
768 inline java_handle_t* java_lang_Thread::get_vmThread() const
769 {
770         return get<java_handle_t*>(_handle, offset_vmThread);
771 }
772
773 inline java_handle_t* java_lang_Thread::get_group() const
774 {
775         return get<java_handle_t*>(_handle, offset_group);
776 }
777
778 inline java_handle_t* java_lang_Thread::get_name() const
779 {
780         return get<java_handle_t*>(_handle, offset_name);
781 }
782
783 inline int32_t java_lang_Thread::get_daemon() const
784 {
785         return get<int32_t>(_handle, offset_daemon);
786 }
787
788 inline int32_t java_lang_Thread::get_priority() const
789 {
790         return get<int32_t>(_handle, offset_priority);
791 }
792
793 inline java_handle_t* java_lang_Thread::get_exceptionHandler() const
794 {
795         return get<java_handle_t*>(_handle, offset_exceptionHandler);
796 }
797
798
799 inline void java_lang_Thread::set_group(java_handle_t* value)
800 {
801         set(_handle, offset_group, value);
802 }
803
804
805 /**
806  * GNU Classpath java/lang/VMThread
807  *
808  * Object layout:
809  *
810  * 0. object header
811  * 1. java.lang.Thread   thread;
812  * 2. boolean            running;
813  * 3. java.lang.VMThread vmdata;
814  */
815 class java_lang_VMThread : public java_lang_Object, private FieldAccess {
816 private:
817         // Static offsets of the object's instance fields.
818         // TODO These offsets need to be checked on VM startup.
819         static const off_t offset_thread  = MEMORY_ALIGN(sizeof(java_object_t),            SIZEOF_VOID_P);
820         static const off_t offset_running = MEMORY_ALIGN(offset_thread  + SIZEOF_VOID_P,   sizeof(int32_t));
821         static const off_t offset_vmdata  = MEMORY_ALIGN(offset_running + sizeof(int32_t), SIZEOF_VOID_P);
822
823 public:
824         java_lang_VMThread(java_handle_t* h) : java_lang_Object(h) {}
825         java_lang_VMThread(java_handle_t* h, java_handle_t* thread, threadobject* vmdata);
826
827         // Getters.
828         java_handle_t* get_thread() const;
829         threadobject*  get_vmdata() const;
830
831         // Setters.
832         void set_thread(java_handle_t* value);
833         void set_vmdata(threadobject* value);
834 };
835
836
837 inline java_lang_VMThread::java_lang_VMThread(java_handle_t* h, java_handle_t* thread, threadobject* vmdata) : java_lang_Object(h)
838 {
839         set_thread(thread);
840         set_vmdata(vmdata);
841 }
842
843
844 inline java_handle_t* java_lang_VMThread::get_thread() const
845 {
846         return get<java_handle_t*>(_handle, offset_thread);
847 }
848
849 inline threadobject* java_lang_VMThread::get_vmdata() const
850 {
851         return get<threadobject*>(_handle, offset_vmdata);
852 }
853
854
855 inline void java_lang_VMThread::set_thread(java_handle_t* value)
856 {
857         set(_handle, offset_thread, value);
858 }
859
860 inline void java_lang_VMThread::set_vmdata(threadobject* value)
861 {
862         set(_handle, offset_vmdata, value);
863 }
864
865
866 /**
867  * GNU Classpath java/lang/Throwable
868  *
869  * Object layout:
870  *
871  * 0. object header
872  * 1. java.lang.String              detailMessage;
873  * 2. java.lang.Throwable           cause;
874  * 3. java.lang.StackTraceElement[] stackTrace;
875  * 4. java.lang.VMThrowable         vmState;
876  */
877 class java_lang_Throwable : public java_lang_Object, private FieldAccess {
878 private:
879         // Static offsets of the object's instance fields.
880         // TODO These offsets need to be checked on VM startup.
881         static const off_t offset_detailMessage = MEMORY_ALIGN(sizeof(java_object_t),                SIZEOF_VOID_P);
882         static const off_t offset_cause         = MEMORY_ALIGN(offset_detailMessage + SIZEOF_VOID_P, SIZEOF_VOID_P);
883         static const off_t offset_stackTrace    = MEMORY_ALIGN(offset_cause         + SIZEOF_VOID_P, SIZEOF_VOID_P);
884         static const off_t offset_vmState       = MEMORY_ALIGN(offset_stackTrace    + SIZEOF_VOID_P, SIZEOF_VOID_P);
885
886 public:
887         java_lang_Throwable(java_handle_t* h) : java_lang_Object(h) {}
888
889         // Getters.
890         java_handle_t* get_detailMessage() const;
891         java_handle_t* get_cause        () const;
892         java_handle_t* get_vmState      () const;
893 };
894
895
896 inline java_handle_t* java_lang_Throwable::get_detailMessage() const
897 {
898         return get<java_handle_t*>(_handle, offset_detailMessage);
899 }
900
901 inline java_handle_t* java_lang_Throwable::get_cause() const
902 {
903         return get<java_handle_t*>(_handle, offset_cause);
904 }
905
906 inline java_handle_t* java_lang_Throwable::get_vmState() const
907 {
908         return get<java_handle_t*>(_handle, offset_vmState);
909 }
910
911
912 /**
913  * GNU Classpath java/lang/VMThrowable
914  *
915  * Object layout:
916  *
917  * 0. object header
918  * 1. java.lang.Object vmdata;
919  */
920 class java_lang_VMThrowable : public java_lang_Object, private FieldAccess {
921 private:
922         // Static offsets of the object's instance fields.
923         // TODO These offsets need to be checked on VM startup.
924         static const off_t offset_vmdata = MEMORY_ALIGN(sizeof(java_object_t), SIZEOF_VOID_P);
925
926 public:
927         java_lang_VMThrowable(java_handle_t* h) : java_lang_Object(h) {}
928
929         java_handle_bytearray_t* get_vmdata() const;
930         void                     set_vmdata(java_handle_bytearray_t* value);
931 };
932
933
934 inline java_handle_bytearray_t* java_lang_VMThrowable::get_vmdata() const
935 {
936         return get<java_handle_bytearray_t*>(_handle, offset_vmdata);
937 }
938
939 inline void java_lang_VMThrowable::set_vmdata(java_handle_bytearray_t* value)
940 {
941         set(_handle, offset_vmdata, value);
942 }
943
944
945 /**
946  * GNU Classpath java/lang/reflect/VMConstructor
947  *
948  * Object layout:
949  *
950  * 0. object header
951  * 1. java.lang.Class               clazz;
952  * 2. int                           slot;
953  * 3. byte[]                        annotations;
954  * 4. byte[]                        parameterAnnotations;
955  * 5. java.util.Map                 declaredAnnotations;
956  * 6. java.lang.reflect.Constructor cons;
957  */
958 class java_lang_reflect_VMConstructor : public java_lang_Object, private FieldAccess {
959 private:
960         // Static offsets of the object's instance fields.
961         // TODO These offsets need to be checked on VM startup.
962         static const off_t offset_clazz                = MEMORY_ALIGN(sizeof(java_object_t),                         SIZEOF_VOID_P);
963         static const off_t offset_slot                 = MEMORY_ALIGN(offset_clazz                + SIZEOF_VOID_P,   sizeof(int32_t));
964         static const off_t offset_annotations          = MEMORY_ALIGN(offset_slot                 + sizeof(int32_t), SIZEOF_VOID_P);
965         static const off_t offset_parameterAnnotations = MEMORY_ALIGN(offset_annotations          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
966         static const off_t offset_declaredAnnotations  = MEMORY_ALIGN(offset_parameterAnnotations + SIZEOF_VOID_P,   SIZEOF_VOID_P);
967         static const off_t offset_cons                 = MEMORY_ALIGN(offset_declaredAnnotations  + SIZEOF_VOID_P,   SIZEOF_VOID_P);
968
969 public:
970         java_lang_reflect_VMConstructor(java_handle_t* h) : java_lang_Object(h) {}
971         java_lang_reflect_VMConstructor(methodinfo* m);
972
973         // Getters.
974         classinfo*               get_clazz               () const;
975         int32_t                  get_slot                () const;
976         java_handle_bytearray_t* get_annotations         () const;
977         java_handle_bytearray_t* get_parameterAnnotations() const;
978         java_handle_t*           get_declaredAnnotations () const;
979         java_handle_t*           get_cons                () const;
980
981         // Setters.
982         void set_clazz               (classinfo* value);
983         void set_slot                (int32_t value);
984         void set_annotations         (java_handle_bytearray_t* value);
985         void set_parameterAnnotations(java_handle_bytearray_t* value);
986         void set_declaredAnnotations (java_handle_t* value);
987         void set_cons                (java_handle_t* value);
988
989         // Convenience functions.
990         methodinfo* get_method();
991 };
992
993
994 inline java_lang_reflect_VMConstructor::java_lang_reflect_VMConstructor(methodinfo* m)
995 {
996         _handle = builtin_new(class_java_lang_reflect_VMConstructor);
997
998         if (is_null())
999                 return;
1000
1001         int                      slot                 = m - m->clazz->methods;
1002         java_handle_bytearray_t* annotations          = method_get_annotations(m);
1003         java_handle_bytearray_t* parameterAnnotations = method_get_parameterannotations(m);
1004
1005         set_clazz(m->clazz);
1006         set_slot(slot);
1007         set_annotations(annotations);
1008         set_parameterAnnotations(parameterAnnotations);
1009 }
1010
1011
1012 inline classinfo* java_lang_reflect_VMConstructor::get_clazz() const
1013 {
1014         return get<classinfo*>(_handle, offset_clazz);
1015 }
1016
1017 inline int32_t java_lang_reflect_VMConstructor::get_slot() const
1018 {
1019         return get<int32_t>(_handle, offset_slot);
1020 }
1021
1022 inline java_handle_bytearray_t* java_lang_reflect_VMConstructor::get_annotations() const
1023 {
1024         return get<java_handle_bytearray_t*>(_handle, offset_annotations);
1025 }
1026
1027 inline java_handle_bytearray_t* java_lang_reflect_VMConstructor::get_parameterAnnotations() const
1028 {
1029         return get<java_handle_bytearray_t*>(_handle, offset_parameterAnnotations);
1030 }
1031
1032 inline java_handle_t* java_lang_reflect_VMConstructor::get_declaredAnnotations() const
1033 {
1034         return get<java_handle_t*>(_handle, offset_declaredAnnotations);
1035 }
1036
1037 inline java_handle_t* java_lang_reflect_VMConstructor::get_cons() const
1038 {
1039         return get<java_handle_t*>(_handle, offset_cons);
1040 }
1041
1042 inline void java_lang_reflect_VMConstructor::set_clazz(classinfo* value)
1043 {
1044         set(_handle, offset_clazz, value);
1045 }
1046
1047 inline void java_lang_reflect_VMConstructor::set_slot(int32_t value)
1048 {
1049         set(_handle, offset_slot, value);
1050 }
1051
1052 inline void java_lang_reflect_VMConstructor::set_annotations(java_handle_bytearray_t* value)
1053 {
1054         set(_handle, offset_annotations, value);
1055 }
1056
1057 inline void java_lang_reflect_VMConstructor::set_parameterAnnotations(java_handle_bytearray_t* value)
1058 {
1059         set(_handle, offset_parameterAnnotations, value);
1060 }
1061
1062 inline void java_lang_reflect_VMConstructor::set_declaredAnnotations(java_handle_t* value)
1063 {
1064         set(_handle, offset_declaredAnnotations, value);
1065 }
1066
1067 inline void java_lang_reflect_VMConstructor::set_cons(java_handle_t* value)
1068 {
1069         set(_handle, offset_cons, value);
1070 }
1071
1072 inline methodinfo* java_lang_reflect_VMConstructor::get_method()
1073 {
1074         classinfo*  c    = get_clazz();
1075         int32_t     slot = get_slot();
1076         methodinfo* m    = &(c->methods[slot]);
1077         return m;
1078 }
1079
1080
1081 /**
1082  * GNU Classpath java/lang/reflect/Constructor
1083  *
1084  * Object layout:
1085  *
1086  * 0. object header
1087  * 1. boolean                                     flag;
1088  * 2. gnu.java.lang.reflect.MethodSignatureParser p;
1089  * 3. java.lang.reflect.VMConstructor             cons;
1090  */
1091 class java_lang_reflect_Constructor : public java_lang_Object, private FieldAccess {
1092 private:
1093         // Static offsets of the object's instance fields.
1094         // TODO These offsets need to be checked on VM startup.
1095         static const off_t offset_flag = MEMORY_ALIGN(sizeof(java_object_t),         sizeof(int32_t));
1096         static const off_t offset_p    = MEMORY_ALIGN(offset_flag + sizeof(int32_t), SIZEOF_VOID_P);
1097         static const off_t offset_cons = MEMORY_ALIGN(offset_p    + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1098
1099 public:
1100         java_lang_reflect_Constructor(java_handle_t* h) : java_lang_Object(h) {}
1101         java_lang_reflect_Constructor(methodinfo* m);
1102
1103         java_handle_t* new_instance(java_handle_objectarray_t* args);
1104
1105         // Getters.
1106         int32_t        get_flag() const;
1107         java_handle_t* get_cons() const;
1108
1109         // Setters.
1110         void set_cons(java_handle_t* value);
1111
1112         // Convenience functions.
1113         methodinfo* get_method  () const;
1114         int32_t     get_override() const;
1115 };
1116
1117
1118 inline java_lang_reflect_Constructor::java_lang_reflect_Constructor(methodinfo* m)
1119 {
1120         java_lang_reflect_VMConstructor jlrvmc(m);
1121
1122         if (jlrvmc.is_null())
1123                 return;
1124
1125         _handle = builtin_new(class_java_lang_reflect_Constructor);
1126
1127         if (is_null())
1128                 return;
1129
1130         // Link the two Java objects.
1131         set_cons(jlrvmc.get_handle());
1132         jlrvmc.set_cons(get_handle());
1133 }
1134
1135
1136 inline int32_t java_lang_reflect_Constructor::get_flag() const
1137 {
1138         return get<int32_t>(_handle, offset_flag);
1139 }
1140
1141 inline java_handle_t* java_lang_reflect_Constructor::get_cons() const
1142 {
1143         return get<java_handle_t*>(_handle, offset_cons);
1144 }
1145
1146
1147 inline void java_lang_reflect_Constructor::set_cons(java_handle_t* value)
1148 {
1149         set(_handle, offset_cons, value);
1150 }
1151
1152
1153 inline methodinfo* java_lang_reflect_Constructor::get_method() const
1154 {
1155         java_lang_reflect_VMConstructor jlrvmc(get_cons());
1156         return jlrvmc.get_method();
1157 }
1158
1159 inline int32_t java_lang_reflect_Constructor::get_override() const
1160 {
1161         return get_flag();
1162 }
1163
1164
1165 /**
1166  * GNU Classpath java/lang/reflect/VMField
1167  *
1168  * Object layout:
1169  *
1170  * 0. object header
1171  * 1. java.lang.Class         clazz;
1172  * 2. java.lang.String        name;
1173  * 3. int                     slot;
1174  * 4. byte[]                  annotations;
1175  * 5. java.lang.Map           declaredAnnotations;
1176  * 6. java.lang.reflect.Field f;
1177  */
1178 class java_lang_reflect_VMField : public java_lang_Object, private FieldAccess {
1179 private:
1180         // Static offsets of the object's instance fields.
1181         // TODO These offsets need to be checked on VM startup.
1182         static const off_t offset_clazz               = MEMORY_ALIGN(sizeof(java_object_t),                        SIZEOF_VOID_P);
1183         static const off_t offset_name                = MEMORY_ALIGN(offset_clazz               + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1184         static const off_t offset_slot                = MEMORY_ALIGN(offset_name                + SIZEOF_VOID_P,   sizeof(int32_t));
1185         static const off_t offset_annotations         = MEMORY_ALIGN(offset_slot                + sizeof(int32_t), SIZEOF_VOID_P);
1186         static const off_t offset_declaredAnnotations = MEMORY_ALIGN(offset_annotations         + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1187         static const off_t offset_f                   = MEMORY_ALIGN(offset_declaredAnnotations + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1188
1189 public:
1190         java_lang_reflect_VMField(java_handle_t* h) : java_lang_Object(h) {}
1191         java_lang_reflect_VMField(fieldinfo* f);
1192
1193         // Getters.
1194         classinfo*               get_clazz              () const;
1195         int32_t                  get_slot               () const;
1196         java_handle_bytearray_t* get_annotations        () const;
1197         java_handle_t*           get_declaredAnnotations() const;
1198         java_handle_t*           get_f                  () const;
1199
1200         // Setters.
1201         void set_clazz              (classinfo* value);
1202         void set_name               (java_handle_t* value);
1203         void set_slot               (int32_t value);
1204         void set_annotations        (java_handle_bytearray_t* value);
1205         void set_declaredAnnotations(java_handle_t* value);
1206         void set_f                  (java_handle_t* value);
1207
1208         // Convenience functions.
1209         fieldinfo* get_field() const;
1210 };
1211
1212
1213 inline java_lang_reflect_VMField::java_lang_reflect_VMField(fieldinfo* f)
1214 {
1215         _handle = builtin_new(class_java_lang_reflect_VMField);
1216
1217         if (is_null())
1218                 return;
1219
1220         java_handle_t*           name        = javastring_intern(javastring_new(f->name));
1221         int                      slot        = f - f->clazz->fields;
1222         java_handle_bytearray_t* annotations = field_get_annotations(f);
1223
1224         set_clazz(f->clazz);
1225         set_name(name);
1226         set_slot(slot);
1227         set_annotations(annotations);
1228 }
1229
1230
1231 inline classinfo* java_lang_reflect_VMField::get_clazz() const
1232 {
1233         return get<classinfo*>(_handle, offset_clazz);
1234 }
1235
1236 inline int32_t java_lang_reflect_VMField::get_slot() const
1237 {
1238         return get<int32_t>(_handle, offset_slot);
1239 }
1240
1241 inline java_handle_bytearray_t* java_lang_reflect_VMField::get_annotations() const
1242 {
1243         return get<java_handle_bytearray_t*>(_handle, offset_annotations);
1244 }
1245
1246 inline java_handle_t* java_lang_reflect_VMField::get_declaredAnnotations() const
1247 {
1248         return get<java_handle_t*>(_handle, offset_declaredAnnotations);
1249 }
1250
1251 inline java_handle_t* java_lang_reflect_VMField::get_f() const
1252 {
1253         return get<java_handle_t*>(_handle, offset_f);
1254 }
1255
1256
1257 inline void java_lang_reflect_VMField::set_clazz(classinfo* value)
1258 {
1259         set(_handle, offset_clazz, value);
1260 }
1261
1262 inline void java_lang_reflect_VMField::set_name(java_handle_t* value)
1263 {
1264         set(_handle, offset_name, value);
1265 }
1266
1267 inline void java_lang_reflect_VMField::set_slot(int32_t value)
1268 {
1269         set(_handle, offset_slot, value);
1270 }
1271
1272 inline void java_lang_reflect_VMField::set_annotations(java_handle_bytearray_t* value)
1273 {
1274         set(_handle, offset_annotations, value);
1275 }
1276
1277 inline void java_lang_reflect_VMField::set_declaredAnnotations(java_handle_t* value)
1278 {
1279         set(_handle, offset_declaredAnnotations, value);
1280 }
1281
1282 inline void java_lang_reflect_VMField::set_f(java_handle_t* value)
1283 {
1284         set(_handle, offset_f, value);
1285 }
1286
1287 inline fieldinfo* java_lang_reflect_VMField::get_field() const
1288 {
1289         classinfo* c    = get_clazz();
1290         int32_t    slot = get_slot();
1291         fieldinfo* f    = &(c->fields[slot]);
1292         return f;
1293 }
1294
1295
1296 /**
1297  * GNU Classpath java/lang/reflect/Field
1298  *
1299  * Object layout:
1300  *
1301  * 0. object header
1302  * 1. boolean                                    flag;
1303  * 2. gnu.java.lang.reflect.FieldSignatureParser p;
1304  * 3. java.lang.reflect.VMField                  f;
1305  */
1306 class java_lang_reflect_Field : public java_lang_Object, private FieldAccess {
1307 private:
1308         // Static offsets of the object's instance fields.
1309         // TODO These offsets need to be checked on VM startup.
1310         static const off_t offset_flag = MEMORY_ALIGN(sizeof(java_object_t),         sizeof(int32_t));
1311         static const off_t offset_p    = MEMORY_ALIGN(offset_flag + sizeof(int32_t), SIZEOF_VOID_P);
1312         static const off_t offset_f    = MEMORY_ALIGN(offset_p    + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1313
1314 public:
1315         java_lang_reflect_Field(java_handle_t* h) : java_lang_Object(h) {}
1316         java_lang_reflect_Field(fieldinfo* f);
1317
1318         // Getters.
1319         int32_t        get_flag() const;
1320         java_handle_t* get_f() const;
1321
1322         // Setters.
1323         void set_f(java_handle_t* value);
1324
1325         // Convenience functions.
1326         fieldinfo* get_field() const;
1327 };
1328
1329
1330 inline java_lang_reflect_Field::java_lang_reflect_Field(fieldinfo* f)
1331 {
1332         java_lang_reflect_VMField jlrvmf(f);
1333
1334         if (jlrvmf.is_null())
1335                 return;
1336
1337         _handle = builtin_new(class_java_lang_reflect_Field);
1338
1339         if (is_null())
1340                 return;
1341
1342         // Link the two Java objects.
1343         set_f(jlrvmf.get_handle());
1344         jlrvmf.set_f(get_handle());
1345 }
1346
1347
1348 inline int32_t java_lang_reflect_Field::get_flag() const
1349 {
1350         return get<int32_t>(_handle, offset_flag);
1351 }
1352
1353 inline java_handle_t* java_lang_reflect_Field::get_f() const
1354 {
1355         return get<java_handle_t*>(_handle, offset_f);
1356 }
1357
1358
1359 inline void java_lang_reflect_Field::set_f(java_handle_t* value)
1360 {
1361         set(_handle, offset_f, value);
1362 }
1363
1364
1365 inline fieldinfo* java_lang_reflect_Field::get_field() const
1366 {
1367         java_lang_reflect_VMField jlrvmf(get_f());
1368         return jlrvmf.get_field();
1369 }
1370
1371
1372 /**
1373  * GNU Classpath java/lang/reflect/VMMethod
1374  *
1375  * Object layout:
1376  *
1377  * 0. object header
1378  * 1. java.lang.Class          clazz;
1379  * 2. java.lang.String         name;
1380  * 3. int                      slot;
1381  * 4. byte[]                   annotations;
1382  * 5. byte[]                   parameterAnnotations;
1383  * 6. byte[]                   annotationDefault;
1384  * 7. java.lang.Map            declaredAnnotations;
1385  * 8. java.lang.reflect.Method m;
1386  */
1387 class java_lang_reflect_VMMethod : public java_lang_Object, private FieldAccess {
1388 private:
1389         // Static offsets of the object's instance fields.
1390         // TODO These offsets need to be checked on VM startup.
1391         static const off_t offset_clazz                = MEMORY_ALIGN(sizeof(java_object_t),                         SIZEOF_VOID_P);
1392         static const off_t offset_name                 = MEMORY_ALIGN(offset_clazz                + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1393         static const off_t offset_slot                 = MEMORY_ALIGN(offset_name                 + SIZEOF_VOID_P,   sizeof(int32_t));
1394         static const off_t offset_annotations          = MEMORY_ALIGN(offset_slot                 + sizeof(int32_t), SIZEOF_VOID_P);
1395         static const off_t offset_parameterAnnotations = MEMORY_ALIGN(offset_annotations          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1396         static const off_t offset_annotationDefault    = MEMORY_ALIGN(offset_parameterAnnotations + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1397         static const off_t offset_declaredAnnotations  = MEMORY_ALIGN(offset_annotationDefault    + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1398         static const off_t offset_m                    = MEMORY_ALIGN(offset_declaredAnnotations  + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1399
1400 public:
1401         java_lang_reflect_VMMethod(java_handle_t* h) : java_lang_Object(h) {}
1402         java_lang_reflect_VMMethod(methodinfo* m);
1403
1404         // Getters.
1405         classinfo*               get_clazz               () const;
1406         int32_t                  get_slot                () const;
1407         java_handle_bytearray_t* get_annotations         () const;
1408         java_handle_bytearray_t* get_parameterAnnotations() const;
1409         java_handle_bytearray_t* get_annotationDefault   () const;
1410         java_handle_t*           get_declaredAnnotations () const;
1411         java_handle_t*           get_m                   () const;
1412
1413         // Setters.
1414         void set_clazz               (classinfo* value);
1415         void set_name                (java_handle_t* value);
1416         void set_slot                (int32_t value);
1417         void set_annotations         (java_handle_bytearray_t* value);
1418         void set_parameterAnnotations(java_handle_bytearray_t* value);
1419         void set_annotationDefault   (java_handle_bytearray_t* value);
1420         void set_declaredAnnotations (java_handle_t* value);
1421         void set_m                   (java_handle_t* value);
1422
1423         // Convenience functions.
1424         methodinfo* get_method() const;
1425 };
1426
1427
1428 inline java_lang_reflect_VMMethod::java_lang_reflect_VMMethod(methodinfo* m)
1429 {
1430         _handle = builtin_new(class_java_lang_reflect_VMMethod);
1431
1432         if (is_null())
1433                 return;
1434
1435         java_handle_t*           name                 = javastring_intern(javastring_new(m->name));
1436         int                      slot                 = m - m->clazz->methods;
1437         java_handle_bytearray_t* annotations          = method_get_annotations(m);
1438         java_handle_bytearray_t* parameterAnnotations = method_get_parameterannotations(m);
1439         java_handle_bytearray_t* annotationDefault    = method_get_annotationdefault(m);
1440
1441         set_clazz(m->clazz);
1442         set_name(name);
1443         set_slot(slot);
1444         set_annotations(annotations);
1445         set_parameterAnnotations(parameterAnnotations);
1446         set_annotationDefault(annotationDefault);
1447 }
1448
1449 inline classinfo* java_lang_reflect_VMMethod::get_clazz() const
1450 {
1451         return get<classinfo*>(_handle, offset_clazz);
1452 }
1453
1454 inline int32_t java_lang_reflect_VMMethod::get_slot() const
1455 {
1456         return get<int32_t>(_handle, offset_slot);
1457 }
1458
1459 inline java_handle_bytearray_t* java_lang_reflect_VMMethod::get_annotations() const
1460 {
1461         return get<java_handle_bytearray_t*>(_handle, offset_annotations);
1462 }
1463
1464 inline java_handle_bytearray_t* java_lang_reflect_VMMethod::get_parameterAnnotations() const
1465 {
1466         return get<java_handle_bytearray_t*>(_handle, offset_parameterAnnotations);
1467 }
1468
1469 inline java_handle_bytearray_t* java_lang_reflect_VMMethod::get_annotationDefault() const
1470 {
1471         return get<java_handle_bytearray_t*>(_handle, offset_annotationDefault);
1472 }
1473
1474 inline java_handle_t* java_lang_reflect_VMMethod::get_declaredAnnotations() const
1475 {
1476         return get<java_handle_t*>(_handle, offset_declaredAnnotations);
1477 }
1478
1479 inline java_handle_t* java_lang_reflect_VMMethod::get_m() const
1480 {
1481         return get<java_handle_t*>(_handle, offset_m);
1482 }
1483
1484 inline void java_lang_reflect_VMMethod::set_clazz(classinfo* value)
1485 {
1486         set(_handle, offset_clazz, value);
1487 }
1488
1489 inline void java_lang_reflect_VMMethod::set_name(java_handle_t* value)
1490 {
1491         set(_handle, offset_name, value);
1492 }
1493
1494 inline void java_lang_reflect_VMMethod::set_slot(int32_t value)
1495 {
1496         set(_handle, offset_slot, value);
1497 }
1498
1499 inline void java_lang_reflect_VMMethod::set_annotations(java_handle_bytearray_t* value)
1500 {
1501         set(_handle, offset_annotations, value);
1502 }
1503
1504 inline void java_lang_reflect_VMMethod::set_parameterAnnotations(java_handle_bytearray_t* value)
1505 {
1506         set(_handle, offset_parameterAnnotations, value);
1507 }
1508
1509 inline void java_lang_reflect_VMMethod::set_annotationDefault(java_handle_bytearray_t* value)
1510 {
1511         set(_handle, offset_annotationDefault, value);
1512 }
1513
1514 inline void java_lang_reflect_VMMethod::set_declaredAnnotations(java_handle_t* value)
1515 {
1516         set(_handle, offset_declaredAnnotations, value);
1517 }
1518
1519 inline void java_lang_reflect_VMMethod::set_m(java_handle_t* value)
1520 {
1521         set(_handle, offset_m, value);
1522 }
1523
1524 inline methodinfo* java_lang_reflect_VMMethod::get_method() const
1525 {
1526         classinfo*  c    = get_clazz();
1527         int32_t     slot = get_slot();
1528         methodinfo* m    = &(c->methods[slot]);
1529         return m;
1530 }
1531
1532
1533 /**
1534  * GNU Classpath java/lang/reflect/Method
1535  *
1536  * Object layout:
1537  *
1538  * 0. object header
1539  * 1. boolean                                     flag;
1540  * 2. gnu.java.lang.reflect.MethodSignatureParser p;
1541  * 3. java.lang.reflect.VMMethod                  m;
1542  */
1543 class java_lang_reflect_Method : public java_lang_Object, private FieldAccess {
1544 private:
1545         // Static offsets of the object's instance fields.
1546         // TODO These offsets need to be checked on VM startup.
1547         static const off_t offset_flag = MEMORY_ALIGN(sizeof(java_object_t),         sizeof(int32_t));
1548         static const off_t offset_p    = MEMORY_ALIGN(offset_flag + sizeof(int32_t), SIZEOF_VOID_P);
1549         static const off_t offset_m    = MEMORY_ALIGN(offset_p    + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1550
1551 public:
1552         java_lang_reflect_Method(java_handle_t* h) : java_lang_Object(h) {}
1553         java_lang_reflect_Method(methodinfo* m);
1554
1555         java_handle_t* invoke(java_handle_t* o, java_handle_objectarray_t* args);
1556
1557         // Getters.
1558         int32_t        get_flag() const;
1559         java_handle_t* get_m() const;
1560
1561         // Setters.
1562         void set_m(java_handle_t* value);
1563
1564         // Convenience functions.
1565         methodinfo* get_method  () const;
1566         int32_t     get_override() const;
1567 };
1568
1569
1570 inline java_lang_reflect_Method::java_lang_reflect_Method(methodinfo* m)
1571 {
1572         java_lang_reflect_VMMethod jlrvmm(m);
1573
1574         if (jlrvmm.is_null())
1575                 return;
1576
1577         _handle = builtin_new(class_java_lang_reflect_Method);
1578
1579         if (is_null())
1580                 return;
1581
1582         // Link the two Java objects.
1583         set_m(jlrvmm.get_handle());
1584         jlrvmm.set_m(get_handle());
1585 }
1586
1587
1588 inline int32_t java_lang_reflect_Method::get_flag() const
1589 {
1590         return get<int32_t>(_handle, offset_flag);
1591 }
1592
1593 inline java_handle_t* java_lang_reflect_Method::get_m() const
1594 {
1595         return get<java_handle_t*>(_handle, offset_m);
1596 }
1597
1598
1599 inline void java_lang_reflect_Method::set_m(java_handle_t* value)
1600 {
1601         set(_handle, offset_m, value);
1602 }
1603
1604
1605 inline methodinfo* java_lang_reflect_Method::get_method() const
1606 {
1607         java_lang_reflect_VMMethod jlrvmm(get_m());
1608         return jlrvmm.get_method();
1609 }
1610
1611 inline int32_t java_lang_reflect_Method::get_override() const
1612 {
1613         return get_flag();
1614 }
1615
1616
1617 /**
1618  * GNU Classpath java/nio/Buffer
1619  *
1620  * Object layout:
1621  *
1622  * 0. object header
1623  * 1. int                   cap;
1624  * 2. int                   limit;
1625  * 3. int                   pos;
1626  * 4. int                   mark;
1627  * 5. gnu.classpath.Pointer address;
1628  */
1629 class java_nio_Buffer : public java_lang_Object, private FieldAccess {
1630 private:
1631         // Static offsets of the object's instance fields.
1632         // TODO These offsets need to be checked on VM startup.
1633         static const off_t offset_cap     = MEMORY_ALIGN(sizeof(java_object_t),          sizeof(int32_t));
1634         static const off_t offset_limit   = MEMORY_ALIGN(offset_cap   + sizeof(int32_t), sizeof(int32_t));
1635         static const off_t offset_pos     = MEMORY_ALIGN(offset_limit + sizeof(int32_t), sizeof(int32_t));
1636         static const off_t offset_mark    = MEMORY_ALIGN(offset_pos   + sizeof(int32_t), sizeof(int32_t));
1637         static const off_t offset_address = MEMORY_ALIGN(offset_mark  + sizeof(int32_t), SIZEOF_VOID_P);
1638
1639 public:
1640         java_nio_Buffer(java_handle_t* h) : java_lang_Object(h) {}
1641
1642         // Getters.
1643         int32_t get_cap() const;
1644 };
1645
1646 inline int32_t java_nio_Buffer::get_cap() const
1647 {
1648         return get<int32_t>(_handle, offset_cap);
1649 }
1650
1651
1652 /**
1653  * GNU Classpath java/nio/DirectByteBufferImpl
1654  *
1655  * Object layout:
1656  *
1657  * 0. object header
1658  * 1. int                   cap;
1659  * 2. int                   limit;
1660  * 3. int                   pos;
1661  * 4. int                   mark;
1662  * 5. gnu.classpath.Pointer address;
1663  * 6. java.nio.ByteOrder    endian;
1664  * 7. byte[]                backing_buffer;
1665  * 8. int                   array_offset;
1666  * 9. java.lang.Object      owner;
1667  */
1668 class java_nio_DirectByteBufferImpl : public java_lang_Object, private FieldAccess {
1669 private:
1670         // Static offsets of the object's instance fields.
1671         // TODO These offsets need to be checked on VM startup.
1672         static const off_t offset_cap            = MEMORY_ALIGN(sizeof(java_object_t),                   sizeof(int32_t));
1673         static const off_t offset_limit          = MEMORY_ALIGN(offset_cap            + sizeof(int32_t), sizeof(int32_t));
1674         static const off_t offset_pos            = MEMORY_ALIGN(offset_limit          + sizeof(int32_t), sizeof(int32_t));
1675         static const off_t offset_mark           = MEMORY_ALIGN(offset_pos            + sizeof(int32_t), sizeof(int32_t));
1676         static const off_t offset_address        = MEMORY_ALIGN(offset_mark           + sizeof(int32_t), SIZEOF_VOID_P);
1677         static const off_t offset_endian         = MEMORY_ALIGN(offset_address        + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1678         static const off_t offset_backing_buffer = MEMORY_ALIGN(offset_endian         + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1679         static const off_t offset_array_offset   = MEMORY_ALIGN(offset_backing_buffer + SIZEOF_VOID_P,   sizeof(int32_t));
1680         static const off_t offset_owner          = MEMORY_ALIGN(offset_array_offset   + sizeof(int32_t), SIZEOF_VOID_P);
1681
1682 public:
1683         java_nio_DirectByteBufferImpl(java_handle_t* h) : java_lang_Object(h) {}
1684
1685         // Getters.
1686         java_handle_t* get_address() const;
1687 };
1688
1689
1690 inline java_handle_t* java_nio_DirectByteBufferImpl::get_address() const
1691 {
1692         return get<java_handle_t*>(_handle, offset_address);
1693 }
1694
1695
1696 /**
1697  * GNU Classpath gnu/classpath/Pointer
1698  *
1699  * Actually there are two classes, gnu.classpath.Pointer32 and
1700  * gnu.classpath.Pointer64, but we only define the abstract super
1701  * class and use the int/long field as void* type.
1702  *
1703  * Object layout:
1704  *
1705  * 0. object header
1706  * 1. int/long data;
1707  */
1708 class gnu_classpath_Pointer : public java_lang_Object, private FieldAccess {
1709 private:
1710         // Static offsets of the object's instance fields.
1711         // TODO These offsets need to be checked on VM startup.
1712         static const off_t offset_data = MEMORY_ALIGN(sizeof(java_object_t), SIZEOF_VOID_P);
1713
1714 public:
1715         gnu_classpath_Pointer(java_handle_t* h) : java_lang_Object(h) {}
1716         gnu_classpath_Pointer(java_handle_t* h, void* data);
1717
1718         // Setters.
1719         void* get_data() const;
1720
1721         // Setters.
1722         void set_data(void* value);
1723 };
1724
1725 inline gnu_classpath_Pointer::gnu_classpath_Pointer(java_handle_t* h, void* data) : java_lang_Object(h)
1726 {
1727         set_data(data);
1728 }
1729
1730 inline void* gnu_classpath_Pointer::get_data() const
1731 {
1732         return get<void*>(_handle, offset_data);
1733 }
1734
1735 inline void gnu_classpath_Pointer::set_data(void* value)
1736 {
1737         set(_handle, offset_data, value);
1738 }
1739
1740 #endif // WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH
1741
1742
1743 #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1744
1745 /**
1746  * OpenJDK java/lang/AssertionStatusDirectives
1747  *
1748  * Object layout:
1749  *
1750  * 0. object header
1751  * 1. java.lang.String[] classes;
1752  * 2. boolean[]          classEnabled;
1753  * 3. java.lang.String[] packages;
1754  * 4. boolean[]          packageEnabled;
1755  * 5. boolean            deflt;
1756  */
1757 class java_lang_AssertionStatusDirectives : public java_lang_Object, private FieldAccess {
1758 private:
1759         // Static offsets of the object's instance fields.
1760         // TODO These offsets need to be checked on VM startup.
1761         static const off_t offset_classes        = MEMORY_ALIGN(sizeof(java_object_t),                 SIZEOF_VOID_P);
1762         static const off_t offset_classEnabled   = MEMORY_ALIGN(offset_classes        + SIZEOF_VOID_P, SIZEOF_VOID_P);
1763         static const off_t offset_packages       = MEMORY_ALIGN(offset_classEnabled   + SIZEOF_VOID_P, SIZEOF_VOID_P);
1764         static const off_t offset_packageEnabled = MEMORY_ALIGN(offset_packages       + SIZEOF_VOID_P, SIZEOF_VOID_P);
1765         static const off_t offset_deflt          = MEMORY_ALIGN(offset_packageEnabled + SIZEOF_VOID_P, sizeof(int32_t));
1766
1767 public:
1768         java_lang_AssertionStatusDirectives(java_handle_objectarray_t* classes, java_handle_booleanarray_t* classEnabled, java_handle_objectarray_t* packages, java_handle_booleanarray_t* packageEnabled);
1769 };
1770
1771 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)
1772 {
1773         classinfo* c = load_class_bootstrap(utf_new_char("java/lang/AssertionStatusDirectives"));
1774
1775         // FIXME Load the class at VM startup.
1776         if (c == NULL)
1777                 return;
1778
1779         _handle = builtin_new(c);
1780
1781         if (is_null())
1782                 return;
1783
1784         set(_handle, offset_classes,        classes);
1785         set(_handle, offset_classEnabled,   classEnabled);
1786         set(_handle, offset_packages,       packages);
1787         set(_handle, offset_packageEnabled, packageEnabled);
1788 }
1789
1790
1791 /**
1792  * OpenJDK java/lang/StackTraceElement
1793  *
1794  * Object layout:
1795  *
1796  * 0. object header
1797  * 1. java.lang.String declaringClass;
1798  * 2. java.lang.String methodName;
1799  * 3. java.lang.String fileName;
1800  * 4. int              lineNumber;
1801  */
1802 class java_lang_StackTraceElement : public java_lang_Object, private FieldAccess {
1803 private:
1804         // Static offsets of the object's instance fields.
1805         // TODO These offsets need to be checked on VM startup.
1806         static const off_t offset_declaringClass = MEMORY_ALIGN(sizeof(java_object_t),                 SIZEOF_VOID_P);
1807         static const off_t offset_methodName     = MEMORY_ALIGN(offset_declaringClass + SIZEOF_VOID_P, SIZEOF_VOID_P);
1808         static const off_t offset_fileName       = MEMORY_ALIGN(offset_methodName     + SIZEOF_VOID_P, SIZEOF_VOID_P);
1809         static const off_t offset_lineNumber     = MEMORY_ALIGN(offset_fileName       + SIZEOF_VOID_P, sizeof(int32_t));
1810
1811 public:
1812         java_lang_StackTraceElement(java_handle_t* h) : java_lang_Object(h) {}
1813         java_lang_StackTraceElement(java_handle_t* declaringClass, java_handle_t* methodName, java_handle_t* fileName, int32_t lineNumber);
1814 };
1815
1816 inline java_lang_StackTraceElement::java_lang_StackTraceElement(java_handle_t* declaringClass, java_handle_t* methodName, java_handle_t* fileName, int32_t lineNumber)
1817 {
1818         _handle = builtin_new(class_java_lang_StackTraceElement);
1819
1820         if (is_null())
1821                 return;
1822
1823         set(_handle, offset_declaringClass, declaringClass);
1824         set(_handle, offset_methodName,     methodName);
1825         set(_handle, offset_fileName,       fileName);
1826         set(_handle, offset_lineNumber,     lineNumber);
1827 }
1828
1829
1830 /**
1831  * OpenJDK java/lang/String
1832  *
1833  * Object layout:
1834  *
1835  * 0. object header
1836  * 1. char[] value;
1837  * 2. int    offset;
1838  * 3. int    count;
1839  * 4. int    hash;
1840  */
1841 class java_lang_String : public java_lang_Object, private FieldAccess {
1842 private:
1843         // Static offsets of the object's instance fields.
1844         // TODO These offsets need to be checked on VM startup.
1845         static const off_t offset_value  = MEMORY_ALIGN(sizeof(java_object_t),           SIZEOF_VOID_P);
1846         static const off_t offset_offset = MEMORY_ALIGN(offset_value  + SIZEOF_VOID_P,   sizeof(int32_t));
1847         static const off_t offset_count  = MEMORY_ALIGN(offset_offset + sizeof(int32_t), sizeof(int32_t));
1848         static const off_t offset_hash   = MEMORY_ALIGN(offset_count  + sizeof(int32_t), sizeof(int32_t));
1849
1850 public:
1851         java_lang_String(java_handle_t* h) : java_lang_Object(h) {}
1852         java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset = 0);
1853
1854         // Getters.
1855         java_handle_chararray_t* get_value () const;
1856         int32_t                  get_offset() const;
1857         int32_t                  get_count () const;
1858
1859         // Setters.
1860         void set_value (java_handle_chararray_t* value);
1861         void set_offset(int32_t value);
1862         void set_count (int32_t value);
1863 };
1864
1865 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)
1866 {
1867         set_value(value);
1868         set_offset(offset);
1869         set_count(count);
1870 }
1871
1872 inline java_handle_chararray_t* java_lang_String::get_value() const
1873 {
1874         return get<java_handle_chararray_t*>(_handle, offset_value);
1875 }
1876
1877 inline int32_t java_lang_String::get_offset() const
1878 {
1879         return get<int32_t>(_handle, offset_offset);
1880 }
1881
1882 inline int32_t java_lang_String::get_count() const
1883 {
1884         return get<int32_t>(_handle, offset_count);
1885 }
1886
1887 inline void java_lang_String::set_value(java_handle_chararray_t* value)
1888 {
1889         set(_handle, offset_value, value);
1890 }
1891
1892 inline void java_lang_String::set_offset(int32_t value)
1893 {
1894         set(_handle, offset_offset, value);
1895 }
1896
1897 inline void java_lang_String::set_count(int32_t value)
1898 {
1899         set(_handle, offset_count, value);
1900 }
1901
1902
1903 /**
1904  * OpenJDK java/lang/Thread
1905  *
1906  * Object layout:
1907  *
1908  * 0.  object header
1909  * 1.  char[]                                    name;
1910  * 2.  int                                       priority;
1911  * 3.  java_lang_Thread                          threadQ;
1912  * 4.  long                                      eetop;
1913  * 5.  boolean                                   single_step;
1914  * 6.  boolean                                   daemon;
1915  * 7.  boolean                                   stillborn;
1916  * 8.  java_lang_Runnable                        target;
1917  * 9.  java_lang_ThreadGroup                     group;
1918  * 10. java_lang_ClassLoader                     contextClassLoader;
1919  * 11. java_security_AccessControlContext        inheritedAccessControlContext;
1920  * 12. java_lang_ThreadLocal_ThreadLocalMap      threadLocals;
1921  * 13. java_lang_ThreadLocal_ThreadLocalMap      inheritableThreadLocals;
1922  * 14. long                                      stackSize;
1923  * 15. long                                      nativeParkEventPointer;
1924  * 16. long                                      tid;
1925  * 17. int                                       threadStatus;
1926  * 18. java_lang_Object                          parkBlocker;
1927  * 19. sun_nio_ch_Interruptible                  blocker;
1928  * 20. java_lang_Object                          blockerLock;
1929  * 21. boolean                                   stopBeforeStart;
1930  * 22. java_lang_Throwable                       throwableFromStop;
1931  * 23. java.lang.Thread.UncaughtExceptionHandler uncaughtExceptionHandler;
1932  */
1933 class java_lang_Thread : public java_lang_Object, private FieldAccess {
1934 private:
1935         // Static offsets of the object's instance fields.
1936         // TODO These offsets need to be checked on VM startup.
1937         static const off_t offset_name                          = MEMORY_ALIGN(sizeof(java_object_t),                                  SIZEOF_VOID_P);
1938         static const off_t offset_priority                      = MEMORY_ALIGN(offset_name                          + SIZEOF_VOID_P,   sizeof(int32_t));
1939         static const off_t offset_threadQ                       = MEMORY_ALIGN(offset_priority                      + sizeof(int32_t), SIZEOF_VOID_P);
1940         static const off_t offset_eetop                         = MEMORY_ALIGN(offset_threadQ                       + SIZEOF_VOID_P,   sizeof(int64_t));
1941         static const off_t offset_single_step                   = MEMORY_ALIGN(offset_eetop                         + sizeof(int64_t), sizeof(int32_t));
1942         static const off_t offset_daemon                        = MEMORY_ALIGN(offset_single_step                   + sizeof(int32_t), sizeof(int32_t));
1943         static const off_t offset_stillborn                     = MEMORY_ALIGN(offset_daemon                        + sizeof(int32_t), sizeof(int32_t));
1944         static const off_t offset_target                        = MEMORY_ALIGN(offset_stillborn                     + sizeof(int32_t), SIZEOF_VOID_P);
1945         static const off_t offset_group                         = MEMORY_ALIGN(offset_target                        + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1946         static const off_t offset_contextClassLoader            = MEMORY_ALIGN(offset_group                         + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1947         static const off_t offset_inheritedAccessControlContext = MEMORY_ALIGN(offset_contextClassLoader            + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1948         static const off_t offset_threadLocals                  = MEMORY_ALIGN(offset_inheritedAccessControlContext + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1949         static const off_t offset_inheritableThreadLocals       = MEMORY_ALIGN(offset_threadLocals                  + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1950         static const off_t offset_stackSize                     = MEMORY_ALIGN(offset_inheritableThreadLocals       + SIZEOF_VOID_P,   sizeof(int64_t));
1951         static const off_t offset_nativeParkEventPointer        = MEMORY_ALIGN(offset_stackSize                     + sizeof(int64_t), sizeof(int64_t));
1952         static const off_t offset_tid                           = MEMORY_ALIGN(offset_nativeParkEventPointer        + sizeof(int64_t), sizeof(int64_t));
1953         static const off_t offset_threadStatus                  = MEMORY_ALIGN(offset_tid                           + sizeof(int64_t), sizeof(int32_t));
1954         static const off_t offset_parkBlocker                   = MEMORY_ALIGN(offset_threadStatus                  + sizeof(int32_t), SIZEOF_VOID_P);
1955         static const off_t offset_blocker                       = MEMORY_ALIGN(offset_parkBlocker                   + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1956         static const off_t offset_blockerLock                   = MEMORY_ALIGN(offset_blocker                       + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1957         static const off_t offset_stopBeforeStart               = MEMORY_ALIGN(offset_blockerLock                   + SIZEOF_VOID_P,   sizeof(int32_t));
1958         static const off_t offset_throwableFromStop             = MEMORY_ALIGN(offset_stopBeforeStart               + sizeof(int32_t), SIZEOF_VOID_P);
1959         static const off_t offset_uncaughtExceptionHandler      = MEMORY_ALIGN(offset_throwableFromStop             + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1960
1961 public:
1962         java_lang_Thread(java_handle_t* h) : java_lang_Object(h) {}
1963 //      java_lang_Thread(threadobject* t);
1964
1965         // Getters.
1966         int32_t        get_priority                () const;
1967         int32_t        get_daemon                  () const;
1968         java_handle_t* get_group                   () const;
1969         java_handle_t* get_uncaughtExceptionHandler() const;
1970
1971         // Setters.
1972         void set_priority    (int32_t value);
1973         void set_group       (java_handle_t* value);
1974         void set_threadStatus(int32_t value);
1975 };
1976
1977
1978 inline int32_t java_lang_Thread::get_priority() const
1979 {
1980         return get<int32_t>(_handle, offset_priority);
1981 }
1982
1983 inline int32_t java_lang_Thread::get_daemon() const
1984 {
1985         return get<int32_t>(_handle, offset_daemon);
1986 }
1987
1988 inline java_handle_t* java_lang_Thread::get_group() const
1989 {
1990         return get<java_handle_t*>(_handle, offset_group);
1991 }
1992
1993 inline java_handle_t* java_lang_Thread::get_uncaughtExceptionHandler() const
1994 {
1995         return get<java_handle_t*>(_handle, offset_uncaughtExceptionHandler);
1996 }
1997
1998
1999 inline void java_lang_Thread::set_priority(int32_t value)
2000 {
2001         set(_handle, offset_priority, value);
2002 }
2003
2004 inline void java_lang_Thread::set_group(java_handle_t* value)
2005 {
2006         set(_handle, offset_group, value);
2007 }
2008
2009 inline void java_lang_Thread::set_threadStatus(int32_t value)
2010 {
2011         set(_handle, offset_threadStatus, value);
2012 }
2013
2014
2015
2016 /**
2017  * OpenJDK java/lang/Throwable
2018  *
2019  * Object layout:
2020  *
2021  * 0. object header
2022  * 1. java.lang.Object              backtrace;
2023  * 2. java.lang.String              detailMessage;
2024  * 3. java.lang.Throwable           cause;
2025  * 4. java.lang.StackTraceElement[] stackTrace;
2026  */
2027 class java_lang_Throwable : public java_lang_Object, private FieldAccess {
2028 private:
2029         // Static offsets of the object's instance fields.
2030         // TODO These offsets need to be checked on VM startup.
2031         static const off_t offset_backtrace     = MEMORY_ALIGN(sizeof(java_object_t),                SIZEOF_VOID_P);
2032         static const off_t offset_detailMessage = MEMORY_ALIGN(offset_backtrace     + SIZEOF_VOID_P, SIZEOF_VOID_P);
2033         static const off_t offset_cause         = MEMORY_ALIGN(offset_detailMessage + SIZEOF_VOID_P, SIZEOF_VOID_P);
2034         static const off_t offset_stackTrace    = MEMORY_ALIGN(offset_cause         + SIZEOF_VOID_P, SIZEOF_VOID_P);
2035
2036 public:
2037         java_lang_Throwable(java_handle_t* h) : java_lang_Object(h) {}
2038         java_lang_Throwable(java_handle_t* h, java_handle_bytearray_t* backtrace);
2039
2040         // Getters.
2041         java_handle_bytearray_t* get_backtrace    () const;
2042         java_handle_t*           get_detailMessage() const;
2043         java_handle_t*           get_cause        () const;
2044
2045         // Setters.
2046         void set_backtrace(java_handle_bytearray_t* value);
2047 };
2048
2049
2050 inline java_lang_Throwable::java_lang_Throwable(java_handle_t* h, java_handle_bytearray_t* backtrace) : java_lang_Object(h)
2051 {
2052         set_backtrace(backtrace);
2053 }
2054
2055
2056 inline java_handle_bytearray_t* java_lang_Throwable::get_backtrace() const
2057 {
2058         return get<java_handle_bytearray_t*>(_handle, offset_backtrace);
2059 }
2060
2061 inline java_handle_t* java_lang_Throwable::get_detailMessage() const
2062 {
2063         return get<java_handle_t*>(_handle, offset_detailMessage);
2064 }
2065
2066 inline java_handle_t* java_lang_Throwable::get_cause() const
2067 {
2068         return get<java_handle_t*>(_handle, offset_cause);
2069 }
2070
2071
2072 inline void java_lang_Throwable::set_backtrace(java_handle_bytearray_t* value)
2073 {
2074         set(_handle, offset_backtrace, value);
2075 }
2076
2077
2078 /**
2079  * OpenJDK java/lang/reflect/Constructor
2080  *
2081  * Object layout:
2082  *
2083  * 0.  object header
2084  * 1.  boolean                                               override;
2085  * 2.  java.lang.Class                                       clazz;
2086  * 3.  int                                                   slot;
2087  * 4.  java.lang.Class[]                                     parameterTypes;
2088  * 5.  java.lang.Class[]                                     exceptionTypes;
2089  * 6.  int                                                   modifiers;
2090  * 7.  java.lang.String                                      signature;
2091  * 8.  sun.reflect.generics.repository.ConstructorRepository genericInfo;
2092  * 9.  byte[]                                                annotations;
2093  * 10. byte[]                                                parameterAnnotations;
2094  * 11. java.lang.Class                                       securityCheckCache;
2095  * 12. sun.reflect.ConstructorAccessor                       constructorAccessor;
2096  * 13. java.lang.reflect.Constructor                         root;
2097  * 14. java.util.Map                                         declaredAnnotations;
2098  */
2099 class java_lang_reflect_Constructor : public java_lang_Object, private FieldAccess {
2100 private:
2101         // Static offsets of the object's instance fields.
2102         // TODO These offsets need to be checked on VM startup.
2103         static const off_t offset_override             = MEMORY_ALIGN(sizeof(java_object_t),                         sizeof(int32_t));
2104         static const off_t offset_clazz                = MEMORY_ALIGN(offset_override             + sizeof(int32_t), SIZEOF_VOID_P);
2105         static const off_t offset_slot                 = MEMORY_ALIGN(offset_clazz                + SIZEOF_VOID_P,   sizeof(int32_t));
2106         static const off_t offset_parameterTypes       = MEMORY_ALIGN(offset_slot                 + sizeof(int32_t), SIZEOF_VOID_P);
2107         static const off_t offset_exceptionTypes       = MEMORY_ALIGN(offset_parameterTypes       + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2108         static const off_t offset_modifiers            = MEMORY_ALIGN(offset_exceptionTypes       + SIZEOF_VOID_P,   sizeof(int32_t));
2109         static const off_t offset_signature            = MEMORY_ALIGN(offset_modifiers            + sizeof(int32_t), SIZEOF_VOID_P);
2110         static const off_t offset_genericInfo          = MEMORY_ALIGN(offset_signature            + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2111         static const off_t offset_annotations          = MEMORY_ALIGN(offset_genericInfo          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2112         static const off_t offset_parameterAnnotations = MEMORY_ALIGN(offset_annotations          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2113         static const off_t offset_securityCheckCache   = MEMORY_ALIGN(offset_parameterAnnotations + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2114         static const off_t offset_constructorAccessor  = MEMORY_ALIGN(offset_securityCheckCache   + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2115         static const off_t offset_root                 = MEMORY_ALIGN(offset_constructorAccessor  + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2116         static const off_t offset_declaredAnnotations  = MEMORY_ALIGN(offset_root                 + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2117
2118 public:
2119         java_lang_reflect_Constructor(java_handle_t* h) : java_lang_Object(h) {}
2120         java_lang_reflect_Constructor(methodinfo* m);
2121
2122         java_handle_t* new_instance(java_handle_objectarray_t* args);
2123
2124         // Getters.
2125         int32_t                  get_override   () const;
2126         classinfo*               get_clazz      () const;
2127         int32_t                  get_slot       () const;
2128         java_handle_bytearray_t* get_annotations() const;
2129
2130         // Setters.
2131         void set_clazz               (classinfo* value);
2132         void set_slot                (int32_t value);
2133         void set_parameterTypes      (java_handle_objectarray_t* value);
2134         void set_exceptionTypes      (java_handle_objectarray_t* value);
2135         void set_modifiers           (int32_t value);
2136         void set_signature           (java_handle_t* value);
2137         void set_annotations         (java_handle_bytearray_t* value);
2138         void set_parameterAnnotations(java_handle_bytearray_t* value);
2139
2140         // Convenience functions.
2141         methodinfo* get_method();
2142 };
2143
2144
2145 inline java_lang_reflect_Constructor::java_lang_reflect_Constructor(methodinfo* m)
2146 {
2147         _handle = builtin_new(class_java_lang_reflect_Constructor);
2148
2149         if (is_null())
2150                 return;
2151
2152         int                        slot                 = m - m->clazz->methods;
2153         java_handle_objectarray_t* parameterTypes       = method_get_parametertypearray(m);
2154         java_handle_objectarray_t* exceptionTypes       = method_get_exceptionarray(m);
2155         java_handle_bytearray_t*   annotations          = method_get_annotations(m);
2156         java_handle_bytearray_t*   parameterAnnotations = method_get_parameterannotations(m);
2157
2158         set_clazz(m->clazz);
2159         set_slot(slot);
2160         set_parameterTypes(parameterTypes);
2161         set_exceptionTypes(exceptionTypes);
2162         set_modifiers(m->flags & ACC_CLASS_REFLECT_MASK);
2163         set_signature(m->signature ? javastring_new(m->signature) : NULL);
2164         set_annotations(annotations);
2165         set_parameterAnnotations(parameterAnnotations);
2166 }
2167
2168
2169 inline int32_t java_lang_reflect_Constructor::get_override() const
2170 {
2171         return get<int32_t>(_handle, offset_override);
2172 }
2173
2174 inline classinfo* java_lang_reflect_Constructor::get_clazz() const
2175 {
2176         return get<classinfo*>(_handle, offset_clazz);
2177 }
2178
2179 inline int32_t java_lang_reflect_Constructor::get_slot() const
2180 {
2181         return get<int32_t>(_handle, offset_slot);
2182 }
2183
2184 inline java_handle_bytearray_t* java_lang_reflect_Constructor::get_annotations() const
2185 {
2186         return get<java_handle_bytearray_t*>(_handle, offset_annotations);
2187 }
2188
2189
2190 inline void java_lang_reflect_Constructor::set_clazz(classinfo* value)
2191 {
2192         set(_handle, offset_clazz, value);
2193 }
2194
2195 inline void java_lang_reflect_Constructor::set_slot(int32_t value)
2196 {
2197         set(_handle, offset_slot, value);
2198 }
2199
2200 inline void java_lang_reflect_Constructor::set_parameterTypes(java_handle_objectarray_t* value)
2201 {
2202         set(_handle, offset_parameterTypes, value);
2203 }
2204
2205 inline void java_lang_reflect_Constructor::set_exceptionTypes(java_handle_objectarray_t* value)
2206 {
2207         set(_handle, offset_exceptionTypes, value);
2208 }
2209
2210 inline void java_lang_reflect_Constructor::set_modifiers(int32_t value)
2211 {
2212         set(_handle, offset_modifiers, value);
2213 }
2214
2215 inline void java_lang_reflect_Constructor::set_signature(java_handle_t* value)
2216 {
2217         set(_handle, offset_signature, value);
2218 }
2219
2220 inline void java_lang_reflect_Constructor::set_annotations(java_handle_bytearray_t* value)
2221 {
2222         set(_handle, offset_annotations, value);
2223 }
2224
2225 inline void java_lang_reflect_Constructor::set_parameterAnnotations(java_handle_bytearray_t* value)
2226 {
2227         set(_handle, offset_parameterAnnotations, value);
2228 }
2229
2230
2231 inline methodinfo* java_lang_reflect_Constructor::get_method()
2232 {
2233         classinfo*  c    = get_clazz();
2234         int32_t     slot = get_slot();
2235         methodinfo* m    = &(c->methods[slot]);
2236         return m;
2237 }
2238
2239
2240 /**
2241  * OpenJDK java/lang/reflect/Field
2242  *
2243  * Object layout:
2244  *
2245  * 0.  object header
2246  * 1.  boolean                                         override;
2247  * 2.  java.lang.Class                                 clazz;
2248  * 3.  int                                             slot;
2249  * 4.  java.lang.String                                name;
2250  * 5.  java.lang.Class                                 type;
2251  * 6.  int                                             modifiers;
2252  * 7.  java.lang.String                                signature;
2253  * 8.  sun.reflect.generics.repository.FieldRepository genericInfo;
2254  * 9.  byte[]                                          annotations;
2255  * 10. sun.reflect.FieldAccessor                       fieldAccessor;
2256  * 11. sun.reflect.FieldAccessor                       overrideFieldAccessor;
2257  * 12. java.lang.reflect.Field                         root;
2258  * 13. java.lang.Class                                 securityCheckCache;
2259  * 14. java.lang.Class                                 securityCheckTargetClassCache;
2260  * 15. java.util.Map                                   declaredAnnotations;
2261  */
2262 class java_lang_reflect_Field : public java_lang_Object, private FieldAccess {
2263 private:
2264         // Static offsets of the object's instance fields.
2265         // TODO These offsets need to be checked on VM startup.
2266         static const off_t offset_override                      = MEMORY_ALIGN(sizeof(java_object_t),                                  sizeof(int32_t));
2267         static const off_t offset_clazz                         = MEMORY_ALIGN(offset_override                      + sizeof(int32_t), SIZEOF_VOID_P);
2268         static const off_t offset_slot                          = MEMORY_ALIGN(offset_clazz                         + SIZEOF_VOID_P,   sizeof(int32_t));
2269         static const off_t offset_name                          = MEMORY_ALIGN(offset_slot                          + sizeof(int32_t), SIZEOF_VOID_P);
2270         static const off_t offset_type                          = MEMORY_ALIGN(offset_name                          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2271         static const off_t offset_modifiers                     = MEMORY_ALIGN(offset_type                          + SIZEOF_VOID_P,   sizeof(int32_t));
2272         static const off_t offset_signature                     = MEMORY_ALIGN(offset_modifiers                     + sizeof(int32_t), SIZEOF_VOID_P);
2273         static const off_t offset_genericInfo                   = MEMORY_ALIGN(offset_signature                     + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2274         static const off_t offset_annotations                   = MEMORY_ALIGN(offset_genericInfo                   + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2275         static const off_t offset_fieldAccessor                 = MEMORY_ALIGN(offset_annotations                   + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2276         static const off_t offset_overrideFieldAccessor         = MEMORY_ALIGN(offset_fieldAccessor                 + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2277         static const off_t offset_root                          = MEMORY_ALIGN(offset_overrideFieldAccessor         + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2278         static const off_t offset_securityCheckCache            = MEMORY_ALIGN(offset_root                          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2279         static const off_t offset_securityCheckTargetClassCache = MEMORY_ALIGN(offset_securityCheckCache            + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2280         static const off_t offset_declaredAnnotations           = MEMORY_ALIGN(offset_securityCheckTargetClassCache + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2281
2282 public:
2283         java_lang_reflect_Field(java_handle_t* h) : java_lang_Object(h) {}
2284         java_lang_reflect_Field(fieldinfo* f);
2285
2286         // Getters.
2287         int32_t                  get_override   () const;
2288         classinfo*               get_clazz      () const;
2289         int32_t                  get_slot       () const;
2290         java_handle_bytearray_t* get_annotations() const;
2291
2292         // Setters.
2293         void set_clazz      (classinfo* value);
2294         void set_slot       (int32_t value);
2295         void set_name       (java_handle_t* value);
2296         void set_type       (classinfo* value);
2297         void set_modifiers  (int32_t value);
2298         void set_signature  (java_handle_t* value);
2299         void set_annotations(java_handle_bytearray_t* value);
2300
2301         // Convenience functions.
2302         fieldinfo* get_field() const;
2303 };
2304
2305
2306 inline java_lang_reflect_Field::java_lang_reflect_Field(fieldinfo* f)
2307 {
2308         _handle = builtin_new(class_java_lang_reflect_Field);
2309
2310         // OOME.
2311         if (is_null())
2312                 return;
2313
2314         set_clazz(f->clazz);
2315         set_slot(f - f->clazz->fields);
2316         set_name(javastring_intern(javastring_new(f->name)));
2317         set_type(field_get_type(f));
2318         set_modifiers(f->flags);
2319         set_signature(f->signature ? javastring_new(f->signature) : NULL);
2320         set_annotations(field_get_annotations(f));
2321 }
2322
2323
2324 inline int32_t java_lang_reflect_Field::get_override() const
2325 {
2326         return get<int32_t>(_handle, offset_override);
2327 }
2328
2329 inline classinfo* java_lang_reflect_Field::get_clazz() const
2330 {
2331         return get<classinfo*>(_handle, offset_clazz);
2332 }
2333
2334 inline int32_t java_lang_reflect_Field::get_slot() const
2335 {
2336         return get<int32_t>(_handle, offset_slot);
2337 }
2338
2339 inline java_handle_bytearray_t* java_lang_reflect_Field::get_annotations() const
2340 {
2341         return get<java_handle_bytearray_t*>(_handle, offset_annotations);
2342 }
2343
2344
2345 inline void java_lang_reflect_Field::set_clazz(classinfo* value)
2346 {
2347         set(_handle, offset_clazz, value);
2348 }
2349
2350 inline void java_lang_reflect_Field::set_slot(int32_t value)
2351 {
2352         set(_handle, offset_slot, value);
2353 }
2354
2355 inline void java_lang_reflect_Field::set_name(java_handle_t* value)
2356 {
2357         set(_handle, offset_name, value);
2358 }
2359
2360 inline void java_lang_reflect_Field::set_type(classinfo* value)
2361 {
2362         set(_handle, offset_type, value);
2363 }
2364
2365 inline void java_lang_reflect_Field::set_modifiers(int32_t value)
2366 {
2367         set(_handle, offset_modifiers, value);
2368 }
2369
2370 inline void java_lang_reflect_Field::set_signature(java_handle_t* value)
2371 {
2372         set(_handle, offset_signature, value);
2373 }
2374
2375 inline void java_lang_reflect_Field::set_annotations(java_handle_bytearray_t* value)
2376 {
2377         set(_handle, offset_annotations, value);
2378 }
2379
2380
2381 inline fieldinfo* java_lang_reflect_Field::get_field() const
2382 {
2383         classinfo* c    = get_clazz();
2384         int32_t    slot = get_slot();
2385         fieldinfo* f    = &(c->fields[slot]);
2386         return f;
2387 }
2388
2389
2390 /**
2391  * OpenJDK java/lang/reflect/Method
2392  *
2393  * Object layout:
2394  *
2395  * 0.  object header
2396  * 1.  boolean                                               override;
2397  * 2.  java.lang.Class                                       clazz;
2398  * 3.  int                                                   slot;
2399  * 4.  java.lang.String                                      name;
2400  * 5.  java.lang.Class                                       returnType;
2401  * 6.  java.lang.Class[]                                     parameterTypes;
2402  * 7.  java.lang.Class[]                                     exceptionTypes;
2403  * 8.  int                                                   modifiers;
2404  * 9.  java.lang.String                                      signature;
2405  * 10  sun.reflect.generics.repository.ConstructorRepository genericInfo;
2406  * 11. byte[]                                                annotations;
2407  * 12. byte[]                                                parameterAnnotations;
2408  * 13. byte[]                                                annotationDefault;
2409  * 14. sun.reflect.MethodAccessor                            methodAccessor;
2410  * 15. java.lang.reflect.Method                              root;
2411  * 16. java.lang.Class                                       securityCheckCache;
2412  * 17. java.lang.Class                                       securityCheckTargetClassCache;
2413  * 18. java.util.Map                                         declaredAnnotations;
2414  */
2415 class java_lang_reflect_Method : public java_lang_Object, private FieldAccess {
2416 private:
2417         // Static offsets of the object's instance fields.
2418         // TODO These offsets need to be checked on VM startup.
2419         static const off_t offset_override                      = MEMORY_ALIGN(sizeof(java_object_t),                                  sizeof(int32_t));
2420         static const off_t offset_clazz                         = MEMORY_ALIGN(offset_override                      + sizeof(int32_t), SIZEOF_VOID_P);
2421         static const off_t offset_slot                          = MEMORY_ALIGN(offset_clazz                         + SIZEOF_VOID_P,   sizeof(int32_t));
2422         static const off_t offset_name                          = MEMORY_ALIGN(offset_slot                          + sizeof(int32_t), SIZEOF_VOID_P);
2423         static const off_t offset_returnType                    = MEMORY_ALIGN(offset_name                          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2424         static const off_t offset_parameterTypes                = MEMORY_ALIGN(offset_returnType                    + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2425         static const off_t offset_exceptionTypes                = MEMORY_ALIGN(offset_parameterTypes                + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2426         static const off_t offset_modifiers                     = MEMORY_ALIGN(offset_exceptionTypes                + SIZEOF_VOID_P,   sizeof(int32_t));
2427         static const off_t offset_signature                     = MEMORY_ALIGN(offset_modifiers                     + sizeof(int32_t), SIZEOF_VOID_P);
2428         static const off_t offset_genericInfo                   = MEMORY_ALIGN(offset_signature                     + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2429         static const off_t offset_annotations                   = MEMORY_ALIGN(offset_genericInfo                   + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2430         static const off_t offset_parameterAnnotations          = MEMORY_ALIGN(offset_annotations                   + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2431         static const off_t offset_annotationDefault             = MEMORY_ALIGN(offset_parameterAnnotations          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2432         static const off_t offset_methodAccessor                = MEMORY_ALIGN(offset_annotationDefault             + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2433         static const off_t offset_root                          = MEMORY_ALIGN(offset_methodAccessor                + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2434         static const off_t offset_securityCheckCache            = MEMORY_ALIGN(offset_root                          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2435         static const off_t offset_securityCheckTargetClassCache = MEMORY_ALIGN(offset_securityCheckCache            + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2436         static const off_t offset_declaredAnnotations           = MEMORY_ALIGN(offset_securityCheckTargetClassCache + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2437
2438 public:
2439         java_lang_reflect_Method(java_handle_t* h) : java_lang_Object(h) {}
2440         java_lang_reflect_Method(methodinfo* m);
2441
2442         java_handle_t* invoke(java_handle_t* o, java_handle_objectarray_t* args);
2443
2444         // Getters.
2445         int32_t                  get_override            () const;
2446         classinfo*               get_clazz               () const;
2447         int32_t                  get_slot                () const;
2448         java_handle_bytearray_t* get_annotations         () const;
2449         java_handle_bytearray_t* get_parameterAnnotations() const;
2450         java_handle_bytearray_t* get_annotationDefault   () const;
2451
2452         // Setters.
2453
2454         // Convenience functions.
2455         methodinfo* get_method() const;
2456 };
2457
2458
2459 inline java_lang_reflect_Method::java_lang_reflect_Method(methodinfo* m)
2460 {
2461         _handle = builtin_new(class_java_lang_reflect_Method);
2462
2463         if (is_null())
2464                 return;
2465
2466         set(_handle, offset_clazz,                m->clazz);
2467         set(_handle, offset_slot,                 (int32_t) (m - m->clazz->methods)); // This cast is important (see PR100).
2468         set(_handle, offset_name,                 javastring_intern(javastring_new(m->name)));
2469         set(_handle, offset_returnType,           method_returntype_get(m));
2470         set(_handle, offset_parameterTypes,       method_get_parametertypearray(m));
2471         set(_handle, offset_exceptionTypes,       method_get_exceptionarray(m));
2472         set(_handle, offset_modifiers,            (int32_t) (m->flags & ACC_CLASS_REFLECT_MASK));
2473         set(_handle, offset_signature,            m->signature ? javastring_new(m->signature) : NULL);
2474         set(_handle, offset_annotations,          method_get_annotations(m));
2475         set(_handle, offset_parameterAnnotations, method_get_parameterannotations(m));
2476         set(_handle, offset_annotationDefault,    method_get_annotationdefault(m));
2477 }
2478
2479
2480 inline int32_t java_lang_reflect_Method::get_override() const
2481 {
2482         return get<int32_t>(_handle, offset_override);
2483 }
2484
2485 inline classinfo* java_lang_reflect_Method::get_clazz() const
2486 {
2487         return get<classinfo*>(_handle, offset_clazz);
2488 }
2489
2490 inline int32_t java_lang_reflect_Method::get_slot() const
2491 {
2492         return get<int32_t>(_handle, offset_slot);
2493 }
2494
2495 inline java_handle_bytearray_t* java_lang_reflect_Method::get_annotations() const
2496 {
2497         return get<java_handle_bytearray_t*>(_handle, offset_annotations);
2498 }
2499
2500 inline java_handle_bytearray_t* java_lang_reflect_Method::get_parameterAnnotations() const
2501 {
2502         return get<java_handle_bytearray_t*>(_handle, offset_parameterAnnotations);
2503 }
2504
2505 inline java_handle_bytearray_t* java_lang_reflect_Method::get_annotationDefault() const
2506 {
2507         return get<java_handle_bytearray_t*>(_handle, offset_annotationDefault);
2508 }
2509
2510
2511 inline methodinfo* java_lang_reflect_Method::get_method() const
2512 {
2513         classinfo*  c    = get_clazz();
2514         int32_t     slot = get_slot();
2515         methodinfo* m    = &(c->methods[slot]);
2516         return m;
2517 }
2518
2519
2520 /**
2521  * OpenJDK java/nio/Buffer
2522  *
2523  * Object layout:
2524  *
2525  * 0. object header
2526  * 1. int  mark;
2527  * 2. int  position;
2528  * 3. int  limit;
2529  * 4. int  capacity;
2530  * 5. long address;
2531  */
2532 class java_nio_Buffer : public java_lang_Object, private FieldAccess {
2533 private:
2534         // Static offsets of the object's instance fields.
2535         // TODO These offsets need to be checked on VM startup.
2536         static const off_t offset_mark     = MEMORY_ALIGN(sizeof(java_object_t),          sizeof(int32_t));
2537         static const off_t offset_position = MEMORY_ALIGN(offset_mark     + sizeof(int32_t), sizeof(int32_t));
2538         static const off_t offset_limit    = MEMORY_ALIGN(offset_position + sizeof(int32_t), sizeof(int32_t));
2539         static const off_t offset_capacity = MEMORY_ALIGN(offset_limit    + sizeof(int32_t), sizeof(int32_t));
2540         static const off_t offset_address  = MEMORY_ALIGN(offset_capacity + sizeof(int32_t), sizeof(int64_t));
2541
2542 public:
2543         java_nio_Buffer(java_handle_t* h) : java_lang_Object(h) {}
2544
2545         // Getters.
2546         void* get_address() const;
2547 };
2548
2549
2550 inline void* java_nio_Buffer::get_address() const
2551 {
2552         return get<void*>(_handle, offset_address);
2553 }
2554
2555 #endif // WITH_JAVA_RUNTIME_LIBRARY_OPENJDK
2556
2557
2558 #if defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
2559
2560 /**
2561  * CLDC 1.1 com/sun/cldchi/jvm/FileDescriptor
2562  *
2563  * Object layout:
2564  *
2565  * 0. object header
2566  * 1. long   pointer;
2567  * 2. int    position;
2568  * 3. int    length;
2569  */
2570 class com_sun_cldchi_jvm_FileDescriptor : public java_lang_Object, private FieldAccess {
2571 private:
2572         // Static offsets of the object's instance fields.
2573         // TODO These offsets need to be checked on VM startup.
2574         static const off_t offset_pointer  = MEMORY_ALIGN(sizeof(java_object_t),             sizeof(int64_t));
2575         static const off_t offset_position = MEMORY_ALIGN(offset_pointer  + sizeof(int64_t), sizeof(int32_t));
2576         static const off_t offset_length   = MEMORY_ALIGN(offset_position + sizeof(int32_t), sizeof(int32_t));
2577
2578 public:
2579         com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h) : java_lang_Object(h) {}
2580         com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h, int64_t pointer, int32_t position, int32_t length);
2581         com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h, com_sun_cldchi_jvm_FileDescriptor& fd);
2582
2583         // Getters.
2584         int64_t get_pointer () const;
2585         int32_t get_position() const;
2586         int32_t get_length  () const;
2587
2588         // Setters.
2589         void set_pointer (int64_t value);
2590         void set_position(int32_t value);
2591         void set_length  (int32_t value);
2592 };
2593
2594
2595 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)
2596 {
2597         set_pointer(pointer);
2598         set_position(position);
2599         set_length(length);
2600 }
2601
2602 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)
2603 {
2604         com_sun_cldchi_jvm_FileDescriptor(h, fd.get_pointer(), fd.get_position(), fd.get_length());
2605 }
2606
2607
2608 inline int64_t com_sun_cldchi_jvm_FileDescriptor::get_pointer() const
2609 {
2610         return get<int64_t>(_handle, offset_pointer);
2611 }
2612
2613 inline int32_t com_sun_cldchi_jvm_FileDescriptor::get_position() const
2614 {
2615         return get<int32_t>(_handle, offset_position);
2616 }
2617
2618 inline int32_t com_sun_cldchi_jvm_FileDescriptor::get_length() const
2619 {
2620         return get<int32_t>(_handle, offset_length);
2621 }
2622
2623
2624 inline void com_sun_cldchi_jvm_FileDescriptor::set_pointer(int64_t value)
2625 {
2626         set(_handle, offset_pointer, value);
2627 }
2628
2629 inline void com_sun_cldchi_jvm_FileDescriptor::set_position(int32_t value)
2630 {
2631         set(_handle, offset_position, value);
2632 }
2633
2634 inline void com_sun_cldchi_jvm_FileDescriptor::set_length(int32_t value)
2635 {
2636         set(_handle, offset_length, value);
2637 }
2638
2639
2640 /**
2641  * CLDC 1.1 java/lang/String
2642  *
2643  * Object layout:
2644  *
2645  * 0. object header
2646  * 1. char[] value;
2647  * 2. int    offset;
2648  * 3. int    count;
2649  */
2650 class java_lang_String : public java_lang_Object, private FieldAccess {
2651 private:
2652         // Static offsets of the object's instance fields.
2653         // TODO These offsets need to be checked on VM startup.
2654         static const off_t offset_value  = MEMORY_ALIGN(sizeof(java_object_t),           SIZEOF_VOID_P);
2655         static const off_t offset_offset = MEMORY_ALIGN(offset_value  + SIZEOF_VOID_P,   sizeof(int32_t));
2656         static const off_t offset_count  = MEMORY_ALIGN(offset_offset + sizeof(int32_t), sizeof(int32_t));
2657
2658 public:
2659         java_lang_String(java_handle_t* h) : java_lang_Object(h) {}
2660         java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset = 0);
2661
2662         // Getters.
2663         java_handle_chararray_t* get_value () const;
2664         int32_t                  get_offset() const;
2665         int32_t                  get_count () const;
2666
2667         // Setters.
2668         void set_value (java_handle_chararray_t* value);
2669         void set_offset(int32_t value);
2670         void set_count (int32_t value);
2671 };
2672
2673
2674 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)
2675 {
2676         set_value(value);
2677         set_offset(offset);
2678         set_count(count);
2679 }
2680
2681 inline java_handle_chararray_t* java_lang_String::get_value() const
2682 {
2683         return get<java_handle_chararray_t*>(_handle, offset_value);
2684 }
2685
2686 inline int32_t java_lang_String::get_offset() const
2687 {
2688         return get<int32_t>(_handle, offset_offset);
2689 }
2690
2691 inline int32_t java_lang_String::get_count() const
2692 {
2693         return get<int32_t>(_handle, offset_count);
2694 }
2695
2696 inline void java_lang_String::set_value(java_handle_chararray_t* value)
2697 {
2698         set(_handle, offset_value, value);
2699 }
2700
2701 inline void java_lang_String::set_offset(int32_t value)
2702 {
2703         set(_handle, offset_offset, value);
2704 }
2705
2706 inline void java_lang_String::set_count(int32_t value)
2707 {
2708         set(_handle, offset_count, value);
2709 }
2710
2711
2712 /**
2713  * CLDC 1.1 java/lang/Thread
2714  *
2715  * Object layout:
2716  *
2717  * 0. object header
2718  * 1. int                priority;
2719  * 2. java.lang.Runnable runnable;
2720  * 3. java.lang.Object   vm_thread;
2721  * 4. int                is_terminated;
2722  * 5. int                is_stillborn;
2723  * 6. char[]             name;
2724  */
2725 class java_lang_Thread : public java_lang_Object, private FieldAccess {
2726 private:
2727         // Static offsets of the object's instance fields.
2728         // TODO These offsets need to be checked on VM startup.
2729         static const off_t offset_priority      = MEMORY_ALIGN(sizeof(java_object_t),              sizeof(int32_t));
2730         static const off_t offset_runnable      = MEMORY_ALIGN(offset_priority      + sizeof(int32_t), SIZEOF_VOID_P);
2731         static const off_t offset_vm_thread     = MEMORY_ALIGN(offset_runnable      + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2732         static const off_t offset_is_terminated = MEMORY_ALIGN(offset_vm_thread     + SIZEOF_VOID_P,   sizeof(int32_t));
2733         static const off_t offset_is_stillborn  = MEMORY_ALIGN(offset_is_terminated + sizeof(int32_t), sizeof(int32_t));
2734         static const off_t offset_name          = MEMORY_ALIGN(offset_is_stillborn  + sizeof(int32_t), SIZEOF_VOID_P);
2735
2736 public:
2737         java_lang_Thread(java_handle_t* h) : java_lang_Object(h) {}
2738 //      java_lang_Thread(threadobject* t);
2739
2740         // Getters.
2741         int32_t                  get_priority () const;
2742         threadobject*            get_vm_thread() const;
2743         java_handle_chararray_t* get_name     () const;
2744
2745         // Setters.
2746         void set_vm_thread(threadobject* value);
2747 };
2748
2749
2750 // inline java_lang_Thread::java_lang_Thread(threadobject* t) : java_lang_Object(h)
2751 // {
2752 //      java_lang_Thread(thread_get_object(t));
2753 // }
2754
2755
2756 inline int32_t java_lang_Thread::get_priority() const
2757 {
2758         return get<int32_t>(_handle, offset_priority);
2759 }
2760
2761 inline threadobject* java_lang_Thread::get_vm_thread() const
2762 {
2763         return get<threadobject*>(_handle, offset_vm_thread);
2764 }
2765
2766 inline java_handle_chararray_t* java_lang_Thread::get_name() const
2767 {
2768         return get<java_handle_chararray_t*>(_handle, offset_name);
2769 }
2770
2771
2772 inline void java_lang_Thread::set_vm_thread(threadobject* value)
2773 {
2774         set(_handle, offset_vm_thread, value);
2775 }
2776
2777
2778 /**
2779  * CLDC 1.1 java/lang/Throwable
2780  *
2781  * Object layout:
2782  *
2783  * 0. object header
2784  * 1. java.lang.String detailMessage;
2785  * 2. java.lang.Object backtrace;
2786  */
2787 class java_lang_Throwable : public java_lang_Object, private FieldAccess {
2788 private:
2789         // Static offsets of the object's instance fields.
2790         // TODO These offsets need to be checked on VM startup.
2791         static const off_t offset_detailMessage = MEMORY_ALIGN(sizeof(java_object_t),                SIZEOF_VOID_P);
2792         static const off_t offset_backtrace     = MEMORY_ALIGN(offset_detailMessage + SIZEOF_VOID_P, SIZEOF_VOID_P);
2793
2794 public:
2795         java_lang_Throwable(java_handle_t* h) : java_lang_Object(h) {}
2796
2797         // Getters.
2798         java_handle_t*           get_detailMessage() const;
2799         java_handle_bytearray_t* get_backtrace    () const;
2800
2801         // Setters.
2802         void set_backtrace(java_handle_bytearray_t* value);
2803 };
2804
2805
2806 inline java_handle_t* java_lang_Throwable::get_detailMessage() const
2807 {
2808         return get<java_handle_t*>(_handle, offset_detailMessage);
2809 }
2810
2811 inline java_handle_bytearray_t* java_lang_Throwable::get_backtrace() const
2812 {
2813         return get<java_handle_bytearray_t*>(_handle, offset_backtrace);
2814 }
2815
2816
2817 inline void java_lang_Throwable::set_backtrace(java_handle_bytearray_t* value)
2818 {
2819         set(_handle, offset_backtrace, value);
2820 }
2821
2822 #endif // WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1
2823
2824 #endif
2825
2826 #endif // _JAVAOBJECTS_HPP
2827
2828
2829 /*
2830  * These are local overrides for various environment variables in Emacs.
2831  * Please do not remove this and leave it at the end of the file, where
2832  * Emacs will automagically detect them.
2833  * ---------------------------------------------------------------------
2834  * Local variables:
2835  * mode: c++
2836  * indent-tabs-mode: t
2837  * c-basic-offset: 4
2838  * tab-width: 4
2839  * End:
2840  */