changeset 22877:b4f50acabc27

Use try/catch around all the logic in a CompilationTask
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Thu, 22 Oct 2015 11:52:54 -0700
parents cc788c1189fc
children f564fd10b118
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java
diffstat 1 files changed, 41 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java	Thu Oct 22 16:21:29 2015 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java	Thu Oct 22 11:52:54 2015 -0700
@@ -248,39 +248,49 @@
                 System.exit(-1);
             }
         } finally {
-            int compiledBytecodes = 0;
-            int codeSize = 0;
-            if (result != null) {
-                compiledBytecodes = result.getBytecodeSize();
-            }
-            if (installedCode != null) {
-                codeSize = installedCode.getSize();
-            }
-            CompiledBytecodes.add(compiledBytecodes);
+            try {
+                int compiledBytecodes = 0;
+                int codeSize = 0;
+                if (result != null) {
+                    compiledBytecodes = result.getBytecodeSize();
+                }
+                if (installedCode != null) {
+                    codeSize = installedCode.getSize();
+                }
+                CompiledBytecodes.add(compiledBytecodes);
 
-            // Log a compilation event.
-            if (compilationEvent.shouldWrite()) {
-                compilationEvent.setMethod(method.format("%H.%n(%p)"));
-                compilationEvent.setCompileId(getId());
-                compilationEvent.setCompileLevel(config.compilationLevelFullOptimization);
-                compilationEvent.setSucceeded(result != null && installedCode != null);
-                compilationEvent.setIsOsr(isOSR);
-                compilationEvent.setCodeSize(codeSize);
-                compilationEvent.setInlinedBytes(compiledBytecodes);
-                compilationEvent.commit();
-            }
+                // Log a compilation event.
+                if (compilationEvent.shouldWrite()) {
+                    compilationEvent.setMethod(method.format("%H.%n(%p)"));
+                    compilationEvent.setCompileId(getId());
+                    compilationEvent.setCompileLevel(config.compilationLevelFullOptimization);
+                    compilationEvent.setSucceeded(result != null && installedCode != null);
+                    compilationEvent.setIsOsr(isOSR);
+                    compilationEvent.setCodeSize(codeSize);
+                    compilationEvent.setInlinedBytes(compiledBytecodes);
+                    compilationEvent.commit();
+                }
 
-            long jvmciEnv = request.getJvmciEnv();
-            if (jvmciEnv != 0) {
-                long ctask = UNSAFE.getAddress(jvmciEnv + config.jvmciEnvTaskOffset);
-                assert ctask != 0L;
-                UNSAFE.putInt(ctask + config.compileTaskNumInlinedBytecodesOffset, compiledBytecodes);
-            }
-            long compilationTime = System.nanoTime() - startCompilationTime;
-            if ((config.ciTime || config.ciTimeEach) && installedCode != null) {
-                long timeUnitsPerSecond = TimeUnit.NANOSECONDS.convert(1, TimeUnit.SECONDS);
-                final HotSpotCodeCacheProvider codeCache = (HotSpotCodeCacheProvider) jvmciRuntime.getHostJVMCIBackend().getCodeCache();
-                codeCache.notifyCompilationStatistics(getId(), method, entryBCI != JVMCICompiler.INVOCATION_ENTRY_BCI, compiledBytecodes, compilationTime, timeUnitsPerSecond, installedCode);
+                long jvmciEnv = request.getJvmciEnv();
+                if (jvmciEnv != 0) {
+                    long ctask = UNSAFE.getAddress(jvmciEnv + config.jvmciEnvTaskOffset);
+                    assert ctask != 0L;
+                    UNSAFE.putInt(ctask + config.compileTaskNumInlinedBytecodesOffset, compiledBytecodes);
+                }
+                long compilationTime = System.nanoTime() - startCompilationTime;
+                if ((config.ciTime || config.ciTimeEach) && installedCode != null) {
+                    long timeUnitsPerSecond = TimeUnit.NANOSECONDS.convert(1, TimeUnit.SECONDS);
+                    final HotSpotCodeCacheProvider codeCache = (HotSpotCodeCacheProvider) jvmciRuntime.getHostJVMCIBackend().getCodeCache();
+                    codeCache.notifyCompilationStatistics(getId(), method, entryBCI != JVMCICompiler.INVOCATION_ENTRY_BCI, compiledBytecodes, compilationTime, timeUnitsPerSecond, installedCode);
+                }
+            } catch (Throwable t) {
+                // Don't allow exceptions during recording of statistics to leak out
+                if (PrintStackTraceOnException.getValue() || ExitVMOnException.getValue()) {
+                    t.printStackTrace(TTY.out);
+                }
+                if (ExitVMOnException.getValue()) {
+                    System.exit(-1);
+                }
             }
         }
     }