1 /*
2 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
24
25 // Interface for manipulating the basic Java classes.
26 //
27 // All dependencies on layout of actual Java classes should be kept here.
28 // If the layout of any of the classes above changes the offsets must be adjusted.
29 //
30 // For most classes we hardwire the offsets for performance reasons. In certain
31 // cases (e.g. java.security.AccessControlContext) we compute the offsets at
32 // startup since the layout here differs between JDK1.2 and JDK1.3.
33 //
34 // Note that fields (static and non-static) are arranged with oops before non-oops
35 // on a per class basis. The offsets below have to reflect this ordering.
36 //
37 // When editing the layouts please update the check_offset verification code
38 // correspondingly. The names in the enums must be identical to the actual field
39 // names in order for the verification code to work.
40
41
42 // Interface to java.lang.String objects
43
44 class java_lang_String : AllStatic {
45 private:
46 enum {
47 hc_value_offset = 0,
48 hc_offset_offset = 1
49 //hc_count_offset = 2 -- not a word-scaled offset
50 //hc_hash_offset = 3 -- not a word-scaled offset
51 };
52
53 static int value_offset;
54 static int offset_offset;
55 static int count_offset;
56 static int hash_offset;
57
58 static Handle basic_create(int length, bool tenured, TRAPS);
59 static Handle basic_create_from_unicode(jchar* unicode, int length, bool tenured, TRAPS);
60
61 static void set_value( oop string, typeArrayOop buffer) { string->obj_field_put(value_offset, (oop)buffer); }
62 static void set_offset(oop string, int offset) { string->int_field_put(offset_offset, offset); }
63 static void set_count( oop string, int count) { string->int_field_put(count_offset, count); }
64
65 public:
66 // Instance creation
67 static Handle create_from_unicode(jchar* unicode, int len, TRAPS);
68 static Handle create_tenured_from_unicode(jchar* unicode, int len, TRAPS);
69 static oop create_oop_from_unicode(jchar* unicode, int len, TRAPS);
70 static Handle create_from_str(const char* utf8_str, TRAPS);
71 static oop create_oop_from_str(const char* utf8_str, TRAPS);
72 static Handle create_from_symbol(symbolHandle symbol, TRAPS);
73 static Handle create_from_platform_dependent_str(const char* str, TRAPS);
74 static Handle char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS);
75
76 static int value_offset_in_bytes() { return value_offset; }
77 static int count_offset_in_bytes() { return count_offset; }
78 static int offset_offset_in_bytes() { return offset_offset; }
79 static int hash_offset_in_bytes() { return hash_offset; }
80
81 // Accessors
82 static typeArrayOop value(oop java_string) {
83 assert(is_instance(java_string), "must be java_string");
84 return (typeArrayOop) java_string->obj_field(value_offset);
85 }
86 static int offset(oop java_string) {
87 assert(is_instance(java_string), "must be java_string");
88 return java_string->int_field(offset_offset);
89 }
90 static int length(oop java_string) {
91 assert(is_instance(java_string), "must be java_string");
92 return java_string->int_field(count_offset);
93 }
94 static int utf8_length(oop java_string);
95
96 // String converters
97 static char* as_utf8_string(oop java_string);
98 static char* as_utf8_string(oop java_string, int start, int len);
99 static char* as_platform_dependent_str(Handle java_string, TRAPS);
100 static jchar* as_unicode_string(oop java_string, int& length);
101
102 static bool equals(oop java_string, jchar* chars, int len);
103
104 // Conversion between '.' and '/' formats
105 static Handle externalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '/', '.', THREAD); }
106 static Handle internalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '.', '/', THREAD); }
107
108 // Conversion
109 static symbolHandle as_symbol(Handle java_string, TRAPS);
110
111 // Testers
112 static bool is_instance(oop obj) {
113 return obj != NULL && obj->klass() == SystemDictionary::string_klass();
114 }
115
116 // Debugging
117 static void print(Handle java_string, outputStream* st);
118 friend class JavaClasses;
119 };
120
121
122 // Interface to java.lang.Class objects
123
124 class java_lang_Class : AllStatic {
125 friend class VMStructs;
126 private:
127 // The fake offsets are added by the class loader when java.lang.Class is loaded
128
129 enum {
130 hc_klass_offset = 0,
131 hc_array_klass_offset = 1,
132 hc_resolved_constructor_offset = 2,
133 hc_number_of_fake_oop_fields = 3
134 };
135
136 static int klass_offset;
137 static int resolved_constructor_offset;
138 static int array_klass_offset;
139 static int number_of_fake_oop_fields;
140
141 static void compute_offsets();
142 static bool offsets_computed;
143 static int classRedefinedCount_offset;
144
145 public:
146 // Instance creation
147 static oop create_mirror(KlassHandle k, TRAPS);
148 static oop create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS);
149 // Conversion
150 static klassOop as_klassOop(oop java_class);
151 // Testing
152 static bool is_instance(oop obj) {
153 return obj != NULL && obj->klass() == SystemDictionary::class_klass();
154 }
155 static bool is_primitive(oop java_class);
156 static BasicType primitive_type(oop java_class);
157 static oop primitive_mirror(BasicType t);
158 // JVM_NewInstance support
159 static methodOop resolved_constructor(oop java_class);
160 static void set_resolved_constructor(oop java_class, methodOop constructor);
161 // JVM_NewArray support
162 static klassOop array_klass(oop java_class);
163 static void set_array_klass(oop java_class, klassOop klass);
164 // compiler support for class operations
165 static int klass_offset_in_bytes() { return klass_offset; }
166 static int resolved_constructor_offset_in_bytes() { return resolved_constructor_offset; }
167 static int array_klass_offset_in_bytes() { return array_klass_offset; }
168 // Support for classRedefinedCount field
169 static int classRedefinedCount(oop the_class_mirror);
170 static void set_classRedefinedCount(oop the_class_mirror, int value);
171 // Debugging
172 friend class JavaClasses;
173 friend class instanceKlass; // verification code accesses offsets
174 friend class ClassFileParser; // access to number_of_fake_fields
175 };
176
177 // Interface to java.lang.Thread objects
178
179 class java_lang_Thread : AllStatic {
180 private:
181 // Note that for this class the layout changed between JDK1.2 and JDK1.3,
182 // so we compute the offsets at startup rather than hard-wiring them.
183 static int _name_offset;
184 static int _group_offset;
185 static int _contextClassLoader_offset;
186 static int _inheritedAccessControlContext_offset;
187 static int _priority_offset;
188 static int _eetop_offset;
189 static int _daemon_offset;
190 static int _stillborn_offset;
191 static int _stackSize_offset;
192 static int _tid_offset;
193 static int _thread_status_offset;
194 static int _park_blocker_offset;
195 static int _park_event_offset ;
196
197 static void compute_offsets();
198
199 public:
200 // Instance creation
201 static oop create();
202 // Returns the JavaThread associated with the thread obj
203 static JavaThread* thread(oop java_thread);
204 // Set JavaThread for instance
205 static void set_thread(oop java_thread, JavaThread* thread);
206 // Name
207 static typeArrayOop name(oop java_thread);
208 static void set_name(oop java_thread, typeArrayOop name);
209 // Priority
210 static ThreadPriority priority(oop java_thread);
211 static void set_priority(oop java_thread, ThreadPriority priority);
212 // Thread group
213 static oop threadGroup(oop java_thread);
214 // Stillborn
215 static bool is_stillborn(oop java_thread);
216 static void set_stillborn(oop java_thread);
217 // Alive (NOTE: this is not really a field, but provides the correct
218 // definition without doing a Java call)
219 static bool is_alive(oop java_thread);
220 // Daemon
221 static bool is_daemon(oop java_thread);
222 static void set_daemon(oop java_thread);
223 // Context ClassLoader
224 static oop context_class_loader(oop java_thread);
225 // Control context
226 static oop inherited_access_control_context(oop java_thread);
227 // Stack size hint
228 static jlong stackSize(oop java_thread);
229 // Thread ID
230 static jlong thread_id(oop java_thread);
231
232 // Blocker object responsible for thread parking
233 static oop park_blocker(oop java_thread);
234
235 // Pointer to type-stable park handler, encoded as jlong.
236 // Should be set when apparently null
237 // For details, see unsafe.cpp Unsafe_Unpark
238 static jlong park_event(oop java_thread);
239 static bool set_park_event(oop java_thread, jlong ptr);
240
241 // Java Thread Status for JVMTI and M&M use.
242 // This thread status info is saved in threadStatus field of
243 // java.lang.Thread java class.
244 enum ThreadStatus {
245 NEW = 0,
246 RUNNABLE = JVMTI_THREAD_STATE_ALIVE + // runnable / running
247 JVMTI_THREAD_STATE_RUNNABLE,
248 SLEEPING = JVMTI_THREAD_STATE_ALIVE + // Thread.sleep()
249 JVMTI_THREAD_STATE_WAITING +
250 JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
251 JVMTI_THREAD_STATE_SLEEPING,
252 IN_OBJECT_WAIT = JVMTI_THREAD_STATE_ALIVE + // Object.wait()
253 JVMTI_THREAD_STATE_WAITING +
254 JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
255 JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
256 IN_OBJECT_WAIT_TIMED = JVMTI_THREAD_STATE_ALIVE + // Object.wait(long)
257 JVMTI_THREAD_STATE_WAITING +
258 JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
259 JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
260 PARKED = JVMTI_THREAD_STATE_ALIVE + // LockSupport.park()
261 JVMTI_THREAD_STATE_WAITING +
262 JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
263 JVMTI_THREAD_STATE_PARKED,
264 PARKED_TIMED = JVMTI_THREAD_STATE_ALIVE + // LockSupport.park(long)
265 JVMTI_THREAD_STATE_WAITING +
266 JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
267 JVMTI_THREAD_STATE_PARKED,
268 BLOCKED_ON_MONITOR_ENTER = JVMTI_THREAD_STATE_ALIVE + // (re-)entering a synchronization block
269 JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER,
270 TERMINATED = JVMTI_THREAD_STATE_TERMINATED
271 };
272 // Write thread status info to threadStatus field of java.lang.Thread.
273 static void set_thread_status(oop java_thread_oop, ThreadStatus status);
274 // Read thread status info from threadStatus field of java.lang.Thread.
275 static ThreadStatus get_thread_status(oop java_thread_oop);
276
277 static const char* thread_status_name(oop java_thread_oop);
278
279 // Debugging
280 friend class JavaClasses;
281 };
282
283 // Interface to java.lang.ThreadGroup objects
284
285 class java_lang_ThreadGroup : AllStatic {
286 private:
287 static int _parent_offset;
288 static int _name_offset;
289 static int _threads_offset;
290 static int _groups_offset;
291 static int _maxPriority_offset;
292 static int _destroyed_offset;
293 static int _daemon_offset;
294 static int _vmAllowSuspension_offset;
295 static int _nthreads_offset;
296 static int _ngroups_offset;
297
298 static void compute_offsets();
299
300 public:
301 // parent ThreadGroup
302 static oop parent(oop java_thread_group);
303 // name
304 static typeArrayOop name(oop java_thread_group);
305 // ("name as oop" accessor is not necessary)
306 // Number of threads in group
307 static int nthreads(oop java_thread_group);
308 // threads
309 static objArrayOop threads(oop java_thread_group);
310 // Number of threads in group
311 static int ngroups(oop java_thread_group);
312 // groups
313 static objArrayOop groups(oop java_thread_group);
314 // maxPriority in group
315 static ThreadPriority maxPriority(oop java_thread_group);
316 // Destroyed
317 static bool is_destroyed(oop java_thread_group);
318 // Daemon
319 static bool is_daemon(oop java_thread_group);
320 // vmAllowSuspension
321 static bool is_vmAllowSuspension(oop java_thread_group);
322 // Debugging
323 friend class JavaClasses;
324 };
325
326
327
328 // Interface to java.lang.Throwable objects
329
330 class java_lang_Throwable: AllStatic {
331 friend class BacktraceBuilder;
332
333 private:
334 // Offsets
335 enum {
336 hc_backtrace_offset = 0,
337 hc_detailMessage_offset = 1,
338 hc_cause_offset = 2, // New since 1.4
339 hc_stackTrace_offset = 3 // New since 1.4
340 };
341 // Trace constants
342 enum {
343 trace_methods_offset = 0,
344 trace_bcis_offset = 1,
345 trace_next_offset = 2,
346 trace_size = 3,
347 trace_chunk_size = 32
348 };
349
350 static int backtrace_offset;
351 static int detailMessage_offset;
352 static int cause_offset;
353 static int stackTrace_offset;
354
355 // Printing
356 static char* print_stack_element_to_buffer(methodOop method, int bci);
357 static void print_to_stream(Handle stream, const char* str);
358 // StackTrace (programmatic access, new since 1.4)
359 static void clear_stacktrace(oop throwable);
360 // No stack trace available
361 static const char* no_stack_trace_message();
362
363 public:
364 // Backtrace
365 static oop backtrace(oop throwable);
366 static void set_backtrace(oop throwable, oop value);
367 // Needed by JVMTI to filter out this internal field.
368 static int get_backtrace_offset() { return backtrace_offset;}
369 static int get_detailMessage_offset() { return detailMessage_offset;}
370 // Message
371 static oop message(oop throwable);
372 static oop message(Handle throwable);
373 static void set_message(oop throwable, oop value);
374 // Print stack trace stored in exception by call-back to Java
375 // Note: this is no longer used in Merlin, but we still suppport
376 // it for compatibility.
377 static void print_stack_trace(oop throwable, oop print_stream);
378 static void print_stack_element(Handle stream, methodOop method, int bci);
379 static void print_stack_element(outputStream *st, methodOop method, int bci);
380 static void print_stack_usage(Handle stream);
381
382 // Allocate space for backtrace (created but stack trace not filled in)
383 static void allocate_backtrace(Handle throwable, TRAPS);
384 // Fill in current stack trace for throwable with preallocated backtrace (no GC)
385 static void fill_in_stack_trace_of_preallocated_backtrace(Handle throwable);
386
387 // Fill in current stack trace, can cause GC
388 static void fill_in_stack_trace(Handle throwable, TRAPS);
389 static void fill_in_stack_trace(Handle throwable);
390 // Programmatic access to stack trace
391 static oop get_stack_trace_element(oop throwable, int index, TRAPS);
392 static int get_stack_trace_depth(oop throwable, TRAPS);
393 // Printing
394 static void print(oop throwable, outputStream* st);
395 static void print(Handle throwable, outputStream* st);
396 static void print_stack_trace(oop throwable, outputStream* st);
397 // Debugging
398 friend class JavaClasses;
399 };
400
401
402 // Interface to java.lang.reflect.AccessibleObject objects
403
404 class java_lang_reflect_AccessibleObject: AllStatic {
405 private:
406 // Note that to reduce dependencies on the JDK we compute these
407 // offsets at run-time.
408 static int override_offset;
409
410 static void compute_offsets();
411
412 public:
413 // Accessors
414 static jboolean override(oop reflect);
415 static void set_override(oop reflect, jboolean value);
416
417 // Debugging
418 friend class JavaClasses;
419 };
420
421
422 // Interface to java.lang.reflect.Method objects
423
424 class java_lang_reflect_Method : public java_lang_reflect_AccessibleObject {
425 private:
426 // Note that to reduce dependencies on the JDK we compute these
427 // offsets at run-time.
428 static int clazz_offset;
429 static int name_offset;
430 static int returnType_offset;
431 static int parameterTypes_offset;
432 static int exceptionTypes_offset;
433 static int slot_offset;
434 static int modifiers_offset;
435 static int signature_offset;
436 static int annotations_offset;
437 static int parameter_annotations_offset;
438 static int annotation_default_offset;
439
440 static void compute_offsets();
441
442 public:
443 // Allocation
444 static Handle create(TRAPS);
445
446 // Accessors
447 static oop clazz(oop reflect);
448 static void set_clazz(oop reflect, oop value);
449
450 static oop name(oop method);
451 static void set_name(oop method, oop value);
452
453 static oop return_type(oop method);
454 static void set_return_type(oop method, oop value);
455
456 static oop parameter_types(oop method);
457 static void set_parameter_types(oop method, oop value);
458
459 static oop exception_types(oop method);
460 static void set_exception_types(oop method, oop value);
461
462 static int slot(oop reflect);
463 static void set_slot(oop reflect, int value);
464
465 static int modifiers(oop method);
466 static void set_modifiers(oop method, int value);
467
468 static bool has_signature_field();
469 static oop signature(oop method);
470 static void set_signature(oop method, oop value);
471
472 static bool has_annotations_field();
473 static oop annotations(oop method);
474 static void set_annotations(oop method, oop value);
475
476 static bool has_parameter_annotations_field();
477 static oop parameter_annotations(oop method);
478 static void set_parameter_annotations(oop method, oop value);
479
480 static bool has_annotation_default_field();
481 static oop annotation_default(oop method);
482 static void set_annotation_default(oop method, oop value);
483
484 // Debugging
485 friend class JavaClasses;
486 };
487
488
489 // Interface to java.lang.reflect.Constructor objects
490
491 class java_lang_reflect_Constructor : public java_lang_reflect_AccessibleObject {
492 private:
493 // Note that to reduce dependencies on the JDK we compute these
494 // offsets at run-time.
495 static int clazz_offset;
496 static int parameterTypes_offset;
497 static int exceptionTypes_offset;
498 static int slot_offset;
499 static int modifiers_offset;
500 static int signature_offset;
501 static int annotations_offset;
502 static int parameter_annotations_offset;
503
504 static void compute_offsets();
505
506 public:
507 // Allocation
508 static Handle create(TRAPS);
509
510 // Accessors
511 static oop clazz(oop reflect);
512 static void set_clazz(oop reflect, oop value);
513
514 static oop parameter_types(oop constructor);
515 static void set_parameter_types(oop constructor, oop value);
516
517 static oop exception_types(oop constructor);
518 static void set_exception_types(oop constructor, oop value);
519
520 static int slot(oop reflect);
521 static void set_slot(oop reflect, int value);
522
523 static int modifiers(oop constructor);
524 static void set_modifiers(oop constructor, int value);
525
526 static bool has_signature_field();
527 static oop signature(oop constructor);
528 static void set_signature(oop constructor, oop value);
529
530 static bool has_annotations_field();
531 static oop annotations(oop constructor);
532 static void set_annotations(oop constructor, oop value);
533
534 static bool has_parameter_annotations_field();
535 static oop parameter_annotations(oop method);
536 static void set_parameter_annotations(oop method, oop value);
537
538 // Debugging
539 friend class JavaClasses;
540 };
541
542
543 // Interface to java.lang.reflect.Field objects
544
545 class java_lang_reflect_Field : public java_lang_reflect_AccessibleObject {
546 private:
547 // Note that to reduce dependencies on the JDK we compute these
548 // offsets at run-time.
549 static int clazz_offset;
550 static int name_offset;
551 static int type_offset;
552 static int slot_offset;
553 static int modifiers_offset;
554 static int signature_offset;
555 static int annotations_offset;
556
557 static void compute_offsets();
558
559 public:
560 // Allocation
561 static Handle create(TRAPS);
562
563 // Accessors
564 static oop clazz(oop reflect);
565 static void set_clazz(oop reflect, oop value);
566
567 static oop name(oop field);
568 static void set_name(oop field, oop value);
569
570 static oop type(oop field);
571 static void set_type(oop field, oop value);
572
573 static int slot(oop reflect);
574 static void set_slot(oop reflect, int value);
575
576 static int modifiers(oop field);
577 static void set_modifiers(oop field, int value);
578
579 static bool has_signature_field();
580 static oop signature(oop constructor);
581 static void set_signature(oop constructor, oop value);
582
583 static bool has_annotations_field();
584 static oop annotations(oop constructor);
585 static void set_annotations(oop constructor, oop value);
586
587 static bool has_parameter_annotations_field();
588 static oop parameter_annotations(oop method);
589 static void set_parameter_annotations(oop method, oop value);
590
591 static bool has_annotation_default_field();
592 static oop annotation_default(oop method);
593 static void set_annotation_default(oop method, oop value);
594
595 // Debugging
596 friend class JavaClasses;
597 };
598
599 // Interface to sun.reflect.ConstantPool objects
600 class sun_reflect_ConstantPool {
601 private:
602 // Note that to reduce dependencies on the JDK we compute these
603 // offsets at run-time.
604 static int _cp_oop_offset;
605
606 static void compute_offsets();
607
608 public:
609 // Allocation
610 static Handle create(TRAPS);
611
612 // Accessors
613 static oop cp_oop(oop reflect);
614 static void set_cp_oop(oop reflect, oop value);
615 static int cp_oop_offset() {
616 return _cp_oop_offset;
617 }
618
619 // Debugging
620 friend class JavaClasses;
621 };
622
623 // Interface to sun.reflect.UnsafeStaticFieldAccessorImpl objects
624 class sun_reflect_UnsafeStaticFieldAccessorImpl {
625 private:
626 static int _base_offset;
627 static void compute_offsets();
628
629 public:
630 static int base_offset() {
631 return _base_offset;
632 }
633
634 // Debugging
635 friend class JavaClasses;
636 };
637
638 // Interface to java.lang primitive type boxing objects:
639 // - java.lang.Boolean
640 // - java.lang.Character
641 // - java.lang.Float
642 // - java.lang.Double
643 // - java.lang.Byte
644 // - java.lang.Short
645 // - java.lang.Integer
646 // - java.lang.Long
647
648 // This could be separated out into 8 individual classes.
649
650 class java_lang_boxing_object: AllStatic {
651 private:
652 enum {
653 hc_value_offset = 0
654 };
655 static int value_offset;
656
657 static oop initialize_and_allocate(BasicType type, TRAPS);
658 public:
659 // Allocation. Returns a boxed value, or NULL for invalid type.
660 static oop create(BasicType type, jvalue* value, TRAPS);
661 // Accessors. Returns the basic type being boxed, or T_ILLEGAL for invalid oop.
662 static BasicType get_value(oop box, jvalue* value);
663 static BasicType set_value(oop box, jvalue* value);
664 static BasicType basic_type(oop box);
665 static bool is_instance(oop box) { return basic_type(box) != T_ILLEGAL; }
666 static bool is_instance(oop box, BasicType type) { return basic_type(box) == type; }
667
668 static int value_offset_in_bytes() { return value_offset; }
669
670 // Debugging
671 friend class JavaClasses;
672 };
673
674
675
676 // Interface to java.lang.ref.Reference objects
677
678 class java_lang_ref_Reference: AllStatic {
679 public:
680 enum {
681 hc_referent_offset = 0,
682 hc_queue_offset = 1,
683 hc_next_offset = 2,
684 hc_discovered_offset = 3 // Is not last, see SoftRefs.
685 };
686 enum {
687 hc_static_lock_offset = 0,
688 hc_static_pending_offset = 1
689 };
690
691 static int referent_offset;
692 static int queue_offset;
693 static int next_offset;
694 static int discovered_offset;
695 static int static_lock_offset;
696 static int static_pending_offset;
697 static int number_of_fake_oop_fields;
698
699 // Accessors
700 static oop referent(oop ref) {
701 return ref->obj_field(referent_offset);
702 }
703 static void set_referent(oop ref, oop value) {
704 ref->obj_field_put(referent_offset, value);
705 }
706 static void set_referent_raw(oop ref, oop value) {
707 ref->obj_field_raw_put(referent_offset, value);
708 }
709 static HeapWord* referent_addr(oop ref) {
710 return ref->obj_field_addr<HeapWord>(referent_offset);
711 }
712 static oop next(oop ref) {
713 return ref->obj_field(next_offset);
714 }
715 static void set_next(oop ref, oop value) {
716 ref->obj_field_put(next_offset, value);
717 }
718 static void set_next_raw(oop ref, oop value) {
719 ref->obj_field_raw_put(next_offset, value);
720 }
721 static HeapWord* next_addr(oop ref) {
722 return ref->obj_field_addr<HeapWord>(next_offset);
723 }
724 static oop discovered(oop ref) {
725 return ref->obj_field(discovered_offset);
726 }
727 static void set_discovered(oop ref, oop value) {
728 ref->obj_field_put(discovered_offset, value);
729 }
730 static void set_discovered_raw(oop ref, oop value) {
731 ref->obj_field_raw_put(discovered_offset, value);
732 }
733 static HeapWord* discovered_addr(oop ref) {
734 return ref->obj_field_addr<HeapWord>(discovered_offset);
735 }
736 // Accessors for statics
737 static oop pending_list_lock();
738 static oop pending_list();
739
740 static HeapWord* pending_list_addr();
741 };
742
743
744 // Interface to java.lang.ref.SoftReference objects
745
746 class java_lang_ref_SoftReference: public java_lang_ref_Reference {
747 public:
748 enum {
749 // The timestamp is a long field and may need to be adjusted for alignment.
750 hc_timestamp_offset = align_object_offset_(hc_discovered_offset + 1)
751 };
752 enum {
753 hc_static_clock_offset = 0
754 };
755
756 static int timestamp_offset;
757 static int static_clock_offset;
758
759 // Accessors
760 static jlong timestamp(oop ref);
761
762 // Accessors for statics
763 static jlong clock();
764 static void set_clock(jlong value);
765 };
766
767
768 // Interface to java.security.AccessControlContext objects
769
770 class java_security_AccessControlContext: AllStatic {
771 private:
772 // Note that for this class the layout changed between JDK1.2 and JDK1.3,
773 // so we compute the offsets at startup rather than hard-wiring them.
774 static int _context_offset;
775 static int _privilegedContext_offset;
776 static int _isPrivileged_offset;
777
778 static void compute_offsets();
779 public:
780 static oop create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS);
781
782 // Debugging/initialization
783 friend class JavaClasses;
784 };
785
786
787 // Interface to java.lang.ClassLoader objects
788
789 class java_lang_ClassLoader : AllStatic {
790 private:
791 enum {
792 hc_parent_offset = 0
793 };
794
795 static int parent_offset;
796
797 public:
798 static oop parent(oop loader);
799
800 static bool is_trusted_loader(oop loader);
801
802 // Fix for 4474172
803 static oop non_reflection_class_loader(oop loader);
804
805 // Debugging
806 friend class JavaClasses;
807 };
808
809
810 // Interface to java.lang.System objects
811
812 class java_lang_System : AllStatic {
813 private:
814 enum {
815 hc_static_in_offset = 0,
816 hc_static_out_offset = 1,
817 hc_static_err_offset = 2
818 };
819
820 static int offset_of_static_fields;
821 static int static_in_offset;
822 static int static_out_offset;
823 static int static_err_offset;
824
825 static void compute_offsets();
826
827 public:
828 static int in_offset_in_bytes();
829 static int out_offset_in_bytes();
830 static int err_offset_in_bytes();
831
832 // Debugging
833 friend class JavaClasses;
834 };
835
836
837 // Interface to java.lang.StackTraceElement objects
838
839 class java_lang_StackTraceElement: AllStatic {
840 private:
841 enum {
842 hc_declaringClass_offset = 0,
843 hc_methodName_offset = 1,
844 hc_fileName_offset = 2,
845 hc_lineNumber_offset = 3
846 };
847
848 static int declaringClass_offset;
849 static int methodName_offset;
850 static int fileName_offset;
851 static int lineNumber_offset;
852
853 public:
854 // Setters
855 static void set_declaringClass(oop element, oop value);
856 static void set_methodName(oop element, oop value);
857 static void set_fileName(oop element, oop value);
858 static void set_lineNumber(oop element, int value);
859
860 // Create an instance of StackTraceElement
861 static oop create(methodHandle m, int bci, TRAPS);
862
863 // Debugging
864 friend class JavaClasses;
865 };
866
867
868 // Interface to java.lang.AssertionStatusDirectives objects
869
870 class java_lang_AssertionStatusDirectives: AllStatic {
871 private:
872 enum {
873 hc_classes_offset,
874 hc_classEnabled_offset,
875 hc_packages_offset,
876 hc_packageEnabled_offset,
877 hc_deflt_offset
878 };
879
880 static int classes_offset;
881 static int classEnabled_offset;
882 static int packages_offset;
883 static int packageEnabled_offset;
884 static int deflt_offset;
885
886 public:
887 // Setters
888 static void set_classes(oop obj, oop val);
889 static void set_classEnabled(oop obj, oop val);
890 static void set_packages(oop obj, oop val);
891 static void set_packageEnabled(oop obj, oop val);
892 static void set_deflt(oop obj, bool val);
893 // Debugging
894 friend class JavaClasses;
895 };
896
897
898 class java_nio_Buffer: AllStatic {
899 private:
900 static int _limit_offset;
901
902 public:
903 static int limit_offset();
904 static void compute_offsets();
905 };
906
907 class sun_misc_AtomicLongCSImpl: AllStatic {
908 private:
909 static int _value_offset;
910
911 public:
912 static int value_offset();
913 static void compute_offsets();
914 };
915
916 class java_util_concurrent_locks_AbstractOwnableSynchronizer : AllStatic {
917 private:
918 static int _owner_offset;
919 public:
920 static void initialize(TRAPS);
921 static oop get_owner_threadObj(oop obj);
922 };
923
924 // Interface to hard-coded offset checking
925
926 class JavaClasses : AllStatic {
927 private:
928 static bool check_offset(const char *klass_name, int offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
929 static bool check_static_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
930 static bool check_constant(const char *klass_name, int constant, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
931 public:
932 static void compute_hard_coded_offsets();
933 static void compute_offsets();
934 static void check_offsets() PRODUCT_RETURN;
935 };