Skip to content
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
* additional information regarding copyright ownership.
*/

package scala.collection.concurrent;
package scala.collection.concurrent

final class Gen {}
import scala.language.`2.13`
import language.experimental.captureChecking

abstract class BasicNode {

def string(lev: Int): String

}
37 changes: 0 additions & 37 deletions library/src/scala/collection/concurrent/CNodeBase.java

This file was deleted.

43 changes: 43 additions & 0 deletions library/src/scala/collection/concurrent/CNodeBase.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc. dba Akka
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

package scala.collection.concurrent

import scala.language.`2.13`
import language.experimental.captureChecking

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater
import scala.annotation.static

private[concurrent] object CNodeBase {
@static
final val updater: AtomicIntegerFieldUpdater[CNodeBase[?, ?]] =
AtomicIntegerFieldUpdater.newUpdater(classOf[CNodeBase[?, ?]], "csize")
}

private[concurrent] abstract class CNodeBase[K, V] extends MainNode[K, V] {

@volatile var csize: Int = -1

def CAS_SIZE(oldval: Int, nval: Int): Boolean = {
CNodeBase.updater.compareAndSet(this, oldval, nval)
}

def WRITE_SIZE(nval: Int): Unit = {
CNodeBase.updater.set(this, nval)
}

def READ_SIZE(): Int = {
CNodeBase.updater.get(this)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
* additional information regarding copyright ownership.
*/

package scala.collection.concurrent;
package scala.collection.concurrent

public abstract class BasicNode {
import scala.language.`2.13`
import language.experimental.captureChecking

public abstract String string(int lev);

}
private[concurrent] final class Gen {}
39 changes: 0 additions & 39 deletions library/src/scala/collection/concurrent/INodeBase.java

This file was deleted.

36 changes: 36 additions & 0 deletions library/src/scala/collection/concurrent/INodeBase.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc. dba Akka
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

package scala.collection.concurrent

import scala.language.`2.13`
import language.experimental.captureChecking

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater
import scala.annotation.static

private[concurrent] object INodeBase {
@static
final val updater: AtomicReferenceFieldUpdater[INodeBase[?, ?], MainNode[?, ?]] =
AtomicReferenceFieldUpdater.newUpdater(classOf[INodeBase[?, ?]], classOf[MainNode[?, ?]], "mainnode")

@static final val RESTART: Object = new Object()

@static final val NO_SUCH_ELEMENT_SENTINEL: Object = new Object()
}

private[concurrent] abstract class INodeBase[K, V](val gen: Gen) extends BasicNode {

@volatile var mainnode: MainNode[K, V] = null

def prev(): BasicNode = null
}
46 changes: 0 additions & 46 deletions library/src/scala/collection/concurrent/MainNode.java

This file was deleted.

50 changes: 50 additions & 0 deletions library/src/scala/collection/concurrent/MainNode.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc. dba Akka
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

package scala.collection.concurrent

import scala.language.`2.13`
import language.experimental.captureChecking

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater
import scala.annotation.static

private[concurrent] object MainNode {
@static val updater: AtomicReferenceFieldUpdater[MainNode[?, ?], MainNode[?, ?]] =
AtomicReferenceFieldUpdater.newUpdater(classOf[MainNode[?, ?]], classOf[MainNode[?, ?]], "prev")
}

private[concurrent] abstract class MainNode[K, V] extends BasicNode {

@volatile var prev: MainNode[K, V] = null

def cachedSize(ct: Object): Int

// standard contract
def knownSize(): Int

def CAS_PREV(oldval: MainNode[K, V], nval: MainNode[K, V]): Boolean = {
MainNode.updater.compareAndSet(this, oldval, nval)
}

def WRITE_PREV(nval: MainNode[K, V]): Unit = {
MainNode.updater.set(this, nval)
}

// do we need this? unclear in the javadocs...
// apparently not - volatile reads are supposed to be safe
// regardless of whether there are concurrent ARFU updates
@deprecated
def READ_PREV(): MainNode[K, V] = {
MainNode.updater.get(this).asInstanceOf[MainNode[K, V]]
}
}
2 changes: 1 addition & 1 deletion library/src/scala/collection/concurrent/TrieMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ object TrieMap extends MapFactory[TrieMap] {
def newBuilder[K, V]: mutable.GrowableBuilder[(K, V), TrieMap[K, V]] = new GrowableBuilder(empty[K, V])

@transient
val inodeupdater: AtomicReferenceFieldUpdater[INodeBase[_, _], MainNode[_, _]] = AtomicReferenceFieldUpdater.newUpdater(classOf[INodeBase[_, _]], classOf[MainNode[_, _]], "mainnode")
val inodeupdater: AtomicReferenceFieldUpdater[INodeBase[_, _], MainNode[_, _]] = INodeBase.updater
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe TrieMap.inodeupdater is unused. but error without this change. Should we deprecate this field? 🤔

Caused by: java.lang.RuntimeException: java.lang.IllegalAccessException: class scala.collection.concurrent.TrieMap$ cannot access a member of class scala.collection.concurrent.INodeBase with modifiers "private volatile"
	at java.base/java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl.<init>(AtomicReferenceFieldUpdater.java:351)
	at java.base/java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater(AtomicReferenceFieldUpdater.java:115)
	at scala.collection.concurrent.TrieMap$.<clinit>(TrieMap.scala:1052)


class MangledHashing[K] extends Hashing[K] {
def hash(k: K): Int = scala.util.hashing.byteswap32(k.##)
Expand Down
Loading