Integrated: 8293578: Duplicate ldc generated by javac
Jan Lahoda
jlahoda at openjdk.org
Fri Sep 16 11:40:54 UTC 2022
On Wed, 14 Sep 2022 17:15:30 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> Consider code like:
>
> var testC = "incorrect".getClass();
> var testV = testC.getConstructor(String.class)
> .newInstance("correct");
> System.err.println(testV);
>
>
> javac has a concept of types with attached constants (to support proper behavior of constant expressions). Normally, these constants are cleared as specific places. But, in the above case, the type of `testC` is actually `Class<? extends String["incorrect"]>`, the constant then gets propagated, and eventually the type of `testV` is `String["incorrect"]`, and the code generator will then replace reads from `testV` with a ldc for the constant, so the code above prints "incorrect" instead of "correct".
>
> The solution is to invoke `.baseType()` to remove the constant value when constructing the synthetic `.getClass()`'s type (so the type of `testC` is `Class<? extends String>`), and also a tweak to `checkLocalVarType`, as suggested in the bug.
This pull request has now been integrated.
Changeset: 39cd1635
Author: Jan Lahoda <jlahoda at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/39cd1635bf07f42857e1a704734db66b2c2fa882
Stats: 103 lines in 3 files changed: 99 ins; 0 del; 4 mod
8293578: Duplicate ldc generated by javac
Reviewed-by: mcimadamore
-------------
PR: https://git.openjdk.org/jdk/pull/10272
More information about the compiler-dev
mailing list