Skip to content

Commit 8511220

Browse files
committed
8355490: Make VM_RedefineClasses::merge_constant_pools only take reference arguments
Reviewed-by: amenkov, sspitsyn, coleenp
1 parent f04e556 commit 8511220

File tree

2 files changed

+32
-40
lines changed

2 files changed

+32
-40
lines changed

src/hotspot/share/prims/jvmtiRedefineClasses.cpp

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,28 +1572,20 @@ void VM_RedefineClasses::map_operand_index(int old_index, int new_index) {
15721572

15731573

15741574
// Merge old_cp and scratch_cp and return the results of the merge via
1575-
// merge_cp_p. The number of entries in *merge_cp_p is returned via
1575+
// merge_cp_p. The number of entries in merge_cp_p is returned via
15761576
// merge_cp_length_p. The entries in old_cp occupy the same locations
1577-
// in *merge_cp_p. Also creates a map of indices from entries in
1578-
// scratch_cp to the corresponding entry in *merge_cp_p. Index map
1577+
// in merge_cp_p. Also creates a map of indices from entries in
1578+
// scratch_cp to the corresponding entry in merge_cp_p. Index map
15791579
// entries are only created for entries in scratch_cp that occupy a
1580-
// different location in *merged_cp_p.
1580+
// different location in merged_cp_p.
15811581
bool VM_RedefineClasses::merge_constant_pools(const constantPoolHandle& old_cp,
1582-
const constantPoolHandle& scratch_cp, constantPoolHandle *merge_cp_p,
1583-
int *merge_cp_length_p, TRAPS) {
1582+
const constantPoolHandle& scratch_cp, constantPoolHandle& merge_cp_p,
1583+
int& merge_cp_length_p, TRAPS) {
15841584

1585-
if (merge_cp_p == nullptr) {
1586-
assert(false, "caller must provide scratch constantPool");
1587-
return false; // robustness
1588-
}
1589-
if (merge_cp_length_p == nullptr) {
1590-
assert(false, "caller must provide scratch CP length");
1591-
return false; // robustness
1592-
}
15931585
// Worst case we need old_cp->length() + scratch_cp()->length(),
15941586
// but the caller might be smart so make sure we have at least
15951587
// the minimum.
1596-
if ((*merge_cp_p)->length() < old_cp->length()) {
1588+
if (merge_cp_p->length() < old_cp->length()) {
15971589
assert(false, "merge area too small");
15981590
return false; // robustness
15991591
}
@@ -1621,36 +1613,36 @@ bool VM_RedefineClasses::merge_constant_pools(const constantPoolHandle& old_cp,
16211613
// revert the copy to JVM_CONSTANT_UnresolvedClass
16221614
// May be resolving while calling this so do the same for
16231615
// JVM_CONSTANT_UnresolvedClass (klass_name_at() deals with transition)
1624-
(*merge_cp_p)->temp_unresolved_klass_at_put(old_i,
1616+
merge_cp_p->temp_unresolved_klass_at_put(old_i,
16251617
old_cp->klass_name_index_at(old_i));
16261618
break;
16271619

16281620
case JVM_CONSTANT_Double:
16291621
case JVM_CONSTANT_Long:
1630-
// just copy the entry to *merge_cp_p, but double and long take
1622+
// just copy the entry to merge_cp_p, but double and long take
16311623
// two constant pool entries
1632-
ConstantPool::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i);
1624+
ConstantPool::copy_entry_to(old_cp, old_i, merge_cp_p, old_i);
16331625
old_i++;
16341626
break;
16351627

16361628
default:
1637-
// just copy the entry to *merge_cp_p
1638-
ConstantPool::copy_entry_to(old_cp, old_i, *merge_cp_p, old_i);
1629+
// just copy the entry to merge_cp_p
1630+
ConstantPool::copy_entry_to(old_cp, old_i, merge_cp_p, old_i);
16391631
break;
16401632
}
16411633
} // end for each old_cp entry
16421634

1643-
ConstantPool::copy_operands(old_cp, *merge_cp_p, CHECK_false);
1644-
(*merge_cp_p)->extend_operands(scratch_cp, CHECK_false);
1635+
ConstantPool::copy_operands(old_cp, merge_cp_p, CHECK_false);
1636+
merge_cp_p->extend_operands(scratch_cp, CHECK_false);
16451637

16461638
// We don't need to sanity check that *merge_cp_length_p is within
16471639
// *merge_cp_p bounds since we have the minimum on-entry check above.
1648-
(*merge_cp_length_p) = old_i;
1640+
merge_cp_length_p = old_i;
16491641
}
16501642

16511643
// merge_cp_len should be the same as old_cp->length() at this point
16521644
// so this trace message is really a "warm-and-breathing" message.
1653-
log_debug(redefine, class, constantpool)("after pass 0: merge_cp_len=%d", *merge_cp_length_p);
1645+
log_debug(redefine, class, constantpool)("after pass 0: merge_cp_len=%d", merge_cp_length_p);
16541646

16551647
int scratch_i; // index into scratch_cp
16561648
{
@@ -1674,13 +1666,13 @@ bool VM_RedefineClasses::merge_constant_pools(const constantPoolHandle& old_cp,
16741666
break;
16751667
}
16761668

1677-
bool match = scratch_cp->compare_entry_to(scratch_i, *merge_cp_p, scratch_i);
1669+
bool match = scratch_cp->compare_entry_to(scratch_i, merge_cp_p, scratch_i);
16781670
if (match) {
16791671
// found a match at the same index so nothing more to do
16801672
continue;
16811673
}
16821674

1683-
int found_i = scratch_cp->find_matching_entry(scratch_i, *merge_cp_p);
1675+
int found_i = scratch_cp->find_matching_entry(scratch_i, merge_cp_p);
16841676
if (found_i != 0) {
16851677
guarantee(found_i != scratch_i,
16861678
"compare_entry_to() and find_matching_entry() do not agree");
@@ -1692,14 +1684,14 @@ bool VM_RedefineClasses::merge_constant_pools(const constantPoolHandle& old_cp,
16921684
}
16931685

16941686
// No match found so we have to append this entry and any unique
1695-
// referenced entries to *merge_cp_p.
1696-
append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p);
1687+
// referenced entries to merge_cp_p.
1688+
append_entry(scratch_cp, scratch_i, &merge_cp_p, &merge_cp_length_p);
16971689
}
16981690
}
16991691

17001692
log_debug(redefine, class, constantpool)
17011693
("after pass 1a: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
1702-
*merge_cp_length_p, scratch_i, _index_map_count);
1694+
merge_cp_length_p, scratch_i, _index_map_count);
17031695

17041696
if (scratch_i < scratch_cp->length()) {
17051697
// Pass 1b:
@@ -1721,24 +1713,24 @@ bool VM_RedefineClasses::merge_constant_pools(const constantPoolHandle& old_cp,
17211713
}
17221714

17231715
int found_i =
1724-
scratch_cp->find_matching_entry(scratch_i, *merge_cp_p);
1716+
scratch_cp->find_matching_entry(scratch_i, merge_cp_p);
17251717
if (found_i != 0) {
1726-
// Found a matching entry somewhere else in *merge_cp_p so
1718+
// Found a matching entry somewhere else in merge_cp_p so
17271719
// just need a mapping entry.
17281720
map_index(scratch_cp, scratch_i, found_i);
17291721
continue;
17301722
}
17311723

17321724
// No match found so we have to append this entry and any unique
1733-
// referenced entries to *merge_cp_p.
1734-
append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p);
1725+
// referenced entries to merge_cp_p.
1726+
append_entry(scratch_cp, scratch_i, &merge_cp_p, &merge_cp_length_p);
17351727
}
17361728

17371729
log_debug(redefine, class, constantpool)
17381730
("after pass 1b: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
1739-
*merge_cp_length_p, scratch_i, _index_map_count);
1731+
merge_cp_length_p, scratch_i, _index_map_count);
17401732
}
1741-
finalize_operands_merge(*merge_cp_p, CHECK_false);
1733+
finalize_operands_merge(merge_cp_p, CHECK_false);
17421734

17431735
return true;
17441736
} // end merge_constant_pools()
@@ -1815,8 +1807,8 @@ jvmtiError VM_RedefineClasses::merge_cp_and_rewrite(
18151807

18161808
// reference to the cp holder is needed for copy_operands()
18171809
merge_cp->set_pool_holder(scratch_class);
1818-
bool result = merge_constant_pools(old_cp, scratch_cp, &merge_cp,
1819-
&merge_cp_length, THREAD);
1810+
bool result = merge_constant_pools(old_cp, scratch_cp, merge_cp,
1811+
merge_cp_length, THREAD);
18201812
merge_cp->set_pool_holder(nullptr);
18211813

18221814
if (!result) {

src/hotspot/share/prims/jvmtiRedefineClasses.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -441,8 +441,8 @@ class VM_RedefineClasses: public VM_Operation {
441441
void map_index(const constantPoolHandle& scratch_cp, int old_index, int new_index);
442442
void map_operand_index(int old_bootstrap_spec_index, int new_bootstrap_spec_index);
443443
bool merge_constant_pools(const constantPoolHandle& old_cp,
444-
const constantPoolHandle& scratch_cp, constantPoolHandle *merge_cp_p,
445-
int *merge_cp_length_p, TRAPS);
444+
const constantPoolHandle& scratch_cp, constantPoolHandle& merge_cp_p,
445+
int& merge_cp_length_p, TRAPS);
446446
jvmtiError merge_cp_and_rewrite(InstanceKlass* the_class,
447447
InstanceKlass* scratch_class, TRAPS);
448448
u2 rewrite_cp_ref_in_annotation_data(

0 commit comments

Comments
 (0)