diff --git a/src/hotspot/share/opto/idealGraphPrinter.cpp b/src/hotspot/share/opto/idealGraphPrinter.cpp index d5858b4bb3f0e..1f0fec8b58a42 100644 --- a/src/hotspot/share/opto/idealGraphPrinter.cpp +++ b/src/hotspot/share/opto/idealGraphPrinter.cpp @@ -609,23 +609,7 @@ void IdealGraphPrinter::visit_node(Node *n, bool edges, VectorSet* temp_set) { } } - if (caller != nullptr) { - stringStream bciStream; - ciMethod* last = nullptr; - int last_bci; - while(caller) { - if (caller->has_method()) { - last = caller->method(); - last_bci = caller->bci(); - } - bciStream.print("%d ", caller->bci()); - caller = caller->caller(); - } - print_prop("bci", bciStream.freeze()); - if (last != nullptr && last->has_linenumber_table() && last_bci >= 0) { - print_prop("line", last->line_number_from_bci(last_bci)); - } - } + print_bci_and_line_number(caller); #ifdef ASSERT if (node->debug_orig() != nullptr) { @@ -654,6 +638,35 @@ void IdealGraphPrinter::visit_node(Node *n, bool edges, VectorSet* temp_set) { } } +void IdealGraphPrinter::print_bci_and_line_number(JVMState* caller) { + if (caller != nullptr) { + ResourceMark rm; + stringStream bciStream; + stringStream lineStream; + + // Print line and bci numbers for the callee and all entries in the call stack until we reach the root method. + while (caller) { + const int bci = caller->bci(); + bool appended_line = false; + if (caller->has_method()) { + ciMethod* method = caller->method(); + if (method->has_linenumber_table() && bci >= 0) { + lineStream.print("%d ", method->line_number_from_bci(bci)); + appended_line = true; + } + } + if (!appended_line) { + lineStream.print("%s ", "_"); + } + bciStream.print("%d ", bci); + caller = caller->caller(); + } + + print_prop("bci", bciStream.freeze()); + print_prop("line", lineStream.freeze()); + } +} + void IdealGraphPrinter::print_field(const Node* node) { buffer[0] = 0; stringStream ss(buffer, sizeof(buffer) - 1); diff --git a/src/hotspot/share/opto/idealGraphPrinter.hpp b/src/hotspot/share/opto/idealGraphPrinter.hpp index aff139a82e3fa..11b0b6e5ea169 100644 --- a/src/hotspot/share/opto/idealGraphPrinter.hpp +++ b/src/hotspot/share/opto/idealGraphPrinter.hpp @@ -40,6 +40,7 @@ class Matcher; class Node; class InlineTree; class ciMethod; +class JVMState; class IdealGraphPrinter : public CHeapObj { private: @@ -96,9 +97,10 @@ class IdealGraphPrinter : public CHeapObj { Compile *C; double _max_freq; - void print_method(ciMethod *method, int bci, InlineTree *tree); - void print_inline_tree(InlineTree *tree); - void visit_node(Node *n, bool edges, VectorSet* temp_set); + void print_method(ciMethod* method, int bci, InlineTree* tree); + void print_inline_tree(InlineTree* tree); + void visit_node(Node* n, bool edges, VectorSet* temp_set); + void print_bci_and_line_number(JVMState* caller); void print_field(const Node* node); ciField* get_field(const Node* node); ciField* find_source_field_of_array_access(const Node* node, uint& depth);