--- old/src/share/vm/runtime/arguments.cpp 2015-05-27 10:37:36.000000000 -0500 +++ new/src/share/vm/runtime/arguments.cpp 2015-05-27 10:37:36.000000000 -0500 @@ -37,6 +37,9 @@ #include "prims/jvmtiExport.hpp" #include "runtime/arguments.hpp" #include "runtime/arguments_ext.hpp" +#include "runtime/commandLineFlagConstraintList.hpp" +#include "runtime/commandLineFlagRangeList.hpp" +#include "runtime/globals.hpp" #include "runtime/globals_extension.hpp" #include "runtime/java.hpp" #include "runtime/os.hpp" @@ -187,7 +190,6 @@ // Initialize system properties key and value. void Arguments::init_system_properties() { - PropertyList_add(&_system_properties, new SystemProperty("java.vm.specification.name", "Java Virtual Machine Specification", false)); PropertyList_add(&_system_properties, new SystemProperty("java.vm.version", VM_Version::vm_release(), false)); @@ -215,8 +217,7 @@ os::init_system_properties_values(); } - - // Update/Initialize System properties after JDK version number is known +// Update/Initialize System properties after JDK version number is known void Arguments::init_version_specific_system_properties() { enum { bufsz = 16 }; char buffer[bufsz]; @@ -569,7 +570,11 @@ } static bool set_bool_flag(char* name, bool value, Flag::Flags origin) { - return CommandLineFlags::boolAtPut(name, &value, origin); + if (CommandLineFlags::boolAtPut(name, &value, origin) == Flag::SUCCESS) { + return true; + } else { + return false; + } } static bool set_fp_numeric_flag(char* name, char* value, Flag::Flags origin) { @@ -578,7 +583,7 @@ return false; } - if (CommandLineFlags::doubleAtPut(name, &v, origin)) { + if (CommandLineFlags::doubleAtPut(name, &v, origin) == Flag::SUCCESS) { return true; } return false; @@ -590,7 +595,7 @@ bool is_neg = false; // Check the sign first since atomull() parses only unsigned values. if (*value == '-') { - if (!CommandLineFlags::intxAt(name, &intx_v)) { + if (CommandLineFlags::intxAt(name, &intx_v) != Flag::SUCCESS) { return false; } value++; @@ -603,26 +608,26 @@ if (is_neg) { intx_v = -intx_v; } - if (CommandLineFlags::intxAtPut(name, &intx_v, origin)) { + if (CommandLineFlags::intxAtPut(name, &intx_v, origin) == Flag::SUCCESS) { return true; } uintx uintx_v = (uintx) v; - if (!is_neg && CommandLineFlags::uintxAtPut(name, &uintx_v, origin)) { + if (!is_neg && (CommandLineFlags::uintxAtPut(name, &uintx_v, origin) == Flag::SUCCESS)) { return true; } uint64_t uint64_t_v = (uint64_t) v; - if (!is_neg && CommandLineFlags::uint64_tAtPut(name, &uint64_t_v, origin)) { + if (!is_neg && (CommandLineFlags::uint64_tAtPut(name, &uint64_t_v, origin) == Flag::SUCCESS)) { return true; } size_t size_t_v = (size_t) v; - if (!is_neg && CommandLineFlags::size_tAtPut(name, &size_t_v, origin)) { + if (!is_neg && (CommandLineFlags::size_tAtPut(name, &size_t_v, origin) == Flag::SUCCESS)) { return true; } return false; } static bool set_string_flag(char* name, const char* value, Flag::Flags origin) { - if (!CommandLineFlags::ccstrAtPut(name, &value, origin)) return false; + if (CommandLineFlags::ccstrAtPut(name, &value, origin) != Flag::SUCCESS) return false; // Contract: CommandLineFlags always returns a pointer that needs freeing. FREE_C_HEAP_ARRAY(char, value); return true; @@ -630,7 +635,7 @@ static bool append_to_string_flag(char* name, const char* new_value, Flag::Flags origin) { const char* old_value = ""; - if (!CommandLineFlags::ccstrAt(name, &old_value)) return false; + if (CommandLineFlags::ccstrAt(name, &old_value) != Flag::SUCCESS) return false; size_t old_len = old_value != NULL ? strlen(old_value) : 0; size_t new_len = strlen(new_value); const char* value; @@ -1397,61 +1402,16 @@ // Oop encoding heap max OopEncodingHeapMax = (uint64_t(max_juint) + 1) << LogMinObjAlignmentInBytes; + if (SurvivorAlignmentInBytes == 0) { + SurvivorAlignmentInBytes = ObjectAlignmentInBytes; + } + #if INCLUDE_ALL_GCS // Set CMS global values CompactibleFreeListSpace::set_cms_values(); #endif // INCLUDE_ALL_GCS } -bool verify_object_alignment() { - // Object alignment. - if (!is_power_of_2(ObjectAlignmentInBytes)) { - jio_fprintf(defaultStream::error_stream(), - "error: ObjectAlignmentInBytes=%d must be power of 2\n", - (int)ObjectAlignmentInBytes); - return false; - } - if ((int)ObjectAlignmentInBytes < BytesPerLong) { - jio_fprintf(defaultStream::error_stream(), - "error: ObjectAlignmentInBytes=%d must be greater or equal %d\n", - (int)ObjectAlignmentInBytes, BytesPerLong); - return false; - } - // It does not make sense to have big object alignment - // since a space lost due to alignment will be greater - // then a saved space from compressed oops. - if ((int)ObjectAlignmentInBytes > 256) { - jio_fprintf(defaultStream::error_stream(), - "error: ObjectAlignmentInBytes=%d must not be greater than 256\n", - (int)ObjectAlignmentInBytes); - return false; - } - // In case page size is very small. - if ((int)ObjectAlignmentInBytes >= os::vm_page_size()) { - jio_fprintf(defaultStream::error_stream(), - "error: ObjectAlignmentInBytes=%d must be less than page size %d\n", - (int)ObjectAlignmentInBytes, os::vm_page_size()); - return false; - } - if(SurvivorAlignmentInBytes == 0) { - SurvivorAlignmentInBytes = ObjectAlignmentInBytes; - } else { - if (!is_power_of_2(SurvivorAlignmentInBytes)) { - jio_fprintf(defaultStream::error_stream(), - "error: SurvivorAlignmentInBytes=%d must be power of 2\n", - (int)SurvivorAlignmentInBytes); - return false; - } - if (SurvivorAlignmentInBytes < ObjectAlignmentInBytes) { - jio_fprintf(defaultStream::error_stream(), - "error: SurvivorAlignmentInBytes=%d must be greater than ObjectAlignmentInBytes=%d \n", - (int)SurvivorAlignmentInBytes, (int)ObjectAlignmentInBytes); - return false; - } - } - return true; -} - size_t Arguments::max_heap_for_compressed_oops() { // Avoid sign flip. assert(OopEncodingHeapMax > (uint64_t)os::vm_page_size(), "Unusual page size"); @@ -1934,42 +1894,6 @@ //=========================================================================================================== // Parsing of main arguments -bool Arguments::verify_interval(uintx val, uintx min, - uintx max, const char* name) { - // Returns true iff value is in the inclusive interval [min..max] - // false, otherwise. - if (val >= min && val <= max) { - return true; - } - jio_fprintf(defaultStream::error_stream(), - "%s of " UINTX_FORMAT " is invalid; must be between " UINTX_FORMAT - " and " UINTX_FORMAT "\n", - name, val, min, max); - return false; -} - -bool Arguments::verify_min_value(intx val, intx min, const char* name) { - // Returns true if given value is at least specified min threshold - // false, otherwise. - if (val >= min ) { - return true; - } - jio_fprintf(defaultStream::error_stream(), - "%s of " INTX_FORMAT " is invalid; must be at least " INTX_FORMAT "\n", - name, val, min); - return false; -} - -bool Arguments::verify_percentage(uintx value, const char* name) { - if (is_percentage(value)) { - return true; - } - jio_fprintf(defaultStream::error_stream(), - "%s of " UINTX_FORMAT " is invalid; must be between 0 and 100\n", - name, value); - return false; -} - // check if do gclog rotation // +UseGCLogFileRotation is a must, // no gc log rotation when log file not supplied or @@ -1986,9 +1910,10 @@ } if (UseGCLogFileRotation && (GCLogFileSize != 0) && (GCLogFileSize < 8*K)) { - FLAG_SET_CMDLINE(size_t, GCLogFileSize, 8*K); - jio_fprintf(defaultStream::output_stream(), + if (FLAG_SET_CMDLINE(size_t, GCLogFileSize, 8*K) == Flag::SUCCESS) { + jio_fprintf(defaultStream::output_stream(), "GCLogFileSize changed to minimum 8K\n"); + } } } @@ -2037,38 +1962,6 @@ return count_p < 2 && count_t < 2; } -bool Arguments::verify_MinHeapFreeRatio(FormatBuffer<80>& err_msg, uintx min_heap_free_ratio) { - if (!is_percentage(min_heap_free_ratio)) { - err_msg.print("MinHeapFreeRatio must have a value between 0 and 100"); - return false; - } - if (min_heap_free_ratio > MaxHeapFreeRatio) { - err_msg.print("MinHeapFreeRatio (" UINTX_FORMAT ") must be less than or " - "equal to MaxHeapFreeRatio (" UINTX_FORMAT ")", min_heap_free_ratio, - MaxHeapFreeRatio); - return false; - } - // This does not set the flag itself, but stores the value in a safe place for later usage. - _min_heap_free_ratio = min_heap_free_ratio; - return true; -} - -bool Arguments::verify_MaxHeapFreeRatio(FormatBuffer<80>& err_msg, uintx max_heap_free_ratio) { - if (!is_percentage(max_heap_free_ratio)) { - err_msg.print("MaxHeapFreeRatio must have a value between 0 and 100"); - return false; - } - if (max_heap_free_ratio < MinHeapFreeRatio) { - err_msg.print("MaxHeapFreeRatio (" UINTX_FORMAT ") must be greater than or " - "equal to MinHeapFreeRatio (" UINTX_FORMAT ")", max_heap_free_ratio, - MinHeapFreeRatio); - return false; - } - // This does not set the flag itself, but stores the value in a safe place for later usage. - _max_heap_free_ratio = max_heap_free_ratio; - return true; -} - // Check consistency of GC selection bool Arguments::check_gc_consistency() { check_gclog_consistency(); @@ -2116,17 +2009,6 @@ } } -// Check stack pages settings -bool Arguments::check_stack_pages() -{ - bool status = true; - status = status && verify_min_value(StackYellowPages, 1, "StackYellowPages"); - status = status && verify_min_value(StackRedPages, 1, "StackRedPages"); - // greater stack shadow pages can't generate instruction to bang stack - status = status && verify_interval(StackShadowPages, 1, 50, "StackShadowPages"); - return status; -} - // Check the consistency of vm_init_args bool Arguments::check_vm_args_consistency() { // Method for adding checks for flag consistency. @@ -2143,50 +2025,6 @@ status = false; } - status = status && verify_interval(AdaptiveSizePolicyWeight, 0, 100, - "AdaptiveSizePolicyWeight"); - status = status && verify_percentage(ThresholdTolerance, "ThresholdTolerance"); - - // Divide by bucket size to prevent a large size from causing rollover when - // calculating amount of memory needed to be allocated for the String table. - status = status && verify_interval(StringTableSize, minimumStringTableSize, - (max_uintx / StringTable::bucket_size()), "StringTable size"); - - status = status && verify_interval(SymbolTableSize, minimumSymbolTableSize, - (max_uintx / SymbolTable::bucket_size()), "SymbolTable size"); - - { - // Using "else if" below to avoid printing two error messages if min > max. - // This will also prevent us from reporting both min>100 and max>100 at the - // same time, but that is less annoying than printing two identical errors IMHO. - FormatBuffer<80> err_msg("%s",""); - if (!verify_MinHeapFreeRatio(err_msg, MinHeapFreeRatio)) { - jio_fprintf(defaultStream::error_stream(), "%s\n", err_msg.buffer()); - status = false; - } else if (!verify_MaxHeapFreeRatio(err_msg, MaxHeapFreeRatio)) { - jio_fprintf(defaultStream::error_stream(), "%s\n", err_msg.buffer()); - status = false; - } - } - - // Min/MaxMetaspaceFreeRatio - status = status && verify_percentage(MinMetaspaceFreeRatio, "MinMetaspaceFreeRatio"); - status = status && verify_percentage(MaxMetaspaceFreeRatio, "MaxMetaspaceFreeRatio"); - - if (MinMetaspaceFreeRatio > MaxMetaspaceFreeRatio) { - jio_fprintf(defaultStream::error_stream(), - "MinMetaspaceFreeRatio (%s" UINTX_FORMAT ") must be less than or " - "equal to MaxMetaspaceFreeRatio (%s" UINTX_FORMAT ")\n", - FLAG_IS_DEFAULT(MinMetaspaceFreeRatio) ? "Default: " : "", - MinMetaspaceFreeRatio, - FLAG_IS_DEFAULT(MaxMetaspaceFreeRatio) ? "Default: " : "", - MaxMetaspaceFreeRatio); - status = false; - } - - // Trying to keep 100% free is not practical - MinMetaspaceFreeRatio = MIN2(MinMetaspaceFreeRatio, (uintx) 99); - if (FullGCALot && FLAG_IS_DEFAULT(MarkSweepAlwaysCompactCount)) { MarkSweepAlwaysCompactCount = 1; // Move objects every gc. } @@ -2194,10 +2032,14 @@ if (UseParallelOldGC && ParallelOldGCSplitALot) { // Settings to encourage splitting. if (!FLAG_IS_CMDLINE(NewRatio)) { - FLAG_SET_CMDLINE(uintx, NewRatio, 2); + if (FLAG_SET_CMDLINE(uintx, NewRatio, 2) != Flag::SUCCESS) { + return false; + } } if (!FLAG_IS_CMDLINE(ScavengeBeforeFullGC)) { - FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false); + if (FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false) != Flag::SUCCESS) { + return false; + } } } @@ -2205,18 +2047,12 @@ FLAG_SET_DEFAULT(ScavengeBeforeFullGC, false); } - status = status && verify_percentage(GCHeapFreeLimit, "GCHeapFreeLimit"); - status = status && verify_percentage(GCTimeLimit, "GCTimeLimit"); if (GCTimeLimit == 100) { // Turn off gc-overhead-limit-exceeded checks FLAG_SET_DEFAULT(UseGCOverheadLimit, false); } status = status && check_gc_consistency(); - status = status && check_stack_pages(); - - status = status && verify_percentage(CMSIncrementalSafetyFactor, - "CMSIncrementalSafetyFactor"); // CMS space iteration, which FLSVerifyAllHeapreferences entails, // insists that we hold the requisite locks so that the iteration is @@ -2250,132 +2086,6 @@ status = false; } - status = status && verify_min_value(ParGCArrayScanChunk, 1, "ParGCArrayScanChunk"); - -#if INCLUDE_ALL_GCS - if (UseG1GC) { - status = status && verify_percentage(G1NewSizePercent, "G1NewSizePercent"); - status = status && verify_percentage(G1MaxNewSizePercent, "G1MaxNewSizePercent"); - status = status && verify_interval(G1NewSizePercent, 0, G1MaxNewSizePercent, "G1NewSizePercent"); - - status = status && verify_percentage(G1ConfidencePercent, "G1ConfidencePercent"); - status = status && verify_percentage(InitiatingHeapOccupancyPercent, - "InitiatingHeapOccupancyPercent"); - status = status && verify_min_value(G1RefProcDrainInterval, 1, - "G1RefProcDrainInterval"); - status = status && verify_min_value((intx)G1ConcMarkStepDurationMillis, 1, - "G1ConcMarkStepDurationMillis"); - status = status && verify_interval(G1ConcRSHotCardLimit, 0, max_jubyte, - "G1ConcRSHotCardLimit"); - status = status && verify_interval(G1ConcRSLogCacheSize, 0, 27, - "G1ConcRSLogCacheSize"); - status = status && verify_interval(StringDeduplicationAgeThreshold, 1, markOopDesc::max_age, - "StringDeduplicationAgeThreshold"); - } - if (UseConcMarkSweepGC) { - status = status && verify_min_value(CMSOldPLABNumRefills, 1, "CMSOldPLABNumRefills"); - status = status && verify_min_value(CMSOldPLABToleranceFactor, 1, "CMSOldPLABToleranceFactor"); - status = status && verify_min_value(CMSOldPLABMax, 1, "CMSOldPLABMax"); - status = status && verify_interval(CMSOldPLABMin, 1, CMSOldPLABMax, "CMSOldPLABMin"); - - status = status && verify_min_value(CMSYoungGenPerWorker, 1, "CMSYoungGenPerWorker"); - - status = status && verify_min_value(CMSSamplingGrain, 1, "CMSSamplingGrain"); - status = status && verify_interval(CMS_SweepWeight, 0, 100, "CMS_SweepWeight"); - status = status && verify_interval(CMS_FLSWeight, 0, 100, "CMS_FLSWeight"); - - status = status && verify_interval(FLSCoalescePolicy, 0, 4, "FLSCoalescePolicy"); - - status = status && verify_min_value(CMSRescanMultiple, 1, "CMSRescanMultiple"); - status = status && verify_min_value(CMSConcMarkMultiple, 1, "CMSConcMarkMultiple"); - - status = status && verify_interval(CMSPrecleanIter, 0, 9, "CMSPrecleanIter"); - status = status && verify_min_value(CMSPrecleanDenominator, 1, "CMSPrecleanDenominator"); - status = status && verify_interval(CMSPrecleanNumerator, 0, CMSPrecleanDenominator - 1, "CMSPrecleanNumerator"); - - status = status && verify_percentage(CMSBootstrapOccupancy, "CMSBootstrapOccupancy"); - - status = status && verify_min_value(CMSPrecleanThreshold, 100, "CMSPrecleanThreshold"); - - status = status && verify_percentage(CMSScheduleRemarkEdenPenetration, "CMSScheduleRemarkEdenPenetration"); - status = status && verify_min_value(CMSScheduleRemarkSamplingRatio, 1, "CMSScheduleRemarkSamplingRatio"); - status = status && verify_min_value(CMSBitMapYieldQuantum, 1, "CMSBitMapYieldQuantum"); - status = status && verify_percentage(CMSTriggerRatio, "CMSTriggerRatio"); - status = status && verify_percentage(CMSIsTooFullPercentage, "CMSIsTooFullPercentage"); - } - - if (UseParallelGC || UseParallelOldGC) { - status = status && verify_interval(ParallelOldDeadWoodLimiterMean, 0, 100, "ParallelOldDeadWoodLimiterMean"); - status = status && verify_interval(ParallelOldDeadWoodLimiterStdDev, 0, 100, "ParallelOldDeadWoodLimiterStdDev"); - - status = status && verify_percentage(YoungGenerationSizeIncrement, "YoungGenerationSizeIncrement"); - status = status && verify_percentage(TenuredGenerationSizeIncrement, "TenuredGenerationSizeIncrement"); - - status = status && verify_min_value(YoungGenerationSizeSupplementDecay, 1, "YoungGenerationSizeSupplementDecay"); - status = status && verify_min_value(TenuredGenerationSizeSupplementDecay, 1, "TenuredGenerationSizeSupplementDecay"); - - status = status && verify_min_value(ParGCCardsPerStrideChunk, 1, "ParGCCardsPerStrideChunk"); - - status = status && verify_min_value(ParallelOldGCSplitInterval, 0, "ParallelOldGCSplitInterval"); - } -#endif // INCLUDE_ALL_GCS - - status = status && verify_interval(RefDiscoveryPolicy, - ReferenceProcessor::DiscoveryPolicyMin, - ReferenceProcessor::DiscoveryPolicyMax, - "RefDiscoveryPolicy"); - - // Limit the lower bound of this flag to 1 as it is used in a division - // expression. - status = status && verify_interval(TLABWasteTargetPercent, - 1, 100, "TLABWasteTargetPercent"); - - status = status && verify_object_alignment(); - - status = status && verify_interval(CompressedClassSpaceSize, 1*M, 3*G, - "CompressedClassSpaceSize"); - - status = status && verify_interval(MarkStackSizeMax, - 1, (max_jint - 1), "MarkStackSizeMax"); - status = status && verify_interval(NUMAChunkResizeWeight, 0, 100, "NUMAChunkResizeWeight"); - - status = status && verify_min_value(LogEventsBufferEntries, 1, "LogEventsBufferEntries"); - - status = status && verify_min_value(HeapSizePerGCThread, (size_t) os::vm_page_size(), "HeapSizePerGCThread"); - - status = status && verify_min_value(GCTaskTimeStampEntries, 1, "GCTaskTimeStampEntries"); - - status = status && verify_percentage(ParallelGCBufferWastePct, "ParallelGCBufferWastePct"); - status = status && verify_interval(TargetPLABWastePct, 1, 100, "TargetPLABWastePct"); - - status = status && verify_min_value(ParGCStridesPerThread, 1, "ParGCStridesPerThread"); - - status = status && verify_min_value(MinRAMFraction, 1, "MinRAMFraction"); - status = status && verify_min_value(InitialRAMFraction, 1, "InitialRAMFraction"); - status = status && verify_min_value(MaxRAMFraction, 1, "MaxRAMFraction"); - status = status && verify_min_value(DefaultMaxRAMFraction, 1, "DefaultMaxRAMFraction"); - - status = status && verify_interval(AdaptiveTimeWeight, 0, 100, "AdaptiveTimeWeight"); - status = status && verify_min_value(AdaptiveSizeDecrementScaleFactor, 1, "AdaptiveSizeDecrementScaleFactor"); - - status = status && verify_interval(TLABAllocationWeight, 0, 100, "TLABAllocationWeight"); - status = status && verify_min_value(MinTLABSize, 1, "MinTLABSize"); - status = status && verify_min_value(TLABRefillWasteFraction, 1, "TLABRefillWasteFraction"); - - status = status && verify_percentage(YoungGenerationSizeSupplement, "YoungGenerationSizeSupplement"); - status = status && verify_percentage(TenuredGenerationSizeSupplement, "TenuredGenerationSizeSupplement"); - - status = status && verify_interval(MaxTenuringThreshold, 0, markOopDesc::max_age + 1, "MaxTenuringThreshold"); - status = status && verify_interval(InitialTenuringThreshold, 0, MaxTenuringThreshold, "InitialTenuringThreshold"); - status = status && verify_percentage(TargetSurvivorRatio, "TargetSurvivorRatio"); - status = status && verify_percentage(MarkSweepDeadRatio, "MarkSweepDeadRatio"); - - status = status && verify_min_value(MarkSweepAlwaysCompactCount, 1, "MarkSweepAlwaysCompactCount"); -#ifdef COMPILER1 - status = status && verify_min_value(ValueMapInitialSize, 1, "ValueMapInitialSize"); -#endif - status = status && verify_min_value(HeapSearchSteps, 1, "HeapSearchSteps"); - if (PrintNMTStatistics) { #if INCLUDE_NMT if (MemTracker::tracking_level() == NMT_off) { @@ -2386,27 +2096,7 @@ } #endif } - - // Need to limit the extent of the padding to reasonable size. - // 8K is well beyond the reasonable HW cache line size, even with the - // aggressive prefetching, while still leaving the room for segregating - // among the distinct pages. - if (ContendedPaddingWidth < 0 || ContendedPaddingWidth > 8192) { - jio_fprintf(defaultStream::error_stream(), - "ContendedPaddingWidth=" INTX_FORMAT " must be in between %d and %d\n", - ContendedPaddingWidth, 0, 8192); - status = false; - } - - // Need to enforce the padding not to break the existing field alignments. - // It is sufficient to check against the largest type size. - if ((ContendedPaddingWidth % BytesPerLong) != 0) { - jio_fprintf(defaultStream::error_stream(), - "ContendedPaddingWidth=" INTX_FORMAT " must be a multiple of %d\n", - ContendedPaddingWidth, BytesPerLong); - status = false; - } - + // Check lower bounds of the code cache // Template Interpreter code is approximately 3X larger in debug builds. uint min_code_cache_size = CodeCacheMinimumUseSpace DEBUG_ONLY(* 3); @@ -2445,17 +2135,9 @@ status = false; } - status &= verify_interval(NmethodSweepActivity, 0, 2000, "NmethodSweepActivity"); - status &= verify_interval(CodeCacheMinBlockLength, 1, 100, "CodeCacheMinBlockLength"); - status &= verify_interval(CodeCacheSegmentSize, 1, 1024, "CodeCacheSegmentSize"); - status &= verify_interval(StartAggressiveSweepingAt, 0, 100, "StartAggressiveSweepingAt"); - - int min_number_of_compiler_threads = get_min_number_of_compiler_threads(); // The default CICompilerCount's value is CI_COMPILER_COUNT. assert(min_number_of_compiler_threads <= CI_COMPILER_COUNT, "minimum should be less or equal default number"); - // Check the minimum number of compiler threads - status &=verify_min_value(CICompilerCount, min_number_of_compiler_threads, "CICompilerCount"); if (!FLAG_IS_DEFAULT(CICompilerCount) && !FLAG_IS_DEFAULT(CICompilerCountPerCPU) && CICompilerCountPerCPU) { warning("The VM option CICompilerCountPerCPU overrides CICompilerCount."); @@ -2648,12 +2330,20 @@ // -verbose:[class/gc/jni] if (match_option(option, "-verbose", &tail)) { if (!strcmp(tail, ":class") || !strcmp(tail, "")) { - FLAG_SET_CMDLINE(bool, TraceClassLoading, true); - FLAG_SET_CMDLINE(bool, TraceClassUnloading, true); + if (FLAG_SET_CMDLINE(bool, TraceClassLoading, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(bool, TraceClassUnloading, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } } else if (!strcmp(tail, ":gc")) { - FLAG_SET_CMDLINE(bool, PrintGC, true); + if (FLAG_SET_CMDLINE(bool, PrintGC, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } } else if (!strcmp(tail, ":jni")) { - FLAG_SET_CMDLINE(bool, PrintJNIResolving, true); + if (FLAG_SET_CMDLINE(bool, PrintJNIResolving, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } } // -da / -ea / -disableassertions / -enableassertions // These accept an optional class/package name separated by a colon, e.g., @@ -2740,16 +2430,24 @@ #endif // !INCLUDE_JVMTI // -Xnoclassgc } else if (match_option(option, "-Xnoclassgc")) { - FLAG_SET_CMDLINE(bool, ClassUnloading, false); + if (FLAG_SET_CMDLINE(bool, ClassUnloading, false) != Flag::SUCCESS) { + return JNI_EINVAL; + } // -Xconcgc } else if (match_option(option, "-Xconcgc")) { - FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true); + if (FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } // -Xnoconcgc } else if (match_option(option, "-Xnoconcgc")) { - FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false); + if (FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false) != Flag::SUCCESS) { + return JNI_EINVAL; + } // -Xbatch } else if (match_option(option, "-Xbatch")) { - FLAG_SET_CMDLINE(bool, BackgroundCompilation, false); + if (FLAG_SET_CMDLINE(bool, BackgroundCompilation, false) != Flag::SUCCESS) { + return JNI_EINVAL; + } // -Xmn for compatibility with other JVM vendors } else if (match_option(option, "-Xmn", &tail)) { julong long_initial_young_size = 0; @@ -2760,8 +2458,12 @@ describe_range_error(errcode); return JNI_EINVAL; } - FLAG_SET_CMDLINE(size_t, MaxNewSize, (size_t)long_initial_young_size); - FLAG_SET_CMDLINE(size_t, NewSize, (size_t)long_initial_young_size); + if (FLAG_SET_CMDLINE(size_t, MaxNewSize, (size_t)long_initial_young_size) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(size_t, NewSize, (size_t)long_initial_young_size) != Flag::SUCCESS) { + return JNI_EINVAL; + } // -Xms } else if (match_option(option, "-Xms", &tail)) { julong long_initial_heap_size = 0; @@ -2776,7 +2478,9 @@ set_min_heap_size((size_t)long_initial_heap_size); // Currently the minimum size and the initial heap sizes are the same. // Can be overridden with -XX:InitialHeapSize. - FLAG_SET_CMDLINE(size_t, InitialHeapSize, (size_t)long_initial_heap_size); + if (FLAG_SET_CMDLINE(size_t, InitialHeapSize, (size_t)long_initial_heap_size) != Flag::SUCCESS) { + return JNI_EINVAL; + } // -Xmx } else if (match_option(option, "-Xmx", &tail) || match_option(option, "-XX:MaxHeapSize=", &tail)) { julong long_max_heap_size = 0; @@ -2787,30 +2491,36 @@ describe_range_error(errcode); return JNI_EINVAL; } - FLAG_SET_CMDLINE(size_t, MaxHeapSize, (size_t)long_max_heap_size); + if (FLAG_SET_CMDLINE(size_t, MaxHeapSize, (size_t)long_max_heap_size) != Flag::SUCCESS) { + return JNI_EINVAL; + } // Xmaxf } else if (match_option(option, "-Xmaxf", &tail)) { char* err; int maxf = (int)(strtod(tail, &err) * 100); - if (*err != '\0' || *tail == '\0' || maxf < 0 || maxf > 100) { + if (*err != '\0' || *tail == '\0') { jio_fprintf(defaultStream::error_stream(), "Bad max heap free percentage size: %s\n", option->optionString); return JNI_EINVAL; } else { - FLAG_SET_CMDLINE(uintx, MaxHeapFreeRatio, maxf); + if (FLAG_SET_CMDLINE(uintx, MaxHeapFreeRatio, maxf) != Flag::SUCCESS) { + return JNI_EINVAL; + } } // Xminf } else if (match_option(option, "-Xminf", &tail)) { char* err; int minf = (int)(strtod(tail, &err) * 100); - if (*err != '\0' || *tail == '\0' || minf < 0 || minf > 100) { + if (*err != '\0' || *tail == '\0') { jio_fprintf(defaultStream::error_stream(), "Bad min heap free percentage size: %s\n", option->optionString); return JNI_EINVAL; } else { - FLAG_SET_CMDLINE(uintx, MinHeapFreeRatio, minf); + if (FLAG_SET_CMDLINE(uintx, MinHeapFreeRatio, minf) != Flag::SUCCESS) { + return JNI_EINVAL; + } } // -Xss } else if (match_option(option, "-Xss", &tail)) { @@ -2823,8 +2533,10 @@ return JNI_EINVAL; } // Internally track ThreadStackSize in units of 1024 bytes. - FLAG_SET_CMDLINE(intx, ThreadStackSize, - round_to((int)long_ThreadStackSize, K) / K); + if (FLAG_SET_CMDLINE(intx, ThreadStackSize, + round_to((int)long_ThreadStackSize, K) / K) != Flag::SUCCESS) { + return JNI_EINVAL; + } // -Xoss } else if (match_option(option, "-Xoss", &tail)) { // HotSpot does not have separate native and Java stacks, ignore silently for compatibility @@ -2837,7 +2549,9 @@ os::vm_page_size()/K); return JNI_EINVAL; } - FLAG_SET_CMDLINE(uintx, CodeCacheExpansionSize, (uintx)long_CodeCacheExpansionSize); + if (FLAG_SET_CMDLINE(uintx, CodeCacheExpansionSize, (uintx)long_CodeCacheExpansionSize) != Flag::SUCCESS) { + return JNI_EINVAL; + } } else if (match_option(option, "-Xmaxjitcodesize", &tail) || match_option(option, "-XX:ReservedCodeCacheSize=", &tail)) { julong long_ReservedCodeCacheSize = 0; @@ -2848,7 +2562,9 @@ "Invalid maximum code cache size: %s.\n", option->optionString); return JNI_EINVAL; } - FLAG_SET_CMDLINE(uintx, ReservedCodeCacheSize, (uintx)long_ReservedCodeCacheSize); + if (FLAG_SET_CMDLINE(uintx, ReservedCodeCacheSize, (uintx)long_ReservedCodeCacheSize) != Flag::SUCCESS) { + return JNI_EINVAL; + } // -XX:NonNMethodCodeHeapSize= } else if (match_option(option, "-XX:NonNMethodCodeHeapSize=", &tail)) { julong long_NonNMethodCodeHeapSize = 0; @@ -2859,7 +2575,9 @@ "Invalid maximum non-nmethod code heap size: %s.\n", option->optionString); return JNI_EINVAL; } - FLAG_SET_CMDLINE(uintx, NonNMethodCodeHeapSize, (uintx)long_NonNMethodCodeHeapSize); + if (FLAG_SET_CMDLINE(uintx, NonNMethodCodeHeapSize, (uintx)long_NonNMethodCodeHeapSize) != Flag::SUCCESS) { + return JNI_EINVAL; + } // -XX:ProfiledCodeHeapSize= } else if (match_option(option, "-XX:ProfiledCodeHeapSize=", &tail)) { julong long_ProfiledCodeHeapSize = 0; @@ -2870,7 +2588,9 @@ "Invalid maximum profiled code heap size: %s.\n", option->optionString); return JNI_EINVAL; } - FLAG_SET_CMDLINE(uintx, ProfiledCodeHeapSize, (uintx)long_ProfiledCodeHeapSize); + if (FLAG_SET_CMDLINE(uintx, ProfiledCodeHeapSize, (uintx)long_ProfiledCodeHeapSize) != Flag::SUCCESS) { + return JNI_EINVAL; + } // -XX:NonProfiledCodeHeapSizee= } else if (match_option(option, "-XX:NonProfiledCodeHeapSize=", &tail)) { julong long_NonProfiledCodeHeapSize = 0; @@ -2881,17 +2601,9 @@ "Invalid maximum non-profiled code heap size: %s.\n", option->optionString); return JNI_EINVAL; } - FLAG_SET_CMDLINE(uintx, NonProfiledCodeHeapSize, (uintx)long_NonProfiledCodeHeapSize); - //-XX:IncreaseFirstTierCompileThresholdAt= - } else if (match_option(option, "-XX:IncreaseFirstTierCompileThresholdAt=", &tail)) { - uintx uint_IncreaseFirstTierCompileThresholdAt = 0; - if (!parse_uintx(tail, &uint_IncreaseFirstTierCompileThresholdAt, 0) || uint_IncreaseFirstTierCompileThresholdAt > 99) { - jio_fprintf(defaultStream::error_stream(), - "Invalid value for IncreaseFirstTierCompileThresholdAt: %s. Should be between 0 and 99.\n", - option->optionString); - return JNI_EINVAL; - } - FLAG_SET_CMDLINE(uintx, IncreaseFirstTierCompileThresholdAt, (uintx)uint_IncreaseFirstTierCompileThresholdAt); + if (FLAG_SET_CMDLINE(uintx, NonProfiledCodeHeapSize, (uintx)long_NonProfiledCodeHeapSize) != Flag::SUCCESS) { + return JNI_EINVAL; + } // -green } else if (match_option(option, "-green")) { jio_fprintf(defaultStream::error_stream(), @@ -2906,10 +2618,14 @@ // -Xrs } else if (match_option(option, "-Xrs")) { // Classic/EVM option, new functionality - FLAG_SET_CMDLINE(bool, ReduceSignalUsage, true); + if (FLAG_SET_CMDLINE(bool, ReduceSignalUsage, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } } else if (match_option(option, "-Xusealtsigs")) { // change default internal VM signals used - lower case for back compat - FLAG_SET_CMDLINE(bool, UseAltSigs, true); + if (FLAG_SET_CMDLINE(bool, UseAltSigs, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } // -Xoptimize } else if (match_option(option, "-Xoptimize")) { // EVM option, ignore silently for compatibility @@ -2924,11 +2640,21 @@ #endif // INCLUDE_FPROF // -Xconcurrentio } else if (match_option(option, "-Xconcurrentio")) { - FLAG_SET_CMDLINE(bool, UseLWPSynchronization, true); - FLAG_SET_CMDLINE(bool, BackgroundCompilation, false); - FLAG_SET_CMDLINE(intx, DeferThrSuspendLoopCount, 1); - FLAG_SET_CMDLINE(bool, UseTLAB, false); - FLAG_SET_CMDLINE(size_t, NewSizeThreadIncrease, 16 * K); // 20Kb per thread added to new generation + if (FLAG_SET_CMDLINE(bool, UseLWPSynchronization, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(bool, BackgroundCompilation, false) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(intx, DeferThrSuspendLoopCount, 1) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(bool, UseTLAB, false) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(size_t, NewSizeThreadIncrease, 16 * K) != Flag::SUCCESS) { // 20Kb per thread added to new generation + return JNI_EINVAL; + } // -Xinternalversion } else if (match_option(option, "-Xinternalversion")) { @@ -2966,7 +2692,9 @@ // Out of the box management support if (match_option(option, "-Dcom.sun.management", &tail)) { #if INCLUDE_MANAGEMENT - FLAG_SET_CMDLINE(bool, ManagementServer, true); + if (FLAG_SET_CMDLINE(bool, ManagementServer, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } #else jio_fprintf(defaultStream::output_stream(), "-Dcom.sun.management is not supported in this VM.\n"); @@ -2985,31 +2713,57 @@ set_mode_flags(_comp); // -Xshare:dump } else if (match_option(option, "-Xshare:dump")) { - FLAG_SET_CMDLINE(bool, DumpSharedSpaces, true); + if (FLAG_SET_CMDLINE(bool, DumpSharedSpaces, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } set_mode_flags(_int); // Prevent compilation, which creates objects // -Xshare:on } else if (match_option(option, "-Xshare:on")) { - FLAG_SET_CMDLINE(bool, UseSharedSpaces, true); - FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true); + if (FLAG_SET_CMDLINE(bool, UseSharedSpaces, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } // -Xshare:auto } else if (match_option(option, "-Xshare:auto")) { - FLAG_SET_CMDLINE(bool, UseSharedSpaces, true); - FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false); + if (FLAG_SET_CMDLINE(bool, UseSharedSpaces, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false) != Flag::SUCCESS) { + return JNI_EINVAL; + } // -Xshare:off } else if (match_option(option, "-Xshare:off")) { - FLAG_SET_CMDLINE(bool, UseSharedSpaces, false); - FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false); + if (FLAG_SET_CMDLINE(bool, UseSharedSpaces, false) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false) != Flag::SUCCESS) { + return JNI_EINVAL; + } // -Xverify } else if (match_option(option, "-Xverify", &tail)) { if (strcmp(tail, ":all") == 0 || strcmp(tail, "") == 0) { - FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, true); - FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true); + if (FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } } else if (strcmp(tail, ":remote") == 0) { - FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false); - FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true); + if (FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } } else if (strcmp(tail, ":none") == 0) { - FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false); - FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, false); + if (FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, false) != Flag::SUCCESS) { + return JNI_EINVAL; + } } else if (is_bad_option(option, args->ignoreUnrecognized, "verification")) { return JNI_EINVAL; } @@ -3034,9 +2788,12 @@ "Note %%p or %%t can only be used once\n", _gc_log_filename); return JNI_EINVAL; } - FLAG_SET_CMDLINE(bool, PrintGC, true); - FLAG_SET_CMDLINE(bool, PrintGCTimeStamps, true); - + if (FLAG_SET_CMDLINE(bool, PrintGC, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(bool, PrintGCTimeStamps, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } // JNI hooks } else if (match_option(option, "-Xcheck", &tail)) { if (!strcmp(tail, ":jni")) { @@ -3088,16 +2845,24 @@ initHeapSize = limit_by_allocatable_memory(initHeapSize); if (FLAG_IS_DEFAULT(MaxHeapSize)) { - FLAG_SET_CMDLINE(size_t, MaxHeapSize, initHeapSize); - FLAG_SET_CMDLINE(size_t, InitialHeapSize, initHeapSize); + if (FLAG_SET_CMDLINE(size_t, MaxHeapSize, initHeapSize) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(size_t, InitialHeapSize, initHeapSize) != Flag::SUCCESS) { + return JNI_EINVAL; + } // Currently the minimum size and the initial heap sizes are the same. set_min_heap_size(initHeapSize); } if (FLAG_IS_DEFAULT(NewSize)) { // Make the young generation 3/8ths of the total heap. - FLAG_SET_CMDLINE(size_t, NewSize, - ((julong)MaxHeapSize / (julong)8) * (julong)3); - FLAG_SET_CMDLINE(size_t, MaxNewSize, NewSize); + if (FLAG_SET_CMDLINE(size_t, NewSize, + ((julong)MaxHeapSize / (julong)8) * (julong)3) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(size_t, MaxNewSize, NewSize) != Flag::SUCCESS) { + return JNI_EINVAL; + } } #if !defined(_ALLBSD_SOURCE) && !defined(AIX) // UseLargePages is not yet supported on BSD and AIX. @@ -3105,14 +2870,22 @@ #endif // Increase some data structure sizes for efficiency - FLAG_SET_CMDLINE(size_t, BaseFootPrintEstimate, MaxHeapSize); - FLAG_SET_CMDLINE(bool, ResizeTLAB, false); - FLAG_SET_CMDLINE(size_t, TLABSize, 256*K); + if (FLAG_SET_CMDLINE(size_t, BaseFootPrintEstimate, MaxHeapSize) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(bool, ResizeTLAB, false) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(size_t, TLABSize, 256*K) != Flag::SUCCESS) { + return JNI_EINVAL; + } // See the OldPLABSize comment below, but replace 'after promotion' // with 'after copying'. YoungPLABSize is the size of the survivor // space per-gc-thread buffers. The default is 4kw. - FLAG_SET_CMDLINE(size_t, YoungPLABSize, 256*K); // Note: this is in words + if (FLAG_SET_CMDLINE(size_t, YoungPLABSize, 256*K) != Flag::SUCCESS) { // Note: this is in words + return JNI_EINVAL; + } // OldPLABSize is the size of the buffers in the old gen that // UseParallelGC uses to promote live data that doesn't fit in the @@ -3127,62 +2900,111 @@ // locality. A minor effect may be that larger PLABs reduce the // number of PLAB allocation events during gc. The value of 8kw // was arrived at by experimenting with specjbb. - FLAG_SET_CMDLINE(size_t, OldPLABSize, 8*K); // Note: this is in words + if (FLAG_SET_CMDLINE(size_t, OldPLABSize, 8*K) != Flag::SUCCESS) { // Note: this is in words + return JNI_EINVAL; + } // Enable parallel GC and adaptive generation sizing - FLAG_SET_CMDLINE(bool, UseParallelGC, true); + if (FLAG_SET_CMDLINE(bool, UseParallelGC, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } FLAG_SET_DEFAULT(ParallelGCThreads, Abstract_VM_Version::parallel_worker_threads()); // Encourage steady state memory management - FLAG_SET_CMDLINE(uintx, ThresholdTolerance, 100); + if (FLAG_SET_CMDLINE(uintx, ThresholdTolerance, 100) != Flag::SUCCESS) { + return JNI_EINVAL; + } // This appears to improve mutator locality - FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false); + if (FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false) != Flag::SUCCESS) { + return JNI_EINVAL; + } // Get around early Solaris scheduling bug // (affinity vs other jobs on system) // but disallow DR and offlining (5008695). - FLAG_SET_CMDLINE(bool, BindGCTaskThreadsToCPUs, true); + if (FLAG_SET_CMDLINE(bool, BindGCTaskThreadsToCPUs, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } // Need to keep consistency of MaxTenuringThreshold and AlwaysTenure/NeverTenure; // and the last option wins. } else if (match_option(option, "-XX:+NeverTenure")) { - FLAG_SET_CMDLINE(bool, NeverTenure, true); - FLAG_SET_CMDLINE(bool, AlwaysTenure, false); - FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, markOopDesc::max_age + 1); + if (FLAG_SET_CMDLINE(bool, NeverTenure, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(bool, AlwaysTenure, false) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, markOopDesc::max_age + 1) != Flag::SUCCESS) { + return JNI_EINVAL; + } } else if (match_option(option, "-XX:+AlwaysTenure")) { - FLAG_SET_CMDLINE(bool, NeverTenure, false); - FLAG_SET_CMDLINE(bool, AlwaysTenure, true); - FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, 0); + if (FLAG_SET_CMDLINE(bool, NeverTenure, false) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(bool, AlwaysTenure, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, 0) != Flag::SUCCESS) { + return JNI_EINVAL; + } } else if (match_option(option, "-XX:MaxTenuringThreshold=", &tail)) { uintx max_tenuring_thresh = 0; - if(!parse_uintx(tail, &max_tenuring_thresh, 0)) { + if (!parse_uintx(tail, &max_tenuring_thresh, 0)) { jio_fprintf(defaultStream::error_stream(), - "Improperly specified VM option 'MaxTenuringThreshold=%s'\n", tail); + "Improperly specified VM option \'MaxTenuringThreshold=%s\'\n", tail); + return JNI_EINVAL; + } + + if (FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, max_tenuring_thresh) != Flag::SUCCESS) { return JNI_EINVAL; } - FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, max_tenuring_thresh); if (MaxTenuringThreshold == 0) { - FLAG_SET_CMDLINE(bool, NeverTenure, false); - FLAG_SET_CMDLINE(bool, AlwaysTenure, true); + if (FLAG_SET_CMDLINE(bool, NeverTenure, false) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(bool, AlwaysTenure, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } } else { - FLAG_SET_CMDLINE(bool, NeverTenure, false); - FLAG_SET_CMDLINE(bool, AlwaysTenure, false); + if (FLAG_SET_CMDLINE(bool, NeverTenure, false) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(bool, AlwaysTenure, false) != Flag::SUCCESS) { + return JNI_EINVAL; + } } } else if (match_option(option, "-XX:+DisplayVMOutputToStderr")) { - FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, false); - FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, true); + if (FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, false) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } } else if (match_option(option, "-XX:+DisplayVMOutputToStdout")) { - FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, false); - FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, true); + if (FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, false) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } } else if (match_option(option, "-XX:+ExtendedDTraceProbes")) { #if defined(DTRACE_ENABLED) - FLAG_SET_CMDLINE(bool, ExtendedDTraceProbes, true); - FLAG_SET_CMDLINE(bool, DTraceMethodProbes, true); - FLAG_SET_CMDLINE(bool, DTraceAllocProbes, true); - FLAG_SET_CMDLINE(bool, DTraceMonitorProbes, true); + if (FLAG_SET_CMDLINE(bool, ExtendedDTraceProbes, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(bool, DTraceMethodProbes, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(bool, DTraceAllocProbes, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(bool, DTraceMonitorProbes, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } #else // defined(DTRACE_ENABLED) jio_fprintf(defaultStream::error_stream(), "ExtendedDTraceProbes flag is not applicable for this configuration\n"); @@ -3190,9 +3012,13 @@ #endif // defined(DTRACE_ENABLED) #ifdef ASSERT } else if (match_option(option, "-XX:+FullGCALot")) { - FLAG_SET_CMDLINE(bool, FullGCALot, true); + if (FLAG_SET_CMDLINE(bool, FullGCALot, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } // disable scavenge before parallel mark-compact - FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false); + if (FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false) != Flag::SUCCESS) { + return JNI_EINVAL; + } #endif } else if (match_option(option, "-XX:CMSMarkStackSize=", &tail) || match_option(option, "-XX:G1MarkStackSize=", &tail)) { @@ -3207,7 +3033,9 @@ jio_fprintf(defaultStream::error_stream(), "Please use -XX:MarkStackSize in place of " "-XX:CMSMarkStackSize or -XX:G1MarkStackSize in the future\n"); - FLAG_SET_CMDLINE(size_t, MarkStackSize, stack_size); + if (FLAG_SET_CMDLINE(size_t, MarkStackSize, stack_size) != Flag::SUCCESS) { + return JNI_EINVAL; + } } else if (match_option(option, "-XX:CMSMarkStackSizeMax=", &tail)) { julong max_stack_size = 0; ArgsRange errcode = parse_memory_size(tail, &max_stack_size, 1); @@ -3221,7 +3049,9 @@ jio_fprintf(defaultStream::error_stream(), "Please use -XX:MarkStackSizeMax in place of " "-XX:CMSMarkStackSizeMax in the future\n"); - FLAG_SET_CMDLINE(size_t, MarkStackSizeMax, max_stack_size); + if (FLAG_SET_CMDLINE(size_t, MarkStackSizeMax, max_stack_size) != Flag::SUCCESS) { + return JNI_EINVAL; + } } else if (match_option(option, "-XX:ParallelMarkingThreads=", &tail) || match_option(option, "-XX:ParallelCMSThreads=", &tail)) { uintx conc_threads = 0; @@ -3233,7 +3063,9 @@ jio_fprintf(defaultStream::error_stream(), "Please use -XX:ConcGCThreads in place of " "-XX:ParallelMarkingThreads or -XX:ParallelCMSThreads in the future\n"); - FLAG_SET_CMDLINE(uintx, ConcGCThreads, conc_threads); + if (FLAG_SET_CMDLINE(uintx, ConcGCThreads, conc_threads) != Flag::SUCCESS) { + return JNI_EINVAL; + } } else if (match_option(option, "-XX:MaxDirectMemorySize=", &tail)) { julong max_direct_memory_size = 0; ArgsRange errcode = parse_memory_size(tail, &max_direct_memory_size, 0); @@ -3244,7 +3076,9 @@ describe_range_error(errcode); return JNI_EINVAL; } - FLAG_SET_CMDLINE(size_t, MaxDirectMemorySize, max_direct_memory_size); + if (FLAG_SET_CMDLINE(size_t, MaxDirectMemorySize, max_direct_memory_size) != Flag::SUCCESS) { + return JNI_EINVAL; + } #if !INCLUDE_MANAGEMENT } else if (match_option(option, "-XX:+ManagementServer")) { jio_fprintf(defaultStream::error_stream(), @@ -3277,9 +3111,15 @@ // -Xshare:on // -XX:+TraceClassPaths if (PrintSharedArchiveAndExit) { - FLAG_SET_CMDLINE(bool, UseSharedSpaces, true); - FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true); - FLAG_SET_CMDLINE(bool, TraceClassPaths, true); + if (FLAG_SET_CMDLINE(bool, UseSharedSpaces, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } + if (FLAG_SET_CMDLINE(bool, TraceClassPaths, true) != Flag::SUCCESS) { + return JNI_EINVAL; + } } // Change the default value for flags which have different default values @@ -3686,6 +3526,10 @@ jint Arguments::parse(const JavaVMInitArgs* args) { + // Initialize ranges and constraints + CommandLineFlagRangeList::init(); + CommandLineFlagConstraintList::init(); + // Remaining part of option string const char* tail; @@ -4020,6 +3864,15 @@ return JNI_OK; } +// Any custom code post the final range and constraint check +// can be done here. We pass a flag that specifies whether +// the check passed successfully +void Arguments::post_final_range_and_constraint_check(bool check_passed) { + // This does not set the flag itself, but stores the value in a safe place for later usage. + _min_heap_free_ratio = MinHeapFreeRatio; + _max_heap_free_ratio = MaxHeapFreeRatio; +} + int Arguments::PropertyList_count(SystemProperty* pl) { int count = 0; while(pl != NULL) {