< prev index next >

src/hotspot/share/oops/klass.cpp

Print this page

 31 #include "classfile/moduleEntry.hpp"
 32 #include "classfile/systemDictionary.hpp"
 33 #include "classfile/systemDictionaryShared.hpp"
 34 #include "classfile/vmClasses.hpp"
 35 #include "classfile/vmSymbols.hpp"
 36 #include "gc/shared/collectedHeap.inline.hpp"
 37 #include "logging/log.hpp"
 38 #include "memory/metadataFactory.hpp"
 39 #include "memory/metaspaceClosure.hpp"
 40 #include "memory/oopFactory.hpp"
 41 #include "memory/resourceArea.hpp"
 42 #include "memory/universe.hpp"
 43 #include "oops/compressedOops.inline.hpp"
 44 #include "oops/instanceKlass.hpp"
 45 #include "oops/klass.inline.hpp"
 46 #include "oops/oop.inline.hpp"
 47 #include "oops/oopHandle.inline.hpp"
 48 #include "prims/jvmtiExport.hpp"
 49 #include "runtime/arguments.hpp"
 50 #include "runtime/atomic.hpp"

 51 #include "runtime/handles.inline.hpp"

 52 #include "utilities/macros.hpp"
 53 #include "utilities/powerOfTwo.hpp"
 54 #include "utilities/stack.inline.hpp"
 55 
 56 void Klass::set_java_mirror(Handle m) {
 57   assert(!m.is_null(), "New mirror should never be null.");
 58   assert(_java_mirror.is_empty(), "should only be used to initialize mirror");
 59   _java_mirror = class_loader_data()->add_handle(m);
 60 }
 61 
 62 oop Klass::java_mirror_no_keepalive() const {
 63   return _java_mirror.peek();
 64 }
 65 
 66 void Klass::replace_java_mirror(oop mirror) {
 67   _java_mirror.replace(mirror);
 68 }
 69 
 70 bool Klass::is_cloneable() const {
 71   return _access_flags.is_cloneable_fast() ||

177                 " Likely error: reflection method does not correctly"
178                 " wrap return value in a mirror object.");
179 #endif
180   ShouldNotReachHere();
181   return NULL;
182 }
183 
184 Method* Klass::uncached_lookup_method(const Symbol* name, const Symbol* signature,
185                                       OverpassLookupMode overpass_mode,
186                                       PrivateLookupMode private_mode) const {
187 #ifdef ASSERT
188   tty->print_cr("Error: uncached_lookup_method called on a klass oop."
189                 " Likely error: reflection method does not correctly"
190                 " wrap return value in a mirror object.");
191 #endif
192   ShouldNotReachHere();
193   return NULL;
194 }
195 
196 void* Klass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw() {
197   return Metaspace::allocate(loader_data, word_size, MetaspaceObj::ClassType, THREAD);


198 }
199 
200 // "Normal" instantiation is preceded by a MetaspaceObj allocation
201 // which zeros out memory - calloc equivalent.
202 // The constructor is also used from CppVtableCloner,
203 // which doesn't zero out the memory before calling the constructor.
204 Klass::Klass(KlassKind kind) : _kind(kind),

205                            _shared_class_path_index(-1) {
206   CDS_ONLY(_shared_class_flags = 0;)
207   CDS_JAVA_HEAP_ONLY(_archived_mirror_index = -1;)
208   _primary_supers[0] = this;
209   set_super_check_offset(in_bytes(primary_supers_offset()));
210 }
211 
212 jint Klass::array_layout_helper(BasicType etype) {
213   assert(etype >= T_BOOLEAN && etype <= T_OBJECT, "valid etype");
214   // Note that T_ARRAY is not allowed here.
215   int  hsize = arrayOopDesc::base_offset_in_bytes(etype);
216   int  esize = type2aelembytes(etype);
217   bool isobj = (etype == T_OBJECT);
218   int  tag   =  isobj ? _lh_array_tag_obj_value : _lh_array_tag_type_value;
219   int lh = array_layout_helper(tag, hsize, etype, exact_log2(esize));
220 
221   assert(lh < (int)_lh_neutral_value, "must look like an array layout");
222   assert(layout_helper_is_array(lh), "correct kind");
223   assert(layout_helper_is_objArray(lh) == isobj, "correct kind");
224   assert(layout_helper_is_typeArray(lh) == !isobj, "correct kind");

727 void Klass::print_on(outputStream* st) const {
728   ResourceMark rm;
729   // print title
730   st->print("%s", internal_name());
731   print_address_on(st);
732   st->cr();
733 }
734 
735 #define BULLET  " - "
736 
737 // Caller needs ResourceMark
738 void Klass::oop_print_on(oop obj, outputStream* st) {
739   // print title
740   st->print_cr("%s ", internal_name());
741   obj->print_address_on(st);
742 
743   if (WizardMode) {
744      // print header
745      obj->mark().print_on(st);
746      st->cr();


747   }
748 
749   // print class
750   st->print(BULLET"klass: ");
751   obj->klass()->print_value_on(st);
752   st->cr();
753 }
754 
755 void Klass::oop_print_value_on(oop obj, outputStream* st) {
756   // print title
757   ResourceMark rm;              // Cannot print in debug mode without this
758   st->print("%s", internal_name());
759   obj->print_address_on(st);
760 }
761 
762 // Verification
763 
764 void Klass::verify_on(outputStream* st) {
765 
766   // This can be expensive, but it is worth checking that this klass is actually
767   // in the CLD graph but not in production.
768   assert(Metaspace::contains((address)this), "Should be");
769 




770   guarantee(this->is_klass(),"should be klass");
771 
772   if (super() != NULL) {
773     guarantee(super()->is_klass(), "should be klass");
774   }
775   if (secondary_super_cache() != NULL) {
776     Klass* ko = secondary_super_cache();
777     guarantee(ko->is_klass(), "should be klass");
778   }
779   for ( uint i = 0; i < primary_super_limit(); i++ ) {
780     Klass* ko = _primary_supers[i];
781     if (ko != NULL) {
782       guarantee(ko->is_klass(), "should be klass");
783     }
784   }
785 
786   if (java_mirror_no_keepalive() != NULL) {
787     guarantee(oopDesc::is_oop(java_mirror_no_keepalive()), "should be instance");
788   }
789 }

 31 #include "classfile/moduleEntry.hpp"
 32 #include "classfile/systemDictionary.hpp"
 33 #include "classfile/systemDictionaryShared.hpp"
 34 #include "classfile/vmClasses.hpp"
 35 #include "classfile/vmSymbols.hpp"
 36 #include "gc/shared/collectedHeap.inline.hpp"
 37 #include "logging/log.hpp"
 38 #include "memory/metadataFactory.hpp"
 39 #include "memory/metaspaceClosure.hpp"
 40 #include "memory/oopFactory.hpp"
 41 #include "memory/resourceArea.hpp"
 42 #include "memory/universe.hpp"
 43 #include "oops/compressedOops.inline.hpp"
 44 #include "oops/instanceKlass.hpp"
 45 #include "oops/klass.inline.hpp"
 46 #include "oops/oop.inline.hpp"
 47 #include "oops/oopHandle.inline.hpp"
 48 #include "prims/jvmtiExport.hpp"
 49 #include "runtime/arguments.hpp"
 50 #include "runtime/atomic.hpp"
 51 #include "runtime/globals.hpp"
 52 #include "runtime/handles.inline.hpp"
 53 #include "utilities/align.hpp"
 54 #include "utilities/macros.hpp"
 55 #include "utilities/powerOfTwo.hpp"
 56 #include "utilities/stack.inline.hpp"
 57 
 58 void Klass::set_java_mirror(Handle m) {
 59   assert(!m.is_null(), "New mirror should never be null.");
 60   assert(_java_mirror.is_empty(), "should only be used to initialize mirror");
 61   _java_mirror = class_loader_data()->add_handle(m);
 62 }
 63 
 64 oop Klass::java_mirror_no_keepalive() const {
 65   return _java_mirror.peek();
 66 }
 67 
 68 void Klass::replace_java_mirror(oop mirror) {
 69   _java_mirror.replace(mirror);
 70 }
 71 
 72 bool Klass::is_cloneable() const {
 73   return _access_flags.is_cloneable_fast() ||

179                 " Likely error: reflection method does not correctly"
180                 " wrap return value in a mirror object.");
181 #endif
182   ShouldNotReachHere();
183   return NULL;
184 }
185 
186 Method* Klass::uncached_lookup_method(const Symbol* name, const Symbol* signature,
187                                       OverpassLookupMode overpass_mode,
188                                       PrivateLookupMode private_mode) const {
189 #ifdef ASSERT
190   tty->print_cr("Error: uncached_lookup_method called on a klass oop."
191                 " Likely error: reflection method does not correctly"
192                 " wrap return value in a mirror object.");
193 #endif
194   ShouldNotReachHere();
195   return NULL;
196 }
197 
198 void* Klass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw() {
199   MetaWord* p = Metaspace::allocate(loader_data, word_size, MetaspaceObj::ClassType, THREAD);
200   assert(is_aligned(p, KlassAlignmentInBytes), "metaspace returned badly aligned memory.");
201   return p;
202 }
203 
204 // "Normal" instantiation is preceded by a MetaspaceObj allocation
205 // which zeros out memory - calloc equivalent.
206 // The constructor is also used from CppVtableCloner,
207 // which doesn't zero out the memory before calling the constructor.
208 Klass::Klass(KlassKind kind) : _kind(kind),
209                            _prototype_header(markWord::prototype() LP64_ONLY(.set_klass(this))),
210                            _shared_class_path_index(-1) {
211   CDS_ONLY(_shared_class_flags = 0;)
212   CDS_JAVA_HEAP_ONLY(_archived_mirror_index = -1;)
213   _primary_supers[0] = this;
214   set_super_check_offset(in_bytes(primary_supers_offset()));
215 }
216 
217 jint Klass::array_layout_helper(BasicType etype) {
218   assert(etype >= T_BOOLEAN && etype <= T_OBJECT, "valid etype");
219   // Note that T_ARRAY is not allowed here.
220   int  hsize = arrayOopDesc::base_offset_in_bytes(etype);
221   int  esize = type2aelembytes(etype);
222   bool isobj = (etype == T_OBJECT);
223   int  tag   =  isobj ? _lh_array_tag_obj_value : _lh_array_tag_type_value;
224   int lh = array_layout_helper(tag, hsize, etype, exact_log2(esize));
225 
226   assert(lh < (int)_lh_neutral_value, "must look like an array layout");
227   assert(layout_helper_is_array(lh), "correct kind");
228   assert(layout_helper_is_objArray(lh) == isobj, "correct kind");
229   assert(layout_helper_is_typeArray(lh) == !isobj, "correct kind");

732 void Klass::print_on(outputStream* st) const {
733   ResourceMark rm;
734   // print title
735   st->print("%s", internal_name());
736   print_address_on(st);
737   st->cr();
738 }
739 
740 #define BULLET  " - "
741 
742 // Caller needs ResourceMark
743 void Klass::oop_print_on(oop obj, outputStream* st) {
744   // print title
745   st->print_cr("%s ", internal_name());
746   obj->print_address_on(st);
747 
748   if (WizardMode) {
749      // print header
750      obj->mark().print_on(st);
751      st->cr();
752      st->print(BULLET"prototype_header: " INTPTR_FORMAT, _prototype_header.value());
753      st->cr();
754   }
755 
756   // print class
757   st->print(BULLET"klass: ");
758   obj->klass()->print_value_on(st);
759   st->cr();
760 }
761 
762 void Klass::oop_print_value_on(oop obj, outputStream* st) {
763   // print title
764   ResourceMark rm;              // Cannot print in debug mode without this
765   st->print("%s", internal_name());
766   obj->print_address_on(st);
767 }
768 
769 // Verification
770 
771 void Klass::verify_on(outputStream* st) {
772 
773   // This can be expensive, but it is worth checking that this klass is actually
774   // in the CLD graph but not in production.
775   assert(Metaspace::contains((address)this), "Should be");
776 
777   if (UseCompressedClassPointers) {
778     assert(is_aligned(this, KlassAlignmentInBytes), "misaligned Klass structure");
779   }
780 
781   guarantee(this->is_klass(),"should be klass");
782 
783   if (super() != NULL) {
784     guarantee(super()->is_klass(), "should be klass");
785   }
786   if (secondary_super_cache() != NULL) {
787     Klass* ko = secondary_super_cache();
788     guarantee(ko->is_klass(), "should be klass");
789   }
790   for ( uint i = 0; i < primary_super_limit(); i++ ) {
791     Klass* ko = _primary_supers[i];
792     if (ko != NULL) {
793       guarantee(ko->is_klass(), "should be klass");
794     }
795   }
796 
797   if (java_mirror_no_keepalive() != NULL) {
798     guarantee(oopDesc::is_oop(java_mirror_no_keepalive()), "should be instance");
799   }
800 }
< prev index next >