IDEA: allow to configure build daemon heap size

This commit is contained in:
Alexey Andreev 2018-07-31 16:31:09 +03:00
parent 67afe6173e
commit 7f46c301bd
5 changed files with 56 additions and 14 deletions

View File

@ -303,7 +303,7 @@ public class DiskCachedClassHolderSource implements ClassHolderSource {
output.writeInt(symbolTable.lookup(value.getEnumValue().getFieldName()));
break;
case AnnotationValue.FLOAT:
output.writeDouble(value.getFloat());
output.writeFloat(value.getFloat());
break;
case AnnotationValue.INT:
output.writeInt(value.getInt());

View File

@ -20,6 +20,7 @@ import org.jetbrains.jps.model.ex.JpsElementBase;
public class TeaVMJpsWorkspaceConfiguration extends JpsElementBase<TeaVMJpsWorkspaceConfiguration> {
private boolean daemonEnabled;
private int daemonMemory = 1024;
private boolean incremental;
public boolean isDaemonEnabled() {
@ -38,6 +39,14 @@ public class TeaVMJpsWorkspaceConfiguration extends JpsElementBase<TeaVMJpsWorks
this.incremental = incremental;
}
public int getDaemonMemory() {
return daemonMemory;
}
public void setDaemonMemory(int daemonMemory) {
this.daemonMemory = daemonMemory;
}
@NotNull
@Override
public TeaVMJpsWorkspaceConfiguration createCopy() {
@ -50,5 +59,6 @@ public class TeaVMJpsWorkspaceConfiguration extends JpsElementBase<TeaVMJpsWorks
public void applyChanges(@NotNull TeaVMJpsWorkspaceConfiguration configuration) {
daemonEnabled = configuration.daemonEnabled;
incremental = configuration.incremental;
daemonMemory = configuration.daemonMemory;
}
}

View File

@ -26,6 +26,7 @@ import org.teavm.idea.jps.model.TeaVMJpsWorkspaceConfiguration;
public class TeaVMDaemonComponent implements ApplicationComponent {
private TeaVMDaemonInfo daemonInfo;
private boolean incremental;
private int daemonMemory;
@Override
public void initComponent() {
@ -34,6 +35,7 @@ public class TeaVMDaemonComponent implements ApplicationComponent {
if (configurationStorage != null) {
TeaVMJpsWorkspaceConfiguration configuration = configurationStorage.getState();
incremental = configuration.isIncremental();
daemonMemory = configuration.getDaemonMemory();
if (configuration.isDaemonEnabled()) {
startDaemon();
}
@ -62,11 +64,11 @@ public class TeaVMDaemonComponent implements ApplicationComponent {
public void startDaemon() {
if (daemonInfo == null) {
try {
daemonInfo = TeaVMBuildDaemon.start(incremental);
daemonInfo = TeaVMBuildDaemon.start(incremental, daemonMemory);
} catch (IOException e) {
throw new RuntimeException(e);
}
updateConfiguration(true);
updateConfiguration(true, daemonMemory);
}
}
@ -74,7 +76,7 @@ public class TeaVMDaemonComponent implements ApplicationComponent {
if (daemonInfo != null) {
daemonInfo.getProcess().destroy();
daemonInfo = null;
updateConfiguration(false);
updateConfiguration(false, daemonMemory);
}
}
@ -86,17 +88,27 @@ public class TeaVMDaemonComponent implements ApplicationComponent {
this.incremental = incremental;
}
public int getDaemonMemory() {
return daemonMemory;
}
public void setDaemonMemory(int daemonMemory) {
this.daemonMemory = daemonMemory;
}
public void applyChanges() {
TeaVMWorkspaceConfigurationStorage configurationStorage = getConfigurationStorage();
TeaVMJpsWorkspaceConfiguration configuration = configurationStorage.getState();
configuration.setIncremental(incremental);
configuration.setDaemonMemory(daemonMemory);
configurationStorage.loadState(configuration);
}
private void updateConfiguration(boolean daemonEnabled) {
private void updateConfiguration(boolean daemonEnabled, int daemonMemory) {
TeaVMWorkspaceConfigurationStorage configurationStorage = getConfigurationStorage();
TeaVMJpsWorkspaceConfiguration configuration = configurationStorage.getState();
configuration.setDaemonEnabled(daemonEnabled);
configuration.setDaemonMemory(daemonMemory);
configurationStorage.loadState(configuration);
}

View File

@ -25,6 +25,7 @@ import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;
@ -282,19 +283,22 @@ public class TeaVMBuildDaemon extends UnicastRemoteObject implements TeaVMRemote
};
}
public static TeaVMDaemonInfo start(boolean incremental) throws IOException {
public static TeaVMDaemonInfo start(boolean incremental, int daemonMemory) throws IOException {
String javaHome = System.getProperty("java.home");
String javaCommand = javaHome + "/bin/java";
String classPath = detectClassPath().stream().collect(Collectors.joining(File.pathSeparator));
String classPath = String.join(File.pathSeparator, detectClassPath());
ProcessBuilder builder = new ProcessBuilder(javaCommand, "-cp", classPath,
"-D" + INCREMENTAL_PROPERTY + "=" + incremental,
"-Xmx" + daemonMemory + "m",
TeaVMBuildDaemon.class.getName());
Process process = builder.start();
Log log = LogFactory.getLog(TeaVMBuildDaemon.class);
BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
BufferedReader stderrReader = new BufferedReader(new InputStreamReader(process.getErrorStream(), "UTF-8"));
BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(process.getInputStream(),
StandardCharsets.UTF_8));
BufferedReader stderrReader = new BufferedReader(new InputStreamReader(process.getErrorStream(),
StandardCharsets.UTF_8));
String line = stdoutReader.readLine();
if (line == null || !line.startsWith(DAEMON_MESSAGE_PREFIX)) {
StringBuilder sb = new StringBuilder();

View File

@ -15,12 +15,14 @@
*/
package org.teavm.idea.ui;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SearchableConfigurable;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.text.DecimalFormat;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
@ -30,6 +32,7 @@ import org.teavm.idea.TeaVMDaemonComponent;
public class TeaVMSettingsEditorTab implements SearchableConfigurable {
private JPanel contentPane;
private JCheckBox daemonCheckBox;
private JFormattedTextField daemonMemoryField;
private JCheckBox incrementalCheckBox;
private TeaVMDaemonComponent daemonComponent;
@ -38,6 +41,8 @@ public class TeaVMSettingsEditorTab implements SearchableConfigurable {
contentPane = new JPanel();
daemonCheckBox = new JCheckBox("use build daemon (can increase performance in most cases)");
JLabel daemonMemoryLabel = new JLabel("Daemon memory size (in megabytes): ");
daemonMemoryField = new JFormattedTextField(new DecimalFormat("#"));
incrementalCheckBox = new JCheckBox("incremental build (only available with daemon)");
contentPane.setLayout(new GridBagLayout());
@ -45,13 +50,19 @@ public class TeaVMSettingsEditorTab implements SearchableConfigurable {
GridBagConstraints labelConstraints = new GridBagConstraints();
labelConstraints.gridwidth = GridBagConstraints.REMAINDER;
labelConstraints.anchor = GridBagConstraints.BASELINE_LEADING;
labelConstraints.anchor = GridBagConstraints.WEST;
labelConstraints.weightx = 1;
labelConstraints.weighty = 1;
labelConstraints.insets.left = 5;
labelConstraints.insets.right = 5;
GridBagConstraints fieldLabelConstraints = (GridBagConstraints) labelConstraints.clone();
fieldLabelConstraints.gridwidth = GridBagConstraints.RELATIVE;
fieldLabelConstraints.weightx = 0;
contentPane.add(daemonCheckBox, labelConstraints);
contentPane.add(daemonMemoryLabel, fieldLabelConstraints);
contentPane.add(daemonMemoryField, labelConstraints);
contentPane.add(incrementalCheckBox, labelConstraints);
GridBagConstraints constraints = new GridBagConstraints();
@ -88,17 +99,21 @@ public class TeaVMSettingsEditorTab implements SearchableConfigurable {
@Override
public boolean isModified() {
return daemonCheckBox.isSelected() != daemonComponent.isDaemonRunning()
|| incrementalCheckBox.isSelected() != daemonComponent.isIncremental();
|| incrementalCheckBox.isSelected() != daemonComponent.isIncremental()
|| ((Number) daemonMemoryField.getValue()).intValue() != daemonComponent.getDaemonMemory();
}
@Override
public void apply() throws ConfigurationException {
public void apply() {
boolean shouldRestartDaemon = true;
if (incrementalCheckBox.isSelected() && !daemonComponent.isIncremental()) {
int newDaemonMemory = ((Number) daemonMemoryField.getValue()).intValue();
if (incrementalCheckBox.isSelected() != daemonComponent.isIncremental()
|| newDaemonMemory != daemonComponent.getDaemonMemory()) {
shouldRestartDaemon = true;
}
daemonComponent.setIncremental(incrementalCheckBox.isSelected());
daemonComponent.setDaemonMemory(newDaemonMemory);
if (daemonCheckBox.isSelected()) {
if (!daemonComponent.isDaemonRunning()) {
@ -122,5 +137,6 @@ public class TeaVMSettingsEditorTab implements SearchableConfigurable {
public void reset() {
daemonCheckBox.setSelected(daemonComponent.isDaemonRunning());
incrementalCheckBox.setSelected(daemonComponent.isIncremental());
daemonMemoryField.setValue(daemonComponent.getDaemonMemory());
}
}