mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-04 17:20:55 +07:00
[platform] recognizing additional VM options in launchers (IDEA-240526 part 2a: sources)
Making launchers concatenate platform's and user's VM options, filtering out `-XX:.*GC` from the former if present in the latter (otherwise JVM refuses to start). GitOrigin-RevId: fd610803054190001b14c39800208ee90d88522a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f80a84debb
commit
cbaf53602e
@@ -324,56 +324,62 @@ NSString *getDefaultFilePath(NSString *fileName) {
|
|||||||
|
|
||||||
NSArray *parseVMOptions() {
|
NSArray *parseVMOptions() {
|
||||||
NSString *vmOptionsFile = nil;
|
NSString *vmOptionsFile = nil;
|
||||||
NSMutableArray *vmOptions = nil;
|
NSMutableArray *vmOptions = nil, *userVmOptions = nil;
|
||||||
|
|
||||||
// 1. $<IDE_NAME>_VM_OPTIONS
|
|
||||||
NSString *variable = [[getExecutable() uppercaseString] stringByAppendingString:@"_VM_OPTIONS"];
|
NSString *variable = [[getExecutable() uppercaseString] stringByAppendingString:@"_VM_OPTIONS"];
|
||||||
NSString *value = [[[NSProcessInfo processInfo] environment] objectForKey:variable];
|
NSString *candidate = [[[NSProcessInfo processInfo] environment] objectForKey:variable];
|
||||||
if (value != nil) {
|
NSLog(@"parseVMOptions: %@ = %@", variable, candidate);
|
||||||
vmOptions = [VMOptionsReader readFile:value];
|
if (candidate != nil) {
|
||||||
if (vmOptions != nil) {
|
// 1. $<IDE_NAME>_VM_OPTIONS
|
||||||
vmOptionsFile = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. <IDE_HOME>.vmoptions || <IDE_HOME>/bin/<bin_name>.vmoptions + <IDE_HOME>.vmoptions (Toolbox)
|
|
||||||
if (vmOptionsFile == nil) {
|
|
||||||
NSString *candidate = [NSString stringWithFormat:@"%@.vmoptions", [[NSBundle mainBundle] bundlePath]];
|
|
||||||
vmOptions = [VMOptionsReader readFile:candidate];
|
vmOptions = [VMOptionsReader readFile:candidate];
|
||||||
if (vmOptions != nil) {
|
if (vmOptions != nil) {
|
||||||
vmOptionsFile = candidate;
|
vmOptionsFile = candidate;
|
||||||
if (![vmOptions containsObject:@"-ea"]) {
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// 2. <IDE_HOME>/bin/<bin_name>.vmoptions ...
|
||||||
candidate = getDefaultFilePath([NSString stringWithFormat:@"/bin/%@.vmoptions", getExecutable()]);
|
candidate = getDefaultFilePath([NSString stringWithFormat:@"/bin/%@.vmoptions", getExecutable()]);
|
||||||
NSMutableArray *mainOptions = [VMOptionsReader readFile:candidate];
|
NSLog(@"parseVMOptions: %@", candidate);
|
||||||
if (mainOptions != nil) {
|
|
||||||
[mainOptions addObjectsFromArray:vmOptions];
|
|
||||||
vmOptions = mainOptions;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. <config_directory>/<bin_name>.vmoptions
|
|
||||||
if (vmOptionsFile == nil) {
|
|
||||||
NSString *candidate = [NSString stringWithFormat:@"%@/%@.vmoptions", getPreferencesFolderPath(), getExecutable()];
|
|
||||||
vmOptions = [VMOptionsReader readFile:candidate];
|
vmOptions = [VMOptionsReader readFile:candidate];
|
||||||
if (vmOptions != nil) {
|
if (vmOptions != nil) {
|
||||||
vmOptionsFile = candidate;
|
vmOptionsFile = candidate;
|
||||||
}
|
}
|
||||||
}
|
// ... [+ <IDE_HOME>.vmoptions (Toolbox) || <config_directory>/<bin_name>.vmoptions]
|
||||||
|
candidate = [NSString stringWithFormat:@"%@.vmoptions", [[NSBundle mainBundle] bundlePath]];
|
||||||
// 4. <IDE_HOME>/bin/<bin_name>.vmoptions [+ <config_directory>/user.vmoptions]
|
NSLog(@"parseVMOptions: %@", candidate);
|
||||||
if (vmOptionsFile == nil) {
|
userVmOptions = [VMOptionsReader readFile:candidate];
|
||||||
NSString *candidate = getDefaultFilePath([NSString stringWithFormat:@"/bin/%@.vmoptions", getExecutable()]);
|
|
||||||
vmOptions = [VMOptionsReader readFile:candidate];
|
|
||||||
if (vmOptions != nil) {
|
|
||||||
vmOptionsFile = candidate;
|
|
||||||
}
|
|
||||||
candidate = [NSString stringWithFormat:@"%@/user.vmoptions", getPreferencesFolderPath()];
|
|
||||||
NSMutableArray *userVmOptions = [VMOptionsReader readFile:candidate];
|
|
||||||
if (userVmOptions != nil) {
|
if (userVmOptions != nil) {
|
||||||
[vmOptions addObjectsFromArray:userVmOptions];
|
|
||||||
vmOptionsFile = candidate;
|
vmOptionsFile = candidate;
|
||||||
|
} else {
|
||||||
|
candidate = [NSString stringWithFormat:@"%@/%@.vmoptions", getPreferencesFolderPath(), getExecutable()];
|
||||||
|
NSLog(@"parseVMOptions: %@", candidate);
|
||||||
|
userVmOptions = [VMOptionsReader readFile:candidate];
|
||||||
|
if (userVmOptions != nil) {
|
||||||
|
vmOptionsFile = candidate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NSLog(@"parseVMOptions: platform=%d user=%d file=%@",
|
||||||
|
vmOptions == nil ? -1 : (int)[vmOptions count], userVmOptions == nil ? -1 : (int)[userVmOptions count], vmOptionsFile);
|
||||||
|
|
||||||
|
if (userVmOptions != nil) {
|
||||||
|
if (vmOptions == nil) {
|
||||||
|
vmOptions = userVmOptions;
|
||||||
|
} else {
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||||
|
BOOL (^GC_lookup)(NSString *, NSUInteger, BOOL *) = ^BOOL(NSString *s, NSUInteger i, BOOL *stop) {
|
||||||
|
return [s hasPrefix:@"-XX:+Use"] == YES && [s hasSuffix:@"GC"] == YES ? YES : NO;
|
||||||
|
};
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
if ([userVmOptions indexOfObjectPassingTest:GC_lookup] != NSNotFound) {
|
||||||
|
NSUInteger gc = [vmOptions indexOfObjectPassingTest:GC_lookup];
|
||||||
|
if (gc != NSNotFound) {
|
||||||
|
[vmOptions removeObjectAtIndex:gc];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[vmOptions addObjectsFromArray:userVmOptions];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -475,7 +476,7 @@ void (JNICALL jniExitHook)(jint code) {
|
|||||||
|
|
||||||
bool LoadVMOptions() {
|
bool LoadVMOptions() {
|
||||||
char bin_vmoptions[_MAX_PATH], buffer1[_MAX_PATH], buffer2[_MAX_PATH], *vmOptionsFile = NULL;
|
char bin_vmoptions[_MAX_PATH], buffer1[_MAX_PATH], buffer2[_MAX_PATH], *vmOptionsFile = NULL;
|
||||||
std::vector<std::string> lines;
|
std::vector<std::string> lines, user_lines;
|
||||||
|
|
||||||
GetModuleFileNameA(NULL, bin_vmoptions, _MAX_PATH);
|
GetModuleFileNameA(NULL, bin_vmoptions, _MAX_PATH);
|
||||||
strcat_s(bin_vmoptions, ".vmoptions");
|
strcat_s(bin_vmoptions, ".vmoptions");
|
||||||
@@ -485,44 +486,39 @@ bool LoadVMOptions() {
|
|||||||
if (GetEnvironmentVariableA(buffer1, buffer2, _MAX_PATH) != 0 && LoadVMOptionsFile(buffer2, lines)) {
|
if (GetEnvironmentVariableA(buffer1, buffer2, _MAX_PATH) != 0 && LoadVMOptionsFile(buffer2, lines)) {
|
||||||
vmOptionsFile = buffer2;
|
vmOptionsFile = buffer2;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
// 2. <IDE_HOME>.vmoptions (Toolbox) [+ <IDE_HOME>\bin\<exe_name>.vmoptions]
|
// 2. <IDE_HOME>\bin\<exe_name>.vmoptions ...
|
||||||
if (vmOptionsFile == NULL) {
|
if (LoadVMOptionsFile(bin_vmoptions, lines)) {
|
||||||
|
vmOptionsFile = bin_vmoptions;
|
||||||
|
}
|
||||||
|
// ... [+ <IDE_HOME>.vmoptions (Toolbox) || <config_directory>\<exe_name>.vmoptions]
|
||||||
strcpy_s(buffer1, _MAX_PATH, bin_vmoptions);
|
strcpy_s(buffer1, _MAX_PATH, bin_vmoptions);
|
||||||
char *ideHomeEnd = strrchr(buffer1, '\\') - 4; // "bin\"
|
char *ideHomeEnd = strrchr(buffer1, '\\') - 4; // "bin\"
|
||||||
strcpy_s(ideHomeEnd, _MAX_PATH - (ideHomeEnd - buffer1), ".vmoptions");
|
strcpy_s(ideHomeEnd, _MAX_PATH - (ideHomeEnd - buffer1), ".vmoptions");
|
||||||
if (LoadVMOptionsFile(buffer1, lines)) {
|
if (LoadVMOptionsFile(buffer1, user_lines)) {
|
||||||
vmOptionsFile = buffer1;
|
vmOptionsFile = buffer1;
|
||||||
if (std::find(lines.begin(), lines.end(), std::string("-ea")) == lines.end()) {
|
|
||||||
std::vector<std::string> lines2;
|
|
||||||
if (LoadVMOptionsFile(bin_vmoptions, lines2)) {
|
|
||||||
lines.insert(lines.begin(), lines2.begin(), lines2.end());
|
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. <config_directory>\<exe_name>.vmoptions
|
|
||||||
if (vmOptionsFile == NULL) {
|
|
||||||
LoadStringA(hInst, IDS_VM_OPTIONS_PATH, buffer1, _MAX_PATH);
|
LoadStringA(hInst, IDS_VM_OPTIONS_PATH, buffer1, _MAX_PATH);
|
||||||
ExpandEnvironmentStringsA(buffer1, buffer2, _MAX_PATH);
|
ExpandEnvironmentStringsA(buffer1, buffer2, _MAX_PATH);
|
||||||
char *exeParentEnd = strrchr(bin_vmoptions, '\\');
|
char *exeParentEnd = strrchr(bin_vmoptions, '\\');
|
||||||
strcat_s(buffer2, exeParentEnd);
|
strcat_s(buffer2, exeParentEnd);
|
||||||
if (LoadVMOptionsFile(buffer2, lines)) {
|
if (LoadVMOptionsFile(buffer2, user_lines)) {
|
||||||
vmOptionsFile = buffer2;
|
vmOptionsFile = buffer2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 4. <IDE_HOME>\bin\<exe_name>.vmoptions [+ <config_directory>\user.vmoptions]
|
if (!user_lines.empty()) {
|
||||||
if (vmOptionsFile == NULL) {
|
if (!lines.empty()) {
|
||||||
if (LoadVMOptionsFile(bin_vmoptions, lines)) {
|
bool (*GC_lookup)(std::string &) = [](std::string &s){
|
||||||
vmOptionsFile = bin_vmoptions;
|
return strncmp(s.c_str(), "-XX:+Use", 8) == 0 && strcmp(s.c_str() + s.length() - 2, "GC") == 0;
|
||||||
|
};
|
||||||
|
if (std::find_if(user_lines.begin(), user_lines.end(), GC_lookup) != user_lines.end()) {
|
||||||
|
lines.erase(std::remove_if(lines.begin(), lines.end(), GC_lookup), lines.end());
|
||||||
}
|
}
|
||||||
char *p = strrchr(buffer2, '\\');
|
|
||||||
strcpy_s(p, _MAX_PATH - (p - buffer2), "\\user.vmoptions");
|
|
||||||
if (LoadVMOptionsFile(buffer2, lines)) {
|
|
||||||
vmOptionsFile = buffer2;
|
|
||||||
}
|
}
|
||||||
|
lines.insert(lines.end(), user_lines.begin(), user_lines.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vmOptionsFile != NULL) {
|
if (vmOptionsFile != NULL) {
|
||||||
|
|||||||
Reference in New Issue
Block a user