< prev index next >

src/hotspot/share/prims/jvmtiRedefineClasses.cpp

Print this page




1606   _index_map_count = 0;
1607   _index_map_p = new intArray(scratch_cp->length(), scratch_cp->length(), -1);
1608 
1609   _operands_cur_length = ConstantPool::operand_array_length(old_cp->operands());
1610   _operands_index_map_count = 0;
1611   int operands_index_map_len = ConstantPool::operand_array_length(scratch_cp->operands());
1612   _operands_index_map_p = new intArray(operands_index_map_len, operands_index_map_len, -1);
1613 
1614   // reference to the cp holder is needed for copy_operands()
1615   merge_cp->set_pool_holder(scratch_class);
1616   bool result = merge_constant_pools(old_cp, scratch_cp, &merge_cp,
1617                   &merge_cp_length, THREAD);
1618   merge_cp->set_pool_holder(NULL);
1619 
1620   if (!result) {
1621     // The merge can fail due to memory allocation failure or due
1622     // to robustness checks.
1623     return JVMTI_ERROR_INTERNAL;
1624   }
1625 





1626   log_info(redefine, class, constantpool)("merge_cp_len=%d, index_map_len=%d", merge_cp_length, _index_map_count);
1627 
1628   if (_index_map_count == 0) {
1629     // there is nothing to map between the new and merged constant pools
1630 
1631     if (old_cp->length() == scratch_cp->length()) {
1632       // The old and new constant pools are the same length and the
1633       // index map is empty. This means that the three constant pools
1634       // are equivalent (but not the same). Unfortunately, the new
1635       // constant pool has not gone through link resolution nor have
1636       // the new class bytecodes gone through constant pool cache
1637       // rewriting so we can't use the old constant pool with the new
1638       // class.
1639 
1640       // toss the merged constant pool at return
1641     } else if (old_cp->length() < scratch_cp->length()) {
1642       // The old constant pool has fewer entries than the new constant
1643       // pool and the index map is empty. This means the new constant
1644       // pool is a superset of the old constant pool. However, the old
1645       // class bytecodes have already gone through constant pool cache


3228 void VM_RedefineClasses::set_new_constant_pool(
3229        ClassLoaderData* loader_data,
3230        InstanceKlass* scratch_class, constantPoolHandle scratch_cp,
3231        int scratch_cp_length, TRAPS) {
3232   assert(scratch_cp->length() >= scratch_cp_length, "sanity check");
3233 
3234   // scratch_cp is a merged constant pool and has enough space for a
3235   // worst case merge situation. We want to associate the minimum
3236   // sized constant pool with the klass to save space.
3237   ConstantPool* cp = ConstantPool::allocate(loader_data, scratch_cp_length, CHECK);
3238   constantPoolHandle smaller_cp(THREAD, cp);
3239 
3240   // preserve version() value in the smaller copy
3241   int version = scratch_cp->version();
3242   assert(version != 0, "sanity check");
3243   smaller_cp->set_version(version);
3244 
3245   // attach klass to new constant pool
3246   // reference to the cp holder is needed for copy_operands()
3247   smaller_cp->set_pool_holder(scratch_class);




3248 
3249   scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD);
3250   if (HAS_PENDING_EXCEPTION) {
3251     // Exception is handled in the caller
3252     loader_data->add_to_deallocate_list(smaller_cp());
3253     return;
3254   }
3255   scratch_cp = smaller_cp;
3256 
3257   // attach new constant pool to klass
3258   scratch_class->set_constants(scratch_cp());
3259   scratch_cp->initialize_unresolved_klasses(loader_data, CHECK);
3260 
3261   int i;  // for portability
3262 
3263   // update each field in klass to use new constant pool indices as needed
3264   for (JavaFieldStream fs(scratch_class); !fs.done(); fs.next()) {
3265     jshort cur_index = fs.name_index();
3266     jshort new_index = find_new_index(cur_index);
3267     if (new_index != 0) {




1606   _index_map_count = 0;
1607   _index_map_p = new intArray(scratch_cp->length(), scratch_cp->length(), -1);
1608 
1609   _operands_cur_length = ConstantPool::operand_array_length(old_cp->operands());
1610   _operands_index_map_count = 0;
1611   int operands_index_map_len = ConstantPool::operand_array_length(scratch_cp->operands());
1612   _operands_index_map_p = new intArray(operands_index_map_len, operands_index_map_len, -1);
1613 
1614   // reference to the cp holder is needed for copy_operands()
1615   merge_cp->set_pool_holder(scratch_class);
1616   bool result = merge_constant_pools(old_cp, scratch_cp, &merge_cp,
1617                   &merge_cp_length, THREAD);
1618   merge_cp->set_pool_holder(NULL);
1619 
1620   if (!result) {
1621     // The merge can fail due to memory allocation failure or due
1622     // to robustness checks.
1623     return JVMTI_ERROR_INTERNAL;
1624   }
1625 
1626  if (old_cp->has_dynamic_constant()) {
1627    merge_cp->set_has_dynamic_constant();
1628    scratch_cp->set_has_dynamic_constant();
1629 }
1630 
1631   log_info(redefine, class, constantpool)("merge_cp_len=%d, index_map_len=%d", merge_cp_length, _index_map_count);
1632 
1633   if (_index_map_count == 0) {
1634     // there is nothing to map between the new and merged constant pools
1635 
1636     if (old_cp->length() == scratch_cp->length()) {
1637       // The old and new constant pools are the same length and the
1638       // index map is empty. This means that the three constant pools
1639       // are equivalent (but not the same). Unfortunately, the new
1640       // constant pool has not gone through link resolution nor have
1641       // the new class bytecodes gone through constant pool cache
1642       // rewriting so we can't use the old constant pool with the new
1643       // class.
1644 
1645       // toss the merged constant pool at return
1646     } else if (old_cp->length() < scratch_cp->length()) {
1647       // The old constant pool has fewer entries than the new constant
1648       // pool and the index map is empty. This means the new constant
1649       // pool is a superset of the old constant pool. However, the old
1650       // class bytecodes have already gone through constant pool cache


3233 void VM_RedefineClasses::set_new_constant_pool(
3234        ClassLoaderData* loader_data,
3235        InstanceKlass* scratch_class, constantPoolHandle scratch_cp,
3236        int scratch_cp_length, TRAPS) {
3237   assert(scratch_cp->length() >= scratch_cp_length, "sanity check");
3238 
3239   // scratch_cp is a merged constant pool and has enough space for a
3240   // worst case merge situation. We want to associate the minimum
3241   // sized constant pool with the klass to save space.
3242   ConstantPool* cp = ConstantPool::allocate(loader_data, scratch_cp_length, CHECK);
3243   constantPoolHandle smaller_cp(THREAD, cp);
3244 
3245   // preserve version() value in the smaller copy
3246   int version = scratch_cp->version();
3247   assert(version != 0, "sanity check");
3248   smaller_cp->set_version(version);
3249 
3250   // attach klass to new constant pool
3251   // reference to the cp holder is needed for copy_operands()
3252   smaller_cp->set_pool_holder(scratch_class);
3253 
3254   if (scratch_cp->has_dynamic_constant()) {
3255     smaller_cp->set_has_dynamic_constant();
3256   }
3257 
3258   scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD);
3259   if (HAS_PENDING_EXCEPTION) {
3260     // Exception is handled in the caller
3261     loader_data->add_to_deallocate_list(smaller_cp());
3262     return;
3263   }
3264   scratch_cp = smaller_cp;
3265 
3266   // attach new constant pool to klass
3267   scratch_class->set_constants(scratch_cp());
3268   scratch_cp->initialize_unresolved_klasses(loader_data, CHECK);
3269 
3270   int i;  // for portability
3271 
3272   // update each field in klass to use new constant pool indices as needed
3273   for (JavaFieldStream fs(scratch_class); !fs.done(); fs.next()) {
3274     jshort cur_index = fs.name_index();
3275     jshort new_index = find_new_index(cur_index);
3276     if (new_index != 0) {


< prev index next >