Skip to content

Commit

Permalink
[Misc] Return suggested value when violate option constraints
Browse files Browse the repository at this point in the history
Summary: Return suggested option value when it violates the constraints.
Exit the VM after all input options are checked.
Test: JTreg
Reviewers: Kuaiwei, wenjie
Issue: dragonwell-project#894
  • Loading branch information
ziyilin committed Nov 26, 2024
1 parent c5b54c5 commit bda9bf3
Show file tree
Hide file tree
Showing 15 changed files with 883 additions and 164 deletions.
31 changes: 25 additions & 6 deletions src/hotspot/os/posix/os_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1516,10 +1516,17 @@ jint os::Posix::set_minimum_stack_sizes() {
// The '-Xss' and '-XX:ThreadStackSize=N' options both set
// ThreadStackSize so we go with "Java thread stack size" instead
// of "ThreadStackSize" to be more friendly.
tty->print_cr("\nThe Java thread stack size specified is too small. "
if (VerifyFlagConstraints) {
ThreadStackSize = _java_thread_min_stack_allowed / K;
stack_size_in_bytes = ThreadStackSize * K;
tty->print_cr("ThreadStackSize:"SIZE_FORMAT"\n", ThreadStackSize);
} else {
tty->print_cr("\nThe Java thread stack size specified is too small. "
"Specify at least " SIZE_FORMAT "k",
_java_thread_min_stack_allowed / K);
return JNI_ERR;
return JNI_ERR;
}

}

// Make the stack size a multiple of the page size so that
Expand All @@ -1537,10 +1544,16 @@ jint os::Posix::set_minimum_stack_sizes() {
stack_size_in_bytes = CompilerThreadStackSize * K;
if (stack_size_in_bytes != 0 &&
stack_size_in_bytes < _compiler_thread_min_stack_allowed) {
tty->print_cr("\nThe CompilerThreadStackSize specified is too small. "
if (VerifyFlagConstraints) {
CompilerThreadStackSize = _compiler_thread_min_stack_allowed / K;
stack_size_in_bytes = CompilerThreadStackSize * K;
tty->print_cr("CompilerThreadStackSize:"SIZE_FORMAT"\n", CompilerThreadStackSize);
} else {
tty->print_cr("\nThe CompilerThreadStackSize specified is too small. "
"Specify at least " SIZE_FORMAT "k",
_compiler_thread_min_stack_allowed / K);
return JNI_ERR;
return JNI_ERR;
}
}

_vm_internal_thread_min_stack_allowed = align_up(_vm_internal_thread_min_stack_allowed, vm_page_size());
Expand All @@ -1549,10 +1562,16 @@ jint os::Posix::set_minimum_stack_sizes() {
stack_size_in_bytes = VMThreadStackSize * K;
if (stack_size_in_bytes != 0 &&
stack_size_in_bytes < _vm_internal_thread_min_stack_allowed) {
tty->print_cr("\nThe VMThreadStackSize specified is too small. "
if (VerifyFlagConstraints) {
VMThreadStackSize = _vm_internal_thread_min_stack_allowed / K;
stack_size_in_bytes = VMThreadStackSize * K;
tty->print_cr("VMThreadStackSize:"SIZE_FORMAT"\n", VMThreadStackSize);
} else {
tty->print_cr("\nThe VMThreadStackSize specified is too small. "
"Specify at least " SIZE_FORMAT "k",
_vm_internal_thread_min_stack_allowed / K);
return JNI_ERR;
return JNI_ERR;
}
}
return JNI_OK;
}
Expand Down
65 changes: 48 additions & 17 deletions src/hotspot/share/compiler/compilerDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,31 +293,62 @@ bool CompilerConfig::check_args_consistency(bool status) {
// Template Interpreter code is approximately 3X larger in debug builds.
uint min_code_cache_size = CodeCacheMinimumUseSpace DEBUG_ONLY(* 3);
if (ReservedCodeCacheSize < InitialCodeCacheSize) {
jio_fprintf(defaultStream::error_stream(),
if (VerifyFlagConstraints) {
ReservedCodeCacheSize = InitialCodeCacheSize;
jio_fprintf(defaultStream::error_stream(), "ReservedCodeCacheSize:%d\n", ReservedCodeCacheSize);
status = true;
} else {
jio_fprintf(defaultStream::error_stream(),
"Invalid ReservedCodeCacheSize: %dK. Must be at least InitialCodeCacheSize=%dK.\n",
ReservedCodeCacheSize/K, InitialCodeCacheSize/K);
status = false;
status = false;
}
} else if (ReservedCodeCacheSize < min_code_cache_size) {
jio_fprintf(defaultStream::error_stream(),
if (VerifyFlagConstraints) {
ReservedCodeCacheSize = min_code_cache_size;
jio_fprintf(defaultStream::error_stream(), "ReservedCodeCacheSize:%d\n", ReservedCodeCacheSize);
status = true;
} else {
jio_fprintf(defaultStream::error_stream(),
"Invalid ReservedCodeCacheSize=%dK. Must be at least %uK.\n", ReservedCodeCacheSize/K,
min_code_cache_size/K);
status = false;
status = false;
}

} else if (ReservedCodeCacheSize > CODE_CACHE_SIZE_LIMIT) {
// Code cache size larger than CODE_CACHE_SIZE_LIMIT is not supported.
jio_fprintf(defaultStream::error_stream(),
"Invalid ReservedCodeCacheSize=%dM. Must be at most %uM.\n", ReservedCodeCacheSize/M,
CODE_CACHE_SIZE_LIMIT/M);
status = false;
if (VerifyFlagConstraints) {
ReservedCodeCacheSize = CODE_CACHE_SIZE_LIMIT;
jio_fprintf(defaultStream::error_stream(), "ReservedCodeCacheSize=%d\n", ReservedCodeCacheSize);
status = true;
} else {
// Code cache size larger than CODE_CACHE_SIZE_LIMIT is not supported.
jio_fprintf(defaultStream::error_stream(),
"Invalid ReservedCodeCacheSize=%dM. Must be at most %uM.\n", ReservedCodeCacheSize/M,
CODE_CACHE_SIZE_LIMIT/M);
status = false;
}
} else if (NonNMethodCodeHeapSize < min_code_cache_size) {
jio_fprintf(defaultStream::error_stream(),
"Invalid NonNMethodCodeHeapSize=%dK. Must be at least %uK.\n", NonNMethodCodeHeapSize/K,
min_code_cache_size/K);
status = false;
if (VerifyFlagConstraints) {
NonNMethodCodeHeapSize = min_code_cache_size;
jio_fprintf(defaultStream::error_stream(), "NonNMethodCodeHeapSize=%d\n", NonNMethodCodeHeapSize);
status = true;
} else {
jio_fprintf(defaultStream::error_stream(),
"Invalid NonNMethodCodeHeapSize=%dK. Must be at least %uK.\n", NonNMethodCodeHeapSize/K,
min_code_cache_size/K);
status = false;
}
} else if (InlineCacheBufferSize > NonNMethodCodeHeapSize / 2) {
jio_fprintf(defaultStream::error_stream(),
"Invalid InlineCacheBufferSize=" SIZE_FORMAT "K. Must be less than or equal to " SIZE_FORMAT "K.\n",
InlineCacheBufferSize/K, NonNMethodCodeHeapSize/2/K);
status = false;
if (VerifyFlagConstraints) {
InlineCacheBufferSize = NonNMethodCodeHeapSize / 2;
jio_fprintf(defaultStream::error_stream(), "InlineCacheBufferSize=%d\n", InlineCacheBufferSize);
status = true;
} else {
jio_fprintf(defaultStream::error_stream(),
"Invalid InlineCacheBufferSize=" SIZE_FORMAT "K. Must be less than or equal to " SIZE_FORMAT "K.\n",
InlineCacheBufferSize/K, NonNMethodCodeHeapSize/2/K);
status = false;
}
}

#ifdef _LP64
Expand Down
10 changes: 7 additions & 3 deletions src/hotspot/share/gc/cms/jvmFlagConstraintsCMS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
static JVMFlag::Error ParallelGCThreadsAndCMSWorkQueueDrainThreshold(uint threads, uintx threshold, bool verbose) {
// CMSWorkQueueDrainThreshold is verified to be less than max_juint
if (UseConcMarkSweepGC && (threads > (uint)(max_jint / (uint)threshold))) {
if (VerifyFlagConstraints) {
//JVMFlag::printError(true, "ParallelGCThreads:"UINT32_FORMAT"\n", )
return JVMFlag::SUCCESS;
}
JVMFlag::printError(verbose,
"ParallelGCThreads (" UINT32_FORMAT ") or CMSWorkQueueDrainThreshold ("
UINTX_FORMAT ") is too large\n",
Expand Down Expand Up @@ -109,7 +113,7 @@ JVMFlag::Error CMSOldPLABMinConstraintFunc(size_t value, bool verbose) {
value, CMSOldPLABMax);
return JVMFlag::VIOLATES_CONSTRAINT;
}
status = MaxPLABSizeBounds("CMSOldPLABMin", value, verbose);
status = MaxPLABSizeBounds("CMSOldPLABMin", &CMSOldPLABMin, value, verbose);
}
return status;
}
Expand All @@ -118,7 +122,7 @@ JVMFlag::Error CMSOldPLABMaxConstraintFunc(size_t value, bool verbose) {
JVMFlag::Error status = JVMFlag::SUCCESS;

if (UseConcMarkSweepGC) {
status = MaxPLABSizeBounds("CMSOldPLABMax", value, verbose);
status = MaxPLABSizeBounds("CMSOldPLABMax", &CMSOldPLABMax, value, verbose);
}
return status;
}
Expand Down Expand Up @@ -236,5 +240,5 @@ JVMFlag::Error OldPLABSizeConstraintFuncCMS(size_t value, bool verbose) {
// For CMS, OldPLABSize is the number of free blocks of a given size that are used when
// replenishing the local per-worker free list caches.
// For more details, please refer to Arguments::set_cms_and_parnew_gc_flags().
return MaxPLABSizeBounds("OldPLABSize", value, verbose);
return MaxPLABSizeBounds("OldPLABSize", &OldPLABSize, value, verbose);
}
44 changes: 32 additions & 12 deletions src/hotspot/share/gc/g1/g1ConcurrentMark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,14 @@ G1ConcurrentMark::G1ConcurrentMark(G1CollectedHeap* g1h,

assert(ConcGCThreads > 0, "ConcGCThreads have been set.");
if (ConcGCThreads > ParallelGCThreads) {
log_warning(gc)("More ConcGCThreads (%u) than ParallelGCThreads (%u).",
if (VerifyFlagConstraints) {
ConcGCThreads = ParallelGCThreads;
tty->print_cr("ConcGCThreads:%u\n", ConcGCThreads);
} else {
log_warning(gc)("More ConcGCThreads (%u) than ParallelGCThreads (%u).",
ConcGCThreads, ParallelGCThreads);
return;
return;
}
}

log_debug(gc)("ConcGCThreads: %u offset %u", ConcGCThreads, _worker_id_offset);
Expand All @@ -454,28 +459,43 @@ G1ConcurrentMark::G1ConcurrentMark(G1CollectedHeap* g1h,
// Verify that the calculated value for MarkStackSize is in range.
// It would be nice to use the private utility routine from Arguments.
if (!(mark_stack_size >= 1 && mark_stack_size <= MarkStackSizeMax)) {
log_warning(gc)("Invalid value calculated for MarkStackSize (" SIZE_FORMAT "): "
if (VerifyFlagConstraints) {
MarkStackSize = mark_stack_size < 1 ? 1 : MarkStackSizeMax;
tty->print_cr("MarkStackSize:"SIZE_FORMAT"\n", MarkStackSize);
} else {
log_warning(gc)("Invalid value calculated for MarkStackSize (" SIZE_FORMAT "): "
"must be between 1 and " SIZE_FORMAT,
mark_stack_size, MarkStackSizeMax);
return;
return;
}
}
FLAG_SET_ERGO(size_t, MarkStackSize, mark_stack_size);
} else {
// Verify MarkStackSize is in range.
if (FLAG_IS_CMDLINE(MarkStackSize)) {
if (FLAG_IS_DEFAULT(MarkStackSizeMax)) {
if (!(MarkStackSize >= 1 && MarkStackSize <= MarkStackSizeMax)) {
log_warning(gc)("Invalid value specified for MarkStackSize (" SIZE_FORMAT "): "
"must be between 1 and " SIZE_FORMAT,
MarkStackSize, MarkStackSizeMax);
return;
if (VerifyFlagConstraints) {
MarkStackSize = MarkStackSize < 1 ? 1 : MarkStackSizeMax;
tty->print_cr("MarkStackSize:"SIZE_FORMAT"\n", MarkStackSize);
} else {
log_warning(gc)("Invalid value specified for MarkStackSize (" SIZE_FORMAT "): "
"must be between 1 and " SIZE_FORMAT,
MarkStackSize, MarkStackSizeMax);
return;
}
}
} else if (FLAG_IS_CMDLINE(MarkStackSizeMax)) {
if (!(MarkStackSize >= 1 && MarkStackSize <= MarkStackSizeMax)) {
log_warning(gc)("Invalid value specified for MarkStackSize (" SIZE_FORMAT ")"
" or for MarkStackSizeMax (" SIZE_FORMAT ")",
MarkStackSize, MarkStackSizeMax);
return;
if (VerifyFlagConstraints) {
MarkStackSize = MarkStackSize < 1 ? 1 : MarkStackSizeMax;
tty->print_cr("MarkStackSize:"SIZE_FORMAT"\n", MarkStackSize);
} else {
log_warning(gc)("Invalid value specified for MarkStackSize (" SIZE_FORMAT ")"
" or for MarkStackSizeMax (" SIZE_FORMAT ")",
MarkStackSize, MarkStackSizeMax);
return;
}
}
}
}
Expand Down
Loading

0 comments on commit bda9bf3

Please sign in to comment.