comparison src/share/vm/prims/jvmtiRedefineClasses.cpp @ 12208:ce5ee9de50ce

8024345: 'assert(_value != NULL) failed: resolving NULL _value' from VM_RedefineClasses::set_new_constant_pool Summary: The OOME's in the JVMTI merge_cp_and_rewrite and set_new_constant_pool must be handled correctly Reviewed-by: coleenp, dholmes Contributed-by: serguei.spitsyn@oracle.com
author sspitsyn
date Fri, 13 Sep 2013 12:47:44 -0700
parents ff8a09595db3
children 0d3ff4d36a31
comparison
equal deleted inserted replaced
12207:ff8a09595db3 12208:ce5ee9de50ce
1393 // garbage, if it crosses a card boundary, it may be scanned 1393 // garbage, if it crosses a card boundary, it may be scanned
1394 // in order to find the start of the first complete object on the card. 1394 // in order to find the start of the first complete object on the card.
1395 ClassLoaderData* loader_data = the_class->class_loader_data(); 1395 ClassLoaderData* loader_data = the_class->class_loader_data();
1396 ConstantPool* merge_cp_oop = 1396 ConstantPool* merge_cp_oop =
1397 ConstantPool::allocate(loader_data, 1397 ConstantPool::allocate(loader_data,
1398 merge_cp_length, 1398 merge_cp_length,
1399 THREAD); 1399 CHECK_(JVMTI_ERROR_OUT_OF_MEMORY));
1400 MergeCPCleaner cp_cleaner(loader_data, merge_cp_oop); 1400 MergeCPCleaner cp_cleaner(loader_data, merge_cp_oop);
1401 1401
1402 HandleMark hm(THREAD); // make sure handles are cleared before 1402 HandleMark hm(THREAD); // make sure handles are cleared before
1403 // MergeCPCleaner clears out merge_cp_oop 1403 // MergeCPCleaner clears out merge_cp_oop
1404 constantPoolHandle merge_cp(THREAD, merge_cp_oop); 1404 constantPoolHandle merge_cp(THREAD, merge_cp_oop);
1470 // and merged constant pools are supersets of the new constant 1470 // and merged constant pools are supersets of the new constant
1471 // pool. 1471 // pool.
1472 1472
1473 // Replace the new constant pool with a shrunken copy of the 1473 // Replace the new constant pool with a shrunken copy of the
1474 // merged constant pool 1474 // merged constant pool
1475 set_new_constant_pool(loader_data, scratch_class, merge_cp, merge_cp_length, THREAD); 1475 set_new_constant_pool(loader_data, scratch_class, merge_cp, merge_cp_length,
1476 CHECK_(JVMTI_ERROR_OUT_OF_MEMORY));
1476 // The new constant pool replaces scratch_cp so have cleaner clean it up. 1477 // The new constant pool replaces scratch_cp so have cleaner clean it up.
1477 // It can't be cleaned up while there are handles to it. 1478 // It can't be cleaned up while there are handles to it.
1478 cp_cleaner.add_scratch_cp(scratch_cp()); 1479 cp_cleaner.add_scratch_cp(scratch_cp());
1479 } 1480 }
1480 } else { 1481 } else {
1500 1501
1501 // Replace the new constant pool with a shrunken copy of the 1502 // Replace the new constant pool with a shrunken copy of the
1502 // merged constant pool so now the rewritten bytecodes have 1503 // merged constant pool so now the rewritten bytecodes have
1503 // valid references; the previous new constant pool will get 1504 // valid references; the previous new constant pool will get
1504 // GCed. 1505 // GCed.
1505 set_new_constant_pool(loader_data, scratch_class, merge_cp, merge_cp_length, THREAD); 1506 set_new_constant_pool(loader_data, scratch_class, merge_cp, merge_cp_length,
1507 CHECK_(JVMTI_ERROR_OUT_OF_MEMORY));
1506 // The new constant pool replaces scratch_cp so have cleaner clean it up. 1508 // The new constant pool replaces scratch_cp so have cleaner clean it up.
1507 // It can't be cleaned up while there are handles to it. 1509 // It can't be cleaned up while there are handles to it.
1508 cp_cleaner.add_scratch_cp(scratch_cp()); 1510 cp_cleaner.add_scratch_cp(scratch_cp());
1509 } 1511 }
1510 1512
2494 assert(scratch_cp->length() >= scratch_cp_length, "sanity check"); 2496 assert(scratch_cp->length() >= scratch_cp_length, "sanity check");
2495 2497
2496 // scratch_cp is a merged constant pool and has enough space for a 2498 // scratch_cp is a merged constant pool and has enough space for a
2497 // worst case merge situation. We want to associate the minimum 2499 // worst case merge situation. We want to associate the minimum
2498 // sized constant pool with the klass to save space. 2500 // sized constant pool with the klass to save space.
2499 constantPoolHandle smaller_cp(THREAD, 2501 ConstantPool* cp = ConstantPool::allocate(loader_data, scratch_cp_length, CHECK);
2500 ConstantPool::allocate(loader_data, scratch_cp_length, THREAD)); 2502 constantPoolHandle smaller_cp(THREAD, cp);
2501 2503
2502 // preserve version() value in the smaller copy 2504 // preserve version() value in the smaller copy
2503 int version = scratch_cp->version(); 2505 int version = scratch_cp->version();
2504 assert(version != 0, "sanity check"); 2506 assert(version != 0, "sanity check");
2505 smaller_cp->set_version(version); 2507 smaller_cp->set_version(version);
2507 // attach klass to new constant pool 2509 // attach klass to new constant pool
2508 // reference to the cp holder is needed for copy_operands() 2510 // reference to the cp holder is needed for copy_operands()
2509 smaller_cp->set_pool_holder(scratch_class()); 2511 smaller_cp->set_pool_holder(scratch_class());
2510 2512
2511 scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD); 2513 scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD);
2514 if (HAS_PENDING_EXCEPTION) {
2515 // Exception is handled in the caller
2516 loader_data->add_to_deallocate_list(smaller_cp());
2517 return;
2518 }
2512 scratch_cp = smaller_cp; 2519 scratch_cp = smaller_cp;
2513 2520
2514 // attach new constant pool to klass 2521 // attach new constant pool to klass
2515 scratch_class->set_constants(scratch_cp()); 2522 scratch_class->set_constants(scratch_cp());
2516 2523