annotate hotspot/src/share/vm/oops/arrayKlass.cpp @ 7397:5b173b4ca846

6989984: Use standard include model for Hospot Summary: Replaced MakeDeps and the includeDB files with more standardized solutions. Reviewed-by: coleenp, kvn, kamg
author stefank
date Tue, 23 Nov 2010 13:22:55 -0800
parents 4d9030fe341f
children 96d498ec7ae1
rev   line source
duke@1 1 /*
stefank@7397 2 * Copyright (c) 1997, 2010, 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/arrayKlassKlass.hpp"
stefank@7397 35 #include "oops/arrayOop.hpp"
stefank@7397 36 #include "oops/instanceKlass.hpp"
stefank@7397 37 #include "oops/objArrayOop.hpp"
stefank@7397 38 #include "oops/oop.inline.hpp"
duke@1 39
duke@1 40 int arrayKlass::object_size(int header_size) const {
duke@1 41 // size of an array klass object
duke@1 42 assert(header_size <= instanceKlass::header_size(), "bad header size");
duke@1 43 // If this assert fails, see comments in base_create_array_klass.
duke@1 44 header_size = instanceKlass::header_size();
duke@1 45 #ifdef _LP64
duke@1 46 int size = header_size + align_object_offset(vtable_length());
duke@1 47 #else
duke@1 48 int size = header_size + vtable_length();
duke@1 49 #endif
duke@1 50 return align_object_size(size);
duke@1 51 }
duke@1 52
duke@1 53
duke@1 54 klassOop 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
duke@1 67 methodOop arrayKlass::uncached_lookup_method(symbolOop name, symbolOop 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
duke@1 73
duke@1 74 arrayKlassHandle arrayKlass::base_create_array_klass(
duke@1 75 const Klass_vtbl& cplusplus_vtbl, int header_size, KlassHandle klass, TRAPS) {
duke@1 76 // Allocation
duke@1 77 // Note: because the Java vtable must start at the same offset in all klasses,
duke@1 78 // we must insert filler fields into arrayKlass to make it the same size as instanceKlass.
duke@1 79 // If this assert fails, add filler to instanceKlass to make it bigger.
duke@1 80 assert(header_size <= instanceKlass::header_size(),
duke@1 81 "array klasses must be same size as instanceKlass");
duke@1 82 header_size = instanceKlass::header_size();
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();
duke@1 86 arrayKlassHandle k;
duke@1 87 KlassHandle base_klass = Klass::base_create_klass(klass,
duke@1 88 header_size + vtable_size,
duke@1 89 cplusplus_vtbl, CHECK_(k));
duke@1 90
duke@1 91 // No safepoint should be possible until the handle's
duke@1 92 // target below becomes parsable
duke@1 93 No_Safepoint_Verifier no_safepoint;
duke@1 94 k = arrayKlassHandle(THREAD, base_klass());
duke@1 95
duke@1 96 assert(!k()->is_parsable(), "not expecting parsability yet.");
never@4571 97 k->set_super(Universe::is_bootstrapping() ? (klassOop)NULL : SystemDictionary::Object_klass());
duke@1 98 k->set_layout_helper(Klass::_lh_neutral_value);
duke@1 99 k->set_dimension(1);
duke@1 100 k->set_higher_dimension(NULL);
duke@1 101 k->set_lower_dimension(NULL);
duke@1 102 k->set_component_mirror(NULL);
duke@1 103 k->set_vtable_length(vtable_size);
duke@1 104 k->set_is_cloneable(); // All arrays are considered to be cloneable (See JLS 20.1.5)
duke@1 105
duke@1 106 assert(k()->is_parsable(), "should be parsable here.");
duke@1 107 // Make sure size calculation is right
duke@1 108 assert(k()->size() == align_object_size(header_size + vtable_size), "wrong size for object");
duke@1 109
duke@1 110 return k;
duke@1 111 }
duke@1 112
duke@1 113
duke@1 114 // Initialization of vtables and mirror object is done separatly from base_create_array_klass,
duke@1 115 // since a GC can happen. At this point all instance variables of the arrayKlass must be setup.
duke@1 116 void arrayKlass::complete_create_array_klass(arrayKlassHandle k, KlassHandle super_klass, TRAPS) {
duke@1 117 ResourceMark rm(THREAD);
duke@1 118 k->initialize_supers(super_klass(), CHECK);
duke@1 119 k->vtable()->initialize_vtable(false, CHECK);
duke@1 120 java_lang_Class::create_mirror(k, CHECK);
duke@1 121 }
duke@1 122
duke@1 123 objArrayOop arrayKlass::compute_secondary_supers(int num_extra_slots, TRAPS) {
duke@1 124 // interfaces = { cloneable_klass, serializable_klass };
duke@1 125 assert(num_extra_slots == 0, "sanity of primitive array type");
duke@1 126 // Must share this for correct bootstrapping!
duke@1 127 return Universe::the_array_interfaces_array();
duke@1 128 }
duke@1 129
duke@1 130 bool arrayKlass::compute_is_subtype_of(klassOop k) {
duke@1 131 // An array is a subtype of Serializable, Clonable, and Object
never@4571 132 return k == SystemDictionary::Object_klass()
never@4571 133 || k == SystemDictionary::Cloneable_klass()
never@4571 134 || k == SystemDictionary::Serializable_klass();
duke@1 135 }
duke@1 136
duke@1 137
duke@1 138 inline intptr_t* arrayKlass::start_of_vtable() const {
duke@1 139 // all vtables start at the same place, that's why we use instanceKlass::header_size here
duke@1 140 return ((intptr_t*)as_klassOop()) + instanceKlass::header_size();
duke@1 141 }
duke@1 142
duke@1 143
duke@1 144 klassVtable* arrayKlass::vtable() const {
duke@1 145 KlassHandle kh(Thread::current(), as_klassOop());
duke@1 146 return new klassVtable(kh, start_of_vtable(), vtable_length() / vtableEntry::size());
duke@1 147 }
duke@1 148
duke@1 149
duke@1 150 objArrayOop arrayKlass::allocate_arrayArray(int n, int length, TRAPS) {
duke@1 151 if (length < 0) {
duke@1 152 THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
duke@1 153 }
duke@1 154 if (length > arrayOopDesc::max_array_length(T_ARRAY)) {
martin@3576 155 report_java_out_of_memory("Requested array size exceeds VM limit");
duke@1 156 THROW_OOP_0(Universe::out_of_memory_error_array_size());
duke@1 157 }
duke@1 158 int size = objArrayOopDesc::object_size(length);
duke@1 159 klassOop k = array_klass(n+dimension(), CHECK_0);
duke@1 160 arrayKlassHandle ak (THREAD, k);
duke@1 161 objArrayOop o =
duke@1 162 (objArrayOop)CollectedHeap::array_allocate(ak, size, length, CHECK_0);
duke@1 163 // initialization to NULL not necessary, area already cleared
duke@1 164 return o;
duke@1 165 }
duke@1 166
duke@1 167
duke@1 168 void arrayKlass::array_klasses_do(void f(klassOop k)) {
duke@1 169 klassOop k = as_klassOop();
duke@1 170 // Iterate over this array klass and all higher dimensions
duke@1 171 while (k != NULL) {
duke@1 172 f(k);
duke@1 173 k = arrayKlass::cast(k)->higher_dimension();
duke@1 174 }
duke@1 175 }
duke@1 176
duke@1 177
duke@1 178 void arrayKlass::with_array_klasses_do(void f(klassOop k)) {
duke@1 179 array_klasses_do(f);
duke@1 180 }
duke@1 181
duke@1 182 // JVM support
duke@1 183
duke@1 184 jint arrayKlass::compute_modifier_flags(TRAPS) const {
duke@1 185 return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
duke@1 186 }
duke@1 187
duke@1 188 // JVMTI support
duke@1 189
duke@1 190 jint arrayKlass::jvmti_class_status() const {
duke@1 191 return JVMTI_CLASS_STATUS_ARRAY;
duke@1 192 }
duke@1 193
duke@1 194 // Printing
duke@1 195
duke@1 196 void arrayKlass::oop_print_on(oop obj, outputStream* st) {
duke@1 197 assert(obj->is_array(), "must be array");
duke@1 198 Klass::oop_print_on(obj, st);
duke@1 199 st->print_cr(" - length: %d", arrayOop(obj)->length());
duke@1 200 }
duke@1 201
duke@1 202 // Verification
duke@1 203
duke@1 204 void arrayKlass::oop_verify_on(oop obj, outputStream* st) {
duke@1 205 guarantee(obj->is_array(), "must be array");
duke@1 206 arrayOop a = arrayOop(obj);
duke@1 207 guarantee(a->length() >= 0, "array with negative length?");
duke@1 208 }