src/share/vm/runtime/arguments.cpp

Print this page
rev 6853 : 8046070: Class Data Sharing clean up and refactoring
Summary: Cleaned up CDS to be more configurable, maintainable and extensible
Reviewed-by: dholmes, coleenp, acorn, mchung

*** 21,30 **** --- 21,31 ---- * questions. * */ #include "precompiled.hpp" + #include "classfile/classLoader.hpp" #include "classfile/javaAssertions.hpp" #include "classfile/stringTable.hpp" #include "classfile/symbolTable.hpp" #include "compiler/compilerOracle.hpp" #include "memory/allocation.inline.hpp"
*** 41,50 **** --- 42,52 ---- #include "runtime/vm_version.hpp" #include "services/management.hpp" #include "services/memTracker.hpp" #include "utilities/defaultStream.hpp" #include "utilities/macros.hpp" + #include "utilities/stringUtils.hpp" #include "utilities/taskqueue.hpp" #if INCLUDE_ALL_GCS #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp" #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
*** 1113,1127 **** #if defined(COMPILER2) || defined(_LP64) || !INCLUDE_CDS // Conflict: required to use shared spaces (-Xshare:on), but // incompatible command line options were chosen. ! static void no_shared_spaces() { if (RequireSharedSpaces) { jio_fprintf(defaultStream::error_stream(), "Class data sharing is inconsistent with other specified options.\n"); ! vm_exit_during_initialization("Unable to use shared archive.", NULL); } else { FLAG_SET_DEFAULT(UseSharedSpaces, false); } } #endif --- 1115,1129 ---- #if defined(COMPILER2) || defined(_LP64) || !INCLUDE_CDS // Conflict: required to use shared spaces (-Xshare:on), but // incompatible command line options were chosen. ! static void no_shared_spaces(const char* message) { if (RequireSharedSpaces) { jio_fprintf(defaultStream::error_stream(), "Class data sharing is inconsistent with other specified options.\n"); ! vm_exit_during_initialization("Unable to use shared archive.", message); } else { FLAG_SET_DEFAULT(UseSharedSpaces, false); } } #endif
*** 1579,1589 **** // server performance. When -server is specified, keep the default off // unless it is asked for. Future work: either add bytecode rewriting // at link time, or rewrite bytecodes in non-shared methods. if (!DumpSharedSpaces && !RequireSharedSpaces && (FLAG_IS_DEFAULT(UseSharedSpaces) || !UseSharedSpaces)) { ! no_shared_spaces(); } #endif set_conservative_max_heap_alignment(); --- 1581,1591 ---- // server performance. When -server is specified, keep the default off // unless it is asked for. Future work: either add bytecode rewriting // at link time, or rewrite bytecodes in non-shared methods. if (!DumpSharedSpaces && !RequireSharedSpaces && (FLAG_IS_DEFAULT(UseSharedSpaces) || !UseSharedSpaces)) { ! no_shared_spaces("COMPILER2 default: -Xshare:auto | off, have to manually setup to on."); } #endif set_conservative_max_heap_alignment();
*** 3300,3320 **** --- 3302,3377 ---- } else if (is_bad_option(option, args->ignoreUnrecognized)) { return JNI_ERR; } } + // PrintSharedArchiveAndExit will turn on + // -Xshare:on + // -XX:+TraceClassPaths + if (PrintSharedArchiveAndExit) { + FLAG_SET_CMDLINE(bool, UseSharedSpaces, true); + FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true); + FLAG_SET_CMDLINE(bool, TraceClassPaths, true); + } + // Change the default value for flags which have different default values // when working with older JDKs. #ifdef LINUX if (JDK_Version::current().compare_major(6) <= 0 && FLAG_IS_DEFAULT(UseLinuxPosixThreadCPUClocks)) { FLAG_SET_DEFAULT(UseLinuxPosixThreadCPUClocks, false); } #endif // LINUX + fix_appclasspath(); return JNI_OK; } + // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled) + // + // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar + // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar". + // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty + // path is treated as the current directory. + // + // This causes problems with CDS, which requires that all directories specified in the classpath + // must be empty. In most cases, applications do NOT want to load classes from the current + // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up + // scripts compatible with CDS. + void Arguments::fix_appclasspath() { + if (IgnoreEmptyClassPaths) { + const char separator = *os::path_separator(); + const char* src = _java_class_path->value(); + + // skip over all the leading empty paths + while (*src == separator) { + src ++; + } + + char* copy = AllocateHeap(strlen(src) + 1, mtInternal); + strncpy(copy, src, strlen(src) + 1); + + // trim all trailing empty paths + for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) { + *tail = '\0'; + } + + char from[3] = {separator, separator, '\0'}; + char to [2] = {separator, '\0'}; + while (StringUtils::replace_no_expand(copy, from, to) > 0) { + // Keep replacing "::" -> ":" until we have no more "::" (non-windows) + // Keep replacing ";;" -> ";" until we have no more ";;" (windows) + } + + _java_class_path->set_value(copy); + FreeHeap(copy); // a copy was made by set_value, so don't need this anymore + } + + if (!PrintSharedArchiveAndExit) { + ClassLoader::trace_class_path("[classpath: ", _java_class_path->value()); + } + } + jint Arguments::finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_required) { // This must be done after all -D arguments have been processed. scp_p->expand_endorsed(); if (scp_assembly_required || scp_p->get_endorsed() != NULL) {
*** 3481,3493 **** if (!UseCompressedOops || !UseCompressedClassPointers) { vm_exit_during_initialization( "Cannot dump shared archive when UseCompressedOops or UseCompressedClassPointers is off.", NULL); } } else { - // UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces. if (!UseCompressedOops || !UseCompressedClassPointers) { ! no_shared_spaces(); } #endif } } --- 3538,3549 ---- if (!UseCompressedOops || !UseCompressedClassPointers) { vm_exit_during_initialization( "Cannot dump shared archive when UseCompressedOops or UseCompressedClassPointers is off.", NULL); } } else { if (!UseCompressedOops || !UseCompressedClassPointers) { ! no_shared_spaces("UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces."); } #endif } }
*** 3723,3733 **** if ((UseSharedSpaces && FLAG_IS_CMDLINE(UseSharedSpaces)) || PrintSharedSpaces) { warning("Shared spaces are not supported in this VM"); FLAG_SET_DEFAULT(UseSharedSpaces, false); FLAG_SET_DEFAULT(PrintSharedSpaces, false); } ! no_shared_spaces(); #endif // INCLUDE_CDS return JNI_OK; } --- 3779,3789 ---- if ((UseSharedSpaces && FLAG_IS_CMDLINE(UseSharedSpaces)) || PrintSharedSpaces) { warning("Shared spaces are not supported in this VM"); FLAG_SET_DEFAULT(UseSharedSpaces, false); FLAG_SET_DEFAULT(PrintSharedSpaces, false); } ! no_shared_spaces("CDS Disabled"); #endif // INCLUDE_CDS return JNI_OK; }