* src/threads/thread.cpp: Break a reference cycle.
[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         static off_t offset_me;
1973
1974 public:
1975         java_lang_Thread(java_handle_t* h) : java_lang_Object(h) {}
1976
1977         // Getters.
1978         int32_t        get_priority                () const;
1979         int32_t        get_daemon                  () const;
1980         java_handle_t* get_group                   () const;
1981         java_handle_t* get_uncaughtExceptionHandler() const;
1982
1983         // Setters.
1984         void set_priority    (int32_t value);
1985         void set_group       (java_handle_t* value);
1986         void set_threadStatus(int32_t value);
1987         void set_me          (java_handle_t* value);
1988
1989         // Offset initializers
1990         static void set_priority_offset(int32_t off)     { offset_priority = off; }
1991         static void set_daemon_offset(int32_t off)       { offset_daemon = off; }
1992         static void set_group_offset(int32_t off)        { offset_group = off; }
1993         static void set_uncaughtExceptionHandler_offset(int32_t off) { offset_uncaughtExceptionHandler = off; }
1994         static void set_threadStatus_offset(int32_t off) { offset_threadStatus = off; }
1995         static void set_me_offset(int32_t off) { offset_me = off; }
1996 };
1997
1998
1999 inline int32_t java_lang_Thread::get_priority() const
2000 {
2001         return get<int32_t>(_handle, offset_priority);
2002 }
2003
2004 inline int32_t java_lang_Thread::get_daemon() const
2005 {
2006         return get<int32_t>(_handle, offset_daemon);
2007 }
2008
2009 inline java_handle_t* java_lang_Thread::get_group() const
2010 {
2011         return get<java_handle_t*>(_handle, offset_group);
2012 }
2013
2014 inline java_handle_t* java_lang_Thread::get_uncaughtExceptionHandler() const
2015 {
2016         return get<java_handle_t*>(_handle, offset_uncaughtExceptionHandler);
2017 }
2018
2019
2020 inline void java_lang_Thread::set_priority(int32_t value)
2021 {
2022         set(_handle, offset_priority, value);
2023 }
2024
2025 inline void java_lang_Thread::set_group(java_handle_t* value)
2026 {
2027         set(_handle, offset_group, value);
2028 }
2029
2030 inline void java_lang_Thread::set_threadStatus(int32_t value)
2031 {
2032         set(_handle, offset_threadStatus, value);
2033 }
2034
2035 inline void java_lang_Thread::set_me(java_handle_t* value)
2036 {
2037         set(_handle, offset_me, value);
2038 }
2039
2040
2041
2042 /**
2043  * OpenJDK java/lang/Throwable
2044  *
2045  * Object layout:
2046  *
2047  * 0. object header
2048  * 1. java.lang.Object              backtrace;
2049  * 2. java.lang.String              detailMessage;
2050  * 3. java.lang.Throwable           cause;
2051  * 4. java.lang.StackTraceElement[] stackTrace;
2052  */
2053 class java_lang_Throwable : public java_lang_Object, private FieldAccess {
2054 private:
2055         // Static offsets of the object's instance fields.
2056         // TODO These offsets need to be checked on VM startup.
2057         static const off_t offset_backtrace     = MEMORY_ALIGN(sizeof(java_object_t),                SIZEOF_VOID_P);
2058         static const off_t offset_detailMessage = MEMORY_ALIGN(offset_backtrace     + SIZEOF_VOID_P, SIZEOF_VOID_P);
2059         static const off_t offset_cause         = MEMORY_ALIGN(offset_detailMessage + SIZEOF_VOID_P, SIZEOF_VOID_P);
2060         static const off_t offset_stackTrace    = MEMORY_ALIGN(offset_cause         + SIZEOF_VOID_P, SIZEOF_VOID_P);
2061
2062 public:
2063         java_lang_Throwable(java_handle_t* h) : java_lang_Object(h) {}
2064         java_lang_Throwable(java_handle_t* h, java_handle_bytearray_t* backtrace);
2065
2066         // Getters.
2067         java_handle_bytearray_t* get_backtrace    () const;
2068         java_handle_t*           get_detailMessage() const;
2069         java_handle_t*           get_cause        () const;
2070
2071         // Setters.
2072         void set_backtrace(java_handle_bytearray_t* value);
2073 };
2074
2075
2076 inline java_lang_Throwable::java_lang_Throwable(java_handle_t* h, java_handle_bytearray_t* backtrace) : java_lang_Object(h)
2077 {
2078         set_backtrace(backtrace);
2079 }
2080
2081
2082 inline java_handle_bytearray_t* java_lang_Throwable::get_backtrace() const
2083 {
2084         return get<java_handle_bytearray_t*>(_handle, offset_backtrace);
2085 }
2086
2087 inline java_handle_t* java_lang_Throwable::get_detailMessage() const
2088 {
2089         return get<java_handle_t*>(_handle, offset_detailMessage);
2090 }
2091
2092 inline java_handle_t* java_lang_Throwable::get_cause() const
2093 {
2094         return get<java_handle_t*>(_handle, offset_cause);
2095 }
2096
2097
2098 inline void java_lang_Throwable::set_backtrace(java_handle_bytearray_t* value)
2099 {
2100         set(_handle, offset_backtrace, value);
2101 }
2102
2103
2104 /**
2105  * OpenJDK java/lang/reflect/Constructor
2106  *
2107  * Object layout:
2108  *
2109  * 0.  object header
2110  * 1.  boolean                                               override;
2111  * 2.  java.lang.Class                                       clazz;
2112  * 3.  int                                                   slot;
2113  * 4.  java.lang.Class[]                                     parameterTypes;
2114  * 5.  java.lang.Class[]                                     exceptionTypes;
2115  * 6.  int                                                   modifiers;
2116  * 7.  java.lang.String                                      signature;
2117  * 8.  sun.reflect.generics.repository.ConstructorRepository genericInfo;
2118  * 9.  byte[]                                                annotations;
2119  * 10. byte[]                                                parameterAnnotations;
2120  * 11. java.lang.Class                                       securityCheckCache;
2121  * 12. sun.reflect.ConstructorAccessor                       constructorAccessor;
2122  * 13. java.lang.reflect.Constructor                         root;
2123  * 14. java.util.Map                                         declaredAnnotations;
2124  */
2125 class java_lang_reflect_Constructor : public java_lang_Object, private FieldAccess {
2126 private:
2127         // Static offsets of the object's instance fields.
2128         // TODO These offsets need to be checked on VM startup.
2129         static const off_t offset_override             = MEMORY_ALIGN(sizeof(java_object_t),                         sizeof(int32_t));
2130         static const off_t offset_clazz                = MEMORY_ALIGN(offset_override             + sizeof(int32_t), SIZEOF_VOID_P);
2131         static const off_t offset_slot                 = MEMORY_ALIGN(offset_clazz                + SIZEOF_VOID_P,   sizeof(int32_t));
2132         static const off_t offset_parameterTypes       = MEMORY_ALIGN(offset_slot                 + sizeof(int32_t), SIZEOF_VOID_P);
2133         static const off_t offset_exceptionTypes       = MEMORY_ALIGN(offset_parameterTypes       + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2134         static const off_t offset_modifiers            = MEMORY_ALIGN(offset_exceptionTypes       + SIZEOF_VOID_P,   sizeof(int32_t));
2135         static const off_t offset_signature            = MEMORY_ALIGN(offset_modifiers            + sizeof(int32_t), SIZEOF_VOID_P);
2136         static const off_t offset_genericInfo          = MEMORY_ALIGN(offset_signature            + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2137         static const off_t offset_annotations          = MEMORY_ALIGN(offset_genericInfo          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2138         static const off_t offset_parameterAnnotations = MEMORY_ALIGN(offset_annotations          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2139         static const off_t offset_securityCheckCache   = MEMORY_ALIGN(offset_parameterAnnotations + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2140         static const off_t offset_constructorAccessor  = MEMORY_ALIGN(offset_securityCheckCache   + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2141         static const off_t offset_root                 = MEMORY_ALIGN(offset_constructorAccessor  + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2142         static const off_t offset_declaredAnnotations  = MEMORY_ALIGN(offset_root                 + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2143
2144 public:
2145         java_lang_reflect_Constructor(java_handle_t* h) : java_lang_Object(h) {}
2146         java_lang_reflect_Constructor(methodinfo* m);
2147
2148         java_handle_t* new_instance(java_handle_objectarray_t* args);
2149
2150         // Getters.
2151         int32_t                  get_override   () const;
2152         classinfo*               get_clazz      () const;
2153         int32_t                  get_slot       () const;
2154         java_handle_bytearray_t* get_annotations() const;
2155
2156         // Setters.
2157         void set_clazz               (classinfo* value);
2158         void set_slot                (int32_t value);
2159         void set_parameterTypes      (java_handle_objectarray_t* value);
2160         void set_exceptionTypes      (java_handle_objectarray_t* value);
2161         void set_modifiers           (int32_t value);
2162         void set_signature           (java_handle_t* value);
2163         void set_annotations         (java_handle_bytearray_t* value);
2164         void set_parameterAnnotations(java_handle_bytearray_t* value);
2165
2166         // Convenience functions.
2167         methodinfo* get_method();
2168 };
2169
2170
2171 inline java_lang_reflect_Constructor::java_lang_reflect_Constructor(methodinfo* m)
2172 {
2173         _handle = builtin_new(class_java_lang_reflect_Constructor);
2174
2175         if (is_null())
2176                 return;
2177
2178         int                        slot                 = m - m->clazz->methods;
2179         java_handle_objectarray_t* parameterTypes       = method_get_parametertypearray(m);
2180         java_handle_objectarray_t* exceptionTypes       = method_get_exceptionarray(m);
2181         java_handle_bytearray_t*   annotations          = method_get_annotations(m);
2182         java_handle_bytearray_t*   parameterAnnotations = method_get_parameterannotations(m);
2183
2184         set_clazz(m->clazz);
2185         set_slot(slot);
2186         set_parameterTypes(parameterTypes);
2187         set_exceptionTypes(exceptionTypes);
2188         set_modifiers(m->flags & ACC_CLASS_REFLECT_MASK);
2189         set_signature(m->signature ? javastring_new(m->signature) : NULL);
2190         set_annotations(annotations);
2191         set_parameterAnnotations(parameterAnnotations);
2192 }
2193
2194
2195 inline int32_t java_lang_reflect_Constructor::get_override() const
2196 {
2197         return get<int32_t>(_handle, offset_override);
2198 }
2199
2200 inline classinfo* java_lang_reflect_Constructor::get_clazz() const
2201 {
2202         return get<classinfo*>(_handle, offset_clazz);
2203 }
2204
2205 inline int32_t java_lang_reflect_Constructor::get_slot() const
2206 {
2207         return get<int32_t>(_handle, offset_slot);
2208 }
2209
2210 inline java_handle_bytearray_t* java_lang_reflect_Constructor::get_annotations() const
2211 {
2212         return get<java_handle_bytearray_t*>(_handle, offset_annotations);
2213 }
2214
2215
2216 inline void java_lang_reflect_Constructor::set_clazz(classinfo* value)
2217 {
2218         set(_handle, offset_clazz, value);
2219 }
2220
2221 inline void java_lang_reflect_Constructor::set_slot(int32_t value)
2222 {
2223         set(_handle, offset_slot, value);
2224 }
2225
2226 inline void java_lang_reflect_Constructor::set_parameterTypes(java_handle_objectarray_t* value)
2227 {
2228         set(_handle, offset_parameterTypes, value);
2229 }
2230
2231 inline void java_lang_reflect_Constructor::set_exceptionTypes(java_handle_objectarray_t* value)
2232 {
2233         set(_handle, offset_exceptionTypes, value);
2234 }
2235
2236 inline void java_lang_reflect_Constructor::set_modifiers(int32_t value)
2237 {
2238         set(_handle, offset_modifiers, value);
2239 }
2240
2241 inline void java_lang_reflect_Constructor::set_signature(java_handle_t* value)
2242 {
2243         set(_handle, offset_signature, value);
2244 }
2245
2246 inline void java_lang_reflect_Constructor::set_annotations(java_handle_bytearray_t* value)
2247 {
2248         set(_handle, offset_annotations, value);
2249 }
2250
2251 inline void java_lang_reflect_Constructor::set_parameterAnnotations(java_handle_bytearray_t* value)
2252 {
2253         set(_handle, offset_parameterAnnotations, value);
2254 }
2255
2256
2257 inline methodinfo* java_lang_reflect_Constructor::get_method()
2258 {
2259         classinfo*  c    = get_clazz();
2260         int32_t     slot = get_slot();
2261         methodinfo* m    = &(c->methods[slot]);
2262         return m;
2263 }
2264
2265
2266 /**
2267  * OpenJDK java/lang/reflect/Field
2268  *
2269  * Object layout:
2270  *
2271  * 0.  object header
2272  * 1.  boolean                                         override;
2273  * 2.  java.lang.Class                                 clazz;
2274  * 3.  int                                             slot;
2275  * 4.  java.lang.String                                name;
2276  * 5.  java.lang.Class                                 type;
2277  * 6.  int                                             modifiers;
2278  * 7.  java.lang.String                                signature;
2279  * 8.  sun.reflect.generics.repository.FieldRepository genericInfo;
2280  * 9.  byte[]                                          annotations;
2281  * 10. sun.reflect.FieldAccessor                       fieldAccessor;
2282  * 11. sun.reflect.FieldAccessor                       overrideFieldAccessor;
2283  * 12. java.lang.reflect.Field                         root;
2284  * 13. java.lang.Class                                 securityCheckCache;
2285  * 14. java.lang.Class                                 securityCheckTargetClassCache;
2286  * 15. java.util.Map                                   declaredAnnotations;
2287  */
2288 class java_lang_reflect_Field : public java_lang_Object, private FieldAccess {
2289 private:
2290         // Static offsets of the object's instance fields.
2291         // TODO These offsets need to be checked on VM startup.
2292         static const off_t offset_override                      = MEMORY_ALIGN(sizeof(java_object_t),                                  sizeof(int32_t));
2293         static const off_t offset_clazz                         = MEMORY_ALIGN(offset_override                      + sizeof(int32_t), SIZEOF_VOID_P);
2294         static const off_t offset_slot                          = MEMORY_ALIGN(offset_clazz                         + SIZEOF_VOID_P,   sizeof(int32_t));
2295         static const off_t offset_name                          = MEMORY_ALIGN(offset_slot                          + sizeof(int32_t), SIZEOF_VOID_P);
2296         static const off_t offset_type                          = MEMORY_ALIGN(offset_name                          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2297         static const off_t offset_modifiers                     = MEMORY_ALIGN(offset_type                          + SIZEOF_VOID_P,   sizeof(int32_t));
2298         static const off_t offset_signature                     = MEMORY_ALIGN(offset_modifiers                     + sizeof(int32_t), SIZEOF_VOID_P);
2299         static const off_t offset_genericInfo                   = MEMORY_ALIGN(offset_signature                     + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2300         static const off_t offset_annotations                   = MEMORY_ALIGN(offset_genericInfo                   + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2301         static const off_t offset_fieldAccessor                 = MEMORY_ALIGN(offset_annotations                   + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2302         static const off_t offset_overrideFieldAccessor         = MEMORY_ALIGN(offset_fieldAccessor                 + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2303         static const off_t offset_root                          = MEMORY_ALIGN(offset_overrideFieldAccessor         + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2304         static const off_t offset_securityCheckCache            = MEMORY_ALIGN(offset_root                          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2305         static const off_t offset_securityCheckTargetClassCache = MEMORY_ALIGN(offset_securityCheckCache            + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2306         static const off_t offset_declaredAnnotations           = MEMORY_ALIGN(offset_securityCheckTargetClassCache + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2307
2308 public:
2309         java_lang_reflect_Field(java_handle_t* h) : java_lang_Object(h) {}
2310         java_lang_reflect_Field(fieldinfo* f);
2311
2312         // Getters.
2313         int32_t                  get_override   () const;
2314         classinfo*               get_clazz      () const;
2315         int32_t                  get_slot       () const;
2316         java_handle_bytearray_t* get_annotations() const;
2317
2318         // Setters.
2319         void set_clazz      (classinfo* value);
2320         void set_slot       (int32_t value);
2321         void set_name       (java_handle_t* value);
2322         void set_type       (classinfo* value);
2323         void set_modifiers  (int32_t value);
2324         void set_signature  (java_handle_t* value);
2325         void set_annotations(java_handle_bytearray_t* value);
2326
2327         // Convenience functions.
2328         fieldinfo* get_field() const;
2329 };
2330
2331
2332 inline java_lang_reflect_Field::java_lang_reflect_Field(fieldinfo* f)
2333 {
2334         _handle = builtin_new(class_java_lang_reflect_Field);
2335
2336         // OOME.
2337         if (is_null())
2338                 return;
2339
2340         set_clazz(f->clazz);
2341         set_slot(f - f->clazz->fields);
2342         set_name(javastring_intern(javastring_new(f->name)));
2343         set_type(field_get_type(f));
2344         set_modifiers(f->flags);
2345         set_signature(f->signature ? javastring_new(f->signature) : NULL);
2346         set_annotations(field_get_annotations(f));
2347 }
2348
2349
2350 inline int32_t java_lang_reflect_Field::get_override() const
2351 {
2352         return get<int32_t>(_handle, offset_override);
2353 }
2354
2355 inline classinfo* java_lang_reflect_Field::get_clazz() const
2356 {
2357         return get<classinfo*>(_handle, offset_clazz);
2358 }
2359
2360 inline int32_t java_lang_reflect_Field::get_slot() const
2361 {
2362         return get<int32_t>(_handle, offset_slot);
2363 }
2364
2365 inline java_handle_bytearray_t* java_lang_reflect_Field::get_annotations() const
2366 {
2367         return get<java_handle_bytearray_t*>(_handle, offset_annotations);
2368 }
2369
2370
2371 inline void java_lang_reflect_Field::set_clazz(classinfo* value)
2372 {
2373         set(_handle, offset_clazz, value);
2374 }
2375
2376 inline void java_lang_reflect_Field::set_slot(int32_t value)
2377 {
2378         set(_handle, offset_slot, value);
2379 }
2380
2381 inline void java_lang_reflect_Field::set_name(java_handle_t* value)
2382 {
2383         set(_handle, offset_name, value);
2384 }
2385
2386 inline void java_lang_reflect_Field::set_type(classinfo* value)
2387 {
2388         set(_handle, offset_type, value);
2389 }
2390
2391 inline void java_lang_reflect_Field::set_modifiers(int32_t value)
2392 {
2393         set(_handle, offset_modifiers, value);
2394 }
2395
2396 inline void java_lang_reflect_Field::set_signature(java_handle_t* value)
2397 {
2398         set(_handle, offset_signature, value);
2399 }
2400
2401 inline void java_lang_reflect_Field::set_annotations(java_handle_bytearray_t* value)
2402 {
2403         set(_handle, offset_annotations, value);
2404 }
2405
2406
2407 inline fieldinfo* java_lang_reflect_Field::get_field() const
2408 {
2409         classinfo* c    = get_clazz();
2410         int32_t    slot = get_slot();
2411         fieldinfo* f    = &(c->fields[slot]);
2412         return f;
2413 }
2414
2415
2416 /**
2417  * OpenJDK java/lang/reflect/Method
2418  *
2419  * Object layout:
2420  *
2421  * 0.  object header
2422  * 1.  boolean                                               override;
2423  * 2.  java.lang.Class                                       clazz;
2424  * 3.  int                                                   slot;
2425  * 4.  java.lang.String                                      name;
2426  * 5.  java.lang.Class                                       returnType;
2427  * 6.  java.lang.Class[]                                     parameterTypes;
2428  * 7.  java.lang.Class[]                                     exceptionTypes;
2429  * 8.  int                                                   modifiers;
2430  * 9.  java.lang.String                                      signature;
2431  * 10  sun.reflect.generics.repository.ConstructorRepository genericInfo;
2432  * 11. byte[]                                                annotations;
2433  * 12. byte[]                                                parameterAnnotations;
2434  * 13. byte[]                                                annotationDefault;
2435  * 14. sun.reflect.MethodAccessor                            methodAccessor;
2436  * 15. java.lang.reflect.Method                              root;
2437  * 16. java.lang.Class                                       securityCheckCache;
2438  * 17. java.lang.Class                                       securityCheckTargetClassCache;
2439  * 18. java.util.Map                                         declaredAnnotations;
2440  */
2441 class java_lang_reflect_Method : public java_lang_Object, private FieldAccess {
2442 private:
2443         // Static offsets of the object's instance fields.
2444         // TODO These offsets need to be checked on VM startup.
2445         static const off_t offset_override                      = MEMORY_ALIGN(sizeof(java_object_t),                                  sizeof(int32_t));
2446         static const off_t offset_clazz                         = MEMORY_ALIGN(offset_override                      + sizeof(int32_t), SIZEOF_VOID_P);
2447         static const off_t offset_slot                          = MEMORY_ALIGN(offset_clazz                         + SIZEOF_VOID_P,   sizeof(int32_t));
2448         static const off_t offset_name                          = MEMORY_ALIGN(offset_slot                          + sizeof(int32_t), SIZEOF_VOID_P);
2449         static const off_t offset_returnType                    = MEMORY_ALIGN(offset_name                          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2450         static const off_t offset_parameterTypes                = MEMORY_ALIGN(offset_returnType                    + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2451         static const off_t offset_exceptionTypes                = MEMORY_ALIGN(offset_parameterTypes                + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2452         static const off_t offset_modifiers                     = MEMORY_ALIGN(offset_exceptionTypes                + SIZEOF_VOID_P,   sizeof(int32_t));
2453         static const off_t offset_signature                     = MEMORY_ALIGN(offset_modifiers                     + sizeof(int32_t), SIZEOF_VOID_P);
2454         static const off_t offset_genericInfo                   = MEMORY_ALIGN(offset_signature                     + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2455         static const off_t offset_annotations                   = MEMORY_ALIGN(offset_genericInfo                   + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2456         static const off_t offset_parameterAnnotations          = MEMORY_ALIGN(offset_annotations                   + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2457         static const off_t offset_annotationDefault             = MEMORY_ALIGN(offset_parameterAnnotations          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2458         static const off_t offset_methodAccessor                = MEMORY_ALIGN(offset_annotationDefault             + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2459         static const off_t offset_root                          = MEMORY_ALIGN(offset_methodAccessor                + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2460         static const off_t offset_securityCheckCache            = MEMORY_ALIGN(offset_root                          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2461         static const off_t offset_securityCheckTargetClassCache = MEMORY_ALIGN(offset_securityCheckCache            + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2462         static const off_t offset_declaredAnnotations           = MEMORY_ALIGN(offset_securityCheckTargetClassCache + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2463
2464 public:
2465         java_lang_reflect_Method(java_handle_t* h) : java_lang_Object(h) {}
2466         java_lang_reflect_Method(methodinfo* m);
2467
2468         java_handle_t* invoke(java_handle_t* o, java_handle_objectarray_t* args);
2469
2470         // Getters.
2471         int32_t                  get_override            () const;
2472         classinfo*               get_clazz               () const;
2473         int32_t                  get_slot                () const;
2474         java_handle_bytearray_t* get_annotations         () const;
2475         java_handle_bytearray_t* get_parameterAnnotations() const;
2476         java_handle_bytearray_t* get_annotationDefault   () const;
2477
2478         // Setters.
2479
2480         // Convenience functions.
2481         methodinfo* get_method() const;
2482 };
2483
2484
2485 inline java_lang_reflect_Method::java_lang_reflect_Method(methodinfo* m)
2486 {
2487         _handle = builtin_new(class_java_lang_reflect_Method);
2488
2489         if (is_null())
2490                 return;
2491
2492         set(_handle, offset_clazz,                m->clazz);
2493         set(_handle, offset_slot,                 (int32_t) (m - m->clazz->methods)); // This cast is important (see PR100).
2494         set(_handle, offset_name,                 javastring_intern(javastring_new(m->name)));
2495         set(_handle, offset_returnType,           method_returntype_get(m));
2496         set(_handle, offset_parameterTypes,       method_get_parametertypearray(m));
2497         set(_handle, offset_exceptionTypes,       method_get_exceptionarray(m));
2498         set(_handle, offset_modifiers,            (int32_t) (m->flags & ACC_CLASS_REFLECT_MASK));
2499         set(_handle, offset_signature,            m->signature ? javastring_new(m->signature) : NULL);
2500         set(_handle, offset_annotations,          method_get_annotations(m));
2501         set(_handle, offset_parameterAnnotations, method_get_parameterannotations(m));
2502         set(_handle, offset_annotationDefault,    method_get_annotationdefault(m));
2503 }
2504
2505
2506 inline int32_t java_lang_reflect_Method::get_override() const
2507 {
2508         return get<int32_t>(_handle, offset_override);
2509 }
2510
2511 inline classinfo* java_lang_reflect_Method::get_clazz() const
2512 {
2513         return get<classinfo*>(_handle, offset_clazz);
2514 }
2515
2516 inline int32_t java_lang_reflect_Method::get_slot() const
2517 {
2518         return get<int32_t>(_handle, offset_slot);
2519 }
2520
2521 inline java_handle_bytearray_t* java_lang_reflect_Method::get_annotations() const
2522 {
2523         return get<java_handle_bytearray_t*>(_handle, offset_annotations);
2524 }
2525
2526 inline java_handle_bytearray_t* java_lang_reflect_Method::get_parameterAnnotations() const
2527 {
2528         return get<java_handle_bytearray_t*>(_handle, offset_parameterAnnotations);
2529 }
2530
2531 inline java_handle_bytearray_t* java_lang_reflect_Method::get_annotationDefault() const
2532 {
2533         return get<java_handle_bytearray_t*>(_handle, offset_annotationDefault);
2534 }
2535
2536
2537 inline methodinfo* java_lang_reflect_Method::get_method() const
2538 {
2539         classinfo*  c    = get_clazz();
2540         int32_t     slot = get_slot();
2541         methodinfo* m    = &(c->methods[slot]);
2542         return m;
2543 }
2544
2545
2546 /**
2547  * OpenJDK java/nio/Buffer
2548  *
2549  * Object layout:
2550  *
2551  * 0. object header
2552  * 1. int  mark;
2553  * 2. int  position;
2554  * 3. int  limit;
2555  * 4. int  capacity;
2556  * 5. long address;
2557  */
2558 class java_nio_Buffer : public java_lang_Object, private FieldAccess {
2559 private:
2560         // Static offsets of the object's instance fields.
2561         // TODO These offsets need to be checked on VM startup.
2562         static const off_t offset_mark     = MEMORY_ALIGN(sizeof(java_object_t),          sizeof(int32_t));
2563         static const off_t offset_position = MEMORY_ALIGN(offset_mark     + sizeof(int32_t), sizeof(int32_t));
2564         static const off_t offset_limit    = MEMORY_ALIGN(offset_position + sizeof(int32_t), sizeof(int32_t));
2565         static const off_t offset_capacity = MEMORY_ALIGN(offset_limit    + sizeof(int32_t), sizeof(int32_t));
2566         static const off_t offset_address  = MEMORY_ALIGN(offset_capacity + sizeof(int32_t), sizeof(int64_t));
2567
2568 public:
2569         java_nio_Buffer(java_handle_t* h) : java_lang_Object(h) {}
2570
2571         // Getters.
2572         void* get_address() const;
2573 };
2574
2575
2576 inline void* java_nio_Buffer::get_address() const
2577 {
2578         return get<void*>(_handle, offset_address);
2579 }
2580
2581 #endif // WITH_JAVA_RUNTIME_LIBRARY_OPENJDK
2582
2583
2584 #if defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
2585
2586 /**
2587  * CLDC 1.1 com/sun/cldchi/jvm/FileDescriptor
2588  *
2589  * Object layout:
2590  *
2591  * 0. object header
2592  * 1. long   pointer;
2593  * 2. int    position;
2594  * 3. int    length;
2595  */
2596 class com_sun_cldchi_jvm_FileDescriptor : public java_lang_Object, private FieldAccess {
2597 private:
2598         // Static offsets of the object's instance fields.
2599         // TODO These offsets need to be checked on VM startup.
2600         static const off_t offset_pointer  = MEMORY_ALIGN(sizeof(java_object_t),             sizeof(int64_t));
2601         static const off_t offset_position = MEMORY_ALIGN(offset_pointer  + sizeof(int64_t), sizeof(int32_t));
2602         static const off_t offset_length   = MEMORY_ALIGN(offset_position + sizeof(int32_t), sizeof(int32_t));
2603
2604 public:
2605         com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h) : java_lang_Object(h) {}
2606         com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h, int64_t pointer, int32_t position, int32_t length);
2607         com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h, com_sun_cldchi_jvm_FileDescriptor& fd);
2608
2609         // Getters.
2610         int64_t get_pointer () const;
2611         int32_t get_position() const;
2612         int32_t get_length  () const;
2613
2614         // Setters.
2615         void set_pointer (int64_t value);
2616         void set_position(int32_t value);
2617         void set_length  (int32_t value);
2618 };
2619
2620
2621 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)
2622 {
2623         set_pointer(pointer);
2624         set_position(position);
2625         set_length(length);
2626 }
2627
2628 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)
2629 {
2630         com_sun_cldchi_jvm_FileDescriptor(h, fd.get_pointer(), fd.get_position(), fd.get_length());
2631 }
2632
2633
2634 inline int64_t com_sun_cldchi_jvm_FileDescriptor::get_pointer() const
2635 {
2636         return get<int64_t>(_handle, offset_pointer);
2637 }
2638
2639 inline int32_t com_sun_cldchi_jvm_FileDescriptor::get_position() const
2640 {
2641         return get<int32_t>(_handle, offset_position);
2642 }
2643
2644 inline int32_t com_sun_cldchi_jvm_FileDescriptor::get_length() const
2645 {
2646         return get<int32_t>(_handle, offset_length);
2647 }
2648
2649
2650 inline void com_sun_cldchi_jvm_FileDescriptor::set_pointer(int64_t value)
2651 {
2652         set(_handle, offset_pointer, value);
2653 }
2654
2655 inline void com_sun_cldchi_jvm_FileDescriptor::set_position(int32_t value)
2656 {
2657         set(_handle, offset_position, value);
2658 }
2659
2660 inline void com_sun_cldchi_jvm_FileDescriptor::set_length(int32_t value)
2661 {
2662         set(_handle, offset_length, value);
2663 }
2664
2665
2666 /**
2667  * CLDC 1.1 java/lang/String
2668  *
2669  * Object layout:
2670  *
2671  * 0. object header
2672  * 1. char[] value;
2673  * 2. int    offset;
2674  * 3. int    count;
2675  */
2676 class java_lang_String : public java_lang_Object, private FieldAccess {
2677 private:
2678         // Static offsets of the object's instance fields.
2679         // TODO These offsets need to be checked on VM startup.
2680         static const off_t offset_value  = MEMORY_ALIGN(sizeof(java_object_t),           SIZEOF_VOID_P);
2681         static const off_t offset_offset = MEMORY_ALIGN(offset_value  + SIZEOF_VOID_P,   sizeof(int32_t));
2682         static const off_t offset_count  = MEMORY_ALIGN(offset_offset + sizeof(int32_t), sizeof(int32_t));
2683
2684 public:
2685         java_lang_String(java_handle_t* h) : java_lang_Object(h) {}
2686         java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset = 0);
2687
2688         // Getters.
2689         java_handle_chararray_t* get_value () const;
2690         int32_t                  get_offset() const;
2691         int32_t                  get_count () const;
2692
2693         // Setters.
2694         void set_value (java_handle_chararray_t* value);
2695         void set_offset(int32_t value);
2696         void set_count (int32_t value);
2697 };
2698
2699
2700 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)
2701 {
2702         set_value(value);
2703         set_offset(offset);
2704         set_count(count);
2705 }
2706
2707 inline java_handle_chararray_t* java_lang_String::get_value() const
2708 {
2709         return get<java_handle_chararray_t*>(_handle, offset_value);
2710 }
2711
2712 inline int32_t java_lang_String::get_offset() const
2713 {
2714         return get<int32_t>(_handle, offset_offset);
2715 }
2716
2717 inline int32_t java_lang_String::get_count() const
2718 {
2719         return get<int32_t>(_handle, offset_count);
2720 }
2721
2722 inline void java_lang_String::set_value(java_handle_chararray_t* value)
2723 {
2724         set(_handle, offset_value, value);
2725 }
2726
2727 inline void java_lang_String::set_offset(int32_t value)
2728 {
2729         set(_handle, offset_offset, value);
2730 }
2731
2732 inline void java_lang_String::set_count(int32_t value)
2733 {
2734         set(_handle, offset_count, value);
2735 }
2736
2737
2738 /**
2739  * CLDC 1.1 java/lang/Thread
2740  *
2741  * Object layout:
2742  *
2743  * 0. object header
2744  * 1. int                priority;
2745  * 2. java.lang.Runnable runnable;
2746  * 3. java.lang.Object   vm_thread;
2747  * 4. int                is_terminated;
2748  * 5. int                is_stillborn;
2749  * 6. char[]             name;
2750  */
2751 class java_lang_Thread : public java_lang_Object, private FieldAccess {
2752 private:
2753         // Static offsets of the object's instance fields.
2754         // TODO These offsets need to be checked on VM startup.
2755         static const off_t offset_priority      = MEMORY_ALIGN(sizeof(java_object_t),              sizeof(int32_t));
2756         static const off_t offset_runnable      = MEMORY_ALIGN(offset_priority      + sizeof(int32_t), SIZEOF_VOID_P);
2757         static const off_t offset_vm_thread     = MEMORY_ALIGN(offset_runnable      + SIZEOF_VOID_P,   SIZEOF_VOID_P);
2758         static const off_t offset_is_terminated = MEMORY_ALIGN(offset_vm_thread     + SIZEOF_VOID_P,   sizeof(int32_t));
2759         static const off_t offset_is_stillborn  = MEMORY_ALIGN(offset_is_terminated + sizeof(int32_t), sizeof(int32_t));
2760         static const off_t offset_name          = MEMORY_ALIGN(offset_is_stillborn  + sizeof(int32_t), SIZEOF_VOID_P);
2761
2762 public:
2763         java_lang_Thread(java_handle_t* h) : java_lang_Object(h) {}
2764 //      java_lang_Thread(threadobject* t);
2765
2766         // Getters.
2767         int32_t                  get_priority () const;
2768         threadobject*            get_vm_thread() const;
2769         java_handle_chararray_t* get_name     () const;
2770
2771         // Setters.
2772         void set_vm_thread(threadobject* value);
2773 };
2774
2775
2776 inline int32_t java_lang_Thread::get_priority() const
2777 {
2778         return get<int32_t>(_handle, offset_priority);
2779 }
2780
2781 inline threadobject* java_lang_Thread::get_vm_thread() const
2782 {
2783         return get<threadobject*>(_handle, offset_vm_thread);
2784 }
2785
2786 inline java_handle_chararray_t* java_lang_Thread::get_name() const
2787 {
2788         return get<java_handle_chararray_t*>(_handle, offset_name);
2789 }
2790
2791
2792 inline void java_lang_Thread::set_vm_thread(threadobject* value)
2793 {
2794         set(_handle, offset_vm_thread, value);
2795 }
2796
2797
2798 /**
2799  * CLDC 1.1 java/lang/Throwable
2800  *
2801  * Object layout:
2802  *
2803  * 0. object header
2804  * 1. java.lang.String detailMessage;
2805  * 2. java.lang.Object backtrace;
2806  */
2807 class java_lang_Throwable : public java_lang_Object, private FieldAccess {
2808 private:
2809         // Static offsets of the object's instance fields.
2810         // TODO These offsets need to be checked on VM startup.
2811         static const off_t offset_detailMessage = MEMORY_ALIGN(sizeof(java_object_t),                SIZEOF_VOID_P);
2812         static const off_t offset_backtrace     = MEMORY_ALIGN(offset_detailMessage + SIZEOF_VOID_P, SIZEOF_VOID_P);
2813
2814 public:
2815         java_lang_Throwable(java_handle_t* h) : java_lang_Object(h) {}
2816
2817         // Getters.
2818         java_handle_t*           get_detailMessage() const;
2819         java_handle_bytearray_t* get_backtrace    () const;
2820
2821         // Setters.
2822         void set_backtrace(java_handle_bytearray_t* value);
2823 };
2824
2825
2826 inline java_handle_t* java_lang_Throwable::get_detailMessage() const
2827 {
2828         return get<java_handle_t*>(_handle, offset_detailMessage);
2829 }
2830
2831 inline java_handle_bytearray_t* java_lang_Throwable::get_backtrace() const
2832 {
2833         return get<java_handle_bytearray_t*>(_handle, offset_backtrace);
2834 }
2835
2836
2837 inline void java_lang_Throwable::set_backtrace(java_handle_bytearray_t* value)
2838 {
2839         set(_handle, offset_backtrace, value);
2840 }
2841
2842 #endif // WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1
2843
2844 #endif
2845
2846 #endif // _JAVAOBJECTS_HPP
2847
2848
2849 /*
2850  * These are local overrides for various environment variables in Emacs.
2851  * Please do not remove this and leave it at the end of the file, where
2852  * Emacs will automagically detect them.
2853  * ---------------------------------------------------------------------
2854  * Local variables:
2855  * mode: c++
2856  * indent-tabs-mode: t
2857  * c-basic-offset: 4
2858  * tab-width: 4
2859  * End:
2860  * vim:noexpandtab:sw=4:ts=4:
2861  */