< prev index next >

src/hotspot/share/oops/klass.cpp

Print this page

 257   tty->print_cr("Error: find_field called on a klass oop."
 258                 " Likely error: reflection method does not correctly"
 259                 " wrap return value in a mirror object.");
 260 #endif
 261   ShouldNotReachHere();
 262   return nullptr;
 263 }
 264 
 265 Method* Klass::uncached_lookup_method(const Symbol* name, const Symbol* signature,
 266                                       OverpassLookupMode overpass_mode,
 267                                       PrivateLookupMode private_mode) const {
 268 #ifdef ASSERT
 269   tty->print_cr("Error: uncached_lookup_method called on a klass oop."
 270                 " Likely error: reflection method does not correctly"
 271                 " wrap return value in a mirror object.");
 272 #endif
 273   ShouldNotReachHere();
 274   return nullptr;
 275 }
 276 
 277 static markWord make_prototype(const Klass* kls) {
 278   markWord prototype = markWord::prototype();
 279 #ifdef _LP64
 280   if (UseCompactObjectHeaders) {
 281     // With compact object headers, the narrow Klass ID is part of the mark word.
 282     // We therefore seed the mark word with the narrow Klass ID.
 283     precond(CompressedKlassPointers::is_encodable(kls));
 284     const narrowKlass nk = CompressedKlassPointers::encode(const_cast<Klass*>(kls));
 285     prototype = prototype.set_narrow_klass(nk);
 286   }
 287 #endif
 288   return prototype;
 289 }
 290 
 291 void* Klass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw() {
 292   return Metaspace::allocate(loader_data, word_size, MetaspaceObj::ClassType, THREAD);
 293 }
 294 
 295 Klass::Klass() : _kind(UnknownKlassKind) {
 296   assert(CDSConfig::is_dumping_static_archive() || CDSConfig::is_using_archive(), "only for cds");
 297 }
 298 
 299 // "Normal" instantiation is preceded by a MetaspaceObj allocation
 300 // which zeros out memory - calloc equivalent.
 301 // The constructor is also used from CppVtableCloner,
 302 // which doesn't zero out the memory before calling the constructor.
 303 Klass::Klass(KlassKind kind) : _kind(kind),
 304                                _prototype_header(make_prototype(this)),
 305                                _shared_class_path_index(-1) {

 306   CDS_ONLY(_aot_class_flags = 0;)
 307   CDS_JAVA_HEAP_ONLY(_archived_mirror_index = -1;)
 308   _primary_supers[0] = this;
 309   set_super_check_offset(in_bytes(primary_supers_offset()));
 310 }
 311 
 312 jint Klass::array_layout_helper(BasicType etype) {
 313   assert(etype >= T_BOOLEAN && etype <= T_OBJECT, "valid etype");
 314   // Note that T_ARRAY is not allowed here.
 315   int  hsize = arrayOopDesc::base_offset_in_bytes(etype);
 316   int  esize = type2aelembytes(etype);
 317   bool isobj = (etype == T_OBJECT);
 318   int  tag   =  isobj ? _lh_array_tag_obj_value : _lh_array_tag_type_value;
 319   int lh = array_layout_helper(tag, hsize, etype, exact_log2(esize));
 320 
 321   assert(lh < (int)_lh_neutral_value, "must look like an array layout");
 322   assert(layout_helper_is_array(lh), "correct kind");
 323   assert(layout_helper_is_objArray(lh) == isobj, "correct kind");
 324   assert(layout_helper_is_typeArray(lh) == !isobj, "correct kind");
 325   assert(layout_helper_header_size(lh) == hsize, "correct decode");
 326   assert(layout_helper_element_type(lh) == etype, "correct decode");
 327   assert(1 << layout_helper_log2_element_size(lh) == esize, "correct decode");
 328 
 329   return lh;
 330 }
 331 
 332 int Klass::modifier_flags() const {
 333   int mods = java_lang_Class::modifiers(java_mirror());
 334   assert(mods == compute_modifier_flags(), "should be same");
 335   return mods;
 336 }
 337 
 338 bool Klass::can_be_primary_super_slow() const {
 339   if (super() == nullptr)
 340     return true;
 341   else if (super()->super_depth() >= primary_super_limit()-1)
 342     return false;
 343   else

1014 void Klass::print_on(outputStream* st) const {
1015   ResourceMark rm;
1016   // print title
1017   st->print("%s", internal_name());
1018   print_address_on(st);
1019   st->cr();
1020 }
1021 
1022 #define BULLET  " - "
1023 
1024 // Caller needs ResourceMark
1025 void Klass::oop_print_on(oop obj, outputStream* st) {
1026   // print title
1027   st->print_cr("%s ", internal_name());
1028   obj->print_address_on(st);
1029 
1030   if (WizardMode) {
1031      // print header
1032      obj->mark().print_on(st);
1033      st->cr();
1034      if (UseCompactObjectHeaders) {
1035        st->print(BULLET"prototype_header: " INTPTR_FORMAT, _prototype_header.value());
1036        st->cr();
1037      }
1038   }
1039 
1040   // print class
1041   st->print(BULLET"klass: ");
1042   obj->klass()->print_value_on(st);
1043   st->print(BULLET"flags: "); _misc_flags.print_on(st); st->cr();
1044   st->cr();
1045 }
1046 
1047 void Klass::oop_print_value_on(oop obj, outputStream* st) {
1048   // print title
1049   ResourceMark rm;              // Cannot print in debug mode without this
1050   st->print("%s", internal_name());
1051   obj->print_address_on(st);
1052 }
1053 
1054 // Verification
1055 
1056 void Klass::verify_on(outputStream* st) {
1057 

 257   tty->print_cr("Error: find_field called on a klass oop."
 258                 " Likely error: reflection method does not correctly"
 259                 " wrap return value in a mirror object.");
 260 #endif
 261   ShouldNotReachHere();
 262   return nullptr;
 263 }
 264 
 265 Method* Klass::uncached_lookup_method(const Symbol* name, const Symbol* signature,
 266                                       OverpassLookupMode overpass_mode,
 267                                       PrivateLookupMode private_mode) const {
 268 #ifdef ASSERT
 269   tty->print_cr("Error: uncached_lookup_method called on a klass oop."
 270                 " Likely error: reflection method does not correctly"
 271                 " wrap return value in a mirror object.");
 272 #endif
 273   ShouldNotReachHere();
 274   return nullptr;
 275 }
 276 














 277 void* Klass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw() {
 278   return Metaspace::allocate(loader_data, word_size, MetaspaceObj::ClassType, THREAD);
 279 }
 280 
 281 Klass::Klass() : _kind(UnknownKlassKind) {
 282   assert(CDSConfig::is_dumping_static_archive() || CDSConfig::is_using_archive(), "only for cds");
 283 }
 284 
 285 // "Normal" instantiation is preceded by a MetaspaceObj allocation
 286 // which zeros out memory - calloc equivalent.
 287 // The constructor is also used from CppVtableCloner,
 288 // which doesn't zero out the memory before calling the constructor.
 289 Klass::Klass(KlassKind kind, markWord prototype_header) : _kind(kind),

 290                                _shared_class_path_index(-1) {
 291   set_prototype_header(make_prototype_header(this, prototype_header));
 292   CDS_ONLY(_aot_class_flags = 0;)
 293   CDS_JAVA_HEAP_ONLY(_archived_mirror_index = -1;)
 294   _primary_supers[0] = this;
 295   set_super_check_offset(in_bytes(primary_supers_offset()));
 296 }
 297 
 298 jint Klass::array_layout_helper(BasicType etype) {
 299   assert(etype >= T_BOOLEAN && etype <= T_OBJECT, "valid etype");
 300   // Note that T_ARRAY is not allowed here.
 301   int  hsize = arrayOopDesc::base_offset_in_bytes(etype);
 302   int  esize = type2aelembytes(etype);
 303   bool isobj = (etype == T_OBJECT);
 304   int  tag   =  isobj ? _lh_array_tag_ref_value : _lh_array_tag_type_value;
 305   int lh = array_layout_helper(tag, false, hsize, etype, exact_log2(esize));
 306 
 307   assert(lh < (int)_lh_neutral_value, "must look like an array layout");
 308   assert(layout_helper_is_array(lh), "correct kind");
 309   assert(layout_helper_is_refArray(lh) == isobj, "correct kind");
 310   assert(layout_helper_is_typeArray(lh) == !isobj, "correct kind");
 311   assert(layout_helper_header_size(lh) == hsize, "correct decode");
 312   assert(layout_helper_element_type(lh) == etype, "correct decode");
 313   assert(1 << layout_helper_log2_element_size(lh) == esize, "correct decode");
 314 
 315   return lh;
 316 }
 317 
 318 int Klass::modifier_flags() const {
 319   int mods = java_lang_Class::modifiers(java_mirror());
 320   assert(mods == compute_modifier_flags(), "should be same");
 321   return mods;
 322 }
 323 
 324 bool Klass::can_be_primary_super_slow() const {
 325   if (super() == nullptr)
 326     return true;
 327   else if (super()->super_depth() >= primary_super_limit()-1)
 328     return false;
 329   else

1000 void Klass::print_on(outputStream* st) const {
1001   ResourceMark rm;
1002   // print title
1003   st->print("%s", internal_name());
1004   print_address_on(st);
1005   st->cr();
1006 }
1007 
1008 #define BULLET  " - "
1009 
1010 // Caller needs ResourceMark
1011 void Klass::oop_print_on(oop obj, outputStream* st) {
1012   // print title
1013   st->print_cr("%s ", internal_name());
1014   obj->print_address_on(st);
1015 
1016   if (WizardMode) {
1017      // print header
1018      obj->mark().print_on(st);
1019      st->cr();
1020      st->print(BULLET"prototype_header: " INTPTR_FORMAT, _prototype_header.value());
1021      st->cr();


1022   }
1023 
1024   // print class
1025   st->print(BULLET"klass: ");
1026   obj->klass()->print_value_on(st);
1027   st->print(BULLET"flags: "); _misc_flags.print_on(st); st->cr();
1028   st->cr();
1029 }
1030 
1031 void Klass::oop_print_value_on(oop obj, outputStream* st) {
1032   // print title
1033   ResourceMark rm;              // Cannot print in debug mode without this
1034   st->print("%s", internal_name());
1035   obj->print_address_on(st);
1036 }
1037 
1038 // Verification
1039 
1040 void Klass::verify_on(outputStream* st) {
1041 
< prev index next >