Skip to content

Commit c59f394

Browse files
author
John Rose
committed
minor bug fixes, cleanups; adapt more clients to new CP APIs
1 parent 09d7021 commit c59f394

File tree

8 files changed

+150
-112
lines changed

8 files changed

+150
-112
lines changed

src/hotspot/share/classfile/classFileParser.cpp

Lines changed: 54 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,12 @@ void ClassFileParser::parse_constant_pool_entries(const ClassFileStream* const s
257257
return;
258258
}
259259
cfs->guarantee_more(5, CHECK); // bsm_index, nt, tag/access_flags
260-
const u2 bootstrap_specifier_index = cfs->get_u2_fast();
260+
const u2 bsm_attribute_index = cfs->get_u2_fast();
261261
const u2 name_and_type_index = cfs->get_u2_fast();
262-
if (_max_bootstrap_specifier_index < (int) bootstrap_specifier_index) {
263-
_max_bootstrap_specifier_index = (int) bootstrap_specifier_index; // collect for later
262+
if (_max_bsm_attribute_index < (int) bsm_attribute_index) {
263+
_max_bsm_attribute_index = (int) bsm_attribute_index; // collect for later
264264
}
265-
cp->dynamic_constant_at_put(index, bootstrap_specifier_index, name_and_type_index);
265+
cp->dynamic_constant_at_put(index, bsm_attribute_index, name_and_type_index);
266266
break;
267267
}
268268
case JVM_CONSTANT_InvokeDynamic : {
@@ -273,12 +273,12 @@ void ClassFileParser::parse_constant_pool_entries(const ClassFileStream* const s
273273
return;
274274
}
275275
cfs->guarantee_more(5, CHECK); // bsm_index, nt, tag/access_flags
276-
const u2 bootstrap_specifier_index = cfs->get_u2_fast();
276+
const u2 bsm_attribute_index = cfs->get_u2_fast();
277277
const u2 name_and_type_index = cfs->get_u2_fast();
278-
if (_max_bootstrap_specifier_index < (int) bootstrap_specifier_index) {
279-
_max_bootstrap_specifier_index = (int) bootstrap_specifier_index; // collect for later
278+
if (_max_bsm_attribute_index < (int) bsm_attribute_index) {
279+
_max_bsm_attribute_index = (int) bsm_attribute_index; // collect for later
280280
}
281-
cp->invoke_dynamic_at_put(index, bootstrap_specifier_index, name_and_type_index);
281+
cp->invoke_dynamic_at_put(index, bsm_attribute_index, name_and_type_index);
282282
break;
283283
}
284284
case JVM_CONSTANT_Integer: {
@@ -444,8 +444,9 @@ void ClassFileParser::parse_constant_pool(const ClassFileStream* const stream,
444444
// fall through
445445
case JVM_CONSTANT_InterfaceMethodref: {
446446
if (!_need_verify) break;
447-
const int klass_ref_index = cp->uncached_klass_ref_index_at(index);
448-
const int name_and_type_ref_index = cp->uncached_name_and_type_ref_index_at(index);
447+
const auto ref = cp->uncached_triple_ref_at(index, /*allow_malformed*/ true);
448+
const int klass_ref_index = ref.klass_index();
449+
const int name_and_type_ref_index = ref.nt_index();
449450
guarantee_property(valid_klass_reference_at(klass_ref_index),
450451
"Invalid constant pool index %u in class file %s",
451452
klass_ref_index, CHECK);
@@ -474,8 +475,9 @@ void ClassFileParser::parse_constant_pool(const ClassFileStream* const stream,
474475
}
475476
case JVM_CONSTANT_NameAndType: {
476477
if (!_need_verify) break;
477-
const int name_ref_index = cp->name_ref_index_at(index);
478-
const int signature_ref_index = cp->signature_ref_index_at(index);
478+
const auto ntp = cp->name_and_type_pair_at(index);
479+
const int name_ref_index = ntp.name_index();
480+
const int signature_ref_index = ntp.signature_index();
479481
guarantee_property(valid_symbol_at(name_ref_index),
480482
"Invalid constant pool index %u in class file %s",
481483
name_ref_index, CHECK);
@@ -509,14 +511,14 @@ void ClassFileParser::parse_constant_pool(const ClassFileStream* const stream,
509511
break;
510512
}
511513
case JVM_CONSTANT_MethodHandle: {
512-
const int ref_index = cp->method_handle_index_at(index);
514+
const auto mhref = cp->method_handle_ref_at(index);
515+
const int ref_index = mhref.ref_index();
513516
guarantee_property(valid_cp_range(ref_index, length),
514517
"Invalid constant pool index %u in class file %s",
515518
ref_index, CHECK);
516519
const constantTag tag = cp->tag_at(ref_index);
517-
const int ref_kind = cp->method_handle_ref_kind_at(index);
518520

519-
switch (ref_kind) {
521+
switch (mhref.ref_kind()) {
520522
case JVM_REF_getField:
521523
case JVM_REF_getStatic:
522524
case JVM_REF_putField:
@@ -562,36 +564,37 @@ void ClassFileParser::parse_constant_pool(const ClassFileStream* const stream,
562564
break;
563565
} // case MethodHandle
564566
case JVM_CONSTANT_MethodType: {
565-
const int ref_index = cp->method_type_index_at(index);
567+
const auto mtref = cp->method_type_ref_at(index);
568+
const int ref_index = mtref.signature_index();
566569
guarantee_property(valid_symbol_at(ref_index),
567570
"Invalid constant pool index %u in class file %s",
568571
ref_index, CHECK);
569572
break;
570573
}
571574
case JVM_CONSTANT_Dynamic: {
572-
const int name_and_type_ref_index =
573-
cp->bootstrap_name_and_type_ref_index_at(index);
575+
const auto bsref = cp->uncached_triple_ref_at(index, /*allow_malformed*/ true);
576+
const int name_and_type_ref_index = bsref.nt_index();
574577

575578
guarantee_property(valid_cp_range(name_and_type_ref_index, length) &&
576579
cp->tag_at(name_and_type_ref_index).is_name_and_type(),
577580
"Invalid constant pool index %u in class file %s",
578581
name_and_type_ref_index, CHECK);
579-
// bootstrap specifier index must be checked later,
582+
// bootstrap attribute index must be checked later,
580583
// when BootstrapMethods attr is available
581584

582585
// Mark the constant pool as having a CONSTANT_Dynamic_info structure
583586
cp->set_has_dynamic_constant();
584587
break;
585588
}
586589
case JVM_CONSTANT_InvokeDynamic: {
587-
const int name_and_type_ref_index =
588-
cp->bootstrap_name_and_type_ref_index_at(index);
590+
const auto bsref = cp->uncached_triple_ref_at(index, /*allow_malformed*/ true);
591+
const int name_and_type_ref_index = bsref.nt_index();
589592

590593
guarantee_property(valid_cp_range(name_and_type_ref_index, length) &&
591594
cp->tag_at(name_and_type_ref_index).is_name_and_type(),
592595
"Invalid constant pool index %u in class file %s",
593596
name_and_type_ref_index, CHECK);
594-
// bootstrap specifier index must be checked later,
597+
// bootstrap attribute index must be checked later,
595598
// when BootstrapMethods attr is available
596599
break;
597600
}
@@ -622,16 +625,15 @@ void ClassFileParser::parse_constant_pool(const ClassFileStream* const stream,
622625
}
623626
case JVM_CONSTANT_NameAndType: {
624627
if (_need_verify) {
625-
const int sig_index = cp->signature_ref_index_at(index);
626-
const int name_index = cp->name_ref_index_at(index);
627-
const Symbol* const name = cp->symbol_at(name_index);
628-
const Symbol* const sig = cp->symbol_at(sig_index);
628+
const auto ntp = cp->name_and_type_pair_at(index);
629+
const Symbol* const name = ntp.name(cp);
630+
const Symbol* const sig = ntp.signature(cp);
629631
guarantee_property(sig->utf8_length() != 0,
630632
"Illegal zero length constant pool entry at %d in class %s",
631-
sig_index, CHECK);
633+
ntp.signature_index(), CHECK);
632634
guarantee_property(name->utf8_length() != 0,
633635
"Illegal zero length constant pool entry at %d in class %s",
634-
name_index, CHECK);
636+
ntp.name_index(), CHECK);
635637

636638
if (Signature::is_method(sig)) {
637639
// Format check method name and signature
@@ -646,21 +648,13 @@ void ClassFileParser::parse_constant_pool(const ClassFileStream* const stream,
646648
break;
647649
}
648650
case JVM_CONSTANT_Dynamic: {
649-
const int name_and_type_ref_index =
650-
cp->uncached_name_and_type_ref_index_at(index);
651-
// already verified to be utf8
652-
const int name_ref_index =
653-
cp->name_ref_index_at(name_and_type_ref_index);
654-
// already verified to be utf8
655-
const int signature_ref_index =
656-
cp->signature_ref_index_at(name_and_type_ref_index);
657-
const Symbol* const name = cp->symbol_at(name_ref_index);
658-
const Symbol* const signature = cp->symbol_at(signature_ref_index);
659651
if (_need_verify) {
660652
// CONSTANT_Dynamic's name and signature are verified above, when iterating NameAndType_info.
661653
// Need only to be sure signature is the right type.
662-
if (Signature::is_method(signature)) {
663-
throwIllegalSignature("CONSTANT_Dynamic", name, signature, CHECK);
654+
const auto bsref = cp->uncached_triple_ref_at(index);
655+
// name, signature are already verified to be utf8
656+
if (Signature::is_method(bsref.signature(cp))) {
657+
throwIllegalSignature("CONSTANT_Dynamic", bsref.name(cp), bsref.signature(cp), CHECK);
664658
}
665659
}
666660
break;
@@ -669,16 +663,10 @@ void ClassFileParser::parse_constant_pool(const ClassFileStream* const stream,
669663
case JVM_CONSTANT_Fieldref:
670664
case JVM_CONSTANT_Methodref:
671665
case JVM_CONSTANT_InterfaceMethodref: {
672-
const int name_and_type_ref_index =
673-
cp->uncached_name_and_type_ref_index_at(index);
674-
// already verified to be utf8
675-
const int name_ref_index =
676-
cp->name_ref_index_at(name_and_type_ref_index);
677-
// already verified to be utf8
678-
const int signature_ref_index =
679-
cp->signature_ref_index_at(name_and_type_ref_index);
680-
const Symbol* const name = cp->symbol_at(name_ref_index);
681-
const Symbol* const signature = cp->symbol_at(signature_ref_index);
666+
const auto ref = cp->uncached_triple_ref_at(index);
667+
// name, signature are already verified to be utf8
668+
const Symbol* const name = ref.name(cp);
669+
const Symbol* const signature = ref.signature(cp);
682670
if (tag == JVM_CONSTANT_Fieldref) {
683671
if (_need_verify) {
684672
// Field name and signature are verified above, when iterating NameAndType_info.
@@ -703,7 +691,7 @@ void ClassFileParser::parse_constant_pool(const ClassFileStream* const stream,
703691
if (name != vmSymbols::object_initializer_name()) {
704692
classfile_parse_error(
705693
"Bad method name at constant pool index %u in class file %s",
706-
name_ref_index, THREAD);
694+
ref.name_index(), THREAD);
707695
return;
708696
} else if (!Signature::is_void_method(signature)) { // must have void signature.
709697
throwIllegalSignature("Method", name, signature, CHECK);
@@ -713,30 +701,27 @@ void ClassFileParser::parse_constant_pool(const ClassFileStream* const stream,
713701
break;
714702
}
715703
case JVM_CONSTANT_MethodHandle: {
716-
const int ref_index = cp->method_handle_index_at(index);
717-
const int ref_kind = cp->method_handle_ref_kind_at(index);
718-
switch (ref_kind) {
704+
const auto mhref = cp->method_handle_ref_at(index);
705+
const int ref_index = mhref.ref_index();
706+
switch (mhref.ref_kind()) {
719707
case JVM_REF_invokeVirtual:
720708
case JVM_REF_invokeStatic:
721709
case JVM_REF_invokeSpecial:
722710
case JVM_REF_newInvokeSpecial: {
723-
const int name_and_type_ref_index =
724-
cp->uncached_name_and_type_ref_index_at(ref_index);
725-
const int name_ref_index =
726-
cp->name_ref_index_at(name_and_type_ref_index);
727-
const Symbol* const name = cp->symbol_at(name_ref_index);
728-
if (ref_kind == JVM_REF_newInvokeSpecial) {
711+
const auto mref = cp->uncached_field_or_method_ref_at(ref_index);
712+
const Symbol* const name = mref.name(cp);
713+
if (mhref.ref_kind() == JVM_REF_newInvokeSpecial) {
729714
if (name != vmSymbols::object_initializer_name()) {
730715
classfile_parse_error(
731716
"Bad constructor name at constant pool index %u in class file %s",
732-
name_ref_index, THREAD);
717+
mref.name_index(), THREAD);
733718
return;
734719
}
735720
} else {
736721
if (name == vmSymbols::object_initializer_name()) {
737722
classfile_parse_error(
738723
"Bad method name at constant pool index %u in class file %s",
739-
name_ref_index, THREAD);
724+
mref.name_index(), THREAD);
740725
return;
741726
}
742727
}
@@ -747,9 +732,9 @@ void ClassFileParser::parse_constant_pool(const ClassFileStream* const stream,
747732
break;
748733
}
749734
case JVM_CONSTANT_MethodType: {
735+
const auto mtref = cp->method_type_ref_at(index);
750736
const Symbol* const no_name = vmSymbols::type_name(); // place holder
751-
const Symbol* const signature = cp->method_type_signature_at(index);
752-
verify_legal_method_signature(no_name, signature, CHECK);
737+
verify_legal_method_signature(no_name, mtref.signature(cp), CHECK);
753738
break;
754739
}
755740
case JVM_CONSTANT_Utf8: {
@@ -3281,12 +3266,12 @@ void ClassFileParser::parse_classfile_bootstrap_methods_attribute(const ClassFil
32813266

32823267
const int attribute_entry_count = cfs->get_u2_fast();
32833268

3284-
guarantee_property(_max_bootstrap_specifier_index < attribute_entry_count,
3269+
guarantee_property(_max_bsm_attribute_index < attribute_entry_count,
32853270
"Short length on BootstrapMethods in class file %s",
32863271
CHECK);
32873272

32883273
// The attribute contains a counted array of counted tuples of shorts,
3289-
// represending bootstrap specifiers:
3274+
// representing bootstrap entries:
32903275
// length*{bootstrap_method_index, argument_count, argument_count*{argument_index}}
32913276
const unsigned int attribute_tail_length = attribute_byte_length - (unsigned)sizeof(u2);
32923277

@@ -3343,6 +3328,7 @@ void ClassFileParser::parse_classfile_bootstrap_methods_attribute(const ClassFil
33433328
assert(next_entry == entries->length(), "");
33443329

33453330
// check access methods, for extra luck
3331+
if (false)//@@@
33463332
if (attribute_entry_count > 0) {
33473333
auto bsme = cp->bsm_attribute_entry(0);
33483334
assert(bsme->bootstrap_method_index() == entries->at(0), "");
@@ -3697,7 +3683,7 @@ void ClassFileParser::parse_classfile_attributes(const ClassFileStream* const cf
36973683
}
36983684
}
36993685

3700-
if (_max_bootstrap_specifier_index >= 0) {
3686+
if (_max_bsm_attribute_index >= 0) {
37013687
guarantee_property(parsed_bootstrap_methods_attribute,
37023688
"Missing BootstrapMethods attribute in class file %s", CHECK);
37033689
}
@@ -5344,7 +5330,7 @@ ClassFileParser::ClassFileParser(ClassFileStream* stream,
53445330
_has_contended_fields(false),
53455331
_has_finalizer(false),
53465332
_has_empty_finalizer(false),
5347-
_max_bootstrap_specifier_index(-1) {
5333+
_max_bsm_attribute_index(-1) {
53485334

53495335
_class_name = name != nullptr ? name : vmSymbols::unknown_class_name();
53505336
_class_name->increment_refcount();

src/hotspot/share/classfile/classFileParser.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class ClassFileParser {
195195
// precomputed flags
196196
bool _has_finalizer;
197197
bool _has_empty_finalizer;
198-
int _max_bootstrap_specifier_index; // detects BSS values
198+
int _max_bsm_attribute_index; // detects indexes into the BootstrapMethods attr
199199

200200
void parse_stream(const ClassFileStream* const stream, TRAPS);
201201

src/hotspot/share/interpreter/bytecodeTracer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,11 @@ void BytecodePrinter::print_invokedynamic(int indy_index, int cp_index, outputSt
307307

308308
// cp_index: must be the cp_index of a JVM_CONSTANT_{Dynamic, DynamicInError, InvokeDynamic}
309309
void BytecodePrinter::print_bsm(int cp_index, outputStream* st) {
310-
assert(constants()->tag_at(cp_index).has_bootstrap(), "must be");
311-
int bsm = constants()->bootstrap_methods_attribute_index(cp_index);
310+
const auto indy = constants()->uncached_bootstrap_specifier_ref_at(cp_index);
311+
const auto bsme = indy.bsme(constants());
312+
const auto bsmh = bsme->bootstrap_method(constants());
312313
const char* ref_kind = "";
313-
switch (constants()->method_handle_ref_kind_at(bsm)) {
314+
switch (bsmh.ref_kind()) {
314315
case JVM_REF_getField : ref_kind = "REF_getField"; break;
315316
case JVM_REF_getStatic : ref_kind = "REF_getStatic"; break;
316317
case JVM_REF_putField : ref_kind = "REF_putField"; break;
@@ -323,8 +324,7 @@ void BytecodePrinter::print_bsm(int cp_index, outputStream* st) {
323324
default : ShouldNotReachHere();
324325
}
325326
st->print(" BSM: %s", ref_kind);
326-
print_field_or_method(constants()->method_handle_index_at(bsm), st);
327-
auto bsme = constants()->bootstrap_methods_attribute_entry(cp_index);
327+
print_field_or_method(bsmh.ref_index(), st);
328328
int argc = bsme->argument_count();;
329329
st->print(" arguments[%d] = {", argc);
330330
if (argc > 0) {

src/hotspot/share/oops/constantPool.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,8 @@ void ConstantPool::resize_bsm_data(int delta_len, int delta_size, TRAPS) {
15921592

15931593
// Copy the old array data. We do not need to change any offsets.
15941594
if (have_old) {
1595+
guarantee(min_offs_len > 0 && min_data_len > 0,
1596+
"must have something to copy %d/%d", min_offs_len, min_data_len);
15951597
Copy::conjoint_memory_atomic(old_offs->adr_at(0),
15961598
new_offs->adr_at(0),
15971599
min_offs_len * sizeof(u4));
@@ -1636,9 +1638,20 @@ void ConstantPool::shrink_bsm_data(int new_len, TRAPS) {
16361638
}
16371639
assert(new_len < old_len, "shrunken bsm_data array must be smaller");
16381640

1639-
int new_data_len = bsm_attribute_offsets()->at(new_len); //offset
1640-
int old_data_len = bsm_attribute_entries()->length(); //length
16411641
int delta_len = new_len - old_len;
1642+
1643+
int old_data_len = bsm_attribute_entries()->length(); //length
1644+
int new_data_len = 0;
1645+
if (new_len > 0) {
1646+
// This is tricky: we cannot trust any offset or data at new_len or beyond.
1647+
// So, work forward from the last valid BSM entry.
1648+
int last_bsme_offset = bsm_attribute_offsets()->at(new_len - 1);
1649+
int last_bsme_header = sizeof(BSMAttributeEntry) / sizeof(u2);
1650+
assert(last_bsme_header == 2, "bsm+argc");
1651+
new_data_len = (last_bsme_offset + last_bsme_header +
1652+
bsm_attribute_entry(new_len - 1)->argument_count());
1653+
}
1654+
16421655
int delta_size = new_data_len - old_data_len;
16431656

16441657
resize_bsm_data(delta_len, delta_size, CHECK);
@@ -2525,7 +2538,8 @@ void ConstantPool::print_entry_on(const int cp_index, outputStream* st) {
25252538
}
25262539
break;
25272540
default:
2528-
ShouldNotReachHere();
2541+
// print something, because this is for debugging
2542+
st->print("? (tag=%d)", tag_at(cp_index).value());
25292543
break;
25302544
}
25312545
st->cr();

0 commit comments

Comments
 (0)