< prev index next >

src/share/vm/oops/klass.cpp

Print this page




  26 #include "classfile/dictionary.hpp"
  27 #include "classfile/javaClasses.hpp"
  28 #include "classfile/systemDictionary.hpp"
  29 #include "classfile/vmSymbols.hpp"
  30 #include "gc/shared/collectedHeap.inline.hpp"
  31 #include "logging/log.hpp"
  32 #include "memory/heapInspection.hpp"
  33 #include "memory/metadataFactory.hpp"
  34 #include "memory/metaspaceClosure.hpp"
  35 #include "memory/metaspaceShared.hpp"
  36 #include "memory/oopFactory.hpp"
  37 #include "memory/resourceArea.hpp"
  38 #include "oops/instanceKlass.hpp"
  39 #include "oops/klass.inline.hpp"
  40 #include "oops/oop.inline.hpp"
  41 #include "runtime/atomic.hpp"
  42 #include "runtime/orderAccess.inline.hpp"
  43 #include "trace/traceMacros.hpp"
  44 #include "utilities/macros.hpp"
  45 #include "utilities/stack.inline.hpp"
  46 #if INCLUDE_ALL_GCS
  47 #include "gc/g1/g1SATBCardTableModRefBS.hpp"
  48 #endif // INCLUDE_ALL_GCS









  49 
  50 bool Klass::is_cloneable() const {
  51   return _access_flags.is_cloneable_fast() ||
  52          is_subtype_of(SystemDictionary::Cloneable_klass());
  53 }
  54 
  55 void Klass::set_is_cloneable() {
  56   if (name() != vmSymbols::java_lang_invoke_MemberName()) {
  57     _access_flags.set_is_cloneable_fast();
  58   } else {
  59     assert(is_final(), "no subclasses allowed");
  60     // MemberName cloning should not be intrinsified and always happen in JVM_Clone.
  61   }
  62 }
  63 
  64 void Klass::set_name(Symbol* n) {
  65   _name = n;
  66   if (_name != NULL) _name->increment_refcount();
  67 }
  68 


 424     }
 425     current->set_next_sibling(sibling);
 426     if (sibling != NULL) {
 427       stack.push(sibling);
 428     }
 429 
 430     // Clean the implementors list and method data.
 431     if (clean_alive_klasses && current->is_instance_klass()) {
 432       InstanceKlass* ik = InstanceKlass::cast(current);
 433       ik->clean_weak_instanceklass_links(is_alive);
 434 
 435       // JVMTI RedefineClasses creates previous versions that are not in
 436       // the class hierarchy, so process them here.
 437       while ((ik = ik->previous_versions()) != NULL) {
 438         ik->clean_weak_instanceklass_links(is_alive);
 439       }
 440     }
 441   }
 442 }
 443 
 444 void Klass::klass_update_barrier_set(oop v) {
 445   record_modified_oops();
 446 }
 447 
 448 // This barrier is used by G1 to remember the old oop values, so
 449 // that we don't forget any objects that were live at the snapshot at
 450 // the beginning. This function is only used when we write oops into Klasses.
 451 void Klass::klass_update_barrier_set_pre(oop* p, oop v) {
 452 #if INCLUDE_ALL_GCS
 453   if (UseG1GC) {
 454     oop obj = *p;
 455     if (obj != NULL) {
 456       G1SATBCardTableModRefBS::enqueue(obj);
 457     }
 458   }
 459 #endif
 460 }
 461 
 462 void Klass::klass_oop_store(oop* p, oop v) {
 463   assert(!Universe::heap()->is_in_reserved((void*)p), "Should store pointer into metadata");
 464   assert(v == NULL || Universe::heap()->is_in_reserved((void*)v), "Should store pointer to an object");
 465 
 466   // do the store
 467   if (always_do_update_barrier) {
 468     klass_oop_store((volatile oop*)p, v);
 469   } else {
 470     klass_update_barrier_set_pre(p, v);
 471     *p = v;
 472     klass_update_barrier_set(v);
 473   }
 474 }
 475 
 476 void Klass::klass_oop_store(volatile oop* p, oop v) {
 477   assert(!Universe::heap()->is_in_reserved((void*)p), "Should store pointer into metadata");
 478   assert(v == NULL || Universe::heap()->is_in_reserved((void*)v), "Should store pointer to an object");
 479 
 480   klass_update_barrier_set_pre((oop*)p, v); // Cast away volatile.
 481   OrderAccess::release_store_ptr(p, v);
 482   klass_update_barrier_set(v);
 483 }
 484 
 485 void Klass::oops_do(OopClosure* cl) {
 486   cl->do_oop(&_java_mirror);
 487 }
 488 
 489 void Klass::metaspace_pointers_do(MetaspaceClosure* it) {
 490   if (log_is_enabled(Trace, cds)) {
 491     ResourceMark rm;
 492     log_trace(cds)("Iter(Klass): %p (%s)", this, external_name());
 493   }
 494 
 495   it->push(&_name);
 496   it->push(&_secondary_super_cache);
 497   it->push(&_secondary_supers);
 498   for (int i = 0; i < _primary_super_limit; i++) {
 499     it->push(&_primary_supers[i]);
 500   }
 501   it->push(&_super);
 502   it->push(&_subklass);
 503   it->push(&_next_sibling);
 504   it->push(&_next_link);
 505 
 506   vtableEntry* vt = start_of_vtable();
 507   for (int i=0; i<vtable_length(); i++) {
 508     it->push(vt[i].method_addr());


 515   if (log_is_enabled(Trace, cds, unshareable)) {
 516     ResourceMark rm;
 517     log_trace(cds, unshareable)("remove: %s", external_name());
 518   }
 519 
 520   set_subklass(NULL);
 521   set_next_sibling(NULL);
 522   set_next_link(NULL);
 523 
 524   // Null out class_loader_data because we don't share that yet.
 525   set_class_loader_data(NULL);
 526   set_is_shared();
 527 }
 528 
 529 void Klass::remove_java_mirror() {
 530   assert (DumpSharedSpaces, "only called for DumpSharedSpaces");
 531   if (log_is_enabled(Trace, cds, unshareable)) {
 532     ResourceMark rm;
 533     log_trace(cds, unshareable)("remove java_mirror: %s", external_name());
 534   }
 535   set_java_mirror(NULL);

 536 }
 537 
 538 void Klass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS) {
 539   assert(is_klass(), "ensure C++ vtable is restored");
 540   assert(is_shared(), "must be set");
 541   TRACE_RESTORE_ID(this);
 542   if (log_is_enabled(Trace, cds, unshareable)) {
 543     ResourceMark rm;
 544     log_trace(cds, unshareable)("restore: %s", external_name());
 545   }
 546 
 547   // If an exception happened during CDS restore, some of these fields may already be
 548   // set.  We leave the class on the CLD list, even if incomplete so that we don't
 549   // modify the CLD list outside a safepoint.
 550   if (class_loader_data() == NULL) {
 551     // Restore class_loader_data to the null class loader data
 552     set_class_loader_data(loader_data);
 553 
 554     // Add to null class loader list first before creating the mirror
 555     // (same order as class file parsing)




  26 #include "classfile/dictionary.hpp"
  27 #include "classfile/javaClasses.hpp"
  28 #include "classfile/systemDictionary.hpp"
  29 #include "classfile/vmSymbols.hpp"
  30 #include "gc/shared/collectedHeap.inline.hpp"
  31 #include "logging/log.hpp"
  32 #include "memory/heapInspection.hpp"
  33 #include "memory/metadataFactory.hpp"
  34 #include "memory/metaspaceClosure.hpp"
  35 #include "memory/metaspaceShared.hpp"
  36 #include "memory/oopFactory.hpp"
  37 #include "memory/resourceArea.hpp"
  38 #include "oops/instanceKlass.hpp"
  39 #include "oops/klass.inline.hpp"
  40 #include "oops/oop.inline.hpp"
  41 #include "runtime/atomic.hpp"
  42 #include "runtime/orderAccess.inline.hpp"
  43 #include "trace/traceMacros.hpp"
  44 #include "utilities/macros.hpp"
  45 #include "utilities/stack.inline.hpp"
  46 
  47 void Klass::set_java_mirror(Handle m) {
  48   if (m.is_null()) {
  49     _java_mirror = NULL;
  50   } else {
  51     _java_mirror = class_loader_data()->add_handle(m);
  52   }
  53 }
  54 
  55 oop Klass::java_mirror() const {
  56   return _java_mirror.resolve();
  57 }
  58 
  59 bool Klass::is_cloneable() const {
  60   return _access_flags.is_cloneable_fast() ||
  61          is_subtype_of(SystemDictionary::Cloneable_klass());
  62 }
  63 
  64 void Klass::set_is_cloneable() {
  65   if (name() != vmSymbols::java_lang_invoke_MemberName()) {
  66     _access_flags.set_is_cloneable_fast();
  67   } else {
  68     assert(is_final(), "no subclasses allowed");
  69     // MemberName cloning should not be intrinsified and always happen in JVM_Clone.
  70   }
  71 }
  72 
  73 void Klass::set_name(Symbol* n) {
  74   _name = n;
  75   if (_name != NULL) _name->increment_refcount();
  76 }
  77 


 433     }
 434     current->set_next_sibling(sibling);
 435     if (sibling != NULL) {
 436       stack.push(sibling);
 437     }
 438 
 439     // Clean the implementors list and method data.
 440     if (clean_alive_klasses && current->is_instance_klass()) {
 441       InstanceKlass* ik = InstanceKlass::cast(current);
 442       ik->clean_weak_instanceklass_links(is_alive);
 443 
 444       // JVMTI RedefineClasses creates previous versions that are not in
 445       // the class hierarchy, so process them here.
 446       while ((ik = ik->previous_versions()) != NULL) {
 447         ik->clean_weak_instanceklass_links(is_alive);
 448       }
 449     }
 450   }
 451 }
 452 













































 453 void Klass::metaspace_pointers_do(MetaspaceClosure* it) {
 454   if (log_is_enabled(Trace, cds)) {
 455     ResourceMark rm;
 456     log_trace(cds)("Iter(Klass): %p (%s)", this, external_name());
 457   }
 458 
 459   it->push(&_name);
 460   it->push(&_secondary_super_cache);
 461   it->push(&_secondary_supers);
 462   for (int i = 0; i < _primary_super_limit; i++) {
 463     it->push(&_primary_supers[i]);
 464   }
 465   it->push(&_super);
 466   it->push(&_subklass);
 467   it->push(&_next_sibling);
 468   it->push(&_next_link);
 469 
 470   vtableEntry* vt = start_of_vtable();
 471   for (int i=0; i<vtable_length(); i++) {
 472     it->push(vt[i].method_addr());


 479   if (log_is_enabled(Trace, cds, unshareable)) {
 480     ResourceMark rm;
 481     log_trace(cds, unshareable)("remove: %s", external_name());
 482   }
 483 
 484   set_subklass(NULL);
 485   set_next_sibling(NULL);
 486   set_next_link(NULL);
 487 
 488   // Null out class_loader_data because we don't share that yet.
 489   set_class_loader_data(NULL);
 490   set_is_shared();
 491 }
 492 
 493 void Klass::remove_java_mirror() {
 494   assert (DumpSharedSpaces, "only called for DumpSharedSpaces");
 495   if (log_is_enabled(Trace, cds, unshareable)) {
 496     ResourceMark rm;
 497     log_trace(cds, unshareable)("remove java_mirror: %s", external_name());
 498   }
 499   // Just null out the mirror.  The class_loader_data() no longer exists.
 500   _java_mirror = NULL;
 501 }
 502 
 503 void Klass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS) {
 504   assert(is_klass(), "ensure C++ vtable is restored");
 505   assert(is_shared(), "must be set");
 506   TRACE_RESTORE_ID(this);
 507   if (log_is_enabled(Trace, cds, unshareable)) {
 508     ResourceMark rm;
 509     log_trace(cds, unshareable)("restore: %s", external_name());
 510   }
 511 
 512   // If an exception happened during CDS restore, some of these fields may already be
 513   // set.  We leave the class on the CLD list, even if incomplete so that we don't
 514   // modify the CLD list outside a safepoint.
 515   if (class_loader_data() == NULL) {
 516     // Restore class_loader_data to the null class loader data
 517     set_class_loader_data(loader_data);
 518 
 519     // Add to null class loader list first before creating the mirror
 520     // (same order as class file parsing)


< prev index next >