annotate src/share/vm/oops/instanceMirrorKlass.cpp @ 5645:fce21ac5968d

8027229: ICCE expected for >=2 maximally specific default methods. Summary: Need to process defaults for interfaces for invokespecial Reviewed-by: lfoltan, hseigel, coleenp, jrose
author acorn
date Wed, 13 Nov 2013 07:31:26 -0800
parents aed758eda82a
children 55a0da3d420b
rev   line source
never@2223 1 /*
coleenp@3602 2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
never@2223 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
never@2223 4 *
never@2223 5 * This code is free software; you can redistribute it and/or modify it
never@2223 6 * under the terms of the GNU General Public License version 2 only, as
never@2223 7 * published by the Free Software Foundation.
never@2223 8 *
never@2223 9 * This code is distributed in the hope that it will be useful, but WITHOUT
never@2223 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
never@2223 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
never@2223 12 * version 2 for more details (a copy is included in the LICENSE file that
never@2223 13 * accompanied this code).
never@2223 14 *
never@2223 15 * You should have received a copy of the GNU General Public License version
never@2223 16 * 2 along with this work; if not, write to the Free Software Foundation,
never@2223 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
never@2223 18 *
never@2223 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
never@2223 20 * or visit www.oracle.com if you need additional information or have any
never@2223 21 * questions.
never@2223 22 *
never@2223 23 */
never@2223 24
never@2223 25 #include "precompiled.hpp"
never@2223 26 #include "classfile/javaClasses.hpp"
never@2223 27 #include "classfile/systemDictionary.hpp"
never@2223 28 #include "gc_implementation/shared/markSweep.inline.hpp"
never@2223 29 #include "gc_interface/collectedHeap.inline.hpp"
never@2223 30 #include "memory/genOopClosures.inline.hpp"
never@2223 31 #include "memory/oopFactory.hpp"
never@2223 32 #include "oops/instanceKlass.hpp"
never@2223 33 #include "oops/instanceMirrorKlass.hpp"
never@2223 34 #include "oops/instanceOop.hpp"
never@2223 35 #include "oops/oop.inline.hpp"
never@2223 36 #include "oops/symbol.hpp"
never@2223 37 #include "runtime/handles.inline.hpp"
jprovino@4107 38 #include "utilities/macros.hpp"
jprovino@4107 39 #if INCLUDE_ALL_GCS
coleenp@3602 40 #include "gc_implementation/concurrentMarkSweep/cmsOopClosures.inline.hpp"
never@2223 41 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
never@2223 42 #include "gc_implementation/g1/g1OopClosures.inline.hpp"
never@2223 43 #include "gc_implementation/g1/g1RemSet.inline.hpp"
never@2223 44 #include "gc_implementation/g1/heapRegionSeq.inline.hpp"
never@2223 45 #include "gc_implementation/parNew/parOopClosures.inline.hpp"
never@2223 46 #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp"
never@2223 47 #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp"
never@2223 48 #include "oops/oop.pcgc.inline.hpp"
jprovino@4107 49 #endif // INCLUDE_ALL_GCS
never@2223 50
coleenp@3612 51 int InstanceMirrorKlass::_offset_of_static_fields = 0;
never@2223 52
never@2223 53 #ifdef ASSERT
never@2223 54 template <class T> void assert_is_in(T *p) {
never@2223 55 T heap_oop = oopDesc::load_heap_oop(p);
never@2223 56 if (!oopDesc::is_null(heap_oop)) {
never@2223 57 oop o = oopDesc::decode_heap_oop_not_null(heap_oop);
never@2223 58 assert(Universe::heap()->is_in(o), "should be in heap");
never@2223 59 }
never@2223 60 }
never@2223 61 template <class T> void assert_is_in_closed_subset(T *p) {
never@2223 62 T heap_oop = oopDesc::load_heap_oop(p);
never@2223 63 if (!oopDesc::is_null(heap_oop)) {
never@2223 64 oop o = oopDesc::decode_heap_oop_not_null(heap_oop);
never@2223 65 assert(Universe::heap()->is_in_closed_subset(o), "should be in closed");
never@2223 66 }
never@2223 67 }
never@2223 68 template <class T> void assert_is_in_reserved(T *p) {
never@2223 69 T heap_oop = oopDesc::load_heap_oop(p);
never@2223 70 if (!oopDesc::is_null(heap_oop)) {
never@2223 71 oop o = oopDesc::decode_heap_oop_not_null(heap_oop);
never@2223 72 assert(Universe::heap()->is_in_reserved(o), "should be in reserved");
never@2223 73 }
never@2223 74 }
never@2223 75 template <class T> void assert_nothing(T *p) {}
never@2223 76
never@2223 77 #else
never@2223 78 template <class T> void assert_is_in(T *p) {}
never@2223 79 template <class T> void assert_is_in_closed_subset(T *p) {}
never@2223 80 template <class T> void assert_is_in_reserved(T *p) {}
never@2223 81 template <class T> void assert_nothing(T *p) {}
never@2223 82 #endif // ASSERT
never@2223 83
never@2223 84 #define InstanceMirrorKlass_SPECIALIZED_OOP_ITERATE( \
never@2223 85 T, start_p, count, do_oop, \
never@2223 86 assert_fn) \
never@2223 87 { \
never@2223 88 T* p = (T*)(start_p); \
never@2223 89 T* const end = p + (count); \
never@2223 90 while (p < end) { \
never@2223 91 (assert_fn)(p); \
never@2223 92 do_oop; \
never@2223 93 ++p; \
never@2223 94 } \
never@2223 95 }
never@2223 96
never@2223 97 #define InstanceMirrorKlass_SPECIALIZED_BOUNDED_OOP_ITERATE( \
never@2223 98 T, start_p, count, low, high, \
never@2223 99 do_oop, assert_fn) \
never@2223 100 { \
never@2223 101 T* const l = (T*)(low); \
never@2223 102 T* const h = (T*)(high); \
never@2223 103 assert(mask_bits((intptr_t)l, sizeof(T)-1) == 0 && \
never@2223 104 mask_bits((intptr_t)h, sizeof(T)-1) == 0, \
never@2223 105 "bounded region must be properly aligned"); \
never@2223 106 T* p = (T*)(start_p); \
never@2223 107 T* end = p + (count); \
never@2223 108 if (p < l) p = l; \
never@2223 109 if (end > h) end = h; \
never@2223 110 while (p < end) { \
never@2223 111 (assert_fn)(p); \
never@2223 112 do_oop; \
never@2223 113 ++p; \
never@2223 114 } \
never@2223 115 }
never@2223 116
never@2223 117
never@2223 118 #define InstanceMirrorKlass_OOP_ITERATE(start_p, count, \
never@2223 119 do_oop, assert_fn) \
never@2223 120 { \
never@2223 121 if (UseCompressedOops) { \
never@2223 122 InstanceMirrorKlass_SPECIALIZED_OOP_ITERATE(narrowOop, \
never@2223 123 start_p, count, \
never@2223 124 do_oop, assert_fn) \
never@2223 125 } else { \
never@2223 126 InstanceMirrorKlass_SPECIALIZED_OOP_ITERATE(oop, \
never@2223 127 start_p, count, \
never@2223 128 do_oop, assert_fn) \
never@2223 129 } \
never@2223 130 }
never@2223 131
never@2223 132 // The following macros call specialized macros, passing either oop or
never@2223 133 // narrowOop as the specialization type. These test the UseCompressedOops
never@2223 134 // flag.
never@2223 135 #define InstanceMirrorKlass_BOUNDED_OOP_ITERATE(start_p, count, low, high, \
never@2223 136 do_oop, assert_fn) \
never@2223 137 { \
never@2223 138 if (UseCompressedOops) { \
never@2223 139 InstanceMirrorKlass_SPECIALIZED_BOUNDED_OOP_ITERATE(narrowOop, \
never@2223 140 start_p, count, \
never@2223 141 low, high, \
never@2223 142 do_oop, assert_fn) \
never@2223 143 } else { \
never@2223 144 InstanceMirrorKlass_SPECIALIZED_BOUNDED_OOP_ITERATE(oop, \
never@2223 145 start_p, count, \
never@2223 146 low, high, \
never@2223 147 do_oop, assert_fn) \
never@2223 148 } \
never@2223 149 }
never@2223 150
never@2223 151
coleenp@3612 152 void InstanceMirrorKlass::oop_follow_contents(oop obj) {
coleenp@3602 153 InstanceKlass::oop_follow_contents(obj);
coleenp@3602 154
coleenp@3602 155 // Follow the klass field in the mirror.
coleenp@3602 156 Klass* klass = java_lang_Class::as_Klass(obj);
coleenp@3602 157 if (klass != NULL) {
coleenp@3602 158 MarkSweep::follow_klass(klass);
coleenp@3602 159 } else {
coleenp@3602 160 // If klass is NULL then this a mirror for a primitive type.
coleenp@3602 161 // We don't have to follow them, since they are handled as strong
coleenp@3602 162 // roots in Universe::oops_do.
coleenp@3602 163 assert(java_lang_Class::is_primitive(obj), "Sanity check");
coleenp@3602 164 }
coleenp@3602 165
never@2223 166 InstanceMirrorKlass_OOP_ITERATE( \
never@2223 167 start_of_static_fields(obj), java_lang_Class::static_oop_field_count(obj), \
never@2223 168 MarkSweep::mark_and_push(p), \
never@2223 169 assert_is_in_closed_subset)
never@2223 170 }
never@2223 171
jprovino@4107 172 #if INCLUDE_ALL_GCS
coleenp@3612 173 void InstanceMirrorKlass::oop_follow_contents(ParCompactionManager* cm,
never@2223 174 oop obj) {
coleenp@3602 175 InstanceKlass::oop_follow_contents(cm, obj);
coleenp@3602 176
coleenp@3602 177 // Follow the klass field in the mirror.
coleenp@3602 178 Klass* klass = java_lang_Class::as_Klass(obj);
coleenp@3602 179 if (klass != NULL) {
coleenp@3602 180 PSParallelCompact::follow_klass(cm, klass);
coleenp@3602 181 } else {
coleenp@3602 182 // If klass is NULL then this a mirror for a primitive type.
coleenp@3602 183 // We don't have to follow them, since they are handled as strong
coleenp@3602 184 // roots in Universe::oops_do.
coleenp@3602 185 assert(java_lang_Class::is_primitive(obj), "Sanity check");
coleenp@3602 186 }
coleenp@3602 187
never@2223 188 InstanceMirrorKlass_OOP_ITERATE( \
never@2223 189 start_of_static_fields(obj), java_lang_Class::static_oop_field_count(obj), \
never@2223 190 PSParallelCompact::mark_and_push(cm, p), \
never@2223 191 assert_is_in)
never@2223 192 }
jprovino@4107 193 #endif // INCLUDE_ALL_GCS
never@2223 194
coleenp@3612 195 int InstanceMirrorKlass::oop_adjust_pointers(oop obj) {
never@2223 196 int size = oop_size(obj);
coleenp@3602 197 InstanceKlass::oop_adjust_pointers(obj);
coleenp@3602 198
coleenp@3602 199 // Follow the klass field in the mirror.
coleenp@3602 200 Klass* klass = java_lang_Class::as_Klass(obj);
coleenp@3602 201 if (klass != NULL) {
coleenp@3602 202 MarkSweep::adjust_klass(klass);
coleenp@3602 203 } else {
coleenp@3602 204 // If klass is NULL then this a mirror for a primitive type.
coleenp@3602 205 // We don't have to follow them, since they are handled as strong
coleenp@3602 206 // roots in Universe::oops_do.
coleenp@3602 207 assert(java_lang_Class::is_primitive(obj), "Sanity check");
coleenp@3602 208 }
coleenp@3602 209
never@2223 210 InstanceMirrorKlass_OOP_ITERATE( \
never@2223 211 start_of_static_fields(obj), java_lang_Class::static_oop_field_count(obj), \
never@2223 212 MarkSweep::adjust_pointer(p), \
never@2223 213 assert_nothing)
never@2223 214 return size;
never@2223 215 }
never@2223 216
never@2223 217 #define InstanceMirrorKlass_SPECIALIZED_OOP_ITERATE_DEFN(T, nv_suffix) \
never@2223 218 InstanceMirrorKlass_OOP_ITERATE( \
never@2223 219 start_of_static_fields(obj), java_lang_Class::static_oop_field_count(obj), \
never@2223 220 (closure)->do_oop##nv_suffix(p), \
never@2223 221 assert_is_in_closed_subset) \
never@2223 222 return oop_size(obj); \
never@2223 223
never@2223 224 #define InstanceMirrorKlass_BOUNDED_SPECIALIZED_OOP_ITERATE(T, nv_suffix, mr) \
never@2223 225 InstanceMirrorKlass_BOUNDED_OOP_ITERATE( \
never@2223 226 start_of_static_fields(obj), java_lang_Class::static_oop_field_count(obj), \
never@2223 227 mr.start(), mr.end(), \
never@2223 228 (closure)->do_oop##nv_suffix(p), \
never@2223 229 assert_is_in_closed_subset) \
never@2223 230 return oop_size(obj); \
never@2223 231
never@2223 232
coleenp@3602 233 #define if_do_metadata_checked(closure, nv_suffix) \
coleenp@3602 234 /* Make sure the non-virtual and the virtual versions match. */ \
coleenp@3602 235 assert(closure->do_metadata##nv_suffix() == closure->do_metadata(), \
coleenp@3602 236 "Inconsistency in do_metadata"); \
coleenp@3602 237 if (closure->do_metadata##nv_suffix())
coleenp@3602 238
coleenp@3612 239 // Macro to define InstanceMirrorKlass::oop_oop_iterate for virtual/nonvirtual for
never@2223 240 // all closures. Macros calling macros above for each oop size.
never@2223 241
never@2223 242 #define InstanceMirrorKlass_OOP_OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \
never@2223 243 \
coleenp@3612 244 int InstanceMirrorKlass:: \
never@2223 245 oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure) { \
never@2223 246 /* Get size before changing pointers */ \
never@2223 247 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::irk); \
never@2223 248 \
coleenp@3602 249 InstanceKlass::oop_oop_iterate##nv_suffix(obj, closure); \
coleenp@3602 250 \
coleenp@3602 251 if_do_metadata_checked(closure, nv_suffix) { \
coleenp@3602 252 Klass* klass = java_lang_Class::as_Klass(obj); \
coleenp@3602 253 /* We'll get NULL for primitive mirrors. */ \
coleenp@3602 254 if (klass != NULL) { \
coleenp@3602 255 closure->do_klass##nv_suffix(klass); \
coleenp@3602 256 } \
coleenp@3602 257 } \
never@2223 258 \
never@2223 259 if (UseCompressedOops) { \
never@2223 260 InstanceMirrorKlass_SPECIALIZED_OOP_ITERATE_DEFN(narrowOop, nv_suffix); \
never@2223 261 } else { \
never@2223 262 InstanceMirrorKlass_SPECIALIZED_OOP_ITERATE_DEFN(oop, nv_suffix); \
never@2223 263 } \
never@2223 264 }
never@2223 265
jprovino@4107 266 #if INCLUDE_ALL_GCS
never@2223 267 #define InstanceMirrorKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN(OopClosureType, nv_suffix) \
never@2223 268 \
coleenp@3612 269 int InstanceMirrorKlass:: \
never@2223 270 oop_oop_iterate_backwards##nv_suffix(oop obj, OopClosureType* closure) { \
never@2223 271 /* Get size before changing pointers */ \
never@2223 272 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::irk); \
never@2223 273 \
coleenp@3602 274 InstanceKlass::oop_oop_iterate_backwards##nv_suffix(obj, closure); \
never@2223 275 \
never@2223 276 if (UseCompressedOops) { \
never@2223 277 InstanceMirrorKlass_SPECIALIZED_OOP_ITERATE_DEFN(narrowOop, nv_suffix); \
never@2223 278 } else { \
never@2223 279 InstanceMirrorKlass_SPECIALIZED_OOP_ITERATE_DEFN(oop, nv_suffix); \
never@2223 280 } \
never@2223 281 }
jprovino@4107 282 #endif // INCLUDE_ALL_GCS
never@2223 283
never@2223 284
never@2223 285 #define InstanceMirrorKlass_OOP_OOP_ITERATE_DEFN_m(OopClosureType, nv_suffix) \
never@2223 286 \
coleenp@3612 287 int InstanceMirrorKlass:: \
never@2223 288 oop_oop_iterate##nv_suffix##_m(oop obj, \
never@2223 289 OopClosureType* closure, \
never@2223 290 MemRegion mr) { \
never@2223 291 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::irk); \
never@2223 292 \
coleenp@3602 293 InstanceKlass::oop_oop_iterate##nv_suffix##_m(obj, closure, mr); \
coleenp@3602 294 \
coleenp@3602 295 if_do_metadata_checked(closure, nv_suffix) { \
coleenp@3602 296 if (mr.contains(obj)) { \
coleenp@3602 297 Klass* klass = java_lang_Class::as_Klass(obj); \
coleenp@3602 298 /* We'll get NULL for primitive mirrors. */ \
coleenp@3602 299 if (klass != NULL) { \
coleenp@3602 300 closure->do_klass##nv_suffix(klass); \
coleenp@3602 301 } \
coleenp@3602 302 } \
coleenp@3602 303 } \
coleenp@3602 304 \
never@2223 305 if (UseCompressedOops) { \
never@2223 306 InstanceMirrorKlass_BOUNDED_SPECIALIZED_OOP_ITERATE(narrowOop, nv_suffix, mr); \
never@2223 307 } else { \
never@2223 308 InstanceMirrorKlass_BOUNDED_SPECIALIZED_OOP_ITERATE(oop, nv_suffix, mr); \
never@2223 309 } \
never@2223 310 }
never@2223 311
never@2223 312 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceMirrorKlass_OOP_OOP_ITERATE_DEFN)
never@2223 313 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceMirrorKlass_OOP_OOP_ITERATE_DEFN)
jprovino@4107 314 #if INCLUDE_ALL_GCS
never@2223 315 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceMirrorKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN)
never@2223 316 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceMirrorKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN)
jprovino@4107 317 #endif // INCLUDE_ALL_GCS
never@2223 318 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceMirrorKlass_OOP_OOP_ITERATE_DEFN_m)
never@2223 319 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceMirrorKlass_OOP_OOP_ITERATE_DEFN_m)
never@2223 320
jprovino@4107 321 #if INCLUDE_ALL_GCS
coleenp@3612 322 void InstanceMirrorKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
coleenp@3602 323 // Note that we don't have to follow the mirror -> klass pointer, since all
coleenp@3602 324 // klasses that are dirty will be scavenged when we iterate over the
coleenp@3602 325 // ClassLoaderData objects.
coleenp@3602 326
coleenp@3602 327 InstanceKlass::oop_push_contents(pm, obj);
never@2223 328 InstanceMirrorKlass_OOP_ITERATE( \
never@2223 329 start_of_static_fields(obj), java_lang_Class::static_oop_field_count(obj),\
never@2223 330 if (PSScavenge::should_scavenge(p)) { \
never@2223 331 pm->claim_or_forward_depth(p); \
never@2223 332 }, \
never@2223 333 assert_nothing )
never@2223 334 }
never@2223 335
coleenp@3612 336 int InstanceMirrorKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
coleenp@3602 337 int size = oop_size(obj);
coleenp@3602 338 InstanceKlass::oop_update_pointers(cm, obj);
coleenp@3602 339
coleenp@3602 340 // Follow the klass field in the mirror.
coleenp@3602 341 Klass* klass = java_lang_Class::as_Klass(obj);
coleenp@3602 342 if (klass != NULL) {
coleenp@3602 343 PSParallelCompact::adjust_klass(cm, klass);
coleenp@3602 344 } else {
coleenp@3602 345 // If klass is NULL then this a mirror for a primitive type.
coleenp@3602 346 // We don't have to follow them, since they are handled as strong
coleenp@3602 347 // roots in Universe::oops_do.
coleenp@3602 348 assert(java_lang_Class::is_primitive(obj), "Sanity check");
coleenp@3602 349 }
coleenp@3602 350
never@2223 351 InstanceMirrorKlass_OOP_ITERATE( \
never@2223 352 start_of_static_fields(obj), java_lang_Class::static_oop_field_count(obj),\
never@2223 353 PSParallelCompact::adjust_pointer(p), \
never@2223 354 assert_nothing)
coleenp@3602 355 return size;
never@2223 356 }
jprovino@4107 357 #endif // INCLUDE_ALL_GCS
never@2223 358
coleenp@3612 359 int InstanceMirrorKlass::instance_size(KlassHandle k) {
never@2223 360 if (k() != NULL && k->oop_is_instance()) {
coleenp@3602 361 return align_object_size(size_helper() + InstanceKlass::cast(k())->static_field_size());
never@2223 362 }
never@2223 363 return size_helper();
never@2223 364 }
never@2223 365
coleenp@3612 366 instanceOop InstanceMirrorKlass::allocate_instance(KlassHandle k, TRAPS) {
never@2223 367 // Query before forming handle.
never@2223 368 int size = instance_size(k);
coleenp@3602 369 KlassHandle h_k(THREAD, this);
never@2770 370 instanceOop i = (instanceOop) CollectedHeap::Class_obj_allocate(h_k, size, k, CHECK_NULL);
never@2223 371 return i;
never@2223 372 }
never@2223 373
coleenp@3612 374 int InstanceMirrorKlass::oop_size(oop obj) const {
never@2223 375 return java_lang_Class::oop_size(obj);
never@2223 376 }
never@2223 377
coleenp@3612 378 int InstanceMirrorKlass::compute_static_oop_field_count(oop obj) {
coleenp@3602 379 Klass* k = java_lang_Class::as_Klass(obj);
coleenp@3602 380 if (k != NULL && k->oop_is_instance()) {
coleenp@3602 381 return InstanceKlass::cast(k)->static_oop_field_count();
never@2223 382 }
never@2223 383 return 0;
never@2223 384 }