Tue, 21 Dec 2010 04:37:30 -0800
7008165: Garbage in ClassFormatError message
Summary: When bootstrap_method_ref in BootstrapMethods attribute points to a wrong CP entry (non-MethodHandle), JVM throws ClassFormatError with a message, where method index and class file name is garbage.
Reviewed-by: iveresov
1 /*
2 * Copyright (c) 1997, 2010, 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(symbolHandle 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 symbolHandle as_symbol(Handle java_string, TRAPS);
120 static symbolOop 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_klass_offset = 0,
142 hc_array_klass_offset = 1,
143 hc_resolved_constructor_offset = 2,
144 hc_number_of_fake_oop_fields = 3
145 };
147 static int klass_offset;
148 static int resolved_constructor_offset;
149 static int array_klass_offset;
150 static int number_of_fake_oop_fields;
152 static void compute_offsets();
153 static bool offsets_computed;
154 static int classRedefinedCount_offset;
155 static int parallelCapable_offset;
157 public:
158 // Instance creation
159 static oop create_mirror(KlassHandle k, TRAPS);
160 static oop create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS);
161 // Conversion
162 static klassOop as_klassOop(oop java_class);
163 static BasicType as_BasicType(oop java_class, klassOop* reference_klass = NULL);
164 static BasicType as_BasicType(oop java_class, KlassHandle* reference_klass) {
165 klassOop refk_oop = NULL;
166 BasicType result = as_BasicType(java_class, &refk_oop);
167 (*reference_klass) = KlassHandle(refk_oop);
168 return result;
169 }
170 static symbolOop as_signature(oop java_class, bool intern_if_not_found, TRAPS);
171 static void print_signature(oop java_class, outputStream *st);
172 // Testing
173 static bool is_instance(oop obj) {
174 return obj != NULL && obj->klass() == SystemDictionary::Class_klass();
175 }
176 static bool is_primitive(oop java_class);
177 static BasicType primitive_type(oop java_class);
178 static oop primitive_mirror(BasicType t);
179 // JVM_NewInstance support
180 static methodOop resolved_constructor(oop java_class);
181 static void set_resolved_constructor(oop java_class, methodOop constructor);
182 // JVM_NewArray support
183 static klassOop array_klass(oop java_class);
184 static void set_array_klass(oop java_class, klassOop klass);
185 // compiler support for class operations
186 static int klass_offset_in_bytes() { return klass_offset; }
187 static int resolved_constructor_offset_in_bytes() { return resolved_constructor_offset; }
188 static int array_klass_offset_in_bytes() { return array_klass_offset; }
189 // Support for classRedefinedCount field
190 static int classRedefinedCount(oop the_class_mirror);
191 static void set_classRedefinedCount(oop the_class_mirror, int value);
192 // Support for parallelCapable field
193 static bool parallelCapable(oop the_class_mirror);
194 // Debugging
195 friend class JavaClasses;
196 friend class instanceKlass; // verification code accesses offsets
197 friend class ClassFileParser; // access to number_of_fake_fields
198 };
200 // Interface to java.lang.Thread objects
202 class java_lang_Thread : AllStatic {
203 private:
204 // Note that for this class the layout changed between JDK1.2 and JDK1.3,
205 // so we compute the offsets at startup rather than hard-wiring them.
206 static int _name_offset;
207 static int _group_offset;
208 static int _contextClassLoader_offset;
209 static int _inheritedAccessControlContext_offset;
210 static int _priority_offset;
211 static int _eetop_offset;
212 static int _daemon_offset;
213 static int _stillborn_offset;
214 static int _stackSize_offset;
215 static int _tid_offset;
216 static int _thread_status_offset;
217 static int _park_blocker_offset;
218 static int _park_event_offset ;
220 static void compute_offsets();
222 public:
223 // Instance creation
224 static oop create();
225 // Returns the JavaThread associated with the thread obj
226 static JavaThread* thread(oop java_thread);
227 // Set JavaThread for instance
228 static void set_thread(oop java_thread, JavaThread* thread);
229 // Name
230 static typeArrayOop name(oop java_thread);
231 static void set_name(oop java_thread, typeArrayOop name);
232 // Priority
233 static ThreadPriority priority(oop java_thread);
234 static void set_priority(oop java_thread, ThreadPriority priority);
235 // Thread group
236 static oop threadGroup(oop java_thread);
237 // Stillborn
238 static bool is_stillborn(oop java_thread);
239 static void set_stillborn(oop java_thread);
240 // Alive (NOTE: this is not really a field, but provides the correct
241 // definition without doing a Java call)
242 static bool is_alive(oop java_thread);
243 // Daemon
244 static bool is_daemon(oop java_thread);
245 static void set_daemon(oop java_thread);
246 // Context ClassLoader
247 static oop context_class_loader(oop java_thread);
248 // Control context
249 static oop inherited_access_control_context(oop java_thread);
250 // Stack size hint
251 static jlong stackSize(oop java_thread);
252 // Thread ID
253 static jlong thread_id(oop java_thread);
255 // Blocker object responsible for thread parking
256 static oop park_blocker(oop java_thread);
258 // Pointer to type-stable park handler, encoded as jlong.
259 // Should be set when apparently null
260 // For details, see unsafe.cpp Unsafe_Unpark
261 static jlong park_event(oop java_thread);
262 static bool set_park_event(oop java_thread, jlong ptr);
264 // Java Thread Status for JVMTI and M&M use.
265 // This thread status info is saved in threadStatus field of
266 // java.lang.Thread java class.
267 enum ThreadStatus {
268 NEW = 0,
269 RUNNABLE = JVMTI_THREAD_STATE_ALIVE + // runnable / running
270 JVMTI_THREAD_STATE_RUNNABLE,
271 SLEEPING = JVMTI_THREAD_STATE_ALIVE + // Thread.sleep()
272 JVMTI_THREAD_STATE_WAITING +
273 JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
274 JVMTI_THREAD_STATE_SLEEPING,
275 IN_OBJECT_WAIT = JVMTI_THREAD_STATE_ALIVE + // Object.wait()
276 JVMTI_THREAD_STATE_WAITING +
277 JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
278 JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
279 IN_OBJECT_WAIT_TIMED = JVMTI_THREAD_STATE_ALIVE + // Object.wait(long)
280 JVMTI_THREAD_STATE_WAITING +
281 JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
282 JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
283 PARKED = JVMTI_THREAD_STATE_ALIVE + // LockSupport.park()
284 JVMTI_THREAD_STATE_WAITING +
285 JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
286 JVMTI_THREAD_STATE_PARKED,
287 PARKED_TIMED = JVMTI_THREAD_STATE_ALIVE + // LockSupport.park(long)
288 JVMTI_THREAD_STATE_WAITING +
289 JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
290 JVMTI_THREAD_STATE_PARKED,
291 BLOCKED_ON_MONITOR_ENTER = JVMTI_THREAD_STATE_ALIVE + // (re-)entering a synchronization block
292 JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER,
293 TERMINATED = JVMTI_THREAD_STATE_TERMINATED
294 };
295 // Write thread status info to threadStatus field of java.lang.Thread.
296 static void set_thread_status(oop java_thread_oop, ThreadStatus status);
297 // Read thread status info from threadStatus field of java.lang.Thread.
298 static ThreadStatus get_thread_status(oop java_thread_oop);
300 static const char* thread_status_name(oop java_thread_oop);
302 // Debugging
303 friend class JavaClasses;
304 };
306 // Interface to java.lang.ThreadGroup objects
308 class java_lang_ThreadGroup : AllStatic {
309 private:
310 static int _parent_offset;
311 static int _name_offset;
312 static int _threads_offset;
313 static int _groups_offset;
314 static int _maxPriority_offset;
315 static int _destroyed_offset;
316 static int _daemon_offset;
317 static int _vmAllowSuspension_offset;
318 static int _nthreads_offset;
319 static int _ngroups_offset;
321 static void compute_offsets();
323 public:
324 // parent ThreadGroup
325 static oop parent(oop java_thread_group);
326 // name
327 static typeArrayOop name(oop java_thread_group);
328 // ("name as oop" accessor is not necessary)
329 // Number of threads in group
330 static int nthreads(oop java_thread_group);
331 // threads
332 static objArrayOop threads(oop java_thread_group);
333 // Number of threads in group
334 static int ngroups(oop java_thread_group);
335 // groups
336 static objArrayOop groups(oop java_thread_group);
337 // maxPriority in group
338 static ThreadPriority maxPriority(oop java_thread_group);
339 // Destroyed
340 static bool is_destroyed(oop java_thread_group);
341 // Daemon
342 static bool is_daemon(oop java_thread_group);
343 // vmAllowSuspension
344 static bool is_vmAllowSuspension(oop java_thread_group);
345 // Debugging
346 friend class JavaClasses;
347 };
351 // Interface to java.lang.Throwable objects
353 class java_lang_Throwable: AllStatic {
354 friend class BacktraceBuilder;
356 private:
357 // Offsets
358 enum {
359 hc_backtrace_offset = 0,
360 hc_detailMessage_offset = 1,
361 hc_cause_offset = 2, // New since 1.4
362 hc_stackTrace_offset = 3 // New since 1.4
363 };
364 // Trace constants
365 enum {
366 trace_methods_offset = 0,
367 trace_bcis_offset = 1,
368 trace_next_offset = 2,
369 trace_size = 3,
370 trace_chunk_size = 32
371 };
373 static int backtrace_offset;
374 static int detailMessage_offset;
375 static int cause_offset;
376 static int stackTrace_offset;
378 // Printing
379 static char* print_stack_element_to_buffer(methodOop method, int bci);
380 static void print_to_stream(Handle stream, const char* str);
381 // StackTrace (programmatic access, new since 1.4)
382 static void clear_stacktrace(oop throwable);
383 // No stack trace available
384 static const char* no_stack_trace_message();
386 public:
387 // Backtrace
388 static oop backtrace(oop throwable);
389 static void set_backtrace(oop throwable, oop value);
390 // Needed by JVMTI to filter out this internal field.
391 static int get_backtrace_offset() { return backtrace_offset;}
392 static int get_detailMessage_offset() { return detailMessage_offset;}
393 // Message
394 static oop message(oop throwable);
395 static oop message(Handle throwable);
396 static void set_message(oop throwable, oop value);
397 // Print stack trace stored in exception by call-back to Java
398 // Note: this is no longer used in Merlin, but we still suppport
399 // it for compatibility.
400 static void print_stack_trace(oop throwable, oop print_stream);
401 static void print_stack_element(Handle stream, methodOop method, int bci);
402 static void print_stack_element(outputStream *st, methodOop method, int bci);
403 static void print_stack_usage(Handle stream);
405 // Allocate space for backtrace (created but stack trace not filled in)
406 static void allocate_backtrace(Handle throwable, TRAPS);
407 // Fill in current stack trace for throwable with preallocated backtrace (no GC)
408 static void fill_in_stack_trace_of_preallocated_backtrace(Handle throwable);
410 // Fill in current stack trace, can cause GC
411 static void fill_in_stack_trace(Handle throwable, TRAPS);
412 static void fill_in_stack_trace(Handle throwable);
413 // Programmatic access to stack trace
414 static oop get_stack_trace_element(oop throwable, int index, TRAPS);
415 static int get_stack_trace_depth(oop throwable, TRAPS);
416 // Printing
417 static void print(oop throwable, outputStream* st);
418 static void print(Handle throwable, outputStream* st);
419 static void print_stack_trace(oop throwable, outputStream* st);
420 // Debugging
421 friend class JavaClasses;
422 };
425 // Interface to java.lang.reflect.AccessibleObject objects
427 class java_lang_reflect_AccessibleObject: AllStatic {
428 private:
429 // Note that to reduce dependencies on the JDK we compute these
430 // offsets at run-time.
431 static int override_offset;
433 static void compute_offsets();
435 public:
436 // Accessors
437 static jboolean override(oop reflect);
438 static void set_override(oop reflect, jboolean value);
440 // Debugging
441 friend class JavaClasses;
442 };
445 // Interface to java.lang.reflect.Method objects
447 class java_lang_reflect_Method : public java_lang_reflect_AccessibleObject {
448 private:
449 // Note that to reduce dependencies on the JDK we compute these
450 // offsets at run-time.
451 static int clazz_offset;
452 static int name_offset;
453 static int returnType_offset;
454 static int parameterTypes_offset;
455 static int exceptionTypes_offset;
456 static int slot_offset;
457 static int modifiers_offset;
458 static int signature_offset;
459 static int annotations_offset;
460 static int parameter_annotations_offset;
461 static int annotation_default_offset;
463 static void compute_offsets();
465 public:
466 // Allocation
467 static Handle create(TRAPS);
469 // Accessors
470 static oop clazz(oop reflect);
471 static void set_clazz(oop reflect, oop value);
473 static oop name(oop method);
474 static void set_name(oop method, oop value);
476 static oop return_type(oop method);
477 static void set_return_type(oop method, oop value);
479 static oop parameter_types(oop method);
480 static void set_parameter_types(oop method, oop value);
482 static oop exception_types(oop method);
483 static void set_exception_types(oop method, oop value);
485 static int slot(oop reflect);
486 static void set_slot(oop reflect, int value);
488 static int modifiers(oop method);
489 static void set_modifiers(oop method, int value);
491 static bool has_signature_field();
492 static oop signature(oop method);
493 static void set_signature(oop method, oop value);
495 static bool has_annotations_field();
496 static oop annotations(oop method);
497 static void set_annotations(oop method, oop value);
499 static bool has_parameter_annotations_field();
500 static oop parameter_annotations(oop method);
501 static void set_parameter_annotations(oop method, oop value);
503 static bool has_annotation_default_field();
504 static oop annotation_default(oop method);
505 static void set_annotation_default(oop method, oop value);
507 // Debugging
508 friend class JavaClasses;
509 };
512 // Interface to java.lang.reflect.Constructor objects
514 class java_lang_reflect_Constructor : public java_lang_reflect_AccessibleObject {
515 private:
516 // Note that to reduce dependencies on the JDK we compute these
517 // offsets at run-time.
518 static int clazz_offset;
519 static int parameterTypes_offset;
520 static int exceptionTypes_offset;
521 static int slot_offset;
522 static int modifiers_offset;
523 static int signature_offset;
524 static int annotations_offset;
525 static int parameter_annotations_offset;
527 static void compute_offsets();
529 public:
530 // Allocation
531 static Handle create(TRAPS);
533 // Accessors
534 static oop clazz(oop reflect);
535 static void set_clazz(oop reflect, oop value);
537 static oop parameter_types(oop constructor);
538 static void set_parameter_types(oop constructor, oop value);
540 static oop exception_types(oop constructor);
541 static void set_exception_types(oop constructor, oop value);
543 static int slot(oop reflect);
544 static void set_slot(oop reflect, int value);
546 static int modifiers(oop constructor);
547 static void set_modifiers(oop constructor, int value);
549 static bool has_signature_field();
550 static oop signature(oop constructor);
551 static void set_signature(oop constructor, oop value);
553 static bool has_annotations_field();
554 static oop annotations(oop constructor);
555 static void set_annotations(oop constructor, oop value);
557 static bool has_parameter_annotations_field();
558 static oop parameter_annotations(oop method);
559 static void set_parameter_annotations(oop method, oop value);
561 // Debugging
562 friend class JavaClasses;
563 };
566 // Interface to java.lang.reflect.Field objects
568 class java_lang_reflect_Field : public java_lang_reflect_AccessibleObject {
569 private:
570 // Note that to reduce dependencies on the JDK we compute these
571 // offsets at run-time.
572 static int clazz_offset;
573 static int name_offset;
574 static int type_offset;
575 static int slot_offset;
576 static int modifiers_offset;
577 static int signature_offset;
578 static int annotations_offset;
580 static void compute_offsets();
582 public:
583 // Allocation
584 static Handle create(TRAPS);
586 // Accessors
587 static oop clazz(oop reflect);
588 static void set_clazz(oop reflect, oop value);
590 static oop name(oop field);
591 static void set_name(oop field, oop value);
593 static oop type(oop field);
594 static void set_type(oop field, oop value);
596 static int slot(oop reflect);
597 static void set_slot(oop reflect, int value);
599 static int modifiers(oop field);
600 static void set_modifiers(oop field, int value);
602 static bool has_signature_field();
603 static oop signature(oop constructor);
604 static void set_signature(oop constructor, oop value);
606 static bool has_annotations_field();
607 static oop annotations(oop constructor);
608 static void set_annotations(oop constructor, oop value);
610 static bool has_parameter_annotations_field();
611 static oop parameter_annotations(oop method);
612 static void set_parameter_annotations(oop method, oop value);
614 static bool has_annotation_default_field();
615 static oop annotation_default(oop method);
616 static void set_annotation_default(oop method, oop value);
618 // Debugging
619 friend class JavaClasses;
620 };
622 // Interface to sun.reflect.ConstantPool objects
623 class sun_reflect_ConstantPool {
624 private:
625 // Note that to reduce dependencies on the JDK we compute these
626 // offsets at run-time.
627 static int _cp_oop_offset;
629 static void compute_offsets();
631 public:
632 // Allocation
633 static Handle create(TRAPS);
635 // Accessors
636 static oop cp_oop(oop reflect);
637 static void set_cp_oop(oop reflect, oop value);
638 static int cp_oop_offset() {
639 return _cp_oop_offset;
640 }
642 // Debugging
643 friend class JavaClasses;
644 };
646 // Interface to sun.reflect.UnsafeStaticFieldAccessorImpl objects
647 class sun_reflect_UnsafeStaticFieldAccessorImpl {
648 private:
649 static int _base_offset;
650 static void compute_offsets();
652 public:
653 static int base_offset() {
654 return _base_offset;
655 }
657 // Debugging
658 friend class JavaClasses;
659 };
661 // Interface to java.lang primitive type boxing objects:
662 // - java.lang.Boolean
663 // - java.lang.Character
664 // - java.lang.Float
665 // - java.lang.Double
666 // - java.lang.Byte
667 // - java.lang.Short
668 // - java.lang.Integer
669 // - java.lang.Long
671 // This could be separated out into 8 individual classes.
673 class java_lang_boxing_object: AllStatic {
674 private:
675 enum {
676 hc_value_offset = 0
677 };
678 static int value_offset;
679 static int long_value_offset;
681 static oop initialize_and_allocate(BasicType type, TRAPS);
682 public:
683 // Allocation. Returns a boxed value, or NULL for invalid type.
684 static oop create(BasicType type, jvalue* value, TRAPS);
685 // Accessors. Returns the basic type being boxed, or T_ILLEGAL for invalid oop.
686 static BasicType get_value(oop box, jvalue* value);
687 static BasicType set_value(oop box, jvalue* value);
688 static BasicType basic_type(oop box);
689 static bool is_instance(oop box) { return basic_type(box) != T_ILLEGAL; }
690 static bool is_instance(oop box, BasicType type) { return basic_type(box) == type; }
691 static void print(oop box, outputStream* st) { jvalue value; print(get_value(box, &value), &value, st); }
692 static void print(BasicType type, jvalue* value, outputStream* st);
694 static int value_offset_in_bytes(BasicType type) {
695 return ( type == T_LONG || type == T_DOUBLE ) ? long_value_offset :
696 value_offset;
697 }
699 // Debugging
700 friend class JavaClasses;
701 };
705 // Interface to java.lang.ref.Reference objects
707 class java_lang_ref_Reference: AllStatic {
708 public:
709 enum {
710 hc_referent_offset = 0,
711 hc_queue_offset = 1,
712 hc_next_offset = 2,
713 hc_discovered_offset = 3 // Is not last, see SoftRefs.
714 };
715 enum {
716 hc_static_lock_offset = 0,
717 hc_static_pending_offset = 1
718 };
720 static int referent_offset;
721 static int queue_offset;
722 static int next_offset;
723 static int discovered_offset;
724 static int static_lock_offset;
725 static int static_pending_offset;
726 static int number_of_fake_oop_fields;
728 // Accessors
729 static oop referent(oop ref) {
730 return ref->obj_field(referent_offset);
731 }
732 static void set_referent(oop ref, oop value) {
733 ref->obj_field_put(referent_offset, value);
734 }
735 static void set_referent_raw(oop ref, oop value) {
736 ref->obj_field_raw_put(referent_offset, value);
737 }
738 static HeapWord* referent_addr(oop ref) {
739 return ref->obj_field_addr<HeapWord>(referent_offset);
740 }
741 static oop next(oop ref) {
742 return ref->obj_field(next_offset);
743 }
744 static void set_next(oop ref, oop value) {
745 ref->obj_field_put(next_offset, value);
746 }
747 static void set_next_raw(oop ref, oop value) {
748 ref->obj_field_raw_put(next_offset, value);
749 }
750 static HeapWord* next_addr(oop ref) {
751 return ref->obj_field_addr<HeapWord>(next_offset);
752 }
753 static oop discovered(oop ref) {
754 return ref->obj_field(discovered_offset);
755 }
756 static void set_discovered(oop ref, oop value) {
757 ref->obj_field_put(discovered_offset, value);
758 }
759 static void set_discovered_raw(oop ref, oop value) {
760 ref->obj_field_raw_put(discovered_offset, value);
761 }
762 static HeapWord* discovered_addr(oop ref) {
763 return ref->obj_field_addr<HeapWord>(discovered_offset);
764 }
765 // Accessors for statics
766 static oop pending_list_lock();
767 static oop pending_list();
769 static HeapWord* pending_list_addr();
770 };
773 // Interface to java.lang.ref.SoftReference objects
775 class java_lang_ref_SoftReference: public java_lang_ref_Reference {
776 public:
777 enum {
778 // The timestamp is a long field and may need to be adjusted for alignment.
779 hc_timestamp_offset = hc_discovered_offset + 1
780 };
781 enum {
782 hc_static_clock_offset = 0
783 };
785 static int timestamp_offset;
786 static int static_clock_offset;
788 // Accessors
789 static jlong timestamp(oop ref);
791 // Accessors for statics
792 static jlong clock();
793 static void set_clock(jlong value);
794 };
797 // Interface to java.dyn.MethodHandle objects
799 class MethodHandleEntry;
801 class java_dyn_MethodHandle: AllStatic {
802 friend class JavaClasses;
804 private:
805 static int _vmentry_offset; // assembly code trampoline for MH
806 static int _vmtarget_offset; // class-specific target reference
807 static int _type_offset; // the MethodType of this MH
808 static int _vmslots_offset; // OPTIONAL hoisted type.form.vmslots
810 static void compute_offsets();
812 public:
813 // Accessors
814 static oop type(oop mh);
815 static void set_type(oop mh, oop mtype);
817 static oop vmtarget(oop mh);
818 static void set_vmtarget(oop mh, oop target);
820 static MethodHandleEntry* vmentry(oop mh);
821 static void set_vmentry(oop mh, MethodHandleEntry* data);
823 static int vmslots(oop mh);
824 static void init_vmslots(oop mh);
825 static int compute_vmslots(oop mh);
827 // Testers
828 static bool is_subclass(klassOop klass) {
829 return Klass::cast(klass)->is_subclass_of(SystemDictionary::MethodHandle_klass());
830 }
831 static bool is_instance(oop obj) {
832 return obj != NULL && is_subclass(obj->klass());
833 }
835 // Accessors for code generation:
836 static int type_offset_in_bytes() { return _type_offset; }
837 static int vmtarget_offset_in_bytes() { return _vmtarget_offset; }
838 static int vmentry_offset_in_bytes() { return _vmentry_offset; }
839 static int vmslots_offset_in_bytes() { return _vmslots_offset; }
840 };
842 class sun_dyn_DirectMethodHandle: public java_dyn_MethodHandle {
843 friend class JavaClasses;
845 private:
846 // _vmtarget_offset; // method or class or interface
847 static int _vmindex_offset; // negative or vtable idx or itable idx
848 static void compute_offsets();
850 public:
851 // Accessors
852 static int vmindex(oop mh);
853 static void set_vmindex(oop mh, int index);
855 // Testers
856 static bool is_subclass(klassOop klass) {
857 return Klass::cast(klass)->is_subclass_of(SystemDictionary::DirectMethodHandle_klass());
858 }
859 static bool is_instance(oop obj) {
860 return obj != NULL && is_subclass(obj->klass());
861 }
863 // Accessors for code generation:
864 static int vmindex_offset_in_bytes() { return _vmindex_offset; }
865 };
867 class sun_dyn_BoundMethodHandle: public java_dyn_MethodHandle {
868 friend class JavaClasses;
870 private:
871 static int _argument_offset; // argument value bound into this MH
872 static int _vmargslot_offset; // relevant argument slot (<= vmslots)
873 static void compute_offsets();
875 public:
876 static oop argument(oop mh);
877 static void set_argument(oop mh, oop ref);
879 static jint vmargslot(oop mh);
880 static void set_vmargslot(oop mh, jint slot);
882 // Testers
883 static bool is_subclass(klassOop klass) {
884 return Klass::cast(klass)->is_subclass_of(SystemDictionary::BoundMethodHandle_klass());
885 }
886 static bool is_instance(oop obj) {
887 return obj != NULL && is_subclass(obj->klass());
888 }
890 static int argument_offset_in_bytes() { return _argument_offset; }
891 static int vmargslot_offset_in_bytes() { return _vmargslot_offset; }
892 };
894 class sun_dyn_AdapterMethodHandle: public sun_dyn_BoundMethodHandle {
895 friend class JavaClasses;
897 private:
898 static int _conversion_offset; // type of conversion to apply
899 static void compute_offsets();
901 public:
902 static int conversion(oop mh);
903 static void set_conversion(oop mh, int conv);
905 // Testers
906 static bool is_subclass(klassOop klass) {
907 return Klass::cast(klass)->is_subclass_of(SystemDictionary::AdapterMethodHandle_klass());
908 }
909 static bool is_instance(oop obj) {
910 return obj != NULL && is_subclass(obj->klass());
911 }
913 // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants):
914 enum {
915 OP_RETYPE_ONLY = 0x0, // no argument changes; straight retype
916 OP_RETYPE_RAW = 0x1, // straight retype, trusted (void->int, Object->T)
917 OP_CHECK_CAST = 0x2, // ref-to-ref conversion; requires a Class argument
918 OP_PRIM_TO_PRIM = 0x3, // converts from one primitive to another
919 OP_REF_TO_PRIM = 0x4, // unboxes a wrapper to produce a primitive
920 OP_PRIM_TO_REF = 0x5, // boxes a primitive into a wrapper (NYI)
921 OP_SWAP_ARGS = 0x6, // swap arguments (vminfo is 2nd arg)
922 OP_ROT_ARGS = 0x7, // rotate arguments (vminfo is displaced arg)
923 OP_DUP_ARGS = 0x8, // duplicates one or more arguments (at TOS)
924 OP_DROP_ARGS = 0x9, // remove one or more argument slots
925 OP_COLLECT_ARGS = 0xA, // combine one or more arguments into a varargs (NYI)
926 OP_SPREAD_ARGS = 0xB, // expand in place a varargs array (of known size)
927 OP_FLYBY = 0xC, // operate first on reified argument list (NYI)
928 OP_RICOCHET = 0xD, // run an adapter chain on the return value (NYI)
929 CONV_OP_LIMIT = 0xE, // limit of CONV_OP enumeration
931 CONV_OP_MASK = 0xF00, // this nybble contains the conversion op field
932 CONV_VMINFO_MASK = 0x0FF, // LSB is reserved for JVM use
933 CONV_VMINFO_SHIFT = 0, // position of bits in CONV_VMINFO_MASK
934 CONV_OP_SHIFT = 8, // position of bits in CONV_OP_MASK
935 CONV_DEST_TYPE_SHIFT = 12, // byte 2 has the adapter BasicType (if needed)
936 CONV_SRC_TYPE_SHIFT = 16, // byte 2 has the source BasicType (if needed)
937 CONV_STACK_MOVE_SHIFT = 20, // high 12 bits give signed SP change
938 CONV_STACK_MOVE_MASK = (1 << (32 - CONV_STACK_MOVE_SHIFT)) - 1
939 };
941 static int conversion_offset_in_bytes() { return _conversion_offset; }
942 };
945 // Interface to sun.dyn.MemberName objects
946 // (These are a private interface for Java code to query the class hierarchy.)
948 class sun_dyn_MemberName: AllStatic {
949 friend class JavaClasses;
951 private:
952 // From java.dyn.MemberName:
953 // private Class<?> clazz; // class in which the method is defined
954 // private String name; // may be null if not yet materialized
955 // private Object type; // may be null if not yet materialized
956 // private int flags; // modifier bits; see reflect.Modifier
957 // private Object vmtarget; // VM-specific target value
958 // private int vmindex; // method index within class or interface
959 static int _clazz_offset;
960 static int _name_offset;
961 static int _type_offset;
962 static int _flags_offset;
963 static int _vmtarget_offset;
964 static int _vmindex_offset;
966 static void compute_offsets();
968 public:
969 // Accessors
970 static oop clazz(oop mname);
971 static void set_clazz(oop mname, oop clazz);
973 static oop type(oop mname);
974 static void set_type(oop mname, oop type);
976 static oop name(oop mname);
977 static void set_name(oop mname, oop name);
979 static int flags(oop mname);
980 static void set_flags(oop mname, int flags);
982 static int modifiers(oop mname) { return (u2) flags(mname); }
983 static void set_modifiers(oop mname, int mods)
984 { set_flags(mname, (flags(mname) &~ (u2)-1) | (u2)mods); }
986 static oop vmtarget(oop mname);
987 static void set_vmtarget(oop mname, oop target);
989 static int vmindex(oop mname);
990 static void set_vmindex(oop mname, int index);
992 // Testers
993 static bool is_subclass(klassOop klass) {
994 return Klass::cast(klass)->is_subclass_of(SystemDictionary::MemberName_klass());
995 }
996 static bool is_instance(oop obj) {
997 return obj != NULL && is_subclass(obj->klass());
998 }
1000 // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants):
1001 enum {
1002 MN_IS_METHOD = 0x00010000, // method (not constructor)
1003 MN_IS_CONSTRUCTOR = 0x00020000, // constructor
1004 MN_IS_FIELD = 0x00040000, // field
1005 MN_IS_TYPE = 0x00080000, // nested type
1006 MN_SEARCH_SUPERCLASSES = 0x00100000, // for MHN.getMembers
1007 MN_SEARCH_INTERFACES = 0x00200000, // for MHN.getMembers
1008 VM_INDEX_UNINITIALIZED = -99
1009 };
1011 // Accessors for code generation:
1012 static int clazz_offset_in_bytes() { return _clazz_offset; }
1013 static int type_offset_in_bytes() { return _type_offset; }
1014 static int name_offset_in_bytes() { return _name_offset; }
1015 static int flags_offset_in_bytes() { return _flags_offset; }
1016 static int vmtarget_offset_in_bytes() { return _vmtarget_offset; }
1017 static int vmindex_offset_in_bytes() { return _vmindex_offset; }
1018 };
1021 // Interface to java.dyn.MethodType objects
1023 class java_dyn_MethodType: AllStatic {
1024 friend class JavaClasses;
1026 private:
1027 static int _rtype_offset;
1028 static int _ptypes_offset;
1029 static int _form_offset;
1031 static void compute_offsets();
1033 public:
1034 // Accessors
1035 static oop rtype(oop mt);
1036 static objArrayOop ptypes(oop mt);
1037 static oop form(oop mt);
1039 static oop ptype(oop mt, int index);
1040 static int ptype_count(oop mt);
1042 static symbolOop as_signature(oop mt, bool intern_if_not_found, TRAPS);
1043 static void print_signature(oop mt, outputStream* st);
1045 static bool is_instance(oop obj) {
1046 return obj != NULL && obj->klass() == SystemDictionary::MethodType_klass();
1047 }
1049 // Accessors for code generation:
1050 static int rtype_offset_in_bytes() { return _rtype_offset; }
1051 static int ptypes_offset_in_bytes() { return _ptypes_offset; }
1052 static int form_offset_in_bytes() { return _form_offset; }
1053 };
1055 class java_dyn_MethodTypeForm: AllStatic {
1056 friend class JavaClasses;
1058 private:
1059 static int _vmslots_offset; // number of argument slots needed
1060 static int _erasedType_offset; // erasedType = canonical MethodType
1061 static int _genericInvoker_offset; // genericInvoker = adapter for invokeGeneric
1063 static void compute_offsets();
1065 public:
1066 // Accessors
1067 static int vmslots(oop mtform);
1068 static oop erasedType(oop mtform);
1069 static oop genericInvoker(oop mtform);
1071 // Accessors for code generation:
1072 static int vmslots_offset_in_bytes() { return _vmslots_offset; }
1073 static int erasedType_offset_in_bytes() { return _erasedType_offset; }
1074 static int genericInvoker_offset_in_bytes() { return _genericInvoker_offset; }
1075 };
1078 // Interface to java.dyn.CallSite objects
1080 class java_dyn_CallSite: AllStatic {
1081 friend class JavaClasses;
1083 private:
1084 static int _target_offset;
1085 static int _caller_method_offset;
1086 static int _caller_bci_offset;
1088 static void compute_offsets();
1090 public:
1091 // Accessors
1092 static oop target(oop site);
1093 static void set_target(oop site, oop target);
1095 static oop caller_method(oop site);
1096 static void set_caller_method(oop site, oop ref);
1098 static jint caller_bci(oop site);
1099 static void set_caller_bci(oop site, jint bci);
1101 // Testers
1102 static bool is_subclass(klassOop klass) {
1103 return Klass::cast(klass)->is_subclass_of(SystemDictionary::CallSite_klass());
1104 }
1105 static bool is_instance(oop obj) {
1106 return obj != NULL && is_subclass(obj->klass());
1107 }
1109 // Accessors for code generation:
1110 static int target_offset_in_bytes() { return _target_offset; }
1111 static int caller_method_offset_in_bytes() { return _caller_method_offset; }
1112 static int caller_bci_offset_in_bytes() { return _caller_bci_offset; }
1113 };
1116 // Interface to java.security.AccessControlContext objects
1118 class java_security_AccessControlContext: AllStatic {
1119 private:
1120 // Note that for this class the layout changed between JDK1.2 and JDK1.3,
1121 // so we compute the offsets at startup rather than hard-wiring them.
1122 static int _context_offset;
1123 static int _privilegedContext_offset;
1124 static int _isPrivileged_offset;
1126 static void compute_offsets();
1127 public:
1128 static oop create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS);
1130 // Debugging/initialization
1131 friend class JavaClasses;
1132 };
1135 // Interface to java.lang.ClassLoader objects
1137 class java_lang_ClassLoader : AllStatic {
1138 private:
1139 enum {
1140 hc_parent_offset = 0
1141 };
1143 static int parent_offset;
1145 public:
1146 static oop parent(oop loader);
1148 static bool is_trusted_loader(oop loader);
1150 // Fix for 4474172
1151 static oop non_reflection_class_loader(oop loader);
1153 // Debugging
1154 friend class JavaClasses;
1155 };
1158 // Interface to java.lang.System objects
1160 class java_lang_System : AllStatic {
1161 private:
1162 enum {
1163 hc_static_in_offset = 0,
1164 hc_static_out_offset = 1,
1165 hc_static_err_offset = 2
1166 };
1168 static int offset_of_static_fields;
1169 static int static_in_offset;
1170 static int static_out_offset;
1171 static int static_err_offset;
1173 static void compute_offsets();
1175 public:
1176 static int in_offset_in_bytes();
1177 static int out_offset_in_bytes();
1178 static int err_offset_in_bytes();
1180 // Debugging
1181 friend class JavaClasses;
1182 };
1185 // Interface to java.lang.StackTraceElement objects
1187 class java_lang_StackTraceElement: AllStatic {
1188 private:
1189 enum {
1190 hc_declaringClass_offset = 0,
1191 hc_methodName_offset = 1,
1192 hc_fileName_offset = 2,
1193 hc_lineNumber_offset = 3
1194 };
1196 static int declaringClass_offset;
1197 static int methodName_offset;
1198 static int fileName_offset;
1199 static int lineNumber_offset;
1201 public:
1202 // Setters
1203 static void set_declaringClass(oop element, oop value);
1204 static void set_methodName(oop element, oop value);
1205 static void set_fileName(oop element, oop value);
1206 static void set_lineNumber(oop element, int value);
1208 // Create an instance of StackTraceElement
1209 static oop create(methodHandle m, int bci, TRAPS);
1211 // Debugging
1212 friend class JavaClasses;
1213 };
1216 // Interface to java.lang.AssertionStatusDirectives objects
1218 class java_lang_AssertionStatusDirectives: AllStatic {
1219 private:
1220 enum {
1221 hc_classes_offset,
1222 hc_classEnabled_offset,
1223 hc_packages_offset,
1224 hc_packageEnabled_offset,
1225 hc_deflt_offset
1226 };
1228 static int classes_offset;
1229 static int classEnabled_offset;
1230 static int packages_offset;
1231 static int packageEnabled_offset;
1232 static int deflt_offset;
1234 public:
1235 // Setters
1236 static void set_classes(oop obj, oop val);
1237 static void set_classEnabled(oop obj, oop val);
1238 static void set_packages(oop obj, oop val);
1239 static void set_packageEnabled(oop obj, oop val);
1240 static void set_deflt(oop obj, bool val);
1241 // Debugging
1242 friend class JavaClasses;
1243 };
1246 class java_nio_Buffer: AllStatic {
1247 private:
1248 static int _limit_offset;
1250 public:
1251 static int limit_offset();
1252 static void compute_offsets();
1253 };
1255 class sun_misc_AtomicLongCSImpl: AllStatic {
1256 private:
1257 static int _value_offset;
1259 public:
1260 static int value_offset();
1261 static void compute_offsets();
1262 };
1264 class java_util_concurrent_locks_AbstractOwnableSynchronizer : AllStatic {
1265 private:
1266 static int _owner_offset;
1267 public:
1268 static void initialize(TRAPS);
1269 static oop get_owner_threadObj(oop obj);
1270 };
1272 // Interface to hard-coded offset checking
1274 class JavaClasses : AllStatic {
1275 private:
1276 static bool check_offset(const char *klass_name, int offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1277 static bool check_static_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1278 static bool check_constant(const char *klass_name, int constant, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1279 public:
1280 static void compute_hard_coded_offsets();
1281 static void compute_offsets();
1282 static void check_offsets() PRODUCT_RETURN;
1283 };
1285 #endif // SHARE_VM_CLASSFILE_JAVACLASSES_HPP