# HG changeset patch # User Doug Simon # Date 1461841481 -7200 # Node ID 7eaa740eaca2b219493e1f665532643c0c05fb41 # Parent b05ad394cfd55d5f7eeb68380ba931298f563e6a make JVMCICompilerFactory an abstract class with security checks (JDK-8155622) diff -r b05ad394cfd5 -r 7eaa740eaca2 jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCICompilerConfig.java --- 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 ""; } + @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; } } diff -r b05ad394cfd5 -r 7eaa740eaca2 jvmci/jdk.vm.ci.runtime/src/jdk/vm/ci/runtime/JVMCICompilerFactory.java --- 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; } }