8379503: Intern constant expression of type String#978
8379503: Intern constant expression of type String#978mabbay wants to merge 28 commits intoopenjdk:code-reflectionfrom
Conversation
…pls that are not required by op evaluation
# Conflicts: # test/jdk/jdk/incubator/code/TestSwitchExpressionOp.java
# Conflicts: # test/jdk/jdk/incubator/code/lib/ArithmeticAndConvOpImpls.java
|
👋 Welcome back mabbay! A progress list of the required criteria for merging this PR into |
|
@mabbay 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: 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 2 new commits pushed to the Please see this link for an up-to-date comparison between the source branch of this pull request and the ➡️ To integrate this PR with the above commit message to the |
PaulSandoz
left a comment
There was a problem hiding this comment.
The reuse of the evaluator is nice.
Using NonConstantExpression works well internally for evaluating one expression, but could be a performance issue when called many times when used for transformation. We could revisit later, at the expense of more complexity with value | error union result.
I logged an issue for this. |
# Conflicts: # src/jdk.incubator.code/share/classes/jdk/incubator/code/dialect/java/JavaOp.java
|
/template append |
|
@mabbay The pull request template has been appended to the pull request body |
| } | ||
| Object v; | ||
| if ((field.getModifiers() & Modifier.STATIC) != 0) { | ||
| // @@@ why using field.get fails ? |
There was a problem hiding this comment.
did you try field::get(null) ?
There was a problem hiding this comment.
Yes, but it throws IllegalAccessException
There was a problem hiding this comment.
We discussed this offline -- this failure is due to the fact that Field::get uses caller sensitive methods -- so access checks are relative to the place where Field::get is called -- in this case jdk.incubator.code.dialect.java. When using VarHandle however, access checks are defined in terms of a user-provided lookup object -- which makes this work more reliably. I'd suggest dropping the comment and maybe say that we need to use VH here.
| throw new NonConstantExpression(); | ||
| } | ||
| Object v; | ||
| if ((field.getModifiers() & Modifier.STATIC) != 0) { |
There was a problem hiding this comment.
Can't you check for STATIC in the above -- e.g. when you also check for FINAL ?
There was a problem hiding this comment.
The first checks are for constant variables (as per JLS). The second check is due to the limitation we have in the model, as we can't get the value of an instance field.
|
The code seems to track JLS 15.29 quite well. Of course there's some limitations in the code model -- e.g. when it comes to variables, we don't know which variables were declared as "final" in the source code, or which also had an initializer. Maybe javac could leave an extra attribute there for a "constant field/var load" -- but not sure whether doing so would help the general issue. |
We need a general solution to cover user built model |
PaulSandoz
left a comment
There was a problem hiding this comment.
Very good.
Let's follow up in another PR with common patterns for constructing and using code transformers.
|
/integrate |
Implement constant folding in the model. An Operation that model a constant expression is replaced by a ConstantOp that has the value of the expression.
This transformation eliminate the need to explicitly intern constant expression of type
Stringin the model, as these expressions are replaced byConstantOpswithStringliterals as values, which are interned naturally.Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/babylon.git pull/978/head:pull/978$ git checkout pull/978Update a local copy of the PR:
$ git checkout pull/978$ git pull https://git.openjdk.org/babylon.git pull/978/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 978View PR using the GUI difftool:
$ git pr show -t 978Using diff file
Download this PR as a diff file:
https://git.openjdk.org/babylon/pull/978.diff
Using Webrev
Link to Webrev Comment