Skip to content

Commit

Permalink
Merge pull request #377 from Ledmington/ledmington/compilation-flags
Browse files Browse the repository at this point in the history
Add compilation flags in sandbox
  • Loading branch information
chriswhocodes committed Oct 28, 2023
2 parents afd1dc9 + 5b87fb7 commit 9071f53
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public enum OnStackReplacement
private static final String KEY_SANDBOX_PRINT_ASSEMBLY = SANDBOX_PREFIX + ".print.assembly";
private static final String KEY_SANDBOX_DISABLE_INLINING = SANDBOX_PREFIX + ".disable.inlining";
private static final String KEY_SANDBOX_COMPILER_THRESHOLD = SANDBOX_PREFIX + ".compiler.threshold";
private static final String KEY_SANDBOX_EXTRA_VM_SWITCHES = SANDBOX_PREFIX + ".extra.vm.switches";
private static final String KEY_SANDBOX_EXTRA_VM_COMPILATION_SWITCHES = SANDBOX_PREFIX + ".extra.vm.switches.compilation";
private static final String KEY_SANDBOX_EXTRA_VM_RUNTIME_SWITCHES = SANDBOX_PREFIX + ".extra.vm.switches.runtime";
private static final String KEY_SANDBOX_BACKGROUND_COMPILATION = SANDBOX_PREFIX + ".background.compilation";
private static final String KEY_SANDBOX_ON_STACK_REPLACEMENT = SANDBOX_PREFIX + ".on.stack.replacement";

Expand Down Expand Up @@ -112,7 +113,8 @@ public enum OnStackReplacement
private boolean disableInlining = false;

private int compileThreshold;
private String extraVMSwitches;
private String extraVMCompilationSwitches;
private String extraVMRuntimeSwitches;

private String profileName = S_PROFILE_DEFAULT;

Expand Down Expand Up @@ -354,7 +356,8 @@ public void unmarshalPropertiesToConfig()
compileThreshold = loadIntFromProperty(loadedProps, KEY_SANDBOX_COMPILER_THRESHOLD,
JITWatchConstants.DEFAULT_COMPILER_THRESHOLD);

extraVMSwitches = getProperty(loadedProps, KEY_SANDBOX_EXTRA_VM_SWITCHES, JITWatchConstants.S_EMPTY);
extraVMCompilationSwitches = getProperty(loadedProps, KEY_SANDBOX_EXTRA_VM_COMPILATION_SWITCHES, JITWatchConstants.S_EMPTY);
extraVMRuntimeSwitches = getProperty(loadedProps, KEY_SANDBOX_EXTRA_VM_RUNTIME_SWITCHES, JITWatchConstants.S_EMPTY);

noPromptHsdis = loadBooleanFromProperty(loadedProps, KEY_NO_PROMPT_HSDIS, false);
}
Expand Down Expand Up @@ -617,7 +620,9 @@ public void marshalConfigToProperties()

putProperty(loadedProps, KEY_SANDBOX_COMPILER_THRESHOLD, Integer.toString(compileThreshold));

putProperty(loadedProps, KEY_SANDBOX_EXTRA_VM_SWITCHES, extraVMSwitches);
putProperty(loadedProps, KEY_SANDBOX_EXTRA_VM_COMPILATION_SWITCHES, extraVMCompilationSwitches);

putProperty(loadedProps, KEY_SANDBOX_EXTRA_VM_RUNTIME_SWITCHES, extraVMRuntimeSwitches);

putProperty(loadedProps, KEY_NO_PROMPT_HSDIS, Boolean.toString(noPromptHsdis));
}
Expand Down Expand Up @@ -823,14 +828,24 @@ public void setCompileThreshold(int compileThreshold)
this.compileThreshold = compileThreshold;
}

public String getExtraVMSwitches()
public String getExtraVMCompilationSwitches()
{
return extraVMCompilationSwitches;
}

public void setExtraVMCompilationSwitches(String extraVMCompilationSwitches)
{
this.extraVMCompilationSwitches = extraVMCompilationSwitches;
}

public String getExtraVMRuntimeSwitches()
{
return extraVMSwitches;
return extraVMRuntimeSwitches;
}

public void setExtraVMSwitches(String extraVMSwitches)
public void setExtraVMRuntimeSwitches(String extraVMRuntimeSwitches)
{
this.extraVMSwitches = extraVMSwitches;
this.extraVMRuntimeSwitches = extraVMRuntimeSwitches;
}

public CompressedOops getCompressedOopsMode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public CompilerGroovy(String languageHomeDir) throws FileNotFoundException
}

@Override
public boolean compile(List<File> sourceFiles, List<String> classpathEntries, File outputDir, Map<String, String> environment, ILogListener logListener)
public boolean compile(List<File> sourceFiles, List<String> classpathEntries, List<String> vmOptions, File outputDir, Map<String, String> environment, ILogListener logListener)
throws IOException
{
List<String> commands = new ArrayList<>();
Expand All @@ -49,6 +49,7 @@ public boolean compile(List<File> sourceFiles, List<String> classpathEntries, Fi
String outputDirPath = outputDir.getAbsolutePath().toString();

List<String> compileOptions = Arrays.asList(new String[] { "-d", outputDirPath });
commands.addAll(vmOptions);

commands.addAll(compileOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public CompilerJRuby(String languageHomeDir) throws FileNotFoundException
}

@Override
public boolean compile(List<File> sourceFiles, List<String> classpathEntries, File outputDir, Map<String, String> environment, ILogListener logListener)
public boolean compile(List<File> sourceFiles, List<String> classpathEntries, List<String> vmOptions, File outputDir, Map<String, String> environment, ILogListener logListener)
throws IOException
{
List<String> commands = new ArrayList<>();
Expand All @@ -58,6 +58,7 @@ public boolean compile(List<File> sourceFiles, List<String> classpathEntries, Fi
//
// commands.addAll(compileOptions);
//
commands.addAll(vmOptions);

if (classpathEntries.size() > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public CompilerJava(String languageHomeDir) throws FileNotFoundException
}

@Override
public boolean compile(List<File> sourceFiles, List<String> classpathEntries, File outputDir, Map<String, String> environment, ILogListener logListener)
public boolean compile(List<File> sourceFiles, List<String> classpathEntries, List<String> vmOptions, File outputDir, Map<String, String> environment, ILogListener logListener)
throws IOException
{
List<String> commands = new ArrayList<>();
Expand All @@ -54,6 +54,7 @@ public boolean compile(List<File> sourceFiles, List<String> classpathEntries, Fi
commands.add(compilerPath.toString());

List<String> compileOptions = Arrays.asList(new String[] { "-g", "-d", outputDirPath });
commands.addAll(vmOptions);

commands.addAll(compileOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public CompilerJavaScript(String languageHomeDir) throws FileNotFoundException
}

@Override
public boolean compile(List<File> sourceFiles, List<String> classpathEntries, File outputDir, Map<String, String> environment, ILogListener logListener)
public boolean compile(List<File> sourceFiles, List<String> classpathEntries, List<String> vmOptions, File outputDir, Map<String, String> environment, ILogListener logListener)
throws IOException
{
List<String> commands = new ArrayList<>();
Expand All @@ -50,6 +50,7 @@ public boolean compile(List<File> sourceFiles, List<String> classpathEntries, Fi

// TODO support optimistic typing shortcuts
List<String> compileOptions = Arrays.asList(new String[] { "-ot=false", "-co", "--dump-debug-dir=" + outputDirPath });
commands.addAll(vmOptions);

commands.addAll(compileOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public CompilerKotlin(String languageHomeDir) throws FileNotFoundException
}

@Override
public boolean compile(List<File> sourceFiles, List<String> classpathEntries, File outputDir, Map<String, String> environment, ILogListener logListener)
public boolean compile(List<File> sourceFiles, List<String> classpathEntries, List<String> vmOptions, File outputDir, Map<String, String> environment, ILogListener logListener)
throws IOException
{
List<String> commands = new ArrayList<>();
Expand All @@ -53,6 +53,7 @@ public boolean compile(List<File> sourceFiles, List<String> classpathEntries, Fi
"-include-runtime",
"-d",
outputDirPath + File.separator + KOTLIN_EXECUTABLE_JAR });
commands.addAll(vmOptions);

commands.addAll(compileOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public CompilerScala(String languageHomeDir) throws FileNotFoundException
}

@Override
public boolean compile(List<File> sourceFiles, List<String> classpathEntries, File outputDir, Map<String, String> environment,ILogListener logListener)
public boolean compile(List<File> sourceFiles, List<String> classpathEntries, List<String> vmOptions, File outputDir, Map<String, String> environment,ILogListener logListener)
throws IOException
{
List<String> commands = new ArrayList<>();
Expand All @@ -54,6 +54,7 @@ public boolean compile(List<File> sourceFiles, List<String> classpathEntries, Fi
String outputDirPath = outputDir.getAbsolutePath().toString();

List<String> compileOptions = Arrays.asList(new String[] { "-print", "-g:vars", "-d", outputDirPath });
commands.addAll(vmOptions);

commands.addAll(compileOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@

public interface ICompiler extends IExternalProcess
{
public boolean compile(List<File> sourceFiles, List<String> classpathEntries, File outputDir, Map<String, String> environment, ILogListener logListener) throws IOException;
public boolean compile(List<File> sourceFiles, List<String> classpathEntries, List<String> vmOptions, File outputDir, Map<String, String> environment, ILogListener logListener) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ public class TestBytecodeLoaderWithInnerClasses

List<String> compileClasspath = new ArrayList<>();

boolean success = compiler.compile(sources, compileClasspath, pathToTempClassDir.toFile(), Collections.emptyMap(),
List<String> vmOptions = new ArrayList<>();

boolean success = compiler.compile(sources, compileClasspath, vmOptions, pathToTempClassDir.toFile(), Collections.emptyMap(),
new NullLogListener());

if (!success)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ private void deleteFile(File file)

List<String> compileClasspath = new ArrayList<>();

boolean success = compiler.compile(sources, compileClasspath, tempDirPath.toFile(), Collections.emptyMap(),
List<String> vmOptions = new ArrayList<>();

boolean success = compiler.compile(sources, compileClasspath, vmOptions, tempDirPath.toFile(), Collections.emptyMap(),
new NullLogListener());

if (!success)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ public void runSandbox(String language, List<File> compileList, File fileToRun)

lastProcess = compiler;

boolean compiledOK = compiler.compile(compileList, buildUniqueClasspath(logParser.getConfig()), SANDBOX_CLASS_DIR.toFile(),
List<String> compilationSwitches = Arrays.asList(logParser.getConfig().getExtraVMCompilationSwitches().split(" "));

boolean compiledOK = compiler.compile(compileList, buildUniqueClasspath(logParser.getConfig()), compilationSwitches, SANDBOX_CLASS_DIR.toFile(),
Collections.<String, String>emptyMap(), logListener);

logListener.handleLogEntry("Compilation success: " + compiledOK);
Expand Down Expand Up @@ -322,9 +324,9 @@ else if (onStackReplacementMode == OnStackReplacement.FORCE_NO_ON_STACK_REPLACEM
options.add("-XX:CompileThreshold=" + logParser.getConfig().getCompileThreshold());
}

if (logParser.getConfig().getExtraVMSwitches().length() > 0)
if (logParser.getConfig().getExtraVMRuntimeSwitches().length() > 0)
{
String extraSwitchString = logParser.getConfig().getExtraVMSwitches();
String extraSwitchString = logParser.getConfig().getExtraVMRuntimeSwitches();
String[] switches = extraSwitchString.split(S_SPACE);

for (String sw : switches)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public class SandboxConfigStage extends Stage
private TextField txtFreqInline;
private TextField txtMaxInline;
private TextField txtCompilerThreshold;
private TextField txtExtraSwitches;
private TextField txtExtraCompilationSwitches;
private TextField txtExtraRuntimeSwitches;

private CheckBox checkBoxPrintAssembly;
private CheckBox checkBoxDisableInlining;
Expand Down Expand Up @@ -102,7 +103,9 @@ public SandboxConfigStage(final IStageClosedListener closedListener, final JITWa

vbox.getChildren().add(buildHBoxCompilationThreshold());

vbox.getChildren().add(buildHBoxExtraSwitches());
vbox.getChildren().add(buildHBoxExtraCompilationSwitches());

vbox.getChildren().add(buildHBoxExtraRuntimeSwitches());

vbox.getChildren().add(buildHBoxButtons());

Expand All @@ -124,7 +127,9 @@ public void handle(ActionEvent e)

setCompilerThreshold(config);

setExtraVMSwitches(config);
setExtraVMCompilationSwitches(config);

setExtraVMRuntimeSwitches(config);

config.setPrintAssembly(checkBoxPrintAssembly.isSelected());
config.setDisableInlining(checkBoxDisableInlining.isSelected());
Expand Down Expand Up @@ -162,9 +167,14 @@ private void setCompilerThreshold(JITWatchConfig config)
}
}

private void setExtraVMSwitches(JITWatchConfig config)
private void setExtraVMCompilationSwitches(JITWatchConfig config)
{
config.setExtraVMSwitches(txtExtraSwitches.getText().trim());
config.setExtraVMCompilationSwitches(txtExtraCompilationSwitches.getText().trim());
}

private void setExtraVMRuntimeSwitches(JITWatchConfig config)
{
config.setExtraVMRuntimeSwitches(txtExtraRuntimeSwitches.getText().trim());
}

private void setMaximumInlineSize(JITWatchConfig config)
Expand Down Expand Up @@ -527,19 +537,36 @@ private HBox buildHBoxCompilationThreshold()
return hbox;
}

private HBox buildHBoxExtraSwitches()
private HBox buildHBoxExtraCompilationSwitches()
{
HBox hbox = new HBox();

Label labelExtraCompilation = new Label("Extra VM compilation switches:");
labelExtraCompilation.setMinWidth(labelWidth);

txtExtraCompilationSwitches = new TextField(config.getExtraVMCompilationSwitches());
txtExtraCompilationSwitches.prefWidthProperty().bind(scene.widthProperty());
txtExtraCompilationSwitches.setAlignment(Pos.BASELINE_LEFT);

hbox.getChildren().add(labelExtraCompilation);
hbox.getChildren().add(txtExtraCompilationSwitches);

return hbox;
}

private HBox buildHBoxExtraRuntimeSwitches()
{
HBox hbox = new HBox();

Label labelExtra = new Label("Extra VM switches:");
labelExtra.setMinWidth(labelWidth);
Label labelExtraRuntime = new Label("Extra VM runtime switches:");
labelExtraRuntime.setMinWidth(labelWidth);

txtExtraSwitches = new TextField(config.getExtraVMSwitches());
txtExtraSwitches.prefWidthProperty().bind(scene.widthProperty());
txtExtraSwitches.setAlignment(Pos.BASELINE_LEFT);
txtExtraRuntimeSwitches = new TextField(config.getExtraVMRuntimeSwitches());
txtExtraRuntimeSwitches.prefWidthProperty().bind(scene.widthProperty());
txtExtraRuntimeSwitches.setAlignment(Pos.BASELINE_LEFT);

hbox.getChildren().add(labelExtra);
hbox.getChildren().add(txtExtraSwitches);
hbox.getChildren().add(labelExtraRuntime);
hbox.getChildren().add(txtExtraRuntimeSwitches);

return hbox;
}
Expand Down

0 comments on commit 9071f53

Please sign in to comment.