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