src/share/vm/oops/constantPoolKlass.cpp

Thu, 13 Mar 2008 14:17:48 -0700

author
dcubed
date
Thu, 13 Mar 2008 14:17:48 -0700
changeset 487
75b0f3cb1943
parent 435
a61af66fc99e
child 548
ba764ed4b6f2
permissions
-rw-r--r--

Merge

duke@435 1 /*
duke@435 2 * Copyright 1997-2006 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 # include "incls/_precompiled.incl"
duke@435 26 # include "incls/_constantPoolKlass.cpp.incl"
duke@435 27
duke@435 28 constantPoolOop constantPoolKlass::allocate(int length, TRAPS) {
duke@435 29 int size = constantPoolOopDesc::object_size(length);
duke@435 30 KlassHandle klass (THREAD, as_klassOop());
duke@435 31 constantPoolOop c =
duke@435 32 (constantPoolOop)CollectedHeap::permanent_array_allocate(klass, size, length, CHECK_NULL);
duke@435 33
duke@435 34 c->set_tags(NULL);
duke@435 35 c->set_cache(NULL);
duke@435 36 c->set_pool_holder(NULL);
duke@435 37 // only set to non-zero if constant pool is merged by RedefineClasses
duke@435 38 c->set_orig_length(0);
duke@435 39 // all fields are initialized; needed for GC
duke@435 40
duke@435 41 // initialize tag array
duke@435 42 // Note: cannot introduce constant pool handle before since it is not
duke@435 43 // completely initialized (no class) -> would cause assertion failure
duke@435 44 constantPoolHandle pool (THREAD, c);
duke@435 45 typeArrayOop t_oop = oopFactory::new_permanent_byteArray(length, CHECK_NULL);
duke@435 46 typeArrayHandle tags (THREAD, t_oop);
duke@435 47 for (int index = 0; index < length; index++) {
duke@435 48 tags()->byte_at_put(index, JVM_CONSTANT_Invalid);
duke@435 49 }
duke@435 50 pool->set_tags(tags());
duke@435 51
duke@435 52 return pool();
duke@435 53 }
duke@435 54
duke@435 55 klassOop constantPoolKlass::create_klass(TRAPS) {
duke@435 56 constantPoolKlass o;
duke@435 57 KlassHandle klassklass(THREAD, Universe::arrayKlassKlassObj());
duke@435 58 arrayKlassHandle k = base_create_array_klass(o.vtbl_value(), header_size(), klassklass, CHECK_NULL);
duke@435 59 arrayKlassHandle super (THREAD, k->super());
duke@435 60 complete_create_array_klass(k, super, CHECK_NULL);
duke@435 61 return k();
duke@435 62 }
duke@435 63
duke@435 64
duke@435 65 int constantPoolKlass::oop_size(oop obj) const {
duke@435 66 assert(obj->is_constantPool(), "must be constantPool");
duke@435 67 return constantPoolOop(obj)->object_size();
duke@435 68 }
duke@435 69
duke@435 70
duke@435 71 void constantPoolKlass::oop_follow_contents(oop obj) {
duke@435 72 assert (obj->is_constantPool(), "obj must be constant pool");
duke@435 73 constantPoolOop cp = (constantPoolOop) obj;
duke@435 74 // Performance tweak: We skip iterating over the klass pointer since we
duke@435 75 // know that Universe::constantPoolKlassObj never moves.
duke@435 76
duke@435 77 // If the tags array is null we are in the middle of allocating this constant pool
duke@435 78 if (cp->tags() != NULL) {
duke@435 79 // gc of constant pool contents
duke@435 80 oop* base = (oop*)cp->base();
duke@435 81 for (int i = 0; i < cp->length(); i++) {
duke@435 82 if (cp->is_pointer_entry(i)) {
duke@435 83 if (*base != NULL) MarkSweep::mark_and_push(base);
duke@435 84 }
duke@435 85 base++;
duke@435 86 }
duke@435 87 // gc of constant pool instance variables
duke@435 88 MarkSweep::mark_and_push(cp->tags_addr());
duke@435 89 MarkSweep::mark_and_push(cp->cache_addr());
duke@435 90 MarkSweep::mark_and_push(cp->pool_holder_addr());
duke@435 91 }
duke@435 92 }
duke@435 93
duke@435 94 #ifndef SERIALGC
duke@435 95 void constantPoolKlass::oop_follow_contents(ParCompactionManager* cm,
duke@435 96 oop obj) {
duke@435 97 assert (obj->is_constantPool(), "obj must be constant pool");
duke@435 98 constantPoolOop cp = (constantPoolOop) obj;
duke@435 99 // Performance tweak: We skip iterating over the klass pointer since we
duke@435 100 // know that Universe::constantPoolKlassObj never moves.
duke@435 101
duke@435 102 // If the tags array is null we are in the middle of allocating this constant
duke@435 103 // pool.
duke@435 104 if (cp->tags() != NULL) {
duke@435 105 // gc of constant pool contents
duke@435 106 oop* base = (oop*)cp->base();
duke@435 107 for (int i = 0; i < cp->length(); i++) {
duke@435 108 if (cp->is_pointer_entry(i)) {
duke@435 109 if (*base != NULL) PSParallelCompact::mark_and_push(cm, base);
duke@435 110 }
duke@435 111 base++;
duke@435 112 }
duke@435 113 // gc of constant pool instance variables
duke@435 114 PSParallelCompact::mark_and_push(cm, cp->tags_addr());
duke@435 115 PSParallelCompact::mark_and_push(cm, cp->cache_addr());
duke@435 116 PSParallelCompact::mark_and_push(cm, cp->pool_holder_addr());
duke@435 117 }
duke@435 118 }
duke@435 119 #endif // SERIALGC
duke@435 120
duke@435 121
duke@435 122 int constantPoolKlass::oop_adjust_pointers(oop obj) {
duke@435 123 assert (obj->is_constantPool(), "obj must be constant pool");
duke@435 124 constantPoolOop cp = (constantPoolOop) obj;
duke@435 125 // Get size before changing pointers.
duke@435 126 // Don't call size() or oop_size() since that is a virtual call.
duke@435 127 int size = cp->object_size();
duke@435 128 // Performance tweak: We skip iterating over the klass pointer since we
duke@435 129 // know that Universe::constantPoolKlassObj never moves.
duke@435 130
duke@435 131 // If the tags array is null we are in the middle of allocating this constant
duke@435 132 // pool.
duke@435 133 if (cp->tags() != NULL) {
duke@435 134 oop* base = (oop*)cp->base();
duke@435 135 for (int i = 0; i< cp->length(); i++) {
duke@435 136 if (cp->is_pointer_entry(i)) {
duke@435 137 MarkSweep::adjust_pointer(base);
duke@435 138 }
duke@435 139 base++;
duke@435 140 }
duke@435 141 }
duke@435 142 MarkSweep::adjust_pointer(cp->tags_addr());
duke@435 143 MarkSweep::adjust_pointer(cp->cache_addr());
duke@435 144 MarkSweep::adjust_pointer(cp->pool_holder_addr());
duke@435 145 return size;
duke@435 146 }
duke@435 147
duke@435 148
duke@435 149 int constantPoolKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
duke@435 150 assert (obj->is_constantPool(), "obj must be constant pool");
duke@435 151 // Performance tweak: We skip iterating over the klass pointer since we
duke@435 152 // know that Universe::constantPoolKlassObj never moves.
duke@435 153 constantPoolOop cp = (constantPoolOop) obj;
duke@435 154 // Get size before changing pointers.
duke@435 155 // Don't call size() or oop_size() since that is a virtual call.
duke@435 156 int size = cp->object_size();
duke@435 157
duke@435 158 // If the tags array is null we are in the middle of allocating this constant
duke@435 159 // pool.
duke@435 160 if (cp->tags() != NULL) {
duke@435 161 oop* base = (oop*)cp->base();
duke@435 162 for (int i = 0; i < cp->length(); i++) {
duke@435 163 if (cp->is_pointer_entry(i)) {
duke@435 164 blk->do_oop(base);
duke@435 165 }
duke@435 166 base++;
duke@435 167 }
duke@435 168 }
duke@435 169 blk->do_oop(cp->tags_addr());
duke@435 170 blk->do_oop(cp->cache_addr());
duke@435 171 blk->do_oop(cp->pool_holder_addr());
duke@435 172 return size;
duke@435 173 }
duke@435 174
duke@435 175
duke@435 176 int constantPoolKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
duke@435 177 assert (obj->is_constantPool(), "obj must be constant pool");
duke@435 178 // Performance tweak: We skip iterating over the klass pointer since we
duke@435 179 // know that Universe::constantPoolKlassObj never moves.
duke@435 180 constantPoolOop cp = (constantPoolOop) obj;
duke@435 181 // Get size before changing pointers.
duke@435 182 // Don't call size() or oop_size() since that is a virtual call.
duke@435 183 int size = cp->object_size();
duke@435 184
duke@435 185 // If the tags array is null we are in the middle of allocating this constant
duke@435 186 // pool.
duke@435 187 if (cp->tags() != NULL) {
duke@435 188 oop* base = (oop*)cp->base();
duke@435 189 for (int i = 0; i < cp->length(); i++) {
duke@435 190 if (mr.contains(base)) {
duke@435 191 if (cp->is_pointer_entry(i)) {
duke@435 192 blk->do_oop(base);
duke@435 193 }
duke@435 194 }
duke@435 195 base++;
duke@435 196 }
duke@435 197 }
duke@435 198 oop* addr;
duke@435 199 addr = cp->tags_addr();
duke@435 200 blk->do_oop(addr);
duke@435 201 addr = cp->cache_addr();
duke@435 202 blk->do_oop(addr);
duke@435 203 addr = cp->pool_holder_addr();
duke@435 204 blk->do_oop(addr);
duke@435 205 return size;
duke@435 206 }
duke@435 207
duke@435 208 #ifndef SERIALGC
duke@435 209 int constantPoolKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
duke@435 210 assert (obj->is_constantPool(), "obj must be constant pool");
duke@435 211 constantPoolOop cp = (constantPoolOop) obj;
duke@435 212
duke@435 213 // If the tags array is null we are in the middle of allocating this constant
duke@435 214 // pool.
duke@435 215 if (cp->tags() != NULL) {
duke@435 216 oop* base = (oop*)cp->base();
duke@435 217 for (int i = 0; i < cp->length(); ++i, ++base) {
duke@435 218 if (cp->is_pointer_entry(i)) {
duke@435 219 PSParallelCompact::adjust_pointer(base);
duke@435 220 }
duke@435 221 }
duke@435 222 }
duke@435 223 PSParallelCompact::adjust_pointer(cp->tags_addr());
duke@435 224 PSParallelCompact::adjust_pointer(cp->cache_addr());
duke@435 225 PSParallelCompact::adjust_pointer(cp->pool_holder_addr());
duke@435 226 return cp->object_size();
duke@435 227 }
duke@435 228
duke@435 229 int
duke@435 230 constantPoolKlass::oop_update_pointers(ParCompactionManager* cm, oop obj,
duke@435 231 HeapWord* beg_addr, HeapWord* end_addr) {
duke@435 232 assert (obj->is_constantPool(), "obj must be constant pool");
duke@435 233 constantPoolOop cp = (constantPoolOop) obj;
duke@435 234
duke@435 235 // If the tags array is null we are in the middle of allocating this constant
duke@435 236 // pool.
duke@435 237 if (cp->tags() != NULL) {
duke@435 238 oop* base = (oop*)cp->base();
duke@435 239 oop* const beg_oop = MAX2((oop*)beg_addr, base);
duke@435 240 oop* const end_oop = MIN2((oop*)end_addr, base + cp->length());
duke@435 241 const size_t beg_idx = pointer_delta(beg_oop, base, sizeof(oop*));
duke@435 242 const size_t end_idx = pointer_delta(end_oop, base, sizeof(oop*));
duke@435 243 for (size_t cur_idx = beg_idx; cur_idx < end_idx; ++cur_idx, ++base) {
duke@435 244 if (cp->is_pointer_entry(int(cur_idx))) {
duke@435 245 PSParallelCompact::adjust_pointer(base);
duke@435 246 }
duke@435 247 }
duke@435 248 }
duke@435 249
duke@435 250 oop* p;
duke@435 251 p = cp->tags_addr();
duke@435 252 PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
duke@435 253 p = cp->cache_addr();
duke@435 254 PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
duke@435 255 p = cp->pool_holder_addr();
duke@435 256 PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
duke@435 257
duke@435 258 return cp->object_size();
duke@435 259 }
duke@435 260
duke@435 261 void constantPoolKlass::oop_copy_contents(PSPromotionManager* pm, oop obj) {
duke@435 262 assert(obj->is_constantPool(), "should be constant pool");
duke@435 263 }
duke@435 264
duke@435 265 void constantPoolKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
duke@435 266 assert(obj->is_constantPool(), "should be constant pool");
duke@435 267 }
duke@435 268 #endif // SERIALGC
duke@435 269
duke@435 270 #ifndef PRODUCT
duke@435 271
duke@435 272 // Printing
duke@435 273
duke@435 274 void constantPoolKlass::oop_print_on(oop obj, outputStream* st) {
duke@435 275 EXCEPTION_MARK;
duke@435 276 oop anObj;
duke@435 277 assert(obj->is_constantPool(), "must be constantPool");
duke@435 278 arrayKlass::oop_print_on(obj, st);
duke@435 279 constantPoolOop cp = constantPoolOop(obj);
duke@435 280
duke@435 281 // Temp. remove cache so we can do lookups with original indicies.
duke@435 282 constantPoolCacheHandle cache (THREAD, cp->cache());
duke@435 283 cp->set_cache(NULL);
duke@435 284
duke@435 285 for (int index = 1; index < cp->length(); index++) { // Index 0 is unused
duke@435 286 st->print(" - %3d : ", index);
duke@435 287 cp->tag_at(index).print_on(st);
duke@435 288 st->print(" : ");
duke@435 289 switch (cp->tag_at(index).value()) {
duke@435 290 case JVM_CONSTANT_Class :
duke@435 291 { anObj = cp->klass_at(index, CATCH);
duke@435 292 anObj->print_value_on(st);
duke@435 293 st->print(" {0x%lx}", (address)anObj);
duke@435 294 }
duke@435 295 break;
duke@435 296 case JVM_CONSTANT_Fieldref :
duke@435 297 case JVM_CONSTANT_Methodref :
duke@435 298 case JVM_CONSTANT_InterfaceMethodref :
duke@435 299 st->print("klass_index=%d", cp->klass_ref_index_at(index));
duke@435 300 st->print(" name_and_type_index=%d", cp->name_and_type_ref_index_at(index));
duke@435 301 break;
duke@435 302 case JVM_CONSTANT_UnresolvedString :
duke@435 303 case JVM_CONSTANT_String :
duke@435 304 anObj = cp->string_at(index, CATCH);
duke@435 305 anObj->print_value_on(st);
duke@435 306 st->print(" {0x%lx}", (address)anObj);
duke@435 307 break;
duke@435 308 case JVM_CONSTANT_Integer :
duke@435 309 st->print("%d", cp->int_at(index));
duke@435 310 break;
duke@435 311 case JVM_CONSTANT_Float :
duke@435 312 st->print("%f", cp->float_at(index));
duke@435 313 break;
duke@435 314 case JVM_CONSTANT_Long :
duke@435 315 st->print_jlong(cp->long_at(index));
duke@435 316 index++; // Skip entry following eigth-byte constant
duke@435 317 break;
duke@435 318 case JVM_CONSTANT_Double :
duke@435 319 st->print("%lf", cp->double_at(index));
duke@435 320 index++; // Skip entry following eigth-byte constant
duke@435 321 break;
duke@435 322 case JVM_CONSTANT_NameAndType :
duke@435 323 st->print("name_index=%d", cp->name_ref_index_at(index));
duke@435 324 st->print(" signature_index=%d", cp->signature_ref_index_at(index));
duke@435 325 break;
duke@435 326 case JVM_CONSTANT_Utf8 :
duke@435 327 cp->symbol_at(index)->print_value_on(st);
duke@435 328 break;
duke@435 329 case JVM_CONSTANT_UnresolvedClass : // fall-through
duke@435 330 case JVM_CONSTANT_UnresolvedClassInError: {
duke@435 331 // unresolved_klass_at requires lock or safe world.
duke@435 332 oop entry = *cp->obj_at_addr(index);
duke@435 333 entry->print_value_on(st);
duke@435 334 }
duke@435 335 break;
duke@435 336 default:
duke@435 337 ShouldNotReachHere();
duke@435 338 break;
duke@435 339 }
duke@435 340 st->cr();
duke@435 341 }
duke@435 342 st->cr();
duke@435 343
duke@435 344 // Restore cache
duke@435 345 cp->set_cache(cache());
duke@435 346 }
duke@435 347
duke@435 348
duke@435 349 #endif
duke@435 350
duke@435 351 const char* constantPoolKlass::internal_name() const {
duke@435 352 return "{constant pool}";
duke@435 353 }
duke@435 354
duke@435 355 // Verification
duke@435 356
duke@435 357 void constantPoolKlass::oop_verify_on(oop obj, outputStream* st) {
duke@435 358 Klass::oop_verify_on(obj, st);
duke@435 359 guarantee(obj->is_constantPool(), "object must be constant pool");
duke@435 360 constantPoolOop cp = constantPoolOop(obj);
duke@435 361 guarantee(cp->is_perm(), "should be in permspace");
duke@435 362 if (!cp->partially_loaded()) {
duke@435 363 oop* base = (oop*)cp->base();
duke@435 364 for (int i = 0; i< cp->length(); i++) {
duke@435 365 if (cp->tag_at(i).is_klass()) {
duke@435 366 guarantee((*base)->is_perm(), "should be in permspace");
duke@435 367 guarantee((*base)->is_klass(), "should be klass");
duke@435 368 }
duke@435 369 if (cp->tag_at(i).is_unresolved_klass()) {
duke@435 370 guarantee((*base)->is_perm(), "should be in permspace");
duke@435 371 guarantee((*base)->is_symbol() || (*base)->is_klass(),
duke@435 372 "should be symbol or klass");
duke@435 373 }
duke@435 374 if (cp->tag_at(i).is_symbol()) {
duke@435 375 guarantee((*base)->is_perm(), "should be in permspace");
duke@435 376 guarantee((*base)->is_symbol(), "should be symbol");
duke@435 377 }
duke@435 378 if (cp->tag_at(i).is_unresolved_string()) {
duke@435 379 guarantee((*base)->is_perm(), "should be in permspace");
duke@435 380 guarantee((*base)->is_symbol() || (*base)->is_instance(),
duke@435 381 "should be symbol or instance");
duke@435 382 }
duke@435 383 if (cp->tag_at(i).is_string()) {
duke@435 384 guarantee((*base)->is_perm(), "should be in permspace");
duke@435 385 guarantee((*base)->is_instance(), "should be instance");
duke@435 386 }
duke@435 387 base++;
duke@435 388 }
duke@435 389 guarantee(cp->tags()->is_perm(), "should be in permspace");
duke@435 390 guarantee(cp->tags()->is_typeArray(), "should be type array");
duke@435 391 if (cp->cache() != NULL) {
duke@435 392 // Note: cache() can be NULL before a class is completely setup or
duke@435 393 // in temporary constant pools used during constant pool merging
duke@435 394 guarantee(cp->cache()->is_perm(), "should be in permspace");
duke@435 395 guarantee(cp->cache()->is_constantPoolCache(), "should be constant pool cache");
duke@435 396 }
duke@435 397 if (cp->pool_holder() != NULL) {
duke@435 398 // Note: pool_holder() can be NULL in temporary constant pools
duke@435 399 // used during constant pool merging
duke@435 400 guarantee(cp->pool_holder()->is_perm(), "should be in permspace");
duke@435 401 guarantee(cp->pool_holder()->is_klass(), "should be klass");
duke@435 402 }
duke@435 403 }
duke@435 404 }
duke@435 405
duke@435 406 bool constantPoolKlass::oop_partially_loaded(oop obj) const {
duke@435 407 assert(obj->is_constantPool(), "object must be constant pool");
duke@435 408 constantPoolOop cp = constantPoolOop(obj);
duke@435 409 return cp->tags() == NULL || cp->pool_holder() == (klassOop) cp; // Check whether pool holder points to self
duke@435 410 }
duke@435 411
duke@435 412
duke@435 413 void constantPoolKlass::oop_set_partially_loaded(oop obj) {
duke@435 414 assert(obj->is_constantPool(), "object must be constant pool");
duke@435 415 constantPoolOop cp = constantPoolOop(obj);
duke@435 416 assert(cp->pool_holder() == NULL, "just checking");
duke@435 417 cp->set_pool_holder((klassOop) cp); // Temporarily set pool holder to point to self
duke@435 418 }
duke@435 419
duke@435 420 #ifndef PRODUCT
duke@435 421 // CompileTheWorld support. Preload all classes loaded references in the passed in constantpool
duke@435 422 void constantPoolKlass::preload_and_initialize_all_classes(oop obj, TRAPS) {
duke@435 423 guarantee(obj->is_constantPool(), "object must be constant pool");
duke@435 424 constantPoolHandle cp(THREAD, (constantPoolOop)obj);
duke@435 425 guarantee(!cp->partially_loaded(), "must be fully loaded");
duke@435 426
duke@435 427 for (int i = 0; i< cp->length(); i++) {
duke@435 428 if (cp->tag_at(i).is_unresolved_klass()) {
duke@435 429 // This will force loading of the class
duke@435 430 klassOop klass = cp->klass_at(i, CHECK);
duke@435 431 if (klass->is_instance()) {
duke@435 432 // Force initialization of class
duke@435 433 instanceKlass::cast(klass)->initialize(CHECK);
duke@435 434 }
duke@435 435 }
duke@435 436 }
duke@435 437 }
duke@435 438
duke@435 439 #endif

mercurial