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())); output.writeInt(symbolTable.lookup(value.getEnumValue().getFieldName()));
break; break;
case AnnotationValue.FLOAT: case AnnotationValue.FLOAT:
output.writeDouble(value.getFloat()); output.writeFloat(value.getFloat());
break; break;
case AnnotationValue.INT: case AnnotationValue.INT:
output.writeInt(value.getInt()); output.writeInt(value.getInt());

View File

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

View File

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

View File

@ -25,6 +25,7 @@ import java.io.InputStreamReader;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.rmi.AlreadyBoundException; import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException; 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 javaHome = System.getProperty("java.home");
String javaCommand = javaHome + "/bin/java"; 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, ProcessBuilder builder = new ProcessBuilder(javaCommand, "-cp", classPath,
"-D" + INCREMENTAL_PROPERTY + "=" + incremental, "-D" + INCREMENTAL_PROPERTY + "=" + incremental,
"-Xmx" + daemonMemory + "m",
TeaVMBuildDaemon.class.getName()); TeaVMBuildDaemon.class.getName());
Process process = builder.start(); Process process = builder.start();
Log log = LogFactory.getLog(TeaVMBuildDaemon.class); Log log = LogFactory.getLog(TeaVMBuildDaemon.class);
BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8")); BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(process.getInputStream(),
BufferedReader stderrReader = new BufferedReader(new InputStreamReader(process.getErrorStream(), "UTF-8")); StandardCharsets.UTF_8));
BufferedReader stderrReader = new BufferedReader(new InputStreamReader(process.getErrorStream(),
StandardCharsets.UTF_8));
String line = stdoutReader.readLine(); String line = stdoutReader.readLine();
if (line == null || !line.startsWith(DAEMON_MESSAGE_PREFIX)) { if (line == null || !line.startsWith(DAEMON_MESSAGE_PREFIX)) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();

View File

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