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