diff --git a/src/hotspot/os/windows/os_windows.cpp b/src/hotspot/os/windows/os_windows.cpp index f5067757125..ffa22bd0365 100644 --- a/src/hotspot/os/windows/os_windows.cpp +++ b/src/hotspot/os/windows/os_windows.cpp @@ -3297,13 +3297,28 @@ static char* map_or_reserve_memory_aligned(size_t size, size_t alignment, int fi } size_t os::commit_memory_limit() { - JOBOBJECT_EXTENDED_LIMIT_INFORMATION jeli = {}; - BOOL res = QueryInformationJobObject(nullptr, JobObjectExtendedLimitInformation, &jeli, sizeof(jeli), nullptr); - + BOOL is_in_job_object = false; + BOOL res = IsProcessInJob(GetCurrentProcess(), nullptr, &is_in_job_object); if (!res) { char buf[512]; size_t buf_len = os::lasterror(buf, sizeof(buf)); - warning("Attempt to query job object information failed: %s", buf_len != 0 ? buf : ""); + warning("Attempt to determine whether the process is running in a job failed for commit limit: %s", buf_len != 0 ? buf : ""); + + // Conservatively assume no limit when there was an error calling IsProcessInJob. + return SIZE_MAX; + } + + if (!is_in_job_object) { + // Not limited by a Job Object + return SIZE_MAX; + } + + JOBOBJECT_EXTENDED_LIMIT_INFORMATION jeli = {}; + res = QueryInformationJobObject(nullptr, JobObjectExtendedLimitInformation, &jeli, sizeof(jeli), nullptr); + if (!res) { + char buf[512]; + size_t buf_len = os::lasterror(buf, sizeof(buf)); + warning("Attempt to query job object information failed for commit limit: %s", buf_len != 0 ? buf : ""); // Conservatively assume no limit when there was an error calling QueryInformationJobObject. return SIZE_MAX;