@@ -141,21 +141,24 @@ void IdealGraphPrinter::init(const char* file_name, bool use_multiple_files, boo
141
141
_depth = 0 ;
142
142
_current_method = nullptr ;
143
143
_network_stream = nullptr ;
144
+ _append = append;
144
145
145
146
if (file_name != nullptr ) {
146
- init_file_stream (file_name, use_multiple_files, append );
147
+ init_file_stream (file_name, use_multiple_files);
147
148
} else {
148
149
init_network_stream ();
149
150
}
150
151
_xml = new (ResourceObj::C_HEAP, mtCompiler) xmlStream (_output);
151
- if (!append ) {
152
+ if (!_append ) {
152
153
head (TOP_ELEMENT);
153
154
}
154
155
}
155
156
156
157
// Destructor, close file or network stream
157
158
IdealGraphPrinter::~IdealGraphPrinter () {
158
- tail (TOP_ELEMENT);
159
+ if (!_append) {
160
+ tail (TOP_ELEMENT);
161
+ }
159
162
160
163
// tty->print_cr("Walk time: %d", (int)_walk_time.milliseconds());
161
164
// tty->print_cr("Output time: %d", (int)_output_time.milliseconds());
@@ -729,10 +732,10 @@ void IdealGraphPrinter::print(const char *name, Node *node) {
729
732
_xml->flush ();
730
733
}
731
734
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) {
733
736
ThreadCritical tc;
734
737
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" );
736
739
ResourceMark rm;
737
740
stringStream st;
738
741
const char * dot = strrchr (file_name, ' .' );
@@ -744,10 +747,10 @@ void IdealGraphPrinter::init_file_stream(const char* file_name, bool use_multipl
744
747
}
745
748
_output = new (ResourceObj::C_HEAP, mtCompiler) fileStream (st.as_string (), " w" );
746
749
} 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" );
748
751
}
749
752
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" );
751
754
_file_count++;
752
755
}
753
756
}
@@ -778,9 +781,16 @@ void IdealGraphPrinter::update_compiled_method(ciMethod* current_method) {
778
781
assert (C != nullptr , " must already be set" );
779
782
if (current_method != _current_method) {
780
783
// 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
+ }
784
794
}
785
795
}
786
796
0 commit comments