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 520942 : 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 691500 : template<class T> inline T RawFieldAccess::raw_get(void* address, const off_t offset)
65 : {
66 691500 : T* p = (T*) (((uintptr_t) address) + offset);
67 691500 : return *p;
68 : }
69 :
70 :
71 355816 : template<class T> inline void RawFieldAccess::raw_set(void* address, const off_t offset, T value)
72 : {
73 355816 : T* p = (T*) (((uintptr_t) address) + offset);
74 355816 : *p = value;
75 355816 : }
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 520942 : 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 383913 : 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 383913 : GCCriticalSection cs;
100 :
101 : // XXX This should be _handle->get_object();
102 383913 : java_object_t* ho = LLNI_UNWRAP(h);
103 383913 : return raw_get<T>(ho, offset);
104 : }
105 :
106 307587 : 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 307587 : GCCriticalSection cs;
110 :
111 : // XXX This should be _handle->get_object();
112 307587 : java_object_t* o = LLNI_UNWRAP(h);
113 307587 : java_object_t* result = raw_get<java_object_t*>(o, offset);
114 307587 : return LLNI_WRAP(result);
115 : }
116 :
117 :
118 192435 : 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 192435 : GCCriticalSection cs;
122 :
123 192435 : java_object_t* ho = LLNI_UNWRAP(h);
124 192435 : raw_set(ho, offset, value);
125 192435 : }
126 :
127 163381 : 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 163381 : GCCriticalSection cs;
131 :
132 : // XXX This should be h->get_object();
133 163381 : java_object_t* o = LLNI_UNWRAP(h);
134 163381 : java_object_t* ovalue = LLNI_UNWRAP(value);
135 163381 : raw_set(o, offset, ovalue);
136 163381 : }
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 559521 : java_lang_Object(java_handle_t* h) : _handle(h) {}
203 577949 : 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 11223 : 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 11223 : GCCriticalSection cs;
238 :
239 : // XXX This should be h->get_object();
240 11223 : java_object_t* o = LLNI_UNWRAP(_handle);
241 11223 : 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 353686 : 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 353686 : 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 85132 : static inline void set_fields(java_handle_t *str, java_handle_chararray_t* value) {
721 85132 : set(str, offset_value, value);
722 85132 : set(str, offset_count, CharArray(value).get_length());
723 85132 : set(str, offset_offset, (int32_t) 0);
724 : // cachedHashCode is assumed to be zero initialized
725 85132 : }
726 :
727 208693 : static inline java_handle_chararray_t *get_value(java_handle_t *str) {
728 208693 : return get<java_handle_chararray_t*>(str, offset_value);
729 : }
730 : static inline int32_t get_count(java_handle_t *str) {
731 : return get<int32_t>(str, offset_count);
732 : }
733 : static inline int32_t get_offset(java_handle_t *str) {
734 : 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 144494 : inline int32_t java_lang_String::get_count() const
751 : {
752 144494 : return get<int32_t>(_handle, offset_count);
753 : }
754 :
755 208693 : inline int32_t java_lang_String::get_offset() const
756 : {
757 208693 : 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 144494 : inline jsize get_string_count(const java_lang_String &s)
778 : {
779 144494 : return s.get_count();
780 : }
781 :
782 208693 : inline jsize get_string_offset(const java_lang_String &s)
783 : {
784 208693 : 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/Class
1851 : *
1852 : * Object layout:
1853 : *
1854 : * 0. object header
1855 : * ? java.lang.ClassLoader classLoader
1856 : */
1857 : class java_lang_Class : public java_lang_Object, private FieldAccess {
1858 : private:
1859 : // Static offsets of the object's instance fields.
1860 : static off_t offset_classLoader;
1861 :
1862 : public:
1863 : java_lang_Class(java_handle_t* h) : java_lang_Object(h) {}
1864 :
1865 : // Setters.
1866 : void set_classLoader(java_handle_t* value);
1867 :
1868 : // Offset initializers
1869 : static void set_classLoader_offset(int32_t off) { offset_classLoader = off; }
1870 : };
1871 :
1872 : inline void java_lang_Class::set_classLoader(java_handle_t* value)
1873 : {
1874 : if (offset_classLoader)
1875 : set(_handle, offset_classLoader, value);
1876 : }
1877 :
1878 : /**
1879 : * OpenJDK java/lang/ClassLoader
1880 : *
1881 : * Object layout:
1882 : *
1883 : * 0. object header
1884 : * 1. boolean initialized
1885 : * 2. java.lang.ClassLoader parent
1886 : * [other fields are not used]
1887 : */
1888 : class java_lang_ClassLoader : public java_lang_Object, private FieldAccess {
1889 : private:
1890 : // Static offsets of the object's instance fields.
1891 : // TODO These offsets need to be checked on VM startup.
1892 : static const off_t offset_initialized = MEMORY_ALIGN(sizeof(java_object_t), sizeof(int32_t));
1893 : static const off_t offset_parent = MEMORY_ALIGN(offset_initialized + sizeof(int32_t), SIZEOF_VOID_P);
1894 :
1895 : public:
1896 : java_lang_ClassLoader(java_handle_t* h) : java_lang_Object(h) {}
1897 :
1898 : // Getters.
1899 : java_handle_t* get_parent() const;
1900 :
1901 : // Invocation wrappers for static methods.
1902 : static java_handle_t* invoke_getSystemClassLoader();
1903 : };
1904 :
1905 : inline java_handle_t* java_lang_ClassLoader::get_parent() const
1906 : {
1907 : return get<java_handle_t*>(_handle, offset_parent);
1908 : }
1909 :
1910 :
1911 : /**
1912 : * OpenJDK java/lang/StackTraceElement
1913 : *
1914 : * Object layout:
1915 : *
1916 : * 0. object header
1917 : * 1. java.lang.String declaringClass;
1918 : * 2. java.lang.String methodName;
1919 : * 3. java.lang.String fileName;
1920 : * 4. int lineNumber;
1921 : */
1922 : class java_lang_StackTraceElement : public java_lang_Object, private FieldAccess {
1923 : private:
1924 : // Static offsets of the object's instance fields.
1925 : // TODO These offsets need to be checked on VM startup.
1926 : static const off_t offset_declaringClass = MEMORY_ALIGN(sizeof(java_object_t), SIZEOF_VOID_P);
1927 : static const off_t offset_methodName = MEMORY_ALIGN(offset_declaringClass + SIZEOF_VOID_P, SIZEOF_VOID_P);
1928 : static const off_t offset_fileName = MEMORY_ALIGN(offset_methodName + SIZEOF_VOID_P, SIZEOF_VOID_P);
1929 : static const off_t offset_lineNumber = MEMORY_ALIGN(offset_fileName + SIZEOF_VOID_P, sizeof(int32_t));
1930 :
1931 : public:
1932 : java_lang_StackTraceElement(java_handle_t* h) : java_lang_Object(h) {}
1933 : java_lang_StackTraceElement(java_handle_t* declaringClass, java_handle_t* methodName, java_handle_t* fileName, int32_t lineNumber);
1934 : };
1935 :
1936 : inline java_lang_StackTraceElement::java_lang_StackTraceElement(java_handle_t* declaringClass, java_handle_t* methodName, java_handle_t* fileName, int32_t lineNumber)
1937 : {
1938 : _handle = builtin_new(class_java_lang_StackTraceElement);
1939 :
1940 : if (is_null())
1941 : return;
1942 :
1943 : set(_handle, offset_declaringClass, declaringClass);
1944 : set(_handle, offset_methodName, methodName);
1945 : set(_handle, offset_fileName, fileName);
1946 : set(_handle, offset_lineNumber, lineNumber);
1947 : }
1948 :
1949 :
1950 : /**
1951 : * OpenJDK java/lang/String
1952 : *
1953 : * Object layout (JDK6):
1954 : *
1955 : * 0. object header
1956 : * 1. char[] value;
1957 : * 2. int offset;
1958 : * 3. int count;
1959 : * 4. int hash;
1960 : *
1961 : * Object layout (JDK7):
1962 : *
1963 : * 0. object header
1964 : * 1. char[] value;
1965 : * 2. int hash;
1966 : */
1967 : class java_lang_String : public java_lang_Object, private FieldAccess {
1968 : private:
1969 : // Static offsets of the object's instance fields.
1970 : // TODO These offsets need to be checked on VM startup.
1971 : static const off_t offset_value = MEMORY_ALIGN(sizeof(java_object_t), SIZEOF_VOID_P);
1972 : #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
1973 : static const off_t offset_offset = MEMORY_ALIGN(offset_value + SIZEOF_VOID_P, sizeof(int32_t));
1974 : static const off_t offset_count = MEMORY_ALIGN(offset_offset + sizeof(int32_t), sizeof(int32_t));
1975 : #else
1976 : static const off_t offset_hash = MEMORY_ALIGN(offset_value + SIZEOF_VOID_P, sizeof(int32_t));
1977 : #endif
1978 :
1979 : public:
1980 : java_lang_String(java_handle_t* h) : java_lang_Object(h) {}
1981 : java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset = 0);
1982 :
1983 : // Getters.
1984 : java_handle_chararray_t* get_value () const;
1985 : #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
1986 : int32_t get_offset() const;
1987 : int32_t get_count () const;
1988 : #endif
1989 :
1990 : // Setters.
1991 : void set_value (java_handle_chararray_t* value);
1992 : #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
1993 : void set_offset(int32_t value);
1994 : void set_count (int32_t value);
1995 : #endif
1996 :
1997 : // Raw access
1998 : static inline void set_fields(java_handle_t *str, java_handle_chararray_t *value) {
1999 : set(str, offset_value, value);
2000 : #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
2001 : set(str, offset_offset, (int32_t) 0);
2002 : set(str, offset_count, CharArray(value).get_length());
2003 : #endif
2004 : // hash is assumed to be zero initialized
2005 : }
2006 :
2007 : static inline java_handle_chararray_t *get_value(java_handle_t *str) {
2008 : return get<java_handle_chararray_t*>(str, offset_value);
2009 : }
2010 : };
2011 :
2012 : 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)
2013 : {
2014 : set_value(value);
2015 : #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
2016 : set_offset(offset);
2017 : set_count(count);
2018 : #endif
2019 : }
2020 :
2021 : inline java_handle_chararray_t* java_lang_String::get_value() const
2022 : {
2023 : return get<java_handle_chararray_t*>(_handle, offset_value);
2024 : }
2025 :
2026 : #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
2027 : inline int32_t java_lang_String::get_offset() const
2028 : {
2029 : return get<int32_t>(_handle, offset_offset);
2030 : }
2031 :
2032 : inline int32_t java_lang_String::get_count() const
2033 : {
2034 : return get<int32_t>(_handle, offset_count);
2035 : }
2036 : #endif
2037 :
2038 : inline void java_lang_String::set_value(java_handle_chararray_t* value)
2039 : {
2040 : set(_handle, offset_value, value);
2041 : }
2042 :
2043 : #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
2044 : inline void java_lang_String::set_offset(int32_t value)
2045 : {
2046 : set(_handle, offset_offset, value);
2047 : }
2048 :
2049 : inline void java_lang_String::set_count(int32_t value)
2050 : {
2051 : set(_handle, offset_count, value);
2052 : }
2053 : #endif
2054 :
2055 : #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
2056 : namespace jdk6_str_ops {
2057 :
2058 : inline jsize get_string_count(const java_lang_String &s)
2059 : {
2060 : return s.get_count();
2061 : }
2062 :
2063 : inline jsize get_string_offset(const java_lang_String &s)
2064 : {
2065 : return s.get_offset();
2066 : }
2067 :
2068 : }
2069 : #endif
2070 :
2071 : namespace jdk7_str_ops {
2072 :
2073 : inline jsize get_string_count(const java_lang_String &s)
2074 : {
2075 : java_handle_chararray_t *value = s.get_value();
2076 : return value ? CharArray(value).get_length() : 0;
2077 : }
2078 :
2079 : inline jsize get_string_offset(const java_lang_String &s)
2080 : {
2081 : return 0;
2082 : }
2083 :
2084 : }
2085 :
2086 : #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
2087 : namespace runtime_str_ops = jdk6_str_ops;
2088 : #else
2089 : namespace runtime_str_ops = jdk7_str_ops;
2090 : #endif
2091 :
2092 :
2093 : /**
2094 : * OpenJDK java/lang/Thread
2095 : */
2096 : class java_lang_Thread : public java_lang_Object, private FieldAccess {
2097 : private:
2098 : static off_t offset_priority;
2099 : static off_t offset_daemon;
2100 : static off_t offset_group;
2101 : static off_t offset_uncaughtExceptionHandler;
2102 : static off_t offset_threadStatus;
2103 : #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
2104 : static off_t offset_me;
2105 : #endif
2106 :
2107 : public:
2108 : java_lang_Thread(java_handle_t* h) : java_lang_Object(h) {}
2109 :
2110 : // Getters.
2111 : int32_t get_priority () const;
2112 : int32_t get_daemon () const;
2113 : java_handle_t* get_group () const;
2114 : java_handle_t* get_uncaughtExceptionHandler() const;
2115 :
2116 : // Setters.
2117 : void set_priority (int32_t value);
2118 : void set_group (java_handle_t* value);
2119 : void set_threadStatus(int32_t value);
2120 : #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
2121 : void set_me (java_handle_t* value);
2122 : #endif
2123 :
2124 : // Offset initializers
2125 : static void set_priority_offset(int32_t off) { offset_priority = off; }
2126 : static void set_daemon_offset(int32_t off) { offset_daemon = off; }
2127 : static void set_group_offset(int32_t off) { offset_group = off; }
2128 : static void set_uncaughtExceptionHandler_offset(int32_t off) { offset_uncaughtExceptionHandler = off; }
2129 : static void set_threadStatus_offset(int32_t off) { offset_threadStatus = off; }
2130 : #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
2131 : static void set_me_offset(int32_t off) { offset_me = off; }
2132 : #endif
2133 : };
2134 :
2135 :
2136 : inline int32_t java_lang_Thread::get_priority() const
2137 : {
2138 : return get<int32_t>(_handle, offset_priority);
2139 : }
2140 :
2141 : inline int32_t java_lang_Thread::get_daemon() const
2142 : {
2143 : return get<int32_t>(_handle, offset_daemon);
2144 : }
2145 :
2146 : inline java_handle_t* java_lang_Thread::get_group() const
2147 : {
2148 : return get<java_handle_t*>(_handle, offset_group);
2149 : }
2150 :
2151 : inline java_handle_t* java_lang_Thread::get_uncaughtExceptionHandler() const
2152 : {
2153 : return get<java_handle_t*>(_handle, offset_uncaughtExceptionHandler);
2154 : }
2155 :
2156 :
2157 : inline void java_lang_Thread::set_priority(int32_t value)
2158 : {
2159 : set(_handle, offset_priority, value);
2160 : }
2161 :
2162 : inline void java_lang_Thread::set_group(java_handle_t* value)
2163 : {
2164 : set(_handle, offset_group, value);
2165 : }
2166 :
2167 : inline void java_lang_Thread::set_threadStatus(int32_t value)
2168 : {
2169 : set(_handle, offset_threadStatus, value);
2170 : }
2171 :
2172 : #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
2173 : inline void java_lang_Thread::set_me(java_handle_t* value)
2174 : {
2175 : set(_handle, offset_me, value);
2176 : }
2177 : #endif
2178 :
2179 :
2180 : /**
2181 : * OpenJDK java/lang/Throwable
2182 : *
2183 : * Object layout:
2184 : *
2185 : * 0. object header
2186 : * 1. java.lang.Object backtrace;
2187 : * 2. java.lang.String detailMessage;
2188 : * 3. java.lang.Throwable cause;
2189 : * 4. java.lang.StackTraceElement[] stackTrace;
2190 : */
2191 : class java_lang_Throwable : public java_lang_Object, private FieldAccess {
2192 : private:
2193 : // Static offsets of the object's instance fields.
2194 : // TODO These offsets need to be checked on VM startup.
2195 : static const off_t offset_backtrace = MEMORY_ALIGN(sizeof(java_object_t), SIZEOF_VOID_P);
2196 : static const off_t offset_detailMessage = MEMORY_ALIGN(offset_backtrace + SIZEOF_VOID_P, SIZEOF_VOID_P);
2197 : static const off_t offset_cause = MEMORY_ALIGN(offset_detailMessage + SIZEOF_VOID_P, SIZEOF_VOID_P);
2198 : static const off_t offset_stackTrace = MEMORY_ALIGN(offset_cause + SIZEOF_VOID_P, SIZEOF_VOID_P);
2199 :
2200 : public:
2201 : java_lang_Throwable(java_handle_t* h) : java_lang_Object(h) {}
2202 : java_lang_Throwable(java_handle_t* h, java_handle_bytearray_t* backtrace);
2203 :
2204 : // Getters.
2205 : java_handle_bytearray_t* get_backtrace () const;
2206 : java_handle_t* get_detailMessage() const;
2207 : java_handle_t* get_cause () const;
2208 :
2209 : // Setters.
2210 : void set_backtrace(java_handle_bytearray_t* value);
2211 : };
2212 :
2213 :
2214 : inline java_lang_Throwable::java_lang_Throwable(java_handle_t* h, java_handle_bytearray_t* backtrace) : java_lang_Object(h)
2215 : {
2216 : set_backtrace(backtrace);
2217 : }
2218 :
2219 :
2220 : inline java_handle_bytearray_t* java_lang_Throwable::get_backtrace() const
2221 : {
2222 : return get<java_handle_bytearray_t*>(_handle, offset_backtrace);
2223 : }
2224 :
2225 : inline java_handle_t* java_lang_Throwable::get_detailMessage() const
2226 : {
2227 : return get<java_handle_t*>(_handle, offset_detailMessage);
2228 : }
2229 :
2230 : inline java_handle_t* java_lang_Throwable::get_cause() const
2231 : {
2232 : return get<java_handle_t*>(_handle, offset_cause);
2233 : }
2234 :
2235 :
2236 : inline void java_lang_Throwable::set_backtrace(java_handle_bytearray_t* value)
2237 : {
2238 : set(_handle, offset_backtrace, value);
2239 : }
2240 :
2241 :
2242 : /**
2243 : * OpenJDK java/lang/reflect/Constructor
2244 : *
2245 : * Object layout:
2246 : *
2247 : * 0. object header
2248 : * 1. boolean override;
2249 : * 2. java.lang.Class clazz;
2250 : * 3. int slot;
2251 : * 4. java.lang.Class[] parameterTypes;
2252 : * 5. java.lang.Class[] exceptionTypes;
2253 : * 6. int modifiers;
2254 : * 7. java.lang.String signature;
2255 : * 8. sun.reflect.generics.repository.ConstructorRepository genericInfo;
2256 : * 9. byte[] annotations;
2257 : * 10. byte[] parameterAnnotations;
2258 : * 11. java.lang.Class securityCheckCache;
2259 : * 12. sun.reflect.ConstructorAccessor constructorAccessor;
2260 : * 13. java.lang.reflect.Constructor root;
2261 : * 14. java.util.Map declaredAnnotations;
2262 : */
2263 : class java_lang_reflect_Constructor : public java_lang_Object, private FieldAccess {
2264 : private:
2265 : // Static offsets of the object's instance fields.
2266 : // TODO These offsets need to be checked on VM startup.
2267 : static const off_t offset_override = MEMORY_ALIGN(sizeof(java_object_t), sizeof(int32_t));
2268 : #ifdef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
2269 : static const off_t offset_securityCheckCache = MEMORY_ALIGN(offset_override + sizeof(int32_t), SIZEOF_VOID_P);
2270 : /* Members of the actual class java.lang.reflect.Constructor */
2271 : static const off_t offset_clazz = MEMORY_ALIGN(offset_securityCheckCache + sizeof(int32_t), SIZEOF_VOID_P);
2272 : #else
2273 : static const off_t offset_clazz = MEMORY_ALIGN(offset_override + sizeof(int32_t), SIZEOF_VOID_P);
2274 : #endif
2275 : static const off_t offset_slot = MEMORY_ALIGN(offset_clazz + SIZEOF_VOID_P, sizeof(int32_t));
2276 : static const off_t offset_parameterTypes = MEMORY_ALIGN(offset_slot + sizeof(int32_t), SIZEOF_VOID_P);
2277 : static const off_t offset_exceptionTypes = MEMORY_ALIGN(offset_parameterTypes + SIZEOF_VOID_P, SIZEOF_VOID_P);
2278 : static const off_t offset_modifiers = MEMORY_ALIGN(offset_exceptionTypes + SIZEOF_VOID_P, sizeof(int32_t));
2279 : static const off_t offset_signature = MEMORY_ALIGN(offset_modifiers + sizeof(int32_t), SIZEOF_VOID_P);
2280 : static const off_t offset_genericInfo = MEMORY_ALIGN(offset_signature + SIZEOF_VOID_P, SIZEOF_VOID_P);
2281 : static const off_t offset_annotations = MEMORY_ALIGN(offset_genericInfo + SIZEOF_VOID_P, SIZEOF_VOID_P);
2282 : static const off_t offset_parameterAnnotations = MEMORY_ALIGN(offset_annotations + SIZEOF_VOID_P, SIZEOF_VOID_P);
2283 : #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
2284 : static const off_t offset_securityCheckCache = MEMORY_ALIGN(offset_parameterAnnotations + SIZEOF_VOID_P, SIZEOF_VOID_P);
2285 : #endif
2286 : static const off_t offset_constructorAccessor = MEMORY_ALIGN(offset_securityCheckCache + SIZEOF_VOID_P, SIZEOF_VOID_P);
2287 : static const off_t offset_root = MEMORY_ALIGN(offset_constructorAccessor + SIZEOF_VOID_P, SIZEOF_VOID_P);
2288 : static const off_t offset_declaredAnnotations = MEMORY_ALIGN(offset_root + SIZEOF_VOID_P, SIZEOF_VOID_P);
2289 :
2290 : public:
2291 : java_lang_reflect_Constructor(java_handle_t* h) : java_lang_Object(h) {}
2292 : java_lang_reflect_Constructor(methodinfo* m);
2293 :
2294 : java_handle_t* new_instance(java_handle_objectarray_t* args);
2295 :
2296 : // Getters.
2297 : int32_t get_override () const;
2298 : classinfo* get_clazz () const;
2299 : int32_t get_slot () const;
2300 : java_handle_bytearray_t* get_annotations() const;
2301 :
2302 : // Setters.
2303 : void set_clazz (classinfo* value);
2304 : void set_slot (int32_t value);
2305 : void set_parameterTypes (java_handle_objectarray_t* value);
2306 : void set_exceptionTypes (java_handle_objectarray_t* value);
2307 : void set_modifiers (int32_t value);
2308 : void set_signature (java_handle_t* value);
2309 : void set_annotations (java_handle_bytearray_t* value);
2310 : void set_parameterAnnotations(java_handle_bytearray_t* value);
2311 :
2312 : // Convenience functions.
2313 : methodinfo* get_method();
2314 : };
2315 :
2316 :
2317 : inline java_lang_reflect_Constructor::java_lang_reflect_Constructor(methodinfo* m)
2318 : {
2319 : _handle = builtin_new(class_java_lang_reflect_Constructor);
2320 :
2321 : if (is_null())
2322 : return;
2323 :
2324 : int slot = m - m->clazz->methods;
2325 : java_handle_objectarray_t* parameterTypes = method_get_parametertypearray(m);
2326 : java_handle_objectarray_t* exceptionTypes = method_get_exceptionarray(m);
2327 : java_handle_bytearray_t* annotations = method_get_annotations(m);
2328 : java_handle_bytearray_t* parameterAnnotations = method_get_parameterannotations(m);
2329 :
2330 : set_clazz(m->clazz);
2331 : set_slot(slot);
2332 : set_parameterTypes(parameterTypes);
2333 : set_exceptionTypes(exceptionTypes);
2334 : set_modifiers(m->flags & ACC_CLASS_REFLECT_MASK);
2335 : set_signature(m->signature ? JavaString::from_utf8(m->signature) : NULL);
2336 : set_annotations(annotations);
2337 : set_parameterAnnotations(parameterAnnotations);
2338 : }
2339 :
2340 :
2341 : inline int32_t java_lang_reflect_Constructor::get_override() const
2342 : {
2343 : return get<int32_t>(_handle, offset_override);
2344 : }
2345 :
2346 : inline classinfo* java_lang_reflect_Constructor::get_clazz() const
2347 : {
2348 : return get<classinfo*>(_handle, offset_clazz);
2349 : }
2350 :
2351 : inline int32_t java_lang_reflect_Constructor::get_slot() const
2352 : {
2353 : return get<int32_t>(_handle, offset_slot);
2354 : }
2355 :
2356 : inline java_handle_bytearray_t* java_lang_reflect_Constructor::get_annotations() const
2357 : {
2358 : return get<java_handle_bytearray_t*>(_handle, offset_annotations);
2359 : }
2360 :
2361 :
2362 : inline void java_lang_reflect_Constructor::set_clazz(classinfo* value)
2363 : {
2364 : set(_handle, offset_clazz, value);
2365 : }
2366 :
2367 : inline void java_lang_reflect_Constructor::set_slot(int32_t value)
2368 : {
2369 : set(_handle, offset_slot, value);
2370 : }
2371 :
2372 : inline void java_lang_reflect_Constructor::set_parameterTypes(java_handle_objectarray_t* value)
2373 : {
2374 : set(_handle, offset_parameterTypes, value);
2375 : }
2376 :
2377 : inline void java_lang_reflect_Constructor::set_exceptionTypes(java_handle_objectarray_t* value)
2378 : {
2379 : set(_handle, offset_exceptionTypes, value);
2380 : }
2381 :
2382 : inline void java_lang_reflect_Constructor::set_modifiers(int32_t value)
2383 : {
2384 : set(_handle, offset_modifiers, value);
2385 : }
2386 :
2387 : inline void java_lang_reflect_Constructor::set_signature(java_handle_t* value)
2388 : {
2389 : set(_handle, offset_signature, value);
2390 : }
2391 :
2392 : inline void java_lang_reflect_Constructor::set_annotations(java_handle_bytearray_t* value)
2393 : {
2394 : set(_handle, offset_annotations, value);
2395 : }
2396 :
2397 : inline void java_lang_reflect_Constructor::set_parameterAnnotations(java_handle_bytearray_t* value)
2398 : {
2399 : set(_handle, offset_parameterAnnotations, value);
2400 : }
2401 :
2402 :
2403 : inline methodinfo* java_lang_reflect_Constructor::get_method()
2404 : {
2405 : classinfo* c = get_clazz();
2406 : int32_t slot = get_slot();
2407 : methodinfo* m = &(c->methods[slot]);
2408 : return m;
2409 : }
2410 :
2411 :
2412 : /**
2413 : * OpenJDK java/lang/reflect/Field
2414 : *
2415 : * Object layout:
2416 : *
2417 : * 0. object header
2418 : * 1. boolean override;
2419 : * 2. java.lang.Class clazz;
2420 : * 3. int slot;
2421 : * 4. java.lang.String name;
2422 : * 5. java.lang.Class type;
2423 : * 6. int modifiers;
2424 : * 7. java.lang.String signature;
2425 : * 8. sun.reflect.generics.repository.FieldRepository genericInfo;
2426 : * 9. byte[] annotations;
2427 : * 10. sun.reflect.FieldAccessor fieldAccessor;
2428 : * 11. sun.reflect.FieldAccessor overrideFieldAccessor;
2429 : * 12. java.lang.reflect.Field root;
2430 : * 13. java.lang.Class securityCheckCache;
2431 : * 14. java.lang.Class securityCheckTargetClassCache;
2432 : * 15. java.util.Map declaredAnnotations;
2433 : */
2434 : class java_lang_reflect_Field : public java_lang_Object, private FieldAccess {
2435 : private:
2436 : // Static offsets of the object's instance fields.
2437 : // TODO These offsets need to be checked on VM startup.
2438 : /* Fields of extended class
2439 : * java.lang.reflect.AccessibleObject */
2440 : static const off_t offset_override = MEMORY_ALIGN(sizeof(java_object_t), sizeof(int32_t));
2441 : #ifdef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
2442 : static const off_t offset_securityCheckCache = MEMORY_ALIGN(offset_override + sizeof(int32_t), SIZEOF_VOID_P);
2443 : /* Members of the actual class java.lang.reflect.Field */
2444 : static const off_t offset_clazz = MEMORY_ALIGN(offset_securityCheckCache + sizeof(int32_t), SIZEOF_VOID_P);
2445 : #else
2446 : static const off_t offset_clazz = MEMORY_ALIGN(offset_override + sizeof(int32_t), SIZEOF_VOID_P);
2447 : #endif
2448 : static const off_t offset_slot = MEMORY_ALIGN(offset_clazz + SIZEOF_VOID_P, sizeof(int32_t));
2449 : static const off_t offset_name = MEMORY_ALIGN(offset_slot + sizeof(int32_t), SIZEOF_VOID_P);
2450 : static const off_t offset_type = MEMORY_ALIGN(offset_name + SIZEOF_VOID_P, SIZEOF_VOID_P);
2451 : static const off_t offset_modifiers = MEMORY_ALIGN(offset_type + SIZEOF_VOID_P, sizeof(int32_t));
2452 : static const off_t offset_signature = MEMORY_ALIGN(offset_modifiers + sizeof(int32_t), SIZEOF_VOID_P);
2453 : static const off_t offset_genericInfo = MEMORY_ALIGN(offset_signature + SIZEOF_VOID_P, SIZEOF_VOID_P);
2454 : static const off_t offset_annotations = MEMORY_ALIGN(offset_genericInfo + SIZEOF_VOID_P, SIZEOF_VOID_P);
2455 : static const off_t offset_fieldAccessor = MEMORY_ALIGN(offset_annotations + SIZEOF_VOID_P, SIZEOF_VOID_P);
2456 : static const off_t offset_overrideFieldAccessor = MEMORY_ALIGN(offset_fieldAccessor + SIZEOF_VOID_P, SIZEOF_VOID_P);
2457 : static const off_t offset_root = MEMORY_ALIGN(offset_overrideFieldAccessor + SIZEOF_VOID_P, SIZEOF_VOID_P);
2458 : #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
2459 : static const off_t offset_securityCheckCache = MEMORY_ALIGN(offset_root + SIZEOF_VOID_P, SIZEOF_VOID_P);
2460 : static const off_t offset_securityCheckTargetClassCache = MEMORY_ALIGN(offset_securityCheckCache + SIZEOF_VOID_P, SIZEOF_VOID_P);
2461 : static const off_t offset_declaredAnnotations = MEMORY_ALIGN(offset_securityCheckTargetClassCache + SIZEOF_VOID_P, SIZEOF_VOID_P);
2462 : #endif
2463 :
2464 : public:
2465 : java_lang_reflect_Field(java_handle_t* h) : java_lang_Object(h) {}
2466 : java_lang_reflect_Field(fieldinfo* f);
2467 :
2468 : // Getters.
2469 : int32_t get_override () const;
2470 : classinfo* get_clazz () const;
2471 : int32_t get_slot () const;
2472 : java_handle_bytearray_t* get_annotations() const;
2473 :
2474 : // Setters.
2475 : void set_clazz (classinfo* value);
2476 : void set_slot (int32_t value);
2477 : void set_name (java_handle_t* value);
2478 : void set_type (classinfo* value);
2479 : void set_modifiers (int32_t value);
2480 : void set_signature (java_handle_t* value);
2481 : void set_annotations(java_handle_bytearray_t* value);
2482 :
2483 : // Convenience functions.
2484 : fieldinfo* get_field() const;
2485 : };
2486 :
2487 :
2488 : inline java_lang_reflect_Field::java_lang_reflect_Field(fieldinfo* f)
2489 : {
2490 : _handle = builtin_new(class_java_lang_reflect_Field);
2491 :
2492 : // OOME.
2493 : if (is_null())
2494 : return;
2495 :
2496 : set_clazz(f->clazz);
2497 : set_slot(f - f->clazz->fields);
2498 : set_name(JavaString::literal(f->name));
2499 : set_type(field_get_type(f));
2500 : set_modifiers(f->flags);
2501 : set_signature(f->signature ? JavaString::from_utf8(f->signature) : NULL);
2502 : set_annotations(field_get_annotations(f));
2503 : }
2504 :
2505 :
2506 : inline int32_t java_lang_reflect_Field::get_override() const
2507 : {
2508 : return get<int32_t>(_handle, offset_override);
2509 : }
2510 :
2511 : inline classinfo* java_lang_reflect_Field::get_clazz() const
2512 : {
2513 : return get<classinfo*>(_handle, offset_clazz);
2514 : }
2515 :
2516 : inline int32_t java_lang_reflect_Field::get_slot() const
2517 : {
2518 : return get<int32_t>(_handle, offset_slot);
2519 : }
2520 :
2521 : inline java_handle_bytearray_t* java_lang_reflect_Field::get_annotations() const
2522 : {
2523 : return get<java_handle_bytearray_t*>(_handle, offset_annotations);
2524 : }
2525 :
2526 :
2527 : inline void java_lang_reflect_Field::set_clazz(classinfo* value)
2528 : {
2529 : set(_handle, offset_clazz, value);
2530 : }
2531 :
2532 : inline void java_lang_reflect_Field::set_slot(int32_t value)
2533 : {
2534 : set(_handle, offset_slot, value);
2535 : }
2536 :
2537 : inline void java_lang_reflect_Field::set_name(java_handle_t* value)
2538 : {
2539 : set(_handle, offset_name, value);
2540 : }
2541 :
2542 : inline void java_lang_reflect_Field::set_type(classinfo* value)
2543 : {
2544 : set(_handle, offset_type, value);
2545 : }
2546 :
2547 : inline void java_lang_reflect_Field::set_modifiers(int32_t value)
2548 : {
2549 : set(_handle, offset_modifiers, value);
2550 : }
2551 :
2552 : inline void java_lang_reflect_Field::set_signature(java_handle_t* value)
2553 : {
2554 : set(_handle, offset_signature, value);
2555 : }
2556 :
2557 : inline void java_lang_reflect_Field::set_annotations(java_handle_bytearray_t* value)
2558 : {
2559 : set(_handle, offset_annotations, value);
2560 : }
2561 :
2562 :
2563 : inline fieldinfo* java_lang_reflect_Field::get_field() const
2564 : {
2565 : classinfo* c = get_clazz();
2566 : int32_t slot = get_slot();
2567 : fieldinfo* f = &(c->fields[slot]);
2568 : return f;
2569 : }
2570 :
2571 :
2572 : /**
2573 : * OpenJDK java/lang/reflect/Method
2574 : *
2575 : * Object layout:
2576 : *
2577 : * 0. object header
2578 : * 1. boolean override;
2579 : * 2. java.lang.Class clazz;
2580 : * 3. int slot;
2581 : * 4. java.lang.String name;
2582 : * 5. java.lang.Class returnType;
2583 : * 6. java.lang.Class[] parameterTypes;
2584 : * 7. java.lang.Class[] exceptionTypes;
2585 : * 8. int modifiers;
2586 : * 9. java.lang.String signature;
2587 : * 10 sun.reflect.generics.repository.ConstructorRepository genericInfo;
2588 : * 11. byte[] annotations;
2589 : * 12. byte[] parameterAnnotations;
2590 : * 13. byte[] annotationDefault;
2591 : * 14. sun.reflect.MethodAccessor methodAccessor;
2592 : * 15. java.lang.reflect.Method root;
2593 : * 16. java.lang.Class securityCheckCache;
2594 : * 17. java.lang.Class securityCheckTargetClassCache;
2595 : * 18. java.util.Map declaredAnnotations;
2596 : */
2597 : class java_lang_reflect_Method : public java_lang_Object, private FieldAccess {
2598 : private:
2599 : // Static offsets of the object's instance fields.
2600 : // TODO These offsets need to be checked on VM startup.
2601 : /* Fields of extended class
2602 : * java.lang.reflect.AccessibleObject */
2603 : static const off_t offset_override = MEMORY_ALIGN(sizeof(java_object_t), sizeof(int32_t));
2604 : #ifdef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
2605 : static const off_t offset_securityCheckCache = MEMORY_ALIGN(offset_override + sizeof(int32_t), SIZEOF_VOID_P);
2606 : /* Members of the actual class java.lang.reflect.Method */
2607 : static const off_t offset_clazz = MEMORY_ALIGN(offset_securityCheckCache + sizeof(int32_t), SIZEOF_VOID_P);
2608 : #else
2609 : static const off_t offset_clazz = MEMORY_ALIGN(offset_override + sizeof(int32_t), SIZEOF_VOID_P);
2610 : #endif
2611 : static const off_t offset_slot = MEMORY_ALIGN(offset_clazz + SIZEOF_VOID_P, sizeof(int32_t));
2612 : static const off_t offset_name = MEMORY_ALIGN(offset_slot + sizeof(int32_t), SIZEOF_VOID_P);
2613 : static const off_t offset_returnType = MEMORY_ALIGN(offset_name + SIZEOF_VOID_P, SIZEOF_VOID_P);
2614 : static const off_t offset_parameterTypes = MEMORY_ALIGN(offset_returnType + SIZEOF_VOID_P, SIZEOF_VOID_P);
2615 : static const off_t offset_exceptionTypes = MEMORY_ALIGN(offset_parameterTypes + SIZEOF_VOID_P, SIZEOF_VOID_P);
2616 : static const off_t offset_modifiers = MEMORY_ALIGN(offset_exceptionTypes + SIZEOF_VOID_P, sizeof(int32_t));
2617 : static const off_t offset_signature = MEMORY_ALIGN(offset_modifiers + sizeof(int32_t), SIZEOF_VOID_P);
2618 : static const off_t offset_genericInfo = MEMORY_ALIGN(offset_signature + SIZEOF_VOID_P, SIZEOF_VOID_P);
2619 : static const off_t offset_annotations = MEMORY_ALIGN(offset_genericInfo + SIZEOF_VOID_P, SIZEOF_VOID_P);
2620 : static const off_t offset_parameterAnnotations = MEMORY_ALIGN(offset_annotations + SIZEOF_VOID_P, SIZEOF_VOID_P);
2621 : static const off_t offset_annotationDefault = MEMORY_ALIGN(offset_parameterAnnotations + SIZEOF_VOID_P, SIZEOF_VOID_P);
2622 : static const off_t offset_methodAccessor = MEMORY_ALIGN(offset_annotationDefault + SIZEOF_VOID_P, SIZEOF_VOID_P);
2623 : static const off_t offset_root = MEMORY_ALIGN(offset_methodAccessor + SIZEOF_VOID_P, SIZEOF_VOID_P);
2624 : #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
2625 : static const off_t offset_securityCheckCache = MEMORY_ALIGN(offset_root + SIZEOF_VOID_P, SIZEOF_VOID_P);
2626 : static const off_t offset_securityCheckTargetClassCache = MEMORY_ALIGN(offset_securityCheckCache + SIZEOF_VOID_P, SIZEOF_VOID_P);
2627 : static const off_t offset_declaredAnnotations = MEMORY_ALIGN(offset_securityCheckTargetClassCache + SIZEOF_VOID_P, SIZEOF_VOID_P);
2628 : #endif
2629 :
2630 : public:
2631 : java_lang_reflect_Method(java_handle_t* h) : java_lang_Object(h) {}
2632 : java_lang_reflect_Method(methodinfo* m);
2633 :
2634 : java_handle_t* invoke(java_handle_t* o, java_handle_objectarray_t* args);
2635 :
2636 : // Getters.
2637 : int32_t get_override () const;
2638 : classinfo* get_clazz () const;
2639 : int32_t get_slot () const;
2640 : java_handle_bytearray_t* get_annotations () const;
2641 : java_handle_bytearray_t* get_parameterAnnotations() const;
2642 : java_handle_bytearray_t* get_annotationDefault () const;
2643 :
2644 : // Setters.
2645 :
2646 : // Convenience functions.
2647 : methodinfo* get_method() const;
2648 : };
2649 :
2650 :
2651 : inline java_lang_reflect_Method::java_lang_reflect_Method(methodinfo* m)
2652 : {
2653 : _handle = builtin_new(class_java_lang_reflect_Method);
2654 :
2655 : if (is_null())
2656 : return;
2657 :
2658 : set(_handle, offset_clazz, m->clazz);
2659 : set(_handle, offset_slot, (int32_t) (m - m->clazz->methods)); // This cast is important (see PR100).
2660 : set(_handle, offset_name, JavaString::literal(m->name));
2661 : set(_handle, offset_returnType, method_returntype_get(m));
2662 : set(_handle, offset_parameterTypes, method_get_parametertypearray(m));
2663 : set(_handle, offset_exceptionTypes, method_get_exceptionarray(m));
2664 : set(_handle, offset_modifiers, (int32_t) (m->flags & ACC_CLASS_REFLECT_MASK));
2665 : set(_handle, offset_signature, m->signature ? JavaString::from_utf8(m->signature) : NULL);
2666 : set(_handle, offset_annotations, method_get_annotations(m));
2667 : set(_handle, offset_parameterAnnotations, method_get_parameterannotations(m));
2668 : set(_handle, offset_annotationDefault, method_get_annotationdefault(m));
2669 : }
2670 :
2671 :
2672 : inline int32_t java_lang_reflect_Method::get_override() const
2673 : {
2674 : return get<int32_t>(_handle, offset_override);
2675 : }
2676 :
2677 : inline classinfo* java_lang_reflect_Method::get_clazz() const
2678 : {
2679 : return get<classinfo*>(_handle, offset_clazz);
2680 : }
2681 :
2682 : inline int32_t java_lang_reflect_Method::get_slot() const
2683 : {
2684 : return get<int32_t>(_handle, offset_slot);
2685 : }
2686 :
2687 : inline java_handle_bytearray_t* java_lang_reflect_Method::get_annotations() const
2688 : {
2689 : return get<java_handle_bytearray_t*>(_handle, offset_annotations);
2690 : }
2691 :
2692 : inline java_handle_bytearray_t* java_lang_reflect_Method::get_parameterAnnotations() const
2693 : {
2694 : return get<java_handle_bytearray_t*>(_handle, offset_parameterAnnotations);
2695 : }
2696 :
2697 : inline java_handle_bytearray_t* java_lang_reflect_Method::get_annotationDefault() const
2698 : {
2699 : return get<java_handle_bytearray_t*>(_handle, offset_annotationDefault);
2700 : }
2701 :
2702 :
2703 : inline methodinfo* java_lang_reflect_Method::get_method() const
2704 : {
2705 : classinfo* c = get_clazz();
2706 : int32_t slot = get_slot();
2707 : methodinfo* m = &(c->methods[slot]);
2708 : return m;
2709 : }
2710 :
2711 :
2712 : /**
2713 : * OpenJDK java/nio/Buffer
2714 : *
2715 : * Object layout:
2716 : *
2717 : * 0. object header
2718 : * 1. int mark;
2719 : * 2. int position;
2720 : * 3. int limit;
2721 : * 4. int capacity;
2722 : * 5. long address;
2723 : */
2724 : class java_nio_Buffer : public java_lang_Object, private FieldAccess {
2725 : private:
2726 : // Static offsets of the object's instance fields.
2727 : // TODO These offsets need to be checked on VM startup.
2728 : static const off_t offset_mark = MEMORY_ALIGN(sizeof(java_object_t), sizeof(int32_t));
2729 : static const off_t offset_position = MEMORY_ALIGN(offset_mark + sizeof(int32_t), sizeof(int32_t));
2730 : static const off_t offset_limit = MEMORY_ALIGN(offset_position + sizeof(int32_t), sizeof(int32_t));
2731 : static const off_t offset_capacity = MEMORY_ALIGN(offset_limit + sizeof(int32_t), sizeof(int32_t));
2732 : static const off_t offset_address = MEMORY_ALIGN(offset_capacity + sizeof(int32_t), sizeof(int64_t));
2733 :
2734 : public:
2735 : java_nio_Buffer(java_handle_t* h) : java_lang_Object(h) {}
2736 :
2737 : // Getters.
2738 : void* get_address() const;
2739 : int32_t get_capacity() const;
2740 : };
2741 :
2742 :
2743 : inline void* java_nio_Buffer::get_address() const
2744 : {
2745 : return get<void*>(_handle, offset_address);
2746 : }
2747 :
2748 : inline int32_t java_nio_Buffer::get_capacity() const
2749 : {
2750 : return get<int32_t>(_handle, offset_capacity);
2751 : }
2752 :
2753 : #endif // WITH_JAVA_RUNTIME_LIBRARY_OPENJDK
2754 :
2755 :
2756 : #if defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
2757 :
2758 : /**
2759 : * CLDC 1.1 com/sun/cldchi/jvm/FileDescriptor
2760 : *
2761 : * Object layout:
2762 : *
2763 : * 0. object header
2764 : * 1. long pointer;
2765 : * 2. int position;
2766 : * 3. int length;
2767 : */
2768 : class com_sun_cldchi_jvm_FileDescriptor : public java_lang_Object, private FieldAccess {
2769 : private:
2770 : // Static offsets of the object's instance fields.
2771 : // TODO These offsets need to be checked on VM startup.
2772 : static const off_t offset_pointer = MEMORY_ALIGN(sizeof(java_object_t), sizeof(int64_t));
2773 : static const off_t offset_position = MEMORY_ALIGN(offset_pointer + sizeof(int64_t), sizeof(int32_t));
2774 : static const off_t offset_length = MEMORY_ALIGN(offset_position + sizeof(int32_t), sizeof(int32_t));
2775 :
2776 : public:
2777 : com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h) : java_lang_Object(h) {}
2778 : com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h, int64_t pointer, int32_t position, int32_t length);
2779 : com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h, com_sun_cldchi_jvm_FileDescriptor& fd);
2780 :
2781 : // Getters.
2782 : int64_t get_pointer () const;
2783 : int32_t get_position() const;
2784 : int32_t get_length () const;
2785 :
2786 : // Setters.
2787 : void set_pointer (int64_t value);
2788 : void set_position(int32_t value);
2789 : void set_length (int32_t value);
2790 : };
2791 :
2792 :
2793 : 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)
2794 : {
2795 : set_pointer(pointer);
2796 : set_position(position);
2797 : set_length(length);
2798 : }
2799 :
2800 : 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)
2801 : {
2802 : com_sun_cldchi_jvm_FileDescriptor(h, fd.get_pointer(), fd.get_position(), fd.get_length());
2803 : }
2804 :
2805 :
2806 : inline int64_t com_sun_cldchi_jvm_FileDescriptor::get_pointer() const
2807 : {
2808 : return get<int64_t>(_handle, offset_pointer);
2809 : }
2810 :
2811 : inline int32_t com_sun_cldchi_jvm_FileDescriptor::get_position() const
2812 : {
2813 : return get<int32_t>(_handle, offset_position);
2814 : }
2815 :
2816 : inline int32_t com_sun_cldchi_jvm_FileDescriptor::get_length() const
2817 : {
2818 : return get<int32_t>(_handle, offset_length);
2819 : }
2820 :
2821 :
2822 : inline void com_sun_cldchi_jvm_FileDescriptor::set_pointer(int64_t value)
2823 : {
2824 : set(_handle, offset_pointer, value);
2825 : }
2826 :
2827 : inline void com_sun_cldchi_jvm_FileDescriptor::set_position(int32_t value)
2828 : {
2829 : set(_handle, offset_position, value);
2830 : }
2831 :
2832 : inline void com_sun_cldchi_jvm_FileDescriptor::set_length(int32_t value)
2833 : {
2834 : set(_handle, offset_length, value);
2835 : }
2836 :
2837 :
2838 : /**
2839 : * CLDC 1.1 java/lang/String
2840 : *
2841 : * Object layout:
2842 : *
2843 : * 0. object header
2844 : * 1. char[] value;
2845 : * 2. int offset;
2846 : * 3. int count;
2847 : */
2848 : class java_lang_String : public java_lang_Object, private FieldAccess {
2849 : private:
2850 : // Static offsets of the object's instance fields.
2851 : // TODO These offsets need to be checked on VM startup.
2852 : static const off_t offset_value = MEMORY_ALIGN(sizeof(java_object_t), SIZEOF_VOID_P);
2853 : static const off_t offset_offset = MEMORY_ALIGN(offset_value + SIZEOF_VOID_P, sizeof(int32_t));
2854 : static const off_t offset_count = MEMORY_ALIGN(offset_offset + sizeof(int32_t), sizeof(int32_t));
2855 :
2856 : public:
2857 : java_lang_String(java_handle_t* h) : java_lang_Object(h) {}
2858 : java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset = 0);
2859 :
2860 : // Getters.
2861 : java_handle_chararray_t* get_value () const;
2862 : int32_t get_offset() const;
2863 : int32_t get_count () const;
2864 :
2865 : // Setters.
2866 : void set_value (java_handle_chararray_t* value);
2867 : void set_offset(int32_t value);
2868 : void set_count (int32_t value);
2869 :
2870 : // Raw access
2871 : static inline void set_fields(java_handle_t *str, java_handle_chararray_t* value) {
2872 : set(str, offset_value, value);
2873 : set(str, offset_offset, 0);
2874 : set(str, offset_count, CharArray(value).get_length());
2875 : }
2876 :
2877 : static inline java_handle_chararray_t *get_value(java_handle_t *str) {
2878 : return get<java_handle_chararray_t*>(str, offset_value);
2879 : }
2880 : static inline int32_t get_count(java_handle_t *str) {
2881 : return get<int32_t>(str, offset_count);
2882 : }
2883 : static inline int32_t get_offset(java_handle_t *str) {
2884 : return get<int32_t>(str, offset_offset);
2885 : }
2886 : };
2887 :
2888 : 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)
2889 : {
2890 : set_value(value);
2891 : set_offset(offset);
2892 : set_count(count);
2893 : }
2894 :
2895 : inline java_handle_chararray_t* java_lang_String::get_value() const
2896 : {
2897 : return get<java_handle_chararray_t*>(_handle, offset_value);
2898 : }
2899 :
2900 : inline int32_t java_lang_String::get_offset() const
2901 : {
2902 : return get<int32_t>(_handle, offset_offset);
2903 : }
2904 :
2905 : inline int32_t java_lang_String::get_count() const
2906 : {
2907 : return get<int32_t>(_handle, offset_count);
2908 : }
2909 :
2910 : inline void java_lang_String::set_value(java_handle_chararray_t* value)
2911 : {
2912 : set(_handle, offset_value, value);
2913 : }
2914 :
2915 : inline void java_lang_String::set_offset(int32_t value)
2916 : {
2917 : set(_handle, offset_offset, value);
2918 : }
2919 :
2920 : inline void java_lang_String::set_count(int32_t value)
2921 : {
2922 : set(_handle, offset_count, value);
2923 : }
2924 :
2925 :
2926 : /**
2927 : * CLDC 1.1 java/lang/Thread
2928 : *
2929 : * Object layout:
2930 : *
2931 : * 0. object header
2932 : * 1. int priority;
2933 : * 2. java.lang.Runnable runnable;
2934 : * 3. java.lang.Object vm_thread;
2935 : * 4. int is_terminated;
2936 : * 5. int is_stillborn;
2937 : * 6. char[] name;
2938 : */
2939 : class java_lang_Thread : public java_lang_Object, private FieldAccess {
2940 : private:
2941 : // Static offsets of the object's instance fields.
2942 : // TODO These offsets need to be checked on VM startup.
2943 : static const off_t offset_priority = MEMORY_ALIGN(sizeof(java_object_t), sizeof(int32_t));
2944 : static const off_t offset_runnable = MEMORY_ALIGN(offset_priority + sizeof(int32_t), SIZEOF_VOID_P);
2945 : static const off_t offset_vm_thread = MEMORY_ALIGN(offset_runnable + SIZEOF_VOID_P, SIZEOF_VOID_P);
2946 : static const off_t offset_is_terminated = MEMORY_ALIGN(offset_vm_thread + SIZEOF_VOID_P, sizeof(int32_t));
2947 : static const off_t offset_is_stillborn = MEMORY_ALIGN(offset_is_terminated + sizeof(int32_t), sizeof(int32_t));
2948 : static const off_t offset_name = MEMORY_ALIGN(offset_is_stillborn + sizeof(int32_t), SIZEOF_VOID_P);
2949 :
2950 : public:
2951 : java_lang_Thread(java_handle_t* h) : java_lang_Object(h) {}
2952 : // java_lang_Thread(threadobject* t);
2953 :
2954 : // Getters.
2955 : int32_t get_priority () const;
2956 : threadobject* get_vm_thread() const;
2957 : java_handle_chararray_t* get_name () const;
2958 :
2959 : // Setters.
2960 : void set_vm_thread(threadobject* value);
2961 : };
2962 :
2963 :
2964 : inline int32_t java_lang_Thread::get_priority() const
2965 : {
2966 : return get<int32_t>(_handle, offset_priority);
2967 : }
2968 :
2969 : inline threadobject* java_lang_Thread::get_vm_thread() const
2970 : {
2971 : return get<threadobject*>(_handle, offset_vm_thread);
2972 : }
2973 :
2974 : inline java_handle_chararray_t* java_lang_Thread::get_name() const
2975 : {
2976 : return get<java_handle_chararray_t*>(_handle, offset_name);
2977 : }
2978 :
2979 :
2980 : inline void java_lang_Thread::set_vm_thread(threadobject* value)
2981 : {
2982 : set(_handle, offset_vm_thread, value);
2983 : }
2984 :
2985 :
2986 : /**
2987 : * CLDC 1.1 java/lang/Throwable
2988 : *
2989 : * Object layout:
2990 : *
2991 : * 0. object header
2992 : * 1. java.lang.String detailMessage;
2993 : * 2. java.lang.Object backtrace;
2994 : */
2995 : class java_lang_Throwable : public java_lang_Object, private FieldAccess {
2996 : private:
2997 : // Static offsets of the object's instance fields.
2998 : // TODO These offsets need to be checked on VM startup.
2999 : static const off_t offset_detailMessage = MEMORY_ALIGN(sizeof(java_object_t), SIZEOF_VOID_P);
3000 : static const off_t offset_backtrace = MEMORY_ALIGN(offset_detailMessage + SIZEOF_VOID_P, SIZEOF_VOID_P);
3001 :
3002 : public:
3003 : java_lang_Throwable(java_handle_t* h) : java_lang_Object(h) {}
3004 :
3005 : // Getters.
3006 : java_handle_t* get_detailMessage() const;
3007 : java_handle_bytearray_t* get_backtrace () const;
3008 :
3009 : // Setters.
3010 : void set_backtrace(java_handle_bytearray_t* value);
3011 : };
3012 :
3013 :
3014 : inline java_handle_t* java_lang_Throwable::get_detailMessage() const
3015 : {
3016 : return get<java_handle_t*>(_handle, offset_detailMessage);
3017 : }
3018 :
3019 : inline java_handle_bytearray_t* java_lang_Throwable::get_backtrace() const
3020 : {
3021 : return get<java_handle_bytearray_t*>(_handle, offset_backtrace);
3022 : }
3023 :
3024 :
3025 : inline void java_lang_Throwable::set_backtrace(java_handle_bytearray_t* value)
3026 : {
3027 : set(_handle, offset_backtrace, value);
3028 : }
3029 :
3030 : #endif // WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1
3031 :
3032 : #endif // JAVAOBJECTS_HPP_
3033 :
3034 :
3035 : /*
3036 : * These are local overrides for various environment variables in Emacs.
3037 : * Please do not remove this and leave it at the end of the file, where
3038 : * Emacs will automagically detect them.
3039 : * ---------------------------------------------------------------------
3040 : * Local variables:
3041 : * mode: c++
3042 : * indent-tabs-mode: t
3043 : * c-basic-offset: 4
3044 : * tab-width: 4
3045 : * End:
3046 : * vim:noexpandtab:sw=4:ts=4:
3047 : */
|