annotate hotspot/src/share/vm/oops/arrayKlass.cpp @ 13728:882756847a04

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