src/share/vm/oops/objArrayKlass.cpp

Tue, 05 Feb 2013 08:25:51 -0800

author
vlivanov
date
Tue, 05 Feb 2013 08:25:51 -0800
changeset 4539
6a51fc70a15e
parent 4304
90273fc0a981
child 4542
db9981fd3124
permissions
-rw-r--r--

8006613: adding reason to made_not_compilable
Reviewed-by: kvn, vlivanov
Contributed-by: Igor Ignatyev <igor.ignatyev@oracle.com>

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

mercurial