Wed, 03 Sep 2014 09:25:44 +0200
Merge
duke@435 | 1 | /* |
coleenp@6316 | 2 | * Copyright (c) 1997, 2014, Oracle and/or its affiliates. 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 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "classfile/javaClasses.hpp" |
stefank@2314 | 27 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 28 | #include "classfile/vmSymbols.hpp" |
stefank@2314 | 29 | #include "gc_interface/collectedHeap.inline.hpp" |
stefank@2314 | 30 | #include "jvmtifiles/jvmti.h" |
stefank@2314 | 31 | #include "memory/gcLocker.hpp" |
stefank@2314 | 32 | #include "memory/universe.inline.hpp" |
stefank@2314 | 33 | #include "oops/arrayKlass.hpp" |
stefank@2314 | 34 | #include "oops/arrayOop.hpp" |
stefank@2314 | 35 | #include "oops/instanceKlass.hpp" |
stefank@2314 | 36 | #include "oops/objArrayOop.hpp" |
stefank@2314 | 37 | #include "oops/oop.inline.hpp" |
duke@435 | 38 | |
coleenp@4142 | 39 | int ArrayKlass::static_size(int header_size) { |
duke@435 | 40 | // size of an array klass object |
coleenp@4037 | 41 | assert(header_size <= InstanceKlass::header_size(), "bad header size"); |
duke@435 | 42 | // If this assert fails, see comments in base_create_array_klass. |
coleenp@4037 | 43 | header_size = InstanceKlass::header_size(); |
coleenp@4037 | 44 | int vtable_len = Universe::base_vtable_size(); |
duke@435 | 45 | #ifdef _LP64 |
coleenp@4037 | 46 | int size = header_size + align_object_offset(vtable_len); |
duke@435 | 47 | #else |
coleenp@4037 | 48 | int size = header_size + vtable_len; |
duke@435 | 49 | #endif |
duke@435 | 50 | return align_object_size(size); |
duke@435 | 51 | } |
duke@435 | 52 | |
duke@435 | 53 | |
coleenp@4142 | 54 | Klass* ArrayKlass::java_super() const { |
duke@435 | 55 | if (super() == NULL) return NULL; // bootstrap case |
duke@435 | 56 | // Array klasses have primary supertypes which are not reported to Java. |
duke@435 | 57 | // Example super chain: String[][] -> Object[][] -> Object[] -> Object |
never@1577 | 58 | return SystemDictionary::Object_klass(); |
duke@435 | 59 | } |
duke@435 | 60 | |
duke@435 | 61 | |
coleenp@4142 | 62 | oop ArrayKlass::multi_allocate(int rank, jint* sizes, TRAPS) { |
duke@435 | 63 | ShouldNotReachHere(); |
duke@435 | 64 | return NULL; |
duke@435 | 65 | } |
duke@435 | 66 | |
lfoltan@6632 | 67 | Method* ArrayKlass::uncached_lookup_method(Symbol* name, Symbol* signature, MethodLookupMode mode) const { |
duke@435 | 68 | // There are no methods in an array klass but the super class (Object) has some |
duke@435 | 69 | assert(super(), "super klass must be present"); |
lfoltan@6632 | 70 | return super()->uncached_lookup_method(name, signature, mode); |
duke@435 | 71 | } |
duke@435 | 72 | |
coleenp@4142 | 73 | ArrayKlass::ArrayKlass(Symbol* name) { |
coleenp@4037 | 74 | set_name(name); |
duke@435 | 75 | |
coleenp@4037 | 76 | set_super(Universe::is_bootstrapping() ? (Klass*)NULL : SystemDictionary::Object_klass()); |
coleenp@4037 | 77 | set_layout_helper(Klass::_lh_neutral_value); |
coleenp@4037 | 78 | set_dimension(1); |
coleenp@4037 | 79 | set_higher_dimension(NULL); |
coleenp@4037 | 80 | set_lower_dimension(NULL); |
coleenp@4037 | 81 | set_component_mirror(NULL); |
duke@435 | 82 | // Arrays don't add any new methods, so their vtable is the same size as |
duke@435 | 83 | // the vtable of klass Object. |
duke@435 | 84 | int vtable_size = Universe::base_vtable_size(); |
coleenp@4037 | 85 | set_vtable_length(vtable_size); |
coleenp@4037 | 86 | set_is_cloneable(); // All arrays are considered to be cloneable (See JLS 20.1.5) |
duke@435 | 87 | } |
duke@435 | 88 | |
duke@435 | 89 | |
duke@435 | 90 | // Initialization of vtables and mirror object is done separatly from base_create_array_klass, |
coleenp@4142 | 91 | // since a GC can happen. At this point all instance variables of the ArrayKlass must be setup. |
coleenp@4142 | 92 | void ArrayKlass::complete_create_array_klass(ArrayKlass* k, KlassHandle super_klass, TRAPS) { |
duke@435 | 93 | ResourceMark rm(THREAD); |
duke@435 | 94 | k->initialize_supers(super_klass(), CHECK); |
duke@435 | 95 | k->vtable()->initialize_vtable(false, CHECK); |
coleenp@5176 | 96 | java_lang_Class::create_mirror(k, Handle(NULL), CHECK); |
duke@435 | 97 | } |
duke@435 | 98 | |
coleenp@4142 | 99 | GrowableArray<Klass*>* ArrayKlass::compute_secondary_supers(int num_extra_slots) { |
duke@435 | 100 | // interfaces = { cloneable_klass, serializable_klass }; |
duke@435 | 101 | assert(num_extra_slots == 0, "sanity of primitive array type"); |
duke@435 | 102 | // Must share this for correct bootstrapping! |
coleenp@4037 | 103 | set_secondary_supers(Universe::the_array_interfaces_array()); |
coleenp@4037 | 104 | return NULL; |
duke@435 | 105 | } |
duke@435 | 106 | |
coleenp@4142 | 107 | bool ArrayKlass::compute_is_subtype_of(Klass* k) { |
duke@435 | 108 | // An array is a subtype of Serializable, Clonable, and Object |
never@1577 | 109 | return k == SystemDictionary::Object_klass() |
never@1577 | 110 | || k == SystemDictionary::Cloneable_klass() |
never@1577 | 111 | || k == SystemDictionary::Serializable_klass(); |
duke@435 | 112 | } |
duke@435 | 113 | |
duke@435 | 114 | |
coleenp@4142 | 115 | inline intptr_t* ArrayKlass::start_of_vtable() const { |
coleenp@4037 | 116 | // all vtables start at the same place, that's why we use InstanceKlass::header_size here |
coleenp@4037 | 117 | return ((intptr_t*)this) + InstanceKlass::header_size(); |
duke@435 | 118 | } |
duke@435 | 119 | |
duke@435 | 120 | |
coleenp@4142 | 121 | klassVtable* ArrayKlass::vtable() const { |
coleenp@4037 | 122 | KlassHandle kh(Thread::current(), this); |
duke@435 | 123 | return new klassVtable(kh, start_of_vtable(), vtable_length() / vtableEntry::size()); |
duke@435 | 124 | } |
duke@435 | 125 | |
duke@435 | 126 | |
coleenp@4142 | 127 | objArrayOop ArrayKlass::allocate_arrayArray(int n, int length, TRAPS) { |
duke@435 | 128 | if (length < 0) { |
duke@435 | 129 | THROW_0(vmSymbols::java_lang_NegativeArraySizeException()); |
duke@435 | 130 | } |
duke@435 | 131 | if (length > arrayOopDesc::max_array_length(T_ARRAY)) { |
martin@1311 | 132 | report_java_out_of_memory("Requested array size exceeds VM limit"); |
sspitsyn@3638 | 133 | JvmtiExport::post_array_size_exhausted(); |
duke@435 | 134 | THROW_OOP_0(Universe::out_of_memory_error_array_size()); |
duke@435 | 135 | } |
duke@435 | 136 | int size = objArrayOopDesc::object_size(length); |
coleenp@4037 | 137 | Klass* k = array_klass(n+dimension(), CHECK_0); |
coleenp@4142 | 138 | ArrayKlass* ak = ArrayKlass::cast(k); |
duke@435 | 139 | objArrayOop o = |
duke@435 | 140 | (objArrayOop)CollectedHeap::array_allocate(ak, size, length, CHECK_0); |
duke@435 | 141 | // initialization to NULL not necessary, area already cleared |
duke@435 | 142 | return o; |
duke@435 | 143 | } |
duke@435 | 144 | |
coleenp@4142 | 145 | void ArrayKlass::array_klasses_do(void f(Klass* k, TRAPS), TRAPS) { |
coleenp@4037 | 146 | Klass* k = this; |
coleenp@4037 | 147 | // Iterate over this array klass and all higher dimensions |
coleenp@4037 | 148 | while (k != NULL) { |
coleenp@4037 | 149 | f(k, CHECK); |
coleenp@4142 | 150 | k = ArrayKlass::cast(k)->higher_dimension(); |
coleenp@4037 | 151 | } |
coleenp@4037 | 152 | } |
duke@435 | 153 | |
coleenp@4142 | 154 | void ArrayKlass::array_klasses_do(void f(Klass* k)) { |
coleenp@4037 | 155 | Klass* k = this; |
duke@435 | 156 | // Iterate over this array klass and all higher dimensions |
duke@435 | 157 | while (k != NULL) { |
duke@435 | 158 | f(k); |
coleenp@4142 | 159 | k = ArrayKlass::cast(k)->higher_dimension(); |
duke@435 | 160 | } |
duke@435 | 161 | } |
duke@435 | 162 | |
coleenp@4037 | 163 | // GC support |
coleenp@4037 | 164 | |
coleenp@4142 | 165 | void ArrayKlass::oops_do(OopClosure* cl) { |
coleenp@4037 | 166 | Klass::oops_do(cl); |
coleenp@4037 | 167 | |
coleenp@4037 | 168 | cl->do_oop(adr_component_mirror()); |
coleenp@4037 | 169 | } |
coleenp@4037 | 170 | |
duke@435 | 171 | // JVM support |
duke@435 | 172 | |
coleenp@4142 | 173 | jint ArrayKlass::compute_modifier_flags(TRAPS) const { |
duke@435 | 174 | return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC; |
duke@435 | 175 | } |
duke@435 | 176 | |
duke@435 | 177 | // JVMTI support |
duke@435 | 178 | |
coleenp@4142 | 179 | jint ArrayKlass::jvmti_class_status() const { |
duke@435 | 180 | return JVMTI_CLASS_STATUS_ARRAY; |
duke@435 | 181 | } |
duke@435 | 182 | |
coleenp@4142 | 183 | void ArrayKlass::remove_unshareable_info() { |
coleenp@4037 | 184 | Klass::remove_unshareable_info(); |
coleenp@4037 | 185 | // Clear the java mirror |
coleenp@4037 | 186 | set_component_mirror(NULL); |
coleenp@4037 | 187 | } |
coleenp@4037 | 188 | |
iklam@7089 | 189 | void ArrayKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS) { |
iklam@7089 | 190 | assert(loader_data == ClassLoaderData::the_null_class_loader_data(), "array classes belong to null loader"); |
iklam@7089 | 191 | Klass::restore_unshareable_info(loader_data, protection_domain, CHECK); |
coleenp@4037 | 192 | // Klass recreates the component mirror also |
coleenp@4037 | 193 | } |
coleenp@4037 | 194 | |
duke@435 | 195 | // Printing |
duke@435 | 196 | |
coleenp@4142 | 197 | void ArrayKlass::print_on(outputStream* st) const { |
coleenp@4037 | 198 | assert(is_klass(), "must be klass"); |
coleenp@4037 | 199 | Klass::print_on(st); |
coleenp@4037 | 200 | } |
coleenp@4037 | 201 | |
coleenp@4142 | 202 | void ArrayKlass::print_value_on(outputStream* st) const { |
coleenp@4037 | 203 | assert(is_klass(), "must be klass"); |
coleenp@4037 | 204 | for(int index = 0; index < dimension(); index++) { |
coleenp@4037 | 205 | st->print("[]"); |
coleenp@4037 | 206 | } |
coleenp@4037 | 207 | } |
coleenp@4037 | 208 | |
coleenp@4142 | 209 | void ArrayKlass::oop_print_on(oop obj, outputStream* st) { |
duke@435 | 210 | assert(obj->is_array(), "must be array"); |
duke@435 | 211 | Klass::oop_print_on(obj, st); |
duke@435 | 212 | st->print_cr(" - length: %d", arrayOop(obj)->length()); |
duke@435 | 213 | } |
duke@435 | 214 | |
coleenp@4037 | 215 | |
duke@435 | 216 | // Verification |
duke@435 | 217 | |
coleenp@6316 | 218 | void ArrayKlass::verify_on(outputStream* st) { |
coleenp@6316 | 219 | Klass::verify_on(st); |
coleenp@4037 | 220 | |
coleenp@4037 | 221 | if (component_mirror() != NULL) { |
coleenp@4037 | 222 | guarantee(component_mirror()->klass() != NULL, "should have a class"); |
coleenp@4037 | 223 | } |
coleenp@4037 | 224 | } |
coleenp@4037 | 225 | |
coleenp@4142 | 226 | void ArrayKlass::oop_verify_on(oop obj, outputStream* st) { |
duke@435 | 227 | guarantee(obj->is_array(), "must be array"); |
duke@435 | 228 | arrayOop a = arrayOop(obj); |
duke@435 | 229 | guarantee(a->length() >= 0, "array with negative length?"); |
duke@435 | 230 | } |