1 /* src/vmcore/javaobjects.hpp - functions to create and access Java objects
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
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.
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.
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
26 #ifndef _JAVAOBJECTS_HPP
27 #define _JAVAOBJECTS_HPP
33 #include "native/llni.h"
35 #include "vm/global.h"
37 #include "vmcore/field.h"
38 #include "vmcore/method.h"
44 * This class provides low-level functions to access Java object
47 * These functions do NOT take care about the GC critical section!
48 * Please use FieldAccess wherever possible.
50 class RawFieldAccess {
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);
57 template<class T> inline T RawFieldAccess::raw_get(void* address, const off_t offset)
59 T* p = (T*) (((uintptr_t) address) + offset);
64 template<class T> inline void RawFieldAccess::raw_set(void* address, const off_t offset, T value)
66 T* p = (T*) (((uintptr_t) address) + offset);
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
77 class FieldAccess : private RawFieldAccess {
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);
83 template<class T> inline T FieldAccess::get(java_handle_t* h, const off_t offset)
88 // XXX Move this to a GC inline function, e.g.
89 // gc->enter_critical();
92 // XXX This should be _handle->get_object();
95 result = raw_get<T>(o, offset);
97 // XXX Move this to a GC inline function.
98 // gc->leave_critical();
104 template<> inline java_handle_t* FieldAccess::get(java_handle_t* h, const off_t offset)
107 java_object_t* result;
108 java_handle_t* hresult;
110 // XXX Move this to a GC inline function, e.g.
111 // gc->enter_critical();
114 // XXX This should be _handle->get_object();
117 result = raw_get<java_object_t*>(o, offset);
119 hresult = LLNI_WRAP(result);
121 // XXX Move this to a GC inline function.
122 // gc->leave_critical();
129 template<class T> inline void FieldAccess::set(java_handle_t* h, const off_t offset, T value)
133 // XXX Move this to a GC inline function, e.g.
134 // gc->enter_critical();
137 // XXX This should be h->get_object();
140 raw_set(o, offset, value);
142 // XXX Move this to a GC inline function.
143 // gc->leave_critical();
147 template<> inline void FieldAccess::set<java_handle_t*>(java_handle_t* h, const off_t offset, java_handle_t* value)
150 java_object_t* ovalue;
152 // XXX Move this to a GC inline function, e.g.
153 // gc->enter_critical();
156 // XXX This should be h->get_object();
158 ovalue = LLNI_UNWRAP(value);
160 raw_set(o, offset, ovalue);
162 // XXX Move this to a GC inline function.
163 // gc->leave_critical();
175 class java_lang_Object {
177 // Handle of Java object.
178 java_handle_t* _handle;
181 java_lang_Object(java_handle_t* h) : _handle(h) {}
182 java_lang_Object(jobject h) : _handle((java_handle_t*) h) {}
186 virtual inline java_handle_t* get_handle() const { return _handle; }
187 inline vftbl_t* get_vftbl () const;
188 inline classinfo* get_Class () const;
190 inline bool is_null() const;
194 inline vftbl_t* java_lang_Object::get_vftbl() const
196 // XXX Move this to a GC inline function, e.g.
197 // gc->enter_critical();
200 // XXX This should be h->get_object();
201 java_object_t* o = LLNI_UNWRAP(_handle);
202 vftbl_t* vftbl = o->vftbl;
204 // XXX Move this to a GC inline function.
205 // gc->leave_critical();
211 inline classinfo* java_lang_Object::get_Class() const
213 return get_vftbl()->clazz;
217 inline bool java_lang_Object::is_null() const
219 return (_handle == NULL);
231 class java_lang_Boolean : public java_lang_Object, private FieldAccess {
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);
238 java_lang_Boolean(java_handle_t* h) : java_lang_Object(h) {}
240 inline uint8_t get_value();
241 inline void set_value(uint8_t value);
244 inline uint8_t java_lang_Boolean::get_value()
246 return get<int32_t>(_handle, offset_value);
249 inline void java_lang_Boolean::set_value(uint8_t value)
251 set(_handle, offset_value, (uint32_t) value);
263 class java_lang_Byte : public java_lang_Object, private FieldAccess {
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);
270 java_lang_Byte(java_handle_t* h) : java_lang_Object(h) {}
272 inline int8_t get_value();
273 inline void set_value(int8_t value);
276 inline int8_t java_lang_Byte::get_value()
278 return get<int32_t>(_handle, offset_value);
281 inline void java_lang_Byte::set_value(int8_t value)
283 set(_handle, offset_value, (int32_t) value);
288 * java/lang/Character
295 class java_lang_Character : public java_lang_Object, private FieldAccess {
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);
302 java_lang_Character(java_handle_t* h) : java_lang_Object(h) {}
304 inline uint16_t get_value();
305 inline void set_value(uint16_t value);
308 inline uint16_t java_lang_Character::get_value()
310 return get<int32_t>(_handle, offset_value);
313 inline void java_lang_Character::set_value(uint16_t value)
315 set(_handle, offset_value, (uint32_t) value);
327 class java_lang_Short : public java_lang_Object, private FieldAccess {
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);
334 java_lang_Short(java_handle_t* h) : java_lang_Object(h) {}
336 inline int16_t get_value();
337 inline void set_value(int16_t value);
340 inline int16_t java_lang_Short::get_value()
342 return get<int32_t>(_handle, offset_value);
345 inline void java_lang_Short::set_value(int16_t value)
347 set(_handle, offset_value, (int32_t) value);
359 class java_lang_Integer : public java_lang_Object, private FieldAccess {
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);
366 java_lang_Integer(java_handle_t* h) : java_lang_Object(h) {}
368 inline int32_t get_value();
369 inline void set_value(int32_t value);
372 inline int32_t java_lang_Integer::get_value()
374 return get<int32_t>(_handle, offset_value);
377 inline void java_lang_Integer::set_value(int32_t value)
379 set(_handle, offset_value, value);
391 class java_lang_Long : public java_lang_Object, private FieldAccess {
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);
398 java_lang_Long(java_handle_t* h) : java_lang_Object(h) {}
400 inline int64_t get_value();
401 inline void set_value(int64_t value);
404 inline int64_t java_lang_Long::get_value()
406 return get<int64_t>(_handle, offset_value);
409 inline void java_lang_Long::set_value(int64_t value)
411 set(_handle, offset_value, value);
423 class java_lang_Float : public java_lang_Object, private FieldAccess {
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);
430 java_lang_Float(java_handle_t* h) : java_lang_Object(h) {}
432 inline float get_value();
433 inline void set_value(float value);
436 inline float java_lang_Float::get_value()
438 return get<float>(_handle, offset_value);
441 inline void java_lang_Float::set_value(float value)
443 set(_handle, offset_value, value);
455 class java_lang_Double : public java_lang_Object, private FieldAccess {
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);
462 java_lang_Double(java_handle_t* h) : java_lang_Object(h) {}
464 inline double get_value();
465 inline void set_value(double value);
468 inline double java_lang_Double::get_value()
470 return get<double>(_handle, offset_value);
473 inline void java_lang_Double::set_value(double value)
475 set(_handle, offset_value, value);
479 #if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
482 * GNU Classpath java/lang/Class
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;
492 class java_lang_Class : public java_lang_Object, private FieldAccess {
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;
502 java_lang_Class(java_handle_t* h) : java_lang_Object(h) {}
505 inline void set_pd(java_handle_t* value);
506 inline void set_pd(jobject value);
509 inline void java_lang_Class::set_pd(java_handle_t* value)
511 set(_handle, offset_pd, value);
514 inline void java_lang_Class::set_pd(jobject value)
516 set_pd((java_handle_t*) value);
521 * GNU Classpath java/lang/StackTraceElement
526 * 1. java.lang.String fileName;
528 * 3. java.lang.String declaringClass;
529 * 4. java.lang.String methodName;
530 * 5. boolean isNative;
532 class java_lang_StackTraceElement : public java_lang_Object, private FieldAccess {
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;
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);
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)
549 java_lang_StackTraceElement((java_handle_t*) h);
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);
560 * GNU Classpath java/lang/String
567 * 3. int cachedHashCode;
570 class java_lang_String : public java_lang_Object, private FieldAccess {
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);
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);
585 inline java_handle_chararray_t* get_value () const;
586 inline int32_t get_count () const;
587 inline int32_t get_offset() const;
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);
595 inline java_lang_String::java_lang_String(jstring h) : java_lang_Object(h)
597 java_lang_String((java_handle_t*) h);
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)
607 inline java_handle_chararray_t* java_lang_String::get_value() const
609 return get<java_handle_chararray_t*>(_handle, offset_value);
612 inline int32_t java_lang_String::get_count() const
614 return get<int32_t>(_handle, offset_count);
617 inline int32_t java_lang_String::get_offset() const
619 return get<int32_t>(_handle, offset_offset);
622 inline void java_lang_String::set_value(java_handle_chararray_t* value)
624 set(_handle, offset_value, value);
627 inline void java_lang_String::set_count(int32_t value)
629 set(_handle, offset_count, value);
632 inline void java_lang_String::set_offset(int32_t value)
634 set(_handle, offset_offset, value);
639 * GNU Classpath java/lang/Thread
644 * 1. java.lang.VMThread vmThread;
645 * 2. java.lang.ThreadGroup group;
646 * 3. java.lang.Runnable runnable;
647 * 4. java.lang.String name;
651 * 8. java.lang.Throwable stillborn;
652 * 9. java.lang.ClassLoader contextClassLoader;
653 * 10. boolean contextClassLoaderIsSystemClassLoader;
655 * 12. java.lang.Object parkBlocker;
656 * 13. gnu.java.util.WeakIdentityHashMap locals;
657 * 14. java_lang_Thread_UncaughtExceptionHandler exceptionHandler;
659 class java_lang_Thread : public java_lang_Object, private FieldAccess {
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;
679 java_lang_Thread(java_handle_t* h) : java_lang_Object(h) {}
680 // java_lang_Thread(threadobject* t);
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;
691 inline void set_group(java_handle_t* value);
695 // inline java_lang_Thread::java_lang_Thread(threadobject* t) : java_lang_Object(h)
697 // java_lang_Thread(thread_get_object(t));
701 inline java_handle_t* java_lang_Thread::get_vmThread() const
703 return get<java_handle_t*>(_handle, offset_vmThread);
706 inline java_handle_t* java_lang_Thread::get_group() const
708 return get<java_handle_t*>(_handle, offset_group);
711 inline java_handle_t* java_lang_Thread::get_name() const
713 return get<java_handle_t*>(_handle, offset_name);
716 inline int32_t java_lang_Thread::get_daemon() const
718 return get<int32_t>(_handle, offset_daemon);
721 inline int32_t java_lang_Thread::get_priority() const
723 return get<int32_t>(_handle, offset_priority);
726 inline java_handle_t* java_lang_Thread::get_exceptionHandler() const
728 return get<java_handle_t*>(_handle, offset_exceptionHandler);
732 inline void java_lang_Thread::set_group(java_handle_t* value)
734 set(_handle, offset_group, value);
739 * GNU Classpath java/lang/VMThread
744 * 1. java.lang.Thread thread;
745 * 2. boolean running;
746 * 3. java.lang.VMThread vmdata;
748 class java_lang_VMThread : public java_lang_Object, private FieldAccess {
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
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);
762 inline java_handle_t* get_thread() const;
763 inline threadobject* get_vmdata() const;
766 inline void set_thread(java_handle_t* value);
767 inline void set_vmdata(threadobject* value);
771 inline java_lang_VMThread::java_lang_VMThread(jobject h) : java_lang_Object(h)
773 java_lang_VMThread((java_handle_t*) h);
776 inline java_lang_VMThread::java_lang_VMThread(java_handle_t* h, java_handle_t* thread, threadobject* vmdata) : java_lang_Object(h)
783 inline java_handle_t* java_lang_VMThread::get_thread() const
785 return get<java_handle_t*>(_handle, offset_thread);
788 inline threadobject* java_lang_VMThread::get_vmdata() const
790 return get<threadobject*>(_handle, offset_vmdata);
794 inline void java_lang_VMThread::set_thread(java_handle_t* value)
796 set(_handle, offset_thread, value);
799 inline void java_lang_VMThread::set_vmdata(threadobject* value)
801 set(_handle, offset_vmdata, value);
806 * GNU Classpath java/lang/Throwable
811 * 1. java.lang.String detailMessage;
812 * 2. java.lang.Throwable cause;
813 * 3. java.lang.StackTraceElement[] stackTrace;
814 * 4. java.lang.VMThrowable vmState;
816 class java_lang_Throwable : public java_lang_Object, private FieldAccess {
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;
826 java_lang_Throwable(java_handle_t* h) : java_lang_Object(h) {}
829 inline java_handle_t* get_detailMessage() const;
830 inline java_handle_t* get_cause () const;
831 inline java_handle_t* get_vmState () const;
835 inline java_handle_t* java_lang_Throwable::get_detailMessage() const
837 return get<java_handle_t*>(_handle, offset_detailMessage);
840 inline java_handle_t* java_lang_Throwable::get_cause() const
842 return get<java_handle_t*>(_handle, offset_cause);
845 inline java_handle_t* java_lang_Throwable::get_vmState() const
847 return get<java_handle_t*>(_handle, offset_vmState);
852 * GNU Classpath java/lang/VMThrowable
857 * 1. java.lang.Object vmdata;
859 class java_lang_VMThrowable : public java_lang_Object, private FieldAccess {
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);
866 java_lang_VMThrowable(java_handle_t* h) : java_lang_Object(h) {}
867 java_lang_VMThrowable(jobject h);
869 inline java_handle_bytearray_t* get_vmdata() const;
870 inline void set_vmdata(java_handle_bytearray_t* value);
873 inline java_lang_VMThrowable::java_lang_VMThrowable(jobject h) : java_lang_Object(h)
875 java_lang_VMThrowable((java_handle_t*) h);
878 inline java_handle_bytearray_t* java_lang_VMThrowable::get_vmdata() const
880 return get<java_handle_bytearray_t*>(_handle, offset_vmdata);
883 inline void java_lang_VMThrowable::set_vmdata(java_handle_bytearray_t* value)
885 set(_handle, offset_vmdata, value);
890 * GNU Classpath java/lang/reflect/Constructor
896 * 2. gnu.java.lang.reflect.MethodSignatureParser p;
897 * 3. java.lang.reflect.VMConstructor cons;
899 class java_lang_reflect_Constructor : public java_lang_Object, private FieldAccess {
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;
908 java_lang_reflect_Constructor(java_handle_t* h) : java_lang_Object(h) {}
909 java_lang_reflect_Constructor(jobject h);
911 static java_handle_t* create(methodinfo* m);
912 static java_handle_t* new_instance(methodinfo* m, java_handle_objectarray_t* args, bool override);
915 inline int32_t get_flag() const;
916 inline java_handle_t* get_cons() const;
919 inline void set_cons(java_handle_t* value);
922 inline java_lang_reflect_Constructor::java_lang_reflect_Constructor(jobject h) : java_lang_Object(h)
924 java_lang_reflect_Constructor((java_handle_t*) h);
927 inline int32_t java_lang_reflect_Constructor::get_flag() const
929 return get<int32_t>(_handle, offset_flag);
932 inline java_handle_t* java_lang_reflect_Constructor::get_cons() const
934 return get<java_handle_t*>(_handle, offset_cons);
937 inline void java_lang_reflect_Constructor::set_cons(java_handle_t* value)
939 set(_handle, offset_cons, value);
944 * GNU Classpath java/lang/reflect/VMConstructor
949 * 1. java.lang.Class clazz;
951 * 3. byte[] annotations;
952 * 4. byte[] parameterAnnotations;
953 * 5. java.util.Map declaredAnnotations;
954 * 6. java.lang.reflect.Constructor cons;
956 class java_lang_reflect_VMConstructor : public java_lang_Object, private FieldAccess {
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;
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);
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;
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);
988 // Convenience functions.
989 inline methodinfo* get_method();
992 inline java_lang_reflect_VMConstructor::java_lang_reflect_VMConstructor(jobject h) : java_lang_Object(h)
994 java_lang_reflect_VMConstructor((java_handle_t*) h);
997 inline java_lang_reflect_VMConstructor::java_lang_reflect_VMConstructor(java_handle_t* h, methodinfo* m) : java_lang_Object(h)
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);
1003 set_clazz(m->clazz);
1005 set_annotations(annotations);
1006 set_parameterAnnotations(parameterAnnotations);
1009 inline classinfo* java_lang_reflect_VMConstructor::get_clazz() const
1011 return get<classinfo*>(_handle, offset_clazz);
1014 inline int32_t java_lang_reflect_VMConstructor::get_slot() const
1016 return get<int32_t>(_handle, offset_slot);
1019 inline java_handle_bytearray_t* java_lang_reflect_VMConstructor::get_annotations() const
1021 return get<java_handle_bytearray_t*>(_handle, offset_annotations);
1024 inline java_handle_bytearray_t* java_lang_reflect_VMConstructor::get_parameterAnnotations() const
1026 return get<java_handle_bytearray_t*>(_handle, offset_parameterAnnotations);
1029 inline java_handle_t* java_lang_reflect_VMConstructor::get_declaredAnnotations() const
1031 return get<java_handle_t*>(_handle, offset_declaredAnnotations);
1034 inline java_handle_t* java_lang_reflect_VMConstructor::get_cons() const
1036 return get<java_handle_t*>(_handle, offset_cons);
1039 inline void java_lang_reflect_VMConstructor::set_clazz(classinfo* value)
1041 set(_handle, offset_clazz, value);
1044 inline void java_lang_reflect_VMConstructor::set_slot(int32_t value)
1046 set(_handle, offset_slot, value);
1049 inline void java_lang_reflect_VMConstructor::set_annotations(java_handle_bytearray_t* value)
1051 set(_handle, offset_annotations, value);
1054 inline void java_lang_reflect_VMConstructor::set_parameterAnnotations(java_handle_bytearray_t* value)
1056 set(_handle, offset_parameterAnnotations, value);
1059 inline void java_lang_reflect_VMConstructor::set_declaredAnnotations(java_handle_t* value)
1061 set(_handle, offset_declaredAnnotations, value);
1064 inline void java_lang_reflect_VMConstructor::set_cons(java_handle_t* value)
1066 set(_handle, offset_cons, value);
1069 inline methodinfo* java_lang_reflect_VMConstructor::get_method()
1071 classinfo* c = get_clazz();
1072 int32_t slot = get_slot();
1073 methodinfo* m = &(c->methods[slot]);
1079 * GNU Classpath java/lang/reflect/Field
1085 * 2. gnu.java.lang.reflect.FieldSignatureParser p;
1086 * 3. java.lang.reflect.VMField f;
1088 class java_lang_reflect_Field : public java_lang_Object, private FieldAccess {
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;
1098 java_lang_reflect_Field(java_handle_t* h) : java_lang_Object(h) {}
1099 java_lang_reflect_Field(jobject h);
1101 static java_handle_t* create(fieldinfo* f);
1104 inline int32_t get_flag() const;
1105 inline java_handle_t* get_f() const;
1108 inline void set_f(java_handle_t* value);
1111 inline java_lang_reflect_Field::java_lang_reflect_Field(jobject h) : java_lang_Object(h)
1113 java_lang_reflect_Field((java_handle_t*) h);
1116 inline int32_t java_lang_reflect_Field::get_flag() const
1118 return get<int32_t>(_handle, offset_flag);
1121 inline java_handle_t* java_lang_reflect_Field::get_f() const
1123 return get<java_handle_t*>(_handle, offset_f);
1126 inline void java_lang_reflect_Field::set_f(java_handle_t* value)
1128 set(_handle, offset_f, value);
1133 * GNU Classpath java/lang/reflect/VMField
1138 * 1. java.lang.Class clazz;
1139 * 2. java.lang.String name;
1141 * 4. byte[] annotations;
1142 * 5. java.lang.Map declaredAnnotations;
1143 * 6. java.lang.reflect.Field f;
1145 class java_lang_reflect_VMField : public java_lang_Object, private FieldAccess {
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;
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);
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;
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);
1176 // Convenience functions.
1177 inline fieldinfo* get_field() const;
1180 inline java_lang_reflect_VMField::java_lang_reflect_VMField(jobject h) : java_lang_Object(h)
1182 java_lang_reflect_VMField((java_handle_t*) h);
1185 inline java_lang_reflect_VMField::java_lang_reflect_VMField(java_handle_t* h, fieldinfo* f) : java_lang_Object(h)
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);
1191 set_clazz(f->clazz);
1194 set_annotations(annotations);
1197 inline classinfo* java_lang_reflect_VMField::get_clazz() const
1199 return get<classinfo*>(_handle, offset_clazz);
1202 inline int32_t java_lang_reflect_VMField::get_slot() const
1204 return get<int32_t>(_handle, offset_slot);
1207 inline java_handle_bytearray_t* java_lang_reflect_VMField::get_annotations() const
1209 return get<java_handle_bytearray_t*>(_handle, offset_annotations);
1212 inline java_handle_t* java_lang_reflect_VMField::get_declaredAnnotations() const
1214 return get<java_handle_t*>(_handle, offset_declaredAnnotations);
1217 inline java_handle_t* java_lang_reflect_VMField::get_f() const
1219 return get<java_handle_t*>(_handle, offset_f);
1222 inline void java_lang_reflect_VMField::set_clazz(classinfo* value)
1224 set(_handle, offset_clazz, value);
1227 inline void java_lang_reflect_VMField::set_name(java_handle_t* value)
1229 set(_handle, offset_name, value);
1232 inline void java_lang_reflect_VMField::set_slot(int32_t value)
1234 set(_handle, offset_slot, value);
1237 inline void java_lang_reflect_VMField::set_annotations(java_handle_bytearray_t* value)
1239 set(_handle, offset_annotations, value);
1242 inline void java_lang_reflect_VMField::set_declaredAnnotations(java_handle_t* value)
1244 set(_handle, offset_declaredAnnotations, value);
1247 inline void java_lang_reflect_VMField::set_f(java_handle_t* value)
1249 set(_handle, offset_f, value);
1252 inline fieldinfo* java_lang_reflect_VMField::get_field() const
1254 classinfo* c = get_clazz();
1255 int32_t slot = get_slot();
1256 fieldinfo* f = &(c->fields[slot]);
1262 * GNU Classpath java/lang/reflect/Method
1268 * 2. gnu.java.lang.reflect.MethodSignatureParser p;
1269 * 3. java.lang.reflect.VMMethod m;
1271 class java_lang_reflect_Method : public java_lang_Object, private FieldAccess {
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;
1281 java_lang_reflect_Method(java_handle_t* h) : java_lang_Object(h) {}
1282 java_lang_reflect_Method(jobject h);
1284 static java_handle_t* create(methodinfo* m);
1287 inline int32_t get_flag() const;
1288 inline java_handle_t* get_m() const;
1291 inline void set_m(java_handle_t* value);
1294 inline java_lang_reflect_Method::java_lang_reflect_Method(jobject h) : java_lang_Object(h)
1296 java_lang_reflect_Method((java_handle_t*) h);
1299 inline int32_t java_lang_reflect_Method::get_flag() const
1301 return get<int32_t>(_handle, offset_flag);
1304 inline java_handle_t* java_lang_reflect_Method::get_m() const
1306 return get<java_handle_t*>(_handle, offset_m);
1309 inline void java_lang_reflect_Method::set_m(java_handle_t* value)
1311 set(_handle, offset_m, value);
1316 * GNU Classpath java/lang/reflect/VMMethod
1321 * 1. java.lang.Class clazz;
1322 * 2. java.lang.String name;
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;
1330 class java_lang_reflect_VMMethod : public java_lang_Object, private FieldAccess {
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;
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);
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;
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);
1367 // Convenience functions.
1368 inline methodinfo* get_method() const;
1371 inline java_lang_reflect_VMMethod::java_lang_reflect_VMMethod(jobject h) : java_lang_Object(h)
1373 java_lang_reflect_VMMethod((java_handle_t*) h);
1376 inline java_lang_reflect_VMMethod::java_lang_reflect_VMMethod(java_handle_t* h, methodinfo* m) : java_lang_Object(h)
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);
1384 set_clazz(m->clazz);
1387 set_annotations(annotations);
1388 set_parameterAnnotations(parameterAnnotations);
1389 set_annotationDefault(annotationDefault);
1392 inline classinfo* java_lang_reflect_VMMethod::get_clazz() const
1394 return get<classinfo*>(_handle, offset_clazz);
1397 inline int32_t java_lang_reflect_VMMethod::get_slot() const
1399 return get<int32_t>(_handle, offset_slot);
1402 inline java_handle_bytearray_t* java_lang_reflect_VMMethod::get_annotations() const
1404 return get<java_handle_bytearray_t*>(_handle, offset_annotations);
1407 inline java_handle_bytearray_t* java_lang_reflect_VMMethod::get_parameterAnnotations() const
1409 return get<java_handle_bytearray_t*>(_handle, offset_parameterAnnotations);
1412 inline java_handle_bytearray_t* java_lang_reflect_VMMethod::get_annotationDefault() const
1414 return get<java_handle_bytearray_t*>(_handle, offset_annotationDefault);
1417 inline java_handle_t* java_lang_reflect_VMMethod::get_declaredAnnotations() const
1419 return get<java_handle_t*>(_handle, offset_declaredAnnotations);
1422 inline java_handle_t* java_lang_reflect_VMMethod::get_m() const
1424 return get<java_handle_t*>(_handle, offset_m);
1427 inline void java_lang_reflect_VMMethod::set_clazz(classinfo* value)
1429 set(_handle, offset_clazz, value);
1432 inline void java_lang_reflect_VMMethod::set_name(java_handle_t* value)
1434 set(_handle, offset_name, value);
1437 inline void java_lang_reflect_VMMethod::set_slot(int32_t value)
1439 set(_handle, offset_slot, value);
1442 inline void java_lang_reflect_VMMethod::set_annotations(java_handle_bytearray_t* value)
1444 set(_handle, offset_annotations, value);
1447 inline void java_lang_reflect_VMMethod::set_parameterAnnotations(java_handle_bytearray_t* value)
1449 set(_handle, offset_parameterAnnotations, value);
1452 inline void java_lang_reflect_VMMethod::set_annotationDefault(java_handle_bytearray_t* value)
1454 set(_handle, offset_annotationDefault, value);
1457 inline void java_lang_reflect_VMMethod::set_declaredAnnotations(java_handle_t* value)
1459 set(_handle, offset_declaredAnnotations, value);
1462 inline void java_lang_reflect_VMMethod::set_m(java_handle_t* value)
1464 set(_handle, offset_m, value);
1467 inline methodinfo* java_lang_reflect_VMMethod::get_method() const
1469 classinfo* c = get_clazz();
1470 int32_t slot = get_slot();
1471 methodinfo* m = &(c->methods[slot]);
1477 * GNU Classpath java/nio/Buffer
1486 * 5. gnu.classpath.Pointer address;
1488 class java_nio_Buffer : public java_lang_Object, private FieldAccess {
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);
1499 java_nio_Buffer(java_handle_t* h) : java_lang_Object(h) {}
1502 inline int32_t get_cap() const;
1505 inline int32_t java_nio_Buffer::get_cap() const
1507 return get<int32_t>(_handle, offset_cap);
1512 * GNU Classpath java/nio/DirectByteBufferImpl
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;
1527 class java_nio_DirectByteBufferImpl : public java_lang_Object, private FieldAccess {
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);
1542 java_nio_DirectByteBufferImpl(java_handle_t* h) : java_lang_Object(h) {}
1543 java_nio_DirectByteBufferImpl(jobject h);
1546 inline java_handle_t* get_address() const;
1549 inline java_nio_DirectByteBufferImpl::java_nio_DirectByteBufferImpl(jobject h) : java_lang_Object(h)
1551 java_nio_DirectByteBufferImpl((java_handle_t*) h);
1554 inline java_handle_t* java_nio_DirectByteBufferImpl::get_address() const
1556 return get<java_handle_t*>(_handle, offset_address);
1561 * GNU Classpath gnu/classpath/Pointer
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.
1572 class gnu_classpath_Pointer : public java_lang_Object, private FieldAccess {
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);
1579 gnu_classpath_Pointer(java_handle_t* h) : java_lang_Object(h) {}
1580 gnu_classpath_Pointer(java_handle_t* h, void* data);
1583 inline void* get_data() const;
1586 inline void set_data(void* value);
1589 inline gnu_classpath_Pointer::gnu_classpath_Pointer(java_handle_t* h, void* data) : java_lang_Object(h)
1594 inline void* gnu_classpath_Pointer::get_data() const
1596 return get<void*>(_handle, offset_data);
1599 inline void gnu_classpath_Pointer::set_data(void* value)
1601 set(_handle, offset_data, value);
1605 # if defined(ENABLE_ANNOTATIONS)
1607 * GNU Classpath sun/reflect/ConstantPool
1612 * 1. java.lang.Object constantPoolOop;
1614 class sun_reflect_ConstantPool : public java_lang_Object, private FieldAccess {
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);
1621 sun_reflect_ConstantPool(java_handle_t* h) : java_lang_Object(h) {}
1624 inline void set_constantPoolOop(classinfo* value);
1625 inline void set_constantPoolOop(jclass value);
1628 inline void sun_reflect_ConstantPool::set_constantPoolOop(classinfo* value)
1630 set(_handle, offset_constantPoolOop, value);
1633 inline void sun_reflect_ConstantPool::set_constantPoolOop(jclass value)
1635 // XXX jclass is a boxed object.
1636 set_constantPoolOop(LLNI_classinfo_unwrap(value));
1638 # endif // ENABLE_ANNOTATIONS
1640 #endif // WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH
1643 #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
1646 * OpenJDK java/lang/reflect/Constructor
1652 * 2. gnu.java.lang.reflect.MethodSignatureParser p;
1653 * 3. java.lang.reflect.VMConstructor cons;
1655 class java_lang_reflect_Constructor : public java_lang_Object, private FieldAccess {
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;
1664 java_lang_reflect_Constructor(java_handle_t* h) : java_lang_Object(h) {}
1665 java_lang_reflect_Constructor(jobject h);
1667 static java_handle_t* create(methodinfo* m);
1668 static java_handle_t* new_instance(methodinfo* m, java_handle_objectarray_t* args, bool override);
1671 inline int32_t get_flag() const;
1672 inline java_handle_t* get_cons() const;
1675 inline void set_cons(java_handle_t* value);
1678 inline java_lang_reflect_Constructor::java_lang_reflect_Constructor(jobject h) : java_lang_Object(h)
1680 java_lang_reflect_Constructor((java_handle_t*) h);
1683 inline int32_t java_lang_reflect_Constructor::get_flag() const
1685 return get<int32_t>(_handle, offset_flag);
1688 inline java_handle_t* java_lang_reflect_Constructor::get_cons() const
1690 return get<java_handle_t*>(_handle, offset_cons);
1693 inline void java_lang_reflect_Constructor::set_cons(java_handle_t* value)
1695 set(_handle, offset_cons, value);
1698 #endif // WITH_JAVA_RUNTIME_LIBRARY_OPENJDK
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);
1709 #endif // _JAVAOBJECTS_HPP
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 * ---------------------------------------------------------------------
1719 * indent-tabs-mode: t