comparison graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/CompilerToVM.java @ 21551:5324104ac4f3

moved com.oracle.graal.hotspot.jvmci classes to com.oracle.jvmci.hotspot module (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Tue, 26 May 2015 17:13:37 +0200
parents
children
comparison
equal deleted inserted replaced
21550:f48a6cea31eb 21551:5324104ac4f3
1 /*
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
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
24 package com.oracle.jvmci.hotspot;
25
26 import sun.misc.*;
27
28 import com.oracle.graal.api.code.*;
29 import com.oracle.graal.api.meta.*;
30 import com.oracle.graal.hotspotvmconfig.*;
31
32 /**
33 * Calls from Java into HotSpot.
34 */
35 public interface CompilerToVM {
36
37 /**
38 * Copies the original bytecode of a given method into a new byte array and returns it.
39 *
40 * @param metaspaceMethod the metaspace Method object
41 * @return a new byte array containing the original bytecode
42 */
43 byte[] getBytecode(long metaspaceMethod);
44
45 int exceptionTableLength(long metaspaceMethod);
46
47 long exceptionTableStart(long metaspaceMethod);
48
49 /**
50 * Determines if a given metaspace Method object has balanced monitors.
51 *
52 * @param metaspaceMethod the metaspace Method object to query
53 * @return true if the method has balanced monitors
54 */
55 boolean hasBalancedMonitors(long metaspaceMethod);
56
57 /**
58 * Determines if a given metaspace Method can be inlined. A method may not be inlinable for a
59 * number of reasons such as:
60 * <ul>
61 * <li>a CompileOracle directive may prevent inlining or compilation of methods</li>
62 * <li>the method may have a bytecode breakpoint set</li>
63 * <li>the method may have other bytecode features that require special handling by the VM</li>
64 * </ul>
65 *
66 * @param metaspaceMethod the metaspace Method object to query
67 * @return true if the method can be inlined
68 */
69 boolean canInlineMethod(long metaspaceMethod);
70
71 /**
72 * Determines if a given metaspace Method should be inlined at any cost. This could be because:
73 * <ul>
74 * <li>a CompileOracle directive may forces inlining of this methods</li>
75 * <li>an annotation forces inlining of this method</li>
76 * </ul>
77 *
78 * @param metaspaceMethod the metaspace Method object to query
79 * @return true if the method should be inlined
80 */
81 boolean shouldInlineMethod(long metaspaceMethod);
82
83 /**
84 * Used to implement {@link ResolvedJavaType#findUniqueConcreteMethod(ResolvedJavaMethod)}.
85 *
86 * @param metaspaceMethod the metaspace Method on which to based the search
87 * @param actualHolderMetaspaceKlass the best known type of receiver
88 * @return the metaspace Method result or 0 is there is no unique concrete method for
89 * {@code metaspaceMethod}
90 */
91 long findUniqueConcreteMethod(long actualHolderMetaspaceKlass, long metaspaceMethod);
92
93 /**
94 * Returns the implementor for the given interface class, if there is a single implementor.
95 *
96 * @param metaspaceKlass the metaspace klass to get the implementor for
97 * @return the implementor as metaspace klass pointer if there is a single implementor, null if
98 * there is no implementor, or the input metaspace klass pointer ({@code metaspaceKlass}
99 * ) itself if there is more than one implementor.
100 */
101 long getKlassImplementor(long metaspaceKlass);
102
103 /**
104 * Determines if a given metaspace method is ignored by security stack walks.
105 *
106 * @param metaspaceMethod the metaspace Method object
107 * @return true if the method is ignored
108 */
109 boolean methodIsIgnoredBySecurityStackWalk(long metaspaceMethod);
110
111 /**
112 * Converts a name to a metaspace klass.
113 *
114 * @param name a well formed Java type in {@linkplain JavaType#getName() internal} format
115 * @param accessingClass the context of resolution (must not be null)
116 * @param resolve force resolution to a {@link ResolvedJavaType}. If true, this method will
117 * either return a {@link ResolvedJavaType} or throw an exception
118 * @return a metaspace klass for {@code name}
119 * @throws LinkageError if {@code resolve == true} and the resolution failed
120 */
121 long lookupType(String name, Class<?> accessingClass, boolean resolve);
122
123 Object resolveConstantInPool(long metaspaceConstantPool, int cpi);
124
125 Object resolvePossiblyCachedConstantInPool(long metaspaceConstantPool, int cpi);
126
127 int lookupNameAndTypeRefIndexInPool(long metaspaceConstantPool, int cpi);
128
129 String lookupNameRefInPool(long metaspaceConstantPool, int cpi);
130
131 String lookupSignatureRefInPool(long metaspaceConstantPool, int cpi);
132
133 int lookupKlassRefIndexInPool(long metaspaceConstantPool, int cpi);
134
135 long constantPoolKlassAt(long metaspaceConstantPool, int cpi);
136
137 /**
138 * Looks up a class entry in a constant pool.
139 *
140 * @param metaspaceConstantPool metaspace constant pool pointer
141 * @param cpi constant pool index
142 * @return a metaspace Klass for a resolved method entry, a metaspace Symbol otherwise (with
143 * tagging)
144 */
145 long lookupKlassInPool(long metaspaceConstantPool, int cpi);
146
147 /**
148 * Looks up a method entry in a constant pool.
149 *
150 * @param metaspaceConstantPool metaspace constant pool pointer
151 * @param cpi constant pool index
152 * @return a metaspace Method for a resolved method entry, 0 otherwise
153 */
154 long lookupMethodInPool(long metaspaceConstantPool, int cpi, byte opcode);
155
156 /**
157 * Looks up a field entry in a constant pool and attempts to resolve it. The values returned in
158 * {@code info} are:
159 *
160 * <pre>
161 * [(int) flags, // only valid if field is resolved
162 * (int) offset] // only valid if field is resolved
163 * </pre>
164 *
165 * @param metaspaceConstantPool metaspace constant pool pointer
166 * @param cpi constant pool index
167 * @param info an array in which the details of the field are returned
168 * @return true if the field is resolved
169 */
170 long resolveField(long metaspaceConstantPool, int cpi, byte opcode, long[] info);
171
172 int constantPoolRemapInstructionOperandFromCache(long metaspaceConstantPool, int cpi);
173
174 Object lookupAppendixInPool(long metaspaceConstantPool, int cpi);
175
176 /**
177 * Installs the result of a compilation into the code cache.
178 *
179 * @param compiledCode the result of a compilation
180 * @param code the details of the installed CodeBlob are written to this object
181 * @return the outcome of the installation which will be one of
182 * {@link HotSpotVMConfig#codeInstallResultOk},
183 * {@link HotSpotVMConfig#codeInstallResultCacheFull},
184 * {@link HotSpotVMConfig#codeInstallResultCodeTooLarge},
185 * {@link HotSpotVMConfig#codeInstallResultDependenciesFailed} or
186 * {@link HotSpotVMConfig#codeInstallResultDependenciesInvalid}.
187 */
188 int installCode(HotSpotCompiledCode compiledCode, InstalledCode code, SpeculationLog speculationLog);
189
190 /**
191 * Notifies the VM of statistics for a completed compilation.
192 *
193 * @param id the identifier of the compilation
194 * @param method the method compiled
195 * @param osr specifies if the compilation was for on-stack-replacement
196 * @param processedBytecodes the number of bytecodes processed during the compilation, including
197 * the bytecodes of all inlined methods
198 * @param time the amount time spent compiling {@code method}
199 * @param timeUnitsPerSecond the granularity of the units for the {@code time} value
200 * @param installedCode the nmethod installed as a result of the compilation
201 */
202 void notifyCompilationStatistics(int id, HotSpotResolvedJavaMethod method, boolean osr, int processedBytecodes, long time, long timeUnitsPerSecond, InstalledCode installedCode);
203
204 void resetCompilationStatistics();
205
206 void initializeConfiguration(HotSpotVMConfig config);
207
208 long resolveMethod(long metaspaceKlassExactReceiver, long metaspaceMethod, long metaspaceKlassCaller);
209
210 long getClassInitializer(long metaspaceKlass);
211
212 boolean hasFinalizableSubclass(long metaspaceKlass);
213
214 /**
215 * Gets the metaspace Method object corresponding to a given {@link Class} object and slot
216 * number.
217 *
218 * @param holder method holder
219 * @param slot slot number of the method
220 * @return the metaspace Method
221 */
222 long getMetaspaceMethod(Class<?> holder, int slot);
223
224 long getMaxCallTargetOffset(long address);
225
226 String disassembleCodeBlob(long codeBlob);
227
228 StackTraceElement getStackTraceElement(long metaspaceMethod, int bci);
229
230 Object executeCompiledMethod(Object arg1, Object arg2, Object arg3, InstalledCode hotspotInstalledCode) throws InvalidInstalledCodeException;
231
232 Object executeCompiledMethodVarargs(Object[] args, InstalledCode hotspotInstalledCode) throws InvalidInstalledCodeException;
233
234 long[] getLineNumberTable(long metaspaceMethod);
235
236 long getLocalVariableTableStart(long metaspaceMethod);
237
238 int getLocalVariableTableLength(long metaspaceMethod);
239
240 String getFileName(HotSpotResolvedJavaType method);
241
242 Class<?> getJavaMirror(long metaspaceKlass);
243
244 long readUnsafeKlassPointer(Object o);
245
246 /**
247 * Reads an object pointer within a VM data structure. That is, any {@link HotSpotVMField} whose
248 * {@link HotSpotVMField#type() type} is {@code "oop"} (e.g.,
249 * {@code ArrayKlass::_component_mirror}, {@code Klass::_java_mirror},
250 * {@code JavaThread::_threadObj}).
251 *
252 * Note that {@link Unsafe#getObject(Object, long)} cannot be used for this since it does a
253 * {@code narrowOop} read if the VM is using compressed oops whereas oops within VM data
254 * structures are (currently) always uncompressed.
255 *
256 * @param address address of an oop field within a VM data structure
257 */
258 Object readUncompressedOop(long address);
259
260 void doNotInlineOrCompile(long metaspaceMethod);
261
262 /**
263 * Invalidates the profiling information and restarts profiling upon the next invocation.
264 *
265 * @param metaspaceMethod the metaspace Method object
266 */
267 void reprofile(long metaspaceMethod);
268
269 void invalidateInstalledCode(InstalledCode hotspotInstalledCode);
270
271 /**
272 * Collects the current values of all Graal benchmark counters, summed up over all threads.
273 */
274 long[] collectCounters();
275
276 boolean isMature(long metaspaceMethodData);
277
278 /**
279 * Generate a unique id to identify the result of the compile.
280 */
281 int allocateCompileId(long metaspaceMethod, int entryBCI);
282
283 /**
284 * Gets the names of the supported GPU architectures.
285 *
286 * @return a comma separated list of names
287 */
288 String getGPUs();
289
290 /**
291 *
292 * @param metaspaceMethod the method to check
293 * @param entryBCI
294 * @param level the compilation level
295 * @return true if the {@code metaspaceMethod} has code for {@code level}
296 */
297 boolean hasCompiledCodeForOSR(long metaspaceMethod, int entryBCI, int level);
298
299 /**
300 * Fetch the time stamp used for printing inside hotspot. It's relative to VM start to that all
301 * events can be ordered.
302 *
303 * @return milliseconds since VM start
304 */
305 long getTimeStamp();
306
307 /**
308 * Gets the value of a metaspace {@code Symbol} as a String.
309 *
310 * @param metaspaceSymbol
311 */
312 String getSymbol(long metaspaceSymbol);
313
314 /**
315 * Looks for the next Java stack frame with the given method.
316 *
317 * @param frame the starting point of the search, where {@code null} refers to the topmost frame
318 * @param methods the metaspace methods to look for, where {@code null} means that any frame is
319 * returned
320 * @return the frame, or {@code null} if the end of the stack was reached during the search
321 */
322 HotSpotStackFrameReference getNextStackFrame(HotSpotStackFrameReference frame, long[] methods, int initialSkip);
323
324 /**
325 * Materialized all virtual objects within the given stack frame and update the locals within
326 * the given stackFrame object.
327 *
328 * @param invalidate if {@code true}, the compiled method for the stack frame will be
329 * invalidated.
330 */
331 void materializeVirtualObjects(HotSpotStackFrameReference stackFrame, boolean invalidate);
332
333 void resolveInvokeDynamic(long metaspaceConstantPool, int index);
334
335 int getVtableIndexForInterface(long metaspaceKlass, long metaspaceMethod);
336
337 boolean shouldDebugNonSafepoints();
338
339 void writeDebugOutput(byte[] bytes, int offset, int length);
340
341 void flushDebugOutput();
342 }