Skip to content

Make lazy vals run on non-fallback graal image - remove dynamic reflection #16346

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

Merged
merged 2 commits into from
Nov 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions library/src/scala/runtime/LazyVals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ import scala.annotation.*
*/
object LazyVals {
@nowarn
private[this] val unsafe: sun.misc.Unsafe =
classOf[sun.misc.Unsafe].getDeclaredFields.nn.find { field =>
field.nn.getType == classOf[sun.misc.Unsafe] && {
field.nn.setAccessible(true)
true
}
}
.map(_.nn.get(null).asInstanceOf[sun.misc.Unsafe])
.getOrElse {
throw new ExceptionInInitializerError {
new IllegalStateException("Can't find instance of sun.misc.Unsafe")
}
}
private[this] val unsafe: sun.misc.Unsafe = {
def throwInitializationException() =
throw new ExceptionInInitializerError(
new IllegalStateException("Can't find instance of sun.misc.Unsafe")
)
try
val unsafeField = classOf[sun.misc.Unsafe].getDeclaredField("theUnsafe").nn
if unsafeField.getType == classOf[sun.misc.Unsafe] then
unsafeField.setAccessible(true)
unsafeField.get(null).asInstanceOf[sun.misc.Unsafe]
else
throwInitializationException()
catch case _: NoSuchFieldException =>
throwInitializationException()
}

private[this] val base: Int = {
val processors = java.lang.Runtime.getRuntime.nn.availableProcessors()
Expand Down