Mercurial > hg > truffle
comparison src/share/vm/runtime/arguments.cpp @ 20654:fa6adc194d48
8064667: Add -XX:+CheckEndorsedAndExtDirs flag to JDK 8
Reviewed-by: coleenp, ccheung
author | mchung |
---|---|
date | Wed, 19 Nov 2014 14:21:09 -0800 |
parents | 86307d477907 |
children | b840813adfcc |
comparison
equal
deleted
inserted
replaced
20653:82d3e7b5277a | 20654:fa6adc194d48 |
---|---|
2960 CommandLineFlags::printFlags(tty, false); | 2960 CommandLineFlags::printFlags(tty, false); |
2961 vm_exit(0); | 2961 vm_exit(0); |
2962 #endif | 2962 #endif |
2963 // -D | 2963 // -D |
2964 } else if (match_option(option, "-D", &tail)) { | 2964 } else if (match_option(option, "-D", &tail)) { |
2965 if (CheckEndorsedAndExtDirs) { | |
2966 if (match_option(option, "-Djava.endorsed.dirs=", &tail)) { | |
2967 // abort if -Djava.endorsed.dirs is set | |
2968 jio_fprintf(defaultStream::output_stream(), | |
2969 "-Djava.endorsed.dirs will not be supported in a future release.\n" | |
2970 "Refer to JEP 220 for details (http://openjdk.java.net/jeps/220).\n"); | |
2971 return JNI_EINVAL; | |
2972 } | |
2973 if (match_option(option, "-Djava.ext.dirs=", &tail)) { | |
2974 // abort if -Djava.ext.dirs is set | |
2975 jio_fprintf(defaultStream::output_stream(), | |
2976 "-Djava.ext.dirs will not be supported in a future release.\n" | |
2977 "Refer to JEP 220 for details (http://openjdk.java.net/jeps/220).\n"); | |
2978 return JNI_EINVAL; | |
2979 } | |
2980 } | |
2981 | |
2965 if (!add_property(tail)) { | 2982 if (!add_property(tail)) { |
2966 return JNI_ENOMEM; | 2983 return JNI_ENOMEM; |
2967 } | 2984 } |
2968 // Out of the box management support | 2985 // Out of the box management support |
2969 if (match_option(option, "-Dcom.sun.management", &tail)) { | 2986 if (match_option(option, "-Dcom.sun.management", &tail)) { |
3393 if (!PrintSharedArchiveAndExit) { | 3410 if (!PrintSharedArchiveAndExit) { |
3394 ClassLoader::trace_class_path("[classpath: ", _java_class_path->value()); | 3411 ClassLoader::trace_class_path("[classpath: ", _java_class_path->value()); |
3395 } | 3412 } |
3396 } | 3413 } |
3397 | 3414 |
3415 static bool has_jar_files(const char* directory) { | |
3416 DIR* dir = os::opendir(directory); | |
3417 if (dir == NULL) return false; | |
3418 | |
3419 struct dirent *entry; | |
3420 char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory), mtInternal); | |
3421 bool hasJarFile = false; | |
3422 while (!hasJarFile && (entry = os::readdir(dir, (dirent *) dbuf)) != NULL) { | |
3423 const char* name = entry->d_name; | |
3424 const char* ext = name + strlen(name) - 4; | |
3425 hasJarFile = ext > name && (os::file_name_strcmp(ext, ".jar") == 0); | |
3426 } | |
3427 FREE_C_HEAP_ARRAY(char, dbuf, mtInternal); | |
3428 os::closedir(dir); | |
3429 return hasJarFile ; | |
3430 } | |
3431 | |
3432 // returns the number of directories in the given path containing JAR files | |
3433 // If the skip argument is not NULL, it will skip that directory | |
3434 static int check_non_empty_dirs(const char* path, const char* type, const char* skip) { | |
3435 const char separator = *os::path_separator(); | |
3436 const char* const end = path + strlen(path); | |
3437 int nonEmptyDirs = 0; | |
3438 while (path < end) { | |
3439 const char* tmp_end = strchr(path, separator); | |
3440 if (tmp_end == NULL) { | |
3441 if ((skip == NULL || strcmp(path, skip) != 0) && has_jar_files(path)) { | |
3442 nonEmptyDirs++; | |
3443 jio_fprintf(defaultStream::output_stream(), | |
3444 "Non-empty %s directory: %s\n", type, path); | |
3445 } | |
3446 path = end; | |
3447 } else { | |
3448 char* dirpath = NEW_C_HEAP_ARRAY(char, tmp_end - path + 1, mtInternal); | |
3449 memcpy(dirpath, path, tmp_end - path); | |
3450 dirpath[tmp_end - path] = '\0'; | |
3451 if ((skip == NULL || strcmp(dirpath, skip) != 0) && has_jar_files(dirpath)) { | |
3452 nonEmptyDirs++; | |
3453 jio_fprintf(defaultStream::output_stream(), | |
3454 "Non-empty %s directory: %s\n", type, dirpath); | |
3455 } | |
3456 FREE_C_HEAP_ARRAY(char, dirpath, mtInternal); | |
3457 path = tmp_end + 1; | |
3458 } | |
3459 } | |
3460 return nonEmptyDirs; | |
3461 } | |
3462 | |
3463 // Returns true if endorsed standards override mechanism and extension mechanism | |
3464 // are not used. | |
3465 static bool check_endorsed_and_ext_dirs() { | |
3466 if (!CheckEndorsedAndExtDirs) | |
3467 return true; | |
3468 | |
3469 char endorsedDir[JVM_MAXPATHLEN]; | |
3470 char extDir[JVM_MAXPATHLEN]; | |
3471 const char* fileSep = os::file_separator(); | |
3472 jio_snprintf(endorsedDir, sizeof(endorsedDir), "%s%slib%sendorsed", | |
3473 Arguments::get_java_home(), fileSep, fileSep); | |
3474 jio_snprintf(extDir, sizeof(extDir), "%s%slib%sext", | |
3475 Arguments::get_java_home(), fileSep, fileSep); | |
3476 | |
3477 // check endorsed directory | |
3478 int nonEmptyDirs = check_non_empty_dirs(Arguments::get_endorsed_dir(), "endorsed", NULL); | |
3479 | |
3480 // check the extension directories but skip the default lib/ext directory | |
3481 nonEmptyDirs += check_non_empty_dirs(Arguments::get_ext_dirs(), "extension", extDir); | |
3482 | |
3483 // List of JAR files installed in the default lib/ext directory. | |
3484 // -XX:+CheckEndorsedAndExtDirs checks if any non-JDK file installed | |
3485 static const char* jdk_ext_jars[] = { | |
3486 "access-bridge-32.jar", | |
3487 "access-bridge-64.jar", | |
3488 "access-bridge.jar", | |
3489 "cldrdata.jar", | |
3490 "dnsns.jar", | |
3491 "jaccess.jar", | |
3492 "jfxrt.jar", | |
3493 "localedata.jar", | |
3494 "nashorn.jar", | |
3495 "sunec.jar", | |
3496 "sunjce_provider.jar", | |
3497 "sunmscapi.jar", | |
3498 "sunpkcs11.jar", | |
3499 "ucrypto.jar", | |
3500 "zipfs.jar", | |
3501 NULL | |
3502 }; | |
3503 | |
3504 // check if the default lib/ext directory has any non-JDK jar files; if so, error | |
3505 DIR* dir = os::opendir(extDir); | |
3506 if (dir != NULL) { | |
3507 int num_ext_jars = 0; | |
3508 struct dirent *entry; | |
3509 char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(extDir), mtInternal); | |
3510 while ((entry = os::readdir(dir, (dirent *) dbuf)) != NULL) { | |
3511 const char* name = entry->d_name; | |
3512 const char* ext = name + strlen(name) - 4; | |
3513 if (ext > name && (os::file_name_strcmp(ext, ".jar") == 0)) { | |
3514 bool is_jdk_jar = false; | |
3515 const char* jarfile = NULL; | |
3516 for (int i=0; (jarfile = jdk_ext_jars[i]) != NULL; i++) { | |
3517 if (os::file_name_strcmp(name, jarfile) == 0) { | |
3518 is_jdk_jar = true; | |
3519 break; | |
3520 } | |
3521 } | |
3522 if (!is_jdk_jar) { | |
3523 jio_fprintf(defaultStream::output_stream(), | |
3524 "%s installed in <JAVA_HOME>/lib/ext\n", name); | |
3525 num_ext_jars++; | |
3526 } | |
3527 } | |
3528 } | |
3529 FREE_C_HEAP_ARRAY(char, dbuf, mtInternal); | |
3530 os::closedir(dir); | |
3531 if (num_ext_jars > 0) { | |
3532 nonEmptyDirs += 1; | |
3533 } | |
3534 } | |
3535 | |
3536 // check if the default lib/endorsed directory exists; if so, error | |
3537 dir = os::opendir(endorsedDir); | |
3538 if (dir != NULL) { | |
3539 jio_fprintf(defaultStream::output_stream(), "<JAVA_HOME>/lib/endorsed exists\n"); | |
3540 os::closedir(dir); | |
3541 nonEmptyDirs += 1; | |
3542 } | |
3543 | |
3544 if (nonEmptyDirs > 0) { | |
3545 jio_fprintf(defaultStream::output_stream(), | |
3546 "Endorsed standards override mechanism and extension mechanism" | |
3547 "will not be supported in a future release.\n" | |
3548 "Refer to JEP 220 for details (http://openjdk.java.net/jeps/220).\n"); | |
3549 return false; | |
3550 } | |
3551 | |
3552 return true; | |
3553 } | |
3554 | |
3398 jint Arguments::finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_required) { | 3555 jint Arguments::finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_required) { |
3399 // This must be done after all -D arguments have been processed. | 3556 // This must be done after all -D arguments have been processed. |
3400 scp_p->expand_endorsed(); | 3557 scp_p->expand_endorsed(); |
3401 | 3558 |
3402 if (scp_assembly_required || scp_p->get_endorsed() != NULL) { | 3559 if (scp_assembly_required || scp_p->get_endorsed() != NULL) { |
3403 // Assemble the bootclasspath elements into the final path. | 3560 // Assemble the bootclasspath elements into the final path. |
3404 Arguments::set_sysclasspath(scp_p->combined_path()); | 3561 Arguments::set_sysclasspath(scp_p->combined_path()); |
3562 } | |
3563 | |
3564 if (!check_endorsed_and_ext_dirs()) { | |
3565 return JNI_ERR; | |
3405 } | 3566 } |
3406 | 3567 |
3407 // This must be done after all arguments have been processed. | 3568 // This must be done after all arguments have been processed. |
3408 // java_compiler() true means set to "NONE" or empty. | 3569 // java_compiler() true means set to "NONE" or empty. |
3409 if (java_compiler() && !xdebug_mode()) { | 3570 if (java_compiler() && !xdebug_mode()) { |