changeset 23358:7eaa740eaca2

make JVMCICompilerFactory an abstract class with security checks (JDK-8155622)
author Doug Simon <doug.simon@oracle.com>
date Thu, 28 Apr 2016 13:04:41 +0200
parents b05ad394cfd5
children 9779df770504
files jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCICompilerConfig.java jvmci/jdk.vm.ci.runtime/src/jdk/vm/ci/runtime/JVMCICompilerFactory.java
diffstat 2 files changed, 41 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCICompilerConfig.java	Thu Apr 28 13:07:46 2016 -0700
+++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCICompilerConfig.java	Thu Apr 28 13:04:41 2016 +0200
@@ -33,16 +33,18 @@
 
 final class HotSpotJVMCICompilerConfig {
 
-    private static class DummyCompilerFactory implements JVMCICompilerFactory, JVMCICompiler {
+    private static class DummyCompilerFactory extends JVMCICompilerFactory implements JVMCICompiler {
 
         public CompilationRequestResult compileMethod(CompilationRequest request) {
             throw new JVMCIError("no JVMCI compiler selected");
         }
 
+        @Override
         public String getCompilerName() {
             return "<none>";
         }
 
+        @Override
         public JVMCICompiler createCompiler(JVMCIRuntime runtime) {
             return this;
         }
@@ -65,6 +67,7 @@
             if (compilerName != null) {
                 for (JVMCICompilerFactory f : Services.load(JVMCICompilerFactory.class)) {
                     if (f.getCompilerName().equals(compilerName)) {
+                        f.onSelection();
                         factory = f;
                     }
                 }
--- a/jvmci/jdk.vm.ci.runtime/src/jdk/vm/ci/runtime/JVMCICompilerFactory.java	Thu Apr 28 13:07:46 2016 -0700
+++ b/jvmci/jdk.vm.ci.runtime/src/jdk/vm/ci/runtime/JVMCICompilerFactory.java	Thu Apr 28 13:04:41 2016 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,20 +23,48 @@
 package jdk.vm.ci.runtime;
 
 /**
- * Factory for a JVMCI compiler.
+ * Service-provider class for creating JVMCI compilers.
  */
-public interface JVMCICompilerFactory {
+public abstract class JVMCICompilerFactory {
+
+    private static Void checkPermission() {
+        SecurityManager sm = System.getSecurityManager();
+        if (sm != null)
+            sm.checkPermission(new RuntimePermission("jvmci"));
+        return null;
+    }
+
+    @SuppressWarnings("unused")
+    private JVMCICompilerFactory(Void ignore) {
+    }
 
     /**
-     * Get the name of this compiler. The compiler will be selected when the jvmci.compiler system
-     * property is equal to this name.
+     * Initializes a new instance of this class.
+     *
+     * @throws SecurityException if a security manager has been installed and it denies
+     *             {@code RuntimePermission("jvmci")}
      */
-    String getCompilerName();
+    protected JVMCICompilerFactory() {
+        this(checkPermission());
+    }
 
     /**
-     * Create a new instance of the {@link JVMCICompiler}.
+     * Get the name of this compiler. The name is used by JVMCI to determine which factory to use.
      */
-    JVMCICompiler createCompiler(JVMCIRuntime runtime);
+    public abstract String getCompilerName();
+
+    /**
+     * Notifies this object that it has been selected to {@linkplain #createCompiler(JVMCIRuntime)
+     * create} a compiler and it should now perform any heavy weight initialization that it deferred
+     * during construction.
+     */
+    public void onSelection() {
+    }
+
+    /**
+     * Create a new instance of a {@link JVMCICompiler}.
+     */
+    public abstract JVMCICompiler createCompiler(JVMCIRuntime runtime);
 
     /**
      * In a tiered system it might be advantageous for startup to keep the JVMCI compiler from
@@ -47,7 +75,7 @@
      * @return 0 or more Strings identifying packages that should by compiled by the first tier
      *         only.
      */
-    default String[] getTrivialPrefixes() {
+    public String[] getTrivialPrefixes() {
         return null;
     }
 }