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