Skip to content

Conversation

@tstuefe
Copy link
Member

@tstuefe tstuefe commented Feb 14, 2025

Somewhat trivial.

I recently hunted a bug for an hour until I realized that I had accessed ciEnv::compiler_data() as C2 Compile when, in fact, it was C1 Compilation. Stupid mistake, but an assert is easy to do and saves time.


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-8350097: Make Compilation::current() and Compile::current() safer (Enhancement - P4)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 23635

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 14, 2025

👋 Welcome back stuefe! 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 Feb 14, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot changed the title JDK-8350097: Make Compilation::current() and Compile::current() safer 8350097: Make Compilation::current() and Compile::current() safer Feb 14, 2025
@openjdk
Copy link

openjdk bot commented Feb 14, 2025

@tstuefe 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 the hotspot-compiler hotspot-compiler-dev@openjdk.org label Feb 14, 2025
@tstuefe tstuefe force-pushed the JDK-8350097-Make-Compilation-current-and-Compile-current-safer branch from 3c2a32a to a103b45 Compare February 14, 2025 14:50
@tstuefe tstuefe marked this pull request as ready for review February 14, 2025 14:51
@openjdk openjdk bot added the rfr Pull request is ready for review label Feb 14, 2025
@mlbridge
Copy link

mlbridge bot commented Feb 14, 2025

Webrevs

#include "compiler/compilerDefinitions.inline.hpp"
#include "compiler/compilerDirectives.hpp"
#include "runtime/deoptimization.hpp"
#include "utilities/debug.hpp"
Copy link
Member

Choose a reason for hiding this comment

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

DEBUG_ONLY lives in utilities/macros.hpp, include that one directly?



static Compilation* current() {
DEBUG_ONLY(ciEnv::current()->check_compiler_data_c1_or_null();)
Copy link
Member

Choose a reason for hiding this comment

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

So, can it be just some sort of:

    assert(CompilerThread::current()->compiler()->is_c1(), "sanity");

...without any other changes in ciEnv?

Copy link
Member

Choose a reason for hiding this comment

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

Context: I think ciEnv is pretty compiler-agnostic, and it would be better to avoid exposing the fact C1/C2 exist to that interface, even if only for asserts. Seems cleaner to check that we are calling Compilation::current() from C1 and Compile::current() from C2.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with Aleksey here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I like this too. Simpler. Okay, I try that.

@dean-long
Copy link
Member

dean-long commented Feb 15, 2025

If we derive C2 Compile and C1 Compilation from a common superclass, then ciEnv::compiler_data() could return that superclass and self-identify using a type field or virtual function. When looking into how we handle failure messages and how complicated it is, I thought moving some fields into a common superclass would be useful. Eventually we could even look into making ciEnv the common superclass, because the lifetimes are almost identical.

This reverts commit e370e14.
@tstuefe
Copy link
Member Author

tstuefe commented Feb 15, 2025

If we derive C2 Compile and C1 Compilation from a common superclass, then ciEnv::compiler_data() could return that superclass and self-identify using a type field or virtual function. When looking into how we handle failure messages and how complicated it is, I thought moving some fields into a common superclass would be useful. Eventually we could even look into making ciEnv the common superclass, because the lifetimes are almost identical.

I thought about that, but Compile inherits from Phase, so any common superclass becomes one of Phase, too. I did not want to change the inheritance structure to deal with such a tiny problem.

@dean-long
Copy link
Member

Since the callers already need to know which compiler they are asking about, I don't see the value in forcing void* through a single interface. How about we improve things by replacing compiler_data with c1_compiler_data() and c2_compiler_data()?

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 27, 2025

@tstuefe This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 24, 2025

@tstuefe This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the /open pull request command.

@bridgekeeper bridgekeeper bot closed this Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot-compiler hotspot-compiler-dev@openjdk.org rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

4 participants