< prev index next >

src/hotspot/share/oops/instanceKlass.cpp

Print this page




 194         }
 195 
 196         Klass* k2 = _constants->klass_at(cp_index, CHECK_false);
 197         if (k2 == k) {
 198           log_trace(class, nestmates)("- class is listed as a nest member");
 199           return true;
 200         }
 201         else {
 202           // same name but different klass!
 203           log_trace(class, nestmates)(" - klass comparison failed!");
 204           // can't have two names the same, so we're done
 205           return false;
 206         }
 207       }
 208     }
 209   }
 210   log_trace(class, nestmates)("- class is NOT a nest member!");
 211   return false;
 212 }
 213 






















































 214 // Return nest-host class, resolving, validating and saving it if needed.
 215 // In cases where this is called from a thread that can not do classloading
 216 // (such as a native JIT thread) then we simply return NULL, which in turn
 217 // causes the access check to return false. Such code will retry the access
 218 // from a more suitable environment later.
 219 InstanceKlass* InstanceKlass::nest_host(Symbol* validationException, TRAPS) {
 220   InstanceKlass* nest_host_k = _nest_host;
 221   if (nest_host_k == NULL) {
 222     // need to resolve and save our nest-host class. This could be attempted
 223     // concurrently but as the result is idempotent and we don't use the class
 224     // then we do not need any synchronization beyond what is implicitly used
 225     // during class loading.
 226     if (_nest_host_index != 0) { // we have a real nest_host
 227       // Before trying to resolve check if we're in a suitable context
 228       if (!THREAD->can_call_java() && !_constants->tag_at(_nest_host_index).is_klass()) {
 229         if (log_is_enabled(Trace, class, nestmates)) {
 230           ResourceMark rm(THREAD);
 231           log_trace(class, nestmates)("Rejected resolution of nest-host of %s in unsuitable thread",
 232                                       this->external_name());
 233         }


 418       _method_ordering->at_put(i, m->at(i));
 419     }
 420   } else {
 421     _method_ordering = Universe::the_empty_int_array();
 422   }
 423 }
 424 
 425 // create a new array of vtable_indices for default methods
 426 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
 427   Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
 428   assert(default_vtable_indices() == NULL, "only create once");
 429   set_default_vtable_indices(vtable_indices);
 430   return vtable_indices;
 431 }
 432 
 433 InstanceKlass::InstanceKlass(const ClassFileParser& parser, unsigned kind, KlassID id) :
 434   Klass(id),
 435   _nest_members(NULL),
 436   _nest_host_index(0),
 437   _nest_host(NULL),

 438   _static_field_size(parser.static_field_size()),
 439   _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
 440   _itable_len(parser.itable_size()),
 441   _init_thread(NULL),
 442   _init_state(allocated),
 443   _reference_type(parser.reference_type())
 444 {
 445   set_vtable_length(parser.vtable_size());
 446   set_kind(kind);
 447   set_access_flags(parser.access_flags());
 448   set_is_unsafe_anonymous(parser.is_unsafe_anonymous());
 449   set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
 450                                                     false));
 451 
 452   assert(NULL == _methods, "underlying memory not zeroed?");
 453   assert(is_instance_klass(), "is layout incorrect?");
 454   assert(size_helper() == parser.layout_size(), "incorrect size_helper?");
 455 
 456   if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
 457     SystemDictionaryShared::init_dumptime_info(this);


 580     // Delete any cached resolution errors for the constant pool
 581     SystemDictionary::delete_resolution_error(constants());
 582 
 583     set_constants(NULL);
 584   }
 585 
 586   if (inner_classes() != NULL &&
 587       inner_classes() != Universe::the_empty_short_array() &&
 588       !inner_classes()->is_shared()) {
 589     MetadataFactory::free_array<jushort>(loader_data, inner_classes());
 590   }
 591   set_inner_classes(NULL);
 592 
 593   if (nest_members() != NULL &&
 594       nest_members() != Universe::the_empty_short_array() &&
 595       !nest_members()->is_shared()) {
 596     MetadataFactory::free_array<jushort>(loader_data, nest_members());
 597   }
 598   set_nest_members(NULL);
 599 













 600   // We should deallocate the Annotations instance if it's not in shared spaces.
 601   if (annotations() != NULL && !annotations()->is_shared()) {
 602     MetadataFactory::free_metadata(loader_data, annotations());
 603   }
 604   set_annotations(NULL);
 605 
 606   if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
 607     SystemDictionaryShared::remove_dumptime_info(this);
 608   }
 609 }
 610 







 611 bool InstanceKlass::should_be_initialized() const {
 612   return !is_initialized();
 613 }
 614 
 615 klassItable InstanceKlass::itable() const {
 616   return klassItable(const_cast<InstanceKlass*>(this));
 617 }
 618 
 619 void InstanceKlass::eager_initialize(Thread *thread) {
 620   if (!EagerInitialization) return;
 621 
 622   if (this->is_not_initialized()) {
 623     // abort if the the class has a class initializer
 624     if (this->class_initializer() != NULL) return;
 625 
 626     // abort if it is java.lang.Object (initialization is handled in genesis)
 627     Klass* super_klass = super();
 628     if (super_klass == NULL) return;
 629 
 630     // abort if the super class should be initialized


2296 
2297   if (itable_length() > 0) {
2298     itableOffsetEntry* ioe = (itableOffsetEntry*)start_of_itable();
2299     int method_table_offset_in_words = ioe->offset()/wordSize;
2300     int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words())
2301                          / itableOffsetEntry::size();
2302 
2303     for (int i = 0; i < nof_interfaces; i ++, ioe ++) {
2304       if (ioe->interface_klass() != NULL) {
2305         it->push(ioe->interface_klass_addr());
2306         itableMethodEntry* ime = ioe->first_method_entry(this);
2307         int n = klassItable::method_count_for_interface(ioe->interface_klass());
2308         for (int index = 0; index < n; index ++) {
2309           it->push(ime[index].method_addr());
2310         }
2311       }
2312     }
2313   }
2314 
2315   it->push(&_nest_members);


2316 }
2317 
2318 void InstanceKlass::remove_unshareable_info() {
2319   Klass::remove_unshareable_info();
2320 
2321   if (is_in_error_state()) {
2322     // Classes are attempted to link during dumping and may fail,
2323     // but these classes are still in the dictionary and class list in CLD.
2324     // Check in_error state first because in_error is > linked state, so
2325     // is_linked() is true.
2326     // If there's a linking error, there is nothing else to remove.
2327     return;
2328   }
2329 
2330   // Reset to the 'allocated' state to prevent any premature accessing to
2331   // a shared class at runtime while the class is still being loaded and
2332   // restored. A class' init_state is set to 'loaded' at runtime when it's
2333   // being added to class hierarchy (see SystemDictionary:::add_to_hierarchy()).
2334   _init_state = allocated;
2335 


3211     bool have_pv = false;
3212     // previous versions are linked together through the InstanceKlass
3213     for (InstanceKlass* pv_node = previous_versions();
3214          pv_node != NULL;
3215          pv_node = pv_node->previous_versions()) {
3216       if (!have_pv)
3217         st->print(BULLET"previous version:  ");
3218       have_pv = true;
3219       pv_node->constants()->print_value_on(st);
3220     }
3221     if (have_pv) st->cr();
3222   }
3223 
3224   if (generic_signature() != NULL) {
3225     st->print(BULLET"generic signature: ");
3226     generic_signature()->print_value_on(st);
3227     st->cr();
3228   }
3229   st->print(BULLET"inner classes:     "); inner_classes()->print_value_on(st);     st->cr();
3230   st->print(BULLET"nest members:     "); nest_members()->print_value_on(st);     st->cr();

3231   if (java_mirror() != NULL) {
3232     st->print(BULLET"java mirror:       ");
3233     java_mirror()->print_value_on(st);
3234     st->cr();
3235   } else {
3236     st->print_cr(BULLET"java mirror:       NULL");
3237   }
3238   st->print(BULLET"vtable length      %d  (start addr: " INTPTR_FORMAT ")", vtable_length(), p2i(start_of_vtable())); st->cr();
3239   if (vtable_length() > 0 && (Verbose || WizardMode))  print_vtable(start_of_vtable(), vtable_length(), st);
3240   st->print(BULLET"itable length      %d (start addr: " INTPTR_FORMAT ")", itable_length(), p2i(start_of_itable())); st->cr();
3241   if (itable_length() > 0 && (Verbose || WizardMode))  print_vtable(start_of_itable(), itable_length(), st);
3242   st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
3243   FieldPrinter print_static_field(st);
3244   ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
3245   st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
3246   FieldPrinter print_nonstatic_field(st);
3247   InstanceKlass* ik = const_cast<InstanceKlass*>(this);
3248   ik->do_nonstatic_fields(&print_nonstatic_field);
3249 
3250   st->print(BULLET"non-static oop maps: ");




 194         }
 195 
 196         Klass* k2 = _constants->klass_at(cp_index, CHECK_false);
 197         if (k2 == k) {
 198           log_trace(class, nestmates)("- class is listed as a nest member");
 199           return true;
 200         }
 201         else {
 202           // same name but different klass!
 203           log_trace(class, nestmates)(" - klass comparison failed!");
 204           // can't have two names the same, so we're done
 205           return false;
 206         }
 207       }
 208     }
 209   }
 210   log_trace(class, nestmates)("- class is NOT a nest member!");
 211   return false;
 212 }
 213 
 214 // Called to verify that k is a permitted subtype of this class
 215 bool InstanceKlass::has_as_permitted_subtype(InstanceKlass* k, TRAPS) const {
 216   if (k == NULL) {
 217     if (log_is_enabled(Trace, class, sealed)) {
 218       ResourceMark rm(THREAD);
 219       log_trace(class, sealed)("Checked for permitted subtype of %s with a NULL instance class", this->external_name());
 220     }
 221     return false;
 222   }
 223   if (_permitted_subtypes == NULL || _permitted_subtypes == Universe::the_empty_short_array()) {
 224     if (log_is_enabled(Trace, class, sealed)) {
 225       ResourceMark rm(THREAD);
 226       log_trace(class, sealed)("Checked for permitted subtype of %s in non-sealed class %s",
 227                                   k->external_name(), this->external_name());
 228     }
 229     return false;
 230   }
 231 
 232   if (log_is_enabled(Trace, class, sealed)) {
 233     ResourceMark rm(THREAD);
 234     log_trace(class, sealed)("Checking for permitted subtype of %s in %s",
 235                                 k->external_name(), this->external_name());
 236   }
 237 
 238   oop classloader1 = this->class_loader();
 239   oop classloader2 = k->class_loader();
 240   if (!oopDesc::equals(classloader1, classloader2)) {
 241       log_trace(class, sealed)("Checked for same class loader of permitted subtype of %s and sealed class %s",
 242                                         k->external_name(), this->external_name());
 243       return false;
 244   }
 245 
 246   // Check for a resolved cp entry, else fall back to a name check.
 247   // We don't want to resolve any class other than the one being checked.
 248   for (int i = 0; i < _permitted_subtypes->length(); i++) {
 249     int cp_index = _permitted_subtypes->at(i);
 250     if (_constants->tag_at(cp_index).is_klass()) {
 251       Klass* k2 = _constants->klass_at(cp_index, CHECK_false);
 252       if (k2 == k) {
 253         log_trace(class, sealed)("- class is listed at permitted_subtypes[%d] => cp[%d]", i, cp_index);
 254         return true;
 255       }
 256     } else {
 257       Symbol* name = _constants->klass_name_at(cp_index);
 258       if (name == k->name()) {
 259         log_trace(class, sealed)("- Found it at permitted_subtypes[%d] => cp[%d]", i, cp_index);
 260         return true;
 261       }
 262     }
 263   }
 264   log_trace(class, sealed)("- class is NOT a permitted subtype!");
 265   return false;
 266 }
 267 
 268 // Return nest-host class, resolving, validating and saving it if needed.
 269 // In cases where this is called from a thread that can not do classloading
 270 // (such as a native JIT thread) then we simply return NULL, which in turn
 271 // causes the access check to return false. Such code will retry the access
 272 // from a more suitable environment later.
 273 InstanceKlass* InstanceKlass::nest_host(Symbol* validationException, TRAPS) {
 274   InstanceKlass* nest_host_k = _nest_host;
 275   if (nest_host_k == NULL) {
 276     // need to resolve and save our nest-host class. This could be attempted
 277     // concurrently but as the result is idempotent and we don't use the class
 278     // then we do not need any synchronization beyond what is implicitly used
 279     // during class loading.
 280     if (_nest_host_index != 0) { // we have a real nest_host
 281       // Before trying to resolve check if we're in a suitable context
 282       if (!THREAD->can_call_java() && !_constants->tag_at(_nest_host_index).is_klass()) {
 283         if (log_is_enabled(Trace, class, nestmates)) {
 284           ResourceMark rm(THREAD);
 285           log_trace(class, nestmates)("Rejected resolution of nest-host of %s in unsuitable thread",
 286                                       this->external_name());
 287         }


 472       _method_ordering->at_put(i, m->at(i));
 473     }
 474   } else {
 475     _method_ordering = Universe::the_empty_int_array();
 476   }
 477 }
 478 
 479 // create a new array of vtable_indices for default methods
 480 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
 481   Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
 482   assert(default_vtable_indices() == NULL, "only create once");
 483   set_default_vtable_indices(vtable_indices);
 484   return vtable_indices;
 485 }
 486 
 487 InstanceKlass::InstanceKlass(const ClassFileParser& parser, unsigned kind, KlassID id) :
 488   Klass(id),
 489   _nest_members(NULL),
 490   _nest_host_index(0),
 491   _nest_host(NULL),
 492   _permitted_subtypes(NULL),
 493   _static_field_size(parser.static_field_size()),
 494   _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
 495   _itable_len(parser.itable_size()),
 496   _init_thread(NULL),
 497   _init_state(allocated),
 498   _reference_type(parser.reference_type())
 499 {
 500   set_vtable_length(parser.vtable_size());
 501   set_kind(kind);
 502   set_access_flags(parser.access_flags());
 503   set_is_unsafe_anonymous(parser.is_unsafe_anonymous());
 504   set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
 505                                                     false));
 506 
 507   assert(NULL == _methods, "underlying memory not zeroed?");
 508   assert(is_instance_klass(), "is layout incorrect?");
 509   assert(size_helper() == parser.layout_size(), "incorrect size_helper?");
 510 
 511   if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
 512     SystemDictionaryShared::init_dumptime_info(this);


 635     // Delete any cached resolution errors for the constant pool
 636     SystemDictionary::delete_resolution_error(constants());
 637 
 638     set_constants(NULL);
 639   }
 640 
 641   if (inner_classes() != NULL &&
 642       inner_classes() != Universe::the_empty_short_array() &&
 643       !inner_classes()->is_shared()) {
 644     MetadataFactory::free_array<jushort>(loader_data, inner_classes());
 645   }
 646   set_inner_classes(NULL);
 647 
 648   if (nest_members() != NULL &&
 649       nest_members() != Universe::the_empty_short_array() &&
 650       !nest_members()->is_shared()) {
 651     MetadataFactory::free_array<jushort>(loader_data, nest_members());
 652   }
 653   set_nest_members(NULL);
 654 
 655   if (record_params() != NULL &&
 656       record_params() != Universe::the_empty_short_array()) {
 657     MetadataFactory::free_array<jushort>(loader_data, record_params());
 658   }
 659   set_record_params(NULL, 0);
 660 
 661   if (permitted_subtypes() != NULL &&
 662       permitted_subtypes() != Universe::the_empty_short_array() &&
 663       !permitted_subtypes()->is_shared()) {
 664     MetadataFactory::free_array<jushort>(loader_data, permitted_subtypes());
 665   }
 666   set_permitted_subtypes(NULL);
 667 
 668   // We should deallocate the Annotations instance if it's not in shared spaces.
 669   if (annotations() != NULL && !annotations()->is_shared()) {
 670     MetadataFactory::free_metadata(loader_data, annotations());
 671   }
 672   set_annotations(NULL);
 673 
 674   if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
 675     SystemDictionaryShared::remove_dumptime_info(this);
 676   }
 677 }
 678 
 679 bool InstanceKlass::is_sealed() const {
 680   return is_final() &&
 681         _permitted_subtypes != NULL &&
 682         _permitted_subtypes != Universe::the_empty_short_array() &&
 683         _permitted_subtypes->length() > 0;
 684 }
 685 
 686 bool InstanceKlass::should_be_initialized() const {
 687   return !is_initialized();
 688 }
 689 
 690 klassItable InstanceKlass::itable() const {
 691   return klassItable(const_cast<InstanceKlass*>(this));
 692 }
 693 
 694 void InstanceKlass::eager_initialize(Thread *thread) {
 695   if (!EagerInitialization) return;
 696 
 697   if (this->is_not_initialized()) {
 698     // abort if the the class has a class initializer
 699     if (this->class_initializer() != NULL) return;
 700 
 701     // abort if it is java.lang.Object (initialization is handled in genesis)
 702     Klass* super_klass = super();
 703     if (super_klass == NULL) return;
 704 
 705     // abort if the super class should be initialized


2371 
2372   if (itable_length() > 0) {
2373     itableOffsetEntry* ioe = (itableOffsetEntry*)start_of_itable();
2374     int method_table_offset_in_words = ioe->offset()/wordSize;
2375     int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words())
2376                          / itableOffsetEntry::size();
2377 
2378     for (int i = 0; i < nof_interfaces; i ++, ioe ++) {
2379       if (ioe->interface_klass() != NULL) {
2380         it->push(ioe->interface_klass_addr());
2381         itableMethodEntry* ime = ioe->first_method_entry(this);
2382         int n = klassItable::method_count_for_interface(ioe->interface_klass());
2383         for (int index = 0; index < n; index ++) {
2384           it->push(ime[index].method_addr());
2385         }
2386       }
2387     }
2388   }
2389 
2390   it->push(&_nest_members);
2391   it->push(&_record_params);
2392   it->push(&_permitted_subtypes);
2393 }
2394 
2395 void InstanceKlass::remove_unshareable_info() {
2396   Klass::remove_unshareable_info();
2397 
2398   if (is_in_error_state()) {
2399     // Classes are attempted to link during dumping and may fail,
2400     // but these classes are still in the dictionary and class list in CLD.
2401     // Check in_error state first because in_error is > linked state, so
2402     // is_linked() is true.
2403     // If there's a linking error, there is nothing else to remove.
2404     return;
2405   }
2406 
2407   // Reset to the 'allocated' state to prevent any premature accessing to
2408   // a shared class at runtime while the class is still being loaded and
2409   // restored. A class' init_state is set to 'loaded' at runtime when it's
2410   // being added to class hierarchy (see SystemDictionary:::add_to_hierarchy()).
2411   _init_state = allocated;
2412 


3288     bool have_pv = false;
3289     // previous versions are linked together through the InstanceKlass
3290     for (InstanceKlass* pv_node = previous_versions();
3291          pv_node != NULL;
3292          pv_node = pv_node->previous_versions()) {
3293       if (!have_pv)
3294         st->print(BULLET"previous version:  ");
3295       have_pv = true;
3296       pv_node->constants()->print_value_on(st);
3297     }
3298     if (have_pv) st->cr();
3299   }
3300 
3301   if (generic_signature() != NULL) {
3302     st->print(BULLET"generic signature: ");
3303     generic_signature()->print_value_on(st);
3304     st->cr();
3305   }
3306   st->print(BULLET"inner classes:     "); inner_classes()->print_value_on(st);     st->cr();
3307   st->print(BULLET"nest members:     "); nest_members()->print_value_on(st);     st->cr();
3308   st->print(BULLET"permitted subtypes:     "); permitted_subtypes()->print_value_on(st);     st->cr();
3309   if (java_mirror() != NULL) {
3310     st->print(BULLET"java mirror:       ");
3311     java_mirror()->print_value_on(st);
3312     st->cr();
3313   } else {
3314     st->print_cr(BULLET"java mirror:       NULL");
3315   }
3316   st->print(BULLET"vtable length      %d  (start addr: " INTPTR_FORMAT ")", vtable_length(), p2i(start_of_vtable())); st->cr();
3317   if (vtable_length() > 0 && (Verbose || WizardMode))  print_vtable(start_of_vtable(), vtable_length(), st);
3318   st->print(BULLET"itable length      %d (start addr: " INTPTR_FORMAT ")", itable_length(), p2i(start_of_itable())); st->cr();
3319   if (itable_length() > 0 && (Verbose || WizardMode))  print_vtable(start_of_itable(), itable_length(), st);
3320   st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
3321   FieldPrinter print_static_field(st);
3322   ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
3323   st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
3324   FieldPrinter print_nonstatic_field(st);
3325   InstanceKlass* ik = const_cast<InstanceKlass*>(this);
3326   ik->do_nonstatic_fields(&print_nonstatic_field);
3327 
3328   st->print(BULLET"non-static oop maps: ");


< prev index next >