annotate src/share/vm/oops/constantPoolKlass.cpp @ 0:a61af66fc99e

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