< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/CompilationTask.java

Print this page




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 
  25 package org.graalvm.compiler.hotspot;
  26 
  27 import static org.graalvm.compiler.core.CompilationWrapper.ExceptionAction.Diagnose;
  28 import static org.graalvm.compiler.core.CompilationWrapper.ExceptionAction.ExitVM;
  29 import static org.graalvm.compiler.core.GraalCompilerOptions.CompilationBailoutAction;
  30 import static org.graalvm.compiler.core.GraalCompilerOptions.CompilationFailureAction;
  31 import static org.graalvm.compiler.core.phases.HighTier.Options.Inline;
  32 import static org.graalvm.compiler.java.BytecodeParserOptions.InlineDuringParsing;
  33 
  34 import java.io.PrintStream;
  35 import java.util.List;
  36 
  37 import jdk.internal.vm.compiler.collections.EconomicMap;
  38 import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
  39 import org.graalvm.compiler.code.CompilationResult;
  40 import org.graalvm.compiler.core.CompilationPrinter;
  41 import org.graalvm.compiler.core.CompilationWrapper;
  42 import org.graalvm.compiler.core.common.CompilationIdentifier;
  43 import org.graalvm.compiler.debug.Assertions;
  44 import org.graalvm.compiler.debug.CounterKey;
  45 import org.graalvm.compiler.debug.DebugCloseable;
  46 import org.graalvm.compiler.debug.DebugContext;
  47 import org.graalvm.compiler.debug.DebugDumpScope;
  48 import org.graalvm.compiler.debug.GraalError;
  49 import org.graalvm.compiler.debug.TimerKey;
  50 import org.graalvm.compiler.options.EnumOptionKey;
  51 import org.graalvm.compiler.options.OptionKey;
  52 import org.graalvm.compiler.options.OptionValues;
  53 import org.graalvm.compiler.printer.GraalDebugHandlersFactory;
  54 
  55 import jdk.vm.ci.code.BailoutException;
  56 import jdk.vm.ci.code.CodeCacheProvider;
  57 import jdk.vm.ci.hotspot.EventProvider;
  58 import jdk.vm.ci.hotspot.HotSpotCompilationRequest;
  59 import jdk.vm.ci.hotspot.HotSpotCompilationRequestResult;
  60 import jdk.vm.ci.hotspot.HotSpotInstalledCode;
  61 import jdk.vm.ci.hotspot.HotSpotJVMCICompilerFactory;
  62 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
  63 import jdk.vm.ci.hotspot.HotSpotNmethod;
  64 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
  65 import jdk.vm.ci.runtime.JVMCICompiler;
  66 import jdk.vm.ci.services.JVMCIServiceLocator;
  67 
  68 public class CompilationTask {
  69 
  70     private static final EventProvider eventProvider;


 128                  */
 129                 return HotSpotCompilationRequestResult.failure(bailout.getMessage(), !bailout.isPermanent());
 130             }
 131             // Log a failure event.
 132             EventProvider.CompilerFailureEvent event = eventProvider.newCompilerFailureEvent();
 133             if (event.shouldWrite()) {
 134                 event.setCompileId(getId());
 135                 event.setMessage(t.getMessage());
 136                 event.commit();
 137             }
 138 
 139             /*
 140              * Treat random exceptions from the compiler as indicating a problem compiling this
 141              * method. Report the result of toString instead of getMessage to ensure that the
 142              * exception type is included in the output in case there's no detail mesage.
 143              */
 144             return HotSpotCompilationRequestResult.failure(t.toString(), false);
 145         }
 146 
 147         @Override
 148         protected ExceptionAction lookupAction(OptionValues values, EnumOptionKey<ExceptionAction> actionKey, Throwable cause) {
 149             // Respect current action if it has been explicitly set.
 150             if (!actionKey.hasBeenSet(values)) {
 151                 if (actionKey == CompilationFailureAction) {
 152                     // Automatically exit on non-bailout during bootstrap
 153                     // or when assertions are enabled.
 154                     if (Assertions.assertionsEnabled() || compiler.getGraalRuntime().isBootstrapping()) {
 155                         return ExitVM;
 156                     }
 157                 } else if (actionKey == CompilationBailoutAction && ((BailoutException) cause).isPermanent()) {
 158                     // Get more info for permanent bailouts during bootstrap
 159                     // or when assertions are enabled.
 160                     assert CompilationBailoutAction.getDefaultValue() == ExceptionAction.Silent;
 161                     if (Assertions.assertionsEnabled() || compiler.getGraalRuntime().isBootstrapping()) {
 162                         return Diagnose;
 163                     }
 164                 }












 165             }
 166             return super.lookupAction(values, actionKey, cause);
 167         }
 168 
 169         @SuppressWarnings("try")
 170         @Override
 171         protected HotSpotCompilationRequestResult performCompilation(DebugContext debug) {
 172             HotSpotResolvedJavaMethod method = getMethod();
 173             int entryBCI = getEntryBCI();
 174             final boolean isOSR = entryBCI != JVMCICompiler.INVOCATION_ENTRY_BCI;
 175             CompilationStatistics stats = CompilationStatistics.create(options, method, isOSR);
 176 
 177             final CompilationPrinter printer = CompilationPrinter.begin(options, compilationId, method, entryBCI);
 178 
 179             try (DebugContext.Scope s = debug.scope("Compiling", new DebugDumpScope(getIdString(), true))) {
 180                 // Begin the compilation event.
 181                 compilationEvent.begin();
 182                 result = compiler.compile(method, entryBCI, useProfilingInfo, compilationId, options, debug);
 183             } catch (Throwable e) {
 184                 throw debug.handle(e);
 185             } finally {
 186                 // End the compilation event.




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 
  25 package org.graalvm.compiler.hotspot;
  26 
  27 import static org.graalvm.compiler.core.CompilationWrapper.ExceptionAction.Diagnose;
  28 import static org.graalvm.compiler.core.CompilationWrapper.ExceptionAction.ExitVM;
  29 import static org.graalvm.compiler.core.GraalCompilerOptions.CompilationBailoutAsFailure;
  30 import static org.graalvm.compiler.core.GraalCompilerOptions.CompilationFailureAction;
  31 import static org.graalvm.compiler.core.phases.HighTier.Options.Inline;
  32 import static org.graalvm.compiler.java.BytecodeParserOptions.InlineDuringParsing;
  33 
  34 import java.io.PrintStream;
  35 import java.util.List;
  36 
  37 import jdk.internal.vm.compiler.collections.EconomicMap;
  38 import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
  39 import org.graalvm.compiler.code.CompilationResult;
  40 import org.graalvm.compiler.core.CompilationPrinter;
  41 import org.graalvm.compiler.core.CompilationWrapper;
  42 import org.graalvm.compiler.core.common.CompilationIdentifier;
  43 import org.graalvm.compiler.debug.Assertions;
  44 import org.graalvm.compiler.debug.CounterKey;
  45 import org.graalvm.compiler.debug.DebugCloseable;
  46 import org.graalvm.compiler.debug.DebugContext;
  47 import org.graalvm.compiler.debug.DebugDumpScope;
  48 import org.graalvm.compiler.debug.GraalError;
  49 import org.graalvm.compiler.debug.TimerKey;

  50 import org.graalvm.compiler.options.OptionKey;
  51 import org.graalvm.compiler.options.OptionValues;
  52 import org.graalvm.compiler.printer.GraalDebugHandlersFactory;
  53 
  54 import jdk.vm.ci.code.BailoutException;
  55 import jdk.vm.ci.code.CodeCacheProvider;
  56 import jdk.vm.ci.hotspot.EventProvider;
  57 import jdk.vm.ci.hotspot.HotSpotCompilationRequest;
  58 import jdk.vm.ci.hotspot.HotSpotCompilationRequestResult;
  59 import jdk.vm.ci.hotspot.HotSpotInstalledCode;
  60 import jdk.vm.ci.hotspot.HotSpotJVMCICompilerFactory;
  61 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
  62 import jdk.vm.ci.hotspot.HotSpotNmethod;
  63 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
  64 import jdk.vm.ci.runtime.JVMCICompiler;
  65 import jdk.vm.ci.services.JVMCIServiceLocator;
  66 
  67 public class CompilationTask {
  68 
  69     private static final EventProvider eventProvider;


 127                  */
 128                 return HotSpotCompilationRequestResult.failure(bailout.getMessage(), !bailout.isPermanent());
 129             }
 130             // Log a failure event.
 131             EventProvider.CompilerFailureEvent event = eventProvider.newCompilerFailureEvent();
 132             if (event.shouldWrite()) {
 133                 event.setCompileId(getId());
 134                 event.setMessage(t.getMessage());
 135                 event.commit();
 136             }
 137 
 138             /*
 139              * Treat random exceptions from the compiler as indicating a problem compiling this
 140              * method. Report the result of toString instead of getMessage to ensure that the
 141              * exception type is included in the output in case there's no detail mesage.
 142              */
 143             return HotSpotCompilationRequestResult.failure(t.toString(), false);
 144         }
 145 
 146         @Override
 147         protected ExceptionAction lookupAction(OptionValues values, Throwable cause) {
 148             if (cause instanceof BailoutException) {
 149                 BailoutException bailout = (BailoutException) cause;
 150                 if (bailout.isPermanent()) {
 151                     // Respect current action if it has been explicitly set.
 152                     if (!CompilationBailoutAsFailure.hasBeenSet(values)) {
 153                         // Get more info for permanent bailouts during bootstrap
 154                         // or when assertions are enabled.
 155                         if (Assertions.assertionsEnabled() || compiler.getGraalRuntime().isBootstrapping()) {
 156                             return Diagnose;
 157                         }
 158 



 159                     }
 160                 }
 161                 if (!CompilationBailoutAsFailure.getValue(values)) {
 162                     return super.lookupAction(values, cause);
 163                 }
 164             }
 165 
 166             // Respect current action if it has been explicitly set.
 167             if (!CompilationFailureAction.hasBeenSet(values)) {
 168                 // Automatically exit on failure during bootstrap
 169                 // or when assertions are enabled.
 170                 if (Assertions.assertionsEnabled() || compiler.getGraalRuntime().isBootstrapping()) {
 171                     return ExitVM;
 172                 }
 173             }
 174             return super.lookupAction(values, cause);
 175         }
 176 
 177         @SuppressWarnings("try")
 178         @Override
 179         protected HotSpotCompilationRequestResult performCompilation(DebugContext debug) {
 180             HotSpotResolvedJavaMethod method = getMethod();
 181             int entryBCI = getEntryBCI();
 182             final boolean isOSR = entryBCI != JVMCICompiler.INVOCATION_ENTRY_BCI;
 183             CompilationStatistics stats = CompilationStatistics.create(options, method, isOSR);
 184 
 185             final CompilationPrinter printer = CompilationPrinter.begin(options, compilationId, method, entryBCI);
 186 
 187             try (DebugContext.Scope s = debug.scope("Compiling", new DebugDumpScope(getIdString(), true))) {
 188                 // Begin the compilation event.
 189                 compilationEvent.begin();
 190                 result = compiler.compile(method, entryBCI, useProfilingInfo, compilationId, options, debug);
 191             } catch (Throwable e) {
 192                 throw debug.handle(e);
 193             } finally {
 194                 // End the compilation event.


< prev index next >