Making java.util.concurrent compilable without references to sun.misc.Unsafe and co.
1.1 --- a/rt/emul/compact/src/main/java/java/util/concurrent/ForkJoinPool.java Sat Mar 19 12:51:03 2016 +0100
1.2 +++ b/rt/emul/compact/src/main/java/java/util/concurrent/ForkJoinPool.java Sat Mar 19 13:15:11 2016 +0100
1.3 @@ -2122,6 +2122,7 @@
1.4 }
1.5
1.6 // Unsafe mechanics
1.7 + private static final Unsafe UNSAFE;
1.8 private static final long ctlOffset;
1.9 private static final long stealCountOffset;
1.10 private static final long blockedCountOffset;
1.11 @@ -2134,12 +2135,11 @@
1.12 static {
1.13 poolNumberGenerator = new AtomicInteger();
1.14 workerSeedGenerator = new Random();
1.15 - modifyThreadPermission = new RuntimePermission("modifyThread");
1.16 defaultForkJoinWorkerThreadFactory =
1.17 new DefaultForkJoinWorkerThreadFactory();
1.18 int s;
1.19 try {
1.20 - UNSAFE = sun.misc.Unsafe.getUnsafe();
1.21 + UNSAFE = Unsafe.getUnsafe();
1.22 Class k = ForkJoinPool.class;
1.23 ctlOffset = UNSAFE.objectFieldOffset
1.24 (k.getDeclaredField("ctl"));
2.1 --- a/rt/emul/compact/src/main/java/java/util/concurrent/ForkJoinTask.java Sat Mar 19 12:51:03 2016 +0100
2.2 +++ b/rt/emul/compact/src/main/java/java/util/concurrent/ForkJoinTask.java Sat Mar 19 13:15:11 2016 +0100
2.3 @@ -37,17 +37,13 @@
2.4
2.5 import java.io.Serializable;
2.6 import java.util.Collection;
2.7 -import java.util.Collections;
2.8 import java.util.List;
2.9 import java.util.RandomAccess;
2.10 -import java.util.Map;
2.11 import java.lang.ref.WeakReference;
2.12 import java.lang.ref.ReferenceQueue;
2.13 import java.util.concurrent.Callable;
2.14 import java.util.concurrent.CancellationException;
2.15 import java.util.concurrent.ExecutionException;
2.16 -import java.util.concurrent.Executor;
2.17 -import java.util.concurrent.ExecutorService;
2.18 import java.util.concurrent.Future;
2.19 import java.util.concurrent.RejectedExecutionException;
2.20 import java.util.concurrent.RunnableFuture;
2.21 @@ -1368,14 +1364,14 @@
2.22 }
2.23
2.24 // Unsafe mechanics
2.25 - private static final sun.misc.Unsafe UNSAFE;
2.26 + private static final Unsafe UNSAFE;
2.27 private static final long statusOffset;
2.28 static {
2.29 exceptionTableLock = new ReentrantLock();
2.30 exceptionTableRefQueue = new ReferenceQueue<Object>();
2.31 exceptionTable = new ExceptionNode[EXCEPTION_MAP_CAPACITY];
2.32 try {
2.33 - UNSAFE = sun.misc.Unsafe.getUnsafe();
2.34 + UNSAFE = Unsafe.getUnsafe();
2.35 statusOffset = UNSAFE.objectFieldOffset
2.36 (ForkJoinTask.class.getDeclaredField("status"));
2.37 } catch (Exception e) {
3.1 --- a/rt/emul/compact/src/main/java/java/util/concurrent/ForkJoinWorkerThread.java Sat Mar 19 12:51:03 2016 +0100
3.2 +++ b/rt/emul/compact/src/main/java/java/util/concurrent/ForkJoinWorkerThread.java Sat Mar 19 13:15:11 2016 +0100
3.3 @@ -976,14 +976,14 @@
3.4 }
3.5
3.6 // Unsafe mechanics
3.7 - private static final sun.misc.Unsafe UNSAFE;
3.8 + private static final Unsafe UNSAFE;
3.9 private static final long ABASE;
3.10 private static final int ASHIFT;
3.11
3.12 static {
3.13 int s;
3.14 try {
3.15 - UNSAFE = sun.misc.Unsafe.getUnsafe();
3.16 + UNSAFE = Unsafe.getUnsafe();
3.17 Class a = ForkJoinTask[].class;
3.18 ABASE = UNSAFE.arrayBaseOffset(a);
3.19 s = UNSAFE.arrayIndexScale(a);
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/rt/emul/compact/src/main/java/java/util/concurrent/Unsafe.java Sat Mar 19 13:15:11 2016 +0100
4.3 @@ -0,0 +1,77 @@
4.4 +/*
4.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4.6 + *
4.7 + * This code is free software; you can redistribute it and/or modify it
4.8 + * under the terms of the GNU General Public License version 2 only, as
4.9 + * published by the Free Software Foundation. Oracle designates this
4.10 + * particular file as subject to the "Classpath" exception as provided
4.11 + * by Oracle in the LICENSE file that accompanied this code.
4.12 + *
4.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
4.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4.15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4.16 + * version 2 for more details (a copy is included in the LICENSE file that
4.17 + * accompanied this code).
4.18 + *
4.19 + * You should have received a copy of the GNU General Public License version
4.20 + * 2 along with this work; if not, write to the Free Software Foundation,
4.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4.22 + *
4.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4.24 + * or visit www.oracle.com if you need additional information or have any
4.25 + * questions.
4.26 + */
4.27 +package java.util.concurrent;
4.28 +
4.29 +import java.lang.reflect.Field;
4.30 +
4.31 +final class Unsafe {
4.32 + static Unsafe getUnsafe() {
4.33 + throw new SecurityException();
4.34 + }
4.35 +
4.36 + void throwException(Throwable exception) {
4.37 + throw new SecurityException();
4.38 + }
4.39 +
4.40 + void putOrderedObject(Object q, long u, ForkJoinTask<?> t) {
4.41 + throw new SecurityException();
4.42 + }
4.43 +
4.44 + boolean compareAndSwapObject(Object q, long l, Object t, Object object) {
4.45 + throw new SecurityException();
4.46 + }
4.47 +
4.48 + Object getObjectVolatile(Object oldQ, long u) {
4.49 + throw new SecurityException();
4.50 + }
4.51 +
4.52 + void putObjectVolatile(Object q, long l, Object t) {
4.53 + throw new SecurityException();
4.54 + }
4.55 +
4.56 + long arrayBaseOffset(Class a) {
4.57 + throw new SecurityException();
4.58 + }
4.59 +
4.60 + int arrayIndexScale(Class a) {
4.61 + throw new SecurityException();
4.62 + }
4.63 +
4.64 + boolean compareAndSwapLong(Object aThis, long ctlOffset, long c, long nc) {
4.65 + throw new SecurityException();
4.66 + }
4.67 +
4.68 + void unpark(ForkJoinWorkerThread w) {
4.69 + throw new SecurityException();
4.70 + }
4.71 +
4.72 + boolean compareAndSwapInt(Object aThis, long blockedCountOffset, int b, int i) {
4.73 + throw new SecurityException();
4.74 + }
4.75 +
4.76 + long objectFieldOffset(Field declaredField) {
4.77 + throw new SecurityException();
4.78 + }
4.79 +
4.80 +}