diff --git a/jdk/make/lib/Lib-java.desktop.gmk b/jdk/make/lib/Lib-java.desktop.gmk index c8bc8195854..5433fe96acb 100644 --- a/jdk/make/lib/Lib-java.desktop.gmk +++ b/jdk/make/lib/Lib-java.desktop.gmk @@ -29,6 +29,7 @@ include LibCommon.gmk $(eval $(call FillCacheFind, $(wildcard $(JDK_TOPDIR)/src/java.desktop/*/native \ $(JDK_TOPDIR)/src/*/java.desktop/*/native))) +include LibosxLibraries.gmk include PlatformLibraries.gmk include Awt2dLibraries.gmk include SoundLibraries.gmk diff --git a/jdk/make/lib/Lib-jdk.deploy.osx.gmk b/jdk/make/lib/LibosxLibraries.gmk similarity index 94% rename from jdk/make/lib/Lib-jdk.deploy.osx.gmk rename to jdk/make/lib/LibosxLibraries.gmk index 881a387e14d..91ab6457cb4 100644 --- a/jdk/make/lib/Lib-jdk.deploy.osx.gmk +++ b/jdk/make/lib/LibosxLibraries.gmk @@ -23,18 +23,15 @@ # questions. # -include LibCommon.gmk - ifeq ($(OPENJDK_TARGET_OS), macosx) ################################################################################ - LIBOSX_DIRS := $(JDK_TOPDIR)/src/jdk.deploy.osx/macosx/native/libosx + LIBOSX_DIRS := $(JDK_TOPDIR)/src/java.desktop/macosx/native/libosx LIBOSX_CFLAGS := -I$(LIBOSX_DIRS) \ -I$(JDK_TOPDIR)/src/java.desktop/macosx/native/libosxapp \ $(LIBJAVA_HEADER_FLAGS) \ -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop \ - -I$(SUPPORT_OUTPUTDIR)/headers/jdk.deploy.osx \ # $(eval $(call SetupNativeCompilation,BUILD_LIBOSX, \ diff --git a/jdk/make/src/classes/build/tools/module/boot.modules b/jdk/make/src/classes/build/tools/module/boot.modules index c774b5a0300..948362f0a51 100644 --- a/jdk/make/src/classes/build/tools/module/boot.modules +++ b/jdk/make/src/classes/build/tools/module/boot.modules @@ -19,7 +19,6 @@ java.xml java.xml.crypto jdk.charsets jdk.deploy -jdk.deploy.osx jdk.httpserver jdk.jfr jdk.jsobject diff --git a/jdk/src/jdk.deploy.osx/macosx/native/libosx/CFileManager.m b/jdk/src/java.desktop/macosx/native/libosx/CFileManager.m similarity index 100% rename from jdk/src/jdk.deploy.osx/macosx/native/libosx/CFileManager.m rename to jdk/src/java.desktop/macosx/native/libosx/CFileManager.m diff --git a/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/Dispatch.java b/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/Dispatch.java deleted file mode 100644 index e983504a626..00000000000 --- a/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/Dispatch.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. - * 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 com.apple.concurrent; - -import java.util.concurrent.*; - -/** - * Factory for {@link Executor}s and {@link ExecutorService}s backed by - * libdispatch. - * - * Access is controlled through the Dispatch.getInstance() method, because - * performed tasks occur on threads owned by libdispatch. These threads are - * not owned by any particular AppContext or have any specific context - * classloader installed. - * - * @since Java for Mac OS X 10.6 Update 2 - */ -public final class Dispatch { - /** - * The priorities of the three default asynchronous queues. - */ - public enum Priority { - LOW(-2), NORMAL(0), HIGH(2); // values from - - final int nativePriority; - Priority(final int nativePriority) { this.nativePriority = nativePriority; } - }; - - final static Dispatch instance = new Dispatch(); - - /** - * Factory method returns an instnace of Dispatch if supported by the - * underlying operating system, and if the caller's security manager - * permits "canInvokeInSystemThreadGroup". - * - * @return a factory instance of Dispatch, or null if not available - */ - public static Dispatch getInstance() { - checkSecurity(); - if (!LibDispatchNative.nativeIsDispatchSupported()) return null; - - return instance; - } - - private static void checkSecurity() { - final SecurityManager security = System.getSecurityManager(); - if (security != null) security.checkPermission(new RuntimePermission("canInvokeInSystemThreadGroup")); - } - - private Dispatch() { } - - /** - * Creates an {@link Executor} that performs tasks asynchronously. The {@link Executor} - * cannot be shutdown, and enqueued {@link Runnable}s cannot be canceled. Passing null - * returns the {@link Priority.NORMAL} {@link Executor}. - * - * @param priority - the priority of the returned {@link Executor} - * @return an asynchronous {@link Executor} - */ - public Executor getAsyncExecutor(Priority priority) { - if (priority == null) priority = Priority.NORMAL; - final long nativeQueue = LibDispatchNative.nativeCreateConcurrentQueue(priority.nativePriority); - if (nativeQueue == 0L) return null; - return new LibDispatchConcurrentQueue(nativeQueue); - } - - int queueIndex = 0; - /** - * Creates an {@link ExecutorService} that performs tasks synchronously in FIFO order. - * Useful to protect a resource against concurrent modification, in lieu of a lock. - * Passing null returns an {@link ExecutorService} with a uniquely labeled queue. - * - * @param label - a label to name the queue, shown in several debugging tools - * @return a synchronous {@link ExecutorService} - */ - public ExecutorService createSerialExecutor(String label) { - if (label == null) label = ""; - if (label.length() > 256) label = label.substring(0, 256); - String queueName = "com.apple.java.concurrent."; - if ("".equals(label)) { - synchronized (this) { - queueName += queueIndex++; - } - } else { - queueName += label; - } - - final long nativeQueue = LibDispatchNative.nativeCreateSerialQueue(queueName); - if (nativeQueue == 0) return null; - return new LibDispatchSerialQueue(nativeQueue); - } - - Executor nonBlockingMainQueue = null; - /** - * Returns an {@link Executor} that performs the provided Runnables on the main queue of the process. - * Runnables submitted to this {@link Executor} will not run until the AWT is started or another native toolkit is running a CFRunLoop or NSRunLoop on the main thread. - * - * Submitting a Runnable to this {@link Executor} does not wait for the Runnable to complete. - * @return an asynchronous {@link Executor} that is backed by the main queue - */ - public synchronized Executor getNonBlockingMainQueueExecutor() { - if (nonBlockingMainQueue != null) return nonBlockingMainQueue; - return nonBlockingMainQueue = new LibDispatchMainQueue.ASync(); - } - - Executor blockingMainQueue = null; - /** - * Returns an {@link Executor} that performs the provided Runnables on the main queue of the process. - * Runnables submitted to this {@link Executor} will not run until the AWT is started or another native toolkit is running a CFRunLoop or NSRunLoop on the main thread. - * - * Submitting a Runnable to this {@link Executor} will block until the Runnable has completed. - * @return an {@link Executor} that is backed by the main queue - */ - public synchronized Executor getBlockingMainQueueExecutor() { - if (blockingMainQueue != null) return blockingMainQueue; - return blockingMainQueue = new LibDispatchMainQueue.Sync(); - } -} diff --git a/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/LibDispatchConcurrentQueue.java b/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/LibDispatchConcurrentQueue.java deleted file mode 100644 index af055aedb57..00000000000 --- a/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/LibDispatchConcurrentQueue.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. - * 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 com.apple.concurrent; - -import java.util.concurrent.Executor; - -class LibDispatchConcurrentQueue extends LibDispatchQueue implements Executor { - LibDispatchConcurrentQueue(final long queuePtr) { - super(queuePtr); - } - - @Override - public void execute(final Runnable task) { - LibDispatchNative.nativeExecuteAsync(ptr, task); - } - - @Override - protected synchronized void dispose() { - // should not dispose the default concurrent queues - } -} diff --git a/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/LibDispatchMainQueue.java b/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/LibDispatchMainQueue.java deleted file mode 100644 index 1e05192986c..00000000000 --- a/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/LibDispatchMainQueue.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. - * 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 com.apple.concurrent; - -import java.util.concurrent.Executor; - -abstract class LibDispatchMainQueue extends LibDispatchQueue implements Executor { - public LibDispatchMainQueue() { - super(LibDispatchNative.nativeGetMainQueue()); - } - - @Override - protected synchronized void dispose() { - // should not dispose the main queue - } - - static class Sync extends LibDispatchMainQueue { - @Override - public void execute(final Runnable task) { - LibDispatchNative.nativeExecuteSync(ptr, task); - } - } - - static class ASync extends LibDispatchMainQueue { - @Override - public void execute(final Runnable task) { - LibDispatchNative.nativeExecuteAsync(ptr, task); - } - } -} diff --git a/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/LibDispatchNative.java b/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/LibDispatchNative.java deleted file mode 100644 index 9b89ac546e3..00000000000 --- a/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/LibDispatchNative.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. - * 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 com.apple.concurrent; - -final class LibDispatchNative { - static { - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Void run() { - System.loadLibrary("osx"); - return null; - } - }); - } - - static native boolean nativeIsDispatchSupported(); - static native long nativeGetMainQueue(); - static native long nativeCreateConcurrentQueue(int priority); - static native long nativeCreateSerialQueue(String name); - static native void nativeReleaseQueue(long nativeQueue); - static native void nativeExecuteAsync(long nativeQueue, Runnable task); - static native void nativeExecuteSync(long nativeQueue, Runnable task); - - private LibDispatchNative() { } -} diff --git a/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/LibDispatchQueue.java b/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/LibDispatchQueue.java deleted file mode 100644 index f464f698541..00000000000 --- a/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/LibDispatchQueue.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. - * 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 com.apple.concurrent; - -class LibDispatchQueue extends LibDispatchRetainedResource { - LibDispatchQueue(final long queuePtr) { - super(queuePtr); - } -} diff --git a/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/LibDispatchRetainedResource.java b/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/LibDispatchRetainedResource.java deleted file mode 100644 index 9d6b59543b0..00000000000 --- a/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/LibDispatchRetainedResource.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. - * 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 com.apple.concurrent; - -class LibDispatchRetainedResource { - protected long ptr; - - protected LibDispatchRetainedResource(final long ptr) { - this.ptr = ptr; - } - - protected synchronized void dispose() { - if (ptr != 0) LibDispatchNative.nativeReleaseQueue(ptr); - ptr = 0; - } - - protected void finalize() throws Throwable { - dispose(); - } -} diff --git a/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/LibDispatchSerialQueue.java b/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/LibDispatchSerialQueue.java deleted file mode 100644 index bb22566aef0..00000000000 --- a/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/LibDispatchSerialQueue.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. - * 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 com.apple.concurrent; - -import java.util.List; -import java.util.concurrent.*; - -class LibDispatchSerialQueue extends AbstractExecutorService { - static final int RUNNING = 0; - static final int SHUTDOWN = 1; -// static final int STOP = 2; // not supported by GCD - static final int TERMINATED = 3; - - final Object lock = new Object(); - LibDispatchQueue nativeQueueWrapper; - volatile int runState; - - LibDispatchSerialQueue(final long queuePtr) { - nativeQueueWrapper = new LibDispatchQueue(queuePtr); - } - - @Override - public void execute(final Runnable task) { - if (nativeQueueWrapper == null) return; - LibDispatchNative.nativeExecuteAsync(nativeQueueWrapper.ptr, task); - } - - @Override - public boolean isShutdown() { - return runState != RUNNING; - } - - @Override - public boolean isTerminated() { - return runState == TERMINATED; - } - - @Override - public void shutdown() { - synchronized (lock) { - if (runState != RUNNING) return; - - runState = SHUTDOWN; - execute(new Runnable() { - public void run() { - synchronized (lock) { - runState = TERMINATED; - lock.notifyAll(); // for the benefit of awaitTermination() - } - } - }); - nativeQueueWrapper = null; - } - } - - @Override - public List shutdownNow() { - shutdown(); - return null; - } - - @Override - public boolean awaitTermination(final long timeout, final TimeUnit unit) throws InterruptedException { - if (runState == TERMINATED) return true; - - final long millis = unit.toMillis(timeout); - if (millis <= 0) return false; - - synchronized (lock) { - if (runState == TERMINATED) return true; - lock.wait(timeout); - if (runState == TERMINATED) return true; - } - - return false; - } -} diff --git a/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/package.html b/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/package.html deleted file mode 100644 index 003a7a239f3..00000000000 --- a/jdk/src/jdk.deploy.osx/macosx/classes/com/apple/concurrent/package.html +++ /dev/null @@ -1,7 +0,0 @@ - - - - -Apple-specific implementations of the java.util.concurrent.* API based on libdispatch. - - diff --git a/jdk/src/jdk.deploy.osx/macosx/native/libosx/Dispatch.m b/jdk/src/jdk.deploy.osx/macosx/native/libosx/Dispatch.m deleted file mode 100644 index cdeac0d435d..00000000000 --- a/jdk/src/jdk.deploy.osx/macosx/native/libosx/Dispatch.m +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. - * 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. - */ - -/* - * Must include this before JavaNativeFoundation.h to get jni.h from build - */ -#include "jni.h" -#include "jni_util.h" - -#import "com_apple_concurrent_LibDispatchNative.h" - -#import -#import - -/* - * Declare library specific JNI_Onload entry if static build - */ -DEF_STATIC_JNI_OnLoad - -/* - * Class: com_apple_concurrent_LibDispatchNative - * Method: nativeIsDispatchSupported - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL Java_com_apple_concurrent_LibDispatchNative_nativeIsDispatchSupported -(JNIEnv *env, jclass clazz) -{ - return JNI_TRUE; -} - - -/* - * Class: com_apple_concurrent_LibDispatchNative - * Method: nativeGetMainQueue - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_com_apple_concurrent_LibDispatchNative_nativeGetMainQueue -(JNIEnv *env, jclass clazz) -{ - dispatch_queue_t queue = dispatch_get_main_queue(); - return ptr_to_jlong(queue); -} - - -/* - * Class: com_apple_concurrent_LibDispatchNative - * Method: nativeCreateConcurrentQueue - * Signature: (I)J - */ -JNIEXPORT jlong JNICALL Java_com_apple_concurrent_LibDispatchNative_nativeCreateConcurrentQueue -(JNIEnv *env, jclass clazz, jint priority) -{ - dispatch_queue_t queue = dispatch_get_global_queue((long)priority, 0); - return ptr_to_jlong(queue); -} - - -/* - * Class: com_apple_concurrent_LibDispatchNative - * Method: nativeCreateSerialQueue - * Signature: (Ljava/lang/String;)J - */ -JNIEXPORT jlong JNICALL Java_com_apple_concurrent_LibDispatchNative_nativeCreateSerialQueue -(JNIEnv *env, jclass clazz, jstring name) -{ - if (name == NULL) return 0L; - - jboolean isCopy; - const char *queue_name = (*env)->GetStringUTFChars(env, name, &isCopy); - dispatch_queue_t queue = dispatch_queue_create(queue_name, NULL); - (*env)->ReleaseStringUTFChars(env, name, queue_name); - - return ptr_to_jlong(queue); -} - - -/* - * Class: com_apple_concurrent_LibDispatchNative - * Method: nativeReleaseQueue - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_com_apple_concurrent_LibDispatchNative_nativeReleaseQueue -(JNIEnv *env, jclass clazz, jlong nativeQueue) -{ - if (nativeQueue == 0L) return; - dispatch_release((dispatch_queue_t)jlong_to_ptr(nativeQueue)); -} - - -static JNF_CLASS_CACHE(jc_Runnable, "java/lang/Runnable"); -static JNF_MEMBER_CACHE(jm_run, jc_Runnable, "run", "()V"); - -static void perform_dispatch(JNIEnv *env, jlong nativeQueue, jobject runnable, void (*dispatch_fxn)(dispatch_queue_t, dispatch_block_t)) -{ -JNF_COCOA_ENTER(env); - dispatch_queue_t queue = (dispatch_queue_t)jlong_to_ptr(nativeQueue); - if (queue == NULL) return; // shouldn't happen - - // create a global-ref around the Runnable, so it can be safely passed to the dispatch thread - JNFJObjectWrapper *wrappedRunnable = [[JNFJObjectWrapper alloc] initWithJObject:runnable withEnv:env]; - - dispatch_fxn(queue, ^{ - // attach the dispatch thread to the JVM if necessary, and get an env - JNFThreadContext ctx = JNFThreadDetachOnThreadDeath | JNFThreadSetSystemClassLoaderOnAttach | JNFThreadAttachAsDaemon; - JNIEnv *blockEnv = JNFObtainEnv(&ctx); - - JNF_COCOA_ENTER(blockEnv); - - // call the user's runnable - JNFCallObjectMethod(blockEnv, [wrappedRunnable jObject], jm_run); - - // explicitly clear object while we have an env (it's cheaper that way) - [wrappedRunnable setJObject:NULL withEnv:blockEnv]; - - JNF_COCOA_EXIT(blockEnv); - - // let the env go, but leave the thread attached as a daemon - JNFReleaseEnv(blockEnv, &ctx); - }); - - // release this thread's interest in the Runnable, the block - // will have retained the it's own interest above - [wrappedRunnable release]; - -JNF_COCOA_EXIT(env); -} - - -/* - * Class: com_apple_concurrent_LibDispatchNative - * Method: nativeExecuteAsync - * Signature: (JLjava/lang/Runnable;)V - */ -JNIEXPORT void JNICALL Java_com_apple_concurrent_LibDispatchNative_nativeExecuteAsync -(JNIEnv *env, jclass clazz, jlong nativeQueue, jobject runnable) -{ - // enqueues and returns - perform_dispatch(env, nativeQueue, runnable, dispatch_async); -} - - -/* - * Class: com_apple_concurrent_LibDispatchNative - * Method: nativeExecuteSync - * Signature: (JLjava/lang/Runnable;)V - */ -JNIEXPORT void JNICALL Java_com_apple_concurrent_LibDispatchNative_nativeExecuteSync -(JNIEnv *env, jclass clazz, jlong nativeQueue, jobject runnable) -{ - // blocks until the Runnable completes - perform_dispatch(env, nativeQueue, runnable, dispatch_sync); -}