@@ -143,21 +143,24 @@ void IdealGraphPrinter::init(const char* file_name, bool use_multiple_files, boo
143
143
_depth = 0 ;
144
144
_current_method = nullptr ;
145
145
_network_stream = nullptr ;
146
+ _append = append;
146
147
147
148
if (file_name != nullptr ) {
148
- init_file_stream (file_name, use_multiple_files, append );
149
+ init_file_stream (file_name, use_multiple_files);
149
150
} else {
150
151
init_network_stream ();
151
152
}
152
153
_xml = new (mtCompiler) xmlStream (_output);
153
- if (!append ) {
154
+ if (!_append ) {
154
155
head (TOP_ELEMENT);
155
156
}
156
157
}
157
158
158
159
// Destructor, close file or network stream
159
160
IdealGraphPrinter::~IdealGraphPrinter () {
160
- tail (TOP_ELEMENT);
161
+ if (!_append) {
162
+ tail (TOP_ELEMENT);
163
+ }
161
164
162
165
// tty->print_cr("Walk time: %d", (int)_walk_time.milliseconds());
163
166
// tty->print_cr("Output time: %d", (int)_output_time.milliseconds());
@@ -860,10 +863,10 @@ void IdealGraphPrinter::print(const char *name, Node *node) {
860
863
_xml->flush ();
861
864
}
862
865
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) {
864
867
ThreadCritical tc;
865
868
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" );
867
870
ResourceMark rm;
868
871
stringStream st;
869
872
const char * dot = strrchr (file_name, ' .' );
@@ -875,10 +878,10 @@ void IdealGraphPrinter::init_file_stream(const char* file_name, bool use_multipl
875
878
}
876
879
_output = new (mtCompiler) fileStream (st.as_string (), " w" );
877
880
} else {
878
- _output = new (mtCompiler) fileStream (file_name, append ? " a" : " w" );
881
+ _output = new (mtCompiler) fileStream (file_name, _append ? " a" : " w" );
879
882
}
880
883
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" );
882
885
_file_count++;
883
886
}
884
887
}
@@ -909,9 +912,16 @@ void IdealGraphPrinter::update_compiled_method(ciMethod* current_method) {
909
912
assert (C != nullptr , " must already be set" );
910
913
if (current_method != _current_method) {
911
914
// 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
+ }
915
925
}
916
926
}
917
927
0 commit comments