annotate hotspot/src/share/vm/oops/arrayKlass.cpp @ 1:489c9b5090e2

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