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