annotate src/share/vm/oops/objArrayKlass.cpp @ 2004:d4fca0a6abde

7011386: race in objArrayKlass::array_klass_impl Summary: Move _lower_dimension field initialization before _higher_dimension and add storestore barrier. Reviewed-by: dholmes, iveresov, never
author kvn
date Tue, 11 Jan 2011 20:26:13 -0800
parents f95d63e2154a
children 3582bf76420e
rev   line source
duke@0 1 /*
kvn@2004 2 * Copyright (c) 1997, 2011, 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"
stefank@1879 26 #include "classfile/systemDictionary.hpp"
stefank@1879 27 #include "classfile/vmSymbols.hpp"
stefank@1879 28 #include "gc_implementation/shared/markSweep.inline.hpp"
stefank@1879 29 #include "gc_interface/collectedHeap.inline.hpp"
stefank@1879 30 #include "memory/genOopClosures.inline.hpp"
stefank@1879 31 #include "memory/resourceArea.hpp"
stefank@1879 32 #include "memory/universe.inline.hpp"
stefank@1879 33 #include "oops/instanceKlass.hpp"
stefank@1879 34 #include "oops/objArrayKlass.hpp"
stefank@1879 35 #include "oops/objArrayKlass.inline.hpp"
stefank@1879 36 #include "oops/objArrayKlassKlass.hpp"
stefank@1879 37 #include "oops/objArrayOop.hpp"
stefank@1879 38 #include "oops/oop.inline.hpp"
stefank@1879 39 #include "oops/oop.inline2.hpp"
stefank@1879 40 #include "oops/symbolOop.hpp"
stefank@1879 41 #include "runtime/handles.inline.hpp"
stefank@1879 42 #include "runtime/mutexLocker.hpp"
stefank@1879 43 #include "utilities/copy.hpp"
stefank@1879 44 #ifndef SERIALGC
stefank@1879 45 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
stefank@1879 46 #include "gc_implementation/g1/g1OopClosures.inline.hpp"
stefank@1879 47 #include "gc_implementation/g1/g1RemSet.inline.hpp"
stefank@1879 48 #include "gc_implementation/g1/heapRegionSeq.inline.hpp"
stefank@1879 49 #include "gc_implementation/parNew/parOopClosures.inline.hpp"
stefank@1879 50 #include "gc_implementation/parallelScavenge/psCompactionManager.hpp"
stefank@1879 51 #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp"
stefank@1879 52 #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp"
stefank@1879 53 #include "oops/oop.pcgc.inline.hpp"
stefank@1879 54 #endif
duke@0 55
duke@0 56 int objArrayKlass::oop_size(oop obj) const {
duke@0 57 assert(obj->is_objArray(), "must be object array");
duke@0 58 return objArrayOop(obj)->object_size();
duke@0 59 }
duke@0 60
duke@0 61 objArrayOop objArrayKlass::allocate(int length, TRAPS) {
duke@0 62 if (length >= 0) {
duke@0 63 if (length <= arrayOopDesc::max_array_length(T_OBJECT)) {
duke@0 64 int size = objArrayOopDesc::object_size(length);
duke@0 65 KlassHandle h_k(THREAD, as_klassOop());
duke@0 66 objArrayOop a = (objArrayOop)CollectedHeap::array_allocate(h_k, size, length, CHECK_NULL);
duke@0 67 assert(a->is_parsable(), "Can't publish unless parsable");
duke@0 68 return a;
duke@0 69 } else {
martin@876 70 report_java_out_of_memory("Requested array size exceeds VM limit");
duke@0 71 THROW_OOP_0(Universe::out_of_memory_error_array_size());
duke@0 72 }
duke@0 73 } else {
duke@0 74 THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
duke@0 75 }
duke@0 76 }
duke@0 77
duke@0 78 static int multi_alloc_counter = 0;
duke@0 79
duke@0 80 oop objArrayKlass::multi_allocate(int rank, jint* sizes, TRAPS) {
duke@0 81 int length = *sizes;
duke@0 82 // Call to lower_dimension uses this pointer, so most be called before a
duke@0 83 // possible GC
duke@0 84 KlassHandle h_lower_dimension(THREAD, lower_dimension());
duke@0 85 // If length < 0 allocate will throw an exception.
duke@0 86 objArrayOop array = allocate(length, CHECK_NULL);
duke@0 87 assert(array->is_parsable(), "Don't handlize unless parsable");
duke@0 88 objArrayHandle h_array (THREAD, array);
duke@0 89 if (rank > 1) {
duke@0 90 if (length != 0) {
duke@0 91 for (int index = 0; index < length; index++) {
duke@0 92 arrayKlass* ak = arrayKlass::cast(h_lower_dimension());
duke@0 93 oop sub_array = ak->multi_allocate(rank-1, &sizes[1], CHECK_NULL);
duke@0 94 assert(sub_array->is_parsable(), "Don't publish until parsable");
duke@0 95 h_array->obj_at_put(index, sub_array);
duke@0 96 }
duke@0 97 } else {
duke@0 98 // Since this array dimension has zero length, nothing will be
duke@0 99 // allocated, however the lower dimension values must be checked
duke@0 100 // for illegal values.
duke@0 101 for (int i = 0; i < rank - 1; ++i) {
duke@0 102 sizes += 1;
duke@0 103 if (*sizes < 0) {
duke@0 104 THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
duke@0 105 }
duke@0 106 }
duke@0 107 }
duke@0 108 }
duke@0 109 return h_array();
duke@0 110 }
duke@0 111
coleenp@113 112 // Either oop or narrowOop depending on UseCompressedOops.
coleenp@113 113 template <class T> void objArrayKlass::do_copy(arrayOop s, T* src,
coleenp@113 114 arrayOop d, T* dst, int length, TRAPS) {
coleenp@113 115
coleenp@113 116 BarrierSet* bs = Universe::heap()->barrier_set();
ysr@342 117 // For performance reasons, we assume we are that the write barrier we
ysr@342 118 // are using has optimized modes for arrays of references. At least one
ysr@342 119 // of the asserts below will fail if this is not the case.
coleenp@113 120 assert(bs->has_write_ref_array_opt(), "Barrier set must have ref array opt");
ysr@342 121 assert(bs->has_write_ref_array_pre_opt(), "For pre-barrier as well.");
coleenp@113 122
coleenp@113 123 if (s == d) {
coleenp@113 124 // since source and destination are equal we do not need conversion checks.
coleenp@113 125 assert(length > 0, "sanity check");
ysr@845 126 bs->write_ref_array_pre(dst, length);
coleenp@113 127 Copy::conjoint_oops_atomic(src, dst, length);
coleenp@113 128 } else {
coleenp@113 129 // We have to make sure all elements conform to the destination array
coleenp@113 130 klassOop bound = objArrayKlass::cast(d->klass())->element_klass();
coleenp@113 131 klassOop stype = objArrayKlass::cast(s->klass())->element_klass();
coleenp@113 132 if (stype == bound || Klass::cast(stype)->is_subtype_of(bound)) {
coleenp@113 133 // elements are guaranteed to be subtypes, so no check necessary
ysr@845 134 bs->write_ref_array_pre(dst, length);
coleenp@113 135 Copy::conjoint_oops_atomic(src, dst, length);
coleenp@113 136 } else {
coleenp@113 137 // slow case: need individual subtype checks
coleenp@113 138 // note: don't use obj_at_put below because it includes a redundant store check
coleenp@113 139 T* from = src;
coleenp@113 140 T* end = from + length;
coleenp@113 141 for (T* p = dst; from < end; from++, p++) {
coleenp@113 142 // XXX this is going to be slow.
coleenp@113 143 T element = *from;
ysr@342 144 // even slower now
ysr@342 145 bool element_is_null = oopDesc::is_null(element);
ysr@342 146 oop new_val = element_is_null ? oop(NULL)
ysr@342 147 : oopDesc::decode_heap_oop_not_null(element);
ysr@342 148 if (element_is_null ||
ysr@342 149 Klass::cast((new_val->klass()))->is_subtype_of(bound)) {
ysr@342 150 bs->write_ref_field_pre(p, new_val);
coleenp@113 151 *p = *from;
coleenp@113 152 } else {
coleenp@113 153 // We must do a barrier to cover the partial copy.
coleenp@113 154 const size_t pd = pointer_delta(p, dst, (size_t)heapOopSize);
coleenp@113 155 // pointer delta is scaled to number of elements (length field in
coleenp@113 156 // objArrayOop) which we assume is 32 bit.
coleenp@113 157 assert(pd == (size_t)(int)pd, "length field overflow");
ysr@1091 158 bs->write_ref_array((HeapWord*)dst, pd);
coleenp@113 159 THROW(vmSymbols::java_lang_ArrayStoreException());
coleenp@113 160 return;
coleenp@113 161 }
coleenp@113 162 }
coleenp@113 163 }
coleenp@113 164 }
ysr@1091 165 bs->write_ref_array((HeapWord*)dst, length);
coleenp@113 166 }
coleenp@113 167
duke@0 168 void objArrayKlass::copy_array(arrayOop s, int src_pos, arrayOop d,
duke@0 169 int dst_pos, int length, TRAPS) {
duke@0 170 assert(s->is_objArray(), "must be obj array");
duke@0 171
duke@0 172 if (!d->is_objArray()) {
duke@0 173 THROW(vmSymbols::java_lang_ArrayStoreException());
duke@0 174 }
duke@0 175
duke@0 176 // Check is all offsets and lengths are non negative
duke@0 177 if (src_pos < 0 || dst_pos < 0 || length < 0) {
duke@0 178 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
duke@0 179 }
duke@0 180 // Check if the ranges are valid
duke@0 181 if ( (((unsigned int) length + (unsigned int) src_pos) > (unsigned int) s->length())
duke@0 182 || (((unsigned int) length + (unsigned int) dst_pos) > (unsigned int) d->length()) ) {
duke@0 183 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
duke@0 184 }
duke@0 185
duke@0 186 // Special case. Boundary cases must be checked first
duke@0 187 // This allows the following call: copy_array(s, s.length(), d.length(), 0).
duke@0 188 // This is correct, since the position is supposed to be an 'in between point', i.e., s.length(),
duke@0 189 // points to the right of the last element.
duke@0 190 if (length==0) {
duke@0 191 return;
duke@0 192 }
coleenp@113 193 if (UseCompressedOops) {
coleenp@113 194 narrowOop* const src = objArrayOop(s)->obj_at_addr<narrowOop>(src_pos);
coleenp@113 195 narrowOop* const dst = objArrayOop(d)->obj_at_addr<narrowOop>(dst_pos);
coleenp@113 196 do_copy<narrowOop>(s, src, d, dst, length, CHECK);
duke@0 197 } else {
coleenp@113 198 oop* const src = objArrayOop(s)->obj_at_addr<oop>(src_pos);
coleenp@113 199 oop* const dst = objArrayOop(d)->obj_at_addr<oop>(dst_pos);
coleenp@113 200 do_copy<oop> (s, src, d, dst, length, CHECK);
duke@0 201 }
duke@0 202 }
duke@0 203
duke@0 204
duke@0 205 klassOop objArrayKlass::array_klass_impl(bool or_null, int n, TRAPS) {
duke@0 206 objArrayKlassHandle h_this(THREAD, as_klassOop());
duke@0 207 return array_klass_impl(h_this, or_null, n, CHECK_NULL);
duke@0 208 }
duke@0 209
duke@0 210
duke@0 211 klassOop objArrayKlass::array_klass_impl(objArrayKlassHandle this_oop, bool or_null, int n, TRAPS) {
duke@0 212
duke@0 213 assert(this_oop->dimension() <= n, "check order of chain");
duke@0 214 int dimension = this_oop->dimension();
duke@0 215 if (dimension == n)
duke@0 216 return this_oop();
duke@0 217
duke@0 218 objArrayKlassHandle ak (THREAD, this_oop->higher_dimension());
duke@0 219 if (ak.is_null()) {
duke@0 220 if (or_null) return NULL;
duke@0 221
duke@0 222 ResourceMark rm;
duke@0 223 JavaThread *jt = (JavaThread *)THREAD;
duke@0 224 {
duke@0 225 MutexLocker mc(Compile_lock, THREAD); // for vtables
duke@0 226 // Ensure atomic creation of higher dimensions
duke@0 227 MutexLocker mu(MultiArray_lock, THREAD);
duke@0 228
duke@0 229 // Check if another thread beat us
duke@0 230 ak = objArrayKlassHandle(THREAD, this_oop->higher_dimension());
duke@0 231 if( ak.is_null() ) {
duke@0 232
duke@0 233 // Create multi-dim klass object and link them together
duke@0 234 klassOop new_klass =
duke@0 235 objArrayKlassKlass::cast(Universe::objArrayKlassKlassObj())->
duke@0 236 allocate_objArray_klass(dimension + 1, this_oop, CHECK_NULL);
duke@0 237 ak = objArrayKlassHandle(THREAD, new_klass);
kvn@2004 238 ak->set_lower_dimension(this_oop());
kvn@2004 239 OrderAccess::storestore();
duke@0 240 this_oop->set_higher_dimension(ak());
duke@0 241 assert(ak->oop_is_objArray(), "incorrect initialization of objArrayKlass");
duke@0 242 }
duke@0 243 }
duke@0 244 } else {
duke@0 245 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
duke@0 246 }
duke@0 247
duke@0 248 if (or_null) {
duke@0 249 return ak->array_klass_or_null(n);
duke@0 250 }
duke@0 251 return ak->array_klass(n, CHECK_NULL);
duke@0 252 }
duke@0 253
duke@0 254 klassOop objArrayKlass::array_klass_impl(bool or_null, TRAPS) {
duke@0 255 return array_klass_impl(or_null, dimension() + 1, CHECK_NULL);
duke@0 256 }
duke@0 257
duke@0 258 bool objArrayKlass::can_be_primary_super_slow() const {
duke@0 259 if (!bottom_klass()->klass_part()->can_be_primary_super())
duke@0 260 // array of interfaces
duke@0 261 return false;
duke@0 262 else
duke@0 263 return Klass::can_be_primary_super_slow();
duke@0 264 }
duke@0 265
duke@0 266 objArrayOop objArrayKlass::compute_secondary_supers(int num_extra_slots, TRAPS) {
duke@0 267 // interfaces = { cloneable_klass, serializable_klass, elemSuper[], ... };
duke@0 268 objArrayOop es = Klass::cast(element_klass())->secondary_supers();
duke@0 269 objArrayHandle elem_supers (THREAD, es);
duke@0 270 int num_elem_supers = elem_supers.is_null() ? 0 : elem_supers->length();
duke@0 271 int num_secondaries = num_extra_slots + 2 + num_elem_supers;
duke@0 272 if (num_secondaries == 2) {
duke@0 273 // Must share this for correct bootstrapping!
duke@0 274 return Universe::the_array_interfaces_array();
duke@0 275 } else {
duke@0 276 objArrayOop sec_oop = oopFactory::new_system_objArray(num_secondaries, CHECK_NULL);
duke@0 277 objArrayHandle secondaries(THREAD, sec_oop);
never@1142 278 secondaries->obj_at_put(num_extra_slots+0, SystemDictionary::Cloneable_klass());
never@1142 279 secondaries->obj_at_put(num_extra_slots+1, SystemDictionary::Serializable_klass());
duke@0 280 for (int i = 0; i < num_elem_supers; i++) {
duke@0 281 klassOop elem_super = (klassOop) elem_supers->obj_at(i);
duke@0 282 klassOop array_super = elem_super->klass_part()->array_klass_or_null();
duke@0 283 assert(array_super != NULL, "must already have been created");
duke@0 284 secondaries->obj_at_put(num_extra_slots+2+i, array_super);
duke@0 285 }
duke@0 286 return secondaries();
duke@0 287 }
duke@0 288 }
duke@0 289
duke@0 290 bool objArrayKlass::compute_is_subtype_of(klassOop k) {
duke@0 291 if (!k->klass_part()->oop_is_objArray())
duke@0 292 return arrayKlass::compute_is_subtype_of(k);
duke@0 293
duke@0 294 objArrayKlass* oak = objArrayKlass::cast(k);
duke@0 295 return element_klass()->klass_part()->is_subtype_of(oak->element_klass());
duke@0 296 }
duke@0 297
duke@0 298 void objArrayKlass::initialize(TRAPS) {
duke@0 299 Klass::cast(bottom_klass())->initialize(THREAD); // dispatches to either instanceKlass or typeArrayKlass
duke@0 300 }
duke@0 301
coleenp@113 302 #define ObjArrayKlass_SPECIALIZED_OOP_ITERATE(T, a, p, do_oop) \
coleenp@113 303 { \
coleenp@113 304 T* p = (T*)(a)->base(); \
coleenp@113 305 T* const end = p + (a)->length(); \
coleenp@113 306 while (p < end) { \
coleenp@113 307 do_oop; \
coleenp@113 308 p++; \
coleenp@113 309 } \
coleenp@113 310 }
coleenp@113 311
coleenp@113 312 #define ObjArrayKlass_SPECIALIZED_BOUNDED_OOP_ITERATE(T, a, p, low, high, do_oop) \
coleenp@113 313 { \
coleenp@113 314 T* const l = (T*)(low); \
coleenp@113 315 T* const h = (T*)(high); \
coleenp@113 316 T* p = (T*)(a)->base(); \
coleenp@113 317 T* end = p + (a)->length(); \
coleenp@113 318 if (p < l) p = l; \
coleenp@113 319 if (end > h) end = h; \
coleenp@113 320 while (p < end) { \
coleenp@113 321 do_oop; \
coleenp@113 322 ++p; \
coleenp@113 323 } \
coleenp@113 324 }
coleenp@113 325
coleenp@113 326 #define ObjArrayKlass_OOP_ITERATE(a, p, do_oop) \
coleenp@113 327 if (UseCompressedOops) { \
coleenp@113 328 ObjArrayKlass_SPECIALIZED_OOP_ITERATE(narrowOop, \
coleenp@113 329 a, p, do_oop) \
coleenp@113 330 } else { \
coleenp@113 331 ObjArrayKlass_SPECIALIZED_OOP_ITERATE(oop, \
coleenp@113 332 a, p, do_oop) \
coleenp@113 333 }
coleenp@113 334
coleenp@113 335 #define ObjArrayKlass_BOUNDED_OOP_ITERATE(a, p, low, high, do_oop) \
coleenp@113 336 if (UseCompressedOops) { \
coleenp@113 337 ObjArrayKlass_SPECIALIZED_BOUNDED_OOP_ITERATE(narrowOop, \
coleenp@113 338 a, p, low, high, do_oop) \
coleenp@113 339 } else { \
coleenp@113 340 ObjArrayKlass_SPECIALIZED_BOUNDED_OOP_ITERATE(oop, \
coleenp@113 341 a, p, low, high, do_oop) \
coleenp@113 342 }
duke@0 343
duke@0 344 void objArrayKlass::oop_follow_contents(oop obj) {
duke@0 345 assert (obj->is_array(), "obj must be array");
jcoomes@1311 346 objArrayOop(obj)->follow_header();
jcoomes@1311 347 if (UseCompressedOops) {
jcoomes@1311 348 objarray_follow_contents<narrowOop>(obj, 0);
jcoomes@1311 349 } else {
jcoomes@1311 350 objarray_follow_contents<oop>(obj, 0);
jcoomes@1311 351 }
duke@0 352 }
duke@0 353
duke@0 354 #ifndef SERIALGC
duke@0 355 void objArrayKlass::oop_follow_contents(ParCompactionManager* cm,
duke@0 356 oop obj) {
jcoomes@1311 357 assert(obj->is_array(), "obj must be array");
jcoomes@1311 358 objArrayOop(obj)->follow_header(cm);
jcoomes@1311 359 if (UseCompressedOops) {
jcoomes@1311 360 objarray_follow_contents<narrowOop>(cm, obj, 0);
jcoomes@1311 361 } else {
jcoomes@1311 362 objarray_follow_contents<oop>(cm, obj, 0);
jcoomes@1311 363 }
duke@0 364 }
duke@0 365 #endif // SERIALGC
duke@0 366
duke@0 367 #define ObjArrayKlass_OOP_OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \
duke@0 368 \
duke@0 369 int objArrayKlass::oop_oop_iterate##nv_suffix(oop obj, \
duke@0 370 OopClosureType* closure) { \
duke@0 371 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::oa); \
duke@0 372 assert (obj->is_array(), "obj must be array"); \
duke@0 373 objArrayOop a = objArrayOop(obj); \
duke@0 374 /* Get size before changing pointers. */ \
duke@0 375 /* Don't call size() or oop_size() since that is a virtual call. */ \
duke@0 376 int size = a->object_size(); \
duke@0 377 if (closure->do_header()) { \
duke@0 378 a->oop_iterate_header(closure); \
duke@0 379 } \
coleenp@113 380 ObjArrayKlass_OOP_ITERATE(a, p, (closure)->do_oop##nv_suffix(p)) \
duke@0 381 return size; \
duke@0 382 }
duke@0 383
duke@0 384 #define ObjArrayKlass_OOP_OOP_ITERATE_DEFN_m(OopClosureType, nv_suffix) \
duke@0 385 \
duke@0 386 int objArrayKlass::oop_oop_iterate##nv_suffix##_m(oop obj, \
duke@0 387 OopClosureType* closure, \
duke@0 388 MemRegion mr) { \
duke@0 389 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::oa); \
duke@0 390 assert(obj->is_array(), "obj must be array"); \
duke@0 391 objArrayOop a = objArrayOop(obj); \
duke@0 392 /* Get size before changing pointers. */ \
duke@0 393 /* Don't call size() or oop_size() since that is a virtual call */ \
duke@0 394 int size = a->object_size(); \
duke@0 395 if (closure->do_header()) { \
duke@0 396 a->oop_iterate_header(closure, mr); \
duke@0 397 } \
coleenp@113 398 ObjArrayKlass_BOUNDED_OOP_ITERATE( \
coleenp@113 399 a, p, mr.start(), mr.end(), (closure)->do_oop##nv_suffix(p)) \
coleenp@113 400 return size; \
coleenp@113 401 }
coleenp@113 402
coleenp@113 403 // Like oop_oop_iterate but only iterates over a specified range and only used
coleenp@113 404 // for objArrayOops.
coleenp@113 405 #define ObjArrayKlass_OOP_OOP_ITERATE_DEFN_r(OopClosureType, nv_suffix) \
coleenp@113 406 \
coleenp@113 407 int objArrayKlass::oop_oop_iterate_range##nv_suffix(oop obj, \
coleenp@113 408 OopClosureType* closure, \
coleenp@113 409 int start, int end) { \
coleenp@113 410 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::oa); \
coleenp@113 411 assert(obj->is_array(), "obj must be array"); \
coleenp@113 412 objArrayOop a = objArrayOop(obj); \
coleenp@113 413 /* Get size before changing pointers. */ \
coleenp@113 414 /* Don't call size() or oop_size() since that is a virtual call */ \
coleenp@113 415 int size = a->object_size(); \
coleenp@113 416 if (UseCompressedOops) { \
coleenp@113 417 HeapWord* low = start == 0 ? (HeapWord*)a : (HeapWord*)a->obj_at_addr<narrowOop>(start);\
coleenp@113 418 /* this might be wierd if end needs to be aligned on HeapWord boundary */ \
coleenp@113 419 HeapWord* high = (HeapWord*)((narrowOop*)a->base() + end); \
coleenp@113 420 MemRegion mr(low, high); \
coleenp@113 421 if (closure->do_header()) { \
coleenp@113 422 a->oop_iterate_header(closure, mr); \
duke@0 423 } \
coleenp@113 424 ObjArrayKlass_SPECIALIZED_BOUNDED_OOP_ITERATE(narrowOop, \
coleenp@113 425 a, p, low, high, (closure)->do_oop##nv_suffix(p)) \
duke@0 426 } else { \
coleenp@113 427 HeapWord* low = start == 0 ? (HeapWord*)a : (HeapWord*)a->obj_at_addr<oop>(start); \
coleenp@113 428 HeapWord* high = (HeapWord*)((oop*)a->base() + end); \
coleenp@113 429 MemRegion mr(low, high); \
coleenp@113 430 if (closure->do_header()) { \
coleenp@113 431 a->oop_iterate_header(closure, mr); \
duke@0 432 } \
coleenp@113 433 ObjArrayKlass_SPECIALIZED_BOUNDED_OOP_ITERATE(oop, \
coleenp@113 434 a, p, low, high, (closure)->do_oop##nv_suffix(p)) \
duke@0 435 } \
duke@0 436 return size; \
duke@0 437 }
duke@0 438
duke@0 439 ALL_OOP_OOP_ITERATE_CLOSURES_1(ObjArrayKlass_OOP_OOP_ITERATE_DEFN)
ysr@342 440 ALL_OOP_OOP_ITERATE_CLOSURES_2(ObjArrayKlass_OOP_OOP_ITERATE_DEFN)
duke@0 441 ALL_OOP_OOP_ITERATE_CLOSURES_1(ObjArrayKlass_OOP_OOP_ITERATE_DEFN_m)
ysr@342 442 ALL_OOP_OOP_ITERATE_CLOSURES_2(ObjArrayKlass_OOP_OOP_ITERATE_DEFN_m)
coleenp@113 443 ALL_OOP_OOP_ITERATE_CLOSURES_1(ObjArrayKlass_OOP_OOP_ITERATE_DEFN_r)
ysr@342 444 ALL_OOP_OOP_ITERATE_CLOSURES_2(ObjArrayKlass_OOP_OOP_ITERATE_DEFN_r)
duke@0 445
duke@0 446 int objArrayKlass::oop_adjust_pointers(oop obj) {
duke@0 447 assert(obj->is_objArray(), "obj must be obj array");
duke@0 448 objArrayOop a = objArrayOop(obj);
duke@0 449 // Get size before changing pointers.
duke@0 450 // Don't call size() or oop_size() since that is a virtual call.
duke@0 451 int size = a->object_size();
duke@0 452 a->adjust_header();
coleenp@113 453 ObjArrayKlass_OOP_ITERATE(a, p, MarkSweep::adjust_pointer(p))
duke@0 454 return size;
duke@0 455 }
duke@0 456
duke@0 457 #ifndef SERIALGC
duke@0 458 void objArrayKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
duke@0 459 assert(obj->is_objArray(), "obj must be obj array");
coleenp@113 460 ObjArrayKlass_OOP_ITERATE( \
coleenp@113 461 objArrayOop(obj), p, \
coleenp@113 462 if (PSScavenge::should_scavenge(p)) { \
coleenp@113 463 pm->claim_or_forward_depth(p); \
coleenp@113 464 })
duke@0 465 }
duke@0 466
duke@0 467 int objArrayKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
duke@0 468 assert (obj->is_objArray(), "obj must be obj array");
duke@0 469 objArrayOop a = objArrayOop(obj);
coleenp@113 470 ObjArrayKlass_OOP_ITERATE(a, p, PSParallelCompact::adjust_pointer(p))
duke@0 471 return a->object_size();
duke@0 472 }
duke@0 473
duke@0 474 int objArrayKlass::oop_update_pointers(ParCompactionManager* cm, oop obj,
duke@0 475 HeapWord* beg_addr, HeapWord* end_addr) {
duke@0 476 assert (obj->is_objArray(), "obj must be obj array");
duke@0 477 objArrayOop a = objArrayOop(obj);
coleenp@113 478 ObjArrayKlass_BOUNDED_OOP_ITERATE( \
coleenp@113 479 a, p, beg_addr, end_addr, \
coleenp@113 480 PSParallelCompact::adjust_pointer(p))
duke@0 481 return a->object_size();
duke@0 482 }
duke@0 483 #endif // SERIALGC
duke@0 484
duke@0 485 // JVM support
duke@0 486
duke@0 487 jint objArrayKlass::compute_modifier_flags(TRAPS) const {
duke@0 488 // The modifier for an objectArray is the same as its element
duke@0 489 if (element_klass() == NULL) {
duke@0 490 assert(Universe::is_bootstrapping(), "partial objArray only at startup");
duke@0 491 return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
duke@0 492 }
coleenp@398 493 // Return the flags of the bottom element type.
coleenp@398 494 jint element_flags = Klass::cast(bottom_klass())->compute_modifier_flags(CHECK_0);
duke@0 495
duke@0 496 return (element_flags & (JVM_ACC_PUBLIC | JVM_ACC_PRIVATE | JVM_ACC_PROTECTED))
duke@0 497 | (JVM_ACC_ABSTRACT | JVM_ACC_FINAL);
duke@0 498 }
duke@0 499
duke@0 500
duke@0 501 #ifndef PRODUCT
duke@0 502 // Printing
duke@0 503
duke@0 504 void objArrayKlass::oop_print_on(oop obj, outputStream* st) {
duke@0 505 arrayKlass::oop_print_on(obj, st);
duke@0 506 assert(obj->is_objArray(), "must be objArray");
duke@0 507 objArrayOop oa = objArrayOop(obj);
duke@0 508 int print_len = MIN2((intx) oa->length(), MaxElementPrintSize);
duke@0 509 for(int index = 0; index < print_len; index++) {
duke@0 510 st->print(" - %3d : ", index);
duke@0 511 oa->obj_at(index)->print_value_on(st);
duke@0 512 st->cr();
duke@0 513 }
duke@0 514 int remaining = oa->length() - print_len;
duke@0 515 if (remaining > 0) {
duke@0 516 tty->print_cr(" - <%d more elements, increase MaxElementPrintSize to print>", remaining);
duke@0 517 }
duke@0 518 }
duke@0 519
jrose@1155 520 #endif //PRODUCT
jrose@1155 521
jrose@665 522 static int max_objArray_print_length = 4;
duke@0 523
duke@0 524 void objArrayKlass::oop_print_value_on(oop obj, outputStream* st) {
duke@0 525 assert(obj->is_objArray(), "must be objArray");
jrose@665 526 st->print("a ");
duke@0 527 element_klass()->print_value_on(st);
jrose@665 528 int len = objArrayOop(obj)->length();
jrose@665 529 st->print("[%d] ", len);
jrose@665 530 obj->print_address_on(st);
jrose@1155 531 if (NOT_PRODUCT(PrintOopAddress ||) PrintMiscellaneous && (WizardMode || Verbose)) {
jrose@665 532 st->print("{");
jrose@665 533 for (int i = 0; i < len; i++) {
jrose@665 534 if (i > max_objArray_print_length) {
jrose@665 535 st->print("..."); break;
jrose@665 536 }
jrose@665 537 st->print(" "INTPTR_FORMAT, (intptr_t)(void*)objArrayOop(obj)->obj_at(i));
jrose@665 538 }
jrose@665 539 st->print(" }");
jrose@665 540 }
duke@0 541 }
duke@0 542
duke@0 543 const char* objArrayKlass::internal_name() const {
duke@0 544 return external_name();
duke@0 545 }
duke@0 546
duke@0 547 // Verification
duke@0 548
duke@0 549 void objArrayKlass::oop_verify_on(oop obj, outputStream* st) {
duke@0 550 arrayKlass::oop_verify_on(obj, st);
duke@0 551 guarantee(obj->is_objArray(), "must be objArray");
duke@0 552 objArrayOop oa = objArrayOop(obj);
duke@0 553 for(int index = 0; index < oa->length(); index++) {
duke@0 554 guarantee(oa->obj_at(index)->is_oop_or_null(), "should be oop");
duke@0 555 }
duke@0 556 }
duke@0 557
duke@0 558 void objArrayKlass::oop_verify_old_oop(oop obj, oop* p, bool allow_dirty) {
duke@0 559 /* $$$ move into remembered set verification?
duke@0 560 RememberedSet::verify_old_oop(obj, p, allow_dirty, true);
duke@0 561 */
duke@0 562 }
coleenp@113 563 void objArrayKlass::oop_verify_old_oop(oop obj, narrowOop* p, bool allow_dirty) {}