use of org.graalvm.compiler.graph.NodeClass in project graal by oracle.
the class FieldsOffsetsFeature method registerFields.
private static void registerFields(FieldIntrospection<?> introspection, BeforeAnalysisAccessImpl config) {
if (introspection instanceof NodeClass<?>) {
NodeClass<?> nodeClass = (NodeClass<?>) introspection;
Fields dataFields = nodeClass.getData();
registerFields(dataFields, DefaultUnsafePartition.get(), config);
Fields inputEdges = nodeClass.getInputEdges();
registerFields(inputEdges, GraalEdgeUnsafePartition.get(), config);
Fields successorEdges = nodeClass.getSuccessorEdges();
registerFields(successorEdges, GraalEdgeUnsafePartition.get(), config);
/* Ensure field shortName is initialized, so that the instance is immutable. */
nodeClass.shortName();
} else {
for (Fields fields : introspection.getAllFields()) {
registerFields(fields, DefaultUnsafePartition.get(), config);
}
}
}
use of org.graalvm.compiler.graph.NodeClass in project graal by oracle.
the class RuntimeStrengthenStampsPhase method duringAnalysis.
@Override
public void duringAnalysis(DuringAnalysisAccess c) {
DuringAnalysisAccessImpl config = (DuringAnalysisAccessImpl) c;
GraalSupport.registerPhaseStatistics(config);
Deque<CallTreeNode> worklist = new ArrayDeque<>();
worklist.addAll(methods.values());
while (!worklist.isEmpty()) {
processMethod(worklist.removeFirst(), worklist, config.getBigBang());
}
SubstrateMethod[] methodsToCompileArr = new SubstrateMethod[methods.size()];
int idx = 0;
for (CallTreeNode node : methods.values()) {
methodsToCompileArr[idx++] = objectReplacer.createMethod(node.implementationMethod);
}
if (GraalSupport.setMethodsToCompile(methodsToCompileArr)) {
config.requireAnalysisIteration();
}
graphEncoder.finishPrepare();
AnalysisMetaAccess metaAccess = config.getMetaAccess();
NodeClass<?>[] nodeClasses = graphEncoder.getNodeClasses();
for (NodeClass<?> nodeClass : nodeClasses) {
metaAccess.lookupJavaType(nodeClass.getClazz()).registerAsAllocated(null);
}
if (GraalSupport.setGraphEncoding(graphEncoder.getEncoding(), graphEncoder.getObjects(), nodeClasses)) {
config.requireAnalysisIteration();
}
if (objectReplacer.updateDataDuringAnalysis(config.getMetaAccess())) {
config.requireAnalysisIteration();
}
}
use of org.graalvm.compiler.graph.NodeClass in project graal by oracle.
the class RuntimeStrengthenStampsPhase method beforeAnalysis.
@Override
public void beforeAnalysis(BeforeAnalysisAccess c) {
BeforeAnalysisAccessImpl config = (BeforeAnalysisAccessImpl) c;
GraalSupport.allocatePhaseStatisticsCache();
populateMatchRuleRegistry();
Function<Providers, Backend> backendProvider = GraalSupport.getRuntimeBackendProvider();
Providers originalProviders = GraalAccess.getOriginalProviders();
runtimeConfigBuilder = new SubstrateRuntimeConfigurationBuilder(RuntimeOptionValues.singleton(), config.getHostVM(), config.getUniverse(), config.getMetaAccess(), originalProviders.getConstantReflection(), backendProvider).build();
RuntimeConfiguration runtimeConfig = runtimeConfigBuilder.getRuntimeConfig();
Providers runtimeProviders = runtimeConfig.getProviders();
WordTypes wordTypes = runtimeConfigBuilder.getWordTypes();
hostedProviders = new HostedProviders(runtimeProviders.getMetaAccess(), runtimeProviders.getCodeCache(), runtimeProviders.getConstantReflection(), runtimeProviders.getConstantFieldProvider(), runtimeProviders.getForeignCalls(), runtimeProviders.getLowerer(), runtimeProviders.getReplacements(), runtimeProviders.getStampProvider(), runtimeConfig.getSnippetReflection(), wordTypes);
SubstrateGraalRuntime graalRuntime = new SubstrateGraalRuntime();
objectReplacer.setGraalRuntime(graalRuntime);
ImageSingletons.add(GraalRuntime.class, graalRuntime);
RuntimeSupport.getRuntimeSupport().addShutdownHook(new GraalSupport.GraalShutdownHook());
FeatureHandler featureHandler = config.getFeatureHandler();
NativeImageGenerator.registerGraphBuilderPlugins(featureHandler, runtimeConfig, hostedProviders, config.getMetaAccess(), config.getUniverse(), null, null, config.getNativeLibraries(), config.getImageClassLoader(), false, false);
DebugContext debug = DebugContext.forCurrentThread();
NativeImageGenerator.registerReplacements(debug, featureHandler, runtimeConfig, runtimeConfig.getProviders(), runtimeConfig.getSnippetReflection(), false);
featureHandler.forEachGraalFeature(feature -> feature.registerCodeObserver(runtimeConfig));
Suites suites = NativeImageGenerator.createSuites(featureHandler, runtimeConfig, runtimeConfig.getSnippetReflection(), false);
LIRSuites lirSuites = NativeImageGenerator.createLIRSuites(featureHandler, runtimeConfig.getProviders(), false);
GraalSupport.setRuntimeConfig(runtimeConfig, suites, lirSuites);
NodeClass<?>[] snippetNodeClasses = ((SubstrateReplacements) runtimeProviders.getReplacements()).getSnippetNodeClasses();
for (NodeClass<?> nodeClass : snippetNodeClasses) {
config.getMetaAccess().lookupJavaType(nodeClass.getClazz()).registerAsAllocated(null);
}
/* Initialize configuration with reasonable default values. */
graphBuilderConfig = GraphBuilderConfiguration.getDefault(hostedProviders.getGraphBuilderPlugins()).withBytecodeExceptionMode(BytecodeExceptionMode.ExplicitOnly);
includeCalleePredicate = GraalFeature::defaultIncludeCallee;
optimisticOpts = OptimisticOptimizations.ALL.remove(OptimisticOptimizations.Optimization.UseLoopLimitChecks);
methods = new LinkedHashMap<>();
graphEncoder = new GraphEncoder(ConfigurationValues.getTarget().arch);
/*
* Ensure that all snippet methods have their SubstrateMethod object created by the object
* replacer, to avoid corner cases later when writing the native image.
*/
for (ResolvedJavaMethod method : ((SubstrateReplacements) runtimeProviders.getReplacements()).getSnippetMethods()) {
objectReplacer.apply(method);
}
}
use of org.graalvm.compiler.graph.NodeClass in project graal by oracle.
the class NodeCostDumpUtil method main.
public static void main(String[] args) {
if (args.length != 1) {
System.err.println("NodeCostDumpUtil expects exactly one argument, the node name regex to match against.");
System.exit(-1);
}
final String pattern = getArgumentRegex(args[0]);
String version = System.getProperty("java.specification.version");
if (version.compareTo("1.9") >= 0) {
System.err.printf("NodeCostDumpUtil does not support JDK versions greater than 1.8, current version is %s.\n", version);
System.exit(-1);
}
String[] jvmciCP = System.getProperty("jvmci.class.path.append").split(File.pathSeparator);
String[] primarySuiteCP = System.getProperty("primary.suite.cp").split(File.pathSeparator);
ClassLoader applicationClassLoader = Thread.currentThread().getContextClassLoader();
HashSet<Class<?>> classes = new HashSet<>();
try {
Set<String> uniquePaths = new HashSet<>(Arrays.asList(primarySuiteCP));
uniquePaths.addAll(Arrays.asList(jvmciCP));
for (String path : uniquePaths) {
if (new File(path).exists()) {
if (path.endsWith(".jar")) {
try (FileSystem jarFileSystem = FileSystems.newFileSystem(URI.create("jar:file:" + path), Collections.emptyMap())) {
initAllClasses(jarFileSystem.getPath("/"), applicationClassLoader, classes);
}
} else {
initAllClasses(FileSystems.getDefault().getPath(path), applicationClassLoader, classes);
}
}
}
} catch (IOException ex) {
GraalError.shouldNotReachHere();
}
System.err.printf("Loaded %d classes...\n", classes.size());
List<Class<?>> nodeClasses = new ArrayList<>();
for (Class<?> loaded : classes) {
if (Node.class.isAssignableFrom(loaded) && !loaded.isArray()) {
nodeClasses.add(loaded);
}
}
System.err.printf("Loaded %s node classes...\n", nodeClasses.size());
List<NodeClass<?>> nc = new ArrayList<>();
for (Class<?> c : nodeClasses) {
try {
nc.add(NodeClass.get(c));
} catch (Throwable t) {
// Silently ignore problems here
}
}
System.err.printf("Read TYPE field from %s node classes...\n", nc.size());
nc = nc.stream().filter(x -> x != null).collect(Collectors.toList());
nc.sort((x, y) -> {
String a = x.getJavaClass().getName();
String b = y.getJavaClass().getName();
return a.compareTo(b);
});
CSVUtil.Escape.println(System.out, FMT, "NodeName", "Size", "Overrides Size Method", "Cycles", "Overrides Cycles Method", "Canonicalizable", "MemoryCheckPoint", "Virtualizable");
for (NodeClass<?> nodeclass : nc) {
String packageStrippedName = null;
try {
packageStrippedName = nodeclass.getJavaClass().getCanonicalName().replace(prefix1, "").replace(prefix2, "");
} catch (Throwable t) {
// do nothing
continue;
}
if (pattern != null && !packageStrippedName.matches(pattern)) {
continue;
}
boolean overridesSizeMethod = false;
boolean overridesCyclesMethod = false;
Class<?> c = nodeclass.getJavaClass();
try {
c.getDeclaredMethod("estimatedNodeSize");
overridesSizeMethod = true;
} catch (Throwable t) {
// do nothing
}
try {
c.getDeclaredMethod("estimatedNodeCycles");
overridesCyclesMethod = true;
} catch (Throwable t) {
// do nothing
}
CSVUtil.Escape.println(System.out, FMT, packageStrippedName, nodeclass.size(), overridesSizeMethod, nodeclass.cycles(), overridesCyclesMethod, canonicalizable(c), memoryCheckPoint(c), virtualizable(c));
}
}
Aggregations