Skip to content
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

Support Android #269

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
69312e4
Support Java VMs without java.lang.management.ManagementFactory.
Apr 30, 2017
23df626
Make ConcurrentSkipListPriorityQueue less unsafe.
May 1, 2017
148cee6
Make ConcurrentSkipListPriorityQueue.Node less unsafe.
May 1, 2017
bd972d0
Make ConcurrentSkipListPriorityQueue.Index less unsafe.
May 1, 2017
bef896c
Implement OwnedSynchronizer2 without access to sun.misc.Unsafe.
May 1, 2017
b6a5697
Support Java 1.6 in ParkableForkJoinTask.
May 1, 2017
014c407
Implement ParkableForkJoinTask without access to sun.misc.Unsafe.
May 1, 2017
2504149
Do not require JMX in DefaultFiberScheduler.
May 1, 2017
2719fdb
Support Java 1.6 in ThreadAccess.
May 1, 2017
43c0287
Implement ThreadAccess without access to sun.misc.Unsafe.
May 1, 2017
8534a6a
Factor-out getDeclaredConstructorAndEnableAccess().
May 1, 2017
d461aaf
Refactor ThreadAccess.
May 2, 2017
d2df7cb
Refactor ThreadAccess.
May 2, 2017
d53884e
Fork-off "JavaVMThreadAccess.java".
May 2, 2017
03024ff
Move functionality from static ThreadAccess methods to JavaVMThreadAc…
May 2, 2017
cf8d212
Fix users of ThreadAccess to use ThreadAccess singleton instead of st…
May 2, 2017
a750cdf
Fork-off "DalvikVMThreadAccess.java".
May 2, 2017
b726a19
Try to load DalvikVMThreadAccess if loading JavaVMThreadAccess fails.
May 2, 2017
d073e81
Provide different Implementations for ThreadLocalRandom depending on …
May 3, 2017
d89a87e
Rename method in order to work around Dalvik VM bug.
May 3, 2017
680b231
Implement DalvikVMThreadAccess.
May 3, 2017
9f7b036
Replace embedded binary blob of JSR166e by dependency on a JSR166e pr…
May 3, 2017
953c05a
Fortify ParkJava1_6.
May 3, 2017
e795f7d
Comment in ParkJava1_6.
May 3, 2017
9344f98
Implement Fiber without access to sun.misc.Unsafe.
May 1, 2017
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
Binary file removed baselib/jsr166e.jar
Binary file not shown.
10 changes: 3 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ project (':quasar-core') {
}

dependencies {
jdk7Compile ":jsr166e"
jdk7Compile group: 'org.glassfish.jersey.bundles.repackaged', name: 'jersey-jsr166e', version: '2.25.1'
jdk7testCompile group: 'org.glassfish.jersey.bundles.repackaged', name: 'jersey-jsr166e', version: '2.25.1'
compile ":high-scale-lib"
compile "org.hdrhistogram:HdrHistogram:2.1.9"
compile("org.latencyutils:LatencyUtils:2.0.3") {
Expand Down Expand Up @@ -530,13 +531,9 @@ project (':quasar-core') {
targetCompatibility = '1.7'
}

// jdk7Jar {
// from zipTree("${baselib}/jsr166e.jar") // include non-Maven jars
// }

jdk7ShadowJar {
dependencies {
include(dependency(':jsr166e'))
include(dependency(group: 'org.glassfish.jersey.bundles.repackaged', name: 'jersey-jsr166e', version: '2.25.1'))
}
}

Expand Down Expand Up @@ -600,7 +597,6 @@ project (':quasar-core') {

[installer, deployer]*.pom*.whenConfigured {
it.dependencies.removeAll { dep ->
dep.artifactId.startsWith('jsr166e') ||
dep.artifactId.startsWith('high-scale-lib') ||
dep.groupId == 'org.ow2.asm'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import co.paralleluniverse.common.util.Debug;
import co.paralleluniverse.common.util.Objects;
import co.paralleluniverse.concurrent.util.MapUtil;
import co.paralleluniverse.concurrent.util.ThreadAccess;
import static co.paralleluniverse.concurrent.util.ThreadAccess.ThreadAccess;
import co.paralleluniverse.fibers.DefaultFiberScheduler;
import co.paralleluniverse.fibers.Fiber;
import co.paralleluniverse.fibers.FiberFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package co.paralleluniverse.common.monitoring;

//import java.util.concurrent.atomic.AtomicLong;
import jsr166e.LongAdder;
import jersey.repackaged.jsr166e.LongAdder;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package co.paralleluniverse.common.monitoring;

import java.lang.ref.WeakReference;
import jsr166e.ForkJoinPool;
import jersey.repackaged.jsr166e.ForkJoinPool;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
import jsr166e.ForkJoinPool;
import jersey.repackaged.jsr166e.ForkJoinPool;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import co.paralleluniverse.common.monitoring.Metrics;
import com.codahale.metrics.Gauge;
import static com.codahale.metrics.MetricRegistry.name;
import jsr166e.ForkJoinPool;
import jersey.repackaged.jsr166e.ForkJoinPool;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import com.codahale.metrics.Reservoir;
import com.codahale.metrics.Snapshot;
import java.io.OutputStream;
import jsr166e.LongAdder;
import jsr166e.LongMaxUpdater;
import jersey.repackaged.jsr166e.LongAdder;
import jersey.repackaged.jsr166e.LongMaxUpdater;

/**
* This is a false reservoir that merely records the precise max and min, as well as an approximate mean.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
*/
package co.paralleluniverse.concurrent.forkjoin;

import jsr166e.ForkJoinPool;
import jsr166e.ForkJoinWorkerThread;
import jersey.repackaged.jsr166e.ForkJoinPool;
import jersey.repackaged.jsr166e.ForkJoinWorkerThread;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
*/
package co.paralleluniverse.concurrent.forkjoin;

import jsr166e.ForkJoinPool;
import jsr166e.ForkJoinWorkerThread;
import jersey.repackaged.jsr166e.ForkJoinPool;
import jersey.repackaged.jsr166e.ForkJoinWorkerThread;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package co.paralleluniverse.concurrent.forkjoin;

import java.util.concurrent.ExecutorService;
import jsr166e.ForkJoinTask;
import jersey.repackaged.jsr166e.ForkJoinTask;

public final class ForkJoinUtil {
public static ExecutorService getPool() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import co.paralleluniverse.fibers.FibersMonitor;
import java.lang.Thread.UncaughtExceptionHandler;
import java.util.concurrent.atomic.AtomicInteger;
import jsr166e.ForkJoinPool;
import jersey.repackaged.jsr166e.ForkJoinPool;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import co.paralleluniverse.common.util.Exceptions;
import co.paralleluniverse.common.util.SystemProperties;
import co.paralleluniverse.common.util.UtilUnsafe;
import co.paralleluniverse.concurrent.util.ThreadAccess;
import static co.paralleluniverse.concurrent.util.ThreadAccess.ThreadAccess;
import co.paralleluniverse.fibers.Fiber;
import jsr166e.ForkJoinPool;
import jsr166e.ForkJoinTask;
import jsr166e.ForkJoinWorkerThread;
import jersey.repackaged.jsr166e.ForkJoinPool;
import jersey.repackaged.jsr166e.ForkJoinTask;
import jersey.repackaged.jsr166e.ForkJoinWorkerThread;

import sun.misc.Unsafe;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

/**
*
Expand All @@ -34,7 +34,7 @@ public abstract class ParkableForkJoinTask<V> extends ForkJoinTask<V> {
public static final FlightRecorder RECORDER = Debug.isDebug() ? Debug.getGlobalFlightRecorder() : null;
public static final boolean CAPTURE_UNPARK_STACK = Debug.isDebug() || SystemProperties.isEmptyOrTrue("co.paralleluniverse.fibers.captureUnparkStackTrace");
public static final Object EMERGENCY_UNBLOCKER = new Object();
public static final Park PARK = new Park();
public static final Park PARK = Park.create();
public static final int RUNNABLE = 0;
public static final int LEASED = 1;
public static final int PARKED = -1;
Expand Down Expand Up @@ -71,7 +71,7 @@ protected boolean exec() {
this.blocker = null;
setCurrent(this);
try {
return doExec();
return internalDoExec();
} finally {
setTarget(currentThread, oldTarget); // can't use enclosing for the same reason can't nullify enclosing. See below.
//enclosing = null; -- can't nullify enclosing here, because by the time we get here, his task may have been re-scheduled and enclosing re-set
Expand Down Expand Up @@ -111,7 +111,7 @@ public static Object getTarget(Thread thread) {
return ThreadAccess.getTarget(thread);
}

boolean doExec() {
boolean internalDoExec() { // Do not call this method "doExec()", as (due to bug https://code.google.com/p/android/issues/detail?id=60406) on some Android VMs, callers of this method will actually call FiberForkJoinScheduler$FiberForkJoinTask.doExec()
try {
onExec();
boolean res = exec1();
Expand Down Expand Up @@ -139,15 +139,15 @@ ParkableForkJoinTask getEnclosing() {

protected void onExec() {
if (Debug.isDebug())
record("doExec", "executing %s", this);
record("internalDoExec", "executing %s", this);
}

protected void onCompletion(boolean res) {
record("doExec", "done normally %s", this, Boolean.valueOf(res));
record("internalDoExec", "done normally %s", this, Boolean.valueOf(res));
}

protected void onException(Throwable t) {
record("doExec", "exception in %s - %s, %s", this, t, t.getStackTrace());
record("internalDoExec", "exception in %s - %s, %s", this, t, t.getStackTrace());
throw Exceptions.rethrow(t);
}

Expand All @@ -157,7 +157,7 @@ protected void parking(boolean yield) {

protected void onParked(boolean yield) {
if (Debug.isDebug())
record("doExec", "parked " + (yield ? "(yield)" : "(park)") + " %s", this);
record("internalDoExec", "parked " + (yield ? "(yield)" : "(park)") + " %s", this);
}

protected Object getUnparker() {
Expand Down Expand Up @@ -305,7 +305,7 @@ protected void yield() throws Exception {
}

protected void submit() {
assert Thread.currentThread() instanceof jsr166e.ForkJoinWorkerThread;
assert Thread.currentThread() instanceof ForkJoinWorkerThread;
fork();
}

Expand All @@ -324,8 +324,10 @@ protected void setState(int state) {
this.state = state;
}

private static final AtomicIntegerFieldUpdater<ParkableForkJoinTask> stateUpdater = AtomicIntegerFieldUpdater.newUpdater(ParkableForkJoinTask.class,"state");

boolean compareAndSetState(int expect, int update) {
return UNSAFE.compareAndSwapInt(this, stateOffset, expect, update);
return stateUpdater.compareAndSet(this, expect, update);
}

@Override
Expand Down Expand Up @@ -366,26 +368,43 @@ public static void record(String method, String format, Object arg1, Object arg2
if (RECORDER != null)
RECORDER.record(1, new FlightRecorderMessage("ParkableForkJoinTask", method, format, new Object[]{arg1, arg2, arg3, arg4, arg5}));
}
private static final Unsafe UNSAFE = UtilUnsafe.getUnsafe();
private static final long stateOffset;

static {
try {
stateOffset = UNSAFE.objectFieldOffset(ParkableForkJoinTask.class.getDeclaredField("state"));
} catch (Exception ex) {
throw new AssertionError(ex);
}
}

public static class Park extends Error {
private Park() {
super(null, null, false, false);
}

protected Park(String message,Throwable cause) { // Just to provide a means for ParkJava1_6 to call its super-constructor.
super(message,cause);
}

@Override
public synchronized Throwable fillInStackTrace() {
return this;
}

public static Park create() {
try {
return new Park();
} catch (NoSuchMethodError e) { // We do not run JDK 1.7 or higher and hence do not have a constructor Error(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) we could call.
return new ParkJava1_6(); // Hence we need to fallback to a JDK 1.6 implementation.
}
}
}

/*
Note that there will be only one singleton instance of this class, possibly being thrown by multiple threads simultaneously.
However, this should not pose any problems, as the Java VM spec does not specify that the "athrow" instruction changes any field of the Throwable object.
Starting with Java 1.7, exception handler code may call addSuppressed(), but under Java 1.7, this class should not be in use in the first place.
*/
public static class ParkJava1_6 extends Park {
private ParkJava1_6() {
super(null, null);
}

public void setStackTrace(StackTraceElement[] stackTrace) {
throw new AssertionError("Cannot set stack trace "+stackTrace+" to singleton throwable.");
}
}

private static final class DummyRunnable implements Runnable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.concurrent.AbstractExecutorService;
import java.util.concurrent.Callable;
import java.util.concurrent.RunnableFuture;
import jsr166e.CompletableFuture;
import jersey.repackaged.jsr166e.CompletableFuture;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import jsr166e.CompletableFuture;
import jersey.repackaged.jsr166e.CompletableFuture;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import java.util.concurrent.Callable;
import java.util.concurrent.RunnableFuture;
import jsr166e.CompletableFuture;
import jersey.repackaged.jsr166e.CompletableFuture;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package co.paralleluniverse.concurrent.util;

import java.util.concurrent.ConcurrentMap;
import jsr166e.ConcurrentHashMapV8;
import jersey.repackaged.jsr166e.ConcurrentHashMapV8;

public final class MapUtil {
public static <K, V> ConcurrentMap<K, V> newConcurrentHashMap() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2013-2017, Parallel Universe Software Co. All rights reserved.
*
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation
*
* or (per the licensee's choosing)
*
* under the terms of the GNU Lesser General Public License version 3.0
* as published by the Free Software Foundation.
*/
package co.paralleluniverse.concurrent.util;


/**
Drop-in replacement for ThreadLocalRandom (with different implementations for JDK8 and JDK7).
*/
public final class ThreadLocalRandom {
public static jersey.repackaged.jsr166e.ThreadLocalRandom current() {
return jersey.repackaged.jsr166e.ThreadLocalRandom.current();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
import java.util.concurrent.Executor;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import jsr166e.ConcurrentHashMapV8;
import jsr166e.ForkJoinPool;
import jsr166e.ForkJoinTask;
import jersey.repackaged.jsr166e.ConcurrentHashMapV8;
import jersey.repackaged.jsr166e.ForkJoinPool;
import jersey.repackaged.jsr166e.ForkJoinTask;

/**
* A {@code ForkJoinPool} based scheduler for fibers.
Expand Down
Loading