Skip to content
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