Mon, 07 Feb 2011 22:19:57 -0800
6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
Summary: Fix block_size_if_printezis_bits() so it does not expect the bits, only uses them when available. Fix block_size_no_stall() so it does not stall when the bits are missing such cases, letting the caller deal with zero size returns. Constant pool cache oops do not need to be unparsable or conc_unsafe after their klass pointer is installed. Some cosmetic clean-ups and some assertion checking for conc-usafety which, in the presence of class file redefinition, has no a-priori time boundedness, so all GCs must be able to safely deal with putatively conc-unsafe objects in a stop-world pause.
Reviewed-by: jmasa, johnc
1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 #include "precompiled.hpp"
26 #include "classfile/javaClasses.hpp"
27 #include "gc_implementation/shared/markSweep.inline.hpp"
28 #include "gc_interface/collectedHeap.inline.hpp"
29 #include "memory/oopFactory.hpp"
30 #include "memory/permGen.hpp"
31 #include "memory/universe.inline.hpp"
32 #include "oops/constantPoolKlass.hpp"
33 #include "oops/constantPoolOop.hpp"
34 #include "oops/oop.inline.hpp"
35 #include "oops/oop.inline2.hpp"
36 #include "oops/symbol.hpp"
37 #include "runtime/handles.inline.hpp"
38 #ifdef TARGET_OS_FAMILY_linux
39 # include "thread_linux.inline.hpp"
40 #endif
41 #ifdef TARGET_OS_FAMILY_solaris
42 # include "thread_solaris.inline.hpp"
43 #endif
44 #ifdef TARGET_OS_FAMILY_windows
45 # include "thread_windows.inline.hpp"
46 #endif
47 #ifndef SERIALGC
48 #include "gc_implementation/parNew/parOopClosures.inline.hpp"
49 #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp"
50 #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp"
51 #include "memory/cardTableRS.hpp"
52 #include "oops/oop.pcgc.inline.hpp"
53 #endif
55 constantPoolOop constantPoolKlass::allocate(int length, bool is_conc_safe, TRAPS) {
56 int size = constantPoolOopDesc::object_size(length);
57 KlassHandle klass (THREAD, as_klassOop());
58 constantPoolOop c =
59 (constantPoolOop)CollectedHeap::permanent_obj_allocate(klass, size, CHECK_NULL);
61 c->set_length(length);
62 c->set_tags(NULL);
63 c->set_cache(NULL);
64 c->set_operands(NULL);
65 c->set_pool_holder(NULL);
66 c->set_flags(0);
67 // only set to non-zero if constant pool is merged by RedefineClasses
68 c->set_orig_length(0);
69 // if constant pool may change during RedefineClasses, it is created
70 // unsafe for GC concurrent processing.
71 c->set_is_conc_safe(is_conc_safe);
72 // all fields are initialized; needed for GC
74 // Note: because we may be in this "conc_unsafe" state when allocating
75 // t_oop below, which may in turn cause a GC, it is imperative that our
76 // size be correct, consistent and henceforth stable, at this stage.
77 assert(c->is_parsable(), "Else size() below is unreliable");
78 DEBUG_ONLY(int sz = c->size();)
80 // initialize tag array
81 // Note: cannot introduce constant pool handle before since it is not
82 // completely initialized (no class) -> would cause assertion failure
83 constantPoolHandle pool (THREAD, c);
84 typeArrayOop t_oop = oopFactory::new_permanent_byteArray(length, CHECK_NULL);
85 typeArrayHandle tags (THREAD, t_oop);
86 for (int index = 0; index < length; index++) {
87 tags()->byte_at_put(index, JVM_CONSTANT_Invalid);
88 }
89 pool->set_tags(tags());
91 // Check that our size was stable at its old value.
92 assert(sz == c->size(), "size() changed");
93 return pool();
94 }
96 klassOop constantPoolKlass::create_klass(TRAPS) {
97 constantPoolKlass o;
98 KlassHandle h_this_klass(THREAD, Universe::klassKlassObj());
99 KlassHandle k = base_create_klass(h_this_klass, header_size(), o.vtbl_value(), CHECK_NULL);
100 // Make sure size calculation is right
101 assert(k()->size() == align_object_size(header_size()), "wrong size for object");
102 java_lang_Class::create_mirror(k, CHECK_NULL); // Allocate mirror
103 return k();
104 }
106 int constantPoolKlass::oop_size(oop obj) const {
107 assert(obj->is_constantPool(), "must be constantPool");
108 return constantPoolOop(obj)->object_size();
109 }
112 void constantPoolKlass::oop_follow_contents(oop obj) {
113 assert (obj->is_constantPool(), "obj must be constant pool");
114 constantPoolOop cp = (constantPoolOop) obj;
115 // Performance tweak: We skip iterating over the klass pointer since we
116 // know that Universe::constantPoolKlassObj never moves.
118 // If the tags array is null we are in the middle of allocating this constant pool
119 if (cp->tags() != NULL) {
120 // gc of constant pool contents
121 oop* base = (oop*)cp->base();
122 for (int i = 0; i < cp->length(); i++) {
123 if (cp->is_pointer_entry(i)) {
124 if (*base != NULL) MarkSweep::mark_and_push(base);
125 }
126 base++;
127 }
128 // gc of constant pool instance variables
129 MarkSweep::mark_and_push(cp->tags_addr());
130 MarkSweep::mark_and_push(cp->cache_addr());
131 MarkSweep::mark_and_push(cp->operands_addr());
132 MarkSweep::mark_and_push(cp->pool_holder_addr());
133 }
134 }
136 #ifndef SERIALGC
137 void constantPoolKlass::oop_follow_contents(ParCompactionManager* cm,
138 oop obj) {
139 assert (obj->is_constantPool(), "obj must be constant pool");
140 constantPoolOop cp = (constantPoolOop) obj;
141 // Performance tweak: We skip iterating over the klass pointer since we
142 // know that Universe::constantPoolKlassObj never moves.
144 // If the tags array is null we are in the middle of allocating this constant
145 // pool.
146 if (cp->tags() != NULL) {
147 // gc of constant pool contents
148 oop* base = (oop*)cp->base();
149 for (int i = 0; i < cp->length(); i++) {
150 if (cp->is_pointer_entry(i)) {
151 if (*base != NULL) PSParallelCompact::mark_and_push(cm, base);
152 }
153 base++;
154 }
155 // gc of constant pool instance variables
156 PSParallelCompact::mark_and_push(cm, cp->tags_addr());
157 PSParallelCompact::mark_and_push(cm, cp->cache_addr());
158 PSParallelCompact::mark_and_push(cm, cp->operands_addr());
159 PSParallelCompact::mark_and_push(cm, cp->pool_holder_addr());
160 }
161 }
162 #endif // SERIALGC
165 int constantPoolKlass::oop_adjust_pointers(oop obj) {
166 assert (obj->is_constantPool(), "obj must be constant pool");
167 constantPoolOop cp = (constantPoolOop) obj;
168 // Get size before changing pointers.
169 // Don't call size() or oop_size() since that is a virtual call.
170 int size = cp->object_size();
171 // Performance tweak: We skip iterating over the klass pointer since we
172 // know that Universe::constantPoolKlassObj never moves.
174 // If the tags array is null we are in the middle of allocating this constant
175 // pool.
176 if (cp->tags() != NULL) {
177 oop* base = (oop*)cp->base();
178 for (int i = 0; i< cp->length(); i++) {
179 if (cp->is_pointer_entry(i)) {
180 MarkSweep::adjust_pointer(base);
181 }
182 base++;
183 }
184 }
185 MarkSweep::adjust_pointer(cp->tags_addr());
186 MarkSweep::adjust_pointer(cp->cache_addr());
187 MarkSweep::adjust_pointer(cp->operands_addr());
188 MarkSweep::adjust_pointer(cp->pool_holder_addr());
189 return size;
190 }
193 int constantPoolKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
194 assert (obj->is_constantPool(), "obj must be constant pool");
195 // Performance tweak: We skip iterating over the klass pointer since we
196 // know that Universe::constantPoolKlassObj never moves.
197 constantPoolOop cp = (constantPoolOop) obj;
198 // Get size before changing pointers.
199 // Don't call size() or oop_size() since that is a virtual call.
200 int size = cp->object_size();
202 // If the tags array is null we are in the middle of allocating this constant
203 // pool.
204 if (cp->tags() != NULL) {
205 oop* base = (oop*)cp->base();
206 for (int i = 0; i < cp->length(); i++) {
207 if (cp->is_pointer_entry(i)) {
208 blk->do_oop(base);
209 }
210 base++;
211 }
212 }
213 blk->do_oop(cp->tags_addr());
214 blk->do_oop(cp->cache_addr());
215 blk->do_oop(cp->operands_addr());
216 blk->do_oop(cp->pool_holder_addr());
217 return size;
218 }
221 int constantPoolKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
222 assert (obj->is_constantPool(), "obj must be constant pool");
223 // Performance tweak: We skip iterating over the klass pointer since we
224 // know that Universe::constantPoolKlassObj never moves.
225 constantPoolOop cp = (constantPoolOop) obj;
226 // Get size before changing pointers.
227 // Don't call size() or oop_size() since that is a virtual call.
228 int size = cp->object_size();
230 // If the tags array is null we are in the middle of allocating this constant
231 // pool.
232 if (cp->tags() != NULL) {
233 oop* base = (oop*)cp->base();
234 for (int i = 0; i < cp->length(); i++) {
235 if (mr.contains(base)) {
236 if (cp->is_pointer_entry(i)) {
237 blk->do_oop(base);
238 }
239 }
240 base++;
241 }
242 }
243 oop* addr;
244 addr = cp->tags_addr();
245 blk->do_oop(addr);
246 addr = cp->cache_addr();
247 blk->do_oop(addr);
248 addr = cp->operands_addr();
249 blk->do_oop(addr);
250 addr = cp->pool_holder_addr();
251 blk->do_oop(addr);
252 return size;
253 }
255 bool constantPoolKlass::oop_is_conc_safe(oop obj) const {
256 assert(obj->is_constantPool(), "must be constantPool");
257 return constantPoolOop(obj)->is_conc_safe();
258 }
260 #ifndef SERIALGC
261 int constantPoolKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
262 assert (obj->is_constantPool(), "obj must be constant pool");
263 constantPoolOop cp = (constantPoolOop) obj;
265 // If the tags array is null we are in the middle of allocating this constant
266 // pool.
267 if (cp->tags() != NULL) {
268 oop* base = (oop*)cp->base();
269 for (int i = 0; i < cp->length(); ++i, ++base) {
270 if (cp->is_pointer_entry(i)) {
271 PSParallelCompact::adjust_pointer(base);
272 }
273 }
274 }
275 PSParallelCompact::adjust_pointer(cp->tags_addr());
276 PSParallelCompact::adjust_pointer(cp->cache_addr());
277 PSParallelCompact::adjust_pointer(cp->operands_addr());
278 PSParallelCompact::adjust_pointer(cp->pool_holder_addr());
279 return cp->object_size();
280 }
282 int
283 constantPoolKlass::oop_update_pointers(ParCompactionManager* cm, oop obj,
284 HeapWord* beg_addr, HeapWord* end_addr) {
285 assert (obj->is_constantPool(), "obj must be constant pool");
286 constantPoolOop cp = (constantPoolOop) obj;
288 // If the tags array is null we are in the middle of allocating this constant
289 // pool.
290 if (cp->tags() != NULL) {
291 oop* base = (oop*)cp->base();
292 oop* const beg_oop = MAX2((oop*)beg_addr, base);
293 oop* const end_oop = MIN2((oop*)end_addr, base + cp->length());
294 const size_t beg_idx = pointer_delta(beg_oop, base, sizeof(oop*));
295 const size_t end_idx = pointer_delta(end_oop, base, sizeof(oop*));
296 for (size_t cur_idx = beg_idx; cur_idx < end_idx; ++cur_idx, ++base) {
297 if (cp->is_pointer_entry(int(cur_idx))) {
298 PSParallelCompact::adjust_pointer(base);
299 }
300 }
301 }
303 oop* p;
304 p = cp->tags_addr();
305 PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
306 p = cp->cache_addr();
307 PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
308 p = cp->operands_addr();
309 PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
310 p = cp->pool_holder_addr();
311 PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
313 return cp->object_size();
314 }
316 void constantPoolKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
317 assert(obj->is_constantPool(), "should be constant pool");
318 constantPoolOop cp = (constantPoolOop) obj;
319 if (AnonymousClasses && cp->has_pseudo_string() && cp->tags() != NULL) {
320 oop* base = (oop*)cp->base();
321 for (int i = 0; i < cp->length(); ++i, ++base) {
322 if (cp->tag_at(i).is_string()) {
323 if (PSScavenge::should_scavenge(base)) {
324 pm->claim_or_forward_depth(base);
325 }
326 }
327 }
328 }
329 }
330 #endif // SERIALGC
332 // Printing
334 void constantPoolKlass::oop_print_on(oop obj, outputStream* st) {
335 EXCEPTION_MARK;
336 oop anObj;
337 assert(obj->is_constantPool(), "must be constantPool");
338 Klass::oop_print_on(obj, st);
339 constantPoolOop cp = constantPoolOop(obj);
340 if (cp->flags() != 0) {
341 st->print(" - flags: 0x%x", cp->flags());
342 if (cp->has_pseudo_string()) st->print(" has_pseudo_string");
343 if (cp->has_invokedynamic()) st->print(" has_invokedynamic");
344 st->cr();
345 }
346 st->print_cr(" - cache: " INTPTR_FORMAT, cp->cache());
348 for (int index = 1; index < cp->length(); index++) { // Index 0 is unused
349 st->print(" - %3d : ", index);
350 cp->tag_at(index).print_on(st);
351 st->print(" : ");
352 switch (cp->tag_at(index).value()) {
353 case JVM_CONSTANT_Class :
354 { anObj = cp->klass_at(index, CATCH);
355 anObj->print_value_on(st);
356 st->print(" {0x%lx}", (address)anObj);
357 }
358 break;
359 case JVM_CONSTANT_Fieldref :
360 case JVM_CONSTANT_Methodref :
361 case JVM_CONSTANT_InterfaceMethodref :
362 st->print("klass_index=%d", cp->uncached_klass_ref_index_at(index));
363 st->print(" name_and_type_index=%d", cp->uncached_name_and_type_ref_index_at(index));
364 break;
365 case JVM_CONSTANT_UnresolvedString :
366 case JVM_CONSTANT_String :
367 if (cp->is_pseudo_string_at(index)) {
368 anObj = cp->pseudo_string_at(index);
369 } else {
370 anObj = cp->string_at(index, CATCH);
371 }
372 anObj->print_value_on(st);
373 st->print(" {0x%lx}", (address)anObj);
374 break;
375 case JVM_CONSTANT_Integer :
376 st->print("%d", cp->int_at(index));
377 break;
378 case JVM_CONSTANT_Float :
379 st->print("%f", cp->float_at(index));
380 break;
381 case JVM_CONSTANT_Long :
382 st->print_jlong(cp->long_at(index));
383 index++; // Skip entry following eigth-byte constant
384 break;
385 case JVM_CONSTANT_Double :
386 st->print("%lf", cp->double_at(index));
387 index++; // Skip entry following eigth-byte constant
388 break;
389 case JVM_CONSTANT_NameAndType :
390 st->print("name_index=%d", cp->name_ref_index_at(index));
391 st->print(" signature_index=%d", cp->signature_ref_index_at(index));
392 break;
393 case JVM_CONSTANT_Utf8 :
394 cp->symbol_at(index)->print_value_on(st);
395 break;
396 case JVM_CONSTANT_UnresolvedClass : // fall-through
397 case JVM_CONSTANT_UnresolvedClassInError: {
398 // unresolved_klass_at requires lock or safe world.
399 CPSlot entry = cp->slot_at(index);
400 if (entry.is_oop()) {
401 entry.get_oop()->print_value_on(st);
402 } else {
403 entry.get_symbol()->print_value_on(st);
404 }
405 }
406 break;
407 case JVM_CONSTANT_MethodHandle :
408 st->print("ref_kind=%d", cp->method_handle_ref_kind_at(index));
409 st->print(" ref_index=%d", cp->method_handle_index_at(index));
410 break;
411 case JVM_CONSTANT_MethodType :
412 st->print("signature_index=%d", cp->method_type_index_at(index));
413 break;
414 case JVM_CONSTANT_InvokeDynamicTrans :
415 case JVM_CONSTANT_InvokeDynamic :
416 {
417 st->print("bootstrap_method_index=%d", cp->invoke_dynamic_bootstrap_method_ref_index_at(index));
418 st->print(" name_and_type_index=%d", cp->invoke_dynamic_name_and_type_ref_index_at(index));
419 int argc = cp->invoke_dynamic_argument_count_at(index);
420 if (argc > 0) {
421 for (int arg_i = 0; arg_i < argc; arg_i++) {
422 int arg = cp->invoke_dynamic_argument_index_at(index, arg_i);
423 st->print((arg_i == 0 ? " arguments={%d" : ", %d"), arg);
424 }
425 st->print("}");
426 }
427 }
428 break;
429 default:
430 ShouldNotReachHere();
431 break;
432 }
433 st->cr();
434 }
435 st->cr();
436 }
438 void constantPoolKlass::oop_print_value_on(oop obj, outputStream* st) {
439 assert(obj->is_constantPool(), "must be constantPool");
440 constantPoolOop cp = constantPoolOop(obj);
441 st->print("constant pool [%d]", cp->length());
442 if (cp->has_pseudo_string()) st->print("/pseudo_string");
443 if (cp->has_invokedynamic()) st->print("/invokedynamic");
444 if (cp->operands() != NULL) st->print("/operands[%d]", cp->operands()->length());
445 cp->print_address_on(st);
446 st->print(" for ");
447 cp->pool_holder()->print_value_on(st);
448 if (cp->cache() != NULL) {
449 st->print(" cache=" PTR_FORMAT, cp->cache());
450 }
451 }
453 const char* constantPoolKlass::internal_name() const {
454 return "{constant pool}";
455 }
457 // Verification
459 void constantPoolKlass::oop_verify_on(oop obj, outputStream* st) {
460 Klass::oop_verify_on(obj, st);
461 guarantee(obj->is_constantPool(), "object must be constant pool");
462 constantPoolOop cp = constantPoolOop(obj);
463 guarantee(cp->is_perm(), "should be in permspace");
464 if (!cp->partially_loaded()) {
465 for (int i = 0; i< cp->length(); i++) {
466 CPSlot entry = cp->slot_at(i);
467 if (cp->tag_at(i).is_klass()) {
468 if (entry.is_oop()) {
469 guarantee(entry.get_oop()->is_perm(), "should be in permspace");
470 guarantee(entry.get_oop()->is_klass(), "should be klass");
471 }
472 }
473 if (cp->tag_at(i).is_unresolved_klass()) {
474 if (entry.is_oop()) {
475 guarantee(entry.get_oop()->is_perm(), "should be in permspace");
476 guarantee(entry.get_oop()->is_klass(), "should be klass");
477 }
478 }
479 if (cp->tag_at(i).is_symbol()) {
480 guarantee(entry.get_symbol()->refcount() != 0, "should have nonzero reference count");
481 }
482 if (cp->tag_at(i).is_unresolved_string()) {
483 if (entry.is_oop()) {
484 guarantee(entry.get_oop()->is_perm(), "should be in permspace");
485 guarantee(entry.get_oop()->is_instance(), "should be instance");
486 }
487 else {
488 guarantee(entry.get_symbol()->refcount() != 0, "should have nonzero reference count");
489 }
490 }
491 if (cp->tag_at(i).is_string()) {
492 if (!cp->has_pseudo_string()) {
493 if (entry.is_oop()) {
494 guarantee(entry.get_oop()->is_perm(), "should be in permspace");
495 guarantee(entry.get_oop()->is_instance(), "should be instance");
496 }
497 } else {
498 // can be non-perm, can be non-instance (array)
499 }
500 }
501 // FIXME: verify JSR 292 tags JVM_CONSTANT_MethodHandle, etc.
502 }
503 guarantee(cp->tags()->is_perm(), "should be in permspace");
504 guarantee(cp->tags()->is_typeArray(), "should be type array");
505 if (cp->cache() != NULL) {
506 // Note: cache() can be NULL before a class is completely setup or
507 // in temporary constant pools used during constant pool merging
508 guarantee(cp->cache()->is_perm(), "should be in permspace");
509 guarantee(cp->cache()->is_constantPoolCache(), "should be constant pool cache");
510 }
511 if (cp->operands() != NULL) {
512 guarantee(cp->operands()->is_perm(), "should be in permspace");
513 guarantee(cp->operands()->is_typeArray(), "should be type array");
514 }
515 if (cp->pool_holder() != NULL) {
516 // Note: pool_holder() can be NULL in temporary constant pools
517 // used during constant pool merging
518 guarantee(cp->pool_holder()->is_perm(), "should be in permspace");
519 guarantee(cp->pool_holder()->is_klass(), "should be klass");
520 }
521 }
522 }
524 bool constantPoolKlass::oop_partially_loaded(oop obj) const {
525 assert(obj->is_constantPool(), "object must be constant pool");
526 constantPoolOop cp = constantPoolOop(obj);
527 return cp->tags() == NULL || cp->pool_holder() == (klassOop) cp; // Check whether pool holder points to self
528 }
531 void constantPoolKlass::oop_set_partially_loaded(oop obj) {
532 assert(obj->is_constantPool(), "object must be constant pool");
533 constantPoolOop cp = constantPoolOop(obj);
534 assert(cp->pool_holder() == NULL, "just checking");
535 cp->set_pool_holder((klassOop) cp); // Temporarily set pool holder to point to self
536 }
538 #ifndef PRODUCT
539 // CompileTheWorld support. Preload all classes loaded references in the passed in constantpool
540 void constantPoolKlass::preload_and_initialize_all_classes(oop obj, TRAPS) {
541 guarantee(obj->is_constantPool(), "object must be constant pool");
542 constantPoolHandle cp(THREAD, (constantPoolOop)obj);
543 guarantee(!cp->partially_loaded(), "must be fully loaded");
545 for (int i = 0; i< cp->length(); i++) {
546 if (cp->tag_at(i).is_unresolved_klass()) {
547 // This will force loading of the class
548 klassOop klass = cp->klass_at(i, CHECK);
549 if (klass->is_instance()) {
550 // Force initialization of class
551 instanceKlass::cast(klass)->initialize(CHECK);
552 }
553 }
554 }
555 }
557 #endif