annotate src/share/vm/oops/objArrayKlass.cpp @ 3707:d8ce2825b193

8000213: NPG: Should have renamed arrayKlass and typeArrayKlass Summary: Capitalize these metadata types (and objArrayKlass) Reviewed-by: stefank, twisti, kvn
author coleenp
date Sat, 29 Sep 2012 06:40:00 -0400
parents da91efe96a93
children 6e5a59a8e4a7
rev   line source
duke@0 1 /*
sspitsyn@3203 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1879 25 #include "precompiled.hpp"
coleenp@3602 26 #include "classfile/symbolTable.hpp"
stefank@1879 27 #include "classfile/systemDictionary.hpp"
stefank@1879 28 #include "classfile/vmSymbols.hpp"
stefank@1879 29 #include "gc_implementation/shared/markSweep.inline.hpp"
stefank@1879 30 #include "gc_interface/collectedHeap.inline.hpp"
stefank@1879 31 #include "memory/genOopClosures.inline.hpp"
coleenp@3602 32 #include "memory/metadataFactory.hpp"
stefank@1879 33 #include "memory/resourceArea.hpp"
stefank@1879 34 #include "memory/universe.inline.hpp"
stefank@1879 35 #include "oops/instanceKlass.hpp"
coleenp@3602 36 #include "oops/klass.inline.hpp"
stefank@1879 37 #include "oops/objArrayKlass.hpp"
stefank@1879 38 #include "oops/objArrayKlass.inline.hpp"
stefank@1879 39 #include "oops/objArrayOop.hpp"
stefank@1879 40 #include "oops/oop.inline.hpp"
stefank@1879 41 #include "oops/oop.inline2.hpp"
coleenp@2062 42 #include "oops/symbol.hpp"
stefank@1879 43 #include "runtime/handles.inline.hpp"
stefank@1879 44 #include "runtime/mutexLocker.hpp"
stefank@1879 45 #include "utilities/copy.hpp"
stefank@1879 46 #ifndef SERIALGC
coleenp@3602 47 #include "gc_implementation/concurrentMarkSweep/cmsOopClosures.inline.hpp"
stefank@1879 48 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
stefank@1879 49 #include "gc_implementation/g1/g1OopClosures.inline.hpp"
stefank@1879 50 #include "gc_implementation/g1/g1RemSet.inline.hpp"
stefank@1879 51 #include "gc_implementation/g1/heapRegionSeq.inline.hpp"
stefank@1879 52 #include "gc_implementation/parNew/parOopClosures.inline.hpp"
stefank@1879 53 #include "gc_implementation/parallelScavenge/psCompactionManager.hpp"
stefank@1879 54 #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp"
stefank@1879 55 #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp"
stefank@1879 56 #include "oops/oop.pcgc.inline.hpp"
stefank@1879 57 #endif
duke@0 58
coleenp@3707 59 ObjArrayKlass* ObjArrayKlass::allocate(ClassLoaderData* loader_data, int n, KlassHandle klass_handle, Symbol* name, TRAPS) {
coleenp@3707 60 assert(ObjArrayKlass::header_size() <= InstanceKlass::header_size(),
coleenp@3602 61 "array klasses must be same size as InstanceKlass");
coleenp@3602 62
coleenp@3707 63 int size = ArrayKlass::static_size(ObjArrayKlass::header_size());
coleenp@3602 64
coleenp@3707 65 return new (loader_data, size, THREAD) ObjArrayKlass(n, klass_handle, name);
coleenp@3602 66 }
coleenp@3602 67
coleenp@3707 68 Klass* ObjArrayKlass::allocate_objArray_klass(ClassLoaderData* loader_data,
coleenp@3602 69 int n, KlassHandle element_klass, TRAPS) {
coleenp@3602 70
coleenp@3602 71 // Eagerly allocate the direct array supertype.
coleenp@3602 72 KlassHandle super_klass = KlassHandle();
coleenp@3602 73 if (!Universe::is_bootstrapping() || SystemDictionary::Object_klass_loaded()) {
coleenp@3602 74 KlassHandle element_super (THREAD, element_klass->super());
coleenp@3602 75 if (element_super.not_null()) {
coleenp@3602 76 // The element type has a direct super. E.g., String[] has direct super of Object[].
coleenp@3602 77 super_klass = KlassHandle(THREAD, element_super->array_klass_or_null());
coleenp@3602 78 bool supers_exist = super_klass.not_null();
coleenp@3602 79 // Also, see if the element has secondary supertypes.
coleenp@3602 80 // We need an array type for each.
coleenp@3602 81 Array<Klass*>* element_supers = element_klass->secondary_supers();
coleenp@3602 82 for( int i = element_supers->length()-1; i >= 0; i-- ) {
coleenp@3602 83 Klass* elem_super = element_supers->at(i);
coleenp@3602 84 if (Klass::cast(elem_super)->array_klass_or_null() == NULL) {
coleenp@3602 85 supers_exist = false;
coleenp@3602 86 break;
coleenp@3602 87 }
coleenp@3602 88 }
coleenp@3602 89 if (!supers_exist) {
coleenp@3602 90 // Oops. Not allocated yet. Back out, allocate it, and retry.
coleenp@3602 91 #ifndef PRODUCT
coleenp@3602 92 if (WizardMode) {
coleenp@3602 93 tty->print_cr("Must retry array klass creation for depth %d",n);
coleenp@3602 94 }
coleenp@3602 95 #endif
coleenp@3602 96 KlassHandle ek;
coleenp@3602 97 {
coleenp@3602 98 MutexUnlocker mu(MultiArray_lock);
coleenp@3602 99 MutexUnlocker mc(Compile_lock); // for vtables
coleenp@3602 100 Klass* sk = element_super->array_klass(CHECK_0);
coleenp@3602 101 super_klass = KlassHandle(THREAD, sk);
coleenp@3602 102 for( int i = element_supers->length()-1; i >= 0; i-- ) {
coleenp@3602 103 KlassHandle elem_super (THREAD, element_supers->at(i));
coleenp@3602 104 elem_super->array_klass(CHECK_0);
coleenp@3602 105 }
coleenp@3602 106 // Now retry from the beginning
coleenp@3602 107 Klass* klass_oop = element_klass->array_klass(n, CHECK_0);
coleenp@3602 108 // Create a handle because the enclosing brace, when locking
coleenp@3602 109 // can cause a gc. Better to have this function return a Handle.
coleenp@3602 110 ek = KlassHandle(THREAD, klass_oop);
coleenp@3602 111 } // re-lock
coleenp@3602 112 return ek();
coleenp@3602 113 }
coleenp@3602 114 } else {
coleenp@3602 115 // The element type is already Object. Object[] has direct super of Object.
coleenp@3602 116 super_klass = KlassHandle(THREAD, SystemDictionary::Object_klass());
coleenp@3602 117 }
coleenp@3602 118 }
coleenp@3602 119
coleenp@3602 120 // Create type name for klass.
coleenp@3602 121 Symbol* name = NULL;
coleenp@3602 122 if (!element_klass->oop_is_instance() ||
coleenp@3602 123 (name = InstanceKlass::cast(element_klass())->array_name()) == NULL) {
coleenp@3602 124
coleenp@3602 125 ResourceMark rm(THREAD);
coleenp@3602 126 char *name_str = element_klass->name()->as_C_string();
coleenp@3602 127 int len = element_klass->name()->utf8_length();
coleenp@3602 128 char *new_str = NEW_RESOURCE_ARRAY(char, len + 4);
coleenp@3602 129 int idx = 0;
coleenp@3602 130 new_str[idx++] = '[';
coleenp@3602 131 if (element_klass->oop_is_instance()) { // it could be an array or simple type
coleenp@3602 132 new_str[idx++] = 'L';
coleenp@3602 133 }
coleenp@3602 134 memcpy(&new_str[idx], name_str, len * sizeof(char));
coleenp@3602 135 idx += len;
coleenp@3602 136 if (element_klass->oop_is_instance()) {
coleenp@3602 137 new_str[idx++] = ';';
coleenp@3602 138 }
coleenp@3602 139 new_str[idx++] = '\0';
coleenp@3602 140 name = SymbolTable::new_permanent_symbol(new_str, CHECK_0);
coleenp@3602 141 if (element_klass->oop_is_instance()) {
coleenp@3602 142 InstanceKlass* ik = InstanceKlass::cast(element_klass());
coleenp@3602 143 ik->set_array_name(name);
coleenp@3602 144 }
coleenp@3602 145 }
coleenp@3602 146
coleenp@3602 147 // Initialize instance variables
coleenp@3707 148 ObjArrayKlass* oak = ObjArrayKlass::allocate(loader_data, n, element_klass, name, CHECK_0);
coleenp@3602 149
coleenp@3602 150 // Add all classes to our internal class loader list here,
coleenp@3602 151 // including classes in the bootstrap (NULL) class loader.
coleenp@3602 152 // GC walks these as strong roots.
coleenp@3602 153 loader_data->add_class(oak);
coleenp@3602 154
coleenp@3602 155 // Call complete_create_array_klass after all instance variables has been initialized.
coleenp@3707 156 ArrayKlass::complete_create_array_klass(oak, super_klass, CHECK_0);
coleenp@3602 157
coleenp@3602 158 return oak;
coleenp@3602 159 }
coleenp@3602 160
coleenp@3707 161 ObjArrayKlass::ObjArrayKlass(int n, KlassHandle element_klass, Symbol* name) : ArrayKlass(name) {
coleenp@3602 162 this->set_dimension(n);
coleenp@3602 163 this->set_element_klass(element_klass());
coleenp@3602 164 // decrement refcount because object arrays are not explicitly freed. The
coleenp@3602 165 // InstanceKlass array_name() keeps the name counted while the klass is
coleenp@3602 166 // loaded.
coleenp@3602 167 name->decrement_refcount();
coleenp@3602 168
coleenp@3602 169 Klass* bk;
coleenp@3602 170 if (element_klass->oop_is_objArray()) {
coleenp@3707 171 bk = ObjArrayKlass::cast(element_klass())->bottom_klass();
coleenp@3602 172 } else {
coleenp@3602 173 bk = element_klass();
coleenp@3602 174 }
coleenp@3602 175 assert(bk != NULL && (Klass::cast(bk)->oop_is_instance() || Klass::cast(bk)->oop_is_typeArray()), "invalid bottom klass");
coleenp@3602 176 this->set_bottom_klass(bk);
coleenp@3602 177 this->set_class_loader_data(bk->class_loader_data());
coleenp@3602 178
coleenp@3602 179 this->set_layout_helper(array_layout_helper(T_OBJECT));
coleenp@3602 180 assert(this->oop_is_array(), "sanity");
coleenp@3602 181 assert(this->oop_is_objArray(), "sanity");
coleenp@3602 182 }
coleenp@3602 183
coleenp@3707 184 int ObjArrayKlass::oop_size(oop obj) const {
duke@0 185 assert(obj->is_objArray(), "must be object array");
duke@0 186 return objArrayOop(obj)->object_size();
duke@0 187 }
duke@0 188
coleenp@3707 189 objArrayOop ObjArrayKlass::allocate(int length, TRAPS) {
duke@0 190 if (length >= 0) {
duke@0 191 if (length <= arrayOopDesc::max_array_length(T_OBJECT)) {
duke@0 192 int size = objArrayOopDesc::object_size(length);
coleenp@3602 193 KlassHandle h_k(THREAD, this);
coleenp@3602 194 return (objArrayOop)CollectedHeap::array_allocate(h_k, size, length, CHECK_NULL);
duke@0 195 } else {
martin@876 196 report_java_out_of_memory("Requested array size exceeds VM limit");
sspitsyn@3203 197 JvmtiExport::post_array_size_exhausted();
duke@0 198 THROW_OOP_0(Universe::out_of_memory_error_array_size());
duke@0 199 }
duke@0 200 } else {
duke@0 201 THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
duke@0 202 }
duke@0 203 }
duke@0 204
duke@0 205 static int multi_alloc_counter = 0;
duke@0 206
coleenp@3707 207 oop ObjArrayKlass::multi_allocate(int rank, jint* sizes, TRAPS) {
duke@0 208 int length = *sizes;
duke@0 209 // Call to lower_dimension uses this pointer, so most be called before a
duke@0 210 // possible GC
duke@0 211 KlassHandle h_lower_dimension(THREAD, lower_dimension());
duke@0 212 // If length < 0 allocate will throw an exception.
duke@0 213 objArrayOop array = allocate(length, CHECK_NULL);
duke@0 214 objArrayHandle h_array (THREAD, array);
duke@0 215 if (rank > 1) {
duke@0 216 if (length != 0) {
duke@0 217 for (int index = 0; index < length; index++) {
coleenp@3707 218 ArrayKlass* ak = ArrayKlass::cast(h_lower_dimension());
duke@0 219 oop sub_array = ak->multi_allocate(rank-1, &sizes[1], CHECK_NULL);
duke@0 220 h_array->obj_at_put(index, sub_array);
duke@0 221 }
duke@0 222 } else {
duke@0 223 // Since this array dimension has zero length, nothing will be
duke@0 224 // allocated, however the lower dimension values must be checked
duke@0 225 // for illegal values.
duke@0 226 for (int i = 0; i < rank - 1; ++i) {
duke@0 227 sizes += 1;
duke@0 228 if (*sizes < 0) {
duke@0 229 THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
duke@0 230 }
duke@0 231 }
duke@0 232 }
duke@0 233 }
duke@0 234 return h_array();
duke@0 235 }
duke@0 236
coleenp@113 237 // Either oop or narrowOop depending on UseCompressedOops.
coleenp@3707 238 template <class T> void ObjArrayKlass::do_copy(arrayOop s, T* src,
coleenp@113 239 arrayOop d, T* dst, int length, TRAPS) {
coleenp@113 240
coleenp@113 241 BarrierSet* bs = Universe::heap()->barrier_set();
ysr@342 242 // For performance reasons, we assume we are that the write barrier we
ysr@342 243 // are using has optimized modes for arrays of references. At least one
ysr@342 244 // of the asserts below will fail if this is not the case.
coleenp@113 245 assert(bs->has_write_ref_array_opt(), "Barrier set must have ref array opt");
ysr@342 246 assert(bs->has_write_ref_array_pre_opt(), "For pre-barrier as well.");
coleenp@113 247
coleenp@113 248 if (s == d) {
coleenp@113 249 // since source and destination are equal we do not need conversion checks.
coleenp@113 250 assert(length > 0, "sanity check");
ysr@845 251 bs->write_ref_array_pre(dst, length);
coleenp@113 252 Copy::conjoint_oops_atomic(src, dst, length);
coleenp@113 253 } else {
coleenp@113 254 // We have to make sure all elements conform to the destination array
coleenp@3707 255 Klass* bound = ObjArrayKlass::cast(d->klass())->element_klass();
coleenp@3707 256 Klass* stype = ObjArrayKlass::cast(s->klass())->element_klass();
coleenp@113 257 if (stype == bound || Klass::cast(stype)->is_subtype_of(bound)) {
coleenp@113 258 // elements are guaranteed to be subtypes, so no check necessary
ysr@845 259 bs->write_ref_array_pre(dst, length);
coleenp@113 260 Copy::conjoint_oops_atomic(src, dst, length);
coleenp@113 261 } else {
coleenp@113 262 // slow case: need individual subtype checks
coleenp@113 263 // note: don't use obj_at_put below because it includes a redundant store check
coleenp@113 264 T* from = src;
coleenp@113 265 T* end = from + length;
coleenp@113 266 for (T* p = dst; from < end; from++, p++) {
coleenp@113 267 // XXX this is going to be slow.
coleenp@113 268 T element = *from;
ysr@342 269 // even slower now
ysr@342 270 bool element_is_null = oopDesc::is_null(element);
ysr@342 271 oop new_val = element_is_null ? oop(NULL)
ysr@342 272 : oopDesc::decode_heap_oop_not_null(element);
ysr@342 273 if (element_is_null ||
ysr@342 274 Klass::cast((new_val->klass()))->is_subtype_of(bound)) {
ysr@342 275 bs->write_ref_field_pre(p, new_val);
coleenp@113 276 *p = *from;
coleenp@113 277 } else {
coleenp@113 278 // We must do a barrier to cover the partial copy.
coleenp@113 279 const size_t pd = pointer_delta(p, dst, (size_t)heapOopSize);
coleenp@113 280 // pointer delta is scaled to number of elements (length field in
coleenp@113 281 // objArrayOop) which we assume is 32 bit.
coleenp@113 282 assert(pd == (size_t)(int)pd, "length field overflow");
ysr@1091 283 bs->write_ref_array((HeapWord*)dst, pd);
coleenp@113 284 THROW(vmSymbols::java_lang_ArrayStoreException());
coleenp@113 285 return;
coleenp@113 286 }
coleenp@113 287 }
coleenp@113 288 }
coleenp@113 289 }
ysr@1091 290 bs->write_ref_array((HeapWord*)dst, length);
coleenp@113 291 }
coleenp@113 292
coleenp@3707 293 void ObjArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d,
duke@0 294 int dst_pos, int length, TRAPS) {
duke@0 295 assert(s->is_objArray(), "must be obj array");
duke@0 296
duke@0 297 if (!d->is_objArray()) {
duke@0 298 THROW(vmSymbols::java_lang_ArrayStoreException());
duke@0 299 }
duke@0 300
duke@0 301 // Check is all offsets and lengths are non negative
duke@0 302 if (src_pos < 0 || dst_pos < 0 || length < 0) {
duke@0 303 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
duke@0 304 }
duke@0 305 // Check if the ranges are valid
duke@0 306 if ( (((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length())
duke@0 307 || (((unsigned int) length + (unsigned int) dst_pos) > (unsigned int) d->length()) ) {
duke@0 308 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
duke@0 309 }
duke@0 310
duke@0 311 // Special case. Boundary cases must be checked first
duke@0 312 // This allows the following call: copy_array(s, s.length(), d.length(), 0).
duke@0 313 // This is correct, since the position is supposed to be an 'in between point', i.e., s.length(),
duke@0 314 // points to the right of the last element.
duke@0 315 if (length==0) {
duke@0 316 return;
duke@0 317 }
coleenp@113 318 if (UseCompressedOops) {
coleenp@113 319 narrowOop* const src = objArrayOop(s)->obj_at_addr<narrowOop>(src_pos);
coleenp@113 320 narrowOop* const dst = objArrayOop(d)->obj_at_addr<narrowOop>(dst_pos);
coleenp@113 321 do_copy<narrowOop>(s, src, d, dst, length, CHECK);
duke@0 322 } else {
coleenp@113 323 oop* const src = objArrayOop(s)->obj_at_addr<oop>(src_pos);
coleenp@113 324 oop* const dst = objArrayOop(d)->obj_at_addr<oop>(dst_pos);
coleenp@113 325 do_copy<oop> (s, src, d, dst, length, CHECK);
duke@0 326 }
duke@0 327 }
duke@0 328
duke@0 329
coleenp@3707 330 Klass* ObjArrayKlass::array_klass_impl(bool or_null, int n, TRAPS) {
duke@0 331
coleenp@3602 332 assert(dimension() <= n, "check order of chain");
coleenp@3602 333 int dim = dimension();
coleenp@3602 334 if (dim == n) return this;
duke@0 335
coleenp@3602 336 if (higher_dimension() == NULL) {
duke@0 337 if (or_null) return NULL;
duke@0 338
duke@0 339 ResourceMark rm;
duke@0 340 JavaThread *jt = (JavaThread *)THREAD;
duke@0 341 {
duke@0 342 MutexLocker mc(Compile_lock, THREAD); // for vtables
duke@0 343 // Ensure atomic creation of higher dimensions
duke@0 344 MutexLocker mu(MultiArray_lock, THREAD);
duke@0 345
duke@0 346 // Check if another thread beat us
coleenp@3602 347 if (higher_dimension() == NULL) {
duke@0 348
duke@0 349 // Create multi-dim klass object and link them together
coleenp@3602 350 Klass* k =
coleenp@3707 351 ObjArrayKlass::allocate_objArray_klass(class_loader_data(), dim + 1, this, CHECK_NULL);
coleenp@3707 352 ObjArrayKlass* ak = ObjArrayKlass::cast(k);
coleenp@3602 353 ak->set_lower_dimension(this);
kvn@2004 354 OrderAccess::storestore();
coleenp@3602 355 set_higher_dimension(ak);
coleenp@3707 356 assert(ak->oop_is_objArray(), "incorrect initialization of ObjArrayKlass");
duke@0 357 }
duke@0 358 }
duke@0 359 } else {
duke@0 360 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
duke@0 361 }
duke@0 362
coleenp@3707 363 ObjArrayKlass *ak = ObjArrayKlass::cast(higher_dimension());
duke@0 364 if (or_null) {
duke@0 365 return ak->array_klass_or_null(n);
duke@0 366 }
duke@0 367 return ak->array_klass(n, CHECK_NULL);
duke@0 368 }
duke@0 369
coleenp@3707 370 Klass* ObjArrayKlass::array_klass_impl(bool or_null, TRAPS) {
duke@0 371 return array_klass_impl(or_null, dimension() + 1, CHECK_NULL);
duke@0 372 }
duke@0 373
coleenp@3707 374 bool ObjArrayKlass::can_be_primary_super_slow() const {
coleenp@3602 375 if (!bottom_klass()->can_be_primary_super())
duke@0 376 // array of interfaces
duke@0 377 return false;
duke@0 378 else
duke@0 379 return Klass::can_be_primary_super_slow();
duke@0 380 }
duke@0 381
coleenp@3707 382 GrowableArray<Klass*>* ObjArrayKlass::compute_secondary_supers(int num_extra_slots) {
duke@0 383 // interfaces = { cloneable_klass, serializable_klass, elemSuper[], ... };
coleenp@3602 384 Array<Klass*>* elem_supers = Klass::cast(element_klass())->secondary_supers();
coleenp@3602 385 int num_elem_supers = elem_supers == NULL ? 0 : elem_supers->length();
duke@0 386 int num_secondaries = num_extra_slots + 2 + num_elem_supers;
duke@0 387 if (num_secondaries == 2) {
duke@0 388 // Must share this for correct bootstrapping!
coleenp@3602 389 set_secondary_supers(Universe::the_array_interfaces_array());
coleenp@3602 390 return NULL;
duke@0 391 } else {
coleenp@3602 392 GrowableArray<Klass*>* secondaries = new GrowableArray<Klass*>(num_elem_supers+2);
coleenp@3602 393 secondaries->push(SystemDictionary::Cloneable_klass());
coleenp@3602 394 secondaries->push(SystemDictionary::Serializable_klass());
duke@0 395 for (int i = 0; i < num_elem_supers; i++) {
coleenp@3602 396 Klass* elem_super = (Klass*) elem_supers->at(i);
coleenp@3602 397 Klass* array_super = elem_super->array_klass_or_null();
duke@0 398 assert(array_super != NULL, "must already have been created");
coleenp@3602 399 secondaries->push(array_super);
duke@0 400 }
coleenp@3602 401 return secondaries;
duke@0 402 }
duke@0 403 }
duke@0 404
coleenp@3707 405 bool ObjArrayKlass::compute_is_subtype_of(Klass* k) {
coleenp@3602 406 if (!k->oop_is_objArray())
coleenp@3707 407 return ArrayKlass::compute_is_subtype_of(k);
duke@0 408
coleenp@3707 409 ObjArrayKlass* oak = ObjArrayKlass::cast(k);
coleenp@3602 410 return element_klass()->is_subtype_of(oak->element_klass());
duke@0 411 }
duke@0 412
coleenp@3707 413 void ObjArrayKlass::initialize(TRAPS) {
coleenp@3707 414 Klass::cast(bottom_klass())->initialize(THREAD); // dispatches to either InstanceKlass or TypeArrayKlass
duke@0 415 }
duke@0 416
coleenp@113 417 #define ObjArrayKlass_SPECIALIZED_OOP_ITERATE(T, a, p, do_oop) \
coleenp@113 418 { \
coleenp@113 419 T* p = (T*)(a)->base(); \
coleenp@113 420 T* const end = p + (a)->length(); \
coleenp@113 421 while (p < end) { \
coleenp@113 422 do_oop; \
coleenp@113 423 p++; \
coleenp@113 424 } \
coleenp@113 425 }
coleenp@113 426
coleenp@113 427 #define ObjArrayKlass_SPECIALIZED_BOUNDED_OOP_ITERATE(T, a, p, low, high, do_oop) \
coleenp@113 428 { \
coleenp@113 429 T* const l = (T*)(low); \
coleenp@113 430 T* const h = (T*)(high); \
coleenp@113 431 T* p = (T*)(a)->base(); \
coleenp@113 432 T* end = p + (a)->length(); \
coleenp@113 433 if (p < l) p = l; \
coleenp@113 434 if (end > h) end = h; \
coleenp@113 435 while (p < end) { \
coleenp@113 436 do_oop; \
coleenp@113 437 ++p; \
coleenp@113 438 } \
coleenp@113 439 }
coleenp@113 440
coleenp@113 441 #define ObjArrayKlass_OOP_ITERATE(a, p, do_oop) \
coleenp@113 442 if (UseCompressedOops) { \
coleenp@113 443 ObjArrayKlass_SPECIALIZED_OOP_ITERATE(narrowOop, \
coleenp@113 444 a, p, do_oop) \
coleenp@113 445 } else { \
coleenp@113 446 ObjArrayKlass_SPECIALIZED_OOP_ITERATE(oop, \
coleenp@113 447 a, p, do_oop) \
coleenp@113 448 }
coleenp@113 449
coleenp@113 450 #define ObjArrayKlass_BOUNDED_OOP_ITERATE(a, p, low, high, do_oop) \
coleenp@113 451 if (UseCompressedOops) { \
coleenp@113 452 ObjArrayKlass_SPECIALIZED_BOUNDED_OOP_ITERATE(narrowOop, \
coleenp@113 453 a, p, low, high, do_oop) \
coleenp@113 454 } else { \
coleenp@113 455 ObjArrayKlass_SPECIALIZED_BOUNDED_OOP_ITERATE(oop, \
coleenp@113 456 a, p, low, high, do_oop) \
coleenp@113 457 }
duke@0 458
coleenp@3707 459 void ObjArrayKlass::oop_follow_contents(oop obj) {
duke@0 460 assert (obj->is_array(), "obj must be array");
coleenp@3602 461 MarkSweep::follow_klass(obj->klass());
jcoomes@1311 462 if (UseCompressedOops) {
jcoomes@1311 463 objarray_follow_contents<narrowOop>(obj, 0);
jcoomes@1311 464 } else {
jcoomes@1311 465 objarray_follow_contents<oop>(obj, 0);
jcoomes@1311 466 }
duke@0 467 }
duke@0 468
duke@0 469 #ifndef SERIALGC
coleenp@3707 470 void ObjArrayKlass::oop_follow_contents(ParCompactionManager* cm,
duke@0 471 oop obj) {
jcoomes@1311 472 assert(obj->is_array(), "obj must be array");
coleenp@3602 473 PSParallelCompact::follow_klass(cm, obj->klass());
jcoomes@1311 474 if (UseCompressedOops) {
jcoomes@1311 475 objarray_follow_contents<narrowOop>(cm, obj, 0);
jcoomes@1311 476 } else {
jcoomes@1311 477 objarray_follow_contents<oop>(cm, obj, 0);
jcoomes@1311 478 }
duke@0 479 }
duke@0 480 #endif // SERIALGC
duke@0 481
coleenp@3602 482 #define if_do_metadata_checked(closure, nv_suffix) \
coleenp@3602 483 /* Make sure the non-virtual and the virtual versions match. */ \
coleenp@3602 484 assert(closure->do_metadata##nv_suffix() == closure->do_metadata(), \
coleenp@3602 485 "Inconsistency in do_metadata"); \
coleenp@3602 486 if (closure->do_metadata##nv_suffix())
coleenp@3602 487
duke@0 488 #define ObjArrayKlass_OOP_OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \
duke@0 489 \
coleenp@3707 490 int ObjArrayKlass::oop_oop_iterate##nv_suffix(oop obj, \
duke@0 491 OopClosureType* closure) { \
duke@0 492 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::oa); \
duke@0 493 assert (obj->is_array(), "obj must be array"); \
duke@0 494 objArrayOop a = objArrayOop(obj); \
duke@0 495 /* Get size before changing pointers. */ \
duke@0 496 /* Don't call size() or oop_size() since that is a virtual call. */ \
duke@0 497 int size = a->object_size(); \
coleenp@3602 498 if_do_metadata_checked(closure, nv_suffix) { \
coleenp@3602 499 closure->do_klass##nv_suffix(obj->klass()); \
duke@0 500 } \
coleenp@113 501 ObjArrayKlass_OOP_ITERATE(a, p, (closure)->do_oop##nv_suffix(p)) \
duke@0 502 return size; \
duke@0 503 }
duke@0 504
duke@0 505 #define ObjArrayKlass_OOP_OOP_ITERATE_DEFN_m(OopClosureType, nv_suffix) \
duke@0 506 \
coleenp@3707 507 int ObjArrayKlass::oop_oop_iterate##nv_suffix##_m(oop obj, \
duke@0 508 OopClosureType* closure, \
duke@0 509 MemRegion mr) { \
duke@0 510 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::oa); \
duke@0 511 assert(obj->is_array(), "obj must be array"); \
duke@0 512 objArrayOop a = objArrayOop(obj); \
duke@0 513 /* Get size before changing pointers. */ \
duke@0 514 /* Don't call size() or oop_size() since that is a virtual call */ \
duke@0 515 int size = a->object_size(); \
coleenp@3602 516 if_do_metadata_checked(closure, nv_suffix) { \
coleenp@3602 517 /* SSS: Do we need to pass down mr here? */ \
coleenp@3602 518 closure->do_klass##nv_suffix(a->klass()); \
duke@0 519 } \
coleenp@113 520 ObjArrayKlass_BOUNDED_OOP_ITERATE( \
coleenp@113 521 a, p, mr.start(), mr.end(), (closure)->do_oop##nv_suffix(p)) \
coleenp@113 522 return size; \
coleenp@113 523 }
coleenp@113 524
coleenp@113 525 // Like oop_oop_iterate but only iterates over a specified range and only used
coleenp@113 526 // for objArrayOops.
coleenp@113 527 #define ObjArrayKlass_OOP_OOP_ITERATE_DEFN_r(OopClosureType, nv_suffix) \
coleenp@113 528 \
coleenp@3707 529 int ObjArrayKlass::oop_oop_iterate_range##nv_suffix(oop obj, \
coleenp@113 530 OopClosureType* closure, \
coleenp@113 531 int start, int end) { \
coleenp@113 532 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::oa); \
coleenp@113 533 assert(obj->is_array(), "obj must be array"); \
coleenp@113 534 objArrayOop a = objArrayOop(obj); \
coleenp@113 535 /* Get size before changing pointers. */ \
coleenp@113 536 /* Don't call size() or oop_size() since that is a virtual call */ \
coleenp@113 537 int size = a->object_size(); \
coleenp@113 538 if (UseCompressedOops) { \
coleenp@113 539 HeapWord* low = start == 0 ? (HeapWord*)a : (HeapWord*)a->obj_at_addr<narrowOop>(start);\
coleenp@113 540 /* this might be wierd if end needs to be aligned on HeapWord boundary */ \
coleenp@113 541 HeapWord* high = (HeapWord*)((narrowOop*)a->base() + end); \
coleenp@113 542 MemRegion mr(low, high); \
coleenp@3602 543 if_do_metadata_checked(closure, nv_suffix) { \
coleenp@3602 544 /* SSS: Do we need to pass down mr here? */ \
coleenp@3602 545 closure->do_klass##nv_suffix(a->klass()); \
duke@0 546 } \
coleenp@113 547 ObjArrayKlass_SPECIALIZED_BOUNDED_OOP_ITERATE(narrowOop, \
coleenp@113 548 a, p, low, high, (closure)->do_oop##nv_suffix(p)) \
duke@0 549 } else { \
coleenp@113 550 HeapWord* low = start == 0 ? (HeapWord*)a : (HeapWord*)a->obj_at_addr<oop>(start); \
coleenp@113 551 HeapWord* high = (HeapWord*)((oop*)a->base() + end); \
coleenp@113 552 MemRegion mr(low, high); \
coleenp@3602 553 if_do_metadata_checked(closure, nv_suffix) { \
coleenp@3602 554 /* SSS: Do we need to pass down mr here? */ \
coleenp@3602 555 closure->do_klass##nv_suffix(a->klass()); \
duke@0 556 } \
coleenp@113 557 ObjArrayKlass_SPECIALIZED_BOUNDED_OOP_ITERATE(oop, \
coleenp@113 558 a, p, low, high, (closure)->do_oop##nv_suffix(p)) \
duke@0 559 } \
duke@0 560 return size; \
duke@0 561 }
duke@0 562
duke@0 563 ALL_OOP_OOP_ITERATE_CLOSURES_1(ObjArrayKlass_OOP_OOP_ITERATE_DEFN)
ysr@342 564 ALL_OOP_OOP_ITERATE_CLOSURES_2(ObjArrayKlass_OOP_OOP_ITERATE_DEFN)
duke@0 565 ALL_OOP_OOP_ITERATE_CLOSURES_1(ObjArrayKlass_OOP_OOP_ITERATE_DEFN_m)
ysr@342 566 ALL_OOP_OOP_ITERATE_CLOSURES_2(ObjArrayKlass_OOP_OOP_ITERATE_DEFN_m)
coleenp@113 567 ALL_OOP_OOP_ITERATE_CLOSURES_1(ObjArrayKlass_OOP_OOP_ITERATE_DEFN_r)
ysr@342 568 ALL_OOP_OOP_ITERATE_CLOSURES_2(ObjArrayKlass_OOP_OOP_ITERATE_DEFN_r)
duke@0 569
coleenp@3707 570 int ObjArrayKlass::oop_adjust_pointers(oop obj) {
duke@0 571 assert(obj->is_objArray(), "obj must be obj array");
duke@0 572 objArrayOop a = objArrayOop(obj);
duke@0 573 // Get size before changing pointers.
duke@0 574 // Don't call size() or oop_size() since that is a virtual call.
duke@0 575 int size = a->object_size();
coleenp@3602 576 MarkSweep::adjust_klass(a->klass());
coleenp@113 577 ObjArrayKlass_OOP_ITERATE(a, p, MarkSweep::adjust_pointer(p))
duke@0 578 return size;
duke@0 579 }
duke@0 580
duke@0 581 #ifndef SERIALGC
coleenp@3707 582 void ObjArrayKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
duke@0 583 assert(obj->is_objArray(), "obj must be obj array");
coleenp@113 584 ObjArrayKlass_OOP_ITERATE( \
coleenp@113 585 objArrayOop(obj), p, \
coleenp@113 586 if (PSScavenge::should_scavenge(p)) { \
coleenp@113 587 pm->claim_or_forward_depth(p); \
coleenp@113 588 })
duke@0 589 }
duke@0 590
coleenp@3707 591 int ObjArrayKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
duke@0 592 assert (obj->is_objArray(), "obj must be obj array");
duke@0 593 objArrayOop a = objArrayOop(obj);
coleenp@3602 594 int size = a->object_size();
coleenp@3602 595 a->update_header(cm);
coleenp@113 596 ObjArrayKlass_OOP_ITERATE(a, p, PSParallelCompact::adjust_pointer(p))
coleenp@3602 597 return size;
duke@0 598 }
duke@0 599 #endif // SERIALGC
duke@0 600
duke@0 601 // JVM support
duke@0 602
coleenp@3707 603 jint ObjArrayKlass::compute_modifier_flags(TRAPS) const {
duke@0 604 // The modifier for an objectArray is the same as its element
duke@0 605 if (element_klass() == NULL) {
duke@0 606 assert(Universe::is_bootstrapping(), "partial objArray only at startup");
duke@0 607 return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
duke@0 608 }
coleenp@398 609 // Return the flags of the bottom element type.
coleenp@398 610 jint element_flags = Klass::cast(bottom_klass())->compute_modifier_flags(CHECK_0);
duke@0 611
duke@0 612 return (element_flags & (JVM_ACC_PUBLIC | JVM_ACC_PRIVATE | JVM_ACC_PROTECTED))
duke@0 613 | (JVM_ACC_ABSTRACT | JVM_ACC_FINAL);
duke@0 614 }
duke@0 615
duke@0 616
coleenp@3602 617 // Printing
coleenp@3602 618
coleenp@3707 619 void ObjArrayKlass::print_on(outputStream* st) const {
duke@0 620 #ifndef PRODUCT
coleenp@3602 621 Klass::print_on(st);
coleenp@3602 622 st->print(" - instance klass: ");
coleenp@3602 623 element_klass()->print_value_on(st);
coleenp@3602 624 st->cr();
coleenp@3602 625 #endif //PRODUCT
coleenp@3602 626 }
coleenp@3602 627
coleenp@3707 628 void ObjArrayKlass::print_value_on(outputStream* st) const {
coleenp@3602 629 assert(is_klass(), "must be klass");
coleenp@3602 630
coleenp@3602 631 element_klass()->print_value_on(st);
coleenp@3602 632 st->print("[]");
coleenp@3602 633 }
coleenp@3602 634
coleenp@3602 635 #ifndef PRODUCT
duke@0 636
coleenp@3707 637 void ObjArrayKlass::oop_print_on(oop obj, outputStream* st) {
coleenp@3707 638 ArrayKlass::oop_print_on(obj, st);
duke@0 639 assert(obj->is_objArray(), "must be objArray");
duke@0 640 objArrayOop oa = objArrayOop(obj);
duke@0 641 int print_len = MIN2((intx) oa->length(), MaxElementPrintSize);
duke@0 642 for(int index = 0; index < print_len; index++) {
duke@0 643 st->print(" - %3d : ", index);
duke@0 644 oa->obj_at(index)->print_value_on(st);
duke@0 645 st->cr();
duke@0 646 }
duke@0 647 int remaining = oa->length() - print_len;
duke@0 648 if (remaining > 0) {
duke@0 649 tty->print_cr(" - <%d more elements, increase MaxElementPrintSize to print>", remaining);
duke@0 650 }
duke@0 651 }
duke@0 652
jrose@1155 653 #endif //PRODUCT
jrose@1155 654
jrose@665 655 static int max_objArray_print_length = 4;
duke@0 656
coleenp@3707 657 void ObjArrayKlass::oop_print_value_on(oop obj, outputStream* st) {
duke@0 658 assert(obj->is_objArray(), "must be objArray");
jrose@665 659 st->print("a ");
duke@0 660 element_klass()->print_value_on(st);
jrose@665 661 int len = objArrayOop(obj)->length();
jrose@665 662 st->print("[%d] ", len);
jrose@665 663 obj->print_address_on(st);
jrose@1155 664 if (NOT_PRODUCT(PrintOopAddress ||) PrintMiscellaneous && (WizardMode || Verbose)) {
jrose@665 665 st->print("{");
jrose@665 666 for (int i = 0; i < len; i++) {
jrose@665 667 if (i > max_objArray_print_length) {
jrose@665 668 st->print("..."); break;
jrose@665 669 }
jrose@665 670 st->print(" "INTPTR_FORMAT, (intptr_t)(void*)objArrayOop(obj)->obj_at(i));
jrose@665 671 }
jrose@665 672 st->print(" }");
jrose@665 673 }
duke@0 674 }
duke@0 675
coleenp@3707 676 const char* ObjArrayKlass::internal_name() const {
duke@0 677 return external_name();
duke@0 678 }
duke@0 679
coleenp@3602 680
duke@0 681 // Verification
duke@0 682
coleenp@3707 683 void ObjArrayKlass::verify_on(outputStream* st) {
coleenp@3707 684 ArrayKlass::verify_on(st);
coleenp@3602 685 guarantee(element_klass()->is_metadata(), "should be in metaspace");
coleenp@3602 686 guarantee(element_klass()->is_klass(), "should be klass");
coleenp@3602 687 guarantee(bottom_klass()->is_metadata(), "should be in metaspace");
coleenp@3602 688 guarantee(bottom_klass()->is_klass(), "should be klass");
coleenp@3602 689 Klass* bk = Klass::cast(bottom_klass());
coleenp@3602 690 guarantee(bk->oop_is_instance() || bk->oop_is_typeArray(), "invalid bottom klass");
coleenp@3602 691 }
coleenp@3602 692
coleenp@3707 693 void ObjArrayKlass::oop_verify_on(oop obj, outputStream* st) {
coleenp@3707 694 ArrayKlass::oop_verify_on(obj, st);
duke@0 695 guarantee(obj->is_objArray(), "must be objArray");
duke@0 696 objArrayOop oa = objArrayOop(obj);
duke@0 697 for(int index = 0; index < oa->length(); index++) {
duke@0 698 guarantee(oa->obj_at(index)->is_oop_or_null(), "should be oop");
duke@0 699 }
duke@0 700 }