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