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