duke@435: /* acorn@4497: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" coleenp@4037: #include "classfile/javaClasses.hpp" coleenp@4037: #include "classfile/dictionary.hpp" stefank@2314: #include "classfile/systemDictionary.hpp" stefank@2314: #include "classfile/vmSymbols.hpp" coleenp@4037: #include "gc_implementation/shared/markSweep.inline.hpp" stefank@2314: #include "gc_interface/collectedHeap.inline.hpp" acorn@4497: #include "memory/heapInspection.hpp" coleenp@4037: #include "memory/metadataFactory.hpp" stefank@2314: #include "memory/oopFactory.hpp" stefank@2314: #include "memory/resourceArea.hpp" stefank@2314: #include "oops/instanceKlass.hpp" stefank@2314: #include "oops/klass.inline.hpp" stefank@2314: #include "oops/oop.inline2.hpp" stefank@2314: #include "runtime/atomic.hpp" coleenp@4037: #include "utilities/stack.hpp" jprovino@4542: #include "utilities/macros.hpp" jprovino@4542: #if INCLUDE_ALL_GCS coleenp@4037: #include "gc_implementation/parallelScavenge/psParallelCompact.hpp" coleenp@4037: #include "gc_implementation/parallelScavenge/psPromotionManager.hpp" coleenp@4037: #include "gc_implementation/parallelScavenge/psScavenge.hpp" jprovino@4542: #endif // INCLUDE_ALL_GCS duke@435: coleenp@2497: void Klass::set_name(Symbol* n) { coleenp@2497: _name = n; coleenp@2497: if (_name != NULL) _name->increment_refcount(); coleenp@2497: } duke@435: coleenp@4037: bool Klass::is_subclass_of(Klass* k) const { duke@435: // Run up the super chain and check coleenp@4037: if (this == k) return true; duke@435: coleenp@4037: Klass* t = const_cast(this)->super(); duke@435: duke@435: while (t != NULL) { duke@435: if (t == k) return true; hseigel@4278: t = t->super(); duke@435: } duke@435: return false; duke@435: } duke@435: coleenp@4037: bool Klass::search_secondary_supers(Klass* k) const { duke@435: // Put some extra logic here out-of-line, before the search proper. duke@435: // This cuts down the size of the inline method. duke@435: duke@435: // This is necessary, since I am never in my own secondary_super list. coleenp@4037: if (this == k) duke@435: return true; duke@435: // Scan the array-of-objects for a match duke@435: int cnt = secondary_supers()->length(); duke@435: for (int i = 0; i < cnt; i++) { coleenp@4037: if (secondary_supers()->at(i) == k) { duke@435: ((Klass*)this)->set_secondary_super_cache(k); duke@435: return true; duke@435: } duke@435: } duke@435: return false; duke@435: } duke@435: duke@435: // Return self, except for abstract classes with exactly 1 duke@435: // implementor. Then return the 1 concrete implementation. duke@435: Klass *Klass::up_cast_abstract() { duke@435: Klass *r = this; duke@435: while( r->is_abstract() ) { // Receiver is abstract? duke@435: Klass *s = r->subklass(); // Check for exactly 1 subklass duke@435: if( !s || s->next_sibling() ) // Oops; wrong count; give up duke@435: return this; // Return 'this' as a no-progress flag duke@435: r = s; // Loop till find concrete class duke@435: } duke@435: return r; // Return the 1 concrete class duke@435: } duke@435: twisti@1040: // Find LCA in class hierarchy duke@435: Klass *Klass::LCA( Klass *k2 ) { duke@435: Klass *k1 = this; duke@435: while( 1 ) { coleenp@4037: if( k1->is_subtype_of(k2) ) return k2; coleenp@4037: if( k2->is_subtype_of(k1) ) return k1; coleenp@4037: k1 = k1->super(); coleenp@4037: k2 = k2->super(); duke@435: } duke@435: } duke@435: duke@435: duke@435: void Klass::check_valid_for_instantiation(bool throwError, TRAPS) { duke@435: ResourceMark rm(THREAD); duke@435: THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError() duke@435: : vmSymbols::java_lang_InstantiationException(), external_name()); duke@435: } duke@435: duke@435: duke@435: void Klass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) { duke@435: THROW(vmSymbols::java_lang_ArrayStoreException()); duke@435: } duke@435: duke@435: duke@435: void Klass::initialize(TRAPS) { duke@435: ShouldNotReachHere(); duke@435: } duke@435: coleenp@4037: bool Klass::compute_is_subtype_of(Klass* k) { duke@435: assert(k->is_klass(), "argument must be a class"); duke@435: return is_subclass_of(k); duke@435: } duke@435: duke@435: coleenp@4037: Method* Klass::uncached_lookup_method(Symbol* name, Symbol* signature) const { duke@435: #ifdef ASSERT duke@435: tty->print_cr("Error: uncached_lookup_method called on a klass oop." duke@435: " Likely error: reflection method does not correctly" duke@435: " wrap return value in a mirror object."); duke@435: #endif duke@435: ShouldNotReachHere(); duke@435: return NULL; duke@435: } duke@435: coleenp@4037: void* Klass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) { coleenp@4037: return Metaspace::allocate(loader_data, word_size, /*read_only*/false, coleenp@4037: Metaspace::ClassType, CHECK_NULL); coleenp@4037: } coleenp@4037: coleenp@4037: Klass::Klass() { coleenp@4037: Klass* k = this; duke@435: duke@435: { // Preinitialize supertype information. duke@435: // A later call to initialize_supers() may update these settings: coleenp@4037: set_super(NULL); duke@435: for (juint i = 0; i < Klass::primary_super_limit(); i++) { coleenp@4037: _primary_supers[i] = NULL; duke@435: } coleenp@4037: set_secondary_supers(NULL); coleenp@4037: _primary_supers[0] = k; coleenp@4037: set_super_check_offset(in_bytes(primary_supers_offset())); duke@435: } duke@435: coleenp@4037: set_java_mirror(NULL); coleenp@4037: set_modifier_flags(0); coleenp@4037: set_layout_helper(Klass::_lh_neutral_value); coleenp@4037: set_name(NULL); duke@435: AccessFlags af; duke@435: af.set_flags(0); coleenp@4037: set_access_flags(af); coleenp@4037: set_subklass(NULL); coleenp@4037: set_next_sibling(NULL); coleenp@4037: set_next_link(NULL); coleenp@4037: set_alloc_count(0); coleenp@4037: TRACE_SET_KLASS_TRACE_ID(this, 0); duke@435: coleenp@4037: set_prototype_header(markOopDesc::prototype()); coleenp@4037: set_biased_lock_revocation_count(0); coleenp@4037: set_last_biased_lock_bulk_revocation_time(0); duke@435: coleenp@4037: // The klass doesn't have any references at this point. coleenp@4037: clear_modified_oops(); coleenp@4037: clear_accumulated_modified_oops(); duke@435: } duke@435: duke@435: jint Klass::array_layout_helper(BasicType etype) { duke@435: assert(etype >= T_BOOLEAN && etype <= T_OBJECT, "valid etype"); duke@435: // Note that T_ARRAY is not allowed here. duke@435: int hsize = arrayOopDesc::base_offset_in_bytes(etype); kvn@464: int esize = type2aelembytes(etype); duke@435: bool isobj = (etype == T_OBJECT); duke@435: int tag = isobj ? _lh_array_tag_obj_value : _lh_array_tag_type_value; duke@435: int lh = array_layout_helper(tag, hsize, etype, exact_log2(esize)); duke@435: duke@435: assert(lh < (int)_lh_neutral_value, "must look like an array layout"); coleenp@4037: assert(layout_helper_is_array(lh), "correct kind"); duke@435: assert(layout_helper_is_objArray(lh) == isobj, "correct kind"); duke@435: assert(layout_helper_is_typeArray(lh) == !isobj, "correct kind"); duke@435: assert(layout_helper_header_size(lh) == hsize, "correct decode"); duke@435: assert(layout_helper_element_type(lh) == etype, "correct decode"); duke@435: assert(1 << layout_helper_log2_element_size(lh) == esize, "correct decode"); duke@435: duke@435: return lh; duke@435: } duke@435: duke@435: bool Klass::can_be_primary_super_slow() const { duke@435: if (super() == NULL) duke@435: return true; coleenp@4037: else if (super()->super_depth() >= primary_super_limit()-1) duke@435: return false; duke@435: else duke@435: return true; duke@435: } duke@435: coleenp@4037: void Klass::initialize_supers(Klass* k, TRAPS) { duke@435: if (FastSuperclassLimit == 0) { duke@435: // None of the other machinery matters. duke@435: set_super(k); duke@435: return; duke@435: } duke@435: if (k == NULL) { duke@435: set_super(NULL); coleenp@4037: _primary_supers[0] = this; duke@435: assert(super_depth() == 0, "Object must already be initialized properly"); never@1577: } else if (k != super() || k == SystemDictionary::Object_klass()) { never@1577: assert(super() == NULL || super() == SystemDictionary::Object_klass(), duke@435: "initialize this only once to a non-trivial value"); duke@435: set_super(k); coleenp@4037: Klass* sup = k; duke@435: int sup_depth = sup->super_depth(); duke@435: juint my_depth = MIN2(sup_depth + 1, (int)primary_super_limit()); duke@435: if (!can_be_primary_super_slow()) duke@435: my_depth = primary_super_limit(); duke@435: for (juint i = 0; i < my_depth; i++) { coleenp@4037: _primary_supers[i] = sup->_primary_supers[i]; duke@435: } coleenp@4037: Klass* *super_check_cell; duke@435: if (my_depth < primary_super_limit()) { coleenp@4037: _primary_supers[my_depth] = this; duke@435: super_check_cell = &_primary_supers[my_depth]; duke@435: } else { duke@435: // Overflow of the primary_supers array forces me to be secondary. duke@435: super_check_cell = &_secondary_super_cache; duke@435: } coleenp@4037: set_super_check_offset((address)super_check_cell - (address) this); duke@435: duke@435: #ifdef ASSERT duke@435: { duke@435: juint j = super_depth(); duke@435: assert(j == my_depth, "computed accessor gets right answer"); coleenp@4037: Klass* t = this; hseigel@4278: while (!t->can_be_primary_super()) { hseigel@4278: t = t->super(); hseigel@4278: j = t->super_depth(); duke@435: } duke@435: for (juint j1 = j+1; j1 < primary_super_limit(); j1++) { duke@435: assert(primary_super_of_depth(j1) == NULL, "super list padding"); duke@435: } duke@435: while (t != NULL) { duke@435: assert(primary_super_of_depth(j) == t, "super list initialization"); hseigel@4278: t = t->super(); duke@435: --j; duke@435: } duke@435: assert(j == (juint)-1, "correct depth count"); duke@435: } duke@435: #endif duke@435: } duke@435: duke@435: if (secondary_supers() == NULL) { duke@435: KlassHandle this_kh (THREAD, this); duke@435: duke@435: // Now compute the list of secondary supertypes. duke@435: // Secondaries can occasionally be on the super chain, duke@435: // if the inline "_primary_supers" array overflows. duke@435: int extras = 0; coleenp@4037: Klass* p; coleenp@4037: for (p = super(); !(p == NULL || p->can_be_primary_super()); p = p->super()) { duke@435: ++extras; duke@435: } duke@435: coleenp@4037: ResourceMark rm(THREAD); // need to reclaim GrowableArrays allocated below coleenp@4037: duke@435: // Compute the "real" non-extra secondaries. coleenp@4037: GrowableArray* secondaries = compute_secondary_supers(extras); coleenp@4037: if (secondaries == NULL) { coleenp@4037: // secondary_supers set by compute_secondary_supers coleenp@4037: return; coleenp@4037: } duke@435: coleenp@4037: GrowableArray* primaries = new GrowableArray(extras); coleenp@4037: coleenp@4037: for (p = this_kh->super(); !(p == NULL || p->can_be_primary_super()); p = p->super()) { duke@435: int i; // Scan for overflow primaries being duplicates of 2nd'arys duke@435: duke@435: // This happens frequently for very deeply nested arrays: the duke@435: // primary superclass chain overflows into the secondary. The duke@435: // secondary list contains the element_klass's secondaries with duke@435: // an extra array dimension added. If the element_klass's duke@435: // secondary list already contains some primary overflows, they duke@435: // (with the extra level of array-ness) will collide with the duke@435: // normal primary superclass overflows. coleenp@4037: for( i = 0; i < secondaries->length(); i++ ) { coleenp@4037: if( secondaries->at(i) == p ) duke@435: break; coleenp@4037: } duke@435: if( i < secondaries->length() ) duke@435: continue; // It's a dup, don't put it in coleenp@4037: primaries->push(p); duke@435: } coleenp@4037: // Combine the two arrays into a metadata object to pack the array. coleenp@4037: // The primaries are added in the reverse order, then the secondaries. coleenp@4037: int new_length = primaries->length() + secondaries->length(); coleenp@4037: Array* s2 = MetadataFactory::new_array( coleenp@4037: class_loader_data(), new_length, CHECK); coleenp@4037: int fill_p = primaries->length(); coleenp@4037: for (int j = 0; j < fill_p; j++) { coleenp@4037: s2->at_put(j, primaries->pop()); // add primaries in reverse order. coleenp@4037: } coleenp@4037: for( int j = 0; j < secondaries->length(); j++ ) { coleenp@4037: s2->at_put(j+fill_p, secondaries->at(j)); // add secondaries on the end. duke@435: } duke@435: duke@435: #ifdef ASSERT duke@435: // We must not copy any NULL placeholders left over from bootstrap. coleenp@4037: for (int j = 0; j < s2->length(); j++) { coleenp@4037: assert(s2->at(j) != NULL, "correct bootstrapping order"); duke@435: } duke@435: #endif duke@435: coleenp@4037: this_kh->set_secondary_supers(s2); duke@435: } duke@435: } duke@435: coleenp@4037: GrowableArray* Klass::compute_secondary_supers(int num_extra_slots) { duke@435: assert(num_extra_slots == 0, "override for complex klasses"); coleenp@4037: set_secondary_supers(Universe::the_empty_klass_array()); coleenp@4037: return NULL; duke@435: } duke@435: duke@435: duke@435: Klass* Klass::subklass() const { hseigel@4278: return _subklass == NULL ? NULL : _subklass; duke@435: } duke@435: coleenp@4037: InstanceKlass* Klass::superklass() const { coleenp@4037: assert(super() == NULL || super()->oop_is_instance(), "must be instance klass"); coleenp@4037: return _super == NULL ? NULL : InstanceKlass::cast(_super); duke@435: } duke@435: duke@435: Klass* Klass::next_sibling() const { hseigel@4278: return _next_sibling == NULL ? NULL : _next_sibling; duke@435: } duke@435: coleenp@4037: void Klass::set_subklass(Klass* s) { coleenp@4037: assert(s != this, "sanity check"); coleenp@4037: _subklass = s; duke@435: } duke@435: coleenp@4037: void Klass::set_next_sibling(Klass* s) { coleenp@4037: assert(s != this, "sanity check"); coleenp@4037: _next_sibling = s; duke@435: } duke@435: duke@435: void Klass::append_to_sibling_list() { coleenp@4178: debug_only(verify();) duke@435: // add ourselves to superklass' subklass list coleenp@4037: InstanceKlass* super = superklass(); duke@435: if (super == NULL) return; // special case: class Object coleenp@4178: assert((!super->is_interface() // interfaces cannot be supers duke@435: && (super->superklass() == NULL || !is_interface())), duke@435: "an interface can only be a subklass of Object"); coleenp@4037: Klass* prev_first_subklass = super->subklass_oop(); duke@435: if (prev_first_subklass != NULL) { duke@435: // set our sibling to be the superklass' previous first subklass duke@435: set_next_sibling(prev_first_subklass); duke@435: } duke@435: // make ourselves the superklass' first subklass coleenp@4037: super->set_subklass(this); coleenp@4178: debug_only(verify();) duke@435: } duke@435: coleenp@4037: bool Klass::is_loader_alive(BoolObjectClosure* is_alive) { coleenp@4037: assert(is_metadata(), "p is not meta-data"); coleenp@4037: assert(ClassLoaderDataGraph::contains((address)this), "is in the metaspace"); coleenp@4304: coleenp@4304: #ifdef ASSERT coleenp@4037: // The class is alive iff the class loader is alive. coleenp@4037: oop loader = class_loader(); coleenp@4304: bool loader_alive = (loader == NULL) || is_alive->do_object_b(loader); coleenp@4304: #endif // ASSERT coleenp@4304: coleenp@4304: // The class is alive if it's mirror is alive (which should be marked if the coleenp@4304: // loader is alive) unless it's an anoymous class. coleenp@4304: bool mirror_alive = is_alive->do_object_b(java_mirror()); coleenp@4304: assert(!mirror_alive || loader_alive, "loader must be alive if the mirror is" coleenp@4304: " but not the other way around with anonymous classes"); coleenp@4304: return mirror_alive; coleenp@4037: } coleenp@4037: coleenp@4037: void Klass::clean_weak_klass_links(BoolObjectClosure* is_alive) { coleenp@4037: if (!ClassUnloading) { coleenp@4037: return; coleenp@4037: } coleenp@4037: coleenp@4037: Klass* root = SystemDictionary::Object_klass(); coleenp@4037: Stack stack; coleenp@4037: coleenp@4037: stack.push(root); coleenp@4037: while (!stack.is_empty()) { coleenp@4037: Klass* current = stack.pop(); coleenp@4037: coleenp@4037: assert(current->is_loader_alive(is_alive), "just checking, this should be live"); coleenp@4037: coleenp@4037: // Find and set the first alive subklass coleenp@4037: Klass* sub = current->subklass_oop(); coleenp@4037: while (sub != NULL && !sub->is_loader_alive(is_alive)) { duke@435: #ifndef PRODUCT coleenp@4304: if (TraceClassUnloading && WizardMode) { coleenp@4304: ResourceMark rm; coleenp@4037: tty->print_cr("[Unlinking class (subclass) %s]", sub->external_name()); coleenp@4304: } duke@435: #endif coleenp@4037: sub = sub->next_sibling_oop(); duke@435: } coleenp@4037: current->set_subklass(sub); coleenp@4037: if (sub != NULL) { coleenp@4037: stack.push(sub); coleenp@4037: } coleenp@4037: coleenp@4037: // Find and set the first alive sibling coleenp@4037: Klass* sibling = current->next_sibling_oop(); coleenp@4037: while (sibling != NULL && !sibling->is_loader_alive(is_alive)) { coleenp@4304: if (TraceClassUnloading && WizardMode) { coleenp@4304: ResourceMark rm; coleenp@4037: tty->print_cr("[Unlinking class (sibling) %s]", sibling->external_name()); coleenp@4304: } coleenp@4037: sibling = sibling->next_sibling_oop(); coleenp@4304: } coleenp@4037: current->set_next_sibling(sibling); coleenp@4037: if (sibling != NULL) { coleenp@4037: stack.push(sibling); coleenp@4304: } coleenp@4037: coleenp@4037: // Clean the implementors list and method data. coleenp@4037: if (current->oop_is_instance()) { coleenp@4037: InstanceKlass* ik = InstanceKlass::cast(current); coleenp@4037: ik->clean_implementors_list(is_alive); coleenp@4037: ik->clean_method_data(is_alive); duke@435: } duke@435: } duke@435: } duke@435: coleenp@4037: void Klass::klass_update_barrier_set(oop v) { coleenp@4037: record_modified_oops(); coleenp@4037: } coleenp@4037: coleenp@4037: void Klass::klass_update_barrier_set_pre(void* p, oop v) { coleenp@4037: // This barrier used by G1, where it's used remember the old oop values, coleenp@4037: // so that we don't forget any objects that were live at the snapshot at coleenp@4037: // the beginning. This function is only used when we write oops into coleenp@4037: // Klasses. Since the Klasses are used as roots in G1, we don't have to coleenp@4037: // do anything here. coleenp@4037: } coleenp@4037: coleenp@4037: void Klass::klass_oop_store(oop* p, oop v) { coleenp@4037: assert(!Universe::heap()->is_in_reserved((void*)p), "Should store pointer into metadata"); coleenp@4037: assert(v == NULL || Universe::heap()->is_in_reserved((void*)v), "Should store pointer to an object"); coleenp@4037: coleenp@4037: // do the store coleenp@4037: if (always_do_update_barrier) { coleenp@4037: klass_oop_store((volatile oop*)p, v); coleenp@4037: } else { coleenp@4037: klass_update_barrier_set_pre((void*)p, v); coleenp@4037: *p = v; coleenp@4037: klass_update_barrier_set(v); coleenp@4037: } coleenp@4037: } coleenp@4037: coleenp@4037: void Klass::klass_oop_store(volatile oop* p, oop v) { coleenp@4037: assert(!Universe::heap()->is_in_reserved((void*)p), "Should store pointer into metadata"); coleenp@4037: assert(v == NULL || Universe::heap()->is_in_reserved((void*)v), "Should store pointer to an object"); coleenp@4037: coleenp@4037: klass_update_barrier_set_pre((void*)p, v); coleenp@4037: OrderAccess::release_store_ptr(p, v); coleenp@4037: klass_update_barrier_set(v); coleenp@4037: } coleenp@4037: coleenp@4037: void Klass::oops_do(OopClosure* cl) { coleenp@4037: cl->do_oop(&_java_mirror); coleenp@4037: } duke@435: duke@435: void Klass::remove_unshareable_info() { duke@435: set_subklass(NULL); duke@435: set_next_sibling(NULL); coleenp@4037: // Clear the java mirror coleenp@4037: set_java_mirror(NULL); coleenp@4037: set_next_link(NULL); coleenp@4037: coleenp@4037: // Null out class_loader_data because we don't share that yet. coleenp@4037: set_class_loader_data(NULL); duke@435: } duke@435: coleenp@4037: void Klass::restore_unshareable_info(TRAPS) { coleenp@4037: ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data(); coleenp@4037: // Restore class_loader_data to the null class loader data coleenp@4037: set_class_loader_data(loader_data); duke@435: coleenp@4037: // Add to null class loader list first before creating the mirror coleenp@4037: // (same order as class file parsing) coleenp@4037: loader_data->add_class(this); coleenp@4037: coleenp@4037: // Recreate the class mirror coleenp@4037: java_lang_Class::create_mirror(this, CHECK); coleenp@2497: } coleenp@2497: coleenp@4037: Klass* Klass::array_klass_or_null(int rank) { duke@435: EXCEPTION_MARK; duke@435: // No exception can be thrown by array_klass_impl when called with or_null == true. duke@435: // (In anycase, the execption mark will fail if it do so) duke@435: return array_klass_impl(true, rank, THREAD); duke@435: } duke@435: duke@435: coleenp@4037: Klass* Klass::array_klass_or_null() { duke@435: EXCEPTION_MARK; duke@435: // No exception can be thrown by array_klass_impl when called with or_null == true. duke@435: // (In anycase, the execption mark will fail if it do so) duke@435: return array_klass_impl(true, THREAD); duke@435: } duke@435: duke@435: coleenp@4037: Klass* Klass::array_klass_impl(bool or_null, int rank, TRAPS) { coleenp@4142: fatal("array_klass should be dispatched to InstanceKlass, ObjArrayKlass or TypeArrayKlass"); duke@435: return NULL; duke@435: } duke@435: duke@435: coleenp@4037: Klass* Klass::array_klass_impl(bool or_null, TRAPS) { coleenp@4142: fatal("array_klass should be dispatched to InstanceKlass, ObjArrayKlass or TypeArrayKlass"); duke@435: return NULL; duke@435: } duke@435: duke@435: coleenp@4037: void Klass::with_array_klasses_do(void f(Klass* k)) { coleenp@4037: f(this); duke@435: } duke@435: duke@435: coleenp@4037: oop Klass::class_loader() const { return class_loader_data()->class_loader(); } coleenp@4037: duke@435: const char* Klass::external_name() const { jrose@866: if (oop_is_instance()) { coleenp@4037: InstanceKlass* ik = (InstanceKlass*) this; jrose@866: if (ik->is_anonymous()) { twisti@2698: assert(EnableInvokeDynamic, ""); coleenp@4304: intptr_t hash = 0; coleenp@4304: if (ik->java_mirror() != NULL) { coleenp@4304: // java_mirror might not be created yet, return 0 as hash. coleenp@4304: hash = ik->java_mirror()->identity_hash(); coleenp@4304: } jrose@866: char hash_buf[40]; jrose@866: sprintf(hash_buf, "/" UINTX_FORMAT, (uintx)hash); jrose@866: size_t hash_len = strlen(hash_buf); jrose@866: jrose@866: size_t result_len = name()->utf8_length(); jrose@866: char* result = NEW_RESOURCE_ARRAY(char, result_len + hash_len + 1); jrose@866: name()->as_klass_external_name(result, (int) result_len + 1); jrose@866: assert(strlen(result) == result_len, ""); jrose@866: strcpy(result + result_len, hash_buf); jrose@866: assert(strlen(result) == result_len + hash_len, ""); jrose@866: return result; jrose@866: } jrose@866: } jrose@1474: if (name() == NULL) return ""; duke@435: return name()->as_klass_external_name(); duke@435: } duke@435: duke@435: jrose@1474: const char* Klass::signature_name() const { jrose@1474: if (name() == NULL) return ""; duke@435: return name()->as_C_string(); duke@435: } duke@435: duke@435: // Unless overridden, modifier_flags is 0. duke@435: jint Klass::compute_modifier_flags(TRAPS) const { duke@435: return 0; duke@435: } duke@435: duke@435: int Klass::atomic_incr_biased_lock_revocation_count() { duke@435: return (int) Atomic::add(1, &_biased_lock_revocation_count); duke@435: } duke@435: duke@435: // Unless overridden, jvmti_class_status has no flags set. duke@435: jint Klass::jvmti_class_status() const { duke@435: return 0; duke@435: } duke@435: coleenp@4037: duke@435: // Printing duke@435: coleenp@4037: void Klass::print_on(outputStream* st) const { coleenp@4037: ResourceMark rm; coleenp@4037: // print title coleenp@4037: st->print("%s", internal_name()); coleenp@4037: print_address_on(st); coleenp@4037: st->cr(); coleenp@4037: } coleenp@4037: duke@435: void Klass::oop_print_on(oop obj, outputStream* st) { duke@435: ResourceMark rm; duke@435: // print title duke@435: st->print_cr("%s ", internal_name()); duke@435: obj->print_address_on(st); duke@435: duke@435: if (WizardMode) { duke@435: // print header duke@435: obj->mark()->print_on(st); duke@435: } duke@435: duke@435: // print class duke@435: st->print(" - klass: "); duke@435: obj->klass()->print_value_on(st); duke@435: st->cr(); duke@435: } duke@435: duke@435: void Klass::oop_print_value_on(oop obj, outputStream* st) { duke@435: // print title duke@435: ResourceMark rm; // Cannot print in debug mode without this duke@435: st->print("%s", internal_name()); duke@435: obj->print_address_on(st); duke@435: } duke@435: acorn@4497: #if INCLUDE_SERVICES acorn@4497: // Size Statistics acorn@4497: void Klass::collect_statistics(KlassSizeStats *sz) const { acorn@4497: sz->_klass_bytes = sz->count(this); acorn@4497: sz->_mirror_bytes = sz->count(java_mirror()); acorn@4497: sz->_secondary_supers_bytes = sz->count_array(secondary_supers()); acorn@4497: acorn@4497: sz->_ro_bytes += sz->_secondary_supers_bytes; acorn@4497: sz->_rw_bytes += sz->_klass_bytes + sz->_mirror_bytes; acorn@4497: } acorn@4497: #endif // INCLUDE_SERVICES coleenp@4037: duke@435: // Verification duke@435: coleenp@4037: void Klass::verify_on(outputStream* st) { coleenp@4037: guarantee(!Universe::heap()->is_in_reserved(this), "Shouldn't be"); coleenp@4037: guarantee(this->is_metadata(), "should be in metaspace"); coleenp@4037: coleenp@4037: assert(ClassLoaderDataGraph::contains((address)this), "Should be"); coleenp@4037: coleenp@4037: guarantee(this->is_klass(),"should be klass"); coleenp@4037: coleenp@4037: if (super() != NULL) { coleenp@4037: guarantee(super()->is_metadata(), "should be in metaspace"); coleenp@4037: guarantee(super()->is_klass(), "should be klass"); coleenp@4037: } coleenp@4037: if (secondary_super_cache() != NULL) { coleenp@4037: Klass* ko = secondary_super_cache(); coleenp@4037: guarantee(ko->is_metadata(), "should be in metaspace"); coleenp@4037: guarantee(ko->is_klass(), "should be klass"); coleenp@4037: } coleenp@4037: for ( uint i = 0; i < primary_super_limit(); i++ ) { coleenp@4037: Klass* ko = _primary_supers[i]; coleenp@4037: if (ko != NULL) { coleenp@4037: guarantee(ko->is_metadata(), "should be in metaspace"); coleenp@4037: guarantee(ko->is_klass(), "should be klass"); coleenp@4037: } coleenp@4037: } coleenp@4037: coleenp@4037: if (java_mirror() != NULL) { coleenp@4037: guarantee(java_mirror()->is_oop(), "should be instance"); coleenp@4037: } coleenp@4037: } coleenp@4037: duke@435: void Klass::oop_verify_on(oop obj, outputStream* st) { duke@435: guarantee(obj->is_oop(), "should be oop"); coleenp@4037: guarantee(obj->klass()->is_metadata(), "should not be in Java heap"); duke@435: guarantee(obj->klass()->is_klass(), "klass field is not a klass"); duke@435: } duke@435: duke@435: #ifndef PRODUCT duke@435: duke@435: void Klass::verify_vtable_index(int i) { duke@435: if (oop_is_instance()) { coleenp@4037: assert(i>=0 && i<((InstanceKlass*)this)->vtable_length()/vtableEntry::size(), "index out of bounds"); duke@435: } else { coleenp@4037: assert(oop_is_array(), "Must be"); coleenp@4142: assert(i>=0 && i<((ArrayKlass*)this)->vtable_length()/vtableEntry::size(), "index out of bounds"); duke@435: } duke@435: } duke@435: duke@435: #endif