fix int overwlow in max heap size calculations for external javac process (follow-up for IDEA-164402)

This commit is contained in:
Eugene Zhuravlev
2016-12-19 10:17:38 +01:00
parent 8e80816dd0
commit f83f867cbd
@@ -504,7 +504,10 @@ public class JavaBuilder extends ModuleLevelBuilder {
//final JpsJavaCompilerConfiguration config = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(project);
//final JpsJavaCompilerOptions options = config.getCurrentCompilerOptions();
//return options.MAXIMUM_HEAP_SIZE;
final int maxMbytes = (int)Runtime.getRuntime().maxMemory() / 1048576;
final int maxMbytes = (int)(Runtime.getRuntime().maxMemory() / 1048576L);
if (maxMbytes < 0) {
return -1; // in case of int overflow, return -1 to let VM choose the heap size
}
return Math.max(maxMbytes * 75 / 100, 256); // minimum 256 Mb, maximum 75% from JPS max heap size
}