8307331: Correctly update line maps when class redefine rewrites bytecodes

Reviewed-by: sspitsyn
(cherry picked from commit f94f957734)
This commit is contained in:
Andrew Dinn
2023-05-05 07:50:21 +00:00
committed by Vitaly Provodin
parent 85359356fd
commit 3911f60ab6

View File

@@ -407,11 +407,24 @@ void Relocator::adjust_exception_table(int bci, int delta) {
}
}
static void print_linenumber_table(unsigned char* table) {
CompressedLineNumberReadStream stream(table);
tty->print_cr("-------------------------------------------------");
while (stream.read_pair()) {
tty->print_cr(" - line %d: %d", stream.line(), stream.bci());
}
tty->print_cr("-------------------------------------------------");
}
// The width of instruction at "bci" is changing by "delta". Adjust the line number table.
void Relocator::adjust_line_no_table(int bci, int delta) {
if (method()->has_linenumber_table()) {
CompressedLineNumberReadStream reader(method()->compressed_linenumber_table());
// if we already made adjustments then use the updated table
unsigned char *table = compressed_line_number_table();
if (table == nullptr) {
table = method()->compressed_linenumber_table();
}
CompressedLineNumberReadStream reader(table);
CompressedLineNumberWriteStream writer(64); // plenty big for most line number tables
while (reader.read_pair()) {
int adjustment = (reader.bci() > bci) ? delta : 0;
@@ -420,6 +433,10 @@ void Relocator::adjust_line_no_table(int bci, int delta) {
writer.write_terminator();
set_compressed_line_number_table(writer.buffer());
set_compressed_line_number_table_size(writer.position());
if (TraceRelocator) {
tty->print_cr("Adjusted line number table");
print_linenumber_table(compressed_line_number_table());
}
}
}