Skip to content

Remove unnececary boxing in a.synchronized(1) #505

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

Closed
DarkDimius opened this issue Apr 28, 2015 · 2 comments
Closed

Remove unnececary boxing in a.synchronized(1) #505

DarkDimius opened this issue Apr 28, 2015 · 2 comments

Comments

@DarkDimius
Copy link
Contributor

Both Scalac and Dotty assume that synchronized takes and returns an Object after erasure.
Actually it doesn't so there's no need to box.
We could potentially leave synchronized as a polymorphic method after erasure and save a bit on GC pressure and bytecode size.

@smarter
Copy link
Member

smarter commented Jan 10, 2018

Fixed in scalac: scala/scala@92d1af1

@allanrenucci
Copy link
Contributor

allanrenucci commented Oct 30, 2018

Raising the priority since it affects thread safe lazy vals. For example:

def test = {
  lazy val foo = 1
  ...
}

compiles to:

def test = {
  lazy var foo$lzy1: dotty.runtime.LazyInt = new dotty.runtime.LazyInt()
  def foo$lzyINIT1(): Int =
    Int.unbox(
      foo$lzy1.synchronized(
        Int.box(
          if (foo$lzy1.initialized()) foo$lzy1.value() else {
            foo$lzy1.value_=(1)
            foo$lzy1.initialized_=(true)
            foo$lzy1.value()
          }
        )
      )
    )
  def foo(): Int =
    if (foo$lzy1.initialized()) foo$lzy1.value() else foo$lzyINIT1()
  ...
}

@allanrenucci allanrenucci self-assigned this Oct 30, 2018
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Nov 1, 2018
`synchronized` is now treated as a magic method by the compiler and is no
longer erased (similarly to `asInstanceOf` and `isInstanceOf`). Backend
is updated to handle this new magic polymorphic method.
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Nov 1, 2018
`synchronized` is now treated as a magic method by the compiler and is no
longer erased (similarly to `asInstanceOf` and `isInstanceOf`). Backend
is updated to handle this new magic polymorphic method.
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Nov 1, 2018
`synchronized` is now treated as a magic method by the compiler and is no
longer erased (similarly to `asInstanceOf` and `isInstanceOf`). Backend
is updated to handle this new magic polymorphic method.
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Nov 1, 2018
`synchronized` is now treated as a magic method by the compiler and is no
longer erased (similarly to `asInstanceOf` and `isInstanceOf`). Backend
is updated to handle this new magic polymorphic method.
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Nov 6, 2018
`synchronized` is now treated as a magic method by the compiler and is no
longer erased (similarly to `asInstanceOf` and `isInstanceOf`). Backend
is updated to handle this new magic polymorphic method.
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Nov 8, 2018
`synchronized` is now treated as a magic method by the compiler and is no
longer erased (similarly to `asInstanceOf` and `isInstanceOf`). Backend
is updated to handle this new magic polymorphic method.
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Nov 8, 2018
`synchronized` is now treated as a magic method by the compiler and is no
longer erased (similarly to `asInstanceOf` and `isInstanceOf`). Backend
is updated to handle this new magic polymorphic method.
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Nov 8, 2018
`synchronized` is now treated as a magic method by the compiler and is no
longer erased (similarly to `asInstanceOf` and `isInstanceOf`). Backend
is updated to handle this new magic polymorphic method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants