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