author | dnsimon |
Wed, 07 Nov 2018 09:39:39 +0100 | |
changeset 52433 | a0ea20bc7af0 |
parent 50858 | 2d3e99a72541 |
child 54669 | ad45b3802d4e |
permissions | -rw-r--r-- |
43972 | 1 |
/* |
52433
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
2 |
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. |
43972 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
package jdk.vm.ci.services; |
|
24 |
||
44836 | 25 |
import java.util.Map; |
52433
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
26 |
import java.util.Set; |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
27 |
|
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
28 |
import jdk.internal.misc.VM; |
43972 | 29 |
|
30 |
/** |
|
44836 | 31 |
* Provides utilities needed by JVMCI clients. |
43972 | 32 |
*/ |
33 |
public final class Services { |
|
34 |
||
44836 | 35 |
// This class must be compilable and executable on JDK 8 since it's used in annotation |
36 |
// processors while building JDK 9 so use of API added in JDK 9 is made via reflection. |
|
37 |
||
50858 | 38 |
/** |
39 |
* Guards code that should be run when building a native image but should be excluded from |
|
40 |
* (being compiled into) the image. Such code must be directly guarded by an {@code if} |
|
41 |
* statement on this field - the guard cannot be behind a method call. |
|
42 |
*/ |
|
43 |
public static final boolean IS_BUILDING_NATIVE_IMAGE; |
|
44 |
||
45 |
/** |
|
46 |
* Guards code that should only be run in native image. Such code must be directly guarded by an |
|
47 |
* {@code if} statement on this field - the guard cannot be behind a method call. |
|
48 |
* |
|
49 |
* The value of this field seen during analysis and compilation of an SVM image must be |
|
50 |
* {@code true}. |
|
51 |
*/ |
|
52 |
public static final boolean IS_IN_NATIVE_IMAGE; |
|
53 |
||
54 |
static { |
|
55 |
/* |
|
56 |
* Prevents javac from constant folding use of this field. It is set to true in the SVM |
|
57 |
* image via substitution during image building. |
|
58 |
*/ |
|
59 |
IS_IN_NATIVE_IMAGE = false; |
|
60 |
IS_BUILDING_NATIVE_IMAGE = false; |
|
61 |
} |
|
62 |
||
43972 | 63 |
private Services() { |
64 |
} |
|
65 |
||
52433
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
66 |
static final Map<String, String> SAVED_PROPERTIES = VM.getSavedProperties(); |
44836 | 67 |
static final boolean JVMCI_ENABLED = Boolean.parseBoolean(SAVED_PROPERTIES.get("jdk.internal.vm.ci.enabled")); |
68 |
||
69 |
/** |
|
70 |
* Checks that JVMCI is enabled in the VM and throws an error if it isn't. |
|
71 |
*/ |
|
72 |
static void checkJVMCIEnabled() { |
|
73 |
if (!JVMCI_ENABLED) { |
|
74 |
throw new Error("The EnableJVMCI VM option must be true (i.e., -XX:+EnableJVMCI) to use JVMCI"); |
|
43972 | 75 |
} |
76 |
} |
|
77 |
||
78 |
/** |
|
44836 | 79 |
* Gets an unmodifiable copy of the system properties saved when {@link System} is initialized. |
43972 | 80 |
*/ |
44836 | 81 |
public static Map<String, String> getSavedProperties() { |
82 |
checkJVMCIEnabled(); |
|
43972 | 83 |
SecurityManager sm = System.getSecurityManager(); |
84 |
if (sm != null) { |
|
85 |
sm.checkPermission(new JVMCIPermission()); |
|
86 |
} |
|
44836 | 87 |
return SAVED_PROPERTIES; |
43972 | 88 |
} |
89 |
||
90 |
/** |
|
44836 | 91 |
* Causes the JVMCI subsystem to be initialized if it isn't already initialized. |
43972 | 92 |
*/ |
44836 | 93 |
public static void initializeJVMCI() { |
94 |
checkJVMCIEnabled(); |
|
95 |
try { |
|
96 |
Class.forName("jdk.vm.ci.runtime.JVMCI"); |
|
97 |
} catch (ClassNotFoundException e) { |
|
98 |
throw new InternalError(e); |
|
43972 | 99 |
} |
100 |
} |
|
52433
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
101 |
|
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
102 |
/** |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
103 |
* Opens all JVMCI packages to {@code otherModule}. |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
104 |
*/ |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
105 |
static void openJVMCITo(Module otherModule) { |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
106 |
Module jvmci = Services.class.getModule(); |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
107 |
if (jvmci != otherModule) { |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
108 |
Set<String> packages = jvmci.getPackages(); |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
109 |
for (String pkg : packages) { |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
110 |
boolean opened = jvmci.isOpen(pkg, otherModule); |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
111 |
if (!opened) { |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
112 |
jvmci.addOpens(pkg, otherModule); |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
113 |
} |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
114 |
} |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
115 |
} |
a0ea20bc7af0
8213347: [JVMCI] remove use of reflection in JVMCI
dnsimon
parents:
50858
diff
changeset
|
116 |
} |
43972 | 117 |
} |