Skip to content

Commit 8a0dd93

Browse files
MaxXSoftshipilev
authored andcommitted
8335536: Fix assertion failure in IdealGraphPrinter when append is true
Backport-of: 6db4c6a772df856fc3099c32a5b2c102a30d360c
1 parent 9677a85 commit 8a0dd93

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/hotspot/share/opto/idealGraphPrinter.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,21 +143,24 @@ void IdealGraphPrinter::init(const char* file_name, bool use_multiple_files, boo
143143
_depth = 0;
144144
_current_method = nullptr;
145145
_network_stream = nullptr;
146+
_append = append;
146147

147148
if (file_name != nullptr) {
148-
init_file_stream(file_name, use_multiple_files, append);
149+
init_file_stream(file_name, use_multiple_files);
149150
} else {
150151
init_network_stream();
151152
}
152153
_xml = new (mtCompiler) xmlStream(_output);
153-
if (!append) {
154+
if (!_append) {
154155
head(TOP_ELEMENT);
155156
}
156157
}
157158

158159
// Destructor, close file or network stream
159160
IdealGraphPrinter::~IdealGraphPrinter() {
160-
tail(TOP_ELEMENT);
161+
if (!_append) {
162+
tail(TOP_ELEMENT);
163+
}
161164

162165
// tty->print_cr("Walk time: %d", (int)_walk_time.milliseconds());
163166
// tty->print_cr("Output time: %d", (int)_output_time.milliseconds());
@@ -830,10 +833,10 @@ void IdealGraphPrinter::print(const char *name, Node *node) {
830833
_xml->flush();
831834
}
832835

833-
void IdealGraphPrinter::init_file_stream(const char* file_name, bool use_multiple_files, bool append) {
836+
void IdealGraphPrinter::init_file_stream(const char* file_name, bool use_multiple_files) {
834837
ThreadCritical tc;
835838
if (use_multiple_files && _file_count != 0) {
836-
assert(!append, "append should only be used for debugging with a single file");
839+
assert(!_append, "append should only be used for debugging with a single file");
837840
ResourceMark rm;
838841
stringStream st;
839842
const char* dot = strrchr(file_name, '.');
@@ -845,10 +848,10 @@ void IdealGraphPrinter::init_file_stream(const char* file_name, bool use_multipl
845848
}
846849
_output = new (mtCompiler) fileStream(st.as_string(), "w");
847850
} else {
848-
_output = new (mtCompiler) fileStream(file_name, append ? "a" : "w");
851+
_output = new (mtCompiler) fileStream(file_name, _append ? "a" : "w");
849852
}
850853
if (use_multiple_files) {
851-
assert(!append, "append should only be used for debugging with a single file");
854+
assert(!_append, "append should only be used for debugging with a single file");
852855
_file_count++;
853856
}
854857
}
@@ -879,9 +882,16 @@ void IdealGraphPrinter::update_compiled_method(ciMethod* current_method) {
879882
assert(C != nullptr, "must already be set");
880883
if (current_method != _current_method) {
881884
// If a different method, end the old and begin with the new one.
882-
end_method();
883-
_current_method = nullptr;
884-
begin_method();
885+
if (_append) {
886+
// Do not call `end_method` if we are appending, just update `_current_method`,
887+
// because `begin_method` is not called in the constructor in append mode.
888+
_current_method = current_method;
889+
} else {
890+
// End the old method and begin a new one.
891+
// Don't worry about `_current_method`, `end_method` will clear it.
892+
end_method();
893+
begin_method();
894+
}
885895
}
886896
}
887897

src/hotspot/share/opto/idealGraphPrinter.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class IdealGraphPrinter : public CHeapObj<mtCompiler> {
9595
bool _traverse_outs;
9696
Compile *C;
9797
double _max_freq;
98+
bool _append;
9899

99100
void print_method(ciMethod *method, int bci, InlineTree *tree);
100101
void print_inline_tree(InlineTree *tree);
@@ -116,7 +117,7 @@ class IdealGraphPrinter : public CHeapObj<mtCompiler> {
116117
void head(const char *name);
117118
void text(const char *s);
118119
void init(const char* file_name, bool use_multiple_files, bool append);
119-
void init_file_stream(const char* file_name, bool use_multiple_files, bool append);
120+
void init_file_stream(const char* file_name, bool use_multiple_files);
120121
void init_network_stream();
121122
IdealGraphPrinter();
122123
~IdealGraphPrinter();

0 commit comments

Comments
 (0)