Tue, 22 Mar 2011 13:36:33 -0700
6962931: move interned strings out of the perm gen
Reviewed-by: never, coleenp, ysr, jwilhelm
1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 #ifndef SHARE_VM_CLASSFILE_JAVACLASSES_HPP
26 #define SHARE_VM_CLASSFILE_JAVACLASSES_HPP
28 #include "classfile/systemDictionary.hpp"
29 #include "jvmtifiles/jvmti.h"
30 #include "oops/oop.hpp"
31 #include "runtime/os.hpp"
32 #include "utilities/utf8.hpp"
34 // Interface for manipulating the basic Java classes.
35 //
36 // All dependencies on layout of actual Java classes should be kept here.
37 // If the layout of any of the classes above changes the offsets must be adjusted.
38 //
39 // For most classes we hardwire the offsets for performance reasons. In certain
40 // cases (e.g. java.security.AccessControlContext) we compute the offsets at
41 // startup since the layout here differs between JDK1.2 and JDK1.3.
42 //
43 // Note that fields (static and non-static) are arranged with oops before non-oops
44 // on a per class basis. The offsets below have to reflect this ordering.
45 //
46 // When editing the layouts please update the check_offset verification code
47 // correspondingly. The names in the enums must be identical to the actual field
48 // names in order for the verification code to work.
51 // Interface to java.lang.String objects
53 class java_lang_String : AllStatic {
54 private:
55 enum {
56 hc_value_offset = 0,
57 hc_offset_offset = 1
58 //hc_count_offset = 2 -- not a word-scaled offset
59 //hc_hash_offset = 3 -- not a word-scaled offset
60 };
62 static int value_offset;
63 static int offset_offset;
64 static int count_offset;
65 static int hash_offset;
67 static Handle basic_create(int length, bool tenured, TRAPS);
68 static Handle basic_create_from_unicode(jchar* unicode, int length, bool tenured, TRAPS);
70 static void set_value( oop string, typeArrayOop buffer) { string->obj_field_put(value_offset, (oop)buffer); }
71 static void set_offset(oop string, int offset) { string->int_field_put(offset_offset, offset); }
72 static void set_count( oop string, int count) { string->int_field_put(count_offset, count); }
74 public:
75 // Instance creation
76 static Handle create_from_unicode(jchar* unicode, int len, TRAPS);
77 static Handle create_tenured_from_unicode(jchar* unicode, int len, TRAPS);
78 static oop create_oop_from_unicode(jchar* unicode, int len, TRAPS);
79 static Handle create_from_str(const char* utf8_str, TRAPS);
80 static oop create_oop_from_str(const char* utf8_str, TRAPS);
81 static Handle create_from_symbol(Symbol* symbol, TRAPS);
82 static Handle create_from_platform_dependent_str(const char* str, TRAPS);
83 static Handle char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS);
85 static int value_offset_in_bytes() { return value_offset; }
86 static int count_offset_in_bytes() { return count_offset; }
87 static int offset_offset_in_bytes() { return offset_offset; }
88 static int hash_offset_in_bytes() { return hash_offset; }
90 // Accessors
91 static typeArrayOop value(oop java_string) {
92 assert(is_instance(java_string), "must be java_string");
93 return (typeArrayOop) java_string->obj_field(value_offset);
94 }
95 static int offset(oop java_string) {
96 assert(is_instance(java_string), "must be java_string");
97 return java_string->int_field(offset_offset);
98 }
99 static int length(oop java_string) {
100 assert(is_instance(java_string), "must be java_string");
101 return java_string->int_field(count_offset);
102 }
103 static int utf8_length(oop java_string);
105 // String converters
106 static char* as_utf8_string(oop java_string);
107 static char* as_utf8_string(oop java_string, char* buf, int buflen);
108 static char* as_utf8_string(oop java_string, int start, int len);
109 static char* as_platform_dependent_str(Handle java_string, TRAPS);
110 static jchar* as_unicode_string(oop java_string, int& length);
112 static bool equals(oop java_string, jchar* chars, int len);
114 // Conversion between '.' and '/' formats
115 static Handle externalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '/', '.', THREAD); }
116 static Handle internalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '.', '/', THREAD); }
118 // Conversion
119 static Symbol* as_symbol(Handle java_string, TRAPS);
120 static Symbol* as_symbol_or_null(oop java_string);
122 // Testers
123 static bool is_instance(oop obj) {
124 return obj != NULL && obj->klass() == SystemDictionary::String_klass();
125 }
127 // Debugging
128 static void print(Handle java_string, outputStream* st);
129 friend class JavaClasses;
130 };
133 // Interface to java.lang.Class objects
135 class java_lang_Class : AllStatic {
136 friend class VMStructs;
137 private:
138 // The fake offsets are added by the class loader when java.lang.Class is loaded
140 enum {
141 hc_number_of_fake_oop_fields = 3,
142 hc_number_of_fake_int_fields = 2
143 };
145 static int klass_offset;
146 static int resolved_constructor_offset;
147 static int array_klass_offset;
148 static int number_of_fake_oop_fields;
150 static int oop_size_offset;
151 static int static_oop_field_count_offset;
153 static void compute_offsets();
154 static bool offsets_computed;
155 static int classRedefinedCount_offset;
156 static int parallelCapable_offset;
158 public:
159 // Instance creation
160 static oop create_mirror(KlassHandle k, TRAPS);
161 static void fixup_mirror(KlassHandle k, TRAPS);
162 static oop create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS);
163 // Conversion
164 static klassOop as_klassOop(oop java_class);
165 static BasicType as_BasicType(oop java_class, klassOop* reference_klass = NULL);
166 static BasicType as_BasicType(oop java_class, KlassHandle* reference_klass) {
167 klassOop refk_oop = NULL;
168 BasicType result = as_BasicType(java_class, &refk_oop);
169 (*reference_klass) = KlassHandle(refk_oop);
170 return result;
171 }
172 static Symbol* as_signature(oop java_class, bool intern_if_not_found, TRAPS);
173 static void print_signature(oop java_class, outputStream *st);
174 // Testing
175 static bool is_instance(oop obj) {
176 return obj != NULL && obj->klass() == SystemDictionary::Class_klass();
177 }
178 static bool is_primitive(oop java_class);
179 static BasicType primitive_type(oop java_class);
180 static oop primitive_mirror(BasicType t);
181 // JVM_NewInstance support
182 static methodOop resolved_constructor(oop java_class);
183 static void set_resolved_constructor(oop java_class, methodOop constructor);
184 // JVM_NewArray support
185 static klassOop array_klass(oop java_class);
186 static void set_array_klass(oop java_class, klassOop klass);
187 // compiler support for class operations
188 static int klass_offset_in_bytes() { return klass_offset; }
189 static int resolved_constructor_offset_in_bytes() { return resolved_constructor_offset; }
190 static int array_klass_offset_in_bytes() { return array_klass_offset; }
191 // Support for classRedefinedCount field
192 static int classRedefinedCount(oop the_class_mirror);
193 static void set_classRedefinedCount(oop the_class_mirror, int value);
194 // Support for parallelCapable field
195 static bool parallelCapable(oop the_class_mirror);
197 static int oop_size(oop java_class);
198 static void set_oop_size(oop java_class, int size);
199 static int static_oop_field_count(oop java_class);
200 static void set_static_oop_field_count(oop java_class, int size);
202 // Debugging
203 friend class JavaClasses;
204 friend class instanceKlass; // verification code accesses offsets
205 friend class ClassFileParser; // access to number_of_fake_fields
206 };
208 // Interface to java.lang.Thread objects
210 class java_lang_Thread : AllStatic {
211 private:
212 // Note that for this class the layout changed between JDK1.2 and JDK1.3,
213 // so we compute the offsets at startup rather than hard-wiring them.
214 static int _name_offset;
215 static int _group_offset;
216 static int _contextClassLoader_offset;
217 static int _inheritedAccessControlContext_offset;
218 static int _priority_offset;
219 static int _eetop_offset;
220 static int _daemon_offset;
221 static int _stillborn_offset;
222 static int _stackSize_offset;
223 static int _tid_offset;
224 static int _thread_status_offset;
225 static int _park_blocker_offset;
226 static int _park_event_offset ;
228 static void compute_offsets();
230 public:
231 // Instance creation
232 static oop create();
233 // Returns the JavaThread associated with the thread obj
234 static JavaThread* thread(oop java_thread);
235 // Set JavaThread for instance
236 static void set_thread(oop java_thread, JavaThread* thread);
237 // Name
238 static typeArrayOop name(oop java_thread);
239 static void set_name(oop java_thread, typeArrayOop name);
240 // Priority
241 static ThreadPriority priority(oop java_thread);
242 static void set_priority(oop java_thread, ThreadPriority priority);
243 // Thread group
244 static oop threadGroup(oop java_thread);
245 // Stillborn
246 static bool is_stillborn(oop java_thread);
247 static void set_stillborn(oop java_thread);
248 // Alive (NOTE: this is not really a field, but provides the correct
249 // definition without doing a Java call)
250 static bool is_alive(oop java_thread);
251 // Daemon
252 static bool is_daemon(oop java_thread);
253 static void set_daemon(oop java_thread);
254 // Context ClassLoader
255 static oop context_class_loader(oop java_thread);
256 // Control context
257 static oop inherited_access_control_context(oop java_thread);
258 // Stack size hint
259 static jlong stackSize(oop java_thread);
260 // Thread ID
261 static jlong thread_id(oop java_thread);
263 // Blocker object responsible for thread parking
264 static oop park_blocker(oop java_thread);
266 // Pointer to type-stable park handler, encoded as jlong.
267 // Should be set when apparently null
268 // For details, see unsafe.cpp Unsafe_Unpark
269 static jlong park_event(oop java_thread);
270 static bool set_park_event(oop java_thread, jlong ptr);
272 // Java Thread Status for JVMTI and M&M use.
273 // This thread status info is saved in threadStatus field of
274 // java.lang.Thread java class.
275 enum ThreadStatus {
276 NEW = 0,
277 RUNNABLE = JVMTI_THREAD_STATE_ALIVE + // runnable / running
278 JVMTI_THREAD_STATE_RUNNABLE,
279 SLEEPING = JVMTI_THREAD_STATE_ALIVE + // Thread.sleep()
280 JVMTI_THREAD_STATE_WAITING +
281 JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
282 JVMTI_THREAD_STATE_SLEEPING,
283 IN_OBJECT_WAIT = JVMTI_THREAD_STATE_ALIVE + // Object.wait()
284 JVMTI_THREAD_STATE_WAITING +
285 JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
286 JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
287 IN_OBJECT_WAIT_TIMED = JVMTI_THREAD_STATE_ALIVE + // Object.wait(long)
288 JVMTI_THREAD_STATE_WAITING +
289 JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
290 JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
291 PARKED = JVMTI_THREAD_STATE_ALIVE + // LockSupport.park()
292 JVMTI_THREAD_STATE_WAITING +
293 JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
294 JVMTI_THREAD_STATE_PARKED,
295 PARKED_TIMED = JVMTI_THREAD_STATE_ALIVE + // LockSupport.park(long)
296 JVMTI_THREAD_STATE_WAITING +
297 JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
298 JVMTI_THREAD_STATE_PARKED,
299 BLOCKED_ON_MONITOR_ENTER = JVMTI_THREAD_STATE_ALIVE + // (re-)entering a synchronization block
300 JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER,
301 TERMINATED = JVMTI_THREAD_STATE_TERMINATED
302 };
303 // Write thread status info to threadStatus field of java.lang.Thread.
304 static void set_thread_status(oop java_thread_oop, ThreadStatus status);
305 // Read thread status info from threadStatus field of java.lang.Thread.
306 static ThreadStatus get_thread_status(oop java_thread_oop);
308 static const char* thread_status_name(oop java_thread_oop);
310 // Debugging
311 friend class JavaClasses;
312 };
314 // Interface to java.lang.ThreadGroup objects
316 class java_lang_ThreadGroup : AllStatic {
317 private:
318 static int _parent_offset;
319 static int _name_offset;
320 static int _threads_offset;
321 static int _groups_offset;
322 static int _maxPriority_offset;
323 static int _destroyed_offset;
324 static int _daemon_offset;
325 static int _vmAllowSuspension_offset;
326 static int _nthreads_offset;
327 static int _ngroups_offset;
329 static void compute_offsets();
331 public:
332 // parent ThreadGroup
333 static oop parent(oop java_thread_group);
334 // name
335 static typeArrayOop name(oop java_thread_group);
336 // ("name as oop" accessor is not necessary)
337 // Number of threads in group
338 static int nthreads(oop java_thread_group);
339 // threads
340 static objArrayOop threads(oop java_thread_group);
341 // Number of threads in group
342 static int ngroups(oop java_thread_group);
343 // groups
344 static objArrayOop groups(oop java_thread_group);
345 // maxPriority in group
346 static ThreadPriority maxPriority(oop java_thread_group);
347 // Destroyed
348 static bool is_destroyed(oop java_thread_group);
349 // Daemon
350 static bool is_daemon(oop java_thread_group);
351 // vmAllowSuspension
352 static bool is_vmAllowSuspension(oop java_thread_group);
353 // Debugging
354 friend class JavaClasses;
355 };
359 // Interface to java.lang.Throwable objects
361 class java_lang_Throwable: AllStatic {
362 friend class BacktraceBuilder;
364 private:
365 // Offsets
366 enum {
367 hc_backtrace_offset = 0,
368 hc_detailMessage_offset = 1,
369 hc_cause_offset = 2, // New since 1.4
370 hc_stackTrace_offset = 3 // New since 1.4
371 };
372 // Trace constants
373 enum {
374 trace_methods_offset = 0,
375 trace_bcis_offset = 1,
376 trace_next_offset = 2,
377 trace_size = 3,
378 trace_chunk_size = 32
379 };
381 static int backtrace_offset;
382 static int detailMessage_offset;
383 static int cause_offset;
384 static int stackTrace_offset;
386 // Printing
387 static char* print_stack_element_to_buffer(methodOop method, int bci);
388 static void print_to_stream(Handle stream, const char* str);
389 // StackTrace (programmatic access, new since 1.4)
390 static void clear_stacktrace(oop throwable);
391 // No stack trace available
392 static const char* no_stack_trace_message();
394 public:
395 // Backtrace
396 static oop backtrace(oop throwable);
397 static void set_backtrace(oop throwable, oop value);
398 // Needed by JVMTI to filter out this internal field.
399 static int get_backtrace_offset() { return backtrace_offset;}
400 static int get_detailMessage_offset() { return detailMessage_offset;}
401 // Message
402 static oop message(oop throwable);
403 static oop message(Handle throwable);
404 static void set_message(oop throwable, oop value);
405 // Print stack trace stored in exception by call-back to Java
406 // Note: this is no longer used in Merlin, but we still suppport
407 // it for compatibility.
408 static void print_stack_trace(oop throwable, oop print_stream);
409 static void print_stack_element(Handle stream, methodOop method, int bci);
410 static void print_stack_element(outputStream *st, methodOop method, int bci);
411 static void print_stack_usage(Handle stream);
413 // Allocate space for backtrace (created but stack trace not filled in)
414 static void allocate_backtrace(Handle throwable, TRAPS);
415 // Fill in current stack trace for throwable with preallocated backtrace (no GC)
416 static void fill_in_stack_trace_of_preallocated_backtrace(Handle throwable);
418 // Fill in current stack trace, can cause GC
419 static void fill_in_stack_trace(Handle throwable, TRAPS);
420 static void fill_in_stack_trace(Handle throwable);
421 // Programmatic access to stack trace
422 static oop get_stack_trace_element(oop throwable, int index, TRAPS);
423 static int get_stack_trace_depth(oop throwable, TRAPS);
424 // Printing
425 static void print(oop throwable, outputStream* st);
426 static void print(Handle throwable, outputStream* st);
427 static void print_stack_trace(oop throwable, outputStream* st);
428 // Debugging
429 friend class JavaClasses;
430 };
433 // Interface to java.lang.reflect.AccessibleObject objects
435 class java_lang_reflect_AccessibleObject: AllStatic {
436 private:
437 // Note that to reduce dependencies on the JDK we compute these
438 // offsets at run-time.
439 static int override_offset;
441 static void compute_offsets();
443 public:
444 // Accessors
445 static jboolean override(oop reflect);
446 static void set_override(oop reflect, jboolean value);
448 // Debugging
449 friend class JavaClasses;
450 };
453 // Interface to java.lang.reflect.Method objects
455 class java_lang_reflect_Method : public java_lang_reflect_AccessibleObject {
456 private:
457 // Note that to reduce dependencies on the JDK we compute these
458 // offsets at run-time.
459 static int clazz_offset;
460 static int name_offset;
461 static int returnType_offset;
462 static int parameterTypes_offset;
463 static int exceptionTypes_offset;
464 static int slot_offset;
465 static int modifiers_offset;
466 static int signature_offset;
467 static int annotations_offset;
468 static int parameter_annotations_offset;
469 static int annotation_default_offset;
471 static void compute_offsets();
473 public:
474 // Allocation
475 static Handle create(TRAPS);
477 // Accessors
478 static oop clazz(oop reflect);
479 static void set_clazz(oop reflect, oop value);
481 static oop name(oop method);
482 static void set_name(oop method, oop value);
484 static oop return_type(oop method);
485 static void set_return_type(oop method, oop value);
487 static oop parameter_types(oop method);
488 static void set_parameter_types(oop method, oop value);
490 static oop exception_types(oop method);
491 static void set_exception_types(oop method, oop value);
493 static int slot(oop reflect);
494 static void set_slot(oop reflect, int value);
496 static int modifiers(oop method);
497 static void set_modifiers(oop method, int value);
499 static bool has_signature_field();
500 static oop signature(oop method);
501 static void set_signature(oop method, oop value);
503 static bool has_annotations_field();
504 static oop annotations(oop method);
505 static void set_annotations(oop method, oop value);
507 static bool has_parameter_annotations_field();
508 static oop parameter_annotations(oop method);
509 static void set_parameter_annotations(oop method, oop value);
511 static bool has_annotation_default_field();
512 static oop annotation_default(oop method);
513 static void set_annotation_default(oop method, oop value);
515 // Debugging
516 friend class JavaClasses;
517 };
520 // Interface to java.lang.reflect.Constructor objects
522 class java_lang_reflect_Constructor : public java_lang_reflect_AccessibleObject {
523 private:
524 // Note that to reduce dependencies on the JDK we compute these
525 // offsets at run-time.
526 static int clazz_offset;
527 static int parameterTypes_offset;
528 static int exceptionTypes_offset;
529 static int slot_offset;
530 static int modifiers_offset;
531 static int signature_offset;
532 static int annotations_offset;
533 static int parameter_annotations_offset;
535 static void compute_offsets();
537 public:
538 // Allocation
539 static Handle create(TRAPS);
541 // Accessors
542 static oop clazz(oop reflect);
543 static void set_clazz(oop reflect, oop value);
545 static oop parameter_types(oop constructor);
546 static void set_parameter_types(oop constructor, oop value);
548 static oop exception_types(oop constructor);
549 static void set_exception_types(oop constructor, oop value);
551 static int slot(oop reflect);
552 static void set_slot(oop reflect, int value);
554 static int modifiers(oop constructor);
555 static void set_modifiers(oop constructor, int value);
557 static bool has_signature_field();
558 static oop signature(oop constructor);
559 static void set_signature(oop constructor, oop value);
561 static bool has_annotations_field();
562 static oop annotations(oop constructor);
563 static void set_annotations(oop constructor, oop value);
565 static bool has_parameter_annotations_field();
566 static oop parameter_annotations(oop method);
567 static void set_parameter_annotations(oop method, oop value);
569 // Debugging
570 friend class JavaClasses;
571 };
574 // Interface to java.lang.reflect.Field objects
576 class java_lang_reflect_Field : public java_lang_reflect_AccessibleObject {
577 private:
578 // Note that to reduce dependencies on the JDK we compute these
579 // offsets at run-time.
580 static int clazz_offset;
581 static int name_offset;
582 static int type_offset;
583 static int slot_offset;
584 static int modifiers_offset;
585 static int signature_offset;
586 static int annotations_offset;
588 static void compute_offsets();
590 public:
591 // Allocation
592 static Handle create(TRAPS);
594 // Accessors
595 static oop clazz(oop reflect);
596 static void set_clazz(oop reflect, oop value);
598 static oop name(oop field);
599 static void set_name(oop field, oop value);
601 static oop type(oop field);
602 static void set_type(oop field, oop value);
604 static int slot(oop reflect);
605 static void set_slot(oop reflect, int value);
607 static int modifiers(oop field);
608 static void set_modifiers(oop field, int value);
610 static bool has_signature_field();
611 static oop signature(oop constructor);
612 static void set_signature(oop constructor, oop value);
614 static bool has_annotations_field();
615 static oop annotations(oop constructor);
616 static void set_annotations(oop constructor, oop value);
618 static bool has_parameter_annotations_field();
619 static oop parameter_annotations(oop method);
620 static void set_parameter_annotations(oop method, oop value);
622 static bool has_annotation_default_field();
623 static oop annotation_default(oop method);
624 static void set_annotation_default(oop method, oop value);
626 // Debugging
627 friend class JavaClasses;
628 };
630 // Interface to sun.reflect.ConstantPool objects
631 class sun_reflect_ConstantPool {
632 private:
633 // Note that to reduce dependencies on the JDK we compute these
634 // offsets at run-time.
635 static int _cp_oop_offset;
637 static void compute_offsets();
639 public:
640 // Allocation
641 static Handle create(TRAPS);
643 // Accessors
644 static oop cp_oop(oop reflect);
645 static void set_cp_oop(oop reflect, oop value);
646 static int cp_oop_offset() {
647 return _cp_oop_offset;
648 }
650 // Debugging
651 friend class JavaClasses;
652 };
654 // Interface to sun.reflect.UnsafeStaticFieldAccessorImpl objects
655 class sun_reflect_UnsafeStaticFieldAccessorImpl {
656 private:
657 static int _base_offset;
658 static void compute_offsets();
660 public:
661 static int base_offset() {
662 return _base_offset;
663 }
665 // Debugging
666 friend class JavaClasses;
667 };
669 // Interface to java.lang primitive type boxing objects:
670 // - java.lang.Boolean
671 // - java.lang.Character
672 // - java.lang.Float
673 // - java.lang.Double
674 // - java.lang.Byte
675 // - java.lang.Short
676 // - java.lang.Integer
677 // - java.lang.Long
679 // This could be separated out into 8 individual classes.
681 class java_lang_boxing_object: AllStatic {
682 private:
683 enum {
684 hc_value_offset = 0
685 };
686 static int value_offset;
687 static int long_value_offset;
689 static oop initialize_and_allocate(BasicType type, TRAPS);
690 public:
691 // Allocation. Returns a boxed value, or NULL for invalid type.
692 static oop create(BasicType type, jvalue* value, TRAPS);
693 // Accessors. Returns the basic type being boxed, or T_ILLEGAL for invalid oop.
694 static BasicType get_value(oop box, jvalue* value);
695 static BasicType set_value(oop box, jvalue* value);
696 static BasicType basic_type(oop box);
697 static bool is_instance(oop box) { return basic_type(box) != T_ILLEGAL; }
698 static bool is_instance(oop box, BasicType type) { return basic_type(box) == type; }
699 static void print(oop box, outputStream* st) { jvalue value; print(get_value(box, &value), &value, st); }
700 static void print(BasicType type, jvalue* value, outputStream* st);
702 static int value_offset_in_bytes(BasicType type) {
703 return ( type == T_LONG || type == T_DOUBLE ) ? long_value_offset :
704 value_offset;
705 }
707 // Debugging
708 friend class JavaClasses;
709 };
713 // Interface to java.lang.ref.Reference objects
715 class java_lang_ref_Reference: AllStatic {
716 public:
717 enum {
718 hc_referent_offset = 0,
719 hc_queue_offset = 1,
720 hc_next_offset = 2,
721 hc_discovered_offset = 3 // Is not last, see SoftRefs.
722 };
723 enum {
724 hc_static_lock_offset = 0,
725 hc_static_pending_offset = 1
726 };
728 static int referent_offset;
729 static int queue_offset;
730 static int next_offset;
731 static int discovered_offset;
732 static int static_lock_offset;
733 static int static_pending_offset;
734 static int number_of_fake_oop_fields;
736 // Accessors
737 static oop referent(oop ref) {
738 return ref->obj_field(referent_offset);
739 }
740 static void set_referent(oop ref, oop value) {
741 ref->obj_field_put(referent_offset, value);
742 }
743 static void set_referent_raw(oop ref, oop value) {
744 ref->obj_field_raw_put(referent_offset, value);
745 }
746 static HeapWord* referent_addr(oop ref) {
747 return ref->obj_field_addr<HeapWord>(referent_offset);
748 }
749 static oop next(oop ref) {
750 return ref->obj_field(next_offset);
751 }
752 static void set_next(oop ref, oop value) {
753 ref->obj_field_put(next_offset, value);
754 }
755 static void set_next_raw(oop ref, oop value) {
756 ref->obj_field_raw_put(next_offset, value);
757 }
758 static HeapWord* next_addr(oop ref) {
759 return ref->obj_field_addr<HeapWord>(next_offset);
760 }
761 static oop discovered(oop ref) {
762 return ref->obj_field(discovered_offset);
763 }
764 static void set_discovered(oop ref, oop value) {
765 ref->obj_field_put(discovered_offset, value);
766 }
767 static void set_discovered_raw(oop ref, oop value) {
768 ref->obj_field_raw_put(discovered_offset, value);
769 }
770 static HeapWord* discovered_addr(oop ref) {
771 return ref->obj_field_addr<HeapWord>(discovered_offset);
772 }
773 // Accessors for statics
774 static oop pending_list_lock();
775 static oop pending_list();
777 static HeapWord* pending_list_addr();
778 };
781 // Interface to java.lang.ref.SoftReference objects
783 class java_lang_ref_SoftReference: public java_lang_ref_Reference {
784 public:
785 enum {
786 // The timestamp is a long field and may need to be adjusted for alignment.
787 hc_timestamp_offset = hc_discovered_offset + 1
788 };
789 enum {
790 hc_static_clock_offset = 0
791 };
793 static int timestamp_offset;
794 static int static_clock_offset;
796 // Accessors
797 static jlong timestamp(oop ref);
799 // Accessors for statics
800 static jlong clock();
801 static void set_clock(jlong value);
802 };
805 // Interface to java.lang.invoke.MethodHandle objects
807 class MethodHandleEntry;
809 class java_lang_invoke_MethodHandle: AllStatic {
810 friend class JavaClasses;
812 private:
813 static int _vmentry_offset; // assembly code trampoline for MH
814 static int _vmtarget_offset; // class-specific target reference
815 static int _type_offset; // the MethodType of this MH
816 static int _vmslots_offset; // OPTIONAL hoisted type.form.vmslots
818 static void compute_offsets();
820 public:
821 // Accessors
822 static oop type(oop mh);
823 static void set_type(oop mh, oop mtype);
825 static oop vmtarget(oop mh);
826 static void set_vmtarget(oop mh, oop target);
828 static MethodHandleEntry* vmentry(oop mh);
829 static void set_vmentry(oop mh, MethodHandleEntry* data);
831 static int vmslots(oop mh);
832 static void init_vmslots(oop mh);
833 static int compute_vmslots(oop mh);
835 // Testers
836 static bool is_subclass(klassOop klass) {
837 return Klass::cast(klass)->is_subclass_of(SystemDictionary::MethodHandle_klass());
838 }
839 static bool is_instance(oop obj) {
840 return obj != NULL && is_subclass(obj->klass());
841 }
843 // Accessors for code generation:
844 static int type_offset_in_bytes() { return _type_offset; }
845 static int vmtarget_offset_in_bytes() { return _vmtarget_offset; }
846 static int vmentry_offset_in_bytes() { return _vmentry_offset; }
847 static int vmslots_offset_in_bytes() { return _vmslots_offset; }
848 };
850 class java_lang_invoke_DirectMethodHandle: public java_lang_invoke_MethodHandle {
851 friend class JavaClasses;
853 private:
854 // _vmtarget_offset; // method or class or interface
855 static int _vmindex_offset; // negative or vtable idx or itable idx
856 static void compute_offsets();
858 public:
859 // Accessors
860 static int vmindex(oop mh);
861 static void set_vmindex(oop mh, int index);
863 // Testers
864 static bool is_subclass(klassOop klass) {
865 return Klass::cast(klass)->is_subclass_of(SystemDictionary::DirectMethodHandle_klass());
866 }
867 static bool is_instance(oop obj) {
868 return obj != NULL && is_subclass(obj->klass());
869 }
871 // Accessors for code generation:
872 static int vmindex_offset_in_bytes() { return _vmindex_offset; }
873 };
875 class java_lang_invoke_BoundMethodHandle: public java_lang_invoke_MethodHandle {
876 friend class JavaClasses;
878 private:
879 static int _argument_offset; // argument value bound into this MH
880 static int _vmargslot_offset; // relevant argument slot (<= vmslots)
881 static void compute_offsets();
883 public:
884 static oop argument(oop mh);
885 static void set_argument(oop mh, oop ref);
887 static jint vmargslot(oop mh);
888 static void set_vmargslot(oop mh, jint slot);
890 // Testers
891 static bool is_subclass(klassOop klass) {
892 return Klass::cast(klass)->is_subclass_of(SystemDictionary::BoundMethodHandle_klass());
893 }
894 static bool is_instance(oop obj) {
895 return obj != NULL && is_subclass(obj->klass());
896 }
898 static int argument_offset_in_bytes() { return _argument_offset; }
899 static int vmargslot_offset_in_bytes() { return _vmargslot_offset; }
900 };
902 class java_lang_invoke_AdapterMethodHandle: public java_lang_invoke_BoundMethodHandle {
903 friend class JavaClasses;
905 private:
906 static int _conversion_offset; // type of conversion to apply
907 static void compute_offsets();
909 public:
910 static int conversion(oop mh);
911 static void set_conversion(oop mh, int conv);
913 // Testers
914 static bool is_subclass(klassOop klass) {
915 return Klass::cast(klass)->is_subclass_of(SystemDictionary::AdapterMethodHandle_klass());
916 }
917 static bool is_instance(oop obj) {
918 return obj != NULL && is_subclass(obj->klass());
919 }
921 // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants):
922 enum {
923 OP_RETYPE_ONLY = 0x0, // no argument changes; straight retype
924 OP_RETYPE_RAW = 0x1, // straight retype, trusted (void->int, Object->T)
925 OP_CHECK_CAST = 0x2, // ref-to-ref conversion; requires a Class argument
926 OP_PRIM_TO_PRIM = 0x3, // converts from one primitive to another
927 OP_REF_TO_PRIM = 0x4, // unboxes a wrapper to produce a primitive
928 OP_PRIM_TO_REF = 0x5, // boxes a primitive into a wrapper (NYI)
929 OP_SWAP_ARGS = 0x6, // swap arguments (vminfo is 2nd arg)
930 OP_ROT_ARGS = 0x7, // rotate arguments (vminfo is displaced arg)
931 OP_DUP_ARGS = 0x8, // duplicates one or more arguments (at TOS)
932 OP_DROP_ARGS = 0x9, // remove one or more argument slots
933 OP_COLLECT_ARGS = 0xA, // combine one or more arguments into a varargs (NYI)
934 OP_SPREAD_ARGS = 0xB, // expand in place a varargs array (of known size)
935 OP_FLYBY = 0xC, // operate first on reified argument list (NYI)
936 OP_RICOCHET = 0xD, // run an adapter chain on the return value (NYI)
937 CONV_OP_LIMIT = 0xE, // limit of CONV_OP enumeration
939 CONV_OP_MASK = 0xF00, // this nybble contains the conversion op field
940 CONV_VMINFO_MASK = 0x0FF, // LSB is reserved for JVM use
941 CONV_VMINFO_SHIFT = 0, // position of bits in CONV_VMINFO_MASK
942 CONV_OP_SHIFT = 8, // position of bits in CONV_OP_MASK
943 CONV_DEST_TYPE_SHIFT = 12, // byte 2 has the adapter BasicType (if needed)
944 CONV_SRC_TYPE_SHIFT = 16, // byte 2 has the source BasicType (if needed)
945 CONV_STACK_MOVE_SHIFT = 20, // high 12 bits give signed SP change
946 CONV_STACK_MOVE_MASK = (1 << (32 - CONV_STACK_MOVE_SHIFT)) - 1
947 };
949 static int conversion_offset_in_bytes() { return _conversion_offset; }
950 };
953 // Interface to java.lang.invoke.MemberName objects
954 // (These are a private interface for Java code to query the class hierarchy.)
956 class java_lang_invoke_MemberName: AllStatic {
957 friend class JavaClasses;
959 private:
960 // From java.lang.invoke.MemberName:
961 // private Class<?> clazz; // class in which the method is defined
962 // private String name; // may be null if not yet materialized
963 // private Object type; // may be null if not yet materialized
964 // private int flags; // modifier bits; see reflect.Modifier
965 // private Object vmtarget; // VM-specific target value
966 // private int vmindex; // method index within class or interface
967 static int _clazz_offset;
968 static int _name_offset;
969 static int _type_offset;
970 static int _flags_offset;
971 static int _vmtarget_offset;
972 static int _vmindex_offset;
974 static void compute_offsets();
976 public:
977 // Accessors
978 static oop clazz(oop mname);
979 static void set_clazz(oop mname, oop clazz);
981 static oop type(oop mname);
982 static void set_type(oop mname, oop type);
984 static oop name(oop mname);
985 static void set_name(oop mname, oop name);
987 static int flags(oop mname);
988 static void set_flags(oop mname, int flags);
990 static int modifiers(oop mname) { return (u2) flags(mname); }
991 static void set_modifiers(oop mname, int mods)
992 { set_flags(mname, (flags(mname) &~ (u2)-1) | (u2)mods); }
994 static oop vmtarget(oop mname);
995 static void set_vmtarget(oop mname, oop target);
997 static int vmindex(oop mname);
998 static void set_vmindex(oop mname, int index);
1000 // Testers
1001 static bool is_subclass(klassOop klass) {
1002 return Klass::cast(klass)->is_subclass_of(SystemDictionary::MemberName_klass());
1003 }
1004 static bool is_instance(oop obj) {
1005 return obj != NULL && is_subclass(obj->klass());
1006 }
1008 // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants):
1009 enum {
1010 MN_IS_METHOD = 0x00010000, // method (not constructor)
1011 MN_IS_CONSTRUCTOR = 0x00020000, // constructor
1012 MN_IS_FIELD = 0x00040000, // field
1013 MN_IS_TYPE = 0x00080000, // nested type
1014 MN_SEARCH_SUPERCLASSES = 0x00100000, // for MHN.getMembers
1015 MN_SEARCH_INTERFACES = 0x00200000, // for MHN.getMembers
1016 VM_INDEX_UNINITIALIZED = -99
1017 };
1019 // Accessors for code generation:
1020 static int clazz_offset_in_bytes() { return _clazz_offset; }
1021 static int type_offset_in_bytes() { return _type_offset; }
1022 static int name_offset_in_bytes() { return _name_offset; }
1023 static int flags_offset_in_bytes() { return _flags_offset; }
1024 static int vmtarget_offset_in_bytes() { return _vmtarget_offset; }
1025 static int vmindex_offset_in_bytes() { return _vmindex_offset; }
1026 };
1029 // Interface to java.lang.invoke.MethodType objects
1031 class java_lang_invoke_MethodType: AllStatic {
1032 friend class JavaClasses;
1034 private:
1035 static int _rtype_offset;
1036 static int _ptypes_offset;
1037 static int _form_offset;
1039 static void compute_offsets();
1041 public:
1042 // Accessors
1043 static oop rtype(oop mt);
1044 static objArrayOop ptypes(oop mt);
1045 static oop form(oop mt);
1047 static oop ptype(oop mt, int index);
1048 static int ptype_count(oop mt);
1050 static Symbol* as_signature(oop mt, bool intern_if_not_found, TRAPS);
1051 static void print_signature(oop mt, outputStream* st);
1053 static bool is_instance(oop obj) {
1054 return obj != NULL && obj->klass() == SystemDictionary::MethodType_klass();
1055 }
1057 // Accessors for code generation:
1058 static int rtype_offset_in_bytes() { return _rtype_offset; }
1059 static int ptypes_offset_in_bytes() { return _ptypes_offset; }
1060 static int form_offset_in_bytes() { return _form_offset; }
1061 };
1063 class java_lang_invoke_MethodTypeForm: AllStatic {
1064 friend class JavaClasses;
1066 private:
1067 static int _vmslots_offset; // number of argument slots needed
1068 static int _erasedType_offset; // erasedType = canonical MethodType
1069 static int _genericInvoker_offset; // genericInvoker = adapter for invokeGeneric
1071 static void compute_offsets();
1073 public:
1074 // Accessors
1075 static int vmslots(oop mtform);
1076 static oop erasedType(oop mtform);
1077 static oop genericInvoker(oop mtform);
1079 // Accessors for code generation:
1080 static int vmslots_offset_in_bytes() { return _vmslots_offset; }
1081 static int erasedType_offset_in_bytes() { return _erasedType_offset; }
1082 static int genericInvoker_offset_in_bytes() { return _genericInvoker_offset; }
1083 };
1086 // Interface to java.lang.invoke.CallSite objects
1088 class java_lang_invoke_CallSite: AllStatic {
1089 friend class JavaClasses;
1091 private:
1092 static int _target_offset;
1093 static int _caller_method_offset;
1094 static int _caller_bci_offset;
1096 static void compute_offsets();
1098 public:
1099 // Accessors
1100 static oop target(oop site);
1101 static void set_target(oop site, oop target);
1103 static oop caller_method(oop site);
1104 static void set_caller_method(oop site, oop ref);
1106 static jint caller_bci(oop site);
1107 static void set_caller_bci(oop site, jint bci);
1109 // Testers
1110 static bool is_subclass(klassOop klass) {
1111 return Klass::cast(klass)->is_subclass_of(SystemDictionary::CallSite_klass());
1112 }
1113 static bool is_instance(oop obj) {
1114 return obj != NULL && is_subclass(obj->klass());
1115 }
1117 // Accessors for code generation:
1118 static int target_offset_in_bytes() { return _target_offset; }
1119 static int caller_method_offset_in_bytes() { return _caller_method_offset; }
1120 static int caller_bci_offset_in_bytes() { return _caller_bci_offset; }
1121 };
1124 // Interface to java.security.AccessControlContext objects
1126 class java_security_AccessControlContext: AllStatic {
1127 private:
1128 // Note that for this class the layout changed between JDK1.2 and JDK1.3,
1129 // so we compute the offsets at startup rather than hard-wiring them.
1130 static int _context_offset;
1131 static int _privilegedContext_offset;
1132 static int _isPrivileged_offset;
1134 static void compute_offsets();
1135 public:
1136 static oop create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS);
1138 // Debugging/initialization
1139 friend class JavaClasses;
1140 };
1143 // Interface to java.lang.ClassLoader objects
1145 class java_lang_ClassLoader : AllStatic {
1146 private:
1147 enum {
1148 hc_parent_offset = 0
1149 };
1151 static int parent_offset;
1153 public:
1154 static oop parent(oop loader);
1156 static bool is_trusted_loader(oop loader);
1158 // Fix for 4474172
1159 static oop non_reflection_class_loader(oop loader);
1161 // Debugging
1162 friend class JavaClasses;
1163 };
1166 // Interface to java.lang.System objects
1168 class java_lang_System : AllStatic {
1169 private:
1170 enum {
1171 hc_static_in_offset = 0,
1172 hc_static_out_offset = 1,
1173 hc_static_err_offset = 2
1174 };
1176 static int static_in_offset;
1177 static int static_out_offset;
1178 static int static_err_offset;
1180 public:
1181 static int in_offset_in_bytes();
1182 static int out_offset_in_bytes();
1183 static int err_offset_in_bytes();
1185 // Debugging
1186 friend class JavaClasses;
1187 };
1190 // Interface to java.lang.StackTraceElement objects
1192 class java_lang_StackTraceElement: AllStatic {
1193 private:
1194 enum {
1195 hc_declaringClass_offset = 0,
1196 hc_methodName_offset = 1,
1197 hc_fileName_offset = 2,
1198 hc_lineNumber_offset = 3
1199 };
1201 static int declaringClass_offset;
1202 static int methodName_offset;
1203 static int fileName_offset;
1204 static int lineNumber_offset;
1206 public:
1207 // Setters
1208 static void set_declaringClass(oop element, oop value);
1209 static void set_methodName(oop element, oop value);
1210 static void set_fileName(oop element, oop value);
1211 static void set_lineNumber(oop element, int value);
1213 // Create an instance of StackTraceElement
1214 static oop create(methodHandle m, int bci, TRAPS);
1216 // Debugging
1217 friend class JavaClasses;
1218 };
1221 // Interface to java.lang.AssertionStatusDirectives objects
1223 class java_lang_AssertionStatusDirectives: AllStatic {
1224 private:
1225 enum {
1226 hc_classes_offset,
1227 hc_classEnabled_offset,
1228 hc_packages_offset,
1229 hc_packageEnabled_offset,
1230 hc_deflt_offset
1231 };
1233 static int classes_offset;
1234 static int classEnabled_offset;
1235 static int packages_offset;
1236 static int packageEnabled_offset;
1237 static int deflt_offset;
1239 public:
1240 // Setters
1241 static void set_classes(oop obj, oop val);
1242 static void set_classEnabled(oop obj, oop val);
1243 static void set_packages(oop obj, oop val);
1244 static void set_packageEnabled(oop obj, oop val);
1245 static void set_deflt(oop obj, bool val);
1246 // Debugging
1247 friend class JavaClasses;
1248 };
1251 class java_nio_Buffer: AllStatic {
1252 private:
1253 static int _limit_offset;
1255 public:
1256 static int limit_offset();
1257 static void compute_offsets();
1258 };
1260 class sun_misc_AtomicLongCSImpl: AllStatic {
1261 private:
1262 static int _value_offset;
1264 public:
1265 static int value_offset();
1266 static void compute_offsets();
1267 };
1269 class java_util_concurrent_locks_AbstractOwnableSynchronizer : AllStatic {
1270 private:
1271 static int _owner_offset;
1272 public:
1273 static void initialize(TRAPS);
1274 static oop get_owner_threadObj(oop obj);
1275 };
1277 // Interface to hard-coded offset checking
1279 class JavaClasses : AllStatic {
1280 private:
1281 static bool check_offset(const char *klass_name, int offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1282 static bool check_static_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1283 static bool check_constant(const char *klass_name, int constant, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1284 public:
1285 static void compute_hard_coded_offsets();
1286 static void compute_offsets();
1287 static void check_offsets() PRODUCT_RETURN;
1288 };
1290 #endif // SHARE_VM_CLASSFILE_JAVACLASSES_HPP