# HG changeset patch # User Jaroslav Tulach # Date 1458389711 -3600 # Node ID 9984d9a62bc08822e05f43b8b77ff8357d09303b # Parent bfaf3300b7baae37bf5be5d9f3953c1318f74bb9 Making java.util.concurrent compilable without references to sun.misc.Unsafe and co. diff -r bfaf3300b7ba -r 9984d9a62bc0 rt/emul/compact/src/main/java/java/util/concurrent/ForkJoinPool.java --- a/rt/emul/compact/src/main/java/java/util/concurrent/ForkJoinPool.java Sat Mar 19 12:51:03 2016 +0100 +++ b/rt/emul/compact/src/main/java/java/util/concurrent/ForkJoinPool.java Sat Mar 19 13:15:11 2016 +0100 @@ -2122,6 +2122,7 @@ } // Unsafe mechanics + private static final Unsafe UNSAFE; private static final long ctlOffset; private static final long stealCountOffset; private static final long blockedCountOffset; @@ -2134,12 +2135,11 @@ static { poolNumberGenerator = new AtomicInteger(); workerSeedGenerator = new Random(); - modifyThreadPermission = new RuntimePermission("modifyThread"); defaultForkJoinWorkerThreadFactory = new DefaultForkJoinWorkerThreadFactory(); int s; try { - UNSAFE = sun.misc.Unsafe.getUnsafe(); + UNSAFE = Unsafe.getUnsafe(); Class k = ForkJoinPool.class; ctlOffset = UNSAFE.objectFieldOffset (k.getDeclaredField("ctl")); diff -r bfaf3300b7ba -r 9984d9a62bc0 rt/emul/compact/src/main/java/java/util/concurrent/ForkJoinTask.java --- a/rt/emul/compact/src/main/java/java/util/concurrent/ForkJoinTask.java Sat Mar 19 12:51:03 2016 +0100 +++ b/rt/emul/compact/src/main/java/java/util/concurrent/ForkJoinTask.java Sat Mar 19 13:15:11 2016 +0100 @@ -37,17 +37,13 @@ import java.io.Serializable; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.RandomAccess; -import java.util.Map; import java.lang.ref.WeakReference; import java.lang.ref.ReferenceQueue; import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.RunnableFuture; @@ -1368,14 +1364,14 @@ } // Unsafe mechanics - private static final sun.misc.Unsafe UNSAFE; + private static final Unsafe UNSAFE; private static final long statusOffset; static { exceptionTableLock = new ReentrantLock(); exceptionTableRefQueue = new ReferenceQueue(); exceptionTable = new ExceptionNode[EXCEPTION_MAP_CAPACITY]; try { - UNSAFE = sun.misc.Unsafe.getUnsafe(); + UNSAFE = Unsafe.getUnsafe(); statusOffset = UNSAFE.objectFieldOffset (ForkJoinTask.class.getDeclaredField("status")); } catch (Exception e) { diff -r bfaf3300b7ba -r 9984d9a62bc0 rt/emul/compact/src/main/java/java/util/concurrent/ForkJoinWorkerThread.java --- a/rt/emul/compact/src/main/java/java/util/concurrent/ForkJoinWorkerThread.java Sat Mar 19 12:51:03 2016 +0100 +++ b/rt/emul/compact/src/main/java/java/util/concurrent/ForkJoinWorkerThread.java Sat Mar 19 13:15:11 2016 +0100 @@ -976,14 +976,14 @@ } // Unsafe mechanics - private static final sun.misc.Unsafe UNSAFE; + private static final Unsafe UNSAFE; private static final long ABASE; private static final int ASHIFT; static { int s; try { - UNSAFE = sun.misc.Unsafe.getUnsafe(); + UNSAFE = Unsafe.getUnsafe(); Class a = ForkJoinTask[].class; ABASE = UNSAFE.arrayBaseOffset(a); s = UNSAFE.arrayIndexScale(a); diff -r bfaf3300b7ba -r 9984d9a62bc0 rt/emul/compact/src/main/java/java/util/concurrent/Unsafe.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/emul/compact/src/main/java/java/util/concurrent/Unsafe.java Sat Mar 19 13:15:11 2016 +0100 @@ -0,0 +1,77 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.util.concurrent; + +import java.lang.reflect.Field; + +final class Unsafe { + static Unsafe getUnsafe() { + throw new SecurityException(); + } + + void throwException(Throwable exception) { + throw new SecurityException(); + } + + void putOrderedObject(Object q, long u, ForkJoinTask t) { + throw new SecurityException(); + } + + boolean compareAndSwapObject(Object q, long l, Object t, Object object) { + throw new SecurityException(); + } + + Object getObjectVolatile(Object oldQ, long u) { + throw new SecurityException(); + } + + void putObjectVolatile(Object q, long l, Object t) { + throw new SecurityException(); + } + + long arrayBaseOffset(Class a) { + throw new SecurityException(); + } + + int arrayIndexScale(Class a) { + throw new SecurityException(); + } + + boolean compareAndSwapLong(Object aThis, long ctlOffset, long c, long nc) { + throw new SecurityException(); + } + + void unpark(ForkJoinWorkerThread w) { + throw new SecurityException(); + } + + boolean compareAndSwapInt(Object aThis, long blockedCountOffset, int b, int i) { + throw new SecurityException(); + } + + long objectFieldOffset(Field declaredField) { + throw new SecurityException(); + } + +}