# HG changeset patch # User twisti # Date 1384922169 28800 # Node ID 36bbe5bbe8fd412b74f5e7ee47cabf42745d990d # Parent 89fbf495e58911d68a17763834b7766ffb2c8881 use AccessController.doPrivileged to enqueue compilations and shutting down the compiler diff -r 89fbf495e589 -r 36bbe5bbe8fd graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompiler.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompiler.java Wed Nov 20 01:11:10 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompiler.java Tue Nov 19 20:36:09 2013 -0800 @@ -39,12 +39,7 @@ * Compiles a method to machine code. This method is called from the VM * (VMToCompiler::compileMethod). */ - void compileMethod(long metaspaceMethod, HotSpotResolvedObjectType holder, int entryBCI, boolean blocking) throws Throwable; - - /** - * Compiles a method to machine code. - */ - void compileMethod(HotSpotResolvedJavaMethod method, int entryBCI, boolean blocking) throws Throwable; + void compileMethod(long metaspaceMethod, HotSpotResolvedObjectType holder, int entryBCI, boolean blocking); /** * Notifies this object of statistics for a completed compilation. @@ -60,7 +55,7 @@ */ void notifyCompilationDone(int id, HotSpotResolvedJavaMethod method, boolean osr, int processedBytecodes, long time, TimeUnit timeUnit, HotSpotInstalledCode installedCode); - void shutdownCompiler() throws Throwable; + void shutdownCompiler() throws Exception; void startCompiler(boolean bootstrapEnabled, long statsAddress) throws Throwable; diff -r 89fbf495e589 -r 36bbe5bbe8fd graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Wed Nov 20 01:11:10 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Tue Nov 19 20:36:09 2013 -0800 @@ -30,6 +30,7 @@ import java.io.*; import java.lang.reflect.*; +import java.security.*; import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.*; @@ -352,11 +353,18 @@ } } - public void shutdownCompiler() throws Throwable { + public void shutdownCompiler() throws Exception { try { assert !CompilationTask.withinEnqueue.get(); CompilationTask.withinEnqueue.set(Boolean.TRUE); - shutdownCompileQueue(compileQueue); + // We have to use a privileged action here because shutting down the compiler might be + // called from user code which very likely contains unprivileged frames. + AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Void run() throws Exception { + shutdownCompileQueue(compileQueue); + return null; + } + }); } finally { CompilationTask.withinEnqueue.set(Boolean.FALSE); } @@ -535,15 +543,22 @@ } @Override - public void compileMethod(long metaspaceMethod, final HotSpotResolvedObjectType holder, final int entryBCI, boolean blocking) throws Throwable { - HotSpotResolvedJavaMethod method = holder.createMethod(metaspaceMethod); - compileMethod(method, entryBCI, blocking); + public void compileMethod(long metaspaceMethod, final HotSpotResolvedObjectType holder, final int entryBCI, final boolean blocking) { + final HotSpotResolvedJavaMethod method = holder.createMethod(metaspaceMethod); + // We have to use a privileged action here because compilations are enqueued from user code + // which very likely contains unprivileged frames. + AccessController.doPrivileged(new PrivilegedAction() { + public Void run() { + compileMethod(method, entryBCI, blocking); + return null; + } + }); } /** * Compiles a method to machine code. */ - public void compileMethod(final HotSpotResolvedJavaMethod method, final int entryBCI, boolean blocking) throws Throwable { + public void compileMethod(final HotSpotResolvedJavaMethod method, final int entryBCI, final boolean blocking) { boolean osrCompilation = entryBCI != StructuredGraph.INVOCATION_ENTRY_BCI; if (osrCompilation && bootstrapRunning) { // no OSR compilations during bootstrap - the compiler is just too slow at this point,