@@ -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());
@@ -830,10 +833,10 @@ void IdealGraphPrinter::print(const char *name, Node *node) {
830
833
_xml->flush ();
831
834
}
832
835
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) {
834
837
ThreadCritical tc;
835
838
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" );
837
840
ResourceMark rm;
838
841
stringStream st;
839
842
const char * dot = strrchr (file_name, ' .' );
@@ -845,10 +848,10 @@ void IdealGraphPrinter::init_file_stream(const char* file_name, bool use_multipl
845
848
}
846
849
_output = new (mtCompiler) fileStream (st.as_string (), " w" );
847
850
} else {
848
- _output = new (mtCompiler) fileStream (file_name, append ? " a" : " w" );
851
+ _output = new (mtCompiler) fileStream (file_name, _append ? " a" : " w" );
849
852
}
850
853
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" );
852
855
_file_count++;
853
856
}
854
857
}
@@ -879,9 +882,16 @@ void IdealGraphPrinter::update_compiled_method(ciMethod* current_method) {
879
882
assert (C != nullptr , " must already be set" );
880
883
if (current_method != _current_method) {
881
884
// 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
+ }
885
895
}
886
896
}
887
897
0 commit comments