Skip to content

Commit

Permalink
Control On Stack Replacement in Sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswhocodes committed Dec 22, 2015
1 parent 082473e commit acc9839
Show file tree
Hide file tree
Showing 9 changed files with 323 additions and 113 deletions.
212 changes: 149 additions & 63 deletions src/main/java/org/adoptopenjdk/jitwatch/core/JITWatchConfig.java
Expand Up @@ -47,6 +47,11 @@ public enum BackgroundCompilation
VM_DEFAULT, FORCE_BACKGROUND_COMPILATION, FORCE_NO_BACKGROUND_COMPILATION; VM_DEFAULT, FORCE_BACKGROUND_COMPILATION, FORCE_NO_BACKGROUND_COMPILATION;
} }


public enum OnStackReplacement
{
VM_DEFAULT, FORCE_ON_STACK_REPLACEMENT, FORCE_NO_ON_STACK_REPLACEMENT;
}

private static final Logger logger = LoggerFactory.getLogger(JITWatchConfig.class); private static final Logger logger = LoggerFactory.getLogger(JITWatchConfig.class);


private static final String PROPERTIES_FILENAME = "jitwatch.properties"; private static final String PROPERTIES_FILENAME = "jitwatch.properties";
Expand Down Expand Up @@ -77,6 +82,7 @@ public enum BackgroundCompilation
private static final String KEY_SANDBOX_COMPILER_THRESHOLD = SANDBOX_PREFIX + ".compiler.threshold"; 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_SWITCHES = SANDBOX_PREFIX + ".extra.vm.switches";
private static final String KEY_SANDBOX_BACKGROUND_COMPILATION = SANDBOX_PREFIX + ".background.compilation"; 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";


private static final String KEY_LAST_PROFILE = "last.profile"; private static final String KEY_LAST_PROFILE = "last.profile";


Expand All @@ -96,7 +102,8 @@ public enum BackgroundCompilation


private TieredCompilation tieredCompilationMode; private TieredCompilation tieredCompilationMode;
private CompressedOops compressedOopsMode; private CompressedOops compressedOopsMode;
private BackgroundCompilation backgroundCompilation; private BackgroundCompilation backgroundCompilationMode;
private OnStackReplacement onStackReplacementMode;


private int freqInlineSize; private int freqInlineSize;
private int maxInlineSize; private int maxInlineSize;
Expand All @@ -109,8 +116,9 @@ public enum BackgroundCompilation
private String profileName = S_PROFILE_DEFAULT; private String profileName = S_PROFILE_DEFAULT;


private final String CONFIG_OVERRIDE = System.getProperty("jitwatch.config.file", null); private final String CONFIG_OVERRIDE = System.getProperty("jitwatch.config.file", null);


private File propertiesFile = (CONFIG_OVERRIDE != null) ? new File(CONFIG_OVERRIDE) : new File(System.getProperty("user.dir"), PROPERTIES_FILENAME); private File propertiesFile = (CONFIG_OVERRIDE != null) ? new File(CONFIG_OVERRIDE)
: new File(System.getProperty("user.dir"), PROPERTIES_FILENAME);


private Properties loadedProps; private Properties loadedProps;


Expand Down Expand Up @@ -325,9 +333,32 @@ public void unmarshalPropertiesToConfig()
mouseFollow = loadBooleanFromProperty(loadedProps, KEY_TRIVIEW_TRILINK_MOUSE_FOLLOW, false); mouseFollow = loadBooleanFromProperty(loadedProps, KEY_TRIVIEW_TRILINK_MOUSE_FOLLOW, false);
localAsmLabels = loadBooleanFromProperty(loadedProps, KEY_TRIVIEW_LOCAL_ASM_LABELS, true); localAsmLabels = loadBooleanFromProperty(loadedProps, KEY_TRIVIEW_LOCAL_ASM_LABELS, true);


int tieredMode = Integer.parseInt(getProperty(loadedProps, KEY_SANDBOX_TIERED_MODE, "0")); loadTieredMode();

loadCompressedOopsMode();

loadBackgroundCompilationMode();

loadOnStackReplacementMode();

freqInlineSize = loadIntFromProperty(loadedProps, KEY_SANDBOX_FREQ_INLINE_SIZE, JITWatchConstants.DEFAULT_FREQ_INLINE_SIZE);


switch (tieredMode) maxInlineSize = loadIntFromProperty(loadedProps, KEY_SANDBOX_MAX_INLINE_SIZE, JITWatchConstants.DEFAULT_MAX_INLINE_SIZE);

printAssembly = loadBooleanFromProperty(loadedProps, KEY_SANDBOX_PRINT_ASSEMBLY, true);
disableInlining = loadBooleanFromProperty(loadedProps, KEY_SANDBOX_DISABLE_INLINING, false);

compileThreshold = loadIntFromProperty(loadedProps, KEY_SANDBOX_COMPILER_THRESHOLD,
JITWatchConstants.DEFAULT_COMPILER_THRESHOLD);

extraVMSwitches = getProperty(loadedProps, KEY_SANDBOX_EXTRA_VM_SWITCHES, JITWatchConstants.S_EMPTY);
}

private void loadTieredMode()
{
int param = Integer.parseInt(getProperty(loadedProps, KEY_SANDBOX_TIERED_MODE, "0"));

switch (param)
{ {
case 0: case 0:
tieredCompilationMode = TieredCompilation.VM_DEFAULT; tieredCompilationMode = TieredCompilation.VM_DEFAULT;
Expand All @@ -339,10 +370,13 @@ public void unmarshalPropertiesToConfig()
tieredCompilationMode = TieredCompilation.FORCE_NO_TIERED; tieredCompilationMode = TieredCompilation.FORCE_NO_TIERED;
break; break;
} }
}


int oopsMode = Integer.parseInt(getProperty(loadedProps, KEY_SANDBOX_COMPRESSED_OOPS_MODE, "0")); private void loadCompressedOopsMode()
{
int param = Integer.parseInt(getProperty(loadedProps, KEY_SANDBOX_COMPRESSED_OOPS_MODE, "0"));


switch (oopsMode) switch (param)
{ {
case 0: case 0:
compressedOopsMode = CompressedOops.VM_DEFAULT; compressedOopsMode = CompressedOops.VM_DEFAULT;
Expand All @@ -354,33 +388,106 @@ public void unmarshalPropertiesToConfig()
compressedOopsMode = CompressedOops.FORCE_NO_COMPRESSED; compressedOopsMode = CompressedOops.FORCE_NO_COMPRESSED;
break; break;
} }
}


int backgroundCompilationMode = Integer.parseInt(getProperty(loadedProps, KEY_SANDBOX_BACKGROUND_COMPILATION, "2")); private void loadBackgroundCompilationMode()
{
int param = Integer.parseInt(getProperty(loadedProps, KEY_SANDBOX_BACKGROUND_COMPILATION, "2"));


switch (backgroundCompilationMode) switch (param)
{ {
case 0: case 0:
backgroundCompilation = BackgroundCompilation.VM_DEFAULT; backgroundCompilationMode = BackgroundCompilation.VM_DEFAULT;
break; break;
case 1: case 1:
backgroundCompilation = BackgroundCompilation.FORCE_BACKGROUND_COMPILATION; backgroundCompilationMode = BackgroundCompilation.FORCE_BACKGROUND_COMPILATION;
break; break;
case 2: case 2:
backgroundCompilation = BackgroundCompilation.FORCE_NO_BACKGROUND_COMPILATION; backgroundCompilationMode = BackgroundCompilation.FORCE_NO_BACKGROUND_COMPILATION;
break; break;
} }
}


freqInlineSize = loadIntFromProperty(loadedProps, KEY_SANDBOX_FREQ_INLINE_SIZE, JITWatchConstants.DEFAULT_FREQ_INLINE_SIZE); private void loadOnStackReplacementMode()
{
int param = Integer.parseInt(getProperty(loadedProps, KEY_SANDBOX_ON_STACK_REPLACEMENT, "0"));


maxInlineSize = loadIntFromProperty(loadedProps, KEY_SANDBOX_MAX_INLINE_SIZE, JITWatchConstants.DEFAULT_MAX_INLINE_SIZE); switch (param)
{
case 0:
onStackReplacementMode = OnStackReplacement.VM_DEFAULT;
break;
case 1:
onStackReplacementMode = OnStackReplacement.FORCE_ON_STACK_REPLACEMENT;
break;
case 2:
onStackReplacementMode = OnStackReplacement.FORCE_NO_ON_STACK_REPLACEMENT;
break;
}
}


printAssembly = loadBooleanFromProperty(loadedProps, KEY_SANDBOX_PRINT_ASSEMBLY, true); private void saveTieredCompilationMode()
disableInlining = loadBooleanFromProperty(loadedProps, KEY_SANDBOX_DISABLE_INLINING, false); {
switch (tieredCompilationMode)
{
case VM_DEFAULT:
putProperty(loadedProps, KEY_SANDBOX_TIERED_MODE, "0");
break;
case FORCE_TIERED:
putProperty(loadedProps, KEY_SANDBOX_TIERED_MODE, "1");
break;
case FORCE_NO_TIERED:
putProperty(loadedProps, KEY_SANDBOX_TIERED_MODE, "2");
break;
}
}


compileThreshold = loadIntFromProperty(loadedProps, KEY_SANDBOX_COMPILER_THRESHOLD, private void saveCompressedOopsMode()
JITWatchConstants.DEFAULT_COMPILER_THRESHOLD); {
switch (compressedOopsMode)
{
case VM_DEFAULT:
putProperty(loadedProps, KEY_SANDBOX_COMPRESSED_OOPS_MODE, "0");
break;
case FORCE_COMPRESSED:
putProperty(loadedProps, KEY_SANDBOX_COMPRESSED_OOPS_MODE, "1");
break;
case FORCE_NO_COMPRESSED:
putProperty(loadedProps, KEY_SANDBOX_COMPRESSED_OOPS_MODE, "2");
break;
}
}


extraVMSwitches = getProperty(loadedProps, KEY_SANDBOX_EXTRA_VM_SWITCHES, JITWatchConstants.S_EMPTY); private void saveBackgroundCompilationMode()
{
switch (backgroundCompilationMode)
{
case VM_DEFAULT:
putProperty(loadedProps, KEY_SANDBOX_BACKGROUND_COMPILATION, "0");
break;
case FORCE_BACKGROUND_COMPILATION:
putProperty(loadedProps, KEY_SANDBOX_BACKGROUND_COMPILATION, "1");
break;
case FORCE_NO_BACKGROUND_COMPILATION:
putProperty(loadedProps, KEY_SANDBOX_BACKGROUND_COMPILATION, "2");
break;
}
}

private void saveOnStackReplacementMode()
{
switch (onStackReplacementMode)
{
case VM_DEFAULT:
putProperty(loadedProps, KEY_SANDBOX_ON_STACK_REPLACEMENT, "0");
break;
case FORCE_ON_STACK_REPLACEMENT:
putProperty(loadedProps, KEY_SANDBOX_ON_STACK_REPLACEMENT, "1");
break;
case FORCE_NO_ON_STACK_REPLACEMENT:
putProperty(loadedProps, KEY_SANDBOX_ON_STACK_REPLACEMENT, "2");
break;
}
} }


private boolean loadBooleanFromProperty(Properties props, String propertyName, boolean defaultValue) private boolean loadBooleanFromProperty(Properties props, String propertyName, boolean defaultValue)
Expand Down Expand Up @@ -482,44 +589,13 @@ public void marshalConfigToProperties()
putProperty(loadedProps, KEY_TRIVIEW_TRILINK_MOUSE_FOLLOW, Boolean.toString(mouseFollow)); putProperty(loadedProps, KEY_TRIVIEW_TRILINK_MOUSE_FOLLOW, Boolean.toString(mouseFollow));
putProperty(loadedProps, KEY_TRIVIEW_LOCAL_ASM_LABELS, Boolean.toString(localAsmLabels)); putProperty(loadedProps, KEY_TRIVIEW_LOCAL_ASM_LABELS, Boolean.toString(localAsmLabels));


switch (tieredCompilationMode) saveTieredCompilationMode();
{
case VM_DEFAULT:
putProperty(loadedProps, KEY_SANDBOX_TIERED_MODE, "0");
break;
case FORCE_TIERED:
putProperty(loadedProps, KEY_SANDBOX_TIERED_MODE, "1");
break;
case FORCE_NO_TIERED:
putProperty(loadedProps, KEY_SANDBOX_TIERED_MODE, "2");
break;
}


switch (compressedOopsMode) saveCompressedOopsMode();
{
case VM_DEFAULT:
putProperty(loadedProps, KEY_SANDBOX_COMPRESSED_OOPS_MODE, "0");
break;
case FORCE_COMPRESSED:
putProperty(loadedProps, KEY_SANDBOX_COMPRESSED_OOPS_MODE, "1");
break;
case FORCE_NO_COMPRESSED:
putProperty(loadedProps, KEY_SANDBOX_COMPRESSED_OOPS_MODE, "2");
break;
}


switch (backgroundCompilation) saveBackgroundCompilationMode();
{
case VM_DEFAULT: saveOnStackReplacementMode();
putProperty(loadedProps, KEY_SANDBOX_BACKGROUND_COMPILATION, "0");
break;
case FORCE_BACKGROUND_COMPILATION:
putProperty(loadedProps, KEY_SANDBOX_BACKGROUND_COMPILATION, "1");
break;
case FORCE_NO_BACKGROUND_COMPILATION:
putProperty(loadedProps, KEY_SANDBOX_BACKGROUND_COMPILATION, "2");
break;
}


if (lastLogDir != null) if (lastLogDir != null)
{ {
Expand Down Expand Up @@ -560,27 +636,27 @@ public void savePropertiesToFile()
public static File getJDKSourceZip() public static File getJDKSourceZip()
{ {
String jrePath = System.getProperty("java.home"); String jrePath = System.getProperty("java.home");

File jreDir = new File(jrePath); File jreDir = new File(jrePath);

File result = null; File result = null;


if (jreDir.exists() && jreDir.isDirectory()) if (jreDir.exists() && jreDir.isDirectory())
{ {
File srcZipFile = new File(jreDir, "src.zip"); File srcZipFile = new File(jreDir, "src.zip");

if (srcZipFile.exists() && srcZipFile.isFile()) if (srcZipFile.exists() && srcZipFile.isFile())
{ {
result = srcZipFile; result = srcZipFile;
} }
else else
{ {
File parentDir = jreDir.getParentFile(); File parentDir = jreDir.getParentFile();

if (parentDir.exists() && parentDir.isDirectory()) if (parentDir.exists() && parentDir.isDirectory())
{ {
srcZipFile = new File(parentDir, "src.zip"); srcZipFile = new File(parentDir, "src.zip");

if (srcZipFile.exists() && srcZipFile.isFile()) if (srcZipFile.exists() && srcZipFile.isFile())
{ {
result = srcZipFile; result = srcZipFile;
Expand Down Expand Up @@ -798,12 +874,22 @@ public void setCompressedOopsMode(CompressedOops compressedOopsMode)


public BackgroundCompilation getBackgroundCompilationMode() public BackgroundCompilation getBackgroundCompilationMode()
{ {
return backgroundCompilation; return backgroundCompilationMode;
}

public void setBackgroundCompilationMode(BackgroundCompilation backgroundCompilationMode)
{
this.backgroundCompilationMode = backgroundCompilationMode;
}

public OnStackReplacement getOnStackReplacementMode()
{
return onStackReplacementMode;
} }


public void setBackgroundCompilationMode(BackgroundCompilation backgroundCompilation) public void setOnStackReplacementMode(OnStackReplacement onStackReplacementMode)
{ {
this.backgroundCompilation = backgroundCompilation; this.onStackReplacementMode = onStackReplacementMode;
} }


public void addOrUpdateVMLanguage(String language, String path) public void addOrUpdateVMLanguage(String language, String path)
Expand Down
Expand Up @@ -335,7 +335,7 @@ public String toString(int annoWidth, int line, boolean useLocalLabels)


if (comment.contains(S_SAFEPOINT_POLL) || comment.contains(S_SAFEPOINT_POLL_RETURN)) if (comment.contains(S_SAFEPOINT_POLL) || comment.contains(S_SAFEPOINT_POLL_RETURN))
{ {
builder.append(" *** SAFEPOINT ***"); builder.append(" *** SAFEPOINT POLL ***");
} }


builder.append(S_NEWLINE); builder.append(S_NEWLINE);
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/adoptopenjdk/jitwatch/sandbox/Sandbox.java
Expand Up @@ -20,6 +20,7 @@
import org.adoptopenjdk.jitwatch.core.JITWatchConfig; import org.adoptopenjdk.jitwatch.core.JITWatchConfig;
import org.adoptopenjdk.jitwatch.core.JITWatchConfig.BackgroundCompilation; import org.adoptopenjdk.jitwatch.core.JITWatchConfig.BackgroundCompilation;
import org.adoptopenjdk.jitwatch.core.JITWatchConfig.CompressedOops; import org.adoptopenjdk.jitwatch.core.JITWatchConfig.CompressedOops;
import org.adoptopenjdk.jitwatch.core.JITWatchConfig.OnStackReplacement;
import org.adoptopenjdk.jitwatch.core.JITWatchConfig.TieredCompilation; import org.adoptopenjdk.jitwatch.core.JITWatchConfig.TieredCompilation;
import org.adoptopenjdk.jitwatch.core.JITWatchConstants; import org.adoptopenjdk.jitwatch.core.JITWatchConstants;
import org.adoptopenjdk.jitwatch.model.IMetaMember; import org.adoptopenjdk.jitwatch.model.IMetaMember;
Expand Down Expand Up @@ -252,6 +253,17 @@ else if (backgroundCompilationMode == BackgroundCompilation.FORCE_NO_BACKGROUND_
options.add("-XX:-BackgroundCompilation"); options.add("-XX:-BackgroundCompilation");
} }


OnStackReplacement onStackReplacementMode = logParser.getConfig().getOnStackReplacementMode();

if (onStackReplacementMode == OnStackReplacement.FORCE_ON_STACK_REPLACEMENT)
{
options.add("-XX:+UseOnStackReplacement");
}
else if (onStackReplacementMode == OnStackReplacement.FORCE_NO_ON_STACK_REPLACEMENT)
{
options.add("-XX:-UseOnStackReplacement");
}

if (!isDisableInlining && logParser.getConfig().getFreqInlineSize() != JITWatchConstants.DEFAULT_FREQ_INLINE_SIZE) if (!isDisableInlining && logParser.getConfig().getFreqInlineSize() != JITWatchConstants.DEFAULT_FREQ_INLINE_SIZE)
{ {
options.add("-XX:FreqInlineSize=" + logParser.getConfig().getFreqInlineSize()); options.add("-XX:FreqInlineSize=" + logParser.getConfig().getFreqInlineSize());
Expand Down
Expand Up @@ -299,7 +299,7 @@ private void handleInlineFailTag(Map<String, String> attrs, String methodID, IMe
} }
else else
{ {
logger.info("No score is set for reason: {}", reason); logger.warn("No score is set for reason: {}", reason);
} }


StringBuilder reasonBuilder = new StringBuilder(); StringBuilder reasonBuilder = new StringBuilder();
Expand Down

0 comments on commit acc9839

Please sign in to comment.