< prev index next >
src/share/vm/runtime/arguments.cpp
Print this page
*** 642,655 ****
default:
return false;
}
}
! Arguments::ArgsRange Arguments::check_memory_size(julong size, julong min_size) {
if (size < min_size) return arg_too_small;
! // Check that size will fit in a size_t (only relevant on 32-bit)
! if (size > max_uintx) return arg_too_big;
return arg_in_range;
}
// Describe an argument out of range error
void Arguments::describe_range_error(ArgsRange errcode) {
--- 642,654 ----
default:
return false;
}
}
! Arguments::ArgsRange Arguments::check_memory_size(julong size, julong min_size, julong max_size) {
if (size < min_size) return arg_too_small;
! if (size > max_size) return arg_too_big;
return arg_in_range;
}
// Describe an argument out of range error
void Arguments::describe_range_error(ArgsRange errcode) {
*** 2615,2627 ****
return false;
}
Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
julong* long_arg,
! julong min_size) {
if (!atojulong(s, long_arg)) return arg_unreadable;
! return check_memory_size(*long_arg, min_size);
}
// Parse JavaVMInitArgs structure
jint Arguments::parse_vm_init_args(const JavaVMInitArgs *java_tool_options_args,
--- 2614,2627 ----
return false;
}
Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
julong* long_arg,
! julong min_size,
! julong max_size) {
if (!atojulong(s, long_arg)) return arg_unreadable;
! return check_memory_size(*long_arg, min_size, max_size);
}
// Parse JavaVMInitArgs structure
jint Arguments::parse_vm_init_args(const JavaVMInitArgs *java_tool_options_args,
*** 2748,2757 ****
--- 2748,2807 ----
}
}
return JNI_OK;
}
+ // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
+ jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
+ assert(is_size_aligned_((size_t)os::vm_page_size(), K), "Implementation assumption");
+
+ // The min and max sizes match the values in globals.hpp.
+ const julong min_size = 1000;
+ // Must limit the max_size to match multiplications
+ // and alignments in the os_<os>.cpp files, so that
+ // the calculation stored in a size_t (same size as uintx)
+ // doesn't overflow.
+ // Must also make sure that when *value is max_size it
+ // doesn't overflow intx in the calculation further down
+ // in this function.
+ const julong max_ThreadStackSize = align_size_down_((julong)max_uintx, (size_t)os::vm_page_size()) / K;
+ const julong max_size = max_ThreadStackSize * K;
+
+ julong size = 0;
+ ArgsRange errcode = parse_memory_size(tail, &size, min_size, max_size);
+ if (errcode != arg_in_range) {
+ bool silent = option == NULL; // Allow testing to silence error messages
+ if (!silent) {
+ jio_fprintf(defaultStream::error_stream(),
+ "Invalid thread stack size: %s\n", option->optionString);
+ describe_range_error(errcode);
+ }
+ return JNI_EINVAL;
+ }
+
+ // Internally track ThreadStackSize in units of 1024 bytes.
+ const julong size_aligned = align_size_up_(size, K);
+ assert(size <= size_aligned,
+ "Overflow: " JULONG_FORMAT " " JULONG_FORMAT,
+ size, size_aligned);
+
+ const julong size_in_K = size_aligned / K;
+ assert(size_in_K < (julong)max_intx,
+ "size_in_K doesn't fit in the type of ThreadStackSize: " JULONG_FORMAT,
+ size_in_K);
+
+ // Check that code expanding ThreadStackSize to a page aligned number of bytes won't overflow.
+ const julong max_expanded = align_size_up_(size_in_K * K, (size_t)os::vm_page_size());
+ assert(max_expanded < max_uintx && max_expanded > size_in_K,
+ "Expansion overflowed: " JULONG_FORMAT " " JULONG_FORMAT,
+ max_expanded, size_in_K);
+
+ *out_ThreadStackSize = (intx)size_in_K;
+
+ return JNI_OK;
+ }
+
jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_mod_javabase, Flag::Flags origin) {
// For match_option to return remaining or value part of option string
const char* tail;
// iterate over arguments
*** 3011,3031 ****
return JNI_EINVAL;
}
}
// -Xss
} else if (match_option(option, "-Xss", &tail)) {
! julong long_ThreadStackSize = 0;
! ArgsRange errcode = parse_memory_size(tail, &long_ThreadStackSize, 1000);
! if (errcode != arg_in_range) {
! jio_fprintf(defaultStream::error_stream(),
! "Invalid thread stack size: %s\n", option->optionString);
! describe_range_error(errcode);
! return JNI_EINVAL;
}
! // Internally track ThreadStackSize in units of 1024 bytes.
! if (FLAG_SET_CMDLINE(intx, ThreadStackSize,
! round_to((int)long_ThreadStackSize, K) / K) != Flag::SUCCESS) {
return JNI_EINVAL;
}
// -Xoss, -Xsqnopause, -Xoptimize, -Xboundthreads, -Xusealtsigs
} else if (match_option(option, "-Xoss", &tail) ||
match_option(option, "-Xsqnopause") ||
--- 3061,3076 ----
return JNI_EINVAL;
}
}
// -Xss
} else if (match_option(option, "-Xss", &tail)) {
! intx value = 0;
! jint err = parse_xss(option, tail, &value);
! if (err != JNI_OK) {
! return err;
}
! if (FLAG_SET_CMDLINE(intx, ThreadStackSize, value) != Flag::SUCCESS) {
return JNI_EINVAL;
}
// -Xoss, -Xsqnopause, -Xoptimize, -Xboundthreads, -Xusealtsigs
} else if (match_option(option, "-Xoss", &tail) ||
match_option(option, "-Xsqnopause") ||
< prev index next >