Skip to content

Commit 73d807a

Browse files
committed
Make lazy vals run on non-fallback graal image - remove dynamic reflection
1 parent e09175e commit 73d807a

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

library/src/scala/runtime/LazyVals.scala

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,15 @@ import scala.annotation.*
99
*/
1010
object LazyVals {
1111
@nowarn
12-
private[this] val unsafe: sun.misc.Unsafe =
13-
classOf[sun.misc.Unsafe].getDeclaredFields.nn.find { field =>
14-
field.nn.getType == classOf[sun.misc.Unsafe] && {
15-
field.nn.setAccessible(true)
16-
true
17-
}
18-
}
19-
.map(_.nn.get(null).asInstanceOf[sun.misc.Unsafe])
20-
.getOrElse {
21-
throw new ExceptionInInitializerError {
22-
new IllegalStateException("Can't find instance of sun.misc.Unsafe")
23-
}
24-
}
12+
private[this] val unsafe: sun.misc.Unsafe = {
13+
val unsafeField = classOf[sun.misc.Unsafe].getDeclaredField("theUnsafe").nn
14+
if unsafeField.getType == classOf[sun.misc.Unsafe] then
15+
unsafeField.setAccessible(true)
16+
else throw new ExceptionInInitializerError {
17+
new IllegalStateException("Can't find instance of sun.misc.Unsafe")
18+
}
19+
unsafeField.get(null).asInstanceOf[sun.misc.Unsafe]
20+
}
2521

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

0 commit comments

Comments
 (0)