Skip to content

Commit ae7be19

Browse files
MaxXSoftPaul Hohensee
authored andcommitted
8335536: Fix assertion failure in IdealGraphPrinter when append is true
Reviewed-by: phh Backport-of: 6db4c6a772df856fc3099c32a5b2c102a30d360c
1 parent 1f14f86 commit ae7be19

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
@@ -141,21 +141,24 @@ void IdealGraphPrinter::init(const char* file_name, bool use_multiple_files, boo
141141
_depth = 0;
142142
_current_method = nullptr;
143143
_network_stream = nullptr;
144+
_append = append;
144145

145146
if (file_name != nullptr) {
146-
init_file_stream(file_name, use_multiple_files, append);
147+
init_file_stream(file_name, use_multiple_files);
147148
} else {
148149
init_network_stream();
149150
}
150151
_xml = new (ResourceObj::C_HEAP, mtCompiler) xmlStream(_output);
151-
if (!append) {
152+
if (!_append) {
152153
head(TOP_ELEMENT);
153154
}
154155
}
155156

156157
// Destructor, close file or network stream
157158
IdealGraphPrinter::~IdealGraphPrinter() {
158-
tail(TOP_ELEMENT);
159+
if (!_append) {
160+
tail(TOP_ELEMENT);
161+
}
159162

160163
// tty->print_cr("Walk time: %d", (int)_walk_time.milliseconds());
161164
// tty->print_cr("Output time: %d", (int)_output_time.milliseconds());
@@ -729,10 +732,10 @@ void IdealGraphPrinter::print(const char *name, Node *node) {
729732
_xml->flush();
730733
}
731734

732-
void IdealGraphPrinter::init_file_stream(const char* file_name, bool use_multiple_files, bool append) {
735+
void IdealGraphPrinter::init_file_stream(const char* file_name, bool use_multiple_files) {
733736
ThreadCritical tc;
734737
if (use_multiple_files && _file_count != 0) {
735-
assert(!append, "append should only be used for debugging with a single file");
738+
assert(!_append, "append should only be used for debugging with a single file");
736739
ResourceMark rm;
737740
stringStream st;
738741
const char* dot = strrchr(file_name, '.');
@@ -744,10 +747,10 @@ void IdealGraphPrinter::init_file_stream(const char* file_name, bool use_multipl
744747
}
745748
_output = new (ResourceObj::C_HEAP, mtCompiler) fileStream(st.as_string(), "w");
746749
} else {
747-
_output = new (ResourceObj::C_HEAP, mtCompiler) fileStream(file_name, append ? "a" : "w");
750+
_output = new (ResourceObj::C_HEAP, mtCompiler) fileStream(file_name, _append ? "a" : "w");
748751
}
749752
if (use_multiple_files) {
750-
assert(!append, "append should only be used for debugging with a single file");
753+
assert(!_append, "append should only be used for debugging with a single file");
751754
_file_count++;
752755
}
753756
}
@@ -778,9 +781,16 @@ void IdealGraphPrinter::update_compiled_method(ciMethod* current_method) {
778781
assert(C != nullptr, "must already be set");
779782
if (current_method != _current_method) {
780783
// If a different method, end the old and begin with the new one.
781-
end_method();
782-
_current_method = nullptr;
783-
begin_method();
784+
if (_append) {
785+
// Do not call `end_method` if we are appending, just update `_current_method`,
786+
// because `begin_method` is not called in the constructor in append mode.
787+
_current_method = current_method;
788+
} else {
789+
// End the old method and begin a new one.
790+
// Don't worry about `_current_method`, `end_method` will clear it.
791+
end_method();
792+
begin_method();
793+
}
784794
}
785795
}
786796

src/hotspot/share/opto/idealGraphPrinter.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class IdealGraphPrinter : public CHeapObj<mtCompiler> {
9393
bool _traverse_outs;
9494
Compile *C;
9595
double _max_freq;
96+
bool _append;
9697

9798
void print_method(ciMethod *method, int bci, InlineTree *tree);
9899
void print_inline_tree(InlineTree *tree);
@@ -110,7 +111,7 @@ class IdealGraphPrinter : public CHeapObj<mtCompiler> {
110111
void head(const char *name);
111112
void text(const char *s);
112113
void init(const char* file_name, bool use_multiple_files, bool append);
113-
void init_file_stream(const char* file_name, bool use_multiple_files, bool append);
114+
void init_file_stream(const char* file_name, bool use_multiple_files);
114115
void init_network_stream();
115116
IdealGraphPrinter();
116117
~IdealGraphPrinter();

0 commit comments

Comments
 (0)