changeset 12784:36bbe5bbe8fd

use AccessController.doPrivileged to enqueue compilations and shutting down the compiler
author twisti
date Tue, 19 Nov 2013 20:36:09 -0800
parents 89fbf495e589
children c13633a4d472 7e9c00c54866
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompiler.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java
diffstat 2 files changed, 23 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- 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;
 
--- 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<Void>() {
+                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<Void>() {
+            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,