OpenJDK / graal / graal-jvmci-8
changeset 2925:b78b4ae0757c
Also call Compiler shutdown hook in case of System.exit call. Draft VMExits.Sandbox class.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Thu, 09 Jun 2011 14:42:24 +0200 |
parents | 9d4e5b492521 |
children | 0e3ec0a4eda4 89cb8a8578f9 bf15ed11c2bc |
files | graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/VMExits.java graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/VMExitsNative.java src/share/vm/classfile/vmSymbols.hpp src/share/vm/graal/graalCompiler.cpp src/share/vm/graal/graalVMExits.cpp src/share/vm/graal/graalVMExits.hpp src/share/vm/prims/jni.cpp src/share/vm/runtime/java.cpp src/share/vm/runtime/thread.cpp |
diffstat | 9 files changed, 103 insertions(+), 54 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/VMExits.java Thu Jun 09 14:02:28 2011 +0200 +++ b/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/VMExits.java Thu Jun 09 14:42:24 2011 +0200 @@ -57,6 +57,7 @@ CiConstant createCiConstantObject(Object object); - void shutdownCompiler(); + void shutdownCompiler() throws Throwable; + void startCompiler(); }
--- a/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/VMExitsNative.java Thu Jun 09 14:02:28 2011 +0200 +++ b/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/VMExitsNative.java Thu Jun 09 14:42:24 2011 +0200 @@ -71,20 +71,48 @@ private static Set<String> compiledMethods = new HashSet<String>(); - public void shutdownCompiler() { + private static PrintStream originalOut; + private static PrintStream originalErr; + + public void startCompiler() { + originalOut = System.out; + originalErr = System.err; + TTY.println("startCompiler: " + originalOut); + } + + public void shutdownCompiler() throws Throwable { compileMethods = false; - if (GraalOptions.Meter) { - GraalMetrics.print(); - } - if (GraalOptions.Time) { - GraalTimers.print(); - } - if (PrintGCStats) { - printGCStats(); - } + new Sandbox() { + + @Override + public void run() { + if (GraalOptions.Meter) { + + GraalMetrics.print(); + } + if (GraalOptions.Time) { + GraalTimers.print(); + } + if (PrintGCStats) { + printGCStats(); + } + } + }.start(); } + public abstract class Sandbox { + + public void start() throws Throwable { + PrintStream oldOut = System.out; + PrintStream oldErr = System.err; + run(); + System.setOut(oldOut); + System.setErr(oldErr); + } + + protected abstract void run() throws Throwable; + } public static void printGCStats() { long totalGarbageCollections = 0; @@ -107,51 +135,56 @@ } @Override - public void compileMethod(long methodVmId, String name, int entryBCI) throws Throwable { + public void compileMethod(final long methodVmId, final String name, final int entryBCI) throws Throwable { if (!compileMethods) { return; } - try { - HotSpotMethodResolved riMethod = new HotSpotMethodResolved(compiler, methodVmId, name); - CiResult result = compiler.getCompiler().compileMethod(riMethod, -1, null, null); - if (LogCompiledMethods) { - String qualifiedName = CiUtil.toJavaName(riMethod.holder()) + "::" + riMethod.name(); - compiledMethods.add(qualifiedName); - } + new Sandbox() { + @Override + public void run() throws Throwable { + try { + HotSpotMethodResolved riMethod = new HotSpotMethodResolved(compiler, methodVmId, name); + CiResult result = compiler.getCompiler().compileMethod(riMethod, -1, null, null); + if (LogCompiledMethods) { + String qualifiedName = CiUtil.toJavaName(riMethod.holder()) + "::" + riMethod.name(); + compiledMethods.add(qualifiedName); + } - if (result.bailout() != null) { - Throwable cause = result.bailout().getCause(); - if (!GraalOptions.QuietBailout) { + if (result.bailout() != null) { + Throwable cause = result.bailout().getCause(); + if (!GraalOptions.QuietBailout) { + StringWriter out = new StringWriter(); + result.bailout().printStackTrace(new PrintWriter(out)); + TTY.println("Bailout:\n" + out.toString()); + if (cause != null) { + Logger.info("Trace for cause: "); + for (StackTraceElement e : cause.getStackTrace()) { + String current = e.getClassName() + "::" + e.getMethodName(); + String type = ""; + if (compiledMethods.contains(current)) { + type = "compiled"; + } + Logger.info(String.format("%-10s %3d %s", type, e.getLineNumber(), current)); + } + } + } + String s = result.bailout().getMessage(); + if (cause != null) { + s = cause.getMessage(); + } + compiler.getVMEntries().recordBailout(s); + } else { + HotSpotTargetMethod.installMethod(compiler, riMethod, result.targetMethod()); + } + } catch (Throwable t) { StringWriter out = new StringWriter(); - result.bailout().printStackTrace(new PrintWriter(out)); - TTY.println("Bailout:\n" + out.toString()); - if (cause != null) { - Logger.info("Trace for cause: "); - for (StackTraceElement e : cause.getStackTrace()) { - String current = e.getClassName() + "::" + e.getMethodName(); - String type = ""; - if (compiledMethods.contains(current)) { - type = "compiled"; - } - Logger.info(String.format("%-10s %3d %s", type, e.getLineNumber(), current)); - } - } + t.printStackTrace(new PrintWriter(out)); + TTY.println("Compilation interrupted: (" + name + ")\n" + out.toString()); + throw t; } - String s = result.bailout().getMessage(); - if (cause != null) { - s = cause.getMessage(); - } - compiler.getVMEntries().recordBailout(s); - } else { - HotSpotTargetMethod.installMethod(compiler, riMethod, result.targetMethod()); } - } catch (Throwable t) { - StringWriter out = new StringWriter(); - t.printStackTrace(new PrintWriter(out)); - TTY.println("Compilation interrupted: (" + name + ")\n" + out.toString()); - throw t; - } + }.start(); } @Override
--- a/src/share/vm/classfile/vmSymbols.hpp Thu Jun 09 14:02:28 2011 +0200 +++ b/src/share/vm/classfile/vmSymbols.hpp Thu Jun 09 14:42:24 2011 +0200 @@ -296,6 +296,7 @@ template(com_sun_cri_ci_CiConstant, "com/sun/cri/ci/CiConstant") \ template(com_sun_cri_ci_CiKind, "com/sun/cri/ci/CiKind") \ template(com_sun_cri_ci_CiRuntimeCall, "com/sun/cri/ci/CiRuntimeCall") \ + template(startCompiler_name, "startCompiler") \ template(shutdownCompiler_name, "shutdownCompiler") \ template(compileMethod_name, "compileMethod") \ template(compileMethod_signature, "(JLjava/lang/String;I)V") \
--- a/src/share/vm/graal/graalCompiler.cpp Thu Jun 09 14:02:28 2011 +0200 +++ b/src/share/vm/graal/graalCompiler.cpp Thu Jun 09 14:42:24 2011 +0200 @@ -68,6 +68,7 @@ { VM_ENTRY_MARK; HandleMark hm; + VMExits::initializeCompiler(); VMExits::setDefaultOptions(); for (int i = 0; i < Arguments::num_graal_args(); ++i) { const char* arg = Arguments::graal_args_array()[i]; @@ -78,8 +79,6 @@ vm_abort(false); } } - - VMExits::initializeCompiler(); } }
--- a/src/share/vm/graal/graalVMExits.cpp Thu Jun 09 14:02:28 2011 +0200 +++ b/src/share/vm/graal/graalVMExits.cpp Thu Jun 09 14:42:24 2011 +0200 @@ -73,6 +73,8 @@ JavaValue result(T_VOID); JavaCalls::call_static(&result, compilerImplKlass, vmSymbols::initialize_name(), vmSymbols::void_method_signature(), Thread::current()); check_pending_exception("Couldn't initialize compiler"); + + startCompiler(); } jboolean VMExits::setOption(Handle option) { @@ -119,6 +121,14 @@ check_pending_exception("Error while calling shutdownCompiler"); } +void VMExits::startCompiler() { + JavaThread* THREAD = JavaThread::current(); + JavaValue result(T_VOID); + JavaCallArguments args; + args.push_oop(instance()); + JavaCalls::call_interface(&result, vmExitsKlass(), vmSymbols::startCompiler_name(), vmSymbols::void_method_signature(), &args, THREAD); + check_pending_exception("Error while calling startCompiler"); +} oop VMExits::createRiMethodResolved(jlong vmId, Handle name, TRAPS) { assert(!name.is_null(), "just checking");
--- a/src/share/vm/graal/graalVMExits.hpp Thu Jun 09 14:02:28 2011 +0200 +++ b/src/share/vm/graal/graalVMExits.hpp Thu Jun 09 14:42:24 2011 +0200 @@ -55,6 +55,9 @@ // public abstract void shutdownCompiler(); static void shutdownCompiler(); + + // public abstract void startCompiler(); + static void startCompiler(); // public abstract RiMethod createRiMethodResolved(long vmId, String name); static oop createRiMethodResolved(jlong vmId, Handle name, TRAPS);
--- a/src/share/vm/prims/jni.cpp Thu Jun 09 14:02:28 2011 +0200 +++ b/src/share/vm/prims/jni.cpp Thu Jun 09 14:42:24 2011 +0200 @@ -29,6 +29,7 @@ #include "classfile/systemDictionary.hpp" #include "classfile/vmSymbols.hpp" #include "interpreter/linkResolver.hpp" +#include "graal/graalCompiler.hpp" #include "memory/allocation.inline.hpp" #include "memory/gcLocker.inline.hpp" #include "memory/oopFactory.hpp"
--- a/src/share/vm/runtime/java.cpp Thu Jun 09 14:02:28 2011 +0200 +++ b/src/share/vm/runtime/java.cpp Thu Jun 09 14:42:24 2011 +0200 @@ -30,6 +30,7 @@ #include "compiler/compileBroker.hpp" #include "compiler/compilerOracle.hpp" #include "interpreter/bytecodeHistogram.hpp" +#include "graal/graalCompiler.hpp" #include "memory/genCollectedHeap.hpp" #include "memory/oopFactory.hpp" #include "memory/universe.hpp" @@ -418,6 +419,10 @@ #define BEFORE_EXIT_DONE 2 static jint volatile _before_exit_status = BEFORE_EXIT_NOT_RUN; + if (UseGraal) { + GraalCompiler::instance()->exit(); + } + // Note: don't use a Mutex to guard the entire before_exit(), as // JVMTI post_thread_end_event and post_vm_death_event will run native code. // A CAS or OSMutex would work just fine but then we need to manipulate
--- a/src/share/vm/runtime/thread.cpp Thu Jun 09 14:02:28 2011 +0200 +++ b/src/share/vm/runtime/thread.cpp Thu Jun 09 14:42:24 2011 +0200 @@ -29,7 +29,6 @@ #include "classfile/vmSymbols.hpp" #include "code/scopeDesc.hpp" #include "compiler/compileBroker.hpp" -#include "graal/graalCompiler.hpp" #include "interpreter/interpreter.hpp" #include "interpreter/linkResolver.hpp" #include "jvmtifiles/jvmtiEnv.hpp" @@ -3660,9 +3659,6 @@ thread->invoke_shutdown_hooks(); } - if (UseGraal) { - GraalCompiler::instance()->exit(); - } before_exit(thread); thread->exit(true);