File tree 1 file changed +6
-5
lines changed
library/src/scala/runtime
1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -27,17 +27,18 @@ object LazyVals {
27
27
28
28
private val base : Int = {
29
29
val processors = java.lang.Runtime .getRuntime.nn.availableProcessors()
30
- 8 * processors * processors
30
+ val rawSize = 8 * processors * processors
31
+ // find the next power of 2
32
+ 1 << (32 - Integer .numberOfLeadingZeros(rawSize - 1 ))
31
33
}
32
34
35
+ private val mask : Int = base - 1
36
+
33
37
private val monitors : Array [Object ] =
34
38
Array .tabulate(base)(_ => new Object )
35
39
36
40
private def getMonitor (obj : Object , fieldId : Int = 0 ) = {
37
- var id = (java.lang.System .identityHashCode(obj) + fieldId) % base
38
-
39
- if (id < 0 ) id += base
40
- monitors(id)
41
+ monitors((java.lang.System .identityHashCode(obj) + fieldId) & mask)
41
42
}
42
43
43
44
private final val LAZY_VAL_MASK = 3L
You can’t perform that action at this time.
0 commit comments