duke@435: /* sspitsyn@3638: * Copyright (c) 1997, 2012, 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" stefank@2314: #include "classfile/javaClasses.hpp" stefank@2314: #include "classfile/systemDictionary.hpp" stefank@2314: #include "classfile/vmSymbols.hpp" stefank@2314: #include "gc_interface/collectedHeap.inline.hpp" stefank@2314: #include "jvmtifiles/jvmti.h" stefank@2314: #include "memory/gcLocker.hpp" stefank@2314: #include "memory/universe.inline.hpp" stefank@2314: #include "oops/arrayKlass.hpp" stefank@2314: #include "oops/arrayOop.hpp" stefank@2314: #include "oops/instanceKlass.hpp" stefank@2314: #include "oops/objArrayOop.hpp" stefank@2314: #include "oops/oop.inline.hpp" duke@435: coleenp@4142: int ArrayKlass::static_size(int header_size) { duke@435: // size of an array klass object coleenp@4037: assert(header_size <= InstanceKlass::header_size(), "bad header size"); duke@435: // If this assert fails, see comments in base_create_array_klass. coleenp@4037: header_size = InstanceKlass::header_size(); coleenp@4037: int vtable_len = Universe::base_vtable_size(); duke@435: #ifdef _LP64 coleenp@4037: int size = header_size + align_object_offset(vtable_len); duke@435: #else coleenp@4037: int size = header_size + vtable_len; duke@435: #endif duke@435: return align_object_size(size); duke@435: } duke@435: duke@435: coleenp@4142: Klass* ArrayKlass::java_super() const { duke@435: if (super() == NULL) return NULL; // bootstrap case duke@435: // Array klasses have primary supertypes which are not reported to Java. duke@435: // Example super chain: String[][] -> Object[][] -> Object[] -> Object never@1577: return SystemDictionary::Object_klass(); duke@435: } duke@435: duke@435: coleenp@4142: oop ArrayKlass::multi_allocate(int rank, jint* sizes, TRAPS) { duke@435: ShouldNotReachHere(); duke@435: return NULL; duke@435: } duke@435: coleenp@4142: Method* ArrayKlass::uncached_lookup_method(Symbol* name, Symbol* signature) const { duke@435: // There are no methods in an array klass but the super class (Object) has some duke@435: assert(super(), "super klass must be present"); duke@435: return Klass::cast(super())->uncached_lookup_method(name, signature); duke@435: } duke@435: coleenp@4142: ArrayKlass::ArrayKlass(Symbol* name) { coleenp@4037: set_alloc_size(0); coleenp@4037: set_name(name); duke@435: coleenp@4037: set_super(Universe::is_bootstrapping() ? (Klass*)NULL : SystemDictionary::Object_klass()); coleenp@4037: set_layout_helper(Klass::_lh_neutral_value); coleenp@4037: set_dimension(1); coleenp@4037: set_higher_dimension(NULL); coleenp@4037: set_lower_dimension(NULL); coleenp@4037: set_component_mirror(NULL); duke@435: // Arrays don't add any new methods, so their vtable is the same size as duke@435: // the vtable of klass Object. duke@435: int vtable_size = Universe::base_vtable_size(); coleenp@4037: set_vtable_length(vtable_size); coleenp@4037: set_is_cloneable(); // All arrays are considered to be cloneable (See JLS 20.1.5) duke@435: } duke@435: duke@435: duke@435: // Initialization of vtables and mirror object is done separatly from base_create_array_klass, coleenp@4142: // since a GC can happen. At this point all instance variables of the ArrayKlass must be setup. coleenp@4142: void ArrayKlass::complete_create_array_klass(ArrayKlass* k, KlassHandle super_klass, TRAPS) { duke@435: ResourceMark rm(THREAD); duke@435: k->initialize_supers(super_klass(), CHECK); duke@435: k->vtable()->initialize_vtable(false, CHECK); duke@435: java_lang_Class::create_mirror(k, CHECK); duke@435: } duke@435: coleenp@4142: GrowableArray* ArrayKlass::compute_secondary_supers(int num_extra_slots) { duke@435: // interfaces = { cloneable_klass, serializable_klass }; duke@435: assert(num_extra_slots == 0, "sanity of primitive array type"); duke@435: // Must share this for correct bootstrapping! coleenp@4037: set_secondary_supers(Universe::the_array_interfaces_array()); coleenp@4037: return NULL; duke@435: } duke@435: coleenp@4142: bool ArrayKlass::compute_is_subtype_of(Klass* k) { duke@435: // An array is a subtype of Serializable, Clonable, and Object never@1577: return k == SystemDictionary::Object_klass() never@1577: || k == SystemDictionary::Cloneable_klass() never@1577: || k == SystemDictionary::Serializable_klass(); duke@435: } duke@435: duke@435: coleenp@4142: inline intptr_t* ArrayKlass::start_of_vtable() const { coleenp@4037: // all vtables start at the same place, that's why we use InstanceKlass::header_size here coleenp@4037: return ((intptr_t*)this) + InstanceKlass::header_size(); duke@435: } duke@435: duke@435: coleenp@4142: klassVtable* ArrayKlass::vtable() const { coleenp@4037: KlassHandle kh(Thread::current(), this); duke@435: return new klassVtable(kh, start_of_vtable(), vtable_length() / vtableEntry::size()); duke@435: } duke@435: duke@435: coleenp@4142: objArrayOop ArrayKlass::allocate_arrayArray(int n, int length, TRAPS) { duke@435: if (length < 0) { duke@435: THROW_0(vmSymbols::java_lang_NegativeArraySizeException()); duke@435: } duke@435: if (length > arrayOopDesc::max_array_length(T_ARRAY)) { 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: int size = objArrayOopDesc::object_size(length); coleenp@4037: Klass* k = array_klass(n+dimension(), CHECK_0); coleenp@4142: ArrayKlass* ak = ArrayKlass::cast(k); duke@435: objArrayOop o = duke@435: (objArrayOop)CollectedHeap::array_allocate(ak, size, length, CHECK_0); duke@435: // initialization to NULL not necessary, area already cleared duke@435: return o; duke@435: } duke@435: coleenp@4142: void ArrayKlass::array_klasses_do(void f(Klass* k, TRAPS), TRAPS) { coleenp@4037: Klass* k = this; coleenp@4037: // Iterate over this array klass and all higher dimensions coleenp@4037: while (k != NULL) { coleenp@4037: f(k, CHECK); coleenp@4142: k = ArrayKlass::cast(k)->higher_dimension(); coleenp@4037: } coleenp@4037: } duke@435: coleenp@4142: void ArrayKlass::array_klasses_do(void f(Klass* k)) { coleenp@4037: Klass* k = this; duke@435: // Iterate over this array klass and all higher dimensions duke@435: while (k != NULL) { duke@435: f(k); coleenp@4142: k = ArrayKlass::cast(k)->higher_dimension(); duke@435: } duke@435: } duke@435: duke@435: coleenp@4142: void ArrayKlass::with_array_klasses_do(void f(Klass* k)) { duke@435: array_klasses_do(f); duke@435: } duke@435: coleenp@4037: coleenp@4037: // GC support coleenp@4037: coleenp@4142: void ArrayKlass::oops_do(OopClosure* cl) { coleenp@4037: Klass::oops_do(cl); coleenp@4037: coleenp@4037: cl->do_oop(adr_component_mirror()); coleenp@4037: } coleenp@4037: duke@435: // JVM support duke@435: coleenp@4142: jint ArrayKlass::compute_modifier_flags(TRAPS) const { duke@435: return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC; duke@435: } duke@435: duke@435: // JVMTI support duke@435: coleenp@4142: jint ArrayKlass::jvmti_class_status() const { duke@435: return JVMTI_CLASS_STATUS_ARRAY; duke@435: } duke@435: coleenp@4142: void ArrayKlass::remove_unshareable_info() { coleenp@4037: Klass::remove_unshareable_info(); coleenp@4037: // Clear the java mirror coleenp@4037: set_component_mirror(NULL); coleenp@4037: } coleenp@4037: coleenp@4142: void ArrayKlass::restore_unshareable_info(TRAPS) { coleenp@4037: Klass::restore_unshareable_info(CHECK); coleenp@4037: // Klass recreates the component mirror also coleenp@4037: } coleenp@4037: duke@435: // Printing duke@435: coleenp@4142: void ArrayKlass::print_on(outputStream* st) const { coleenp@4037: assert(is_klass(), "must be klass"); coleenp@4037: Klass::print_on(st); coleenp@4037: } coleenp@4037: coleenp@4142: void ArrayKlass::print_value_on(outputStream* st) const { coleenp@4037: assert(is_klass(), "must be klass"); coleenp@4037: for(int index = 0; index < dimension(); index++) { coleenp@4037: st->print("[]"); coleenp@4037: } coleenp@4037: } coleenp@4037: coleenp@4142: void ArrayKlass::oop_print_on(oop obj, outputStream* st) { duke@435: assert(obj->is_array(), "must be array"); duke@435: Klass::oop_print_on(obj, st); duke@435: st->print_cr(" - length: %d", arrayOop(obj)->length()); duke@435: } duke@435: coleenp@4037: duke@435: // Verification duke@435: coleenp@4142: void ArrayKlass::verify_on(outputStream* st) { coleenp@4037: Klass::verify_on(st); coleenp@4037: coleenp@4037: if (component_mirror() != NULL) { coleenp@4037: guarantee(component_mirror()->klass() != NULL, "should have a class"); coleenp@4037: } coleenp@4037: } coleenp@4037: coleenp@4142: void ArrayKlass::oop_verify_on(oop obj, outputStream* st) { duke@435: guarantee(obj->is_array(), "must be array"); duke@435: arrayOop a = arrayOop(obj); duke@435: guarantee(a->length() >= 0, "array with negative length?"); duke@435: }