< prev index next >

src/java.base/share/native/libjli/java.c

Print this page




 155     VM_ERROR,
 156     VM_IF_SERVER_CLASS,
 157     VM_IGNORE
 158 };
 159 
 160 struct vmdesc {
 161     char *name;
 162     int flag;
 163     char *alias;
 164     char *server_class;
 165 };
 166 static struct vmdesc *knownVMs = NULL;
 167 static int knownVMsCount = 0;
 168 static int knownVMsLimit = 0;
 169 
 170 static void GrowKnownVMs(int minimum);
 171 static int  KnownVMIndex(const char* name);
 172 static void FreeKnownVMs();
 173 static jboolean IsWildCardEnabled();
 174 



 175 /*
 176  * This reports error.  VM will not be created and no usage is printed.
 177  */
 178 #define REPORT_ERROR(AC_ok, AC_failure_message, AC_questionable_arg) \
 179     do { \
 180         if (!AC_ok) { \
 181             JLI_ReportErrorMessage(AC_failure_message, AC_questionable_arg); \
 182             printUsage = JNI_FALSE; \
 183             *pret = 1; \
 184             return JNI_FALSE; \
 185         } \
 186     } while (JNI_FALSE)
 187 
 188 #define ARG_CHECK(AC_arg_count, AC_failure_message, AC_questionable_arg) \
 189     do { \
 190         if (AC_arg_count < 1) { \
 191             JLI_ReportErrorMessage(AC_failure_message, AC_questionable_arg); \
 192             printUsage = JNI_TRUE; \
 193             *pret = 1; \
 194             return JNI_TRUE; \


 197 
 198 /*
 199  * Running Java code in primordial thread caused many problems. We will
 200  * create a new thread to invoke JVM. See 6316197 for more information.
 201  */
 202 static jlong threadStackSize    = 0;  /* stack size of the new thread */
 203 static jlong maxHeapSize        = 0;  /* max heap size */
 204 static jlong initialHeapSize    = 0;  /* inital heap size */
 205 
 206 /*
 207  * A minimum -Xss stack size suitable for all platforms.
 208  */
 209 #ifndef STACK_SIZE_MINIMUM
 210 #define STACK_SIZE_MINIMUM (64 * KB)
 211 #endif
 212 
 213 /*
 214  * Entry point.
 215  */
 216 JNIEXPORT int JNICALL
 217 JLI_Launch(int argc, char ** argv,              /* main argc, argc */
 218         int jargc, const char** jargv,          /* java args */
 219         int appclassc, const char** appclassv,  /* app classpath */
 220         const char* fullversion,                /* full version defined */
 221         const char* dotversion,                 /* UNUSED dot version defined */
 222         const char* pname,                      /* program name */
 223         const char* lname,                      /* launcher name */
 224         jboolean javaargs,                      /* JAVA_ARGS */
 225         jboolean cpwildcard,                    /* classpath wildcard*/
 226         jboolean javaw,                         /* windows-only javaw */
 227         jint ergo                               /* unused */
 228 )
 229 {
 230     int mode = LM_UNKNOWN;
 231     char *what = NULL;
 232     char *main_class = NULL;
 233     int ret;
 234     InvocationFunctions ifn;
 235     jlong start, end;
 236     char jvmpath[MAXPATHLEN];
 237     char jrepath[MAXPATHLEN];


 300     ++argv;
 301     --argc;
 302 
 303     if (IsJavaArgs()) {
 304         /* Preprocess wrapper arguments */
 305         TranslateApplicationArgs(jargc, jargv, &argc, &argv);
 306         if (!AddApplicationOptions(appclassc, appclassv)) {
 307             return(1);
 308         }
 309     } else {
 310         /* Set default CLASSPATH */
 311         char* cpath = getenv("CLASSPATH");
 312         if (cpath != NULL) {
 313             SetClassPath(cpath);
 314         }
 315     }
 316 
 317     /* Parse command line options; if the return value of
 318      * ParseArguments is false, the program should exit.
 319      */
 320     if (!ParseArguments(&argc, &argv, &mode, &what, &ret, jrepath))
 321     {
 322         return(ret);
 323     }
 324 
 325     /* Override class path if -jar flag was specified */
 326     if (mode == LM_JAR) {
 327         SetClassPath(what);     /* Override class path */
 328     }
 329 
 330     /* set the -Dsun.java.command pseudo property */
 331     SetJavaCommandLineProp(what, argc, argv);
 332 
 333     /* Set the -Dsun.java.launcher pseudo property */
 334     SetJavaLauncherProp();
 335 
 336     /* set the -Dsun.java.launcher.* platform properties */
 337     SetJavaLauncherPlatformProps();
 338 
 339     return JVMInit(&ifn, threadStackSize, argc, argv, mode, what, ret);
 340 }
 341 /*


 568            JLI_StrCmp(name, "--class-path") == 0;
 569 }
 570 
 571 /*
 572  * Test if the given name is a launcher option taking the main entry point.
 573  */
 574 static jboolean
 575 IsLauncherMainOption(const char* name) {
 576     return JLI_StrCmp(name, "--module") == 0 ||
 577            JLI_StrCmp(name, "-m") == 0;
 578 }
 579 
 580 /*
 581  * Test if the given name is a white-space launcher option.
 582  */
 583 static jboolean
 584 IsLauncherOption(const char* name) {
 585     return IsClassPathOption(name) ||
 586            IsLauncherMainOption(name) ||
 587            JLI_StrCmp(name, "--describe-module") == 0 ||
 588            JLI_StrCmp(name, "-d") == 0;

 589 }
 590 
 591 /*
 592  * Test if the given name is a module-system white-space option that
 593  * will be passed to the VM with its corresponding long-form option
 594  * name and "=" delimiter.
 595  */
 596 static jboolean
 597 IsModuleOption(const char* name) {
 598     return JLI_StrCmp(name, "--module-path") == 0 ||
 599            JLI_StrCmp(name, "-p") == 0 ||
 600            JLI_StrCmp(name, "--upgrade-module-path") == 0 ||
 601            JLI_StrCmp(name, "--add-modules") == 0 ||
 602            JLI_StrCmp(name, "--limit-modules") == 0 ||
 603            JLI_StrCmp(name, "--add-exports") == 0 ||
 604            JLI_StrCmp(name, "--add-opens") == 0 ||
 605            JLI_StrCmp(name, "--add-reads") == 0 ||
 606            JLI_StrCmp(name, "--patch-module") == 0;
 607 }
 608 


 610 IsLongFormModuleOption(const char* name) {
 611     return JLI_StrCCmp(name, "--module-path=") == 0 ||
 612            JLI_StrCCmp(name, "--upgrade-module-path=") == 0 ||
 613            JLI_StrCCmp(name, "--add-modules=") == 0 ||
 614            JLI_StrCCmp(name, "--limit-modules=") == 0 ||
 615            JLI_StrCCmp(name, "--add-exports=") == 0 ||
 616            JLI_StrCCmp(name, "--add-reads=") == 0 ||
 617            JLI_StrCCmp(name, "--patch-module=") == 0;
 618 }
 619 
 620 /*
 621  * Test if the given name has a white space option.
 622  */
 623 jboolean
 624 IsWhiteSpaceOption(const char* name) {
 625     return IsModuleOption(name) ||
 626            IsLauncherOption(name);
 627 }
 628 
 629 /*























 630  * Checks the command line options to find which JVM type was
 631  * specified.  If no command line option was given for the JVM type,
 632  * the default type is used.  The environment variable
 633  * JDK_ALTERNATE_VM and the command line option -XXaltjvm= are also
 634  * checked as ways of specifying which JVM type to invoke.
 635  */
 636 char *
 637 CheckJvmType(int *pargc, char ***argv, jboolean speculative) {
 638     int i, argi;
 639     int argc;
 640     char **newArgv;
 641     int newArgvIdx = 0;
 642     int isVMType;
 643     int jvmidx = -1;
 644     char *jvmtype = getenv("JDK_ALTERNATE_VM");
 645 
 646     argc = *pargc;
 647 
 648     /* To make things simpler we always copy the argv array */
 649     newArgv = JLI_MemAlloc((argc + 1) * sizeof(char *));


1213         kind = IsLauncherMainOption(arg) ? LAUNCHER_MAIN_OPTION
1214                                          : LAUNCHER_OPTION_WITH_ARGUMENT;
1215     } else if (IsModuleOption(arg)) {
1216         kind = VM_LONG_OPTION_WITH_ARGUMENT;
1217         if (has_arg) {
1218             value = *argv;
1219             argv++; --argc;
1220         }
1221 
1222         /*
1223          * Support short form alias
1224          */
1225         if (JLI_StrCmp(arg, "-p") == 0) {
1226             option = "--module-path";
1227         }
1228 
1229     } else if (JLI_StrCCmp(arg, "--") == 0 && (equals = JLI_StrChr(arg, '=')) != NULL) {
1230         value = equals+1;
1231         if (JLI_StrCCmp(arg, "--describe-module=") == 0 ||
1232             JLI_StrCCmp(arg, "--module=") == 0 ||
1233             JLI_StrCCmp(arg, "--class-path=") == 0) {

1234             kind = LAUNCHER_OPTION_WITH_ARGUMENT;
1235         } else {
1236             kind = VM_LONG_OPTION;
1237         }
1238     }
1239 
1240     *pargc = argc;
1241     *pargv = argv;
1242     *poption = option;
1243     *pvalue = value;
1244     return kind;
1245 }
1246 
1247 /*
1248  * Parses command line arguments.  Returns JNI_FALSE if launcher
1249  * should exit without starting vm, returns JNI_TRUE if vm needs
1250  * to be started to process given options.  *pret (the launcher
1251  * process return value) is set to 0 for a normal exit.
1252  */
1253 static jboolean


1257 {
1258     int argc = *pargc;
1259     char **argv = *pargv;
1260     int mode = LM_UNKNOWN;
1261     char *arg;
1262 
1263     *pret = 0;
1264 
1265     while ((arg = *argv) != 0 && *arg == '-') {
1266         char *option = NULL;
1267         char *value = NULL;
1268         int kind = GetOpt(&argc, &argv, &option, &value);
1269         jboolean has_arg = value != NULL && JLI_StrLen(value) > 0;
1270         jboolean has_arg_any_len = value != NULL;
1271 
1272 /*
1273  * Option to set main entry point
1274  */
1275         if (JLI_StrCmp(arg, "-jar") == 0) {
1276             ARG_CHECK(argc, ARG_ERROR2, arg);
1277             mode = LM_JAR;
1278         } else if (JLI_StrCmp(arg, "--module") == 0 ||
1279                    JLI_StrCCmp(arg, "--module=") == 0 ||
1280                    JLI_StrCmp(arg, "-m") == 0) {
1281             REPORT_ERROR (has_arg, ARG_ERROR5, arg);
1282             SetMainModule(value);
1283             mode = LM_MODULE;
1284             if (has_arg) {
1285                *pwhat = value;
1286                 break;
1287             }












1288         } else if (JLI_StrCmp(arg, "--class-path") == 0 ||
1289                    JLI_StrCCmp(arg, "--class-path=") == 0 ||
1290                    JLI_StrCmp(arg, "-classpath") == 0 ||
1291                    JLI_StrCmp(arg, "-cp") == 0) {
1292             REPORT_ERROR (has_arg_any_len, ARG_ERROR1, arg);
1293             SetClassPath(value);
1294             mode = LM_CLASS;
1295         } else if (JLI_StrCmp(arg, "--list-modules") == 0) {
1296             listModules = JNI_TRUE;
1297         } else if (JLI_StrCmp(arg, "--show-resolved-modules") == 0) {
1298             showResolvedModules = JNI_TRUE;
1299         } else if (JLI_StrCmp(arg, "--validate-modules") == 0) {
1300             AddOption("-Djdk.module.validation=true", NULL);
1301             validateModules = JNI_TRUE;
1302         } else if (JLI_StrCmp(arg, "--describe-module") == 0 ||
1303                    JLI_StrCCmp(arg, "--describe-module=") == 0 ||
1304                    JLI_StrCmp(arg, "-d") == 0) {
1305             REPORT_ERROR (has_arg_any_len, ARG_ERROR12, arg);
1306             describeModule = value;
1307 /*


1418             }
1419             AddOption(arg, NULL);
1420         }
1421     }
1422 
1423     if (*pwhat == NULL && --argc >= 0) {
1424         *pwhat = *argv++;
1425     }
1426 
1427     if (*pwhat == NULL) {
1428         /* LM_UNKNOWN okay for options that exit */
1429         if (!listModules && !describeModule && !validateModules) {
1430             *pret = 1;
1431         }
1432     } else if (mode == LM_UNKNOWN) {
1433         /* default to LM_CLASS if -m, -jar and -cp options are
1434          * not specified */
1435         if (!_have_classpath) {
1436             SetClassPath(".");
1437         }
1438         mode = LM_CLASS;



1439     }
1440 






1441     if (argc >= 0) {
1442         *pargc = argc;
1443         *pargv = argv;

1444     }
1445 
1446     *pmode = mode;
1447 
1448     return JNI_TRUE;
1449 }
1450 
1451 /*
1452  * Initializes the Java Virtual Machine. Also frees options array when
1453  * finished.
1454  */
1455 static jboolean
1456 InitializeJVM(JavaVM **pvm, JNIEnv **penv, InvocationFunctions *ifn)
1457 {
1458     JavaVMInitArgs args;
1459     jint r;
1460 
1461     memset(&args, 0, sizeof(args));
1462     args.version  = JNI_VERSION_1_2;
1463     args.nOptions = numOptions;




 155     VM_ERROR,
 156     VM_IF_SERVER_CLASS,
 157     VM_IGNORE
 158 };
 159 
 160 struct vmdesc {
 161     char *name;
 162     int flag;
 163     char *alias;
 164     char *server_class;
 165 };
 166 static struct vmdesc *knownVMs = NULL;
 167 static int knownVMsCount = 0;
 168 static int knownVMsLimit = 0;
 169 
 170 static void GrowKnownVMs(int minimum);
 171 static int  KnownVMIndex(const char* name);
 172 static void FreeKnownVMs();
 173 static jboolean IsWildCardEnabled();
 174 
 175 
 176 #define SOURCE_LAUNCHER_MAIN_ENTRY "jdk.compiler/com.sun.tools.javac.launcher.Main"
 177 
 178 /*
 179  * This reports error.  VM will not be created and no usage is printed.
 180  */
 181 #define REPORT_ERROR(AC_ok, AC_failure_message, AC_questionable_arg) \
 182     do { \
 183         if (!AC_ok) { \
 184             JLI_ReportErrorMessage(AC_failure_message, AC_questionable_arg); \
 185             printUsage = JNI_FALSE; \
 186             *pret = 1; \
 187             return JNI_FALSE; \
 188         } \
 189     } while (JNI_FALSE)
 190 
 191 #define ARG_CHECK(AC_arg_count, AC_failure_message, AC_questionable_arg) \
 192     do { \
 193         if (AC_arg_count < 1) { \
 194             JLI_ReportErrorMessage(AC_failure_message, AC_questionable_arg); \
 195             printUsage = JNI_TRUE; \
 196             *pret = 1; \
 197             return JNI_TRUE; \


 200 
 201 /*
 202  * Running Java code in primordial thread caused many problems. We will
 203  * create a new thread to invoke JVM. See 6316197 for more information.
 204  */
 205 static jlong threadStackSize    = 0;  /* stack size of the new thread */
 206 static jlong maxHeapSize        = 0;  /* max heap size */
 207 static jlong initialHeapSize    = 0;  /* inital heap size */
 208 
 209 /*
 210  * A minimum -Xss stack size suitable for all platforms.
 211  */
 212 #ifndef STACK_SIZE_MINIMUM
 213 #define STACK_SIZE_MINIMUM (64 * KB)
 214 #endif
 215 
 216 /*
 217  * Entry point.
 218  */
 219 JNIEXPORT int JNICALL
 220 JLI_Launch(int argc, char ** argv,              /* main argc, argv */
 221         int jargc, const char** jargv,          /* java args */
 222         int appclassc, const char** appclassv,  /* app classpath */
 223         const char* fullversion,                /* full version defined */
 224         const char* dotversion,                 /* UNUSED dot version defined */
 225         const char* pname,                      /* program name */
 226         const char* lname,                      /* launcher name */
 227         jboolean javaargs,                      /* JAVA_ARGS */
 228         jboolean cpwildcard,                    /* classpath wildcard*/
 229         jboolean javaw,                         /* windows-only javaw */
 230         jint ergo                               /* unused */
 231 )
 232 {
 233     int mode = LM_UNKNOWN;
 234     char *what = NULL;
 235     char *main_class = NULL;
 236     int ret;
 237     InvocationFunctions ifn;
 238     jlong start, end;
 239     char jvmpath[MAXPATHLEN];
 240     char jrepath[MAXPATHLEN];


 303     ++argv;
 304     --argc;
 305 
 306     if (IsJavaArgs()) {
 307         /* Preprocess wrapper arguments */
 308         TranslateApplicationArgs(jargc, jargv, &argc, &argv);
 309         if (!AddApplicationOptions(appclassc, appclassv)) {
 310             return(1);
 311         }
 312     } else {
 313         /* Set default CLASSPATH */
 314         char* cpath = getenv("CLASSPATH");
 315         if (cpath != NULL) {
 316             SetClassPath(cpath);
 317         }
 318     }
 319 
 320     /* Parse command line options; if the return value of
 321      * ParseArguments is false, the program should exit.
 322      */
 323     if (!ParseArguments(&argc, &argv, &mode, &what, &ret, jrepath)) {

 324         return(ret);
 325     }
 326 
 327     /* Override class path if -jar flag was specified */
 328     if (mode == LM_JAR) {
 329         SetClassPath(what);     /* Override class path */
 330     }
 331 
 332     /* set the -Dsun.java.command pseudo property */
 333     SetJavaCommandLineProp(what, argc, argv);
 334 
 335     /* Set the -Dsun.java.launcher pseudo property */
 336     SetJavaLauncherProp();
 337 
 338     /* set the -Dsun.java.launcher.* platform properties */
 339     SetJavaLauncherPlatformProps();
 340 
 341     return JVMInit(&ifn, threadStackSize, argc, argv, mode, what, ret);
 342 }
 343 /*


 570            JLI_StrCmp(name, "--class-path") == 0;
 571 }
 572 
 573 /*
 574  * Test if the given name is a launcher option taking the main entry point.
 575  */
 576 static jboolean
 577 IsLauncherMainOption(const char* name) {
 578     return JLI_StrCmp(name, "--module") == 0 ||
 579            JLI_StrCmp(name, "-m") == 0;
 580 }
 581 
 582 /*
 583  * Test if the given name is a white-space launcher option.
 584  */
 585 static jboolean
 586 IsLauncherOption(const char* name) {
 587     return IsClassPathOption(name) ||
 588            IsLauncherMainOption(name) ||
 589            JLI_StrCmp(name, "--describe-module") == 0 ||
 590            JLI_StrCmp(name, "-d") == 0 ||
 591            JLI_StrCmp(name, "--source") == 0;
 592 }
 593 
 594 /*
 595  * Test if the given name is a module-system white-space option that
 596  * will be passed to the VM with its corresponding long-form option
 597  * name and "=" delimiter.
 598  */
 599 static jboolean
 600 IsModuleOption(const char* name) {
 601     return JLI_StrCmp(name, "--module-path") == 0 ||
 602            JLI_StrCmp(name, "-p") == 0 ||
 603            JLI_StrCmp(name, "--upgrade-module-path") == 0 ||
 604            JLI_StrCmp(name, "--add-modules") == 0 ||
 605            JLI_StrCmp(name, "--limit-modules") == 0 ||
 606            JLI_StrCmp(name, "--add-exports") == 0 ||
 607            JLI_StrCmp(name, "--add-opens") == 0 ||
 608            JLI_StrCmp(name, "--add-reads") == 0 ||
 609            JLI_StrCmp(name, "--patch-module") == 0;
 610 }
 611 


 613 IsLongFormModuleOption(const char* name) {
 614     return JLI_StrCCmp(name, "--module-path=") == 0 ||
 615            JLI_StrCCmp(name, "--upgrade-module-path=") == 0 ||
 616            JLI_StrCCmp(name, "--add-modules=") == 0 ||
 617            JLI_StrCCmp(name, "--limit-modules=") == 0 ||
 618            JLI_StrCCmp(name, "--add-exports=") == 0 ||
 619            JLI_StrCCmp(name, "--add-reads=") == 0 ||
 620            JLI_StrCCmp(name, "--patch-module=") == 0;
 621 }
 622 
 623 /*
 624  * Test if the given name has a white space option.
 625  */
 626 jboolean
 627 IsWhiteSpaceOption(const char* name) {
 628     return IsModuleOption(name) ||
 629            IsLauncherOption(name);
 630 }
 631 
 632 /*
 633  * Check if it is OK to set the mode. 
 634  * If the mode was previously set, and should not be changed,
 635  * a fatal error is reported.
 636  */
 637 static int
 638 checkMode(int mode, int newMode, const char *arg) {
 639     if (mode == LM_SOURCE) {
 640         JLI_ReportErrorMessage(ARG_ERROR14, arg);
 641         exit(1);
 642     }
 643     return newMode;
 644 }
 645 
 646 /*
 647  * Test if an arg identifies a source file.
 648  */
 649 jboolean
 650 IsSourceFile(const char *arg) {
 651     struct stat st;
 652     return (JLI_HasSuffix(arg, ".java") && stat(arg, &st) == 0);
 653 }
 654 
 655 /*
 656  * Checks the command line options to find which JVM type was
 657  * specified.  If no command line option was given for the JVM type,
 658  * the default type is used.  The environment variable
 659  * JDK_ALTERNATE_VM and the command line option -XXaltjvm= are also
 660  * checked as ways of specifying which JVM type to invoke.
 661  */
 662 char *
 663 CheckJvmType(int *pargc, char ***argv, jboolean speculative) {
 664     int i, argi;
 665     int argc;
 666     char **newArgv;
 667     int newArgvIdx = 0;
 668     int isVMType;
 669     int jvmidx = -1;
 670     char *jvmtype = getenv("JDK_ALTERNATE_VM");
 671 
 672     argc = *pargc;
 673 
 674     /* To make things simpler we always copy the argv array */
 675     newArgv = JLI_MemAlloc((argc + 1) * sizeof(char *));


1239         kind = IsLauncherMainOption(arg) ? LAUNCHER_MAIN_OPTION
1240                                          : LAUNCHER_OPTION_WITH_ARGUMENT;
1241     } else if (IsModuleOption(arg)) {
1242         kind = VM_LONG_OPTION_WITH_ARGUMENT;
1243         if (has_arg) {
1244             value = *argv;
1245             argv++; --argc;
1246         }
1247 
1248         /*
1249          * Support short form alias
1250          */
1251         if (JLI_StrCmp(arg, "-p") == 0) {
1252             option = "--module-path";
1253         }
1254 
1255     } else if (JLI_StrCCmp(arg, "--") == 0 && (equals = JLI_StrChr(arg, '=')) != NULL) {
1256         value = equals+1;
1257         if (JLI_StrCCmp(arg, "--describe-module=") == 0 ||
1258             JLI_StrCCmp(arg, "--module=") == 0 ||
1259             JLI_StrCCmp(arg, "--class-path=") == 0||
1260             JLI_StrCCmp(arg, "--source=") == 0) {
1261             kind = LAUNCHER_OPTION_WITH_ARGUMENT;
1262         } else {
1263             kind = VM_LONG_OPTION;
1264         }
1265     }
1266 
1267     *pargc = argc;
1268     *pargv = argv;
1269     *poption = option;
1270     *pvalue = value;
1271     return kind;
1272 }
1273 
1274 /*
1275  * Parses command line arguments.  Returns JNI_FALSE if launcher
1276  * should exit without starting vm, returns JNI_TRUE if vm needs
1277  * to be started to process given options.  *pret (the launcher
1278  * process return value) is set to 0 for a normal exit.
1279  */
1280 static jboolean


1284 {
1285     int argc = *pargc;
1286     char **argv = *pargv;
1287     int mode = LM_UNKNOWN;
1288     char *arg;
1289 
1290     *pret = 0;
1291 
1292     while ((arg = *argv) != 0 && *arg == '-') {
1293         char *option = NULL;
1294         char *value = NULL;
1295         int kind = GetOpt(&argc, &argv, &option, &value);
1296         jboolean has_arg = value != NULL && JLI_StrLen(value) > 0;
1297         jboolean has_arg_any_len = value != NULL;
1298 
1299 /*
1300  * Option to set main entry point
1301  */
1302         if (JLI_StrCmp(arg, "-jar") == 0) {
1303             ARG_CHECK(argc, ARG_ERROR2, arg);
1304             mode = checkMode(mode, LM_JAR, arg);
1305         } else if (JLI_StrCmp(arg, "--module") == 0 ||
1306                    JLI_StrCCmp(arg, "--module=") == 0 ||
1307                    JLI_StrCmp(arg, "-m") == 0) {
1308             REPORT_ERROR (has_arg, ARG_ERROR5, arg);
1309             SetMainModule(value);
1310             mode = checkMode(mode, LM_MODULE, arg);
1311             if (has_arg) {
1312                *pwhat = value;
1313                 break;
1314             }
1315         } else if (JLI_StrCmp(arg, "--source") == 0 ||
1316                    JLI_StrCCmp(arg, "--source=") == 0) {
1317             REPORT_ERROR (has_arg, ARG_ERROR13, arg);
1318             mode = LM_SOURCE;
1319             if (has_arg) {
1320                 const char *prop = "-Djdk.internal.javac.source=";
1321                 size_t size = JLI_StrLen(prop) + JLI_StrLen(value) + 1;
1322                 char *propValue = (char *)JLI_MemAlloc(size + 1);
1323                 JLI_StrCpy(propValue, prop);
1324                 JLI_StrCat(propValue, value);
1325                 AddOption(propValue, NULL);
1326             }
1327         } else if (JLI_StrCmp(arg, "--class-path") == 0 ||
1328                    JLI_StrCCmp(arg, "--class-path=") == 0 ||
1329                    JLI_StrCmp(arg, "-classpath") == 0 ||
1330                    JLI_StrCmp(arg, "-cp") == 0) {
1331             REPORT_ERROR (has_arg_any_len, ARG_ERROR1, arg);
1332             SetClassPath(value);
1333             mode = LM_CLASS;
1334         } else if (JLI_StrCmp(arg, "--list-modules") == 0) {
1335             listModules = JNI_TRUE;
1336         } else if (JLI_StrCmp(arg, "--show-resolved-modules") == 0) {
1337             showResolvedModules = JNI_TRUE;
1338         } else if (JLI_StrCmp(arg, "--validate-modules") == 0) {
1339             AddOption("-Djdk.module.validation=true", NULL);
1340             validateModules = JNI_TRUE;
1341         } else if (JLI_StrCmp(arg, "--describe-module") == 0 ||
1342                    JLI_StrCCmp(arg, "--describe-module=") == 0 ||
1343                    JLI_StrCmp(arg, "-d") == 0) {
1344             REPORT_ERROR (has_arg_any_len, ARG_ERROR12, arg);
1345             describeModule = value;
1346 /*


1457             }
1458             AddOption(arg, NULL);
1459         }
1460     }
1461 
1462     if (*pwhat == NULL && --argc >= 0) {
1463         *pwhat = *argv++;
1464     }
1465 
1466     if (*pwhat == NULL) {
1467         /* LM_UNKNOWN okay for options that exit */
1468         if (!listModules && !describeModule && !validateModules) {
1469             *pret = 1;
1470         }
1471     } else if (mode == LM_UNKNOWN) {
1472         /* default to LM_CLASS if -m, -jar and -cp options are
1473          * not specified */
1474         if (!_have_classpath) {
1475             SetClassPath(".");
1476         }
1477         mode = IsSourceFile(arg) ? LM_SOURCE : LM_CLASS;
1478     } else if (mode == LM_CLASS && IsSourceFile(arg)) {
1479         /* override LM_CLASS mode if given a source file */
1480         mode = LM_SOURCE;
1481     }
1482 
1483     if (mode == LM_SOURCE) {
1484         AddOption("--add-modules=ALL-DEFAULT", NULL);
1485         *pwhat = SOURCE_LAUNCHER_MAIN_ENTRY;
1486         *pargc = argc + 1;
1487         *pargv = argv - 1;
1488     } else {
1489         if (argc >= 0) {
1490             *pargc = argc;
1491             *pargv = argv;
1492         }
1493     }
1494 
1495     *pmode = mode;
1496 
1497     return JNI_TRUE;
1498 }
1499 
1500 /*
1501  * Initializes the Java Virtual Machine. Also frees options array when
1502  * finished.
1503  */
1504 static jboolean
1505 InitializeJVM(JavaVM **pvm, JNIEnv **penv, InvocationFunctions *ifn)
1506 {
1507     JavaVMInitArgs args;
1508     jint r;
1509 
1510     memset(&args, 0, sizeof(args));
1511     args.version  = JNI_VERSION_1_2;
1512     args.nOptions = numOptions;


< prev index next >