45 #include "logging/logMessage.hpp"
46 #include "logging/logStream.hpp"
47 #include "memory/allocation.inline.hpp"
48 #include "memory/heapInspection.hpp"
49 #include "memory/iterator.inline.hpp"
50 #include "memory/metadataFactory.hpp"
51 #include "memory/metaspaceClosure.hpp"
52 #include "memory/metaspaceShared.hpp"
53 #include "memory/oopFactory.hpp"
54 #include "memory/resourceArea.hpp"
55 #include "oops/fieldStreams.hpp"
56 #include "oops/constantPool.hpp"
57 #include "oops/instanceClassLoaderKlass.hpp"
58 #include "oops/instanceKlass.inline.hpp"
59 #include "oops/instanceMirrorKlass.hpp"
60 #include "oops/instanceOop.hpp"
61 #include "oops/klass.inline.hpp"
62 #include "oops/method.hpp"
63 #include "oops/oop.inline.hpp"
64 #include "oops/symbol.hpp"
65 #include "prims/jvmtiExport.hpp"
66 #include "prims/jvmtiRedefineClasses.hpp"
67 #include "prims/jvmtiThreadState.hpp"
68 #include "prims/methodComparator.hpp"
69 #include "runtime/atomic.hpp"
70 #include "runtime/fieldDescriptor.inline.hpp"
71 #include "runtime/handles.inline.hpp"
72 #include "runtime/javaCalls.hpp"
73 #include "runtime/mutexLocker.hpp"
74 #include "runtime/orderAccess.hpp"
75 #include "runtime/thread.inline.hpp"
76 #include "services/classLoadingService.hpp"
77 #include "services/threadService.hpp"
78 #include "utilities/dtrace.hpp"
79 #include "utilities/events.hpp"
80 #include "utilities/macros.hpp"
81 #include "utilities/stringUtils.hpp"
82 #ifdef COMPILER1
83 #include "c1/c1_Compiler.hpp"
84 #endif
353
354 bool access = (cur_host == k_nest_host);
355
356 if (log_is_enabled(Trace, class, nestmates)) {
357 ResourceMark rm(THREAD);
358 log_trace(class, nestmates)("Class %s does %shave nestmate access to %s",
359 this->external_name(),
360 access ? "" : "NOT ",
361 k->external_name());
362 }
363
364 return access;
365 }
366
367 InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& parser, TRAPS) {
368 const int size = InstanceKlass::size(parser.vtable_size(),
369 parser.itable_size(),
370 nonstatic_oop_map_size(parser.total_oop_map_count()),
371 parser.is_interface(),
372 parser.is_unsafe_anonymous(),
373 should_store_fingerprint(parser.is_unsafe_anonymous()));
374
375 const Symbol* const class_name = parser.class_name();
376 assert(class_name != NULL, "invariant");
377 ClassLoaderData* loader_data = parser.loader_data();
378 assert(loader_data != NULL, "invariant");
379
380 InstanceKlass* ik;
381
382 // Allocation
383 if (REF_NONE == parser.reference_type()) {
384 if (class_name == vmSymbols::java_lang_Class()) {
385 // mirror
386 ik = new (loader_data, size, THREAD) InstanceMirrorKlass(parser);
387 }
388 else if (is_class_loader(class_name, parser)) {
389 // class loader
390 ik = new (loader_data, size, THREAD) InstanceClassLoaderKlass(parser);
391 } else {
392 // normal
393 ik = new (loader_data, size, THREAD) InstanceKlass(parser, InstanceKlass::_misc_kind_other);
394 }
395 } else {
396 // reference
397 ik = new (loader_data, size, THREAD) InstanceRefKlass(parser);
398 }
399
400 // Check for pending exception before adding to the loader data and incrementing
401 // class count. Can get OOM here.
402 if (HAS_PENDING_EXCEPTION) {
403 return NULL;
404 }
405
406 return ik;
407 }
408
409
410 // copy method ordering from resource area to Metaspace
411 void InstanceKlass::copy_method_ordering(const intArray* m, TRAPS) {
412 if (m != NULL) {
413 // allocate a new array and copy contents (memcpy?)
414 _method_ordering = MetadataFactory::new_array<int>(class_loader_data(), m->length(), CHECK);
415 for (int i = 0; i < m->length(); i++) {
416 _method_ordering->at_put(i, m->at(i));
417 }
418 } else {
419 _method_ordering = Universe::the_empty_int_array();
420 }
421 }
422
423 // create a new array of vtable_indices for default methods
424 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
425 Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
426 assert(default_vtable_indices() == NULL, "only create once");
427 set_default_vtable_indices(vtable_indices);
428 return vtable_indices;
429 }
430
431 InstanceKlass::InstanceKlass(const ClassFileParser& parser, unsigned kind, KlassID id) :
432 Klass(id),
433 _nest_members(NULL),
434 _nest_host_index(0),
435 _nest_host(NULL),
436 _static_field_size(parser.static_field_size()),
437 _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
438 _itable_len(parser.itable_size()),
439 _reference_type(parser.reference_type())
440 {
441 set_vtable_length(parser.vtable_size());
442 set_kind(kind);
443 set_access_flags(parser.access_flags());
444 set_is_unsafe_anonymous(parser.is_unsafe_anonymous());
445 set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
446 false));
447
448 assert(NULL == _methods, "underlying memory not zeroed?");
449 assert(is_instance_klass(), "is layout incorrect?");
450 assert(size_helper() == parser.layout_size(), "incorrect size_helper?");
451
452 if (DumpSharedSpaces) {
453 SystemDictionaryShared::init_dumptime_info(this);
454 }
455 }
456
457 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
458 Array<Method*>* methods) {
459 if (methods != NULL && methods != Universe::the_empty_method_array() &&
460 !methods->is_shared()) {
461 for (int i = 0; i < methods->length(); i++) {
462 Method* method = methods->at(i);
463 if (method == NULL) continue; // maybe null if error processing
464 // Only want to delete methods that are not executing for RedefineClasses.
465 // The previous version will point to them so they're not totally dangling
466 assert (!method->on_stack(), "shouldn't be called with methods on stack");
772 vmSymbols::java_lang_IncompatibleClassChangeError(),
773 "class %s has interface %s as super class",
774 external_name(),
775 super_klass->external_name()
776 );
777 return false;
778 }
779
780 InstanceKlass* ik_super = InstanceKlass::cast(super_klass);
781 ik_super->link_class_impl(CHECK_false);
782 }
783
784 // link all interfaces implemented by this class before linking this class
785 Array<InstanceKlass*>* interfaces = local_interfaces();
786 int num_interfaces = interfaces->length();
787 for (int index = 0; index < num_interfaces; index++) {
788 InstanceKlass* interk = interfaces->at(index);
789 interk->link_class_impl(CHECK_false);
790 }
791
792 // in case the class is linked in the process of linking its superclasses
793 if (is_linked()) {
794 return true;
795 }
796
797 // trace only the link time for this klass that includes
798 // the verification time
799 PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(),
800 ClassLoader::perf_class_link_selftime(),
801 ClassLoader::perf_classes_linked(),
802 jt->get_thread_stat()->perf_recursion_counts_addr(),
803 jt->get_thread_stat()->perf_timers_addr(),
804 PerfClassTraceTime::CLASS_LINK);
805
806 // verification & rewriting
807 {
808 HandleMark hm(THREAD);
809 Handle h_init_lock(THREAD, init_lock());
810 ObjectLocker ol(h_init_lock, THREAD, h_init_lock() != NULL);
811 // rewritten will have been set if loader constraint error found
841 // Initialize the vtable and interface table after
842 // methods have been rewritten since rewrite may
843 // fabricate new Method*s.
844 // also does loader constraint checking
845 //
846 // initialize_vtable and initialize_itable need to be rerun for
847 // a shared class if the class is not loaded by the NULL classloader.
848 ClassLoaderData * loader_data = class_loader_data();
849 if (!(is_shared() &&
850 loader_data->is_the_null_class_loader_data())) {
851 vtable().initialize_vtable(true, CHECK_false);
852 itable().initialize_itable(true, CHECK_false);
853 }
854 #ifdef ASSERT
855 else {
856 vtable().verify(tty, true);
857 // In case itable verification is ever added.
858 // itable().verify(tty, true);
859 }
860 #endif
861 set_init_state(linked);
862 if (JvmtiExport::should_post_class_prepare()) {
863 Thread *thread = THREAD;
864 assert(thread->is_Java_thread(), "thread->is_Java_thread()");
865 JvmtiExport::post_class_prepare((JavaThread *) thread, this);
866 }
867 }
868 }
869 return true;
870 }
871
872 // Rewrite the byte codes of all of the methods of a class.
873 // The rewriter must be called exactly once. Rewriting must happen after
874 // verification but before the first method of the class is executed.
875 void InstanceKlass::rewrite_class(TRAPS) {
876 assert(is_loaded(), "must be loaded");
877 if (is_rewritten()) {
878 assert(is_shared(), "rewriting an unshared class?");
879 return;
880 }
994 // having a superinterface that declares, non-static, concrete methods
995 if (!HAS_PENDING_EXCEPTION && has_nonstatic_concrete_methods()) {
996 initialize_super_interfaces(THREAD);
997 }
998
999 // If any exceptions, complete abruptly, throwing the same exception as above.
1000 if (HAS_PENDING_EXCEPTION) {
1001 Handle e(THREAD, PENDING_EXCEPTION);
1002 CLEAR_PENDING_EXCEPTION;
1003 {
1004 EXCEPTION_MARK;
1005 // Locks object, set state, and notify all waiting threads
1006 set_initialization_state_and_notify(initialization_error, THREAD);
1007 CLEAR_PENDING_EXCEPTION;
1008 }
1009 DTRACE_CLASSINIT_PROBE_WAIT(super__failed, -1, wait);
1010 THROW_OOP(e());
1011 }
1012 }
1013
1014
1015 // Look for aot compiled methods for this klass, including class initializer.
1016 AOTLoader::load_for_klass(this, THREAD);
1017
1018 // Step 8
1019 {
1020 DTRACE_CLASSINIT_PROBE_WAIT(clinit, -1, wait);
1021 // Timer includes any side effects of class initialization (resolution,
1022 // etc), but not recursive entry into call_class_initializer().
1023 PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
1024 ClassLoader::perf_class_init_selftime(),
1025 ClassLoader::perf_classes_inited(),
1026 jt->get_thread_stat()->perf_recursion_counts_addr(),
1027 jt->get_thread_stat()->perf_timers_addr(),
1028 PerfClassTraceTime::CLASS_CLINIT);
1029 call_class_initializer(THREAD);
1030 }
1031
1032 // Step 9
1033 if (!HAS_PENDING_EXCEPTION) {
1034 set_initialization_state_and_notify(fully_initialized, CHECK);
1035 {
1036 debug_only(vtable().verify(tty, true);)
1037 }
1038 }
1039 else {
1040 // Step 10 and 11
1041 Handle e(THREAD, PENDING_EXCEPTION);
1042 CLEAR_PENDING_EXCEPTION;
1043 // JVMTI has already reported the pending exception
1044 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1045 JvmtiExport::clear_detected_exception(jt);
1046 {
1047 EXCEPTION_MARK;
1048 set_initialization_state_and_notify(initialization_error, THREAD);
1049 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, class initialization error is thrown below
1050 // JVMTI has already reported the pending exception
1051 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1052 JvmtiExport::clear_detected_exception(jt);
1053 }
1054 DTRACE_CLASSINIT_PROBE_WAIT(error, -1, wait);
1055 if (e->is_a(SystemDictionary::Error_klass())) {
1056 THROW_OOP(e());
1057 } else {
1058 JavaCallArguments args(e);
1059 THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(),
1060 vmSymbols::throwable_void_signature(),
1342 ResourceMark rm;
1343 LogStream ls(lt);
1344 ls.print("%d Initializing ", call_class_initializer_counter++);
1345 name()->print_value_on(&ls);
1346 ls.print_cr("%s (" INTPTR_FORMAT ")", h_method() == NULL ? "(no method)" : "", p2i(this));
1347 }
1348 if (h_method() != NULL) {
1349 JavaCallArguments args; // No arguments
1350 JavaValue result(T_VOID);
1351 JavaCalls::call(&result, h_method, &args, CHECK); // Static call (no args)
1352 }
1353 }
1354
1355
1356 void InstanceKlass::mask_for(const methodHandle& method, int bci,
1357 InterpreterOopMap* entry_for) {
1358 // Lazily create the _oop_map_cache at first request
1359 // Lock-free access requires load_acquire.
1360 OopMapCache* oop_map_cache = OrderAccess::load_acquire(&_oop_map_cache);
1361 if (oop_map_cache == NULL) {
1362 MutexLocker x(OopMapCacheAlloc_lock);
1363 // Check if _oop_map_cache was allocated while we were waiting for this lock
1364 if ((oop_map_cache = _oop_map_cache) == NULL) {
1365 oop_map_cache = new OopMapCache();
1366 // Ensure _oop_map_cache is stable, since it is examined without a lock
1367 OrderAccess::release_store(&_oop_map_cache, oop_map_cache);
1368 }
1369 }
1370 // _oop_map_cache is constant after init; lookup below does its own locking.
1371 oop_map_cache->lookup(method, bci, entry_for);
1372 }
1373
1374
1375 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1376 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1377 Symbol* f_name = fs.name();
1378 Symbol* f_sig = fs.signature();
1379 if (f_name == name && f_sig == sig) {
1380 fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1381 return true;
1382 }
2504
2505 #if INCLUDE_JVMTI
2506 // Deallocate breakpoint records
2507 if (breakpoints() != 0x0) {
2508 methods_do(clear_all_breakpoints);
2509 assert(breakpoints() == 0x0, "should have cleared breakpoints");
2510 }
2511
2512 // deallocate the cached class file
2513 if (_cached_class_file != NULL) {
2514 os::free(_cached_class_file);
2515 _cached_class_file = NULL;
2516 }
2517 #endif
2518
2519 // Decrement symbol reference counts associated with the unloaded class.
2520 if (_name != NULL) _name->decrement_refcount();
2521 // unreference array name derived from this class name (arrays of an unloaded
2522 // class can't be referenced anymore).
2523 if (_array_name != NULL) _array_name->decrement_refcount();
2524 if (_source_debug_extension != NULL) FREE_C_HEAP_ARRAY(char, _source_debug_extension);
2525 }
2526
2527 void InstanceKlass::set_source_debug_extension(const char* array, int length) {
2528 if (array == NULL) {
2529 _source_debug_extension = NULL;
2530 } else {
2531 // Adding one to the attribute length in order to store a null terminator
2532 // character could cause an overflow because the attribute length is
2533 // already coded with an u4 in the classfile, but in practice, it's
2534 // unlikely to happen.
2535 assert((length+1) > length, "Overflow checking");
2536 char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass);
2537 for (int i = 0; i < length; i++) {
2538 sde[i] = array[i];
2539 }
2540 sde[length] = '\0';
2541 _source_debug_extension = sde;
2542 }
2543 }
2544
2545 const char* InstanceKlass::signature_name() const {
2546 int hash_len = 0;
2547 char hash_buf[40];
2548
2549 // If this is an unsafe anonymous class, append a hash to make the name unique
2550 if (is_unsafe_anonymous()) {
2551 intptr_t hash = (java_mirror() != NULL) ? java_mirror()->identity_hash() : 0;
2552 jio_snprintf(hash_buf, sizeof(hash_buf), "/" UINTX_FORMAT, (uintx)hash);
2553 hash_len = (int)strlen(hash_buf);
2554 }
2555
2556 // Get the internal name as a c string
2557 const char* src = (const char*) (name()->as_C_string());
2558 const int src_length = (int)strlen(src);
2559
2560 char* dest = NEW_RESOURCE_ARRAY(char, src_length + hash_len + 3);
2561
2562 // Add L as type indicator
2563 int dest_index = 0;
2564 dest[dest_index++] = 'L';
2565
2566 // Add the actual class name
2567 for (int src_index = 0; src_index < src_length; ) {
2568 dest[dest_index++] = src[src_index++];
2569 }
2570
2571 // If we have a hash, append it
2572 for (int hash_index = 0; hash_index < hash_len; ) {
2573 dest[dest_index++] = hash_buf[hash_index++];
2574 }
2575
2576 // Add the semicolon and the NULL
2577 dest[dest_index++] = ';';
2578 dest[dest_index] = '\0';
2579 return dest;
2580 }
2581
2582 // Used to obtain the package name from a fully qualified class name.
2583 Symbol* InstanceKlass::package_from_name(const Symbol* name, TRAPS) {
2584 if (name == NULL) {
3066 }
3067 osr = osr->osr_link();
3068 }
3069 if (best != NULL && best->comp_level() >= comp_level && match_level == false) {
3070 return best;
3071 }
3072 return NULL;
3073 }
3074
3075 // -----------------------------------------------------------------------------------------------------
3076 // Printing
3077
3078 #ifndef PRODUCT
3079
3080 #define BULLET " - "
3081
3082 static const char* state_names[] = {
3083 "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error"
3084 };
3085
3086 static void print_vtable(intptr_t* start, int len, outputStream* st) {
3087 for (int i = 0; i < len; i++) {
3088 intptr_t e = start[i];
3089 st->print("%d : " INTPTR_FORMAT, i, e);
3090 if (e != 0 && ((Metadata*)e)->is_metaspace_object()) {
3091 st->print(" ");
3092 ((Metadata*)e)->print_value_on(st);
3093 }
3094 st->cr();
3095 }
3096 }
3097
3098 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3099 return print_vtable(reinterpret_cast<intptr_t*>(start), len, st);
3100 }
3101
3102 void InstanceKlass::print_on(outputStream* st) const {
3103 assert(is_klass(), "must be klass");
3104 Klass::print_on(st);
3105
3106 st->print(BULLET"instance size: %d", size_helper()); st->cr();
3107 st->print(BULLET"klass size: %d", size()); st->cr();
3108 st->print(BULLET"access: "); access_flags().print_on(st); st->cr();
3109 st->print(BULLET"state: "); st->print_cr("%s", state_names[_init_state]);
3110 st->print(BULLET"name: "); name()->print_value_on(st); st->cr();
3111 st->print(BULLET"super: "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
3112 st->print(BULLET"sub: ");
3113 Klass* sub = subklass();
3114 int n;
3115 for (n = 0; sub != NULL; n++, sub = sub->next_sibling()) {
3116 if (n < MaxSubklassPrintSize) {
3117 sub->print_value_on(st);
3118 st->print(" ");
3119 }
3120 }
3121 if (n >= MaxSubklassPrintSize) st->print("(" INTX_FORMAT " more klasses...)", n - MaxSubklassPrintSize);
3122 st->cr();
3123
3124 if (is_interface()) {
3125 st->print_cr(BULLET"nof implementors: %d", nof_implementors());
3126 if (nof_implementors() == 1) {
3127 st->print_cr(BULLET"implementor: ");
3128 st->print(" ");
3129 implementor()->print_value_on(st);
3130 st->cr();
3131 }
3132 }
3133
3134 st->print(BULLET"arrays: "); Metadata::print_value_on_maybe_null(st, array_klasses()); st->cr();
3135 st->print(BULLET"methods: "); methods()->print_value_on(st); st->cr();
3136 if (Verbose || WizardMode) {
3137 Array<Method*>* method_array = methods();
3138 for (int i = 0; i < method_array->length(); i++) {
3139 st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
3140 }
3141 }
3142 st->print(BULLET"method ordering: "); method_ordering()->print_value_on(st); st->cr();
3143 st->print(BULLET"default_methods: "); default_methods()->print_value_on(st); st->cr();
3144 if (Verbose && default_methods() != NULL) {
3145 Array<Method*>* method_array = default_methods();
3146 for (int i = 0; i < method_array->length(); i++) {
3147 st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
3148 }
3149 }
3150 if (default_vtable_indices() != NULL) {
3151 st->print(BULLET"default vtable indices: "); default_vtable_indices()->print_value_on(st); st->cr();
3152 }
3153 st->print(BULLET"local interfaces: "); local_interfaces()->print_value_on(st); st->cr();
3154 st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr();
3155 st->print(BULLET"constants: "); constants()->print_value_on(st); st->cr();
3156 if (class_loader_data() != NULL) {
3157 st->print(BULLET"class loader data: ");
3158 class_loader_data()->print_value_on(st);
3159 st->cr();
3160 }
3161 st->print(BULLET"unsafe anonymous host class: "); Metadata::print_value_on_maybe_null(st, unsafe_anonymous_host()); st->cr();
3162 if (source_file_name() != NULL) {
3163 st->print(BULLET"source file: ");
3164 source_file_name()->print_value_on(st);
3165 st->cr();
3166 }
3167 if (source_debug_extension() != NULL) {
3168 st->print(BULLET"source debug extension: ");
3169 st->print("%s", source_debug_extension());
3170 st->cr();
3171 }
3172 st->print(BULLET"class annotations: "); class_annotations()->print_value_on(st); st->cr();
3173 st->print(BULLET"class type annotations: "); class_type_annotations()->print_value_on(st); st->cr();
3174 st->print(BULLET"field annotations: "); fields_annotations()->print_value_on(st); st->cr();
3187 if (have_pv) st->cr();
3188 }
3189
3190 if (generic_signature() != NULL) {
3191 st->print(BULLET"generic signature: ");
3192 generic_signature()->print_value_on(st);
3193 st->cr();
3194 }
3195 st->print(BULLET"inner classes: "); inner_classes()->print_value_on(st); st->cr();
3196 st->print(BULLET"nest members: "); nest_members()->print_value_on(st); st->cr();
3197 if (java_mirror() != NULL) {
3198 st->print(BULLET"java mirror: ");
3199 java_mirror()->print_value_on(st);
3200 st->cr();
3201 } else {
3202 st->print_cr(BULLET"java mirror: NULL");
3203 }
3204 st->print(BULLET"vtable length %d (start addr: " INTPTR_FORMAT ")", vtable_length(), p2i(start_of_vtable())); st->cr();
3205 if (vtable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_vtable(), vtable_length(), st);
3206 st->print(BULLET"itable length %d (start addr: " INTPTR_FORMAT ")", itable_length(), p2i(start_of_itable())); st->cr();
3207 if (itable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_itable(), itable_length(), st);
3208 st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
3209 FieldPrinter print_static_field(st);
3210 ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
3211 st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
3212 FieldPrinter print_nonstatic_field(st);
3213 InstanceKlass* ik = const_cast<InstanceKlass*>(this);
3214 ik->do_nonstatic_fields(&print_nonstatic_field);
3215
3216 st->print(BULLET"non-static oop maps: ");
3217 OopMapBlock* map = start_of_nonstatic_oop_maps();
3218 OopMapBlock* end_map = map + nonstatic_oop_map_count();
3219 while (map < end_map) {
3220 st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1));
3221 map++;
3222 }
3223 st->cr();
3224 }
3225
3226 #endif //PRODUCT
3227
3961 if (holder == NULL) {
3962 return NULL; // The version of klass is gone, no method is found
3963 }
3964 Method* method = holder->method_with_orig_idnum(idnum);
3965 return method;
3966 }
3967
3968 #if INCLUDE_JVMTI
3969 JvmtiCachedClassFileData* InstanceKlass::get_cached_class_file() {
3970 return _cached_class_file;
3971 }
3972
3973 jint InstanceKlass::get_cached_class_file_len() {
3974 return VM_RedefineClasses::get_cached_class_file_len(_cached_class_file);
3975 }
3976
3977 unsigned char * InstanceKlass::get_cached_class_file_bytes() {
3978 return VM_RedefineClasses::get_cached_class_file_bytes(_cached_class_file);
3979 }
3980 #endif
|
45 #include "logging/logMessage.hpp"
46 #include "logging/logStream.hpp"
47 #include "memory/allocation.inline.hpp"
48 #include "memory/heapInspection.hpp"
49 #include "memory/iterator.inline.hpp"
50 #include "memory/metadataFactory.hpp"
51 #include "memory/metaspaceClosure.hpp"
52 #include "memory/metaspaceShared.hpp"
53 #include "memory/oopFactory.hpp"
54 #include "memory/resourceArea.hpp"
55 #include "oops/fieldStreams.hpp"
56 #include "oops/constantPool.hpp"
57 #include "oops/instanceClassLoaderKlass.hpp"
58 #include "oops/instanceKlass.inline.hpp"
59 #include "oops/instanceMirrorKlass.hpp"
60 #include "oops/instanceOop.hpp"
61 #include "oops/klass.inline.hpp"
62 #include "oops/method.hpp"
63 #include "oops/oop.inline.hpp"
64 #include "oops/symbol.hpp"
65 #include "oops/valueKlass.hpp"
66 #include "prims/jvmtiExport.hpp"
67 #include "prims/jvmtiRedefineClasses.hpp"
68 #include "prims/jvmtiThreadState.hpp"
69 #include "prims/methodComparator.hpp"
70 #include "runtime/atomic.hpp"
71 #include "runtime/fieldDescriptor.inline.hpp"
72 #include "runtime/handles.inline.hpp"
73 #include "runtime/javaCalls.hpp"
74 #include "runtime/mutexLocker.hpp"
75 #include "runtime/orderAccess.hpp"
76 #include "runtime/thread.inline.hpp"
77 #include "services/classLoadingService.hpp"
78 #include "services/threadService.hpp"
79 #include "utilities/dtrace.hpp"
80 #include "utilities/events.hpp"
81 #include "utilities/macros.hpp"
82 #include "utilities/stringUtils.hpp"
83 #ifdef COMPILER1
84 #include "c1/c1_Compiler.hpp"
85 #endif
354
355 bool access = (cur_host == k_nest_host);
356
357 if (log_is_enabled(Trace, class, nestmates)) {
358 ResourceMark rm(THREAD);
359 log_trace(class, nestmates)("Class %s does %shave nestmate access to %s",
360 this->external_name(),
361 access ? "" : "NOT ",
362 k->external_name());
363 }
364
365 return access;
366 }
367
368 InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& parser, TRAPS) {
369 const int size = InstanceKlass::size(parser.vtable_size(),
370 parser.itable_size(),
371 nonstatic_oop_map_size(parser.total_oop_map_count()),
372 parser.is_interface(),
373 parser.is_unsafe_anonymous(),
374 should_store_fingerprint(parser.is_unsafe_anonymous()),
375 parser.has_flattenable_fields() ? parser.java_fields_count() : 0,
376 parser.is_value_type());
377
378 const Symbol* const class_name = parser.class_name();
379 assert(class_name != NULL, "invariant");
380 ClassLoaderData* loader_data = parser.loader_data();
381 assert(loader_data != NULL, "invariant");
382
383 InstanceKlass* ik;
384
385 // Allocation
386 if (REF_NONE == parser.reference_type()) {
387 if (class_name == vmSymbols::java_lang_Class()) {
388 // mirror
389 ik = new (loader_data, size, THREAD) InstanceMirrorKlass(parser);
390 } else if (is_class_loader(class_name, parser)) {
391 // class loader
392 ik = new (loader_data, size, THREAD) InstanceClassLoaderKlass(parser);
393 } else if (parser.is_value_type()) {
394 // value type
395 ik = new (loader_data, size, THREAD) ValueKlass(parser);
396 } else {
397 // normal
398 ik = new (loader_data, size, THREAD) InstanceKlass(parser, InstanceKlass::_misc_kind_other);
399 }
400 } else {
401 // reference
402 ik = new (loader_data, size, THREAD) InstanceRefKlass(parser);
403 }
404
405 // Check for pending exception before adding to the loader data and incrementing
406 // class count. Can get OOM here.
407 if (HAS_PENDING_EXCEPTION) {
408 return NULL;
409 }
410
411 #ifdef ASSERT
412 assert(ik->size() == size, "");
413 ik->bounds_check((address) ik->start_of_vtable(), false, size);
414 ik->bounds_check((address) ik->start_of_itable(), false, size);
415 ik->bounds_check((address) ik->end_of_itable(), true, size);
416 ik->bounds_check((address) ik->end_of_nonstatic_oop_maps(), true, size);
417 #endif //ASSERT
418 return ik;
419 }
420
421 #ifndef PRODUCT
422 bool InstanceKlass::bounds_check(address addr, bool edge_ok, intptr_t size_in_bytes) const {
423 const char* bad = NULL;
424 address end = NULL;
425 if (addr < (address)this) {
426 bad = "before";
427 } else if (addr == (address)this) {
428 if (edge_ok) return true;
429 bad = "just before";
430 } else if (addr == (end = (address)this + sizeof(intptr_t) * (size_in_bytes < 0 ? size() : size_in_bytes))) {
431 if (edge_ok) return true;
432 bad = "just after";
433 } else if (addr > end) {
434 bad = "after";
435 } else {
436 return true;
437 }
438 tty->print_cr("%s object bounds: " INTPTR_FORMAT " [" INTPTR_FORMAT ".." INTPTR_FORMAT "]",
439 bad, (intptr_t)addr, (intptr_t)this, (intptr_t)end);
440 Verbose = WizardMode = true; this->print(); //@@
441 return false;
442 }
443 #endif //PRODUCT
444
445 // copy method ordering from resource area to Metaspace
446 void InstanceKlass::copy_method_ordering(const intArray* m, TRAPS) {
447 if (m != NULL) {
448 // allocate a new array and copy contents (memcpy?)
449 _method_ordering = MetadataFactory::new_array<int>(class_loader_data(), m->length(), CHECK);
450 for (int i = 0; i < m->length(); i++) {
451 _method_ordering->at_put(i, m->at(i));
452 }
453 } else {
454 _method_ordering = Universe::the_empty_int_array();
455 }
456 }
457
458 // create a new array of vtable_indices for default methods
459 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
460 Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
461 assert(default_vtable_indices() == NULL, "only create once");
462 set_default_vtable_indices(vtable_indices);
463 return vtable_indices;
464 }
465
466 InstanceKlass::InstanceKlass(const ClassFileParser& parser, unsigned kind, KlassID id) :
467 Klass(id),
468 _nest_members(NULL),
469 _nest_host_index(0),
470 _nest_host(NULL),
471 _static_field_size(parser.static_field_size()),
472 _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
473 _itable_len(parser.itable_size()),
474 _extra_flags(0),
475 _reference_type(parser.reference_type()),
476 _adr_valueklass_fixed_block(NULL) {
477 set_vtable_length(parser.vtable_size());
478 set_kind(kind);
479 set_access_flags(parser.access_flags());
480 set_is_unsafe_anonymous(parser.is_unsafe_anonymous());
481 set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
482 false));
483 if (parser.has_flattenable_fields()) {
484 set_has_value_fields();
485 }
486 _java_fields_count = parser.java_fields_count();
487
488 assert(NULL == _methods, "underlying memory not zeroed?");
489 assert(is_instance_klass(), "is layout incorrect?");
490 assert(size_helper() == parser.layout_size(), "incorrect size_helper?");
491
492 if (DumpSharedSpaces) {
493 SystemDictionaryShared::init_dumptime_info(this);
494 }
495 }
496
497 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
498 Array<Method*>* methods) {
499 if (methods != NULL && methods != Universe::the_empty_method_array() &&
500 !methods->is_shared()) {
501 for (int i = 0; i < methods->length(); i++) {
502 Method* method = methods->at(i);
503 if (method == NULL) continue; // maybe null if error processing
504 // Only want to delete methods that are not executing for RedefineClasses.
505 // The previous version will point to them so they're not totally dangling
506 assert (!method->on_stack(), "shouldn't be called with methods on stack");
812 vmSymbols::java_lang_IncompatibleClassChangeError(),
813 "class %s has interface %s as super class",
814 external_name(),
815 super_klass->external_name()
816 );
817 return false;
818 }
819
820 InstanceKlass* ik_super = InstanceKlass::cast(super_klass);
821 ik_super->link_class_impl(CHECK_false);
822 }
823
824 // link all interfaces implemented by this class before linking this class
825 Array<InstanceKlass*>* interfaces = local_interfaces();
826 int num_interfaces = interfaces->length();
827 for (int index = 0; index < num_interfaces; index++) {
828 InstanceKlass* interk = interfaces->at(index);
829 interk->link_class_impl(CHECK_false);
830 }
831
832
833 // If a class declares a method that uses a value class as an argument
834 // type or return value type, this value class must be loaded during the
835 // linking of this class because size and properties of the value class
836 // must be known in order to be able to perform value type optimizations.
837 // The implementation below is an approximation of this rule, the code
838 // iterates over all methods of the current class (including overridden
839 // methods), not only the methods declared by this class. This
840 // approximation makes the code simpler, and doesn't change the semantic
841 // because classes declaring methods overridden by the current class are
842 // linked (and have performed their own pre-loading) before the linking
843 // of the current class.
844 // This is also the moment to detect potential mismatch between the
845 // ValueTypes attribute and the kind of the class effectively loaded.
846
847
848 // Note:
849 // Value class types used for flattenable fields are loaded during
850 // the loading phase (see ClassFileParser::post_process_parsed_stream()).
851 // Value class types used as element types for array creation
852 // are not pre-loaded. Their loading is triggered by either anewarray
853 // or multianewarray bytecodes.
854
855 // Could it be possible to do the following processing only if the
856 // class uses value types?
857 {
858 ResourceMark rm(THREAD);
859 for (int i = 0; i < methods()->length(); i++) {
860 Method* m = methods()->at(i);
861 for (SignatureStream ss(m->signature()); !ss.is_done(); ss.next()) {
862 Symbol* sig = ss.as_symbol(THREAD);
863 if (ss.is_object()) {
864 Symbol* symb = sig;
865 if (ss.is_array()) {
866 int i=0;
867 while (sig->char_at(i) == '[') i++;
868 if (i == sig->utf8_length() - 1 ) continue; // primitive array
869 symb = SymbolTable::lookup(sig->as_C_string() + i + 1,
870 sig->utf8_length() - 3, CHECK_false);
871 }
872 if (ss.type() == T_VALUETYPE) {
873 oop loader = class_loader();
874 oop protection_domain = this->protection_domain();
875 Klass* klass = SystemDictionary::resolve_or_fail(symb,
876 Handle(THREAD, loader), Handle(THREAD, protection_domain), true,
877 CHECK_false);
878 if (symb != sig) {
879 symb->decrement_refcount();
880 }
881 if (klass == NULL) {
882 THROW_(vmSymbols::java_lang_LinkageError(), false);
883 }
884 if (!klass->is_value()) {
885 THROW_(vmSymbols::java_lang_IncompatibleClassChangeError(), false);
886 }
887 }
888 }
889 }
890 }
891 }
892
893 // in case the class is linked in the process of linking its superclasses
894 if (is_linked()) {
895 return true;
896 }
897
898 // trace only the link time for this klass that includes
899 // the verification time
900 PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(),
901 ClassLoader::perf_class_link_selftime(),
902 ClassLoader::perf_classes_linked(),
903 jt->get_thread_stat()->perf_recursion_counts_addr(),
904 jt->get_thread_stat()->perf_timers_addr(),
905 PerfClassTraceTime::CLASS_LINK);
906
907 // verification & rewriting
908 {
909 HandleMark hm(THREAD);
910 Handle h_init_lock(THREAD, init_lock());
911 ObjectLocker ol(h_init_lock, THREAD, h_init_lock() != NULL);
912 // rewritten will have been set if loader constraint error found
942 // Initialize the vtable and interface table after
943 // methods have been rewritten since rewrite may
944 // fabricate new Method*s.
945 // also does loader constraint checking
946 //
947 // initialize_vtable and initialize_itable need to be rerun for
948 // a shared class if the class is not loaded by the NULL classloader.
949 ClassLoaderData * loader_data = class_loader_data();
950 if (!(is_shared() &&
951 loader_data->is_the_null_class_loader_data())) {
952 vtable().initialize_vtable(true, CHECK_false);
953 itable().initialize_itable(true, CHECK_false);
954 }
955 #ifdef ASSERT
956 else {
957 vtable().verify(tty, true);
958 // In case itable verification is ever added.
959 // itable().verify(tty, true);
960 }
961 #endif
962
963 set_init_state(linked);
964 if (JvmtiExport::should_post_class_prepare()) {
965 Thread *thread = THREAD;
966 assert(thread->is_Java_thread(), "thread->is_Java_thread()");
967 JvmtiExport::post_class_prepare((JavaThread *) thread, this);
968 }
969 }
970 }
971 return true;
972 }
973
974 // Rewrite the byte codes of all of the methods of a class.
975 // The rewriter must be called exactly once. Rewriting must happen after
976 // verification but before the first method of the class is executed.
977 void InstanceKlass::rewrite_class(TRAPS) {
978 assert(is_loaded(), "must be loaded");
979 if (is_rewritten()) {
980 assert(is_shared(), "rewriting an unshared class?");
981 return;
982 }
1096 // having a superinterface that declares, non-static, concrete methods
1097 if (!HAS_PENDING_EXCEPTION && has_nonstatic_concrete_methods()) {
1098 initialize_super_interfaces(THREAD);
1099 }
1100
1101 // If any exceptions, complete abruptly, throwing the same exception as above.
1102 if (HAS_PENDING_EXCEPTION) {
1103 Handle e(THREAD, PENDING_EXCEPTION);
1104 CLEAR_PENDING_EXCEPTION;
1105 {
1106 EXCEPTION_MARK;
1107 // Locks object, set state, and notify all waiting threads
1108 set_initialization_state_and_notify(initialization_error, THREAD);
1109 CLEAR_PENDING_EXCEPTION;
1110 }
1111 DTRACE_CLASSINIT_PROBE_WAIT(super__failed, -1, wait);
1112 THROW_OOP(e());
1113 }
1114 }
1115
1116 // Step 8
1117 // Initialize classes of flattenable fields
1118 {
1119 for (AllFieldStream fs(this); !fs.done(); fs.next()) {
1120 if (fs.is_flattenable()) {
1121 InstanceKlass* field_klass = InstanceKlass::cast(this->get_value_field_klass(fs.index()));
1122 field_klass->initialize(CHECK);
1123 }
1124 }
1125 }
1126
1127
1128 // Look for aot compiled methods for this klass, including class initializer.
1129 AOTLoader::load_for_klass(this, THREAD);
1130
1131 // Step 9
1132 {
1133 DTRACE_CLASSINIT_PROBE_WAIT(clinit, -1, wait);
1134 // Timer includes any side effects of class initialization (resolution,
1135 // etc), but not recursive entry into call_class_initializer().
1136 PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
1137 ClassLoader::perf_class_init_selftime(),
1138 ClassLoader::perf_classes_inited(),
1139 jt->get_thread_stat()->perf_recursion_counts_addr(),
1140 jt->get_thread_stat()->perf_timers_addr(),
1141 PerfClassTraceTime::CLASS_CLINIT);
1142 call_class_initializer(THREAD);
1143 }
1144
1145 // Step 10
1146 if (!HAS_PENDING_EXCEPTION) {
1147 set_initialization_state_and_notify(fully_initialized, CHECK);
1148 {
1149 debug_only(vtable().verify(tty, true);)
1150 }
1151 }
1152 else {
1153 // Step 11 and 12
1154 Handle e(THREAD, PENDING_EXCEPTION);
1155 CLEAR_PENDING_EXCEPTION;
1156 // JVMTI has already reported the pending exception
1157 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1158 JvmtiExport::clear_detected_exception(jt);
1159 {
1160 EXCEPTION_MARK;
1161 set_initialization_state_and_notify(initialization_error, THREAD);
1162 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, class initialization error is thrown below
1163 // JVMTI has already reported the pending exception
1164 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
1165 JvmtiExport::clear_detected_exception(jt);
1166 }
1167 DTRACE_CLASSINIT_PROBE_WAIT(error, -1, wait);
1168 if (e->is_a(SystemDictionary::Error_klass())) {
1169 THROW_OOP(e());
1170 } else {
1171 JavaCallArguments args(e);
1172 THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(),
1173 vmSymbols::throwable_void_signature(),
1455 ResourceMark rm;
1456 LogStream ls(lt);
1457 ls.print("%d Initializing ", call_class_initializer_counter++);
1458 name()->print_value_on(&ls);
1459 ls.print_cr("%s (" INTPTR_FORMAT ")", h_method() == NULL ? "(no method)" : "", p2i(this));
1460 }
1461 if (h_method() != NULL) {
1462 JavaCallArguments args; // No arguments
1463 JavaValue result(T_VOID);
1464 JavaCalls::call(&result, h_method, &args, CHECK); // Static call (no args)
1465 }
1466 }
1467
1468
1469 void InstanceKlass::mask_for(const methodHandle& method, int bci,
1470 InterpreterOopMap* entry_for) {
1471 // Lazily create the _oop_map_cache at first request
1472 // Lock-free access requires load_acquire.
1473 OopMapCache* oop_map_cache = OrderAccess::load_acquire(&_oop_map_cache);
1474 if (oop_map_cache == NULL) {
1475 MutexLockerEx x(OopMapCacheAlloc_lock, Mutex::_no_safepoint_check_flag);
1476 // Check if _oop_map_cache was allocated while we were waiting for this lock
1477 if ((oop_map_cache = _oop_map_cache) == NULL) {
1478 oop_map_cache = new OopMapCache();
1479 // Ensure _oop_map_cache is stable, since it is examined without a lock
1480 OrderAccess::release_store(&_oop_map_cache, oop_map_cache);
1481 }
1482 }
1483 // _oop_map_cache is constant after init; lookup below does its own locking.
1484 oop_map_cache->lookup(method, bci, entry_for);
1485 }
1486
1487
1488 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1489 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1490 Symbol* f_name = fs.name();
1491 Symbol* f_sig = fs.signature();
1492 if (f_name == name && f_sig == sig) {
1493 fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1494 return true;
1495 }
2617
2618 #if INCLUDE_JVMTI
2619 // Deallocate breakpoint records
2620 if (breakpoints() != 0x0) {
2621 methods_do(clear_all_breakpoints);
2622 assert(breakpoints() == 0x0, "should have cleared breakpoints");
2623 }
2624
2625 // deallocate the cached class file
2626 if (_cached_class_file != NULL) {
2627 os::free(_cached_class_file);
2628 _cached_class_file = NULL;
2629 }
2630 #endif
2631
2632 // Decrement symbol reference counts associated with the unloaded class.
2633 if (_name != NULL) _name->decrement_refcount();
2634 // unreference array name derived from this class name (arrays of an unloaded
2635 // class can't be referenced anymore).
2636 if (_array_name != NULL) _array_name->decrement_refcount();
2637 if (_value_types != NULL) {
2638 for (int i = 0; i < _value_types->length(); i++) {
2639 Symbol* s = _value_types->at(i)._class_name;
2640 if (s != NULL) {
2641 s->decrement_refcount();
2642 }
2643 }
2644 }
2645 if (_source_debug_extension != NULL) FREE_C_HEAP_ARRAY(char, _source_debug_extension);
2646 }
2647
2648 void InstanceKlass::set_source_debug_extension(const char* array, int length) {
2649 if (array == NULL) {
2650 _source_debug_extension = NULL;
2651 } else {
2652 // Adding one to the attribute length in order to store a null terminator
2653 // character could cause an overflow because the attribute length is
2654 // already coded with an u4 in the classfile, but in practice, it's
2655 // unlikely to happen.
2656 assert((length+1) > length, "Overflow checking");
2657 char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass);
2658 for (int i = 0; i < length; i++) {
2659 sde[i] = array[i];
2660 }
2661 sde[length] = '\0';
2662 _source_debug_extension = sde;
2663 }
2664 }
2665
2666 const char* InstanceKlass::signature_name() const {
2667 return signature_name_of(is_value() ? 'Q' : 'L');
2668 }
2669
2670 const char* InstanceKlass::signature_name_of(char c) const {
2671 int hash_len = 0;
2672 char hash_buf[40];
2673
2674 // If this is an unsafe anonymous class, append a hash to make the name unique
2675 if (is_unsafe_anonymous()) {
2676 intptr_t hash = (java_mirror() != NULL) ? java_mirror()->identity_hash() : 0;
2677 jio_snprintf(hash_buf, sizeof(hash_buf), "/" UINTX_FORMAT, (uintx)hash);
2678 hash_len = (int)strlen(hash_buf);
2679 }
2680
2681 // Get the internal name as a c string
2682 const char* src = (const char*) (name()->as_C_string());
2683 const int src_length = (int)strlen(src);
2684
2685 char* dest = NEW_RESOURCE_ARRAY(char, src_length + hash_len + 3);
2686
2687 // Add L or Q as type indicator
2688 int dest_index = 0;
2689 dest[dest_index++] = c;
2690
2691 // Add the actual class name
2692 for (int src_index = 0; src_index < src_length; ) {
2693 dest[dest_index++] = src[src_index++];
2694 }
2695
2696 // If we have a hash, append it
2697 for (int hash_index = 0; hash_index < hash_len; ) {
2698 dest[dest_index++] = hash_buf[hash_index++];
2699 }
2700
2701 // Add the semicolon and the NULL
2702 dest[dest_index++] = ';';
2703 dest[dest_index] = '\0';
2704 return dest;
2705 }
2706
2707 // Used to obtain the package name from a fully qualified class name.
2708 Symbol* InstanceKlass::package_from_name(const Symbol* name, TRAPS) {
2709 if (name == NULL) {
3191 }
3192 osr = osr->osr_link();
3193 }
3194 if (best != NULL && best->comp_level() >= comp_level && match_level == false) {
3195 return best;
3196 }
3197 return NULL;
3198 }
3199
3200 // -----------------------------------------------------------------------------------------------------
3201 // Printing
3202
3203 #ifndef PRODUCT
3204
3205 #define BULLET " - "
3206
3207 static const char* state_names[] = {
3208 "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error"
3209 };
3210
3211 static void print_vtable(address self, intptr_t* start, int len, outputStream* st) {
3212 ResourceMark rm;
3213 int* forward_refs = NEW_RESOURCE_ARRAY(int, len);
3214 for (int i = 0; i < len; i++) forward_refs[i] = 0;
3215 for (int i = 0; i < len; i++) {
3216 intptr_t e = start[i];
3217 st->print("%d : " INTPTR_FORMAT, i, e);
3218 if (forward_refs[i] != 0) {
3219 int from = forward_refs[i];
3220 int off = (int) start[from];
3221 st->print(" (offset %d <= [%d])", off, from);
3222 }
3223 if (e != 0 && ((Metadata*)e)->is_metaspace_object()) {
3224 st->print(" ");
3225 ((Metadata*)e)->print_value_on(st);
3226 } else if (self != NULL && e > 0 && e < 0x10000) {
3227 address location = self + e;
3228 int index = (int)((intptr_t*)location - start);
3229 st->print(" (offset %d => [%d])", (int)e, index);
3230 if (index >= 0 && index < len)
3231 forward_refs[index] = i;
3232 }
3233 st->cr();
3234 }
3235 }
3236
3237 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
3238 return print_vtable(NULL, reinterpret_cast<intptr_t*>(start), len, st);
3239 }
3240
3241 template<typename T>
3242 static void print_array_on(outputStream* st, Array<T>* array) {
3243 if (array == NULL) { st->print_cr("NULL"); return; }
3244 array->print_value_on(st); st->cr();
3245 if (Verbose || WizardMode) {
3246 for (int i = 0; i < array->length(); i++) {
3247 st->print("%d : ", i); array->at(i)->print_value_on(st); st->cr();
3248 }
3249 }
3250 }
3251
3252 static void print_array_on(outputStream* st, Array<int>* array) {
3253 if (array == NULL) { st->print_cr("NULL"); return; }
3254 array->print_value_on(st); st->cr();
3255 if (Verbose || WizardMode) {
3256 for (int i = 0; i < array->length(); i++) {
3257 st->print("%d : %d", i, array->at(i)); st->cr();
3258 }
3259 }
3260 }
3261
3262 void InstanceKlass::print_on(outputStream* st) const {
3263 assert(is_klass(), "must be klass");
3264 Klass::print_on(st);
3265
3266 st->print(BULLET"instance size: %d", size_helper()); st->cr();
3267 st->print(BULLET"klass size: %d", size()); st->cr();
3268 st->print(BULLET"access: "); access_flags().print_on(st); st->cr();
3269 st->print(BULLET"misc flags: 0x%x", _misc_flags); st->cr();
3270 st->print(BULLET"state: "); st->print_cr("%s", state_names[_init_state]);
3271 st->print(BULLET"name: "); name()->print_value_on(st); st->cr();
3272 st->print(BULLET"super: "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
3273 st->print(BULLET"sub: ");
3274 Klass* sub = subklass();
3275 int n;
3276 for (n = 0; sub != NULL; n++, sub = sub->next_sibling()) {
3277 if (n < MaxSubklassPrintSize) {
3278 sub->print_value_on(st);
3279 st->print(" ");
3280 }
3281 }
3282 if (n >= MaxSubklassPrintSize) st->print("(" INTX_FORMAT " more klasses...)", n - MaxSubklassPrintSize);
3283 st->cr();
3284
3285 if (is_interface()) {
3286 st->print_cr(BULLET"nof implementors: %d", nof_implementors());
3287 if (nof_implementors() == 1) {
3288 st->print_cr(BULLET"implementor: ");
3289 st->print(" ");
3290 implementor()->print_value_on(st);
3291 st->cr();
3292 }
3293 }
3294
3295 st->print(BULLET"arrays: "); Metadata::print_value_on_maybe_null(st, array_klasses()); st->cr();
3296 st->print(BULLET"methods: "); print_array_on(st, methods());
3297 st->print(BULLET"method ordering: "); print_array_on(st, method_ordering());
3298 st->print(BULLET"default_methods: "); print_array_on(st, default_methods());
3299 if (default_vtable_indices() != NULL) {
3300 st->print(BULLET"default vtable indices: "); print_array_on(st, default_vtable_indices());
3301 }
3302 st->print(BULLET"local interfaces: "); print_array_on(st, local_interfaces());
3303 st->print(BULLET"trans. interfaces: "); print_array_on(st, transitive_interfaces());
3304 st->print(BULLET"constants: "); constants()->print_value_on(st); st->cr();
3305 if (class_loader_data() != NULL) {
3306 st->print(BULLET"class loader data: ");
3307 class_loader_data()->print_value_on(st);
3308 st->cr();
3309 }
3310 st->print(BULLET"unsafe anonymous host class: "); Metadata::print_value_on_maybe_null(st, unsafe_anonymous_host()); st->cr();
3311 if (source_file_name() != NULL) {
3312 st->print(BULLET"source file: ");
3313 source_file_name()->print_value_on(st);
3314 st->cr();
3315 }
3316 if (source_debug_extension() != NULL) {
3317 st->print(BULLET"source debug extension: ");
3318 st->print("%s", source_debug_extension());
3319 st->cr();
3320 }
3321 st->print(BULLET"class annotations: "); class_annotations()->print_value_on(st); st->cr();
3322 st->print(BULLET"class type annotations: "); class_type_annotations()->print_value_on(st); st->cr();
3323 st->print(BULLET"field annotations: "); fields_annotations()->print_value_on(st); st->cr();
3336 if (have_pv) st->cr();
3337 }
3338
3339 if (generic_signature() != NULL) {
3340 st->print(BULLET"generic signature: ");
3341 generic_signature()->print_value_on(st);
3342 st->cr();
3343 }
3344 st->print(BULLET"inner classes: "); inner_classes()->print_value_on(st); st->cr();
3345 st->print(BULLET"nest members: "); nest_members()->print_value_on(st); st->cr();
3346 if (java_mirror() != NULL) {
3347 st->print(BULLET"java mirror: ");
3348 java_mirror()->print_value_on(st);
3349 st->cr();
3350 } else {
3351 st->print_cr(BULLET"java mirror: NULL");
3352 }
3353 st->print(BULLET"vtable length %d (start addr: " INTPTR_FORMAT ")", vtable_length(), p2i(start_of_vtable())); st->cr();
3354 if (vtable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_vtable(), vtable_length(), st);
3355 st->print(BULLET"itable length %d (start addr: " INTPTR_FORMAT ")", itable_length(), p2i(start_of_itable())); st->cr();
3356 if (itable_length() > 0 && (Verbose || WizardMode)) print_vtable(NULL, start_of_itable(), itable_length(), st);
3357 st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
3358 FieldPrinter print_static_field(st);
3359 ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
3360 st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
3361 FieldPrinter print_nonstatic_field(st);
3362 InstanceKlass* ik = const_cast<InstanceKlass*>(this);
3363 ik->do_nonstatic_fields(&print_nonstatic_field);
3364
3365 st->print(BULLET"non-static oop maps: ");
3366 OopMapBlock* map = start_of_nonstatic_oop_maps();
3367 OopMapBlock* end_map = map + nonstatic_oop_map_count();
3368 while (map < end_map) {
3369 st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1));
3370 map++;
3371 }
3372 st->cr();
3373 }
3374
3375 #endif //PRODUCT
3376
4110 if (holder == NULL) {
4111 return NULL; // The version of klass is gone, no method is found
4112 }
4113 Method* method = holder->method_with_orig_idnum(idnum);
4114 return method;
4115 }
4116
4117 #if INCLUDE_JVMTI
4118 JvmtiCachedClassFileData* InstanceKlass::get_cached_class_file() {
4119 return _cached_class_file;
4120 }
4121
4122 jint InstanceKlass::get_cached_class_file_len() {
4123 return VM_RedefineClasses::get_cached_class_file_len(_cached_class_file);
4124 }
4125
4126 unsigned char * InstanceKlass::get_cached_class_file_bytes() {
4127 return VM_RedefineClasses::get_cached_class_file_bytes(_cached_class_file);
4128 }
4129 #endif
4130
4131 #define THROW_DVT_ERROR(s) \
4132 Exceptions::fthrow(THREAD_AND_LOCATION, vmSymbols::java_lang_IncompatibleClassChangeError(), \
4133 "ValueCapableClass class '%s' %s", external_name(),(s)); \
4134 return
|