Skip to content

Commit

Permalink
8335536: Fix assertion failure in IdealGraphPrinter when append is true
Browse files Browse the repository at this point in the history
Reviewed-by: thartmann, chagedorn, tholenstein
  • Loading branch information
MaxXSoft authored and TobiHartmann committed Jul 3, 2024
1 parent 350f9c1 commit 6db4c6a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
30 changes: 20 additions & 10 deletions src/hotspot/share/opto/idealGraphPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,24 @@ void IdealGraphPrinter::init(const char* file_name, bool use_multiple_files, boo
_depth = 0;
_current_method = nullptr;
_network_stream = nullptr;
_append = append;

if (file_name != nullptr) {
init_file_stream(file_name, use_multiple_files, append);
init_file_stream(file_name, use_multiple_files);
} else {
init_network_stream();
}
_xml = new (mtCompiler) xmlStream(_output);
if (!append) {
if (!_append) {
head(TOP_ELEMENT);
}
}

// Destructor, close file or network stream
IdealGraphPrinter::~IdealGraphPrinter() {
tail(TOP_ELEMENT);
if (!_append) {
tail(TOP_ELEMENT);
}

// tty->print_cr("Walk time: %d", (int)_walk_time.milliseconds());
// tty->print_cr("Output time: %d", (int)_output_time.milliseconds());
Expand Down Expand Up @@ -860,10 +863,10 @@ void IdealGraphPrinter::print(const char *name, Node *node) {
_xml->flush();
}

void IdealGraphPrinter::init_file_stream(const char* file_name, bool use_multiple_files, bool append) {
void IdealGraphPrinter::init_file_stream(const char* file_name, bool use_multiple_files) {
ThreadCritical tc;
if (use_multiple_files && _file_count != 0) {
assert(!append, "append should only be used for debugging with a single file");
assert(!_append, "append should only be used for debugging with a single file");
ResourceMark rm;
stringStream st;
const char* dot = strrchr(file_name, '.');
Expand All @@ -875,10 +878,10 @@ void IdealGraphPrinter::init_file_stream(const char* file_name, bool use_multipl
}
_output = new (mtCompiler) fileStream(st.as_string(), "w");
} else {
_output = new (mtCompiler) fileStream(file_name, append ? "a" : "w");
_output = new (mtCompiler) fileStream(file_name, _append ? "a" : "w");
}
if (use_multiple_files) {
assert(!append, "append should only be used for debugging with a single file");
assert(!_append, "append should only be used for debugging with a single file");
_file_count++;
}
}
Expand Down Expand Up @@ -909,9 +912,16 @@ void IdealGraphPrinter::update_compiled_method(ciMethod* current_method) {
assert(C != nullptr, "must already be set");
if (current_method != _current_method) {
// If a different method, end the old and begin with the new one.
end_method();
_current_method = nullptr;
begin_method();
if (_append) {
// Do not call `end_method` if we are appending, just update `_current_method`,
// because `begin_method` is not called in the constructor in append mode.
_current_method = current_method;
} else {
// End the old method and begin a new one.
// Don't worry about `_current_method`, `end_method` will clear it.
end_method();
begin_method();
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/share/opto/idealGraphPrinter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class IdealGraphPrinter : public CHeapObj<mtCompiler> {
bool _traverse_outs;
Compile *C;
double _max_freq;
bool _append;

void print_method(ciMethod* method, int bci, InlineTree* tree);
void print_inline_tree(InlineTree* tree);
Expand All @@ -118,7 +119,7 @@ class IdealGraphPrinter : public CHeapObj<mtCompiler> {
void head(const char *name);
void text(const char *s);
void init(const char* file_name, bool use_multiple_files, bool append);
void init_file_stream(const char* file_name, bool use_multiple_files, bool append);
void init_file_stream(const char* file_name, bool use_multiple_files);
void init_network_stream();
IdealGraphPrinter();
~IdealGraphPrinter();
Expand Down

5 comments on commit 6db4c6a

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaxXSoft
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 6db4c6a Jul 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaxXSoft the backport was successfully created on the branch backport-MaxXSoft-6db4c6a7-master in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 6db4c6a7 from the openjdk/jdk repository.

The commit being backported was authored by Qizheng Xing on 3 Jul 2024 and was reviewed by Tobias Hartmann, Christian Hagedorn and Tobias Holenstein.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-MaxXSoft-6db4c6a7-master:backport-MaxXSoft-6db4c6a7-master
$ git checkout backport-MaxXSoft-6db4c6a7-master
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-MaxXSoft-6db4c6a7-master

⚠️ @MaxXSoft You are not yet a collaborator in my fork openjdk-bots/jdk21u-dev. An invite will be sent out and you need to accept it before you can proceed.

@MaxXSoft
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk23u

@openjdk
Copy link

@openjdk openjdk bot commented on 6db4c6a Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaxXSoft the backport was successfully created on the branch backport-MaxXSoft-6db4c6a7-master in my personal fork of openjdk/jdk23u. To create a pull request with this backport targeting openjdk/jdk23u:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 6db4c6a7 from the openjdk/jdk repository.

The commit being backported was authored by Qizheng Xing on 3 Jul 2024 and was reviewed by Tobias Hartmann, Christian Hagedorn and Tobias Holenstein.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk23u:

$ git fetch https://github.com/openjdk-bots/jdk23u.git backport-MaxXSoft-6db4c6a7-master:backport-MaxXSoft-6db4c6a7-master
$ git checkout backport-MaxXSoft-6db4c6a7-master
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk23u.git backport-MaxXSoft-6db4c6a7-master

⚠️ @MaxXSoft You are not yet a collaborator in my fork openjdk-bots/jdk23u. An invite will be sent out and you need to accept it before you can proceed.

Please sign in to comment.