10000 SI-8362: Support for Future without sun.misc.Unsafe. · scala/scala@30a6b69 · GitHub
[go: up one dir, main page]

Skip to content

Commit 30a6b69

Browse files
committed
SI-8362: Support for Future without sun.misc.Unsafe.
Instead of using AtomicReferenceFieldUpdater extends directly AtomicReference as AtomicReferenceFieldUpdater.compareAndSet() isn't necessarily even inlined by Hotspot, while AtomicReference.compareAndSet() should be compiled down to the machine's CAS instruction. The implementation is similar to the 2.12.x branch’s one. Add an exclusion rule for mima to not check backward and forward compatibility as the class is package protected and in an imp package.
1 parent f4424c8 commit 30a6b69

File tree

3 files changed

+16
-40
lines changed

3 files changed

+16
-40
lines changed

bincompat-backward.whitelist.conf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ filter {
208208
{
209209
matchName="scala.reflect.io.ZipArchive.scala$reflect$io$ZipArchive$$walkIterator"
210210
problemName=MissingMethodProblem
211-
}
211+
},
212+
// SI-8362 - package-protected class in an impl package
213+
{
214+
matchName="scala.concurrent.impl.Promise$DefaultPromise"
215+
problemName=MissingTypesProblem
216+
}
212217
]
213218
}

bincompat-forward.whitelist.conf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,11 @@ filter {
314314
{
315315
matchName="scala.reflect.runtime.Settings#IntSetting.valueSetByUser"
316316
problemName=MissingMethodProblem
317-
}
317+
},
318+
// see SI-8362 - package-protected class in an impl package
319+
{
320+
matchName="scala.concurrent.impl.Promise$DefaultPromise"
321+
problemName=MissingTypesProblem
322+
}
318323
]
319324
}

src/library/scala/concurrent/impl/AbstractPromise.java

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,17 @@
99
package scala.concurrent.impl;
1010

1111

12-
import scala.concurrent.util.Unsafe;
13-
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
12+
import java.util.concurrent.atomic.AtomicReference;
1413

1514

1615

17-
abstract class AbstractPromise {
18-
private volatile Object _ref;
19-
20-
final static long _refoffset;
21-
/*
22-
* In a runtime with a security manager installed, or a non-Oracle runtime,
23-
* the Unsafe class may be unavailable. In this case, _refoffset will be
24-
* set to -1.
25-
*
26-
* We assume that a valid field offset will be non-negative, and likely a
27-
* multiple of 4.
28-
*/
29-
static {
30-
long refoffset = -1;
31-
try {
32-
refoffset = Unsafe.instance.objectFieldOffset(AbstractPromise.class.getDeclaredField("_ref"));
33-
} catch (Throwable t) {
34-
/* Unsafe object instance access failed */
35-
}
36-
_refoffset = refoffset;
37-
}
16+
abstract class AbstractPromise extends AtomicReference<Object> {
3817

39-
/*
40-
* The Hotspot compiler can identify that the value of _refoffset never
41-
* changes, and compile only the branch below that is used. When the Unsafe
42-
* object is available, the compare-and-swap operation will be inlined
43-
* directly into *this* method's caller.
44-
*/
4518
protected final boolean updateState(Object oldState, Object newState) {
46-
if (_refoffset == -1) {
47-
return updater.compareAndSet(this, oldState, newState);
48-
} else {
49-
return Unsafe.instance.compareAndSwapObject(this, _refoffset, oldState, newState);
50-
}
19+
return compareAndSet(oldState, newState);
5120
}
5221

5322
protected final Object getState() {
54-
return _ref;
23+
return get();
5524
}
56-
57-
protected final static AtomicReferenceFieldUpdater<AbstractPromise, Object> updater =
58-
AtomicReferenceFieldUpdater.newUpdater(AbstractPromise.class, Object.class, "_ref");
5925
}

0 commit comments

Comments
 (0)
0