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