* Merged with 347adb07b1f5.
[cacao.git] / src / vmcore / javaobjects.hpp
1 /* src/vmcore/javaobjects.hpp - functions to create and access Java objects
2
3    Copyright (C) 2008 Theobroma Systems Ltd.
4
5    This file is part of CACAO.
6
7    This program is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License as
9    published by the Free Software Foundation; either version 2, or (at
10    your option) any later version.
11
12    This program is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20    02110-1301, USA.
21
22 */
23
24
25 #ifndef _JAVAOBJECTS_HPP
26 #define _JAVAOBJECTS_HPP
27
28 #include "config.h"
29
30 #include <stdint.h>
31
32 #include "mm/memory.h"
33
34 #include "native/llni.h"
35
36 #include "vm/global.h"
37
38 #include "vmcore/field.h"
39 #include "vmcore/method.h"
40
41
42 #ifdef __cplusplus
43
44 /**
45  * This class provides low-level functions to access Java object
46  * instance fields.
47  *
48  * These functions do NOT take care about the GC critical section!
49  * Please use FieldAccess wherever possible.
50  */
51 class RawFieldAccess {
52 protected:
53         template<class T> static inline T    raw_get(void* address, const off_t offset);
54         template<class T> static inline void raw_set(void* address, const off_t offset, T value);
55 };
56
57
58 template<class T> inline T RawFieldAccess::raw_get(void* address, const off_t offset)
59 {
60         T* p = (T*) (((uintptr_t) address) + offset);
61         return *p;
62 }
63
64
65 template<class T> inline void RawFieldAccess::raw_set(void* address, const off_t offset, T value)
66 {
67         T* p = (T*) (((uintptr_t) address) + offset);
68         *p = value;
69 }
70
71
72 /**
73  * This classes provides functions to access Java object instance
74  * fields.  These functions enter a critical GC section before
75  * accessing the Java object throught the handle and leave it
76  * afterwards.
77  */
78 class FieldAccess : private RawFieldAccess {
79 protected:
80         template<class T> static inline T    get(java_handle_t* h, const off_t offset);
81         template<class T> static inline void set(java_handle_t* h, const off_t offset, T value);
82 };
83
84 template<class T> inline T FieldAccess::get(java_handle_t* h, const off_t offset)
85 {
86         java_object_t* o;
87         T result;
88                 
89         // XXX Move this to a GC inline function, e.g.
90         // gc->enter_critical();
91         LLNI_CRITICAL_START;
92
93         // XXX This should be _handle->get_object();
94         o = LLNI_UNWRAP(h);
95
96         result = raw_get<T>(o, offset);
97
98         // XXX Move this to a GC inline function.
99         // gc->leave_critical();
100         LLNI_CRITICAL_END;
101
102         return result;
103 }       
104
105 template<> inline java_handle_t* FieldAccess::get(java_handle_t* h, const off_t offset)
106 {
107         java_object_t* o;
108         java_object_t* result;
109         java_handle_t* hresult;
110                 
111         // XXX Move this to a GC inline function, e.g.
112         // gc->enter_critical();
113         LLNI_CRITICAL_START;
114
115         // XXX This should be _handle->get_object();
116         o = LLNI_UNWRAP(h);
117
118         result = raw_get<java_object_t*>(o, offset);
119
120         hresult = LLNI_WRAP(result);
121
122         // XXX Move this to a GC inline function.
123         // gc->leave_critical();
124         LLNI_CRITICAL_END;
125
126         return result;
127 }       
128
129
130 template<class T> inline void FieldAccess::set(java_handle_t* h, const off_t offset, T value)
131 {
132         java_object_t* o;
133
134         // XXX Move this to a GC inline function, e.g.
135         // gc->enter_critical();
136         LLNI_CRITICAL_START;
137
138         // XXX This should be h->get_object();
139         o = LLNI_UNWRAP(h);
140
141         raw_set(o, offset, value);
142
143         // XXX Move this to a GC inline function.
144         // gc->leave_critical();
145         LLNI_CRITICAL_END;
146 }
147
148 template<> inline void FieldAccess::set<java_handle_t*>(java_handle_t* h, const off_t offset, java_handle_t* value)
149 {
150         java_object_t* o;
151         java_object_t* ovalue;
152
153         // XXX Move this to a GC inline function, e.g.
154         // gc->enter_critical();
155         LLNI_CRITICAL_START;
156
157         // XXX This should be h->get_object();
158         o      = LLNI_UNWRAP(h);
159         ovalue = LLNI_UNWRAP(value);
160
161         raw_set(o, offset, ovalue);
162
163         // XXX Move this to a GC inline function.
164         // gc->leave_critical();
165         LLNI_CRITICAL_END;
166 }
167
168
169 /**
170  * java/lang/Object
171  *
172  * Object layout:
173  *
174  * 0. object header
175  */
176 class java_lang_Object {
177 protected:
178         // Handle of Java object.
179         java_handle_t* _handle;
180
181 protected:
182         java_lang_Object(java_handle_t* h) : _handle(h) {}
183         java_lang_Object(jobject h) : _handle((java_handle_t*) h) {}
184
185 public:
186         // Getters.
187         virtual inline java_handle_t* get_handle() const { return _handle; }
188         inline vftbl_t*               get_vftbl () const;
189         inline classinfo*             get_Class () const;
190
191         inline bool is_null() const;
192 };
193
194
195 inline vftbl_t* java_lang_Object::get_vftbl() const
196 {
197         // XXX Move this to a GC inline function, e.g.
198         // gc->enter_critical();
199         LLNI_CRITICAL_START;
200
201         // XXX This should be h->get_object();
202         java_object_t* o = LLNI_UNWRAP(_handle);
203         vftbl_t* vftbl = o->vftbl;
204
205         // XXX Move this to a GC inline function.
206         // gc->leave_critical();
207         LLNI_CRITICAL_END;
208
209         return vftbl;
210 }
211
212 inline classinfo* java_lang_Object::get_Class() const
213 {
214         return get_vftbl()->clazz;
215 }
216
217
218 inline bool java_lang_Object::is_null() const
219 {
220         return (_handle == NULL);
221 }
222
223
224 /**
225  * java/lang/Boolean
226  *
227  * Object layout:
228  *
229  * 0. object header
230  * 1. boolean value;
231  */
232 class java_lang_Boolean : public java_lang_Object, private FieldAccess {
233 private:
234         // Static offsets of the object's instance fields.
235         // TODO These offsets need to be checked on VM startup.
236         static const off_t offset_value = MEMORY_ALIGN(sizeof(java_object_t), sizeof(int32_t));
237
238 public:
239         java_lang_Boolean(java_handle_t* h) : java_lang_Object(h) {}
240
241         inline uint8_t get_value();
242         inline void    set_value(uint8_t value);
243 };
244
245 inline uint8_t java_lang_Boolean::get_value()
246 {
247         return get<int32_t>(_handle, offset_value);
248 }
249
250 inline void java_lang_Boolean::set_value(uint8_t value)
251 {
252         set(_handle, offset_value, (uint32_t) value);
253 }
254
255
256 /**
257  * java/lang/Byte
258  *
259  * Object layout:
260  *
261  * 0. object header
262  * 1. byte value;
263  */
264 class java_lang_Byte : public java_lang_Object, private FieldAccess {
265 private:
266         // Static offsets of the object's instance fields.
267         // TODO These offsets need to be checked on VM startup.
268         static const off_t offset_value = MEMORY_ALIGN(sizeof(java_object_t), sizeof(int32_t));
269
270 public:
271         java_lang_Byte(java_handle_t* h) : java_lang_Object(h) {}
272
273         inline int8_t get_value();
274         inline void   set_value(int8_t value);
275 };
276
277 inline int8_t java_lang_Byte::get_value()
278 {
279         return get<int32_t>(_handle, offset_value);
280 }
281
282 inline void java_lang_Byte::set_value(int8_t value)
283 {
284         set(_handle, offset_value, (int32_t) value);
285 }
286
287
288 /**
289  * java/lang/Character
290  *
291  * Object layout:
292  *
293  * 0. object header
294  * 1. char value;
295  */
296 class java_lang_Character : public java_lang_Object, private FieldAccess {
297 private:
298         // Static offsets of the object's instance fields.
299         // TODO These offsets need to be checked on VM startup.
300         static const off_t offset_value = MEMORY_ALIGN(sizeof(java_object_t), sizeof(int32_t));
301
302 public:
303         java_lang_Character(java_handle_t* h) : java_lang_Object(h) {}
304
305         inline uint16_t get_value();
306         inline void     set_value(uint16_t value);
307 };
308
309 inline uint16_t java_lang_Character::get_value()
310 {
311         return get<int32_t>(_handle, offset_value);
312 }
313
314 inline void java_lang_Character::set_value(uint16_t value)
315 {
316         set(_handle, offset_value, (uint32_t) value);
317 }
318
319
320 /**
321  * java/lang/Short
322  *
323  * Object layout:
324  *
325  * 0. object header
326  * 1. short value;
327  */
328 class java_lang_Short : public java_lang_Object, private FieldAccess {
329 private:
330         // Static offsets of the object's instance fields.
331         // TODO These offsets need to be checked on VM startup.
332         static const off_t offset_value = MEMORY_ALIGN(sizeof(java_object_t), sizeof(int32_t));
333
334 public:
335         java_lang_Short(java_handle_t* h) : java_lang_Object(h) {}
336
337         inline int16_t get_value();
338         inline void    set_value(int16_t value);
339 };
340
341 inline int16_t java_lang_Short::get_value()
342 {
343         return get<int32_t>(_handle, offset_value);
344 }
345
346 inline void java_lang_Short::set_value(int16_t value)
347 {
348         set(_handle, offset_value, (int32_t) value);
349 }
350
351
352 /**
353  * java/lang/Integer
354  *
355  * Object layout:
356  *
357  * 0. object header
358  * 1. int value;
359  */
360 class java_lang_Integer : public java_lang_Object, private FieldAccess {
361 private:
362         // Static offsets of the object's instance fields.
363         // TODO These offsets need to be checked on VM startup.
364         static const off_t offset_value = MEMORY_ALIGN(sizeof(java_object_t), sizeof(int32_t));
365
366 public:
367         java_lang_Integer(java_handle_t* h) : java_lang_Object(h) {}
368
369         inline int32_t get_value();
370         inline void    set_value(int32_t value);
371 };
372
373 inline int32_t java_lang_Integer::get_value()
374 {
375         return get<int32_t>(_handle, offset_value);
376 }
377
378 inline void java_lang_Integer::set_value(int32_t value)
379 {
380         set(_handle, offset_value, value);
381 }
382
383
384 /**
385  * java/lang/Long
386  *
387  * Object layout:
388  *
389  * 0. object header
390  * 1. long value;
391  */
392 class java_lang_Long : public java_lang_Object, private FieldAccess {
393 private:
394         // Static offsets of the object's instance fields.
395         // TODO These offsets need to be checked on VM startup.
396         static const off_t offset_value = MEMORY_ALIGN(sizeof(java_object_t), sizeof(int64_t));
397
398 public:
399         java_lang_Long(java_handle_t* h) : java_lang_Object(h) {}
400
401         inline int64_t get_value();
402         inline void    set_value(int64_t value);
403 };
404
405 inline int64_t java_lang_Long::get_value()
406 {
407         return get<int64_t>(_handle, offset_value);
408 }
409
410 inline void java_lang_Long::set_value(int64_t value)
411 {
412         set(_handle, offset_value, value);
413 }
414
415
416 /**
417  * java/lang/Float
418  *
419  * Object layout:
420  *
421  * 0. object header
422  * 1. float value;
423  */
424 class java_lang_Float : public java_lang_Object, private FieldAccess {
425 private:
426         // Static offsets of the object's instance fields.
427         // TODO These offsets need to be checked on VM startup.
428         static const off_t offset_value = MEMORY_ALIGN(sizeof(java_object_t), sizeof(float));
429
430 public:
431         java_lang_Float(java_handle_t* h) : java_lang_Object(h) {}
432
433         inline float get_value();
434         inline void  set_value(float value);
435 };
436
437 inline float java_lang_Float::get_value()
438 {
439         return get<float>(_handle, offset_value);
440 }
441
442 inline void java_lang_Float::set_value(float value)
443 {
444         set(_handle, offset_value, value);
445 }
446
447
448 /**
449  * java/lang/Double
450  *
451  * Object layout:
452  *
453  * 0. object header
454  * 1. double value;
455  */
456 class java_lang_Double : public java_lang_Object, private FieldAccess {
457 private:
458         // Static offsets of the object's instance fields.
459         // TODO These offsets need to be checked on VM startup.
460         static const off_t offset_value = MEMORY_ALIGN(sizeof(java_object_t), sizeof(double));
461
462 public:
463         java_lang_Double(java_handle_t* h) : java_lang_Object(h) {}
464
465         inline double get_value();
466         inline void   set_value(double value);
467 };
468
469 inline double java_lang_Double::get_value()
470 {
471         return get<double>(_handle, offset_value);
472 }
473
474 inline void java_lang_Double::set_value(double value)
475 {
476         set(_handle, offset_value, value);
477 }
478
479
480 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
481
482 /**
483  * GNU Classpath java/lang/Class
484  *
485  * Object layout:
486  *
487  * 0. object header
488  * 1. java.lang.Object[]             signers;
489  * 2. java.security.ProtectionDomain pd;
490  * 3. java.lang.Object               vmdata;
491  * 4. java.lang.reflect.Constructor  constructor;
492  */
493 class java_lang_Class : public java_lang_Object, private FieldAccess {
494 private:
495         // Static offsets of the object's instance fields.
496         // TODO These offsets need to be checked on VM startup.
497         static const off_t offset_signers     = MEMORY_ALIGN(sizeof(java_object_t),          SIZEOF_VOID_P);
498         static const off_t offset_pd          = MEMORY_ALIGN(offset_signers + SIZEOF_VOID_P, SIZEOF_VOID_P);
499         static const off_t offset_vmdata      = MEMORY_ALIGN(offset_pd      + SIZEOF_VOID_P, SIZEOF_VOID_P);
500         static const off_t offset_constructor = MEMORY_ALIGN(offset_vmdata  + SIZEOF_VOID_P, SIZEOF_VOID_P);
501
502 public:
503         java_lang_Class(java_handle_t* h) : java_lang_Object(h) {}
504
505         // Setters.
506         inline void set_pd(java_handle_t* value);
507         inline void set_pd(jobject value);
508 };
509
510 inline void java_lang_Class::set_pd(java_handle_t* value)
511 {
512         set(_handle, offset_pd, value);
513 }
514
515 inline void java_lang_Class::set_pd(jobject value)
516 {
517         set_pd((java_handle_t*) value);
518 }
519
520
521 /**
522  * GNU Classpath java/lang/StackTraceElement
523  *
524  * Object layout:
525  *
526  * 0. object header
527  * 1. java.lang.String fileName;
528  * 2. int              lineNumber;
529  * 3. java.lang.String declaringClass;
530  * 4. java.lang.String methodName;
531  * 5. boolean          isNative;
532  */
533 class java_lang_StackTraceElement : public java_lang_Object, private FieldAccess {
534 private:
535         // Static offsets of the object's instance fields.
536         // TODO These offsets need to be checked on VM startup.
537         static const off_t offset_fileName       = MEMORY_ALIGN(sizeof(java_object_t),                   SIZEOF_VOID_P);
538         static const off_t offset_lineNumber     = MEMORY_ALIGN(offset_fileName       + SIZEOF_VOID_P,   sizeof(int32_t));
539         static const off_t offset_declaringClass = MEMORY_ALIGN(offset_lineNumber     + sizeof(int32_t), SIZEOF_VOID_P);
540         static const off_t offset_methodName     = MEMORY_ALIGN(offset_declaringClass + SIZEOF_VOID_P,   SIZEOF_VOID_P);
541         static const off_t offset_isNative       = MEMORY_ALIGN(offset_methodName     + SIZEOF_VOID_P,   SIZEOF_VOID_P);
542
543 public:
544         java_lang_StackTraceElement(java_handle_t* h) : java_lang_Object(h) {}
545         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);
546 };
547
548 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)
549 {
550         java_lang_StackTraceElement((java_handle_t*) h);
551
552         set(_handle, offset_fileName,       fileName);
553         set(_handle, offset_lineNumber,     lineNumber);
554         set(_handle, offset_declaringClass, declaringClass);
555         set(_handle, offset_methodName,     methodName);
556         set(_handle, offset_isNative,       isNative);
557 }
558
559
560 /**
561  * GNU Classpath java/lang/String
562  *
563  * Object layout:
564  *
565  * 0. object header
566  * 1. char[] value;
567  * 2. int    count;
568  * 3. int    cachedHashCode;
569  * 4. int    offset;
570  */
571 class java_lang_String : 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_value          = MEMORY_ALIGN(sizeof(java_object_t),                   SIZEOF_VOID_P);
576         static const off_t offset_count          = MEMORY_ALIGN(offset_value          + SIZEOF_VOID_P,   sizeof(int32_t));
577         static const off_t offset_cachedHashCode = MEMORY_ALIGN(offset_count          + sizeof(int32_t), sizeof(int32_t));
578         static const off_t offset_offset         = MEMORY_ALIGN(offset_cachedHashCode + sizeof(int32_t), sizeof(int32_t));
579
580 public:
581         java_lang_String(java_handle_t* h) : java_lang_Object(h) {}
582         java_lang_String(jstring h);
583         java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset = 0);
584
585         // Getters.
586         inline java_handle_chararray_t* get_value () const;
587         inline int32_t                  get_count () const;
588         inline int32_t                  get_offset() const;
589
590         // Setters.
591         inline void set_value (java_handle_chararray_t* value);
592         inline void set_count (int32_t value);
593         inline void set_offset(int32_t value);
594 };
595
596 inline java_lang_String::java_lang_String(jstring h) : java_lang_Object(h)
597 {
598         java_lang_String((java_handle_t*) h);
599 }
600
601 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)
602 {
603         set_value(value);
604         set_count(count);
605         set_offset(offset);
606 }
607
608 inline java_handle_chararray_t* java_lang_String::get_value() const
609 {
610         return get<java_handle_chararray_t*>(_handle, offset_value);
611 }
612
613 inline int32_t java_lang_String::get_count() const
614 {
615         return get<int32_t>(_handle, offset_count);
616 }
617
618 inline int32_t java_lang_String::get_offset() const
619 {
620         return get<int32_t>(_handle, offset_offset);
621 }
622
623 inline void java_lang_String::set_value(java_handle_chararray_t* value)
624 {
625         set(_handle, offset_value, value);
626 }
627
628 inline void java_lang_String::set_count(int32_t value)
629 {
630         set(_handle, offset_count, value);
631 }
632
633 inline void java_lang_String::set_offset(int32_t value)
634 {
635         set(_handle, offset_offset, value);
636 }
637
638
639 /**
640  * GNU Classpath java/lang/Thread
641  *
642  * Object layout:
643  *
644  *  0. object header
645  *  1. java.lang.VMThread                        vmThread;
646  *  2. java.lang.ThreadGroup                     group;
647  *  3. java.lang.Runnable                        runnable;
648  *  4. java.lang.String                          name;
649  *  5. boolean                                   daemon;
650  *  6. int                                       priority;
651  *  7. long                                      stacksize;
652  *  8. java.lang.Throwable                       stillborn;
653  *  9. java.lang.ClassLoader                     contextClassLoader;
654  * 10. boolean                                   contextClassLoaderIsSystemClassLoader;
655  * 11. long                                      threadId;
656  * 12. java.lang.Object                          parkBlocker;
657  * 13. gnu.java.util.WeakIdentityHashMap         locals;
658  * 14. java_lang_Thread_UncaughtExceptionHandler exceptionHandler;
659  */
660 class java_lang_Thread : public java_lang_Object, private FieldAccess {
661 private:
662         // Static offsets of the object's instance fields.
663         // TODO These offsets need to be checked on VM startup.
664         static const off_t offset_vmThread                              = MEMORY_ALIGN(sizeof(java_object_t),                                          SIZEOF_VOID_P);
665         static const off_t offset_group                                 = MEMORY_ALIGN(offset_vmThread                              + SIZEOF_VOID_P,   SIZEOF_VOID_P);
666         static const off_t offset_runnable                              = MEMORY_ALIGN(offset_group                                 + SIZEOF_VOID_P,   SIZEOF_VOID_P);
667         static const off_t offset_name                                  = MEMORY_ALIGN(offset_runnable                              + SIZEOF_VOID_P,   SIZEOF_VOID_P);
668         static const off_t offset_daemon                                = MEMORY_ALIGN(offset_name                                  + SIZEOF_VOID_P,   sizeof(int32_t));
669         static const off_t offset_priority                              = MEMORY_ALIGN(offset_daemon                                + sizeof(int32_t), sizeof(int32_t));
670         static const off_t offset_stacksize                             = MEMORY_ALIGN(offset_priority                              + sizeof(int32_t), sizeof(int64_t));
671         static const off_t offset_stillborn                             = MEMORY_ALIGN(offset_stacksize                             + sizeof(int64_t), SIZEOF_VOID_P);
672         static const off_t offset_contextClassLoader                    = MEMORY_ALIGN(offset_stillborn                             + SIZEOF_VOID_P,   SIZEOF_VOID_P);
673         static const off_t offset_contextClassLoaderIsSystemClassLoader = MEMORY_ALIGN(offset_contextClassLoader                    + SIZEOF_VOID_P,   SIZEOF_VOID_P);
674         static const off_t offset_threadId                              = MEMORY_ALIGN(offset_contextClassLoaderIsSystemClassLoader + sizeof(int32_t), sizeof(int64_t));
675         static const off_t offset_parkBlocker                           = MEMORY_ALIGN(offset_threadId                              + sizeof(int64_t), SIZEOF_VOID_P);
676         static const off_t offset_locals                                = MEMORY_ALIGN(offset_parkBlocker                           + SIZEOF_VOID_P,   SIZEOF_VOID_P);
677         static const off_t offset_exceptionHandler                      = MEMORY_ALIGN(offset_locals                                + SIZEOF_VOID_P,   SIZEOF_VOID_P);
678
679 public:
680         java_lang_Thread(java_handle_t* h) : java_lang_Object(h) {}
681 //      java_lang_Thread(threadobject* t);
682
683         // Getters.
684         inline java_handle_t* get_vmThread        () const;
685         inline java_handle_t* get_group           () const;
686         inline java_handle_t* get_name            () const;
687         inline int32_t        get_daemon          () const;
688         inline int32_t        get_priority        () const;
689         inline java_handle_t* get_exceptionHandler() const;
690
691         // Setters.
692         inline void set_group(java_handle_t* value);
693 };
694
695
696 // inline java_lang_Thread::java_lang_Thread(threadobject* t) : java_lang_Object(h)
697 // {
698 //      java_lang_Thread(thread_get_object(t));
699 // }
700
701
702 inline java_handle_t* java_lang_Thread::get_vmThread() const
703 {
704         return get<java_handle_t*>(_handle, offset_vmThread);
705 }
706
707 inline java_handle_t* java_lang_Thread::get_group() const
708 {
709         return get<java_handle_t*>(_handle, offset_group);
710 }
711
712 inline java_handle_t* java_lang_Thread::get_name() const
713 {
714         return get<java_handle_t*>(_handle, offset_name);
715 }
716
717 inline int32_t java_lang_Thread::get_daemon() const
718 {
719         return get<int32_t>(_handle, offset_daemon);
720 }
721
722 inline int32_t java_lang_Thread::get_priority() const
723 {
724         return get<int32_t>(_handle, offset_priority);
725 }
726
727 inline java_handle_t* java_lang_Thread::get_exceptionHandler() const
728 {
729         return get<java_handle_t*>(_handle, offset_exceptionHandler);
730 }
731
732
733 inline void java_lang_Thread::set_group(java_handle_t* value)
734 {
735         set(_handle, offset_group, value);
736 }
737
738
739 /**
740  * GNU Classpath java/lang/VMThread
741  *
742  * Object layout:
743  *
744  * 0. object header
745  * 1. java.lang.Thread   thread;
746  * 2. boolean            running;
747  * 3. java.lang.VMThread vmdata;
748  */
749 class java_lang_VMThread : public java_lang_Object, private FieldAccess {
750 private:
751         // Static offsets of the object's instance fields.
752         // TODO These offsets need to be checked on VM startup.
753         static const off_t offset_thread  = MEMORY_ALIGN(sizeof(java_object_t),            SIZEOF_VOID_P);
754         static const off_t offset_running = MEMORY_ALIGN(offset_thread  + SIZEOF_VOID_P,   sizeof(int32_t));
755         static const off_t offset_vmdata  = MEMORY_ALIGN(offset_running + sizeof(int32_t), SIZEOF_VOID_P);
756
757 public:
758         java_lang_VMThread(java_handle_t* h) : java_lang_Object(h) {}
759         java_lang_VMThread(jobject h);
760         java_lang_VMThread(java_handle_t* h, java_handle_t* thread, threadobject* vmdata);
761
762         // Getters.
763         inline java_handle_t* get_thread() const;
764         inline threadobject*  get_vmdata() const;
765
766         // Setters.
767         inline void set_thread(java_handle_t* value);
768         inline void set_vmdata(threadobject* value);
769 };
770
771
772 inline java_lang_VMThread::java_lang_VMThread(jobject h) : java_lang_Object(h)
773 {
774         java_lang_VMThread((java_handle_t*) h);
775 }
776
777 inline java_lang_VMThread::java_lang_VMThread(java_handle_t* h, java_handle_t* thread, threadobject* vmdata) : java_lang_Object(h)
778 {
779         set_thread(thread);
780         set_vmdata(vmdata);
781 }
782
783
784 inline java_handle_t* java_lang_VMThread::get_thread() const
785 {
786         return get<java_handle_t*>(_handle, offset_thread);
787 }
788
789 inline threadobject* java_lang_VMThread::get_vmdata() const
790 {
791         return get<threadobject*>(_handle, offset_vmdata);
792 }
793
794
795 inline void java_lang_VMThread::set_thread(java_handle_t* value)
796 {
797         set(_handle, offset_thread, value);
798 }
799
800 inline void java_lang_VMThread::set_vmdata(threadobject* value)
801 {
802         set(_handle, offset_vmdata, value);
803 }
804
805
806 /**
807  * GNU Classpath java/lang/Throwable
808  *
809  * Object layout:
810  *
811  * 0. object header
812  * 1. java.lang.String              detailMessage;
813  * 2. java.lang.Throwable           cause;
814  * 3. java.lang.StackTraceElement[] stackTrace;
815  * 4. java.lang.VMThrowable         vmState;
816  */
817 class java_lang_Throwable : public java_lang_Object, private FieldAccess {
818 private:
819         // Static offsets of the object's instance fields.
820         // TODO These offsets need to be checked on VM startup.
821         static const off_t offset_detailMessage = MEMORY_ALIGN(sizeof(java_object_t),                SIZEOF_VOID_P);
822         static const off_t offset_cause         = MEMORY_ALIGN(offset_detailMessage + SIZEOF_VOID_P, SIZEOF_VOID_P);
823         static const off_t offset_stackTrace    = MEMORY_ALIGN(offset_cause         + SIZEOF_VOID_P, SIZEOF_VOID_P);
824         static const off_t offset_vmState       = MEMORY_ALIGN(offset_stackTrace    + SIZEOF_VOID_P, SIZEOF_VOID_P);
825
826 public:
827         java_lang_Throwable(java_handle_t* h) : java_lang_Object(h) {}
828
829         // Getters.
830         inline java_handle_t* get_detailMessage() const;
831         inline java_handle_t* get_cause        () const;
832         inline java_handle_t* get_vmState      () const;
833 };
834
835
836 inline java_handle_t* java_lang_Throwable::get_detailMessage() const
837 {
838         return get<java_handle_t*>(_handle, offset_detailMessage);
839 }
840
841 inline java_handle_t* java_lang_Throwable::get_cause() const
842 {
843         return get<java_handle_t*>(_handle, offset_cause);
844 }
845
846 inline java_handle_t* java_lang_Throwable::get_vmState() const
847 {
848         return get<java_handle_t*>(_handle, offset_vmState);
849 }
850
851
852 /**
853  * GNU Classpath java/lang/VMThrowable
854  *
855  * Object layout:
856  *
857  * 0. object header
858  * 1. java.lang.Object vmdata;
859  */
860 class java_lang_VMThrowable : public java_lang_Object, private FieldAccess {
861 private:
862         // Static offsets of the object's instance fields.
863         // TODO These offsets need to be checked on VM startup.
864         static const off_t offset_vmdata = MEMORY_ALIGN(sizeof(java_object_t), SIZEOF_VOID_P);
865
866 public:
867         java_lang_VMThrowable(java_handle_t* h) : java_lang_Object(h) {}
868         java_lang_VMThrowable(jobject h);
869
870         inline java_handle_bytearray_t* get_vmdata() const;
871         inline void                     set_vmdata(java_handle_bytearray_t* value);
872 };
873
874 inline java_lang_VMThrowable::java_lang_VMThrowable(jobject h) : java_lang_Object(h)
875 {
876         java_lang_VMThrowable((java_handle_t*) h);
877 }
878
879 inline java_handle_bytearray_t* java_lang_VMThrowable::get_vmdata() const
880 {
881         return get<java_handle_bytearray_t*>(_handle, offset_vmdata);
882 }
883
884 inline void java_lang_VMThrowable::set_vmdata(java_handle_bytearray_t* value)
885 {
886         set(_handle, offset_vmdata, value);
887 }
888
889
890 /**
891  * GNU Classpath java/lang/reflect/Constructor
892  *
893  * Object layout:
894  *
895  * 0. object header
896  * 1. boolean                                     flag;
897  * 2. gnu.java.lang.reflect.MethodSignatureParser p;
898  * 3. java.lang.reflect.VMConstructor             cons;
899  */
900 class java_lang_reflect_Constructor : public java_lang_Object, private FieldAccess {
901 private:
902         // Static offsets of the object's instance fields.
903         // TODO These offsets need to be checked on VM startup.
904         static const off_t offset_flag = MEMORY_ALIGN(sizeof(java_object_t),         sizeof(int32_t));
905         static const off_t offset_p    = MEMORY_ALIGN(offset_flag + sizeof(int32_t), SIZEOF_VOID_P);
906         static const off_t offset_cons = MEMORY_ALIGN(offset_p    + SIZEOF_VOID_P,   SIZEOF_VOID_P);
907
908 public:
909         java_lang_reflect_Constructor(java_handle_t* h) : java_lang_Object(h) {}
910         java_lang_reflect_Constructor(jobject h);
911
912         static java_handle_t* create(methodinfo* m);
913         static java_handle_t* new_instance(methodinfo* m, java_handle_objectarray_t* args, bool override);
914
915         // Getters.
916         inline int32_t        get_flag() const;
917         inline java_handle_t* get_cons() const;
918
919         // Setters.
920         inline void set_cons(java_handle_t* value);
921 };
922
923 inline java_lang_reflect_Constructor::java_lang_reflect_Constructor(jobject h) : java_lang_Object(h)
924 {
925         java_lang_reflect_Constructor((java_handle_t*) h);
926 }
927
928 inline int32_t java_lang_reflect_Constructor::get_flag() const
929 {
930         return get<int32_t>(_handle, offset_flag);
931 }
932
933 inline java_handle_t* java_lang_reflect_Constructor::get_cons() const
934 {
935         return get<java_handle_t*>(_handle, offset_cons);
936 }
937
938 inline void java_lang_reflect_Constructor::set_cons(java_handle_t* value)
939 {
940         set(_handle, offset_cons, value);
941 }
942
943
944 /**
945  * GNU Classpath java/lang/reflect/VMConstructor
946  *
947  * Object layout:
948  *
949  * 0. object header
950  * 1. java.lang.Class               clazz;
951  * 2. int                           slot;
952  * 3. byte[]                        annotations;
953  * 4. byte[]                        parameterAnnotations;
954  * 5. java.util.Map                 declaredAnnotations;
955  * 6. java.lang.reflect.Constructor cons;
956  */
957 class java_lang_reflect_VMConstructor : public java_lang_Object, private FieldAccess {
958 private:
959         // Static offsets of the object's instance fields.
960         // TODO These offsets need to be checked on VM startup.
961         static const off_t offset_clazz                = MEMORY_ALIGN(sizeof(java_object_t),                         SIZEOF_VOID_P);
962         static const off_t offset_slot                 = MEMORY_ALIGN(offset_clazz                + SIZEOF_VOID_P,   sizeof(int32_t));
963         static const off_t offset_annotations          = MEMORY_ALIGN(offset_slot                 + sizeof(int32_t), SIZEOF_VOID_P);
964         static const off_t offset_parameterAnnotations = MEMORY_ALIGN(offset_annotations          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
965         static const off_t offset_declaredAnnotations  = MEMORY_ALIGN(offset_parameterAnnotations + SIZEOF_VOID_P,   SIZEOF_VOID_P);
966         static const off_t offset_cons                 = MEMORY_ALIGN(offset_declaredAnnotations  + SIZEOF_VOID_P,   SIZEOF_VOID_P);
967
968 public:
969         java_lang_reflect_VMConstructor(java_handle_t* h) : java_lang_Object(h) {}
970         java_lang_reflect_VMConstructor(jobject h);
971         java_lang_reflect_VMConstructor(java_handle_t* h, methodinfo* m);
972
973         // Getters.
974         inline classinfo*               get_clazz               () const;
975         inline int32_t                  get_slot                () const;
976         inline java_handle_bytearray_t* get_annotations         () const;
977         inline java_handle_bytearray_t* get_parameterAnnotations() const;
978         inline java_handle_t*           get_declaredAnnotations () const;
979         inline java_handle_t*           get_cons                () const;
980
981         // Setters.
982         inline void set_clazz               (classinfo* value);
983         inline void set_slot                (int32_t value);
984         inline void set_annotations         (java_handle_bytearray_t* value);
985         inline void set_parameterAnnotations(java_handle_bytearray_t* value);
986         inline void set_declaredAnnotations (java_handle_t* value);
987         inline void set_cons                (java_handle_t* value);
988
989         // Convenience functions.
990         inline methodinfo* get_method();
991 };
992
993 inline java_lang_reflect_VMConstructor::java_lang_reflect_VMConstructor(jobject h) : java_lang_Object(h)
994 {
995         java_lang_reflect_VMConstructor((java_handle_t*) h);
996 }
997
998 inline java_lang_reflect_VMConstructor::java_lang_reflect_VMConstructor(java_handle_t* h, methodinfo* m) : java_lang_Object(h)
999 {
1000         int                      slot                 = m - m->clazz->methods;
1001         java_handle_bytearray_t* annotations          = method_get_annotations(m);
1002         java_handle_bytearray_t* parameterAnnotations = method_get_parameterannotations(m);
1003
1004         set_clazz(m->clazz);
1005         set_slot(slot);
1006         set_annotations(annotations);
1007         set_parameterAnnotations(parameterAnnotations);
1008 }
1009
1010 inline classinfo* java_lang_reflect_VMConstructor::get_clazz() const
1011 {
1012         return get<classinfo*>(_handle, offset_clazz);
1013 }
1014
1015 inline int32_t java_lang_reflect_VMConstructor::get_slot() const
1016 {
1017         return get<int32_t>(_handle, offset_slot);
1018 }
1019
1020 inline java_handle_bytearray_t* java_lang_reflect_VMConstructor::get_annotations() const
1021 {
1022         return get<java_handle_bytearray_t*>(_handle, offset_annotations);
1023 }
1024
1025 inline java_handle_bytearray_t* java_lang_reflect_VMConstructor::get_parameterAnnotations() const
1026 {
1027         return get<java_handle_bytearray_t*>(_handle, offset_parameterAnnotations);
1028 }
1029
1030 inline java_handle_t* java_lang_reflect_VMConstructor::get_declaredAnnotations() const
1031 {
1032         return get<java_handle_t*>(_handle, offset_declaredAnnotations);
1033 }
1034
1035 inline java_handle_t* java_lang_reflect_VMConstructor::get_cons() const
1036 {
1037         return get<java_handle_t*>(_handle, offset_cons);
1038 }
1039
1040 inline void java_lang_reflect_VMConstructor::set_clazz(classinfo* value)
1041 {
1042         set(_handle, offset_clazz, value);
1043 }
1044
1045 inline void java_lang_reflect_VMConstructor::set_slot(int32_t value)
1046 {
1047         set(_handle, offset_slot, value);
1048 }
1049
1050 inline void java_lang_reflect_VMConstructor::set_annotations(java_handle_bytearray_t* value)
1051 {
1052         set(_handle, offset_annotations, value);
1053 }
1054
1055 inline void java_lang_reflect_VMConstructor::set_parameterAnnotations(java_handle_bytearray_t* value)
1056 {
1057         set(_handle, offset_parameterAnnotations, value);
1058 }
1059
1060 inline void java_lang_reflect_VMConstructor::set_declaredAnnotations(java_handle_t* value)
1061 {
1062         set(_handle, offset_declaredAnnotations, value);
1063 }
1064
1065 inline void java_lang_reflect_VMConstructor::set_cons(java_handle_t* value)
1066 {
1067         set(_handle, offset_cons, value);
1068 }
1069
1070 inline methodinfo* java_lang_reflect_VMConstructor::get_method()
1071 {
1072         classinfo*  c    = get_clazz();
1073         int32_t     slot = get_slot();
1074         methodinfo* m    = &(c->methods[slot]);
1075         return m;
1076 }
1077
1078
1079 /**
1080  * GNU Classpath java/lang/reflect/Field
1081  *
1082  * Object layout:
1083  *
1084  * 0. object header
1085  * 1. boolean                                    flag;
1086  * 2. gnu.java.lang.reflect.FieldSignatureParser p;
1087  * 3. java.lang.reflect.VMField                  f;
1088  */
1089 class java_lang_reflect_Field : public java_lang_Object, private FieldAccess {
1090 private:
1091         // Static offsets of the object's instance fields.
1092         // TODO These offsets need to be checked on VM startup.
1093         static const off_t offset_flag = MEMORY_ALIGN(sizeof(java_object_t),         sizeof(int32_t));
1094         static const off_t offset_p    = MEMORY_ALIGN(offset_flag + sizeof(int32_t), SIZEOF_VOID_P);
1095         static const off_t offset_f    = MEMORY_ALIGN(offset_p    + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1096
1097 public:
1098         java_lang_reflect_Field(java_handle_t* h) : java_lang_Object(h) {}
1099         java_lang_reflect_Field(jobject h);
1100
1101         static java_handle_t* create(fieldinfo* f);
1102
1103         // Getters.
1104         inline int32_t        get_flag() const;
1105         inline java_handle_t* get_f() const;
1106
1107         // Setters.
1108         inline void set_f(java_handle_t* value);
1109 };
1110
1111 inline java_lang_reflect_Field::java_lang_reflect_Field(jobject h) : java_lang_Object(h)
1112 {
1113         java_lang_reflect_Field((java_handle_t*) h);
1114 }
1115
1116 inline int32_t java_lang_reflect_Field::get_flag() const
1117 {
1118         return get<int32_t>(_handle, offset_flag);
1119 }
1120
1121 inline java_handle_t* java_lang_reflect_Field::get_f() const
1122 {
1123         return get<java_handle_t*>(_handle, offset_f);
1124 }
1125
1126 inline void java_lang_reflect_Field::set_f(java_handle_t* value)
1127 {
1128         set(_handle, offset_f, value);
1129 }
1130
1131
1132 /**
1133  * GNU Classpath java/lang/reflect/VMField
1134  *
1135  * Object layout:
1136  *
1137  * 0. object header
1138  * 1. java.lang.Class         clazz;
1139  * 2. java.lang.String        name;
1140  * 3. int                     slot;
1141  * 4. byte[]                  annotations;
1142  * 5. java.lang.Map           declaredAnnotations;
1143  * 6. java.lang.reflect.Field f;
1144  */
1145 class java_lang_reflect_VMField : public java_lang_Object, private FieldAccess {
1146 private:
1147         // Static offsets of the object's instance fields.
1148         // TODO These offsets need to be checked on VM startup.
1149         static const off_t offset_clazz               = MEMORY_ALIGN(sizeof(java_object_t),                        SIZEOF_VOID_P);
1150         static const off_t offset_name                = MEMORY_ALIGN(offset_clazz               + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1151         static const off_t offset_slot                = MEMORY_ALIGN(offset_name                + SIZEOF_VOID_P,   sizeof(int32_t));
1152         static const off_t offset_annotations         = MEMORY_ALIGN(offset_slot                + sizeof(int32_t), SIZEOF_VOID_P);
1153         static const off_t offset_declaredAnnotations = MEMORY_ALIGN(offset_annotations         + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1154         static const off_t offset_f                   = MEMORY_ALIGN(offset_declaredAnnotations + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1155
1156 public:
1157         java_lang_reflect_VMField(java_handle_t* h) : java_lang_Object(h) {}
1158         java_lang_reflect_VMField(jobject h);
1159         java_lang_reflect_VMField(java_handle_t* h, fieldinfo* f);
1160
1161         // Getters.
1162         inline classinfo*               get_clazz              () const;
1163         inline int32_t                  get_slot               () const;
1164         inline java_handle_bytearray_t* get_annotations        () const;
1165         inline java_handle_t*           get_declaredAnnotations() const;
1166         inline java_handle_t*           get_f                  () const;
1167
1168         // Setters.
1169         inline void set_clazz              (classinfo* value);
1170         inline void set_name               (java_handle_t* value);
1171         inline void set_slot               (int32_t value);
1172         inline void set_annotations        (java_handle_bytearray_t* value);
1173         inline void set_declaredAnnotations(java_handle_t* value);
1174         inline void set_f                  (java_handle_t* value);
1175
1176         // Convenience functions.
1177         inline fieldinfo* get_field() const;
1178 };
1179
1180 inline java_lang_reflect_VMField::java_lang_reflect_VMField(jobject h) : java_lang_Object(h)
1181 {
1182         java_lang_reflect_VMField((java_handle_t*) h);
1183 }
1184
1185 inline java_lang_reflect_VMField::java_lang_reflect_VMField(java_handle_t* h, fieldinfo* f) : java_lang_Object(h)
1186 {
1187         java_handle_t*           name        = javastring_intern(javastring_new(f->name));
1188         int                      slot        = f - f->clazz->fields;
1189         java_handle_bytearray_t* annotations = field_get_annotations(f);
1190
1191         set_clazz(f->clazz);
1192         set_name(name);
1193         set_slot(slot);
1194         set_annotations(annotations);
1195 }
1196
1197 inline classinfo* java_lang_reflect_VMField::get_clazz() const
1198 {
1199         return get<classinfo*>(_handle, offset_clazz);
1200 }
1201
1202 inline int32_t java_lang_reflect_VMField::get_slot() const
1203 {
1204         return get<int32_t>(_handle, offset_slot);
1205 }
1206
1207 inline java_handle_bytearray_t* java_lang_reflect_VMField::get_annotations() const
1208 {
1209         return get<java_handle_bytearray_t*>(_handle, offset_annotations);
1210 }
1211
1212 inline java_handle_t* java_lang_reflect_VMField::get_declaredAnnotations() const
1213 {
1214         return get<java_handle_t*>(_handle, offset_declaredAnnotations);
1215 }
1216
1217 inline java_handle_t* java_lang_reflect_VMField::get_f() const
1218 {
1219         return get<java_handle_t*>(_handle, offset_f);
1220 }
1221
1222 inline void java_lang_reflect_VMField::set_clazz(classinfo* value)
1223 {
1224         set(_handle, offset_clazz, value);
1225 }
1226
1227 inline void java_lang_reflect_VMField::set_name(java_handle_t* value)
1228 {
1229         set(_handle, offset_name, value);
1230 }
1231
1232 inline void java_lang_reflect_VMField::set_slot(int32_t value)
1233 {
1234         set(_handle, offset_slot, value);
1235 }
1236
1237 inline void java_lang_reflect_VMField::set_annotations(java_handle_bytearray_t* value)
1238 {
1239         set(_handle, offset_annotations, value);
1240 }
1241
1242 inline void java_lang_reflect_VMField::set_declaredAnnotations(java_handle_t* value)
1243 {
1244         set(_handle, offset_declaredAnnotations, value);
1245 }
1246
1247 inline void java_lang_reflect_VMField::set_f(java_handle_t* value)
1248 {
1249         set(_handle, offset_f, value);
1250 }
1251
1252 inline fieldinfo* java_lang_reflect_VMField::get_field() const
1253 {
1254         classinfo* c    = get_clazz();
1255         int32_t    slot = get_slot();
1256         fieldinfo* f    = &(c->fields[slot]);
1257         return f;
1258 }
1259
1260
1261 /**
1262  * GNU Classpath java/lang/reflect/Method
1263  *
1264  * Object layout:
1265  *
1266  * 0. object header
1267  * 1. boolean                                     flag;
1268  * 2. gnu.java.lang.reflect.MethodSignatureParser p;
1269  * 3. java.lang.reflect.VMMethod                  m;
1270  */
1271 class java_lang_reflect_Method : public java_lang_Object, private FieldAccess {
1272 private:
1273         // Static offsets of the object's instance fields.
1274         // TODO These offsets need to be checked on VM startup.
1275         static const off_t offset_flag = MEMORY_ALIGN(sizeof(java_object_t),         sizeof(int32_t));
1276         static const off_t offset_p    = MEMORY_ALIGN(offset_flag + sizeof(int32_t), SIZEOF_VOID_P);
1277         static const off_t offset_m    = MEMORY_ALIGN(offset_p    + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1278
1279 public:
1280         java_lang_reflect_Method(java_handle_t* h) : java_lang_Object(h) {}
1281         java_lang_reflect_Method(jobject h);
1282
1283         static java_handle_t* create(methodinfo* m);
1284
1285         // Getters.
1286         inline int32_t        get_flag() const;
1287         inline java_handle_t* get_m() const;
1288
1289         // Setters.
1290         inline void set_m(java_handle_t* value);
1291 };
1292
1293 inline java_lang_reflect_Method::java_lang_reflect_Method(jobject h) : java_lang_Object(h)
1294 {
1295         java_lang_reflect_Method((java_handle_t*) h);
1296 }
1297
1298 inline int32_t java_lang_reflect_Method::get_flag() const
1299 {
1300         return get<int32_t>(_handle, offset_flag);
1301 }
1302
1303 inline java_handle_t* java_lang_reflect_Method::get_m() const
1304 {
1305         return get<java_handle_t*>(_handle, offset_m);
1306 }
1307
1308 inline void java_lang_reflect_Method::set_m(java_handle_t* value)
1309 {
1310         set(_handle, offset_m, value);
1311 }
1312
1313
1314 /**
1315  * GNU Classpath java/lang/reflect/VMMethod
1316  *
1317  * Object layout:
1318  *
1319  * 0. object header
1320  * 1. java.lang.Class          clazz;
1321  * 2. java.lang.String         name;
1322  * 3. int                      slot;
1323  * 4. byte[]                   annotations;
1324  * 5. byte[]                   parameterAnnotations;
1325  * 6. byte[]                   annotationDefault;
1326  * 7. java.lang.Map            declaredAnnotations;
1327  * 8. java.lang.reflect.Method m;
1328  */
1329 class java_lang_reflect_VMMethod : public java_lang_Object, private FieldAccess {
1330 private:
1331         // Static offsets of the object's instance fields.
1332         // TODO These offsets need to be checked on VM startup.
1333         static const off_t offset_clazz                = MEMORY_ALIGN(sizeof(java_object_t),                         SIZEOF_VOID_P);
1334         static const off_t offset_name                 = MEMORY_ALIGN(offset_clazz                + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1335         static const off_t offset_slot                 = MEMORY_ALIGN(offset_name                 + SIZEOF_VOID_P,   sizeof(int32_t));
1336         static const off_t offset_annotations          = MEMORY_ALIGN(offset_slot                 + sizeof(int32_t), SIZEOF_VOID_P);
1337         static const off_t offset_parameterAnnotations = MEMORY_ALIGN(offset_annotations          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1338         static const off_t offset_annotationDefault    = MEMORY_ALIGN(offset_parameterAnnotations + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1339         static const off_t offset_declaredAnnotations  = MEMORY_ALIGN(offset_annotationDefault    + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1340         static const off_t offset_m                    = MEMORY_ALIGN(offset_declaredAnnotations  + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1341
1342 public:
1343         java_lang_reflect_VMMethod(java_handle_t* h) : java_lang_Object(h) {}
1344         java_lang_reflect_VMMethod(jobject h);
1345         java_lang_reflect_VMMethod(java_handle_t* h, methodinfo* m);
1346
1347         // Getters.
1348         inline classinfo*               get_clazz               () const;
1349         inline int32_t                  get_slot                () const;
1350         inline java_handle_bytearray_t* get_annotations         () const;
1351         inline java_handle_bytearray_t* get_parameterAnnotations() const;
1352         inline java_handle_bytearray_t* get_annotationDefault   () const;
1353         inline java_handle_t*           get_declaredAnnotations () const;
1354         inline java_handle_t*           get_m                   () const;
1355
1356         // Setters.
1357         inline void set_clazz               (classinfo* value);
1358         inline void set_name                (java_handle_t* value);
1359         inline void set_slot                (int32_t value);
1360         inline void set_annotations         (java_handle_bytearray_t* value);
1361         inline void set_parameterAnnotations(java_handle_bytearray_t* value);
1362         inline void set_annotationDefault   (java_handle_bytearray_t* value);
1363         inline void set_declaredAnnotations (java_handle_t* value);
1364         inline void set_m                   (java_handle_t* value);
1365
1366         // Convenience functions.
1367         inline methodinfo* get_method() const;
1368 };
1369
1370 inline java_lang_reflect_VMMethod::java_lang_reflect_VMMethod(jobject h) : java_lang_Object(h)
1371 {
1372         java_lang_reflect_VMMethod((java_handle_t*) h);
1373 }
1374
1375 inline java_lang_reflect_VMMethod::java_lang_reflect_VMMethod(java_handle_t* h, methodinfo* m) : java_lang_Object(h)
1376 {
1377         java_handle_t*           name                 = javastring_intern(javastring_new(m->name));
1378         int                      slot                 = m - m->clazz->methods;
1379         java_handle_bytearray_t* annotations          = method_get_annotations(m);
1380         java_handle_bytearray_t* parameterAnnotations = method_get_parameterannotations(m);
1381         java_handle_bytearray_t* annotationDefault    = method_get_annotationdefault(m);
1382
1383         set_clazz(m->clazz);
1384         set_name(name);
1385         set_slot(slot);
1386         set_annotations(annotations);
1387         set_parameterAnnotations(parameterAnnotations);
1388         set_annotationDefault(annotationDefault);
1389 }
1390
1391 inline classinfo* java_lang_reflect_VMMethod::get_clazz() const
1392 {
1393         return get<classinfo*>(_handle, offset_clazz);
1394 }
1395
1396 inline int32_t java_lang_reflect_VMMethod::get_slot() const
1397 {
1398         return get<int32_t>(_handle, offset_slot);
1399 }
1400
1401 inline java_handle_bytearray_t* java_lang_reflect_VMMethod::get_annotations() const
1402 {
1403         return get<java_handle_bytearray_t*>(_handle, offset_annotations);
1404 }
1405
1406 inline java_handle_bytearray_t* java_lang_reflect_VMMethod::get_parameterAnnotations() const
1407 {
1408         return get<java_handle_bytearray_t*>(_handle, offset_parameterAnnotations);
1409 }
1410
1411 inline java_handle_bytearray_t* java_lang_reflect_VMMethod::get_annotationDefault() const
1412 {
1413         return get<java_handle_bytearray_t*>(_handle, offset_annotationDefault);
1414 }
1415
1416 inline java_handle_t* java_lang_reflect_VMMethod::get_declaredAnnotations() const
1417 {
1418         return get<java_handle_t*>(_handle, offset_declaredAnnotations);
1419 }
1420
1421 inline java_handle_t* java_lang_reflect_VMMethod::get_m() const
1422 {
1423         return get<java_handle_t*>(_handle, offset_m);
1424 }
1425
1426 inline void java_lang_reflect_VMMethod::set_clazz(classinfo* value)
1427 {
1428         set(_handle, offset_clazz, value);
1429 }
1430
1431 inline void java_lang_reflect_VMMethod::set_name(java_handle_t* value)
1432 {
1433         set(_handle, offset_name, value);
1434 }
1435
1436 inline void java_lang_reflect_VMMethod::set_slot(int32_t value)
1437 {
1438         set(_handle, offset_slot, value);
1439 }
1440
1441 inline void java_lang_reflect_VMMethod::set_annotations(java_handle_bytearray_t* value)
1442 {
1443         set(_handle, offset_annotations, value);
1444 }
1445
1446 inline void java_lang_reflect_VMMethod::set_parameterAnnotations(java_handle_bytearray_t* value)
1447 {
1448         set(_handle, offset_parameterAnnotations, value);
1449 }
1450
1451 inline void java_lang_reflect_VMMethod::set_annotationDefault(java_handle_bytearray_t* value)
1452 {
1453         set(_handle, offset_annotationDefault, value);
1454 }
1455
1456 inline void java_lang_reflect_VMMethod::set_declaredAnnotations(java_handle_t* value)
1457 {
1458         set(_handle, offset_declaredAnnotations, value);
1459 }
1460
1461 inline void java_lang_reflect_VMMethod::set_m(java_handle_t* value)
1462 {
1463         set(_handle, offset_m, value);
1464 }
1465
1466 inline methodinfo* java_lang_reflect_VMMethod::get_method() const
1467 {
1468         classinfo*  c    = get_clazz();
1469         int32_t     slot = get_slot();
1470         methodinfo* m    = &(c->methods[slot]);
1471         return m;
1472 }
1473
1474
1475 /**
1476  * GNU Classpath java/nio/Buffer
1477  *
1478  * Object layout:
1479  *
1480  * 0. object header
1481  * 1. int                   cap;
1482  * 2. int                   limit;
1483  * 3. int                   pos;
1484  * 4. int                   mark;
1485  * 5. gnu.classpath.Pointer address;
1486  */
1487 class java_nio_Buffer : public java_lang_Object, private FieldAccess {
1488 private:
1489         // Static offsets of the object's instance fields.
1490         // TODO These offsets need to be checked on VM startup.
1491         static const off_t offset_cap     = MEMORY_ALIGN(sizeof(java_object_t),          sizeof(int32_t));
1492         static const off_t offset_limit   = MEMORY_ALIGN(offset_cap   + sizeof(int32_t), sizeof(int32_t));
1493         static const off_t offset_pos     = MEMORY_ALIGN(offset_limit + sizeof(int32_t), sizeof(int32_t));
1494         static const off_t offset_mark    = MEMORY_ALIGN(offset_pos   + sizeof(int32_t), sizeof(int32_t));
1495         static const off_t offset_address = MEMORY_ALIGN(offset_mark  + sizeof(int32_t), SIZEOF_VOID_P);
1496
1497 public:
1498         java_nio_Buffer(java_handle_t* h) : java_lang_Object(h) {}
1499
1500         // Getters.
1501         inline int32_t get_cap() const;
1502 };
1503
1504 inline int32_t java_nio_Buffer::get_cap() const
1505 {
1506         return get<int32_t>(_handle, offset_cap);
1507 }
1508
1509
1510 /**
1511  * GNU Classpath java/nio/DirectByteBufferImpl
1512  *
1513  * Object layout:
1514  *
1515  * 0. object header
1516  * 1. int                   cap;
1517  * 2. int                   limit;
1518  * 3. int                   pos;
1519  * 4. int                   mark;
1520  * 5. gnu.classpath.Pointer address;
1521  * 6. java.nio.ByteOrder    endian;
1522  * 7. byte[]                backing_buffer;
1523  * 8. int                   array_offset;
1524  * 9. java.lang.Object      owner;
1525  */
1526 class java_nio_DirectByteBufferImpl : public java_lang_Object, private FieldAccess {
1527 private:
1528         // Static offsets of the object's instance fields.
1529         // TODO These offsets need to be checked on VM startup.
1530         static const off_t offset_cap            = MEMORY_ALIGN(sizeof(java_object_t),                   sizeof(int32_t));
1531         static const off_t offset_limit          = MEMORY_ALIGN(offset_cap            + sizeof(int32_t), sizeof(int32_t));
1532         static const off_t offset_pos            = MEMORY_ALIGN(offset_limit          + sizeof(int32_t), sizeof(int32_t));
1533         static const off_t offset_mark           = MEMORY_ALIGN(offset_pos            + sizeof(int32_t), sizeof(int32_t));
1534         static const off_t offset_address        = MEMORY_ALIGN(offset_mark           + sizeof(int32_t), SIZEOF_VOID_P);
1535         static const off_t offset_endian         = MEMORY_ALIGN(offset_address        + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1536         static const off_t offset_backing_buffer = MEMORY_ALIGN(offset_endian         + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1537         static const off_t offset_array_offset   = MEMORY_ALIGN(offset_backing_buffer + SIZEOF_VOID_P,   sizeof(int32_t));
1538         static const off_t offset_owner          = MEMORY_ALIGN(offset_array_offset   + sizeof(int32_t), SIZEOF_VOID_P);
1539
1540 public:
1541         java_nio_DirectByteBufferImpl(java_handle_t* h) : java_lang_Object(h) {}
1542         java_nio_DirectByteBufferImpl(jobject h);
1543
1544         // Getters.
1545         inline java_handle_t* get_address() const;
1546 };
1547
1548 inline java_nio_DirectByteBufferImpl::java_nio_DirectByteBufferImpl(jobject h) : java_lang_Object(h)
1549 {
1550         java_nio_DirectByteBufferImpl((java_handle_t*) h);
1551 }
1552
1553 inline java_handle_t* java_nio_DirectByteBufferImpl::get_address() const
1554 {
1555         return get<java_handle_t*>(_handle, offset_address);
1556 }
1557
1558
1559 /**
1560  * GNU Classpath gnu/classpath/Pointer
1561  *
1562  * Actually there are two classes, gnu.classpath.Pointer32 and
1563  * gnu.classpath.Pointer64, but we only define the abstract super
1564  * class and use the int/long field as void* type.
1565  *
1566  * Object layout:
1567  *
1568  * 0. object header
1569  * 1. int/long data;
1570  */
1571 class gnu_classpath_Pointer : public java_lang_Object, private FieldAccess {
1572 private:
1573         // Static offsets of the object's instance fields.
1574         // TODO These offsets need to be checked on VM startup.
1575         static const off_t offset_data = MEMORY_ALIGN(sizeof(java_object_t), SIZEOF_VOID_P);
1576
1577 public:
1578         gnu_classpath_Pointer(java_handle_t* h) : java_lang_Object(h) {}
1579         gnu_classpath_Pointer(java_handle_t* h, void* data);
1580
1581         // Setters.
1582         inline void* get_data() const;
1583
1584         // Setters.
1585         inline void set_data(void* value);
1586 };
1587
1588 inline gnu_classpath_Pointer::gnu_classpath_Pointer(java_handle_t* h, void* data) : java_lang_Object(h)
1589 {
1590         set_data(data);
1591 }
1592
1593 inline void* gnu_classpath_Pointer::get_data() const
1594 {
1595         return get<void*>(_handle, offset_data);
1596 }
1597
1598 inline void gnu_classpath_Pointer::set_data(void* value)
1599 {
1600         set(_handle, offset_data, value);
1601 }
1602
1603
1604 # if defined(ENABLE_ANNOTATIONS)
1605 /**
1606  * GNU Classpath sun/reflect/ConstantPool
1607  *
1608  * Object layout:
1609  *
1610  * 0. object header
1611  * 1. java.lang.Object constantPoolOop;
1612  */
1613 class sun_reflect_ConstantPool : public java_lang_Object, private FieldAccess {
1614 private:
1615         // Static offsets of the object's instance fields.
1616         // TODO These offsets need to be checked on VM startup.
1617         static const off_t offset_constantPoolOop = MEMORY_ALIGN(sizeof(java_object_t), SIZEOF_VOID_P);
1618
1619 public:
1620         sun_reflect_ConstantPool(java_handle_t* h) : java_lang_Object(h) {}
1621
1622         // Setters.
1623         inline void set_constantPoolOop(classinfo* value);
1624         inline void set_constantPoolOop(jclass value);
1625 };
1626
1627 inline void sun_reflect_ConstantPool::set_constantPoolOop(classinfo* value)
1628 {
1629         set(_handle, offset_constantPoolOop, value);
1630 }
1631
1632 inline void sun_reflect_ConstantPool::set_constantPoolOop(jclass value)
1633 {
1634         // XXX jclass is a boxed object.
1635         set_constantPoolOop(LLNI_classinfo_unwrap(value));
1636 }
1637 # endif // ENABLE_ANNOTATIONS
1638
1639 #endif // WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH
1640
1641
1642 #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1643
1644 /**
1645  * OpenJDK java/lang/reflect/Constructor
1646  *
1647  * Object layout:
1648  *
1649  * 0.  object header
1650  * 1.  boolean                                               override;
1651  * 2.  java.lang.Class                                       clazz;
1652  * 3.  int                                                   slot;
1653  * 4.  java.lang.Class[]                                     parameterTypes;
1654  * 5.  java.lang.Class[]                                     exceptionTypes;
1655  * 6.  int                                                   modifiers;
1656  * 7.  java.lang.String                                      signature;
1657  * 8.  sun.reflect.generics.repository.ConstructorRepository genericInfo;
1658  * 9.  byte[]                                                annotations;
1659  * 10. byte[]                                                parameterAnnotations;
1660  * 11. java.lang.Class                                       securityCheckCache;
1661  * 12. sun.reflect.ConstructorAccessor                       constructorAccessor;
1662  * 13. java.lang.reflect.Constructor                         root;
1663  * 14. java.util.Map                                         declaredAnnotations;
1664  */
1665 class java_lang_reflect_VMConstructor : public java_lang_Object, private FieldAccess {
1666 private:
1667         // Static offsets of the object's instance fields.
1668         // TODO These offsets need to be checked on VM startup.
1669         static const off_t offset_clazz                = MEMORY_ALIGN(sizeof(java_object_t),                         SIZEOF_VOID_P);
1670         static const off_t offset_slot                 = MEMORY_ALIGN(offset_clazz                + SIZEOF_VOID_P,   sizeof(int32_t));
1671         static const off_t offset_annotations          = MEMORY_ALIGN(offset_slot                 + sizeof(int32_t), SIZEOF_VOID_P);
1672         static const off_t offset_parameterAnnotations = MEMORY_ALIGN(offset_annotations          + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1673         static const off_t offset_declaredAnnotations  = MEMORY_ALIGN(offset_parameterAnnotations + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1674         static const off_t offset_cons                 = MEMORY_ALIGN(offset_declaredAnnotations  + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1675
1676 public:
1677         java_lang_reflect_VMConstructor(java_handle_t* h) : java_lang_Object(h) {}
1678         java_lang_reflect_VMConstructor(jobject h);
1679         java_lang_reflect_VMConstructor(java_handle_t* h, methodinfo* m);
1680
1681         // Getters.
1682         inline classinfo*               get_clazz               () const;
1683         inline int32_t                  get_slot                () const;
1684         inline java_handle_bytearray_t* get_annotations         () const;
1685         inline java_handle_bytearray_t* get_parameterAnnotations() const;
1686         inline java_handle_t*           get_declaredAnnotations () const;
1687         inline java_handle_t*           get_cons                () const;
1688
1689         // Setters.
1690         inline void set_clazz               (classinfo* value);
1691         inline void set_slot                (int32_t value);
1692         inline void set_annotations         (java_handle_bytearray_t* value);
1693         inline void set_parameterAnnotations(java_handle_bytearray_t* value);
1694         inline void set_declaredAnnotations (java_handle_t* value);
1695         inline void set_cons                (java_handle_t* value);
1696
1697         // Convenience functions.
1698         inline methodinfo* get_method();
1699 };
1700
1701 inline java_lang_reflect_VMConstructor::java_lang_reflect_VMConstructor(jobject h) : java_lang_Object(h)
1702 {
1703         java_lang_reflect_VMConstructor((java_handle_t*) h);
1704 }
1705
1706 inline java_lang_reflect_VMConstructor::java_lang_reflect_VMConstructor(java_handle_t* h, methodinfo* m) : java_lang_Object(h)
1707 {
1708         int                      slot                 = m - m->clazz->methods;
1709         java_handle_bytearray_t* annotations          = method_get_annotations(m);
1710         java_handle_bytearray_t* parameterAnnotations = method_get_parameterannotations(m);
1711
1712         set_clazz(m->clazz);
1713         set_slot(slot);
1714         set_annotations(annotations);
1715         set_parameterAnnotations(parameterAnnotations);
1716 }
1717
1718 inline classinfo* java_lang_reflect_VMConstructor::get_clazz() const
1719 {
1720         return get<classinfo*>(_handle, offset_clazz);
1721 }
1722
1723 inline int32_t java_lang_reflect_VMConstructor::get_slot() const
1724 {
1725         return get<int32_t>(_handle, offset_slot);
1726 }
1727
1728 inline java_handle_bytearray_t* java_lang_reflect_VMConstructor::get_annotations() const
1729 {
1730         return get<java_handle_bytearray_t*>(_handle, offset_annotations);
1731 }
1732
1733 inline java_handle_bytearray_t* java_lang_reflect_VMConstructor::get_parameterAnnotations() const
1734 {
1735         return get<java_handle_bytearray_t*>(_handle, offset_parameterAnnotations);
1736 }
1737
1738 inline java_handle_t* java_lang_reflect_VMConstructor::get_declaredAnnotations() const
1739 {
1740         return get<java_handle_t*>(_handle, offset_declaredAnnotations);
1741 }
1742
1743 inline java_handle_t* java_lang_reflect_VMConstructor::get_cons() const
1744 {
1745         return get<java_handle_t*>(_handle, offset_cons);
1746 }
1747
1748 inline void java_lang_reflect_VMConstructor::set_clazz(classinfo* value)
1749 {
1750         set(_handle, offset_clazz, value);
1751 }
1752
1753 inline void java_lang_reflect_VMConstructor::set_slot(int32_t value)
1754 {
1755         set(_handle, offset_slot, value);
1756 }
1757
1758 inline void java_lang_reflect_VMConstructor::set_annotations(java_handle_bytearray_t* value)
1759 {
1760         set(_handle, offset_annotations, value);
1761 }
1762
1763 inline void java_lang_reflect_VMConstructor::set_parameterAnnotations(java_handle_bytearray_t* value)
1764 {
1765         set(_handle, offset_parameterAnnotations, value);
1766 }
1767
1768 inline void java_lang_reflect_VMConstructor::set_declaredAnnotations(java_handle_t* value)
1769 {
1770         set(_handle, offset_declaredAnnotations, value);
1771 }
1772
1773 inline void java_lang_reflect_VMConstructor::set_cons(java_handle_t* value)
1774 {
1775         set(_handle, offset_cons, value);
1776 }
1777
1778 inline methodinfo* java_lang_reflect_VMConstructor::get_method()
1779 {
1780         classinfo*  c    = get_clazz();
1781         int32_t     slot = get_slot();
1782         methodinfo* m    = &(c->methods[slot]);
1783         return m;
1784 }
1785
1786 #endif // WITH_JAVA_RUNTIME_LIBRARY_OPENJDK
1787
1788 #if defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
1789
1790 /**
1791  * CLDC 1.1 com/sun/cldchi/jvm/FileDescriptor
1792  *
1793  * Object layout:
1794  *
1795  * 0. object header
1796  * 1. long   pointer;
1797  * 2. int    position;
1798  * 3. int    length;
1799  */
1800 class com_sun_cldchi_jvm_FileDescriptor : public java_lang_Object, private FieldAccess {
1801 private:
1802         // Static offsets of the object's instance fields.
1803         // TODO These offsets need to be checked on VM startup.
1804         static const off_t offset_pointer  = MEMORY_ALIGN(sizeof(java_object_t),             sizeof(int64_t));
1805         static const off_t offset_position = MEMORY_ALIGN(offset_pointer  + sizeof(int64_t), sizeof(int32_t));
1806         static const off_t offset_length   = MEMORY_ALIGN(offset_position + sizeof(int32_t), sizeof(int32_t));
1807
1808 public:
1809         com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h) : java_lang_Object(h) {}
1810         com_sun_cldchi_jvm_FileDescriptor(jobject h);
1811         com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h, int64_t pointer, int32_t position, int32_t length);
1812         com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h, com_sun_cldchi_jvm_FileDescriptor& fd);
1813
1814         // Getters.
1815         inline int64_t get_pointer () const;
1816         inline int32_t get_position() const;
1817         inline int32_t get_length  () const;
1818
1819         // Setters.
1820         inline void set_pointer (int64_t value);
1821         inline void set_position(int32_t value);
1822         inline void set_length  (int32_t value);
1823 };
1824
1825
1826 inline com_sun_cldchi_jvm_FileDescriptor::com_sun_cldchi_jvm_FileDescriptor(jobject h) : java_lang_Object(h)
1827 {
1828         com_sun_cldchi_jvm_FileDescriptor((java_handle_t*) h);
1829 }
1830
1831 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)
1832 {
1833         set_pointer(pointer);
1834         set_position(position);
1835         set_length(length);
1836 }
1837
1838 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)
1839 {
1840         com_sun_cldchi_jvm_FileDescriptor(h, fd.get_pointer(), fd.get_position(), fd.get_length());
1841 }
1842
1843
1844 inline int64_t com_sun_cldchi_jvm_FileDescriptor::get_pointer() const
1845 {
1846         return get<int64_t>(_handle, offset_pointer);
1847 }
1848
1849 inline int32_t com_sun_cldchi_jvm_FileDescriptor::get_position() const
1850 {
1851         return get<int32_t>(_handle, offset_position);
1852 }
1853
1854 inline int32_t com_sun_cldchi_jvm_FileDescriptor::get_length() const
1855 {
1856         return get<int32_t>(_handle, offset_length);
1857 }
1858
1859
1860 inline void com_sun_cldchi_jvm_FileDescriptor::set_pointer(int64_t value)
1861 {
1862         set(_handle, offset_pointer, value);
1863 }
1864
1865 inline void com_sun_cldchi_jvm_FileDescriptor::set_position(int32_t value)
1866 {
1867         set(_handle, offset_position, value);
1868 }
1869
1870 inline void com_sun_cldchi_jvm_FileDescriptor::set_length(int32_t value)
1871 {
1872         set(_handle, offset_length, value);
1873 }
1874
1875
1876 /**
1877  * CLDC 1.1 java/lang/String
1878  *
1879  * Object layout:
1880  *
1881  * 0. object header
1882  * 1. char[] value;
1883  * 2. int    offset;
1884  * 3. int    count;
1885  */
1886 class java_lang_String : public java_lang_Object, private FieldAccess {
1887 private:
1888         // Static offsets of the object's instance fields.
1889         // TODO These offsets need to be checked on VM startup.
1890         static const off_t offset_value  = MEMORY_ALIGN(sizeof(java_object_t),           SIZEOF_VOID_P);
1891         static const off_t offset_offset = MEMORY_ALIGN(offset_value  + SIZEOF_VOID_P,   sizeof(int32_t));
1892         static const off_t offset_count  = MEMORY_ALIGN(offset_offset + sizeof(int32_t), sizeof(int32_t));
1893
1894 public:
1895         java_lang_String(java_handle_t* h) : java_lang_Object(h) {}
1896         java_lang_String(jstring h);
1897         java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset = 0);
1898
1899         // Getters.
1900         inline java_handle_chararray_t* get_value () const;
1901         inline int32_t                  get_offset() const;
1902         inline int32_t                  get_count () const;
1903
1904         // Setters.
1905         inline void set_value (java_handle_chararray_t* value);
1906         inline void set_offset(int32_t value);
1907         inline void set_count (int32_t value);
1908 };
1909
1910 inline java_lang_String::java_lang_String(jstring h) : java_lang_Object(h)
1911 {
1912         java_lang_String((java_handle_t*) h);
1913 }
1914
1915 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)
1916 {
1917         set_value(value);
1918         set_offset(offset);
1919         set_count(count);
1920 }
1921
1922 inline java_handle_chararray_t* java_lang_String::get_value() const
1923 {
1924         return get<java_handle_chararray_t*>(_handle, offset_value);
1925 }
1926
1927 inline int32_t java_lang_String::get_offset() const
1928 {
1929         return get<int32_t>(_handle, offset_offset);
1930 }
1931
1932 inline int32_t java_lang_String::get_count() const
1933 {
1934         return get<int32_t>(_handle, offset_count);
1935 }
1936
1937 inline void java_lang_String::set_value(java_handle_chararray_t* value)
1938 {
1939         set(_handle, offset_value, value);
1940 }
1941
1942 inline void java_lang_String::set_offset(int32_t value)
1943 {
1944         set(_handle, offset_offset, value);
1945 }
1946
1947 inline void java_lang_String::set_count(int32_t value)
1948 {
1949         set(_handle, offset_count, value);
1950 }
1951
1952
1953 /**
1954  * CLDC 1.1 java/lang/Thread
1955  *
1956  * Object layout:
1957  *
1958  * 0. object header
1959  * 1. int                priority;
1960  * 2. java.lang.Runnable runnable;
1961  * 3. java.lang.Object   vm_thread;
1962  * 4. int                is_terminated;
1963  * 5. int                is_stillborn;
1964  * 6. char[]             name;
1965  */
1966 class java_lang_Thread : public java_lang_Object, private FieldAccess {
1967 private:
1968         // Static offsets of the object's instance fields.
1969         // TODO These offsets need to be checked on VM startup.
1970         static const off_t offset_priority      = MEMORY_ALIGN(sizeof(java_object_t),              sizeof(int32_t));
1971         static const off_t offset_runnable      = MEMORY_ALIGN(offset_priority      + sizeof(int32_t), SIZEOF_VOID_P);
1972         static const off_t offset_vm_thread     = MEMORY_ALIGN(offset_runnable      + SIZEOF_VOID_P,   SIZEOF_VOID_P);
1973         static const off_t offset_is_terminated = MEMORY_ALIGN(offset_vm_thread     + SIZEOF_VOID_P,   sizeof(int32_t));
1974         static const off_t offset_is_stillborn  = MEMORY_ALIGN(offset_is_terminated + sizeof(int32_t), sizeof(int32_t));
1975         static const off_t offset_name          = MEMORY_ALIGN(offset_is_stillborn  + sizeof(int32_t), SIZEOF_VOID_P);
1976
1977 public:
1978         java_lang_Thread(java_handle_t* h) : java_lang_Object(h) {}
1979         java_lang_Thread(jobject h);
1980 //      java_lang_Thread(threadobject* t);
1981
1982         // Getters.
1983         inline int32_t                  get_priority () const;
1984         inline threadobject*            get_vm_thread() const;
1985         inline java_handle_chararray_t* get_name     () const;
1986
1987         // Setters.
1988         inline void set_vm_thread(threadobject* value);
1989 };
1990
1991
1992 inline java_lang_Thread::java_lang_Thread(jobject h) : java_lang_Object(h)
1993 {
1994         java_lang_Thread((java_handle_t*) h);
1995 }
1996
1997 // inline java_lang_Thread::java_lang_Thread(threadobject* t) : java_lang_Object(h)
1998 // {
1999 //      java_lang_Thread(thread_get_object(t));
2000 // }
2001
2002
2003 inline int32_t java_lang_Thread::get_priority() const
2004 {
2005         return get<int32_t>(_handle, offset_priority);
2006 }
2007
2008 inline threadobject* java_lang_Thread::get_vm_thread() const
2009 {
2010         return get<threadobject*>(_handle, offset_vm_thread);
2011 }
2012
2013 inline java_handle_chararray_t* java_lang_Thread::get_name() const
2014 {
2015         return get<java_handle_chararray_t*>(_handle, offset_name);
2016 }
2017
2018
2019 inline void java_lang_Thread::set_vm_thread(threadobject* value)
2020 {
2021         set(_handle, offset_vm_thread, value);
2022 }
2023
2024
2025 /**
2026  * CLDC 1.1 java/lang/Throwable
2027  *
2028  * Object layout:
2029  *
2030  * 0. object header
2031  * 1. java.lang.String detailMessage;
2032  * 2. java.lang.Object backtrace;
2033  */
2034 class java_lang_Throwable : public java_lang_Object, private FieldAccess {
2035 private:
2036         // Static offsets of the object's instance fields.
2037         // TODO These offsets need to be checked on VM startup.
2038         static const off_t offset_detailMessage = MEMORY_ALIGN(sizeof(java_object_t),                SIZEOF_VOID_P);
2039         static const off_t offset_backtrace     = MEMORY_ALIGN(offset_detailMessage + SIZEOF_VOID_P, SIZEOF_VOID_P);
2040
2041 public:
2042         java_lang_Throwable(java_handle_t* h) : java_lang_Object(h) {}
2043         java_lang_Throwable(jobject h);
2044
2045         // Getters.
2046         inline java_handle_t*           get_detailMessage() const;
2047         inline java_handle_bytearray_t* get_backtrace    () const;
2048
2049         // Setters.
2050         inline void set_backtrace(java_handle_bytearray_t* value);
2051 };
2052
2053
2054 inline java_lang_Throwable::java_lang_Throwable(jobject h) : java_lang_Object(h)
2055 {
2056         java_lang_Throwable((java_handle_t*) h);
2057 }
2058
2059
2060 inline java_handle_t* java_lang_Throwable::get_detailMessage() const
2061 {
2062         return get<java_handle_t*>(_handle, offset_detailMessage);
2063 }
2064
2065 inline java_handle_bytearray_t* java_lang_Throwable::get_backtrace() const
2066 {
2067         return get<java_handle_bytearray_t*>(_handle, offset_backtrace);
2068 }
2069
2070
2071 inline void java_lang_Throwable::set_backtrace(java_handle_bytearray_t* value)
2072 {
2073         set(_handle, offset_backtrace, value);
2074 }
2075
2076 #endif // WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1
2077
2078 #else
2079
2080 // Legacy C interface.
2081 java_handle_t* java_lang_reflect_Constructor_create(methodinfo* m);
2082 java_handle_t* java_lang_reflect_Field_create(fieldinfo* f);
2083 java_handle_t* java_lang_reflect_Method_create(methodinfo* m);
2084
2085 #endif
2086
2087 #endif // _JAVAOBJECTS_HPP
2088
2089
2090 /*
2091  * These are local overrides for various environment variables in Emacs.
2092  * Please do not remove this and leave it at the end of the file, where
2093  * Emacs will automagically detect them.
2094  * ---------------------------------------------------------------------
2095  * Local variables:
2096  * mode: c++
2097  * indent-tabs-mode: t
2098  * c-basic-offset: 4
2099  * tab-width: 4
2100  * End:
2101  */