--- a/jdk/src/java.base/share/native/libjli/java.c Tue Mar 15 13:48:26 2016 -0700
+++ b/jdk/src/java.base/share/native/libjli/java.c Thu Mar 17 19:04:16 2016 +0000
@@ -69,10 +69,12 @@
static jboolean printUsage = JNI_FALSE; /* print and exit*/
static jboolean printXUsage = JNI_FALSE; /* print and exit*/
static char *showSettings = NULL; /* print but continue */
+static char *listModules = NULL;
static const char *_program_name;
static const char *_launcher_name;
static jboolean _is_java_args = JNI_FALSE;
+static jboolean _have_classpath = JNI_FALSE;
static const char *_fVersion;
static jboolean _wc_enabled = JNI_FALSE;
static jint _ergo_policy = DEFAULT_POLICY;
@@ -96,6 +98,14 @@
* Prototypes for functions internal to launcher.
*/
static void SetClassPath(const char *s);
+static void SetModulePath(const char *s);
+static void SetUpgradeModulePath(const char *s);
+static void SetMainModule(const char *s);
+static void SetAddModulesProp(const char *mods);
+static void SetLimitModulesProp(const char *mods);
+static void SetAddReadsProp(const jint n, const char *s);
+static void SetAddExportsProp(const jint n, const char *s);
+static void SetPatchProp(const jint n, const char *s);
static void SelectVersion(int argc, char **argv, char **main_class);
static void SetJvmEnvironment(int argc, char **argv);
static jboolean ParseArguments(int *pargc, char ***pargv,
@@ -114,6 +124,7 @@
static void PrintJavaVersion(JNIEnv *env, jboolean extraLF);
static void PrintUsage(JNIEnv* env, jboolean doXUsage);
static void ShowSettings(JNIEnv* env, char *optString);
+static void ListModules(JNIEnv* env, char *optString);
static void SetPaths(int argc, char **argv);
@@ -193,7 +204,6 @@
{
int mode = LM_UNKNOWN;
char *what = NULL;
- char *cpath = 0;
char *main_class = NULL;
int ret;
InvocationFunctions ifn;
@@ -270,11 +280,10 @@
}
} else {
/* Set default CLASSPATH */
- cpath = getenv("CLASSPATH");
- if (cpath == NULL) {
- cpath = ".";
+ char* cpath = getenv("CLASSPATH");
+ if (cpath != NULL) {
+ SetClassPath(cpath);
}
- SetClassPath(cpath);
}
/* Parse command line options; if the return value of
@@ -382,6 +391,12 @@
CHECK_EXCEPTION_LEAVE(1);
}
+ if (listModules != NULL) {
+ ListModules(env, listModules);
+ CHECK_EXCEPTION_LEAVE(1);
+ LEAVE();
+ }
+
if (printVersion || showVersion) {
PrintJavaVersion(env, showVersion);
CHECK_EXCEPTION_LEAVE(0);
@@ -520,7 +535,12 @@
}
} else {
if (JLI_StrCmp(arg, "-classpath") == 0 ||
- JLI_StrCmp(arg, "-cp") == 0) {
+ JLI_StrCmp(arg, "-cp") == 0 ||
+ JLI_StrCmp(arg, "-modulepath") == 0 ||
+ JLI_StrCmp(arg, "-mp") == 0 ||
+ JLI_StrCmp(arg, "-upgrademodulepath") == 0 ||
+ JLI_StrCmp(arg, "-addmods") == 0 ||
+ JLI_StrCmp(arg, "-limitmods") == 0) {
newArgv[newArgvIdx++] = arg;
argi++;
if (argi < argc) {
@@ -841,6 +861,105 @@
AddOption(def, NULL);
if (s != orig)
JLI_MemFree((char *) s);
+ _have_classpath = JNI_TRUE;
+}
+
+static void
+SetModulePath(const char *s)
+{
+ char *def;
+ const char *orig = s;
+ static const char format[] = "-Djdk.module.path=%s";
+ if (s == NULL)
+ return;
+ s = JLI_WildcardExpandClasspath(s);
+ def = JLI_MemAlloc(sizeof(format)
+ - 2 /* strlen("%s") */
+ + JLI_StrLen(s));
+ sprintf(def, format, s);
+ AddOption(def, NULL);
+ if (s != orig)
+ JLI_MemFree((char *) s);
+}
+
+static void
+SetUpgradeModulePath(const char *s)
+{
+ char *def;
+ const char *orig = s;
+ static const char format[] = "-Djdk.upgrade.module.path=%s";
+ if (s == NULL)
+ return;
+ s = JLI_WildcardExpandClasspath(s);
+ def = JLI_MemAlloc(sizeof(format)
+ - 2 /* strlen("%s") */
+ + JLI_StrLen(s));
+ sprintf(def, format, s);
+ AddOption(def, NULL);
+ if (s != orig)
+ JLI_MemFree((char *) s);
+}
+
+static void
+SetMainModule(const char *s)
+{
+ static const char format[] = "-Djdk.module.main=%s";
+ char* slash = JLI_StrChr(s, '/');
+ size_t s_len, def_len;
+ char *def;
+
+ /* value may be <module> or <module>/<mainclass> */
+ if (slash == NULL) {
+ s_len = JLI_StrLen(s);
+ } else {
+ s_len = (size_t) (slash - s);
+ }
+ def_len = sizeof(format)
+ - 2 /* strlen("%s") */
+ + s_len;
+ def = JLI_MemAlloc(def_len);
+ JLI_Snprintf(def, def_len, format, s);
+ AddOption(def, NULL);
+}
+
+static void
+SetAddModulesProp(const char *mods) {
+ size_t buflen = JLI_StrLen(mods) + 40;
+ char *prop = (char *)JLI_MemAlloc(buflen);
+ JLI_Snprintf(prop, buflen, "-Djdk.launcher.addmods=%s", mods);
+ AddOption(prop, NULL);
+}
+
+static void
+SetLimitModulesProp(const char *mods) {
+ size_t buflen = JLI_StrLen(mods) + 40;
+ char *prop = (char *)JLI_MemAlloc(buflen);
+ JLI_Snprintf(prop, buflen, "-Djdk.launcher.limitmods=%s", mods);
+ AddOption(prop, NULL);
+}
+
+static void
+SetAddReadsProp(const jint n, const char *s) {
+ size_t buflen = JLI_StrLen(s) + 40;
+ char *prop = (char *)JLI_MemAlloc(buflen);
+ JLI_Snprintf(prop, buflen, "-Djdk.launcher.addreads.%d=%s", n, s);
+ AddOption(prop, NULL);
+}
+
+static void
+SetAddExportsProp(const jint n, const char *s) {
+ size_t buflen = JLI_StrLen(s) + 40;
+ char *prop = (char *)JLI_MemAlloc(buflen);
+ JLI_Snprintf(prop, buflen, "-Djdk.launcher.addexports.%d=%s", n, s);
+ AddOption(prop, NULL);
+}
+
+static void
+SetPatchProp(const jint n, const char *s) {
+ size_t buflen = JLI_StrLen(s) + 40;
+ char *prop = (char *)JLI_MemAlloc(buflen);
+ JLI_Snprintf(prop, buflen, "-Djdk.launcher.patch.%d=%s", n, s);
+ AddOption(prop, NULL);
}
/*
@@ -1030,9 +1149,45 @@
SetClassPath(*argv);
mode = LM_CLASS;
argv++; --argc;
+ } else if (JLI_StrCmp(arg, "-modulepath") == 0 || JLI_StrCmp(arg, "-mp") == 0) {
+ ARG_CHECK (argc, ARG_ERROR4, arg);
+ SetModulePath(*argv);
+ argv++; --argc;
+ } else if (JLI_StrCmp(arg, "-upgrademodulepath") == 0) {
+ ARG_CHECK (argc, ARG_ERROR4, arg);
+ SetUpgradeModulePath(*argv);
+ argv++; --argc;
} else if (JLI_StrCmp(arg, "-jar") == 0) {
ARG_CHECK (argc, ARG_ERROR2, arg);
mode = LM_JAR;
+ } else if (JLI_StrCmp(arg, "-m") == 0) {
+ ARG_CHECK (argc, ARG_ERROR5, arg);
+ SetMainModule(*argv);
+ mode = LM_MODULE;
+ } else if (JLI_StrCmp(arg, "-addmods") == 0) {
+ ARG_CHECK (argc, ARG_ERROR6, arg);
+ SetAddModulesProp(*argv);
+ argv++; --argc;
+ } else if (JLI_StrCmp(arg, "-limitmods") == 0) {
+ ARG_CHECK (argc, ARG_ERROR6, arg);
+ SetLimitModulesProp(*argv);
+ argv++; --argc;
+ } else if (JLI_StrCmp(arg, "-listmods") == 0 ||
+ JLI_StrCCmp(arg, "-listmods:") == 0) {
+ listModules = arg;
+ return JNI_TRUE;
+ } else if (JLI_StrCCmp(arg, "-XaddReads:") == 0) {
+ static jint n;
+ char *value = arg + 11;
+ SetAddReadsProp(n++, value);
+ } else if (JLI_StrCCmp(arg, "-XaddExports:") == 0) {
+ static jint n;
+ char *value = arg + 13;
+ SetAddExportsProp(n++, value);
+ } else if (JLI_StrCCmp(arg, "-Xpatch:") == 0) {
+ static jint n;
+ char *value = arg + 8;
+ SetPatchProp(n++, value);
} else if (JLI_StrCmp(arg, "-help") == 0 ||
JLI_StrCmp(arg, "-h") == 0 ||
JLI_StrCmp(arg, "-?") == 0) {
@@ -1051,10 +1206,13 @@
* In the latter case, any SUBOPT value not recognized will default to "all"
*/
} else if (JLI_StrCmp(arg, "-XshowSettings") == 0 ||
- JLI_StrCCmp(arg, "-XshowSettings:") == 0) {
+ JLI_StrCCmp(arg, "-XshowSettings:") == 0) {
showSettings = arg;
} else if (JLI_StrCmp(arg, "-Xdiag") == 0) {
AddOption("-Dsun.java.launcher.diag=true", NULL);
+ AddOption("-Djdk.launcher.traceResolver=true", NULL);
+ } else if (JLI_StrCmp(arg, "-Xdiag:resolver") == 0) {
+ AddOption("-Djdk.launcher.traceResolver=true", NULL);
/*
* The following case provide backward compatibility with old-style
* command line options.
@@ -1099,6 +1257,10 @@
} else if (RemovableOption(arg)) {
; /* Do not pass option to vm. */
} else {
+ /* java.class.path set on the command line */
+ if (JLI_StrCCmp(arg, "-Djava.class.path=") == 0) {
+ _have_classpath = JNI_TRUE;
+ }
AddOption(arg, NULL);
}
}
@@ -1110,8 +1272,11 @@
if (*pwhat == NULL) {
*pret = 1;
} else if (mode == LM_UNKNOWN) {
- /* default to LM_CLASS if -jar and -cp option are
+ /* default to LM_CLASS if -m, -jar and -cp options are
* not specified */
+ if (!_have_classpath) {
+ SetClassPath(".");
+ }
mode = LM_CLASS;
}
@@ -1503,6 +1668,24 @@
ServerClassMachine());
}
+/**
+ * List modules supported by the runtime
+ */
+static void
+ListModules(JNIEnv *env, char *optString)
+{
+ jmethodID listModulesID;
+ jstring joptString;
+ jclass cls = GetLauncherHelperClass(env);
+ NULL_CHECK(cls);
+ NULL_CHECK(listModulesID = (*env)->GetStaticMethodID(env, cls,
+ "listModules", "(ZLjava/lang/String;)V"));
+ NULL_CHECK(joptString = (*env)->NewStringUTF(env, optString));
+ (*env)->CallStaticVoidMethod(env, cls, listModulesID,
+ USE_STDERR,
+ joptString);
+}
+
/*
* Prints default usage or the Xusage message, see sun.launcher.LauncherHelper.java
*/