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