932 @SuppressWarnings("try")
933 protected InstalledCode getCode(final ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, boolean forceCompile, boolean installAsDefault, OptionValues options) {
934 if (!forceCompile && graph == null) {
935 InstalledCode cached = cache.get(installedCodeOwner);
936 if (cached != null) {
937 if (cached.isValid()) {
938 return cached;
939 }
940 }
941 }
942 // loop for retrying compilation
943 for (int retry = 0; retry <= BAILOUT_RETRY_LIMIT; retry++) {
944 final CompilationIdentifier id = getOrCreateCompilationId(installedCodeOwner, graph);
945
946 InstalledCode installedCode = null;
947 StructuredGraph graphToCompile = graph == null ? parseForCompile(installedCodeOwner, id, options) : graph;
948 DebugContext debug = graphToCompile.getDebug();
949
950 try (AllocSpy spy = AllocSpy.open(installedCodeOwner); DebugContext.Scope ds = debug.scope("Compiling", new DebugDumpScope(id.toString(CompilationIdentifier.Verbosity.ID), true))) {
951 CompilationPrinter printer = CompilationPrinter.begin(options, id, installedCodeOwner, INVOCATION_ENTRY_BCI);
952 CompilationResult compResult = compile(installedCodeOwner, graphToCompile, new CompilationResult(), id, options);
953 printer.finish(compResult);
954
955 try (DebugContext.Scope s = debug.scope("CodeInstall", getCodeCache(), installedCodeOwner, compResult);
956 DebugContext.Activation a = debug.activate()) {
957 try {
958 if (installAsDefault) {
959 installedCode = addDefaultMethod(debug, installedCodeOwner, compResult);
960 } else {
961 installedCode = addMethod(debug, installedCodeOwner, compResult);
962 }
963 if (installedCode == null) {
964 throw new GraalError("Could not install code for " + installedCodeOwner.format("%H.%n(%p)"));
965 }
966 } catch (BailoutException e) {
967 if (retry <= BAILOUT_RETRY_LIMIT && graph == null && !e.isPermanent()) {
968 // retry (if there is no predefined graph)
969 TTY.println(String.format("Restart compilation %s (%s) due to a non-permanent bailout!", installedCodeOwner, id));
970 continue;
971 }
972 throw e;
1002 }
1003
1004 protected final StructuredGraph parseForCompile(ResolvedJavaMethod method) {
1005 return parseEager(method, AllowAssumptions.YES, getCompilationId(method), getInitialOptions());
1006 }
1007
1008 protected StructuredGraph parseForCompile(ResolvedJavaMethod method, CompilationIdentifier compilationId, OptionValues options) {
1009 return parseEager(method, AllowAssumptions.YES, compilationId, options);
1010 }
1011
1012 /**
1013 * Compiles a given method.
1014 *
1015 * @param installedCodeOwner the method the compiled code will be associated with when installed
1016 * @param graph the graph to be compiled for {@code installedCodeOwner}. If null, a graph will
1017 * be obtained from {@code installedCodeOwner} via
1018 * {@link #parseForCompile(ResolvedJavaMethod)}.
1019 */
1020 protected final CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph) {
1021 OptionValues options = graph == null ? getInitialOptions() : graph.getOptions();
1022 return compile(installedCodeOwner, graph, new CompilationResult(), getOrCreateCompilationId(installedCodeOwner, graph), options);
1023 }
1024
1025 protected final CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, CompilationIdentifier compilationId) {
1026 OptionValues options = graph == null ? getInitialOptions() : graph.getOptions();
1027 return compile(installedCodeOwner, graph, new CompilationResult(), compilationId, options);
1028 }
1029
1030 protected final CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, OptionValues options) {
1031 assert graph == null || graph.getOptions() == options;
1032 return compile(installedCodeOwner, graph, new CompilationResult(), getOrCreateCompilationId(installedCodeOwner, graph), options);
1033 }
1034
1035 /**
1036 * Compiles a given method.
1037 *
1038 * @param installedCodeOwner the method the compiled code will be associated with when installed
1039 * @param graph the graph to be compiled for {@code installedCodeOwner}. If null, a graph will
1040 * be obtained from {@code installedCodeOwner} via
1041 * {@link #parseForCompile(ResolvedJavaMethod)}.
1042 * @param compilationId
1043 */
1044 @SuppressWarnings("try")
1045 protected CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, CompilationResult compilationResult, CompilationIdentifier compilationId, OptionValues options) {
1046 StructuredGraph graphToCompile = graph == null ? parseForCompile(installedCodeOwner, compilationId, options) : graph;
1047 lastCompiledGraph = graphToCompile;
1048 DebugContext debug = graphToCompile.getDebug();
1049 try (DebugContext.Scope s = debug.scope("Compile", graphToCompile)) {
1050 assert options != null;
1051 Request<CompilationResult> request = new Request<>(graphToCompile, installedCodeOwner, getProviders(), getBackend(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL,
1052 graphToCompile.getProfilingInfo(), createSuites(options), createLIRSuites(options), compilationResult, CompilationResultBuilderFactory.Default);
|
932 @SuppressWarnings("try")
933 protected InstalledCode getCode(final ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, boolean forceCompile, boolean installAsDefault, OptionValues options) {
934 if (!forceCompile && graph == null) {
935 InstalledCode cached = cache.get(installedCodeOwner);
936 if (cached != null) {
937 if (cached.isValid()) {
938 return cached;
939 }
940 }
941 }
942 // loop for retrying compilation
943 for (int retry = 0; retry <= BAILOUT_RETRY_LIMIT; retry++) {
944 final CompilationIdentifier id = getOrCreateCompilationId(installedCodeOwner, graph);
945
946 InstalledCode installedCode = null;
947 StructuredGraph graphToCompile = graph == null ? parseForCompile(installedCodeOwner, id, options) : graph;
948 DebugContext debug = graphToCompile.getDebug();
949
950 try (AllocSpy spy = AllocSpy.open(installedCodeOwner); DebugContext.Scope ds = debug.scope("Compiling", new DebugDumpScope(id.toString(CompilationIdentifier.Verbosity.ID), true))) {
951 CompilationPrinter printer = CompilationPrinter.begin(options, id, installedCodeOwner, INVOCATION_ENTRY_BCI);
952 CompilationResult compResult = compile(installedCodeOwner, graphToCompile, new CompilationResult(graphToCompile.compilationId()), id, options);
953 printer.finish(compResult);
954
955 try (DebugContext.Scope s = debug.scope("CodeInstall", getCodeCache(), installedCodeOwner, compResult);
956 DebugContext.Activation a = debug.activate()) {
957 try {
958 if (installAsDefault) {
959 installedCode = addDefaultMethod(debug, installedCodeOwner, compResult);
960 } else {
961 installedCode = addMethod(debug, installedCodeOwner, compResult);
962 }
963 if (installedCode == null) {
964 throw new GraalError("Could not install code for " + installedCodeOwner.format("%H.%n(%p)"));
965 }
966 } catch (BailoutException e) {
967 if (retry <= BAILOUT_RETRY_LIMIT && graph == null && !e.isPermanent()) {
968 // retry (if there is no predefined graph)
969 TTY.println(String.format("Restart compilation %s (%s) due to a non-permanent bailout!", installedCodeOwner, id));
970 continue;
971 }
972 throw e;
1002 }
1003
1004 protected final StructuredGraph parseForCompile(ResolvedJavaMethod method) {
1005 return parseEager(method, AllowAssumptions.YES, getCompilationId(method), getInitialOptions());
1006 }
1007
1008 protected StructuredGraph parseForCompile(ResolvedJavaMethod method, CompilationIdentifier compilationId, OptionValues options) {
1009 return parseEager(method, AllowAssumptions.YES, compilationId, options);
1010 }
1011
1012 /**
1013 * Compiles a given method.
1014 *
1015 * @param installedCodeOwner the method the compiled code will be associated with when installed
1016 * @param graph the graph to be compiled for {@code installedCodeOwner}. If null, a graph will
1017 * be obtained from {@code installedCodeOwner} via
1018 * {@link #parseForCompile(ResolvedJavaMethod)}.
1019 */
1020 protected final CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph) {
1021 OptionValues options = graph == null ? getInitialOptions() : graph.getOptions();
1022 CompilationIdentifier compilationId = getOrCreateCompilationId(installedCodeOwner, graph);
1023 return compile(installedCodeOwner, graph, new CompilationResult(compilationId), compilationId, options);
1024 }
1025
1026 protected final CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, CompilationIdentifier compilationId) {
1027 OptionValues options = graph == null ? getInitialOptions() : graph.getOptions();
1028 return compile(installedCodeOwner, graph, new CompilationResult(compilationId), compilationId, options);
1029 }
1030
1031 protected final CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, OptionValues options) {
1032 assert graph == null || graph.getOptions() == options;
1033 CompilationIdentifier compilationId = getOrCreateCompilationId(installedCodeOwner, graph);
1034 return compile(installedCodeOwner, graph, new CompilationResult(compilationId), compilationId, options);
1035 }
1036
1037 /**
1038 * Compiles a given method.
1039 *
1040 * @param installedCodeOwner the method the compiled code will be associated with when installed
1041 * @param graph the graph to be compiled for {@code installedCodeOwner}. If null, a graph will
1042 * be obtained from {@code installedCodeOwner} via
1043 * {@link #parseForCompile(ResolvedJavaMethod)}.
1044 * @param compilationId
1045 */
1046 @SuppressWarnings("try")
1047 protected CompilationResult compile(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, CompilationResult compilationResult, CompilationIdentifier compilationId, OptionValues options) {
1048 StructuredGraph graphToCompile = graph == null ? parseForCompile(installedCodeOwner, compilationId, options) : graph;
1049 lastCompiledGraph = graphToCompile;
1050 DebugContext debug = graphToCompile.getDebug();
1051 try (DebugContext.Scope s = debug.scope("Compile", graphToCompile)) {
1052 assert options != null;
1053 Request<CompilationResult> request = new Request<>(graphToCompile, installedCodeOwner, getProviders(), getBackend(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL,
1054 graphToCompile.getProfilingInfo(), createSuites(options), createLIRSuites(options), compilationResult, CompilationResultBuilderFactory.Default);
|