ui: maximum allocated jvm memory configurable in preferences

* added setting for maximum memory allocated by JVM to Preferences window.
* a value of -1 ignores this setting
* changed default value for this setting to -1
* increased JNI version to Java 1.8

* disabled some file system tests for windows
This commit is contained in:
malte_langkabel
2016-09-29 10:05:03 +02:00
parent 52fb2ae6f6
commit e5cd905670
5 changed files with 39 additions and 7 deletions
+1 -1
View File
@@ -197,7 +197,7 @@ void ApplicationSettings::setJavaPath(const std::string path)
int ApplicationSettings::getJavaMaximumMemory() const int ApplicationSettings::getJavaMaximumMemory() const
{ {
return getValue<int>("indexing/java/java_maximum_memory", 512); return getValue<int>("indexing/java/java_maximum_memory", -1);
} }
void ApplicationSettings::setJavaMaximumMemory(int size) void ApplicationSettings::setJavaMaximumMemory(int size)
@@ -144,6 +144,7 @@ void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row)
, layout, row , layout, row
); );
layout->setRowMinimumHeight(row, 30);
row++; row++;
layout->setRowMinimumHeight(row++, 20); layout->setRowMinimumHeight(row++, 20);
@@ -231,8 +232,23 @@ void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row)
} }
addJavaPathDetection(layout, row); addJavaPathDetection(layout, row);
layout->setRowMinimumHeight(row++, 20); layout->setRowMinimumHeight(row, 20);
row++;
// jvm max memory
m_jvmMaximumMemory = new QLineEdit();
m_jvmMaximumMemory->setObjectName("name");
m_jvmMaximumMemory->setAttribute(Qt::WA_MacShowFocusRect, 0);
layout->addWidget(createFormLabel("JVM Maximum Memory"), row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight);
layout->addWidget(m_jvmMaximumMemory, row, QtProjectWizzardWindow::BACK_COL);
addHelpButton(
"Specify the maximum amount of memory that should be allocated by the indexer's JVM. A value of -1 ignores this setting."
, layout, row
);
layout->setRowMinimumHeight(row, 30);
row++;
// C/C++ // C/C++
layout->addWidget(createFormTitle("C/C++"), row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignLeft); layout->addWidget(createFormTitle("C/C++"), row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignLeft);
@@ -272,6 +288,8 @@ void QtProjectWizzardContentPreferences::load()
{ {
m_javaPath->setText(QString::fromStdString(appSettings->getJavaPath())); m_javaPath->setText(QString::fromStdString(appSettings->getJavaPath()));
} }
m_jvmMaximumMemory->setText(QString::number(appSettings->getJavaMaximumMemory()));
} }
void QtProjectWizzardContentPreferences::save() void QtProjectWizzardContentPreferences::save()
@@ -304,6 +322,9 @@ void QtProjectWizzardContentPreferences::save()
{ {
appSettings->setJavaPath(m_javaPath->getText().toStdString()); appSettings->setJavaPath(m_javaPath->getText().toStdString());
} }
int jvmMaximumMemory = m_jvmMaximumMemory->text().toInt();
if (jvmMaximumMemory) appSettings->setJavaMaximumMemory(jvmMaximumMemory);
} }
bool QtProjectWizzardContentPreferences::check() bool QtProjectWizzardContentPreferences::check()
@@ -53,6 +53,7 @@ private:
std::shared_ptr<CombinedPathDetector> m_javaPathDetector; std::shared_ptr<CombinedPathDetector> m_javaPathDetector;
QComboBox* m_javaPathDetectorBox; QComboBox* m_javaPathDetectorBox;
QtLocationPicker* m_javaPath; QtLocationPicker* m_javaPath;
QLineEdit* m_jvmMaximumMemory;
}; };
#endif // QT_PROJECT_WIZZARD_CONTENT_PREFERENCES_H #endif // QT_PROJECT_WIZZARD_CONTENT_PREFERENCES_H
@@ -42,18 +42,24 @@ void JavaEnvironmentFactory::createInstance(std::string classPath, std::string&
s_classPath = classPath; s_classPath = classPath;
const int jvmMaximumMemory = ApplicationSettings::getInstance()->getJavaMaximumMemory();
const int optionCount = (jvmMaximumMemory < 0 ? 2 : 3);
const std::string maximumMemoryOprionString = "-Xmx" + std::to_string(jvmMaximumMemory) + "m";
JavaVM* jvm = nullptr; // Pointer to the JVM (Java Virtual Machine) JavaVM* jvm = nullptr; // Pointer to the JVM (Java Virtual Machine)
JNIEnv* env = nullptr; // Pointer to native interface JNIEnv* env = nullptr; // Pointer to native interface
JavaVMInitArgs vm_args; // Initialization arguments JavaVMInitArgs vm_args; // Initialization arguments
JavaVMOption* options = new JavaVMOption[3]; // JVM invocation options JavaVMOption* options = new JavaVMOption[optionCount]; // JVM invocation options
std::string classPathOption = "-Djava.class.path=" + classPath; std::string classPathOption = "-Djava.class.path=" + classPath;
options[0].optionString = const_cast<char*>(classPathOption.c_str()); options[0].optionString = const_cast<char*>(classPathOption.c_str());
options[1].optionString = const_cast<char*>("-Xms64m"); options[1].optionString = const_cast<char*>("-Xms64m");
std::string maximumMemoryOprionString = "-Xmx" + std::to_string(ApplicationSettings::getInstance()->getJavaMaximumMemory()) + "m"; if (optionCount == 3)
options[2].optionString = const_cast<char*>(maximumMemoryOprionString.c_str()); {
vm_args.version = JNI_VERSION_1_6; options[2].optionString = const_cast<char*>(maximumMemoryOprionString.c_str());
vm_args.nOptions = 3; }
vm_args.version = JNI_VERSION_1_8;
vm_args.nOptions = optionCount;
vm_args.options = options; vm_args.options = options;
vm_args.ignoreUnrecognized = false; // invalid options make the JVM init fail vm_args.ignoreUnrecognized = false; // invalid options make the JVM init fail
+4
View File
@@ -54,6 +54,7 @@ public:
void test_find_file_infos() void test_find_file_infos()
{ {
#ifndef _WIN32
std::vector<std::string> extensions; std::vector<std::string> extensions;
extensions.push_back(".h"); extensions.push_back(".h");
extensions.push_back(".hpp"); extensions.push_back(".hpp");
@@ -67,10 +68,12 @@ public:
TS_ASSERT_EQUALS(files.size(), 2); TS_ASSERT_EQUALS(files.size(), 2);
TS_ASSERT(isInFileInfos(files, "./data/FileSystemTestSuite/src/test.cpp")); TS_ASSERT(isInFileInfos(files, "./data/FileSystemTestSuite/src/test.cpp"));
TS_ASSERT(isInFileInfos(files, "./data/FileSystemTestSuite/src/test.h")); TS_ASSERT(isInFileInfos(files, "./data/FileSystemTestSuite/src/test.h"));
#endif
} }
void test_find_file_infos_with_symlinks() void test_find_file_infos_with_symlinks()
{ {
#ifndef _WIN32
std::vector<std::string> extensions; std::vector<std::string> extensions;
extensions.push_back(".h"); extensions.push_back(".h");
extensions.push_back(".hpp"); extensions.push_back(".hpp");
@@ -87,6 +90,7 @@ public:
TS_ASSERT(isInFileInfos(files, "./data/FileSystemTestSuite/src/main.cpp")); TS_ASSERT(isInFileInfos(files, "./data/FileSystemTestSuite/src/main.cpp"));
TS_ASSERT(isInFileInfos(files, "./data/FileSystemTestSuite/src/Settings/src/test.cpp")); TS_ASSERT(isInFileInfos(files, "./data/FileSystemTestSuite/src/Settings/src/test.cpp"));
TS_ASSERT(isInFileInfos(files, "./data/FileSystemTestSuite/src/Settings/src/test.h")); TS_ASSERT(isInFileInfos(files, "./data/FileSystemTestSuite/src/Settings/src/test.h"));
#endif
} }
void test_filesystem_finds_existing_files() void test_filesystem_finds_existing_files()