comparison graal/com.oracle.max.cri/src/com/sun/cri/ri/RiRuntime.java @ 3733:e233f5660da4

Added Java files from Maxine project.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sat, 17 Dec 2011 19:59:18 +0100
parents
children feb590a8497f
comparison
equal deleted inserted replaced
3732:3e2e8b8abdaf 3733:e233f5660da4
1 /*
2 * Copyright (c) 2009, 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 package com.sun.cri.ri;
24
25 import java.lang.reflect.*;
26
27 import com.sun.cri.ci.*;
28
29 /**
30 * Encapsulates the main functionality of the runtime for the compiler, including access
31 * to constant pools, OSR frames, inlining requirements, and runtime calls such as checkcast.
32 s */
33 public interface RiRuntime {
34
35 /**
36 * Checks whether the specified method is required to be inlined (for semantic reasons).
37 * If this method returns true, then the null-check of the receiver emitted during
38 * inlining is omitted.
39 *
40 * @param method the method being called
41 * @return {@code true} if the method must be inlined; {@code false} to let the compiler
42 * use its own heuristics
43 */
44 boolean mustInline(RiResolvedMethod method);
45
46 /**
47 * Checks whether the specified method must not be inlined (for semantic reasons).
48 * @param method the method being called
49 * @return {@code true} if the method must not be inlined; {@code false} to let the compiler
50 * use its own heuristics
51 */
52 boolean mustNotInline(RiResolvedMethod method);
53
54 /**
55 * Checks whether the specified method cannot be compiled.
56 * @param method the method being called
57 * @return {@code true} if the method cannot be compiled
58 */
59 boolean mustNotCompile(RiResolvedMethod method);
60
61 /**
62 * Offset of the lock within the lock object on the stack.
63
64 * Note: superseded by sizeOfLockData() in Graal.
65 *
66 * @return the offset in bytes
67 */
68 int basicObjectLockOffsetInBytes();
69
70 /**
71 * Get the size in bytes of a lock object on the stack.
72 *
73 * Note: superseded by sizeOfLockData() in Graal.
74 */
75 int sizeOfBasicObjectLock();
76
77 /**
78 * Get the size in bytes for locking information on the stack.
79 */
80 int sizeOfLockData();
81
82 /**
83 * The offset of the normal entry to the code. The compiler inserts NOP instructions to satisfy this constraint.
84 *
85 * @return the code offset in bytes
86 */
87 int codeOffset();
88
89 /**
90 * Returns the disassembly of the given code bytes. Used for debugging purposes only.
91 *
92 * @param code the code bytes that should be disassembled
93 * @param address an address at which the bytes are located. This can be used for an address prefix per line of disassembly.
94 * @return the disassembly. This will be of length 0 if the runtime does not support disassembling.
95 */
96 String disassemble(byte[] code, long address);
97
98 /**
99 * Returns the disassembly of the given code bytes. Used for debugging purposes only.
100 *
101 * @param targetMethod the {@link CiTargetMethod} containing the code bytes that should be disassembled
102 * @return the disassembly. This will be of length 0 if the runtime does not support disassembling.
103 */
104 String disassemble(CiTargetMethod targetMethod);
105
106 /**
107 * Returns the disassembly of the given method in a {@code javap}-like format.
108 * Used for debugging purposes only.
109 *
110 * @param method the method that should be disassembled
111 * @return the disassembly. This will be of length 0 if the runtime does not support disassembling.
112 */
113 String disassemble(RiResolvedMethod method);
114
115 /**
116 * Registers the given compiler stub and returns an object that can be used to identify it in the relocation
117 * information.
118 *
119 * @param targetMethod the target method representing the code of the compiler stub
120 * @param name the name of the stub, used for debugging purposes only
121 * @return the identification object
122 */
123 Object registerCompilerStub(CiTargetMethod targetMethod, String name);
124
125 /**
126 * Returns the RiType object representing the base type for the given kind.
127 */
128 RiResolvedType asRiType(CiKind kind);
129
130 /**
131 * Returns the type of the given constant object.
132 *
133 * @return {@code null} if {@code constant.isNull() || !constant.kind.isObject()}
134 */
135 RiResolvedType getTypeOf(CiConstant constant);
136
137
138 RiResolvedType getType(Class<?> clazz);
139
140 /**
141 * Returns true if the given type is a subtype of java/lang/Throwable.
142 */
143 boolean isExceptionType(RiResolvedType type);
144
145 /**
146 * Checks whether this method is foldable (i.e. if it is a pure function without side effects).
147 * @param method the method that is checked
148 * @return whether the method is foldable
149 */
150 boolean isFoldable(RiResolvedMethod method);
151
152 /**
153 * Attempts to compile-time evaluate or "fold" a call to a given method. A foldable method is a pure function
154 * that has no side effects. Such methods can be executed via reflection when all their inputs are constants,
155 * and the resulting value is substituted for the method call. May only be called on methods for which
156 * isFoldable(method) returns {@code true}. The array of constant for arguments may contain {@code null} values, which
157 * means that this particular argument does not evaluate to a compile time constant.
158 *
159 * @param method the compiler interface method for which folding is being requested
160 * @param args the arguments to the call as an array of CiConstant objects
161 * @return the result of the folding or {@code null} if no folding occurred
162 */
163 CiConstant fold(RiResolvedMethod method, CiConstant[] args);
164
165 /**
166 * Used by the canonicalizer to compare objects, since a given runtime might not want to expose the real objects to the compiler.
167 *
168 * @return true if the two parameters represent the same runtime object, false otherwise
169 */
170 boolean areConstantObjectsEqual(CiConstant x, CiConstant y);
171
172 /**
173 * Gets the register configuration to use when compiling a given method.
174 *
175 * @param method the top level method of a compilation
176 */
177 RiRegisterConfig getRegisterConfig(RiMethod method);
178
179 /**
180 * Custom area on the stack of each compiled method that the VM can use for its own purposes.
181 * @return the size of the custom area in bytes
182 */
183 int getCustomStackAreaSize();
184
185 /**
186 * Gets the length of the array that is wrapped in a CiConstant object.
187 */
188 int getArrayLength(CiConstant array);
189
190 /**
191 * Converts the given CiConstant object to a object.
192 *
193 * @return {@code null} if the conversion is not possible <b>OR</b> {@code c.isNull() == true}
194 */
195 Object asJavaObject(CiConstant c);
196
197 /**
198 * Converts the given CiConstant object to a {@link Class} object.
199 *
200 * @return {@code null} if the conversion is not possible.
201 */
202 Class<?> asJavaClass(CiConstant c);
203
204 /**
205 * Performs any runtime-specific conversion on the object used to describe the target of a call.
206 */
207 Object asCallTarget(Object target);
208
209 /**
210 * Returns the maximum absolute offset of a runtime call target from any position in the code cache or -1
211 * when not known or not applicable. Intended for determining the required size of address/offset fields.
212 */
213 long getMaxCallTargetOffset(CiRuntimeCall rtcall);
214
215 /**
216 * Provides the {@link RiMethod} for a {@link Method} obtained via reflection.
217 */
218 RiResolvedMethod getRiMethod(Method reflectionMethod);
219
220 /**
221 * Installs some given machine code as the implementation of a given method.
222 *
223 * @param method a method whose executable code is being modified
224 * @param code the code to be executed when {@code method} is called
225 */
226 void installMethod(RiMethod method, CiTargetMethod code);
227
228 /**
229 * Adds the given machine code as an implementation of the given method without making it the default implementation.
230 * @param method a method to which the executable code is begin added
231 * @param code the code to be added
232 * @return a reference to the compiled and ready-to-run code
233 */
234 RiCompiledMethod addMethod(RiResolvedMethod method, CiTargetMethod code);
235
236 /**
237 * Executes the given runnable on a compiler thread, which means that it can access constant pools, etc.
238 */
239 void executeOnCompilerThread(Runnable r);
240 }