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