< prev index next >

src/hotspot/share/oops/klass.cpp

Print this page

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

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

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

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














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

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

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


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