Skip to content

Reorganize standard library collections under cc #18858

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

Merged
merged 19 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
19 changes: 19 additions & 0 deletions tests/pos-special/stdlib/collection/concurrent/BasicNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc.
*
* 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;

public abstract class BasicNode {

public abstract String string(int lev);

}
37 changes: 37 additions & 0 deletions tests/pos-special/stdlib/collection/concurrent/CNodeBase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc.
*
* 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 java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

abstract class CNodeBase<K, V> extends MainNode<K, V> {

@SuppressWarnings("unchecked")
public static final AtomicIntegerFieldUpdater<CNodeBase<?, ?>> updater =
AtomicIntegerFieldUpdater.newUpdater((Class<CNodeBase<?, ?>>) (Class<?>) CNodeBase.class, "csize");

public volatile int csize = -1;

public boolean CAS_SIZE(int oldval, int nval) {
return updater.compareAndSet(this, oldval, nval);
}

public void WRITE_SIZE(int nval) {
updater.set(this, nval);
}

public int READ_SIZE() {
return updater.get(this);
}

}
15 changes: 15 additions & 0 deletions tests/pos-special/stdlib/collection/concurrent/Gen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc.
*
* 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;

final class Gen {}
39 changes: 39 additions & 0 deletions tests/pos-special/stdlib/collection/concurrent/INodeBase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc.
*
* 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 java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

abstract class INodeBase<K, V> extends BasicNode {

@SuppressWarnings("unchecked")
public static final AtomicReferenceFieldUpdater<INodeBase<?, ?>, MainNode<?, ?>> updater =
AtomicReferenceFieldUpdater.newUpdater((Class<INodeBase<?, ?>>) (Class<?>) INodeBase.class, (Class<MainNode<?, ?>>) (Class<?>) MainNode.class, "mainnode");

static final Object RESTART = new Object();

static final Object NO_SUCH_ELEMENT_SENTINEL = new Object();

public volatile MainNode<K, V> mainnode = null;

public final Gen gen;

public INodeBase(Gen generation) {
gen = generation;
}

public BasicNode prev() {
return null;
}

}
46 changes: 46 additions & 0 deletions tests/pos-special/stdlib/collection/concurrent/MainNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc.
*
* 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 java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

abstract class MainNode<K, V> extends BasicNode {

@SuppressWarnings("unchecked")
public static final AtomicReferenceFieldUpdater<MainNode<?, ?>, MainNode<?, ?>> updater =
AtomicReferenceFieldUpdater.newUpdater((Class<MainNode<?, ?>>) (Class<?>) MainNode.class, (Class<MainNode<?, ?>>) (Class<?>) MainNode.class, "prev");

public volatile MainNode<K, V> prev = null;

public abstract int cachedSize(Object ct);

// standard contract
public abstract int knownSize();

public boolean CAS_PREV(MainNode<K, V> oldval, MainNode<K, V> nval) {
return updater.compareAndSet(this, oldval, nval);
}

public void WRITE_PREV(MainNode<K, V> nval) {
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 @SuppressWarnings("unchecked")
public MainNode<K, V> READ_PREV() {
return (MainNode<K, V>) updater.get(this);
}

}
Loading