use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.
the class SnippetStub method getGraph.
@Override
@SuppressWarnings("try")
protected StructuredGraph getGraph(DebugContext debug, CompilationIdentifier compilationId) {
Plugins defaultPlugins = providers.getGraphBuilderPlugins();
MetaAccessProvider metaAccess = providers.getMetaAccess();
SnippetReflectionProvider snippetReflection = providers.getSnippetReflection();
Plugins plugins = new Plugins(defaultPlugins);
plugins.prependParameterPlugin(new ConstantBindingParameterPlugin(makeConstArgs(), metaAccess, snippetReflection));
GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(plugins);
// Stubs cannot have optimistic assumptions since they have
// to be valid for the entire run of the VM.
final StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).compilationId(compilationId).build();
try (DebugContext.Scope outer = debug.scope("SnippetStub", graph)) {
graph.disableUnsafeAccessTracking();
IntrinsicContext initialIntrinsicContext = new IntrinsicContext(method, method, getReplacementsBytecodeProvider(), INLINE_AFTER_PARSING);
GraphBuilderPhase.Instance instance = new GraphBuilderPhase.Instance(metaAccess, providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), config, OptimisticOptimizations.NONE, initialIntrinsicContext);
instance.apply(graph);
for (ParameterNode param : graph.getNodes(ParameterNode.TYPE)) {
int index = param.index();
if (method.getParameterAnnotation(NonNullParameter.class, index) != null) {
param.setStamp(param.stamp(NodeView.DEFAULT).join(StampFactory.objectNonNull()));
}
}
new RemoveValueProxyPhase().apply(graph);
graph.setGuardsStage(GuardsStage.FLOATING_GUARDS);
CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
PhaseContext context = new PhaseContext(providers);
canonicalizer.apply(graph, context);
new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
} catch (Throwable e) {
throw debug.handle(e);
}
return graph;
}
use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.
the class GraphKit method inline.
/**
* Inlines a given invocation to a method. The graph of the inlined method is processed in the
* same manner as for snippets and method substitutions.
*/
public void inline(InvokeNode invoke) {
ResolvedJavaMethod method = ((MethodCallTargetNode) invoke.callTarget()).targetMethod();
MetaAccessProvider metaAccess = providers.getMetaAccess();
Plugins plugins = new Plugins(graphBuilderPlugins);
GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(plugins);
StructuredGraph calleeGraph = new StructuredGraph.Builder(invoke.getOptions(), invoke.getDebug()).method(method).build();
if (invoke.graph().trackNodeSourcePosition()) {
calleeGraph.setTrackNodeSourcePosition();
}
IntrinsicContext initialReplacementContext = new IntrinsicContext(method, method, providers.getReplacements().getDefaultReplacementBytecodeProvider(), INLINE_AFTER_PARSING);
GraphBuilderPhase.Instance instance = new GraphBuilderPhase.Instance(metaAccess, providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), config, OptimisticOptimizations.NONE, initialReplacementContext);
instance.apply(calleeGraph);
// Remove all frame states from inlinee
calleeGraph.clearAllStateAfter();
new DeadCodeEliminationPhase(Optionality.Required).apply(calleeGraph);
InliningUtil.inline(invoke, calleeGraph, false, method);
}
use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.
the class ClassfileBytecodeProviderTest method test.
@Test
public void test() {
RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class);
Providers providers = rt.getHostBackend().getProviders();
MetaAccessProvider metaAccess = providers.getMetaAccess();
Assume.assumeTrue(VerifyPhase.class.desiredAssertionStatus());
String propertyName = Java8OrEarlier ? "sun.boot.class.path" : "jdk.module.path";
String bootclasspath = System.getProperty(propertyName);
Assert.assertNotNull("Cannot find value of " + propertyName, bootclasspath);
for (String path : bootclasspath.split(File.pathSeparator)) {
if (shouldProcess(path)) {
try {
final ZipFile zipFile = new ZipFile(new File(path));
for (final Enumeration<? extends ZipEntry> entry = zipFile.entries(); entry.hasMoreElements(); ) {
final ZipEntry zipEntry = entry.nextElement();
String name = zipEntry.getName();
if (name.endsWith(".class") && !name.equals("module-info.class") && !name.startsWith("META-INF/versions/")) {
String className = name.substring(0, name.length() - ".class".length()).replace('/', '.');
if (isInNativeImage(className)) {
/*
* Native image requires non-graalsdk classes to be present in the
* classpath.
*/
continue;
}
try {
checkClass(metaAccess, getSnippetReflection(), className);
} catch (ClassNotFoundException e) {
throw new AssertionError(e);
}
}
}
} catch (IOException ex) {
Assert.fail(ex.toString());
}
}
}
}
use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.
the class HotSpotGraalMBeanTest method dumpOperation.
@Test
public void dumpOperation() throws Exception {
Field field = null;
try {
field = stopMBeanServer();
} catch (Exception ex) {
if (ex.getClass().getName().equals("java.lang.reflect.InaccessibleObjectException")) {
// skip on JDK9
return;
}
}
assertNull("The platformMBeanServer isn't initialized now", field.get(null));
ObjectName name;
assertNotNull("Server is started", ManagementFactory.getPlatformMBeanServer());
HotSpotGraalMBean realBean = HotSpotGraalMBean.create(null);
assertNotNull("Bean is registered", name = realBean.ensureRegistered(false));
final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
ObjectInstance bean = server.getObjectInstance(name);
assertNotNull("Bean is registered", bean);
MBeanInfo info = server.getMBeanInfo(name);
assertNotNull("Info is found", info);
final MBeanOperationInfo[] arr = info.getOperations();
assertEquals("Currently three overloads", 3, arr.length);
MBeanOperationInfo dumpOp = null;
for (int i = 0; i < arr.length; i++) {
assertEquals("dumpMethod", arr[i].getName());
if (arr[i].getSignature().length == 3) {
dumpOp = arr[i];
}
}
assertNotNull("three args variant found", dumpOp);
server.invoke(name, "dumpMethod", new Object[] { "java.util.Arrays", "asList", ":3" }, null);
MBeanAttributeInfo dump = (MBeanAttributeInfo) findAttributeInfo("Dump", info);
Attribute dumpTo1 = new Attribute(dump.getName(), "");
server.setAttribute(name, dumpTo1);
Object after = server.getAttribute(name, dump.getName());
assertEquals("", after);
OptionValues empty = new OptionValues(EconomicMap.create());
OptionValues unsetDump = realBean.optionsFor(empty, null);
final MetaAccessProvider metaAccess = jdk.vm.ci.runtime.JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess();
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(Arrays.class.getMethod("asList", Object[].class));
final OptionValues forMethod = realBean.optionsFor(unsetDump, method);
assertNotSame(unsetDump, forMethod);
Object nothing = unsetDump.getMap().get(DebugOptions.Dump);
assertEquals("Empty string", "", nothing);
Object specialValue = forMethod.getMap().get(DebugOptions.Dump);
assertEquals(":3", specialValue);
OptionValues normalMethod = realBean.optionsFor(unsetDump, null);
Object noSpecialValue = normalMethod.getMap().get(DebugOptions.Dump);
assertEquals("Empty string", "", noSpecialValue);
}
use of jdk.vm.ci.meta.MetaAccessProvider in project graal by oracle.
the class VerifyGetOptionsUsage method verify.
@Override
protected boolean verify(StructuredGraph graph, PhaseContext context) {
MetaAccessProvider metaAccess = context.getMetaAccess();
ResolvedJavaType canonicalizerToolClass = metaAccess.lookupJavaType(CanonicalizerTool.class);
boolean hasTool = false;
try {
for (ResolvedJavaMethod.Parameter parameter : graph.method().getParameters()) {
if (parameter.getType().getName().equals(canonicalizerToolClass.getName())) {
hasTool = true;
break;
}
}
} catch (MalformedParametersException e) {
// Lambdas sometimes have malformed parameters so ignore this.
}
if (hasTool) {
ResolvedJavaMethod getOptionsMethod = metaAccess.lookupJavaMethod(lookupMethod(Node.class, "getOptions"));
for (MethodCallTargetNode t : graph.getNodes(MethodCallTargetNode.TYPE)) {
ResolvedJavaMethod callee = t.targetMethod();
if (callee.equals(getOptionsMethod)) {
if (hasTool) {
throw new VerificationError("Must use CanonicalizerTool.getOptions() instead of Node.getOptions() in method '%s' of class '%s'.", graph.method().getName(), graph.method().getDeclaringClass().getName());
}
}
}
}
return true;
}
Aggregations