@@ -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
159160IdealGraphPrinter::~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
0 commit comments