Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Niefer2007-04-23 14:58:45 +0000
committerAndrew Niefer2007-04-23 14:58:45 +0000
commit17d90b94c504f35214623e1382c1a85b79d0bae9 (patch)
treeff8b6f6835d3a71f87786519cafae604bf41d056
parent89f7944a131d088a1ab5eab96a7a971505b346d0 (diff)
downloadrt.equinox.framework-17d90b94c504f35214623e1382c1a85b79d0bae9.tar.gz
rt.equinox.framework-17d90b94c504f35214623e1382c1a85b79d0bae9.tar.xz
rt.equinox.framework-17d90b94c504f35214623e1382c1a85b79d0bae9.zip
bug 181698
-rw-r--r--bundles/org.eclipse.equinox.executable/library/carbon/eclipseCarbon.c76
-rw-r--r--bundles/org.eclipse.equinox.executable/library/eclipse.c5
-rw-r--r--bundles/org.eclipse.equinox.executable/library/eclipseJNI.c13
-rw-r--r--bundles/org.eclipse.equinox.executable/library/eclipseJNI.h5
-rw-r--r--bundles/org.eclipse.equinox.executable/library/eclipseNix.c7
-rw-r--r--bundles/org.eclipse.equinox.executable/library/eclipseOS.h6
-rw-r--r--bundles/org.eclipse.equinox.executable/library/make_version.mak2
-rw-r--r--bundles/org.eclipse.equinox.executable/library/win32/eclipseWin.c6
-rw-r--r--bundles/org.eclipse.equinox.executable/library/wpf/eclipseWpf.cpp6
9 files changed, 118 insertions, 8 deletions
diff --git a/bundles/org.eclipse.equinox.executable/library/carbon/eclipseCarbon.c b/bundles/org.eclipse.equinox.executable/library/carbon/eclipseCarbon.c
index 65a75fbf4..de8ebb9da 100644
--- a/bundles/org.eclipse.equinox.executable/library/carbon/eclipseCarbon.c
+++ b/bundles/org.eclipse.equinox.executable/library/carbon/eclipseCarbon.c
@@ -14,12 +14,13 @@
#include "eclipseOS.h"
#include "eclipseCommon.h"
+#include "eclipseJNI.h"
#include <unistd.h>
#include <CoreServices/CoreServices.h>
#include <Carbon/Carbon.h>
#include <mach-o/dyld.h>
-
+#include <pthread.h>
#include "NgCommon.h"
#include "NgImageData.h"
#include "NgWinBMPFileFormat.h"
@@ -45,6 +46,19 @@ static ControlRef pane = NULL;
static CGImageRef image = NULL;
static CGImageRef loadBMPImage(const char *image);
+/* thread stuff */
+typedef struct {
+ _TCHAR * libPath;
+ _TCHAR ** vmArgs;
+ _TCHAR ** progArgs;
+ int result;
+} StartVMArgs;
+
+static CFRunLoopRef loopRef = NULL;
+static void * startThread(void * init);
+static void runEventLoop(CFRunLoopRef ref);
+static void dummyCallback(void * info) {}
+
typedef CGImageSourceRef (*CGImageSourceCreateWithURL_FUNC) (CFURLRef, CFDictionaryRef);
typedef CGImageRef (*CGImageSourceCreateImageAtIndex_FUNC)(CGImageSourceRef, size_t, CFDictionaryRef);
static CGImageSourceCreateWithURL_FUNC createWithURL = NULL;
@@ -250,6 +264,66 @@ int launchJavaVM( _TCHAR* args[] )
return -1;
}
+int startJavaVM( _TCHAR* libPath, _TCHAR* vmArgs[], _TCHAR* progArgs[] )
+{
+ if (secondThread == 0)
+ return startJavaVM(libPath, vmArgs, progArgs);
+
+ /* else, --launcher.secondThread was specified, create a new thread and run the
+ * vm on it. This main thread will run the CFRunLoop
+ */
+ pthread_t thread;
+ struct rlimit limit = {0, 0};
+ int stackSize = 0;
+ if (getrlimit(RLIMIT_STACK, &limit) == 0) {
+ if (limit.rlim_cur != 0) {
+ stackSize = limit.rlim_cur;
+ }
+ }
+
+ /* initialize thread attributes */
+ pthread_attr_t attributes;
+ pthread_attr_init(&attributes);
+ pthread_attr_setscope(&attributes, PTHREAD_SCOPE_SYSTEM);
+ pthread_attr_setdetachstate(&attributes, PTHREAD_CREATE_DETACHED);
+ if (stackSize != 0)
+ pthread_attr_setstacksize(&attributes, stackSize);
+
+ /* arguments to start the vm */
+ StartVMArgs args;
+ args.libPath = libPath;
+ args.vmArgs = vmArgs;
+ args.progArgs = progArgs;
+
+ loopRef = CFRunLoopGetCurrent();
+
+ /* create the thread */
+ pthread_create( &thread, &attributes, &startThread, &args);
+ pthread_attr_destroy(&attributes);
+
+ runEventLoop(loopRef);
+
+ return args.result;
+}
+
+void * startThread(void * init) {
+ StartVMArgs *args = (StartVMArgs *) init;
+ args->result = startJavaJNI(args->libPath, args->vmArgs, args->progArgs);
+ return NULL;
+}
+
+void runEventLoop(CFRunLoopRef ref) {
+ CFRunLoopSourceContext sourceContext = { .version = 0, .info = NULL, .retain = NULL, .release = NULL,
+ .copyDescription = NULL, .equal = NULL, .hash = NULL,
+ .schedule = NULL, .cancel = NULL, .perform = &dummyCallback };
+
+ CFRunLoopSourceRef sourceRef = CFRunLoopSourceCreate(NULL, 0, &sourceContext);
+ CFRunLoopAddSource(ref, sourceRef, kCFRunLoopCommonModes);
+
+ CFRunLoopRun();
+ CFRelease(sourceRef);
+}
+
void disposeData(void *info, void *data, size_t size)
{
DisposePtr(data);
diff --git a/bundles/org.eclipse.equinox.executable/library/eclipse.c b/bundles/org.eclipse.equinox.executable/library/eclipse.c
index b78523e2f..94440b04b 100644
--- a/bundles/org.eclipse.equinox.executable/library/eclipse.c
+++ b/bundles/org.eclipse.equinox.executable/library/eclipse.c
@@ -227,6 +227,7 @@ companion startup.jar file (in the same directory as the executable).");
#define LIBRARY _T_ECLIPSE("--launcher.library")
#define SUPRESSERRORS _T_ECLIPSE("--launcher.suppressErrors")
#define INI _T_ECLIPSE("--launcher.ini")
+#define SECOND_THREAD _T_ECLIPSE("--launcher.secondThread")
/* constants for ee options file */
#define EE_EXECUTABLE _T_ECLIPSE("-Dee.executable=")
@@ -241,7 +242,8 @@ static int needConsole = 0; /* True: user wants a console */
static int debug = 0; /* True: output debugging info */
static int noSplash = 0; /* True: do not show splash win */
static int suppressErrors = 0; /* True: do not display errors dialogs */
-
+ int secondThread = 0; /* True: start the VM on a second thread */
+
static _TCHAR* showSplashArg = NULL; /* showsplash data (main launcher window) */
static _TCHAR* splashBitmap = NULL; /* the actual splash bitmap */
static _TCHAR * startupArg = NULL; /* path of the startup.jar the user wants to run relative to the program path */
@@ -280,6 +282,7 @@ static Option options[] = {
{ DEBUG, &debug, VALUE_IS_FLAG, 0 },
{ NOSPLASH, &noSplash, VALUE_IS_FLAG, 1 },
{ SUPRESSERRORS, &suppressErrors, VALUE_IS_FLAG, 1},
+ { SECOND_THREAD, &secondThread, VALUE_IS_FLAG, 1 },
{ LIBRARY, NULL, 0, 2 }, /* library was parsed by exe, just remove it */
{ INI, NULL, 0, 2 }, /* same with ini */
{ OS, &osArg, 0, 2 },
diff --git a/bundles/org.eclipse.equinox.executable/library/eclipseJNI.c b/bundles/org.eclipse.equinox.executable/library/eclipseJNI.c
index d3292df62..3623107bd 100644
--- a/bundles/org.eclipse.equinox.executable/library/eclipseJNI.c
+++ b/bundles/org.eclipse.equinox.executable/library/eclipseJNI.c
@@ -271,7 +271,7 @@ static jobjectArray createRunArgs( JNIEnv *env, _TCHAR * args[] ) {
return stringArray;
}
-int startJavaVM( _TCHAR* libPath, _TCHAR* vmArgs[], _TCHAR* progArgs[] )
+int startJavaJNI( _TCHAR* libPath, _TCHAR* vmArgs[], _TCHAR* progArgs[] )
{
int i;
int numVMArgs = -1;
@@ -358,8 +358,17 @@ int startJavaVM( _TCHAR* libPath, _TCHAR* vmArgs[], _TCHAR* progArgs[] )
}
void cleanupVM(int exitCode) {
- if (jvm == 0 || env == 0)
+ JNIEnv * localEnv = env;
+ if (jvm == 0)
return;
+
+ if (secondThread)
+ (*jvm)->AttachCurrentThread(jvm, (void**)&localEnv, NULL);
+ else
+ localEnv = env;
+ if (localEnv == 0)
+ return;
+
/* we call System.exit() unless osgi.noShutdown is set */
if (shouldShutdown(env)) {
jclass systemClass = NULL;
diff --git a/bundles/org.eclipse.equinox.executable/library/eclipseJNI.h b/bundles/org.eclipse.equinox.executable/library/eclipseJNI.h
index d1acf039e..d19f27eaa 100644
--- a/bundles/org.eclipse.equinox.executable/library/eclipseJNI.h
+++ b/bundles/org.eclipse.equinox.executable/library/eclipseJNI.h
@@ -18,8 +18,7 @@
#define loadVMLibrary loadVMLibraryW
#define unloadVMLibrary unloadVMLibraryW
#define getInvocationFunction getInvocationFunctionW
-#define launchJavaVM launchJavaVMW
-#define startJavaVM startJavaVMW
+#define startJavaJNI startJavaJNIW
#define cleanupVM cleanupVMW
#endif
@@ -77,7 +76,7 @@ JNIEXPORT void JNICALL takedown_splash(JNIEnv *, jobject);
* be returned to the main launcher, which will display a message if
* the termination was not normal.
*/
-extern int startJavaVM( _TCHAR* libPath, _TCHAR* vmArgs[], _TCHAR* progArgs[] );
+extern int startJavaJNI( _TCHAR* libPath, _TCHAR* vmArgs[], _TCHAR* progArgs[] );
extern void cleanupVM( int );
#endif
diff --git a/bundles/org.eclipse.equinox.executable/library/eclipseNix.c b/bundles/org.eclipse.equinox.executable/library/eclipseNix.c
index 9fb72a9b8..d26309897 100644
--- a/bundles/org.eclipse.equinox.executable/library/eclipseNix.c
+++ b/bundles/org.eclipse.equinox.executable/library/eclipseNix.c
@@ -14,6 +14,8 @@
#include "eclipseCommon.h"
#include "eclipseMozilla.h"
#include "eclipseUtil.h"
+#include "eclipseJNI.h"
+
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
@@ -209,3 +211,8 @@ void restartLauncher( char* program, char* args[] )
void processVMArgs(_TCHAR **vmargs[] ) {
/* nothing yet */
}
+
+int startJavaVM( _TCHAR* libPath, _TCHAR* vmArgs[], _TCHAR* progArgs[] )
+{
+ return startJavaJNI(libPath, vmArgs, progArgs);
+}
diff --git a/bundles/org.eclipse.equinox.executable/library/eclipseOS.h b/bundles/org.eclipse.equinox.executable/library/eclipseOS.h
index 4074ced86..a4d5ce26b 100644
--- a/bundles/org.eclipse.equinox.executable/library/eclipseOS.h
+++ b/bundles/org.eclipse.equinox.executable/library/eclipseOS.h
@@ -30,9 +30,11 @@
#define takeDownSplash takeDownSplashW
#define restartLauncher restartLauncherW
#define launchJavaVM launchJavaVMW
+#define startJavaVM startJavaVMW
#define eeLibPath eeLibPathW
#define processVMArgs processVMArgsW
#define initialArgv initialArgvW
+#define secondThread secondThreadW
#endif
/* Operating System Dependent Information */
@@ -47,6 +49,7 @@ extern _TCHAR* vmLibrary; /* name of the VM shared library */
extern int initialArgc; /* argc originally used to start launcher */
extern _TCHAR** initialArgv; /* argv originally used to start launcher */
extern _TCHAR* eeLibPath; /* library path specified in a .ee file */
+extern int secondThread; /* whether or not to start the vm on a second thread */
/* OS Specific Functions */
@@ -114,6 +117,9 @@ extern void restartLauncher( _TCHAR* program, _TCHAR* args[] );
/* launch the vm in a separate process and wait for it to finish */
extern int launchJavaVM( _TCHAR* args[] );
+/* launch the vm in this process using JNI invocation */
+extern int startJavaVM( _TCHAR* libPath, _TCHAR* vmArgs[], _TCHAR* progArgs[] );
+
/* do any platform specific processing of the user vmargs */
extern void processVMArgs(_TCHAR **vmargs[] );
diff --git a/bundles/org.eclipse.equinox.executable/library/make_version.mak b/bundles/org.eclipse.equinox.executable/library/make_version.mak
index 028e6edf7..0c0c950f6 100644
--- a/bundles/org.eclipse.equinox.executable/library/make_version.mak
+++ b/bundles/org.eclipse.equinox.executable/library/make_version.mak
@@ -10,5 +10,5 @@
#*******************************************************************************
maj_ver=1
-min_ver=011
+min_ver=012
LIB_VERSION = $(maj_ver)$(min_ver)
diff --git a/bundles/org.eclipse.equinox.executable/library/win32/eclipseWin.c b/bundles/org.eclipse.equinox.executable/library/win32/eclipseWin.c
index 3c6a37bfd..6fa03dbd5 100644
--- a/bundles/org.eclipse.equinox.executable/library/win32/eclipseWin.c
+++ b/bundles/org.eclipse.equinox.executable/library/win32/eclipseWin.c
@@ -13,6 +13,7 @@
#include "eclipseOS.h"
#include "eclipseUtil.h"
#include "eclipseCommon.h"
+#include "eclipseJNI.h"
#include <windows.h>
#include <commctrl.h>
@@ -436,3 +437,8 @@ static void CALLBACK detectJvmExit( HWND hwnd, UINT uMsg, UINT id, DWORD dwTime
void processVMArgs(_TCHAR **vmargs[] ) {
/* nothing yet */
}
+
+int startJavaVM( _TCHAR* libPath, _TCHAR* vmArgs[], _TCHAR* progArgs[] )
+{
+ return startJavaJNI(libPath, vmArgs, progArgs);
+}
diff --git a/bundles/org.eclipse.equinox.executable/library/wpf/eclipseWpf.cpp b/bundles/org.eclipse.equinox.executable/library/wpf/eclipseWpf.cpp
index 096841974..d6ed59d43 100644
--- a/bundles/org.eclipse.equinox.executable/library/wpf/eclipseWpf.cpp
+++ b/bundles/org.eclipse.equinox.executable/library/wpf/eclipseWpf.cpp
@@ -15,6 +15,7 @@ extern "C" {
#include "eclipseOS.h"
#include "eclipseUtil.h"
#include "eclipseCommon.h"
+#include "eclipseJNI.h"
#include <process.h>
#include <stdio.h>
@@ -507,4 +508,9 @@ void processVMArgs(_TCHAR **vmargs[] ) {
// /* nothing yet */
}
+int startJavaJNI( _TCHAR* libPath, _TCHAR* vmArgs[], _TCHAR* progArgs[] )
+{
+ return startJavaJNI(libPath, vmArgs, progArgs);
+}
+
} // extern "C"

Back to the top