logic: fixed application crash on windows if JVM tries to allocate too much memory by reducing the amount of allocated memory to the available size.

This commit is contained in:
mlangkabel
2018-08-28 13:06:36 +02:00
parent 5f80d79540
commit 21d58357f2
4 changed files with 78 additions and 1 deletions
@@ -8,6 +8,7 @@
#include "settings/ApplicationSettings.h"
#include "utility/logging/logging.h"
#include "utility/utilityLibrary.h"
#include "utility/utilityWindows.h"
void JavaEnvironmentFactory::createInstance(std::string classPath, std::string& errorString)
{
@@ -41,7 +42,22 @@ void JavaEnvironmentFactory::createInstance(std::string classPath, std::string&
s_classPath = classPath;
const int jvmMaximumMemory = ApplicationSettings::getInstance()->getJavaMaximumMemory();
int jvmMaximumMemory = ApplicationSettings::getInstance()->getJavaMaximumMemory();
#ifdef WIN32
if (jvmMaximumMemory > 0)
{
const float underestimationFactor = 0.8f;
const int maximumMB = utility::getLargestByteSizeOfAllocatableMemory() / 1024 / 1024 * underestimationFactor;
if (jvmMaximumMemory > maximumMB)
{
LOG_WARNING("Selected amount of maximum JVM memory of " + std::to_string(jvmMaximumMemory) + " MB exceeds maximum allocatable "
"memory on system. Correcting selected value to " + std::to_string(maximumMB) + " MB.");
jvmMaximumMemory = maximumMB;
}
}
#endif // WIN32
const int optionCount = (jvmMaximumMemory < 0 ? 2 : 3);
const std::string maximumMemoryOprionString = "-Xmx" + std::to_string(jvmMaximumMemory) + "m";