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