Open szymon-rd opened 2 years ago
This is tracked by https://github.com/lampepfl/dotty/issues/9013, as noted in that issue it doesn't seem possible to decide whether we can use VarHandle at runtime without ruining the performance of VarHandle
What we could do is 1) under -release >= 9, use VarHandle properly 2) under -release 8, keep using unsafe but have a (potentially slower) runtime fallback if the method is not available
Also I'm not sure if we already changed the default of -release to match the currently used jvm, I think we wanted to do that for 3.2
It looks like currently the default value is java 8
@smarter You want to have both (or even all three possible) implementations of lazy vals in the stdlib. Then, depending on the -release
flag set in the user project, choose the proper implementation during desugaring.
Am I getting it right?
Two thoughts here :
@Kordyjan yes @michelou There's no plan to drop java 8 support
@smarter That's fine (and also my expectation). I was focused primarily on the "default" JVM.
The "default" is whatever is installed on your system, this is already the case now but it's not reflected in the class file version number we emit.
If whining helps, it is annoying to go to try something out and it errors because my current jdk is 18.
Perhaps if I read up on the linked ticket and the "new lazy val" PR, I'll understand the end game. -release
is awesome.
I think it's important for the compiler to compile on every jdk people might use, so a PR that would silence the deprecation would be welcome.
Just for silence https://github.com/lampepfl/dotty/pull/15520
Compiler version
At current main - 1ea177df6d, and also previous versions.
The problem
The problem is caused by usage of
Unsafe.objectFieldOffset
in runtime. When compiling the compiler on JVM 18, the following errors appear:It's not a problem per se, as we don't use this version of JDK on compiling. But, per the documentation:
And we heavily rely on this feature in the current and the new lazy vals implementation. It's not a problem now, but soon lazy vals can stop working on new jvms as we don't have any guarantee on their stability.
Proposal
Use MethodHandles to execute the Unsafe methods if the currently running jvm version == 1.8. In other case, use the VarHandles. It's a pretty complex approach and there may be another simpler solution.