diff options
author | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2016-04-20 11:35:47 +0200 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2016-06-07 14:18:27 +0200 |
commit | e1fcb4c8a70d2ffa32d22bef707bb87dd0acf439 (patch) | |
tree | d1c6a6c7a696f57af8a18625cd4f64dd408e7f90 /src/dotty | |
parent | d9702d2173b7813a3a463f2cd93ac19284ca83ff (diff) | |
download | dotty-e1fcb4c8a70d2ffa32d22bef707bb87dd0acf439.tar.gz dotty-e1fcb4c8a70d2ffa32d22bef707bb87dd0acf439.tar.bz2 dotty-e1fcb4c8a70d2ffa32d22bef707bb87dd0acf439.zip |
LazyVals: support debug mode.
Helps to spot usage of unsafe that would lead to undefined behaviour.
Diffstat (limited to 'src/dotty')
-rw-r--r-- | src/dotty/runtime/LazyVals.scala | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/dotty/runtime/LazyVals.scala b/src/dotty/runtime/LazyVals.scala index f09e96f57..e42532ce0 100644 --- a/src/dotty/runtime/LazyVals.scala +++ b/src/dotty/runtime/LazyVals.scala @@ -10,14 +10,24 @@ object LazyVals { final val BITS_PER_LAZY_VAL = 2L final val LAZY_VAL_MASK = 3L + final val debug = false - @inline def STATE(cur: Long, ord: Int) = (cur >> (ord * BITS_PER_LAZY_VAL)) & LAZY_VAL_MASK + @inline def STATE(cur: Long, ord: Int) = { + val r = (cur >> (ord * BITS_PER_LAZY_VAL)) & LAZY_VAL_MASK + if (debug) + println(s"STATE($cur, $ord) = $r") + r + } @inline def CAS(t: Object, offset: Long, e: Long, v: Int, ord: Int) = { + if (debug) + println(s"CAS($t, $offset, $e, $v, $ord)") val mask = ~(LAZY_VAL_MASK << ord * BITS_PER_LAZY_VAL) val n = (e & mask) | (v << (ord * BITS_PER_LAZY_VAL)) compareAndSet(t, offset, e, n) } @inline def setFlag(t: Object, offset: Long, v: Int, ord: Int) = { + if (debug) + println(s"setFlag($t, $offset, $v, $ord)") var retry = true while (retry) { val cur = get(t, offset) @@ -35,6 +45,8 @@ object LazyVals { } } @inline def wait4Notification(t: Object, offset: Long, cur: Long, ord: Int) = { + if (debug) + println(s"wait4Notification($t, $offset, $cur, $ord)") var retry = true while (retry) { val cur = get(t, offset) @@ -68,7 +80,12 @@ object LazyVals { monitors(id) } - @inline def getOffset(clz: Class[_], name: String) = unsafe.objectFieldOffset(clz.getDeclaredField(name)) + @inline def getOffset(clz: Class[_], name: String) = { + val r = unsafe.objectFieldOffset(clz.getDeclaredField(name)) + if (debug) + println(s"getOffset($clz, $name) = $r") + r + } object Names { final val state = "STATE" |