* @return a working JavaArguments object.
*/
private JavaArguments getBestEffortArguments(JavaArguments origJavaArguments,
String javaHome, String installPath)
{
JavaArguments memArgs = new JavaArguments();
memArgs.setInitialMemory(origJavaArguments.getInitialMemory());
memArgs.setMaxMemory(origJavaArguments.getMaxMemory());
String m = memArgs.getStringArguments();
boolean supportsMemory = false;
if (m.length() > 0)
{
supportsMemory = Utils.supportsOption(m, javaHome, installPath);
}
JavaArguments additionalArgs = new JavaArguments();
additionalArgs.setAdditionalArguments(
origJavaArguments.getAdditionalArguments());
String a = additionalArgs.getStringArguments();
boolean supportsAdditional = false;
if (a.length() > 0)
{
supportsAdditional = Utils.supportsOption(a, javaHome, installPath);
}
JavaArguments javaArgs = new JavaArguments();
if (supportsMemory)
{
javaArgs.setInitialMemory(origJavaArguments.getInitialMemory());
javaArgs.setMaxMemory(origJavaArguments.getMaxMemory());
}
else
{
// Try to figure out a smaller amount of memory.
long currentMaxMemory = Runtime.getRuntime().maxMemory();
int maxMemory = origJavaArguments.getMaxMemory();
if (maxMemory != -1)
{
maxMemory = maxMemory / 2;
while ((1024 * 1024 * maxMemory) < currentMaxMemory &&
!Utils.supportsOption(JavaArguments.getMaxMemoryArgument(maxMemory),
javaHome, installPath))
{
maxMemory = maxMemory / 2;
}
if ((1024 * 1024 * maxMemory) > currentMaxMemory)
{
// Supports this option.
javaArgs.setMaxMemory(maxMemory);
}
}
}
if (supportsAdditional)
{
javaArgs.setAdditionalArguments(
origJavaArguments.getAdditionalArguments());
}
return javaArgs;
}