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