Skip to content

Commit 6db4c6a

Browse files
MaxXSoftTobiHartmann
authored andcommitted
8335536: Fix assertion failure in IdealGraphPrinter when append is true
Reviewed-by: thartmann, chagedorn, tholenstein
1 parent 350f9c1 commit 6db4c6a

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());
@@ -860,10 +863,10 @@ void IdealGraphPrinter::print(const char *name, Node *node) {
860863
_xml->flush();
861864
}
862865

863-
void IdealGraphPrinter::init_file_stream(const char* file_name, bool use_multiple_files, bool append) {
866+
void IdealGraphPrinter::init_file_stream(const char* file_name, bool use_multiple_files) {
864867
ThreadCritical tc;
865868
if (use_multiple_files && _file_count != 0) {
866-
assert(!append, "append should only be used for debugging with a single file");
869+
assert(!_append, "append should only be used for debugging with a single file");
867870
ResourceMark rm;
868871
stringStream st;
869872
const char* dot = strrchr(file_name, '.');
@@ -875,10 +878,10 @@ void IdealGraphPrinter::init_file_stream(const char* file_name, bool use_multipl
875878
}
876879
_output = new (mtCompiler) fileStream(st.as_string(), "w");
877880
} else {
878-
_output = new (mtCompiler) fileStream(file_name, append ? "a" : "w");
881+
_output = new (mtCompiler) fileStream(file_name, _append ? "a" : "w");
879882
}
880883
if (use_multiple_files) {
881-
assert(!append, "append should only be used for debugging with a single file");
884+
assert(!_append, "append should only be used for debugging with a single file");
882885
_file_count++;
883886
}
884887
}
@@ -909,9 +912,16 @@ void IdealGraphPrinter::update_compiled_method(ciMethod* current_method) {
909912
assert(C != nullptr, "must already be set");
910913
if (current_method != _current_method) {
911914
// If a different method, end the old and begin with the new one.
912-
end_method();
913-
_current_method = nullptr;
914-
begin_method();
915+
if (_append) {
916+
// Do not call `end_method` if we are appending, just update `_current_method`,
917+
// because `begin_method` is not called in the constructor in append mode.
918+
_current_method = current_method;
919+
} else {
920+
// End the old method and begin a new one.
921+
// Don't worry about `_current_method`, `end_method` will clear it.
922+
end_method();
923+
begin_method();
924+
}
915925
}
916926
}
917927

src/hotspot/share/opto/idealGraphPrinter.hpp

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

100101
void print_method(ciMethod* method, int bci, InlineTree* tree);
101102
void print_inline_tree(InlineTree* tree);
@@ -118,7 +119,7 @@ class IdealGraphPrinter : public CHeapObj<mtCompiler> {
118119
void head(const char *name);
119120
void text(const char *s);
120121
void init(const char* file_name, bool use_multiple_files, bool append);
121-
void init_file_stream(const char* file_name, bool use_multiple_files, bool append);
122+
void init_file_stream(const char* file_name, bool use_multiple_files);
122123
void init_network_stream();
123124
IdealGraphPrinter();
124125
~IdealGraphPrinter();

0 commit comments

Comments
 (0)