187 " Likely error: reflection method does not correctly"
188 " wrap return value in a mirror object.");
189 #endif
190 ShouldNotReachHere();
191 return nullptr;
192 }
193
194 void* Klass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw() {
195 return Metaspace::allocate(loader_data, word_size, MetaspaceObj::ClassType, THREAD);
196 }
197
198 Klass::Klass() : _kind(UnknownKlassKind) {
199 assert(CDSConfig::is_dumping_static_archive() || UseSharedSpaces, "only for cds");
200 }
201
202 // "Normal" instantiation is preceded by a MetaspaceObj allocation
203 // which zeros out memory - calloc equivalent.
204 // The constructor is also used from CppVtableCloner,
205 // which doesn't zero out the memory before calling the constructor.
206 Klass::Klass(KlassKind kind) : _kind(kind),
207 _shared_class_path_index(-1) {
208 CDS_ONLY(_shared_class_flags = 0;)
209 CDS_JAVA_HEAP_ONLY(_archived_mirror_index = -1;)
210 _primary_supers[0] = this;
211 set_super_check_offset(in_bytes(primary_supers_offset()));
212 }
213
214 jint Klass::array_layout_helper(BasicType etype) {
215 assert(etype >= T_BOOLEAN && etype <= T_OBJECT, "valid etype");
216 // Note that T_ARRAY is not allowed here.
217 int hsize = arrayOopDesc::base_offset_in_bytes(etype);
218 int esize = type2aelembytes(etype);
219 bool isobj = (etype == T_OBJECT);
220 int tag = isobj ? _lh_array_tag_obj_value : _lh_array_tag_type_value;
221 int lh = array_layout_helper(tag, hsize, etype, exact_log2(esize));
222
223 assert(lh < (int)_lh_neutral_value, "must look like an array layout");
224 assert(layout_helper_is_array(lh), "correct kind");
225 assert(layout_helper_is_objArray(lh) == isobj, "correct kind");
226 assert(layout_helper_is_typeArray(lh) == !isobj, "correct kind");
227 assert(layout_helper_header_size(lh) == hsize, "correct decode");
228 assert(layout_helper_element_type(lh) == etype, "correct decode");
229 assert(1 << layout_helper_log2_element_size(lh) == esize, "correct decode");
230
231 return lh;
232 }
233
234 bool Klass::can_be_primary_super_slow() const {
235 if (super() == nullptr)
236 return true;
237 else if (super()->super_depth() >= primary_super_limit()-1)
238 return false;
239 else
240 return true;
241 }
733 void Klass::print_on(outputStream* st) const {
734 ResourceMark rm;
735 // print title
736 st->print("%s", internal_name());
737 print_address_on(st);
738 st->cr();
739 }
740
741 #define BULLET " - "
742
743 // Caller needs ResourceMark
744 void Klass::oop_print_on(oop obj, outputStream* st) {
745 // print title
746 st->print_cr("%s ", internal_name());
747 obj->print_address_on(st);
748
749 if (WizardMode) {
750 // print header
751 obj->mark().print_on(st);
752 st->cr();
753 }
754
755 // print class
756 st->print(BULLET"klass: ");
757 obj->klass()->print_value_on(st);
758 st->cr();
759 }
760
761 void Klass::oop_print_value_on(oop obj, outputStream* st) {
762 // print title
763 ResourceMark rm; // Cannot print in debug mode without this
764 st->print("%s", internal_name());
765 obj->print_address_on(st);
766 }
767
768 // Verification
769
770 void Klass::verify_on(outputStream* st) {
771
772 // This can be expensive, but it is worth checking that this klass is actually
|
187 " Likely error: reflection method does not correctly"
188 " wrap return value in a mirror object.");
189 #endif
190 ShouldNotReachHere();
191 return nullptr;
192 }
193
194 void* Klass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw() {
195 return Metaspace::allocate(loader_data, word_size, MetaspaceObj::ClassType, THREAD);
196 }
197
198 Klass::Klass() : _kind(UnknownKlassKind) {
199 assert(CDSConfig::is_dumping_static_archive() || UseSharedSpaces, "only for cds");
200 }
201
202 // "Normal" instantiation is preceded by a MetaspaceObj allocation
203 // which zeros out memory - calloc equivalent.
204 // The constructor is also used from CppVtableCloner,
205 // which doesn't zero out the memory before calling the constructor.
206 Klass::Klass(KlassKind kind) : _kind(kind),
207 _prototype_header(markWord::prototype()),
208 _shared_class_path_index(-1) {
209 CDS_ONLY(_shared_class_flags = 0;)
210 CDS_JAVA_HEAP_ONLY(_archived_mirror_index = -1;)
211 _primary_supers[0] = this;
212 set_super_check_offset(in_bytes(primary_supers_offset()));
213 }
214
215 jint Klass::array_layout_helper(BasicType etype) {
216 assert(etype >= T_BOOLEAN && etype <= T_OBJECT, "valid etype");
217 // Note that T_ARRAY is not allowed here.
218 int hsize = arrayOopDesc::base_offset_in_bytes(etype);
219 int esize = type2aelembytes(etype);
220 bool isobj = (etype == T_OBJECT);
221 int tag = isobj ? _lh_array_tag_obj_value : _lh_array_tag_type_value;
222 int lh = array_layout_helper(tag, false, hsize, etype, exact_log2(esize));
223
224 assert(lh < (int)_lh_neutral_value, "must look like an array layout");
225 assert(layout_helper_is_array(lh), "correct kind");
226 assert(layout_helper_is_objArray(lh) == isobj, "correct kind");
227 assert(layout_helper_is_typeArray(lh) == !isobj, "correct kind");
228 assert(layout_helper_header_size(lh) == hsize, "correct decode");
229 assert(layout_helper_element_type(lh) == etype, "correct decode");
230 assert(1 << layout_helper_log2_element_size(lh) == esize, "correct decode");
231
232 return lh;
233 }
234
235 bool Klass::can_be_primary_super_slow() const {
236 if (super() == nullptr)
237 return true;
238 else if (super()->super_depth() >= primary_super_limit()-1)
239 return false;
240 else
241 return true;
242 }
734 void Klass::print_on(outputStream* st) const {
735 ResourceMark rm;
736 // print title
737 st->print("%s", internal_name());
738 print_address_on(st);
739 st->cr();
740 }
741
742 #define BULLET " - "
743
744 // Caller needs ResourceMark
745 void Klass::oop_print_on(oop obj, outputStream* st) {
746 // print title
747 st->print_cr("%s ", internal_name());
748 obj->print_address_on(st);
749
750 if (WizardMode) {
751 // print header
752 obj->mark().print_on(st);
753 st->cr();
754 st->print(BULLET"prototype_header: " INTPTR_FORMAT, _prototype_header.value());
755 st->cr();
756 }
757
758 // print class
759 st->print(BULLET"klass: ");
760 obj->klass()->print_value_on(st);
761 st->cr();
762 }
763
764 void Klass::oop_print_value_on(oop obj, outputStream* st) {
765 // print title
766 ResourceMark rm; // Cannot print in debug mode without this
767 st->print("%s", internal_name());
768 obj->print_address_on(st);
769 }
770
771 // Verification
772
773 void Klass::verify_on(outputStream* st) {
774
775 // This can be expensive, but it is worth checking that this klass is actually
|