src/share/vm/oops/arrayKlass.cpp

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 435
a61af66fc99e
child 1311
1413494da700
permissions
-rw-r--r--

Initial load

duke@435 1 /*
duke@435 2 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 # include "incls/_precompiled.incl"
duke@435 26 # include "incls/_arrayKlass.cpp.incl"
duke@435 27
duke@435 28 int arrayKlass::object_size(int header_size) const {
duke@435 29 // size of an array klass object
duke@435 30 assert(header_size <= instanceKlass::header_size(), "bad header size");
duke@435 31 // If this assert fails, see comments in base_create_array_klass.
duke@435 32 header_size = instanceKlass::header_size();
duke@435 33 #ifdef _LP64
duke@435 34 int size = header_size + align_object_offset(vtable_length());
duke@435 35 #else
duke@435 36 int size = header_size + vtable_length();
duke@435 37 #endif
duke@435 38 return align_object_size(size);
duke@435 39 }
duke@435 40
duke@435 41
duke@435 42 klassOop arrayKlass::java_super() const {
duke@435 43 if (super() == NULL) return NULL; // bootstrap case
duke@435 44 // Array klasses have primary supertypes which are not reported to Java.
duke@435 45 // Example super chain: String[][] -> Object[][] -> Object[] -> Object
duke@435 46 return SystemDictionary::object_klass();
duke@435 47 }
duke@435 48
duke@435 49
duke@435 50 oop arrayKlass::multi_allocate(int rank, jint* sizes, TRAPS) {
duke@435 51 ShouldNotReachHere();
duke@435 52 return NULL;
duke@435 53 }
duke@435 54
duke@435 55 methodOop arrayKlass::uncached_lookup_method(symbolOop name, symbolOop signature) const {
duke@435 56 // There are no methods in an array klass but the super class (Object) has some
duke@435 57 assert(super(), "super klass must be present");
duke@435 58 return Klass::cast(super())->uncached_lookup_method(name, signature);
duke@435 59 }
duke@435 60
duke@435 61
duke@435 62 arrayKlassHandle arrayKlass::base_create_array_klass(
duke@435 63 const Klass_vtbl& cplusplus_vtbl, int header_size, KlassHandle klass, TRAPS) {
duke@435 64 // Allocation
duke@435 65 // Note: because the Java vtable must start at the same offset in all klasses,
duke@435 66 // we must insert filler fields into arrayKlass to make it the same size as instanceKlass.
duke@435 67 // If this assert fails, add filler to instanceKlass to make it bigger.
duke@435 68 assert(header_size <= instanceKlass::header_size(),
duke@435 69 "array klasses must be same size as instanceKlass");
duke@435 70 header_size = instanceKlass::header_size();
duke@435 71 // Arrays don't add any new methods, so their vtable is the same size as
duke@435 72 // the vtable of klass Object.
duke@435 73 int vtable_size = Universe::base_vtable_size();
duke@435 74 arrayKlassHandle k;
duke@435 75 KlassHandle base_klass = Klass::base_create_klass(klass,
duke@435 76 header_size + vtable_size,
duke@435 77 cplusplus_vtbl, CHECK_(k));
duke@435 78
duke@435 79 // No safepoint should be possible until the handle's
duke@435 80 // target below becomes parsable
duke@435 81 No_Safepoint_Verifier no_safepoint;
duke@435 82 k = arrayKlassHandle(THREAD, base_klass());
duke@435 83
duke@435 84 assert(!k()->is_parsable(), "not expecting parsability yet.");
duke@435 85 k->set_super(Universe::is_bootstrapping() ? (klassOop)NULL : SystemDictionary::object_klass());
duke@435 86 k->set_layout_helper(Klass::_lh_neutral_value);
duke@435 87 k->set_dimension(1);
duke@435 88 k->set_higher_dimension(NULL);
duke@435 89 k->set_lower_dimension(NULL);
duke@435 90 k->set_component_mirror(NULL);
duke@435 91 k->set_vtable_length(vtable_size);
duke@435 92 k->set_is_cloneable(); // All arrays are considered to be cloneable (See JLS 20.1.5)
duke@435 93
duke@435 94 assert(k()->is_parsable(), "should be parsable here.");
duke@435 95 // Make sure size calculation is right
duke@435 96 assert(k()->size() == align_object_size(header_size + vtable_size), "wrong size for object");
duke@435 97
duke@435 98 return k;
duke@435 99 }
duke@435 100
duke@435 101
duke@435 102 // Initialization of vtables and mirror object is done separatly from base_create_array_klass,
duke@435 103 // since a GC can happen. At this point all instance variables of the arrayKlass must be setup.
duke@435 104 void arrayKlass::complete_create_array_klass(arrayKlassHandle k, KlassHandle super_klass, TRAPS) {
duke@435 105 ResourceMark rm(THREAD);
duke@435 106 k->initialize_supers(super_klass(), CHECK);
duke@435 107 k->vtable()->initialize_vtable(false, CHECK);
duke@435 108 java_lang_Class::create_mirror(k, CHECK);
duke@435 109 }
duke@435 110
duke@435 111 objArrayOop arrayKlass::compute_secondary_supers(int num_extra_slots, TRAPS) {
duke@435 112 // interfaces = { cloneable_klass, serializable_klass };
duke@435 113 assert(num_extra_slots == 0, "sanity of primitive array type");
duke@435 114 // Must share this for correct bootstrapping!
duke@435 115 return Universe::the_array_interfaces_array();
duke@435 116 }
duke@435 117
duke@435 118 bool arrayKlass::compute_is_subtype_of(klassOop k) {
duke@435 119 // An array is a subtype of Serializable, Clonable, and Object
duke@435 120 return k == SystemDictionary::object_klass()
duke@435 121 || k == SystemDictionary::cloneable_klass()
duke@435 122 || k == SystemDictionary::serializable_klass();
duke@435 123 }
duke@435 124
duke@435 125
duke@435 126 inline intptr_t* arrayKlass::start_of_vtable() const {
duke@435 127 // all vtables start at the same place, that's why we use instanceKlass::header_size here
duke@435 128 return ((intptr_t*)as_klassOop()) + instanceKlass::header_size();
duke@435 129 }
duke@435 130
duke@435 131
duke@435 132 klassVtable* arrayKlass::vtable() const {
duke@435 133 KlassHandle kh(Thread::current(), as_klassOop());
duke@435 134 return new klassVtable(kh, start_of_vtable(), vtable_length() / vtableEntry::size());
duke@435 135 }
duke@435 136
duke@435 137
duke@435 138 objArrayOop arrayKlass::allocate_arrayArray(int n, int length, TRAPS) {
duke@435 139 if (length < 0) {
duke@435 140 THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
duke@435 141 }
duke@435 142 if (length > arrayOopDesc::max_array_length(T_ARRAY)) {
duke@435 143 THROW_OOP_0(Universe::out_of_memory_error_array_size());
duke@435 144 }
duke@435 145 int size = objArrayOopDesc::object_size(length);
duke@435 146 klassOop k = array_klass(n+dimension(), CHECK_0);
duke@435 147 arrayKlassHandle ak (THREAD, k);
duke@435 148 objArrayOop o =
duke@435 149 (objArrayOop)CollectedHeap::array_allocate(ak, size, length, CHECK_0);
duke@435 150 // initialization to NULL not necessary, area already cleared
duke@435 151 return o;
duke@435 152 }
duke@435 153
duke@435 154
duke@435 155 void arrayKlass::array_klasses_do(void f(klassOop k)) {
duke@435 156 klassOop k = as_klassOop();
duke@435 157 // Iterate over this array klass and all higher dimensions
duke@435 158 while (k != NULL) {
duke@435 159 f(k);
duke@435 160 k = arrayKlass::cast(k)->higher_dimension();
duke@435 161 }
duke@435 162 }
duke@435 163
duke@435 164
duke@435 165 void arrayKlass::with_array_klasses_do(void f(klassOop k)) {
duke@435 166 array_klasses_do(f);
duke@435 167 }
duke@435 168
duke@435 169 // JVM support
duke@435 170
duke@435 171 jint arrayKlass::compute_modifier_flags(TRAPS) const {
duke@435 172 return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
duke@435 173 }
duke@435 174
duke@435 175 // JVMTI support
duke@435 176
duke@435 177 jint arrayKlass::jvmti_class_status() const {
duke@435 178 return JVMTI_CLASS_STATUS_ARRAY;
duke@435 179 }
duke@435 180
duke@435 181 #ifndef PRODUCT
duke@435 182
duke@435 183 // Printing
duke@435 184
duke@435 185 void arrayKlass::oop_print_on(oop obj, outputStream* st) {
duke@435 186 assert(obj->is_array(), "must be array");
duke@435 187 Klass::oop_print_on(obj, st);
duke@435 188 st->print_cr(" - length: %d", arrayOop(obj)->length());
duke@435 189 }
duke@435 190
duke@435 191 #endif
duke@435 192
duke@435 193 // Verification
duke@435 194
duke@435 195 void arrayKlass::oop_verify_on(oop obj, outputStream* st) {
duke@435 196 guarantee(obj->is_array(), "must be array");
duke@435 197 arrayOop a = arrayOop(obj);
duke@435 198 guarantee(a->length() >= 0, "array with negative length?");
duke@435 199 }

mercurial