Skip to content

Commit 6fe959c

Browse files
Matias Saavedra Silvaiklam
andcommitted
8307306: Change some ConstantPool::name_ref_at calls to uncached_name_ref_at
Co-authored-by: Ioi Lam <iklam@openjdk.org> Reviewed-by: coleenp, fparain
1 parent 3f6a354 commit 6fe959c

File tree

5 files changed

+27
-24
lines changed

5 files changed

+27
-24
lines changed

src/hotspot/share/classfile/classFileParser.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,8 @@ void ClassFileParser::parse_constant_pool(const ClassFileStream* const stream,
452452
// fall through
453453
case JVM_CONSTANT_InterfaceMethodref: {
454454
if (!_need_verify) break;
455-
const int klass_ref_index = cp->klass_ref_index_at(index);
456-
const int name_and_type_ref_index = cp->name_and_type_ref_index_at(index);
455+
const int klass_ref_index = cp->uncached_klass_ref_index_at(index);
456+
const int name_and_type_ref_index = cp->uncached_name_and_type_ref_index_at(index);
457457
check_property(valid_klass_reference_at(klass_ref_index),
458458
"Invalid constant pool index %u in class file %s",
459459
klass_ref_index, CHECK);
@@ -655,7 +655,7 @@ void ClassFileParser::parse_constant_pool(const ClassFileStream* const stream,
655655
}
656656
case JVM_CONSTANT_Dynamic: {
657657
const int name_and_type_ref_index =
658-
cp->name_and_type_ref_index_at(index);
658+
cp->uncached_name_and_type_ref_index_at(index);
659659
// already verified to be utf8
660660
const int name_ref_index =
661661
cp->name_ref_index_at(name_and_type_ref_index);
@@ -678,7 +678,7 @@ void ClassFileParser::parse_constant_pool(const ClassFileStream* const stream,
678678
case JVM_CONSTANT_Methodref:
679679
case JVM_CONSTANT_InterfaceMethodref: {
680680
const int name_and_type_ref_index =
681-
cp->name_and_type_ref_index_at(index);
681+
cp->uncached_name_and_type_ref_index_at(index);
682682
// already verified to be utf8
683683
const int name_ref_index =
684684
cp->name_ref_index_at(name_and_type_ref_index);
@@ -729,7 +729,7 @@ void ClassFileParser::parse_constant_pool(const ClassFileStream* const stream,
729729
case JVM_REF_invokeSpecial:
730730
case JVM_REF_newInvokeSpecial: {
731731
const int name_and_type_ref_index =
732-
cp->name_and_type_ref_index_at(ref_index);
732+
cp->uncached_name_and_type_ref_index_at(ref_index);
733733
const int name_ref_index =
734734
cp->name_ref_index_at(name_and_type_ref_index);
735735
const Symbol* const name = cp->symbol_at(name_ref_index);

src/hotspot/share/classfile/verifier.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,8 +2310,8 @@ void ClassVerifier::verify_field_instructions(RawBytecodeStream* bcs,
23102310
1 << JVM_CONSTANT_Fieldref, CHECK_VERIFY(this));
23112311

23122312
// Get field name and signature
2313-
Symbol* field_name = cp->name_ref_at(index);
2314-
Symbol* field_sig = cp->signature_ref_at(index);
2313+
Symbol* field_name = cp->uncached_name_ref_at(index);
2314+
Symbol* field_sig = cp->uncached_signature_ref_at(index);
23152315
bool is_getfield = false;
23162316

23172317
// Field signature was checked in ClassFileParser.
@@ -2401,7 +2401,7 @@ void ClassVerifier::verify_field_instructions(RawBytecodeStream* bcs,
24012401
return;
24022402
}
24032403
Symbol* ref_class_name =
2404-
cp->klass_name_at(cp->klass_ref_index_at(index));
2404+
cp->klass_name_at(cp->uncached_klass_ref_index_at(index));
24052405
if (!name_in_supers(ref_class_name, current_class()))
24062406
// stack_object_type must be assignable to _current_class_type since:
24072407
// 1. stack_object_type must be assignable to ref_class.
@@ -2725,7 +2725,7 @@ void ClassVerifier::verify_invoke_init(
27252725
if (was_recursively_verified()) return;
27262726
Method* m = InstanceKlass::cast(ref_klass)->uncached_lookup_method(
27272727
vmSymbols::object_initializer_name(),
2728-
cp->signature_ref_at(bcs->get_index_u2()),
2728+
cp->uncached_signature_ref_at(bcs->get_index_u2()),
27292729
Klass::OverpassLookupMode::find);
27302730
// Do nothing if method is not found. Let resolution detect the error.
27312731
if (m != nullptr) {
@@ -2804,8 +2804,8 @@ void ClassVerifier::verify_invoke_instructions(
28042804
verify_cp_type(bcs->bci(), index, cp, types, CHECK_VERIFY(this));
28052805

28062806
// Get method name and signature
2807-
Symbol* method_name = cp->name_ref_at(index);
2808-
Symbol* method_sig = cp->signature_ref_at(index);
2807+
Symbol* method_name = cp->uncached_name_ref_at(index);
2808+
Symbol* method_sig = cp->uncached_signature_ref_at(index);
28092809

28102810
// Method signature was checked in ClassFileParser.
28112811
assert(SignatureVerifier::is_valid_method_signature(method_sig),
@@ -2828,7 +2828,7 @@ void ClassVerifier::verify_invoke_instructions(
28282828
"buffer type must match VerificationType size");
28292829

28302830
// Get the UTF8 index for this signature.
2831-
int sig_index = cp->signature_ref_index_at(cp->name_and_type_ref_index_at(index));
2831+
int sig_index = cp->signature_ref_index_at(cp->uncached_name_and_type_ref_index_at(index));
28322832

28332833
// Get the signature's verification types.
28342834
sig_as_verification_types* mth_sig_verif_types;
@@ -2934,7 +2934,7 @@ void ClassVerifier::verify_invoke_instructions(
29342934
if (was_recursively_verified()) return;
29352935
assert(cp->cache() == nullptr, "not rewritten yet");
29362936
Symbol* ref_class_name =
2937-
cp->klass_name_at(cp->klass_ref_index_at(index));
2937+
cp->klass_name_at(cp->uncached_klass_ref_index_at(index));
29382938
// See the comments in verify_field_instructions() for
29392939
// the rationale behind this.
29402940
if (name_in_supers(ref_class_name, current_class())) {

src/hotspot/share/classfile/verifier.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ class ClassVerifier : public StackObj {
297297

298298
VerificationType cp_ref_index_to_type(
299299
int index, const constantPoolHandle& cp, TRAPS) {
300-
return cp_index_to_type(cp->klass_ref_index_at(index), cp, THREAD);
300+
return cp_index_to_type(cp->uncached_klass_ref_index_at(index), cp, THREAD);
301301
}
302302

303303
bool is_protected_access(

src/hotspot/share/interpreter/rewriter.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,15 @@ void Rewriter::maybe_rewrite_invokehandle(address opc, int cp_index, int cache_i
226226
int status = _method_handle_invokers.at(cp_index);
227227
assert(status >= -1 && status <= 1, "oob tri-state");
228228
if (status == 0) {
229-
if (_pool->klass_ref_at_noresolve(cp_index) == vmSymbols::java_lang_invoke_MethodHandle() &&
229+
if (_pool->uncached_klass_ref_at_noresolve(cp_index) == vmSymbols::java_lang_invoke_MethodHandle() &&
230230
MethodHandles::is_signature_polymorphic_name(vmClasses::MethodHandle_klass(),
231-
_pool->name_ref_at(cp_index))) {
231+
_pool->uncached_name_ref_at(cp_index))) {
232232
// we may need a resolved_refs entry for the appendix
233233
add_invokedynamic_resolved_references_entry(cp_index, cache_index);
234234
status = +1;
235-
} else if (_pool->klass_ref_at_noresolve(cp_index) == vmSymbols::java_lang_invoke_VarHandle() &&
235+
} else if (_pool->uncached_klass_ref_at_noresolve(cp_index) == vmSymbols::java_lang_invoke_VarHandle() &&
236236
MethodHandles::is_signature_polymorphic_name(vmClasses::VarHandle_klass(),
237-
_pool->name_ref_at(cp_index))) {
237+
_pool->uncached_name_ref_at(cp_index))) {
238238
// we may need a resolved_refs entry for the appendix
239239
add_invokedynamic_resolved_references_entry(cp_index, cache_index);
240240
status = +1;
@@ -421,11 +421,11 @@ void Rewriter::scan_method(Thread* thread, Method* method, bool reverse, bool* i
421421
InstanceKlass* klass = method->method_holder();
422422
u2 bc_index = Bytes::get_Java_u2(bcp + prefix_length + 1);
423423
constantPoolHandle cp(thread, method->constants());
424-
Symbol* ref_class_name = cp->klass_name_at(cp->klass_ref_index_at(bc_index));
424+
Symbol* ref_class_name = cp->klass_name_at(cp->uncached_klass_ref_index_at(bc_index));
425425

426426
if (klass->name() == ref_class_name) {
427-
Symbol* field_name = cp->name_ref_at(bc_index);
428-
Symbol* field_sig = cp->signature_ref_at(bc_index);
427+
Symbol* field_name = cp->uncached_name_ref_at(bc_index);
428+
Symbol* field_sig = cp->uncached_signature_ref_at(bc_index);
429429

430430
fieldDescriptor fd;
431431
if (klass->find_field(field_name, field_sig, &fd) != nullptr) {

src/hotspot/share/oops/constantPool.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,8 @@ Symbol* ConstantPool::impl_signature_ref_at(int which, bool uncached) {
688688

689689
int ConstantPool::impl_name_and_type_ref_index_at(int which, bool uncached) {
690690
int i = which;
691-
if (!uncached && cache() != nullptr) {
691+
if (!uncached) {
692+
assert(cache() != nullptr, "'which' is a rewritten index so this class must have been rewritten");
692693
if (ConstantPool::is_invokedynamic_index(which)) {
693694
// Invokedynamic index is index into the resolved indy array in the constant pool cache
694695
int pool_index = invokedynamic_bootstrap_ref_index_at(which);
@@ -713,7 +714,8 @@ int ConstantPool::impl_name_and_type_ref_index_at(int which, bool uncached) {
713714

714715
constantTag ConstantPool::impl_tag_ref_at(int which, bool uncached) {
715716
int pool_index = which;
716-
if (!uncached && cache() != nullptr) {
717+
if (!uncached) {
718+
assert(cache() != nullptr, "'which' is a rewritten index so this class must have been rewritten");
717719
if (ConstantPool::is_invokedynamic_index(which)) {
718720
// Invokedynamic index is index into resolved_references
719721
pool_index = invokedynamic_bootstrap_ref_index_at(which);
@@ -729,7 +731,8 @@ int ConstantPool::impl_klass_ref_index_at(int which, bool uncached) {
729731
guarantee(!ConstantPool::is_invokedynamic_index(which),
730732
"an invokedynamic instruction does not have a klass");
731733
int i = which;
732-
if (!uncached && cache() != nullptr) {
734+
if (!uncached) {
735+
assert(cache() != nullptr, "'which' is a rewritten index so this class must have been rewritten");
733736
// change byte-ordering and go via cache
734737
i = remap_instruction_operand_from_cache(which);
735738
}

0 commit comments

Comments
 (0)