duke@435: /* coleenp@6316: * Copyright (c) 1997, 2014, 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/symbolTable.hpp" stefank@2314: #include "classfile/systemDictionary.hpp" stefank@2314: #include "classfile/vmSymbols.hpp" stefank@2314: #include "gc_implementation/shared/markSweep.inline.hpp" stefank@2314: #include "gc_interface/collectedHeap.inline.hpp" stefank@2314: #include "memory/genOopClosures.inline.hpp" stefank@6982: #include "memory/iterator.inline.hpp" coleenp@4037: #include "memory/metadataFactory.hpp" stefank@2314: #include "memory/resourceArea.hpp" stefank@2314: #include "memory/universe.inline.hpp" stefank@2314: #include "oops/instanceKlass.hpp" coleenp@4037: #include "oops/klass.inline.hpp" stefank@2314: #include "oops/objArrayKlass.hpp" stefank@2314: #include "oops/objArrayKlass.inline.hpp" stefank@2314: #include "oops/objArrayOop.hpp" stefank@2314: #include "oops/oop.inline.hpp" stefank@2314: #include "oops/oop.inline2.hpp" coleenp@2497: #include "oops/symbol.hpp" stefank@2314: #include "runtime/handles.inline.hpp" stefank@2314: #include "runtime/mutexLocker.hpp" goetz@6911: #include "runtime/orderAccess.inline.hpp" stefank@2314: #include "utilities/copy.hpp" jprovino@4542: #include "utilities/macros.hpp" jprovino@4542: #if INCLUDE_ALL_GCS coleenp@4037: #include "gc_implementation/concurrentMarkSweep/cmsOopClosures.inline.hpp" stefank@2314: #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" stefank@2314: #include "gc_implementation/g1/g1OopClosures.inline.hpp" stefank@2314: #include "gc_implementation/g1/g1RemSet.inline.hpp" tschatzl@7091: #include "gc_implementation/g1/heapRegionManager.inline.hpp" stefank@2314: #include "gc_implementation/parNew/parOopClosures.inline.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/psCompactionManager.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp" stefank@2314: #include "oops/oop.pcgc.inline.hpp" jprovino@4542: #endif // INCLUDE_ALL_GCS duke@435: coleenp@4142: ObjArrayKlass* ObjArrayKlass::allocate(ClassLoaderData* loader_data, int n, KlassHandle klass_handle, Symbol* name, TRAPS) { coleenp@4142: assert(ObjArrayKlass::header_size() <= InstanceKlass::header_size(), coleenp@4037: "array klasses must be same size as InstanceKlass"); coleenp@4037: coleenp@4142: int size = ArrayKlass::static_size(ObjArrayKlass::header_size()); coleenp@4037: coleenp@4142: return new (loader_data, size, THREAD) ObjArrayKlass(n, klass_handle, name); coleenp@4037: } coleenp@4037: coleenp@4142: Klass* ObjArrayKlass::allocate_objArray_klass(ClassLoaderData* loader_data, coleenp@4037: int n, KlassHandle element_klass, TRAPS) { coleenp@4037: coleenp@4037: // Eagerly allocate the direct array supertype. coleenp@4037: KlassHandle super_klass = KlassHandle(); coleenp@4037: if (!Universe::is_bootstrapping() || SystemDictionary::Object_klass_loaded()) { coleenp@4037: KlassHandle element_super (THREAD, element_klass->super()); coleenp@4037: if (element_super.not_null()) { coleenp@4037: // The element type has a direct super. E.g., String[] has direct super of Object[]. coleenp@4037: super_klass = KlassHandle(THREAD, element_super->array_klass_or_null()); coleenp@4037: bool supers_exist = super_klass.not_null(); coleenp@4037: // Also, see if the element has secondary supertypes. coleenp@4037: // We need an array type for each. coleenp@4037: Array* element_supers = element_klass->secondary_supers(); coleenp@4037: for( int i = element_supers->length()-1; i >= 0; i-- ) { coleenp@4037: Klass* elem_super = element_supers->at(i); hseigel@4278: if (elem_super->array_klass_or_null() == NULL) { coleenp@4037: supers_exist = false; coleenp@4037: break; coleenp@4037: } coleenp@4037: } coleenp@4037: if (!supers_exist) { coleenp@4037: // Oops. Not allocated yet. Back out, allocate it, and retry. coleenp@4037: KlassHandle ek; coleenp@4037: { coleenp@4037: MutexUnlocker mu(MultiArray_lock); coleenp@4037: MutexUnlocker mc(Compile_lock); // for vtables coleenp@4037: Klass* sk = element_super->array_klass(CHECK_0); coleenp@4037: super_klass = KlassHandle(THREAD, sk); coleenp@4037: for( int i = element_supers->length()-1; i >= 0; i-- ) { coleenp@4037: KlassHandle elem_super (THREAD, element_supers->at(i)); coleenp@4037: elem_super->array_klass(CHECK_0); coleenp@4037: } coleenp@4037: // Now retry from the beginning coleenp@4037: Klass* klass_oop = element_klass->array_klass(n, CHECK_0); coleenp@4037: // Create a handle because the enclosing brace, when locking coleenp@4037: // can cause a gc. Better to have this function return a Handle. coleenp@4037: ek = KlassHandle(THREAD, klass_oop); coleenp@4037: } // re-lock coleenp@4037: return ek(); coleenp@4037: } coleenp@4037: } else { coleenp@4037: // The element type is already Object. Object[] has direct super of Object. coleenp@4037: super_klass = KlassHandle(THREAD, SystemDictionary::Object_klass()); coleenp@4037: } coleenp@4037: } coleenp@4037: coleenp@4037: // Create type name for klass. coleenp@4037: Symbol* name = NULL; coleenp@4037: if (!element_klass->oop_is_instance() || coleenp@4037: (name = InstanceKlass::cast(element_klass())->array_name()) == NULL) { coleenp@4037: coleenp@4037: ResourceMark rm(THREAD); coleenp@4037: char *name_str = element_klass->name()->as_C_string(); coleenp@4037: int len = element_klass->name()->utf8_length(); coleenp@4037: char *new_str = NEW_RESOURCE_ARRAY(char, len + 4); coleenp@4037: int idx = 0; coleenp@4037: new_str[idx++] = '['; coleenp@4037: if (element_klass->oop_is_instance()) { // it could be an array or simple type coleenp@4037: new_str[idx++] = 'L'; coleenp@4037: } coleenp@4037: memcpy(&new_str[idx], name_str, len * sizeof(char)); coleenp@4037: idx += len; coleenp@4037: if (element_klass->oop_is_instance()) { coleenp@4037: new_str[idx++] = ';'; coleenp@4037: } coleenp@4037: new_str[idx++] = '\0'; coleenp@4037: name = SymbolTable::new_permanent_symbol(new_str, CHECK_0); coleenp@4037: if (element_klass->oop_is_instance()) { coleenp@4037: InstanceKlass* ik = InstanceKlass::cast(element_klass()); coleenp@4037: ik->set_array_name(name); coleenp@4037: } coleenp@4037: } coleenp@4037: coleenp@4037: // Initialize instance variables coleenp@4142: ObjArrayKlass* oak = ObjArrayKlass::allocate(loader_data, n, element_klass, name, CHECK_0); coleenp@4037: coleenp@4037: // Add all classes to our internal class loader list here, coleenp@4037: // including classes in the bootstrap (NULL) class loader. coleenp@4037: // GC walks these as strong roots. coleenp@4037: loader_data->add_class(oak); coleenp@4037: coleenp@4037: // Call complete_create_array_klass after all instance variables has been initialized. coleenp@4142: ArrayKlass::complete_create_array_klass(oak, super_klass, CHECK_0); coleenp@4037: coleenp@4037: return oak; coleenp@4037: } coleenp@4037: coleenp@4142: ObjArrayKlass::ObjArrayKlass(int n, KlassHandle element_klass, Symbol* name) : ArrayKlass(name) { coleenp@4037: this->set_dimension(n); coleenp@4037: this->set_element_klass(element_klass()); coleenp@4037: // decrement refcount because object arrays are not explicitly freed. The coleenp@4037: // InstanceKlass array_name() keeps the name counted while the klass is coleenp@4037: // loaded. coleenp@4037: name->decrement_refcount(); coleenp@4037: coleenp@4037: Klass* bk; coleenp@4037: if (element_klass->oop_is_objArray()) { coleenp@4142: bk = ObjArrayKlass::cast(element_klass())->bottom_klass(); coleenp@4037: } else { coleenp@4037: bk = element_klass(); coleenp@4037: } hseigel@4278: assert(bk != NULL && (bk->oop_is_instance() || bk->oop_is_typeArray()), "invalid bottom klass"); coleenp@4037: this->set_bottom_klass(bk); coleenp@4037: this->set_class_loader_data(bk->class_loader_data()); coleenp@4037: coleenp@4037: this->set_layout_helper(array_layout_helper(T_OBJECT)); coleenp@4037: assert(this->oop_is_array(), "sanity"); coleenp@4037: assert(this->oop_is_objArray(), "sanity"); coleenp@4037: } coleenp@4037: coleenp@4142: int ObjArrayKlass::oop_size(oop obj) const { duke@435: assert(obj->is_objArray(), "must be object array"); duke@435: return objArrayOop(obj)->object_size(); duke@435: } duke@435: coleenp@4142: objArrayOop ObjArrayKlass::allocate(int length, TRAPS) { duke@435: if (length >= 0) { duke@435: if (length <= arrayOopDesc::max_array_length(T_OBJECT)) { duke@435: int size = objArrayOopDesc::object_size(length); coleenp@4037: KlassHandle h_k(THREAD, this); coleenp@4037: return (objArrayOop)CollectedHeap::array_allocate(h_k, size, length, CHECK_NULL); duke@435: } else { martin@1311: report_java_out_of_memory("Requested array size exceeds VM limit"); sspitsyn@3638: JvmtiExport::post_array_size_exhausted(); duke@435: THROW_OOP_0(Universe::out_of_memory_error_array_size()); duke@435: } duke@435: } else { duke@435: THROW_0(vmSymbols::java_lang_NegativeArraySizeException()); duke@435: } duke@435: } duke@435: duke@435: static int multi_alloc_counter = 0; duke@435: coleenp@4142: oop ObjArrayKlass::multi_allocate(int rank, jint* sizes, TRAPS) { duke@435: int length = *sizes; duke@435: // Call to lower_dimension uses this pointer, so most be called before a duke@435: // possible GC duke@435: KlassHandle h_lower_dimension(THREAD, lower_dimension()); duke@435: // If length < 0 allocate will throw an exception. duke@435: objArrayOop array = allocate(length, CHECK_NULL); duke@435: objArrayHandle h_array (THREAD, array); duke@435: if (rank > 1) { duke@435: if (length != 0) { duke@435: for (int index = 0; index < length; index++) { coleenp@4142: ArrayKlass* ak = ArrayKlass::cast(h_lower_dimension()); duke@435: oop sub_array = ak->multi_allocate(rank-1, &sizes[1], CHECK_NULL); duke@435: h_array->obj_at_put(index, sub_array); duke@435: } duke@435: } else { duke@435: // Since this array dimension has zero length, nothing will be duke@435: // allocated, however the lower dimension values must be checked duke@435: // for illegal values. duke@435: for (int i = 0; i < rank - 1; ++i) { duke@435: sizes += 1; duke@435: if (*sizes < 0) { duke@435: THROW_0(vmSymbols::java_lang_NegativeArraySizeException()); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: return h_array(); duke@435: } duke@435: coleenp@548: // Either oop or narrowOop depending on UseCompressedOops. coleenp@4142: template void ObjArrayKlass::do_copy(arrayOop s, T* src, coleenp@548: arrayOop d, T* dst, int length, TRAPS) { coleenp@548: coleenp@548: BarrierSet* bs = Universe::heap()->barrier_set(); ysr@777: // For performance reasons, we assume we are that the write barrier we ysr@777: // are using has optimized modes for arrays of references. At least one ysr@777: // of the asserts below will fail if this is not the case. coleenp@548: assert(bs->has_write_ref_array_opt(), "Barrier set must have ref array opt"); ysr@777: assert(bs->has_write_ref_array_pre_opt(), "For pre-barrier as well."); coleenp@548: coleenp@548: if (s == d) { coleenp@548: // since source and destination are equal we do not need conversion checks. coleenp@548: assert(length > 0, "sanity check"); ysr@1280: bs->write_ref_array_pre(dst, length); coleenp@548: Copy::conjoint_oops_atomic(src, dst, length); coleenp@548: } else { coleenp@548: // We have to make sure all elements conform to the destination array coleenp@4142: Klass* bound = ObjArrayKlass::cast(d->klass())->element_klass(); coleenp@4142: Klass* stype = ObjArrayKlass::cast(s->klass())->element_klass(); hseigel@4278: if (stype == bound || stype->is_subtype_of(bound)) { coleenp@548: // elements are guaranteed to be subtypes, so no check necessary ysr@1280: bs->write_ref_array_pre(dst, length); coleenp@548: Copy::conjoint_oops_atomic(src, dst, length); coleenp@548: } else { coleenp@548: // slow case: need individual subtype checks coleenp@548: // note: don't use obj_at_put below because it includes a redundant store check coleenp@548: T* from = src; coleenp@548: T* end = from + length; coleenp@548: for (T* p = dst; from < end; from++, p++) { coleenp@548: // XXX this is going to be slow. coleenp@548: T element = *from; ysr@777: // even slower now ysr@777: bool element_is_null = oopDesc::is_null(element); ysr@777: oop new_val = element_is_null ? oop(NULL) ysr@777: : oopDesc::decode_heap_oop_not_null(element); ysr@777: if (element_is_null || hseigel@4278: (new_val->klass())->is_subtype_of(bound)) { ysr@777: bs->write_ref_field_pre(p, new_val); dsimms@6571: *p = element; coleenp@548: } else { coleenp@548: // We must do a barrier to cover the partial copy. coleenp@548: const size_t pd = pointer_delta(p, dst, (size_t)heapOopSize); coleenp@548: // pointer delta is scaled to number of elements (length field in coleenp@548: // objArrayOop) which we assume is 32 bit. coleenp@548: assert(pd == (size_t)(int)pd, "length field overflow"); ysr@1526: bs->write_ref_array((HeapWord*)dst, pd); coleenp@548: THROW(vmSymbols::java_lang_ArrayStoreException()); coleenp@548: return; coleenp@548: } coleenp@548: } coleenp@548: } coleenp@548: } ysr@1526: bs->write_ref_array((HeapWord*)dst, length); coleenp@548: } coleenp@548: coleenp@4142: void ObjArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d, duke@435: int dst_pos, int length, TRAPS) { duke@435: assert(s->is_objArray(), "must be obj array"); duke@435: duke@435: if (!d->is_objArray()) { duke@435: THROW(vmSymbols::java_lang_ArrayStoreException()); duke@435: } duke@435: duke@435: // Check is all offsets and lengths are non negative duke@435: if (src_pos < 0 || dst_pos < 0 || length < 0) { duke@435: THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); duke@435: } duke@435: // Check if the ranges are valid duke@435: if ( (((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length()) duke@435: || (((unsigned int) length + (unsigned int) dst_pos) > (unsigned int) d->length()) ) { duke@435: THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); duke@435: } duke@435: duke@435: // Special case. Boundary cases must be checked first duke@435: // This allows the following call: copy_array(s, s.length(), d.length(), 0). duke@435: // This is correct, since the position is supposed to be an 'in between point', i.e., s.length(), duke@435: // points to the right of the last element. duke@435: if (length==0) { duke@435: return; duke@435: } coleenp@548: if (UseCompressedOops) { coleenp@548: narrowOop* const src = objArrayOop(s)->obj_at_addr(src_pos); coleenp@548: narrowOop* const dst = objArrayOop(d)->obj_at_addr(dst_pos); coleenp@548: do_copy(s, src, d, dst, length, CHECK); duke@435: } else { coleenp@548: oop* const src = objArrayOop(s)->obj_at_addr(src_pos); coleenp@548: oop* const dst = objArrayOop(d)->obj_at_addr(dst_pos); coleenp@548: do_copy (s, src, d, dst, length, CHECK); duke@435: } duke@435: } duke@435: duke@435: coleenp@4142: Klass* ObjArrayKlass::array_klass_impl(bool or_null, int n, TRAPS) { duke@435: coleenp@4037: assert(dimension() <= n, "check order of chain"); coleenp@4037: int dim = dimension(); coleenp@4037: if (dim == n) return this; duke@435: coleenp@4037: if (higher_dimension() == NULL) { duke@435: if (or_null) return NULL; duke@435: duke@435: ResourceMark rm; duke@435: JavaThread *jt = (JavaThread *)THREAD; duke@435: { duke@435: MutexLocker mc(Compile_lock, THREAD); // for vtables duke@435: // Ensure atomic creation of higher dimensions duke@435: MutexLocker mu(MultiArray_lock, THREAD); duke@435: duke@435: // Check if another thread beat us coleenp@4037: if (higher_dimension() == NULL) { duke@435: duke@435: // Create multi-dim klass object and link them together coleenp@4037: Klass* k = coleenp@4142: ObjArrayKlass::allocate_objArray_klass(class_loader_data(), dim + 1, this, CHECK_NULL); coleenp@4142: ObjArrayKlass* ak = ObjArrayKlass::cast(k); coleenp@4037: ak->set_lower_dimension(this); kvn@2439: OrderAccess::storestore(); coleenp@4037: set_higher_dimension(ak); coleenp@4142: assert(ak->oop_is_objArray(), "incorrect initialization of ObjArrayKlass"); duke@435: } duke@435: } duke@435: } else { duke@435: CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops()); duke@435: } duke@435: coleenp@4142: ObjArrayKlass *ak = ObjArrayKlass::cast(higher_dimension()); duke@435: if (or_null) { duke@435: return ak->array_klass_or_null(n); duke@435: } duke@435: return ak->array_klass(n, CHECK_NULL); duke@435: } duke@435: coleenp@4142: Klass* ObjArrayKlass::array_klass_impl(bool or_null, TRAPS) { duke@435: return array_klass_impl(or_null, dimension() + 1, CHECK_NULL); duke@435: } duke@435: coleenp@4142: bool ObjArrayKlass::can_be_primary_super_slow() const { coleenp@4037: if (!bottom_klass()->can_be_primary_super()) duke@435: // array of interfaces duke@435: return false; duke@435: else duke@435: return Klass::can_be_primary_super_slow(); duke@435: } duke@435: coleenp@4142: GrowableArray* ObjArrayKlass::compute_secondary_supers(int num_extra_slots) { duke@435: // interfaces = { cloneable_klass, serializable_klass, elemSuper[], ... }; hseigel@4278: Array* elem_supers = element_klass()->secondary_supers(); coleenp@4037: int num_elem_supers = elem_supers == NULL ? 0 : elem_supers->length(); duke@435: int num_secondaries = num_extra_slots + 2 + num_elem_supers; duke@435: if (num_secondaries == 2) { duke@435: // Must share this for correct bootstrapping! coleenp@4037: set_secondary_supers(Universe::the_array_interfaces_array()); coleenp@4037: return NULL; duke@435: } else { coleenp@4037: GrowableArray* secondaries = new GrowableArray(num_elem_supers+2); coleenp@4037: secondaries->push(SystemDictionary::Cloneable_klass()); coleenp@4037: secondaries->push(SystemDictionary::Serializable_klass()); duke@435: for (int i = 0; i < num_elem_supers; i++) { coleenp@4037: Klass* elem_super = (Klass*) elem_supers->at(i); coleenp@4037: Klass* array_super = elem_super->array_klass_or_null(); duke@435: assert(array_super != NULL, "must already have been created"); coleenp@4037: secondaries->push(array_super); duke@435: } coleenp@4037: return secondaries; duke@435: } duke@435: } duke@435: coleenp@4142: bool ObjArrayKlass::compute_is_subtype_of(Klass* k) { coleenp@4037: if (!k->oop_is_objArray()) coleenp@4142: return ArrayKlass::compute_is_subtype_of(k); duke@435: coleenp@4142: ObjArrayKlass* oak = ObjArrayKlass::cast(k); coleenp@4037: return element_klass()->is_subtype_of(oak->element_klass()); duke@435: } duke@435: coleenp@4142: void ObjArrayKlass::initialize(TRAPS) { hseigel@4278: bottom_klass()->initialize(THREAD); // dispatches to either InstanceKlass or TypeArrayKlass duke@435: } duke@435: coleenp@548: #define ObjArrayKlass_SPECIALIZED_OOP_ITERATE(T, a, p, do_oop) \ coleenp@548: { \ coleenp@548: T* p = (T*)(a)->base(); \ coleenp@548: T* const end = p + (a)->length(); \ coleenp@548: while (p < end) { \ coleenp@548: do_oop; \ coleenp@548: p++; \ coleenp@548: } \ coleenp@548: } coleenp@548: coleenp@548: #define ObjArrayKlass_SPECIALIZED_BOUNDED_OOP_ITERATE(T, a, p, low, high, do_oop) \ coleenp@548: { \ coleenp@548: T* const l = (T*)(low); \ coleenp@548: T* const h = (T*)(high); \ coleenp@548: T* p = (T*)(a)->base(); \ coleenp@548: T* end = p + (a)->length(); \ coleenp@548: if (p < l) p = l; \ coleenp@548: if (end > h) end = h; \ coleenp@548: while (p < end) { \ coleenp@548: do_oop; \ coleenp@548: ++p; \ coleenp@548: } \ coleenp@548: } coleenp@548: coleenp@548: #define ObjArrayKlass_OOP_ITERATE(a, p, do_oop) \ coleenp@548: if (UseCompressedOops) { \ coleenp@548: ObjArrayKlass_SPECIALIZED_OOP_ITERATE(narrowOop, \ coleenp@548: a, p, do_oop) \ coleenp@548: } else { \ coleenp@548: ObjArrayKlass_SPECIALIZED_OOP_ITERATE(oop, \ coleenp@548: a, p, do_oop) \ coleenp@548: } coleenp@548: coleenp@548: #define ObjArrayKlass_BOUNDED_OOP_ITERATE(a, p, low, high, do_oop) \ coleenp@548: if (UseCompressedOops) { \ coleenp@548: ObjArrayKlass_SPECIALIZED_BOUNDED_OOP_ITERATE(narrowOop, \ coleenp@548: a, p, low, high, do_oop) \ coleenp@548: } else { \ coleenp@548: ObjArrayKlass_SPECIALIZED_BOUNDED_OOP_ITERATE(oop, \ coleenp@548: a, p, low, high, do_oop) \ coleenp@548: } duke@435: coleenp@4142: void ObjArrayKlass::oop_follow_contents(oop obj) { duke@435: assert (obj->is_array(), "obj must be array"); coleenp@4037: MarkSweep::follow_klass(obj->klass()); jcoomes@1746: if (UseCompressedOops) { jcoomes@1746: objarray_follow_contents(obj, 0); jcoomes@1746: } else { jcoomes@1746: objarray_follow_contents(obj, 0); jcoomes@1746: } duke@435: } duke@435: jprovino@4542: #if INCLUDE_ALL_GCS coleenp@4142: void ObjArrayKlass::oop_follow_contents(ParCompactionManager* cm, duke@435: oop obj) { jcoomes@1746: assert(obj->is_array(), "obj must be array"); coleenp@4037: PSParallelCompact::follow_klass(cm, obj->klass()); jcoomes@1746: if (UseCompressedOops) { jcoomes@1746: objarray_follow_contents(cm, obj, 0); jcoomes@1746: } else { jcoomes@1746: objarray_follow_contents(cm, obj, 0); jcoomes@1746: } duke@435: } jprovino@4542: #endif // INCLUDE_ALL_GCS duke@435: duke@435: #define ObjArrayKlass_OOP_OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \ duke@435: \ coleenp@4142: int ObjArrayKlass::oop_oop_iterate##nv_suffix(oop obj, \ duke@435: OopClosureType* closure) { \ duke@435: SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::oa); \ duke@435: assert (obj->is_array(), "obj must be array"); \ duke@435: objArrayOop a = objArrayOop(obj); \ duke@435: /* Get size before changing pointers. */ \ duke@435: /* Don't call size() or oop_size() since that is a virtual call. */ \ duke@435: int size = a->object_size(); \ coleenp@4037: if_do_metadata_checked(closure, nv_suffix) { \ coleenp@4037: closure->do_klass##nv_suffix(obj->klass()); \ duke@435: } \ coleenp@548: ObjArrayKlass_OOP_ITERATE(a, p, (closure)->do_oop##nv_suffix(p)) \ duke@435: return size; \ duke@435: } duke@435: duke@435: #define ObjArrayKlass_OOP_OOP_ITERATE_DEFN_m(OopClosureType, nv_suffix) \ duke@435: \ coleenp@4142: int ObjArrayKlass::oop_oop_iterate##nv_suffix##_m(oop obj, \ duke@435: OopClosureType* closure, \ duke@435: MemRegion mr) { \ duke@435: SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::oa); \ duke@435: assert(obj->is_array(), "obj must be array"); \ duke@435: objArrayOop a = objArrayOop(obj); \ duke@435: /* Get size before changing pointers. */ \ duke@435: /* Don't call size() or oop_size() since that is a virtual call */ \ duke@435: int size = a->object_size(); \ coleenp@4037: if_do_metadata_checked(closure, nv_suffix) { \ coleenp@4037: /* SSS: Do we need to pass down mr here? */ \ coleenp@4037: closure->do_klass##nv_suffix(a->klass()); \ duke@435: } \ coleenp@548: ObjArrayKlass_BOUNDED_OOP_ITERATE( \ coleenp@548: a, p, mr.start(), mr.end(), (closure)->do_oop##nv_suffix(p)) \ coleenp@548: return size; \ coleenp@548: } coleenp@548: coleenp@548: // Like oop_oop_iterate but only iterates over a specified range and only used coleenp@548: // for objArrayOops. coleenp@548: #define ObjArrayKlass_OOP_OOP_ITERATE_DEFN_r(OopClosureType, nv_suffix) \ coleenp@548: \ coleenp@4142: int ObjArrayKlass::oop_oop_iterate_range##nv_suffix(oop obj, \ coleenp@548: OopClosureType* closure, \ coleenp@548: int start, int end) { \ coleenp@548: SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::oa); \ coleenp@548: assert(obj->is_array(), "obj must be array"); \ coleenp@548: objArrayOop a = objArrayOop(obj); \ coleenp@548: /* Get size before changing pointers. */ \ coleenp@548: /* Don't call size() or oop_size() since that is a virtual call */ \ coleenp@548: int size = a->object_size(); \ coleenp@548: if (UseCompressedOops) { \ coleenp@548: HeapWord* low = start == 0 ? (HeapWord*)a : (HeapWord*)a->obj_at_addr(start);\ coleenp@548: /* this might be wierd if end needs to be aligned on HeapWord boundary */ \ coleenp@548: HeapWord* high = (HeapWord*)((narrowOop*)a->base() + end); \ coleenp@548: MemRegion mr(low, high); \ coleenp@4037: if_do_metadata_checked(closure, nv_suffix) { \ coleenp@4037: /* SSS: Do we need to pass down mr here? */ \ coleenp@4037: closure->do_klass##nv_suffix(a->klass()); \ duke@435: } \ coleenp@548: ObjArrayKlass_SPECIALIZED_BOUNDED_OOP_ITERATE(narrowOop, \ coleenp@548: a, p, low, high, (closure)->do_oop##nv_suffix(p)) \ duke@435: } else { \ coleenp@548: HeapWord* low = start == 0 ? (HeapWord*)a : (HeapWord*)a->obj_at_addr(start); \ coleenp@548: HeapWord* high = (HeapWord*)((oop*)a->base() + end); \ coleenp@548: MemRegion mr(low, high); \ coleenp@4037: if_do_metadata_checked(closure, nv_suffix) { \ coleenp@4037: /* SSS: Do we need to pass down mr here? */ \ coleenp@4037: closure->do_klass##nv_suffix(a->klass()); \ duke@435: } \ coleenp@548: ObjArrayKlass_SPECIALIZED_BOUNDED_OOP_ITERATE(oop, \ coleenp@548: a, p, low, high, (closure)->do_oop##nv_suffix(p)) \ duke@435: } \ duke@435: return size; \ duke@435: } duke@435: duke@435: ALL_OOP_OOP_ITERATE_CLOSURES_1(ObjArrayKlass_OOP_OOP_ITERATE_DEFN) ysr@777: ALL_OOP_OOP_ITERATE_CLOSURES_2(ObjArrayKlass_OOP_OOP_ITERATE_DEFN) duke@435: ALL_OOP_OOP_ITERATE_CLOSURES_1(ObjArrayKlass_OOP_OOP_ITERATE_DEFN_m) ysr@777: ALL_OOP_OOP_ITERATE_CLOSURES_2(ObjArrayKlass_OOP_OOP_ITERATE_DEFN_m) coleenp@548: ALL_OOP_OOP_ITERATE_CLOSURES_1(ObjArrayKlass_OOP_OOP_ITERATE_DEFN_r) ysr@777: ALL_OOP_OOP_ITERATE_CLOSURES_2(ObjArrayKlass_OOP_OOP_ITERATE_DEFN_r) duke@435: coleenp@4142: int ObjArrayKlass::oop_adjust_pointers(oop obj) { duke@435: assert(obj->is_objArray(), "obj must be obj array"); duke@435: objArrayOop a = objArrayOop(obj); duke@435: // Get size before changing pointers. duke@435: // Don't call size() or oop_size() since that is a virtual call. duke@435: int size = a->object_size(); coleenp@548: ObjArrayKlass_OOP_ITERATE(a, p, MarkSweep::adjust_pointer(p)) duke@435: return size; duke@435: } duke@435: jprovino@4542: #if INCLUDE_ALL_GCS coleenp@4142: void ObjArrayKlass::oop_push_contents(PSPromotionManager* pm, oop obj) { duke@435: assert(obj->is_objArray(), "obj must be obj array"); coleenp@548: ObjArrayKlass_OOP_ITERATE( \ coleenp@548: objArrayOop(obj), p, \ coleenp@548: if (PSScavenge::should_scavenge(p)) { \ coleenp@548: pm->claim_or_forward_depth(p); \ coleenp@548: }) duke@435: } duke@435: coleenp@4142: int ObjArrayKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) { duke@435: assert (obj->is_objArray(), "obj must be obj array"); duke@435: objArrayOop a = objArrayOop(obj); coleenp@4037: int size = a->object_size(); coleenp@548: ObjArrayKlass_OOP_ITERATE(a, p, PSParallelCompact::adjust_pointer(p)) coleenp@4037: return size; duke@435: } jprovino@4542: #endif // INCLUDE_ALL_GCS duke@435: duke@435: // JVM support duke@435: coleenp@4142: jint ObjArrayKlass::compute_modifier_flags(TRAPS) const { duke@435: // The modifier for an objectArray is the same as its element duke@435: if (element_klass() == NULL) { duke@435: assert(Universe::is_bootstrapping(), "partial objArray only at startup"); duke@435: return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC; duke@435: } coleenp@833: // Return the flags of the bottom element type. hseigel@4278: jint element_flags = bottom_klass()->compute_modifier_flags(CHECK_0); duke@435: duke@435: return (element_flags & (JVM_ACC_PUBLIC | JVM_ACC_PRIVATE | JVM_ACC_PROTECTED)) duke@435: | (JVM_ACC_ABSTRACT | JVM_ACC_FINAL); duke@435: } duke@435: duke@435: coleenp@4037: // Printing coleenp@4037: coleenp@4142: void ObjArrayKlass::print_on(outputStream* st) const { duke@435: #ifndef PRODUCT coleenp@4037: Klass::print_on(st); coleenp@4037: st->print(" - instance klass: "); coleenp@4037: element_klass()->print_value_on(st); coleenp@4037: st->cr(); coleenp@4037: #endif //PRODUCT coleenp@4037: } coleenp@4037: coleenp@4142: void ObjArrayKlass::print_value_on(outputStream* st) const { coleenp@4037: assert(is_klass(), "must be klass"); coleenp@4037: coleenp@4037: element_klass()->print_value_on(st); coleenp@4037: st->print("[]"); coleenp@4037: } coleenp@4037: coleenp@4037: #ifndef PRODUCT duke@435: coleenp@4142: void ObjArrayKlass::oop_print_on(oop obj, outputStream* st) { coleenp@4142: ArrayKlass::oop_print_on(obj, st); duke@435: assert(obj->is_objArray(), "must be objArray"); duke@435: objArrayOop oa = objArrayOop(obj); duke@435: int print_len = MIN2((intx) oa->length(), MaxElementPrintSize); duke@435: for(int index = 0; index < print_len; index++) { duke@435: st->print(" - %3d : ", index); duke@435: oa->obj_at(index)->print_value_on(st); duke@435: st->cr(); duke@435: } duke@435: int remaining = oa->length() - print_len; duke@435: if (remaining > 0) { stefank@4126: st->print_cr(" - <%d more elements, increase MaxElementPrintSize to print>", remaining); duke@435: } duke@435: } duke@435: jrose@1590: #endif //PRODUCT jrose@1590: jrose@1100: static int max_objArray_print_length = 4; duke@435: coleenp@4142: void ObjArrayKlass::oop_print_value_on(oop obj, outputStream* st) { duke@435: assert(obj->is_objArray(), "must be objArray"); jrose@1100: st->print("a "); duke@435: element_klass()->print_value_on(st); jrose@1100: int len = objArrayOop(obj)->length(); jrose@1100: st->print("[%d] ", len); jrose@1100: obj->print_address_on(st); jrose@1590: if (NOT_PRODUCT(PrintOopAddress ||) PrintMiscellaneous && (WizardMode || Verbose)) { jrose@1100: st->print("{"); jrose@1100: for (int i = 0; i < len; i++) { jrose@1100: if (i > max_objArray_print_length) { jrose@1100: st->print("..."); break; jrose@1100: } jrose@1100: st->print(" "INTPTR_FORMAT, (intptr_t)(void*)objArrayOop(obj)->obj_at(i)); jrose@1100: } jrose@1100: st->print(" }"); jrose@1100: } duke@435: } duke@435: coleenp@4142: const char* ObjArrayKlass::internal_name() const { duke@435: return external_name(); duke@435: } duke@435: coleenp@4037: duke@435: // Verification duke@435: coleenp@6316: void ObjArrayKlass::verify_on(outputStream* st) { coleenp@6316: ArrayKlass::verify_on(st); coleenp@4037: guarantee(element_klass()->is_klass(), "should be klass"); coleenp@4037: guarantee(bottom_klass()->is_klass(), "should be klass"); hseigel@4278: Klass* bk = bottom_klass(); coleenp@4037: guarantee(bk->oop_is_instance() || bk->oop_is_typeArray(), "invalid bottom klass"); coleenp@4037: } coleenp@4037: coleenp@4142: void ObjArrayKlass::oop_verify_on(oop obj, outputStream* st) { coleenp@4142: ArrayKlass::oop_verify_on(obj, st); duke@435: guarantee(obj->is_objArray(), "must be objArray"); duke@435: objArrayOop oa = objArrayOop(obj); duke@435: for(int index = 0; index < oa->length(); index++) { duke@435: guarantee(oa->obj_at(index)->is_oop_or_null(), "should be oop"); duke@435: } duke@435: }