Skip to content

8365829: Multiple definitions of static 'phase_names' #26851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

fandreuz
Copy link
Contributor

@fandreuz fandreuz commented Aug 20, 2025

  • opto/phasetype.hpp defines static const char* phase_names[]
  • compiler/compilerEvent.cpp defines static GrowableArray<const char*>* phase_names

This is not a problem when the two files are compiled as different translation units, but it causes a build failure if any of them is pulled in by a precompiled header:

/jdk/src/hotspot/share/compiler/compilerEvent.cpp:59:36: error: redefinition of 'phase_names' with a different type: 'GrowableArray<const char *> *' vs 'const char *[100]'
   59 | static GrowableArray<const char*>* phase_names = nullptr;
      | ^
/jdk/src/hotspot/share/opto/phasetype.hpp:147:20: note: previous definition is here
  147 | static const char* phase_names[] = {
      | ^
/jdk/src/hotspot/share/compiler/compilerEvent.cpp:67:39: error: member reference base type 'const char *' is not a structure or union
   67 | const u4 nof_entries = phase_names->length();
      | ~~~~~~~~~~~^ ~~~~~~
/jdk/src/hotspot/share/compiler/compilerEvent.cpp:71:31: error: member reference base type 'const char *' is not a structure or union
   71 | writer.write(phase_names->at(i));
      | ~~~~~~~~~~~^ ~~
/jdk/src/hotspot/share/compiler/compilerEvent.cpp:77:34: error: member reference base type 'const char *' is not a structure or union
   77 | for (int i = 0; i < phase_names->length(); i++) {
      | ~~~~~~~~~~~^ ~~~~~~
/jdk/src/hotspot/share/compiler/compilerEvent.cpp:78:35: error: member reference base type 'const char *' is not a structure or union
   78 | const char* name = phase_names->at(i);
      | ~~~~~~~~~~~^ ~~
/jdk/src/hotspot/share/compiler/compilerEvent.cpp:91:9: error: comparison of array 'phase_names' equal to a null pointer is always false [-Werror,-Wtautological-pointer-compare]
   91 | if (phase_names == nullptr) {
      | ^~~~~~~~~~~ ~~~~~~~
/jdk/src/hotspot/share/compiler/compilerEvent.cpp:92:19: error: array type 'const char *[100]' is not assignable
   92 | phase_names = new (mtInternal) GrowableArray<const char*>(100, mtCompiler);
      | ~~~~~~~~~~~ ^
/jdk/src/hotspot/share/compiler/compilerEvent.cpp:103:24: error: member reference base type 'const char *' is not a structure or union
  103 | index = phase_names->length();
      | ~~~~~~~~~~~^ ~~~~~~
/jdk/src/hotspot/share/compiler/compilerEvent.cpp:104:16: error: member reference base type 'const char *' is not a structure or union
  104 | phase_names->append(use_strdup ? os::strdup(phase_name) : phase_name);
      | ~~~~~~~~~~~^ ~~~~~~
9 errors generated.

Passes tier1.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8365829: Multiple definitions of static 'phase_names' (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26851/head:pull/26851
$ git checkout pull/26851

Update a local copy of the PR:
$ git checkout pull/26851
$ git pull https://git.openjdk.org/jdk.git pull/26851/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26851

View PR using the GUI difftool:
$ git pr show -t 26851

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26851.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 20, 2025

👋 Welcome back fandreuz! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Aug 20, 2025

@fandreuz This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8365829: Multiple definitions of static 'phase_names'

Reviewed-by: kbarrett

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 47 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@kimbarrett) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk
Copy link

openjdk bot commented Aug 20, 2025

@fandreuz The following label will be automatically applied to this pull request:

  • hotspot-compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added hotspot-compiler [email protected] rfr Pull request is ready for review labels Aug 20, 2025
@mlbridge
Copy link

mlbridge bot commented Aug 20, 2025

Webrevs

@openjdk
Copy link

openjdk bot commented Aug 20, 2025

⚠️ @fandreuz This pull request contains merges that bring in commits not present in the target repository. Since this is not a "merge style" pull request, these changes will be squashed when this pull request in integrated. If this is your intention, then please ignore this message. If you want to preserve the commit structure, you must change the title of this pull request to Merge <project>:<branch> where <project> is the name of another project in the OpenJDK organization (for example Merge jdk:master).

class CompilerPhaseTypeHelper {
public:
static const char* phase_descriptions[];
static const char* phase_names[];

Choose a reason for hiding this comment

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

Is there a reason for these to be public rather than private?
Also, we "always" prefix data member names with a leading underscore; see Style Guide.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

phase_name is accessed by static CompilerPhaseType find_phase, should we make it a friend of the CompilerPhaseTypeHelper?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Underscore: 90e9c53

Choose a reason for hiding this comment

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

Don't make it a friend, make it a static member function, and fix the one
caller (later in this file). (The definition of find_phase could be moved to
the new .cpp file.) I think the caller also has an ODR problem, with calls
from different including TUs getting a different file-scoped find_phase.

It looks like there might be a lot of file-scoped static declarations from
header files in our code. I've made a note to look into this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure: cc7da3a

Copy link

@kimbarrett kimbarrett left a comment

Choose a reason for hiding this comment

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

Looks good.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 21, 2025
@fandreuz
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Aug 21, 2025
@openjdk
Copy link

openjdk bot commented Aug 21, 2025

@fandreuz
Your change (at version cc7da3a) is now ready to be sponsored by a Committer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-compiler [email protected] ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored
Development

Successfully merging this pull request may close these issues.

3 participants