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