annotate src/share/vm/oops/constantPoolKlass.cpp @ 113:ba764ed4b6f2

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