This commit introduces C++ wrapper classes for Java heap objects.
[cacao.git] / src / vmcore / javaobjects.hpp
1 /* src/vmcore/javaobjects.hpp - functions to create and access Java objects
2
3    Copyright (C) 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _JAVAOBJECTS_HPP
27 #define _JAVAOBJECTS_HPP
28
29 #include "config.h"
30
31 #include <stdint.h>
32
33 #include "native/llni.h"
34
35 #include "vm/global.h"
36
37 #include "vmcore/field.h"
38 #include "vmcore/method.h"
39
40
41 #ifdef __cplusplus
42
43 /**
44  * This class provides low-level functions to access Java object
45  * instance fields.
46  *
47  * These functions do NOT take care about the GC critical section!
48  * Please use FieldAccess wherever possible.
49  */
50 class RawFieldAccess {
51 protected:
52         template<class T> static inline T    raw_get(void* address, const off_t offset);
53         template<class T> static inline void raw_set(void* address, const off_t offset, T value);
54 };
55
56
57 template<class T> inline T RawFieldAccess::raw_get(void* address, const off_t offset)
58 {
59         T* p = (T*) (((uintptr_t) address) + offset);
60         return *p;
61 }
62
63
64 template<class T> inline void RawFieldAccess::raw_set(void* address, const off_t offset, T value)
65 {
66         T* p = (T*) (((uintptr_t) address) + offset);
67         *p = value;
68 }
69
70
71 /**
72  * This classes provides functions to access Java object instance
73  * fields.  These functions enter a critical GC section before
74  * accessing the Java object throught the handle and leave it
75  * afterwards.
76  */
77 class FieldAccess : private RawFieldAccess {
78 protected:
79         template<class T> static inline T    get(java_handle_t* h, const off_t offset);
80         template<class T> static inline void set(java_handle_t* h, const off_t offset, T value);
81 };
82
83 template<class T> inline T FieldAccess::get(java_handle_t* h, const off_t offset)
84 {
85         java_object_t* o;
86         T result;
87                 
88         // XXX Move this to a GC inline function, e.g.
89         // gc->enter_critical();
90         LLNI_CRITICAL_START;
91
92         // XXX This should be _handle->get_object();
93         o = LLNI_UNWRAP(h);
94
95         result = raw_get<T>(o, offset);
96
97         // XXX Move this to a GC inline function.
98         // gc->leave_critical();
99         LLNI_CRITICAL_END;
100
101         return result;
102 }       
103
104 template<> inline java_handle_t* FieldAccess::get(java_handle_t* h, const off_t offset)
105 {
106         java_object_t* o;
107         java_object_t* result;
108         java_handle_t* hresult;
109                 
110         // XXX Move this to a GC inline function, e.g.
111         // gc->enter_critical();
112         LLNI_CRITICAL_START;
113
114         // XXX This should be _handle->get_object();
115         o = LLNI_UNWRAP(h);
116
117         result = raw_get<java_object_t*>(o, offset);
118
119         hresult = LLNI_WRAP(result);
120
121         // XXX Move this to a GC inline function.
122         // gc->leave_critical();
123         LLNI_CRITICAL_END;
124
125         return result;
126 }       
127
128
129 template<class T> inline void FieldAccess::set(java_handle_t* h, const off_t offset, T value)
130 {
131         java_object_t* o;
132
133         // XXX Move this to a GC inline function, e.g.
134         // gc->enter_critical();
135         LLNI_CRITICAL_START;
136
137         // XXX This should be h->get_object();
138         o = LLNI_UNWRAP(h);
139
140         raw_set(o, offset, value);
141
142         // XXX Move this to a GC inline function.
143         // gc->leave_critical();
144         LLNI_CRITICAL_END;
145 }
146
147 template<> inline void FieldAccess::set<java_handle_t*>(java_handle_t* h, const off_t offset, java_handle_t* value)
148 {
149         java_object_t* o;
150         java_object_t* ovalue;
151
152         // XXX Move this to a GC inline function, e.g.
153         // gc->enter_critical();
154         LLNI_CRITICAL_START;
155
156         // XXX This should be h->get_object();
157         o      = LLNI_UNWRAP(h);
158         ovalue = LLNI_UNWRAP(value);
159
160         raw_set(o, offset, ovalue);
161
162         // XXX Move this to a GC inline function.
163         // gc->leave_critical();
164         LLNI_CRITICAL_END;
165 }
166
167
168 /**
169  * java/lang/Object
170  *
171  * Object layout:
172  *
173  * 0. object header
174  */
175 class java_lang_Object {
176 protected:
177         // Handle of Java object.
178         java_handle_t* _handle;
179
180 protected:
181         java_lang_Object(java_handle_t* h) : _handle(h) {}
182         java_lang_Object(jobject h) : _handle((java_handle_t*) h) {}
183
184 public:
185         // Getters.
186         virtual inline java_handle_t* get_handle() const { return _handle; }
187         inline vftbl_t*               get_vftbl () const;
188         inline classinfo*             get_Class () const;
189
190         inline bool is_null() const;
191 };
192
193
194 inline vftbl_t* java_lang_Object::get_vftbl() const
195 {
196         // XXX Move this to a GC inline function, e.g.
197         // gc->enter_critical();
198         LLNI_CRITICAL_START;
199
200         // XXX This should be h->get_object();
201         java_object_t* o = LLNI_UNWRAP(_handle);
202         vftbl_t* vftbl = o->vftbl;
203
204         // XXX Move this to a GC inline function.
205         // gc->leave_critical();
206         LLNI_CRITICAL_END;
207
208         return vftbl;
209 }
210
211 inline classinfo* java_lang_Object::get_Class() const
212 {
213         return get_vftbl()->clazz;
214 }
215
216
217 inline bool java_lang_Object::is_null() const
218 {
219         return (_handle == NULL);
220 }
221
222
223 /**
224  * java/lang/Boolean
225  *
226  * Object layout:
227  *
228  * 0. object header
229  * 1. boolean value;
230  */
231 class java_lang_Boolean : public java_lang_Object, private FieldAccess {
232 private:
233         // Static offsets of the object's instance fields.
234         // TODO These offsets need to be checked on VM startup.
235         static const off_t offset_value = sizeof(java_object_t);
236
237 public:
238         java_lang_Boolean(java_handle_t* h) : java_lang_Object(h) {}
239
240         inline uint8_t get_value();
241         inline void    set_value(uint8_t value);
242 };
243
244 inline uint8_t java_lang_Boolean::get_value()
245 {
246         return get<int32_t>(_handle, offset_value);
247 }
248
249 inline void java_lang_Boolean::set_value(uint8_t value)
250 {
251         set(_handle, offset_value, (uint32_t) value);
252 }
253
254
255 /**
256  * java/lang/Byte
257  *
258  * Object layout:
259  *
260  * 0. object header
261  * 1. byte value;
262  */
263 class java_lang_Byte : public java_lang_Object, private FieldAccess {
264 private:
265         // Static offsets of the object's instance fields.
266         // TODO These offsets need to be checked on VM startup.
267         static const off_t offset_value = sizeof(java_object_t);
268
269 public:
270         java_lang_Byte(java_handle_t* h) : java_lang_Object(h) {}
271
272         inline int8_t get_value();
273         inline void   set_value(int8_t value);
274 };
275
276 inline int8_t java_lang_Byte::get_value()
277 {
278         return get<int32_t>(_handle, offset_value);
279 }
280
281 inline void java_lang_Byte::set_value(int8_t value)
282 {
283         set(_handle, offset_value, (int32_t) value);
284 }
285
286
287 /**
288  * java/lang/Character
289  *
290  * Object layout:
291  *
292  * 0. object header
293  * 1. char value;
294  */
295 class java_lang_Character : public java_lang_Object, private FieldAccess {
296 private:
297         // Static offsets of the object's instance fields.
298         // TODO These offsets need to be checked on VM startup.
299         static const off_t offset_value = sizeof(java_object_t);
300
301 public:
302         java_lang_Character(java_handle_t* h) : java_lang_Object(h) {}
303
304         inline uint16_t get_value();
305         inline void     set_value(uint16_t value);
306 };
307
308 inline uint16_t java_lang_Character::get_value()
309 {
310         return get<int32_t>(_handle, offset_value);
311 }
312
313 inline void java_lang_Character::set_value(uint16_t value)
314 {
315         set(_handle, offset_value, (uint32_t) value);
316 }
317
318
319 /**
320  * java/lang/Short
321  *
322  * Object layout:
323  *
324  * 0. object header
325  * 1. short value;
326  */
327 class java_lang_Short : public java_lang_Object, private FieldAccess {
328 private:
329         // Static offsets of the object's instance fields.
330         // TODO These offsets need to be checked on VM startup.
331         static const off_t offset_value = sizeof(java_object_t);
332
333 public:
334         java_lang_Short(java_handle_t* h) : java_lang_Object(h) {}
335
336         inline int16_t get_value();
337         inline void    set_value(int16_t value);
338 };
339
340 inline int16_t java_lang_Short::get_value()
341 {
342         return get<int32_t>(_handle, offset_value);
343 }
344
345 inline void java_lang_Short::set_value(int16_t value)
346 {
347         set(_handle, offset_value, (int32_t) value);
348 }
349
350
351 /**
352  * java/lang/Integer
353  *
354  * Object layout:
355  *
356  * 0. object header
357  * 1. int value;
358  */
359 class java_lang_Integer : public java_lang_Object, private FieldAccess {
360 private:
361         // Static offsets of the object's instance fields.
362         // TODO These offsets need to be checked on VM startup.
363         static const off_t offset_value = sizeof(java_object_t);
364
365 public:
366         java_lang_Integer(java_handle_t* h) : java_lang_Object(h) {}
367
368         inline int32_t get_value();
369         inline void    set_value(int32_t value);
370 };
371
372 inline int32_t java_lang_Integer::get_value()
373 {
374         return get<int32_t>(_handle, offset_value);
375 }
376
377 inline void java_lang_Integer::set_value(int32_t value)
378 {
379         set(_handle, offset_value, value);
380 }
381
382
383 /**
384  * java/lang/Long
385  *
386  * Object layout:
387  *
388  * 0. object header
389  * 1. long value;
390  */
391 class java_lang_Long : public java_lang_Object, private FieldAccess {
392 private:
393         // Static offsets of the object's instance fields.
394         // TODO These offsets need to be checked on VM startup.
395         static const off_t offset_value = sizeof(java_object_t);
396
397 public:
398         java_lang_Long(java_handle_t* h) : java_lang_Object(h) {}
399
400         inline int64_t get_value();
401         inline void    set_value(int64_t value);
402 };
403
404 inline int64_t java_lang_Long::get_value()
405 {
406         return get<int64_t>(_handle, offset_value);
407 }
408
409 inline void java_lang_Long::set_value(int64_t value)
410 {
411         set(_handle, offset_value, value);
412 }
413
414
415 /**
416  * java/lang/Float
417  *
418  * Object layout:
419  *
420  * 0. object header
421  * 1. float value;
422  */
423 class java_lang_Float : public java_lang_Object, private FieldAccess {
424 private:
425         // Static offsets of the object's instance fields.
426         // TODO These offsets need to be checked on VM startup.
427         static const off_t offset_value = sizeof(java_object_t);
428
429 public:
430         java_lang_Float(java_handle_t* h) : java_lang_Object(h) {}
431
432         inline float get_value();
433         inline void  set_value(float value);
434 };
435
436 inline float java_lang_Float::get_value()
437 {
438         return get<float>(_handle, offset_value);
439 }
440
441 inline void java_lang_Float::set_value(float value)
442 {
443         set(_handle, offset_value, value);
444 }
445
446
447 /**
448  * java/lang/Double
449  *
450  * Object layout:
451  *
452  * 0. object header
453  * 1. double value;
454  */
455 class java_lang_Double : public java_lang_Object, private FieldAccess {
456 private:
457         // Static offsets of the object's instance fields.
458         // TODO These offsets need to be checked on VM startup.
459         static const off_t offset_value = sizeof(java_object_t);
460
461 public:
462         java_lang_Double(java_handle_t* h) : java_lang_Object(h) {}
463
464         inline double get_value();
465         inline void   set_value(double value);
466 };
467
468 inline double java_lang_Double::get_value()
469 {
470         return get<double>(_handle, offset_value);
471 }
472
473 inline void java_lang_Double::set_value(double value)
474 {
475         set(_handle, offset_value, value);
476 }
477
478
479 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
480
481 /**
482  * GNU Classpath java/lang/Class
483  *
484  * Object layout:
485  *
486  * 0. object header
487  * 1. java.lang.Object[]             signers;
488  * 2. java.security.ProtectionDomain pd;
489  * 3. java.lang.Object               vmdata;
490  * 4. java.lang.reflect.Constructor  constructor;
491  */
492 class java_lang_Class : public java_lang_Object, private FieldAccess {
493 private:
494         // Static offsets of the object's instance fields.
495         // TODO These offsets need to be checked on VM startup.
496         static const off_t offset_signers     = sizeof(java_object_t);
497         static const off_t offset_pd          = offset_signers + SIZEOF_VOID_P;
498         static const off_t offset_vmdata      = offset_pd      + SIZEOF_VOID_P;
499         static const off_t offset_constructor = offset_vmdata  + SIZEOF_VOID_P;
500
501 public:
502         java_lang_Class(java_handle_t* h) : java_lang_Object(h) {}
503
504         // Setters.
505         inline void set_pd(java_handle_t* value);
506         inline void set_pd(jobject value);
507 };
508
509 inline void java_lang_Class::set_pd(java_handle_t* value)
510 {
511         set(_handle, offset_pd, value);
512 }
513
514 inline void java_lang_Class::set_pd(jobject value)
515 {
516         set_pd((java_handle_t*) value);
517 }
518
519
520 /**
521  * GNU Classpath java/lang/StackTraceElement
522  *
523  * Object layout:
524  *
525  * 0. object header
526  * 1. java.lang.String fileName;
527  * 2. int              lineNumber;
528  * 3. java.lang.String declaringClass;
529  * 4. java.lang.String methodName;
530  * 5. boolean          isNative;
531  */
532 class java_lang_StackTraceElement : public java_lang_Object, private FieldAccess {
533 private:
534         // Static offsets of the object's instance fields.
535         // TODO These offsets need to be checked on VM startup.
536         static const off_t offset_fileName       = sizeof(java_object_t);
537         static const off_t offset_lineNumber     = offset_fileName       + SIZEOF_VOID_P;
538         static const off_t offset_declaringClass = offset_lineNumber     + sizeof(int32_t) + 4;
539         static const off_t offset_methodName     = offset_declaringClass + SIZEOF_VOID_P;
540         static const off_t offset_isNative       = offset_methodName     + SIZEOF_VOID_P;
541
542 public:
543         java_lang_StackTraceElement(java_handle_t* h) : java_lang_Object(h) {}
544         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);
545 };
546
547 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)
548 {
549         java_lang_StackTraceElement((java_handle_t*) h);
550
551         set(_handle, offset_fileName,       fileName);
552         set(_handle, offset_lineNumber,     lineNumber);
553         set(_handle, offset_declaringClass, declaringClass);
554         set(_handle, offset_methodName,     methodName);
555         set(_handle, offset_isNative,       isNative);
556 }
557
558
559 /**
560  * GNU Classpath java/lang/String
561  *
562  * Object layout:
563  *
564  * 0. object header
565  * 1. char[] value;
566  * 2. int    count;
567  * 3. int    cachedHashCode;
568  * 4. int    offset;
569  */
570 class java_lang_String : public java_lang_Object, private FieldAccess {
571 private:
572         // Static offsets of the object's instance fields.
573         // TODO These offsets need to be checked on VM startup.
574         static const off_t offset_value          = sizeof(java_object_t);
575         static const off_t offset_count          = offset_value          + SIZEOF_VOID_P;
576         static const off_t offset_cachedHashCode = offset_count          + sizeof(int32_t);
577         static const off_t offset_offset         = offset_cachedHashCode + sizeof(int32_t);
578
579 public:
580         java_lang_String(java_handle_t* h) : java_lang_Object(h) {}
581         java_lang_String(jstring h);
582         java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset = 0);
583
584         // Getters.
585         inline java_handle_chararray_t* get_value () const;
586         inline int32_t                  get_count () const;
587         inline int32_t                  get_offset() const;
588
589         // Setters.
590         inline void set_value (java_handle_chararray_t* value);
591         inline void set_count (int32_t value);
592         inline void set_offset(int32_t value);
593 };
594
595 inline java_lang_String::java_lang_String(jstring h) : java_lang_Object(h)
596 {
597         java_lang_String((java_handle_t*) h);
598 }
599
600 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)
601 {
602         set_value(value);
603         set_count(count);
604         set_offset(offset);
605 }
606
607 inline java_handle_chararray_t* java_lang_String::get_value() const
608 {
609         return get<java_handle_chararray_t*>(_handle, offset_value);
610 }
611
612 inline int32_t java_lang_String::get_count() const
613 {
614         return get<int32_t>(_handle, offset_count);
615 }
616
617 inline int32_t java_lang_String::get_offset() const
618 {
619         return get<int32_t>(_handle, offset_offset);
620 }
621
622 inline void java_lang_String::set_value(java_handle_chararray_t* value)
623 {
624         set(_handle, offset_value, value);
625 }
626
627 inline void java_lang_String::set_count(int32_t value)
628 {
629         set(_handle, offset_count, value);
630 }
631
632 inline void java_lang_String::set_offset(int32_t value)
633 {
634         set(_handle, offset_offset, value);
635 }
636
637
638 /**
639  * GNU Classpath java/lang/Thread
640  *
641  * Object layout:
642  *
643  *  0. object header
644  *  1. java.lang.VMThread                        vmThread;
645  *  2. java.lang.ThreadGroup                     group;
646  *  3. java.lang.Runnable                        runnable;
647  *  4. java.lang.String                          name;
648  *  5. boolean                                   daemon;
649  *  6. int                                       priority;
650  *  7. long                                      stacksize;
651  *  8. java.lang.Throwable                       stillborn;
652  *  9. java.lang.ClassLoader                     contextClassLoader;
653  * 10. boolean                                   contextClassLoaderIsSystemClassLoader;
654  * 11. long                                      threadId;
655  * 12. java.lang.Object                          parkBlocker;
656  * 13. gnu.java.util.WeakIdentityHashMap         locals;
657  * 14. java_lang_Thread_UncaughtExceptionHandler exceptionHandler;
658  */
659 class java_lang_Thread : public java_lang_Object, private FieldAccess {
660 private:
661         // Static offsets of the object's instance fields.
662         // TODO These offsets need to be checked on VM startup.
663         static const off_t offset_vmThread                              = sizeof(java_object_t);
664         static const off_t offset_group                                 = offset_vmThread                              + SIZEOF_VOID_P;
665         static const off_t offset_runnable                              = offset_group                                 + SIZEOF_VOID_P;
666         static const off_t offset_name                                  = offset_runnable                              + SIZEOF_VOID_P;
667         static const off_t offset_daemon                                = offset_name                                  + SIZEOF_VOID_P;
668         static const off_t offset_priority                              = offset_daemon                                + sizeof(int32_t); // FIXME
669         static const off_t offset_stacksize                             = offset_priority                              + sizeof(int32_t); // FIXME
670         static const off_t offset_stillborn                             = offset_stacksize                             + sizeof(int64_t); // FIXME
671         static const off_t offset_contextClassLoader                    = offset_stillborn                             + SIZEOF_VOID_P;
672         static const off_t offset_contextClassLoaderIsSystemClassLoader = offset_contextClassLoader                    + SIZEOF_VOID_P;
673         static const off_t offset_threadId                              = offset_contextClassLoaderIsSystemClassLoader + sizeof(int32_t); // FIXME
674         static const off_t offset_parkBlocker                           = offset_threadId                              + sizeof(int64_t); // FIXME
675         static const off_t offset_locals                                = offset_parkBlocker                           + SIZEOF_VOID_P;
676         static const off_t offset_exceptionHandler                      = offset_locals                                + SIZEOF_VOID_P;
677
678 public:
679         java_lang_Thread(java_handle_t* h) : java_lang_Object(h) {}
680 //      java_lang_Thread(threadobject* t);
681
682         // Getters.
683         inline java_handle_t* get_vmThread        () const;
684         inline java_handle_t* get_group           () const;
685         inline java_handle_t* get_name            () const;
686         inline int32_t        get_daemon          () const;
687         inline int32_t        get_priority        () const;
688         inline java_handle_t* get_exceptionHandler() const;
689
690         // Setters.
691         inline void set_group(java_handle_t* value);
692 };
693
694
695 // inline java_lang_Thread::java_lang_Thread(threadobject* t) : java_lang_Object(h)
696 // {
697 //      java_lang_Thread(thread_get_object(t));
698 // }
699
700
701 inline java_handle_t* java_lang_Thread::get_vmThread() const
702 {
703         return get<java_handle_t*>(_handle, offset_vmThread);
704 }
705
706 inline java_handle_t* java_lang_Thread::get_group() const
707 {
708         return get<java_handle_t*>(_handle, offset_group);
709 }
710
711 inline java_handle_t* java_lang_Thread::get_name() const
712 {
713         return get<java_handle_t*>(_handle, offset_name);
714 }
715
716 inline int32_t java_lang_Thread::get_daemon() const
717 {
718         return get<int32_t>(_handle, offset_daemon);
719 }
720
721 inline int32_t java_lang_Thread::get_priority() const
722 {
723         return get<int32_t>(_handle, offset_priority);
724 }
725
726 inline java_handle_t* java_lang_Thread::get_exceptionHandler() const
727 {
728         return get<java_handle_t*>(_handle, offset_exceptionHandler);
729 }
730
731
732 inline void java_lang_Thread::set_group(java_handle_t* value)
733 {
734         set(_handle, offset_group, value);
735 }
736
737
738 /**
739  * GNU Classpath java/lang/VMThread
740  *
741  * Object layout:
742  *
743  * 0. object header
744  * 1. java.lang.Thread   thread;
745  * 2. boolean            running;
746  * 3. java.lang.VMThread vmdata;
747  */
748 class java_lang_VMThread : public java_lang_Object, private FieldAccess {
749 private:
750         // Static offsets of the object's instance fields.
751         // TODO These offsets need to be checked on VM startup.
752         static const off_t offset_thread  = sizeof(java_object_t);
753         static const off_t offset_running = offset_thread  + SIZEOF_VOID_P;
754         static const off_t offset_vmdata  = offset_running + sizeof(int32_t); // FIXME
755
756 public:
757         java_lang_VMThread(java_handle_t* h) : java_lang_Object(h) {}
758         java_lang_VMThread(jobject h);
759         java_lang_VMThread(java_handle_t* h, java_handle_t* thread, threadobject* vmdata);
760
761         // Getters.
762         inline java_handle_t* get_thread() const;
763         inline threadobject*  get_vmdata() const;
764
765         // Setters.
766         inline void set_thread(java_handle_t* value);
767         inline void set_vmdata(threadobject* value);
768 };
769
770
771 inline java_lang_VMThread::java_lang_VMThread(jobject h) : java_lang_Object(h)
772 {
773         java_lang_VMThread((java_handle_t*) h);
774 }
775
776 inline java_lang_VMThread::java_lang_VMThread(java_handle_t* h, java_handle_t* thread, threadobject* vmdata) : java_lang_Object(h)
777 {
778         set_thread(thread);
779         set_vmdata(vmdata);
780 }
781
782
783 inline java_handle_t* java_lang_VMThread::get_thread() const
784 {
785         return get<java_handle_t*>(_handle, offset_thread);
786 }
787
788 inline threadobject* java_lang_VMThread::get_vmdata() const
789 {
790         return get<threadobject*>(_handle, offset_vmdata);
791 }
792
793
794 inline void java_lang_VMThread::set_thread(java_handle_t* value)
795 {
796         set(_handle, offset_thread, value);
797 }
798
799 inline void java_lang_VMThread::set_vmdata(threadobject* value)
800 {
801         set(_handle, offset_vmdata, value);
802 }
803
804
805 /**
806  * GNU Classpath java/lang/Throwable
807  *
808  * Object layout:
809  *
810  * 0. object header
811  * 1. java.lang.String              detailMessage;
812  * 2. java.lang.Throwable           cause;
813  * 3. java.lang.StackTraceElement[] stackTrace;
814  * 4. java.lang.VMThrowable         vmState;
815  */
816 class java_lang_Throwable : public java_lang_Object, private FieldAccess {
817 private:
818         // Static offsets of the object's instance fields.
819         // TODO These offsets need to be checked on VM startup.
820         static const off_t offset_detailMessage = sizeof(java_object_t);
821         static const off_t offset_cause         = offset_detailMessage + SIZEOF_VOID_P;
822         static const off_t offset_stackTrace    = offset_cause         + SIZEOF_VOID_P;
823         static const off_t offset_vmState       = offset_stackTrace    + SIZEOF_VOID_P;
824
825 public:
826         java_lang_Throwable(java_handle_t* h) : java_lang_Object(h) {}
827
828         // Getters.
829         inline java_handle_t* get_detailMessage() const;
830         inline java_handle_t* get_cause        () const;
831         inline java_handle_t* get_vmState      () const;
832 };
833
834
835 inline java_handle_t* java_lang_Throwable::get_detailMessage() const
836 {
837         return get<java_handle_t*>(_handle, offset_detailMessage);
838 }
839
840 inline java_handle_t* java_lang_Throwable::get_cause() const
841 {
842         return get<java_handle_t*>(_handle, offset_cause);
843 }
844
845 inline java_handle_t* java_lang_Throwable::get_vmState() const
846 {
847         return get<java_handle_t*>(_handle, offset_vmState);
848 }
849
850
851 /**
852  * GNU Classpath java/lang/VMThrowable
853  *
854  * Object layout:
855  *
856  * 0. object header
857  * 1. java.lang.Object vmdata;
858  */
859 class java_lang_VMThrowable : public java_lang_Object, private FieldAccess {
860 private:
861         // Static offsets of the object's instance fields.
862         // TODO These offsets need to be checked on VM startup.
863         static const off_t offset_vmdata = sizeof(java_object_t);
864
865 public:
866         java_lang_VMThrowable(java_handle_t* h) : java_lang_Object(h) {}
867         java_lang_VMThrowable(jobject h);
868
869         inline java_handle_bytearray_t* get_vmdata() const;
870         inline void                     set_vmdata(java_handle_bytearray_t* value);
871 };
872
873 inline java_lang_VMThrowable::java_lang_VMThrowable(jobject h) : java_lang_Object(h)
874 {
875         java_lang_VMThrowable((java_handle_t*) h);
876 }
877
878 inline java_handle_bytearray_t* java_lang_VMThrowable::get_vmdata() const
879 {
880         return get<java_handle_bytearray_t*>(_handle, offset_vmdata);
881 }
882
883 inline void java_lang_VMThrowable::set_vmdata(java_handle_bytearray_t* value)
884 {
885         set(_handle, offset_vmdata, value);
886 }
887
888
889 /**
890  * GNU Classpath java/lang/reflect/Constructor
891  *
892  * Object layout:
893  *
894  * 0. object header
895  * 1. boolean                                     flag;
896  * 2. gnu.java.lang.reflect.MethodSignatureParser p;
897  * 3. java.lang.reflect.VMConstructor             cons;
898  */
899 class java_lang_reflect_Constructor : public java_lang_Object, private FieldAccess {
900 private:
901         // Static offsets of the object's instance fields.
902         // TODO These offsets need to be checked on VM startup.
903         static const off_t offset_flag = sizeof(java_object_t);
904         static const off_t offset_p    = offset_flag + sizeof(int32_t) + 4;
905         static const off_t offset_cons = offset_p    + SIZEOF_VOID_P;
906
907 public:
908         java_lang_reflect_Constructor(java_handle_t* h) : java_lang_Object(h) {}
909         java_lang_reflect_Constructor(jobject h);
910
911         static java_handle_t* create(methodinfo* m);
912         static java_handle_t* new_instance(methodinfo* m, java_handle_objectarray_t* args, bool override);
913
914         // Getters.
915         inline int32_t        get_flag() const;
916         inline java_handle_t* get_cons() const;
917
918         // Setters.
919         inline void set_cons(java_handle_t* value);
920 };
921
922 inline java_lang_reflect_Constructor::java_lang_reflect_Constructor(jobject h) : java_lang_Object(h)
923 {
924         java_lang_reflect_Constructor((java_handle_t*) h);
925 }
926
927 inline int32_t java_lang_reflect_Constructor::get_flag() const
928 {
929         return get<int32_t>(_handle, offset_flag);
930 }
931
932 inline java_handle_t* java_lang_reflect_Constructor::get_cons() const
933 {
934         return get<java_handle_t*>(_handle, offset_cons);
935 }
936
937 inline void java_lang_reflect_Constructor::set_cons(java_handle_t* value)
938 {
939         set(_handle, offset_cons, value);
940 }
941
942
943 /**
944  * GNU Classpath java/lang/reflect/VMConstructor
945  *
946  * Object layout:
947  *
948  * 0. object header
949  * 1. java.lang.Class               clazz;
950  * 2. int                           slot;
951  * 3. byte[]                        annotations;
952  * 4. byte[]                        parameterAnnotations;
953  * 5. java.util.Map                 declaredAnnotations;
954  * 6. java.lang.reflect.Constructor cons;
955  */
956 class java_lang_reflect_VMConstructor : public java_lang_Object, private FieldAccess {
957 private:
958         // Static offsets of the object's instance fields.
959         // TODO These offsets need to be checked on VM startup.
960         static const off_t offset_clazz                = sizeof(java_object_t);
961         static const off_t offset_slot                 = offset_clazz                + SIZEOF_VOID_P;
962         static const off_t offset_annotations          = offset_slot                 + sizeof(int32_t) + 4;
963         static const off_t offset_parameterAnnotations = offset_annotations          + SIZEOF_VOID_P;
964         static const off_t offset_declaredAnnotations  = offset_parameterAnnotations + SIZEOF_VOID_P;
965         static const off_t offset_cons                 = offset_declaredAnnotations  + SIZEOF_VOID_P;
966
967 public:
968         java_lang_reflect_VMConstructor(java_handle_t* h) : java_lang_Object(h) {}
969         java_lang_reflect_VMConstructor(jobject h);
970         java_lang_reflect_VMConstructor(java_handle_t* h, methodinfo* m);
971
972         // Getters.
973         inline classinfo*               get_clazz               () const;
974         inline int32_t                  get_slot                () const;
975         inline java_handle_bytearray_t* get_annotations         () const;
976         inline java_handle_bytearray_t* get_parameterAnnotations() const;
977         inline java_handle_t*           get_declaredAnnotations () const;
978         inline java_handle_t*           get_cons                () const;
979
980         // Setters.
981         inline void set_clazz               (classinfo* value);
982         inline void set_slot                (int32_t value);
983         inline void set_annotations         (java_handle_bytearray_t* value);
984         inline void set_parameterAnnotations(java_handle_bytearray_t* value);
985         inline void set_declaredAnnotations (java_handle_t* value);
986         inline void set_cons                (java_handle_t* value);
987
988         // Convenience functions.
989         inline methodinfo* get_method();
990 };
991
992 inline java_lang_reflect_VMConstructor::java_lang_reflect_VMConstructor(jobject h) : java_lang_Object(h)
993 {
994         java_lang_reflect_VMConstructor((java_handle_t*) h);
995 }
996
997 inline java_lang_reflect_VMConstructor::java_lang_reflect_VMConstructor(java_handle_t* h, methodinfo* m) : java_lang_Object(h)
998 {
999         int                      slot                 = m - m->clazz->methods;
1000         java_handle_bytearray_t* annotations          = method_get_annotations(m);
1001         java_handle_bytearray_t* parameterAnnotations = method_get_parameterannotations(m);
1002
1003         set_clazz(m->clazz);
1004         set_slot(slot);
1005         set_annotations(annotations);
1006         set_parameterAnnotations(parameterAnnotations);
1007 }
1008
1009 inline classinfo* java_lang_reflect_VMConstructor::get_clazz() const
1010 {
1011         return get<classinfo*>(_handle, offset_clazz);
1012 }
1013
1014 inline int32_t java_lang_reflect_VMConstructor::get_slot() const
1015 {
1016         return get<int32_t>(_handle, offset_slot);
1017 }
1018
1019 inline java_handle_bytearray_t* java_lang_reflect_VMConstructor::get_annotations() const
1020 {
1021         return get<java_handle_bytearray_t*>(_handle, offset_annotations);
1022 }
1023
1024 inline java_handle_bytearray_t* java_lang_reflect_VMConstructor::get_parameterAnnotations() const
1025 {
1026         return get<java_handle_bytearray_t*>(_handle, offset_parameterAnnotations);
1027 }
1028
1029 inline java_handle_t* java_lang_reflect_VMConstructor::get_declaredAnnotations() const
1030 {
1031         return get<java_handle_t*>(_handle, offset_declaredAnnotations);
1032 }
1033
1034 inline java_handle_t* java_lang_reflect_VMConstructor::get_cons() const
1035 {
1036         return get<java_handle_t*>(_handle, offset_cons);
1037 }
1038
1039 inline void java_lang_reflect_VMConstructor::set_clazz(classinfo* value)
1040 {
1041         set(_handle, offset_clazz, value);
1042 }
1043
1044 inline void java_lang_reflect_VMConstructor::set_slot(int32_t value)
1045 {
1046         set(_handle, offset_slot, value);
1047 }
1048
1049 inline void java_lang_reflect_VMConstructor::set_annotations(java_handle_bytearray_t* value)
1050 {
1051         set(_handle, offset_annotations, value);
1052 }
1053
1054 inline void java_lang_reflect_VMConstructor::set_parameterAnnotations(java_handle_bytearray_t* value)
1055 {
1056         set(_handle, offset_parameterAnnotations, value);
1057 }
1058
1059 inline void java_lang_reflect_VMConstructor::set_declaredAnnotations(java_handle_t* value)
1060 {
1061         set(_handle, offset_declaredAnnotations, value);
1062 }
1063
1064 inline void java_lang_reflect_VMConstructor::set_cons(java_handle_t* value)
1065 {
1066         set(_handle, offset_cons, value);
1067 }
1068
1069 inline methodinfo* java_lang_reflect_VMConstructor::get_method()
1070 {
1071         classinfo*  c    = get_clazz();
1072         int32_t     slot = get_slot();
1073         methodinfo* m    = &(c->methods[slot]);
1074         return m;
1075 }
1076
1077
1078 /**
1079  * GNU Classpath java/lang/reflect/Field
1080  *
1081  * Object layout:
1082  *
1083  * 0. object header
1084  * 1. boolean                                    flag;
1085  * 2. gnu.java.lang.reflect.FieldSignatureParser p;
1086  * 3. java.lang.reflect.VMField                  f;
1087  */
1088 class java_lang_reflect_Field : public java_lang_Object, private FieldAccess {
1089 private:
1090         // Static offsets of the object's instance fields.
1091         // TODO These offsets need to be checked on VM startup.
1092         static const off_t offset_flag = sizeof(java_object_t);
1093         // Currently we align 64-bit data types to 8-bytes.
1094         static const off_t offset_p    = offset_flag + sizeof(int32_t) + 4;
1095         static const off_t offset_f    = offset_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               = sizeof(java_object_t);
1150         static const off_t offset_name                = offset_clazz               + SIZEOF_VOID_P;
1151         static const off_t offset_slot                = offset_name                + SIZEOF_VOID_P;
1152         static const off_t offset_annotations         = offset_slot                + sizeof(int32_t) + 4;
1153         static const off_t offset_declaredAnnotations = offset_annotations         + SIZEOF_VOID_P;
1154         static const off_t offset_f                   = offset_declaredAnnotations + 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 = sizeof(java_object_t);
1276         // Currently we align 64-bit data types to 8-bytes.
1277         static const off_t offset_p    = offset_flag + sizeof(int32_t) + 4;
1278         static const off_t offset_m    = offset_p    + SIZEOF_VOID_P;
1279
1280 public:
1281         java_lang_reflect_Method(java_handle_t* h) : java_lang_Object(h) {}
1282         java_lang_reflect_Method(jobject h);
1283
1284         static java_handle_t* create(methodinfo* m);
1285
1286         // Getters.
1287         inline int32_t        get_flag() const;
1288         inline java_handle_t* get_m() const;
1289
1290         // Setters.
1291         inline void set_m(java_handle_t* value);
1292 };
1293
1294 inline java_lang_reflect_Method::java_lang_reflect_Method(jobject h) : java_lang_Object(h)
1295 {
1296         java_lang_reflect_Method((java_handle_t*) h);
1297 }
1298
1299 inline int32_t java_lang_reflect_Method::get_flag() const
1300 {
1301         return get<int32_t>(_handle, offset_flag);
1302 }
1303
1304 inline java_handle_t* java_lang_reflect_Method::get_m() const
1305 {
1306         return get<java_handle_t*>(_handle, offset_m);
1307 }
1308
1309 inline void java_lang_reflect_Method::set_m(java_handle_t* value)
1310 {
1311         set(_handle, offset_m, value);
1312 }
1313
1314
1315 /**
1316  * GNU Classpath java/lang/reflect/VMMethod
1317  *
1318  * Object layout:
1319  *
1320  * 0. object header
1321  * 1. java.lang.Class          clazz;
1322  * 2. java.lang.String         name;
1323  * 3. int                      slot;
1324  * 4. byte[]                   annotations;
1325  * 5. byte[]                   parameterAnnotations;
1326  * 6. byte[]                   annotationDefault;
1327  * 7. java.lang.Map            declaredAnnotations;
1328  * 8. java.lang.reflect.Method m;
1329  */
1330 class java_lang_reflect_VMMethod : public java_lang_Object, private FieldAccess {
1331 private:
1332         // Static offsets of the object's instance fields.
1333         // TODO These offsets need to be checked on VM startup.
1334         static const off_t offset_clazz                = sizeof(java_object_t);
1335         static const off_t offset_name                 = offset_clazz                + SIZEOF_VOID_P;
1336         static const off_t offset_slot                 = offset_name                 + SIZEOF_VOID_P;
1337         static const off_t offset_annotations          = offset_slot                 + sizeof(int32_t) + 4;
1338         static const off_t offset_parameterAnnotations = offset_annotations          + SIZEOF_VOID_P;
1339         static const off_t offset_annotationDefault    = offset_parameterAnnotations + SIZEOF_VOID_P;
1340         static const off_t offset_declaredAnnotations  = offset_annotationDefault    + SIZEOF_VOID_P;
1341         static const off_t offset_m                    = offset_declaredAnnotations  + SIZEOF_VOID_P;
1342
1343 public:
1344         java_lang_reflect_VMMethod(java_handle_t* h) : java_lang_Object(h) {}
1345         java_lang_reflect_VMMethod(jobject h);
1346         java_lang_reflect_VMMethod(java_handle_t* h, methodinfo* m);
1347
1348         // Getters.
1349         inline classinfo*               get_clazz               () const;
1350         inline int32_t                  get_slot                () const;
1351         inline java_handle_bytearray_t* get_annotations         () const;
1352         inline java_handle_bytearray_t* get_parameterAnnotations() const;
1353         inline java_handle_bytearray_t* get_annotationDefault   () const;
1354         inline java_handle_t*           get_declaredAnnotations () const;
1355         inline java_handle_t*           get_m                   () const;
1356
1357         // Setters.
1358         inline void set_clazz               (classinfo* value);
1359         inline void set_name                (java_handle_t* value);
1360         inline void set_slot                (int32_t value);
1361         inline void set_annotations         (java_handle_bytearray_t* value);
1362         inline void set_parameterAnnotations(java_handle_bytearray_t* value);
1363         inline void set_annotationDefault   (java_handle_bytearray_t* value);
1364         inline void set_declaredAnnotations (java_handle_t* value);
1365         inline void set_m                   (java_handle_t* value);
1366
1367         // Convenience functions.
1368         inline methodinfo* get_method() const;
1369 };
1370
1371 inline java_lang_reflect_VMMethod::java_lang_reflect_VMMethod(jobject h) : java_lang_Object(h)
1372 {
1373         java_lang_reflect_VMMethod((java_handle_t*) h);
1374 }
1375
1376 inline java_lang_reflect_VMMethod::java_lang_reflect_VMMethod(java_handle_t* h, methodinfo* m) : java_lang_Object(h)
1377 {
1378         java_handle_t*           name                 = javastring_intern(javastring_new(m->name));
1379         int                      slot                 = m - m->clazz->methods;
1380         java_handle_bytearray_t* annotations          = method_get_annotations(m);
1381         java_handle_bytearray_t* parameterAnnotations = method_get_parameterannotations(m);
1382         java_handle_bytearray_t* annotationDefault    = method_get_annotationdefault(m);
1383
1384         set_clazz(m->clazz);
1385         set_name(name);
1386         set_slot(slot);
1387         set_annotations(annotations);
1388         set_parameterAnnotations(parameterAnnotations);
1389         set_annotationDefault(annotationDefault);
1390 }
1391
1392 inline classinfo* java_lang_reflect_VMMethod::get_clazz() const
1393 {
1394         return get<classinfo*>(_handle, offset_clazz);
1395 }
1396
1397 inline int32_t java_lang_reflect_VMMethod::get_slot() const
1398 {
1399         return get<int32_t>(_handle, offset_slot);
1400 }
1401
1402 inline java_handle_bytearray_t* java_lang_reflect_VMMethod::get_annotations() const
1403 {
1404         return get<java_handle_bytearray_t*>(_handle, offset_annotations);
1405 }
1406
1407 inline java_handle_bytearray_t* java_lang_reflect_VMMethod::get_parameterAnnotations() const
1408 {
1409         return get<java_handle_bytearray_t*>(_handle, offset_parameterAnnotations);
1410 }
1411
1412 inline java_handle_bytearray_t* java_lang_reflect_VMMethod::get_annotationDefault() const
1413 {
1414         return get<java_handle_bytearray_t*>(_handle, offset_annotationDefault);
1415 }
1416
1417 inline java_handle_t* java_lang_reflect_VMMethod::get_declaredAnnotations() const
1418 {
1419         return get<java_handle_t*>(_handle, offset_declaredAnnotations);
1420 }
1421
1422 inline java_handle_t* java_lang_reflect_VMMethod::get_m() const
1423 {
1424         return get<java_handle_t*>(_handle, offset_m);
1425 }
1426
1427 inline void java_lang_reflect_VMMethod::set_clazz(classinfo* value)
1428 {
1429         set(_handle, offset_clazz, value);
1430 }
1431
1432 inline void java_lang_reflect_VMMethod::set_name(java_handle_t* value)
1433 {
1434         set(_handle, offset_name, value);
1435 }
1436
1437 inline void java_lang_reflect_VMMethod::set_slot(int32_t value)
1438 {
1439         set(_handle, offset_slot, value);
1440 }
1441
1442 inline void java_lang_reflect_VMMethod::set_annotations(java_handle_bytearray_t* value)
1443 {
1444         set(_handle, offset_annotations, value);
1445 }
1446
1447 inline void java_lang_reflect_VMMethod::set_parameterAnnotations(java_handle_bytearray_t* value)
1448 {
1449         set(_handle, offset_parameterAnnotations, value);
1450 }
1451
1452 inline void java_lang_reflect_VMMethod::set_annotationDefault(java_handle_bytearray_t* value)
1453 {
1454         set(_handle, offset_annotationDefault, value);
1455 }
1456
1457 inline void java_lang_reflect_VMMethod::set_declaredAnnotations(java_handle_t* value)
1458 {
1459         set(_handle, offset_declaredAnnotations, value);
1460 }
1461
1462 inline void java_lang_reflect_VMMethod::set_m(java_handle_t* value)
1463 {
1464         set(_handle, offset_m, value);
1465 }
1466
1467 inline methodinfo* java_lang_reflect_VMMethod::get_method() const
1468 {
1469         classinfo*  c    = get_clazz();
1470         int32_t     slot = get_slot();
1471         methodinfo* m    = &(c->methods[slot]);
1472         return m;
1473 }
1474
1475
1476 /**
1477  * GNU Classpath java/nio/Buffer
1478  *
1479  * Object layout:
1480  *
1481  * 0. object header
1482  * 1. int                   cap;
1483  * 2. int                   limit;
1484  * 3. int                   pos;
1485  * 4. int                   mark;
1486  * 5. gnu.classpath.Pointer address;
1487  */
1488 class java_nio_Buffer : public java_lang_Object, private FieldAccess {
1489 private:
1490         // Static offsets of the object's instance fields.
1491         // TODO These offsets need to be checked on VM startup.
1492         static const off_t offset_cap     = sizeof(java_object_t);
1493         static const off_t offset_limit   = offset_cap   + sizeof(int32_t);
1494         static const off_t offset_pos     = offset_limit + sizeof(int32_t);
1495         static const off_t offset_mark    = offset_pos   + sizeof(int32_t);
1496         static const off_t offset_address = offset_mark  + sizeof(int32_t);
1497
1498 public:
1499         java_nio_Buffer(java_handle_t* h) : java_lang_Object(h) {}
1500
1501         // Getters.
1502         inline int32_t get_cap() const;
1503 };
1504
1505 inline int32_t java_nio_Buffer::get_cap() const
1506 {
1507         return get<int32_t>(_handle, offset_cap);
1508 }
1509
1510
1511 /**
1512  * GNU Classpath java/nio/DirectByteBufferImpl
1513  *
1514  * Object layout:
1515  *
1516  * 0. object header
1517  * 1. int                   cap;
1518  * 2. int                   limit;
1519  * 3. int                   pos;
1520  * 4. int                   mark;
1521  * 5. gnu.classpath.Pointer address;
1522  * 6. java.nio.ByteOrder    endian;
1523  * 7. byte[]                backing_buffer;
1524  * 8. int                   array_offset;
1525  * 9. java.lang.Object      owner;
1526  */
1527 class java_nio_DirectByteBufferImpl : public java_lang_Object, private FieldAccess {
1528 private:
1529         // Static offsets of the object's instance fields.
1530         // TODO These offsets need to be checked on VM startup.
1531         static const off_t offset_cap            = sizeof(java_object_t);
1532         static const off_t offset_limit          = offset_cap            + sizeof(int32_t);
1533         static const off_t offset_pos            = offset_limit          + sizeof(int32_t);
1534         static const off_t offset_mark           = offset_pos            + sizeof(int32_t);
1535         static const off_t offset_address        = offset_mark           + sizeof(int32_t);
1536         static const off_t offset_endian         = offset_address        + SIZEOF_VOID_P;
1537         static const off_t offset_backing_buffer = offset_endian         + SIZEOF_VOID_P;
1538         static const off_t offset_array_offset   = offset_backing_buffer + SIZEOF_VOID_P;
1539         static const off_t offset_owner          = offset_array_offset   + sizeof(int32_t);
1540
1541 public:
1542         java_nio_DirectByteBufferImpl(java_handle_t* h) : java_lang_Object(h) {}
1543         java_nio_DirectByteBufferImpl(jobject h);
1544
1545         // Getters.
1546         inline java_handle_t* get_address() const;
1547 };
1548
1549 inline java_nio_DirectByteBufferImpl::java_nio_DirectByteBufferImpl(jobject h) : java_lang_Object(h)
1550 {
1551         java_nio_DirectByteBufferImpl((java_handle_t*) h);
1552 }
1553
1554 inline java_handle_t* java_nio_DirectByteBufferImpl::get_address() const
1555 {
1556         return get<java_handle_t*>(_handle, offset_address);
1557 }
1558
1559
1560 /**
1561  * GNU Classpath gnu/classpath/Pointer
1562  *
1563  * Actually there are two classes, gnu.classpath.Pointer32 and
1564  * gnu.classpath.Pointer64, but we only define the abstract super
1565  * class and use the int/long field as void* type.
1566  *
1567  * Object layout:
1568  *
1569  * 0. object header
1570  * 1. int/long data;
1571  */
1572 class gnu_classpath_Pointer : public java_lang_Object, private FieldAccess {
1573 private:
1574         // Static offsets of the object's instance fields.
1575         // TODO These offsets need to be checked on VM startup.
1576         static const off_t offset_data = sizeof(java_object_t);
1577
1578 public:
1579         gnu_classpath_Pointer(java_handle_t* h) : java_lang_Object(h) {}
1580         gnu_classpath_Pointer(java_handle_t* h, void* data);
1581
1582         // Setters.
1583         inline void* get_data() const;
1584
1585         // Setters.
1586         inline void set_data(void* value);
1587 };
1588
1589 inline gnu_classpath_Pointer::gnu_classpath_Pointer(java_handle_t* h, void* data) : java_lang_Object(h)
1590 {
1591         set_data(data);
1592 }
1593
1594 inline void* gnu_classpath_Pointer::get_data() const
1595 {
1596         return get<void*>(_handle, offset_data);
1597 }
1598
1599 inline void gnu_classpath_Pointer::set_data(void* value)
1600 {
1601         set(_handle, offset_data, value);
1602 }
1603
1604
1605 # if defined(ENABLE_ANNOTATIONS)
1606 /**
1607  * GNU Classpath sun/reflect/ConstantPool
1608  *
1609  * Object layout:
1610  *
1611  * 0. object header
1612  * 1. java.lang.Object constantPoolOop;
1613  */
1614 class sun_reflect_ConstantPool : public java_lang_Object, private FieldAccess {
1615 private:
1616         // Static offsets of the object's instance fields.
1617         // TODO These offsets need to be checked on VM startup.
1618         static const off_t offset_constantPoolOop = sizeof(java_object_t);
1619
1620 public:
1621         sun_reflect_ConstantPool(java_handle_t* h) : java_lang_Object(h) {}
1622
1623         // Setters.
1624         inline void set_constantPoolOop(classinfo* value);
1625         inline void set_constantPoolOop(jclass value);
1626 };
1627
1628 inline void sun_reflect_ConstantPool::set_constantPoolOop(classinfo* value)
1629 {
1630         set(_handle, offset_constantPoolOop, value);
1631 }
1632
1633 inline void sun_reflect_ConstantPool::set_constantPoolOop(jclass value)
1634 {
1635         // XXX jclass is a boxed object.
1636         set_constantPoolOop(LLNI_classinfo_unwrap(value));
1637 }
1638 # endif // ENABLE_ANNOTATIONS
1639
1640 #endif // WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH
1641
1642
1643 #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1644
1645 /**
1646  * OpenJDK java/lang/reflect/Constructor
1647  *
1648  * Object layout:
1649  *
1650  * 0. object header
1651  * 1. boolean                                     flag;
1652  * 2. gnu.java.lang.reflect.MethodSignatureParser p;
1653  * 3. java.lang.reflect.VMConstructor             cons;
1654  */
1655 class java_lang_reflect_Constructor : public java_lang_Object, private FieldAccess {
1656 private:
1657         // Static offsets of the object's instance fields.
1658         // TODO These offsets need to be checked on VM startup.
1659         static const off_t offset_flag = sizeof(java_object_t);
1660         static const off_t offset_p    = offset_flag + sizeof(int32_t) + 4;
1661         static const off_t offset_cons = offset_p    + SIZEOF_VOID_P;
1662
1663 public:
1664         java_lang_reflect_Constructor(java_handle_t* h) : java_lang_Object(h) {}
1665         java_lang_reflect_Constructor(jobject h);
1666
1667         static java_handle_t* create(methodinfo* m);
1668         static java_handle_t* new_instance(methodinfo* m, java_handle_objectarray_t* args, bool override);
1669
1670         // Getters.
1671         inline int32_t        get_flag() const;
1672         inline java_handle_t* get_cons() const;
1673
1674         // Setters.
1675         inline void set_cons(java_handle_t* value);
1676 };
1677
1678 inline java_lang_reflect_Constructor::java_lang_reflect_Constructor(jobject h) : java_lang_Object(h)
1679 {
1680         java_lang_reflect_Constructor((java_handle_t*) h);
1681 }
1682
1683 inline int32_t java_lang_reflect_Constructor::get_flag() const
1684 {
1685         return get<int32_t>(_handle, offset_flag);
1686 }
1687
1688 inline java_handle_t* java_lang_reflect_Constructor::get_cons() const
1689 {
1690         return get<java_handle_t*>(_handle, offset_cons);
1691 }
1692
1693 inline void java_lang_reflect_Constructor::set_cons(java_handle_t* value)
1694 {
1695         set(_handle, offset_cons, value);
1696 }
1697
1698 #endif // WITH_JAVA_RUNTIME_LIBRARY_OPENJDK
1699
1700 #else
1701
1702 // Legacy C interface.
1703 java_handle_t* java_lang_reflect_Constructor_create(methodinfo* m);
1704 java_handle_t* java_lang_reflect_Field_create(fieldinfo* f);
1705 java_handle_t* java_lang_reflect_Method_create(methodinfo* m);
1706
1707 #endif
1708
1709 #endif // _JAVAOBJECTS_HPP
1710
1711
1712 /*
1713  * These are local overrides for various environment variables in Emacs.
1714  * Please do not remove this and leave it at the end of the file, where
1715  * Emacs will automagically detect them.
1716  * ---------------------------------------------------------------------
1717  * Local variables:
1718  * mode: c++
1719  * indent-tabs-mode: t
1720  * c-basic-offset: 4
1721  * tab-width: 4
1722  * End:
1723  */