Skip to content

Commit 49587e2

Browse files
authored
Reorganize standard library collections under cc (#18858)
1. Revert previous merge commit 2. Add all changes to capture tracking in the compiler to make (4) go through. 3. Add all collection classes without changes to test directory in one commit [3caf116](3caf116). 4. Add all changes to collection classes made for capture checking in another commit [b5bfbab](b5bfbab).
2 parents 0cd94fc + b5bfbab commit 49587e2

27 files changed

+4727
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Scala (https://www.scala-lang.org)
3+
*
4+
* Copyright EPFL and Lightbend, Inc.
5+
*
6+
* Licensed under Apache License 2.0
7+
* (http://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package scala.collection.concurrent;
14+
15+
public abstract class BasicNode {
16+
17+
public abstract String string(int lev);
18+
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Scala (https://www.scala-lang.org)
3+
*
4+
* Copyright EPFL and Lightbend, Inc.
5+
*
6+
* Licensed under Apache License 2.0
7+
* (http://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package scala.collection.concurrent;
14+
15+
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
16+
17+
abstract class CNodeBase<K, V> extends MainNode<K, V> {
18+
19+
@SuppressWarnings("unchecked")
20+
public static final AtomicIntegerFieldUpdater<CNodeBase<?, ?>> updater =
21+
AtomicIntegerFieldUpdater.newUpdater((Class<CNodeBase<?, ?>>) (Class<?>) CNodeBase.class, "csize");
22+
23+
public volatile int csize = -1;
24+
25+
public boolean CAS_SIZE(int oldval, int nval) {
26+
return updater.compareAndSet(this, oldval, nval);
27+
}
28+
29+
public void WRITE_SIZE(int nval) {
30+
updater.set(this, nval);
31+
}
32+
33+
public int READ_SIZE() {
34+
return updater.get(this);
35+
}
36+
37+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Scala (https://www.scala-lang.org)
3+
*
4+
* Copyright EPFL and Lightbend, Inc.
5+
*
6+
* Licensed under Apache License 2.0
7+
* (http://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package scala.collection.concurrent;
14+
15+
final class Gen {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Scala (https://www.scala-lang.org)
3+
*
4+
* Copyright EPFL and Lightbend, Inc.
5+
*
6+
* Licensed under Apache License 2.0
7+
* (http://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package scala.collection.concurrent;
14+
15+
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
16+
17+
abstract class INodeBase<K, V> extends BasicNode {
18+
19+
@SuppressWarnings("unchecked")
20+
public static final AtomicReferenceFieldUpdater<INodeBase<?, ?>, MainNode<?, ?>> updater =
21+
AtomicReferenceFieldUpdater.newUpdater((Class<INodeBase<?, ?>>) (Class<?>) INodeBase.class, (Class<MainNode<?, ?>>) (Class<?>) MainNode.class, "mainnode");
22+
23+
static final Object RESTART = new Object();
24+
25+
static final Object NO_SUCH_ELEMENT_SENTINEL = new Object();
26+
27+
public volatile MainNode<K, V> mainnode = null;
28+
29+
public final Gen gen;
30+
31+
public INodeBase(Gen generation) {
32+
gen = generation;
33+
}
34+
35+
public BasicNode prev() {
36+
return null;
37+
}
38+
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Scala (https://www.scala-lang.org)
3+
*
4+
* Copyright EPFL and Lightbend, Inc.
5+
*
6+
* Licensed under Apache License 2.0
7+
* (http://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package scala.collection.concurrent;
14+
15+
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
16+
17+
abstract class MainNode<K, V> extends BasicNode {
18+
19+
@SuppressWarnings("unchecked")
20+
public static final AtomicReferenceFieldUpdater<MainNode<?, ?>, MainNode<?, ?>> updater =
21+
AtomicReferenceFieldUpdater.newUpdater((Class<MainNode<?, ?>>) (Class<?>) MainNode.class, (Class<MainNode<?, ?>>) (Class<?>) MainNode.class, "prev");
22+
23+
public volatile MainNode<K, V> prev = null;
24+
25+
public abstract int cachedSize(Object ct);
26+
27+
// standard contract
28+
public abstract int knownSize();
29+
30+
public boolean CAS_PREV(MainNode<K, V> oldval, MainNode<K, V> nval) {
31+
return updater.compareAndSet(this, oldval, nval);
32+
}
33+
34+
public void WRITE_PREV(MainNode<K, V> nval) {
35+
updater.set(this, nval);
36+
}
37+
38+
// do we need this? unclear in the javadocs...
39+
// apparently not - volatile reads are supposed to be safe
40+
// regardless of whether there are concurrent ARFU updates
41+
@Deprecated @SuppressWarnings("unchecked")
42+
public MainNode<K, V> READ_PREV() {
43+
return (MainNode<K, V>) updater.get(this);
44+
}
45+
46+
}

0 commit comments

Comments
 (0)