1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/oops/arrayKlass.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,199 @@ 1.4 +/* 1.5 + * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +# include "incls/_precompiled.incl" 1.29 +# include "incls/_arrayKlass.cpp.incl" 1.30 + 1.31 +int arrayKlass::object_size(int header_size) const { 1.32 + // size of an array klass object 1.33 + assert(header_size <= instanceKlass::header_size(), "bad header size"); 1.34 + // If this assert fails, see comments in base_create_array_klass. 1.35 + header_size = instanceKlass::header_size(); 1.36 +#ifdef _LP64 1.37 + int size = header_size + align_object_offset(vtable_length()); 1.38 +#else 1.39 + int size = header_size + vtable_length(); 1.40 +#endif 1.41 + return align_object_size(size); 1.42 +} 1.43 + 1.44 + 1.45 +klassOop arrayKlass::java_super() const { 1.46 + if (super() == NULL) return NULL; // bootstrap case 1.47 + // Array klasses have primary supertypes which are not reported to Java. 1.48 + // Example super chain: String[][] -> Object[][] -> Object[] -> Object 1.49 + return SystemDictionary::object_klass(); 1.50 +} 1.51 + 1.52 + 1.53 +oop arrayKlass::multi_allocate(int rank, jint* sizes, TRAPS) { 1.54 + ShouldNotReachHere(); 1.55 + return NULL; 1.56 +} 1.57 + 1.58 +methodOop arrayKlass::uncached_lookup_method(symbolOop name, symbolOop signature) const { 1.59 + // There are no methods in an array klass but the super class (Object) has some 1.60 + assert(super(), "super klass must be present"); 1.61 + return Klass::cast(super())->uncached_lookup_method(name, signature); 1.62 +} 1.63 + 1.64 + 1.65 +arrayKlassHandle arrayKlass::base_create_array_klass( 1.66 +const Klass_vtbl& cplusplus_vtbl, int header_size, KlassHandle klass, TRAPS) { 1.67 + // Allocation 1.68 + // Note: because the Java vtable must start at the same offset in all klasses, 1.69 + // we must insert filler fields into arrayKlass to make it the same size as instanceKlass. 1.70 + // If this assert fails, add filler to instanceKlass to make it bigger. 1.71 + assert(header_size <= instanceKlass::header_size(), 1.72 + "array klasses must be same size as instanceKlass"); 1.73 + header_size = instanceKlass::header_size(); 1.74 + // Arrays don't add any new methods, so their vtable is the same size as 1.75 + // the vtable of klass Object. 1.76 + int vtable_size = Universe::base_vtable_size(); 1.77 + arrayKlassHandle k; 1.78 + KlassHandle base_klass = Klass::base_create_klass(klass, 1.79 + header_size + vtable_size, 1.80 + cplusplus_vtbl, CHECK_(k)); 1.81 + 1.82 + // No safepoint should be possible until the handle's 1.83 + // target below becomes parsable 1.84 + No_Safepoint_Verifier no_safepoint; 1.85 + k = arrayKlassHandle(THREAD, base_klass()); 1.86 + 1.87 + assert(!k()->is_parsable(), "not expecting parsability yet."); 1.88 + k->set_super(Universe::is_bootstrapping() ? (klassOop)NULL : SystemDictionary::object_klass()); 1.89 + k->set_layout_helper(Klass::_lh_neutral_value); 1.90 + k->set_dimension(1); 1.91 + k->set_higher_dimension(NULL); 1.92 + k->set_lower_dimension(NULL); 1.93 + k->set_component_mirror(NULL); 1.94 + k->set_vtable_length(vtable_size); 1.95 + k->set_is_cloneable(); // All arrays are considered to be cloneable (See JLS 20.1.5) 1.96 + 1.97 + assert(k()->is_parsable(), "should be parsable here."); 1.98 + // Make sure size calculation is right 1.99 + assert(k()->size() == align_object_size(header_size + vtable_size), "wrong size for object"); 1.100 + 1.101 + return k; 1.102 +} 1.103 + 1.104 + 1.105 +// Initialization of vtables and mirror object is done separatly from base_create_array_klass, 1.106 +// since a GC can happen. At this point all instance variables of the arrayKlass must be setup. 1.107 +void arrayKlass::complete_create_array_klass(arrayKlassHandle k, KlassHandle super_klass, TRAPS) { 1.108 + ResourceMark rm(THREAD); 1.109 + k->initialize_supers(super_klass(), CHECK); 1.110 + k->vtable()->initialize_vtable(false, CHECK); 1.111 + java_lang_Class::create_mirror(k, CHECK); 1.112 +} 1.113 + 1.114 +objArrayOop arrayKlass::compute_secondary_supers(int num_extra_slots, TRAPS) { 1.115 + // interfaces = { cloneable_klass, serializable_klass }; 1.116 + assert(num_extra_slots == 0, "sanity of primitive array type"); 1.117 + // Must share this for correct bootstrapping! 1.118 + return Universe::the_array_interfaces_array(); 1.119 +} 1.120 + 1.121 +bool arrayKlass::compute_is_subtype_of(klassOop k) { 1.122 + // An array is a subtype of Serializable, Clonable, and Object 1.123 + return k == SystemDictionary::object_klass() 1.124 + || k == SystemDictionary::cloneable_klass() 1.125 + || k == SystemDictionary::serializable_klass(); 1.126 +} 1.127 + 1.128 + 1.129 +inline intptr_t* arrayKlass::start_of_vtable() const { 1.130 + // all vtables start at the same place, that's why we use instanceKlass::header_size here 1.131 + return ((intptr_t*)as_klassOop()) + instanceKlass::header_size(); 1.132 +} 1.133 + 1.134 + 1.135 +klassVtable* arrayKlass::vtable() const { 1.136 + KlassHandle kh(Thread::current(), as_klassOop()); 1.137 + return new klassVtable(kh, start_of_vtable(), vtable_length() / vtableEntry::size()); 1.138 +} 1.139 + 1.140 + 1.141 +objArrayOop arrayKlass::allocate_arrayArray(int n, int length, TRAPS) { 1.142 + if (length < 0) { 1.143 + THROW_0(vmSymbols::java_lang_NegativeArraySizeException()); 1.144 + } 1.145 + if (length > arrayOopDesc::max_array_length(T_ARRAY)) { 1.146 + THROW_OOP_0(Universe::out_of_memory_error_array_size()); 1.147 + } 1.148 + int size = objArrayOopDesc::object_size(length); 1.149 + klassOop k = array_klass(n+dimension(), CHECK_0); 1.150 + arrayKlassHandle ak (THREAD, k); 1.151 + objArrayOop o = 1.152 + (objArrayOop)CollectedHeap::array_allocate(ak, size, length, CHECK_0); 1.153 + // initialization to NULL not necessary, area already cleared 1.154 + return o; 1.155 +} 1.156 + 1.157 + 1.158 +void arrayKlass::array_klasses_do(void f(klassOop k)) { 1.159 + klassOop k = as_klassOop(); 1.160 + // Iterate over this array klass and all higher dimensions 1.161 + while (k != NULL) { 1.162 + f(k); 1.163 + k = arrayKlass::cast(k)->higher_dimension(); 1.164 + } 1.165 +} 1.166 + 1.167 + 1.168 +void arrayKlass::with_array_klasses_do(void f(klassOop k)) { 1.169 + array_klasses_do(f); 1.170 +} 1.171 + 1.172 +// JVM support 1.173 + 1.174 +jint arrayKlass::compute_modifier_flags(TRAPS) const { 1.175 + return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC; 1.176 +} 1.177 + 1.178 +// JVMTI support 1.179 + 1.180 +jint arrayKlass::jvmti_class_status() const { 1.181 + return JVMTI_CLASS_STATUS_ARRAY; 1.182 +} 1.183 + 1.184 +#ifndef PRODUCT 1.185 + 1.186 +// Printing 1.187 + 1.188 +void arrayKlass::oop_print_on(oop obj, outputStream* st) { 1.189 + assert(obj->is_array(), "must be array"); 1.190 + Klass::oop_print_on(obj, st); 1.191 + st->print_cr(" - length: %d", arrayOop(obj)->length()); 1.192 +} 1.193 + 1.194 +#endif 1.195 + 1.196 +// Verification 1.197 + 1.198 +void arrayKlass::oop_verify_on(oop obj, outputStream* st) { 1.199 + guarantee(obj->is_array(), "must be array"); 1.200 + arrayOop a = arrayOop(obj); 1.201 + guarantee(a->length() >= 0, "array with negative length?"); 1.202 +}