< prev index next >

src/share/vm/oops/klass.cpp

Print this page


  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  */
  24 
  25 #include "precompiled.hpp"
  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/oopFactory.hpp"
  35 #include "memory/resourceArea.hpp"
  36 #include "oops/instanceKlass.hpp"
  37 #include "oops/klass.inline.hpp"
  38 #include "oops/oop.inline.hpp"
  39 #include "runtime/atomic.hpp"
  40 #include "runtime/orderAccess.inline.hpp"
  41 #include "trace/traceMacros.hpp"
  42 #include "utilities/macros.hpp"
  43 #include "utilities/stack.inline.hpp"
  44 #if INCLUDE_ALL_GCS
  45 #include "gc/g1/g1SATBCardTableModRefBS.hpp"
  46 #endif // INCLUDE_ALL_GCS
  47 
  48 bool Klass::is_cloneable() const {
  49   return _access_flags.is_cloneable_fast() ||
  50          is_subtype_of(SystemDictionary::Cloneable_klass());
  51 }
  52 
  53 void Klass::set_is_cloneable() {


 145 #ifdef ASSERT
 146   tty->print_cr("Error: find_field called on a klass oop."
 147                 " Likely error: reflection method does not correctly"
 148                 " wrap return value in a mirror object.");
 149 #endif
 150   ShouldNotReachHere();
 151   return NULL;
 152 }
 153 
 154 Method* Klass::uncached_lookup_method(const Symbol* name, const Symbol* signature, OverpassLookupMode overpass_mode) const {
 155 #ifdef ASSERT
 156   tty->print_cr("Error: uncached_lookup_method called on a klass oop."
 157                 " Likely error: reflection method does not correctly"
 158                 " wrap return value in a mirror object.");
 159 #endif
 160   ShouldNotReachHere();
 161   return NULL;
 162 }
 163 
 164 void* Klass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw() {
 165   return Metaspace::allocate(loader_data, word_size, /*read_only*/false,
 166                              MetaspaceObj::ClassType, THREAD);
 167 }
 168 
 169 // "Normal" instantiation is preceeded by a MetaspaceObj allocation
 170 // which zeros out memory - calloc equivalent.
 171 // The constructor is also used from CppVtableCloner,
 172 // which doesn't zero out the memory before calling the constructor.
 173 // Need to set the _java_mirror field explicitly to not hit an assert that the field
 174 // should be NULL before setting it.
 175 Klass::Klass() : _prototype_header(markOopDesc::prototype()),
 176                  _shared_class_path_index(-1),
 177                  _java_mirror(NULL) {
 178 
 179   _primary_supers[0] = this;
 180   set_super_check_offset(in_bytes(primary_supers_offset()));
 181 }
 182 
 183 jint Klass::array_layout_helper(BasicType etype) {
 184   assert(etype >= T_BOOLEAN && etype <= T_OBJECT, "valid etype");
 185   // Note that T_ARRAY is not allowed here.
 186   int  hsize = arrayOopDesc::base_offset_in_bytes(etype);


 466   if (always_do_update_barrier) {
 467     klass_oop_store((volatile oop*)p, v);
 468   } else {
 469     klass_update_barrier_set_pre(p, v);
 470     *p = v;
 471     klass_update_barrier_set(v);
 472   }
 473 }
 474 
 475 void Klass::klass_oop_store(volatile oop* p, oop v) {
 476   assert(!Universe::heap()->is_in_reserved((void*)p), "Should store pointer into metadata");
 477   assert(v == NULL || Universe::heap()->is_in_reserved((void*)v), "Should store pointer to an object");
 478 
 479   klass_update_barrier_set_pre((oop*)p, v); // Cast away volatile.
 480   OrderAccess::release_store_ptr(p, v);
 481   klass_update_barrier_set(v);
 482 }
 483 
 484 void Klass::oops_do(OopClosure* cl) {
 485   cl->do_oop(&_java_mirror);























 486 }
 487 
 488 void Klass::remove_unshareable_info() {
 489   assert (DumpSharedSpaces, "only called for DumpSharedSpaces");
 490   TRACE_REMOVE_ID(this);
 491 
 492   set_subklass(NULL);
 493   set_next_sibling(NULL);
 494   // Clear the java mirror
 495   set_java_mirror(NULL);
 496   set_next_link(NULL);
 497 
 498   // Null out class_loader_data because we don't share that yet.
 499   set_class_loader_data(NULL);
 500   set_is_shared();
 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");




  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  */
  24 
  25 #include "precompiled.hpp"
  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() {


 147 #ifdef ASSERT
 148   tty->print_cr("Error: find_field called on a klass oop."
 149                 " Likely error: reflection method does not correctly"
 150                 " wrap return value in a mirror object.");
 151 #endif
 152   ShouldNotReachHere();
 153   return NULL;
 154 }
 155 
 156 Method* Klass::uncached_lookup_method(const Symbol* name, const Symbol* signature, OverpassLookupMode overpass_mode) const {
 157 #ifdef ASSERT
 158   tty->print_cr("Error: uncached_lookup_method called on a klass oop."
 159                 " Likely error: reflection method does not correctly"
 160                 " wrap return value in a mirror object.");
 161 #endif
 162   ShouldNotReachHere();
 163   return NULL;
 164 }
 165 
 166 void* Klass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw() {
 167   return Metaspace::allocate(loader_data, word_size, MetaspaceObj::ClassType, THREAD);

 168 }
 169 
 170 // "Normal" instantiation is preceeded by a MetaspaceObj allocation
 171 // which zeros out memory - calloc equivalent.
 172 // The constructor is also used from CppVtableCloner,
 173 // which doesn't zero out the memory before calling the constructor.
 174 // Need to set the _java_mirror field explicitly to not hit an assert that the field
 175 // should be NULL before setting it.
 176 Klass::Klass() : _prototype_header(markOopDesc::prototype()),
 177                  _shared_class_path_index(-1),
 178                  _java_mirror(NULL) {
 179 
 180   _primary_supers[0] = this;
 181   set_super_check_offset(in_bytes(primary_supers_offset()));
 182 }
 183 
 184 jint Klass::array_layout_helper(BasicType etype) {
 185   assert(etype >= T_BOOLEAN && etype <= T_OBJECT, "valid etype");
 186   // Note that T_ARRAY is not allowed here.
 187   int  hsize = arrayOopDesc::base_offset_in_bytes(etype);


 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());
 509   }
 510 }
 511 
 512 void Klass::remove_unshareable_info() {
 513   assert (DumpSharedSpaces, "only called for DumpSharedSpaces");
 514   TRACE_REMOVE_ID(this);
 515 
 516   set_subklass(NULL);
 517   set_next_sibling(NULL);
 518   // Clear the java mirror
 519   set_java_mirror(NULL);
 520   set_next_link(NULL);
 521 
 522   // Null out class_loader_data because we don't share that yet.
 523   set_class_loader_data(NULL);
 524   set_is_shared();
 525 }
 526 
 527 void Klass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS) {
 528   assert(is_klass(), "ensure C++ vtable is restored");
 529   assert(is_shared(), "must be set");


< prev index next >