author | kvn |
Tue, 29 Oct 2019 15:35:06 -0700 | |
changeset 58851 | f1e6442241ca |
parent 58793 | 81ad1da857f6 |
permissions | -rw-r--r-- |
43972 | 1 |
/* |
54647
c0d9bc9b4e1f
8219403: JVMCIRuntime::adjust_comp_level should be replaced
dlong
parents:
52381
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, 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.hotspot; |
|
24 |
||
25 |
import static jdk.vm.ci.common.InitTimer.timer; |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
26 |
import static jdk.vm.ci.hotspot.HotSpotJVMCICompilerFactory.CompilationLevelAdjustment.None; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
27 |
import static jdk.vm.ci.services.Services.IS_BUILDING_NATIVE_IMAGE; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
28 |
import static jdk.vm.ci.services.Services.IS_IN_NATIVE_IMAGE; |
43972 | 29 |
|
30 |
import java.io.IOException; |
|
31 |
import java.io.OutputStream; |
|
32 |
import java.io.PrintStream; |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
33 |
import java.io.Serializable; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
34 |
import java.lang.invoke.CallSite; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
35 |
import java.lang.invoke.ConstantCallSite; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
36 |
import java.lang.invoke.MethodHandle; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
37 |
import java.lang.ref.WeakReference; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
38 |
import java.util.ArrayList; |
43972 | 39 |
import java.util.Collections; |
40 |
import java.util.HashMap; |
|
41 |
import java.util.List; |
|
42 |
import java.util.Map; |
|
43 |
import java.util.Objects; |
|
44836 | 44 |
import java.util.ServiceLoader; |
50858 | 45 |
import java.util.function.Predicate; |
43972 | 46 |
|
47 |
import jdk.vm.ci.code.Architecture; |
|
48 |
import jdk.vm.ci.code.CompilationRequestResult; |
|
49 |
import jdk.vm.ci.code.CompiledCode; |
|
50 |
import jdk.vm.ci.code.InstalledCode; |
|
51 |
import jdk.vm.ci.common.InitTimer; |
|
52 |
import jdk.vm.ci.common.JVMCIError; |
|
54647
c0d9bc9b4e1f
8219403: JVMCIRuntime::adjust_comp_level should be replaced
dlong
parents:
52381
diff
changeset
|
53 |
import jdk.vm.ci.common.NativeImageReinitialize; |
43972 | 54 |
import jdk.vm.ci.meta.JavaKind; |
55 |
import jdk.vm.ci.meta.JavaType; |
|
56 |
import jdk.vm.ci.meta.ResolvedJavaType; |
|
50858 | 57 |
import jdk.vm.ci.meta.UnresolvedJavaType; |
43972 | 58 |
import jdk.vm.ci.runtime.JVMCI; |
59 |
import jdk.vm.ci.runtime.JVMCIBackend; |
|
60 |
import jdk.vm.ci.runtime.JVMCICompiler; |
|
61 |
import jdk.vm.ci.runtime.JVMCICompilerFactory; |
|
50858 | 62 |
import jdk.vm.ci.runtime.JVMCIRuntime; |
43972 | 63 |
import jdk.vm.ci.services.JVMCIServiceLocator; |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
64 |
import jdk.vm.ci.services.Services; |
54647
c0d9bc9b4e1f
8219403: JVMCIRuntime::adjust_comp_level should be replaced
dlong
parents:
52381
diff
changeset
|
65 |
|
43972 | 66 |
/** |
67 |
* HotSpot implementation of a JVMCI runtime. |
|
68 |
*/ |
|
50858 | 69 |
public final class HotSpotJVMCIRuntime implements JVMCIRuntime { |
43972 | 70 |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
71 |
/** |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
72 |
* Singleton instance lazily initialized via double-checked locking. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
73 |
*/ |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
74 |
@NativeImageReinitialize private static volatile HotSpotJVMCIRuntime instance; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
75 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
76 |
private HotSpotResolvedObjectTypeImpl javaLangObject; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
77 |
private HotSpotResolvedObjectTypeImpl javaLangInvokeMethodHandle; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
78 |
private HotSpotResolvedObjectTypeImpl constantCallSiteType; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
79 |
private HotSpotResolvedObjectTypeImpl callSiteType; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
80 |
private HotSpotResolvedObjectTypeImpl javaLangString; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
81 |
private HotSpotResolvedObjectTypeImpl javaLangClass; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
82 |
private HotSpotResolvedObjectTypeImpl throwableType; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
83 |
private HotSpotResolvedObjectTypeImpl serializableType; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
84 |
private HotSpotResolvedObjectTypeImpl cloneableType; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
85 |
private HotSpotResolvedObjectTypeImpl enumType; |
43972 | 86 |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
87 |
HotSpotResolvedObjectTypeImpl getJavaLangObject() { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
88 |
if (javaLangObject == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
89 |
javaLangObject = (HotSpotResolvedObjectTypeImpl) fromClass(Object.class); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
90 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
91 |
return javaLangObject; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
92 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
93 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
94 |
HotSpotResolvedObjectTypeImpl getJavaLangString() { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
95 |
if (javaLangString == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
96 |
javaLangString = (HotSpotResolvedObjectTypeImpl) fromClass(String.class); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
97 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
98 |
return javaLangString; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
99 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
100 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
101 |
HotSpotResolvedObjectTypeImpl getJavaLangClass() { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
102 |
if (javaLangClass == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
103 |
javaLangClass = (HotSpotResolvedObjectTypeImpl) fromClass(Class.class); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
104 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
105 |
return javaLangClass; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
106 |
} |
49351
8bb47943a8dd
8199066: [JVMCI] EagerJVMCI option should also initialize the JVMCI compiler
dnsimon
parents:
47216
diff
changeset
|
107 |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
108 |
HotSpotResolvedObjectTypeImpl getJavaLangCloneable() { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
109 |
if (cloneableType == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
110 |
cloneableType = (HotSpotResolvedObjectTypeImpl) fromClass(Cloneable.class); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
111 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
112 |
return cloneableType; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
113 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
114 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
115 |
HotSpotResolvedObjectTypeImpl getJavaLangSerializable() { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
116 |
if (serializableType == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
117 |
serializableType = (HotSpotResolvedObjectTypeImpl) fromClass(Serializable.class); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
118 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
119 |
return serializableType; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
120 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
121 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
122 |
HotSpotResolvedObjectTypeImpl getJavaLangThrowable() { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
123 |
if (throwableType == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
124 |
throwableType = (HotSpotResolvedObjectTypeImpl) fromClass(Throwable.class); |
43972 | 125 |
} |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
126 |
return throwableType; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
127 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
128 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
129 |
HotSpotResolvedObjectTypeImpl getJavaLangEnum() { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
130 |
if (enumType == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
131 |
enumType = (HotSpotResolvedObjectTypeImpl) fromClass(Enum.class); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
132 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
133 |
return enumType; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
134 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
135 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
136 |
HotSpotResolvedObjectTypeImpl getConstantCallSite() { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
137 |
if (constantCallSiteType == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
138 |
constantCallSiteType = (HotSpotResolvedObjectTypeImpl) fromClass(ConstantCallSite.class); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
139 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
140 |
return constantCallSiteType; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
141 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
142 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
143 |
HotSpotResolvedObjectTypeImpl getCallSite() { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
144 |
if (callSiteType == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
145 |
callSiteType = (HotSpotResolvedObjectTypeImpl) fromClass(CallSite.class); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
146 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
147 |
return callSiteType; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
148 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
149 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
150 |
HotSpotResolvedObjectType getMethodHandleClass() { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
151 |
if (javaLangInvokeMethodHandle == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
152 |
javaLangInvokeMethodHandle = (HotSpotResolvedObjectTypeImpl) fromClass(MethodHandle.class); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
153 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
154 |
return javaLangInvokeMethodHandle; |
43972 | 155 |
} |
156 |
||
157 |
/** |
|
158 |
* Gets the singleton {@link HotSpotJVMCIRuntime} object. |
|
159 |
*/ |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
160 |
@VMEntryPoint |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
161 |
@SuppressWarnings("try") |
43972 | 162 |
public static HotSpotJVMCIRuntime runtime() { |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
163 |
HotSpotJVMCIRuntime result = instance; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
164 |
if (result == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
165 |
// Synchronize on JVMCI.class to avoid deadlock |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
166 |
// between the two JVMCI initialization paths: |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
167 |
// HotSpotJVMCIRuntime.runtime() and JVMCI.getRuntime(). |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
168 |
synchronized (JVMCI.class) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
169 |
result = instance; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
170 |
if (result == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
171 |
try (InitTimer t = timer("HotSpotJVMCIRuntime.<init>")) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
172 |
instance = result = new HotSpotJVMCIRuntime(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
173 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
174 |
// Can only do eager initialization of the JVMCI compiler |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
175 |
// once the singleton instance is available. |
54732 | 176 |
if (result.config.getFlag("EagerJVMCI", Boolean.class)) { |
177 |
result.getCompiler(); |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
178 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
179 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
180 |
// Ensures JVMCIRuntime::_HotSpotJVMCIRuntime_instance is |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
181 |
// initialized. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
182 |
JVMCI.getRuntime(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
183 |
} |
58851 | 184 |
// Make sure all the primitive box caches are populated (required to properly |
185 |
// materialize boxed primitives |
|
55159
a38132298eda
8223320: [AOT] jck test api/javax_script/ScriptEngine/PutGet.html fails when test classes are AOTed
iveresov
parents:
54733
diff
changeset
|
186 |
// during deoptimization). |
58851 | 187 |
Boolean.valueOf(false); |
188 |
Byte.valueOf((byte) 0); |
|
189 |
Short.valueOf((short) 0); |
|
190 |
Character.valueOf((char) 0); |
|
191 |
Integer.valueOf(0); |
|
192 |
Long.valueOf(0); |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
193 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
194 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
195 |
return result; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
196 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
197 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
198 |
@VMEntryPoint |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
199 |
static Throwable decodeThrowable(String encodedThrowable) throws Throwable { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
200 |
return TranslatedException.decodeThrowable(encodedThrowable); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
201 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
202 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
203 |
@VMEntryPoint |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
204 |
static String encodeThrowable(Throwable throwable) throws Throwable { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
205 |
return TranslatedException.encodeThrowable(throwable); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
206 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
207 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
208 |
@VMEntryPoint |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
209 |
static String callToString(Object o) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
210 |
return o.toString(); |
43972 | 211 |
} |
212 |
||
213 |
/** |
|
214 |
* A list of all supported JVMCI options. |
|
215 |
*/ |
|
216 |
public enum Option { |
|
217 |
// @formatter:off |
|
44836 | 218 |
Compiler(String.class, null, "Selects the system compiler. This must match the getCompilerName() value returned " + |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
219 |
"by a jdk.vm.ci.runtime.JVMCICompilerFactory provider. " + |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
220 |
"An empty string or the value \"null\" selects a compiler " + |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
221 |
"that will raise an exception upon receiving a compilation request."), |
43972 | 222 |
// Note: The following one is not used (see InitTimer.ENABLED). It is added here |
223 |
// so that -XX:+JVMCIPrintProperties shows the option. |
|
224 |
InitTimer(Boolean.class, false, "Specifies if initialization timing is enabled."), |
|
225 |
PrintConfig(Boolean.class, false, "Prints VM configuration available via JVMCI."), |
|
55463 | 226 |
AuditHandles(Boolean.class, false, "Record stack trace along with scoped foreign object reference wrappers " + |
227 |
"to debug issue with a wrapper being used after its scope has closed."), |
|
43972 | 228 |
TraceMethodDataFilter(String.class, null, |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
229 |
"Enables tracing of profiling info when read by JVMCI.", |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
230 |
"Empty value: trace all methods", |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
231 |
"Non-empty value: trace methods whose fully qualified name contains the value."), |
43972 | 232 |
UseProfilingInformation(Boolean.class, true, ""); |
233 |
// @formatter:on |
|
234 |
||
235 |
/** |
|
236 |
* The prefix for system properties that are JVMCI options. |
|
237 |
*/ |
|
238 |
private static final String JVMCI_OPTION_PROPERTY_PREFIX = "jvmci."; |
|
239 |
||
240 |
/** |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
241 |
* Sentinel for value initialized to {@code null} since {@code null} means uninitialized. |
43972 | 242 |
*/ |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
243 |
private static final String NULL_VALUE = "NULL"; |
43972 | 244 |
|
245 |
private final Class<?> type; |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
246 |
@NativeImageReinitialize private Object value; |
43972 | 247 |
private final Object defaultValue; |
248 |
private boolean isDefault; |
|
249 |
private final String[] helpLines; |
|
250 |
||
251 |
Option(Class<?> type, Object defaultValue, String... helpLines) { |
|
252 |
assert Character.isUpperCase(name().charAt(0)) : "Option name must start with upper-case letter: " + name(); |
|
253 |
this.type = type; |
|
254 |
this.defaultValue = defaultValue; |
|
255 |
this.helpLines = helpLines; |
|
256 |
} |
|
257 |
||
258 |
@SuppressFBWarnings(value = "ES_COMPARING_STRINGS_WITH_EQ", justification = "sentinel must be String since it's a static final in an enum") |
|
259 |
private Object getValue() { |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
260 |
if (value == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
261 |
String propertyValue = Services.getSavedProperty(getPropertyName()); |
43972 | 262 |
if (propertyValue == null) { |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
263 |
this.value = defaultValue == null ? NULL_VALUE : defaultValue; |
43972 | 264 |
this.isDefault = true; |
265 |
} else { |
|
266 |
if (type == Boolean.class) { |
|
267 |
this.value = Boolean.parseBoolean(propertyValue); |
|
268 |
} else if (type == String.class) { |
|
269 |
this.value = propertyValue; |
|
270 |
} else { |
|
271 |
throw new JVMCIError("Unexpected option type " + type); |
|
272 |
} |
|
273 |
this.isDefault = false; |
|
274 |
} |
|
275 |
} |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
276 |
return value == NULL_VALUE ? null : value; |
43972 | 277 |
} |
278 |
||
279 |
/** |
|
280 |
* Gets the name of system property from which this option gets its value. |
|
281 |
*/ |
|
282 |
public String getPropertyName() { |
|
283 |
return JVMCI_OPTION_PROPERTY_PREFIX + name(); |
|
284 |
} |
|
285 |
||
286 |
/** |
|
287 |
* Returns the option's value as boolean. |
|
288 |
* |
|
289 |
* @return option's value |
|
290 |
*/ |
|
291 |
public boolean getBoolean() { |
|
292 |
return (boolean) getValue(); |
|
293 |
} |
|
294 |
||
295 |
/** |
|
296 |
* Returns the option's value as String. |
|
297 |
* |
|
298 |
* @return option's value |
|
299 |
*/ |
|
300 |
public String getString() { |
|
301 |
return (String) getValue(); |
|
302 |
} |
|
303 |
||
304 |
private static final int PROPERTY_LINE_WIDTH = 80; |
|
305 |
private static final int PROPERTY_HELP_INDENT = 10; |
|
306 |
||
307 |
/** |
|
308 |
* Prints a description of the properties used to configure shared JVMCI code. |
|
309 |
* |
|
310 |
* @param out stream to print to |
|
311 |
*/ |
|
312 |
public static void printProperties(PrintStream out) { |
|
313 |
out.println("[JVMCI properties]"); |
|
314 |
Option[] values = values(); |
|
315 |
for (Option option : values) { |
|
316 |
Object value = option.getValue(); |
|
317 |
if (value instanceof String) { |
|
318 |
value = '"' + String.valueOf(value) + '"'; |
|
319 |
} |
|
320 |
||
321 |
String name = option.getPropertyName(); |
|
322 |
String assign = option.isDefault ? "=" : ":="; |
|
323 |
String typeName = option.type.getSimpleName(); |
|
324 |
String linePrefix = String.format("%s %s %s ", name, assign, value); |
|
325 |
int typeStartPos = PROPERTY_LINE_WIDTH - typeName.length(); |
|
326 |
int linePad = typeStartPos - linePrefix.length(); |
|
327 |
if (linePad > 0) { |
|
328 |
out.printf("%s%-" + linePad + "s[%s]%n", linePrefix, "", typeName); |
|
329 |
} else { |
|
330 |
out.printf("%s[%s]%n", linePrefix, typeName); |
|
331 |
} |
|
332 |
for (String line : option.helpLines) { |
|
333 |
out.printf("%" + PROPERTY_HELP_INDENT + "s%s%n", "", line); |
|
334 |
} |
|
335 |
} |
|
336 |
} |
|
337 |
} |
|
338 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
339 |
private static HotSpotJVMCIBackendFactory findFactory(String architecture) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
340 |
Iterable<HotSpotJVMCIBackendFactory> factories = getHotSpotJVMCIBackendFactories(); |
58851 | 341 |
assert factories != null : "sanity"; |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
342 |
for (HotSpotJVMCIBackendFactory factory : factories) { |
43972 | 343 |
if (factory.getArchitecture().equalsIgnoreCase(architecture)) { |
344 |
return factory; |
|
345 |
} |
|
346 |
} |
|
347 |
||
348 |
throw new JVMCIError("No JVMCI runtime available for the %s architecture", architecture); |
|
349 |
} |
|
350 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
351 |
private static volatile List<HotSpotJVMCIBackendFactory> cachedHotSpotJVMCIBackendFactories; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
352 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
353 |
@SuppressFBWarnings(value = "LI_LAZY_INIT_UPDATE_STATIC", justification = "not sure about this") |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
354 |
private static Iterable<HotSpotJVMCIBackendFactory> getHotSpotJVMCIBackendFactories() { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
355 |
if (IS_IN_NATIVE_IMAGE || cachedHotSpotJVMCIBackendFactories != null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
356 |
return cachedHotSpotJVMCIBackendFactories; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
357 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
358 |
Iterable<HotSpotJVMCIBackendFactory> result = ServiceLoader.load(HotSpotJVMCIBackendFactory.class, ClassLoader.getSystemClassLoader()); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
359 |
if (IS_BUILDING_NATIVE_IMAGE) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
360 |
cachedHotSpotJVMCIBackendFactories = new ArrayList<>(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
361 |
for (HotSpotJVMCIBackendFactory factory : result) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
362 |
cachedHotSpotJVMCIBackendFactories.add(factory); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
363 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
364 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
365 |
return result; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
366 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
367 |
|
43972 | 368 |
/** |
369 |
* Gets the kind of a word value on the {@linkplain #getHostJVMCIBackend() host} backend. |
|
370 |
*/ |
|
371 |
public static JavaKind getHostWordKind() { |
|
372 |
return runtime().getHostJVMCIBackend().getCodeCache().getTarget().wordJavaKind; |
|
373 |
} |
|
374 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
375 |
protected final CompilerToVM compilerToVm; |
43972 | 376 |
|
377 |
protected final HotSpotVMConfigStore configStore; |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
378 |
protected final HotSpotVMConfig config; |
43972 | 379 |
private final JVMCIBackend hostBackend; |
380 |
||
381 |
private final JVMCICompilerFactory compilerFactory; |
|
382 |
private final HotSpotJVMCICompilerFactory hsCompilerFactory; |
|
383 |
private volatile JVMCICompiler compiler; |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
384 |
protected final HotSpotJVMCIReflection reflection; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
385 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
386 |
@NativeImageReinitialize private volatile boolean creatingCompiler; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
387 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
388 |
/** |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
389 |
* Cache for speeding up {@link #fromClass(Class)}. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
390 |
*/ |
54733
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
391 |
@NativeImageReinitialize private volatile ClassValue<WeakReferenceHolder<HotSpotResolvedJavaType>> resolvedJavaType; |
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
392 |
|
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
393 |
/** |
58851 | 394 |
* To avoid calling ClassValue.remove to refresh the weak reference, which under certain |
395 |
* circumstances can lead to an infinite loop, we use a permanent holder with a mutable field |
|
396 |
* that we refresh. |
|
54733
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
397 |
*/ |
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
398 |
private static class WeakReferenceHolder<T> { |
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
399 |
private volatile WeakReference<T> ref; |
58851 | 400 |
|
54733
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
401 |
WeakReferenceHolder(T value) { |
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
402 |
set(value); |
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
403 |
} |
58851 | 404 |
|
54733
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
405 |
void set(T value) { |
58851 | 406 |
ref = new WeakReference<>(value); |
54733
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
407 |
} |
58851 | 408 |
|
54733
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
409 |
T get() { |
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
410 |
return ref.get(); |
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
411 |
} |
58851 | 412 |
} |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
413 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
414 |
@NativeImageReinitialize private HashMap<Long, WeakReference<ResolvedJavaType>> resolvedJavaTypes; |
43972 | 415 |
|
416 |
/** |
|
58851 | 417 |
* Stores the value set by {@link #excludeFromJVMCICompilation(Module...)} so that it can be |
418 |
* read from the VM. |
|
43972 | 419 |
*/ |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
420 |
@SuppressWarnings("unused")// |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
421 |
@NativeImageReinitialize private Module[] excludeFromJVMCICompilation; |
54647
c0d9bc9b4e1f
8219403: JVMCIRuntime::adjust_comp_level should be replaced
dlong
parents:
52381
diff
changeset
|
422 |
|
43972 | 423 |
private final Map<Class<? extends Architecture>, JVMCIBackend> backends = new HashMap<>(); |
424 |
||
425 |
private volatile List<HotSpotVMEventListener> vmEventListeners; |
|
426 |
||
427 |
private Iterable<HotSpotVMEventListener> getVmEventListeners() { |
|
428 |
if (vmEventListeners == null) { |
|
429 |
synchronized (this) { |
|
430 |
if (vmEventListeners == null) { |
|
431 |
vmEventListeners = JVMCIServiceLocator.getProviders(HotSpotVMEventListener.class); |
|
432 |
} |
|
433 |
} |
|
434 |
} |
|
435 |
return vmEventListeners; |
|
436 |
} |
|
437 |
||
438 |
@SuppressWarnings("try") |
|
439 |
private HotSpotJVMCIRuntime() { |
|
440 |
compilerToVm = new CompilerToVM(); |
|
441 |
||
442 |
try (InitTimer t = timer("HotSpotVMConfig<init>")) { |
|
443 |
configStore = new HotSpotVMConfigStore(compilerToVm); |
|
444 |
config = new HotSpotVMConfig(configStore); |
|
445 |
} |
|
446 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
447 |
reflection = IS_IN_NATIVE_IMAGE ? new SharedLibraryJVMCIReflection() : new HotSpotJDKReflection(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
448 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
449 |
PrintStream vmLogStream = null; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
450 |
if (IS_IN_NATIVE_IMAGE) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
451 |
// Redirect System.out and System.err to HotSpot's TTY stream |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
452 |
vmLogStream = new PrintStream(getLogStream()); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
453 |
System.setOut(vmLogStream); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
454 |
System.setErr(vmLogStream); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
455 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
456 |
|
43972 | 457 |
String hostArchitecture = config.getHostArchitectureName(); |
458 |
||
459 |
HotSpotJVMCIBackendFactory factory; |
|
460 |
try (InitTimer t = timer("find factory:", hostArchitecture)) { |
|
461 |
factory = findFactory(hostArchitecture); |
|
462 |
} |
|
463 |
||
464 |
try (InitTimer t = timer("create JVMCI backend:", hostArchitecture)) { |
|
465 |
hostBackend = registerBackend(factory.createJVMCIBackend(this, null)); |
|
466 |
} |
|
467 |
||
468 |
compilerFactory = HotSpotJVMCICompilerConfig.getCompilerFactory(); |
|
469 |
if (compilerFactory instanceof HotSpotJVMCICompilerFactory) { |
|
470 |
hsCompilerFactory = (HotSpotJVMCICompilerFactory) compilerFactory; |
|
54647
c0d9bc9b4e1f
8219403: JVMCIRuntime::adjust_comp_level should be replaced
dlong
parents:
52381
diff
changeset
|
471 |
if (hsCompilerFactory.getCompilationLevelAdjustment() != None) { |
c0d9bc9b4e1f
8219403: JVMCIRuntime::adjust_comp_level should be replaced
dlong
parents:
52381
diff
changeset
|
472 |
String name = HotSpotJVMCICompilerFactory.class.getName(); |
c0d9bc9b4e1f
8219403: JVMCIRuntime::adjust_comp_level should be replaced
dlong
parents:
52381
diff
changeset
|
473 |
String msg = String.format("%s.getCompilationLevelAdjustment() is no longer supported. " + |
c0d9bc9b4e1f
8219403: JVMCIRuntime::adjust_comp_level should be replaced
dlong
parents:
52381
diff
changeset
|
474 |
"Use %s.excludeFromJVMCICompilation() instead.", name, name); |
c0d9bc9b4e1f
8219403: JVMCIRuntime::adjust_comp_level should be replaced
dlong
parents:
52381
diff
changeset
|
475 |
throw new UnsupportedOperationException(msg); |
43972 | 476 |
} |
477 |
} else { |
|
478 |
hsCompilerFactory = null; |
|
479 |
} |
|
480 |
||
481 |
if (config.getFlag("JVMCIPrintProperties", Boolean.class)) { |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
482 |
if (vmLogStream == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
483 |
vmLogStream = new PrintStream(getLogStream()); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
484 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
485 |
Option.printProperties(vmLogStream); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
486 |
compilerFactory.printProperties(vmLogStream); |
43972 | 487 |
System.exit(0); |
488 |
} |
|
489 |
||
490 |
if (Option.PrintConfig.getBoolean()) { |
|
54732 | 491 |
configStore.printConfig(); |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
492 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
493 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
494 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
495 |
HotSpotResolvedJavaType createClass(Class<?> javaClass) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
496 |
if (javaClass.isPrimitive()) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
497 |
return HotSpotResolvedPrimitiveType.forKind(JavaKind.fromJavaClass(javaClass)); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
498 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
499 |
if (IS_IN_NATIVE_IMAGE) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
500 |
try { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
501 |
return compilerToVm.lookupType(javaClass.getName().replace('.', '/'), null, true); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
502 |
} catch (ClassNotFoundException e) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
503 |
throw new JVMCIError(e); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
504 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
505 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
506 |
return compilerToVm.lookupClass(javaClass); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
507 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
508 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
509 |
private HotSpotResolvedJavaType fromClass0(Class<?> javaClass) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
510 |
if (resolvedJavaType == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
511 |
synchronized (this) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
512 |
if (resolvedJavaType == null) { |
58851 | 513 |
resolvedJavaType = new ClassValue<>() { |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
514 |
@Override |
54733
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
515 |
protected WeakReferenceHolder<HotSpotResolvedJavaType> computeValue(Class<?> type) { |
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
516 |
return new WeakReferenceHolder<>(createClass(type)); |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
517 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
518 |
}; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
519 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
520 |
} |
43972 | 521 |
} |
54733
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
522 |
|
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
523 |
WeakReferenceHolder<HotSpotResolvedJavaType> ref = resolvedJavaType.get(javaClass); |
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
524 |
HotSpotResolvedJavaType javaType = ref.get(); |
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
525 |
if (javaType == null) { |
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
526 |
/* |
58851 | 527 |
* If the referent has become null, create a new value and update cached weak reference. |
54733
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
528 |
*/ |
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
529 |
javaType = createClass(javaClass); |
28dd27202591
8218700: infinite loop in HotSpotJVMCIMetaAccessContext.fromClass after OutOfMemoryError
dlong
parents:
54732
diff
changeset
|
530 |
ref.set(javaType); |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
531 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
532 |
return javaType; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
533 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
534 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
535 |
/** |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
536 |
* Gets the JVMCI mirror for a {@link Class} object. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
537 |
* |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
538 |
* @return the {@link ResolvedJavaType} corresponding to {@code javaClass} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
539 |
*/ |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
540 |
HotSpotResolvedJavaType fromClass(Class<?> javaClass) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
541 |
if (javaClass == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
542 |
return null; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
543 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
544 |
return fromClass0(javaClass); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
545 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
546 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
547 |
synchronized HotSpotResolvedObjectTypeImpl fromMetaspace(long klassPointer, String signature) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
548 |
if (resolvedJavaTypes == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
549 |
resolvedJavaTypes = new HashMap<>(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
550 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
551 |
assert klassPointer != 0; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
552 |
WeakReference<ResolvedJavaType> klassReference = resolvedJavaTypes.get(klassPointer); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
553 |
HotSpotResolvedObjectTypeImpl javaType = null; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
554 |
if (klassReference != null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
555 |
javaType = (HotSpotResolvedObjectTypeImpl) klassReference.get(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
556 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
557 |
if (javaType == null) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
558 |
javaType = new HotSpotResolvedObjectTypeImpl(klassPointer, signature); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
559 |
resolvedJavaTypes.put(klassPointer, new WeakReference<>(javaType)); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
560 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
561 |
return javaType; |
43972 | 562 |
} |
563 |
||
564 |
private JVMCIBackend registerBackend(JVMCIBackend backend) { |
|
565 |
Class<? extends Architecture> arch = backend.getCodeCache().getTarget().arch.getClass(); |
|
566 |
JVMCIBackend oldValue = backends.put(arch, backend); |
|
567 |
assert oldValue == null : "cannot overwrite existing backend for architecture " + arch.getSimpleName(); |
|
568 |
return backend; |
|
569 |
} |
|
570 |
||
571 |
public HotSpotVMConfigStore getConfigStore() { |
|
572 |
return configStore; |
|
573 |
} |
|
574 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
575 |
public HotSpotVMConfig getConfig() { |
43972 | 576 |
return config; |
577 |
} |
|
578 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
579 |
public CompilerToVM getCompilerToVM() { |
43972 | 580 |
return compilerToVm; |
581 |
} |
|
582 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
583 |
HotSpotJVMCIReflection getReflection() { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
584 |
return reflection; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
585 |
} |
50858 | 586 |
|
587 |
/** |
|
588 |
* Gets a predicate that determines if a given type can be considered trusted for the purpose of |
|
589 |
* intrinsifying methods it declares. |
|
590 |
* |
|
591 |
* @param compilerLeafClasses classes in the leaves of the module graph comprising the JVMCI |
|
592 |
* compiler. |
|
593 |
*/ |
|
594 |
public Predicate<ResolvedJavaType> getIntrinsificationTrustPredicate(Class<?>... compilerLeafClasses) { |
|
58851 | 595 |
return new Predicate<>() { |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
596 |
@Override |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
597 |
public boolean test(ResolvedJavaType type) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
598 |
if (type instanceof HotSpotResolvedObjectTypeImpl) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
599 |
HotSpotResolvedObjectTypeImpl hsType = (HotSpotResolvedObjectTypeImpl) type; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
600 |
return compilerToVm.isTrustedForIntrinsics(hsType); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
601 |
} else { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
602 |
return false; |
51420
6bb7b8d0da76
8209535: [JVMCI] Do not swallow NoClassDefFoundError when converting JVMCI methods and fields to reflection objects
dnsimon
parents:
50858
diff
changeset
|
603 |
} |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
604 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
605 |
}; |
50858 | 606 |
} |
607 |
||
608 |
/** |
|
609 |
* Get the {@link Class} corresponding to {@code type}. |
|
610 |
* |
|
611 |
* @param type the type for which a {@link Class} is requested |
|
612 |
* @return the original Java class corresponding to {@code type} or {@code null} if this runtime |
|
613 |
* does not support mapping {@link ResolvedJavaType} instances to {@link Class} |
|
614 |
* instances |
|
615 |
*/ |
|
616 |
public Class<?> getMirror(ResolvedJavaType type) { |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
617 |
if (type instanceof HotSpotResolvedJavaType && reflection instanceof HotSpotJDKReflection) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
618 |
return ((HotSpotJDKReflection) reflection).getMirror((HotSpotResolvedJavaType) type); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
619 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
620 |
return null; |
50858 | 621 |
} |
622 |
||
623 |
@Override |
|
43972 | 624 |
public JVMCICompiler getCompiler() { |
625 |
if (compiler == null) { |
|
626 |
synchronized (this) { |
|
627 |
if (compiler == null) { |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
628 |
assert !creatingCompiler : "recursive compiler creation"; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
629 |
creatingCompiler = true; |
43972 | 630 |
compiler = compilerFactory.createCompiler(this); |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
631 |
creatingCompiler = false; |
43972 | 632 |
} |
633 |
} |
|
634 |
} |
|
635 |
return compiler; |
|
636 |
} |
|
637 |
||
50858 | 638 |
/** |
639 |
* Converts a name to a Java type. This method attempts to resolve {@code name} to a |
|
640 |
* {@link ResolvedJavaType}. |
|
641 |
* |
|
642 |
* @param name a well formed Java type in {@linkplain JavaType#getName() internal} format |
|
643 |
* @param accessingType the context of resolution which must be non-null |
|
644 |
* @param resolve specifies whether resolution failure results in an unresolved type being |
|
645 |
* return or a {@link LinkageError} being thrown |
|
646 |
* @return a Java type for {@code name} which is guaranteed to be of type |
|
647 |
* {@link ResolvedJavaType} if {@code resolve == true} |
|
648 |
* @throws LinkageError if {@code resolve == true} and the resolution failed |
|
649 |
* @throws NullPointerException if {@code accessingClass} is {@code null} |
|
650 |
*/ |
|
43972 | 651 |
public JavaType lookupType(String name, HotSpotResolvedObjectType accessingType, boolean resolve) { |
652 |
Objects.requireNonNull(accessingType, "cannot resolve type without an accessing class"); |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
653 |
return lookupTypeInternal(name, accessingType, resolve); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
654 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
655 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
656 |
JavaType lookupTypeInternal(String name, HotSpotResolvedObjectType accessingType, boolean resolve) { |
43972 | 657 |
// If the name represents a primitive type we can short-circuit the lookup. |
658 |
if (name.length() == 1) { |
|
659 |
JavaKind kind = JavaKind.fromPrimitiveOrVoidTypeChar(name.charAt(0)); |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
660 |
return HotSpotResolvedPrimitiveType.forKind(kind); |
43972 | 661 |
} |
662 |
||
663 |
// Resolve non-primitive types in the VM. |
|
664 |
HotSpotResolvedObjectTypeImpl hsAccessingType = (HotSpotResolvedObjectTypeImpl) accessingType; |
|
46972
3e88de95fccf
8186459: [JVMCI] ClassNotFoundException thrown by CompilerToVM.lookupType() should be converted to a LinkageError
dnsimon
parents:
44836
diff
changeset
|
665 |
try { |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
666 |
final HotSpotResolvedJavaType klass = compilerToVm.lookupType(name, hsAccessingType, resolve); |
43972 | 667 |
|
46972
3e88de95fccf
8186459: [JVMCI] ClassNotFoundException thrown by CompilerToVM.lookupType() should be converted to a LinkageError
dnsimon
parents:
44836
diff
changeset
|
668 |
if (klass == null) { |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
669 |
assert resolve == false : name; |
50858 | 670 |
return UnresolvedJavaType.create(name); |
46972
3e88de95fccf
8186459: [JVMCI] ClassNotFoundException thrown by CompilerToVM.lookupType() should be converted to a LinkageError
dnsimon
parents:
44836
diff
changeset
|
671 |
} |
3e88de95fccf
8186459: [JVMCI] ClassNotFoundException thrown by CompilerToVM.lookupType() should be converted to a LinkageError
dnsimon
parents:
44836
diff
changeset
|
672 |
return klass; |
3e88de95fccf
8186459: [JVMCI] ClassNotFoundException thrown by CompilerToVM.lookupType() should be converted to a LinkageError
dnsimon
parents:
44836
diff
changeset
|
673 |
} catch (ClassNotFoundException e) { |
3e88de95fccf
8186459: [JVMCI] ClassNotFoundException thrown by CompilerToVM.lookupType() should be converted to a LinkageError
dnsimon
parents:
44836
diff
changeset
|
674 |
throw (NoClassDefFoundError) new NoClassDefFoundError().initCause(e); |
43972 | 675 |
} |
676 |
} |
|
677 |
||
50858 | 678 |
@Override |
43972 | 679 |
public JVMCIBackend getHostJVMCIBackend() { |
680 |
return hostBackend; |
|
681 |
} |
|
682 |
||
50858 | 683 |
@Override |
43972 | 684 |
public <T extends Architecture> JVMCIBackend getJVMCIBackend(Class<T> arch) { |
685 |
assert arch != Architecture.class; |
|
686 |
return backends.get(arch); |
|
687 |
} |
|
688 |
||
689 |
public Map<Class<? extends Architecture>, JVMCIBackend> getJVMCIBackends() { |
|
690 |
return Collections.unmodifiableMap(backends); |
|
691 |
} |
|
692 |
||
55463 | 693 |
@SuppressWarnings("try") |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
694 |
@VMEntryPoint |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
695 |
private HotSpotCompilationRequestResult compileMethod(HotSpotResolvedJavaMethod method, int entryBCI, long compileState, int id) { |
55463 | 696 |
HotSpotCompilationRequest request = new HotSpotCompilationRequest(method, entryBCI, compileState, id); |
697 |
CompilationRequestResult result = getCompiler().compileMethod(request); |
|
43972 | 698 |
assert result != null : "compileMethod must always return something"; |
699 |
HotSpotCompilationRequestResult hsResult; |
|
700 |
if (result instanceof HotSpotCompilationRequestResult) { |
|
701 |
hsResult = (HotSpotCompilationRequestResult) result; |
|
702 |
} else { |
|
703 |
Object failure = result.getFailure(); |
|
704 |
if (failure != null) { |
|
705 |
boolean retry = false; // Be conservative with unknown compiler |
|
706 |
hsResult = HotSpotCompilationRequestResult.failure(failure.toString(), retry); |
|
707 |
} else { |
|
708 |
int inlinedBytecodes = -1; |
|
709 |
hsResult = HotSpotCompilationRequestResult.success(inlinedBytecodes); |
|
710 |
} |
|
711 |
} |
|
712 |
return hsResult; |
|
713 |
} |
|
714 |
||
715 |
/** |
|
716 |
* Shuts down the runtime. |
|
717 |
*/ |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
718 |
@VMEntryPoint |
43972 | 719 |
private void shutdown() throws Exception { |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
720 |
// Cleaners are normally only processed when a new Cleaner is |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
721 |
// instantiated so process all remaining cleaners now. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
722 |
Cleaner.clean(); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
723 |
|
43972 | 724 |
for (HotSpotVMEventListener vmEventListener : getVmEventListeners()) { |
725 |
vmEventListener.notifyShutdown(); |
|
726 |
} |
|
727 |
} |
|
728 |
||
729 |
/** |
|
730 |
* Notify on completion of a bootstrap. |
|
731 |
*/ |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
732 |
@VMEntryPoint |
43972 | 733 |
private void bootstrapFinished() throws Exception { |
734 |
for (HotSpotVMEventListener vmEventListener : getVmEventListeners()) { |
|
735 |
vmEventListener.notifyBootstrapFinished(); |
|
736 |
} |
|
737 |
} |
|
738 |
||
739 |
/** |
|
740 |
* Notify on successful install into the CodeCache. |
|
741 |
* |
|
742 |
* @param hotSpotCodeCacheProvider |
|
743 |
* @param installedCode |
|
744 |
* @param compiledCode |
|
745 |
*/ |
|
746 |
void notifyInstall(HotSpotCodeCacheProvider hotSpotCodeCacheProvider, InstalledCode installedCode, CompiledCode compiledCode) { |
|
747 |
for (HotSpotVMEventListener vmEventListener : getVmEventListeners()) { |
|
748 |
vmEventListener.notifyInstall(hotSpotCodeCacheProvider, installedCode, compiledCode); |
|
749 |
} |
|
750 |
} |
|
751 |
||
54732 | 752 |
/** |
753 |
* Writes {@code length} bytes from {@code bytes} starting at offset {@code offset} to HotSpot's |
|
754 |
* log stream. |
|
755 |
* |
|
756 |
* @param flush specifies if the log stream should be flushed after writing |
|
757 |
* @param canThrow specifies if an error in the {@code bytes}, {@code offset} or {@code length} |
|
758 |
* arguments should result in an exception or a negative return value. If |
|
759 |
* {@code false}, this call will not perform any heap allocation |
|
760 |
* @return 0 on success, -1 if {@code bytes == null && !canThrow}, -2 if {@code !canThrow} and |
|
761 |
* copying would cause access of data outside array bounds |
|
762 |
* @throws NullPointerException if {@code bytes == null} |
|
763 |
* @throws IndexOutOfBoundsException if copying would cause access of data outside array bounds |
|
764 |
*/ |
|
765 |
public int writeDebugOutput(byte[] bytes, int offset, int length, boolean flush, boolean canThrow) { |
|
766 |
return compilerToVm.writeDebugOutput(bytes, offset, length, flush, canThrow); |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
767 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
768 |
|
50858 | 769 |
/** |
770 |
* Gets an output stream that writes to HotSpot's {@code tty} stream. |
|
771 |
*/ |
|
43972 | 772 |
public OutputStream getLogStream() { |
773 |
return new OutputStream() { |
|
774 |
||
775 |
@Override |
|
776 |
public void write(byte[] b, int off, int len) throws IOException { |
|
777 |
if (b == null) { |
|
778 |
throw new NullPointerException(); |
|
779 |
} else if (off < 0 || off > b.length || len < 0 || (off + len) > b.length || (off + len) < 0) { |
|
780 |
throw new IndexOutOfBoundsException(); |
|
781 |
} else if (len == 0) { |
|
782 |
return; |
|
783 |
} |
|
54732 | 784 |
compilerToVm.writeDebugOutput(b, off, len, false, true); |
43972 | 785 |
} |
786 |
||
787 |
@Override |
|
788 |
public void write(int b) throws IOException { |
|
789 |
write(new byte[]{(byte) b}, 0, 1); |
|
790 |
} |
|
791 |
||
792 |
@Override |
|
793 |
public void flush() throws IOException { |
|
794 |
compilerToVm.flushDebugOutput(); |
|
795 |
} |
|
796 |
}; |
|
797 |
} |
|
798 |
||
799 |
/** |
|
800 |
* Collects the current values of all JVMCI benchmark counters, summed up over all threads. |
|
801 |
*/ |
|
802 |
public long[] collectCounters() { |
|
803 |
return compilerToVm.collectCounters(); |
|
804 |
} |
|
50858 | 805 |
|
806 |
/** |
|
55206 | 807 |
* @return the current number of per thread counters. May be set through |
808 |
* {@code -XX:JVMCICompilerSize=} command line option or the |
|
809 |
* {@link #setCountersSize(int)} call. |
|
810 |
*/ |
|
811 |
public int getCountersSize() { |
|
812 |
return compilerToVm.getCountersSize(); |
|
813 |
} |
|
814 |
||
815 |
/** |
|
58282
03fce7b04b42
8230395: Code checks for NULL value returned from NEW_C_HEAP_ARRAY which can not happen
dholmes
parents:
55463
diff
changeset
|
816 |
* Enlarge the number of per thread counters available. Requires a safepoint so |
55206 | 817 |
* resizing should be rare to avoid performance effects. |
818 |
* |
|
819 |
* @param newSize |
|
820 |
*/ |
|
58282
03fce7b04b42
8230395: Code checks for NULL value returned from NEW_C_HEAP_ARRAY which can not happen
dholmes
parents:
55463
diff
changeset
|
821 |
public void setCountersSize(int newSize) { |
03fce7b04b42
8230395: Code checks for NULL value returned from NEW_C_HEAP_ARRAY which can not happen
dholmes
parents:
55463
diff
changeset
|
822 |
compilerToVm.setCountersSize(newSize); |
55206 | 823 |
} |
824 |
||
825 |
/** |
|
50858 | 826 |
* The offset from the origin of an array to the first element. |
827 |
* |
|
828 |
* @return the offset in bytes |
|
829 |
*/ |
|
830 |
public int getArrayBaseOffset(JavaKind kind) { |
|
831 |
switch (kind) { |
|
832 |
case Boolean: |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
833 |
return compilerToVm.ARRAY_BOOLEAN_BASE_OFFSET; |
50858 | 834 |
case Byte: |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
835 |
return compilerToVm.ARRAY_BYTE_BASE_OFFSET; |
50858 | 836 |
case Char: |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
837 |
return compilerToVm.ARRAY_CHAR_BASE_OFFSET; |
50858 | 838 |
case Short: |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
839 |
return compilerToVm.ARRAY_SHORT_BASE_OFFSET; |
50858 | 840 |
case Int: |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
841 |
return compilerToVm.ARRAY_INT_BASE_OFFSET; |
50858 | 842 |
case Long: |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
843 |
return compilerToVm.ARRAY_LONG_BASE_OFFSET; |
50858 | 844 |
case Float: |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
845 |
return compilerToVm.ARRAY_FLOAT_BASE_OFFSET; |
50858 | 846 |
case Double: |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
847 |
return compilerToVm.ARRAY_DOUBLE_BASE_OFFSET; |
50858 | 848 |
case Object: |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
849 |
return compilerToVm.ARRAY_OBJECT_BASE_OFFSET; |
50858 | 850 |
default: |
851 |
throw new JVMCIError("%s", kind); |
|
852 |
} |
|
853 |
||
854 |
} |
|
855 |
||
856 |
/** |
|
857 |
* The scale used for the index when accessing elements of an array of this kind. |
|
858 |
* |
|
859 |
* @return the scale in order to convert the index into a byte offset |
|
860 |
*/ |
|
861 |
public int getArrayIndexScale(JavaKind kind) { |
|
862 |
switch (kind) { |
|
863 |
case Boolean: |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
864 |
return compilerToVm.ARRAY_BOOLEAN_INDEX_SCALE; |
50858 | 865 |
case Byte: |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
866 |
return compilerToVm.ARRAY_BYTE_INDEX_SCALE; |
50858 | 867 |
case Char: |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
868 |
return compilerToVm.ARRAY_CHAR_INDEX_SCALE; |
50858 | 869 |
case Short: |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
870 |
return compilerToVm.ARRAY_SHORT_INDEX_SCALE; |
50858 | 871 |
case Int: |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
872 |
return compilerToVm.ARRAY_INT_INDEX_SCALE; |
50858 | 873 |
case Long: |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
874 |
return compilerToVm.ARRAY_LONG_INDEX_SCALE; |
50858 | 875 |
case Float: |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
876 |
return compilerToVm.ARRAY_FLOAT_INDEX_SCALE; |
50858 | 877 |
case Double: |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
878 |
return compilerToVm.ARRAY_DOUBLE_INDEX_SCALE; |
50858 | 879 |
case Object: |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
880 |
return compilerToVm.ARRAY_OBJECT_INDEX_SCALE; |
50858 | 881 |
default: |
882 |
throw new JVMCIError("%s", kind); |
|
883 |
||
884 |
} |
|
885 |
} |
|
886 |
||
887 |
/** |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
888 |
* Links each native method in {@code clazz} to an implementation in the JVMCI shared library. |
50858 | 889 |
* <p> |
890 |
* A use case for this is a JVMCI compiler implementation that offers an API to Java code |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
891 |
* executing in HotSpot to exercise functionality (mostly) in the JVMCI shared library. For |
50858 | 892 |
* example: |
893 |
* |
|
894 |
* <pre> |
|
895 |
* package com.jcompile; |
|
896 |
* |
|
897 |
* import java.lang.reflect.Method; |
|
898 |
* |
|
899 |
* public static class JCompile { |
|
900 |
* static { |
|
901 |
* HotSpotJVMCIRuntime.runtime().registerNativeMethods(JCompile.class); |
|
902 |
* } |
|
903 |
* public static boolean compile(Method method, String[] options) { |
|
904 |
* // Convert to simpler data types for passing/serializing across native interface |
|
905 |
* long metaspaceMethodHandle = getHandle(method); |
|
906 |
* char[] opts = convertToCharArray(options); |
|
907 |
* return compile(metaspaceMethodHandle, opts); |
|
908 |
* } |
|
909 |
* private static native boolean compile0(long metaspaceMethodHandle, char[] options); |
|
910 |
* |
|
911 |
* private static long getHandle(Method method) { ... } |
|
912 |
* private static char[] convertToCharArray(String[] a) { ... } |
|
913 |
* } |
|
914 |
* </pre> |
|
915 |
* |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
916 |
* The implementation of the native {@code JCompile.compile0} method would be in the JVMCI |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
917 |
* shared library that contains the bulk of the JVMCI compiler. The {@code JCompile.compile0} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
918 |
* implementation will be exported as the following JNI-compatible symbol: |
50858 | 919 |
* |
920 |
* <pre> |
|
921 |
* Java_com_jcompile_JCompile_compile0 |
|
922 |
* </pre> |
|
923 |
* |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
924 |
* @see "https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/design.html#resolving_native_method_names" |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
925 |
* @see "https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/invocation.html#creating_the_vm" |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
926 |
* @see "https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/invocation.html#invocation_api_functions" |
50858 | 927 |
* |
928 |
* |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
929 |
* @return an array of 4 longs where the first value is the {@code JavaVM*} value representing |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
930 |
* the Java VM in the JVMCI shared library, and the remaining values are the first 3 |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
931 |
* pointers in the Invocation API function table (i.e., {@code JNIInvokeInterface}) |
50858 | 932 |
* @throws NullPointerException if {@code clazz == null} |
54732 | 933 |
* @throws UnsupportedOperationException if the JVMCI shared library is not enabled (i.e. |
934 |
* {@code -XX:-UseJVMCINativeLibrary}) |
|
935 |
* @throws IllegalStateException if the current execution context is the JVMCI shared library |
|
936 |
* @throws IllegalArgumentException if {@code clazz} is {@link Class#isPrimitive()} |
|
937 |
* @throws UnsatisfiedLinkError if there's a problem linking a native method in {@code clazz} |
|
938 |
* (no matching JNI symbol or the native method is already linked to a different |
|
939 |
* address) |
|
50858 | 940 |
*/ |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
941 |
public long[] registerNativeMethods(Class<?> clazz) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
942 |
return compilerToVm.registerNativeMethods(clazz); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
943 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
944 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
945 |
/** |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
946 |
* Creates or retrieves an object in the peer runtime that mirrors {@code obj}. The types whose |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
947 |
* objects can be translated are: |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
948 |
* <ul> |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
949 |
* <li>{@link HotSpotResolvedJavaMethodImpl},</li> |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
950 |
* <li>{@link HotSpotResolvedObjectTypeImpl},</li> |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
951 |
* <li>{@link HotSpotResolvedPrimitiveType},</li> |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
952 |
* <li>{@link IndirectHotSpotObjectConstantImpl},</li> |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
953 |
* <li>{@link DirectHotSpotObjectConstantImpl} and</li> |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
954 |
* <li>{@link HotSpotNmethod}</li> |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
955 |
* </ul> |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
956 |
* |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
957 |
* This mechanism can be used to pass and return values between the HotSpot and JVMCI shared |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
958 |
* library runtimes. In the receiving runtime, the value can be converted back to an object with |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
959 |
* {@link #unhand(Class, long)}. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
960 |
* |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
961 |
* @param obj an object for which an equivalent instance in the peer runtime is requested |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
962 |
* @return a JNI global reference to the mirror of {@code obj} in the peer runtime |
54732 | 963 |
* @throws UnsupportedOperationException if the JVMCI shared library is not enabled (i.e. |
964 |
* {@code -XX:-UseJVMCINativeLibrary}) |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
965 |
* @throws IllegalArgumentException if {@code obj} is not of a translatable type |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
966 |
* |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
967 |
* @see "https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/design.html#global_and_local_references" |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
968 |
*/ |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
969 |
public long translate(Object obj) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
970 |
return compilerToVm.translate(obj); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
971 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
972 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
973 |
/** |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
974 |
* Dereferences and returns the object referred to by the JNI global reference {@code handle}. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
975 |
* The global reference is deleted prior to returning. Any further use of {@code handle} is |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
976 |
* invalid. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
977 |
* |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
978 |
* @param handle a JNI global reference to an object in the current runtime |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
979 |
* @return the object referred to by {@code handle} |
54732 | 980 |
* @throws UnsupportedOperationException if the JVMCI shared library is not enabled (i.e. |
981 |
* {@code -XX:-UseJVMCINativeLibrary}) |
|
982 |
* @throws ClassCastException if the returned object cannot be cast to {@code type} |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
983 |
* |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
984 |
* @see "https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/design.html#global_and_local_references" |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
985 |
* |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
986 |
*/ |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
987 |
public <T> T unhand(Class<T> type, long handle) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
54647
diff
changeset
|
988 |
return type.cast(compilerToVm.unhand(handle)); |
50858 | 989 |
} |
54647
c0d9bc9b4e1f
8219403: JVMCIRuntime::adjust_comp_level should be replaced
dlong
parents:
52381
diff
changeset
|
990 |
|
c0d9bc9b4e1f
8219403: JVMCIRuntime::adjust_comp_level should be replaced
dlong
parents:
52381
diff
changeset
|
991 |
/** |
54732 | 992 |
* Determines if the current thread is attached to the peer runtime. |
993 |
* |
|
994 |
* @throws UnsupportedOperationException if the JVMCI shared library is not enabled (i.e. |
|
995 |
* {@code -XX:-UseJVMCINativeLibrary}) |
|
996 |
* @throws IllegalStateException if the peer runtime has not been initialized |
|
997 |
*/ |
|
998 |
public boolean isCurrentThreadAttached() { |
|
999 |
return compilerToVm.isCurrentThreadAttached(); |
|
1000 |
} |
|
1001 |
||
1002 |
/** |
|
58793 | 1003 |
* Gets the address of the HotSpot {@code JavaThread} C++ object for the current thread. This |
1004 |
* will return {@code 0} if called from an unattached JVMCI shared library thread. |
|
1005 |
*/ |
|
1006 |
public long getCurrentJavaThread() { |
|
1007 |
return compilerToVm.getCurrentJavaThread(); |
|
1008 |
} |
|
1009 |
||
1010 |
/** |
|
54732 | 1011 |
* Ensures the current thread is attached to the peer runtime. |
1012 |
* |
|
1013 |
* @param asDaemon if the thread is not yet attached, should it be attached as a daemon |
|
1014 |
* @return {@code true} if this call attached the current thread, {@code false} if the current |
|
1015 |
* thread was already attached |
|
1016 |
* @throws UnsupportedOperationException if the JVMCI shared library is not enabled (i.e. |
|
1017 |
* {@code -XX:-UseJVMCINativeLibrary}) |
|
1018 |
* @throws IllegalStateException if the peer runtime has not been initialized or there is an |
|
1019 |
* error while trying to attach the thread |
|
1020 |
*/ |
|
1021 |
public boolean attachCurrentThread(boolean asDaemon) { |
|
1022 |
return compilerToVm.attachCurrentThread(asDaemon); |
|
1023 |
} |
|
1024 |
||
1025 |
/** |
|
1026 |
* Detaches the current thread from the peer runtime. |
|
1027 |
* |
|
1028 |
* @throws UnsupportedOperationException if the JVMCI shared library is not enabled (i.e. |
|
1029 |
* {@code -XX:-UseJVMCINativeLibrary}) |
|
1030 |
* @throws IllegalStateException if the peer runtime has not been initialized or if the current |
|
1031 |
* thread is not attached or if there is an error while trying to detach the thread |
|
1032 |
*/ |
|
1033 |
public void detachCurrentThread() { |
|
1034 |
compilerToVm.detachCurrentThread(); |
|
1035 |
} |
|
1036 |
||
1037 |
/** |
|
54647
c0d9bc9b4e1f
8219403: JVMCIRuntime::adjust_comp_level should be replaced
dlong
parents:
52381
diff
changeset
|
1038 |
* Informs HotSpot that no method whose module is in {@code modules} is to be compiled |
c0d9bc9b4e1f
8219403: JVMCIRuntime::adjust_comp_level should be replaced
dlong
parents:
52381
diff
changeset
|
1039 |
* with {@link #compileMethod}. |
c0d9bc9b4e1f
8219403: JVMCIRuntime::adjust_comp_level should be replaced
dlong
parents:
52381
diff
changeset
|
1040 |
* |
c0d9bc9b4e1f
8219403: JVMCIRuntime::adjust_comp_level should be replaced
dlong
parents:
52381
diff
changeset
|
1041 |
* @param modules the set of modules containing JVMCI compiler classes |
c0d9bc9b4e1f
8219403: JVMCIRuntime::adjust_comp_level should be replaced
dlong
parents:
52381
diff
changeset
|
1042 |
*/ |
c0d9bc9b4e1f
8219403: JVMCIRuntime::adjust_comp_level should be replaced
dlong
parents:
52381
diff
changeset
|
1043 |
public void excludeFromJVMCICompilation(Module...modules) { |
c0d9bc9b4e1f
8219403: JVMCIRuntime::adjust_comp_level should be replaced
dlong
parents:
52381
diff
changeset
|
1044 |
this.excludeFromJVMCICompilation = modules.clone(); |
c0d9bc9b4e1f
8219403: JVMCIRuntime::adjust_comp_level should be replaced
dlong
parents:
52381
diff
changeset
|
1045 |
} |
55463 | 1046 |
|
1047 |
/** |
|
1048 |
* Calls {@link System#exit(int)} in HotSpot's runtime. |
|
1049 |
*/ |
|
1050 |
public void exitHotSpot(int status) { |
|
1051 |
if (!IS_IN_NATIVE_IMAGE) { |
|
1052 |
System.exit(status); |
|
1053 |
} |
|
1054 |
compilerToVm.callSystemExit(status); |
|
1055 |
} |
|
43972 | 1056 |
} |