Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSravan Kumar Lakkimsetti2017-09-21 16:16:10 +0000
committerSravan Kumar Lakkimsetti2017-09-21 16:16:10 +0000
commitbd29c279fe7c52910ef977717a9e41f5ec928846 (patch)
tree835b4d2fefb339453477e1f63505e5e43230f03d
parent1e4c4c30d8ae7d52c820d93fe1925bde976af065 (diff)
downloadrt.equinox.framework-bd29c279fe7c52910ef977717a9e41f5ec928846.tar.gz
rt.equinox.framework-bd29c279fe7c52910ef977717a9e41f5ec928846.tar.xz
rt.equinox.framework-bd29c279fe7c52910ef977717a9e41f5ec928846.zip
Bug 520636 - Make sure Eclipse starts with Java 9
Change-Id: Icf118d53142c6e809c872f7659f9a53cea3482ad Signed-off-by: Sravan Kumar Lakkimsetti <sravankumarl@in.ibm.com>
-rw-r--r--features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCocoa.c40
-rw-r--r--features/org.eclipse.equinox.executable.feature/library/eclipse.c60
-rw-r--r--features/org.eclipse.equinox.executable.feature/library/eclipseNix.c26
-rw-r--r--features/org.eclipse.equinox.executable.feature/library/eclipseOS.h4
-rw-r--r--features/org.eclipse.equinox.executable.feature/library/win32/eclipseWin.c31
5 files changed, 80 insertions, 81 deletions
diff --git a/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCocoa.c b/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCocoa.c
index 6bfa9def6..023223103 100644
--- a/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCocoa.c
+++ b/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCocoa.c
@@ -44,7 +44,7 @@ char *findCommand(char *command);
char* defaultVM = "java";
char* vmLibrary = "JavaVM";
char* shippedVMDir = "../../jre/Contents/Home/bin/"; // relative to launcher
-int isSunMaxPermSizeVM = 0;
+int isModularJVM = 0;
static void adjustLibraryPath(char * vmLibrary);
static char * findLib(char * command);
@@ -330,7 +330,8 @@ char** getArgVM( char* vm )
return result;
}
-char * getJavaVersion(char* command) {
+/* set isModularJVM to 1 if the JVM version is >= 9, 0 otherwise */
+void checkJavaVersion(char* command) {
FILE *fp;
char buffer[4096];
char *version = NULL, *firstChar;
@@ -338,7 +339,7 @@ char * getJavaVersion(char* command) {
sprintf(buffer,"%s -version 2>&1", command);
fp = popen(buffer, "r");
if (fp == NULL) {
- return NULL;
+ return;
}
while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) {
if (!version) {
@@ -354,25 +355,20 @@ char * getJavaVersion(char* command) {
version[numChars] = '\0';
}
}
- if (strstr(buffer, "Java HotSpot(TM)") || strstr(buffer, "OpenJDK")) {
- if (version != NULL) {
- _TCHAR *value = strtok(version, ".");
- if (value != NULL && (strtol(value, NULL, 10) == 1)) {
- value = strtok(NULL, ".");
- if (strtol(value, NULL, 10) < 8) {
- isSunMaxPermSizeVM = 1;
- }
- }
+ if (version != NULL) {
+ char *str = version;
+ /* According to the new Java version-string scheme, the first element is
+ * the major version number, details at http://openjdk.java.net/jeps/223 */
+ char *majorVersion = strtok(str, ".-");
+ if (majorVersion != NULL && (strtol(majorVersion, NULL, 10) >= 9)) {
+ isModularJVM = 1;
}
- break;
- }
- if (strstr(buffer, "IBM") != NULL) {
- isSunMaxPermSizeVM = 0;
- break;
+ free(version);
}
+ break;
}
pclose(fp);
- return version;
+ return;
}
char * getJavaHome() {
@@ -429,8 +425,8 @@ char * findVMLibrary( char* command ) {
if (strstr(cmd, "/JavaVM.framework/") != NULL && (strstr(cmd, "/Current/") != NULL || strstr(cmd, "/A/") != NULL)) {
cmd = getJavaHome();
}
- // This is necessary to initialize isSunMaxPermSizeVM
- getJavaVersion(cmd);
+ // This is necessary to initialize isModularJVM
+ checkJavaVersion(cmd);
result = JAVA_FRAMEWORK;
if (strstr(cmd, "/JavaVM.framework/") == NULL) {
char * lib = findLib(cmd);
@@ -625,8 +621,8 @@ void processVMArgs(char **vmargs[] )
}
}
-int isMaxPermSizeVM( _TCHAR * javaVM, _TCHAR * jniLib ) {
- return isSunMaxPermSizeVM;
+int isModularVM( _TCHAR * javaVM, _TCHAR * jniLib ) {
+ return isModularJVM;
}
NSString* getApplicationSupport() {
diff --git a/features/org.eclipse.equinox.executable.feature/library/eclipse.c b/features/org.eclipse.equinox.executable.feature/library/eclipse.c
index fa7db0cfc..dc951a5a6 100644
--- a/features/org.eclipse.equinox.executable.feature/library/eclipse.c
+++ b/features/org.eclipse.equinox.executable.feature/library/eclipse.c
@@ -252,6 +252,7 @@ home directory.");
#define PERM_GEN _T_ECLIPSE("--launcher.XXMaxPermSize")
#define XXPERMGEN _T_ECLIPSE("-XX:MaxPermSize=")
+#define ADDMODULES _T_ECLIPSE("--add-modules")
#define ACTION_OPENFILE _T_ECLIPSE("openFile")
#define GTK_VERSION _T_ECLIPSE("--launcher.GTK_version")
@@ -271,6 +272,9 @@ 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 int appendVmargs = 0; /* True: append cmdline vmargs to launcher.ini vmargs */
+#ifdef MACOSX
+static int skipJava9ParamRemoval = 0; /* Set to true only on macOS, if -vm was present on commandline or in eclipse.ini and points to a shared lib */
+#endif
static _TCHAR* showSplashArg = NULL; /* showsplash data (main launcher window) */
static _TCHAR* splashBitmap = NULL; /* the actual splash bitmap */
@@ -1035,28 +1039,41 @@ static _TCHAR** mergeConfigurationFilesVMArgs() {
}
static void adjustVMArgs(_TCHAR *javaVM, _TCHAR *jniLib, _TCHAR **vmArgv[]) {
- /* Sun/Oracle VMs below version 8 need some extra perm gen space */
- /* Detecting Sun VM is expensive - only do so if necessary */
- if (permGen != NULL) {
- int specified = 0, i = -1;
-
- /* first check to see if it is already specified */
- while ((*vmArgv)[++i] != NULL) {
- /* we are also counting the number of args here */
- if (!specified && _tcsncmp((*vmArgv)[i], XXPERMGEN, _tcslen(XXPERMGEN)) == 0) {
- specified = 1;
- }
- }
+ /* JVMs whose version is >= 9 need an extra VM argument (--add-modules) to start eclipse but earlier versions
+ * do not recognize this argument, remove it from the list of VM arguments when the JVM version is below 9 */
- if (!specified && isMaxPermSizeVM(javaVM, jniLib)) {
- _TCHAR ** oldArgs = *vmArgv;
- _TCHAR *newArg = malloc((_tcslen(XXPERMGEN) + _tcslen(permGen) + 1) * sizeof(_TCHAR));
- _stprintf(newArg, _T_ECLIPSE("%s%s"), XXPERMGEN, permGen);
+ int i = 0;
+
+#ifdef MACOSX
+ if (!skipJava9ParamRemoval && !isModularVM(javaVM, jniLib)) {
+#else
+ if (!isModularVM(javaVM, jniLib)) {
+#endif
+ while ((*vmArgv)[i] != NULL) {
+ if (_tcsncmp((*vmArgv)[i], ADDMODULES, _tcslen(ADDMODULES)) == 0) {
+ int j = 0, k = 0;
+
+ if ((_tcschr((*vmArgv)[i], '=') != NULL) && ((*vmArgv)[i][13] == '=')) {
+ /* --add-modules=<value> */
+ j = i + 1;
+ } else if (_tcslen(ADDMODULES) == _tcslen((*vmArgv)[i])) {
+ /* --add-modules <value> OR --add-modules <end-of-vmArgv> */
+ ((*vmArgv)[i + 1] != NULL) ? (j = i + 2) : (j = i + 1);
+ } else {
+ /* Probable new argument e.g. --add-modules-if-required or misspelled argument e.g. --add-modulesq */
+ i++;
+ continue;
+ }
- *vmArgv = malloc((i + 2) * sizeof(_TCHAR *));
- memcpy(*vmArgv, oldArgs, i * sizeof(_TCHAR *));
- (*vmArgv)[i] = newArg;
- (*vmArgv)[i + 1] = 0;
+ /* shift all remaining arguments, but keep i, so that we can find repeated occurrences of --add-modules */
+ k = i;
+ (*vmArgv)[k] = (*vmArgv)[j];
+ while ((*vmArgv)[j] != NULL) {
+ (*vmArgv)[++k] = (*vmArgv)[++j];
+ }
+ } else {
+ i++;
+ }
}
}
}
@@ -1682,6 +1699,9 @@ static int determineVM(_TCHAR** msg) {
return vmEEProps(vmName, msg);
case VM_LIBRARY:
+#ifdef MACOSX
+ skipJava9ParamRemoval = 1;
+#endif
ch = findCommand(vmName);
if(ch != NULL) {
jniLib = findVMLibrary(ch);
diff --git a/features/org.eclipse.equinox.executable.feature/library/eclipseNix.c b/features/org.eclipse.equinox.executable.feature/library/eclipseNix.c
index bda8b3cb9..5cfced7a0 100644
--- a/features/org.eclipse.equinox.executable.feature/library/eclipseNix.c
+++ b/features/org.eclipse.equinox.executable.feature/library/eclipseNix.c
@@ -168,7 +168,8 @@ JavaResults* startJavaVM( _TCHAR* libPath, _TCHAR* vmArgs[], _TCHAR* progArgs[],
return startJavaJNI(libPath, vmArgs, progArgs, jarFile);
}
-int isMaxPermSizeVM( _TCHAR * javaVM, _TCHAR * jniLib ) {
+/* returns 1 if the JVM version is >= 9, 0 otherwise */
+int isModularVM( _TCHAR * javaVM, _TCHAR * jniLib ) {
if (javaVM == NULL) {
return 0;
}
@@ -194,22 +195,17 @@ int isMaxPermSizeVM( _TCHAR * javaVM, _TCHAR * jniLib ) {
version[numChars] = '\0';
}
}
- if (_tcsstr(buffer, "Java HotSpot(TM)") || _tcsstr(buffer, "OpenJDK")) {
- if (version != NULL) {
- _TCHAR *value = _tcstok(version, ".");
- if (value != NULL && (_tcstol(value, NULL, 10) == 1)) {
- value = _tcstok(NULL, ".");
- if (_tcstol(value, NULL, 10) < 8) {
- result = 1;
- }
- }
+ if (version != NULL) {
+ _TCHAR *str = version;
+ /* According to the new Java version-string scheme, the first element is
+ * the major version number, details at http://openjdk.java.net/jeps/223 */
+ _TCHAR *majorVersion = _tcstok(str, ".-");
+ if (majorVersion != NULL && (_tcstol(majorVersion, NULL, 10) >= 9)) {
+ result = 1;
}
- break;
- }
- if (_tcsstr(buffer, "IBM") != NULL) {
- result = 0;
- break;
+ free(version);
}
+ break;
}
pclose(fp);
return result;
diff --git a/features/org.eclipse.equinox.executable.feature/library/eclipseOS.h b/features/org.eclipse.equinox.executable.feature/library/eclipseOS.h
index 7e78322b1..0b2b6a782 100644
--- a/features/org.eclipse.equinox.executable.feature/library/eclipseOS.h
+++ b/features/org.eclipse.equinox.executable.feature/library/eclipseOS.h
@@ -110,8 +110,8 @@ extern JavaResults* startJavaVM( _TCHAR* libPath, _TCHAR* vmArgs[], _TCHAR* prog
/* do any platform specific processing of the user vmargs */
extern void processVMArgs(_TCHAR **vmargs[] );
-/* is this a Sun/Oracle VM whose version is < 8 (then it needs extra perm gen space), returns 0 if we don't know */
-extern int isMaxPermSizeVM( _TCHAR * javaVM, _TCHAR * jniLib );
+/* is this a JVM whose version is >= 9 (then allow the --add-modules VM argument), returns 0 if we don't know */
+extern int isModularVM( _TCHAR * javaVM, _TCHAR * jniLib );
/* an array of paths that will need to be on the search path to load the vm shared library */
extern _TCHAR ** getVMLibrarySearchPath(_TCHAR * vmLibrary);
diff --git a/features/org.eclipse.equinox.executable.feature/library/win32/eclipseWin.c b/features/org.eclipse.equinox.executable.feature/library/win32/eclipseWin.c
index 4df9e99dd..73a394344 100644
--- a/features/org.eclipse.equinox.executable.feature/library/win32/eclipseWin.c
+++ b/features/org.eclipse.equinox.executable.feature/library/win32/eclipseWin.c
@@ -77,10 +77,7 @@ typedef struct {
WORD codepage;
} TRANSLATIONS;
-#define COMPANY_NAME_KEY _T_ECLIPSE("\\StringFileInfo\\%04x%04x\\CompanyName")
#define PRODUCT_VERSION_KEY _T_ECLIPSE("\\StringFileInfo\\%04x%04x\\ProductVersion")
-#define SUN_MICROSYSTEMS _T_ECLIPSE("Sun Microsystems")
-#define ORACLE _T_ECLIPSE("Oracle")
static void sendOpenFileMessage(HWND window) {
_TCHAR* id;
@@ -600,16 +597,16 @@ JavaResults* startJavaVM( _TCHAR* libPath, _TCHAR* vmArgs[], _TCHAR* progArgs[],
return startJavaJNI(libPath, vmArgs, progArgs, jarFile);
}
-int isMaxPermSizeVM( _TCHAR * javaVM, _TCHAR * jniLib ) {
+/* returns 1 if the JVM version is >= 9, 0 otherwise */
+int isModularVM( _TCHAR * javaVM, _TCHAR * jniLib ) {
_TCHAR *vm = (jniLib != NULL) ? jniLib : javaVM;
int result = 0;
DWORD infoSize;
DWORD handle;
void * info;
- _TCHAR *key, *value, *versionKey, *version, *majorVersion = NULL;
- size_t i;
- int valueSize, versionSize;
+ _TCHAR *versionKey, *version, *majorVersion = NULL;
+ int versionSize;
if (vm == NULL)
return 0;
@@ -623,25 +620,15 @@ int isMaxPermSizeVM( _TCHAR * javaVM, _TCHAR * jniLib ) {
VerQueryValue(info, _T_ECLIPSE("\\VarFileInfo\\Translation"), (void *) &translations, &translationsSize);
/* this size is only right because %04x is 4 characters */
- key = malloc((_tcslen(COMPANY_NAME_KEY) + 1) * sizeof(_TCHAR));
versionKey = malloc((_tcslen(PRODUCT_VERSION_KEY) + 1) * sizeof(_TCHAR));
- for (i = 0; i < (translationsSize / sizeof(TRANSLATIONS)); i++) {
- _stprintf(key, COMPANY_NAME_KEY, translations[i].language, translations[i].codepage);
- VerQueryValue(info, key, (void *)&value, &valueSize);
-
- if ((_tcsncmp(value, SUN_MICROSYSTEMS, _tcslen(SUN_MICROSYSTEMS)) == 0) || (_tcsncmp(value, ORACLE, _tcslen(ORACLE)) == 0)) {
- _stprintf(versionKey, PRODUCT_VERSION_KEY, translations[i].language, translations[i].codepage);
- VerQueryValue(info, versionKey, (void *)&version, &versionSize);
- if (versionSize > 1) {
- majorVersion = _tcstok(version, ".");
- }
- if ((majorVersion != NULL) && (_tcstol(majorVersion, NULL, 10) < 8)) {
+ _stprintf(versionKey, PRODUCT_VERSION_KEY, translations[0].language, translations[0].codepage);
+ VerQueryValue(info, versionKey, (void *)&version, &versionSize);
+ if (versionSize >= 1) {
+ majorVersion = _tcstok(version, ".-");
+ if ((majorVersion != NULL) && (_tcstol(majorVersion, NULL, 10) >= 9)) {
result = 1;
}
- break;
}
- }
- free(key);
free(versionKey);
}
free(info);

Back to the top