Skip to content

Commit

Permalink
added indirection for RuntimeMXBean.getInputArguments
Browse files Browse the repository at this point in the history
  • Loading branch information
dougxc committed Apr 18, 2018
1 parent 51257d3 commit 30df44d
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,6 @@
*/
public class CheckGraalInvariants extends GraalCompilerTest {

public CheckGraalInvariants() {
try {
Class.forName("java.lang.management.ManagementFactory");
} catch (ClassNotFoundException ex) {
Assume.assumeNoException("cannot run without java.management JDK9 module", ex);
}
}

private static boolean shouldVerifyEquals(ResolvedJavaMethod m) {
if (m.getName().equals("identityEquals")) {
ResolvedJavaType c = m.getDeclaringClass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static java.lang.Thread.currentThread;

import java.lang.management.ManagementFactory;
import java.util.List;

import org.graalvm.compiler.serviceprovider.ServiceProvider;
import org.graalvm.compiler.serviceprovider.GraalServices.JMXService;
Expand Down Expand Up @@ -58,4 +59,9 @@ protected boolean isThreadAllocatedMemorySupported() {
protected boolean isCurrentThreadCpuTimeSupported() {
return threadMXBean.isThreadCpuTimeSupported();
}

@Override
protected List<String> getInputArguments() {
return ManagementFactory.getRuntimeMXBean().getInputArguments();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import java.lang.management.ManagementFactory;
import java.lang.management.MonitorInfo;
import java.lang.management.RuntimeMXBean;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
import java.util.Collection;
Expand All @@ -41,6 +40,7 @@
import org.graalvm.compiler.hotspot.phases.OnStackReplacementPhase;
import org.graalvm.compiler.options.OptionKey;
import org.graalvm.compiler.options.OptionValues;
import org.graalvm.compiler.serviceprovider.GraalServices;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.BeforeClass;
Expand All @@ -58,11 +58,6 @@ public class GraalOSRLockTest extends GraalOSRTestBase {

@BeforeClass
public static void checkVMArguments() {
try {
Class.forName("java.lang.management.ManagementFactory");
} catch (ClassNotFoundException ex) {
Assume.assumeNoException("cannot check for monitors without java.management JDK9 module", ex);
}
/*
* Note: The -Xcomp execution mode of the VM will stop most of the OSR test cases from
* working as every method is compiled at level3 (followed by level4 on the second
Expand All @@ -71,8 +66,8 @@ public static void checkVMArguments() {
* installed nmethod at a given BCI.
*
*/
RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
List<String> arguments = runtimeMxBean.getInputArguments();
List<String> arguments = GraalServices.getInputArguments();
Assume.assumeTrue("cannot check for monitors without", arguments != null);
for (String arg : arguments) {
Assume.assumeFalse(arg.equals(COMPILE_ONLY_FLAG));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.List;

import org.graalvm.compiler.options.OptionKey;
import org.graalvm.compiler.options.OptionValues;
Expand Down Expand Up @@ -116,8 +117,10 @@ public PrintStream getStream(OptionValues options) {
/*
* Add the JVM and Java arguments to the log file to help identity it.
*/
String inputArguments = String.join(" ", java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments());
ps.println("VM Arguments: " + inputArguments);
List<String> inputArguments = GraalServices.getInputArguments();
if (inputArguments != null) {
ps.println("VM Arguments: " + String.join(" ", inputArguments));
}
String cmd = System.getProperty("sun.java.command");
if (cmd != null) {
ps.println("sun.java.command=" + cmd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.graalvm.compiler.nodes.StructuredGraph;
import org.graalvm.compiler.options.OptionValues;
import org.graalvm.compiler.phases.contract.NodeCostUtil;
import org.graalvm.compiler.serviceprovider.GraalServices;

import jdk.vm.ci.meta.JavaMethod;
import jdk.vm.ci.meta.ResolvedJavaMethod;
Expand Down Expand Up @@ -86,11 +87,11 @@ public GraphPrinterDumpHandler(GraphPrinterSupplier printerSupplier) {
}

private static String jvmArguments() {
try {
return String.join(" ", java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments());
} catch (LinkageError err) {
return "unknown";
List<String> inputArguments = GraalServices.getInputArguments();
if (inputArguments != null) {
return String.join(" ", inputArguments);
}
return "unknown";
}

private void ensureInitialized(DebugContext ctx, Graph graph) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import java.util.concurrent.atomic.AtomicLong;
Expand Down Expand Up @@ -216,6 +217,8 @@ public abstract static class JMXService {

protected abstract boolean isCurrentThreadCpuTimeSupported();

protected abstract List<String> getInputArguments();

// Placing this static field in JMXService (instead of GraalServices)
// allows for lazy initialization.
static final JMXService instance = loadSingle(JMXService.class, false);
Expand Down Expand Up @@ -304,4 +307,26 @@ public static boolean isCurrentThreadCpuTimeSupported() {
}
return jmx.isCurrentThreadCpuTimeSupported();
}

/**
* Gets the input arguments passed to the Java virtual machine which does not include the
* arguments to the {@code main} method. This method returns an empty list if there is no input
* argument to the Java virtual machine.
* <p>
* Some Java virtual machine implementations may take input arguments from multiple different
* sources: for examples, arguments passed from the application that launches the Java virtual
* machine such as the 'java' command, environment variables, configuration files, etc.
* <p>
* Typically, not all command-line options to the 'java' command are passed to the Java virtual
* machine. Thus, the returned input arguments may not include all command-line options.
*
* @return the input arguments to the JVM or {@code null} if they are unavailable
*/
public static List<String> getInputArguments() {
JMXService jmx = JMXService.instance;
if (jmx == null) {
return null;
}
return jmx.getInputArguments();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceConfigurationError;
import java.util.concurrent.atomic.AtomicLong;

Expand Down Expand Up @@ -217,9 +218,14 @@ protected boolean isCurrentThreadCpuTimeSupported() {
return threadMXBean.isCurrentThreadCpuTimeSupported();
}

protected List<String> getInputArguments() {
return java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments();
}

// Placing this static field in JMXService (instead of GraalServices)
// allows for lazy initialization.
static final JMXService jmx = new JMXService();

}

/**
Expand Down Expand Up @@ -289,4 +295,22 @@ public static boolean isThreadAllocatedMemorySupported() {
public static boolean isCurrentThreadCpuTimeSupported() {
return jmx.isCurrentThreadCpuTimeSupported();
}

/**
* Gets the input arguments passed to the Java virtual machine which does not include the
* arguments to the {@code main} method. This method returns an empty list if there is no input
* argument to the Java virtual machine.
* <p>
* Some Java virtual machine implementations may take input arguments from multiple different
* sources: for examples, arguments passed from the application that launches the Java virtual
* machine such as the 'java' command, environment variables, configuration files, etc.
* <p>
* Typically, not all command-line options to the 'java' command are passed to the Java virtual
* machine. Thus, the returned input arguments may not include all command-line options.
*
* @return the input arguments to the JVM or {@code null} if they are unavailable
*/
public static List<String> getInputArguments() {
return jmx.getInputArguments();
}
}

0 comments on commit 30df44d

Please sign in to comment.