arrayKlass.cpp revision 3322
0N/A/*
3322N/A * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "classfile/javaClasses.hpp"
1879N/A#include "classfile/systemDictionary.hpp"
1879N/A#include "classfile/vmSymbols.hpp"
1879N/A#include "gc_interface/collectedHeap.inline.hpp"
1879N/A#include "jvmtifiles/jvmti.h"
1879N/A#include "memory/gcLocker.hpp"
1879N/A#include "memory/universe.inline.hpp"
1879N/A#include "oops/arrayKlass.hpp"
1879N/A#include "oops/arrayKlassKlass.hpp"
1879N/A#include "oops/arrayOop.hpp"
1879N/A#include "oops/instanceKlass.hpp"
1879N/A#include "oops/objArrayOop.hpp"
1879N/A#include "oops/oop.inline.hpp"
0N/A
0N/Aint arrayKlass::object_size(int header_size) const {
0N/A // size of an array klass object
0N/A assert(header_size <= instanceKlass::header_size(), "bad header size");
0N/A // If this assert fails, see comments in base_create_array_klass.
0N/A header_size = instanceKlass::header_size();
0N/A#ifdef _LP64
0N/A int size = header_size + align_object_offset(vtable_length());
0N/A#else
0N/A int size = header_size + vtable_length();
0N/A#endif
0N/A return align_object_size(size);
0N/A}
0N/A
0N/A
0N/AklassOop arrayKlass::java_super() const {
0N/A if (super() == NULL) return NULL; // bootstrap case
0N/A // Array klasses have primary supertypes which are not reported to Java.
0N/A // Example super chain: String[][] -> Object[][] -> Object[] -> Object
1142N/A return SystemDictionary::Object_klass();
0N/A}
0N/A
0N/A
0N/Aoop arrayKlass::multi_allocate(int rank, jint* sizes, TRAPS) {
0N/A ShouldNotReachHere();
0N/A return NULL;
0N/A}
0N/A
2062N/AmethodOop arrayKlass::uncached_lookup_method(Symbol* name, Symbol* signature) const {
0N/A // There are no methods in an array klass but the super class (Object) has some
0N/A assert(super(), "super klass must be present");
0N/A return Klass::cast(super())->uncached_lookup_method(name, signature);
0N/A}
0N/A
0N/A
0N/AarrayKlassHandle arrayKlass::base_create_array_klass(
0N/Aconst Klass_vtbl& cplusplus_vtbl, int header_size, KlassHandle klass, TRAPS) {
0N/A // Allocation
0N/A // Note: because the Java vtable must start at the same offset in all klasses,
0N/A // we must insert filler fields into arrayKlass to make it the same size as instanceKlass.
0N/A // If this assert fails, add filler to instanceKlass to make it bigger.
0N/A assert(header_size <= instanceKlass::header_size(),
0N/A "array klasses must be same size as instanceKlass");
0N/A header_size = instanceKlass::header_size();
0N/A // Arrays don't add any new methods, so their vtable is the same size as
0N/A // the vtable of klass Object.
0N/A int vtable_size = Universe::base_vtable_size();
0N/A arrayKlassHandle k;
0N/A KlassHandle base_klass = Klass::base_create_klass(klass,
0N/A header_size + vtable_size,
0N/A cplusplus_vtbl, CHECK_(k));
0N/A
0N/A // No safepoint should be possible until the handle's
0N/A // target below becomes parsable
0N/A No_Safepoint_Verifier no_safepoint;
0N/A k = arrayKlassHandle(THREAD, base_klass());
0N/A
0N/A assert(!k()->is_parsable(), "not expecting parsability yet.");
1142N/A k->set_super(Universe::is_bootstrapping() ? (klassOop)NULL : SystemDictionary::Object_klass());
0N/A k->set_layout_helper(Klass::_lh_neutral_value);
0N/A k->set_dimension(1);
0N/A k->set_higher_dimension(NULL);
0N/A k->set_lower_dimension(NULL);
0N/A k->set_component_mirror(NULL);
0N/A k->set_vtable_length(vtable_size);
0N/A k->set_is_cloneable(); // All arrays are considered to be cloneable (See JLS 20.1.5)
0N/A
0N/A assert(k()->is_parsable(), "should be parsable here.");
0N/A // Make sure size calculation is right
0N/A assert(k()->size() == align_object_size(header_size + vtable_size), "wrong size for object");
0N/A
0N/A return k;
0N/A}
0N/A
0N/A
0N/A// Initialization of vtables and mirror object is done separatly from base_create_array_klass,
0N/A// since a GC can happen. At this point all instance variables of the arrayKlass must be setup.
0N/Avoid arrayKlass::complete_create_array_klass(arrayKlassHandle k, KlassHandle super_klass, TRAPS) {
0N/A ResourceMark rm(THREAD);
0N/A k->initialize_supers(super_klass(), CHECK);
0N/A k->vtable()->initialize_vtable(false, CHECK);
0N/A java_lang_Class::create_mirror(k, CHECK);
0N/A}
0N/A
0N/AobjArrayOop arrayKlass::compute_secondary_supers(int num_extra_slots, TRAPS) {
0N/A // interfaces = { cloneable_klass, serializable_klass };
0N/A assert(num_extra_slots == 0, "sanity of primitive array type");
0N/A // Must share this for correct bootstrapping!
0N/A return Universe::the_array_interfaces_array();
0N/A}
0N/A
0N/Abool arrayKlass::compute_is_subtype_of(klassOop k) {
0N/A // An array is a subtype of Serializable, Clonable, and Object
1142N/A return k == SystemDictionary::Object_klass()
1142N/A || k == SystemDictionary::Cloneable_klass()
1142N/A || k == SystemDictionary::Serializable_klass();
0N/A}
0N/A
0N/A
0N/Ainline intptr_t* arrayKlass::start_of_vtable() const {
0N/A // all vtables start at the same place, that's why we use instanceKlass::header_size here
0N/A return ((intptr_t*)as_klassOop()) + instanceKlass::header_size();
0N/A}
0N/A
0N/A
0N/AklassVtable* arrayKlass::vtable() const {
0N/A KlassHandle kh(Thread::current(), as_klassOop());
0N/A return new klassVtable(kh, start_of_vtable(), vtable_length() / vtableEntry::size());
0N/A}
0N/A
0N/A
0N/AobjArrayOop arrayKlass::allocate_arrayArray(int n, int length, TRAPS) {
0N/A if (length < 0) {
0N/A THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
0N/A }
0N/A if (length > arrayOopDesc::max_array_length(T_ARRAY)) {
876N/A report_java_out_of_memory("Requested array size exceeds VM limit");
3322N/A JvmtiExport::post_array_size_exhausted();
0N/A THROW_OOP_0(Universe::out_of_memory_error_array_size());
0N/A }
0N/A int size = objArrayOopDesc::object_size(length);
0N/A klassOop k = array_klass(n+dimension(), CHECK_0);
0N/A arrayKlassHandle ak (THREAD, k);
0N/A objArrayOop o =
0N/A (objArrayOop)CollectedHeap::array_allocate(ak, size, length, CHECK_0);
0N/A // initialization to NULL not necessary, area already cleared
0N/A return o;
0N/A}
0N/A
0N/A
0N/Avoid arrayKlass::array_klasses_do(void f(klassOop k)) {
0N/A klassOop k = as_klassOop();
0N/A // Iterate over this array klass and all higher dimensions
0N/A while (k != NULL) {
0N/A f(k);
0N/A k = arrayKlass::cast(k)->higher_dimension();
0N/A }
0N/A}
0N/A
0N/A
0N/Avoid arrayKlass::with_array_klasses_do(void f(klassOop k)) {
0N/A array_klasses_do(f);
0N/A}
0N/A
0N/A// JVM support
0N/A
0N/Ajint arrayKlass::compute_modifier_flags(TRAPS) const {
0N/A return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
0N/A}
0N/A
0N/A// JVMTI support
0N/A
0N/Ajint arrayKlass::jvmti_class_status() const {
0N/A return JVMTI_CLASS_STATUS_ARRAY;
0N/A}
0N/A
0N/A// Printing
0N/A
0N/Avoid arrayKlass::oop_print_on(oop obj, outputStream* st) {
0N/A assert(obj->is_array(), "must be array");
0N/A Klass::oop_print_on(obj, st);
0N/A st->print_cr(" - length: %d", arrayOop(obj)->length());
0N/A}
0N/A
0N/A// Verification
0N/A
0N/Avoid arrayKlass::oop_verify_on(oop obj, outputStream* st) {
0N/A guarantee(obj->is_array(), "must be array");
0N/A arrayOop a = arrayOop(obj);
0N/A guarantee(a->length() >= 0, "array with negative length?");
0N/A}