Mercurial > hg > truffle
comparison src/share/vm/c1x/c1x_Compiler.hpp @ 1423:760213a60e8b
* rewrite of the code installation
* partial support for safepoints
* macro-based CiTargetMethod interface
* code stub support
author | Lukas Stadler <lukas.stadler@oracle.com> |
---|---|
date | Mon, 16 Aug 2010 18:59:36 -0700 |
parents | 3483ec571caf |
children | 98fffb304868 |
comparison
equal
deleted
inserted
replaced
1422:3483ec571caf | 1423:760213a60e8b |
---|---|
49 virtual void compile_method(ciEnv* env, ciMethod* target, int entry_bci); | 49 virtual void compile_method(ciEnv* env, ciMethod* target, int entry_bci); |
50 | 50 |
51 // Print compilation timers and statistics | 51 // Print compilation timers and statistics |
52 virtual void print_timers(); | 52 virtual void print_timers(); |
53 | 53 |
54 static oop get_RiType(oop klass, klassOop accessingType, TRAPS); | |
55 static oop get_RiType(ciType *klass, klassOop accessor, TRAPS); | 54 static oop get_RiType(ciType *klass, klassOop accessor, TRAPS); |
56 static oop get_RiField(ciField *ciField, TRAPS); | 55 static oop get_RiField(ciField *ciField, TRAPS); |
56 | |
57 static void compute_offsets(); | |
58 | |
59 // this needs to correspond to HotSpotXirGenerator.java | |
60 enum MarkId { | |
61 MARK_VERIFIED_ENTRY = 1, | |
62 MARK_UNVERIFIED_ENTRY = 2, | |
63 MARK_STATIC_CALL_STUB = 1000 | |
64 }; | |
57 | 65 |
58 /* | 66 /* |
59 static oop get_RiMethod(ciMethod *ciMethod, TRAPS); | 67 static oop get_RiMethod(ciMethod *ciMethod, TRAPS); |
60 static oop get_RiType(klassOop klass, TRAPS); | 68 static oop get_RiType(klassOop klass, TRAPS); |
61 static oop get_RiMethod(methodOop method, TRAPS); | 69 static oop get_RiMethod(methodOop method, TRAPS); |
64 */ | 72 */ |
65 }; | 73 }; |
66 | 74 |
67 class C1XObjects : public AllStatic { | 75 class C1XObjects : public AllStatic { |
68 | 76 |
77 private: | |
78 static GrowableArray<address>* _stubs; | |
79 static GrowableArray<jobject>* _localHandles; | |
80 | |
81 static oop getObject(jlong id); | |
82 | |
69 public: | 83 public: |
70 static oop getReflectedMethod(methodOop method, TRAPS); | 84 // this enum needs to have the same values as the one in HotSpotProxy.java |
71 static oop getReflectedClass(klassOop klass); | 85 enum CompilerObjectType { |
72 static oop getReflectedSymbol(symbolOop symbol, TRAPS); | 86 STUB = 0x100000000000000l, |
73 | 87 METHOD = 0x200000000000000l, |
74 static methodOop getInternalMethod(oop method); | 88 CLASS = 0x300000000000000l, |
75 static klassOop getInternalClass(oop klass); | 89 SYMBOL = 0x400000000000000l, |
76 static symbolOop getInternalSymbol(oop string); | 90 CONSTANT_POOL = 0x500000000000000l, |
77 | 91 CONSTANT = 0x600000000000000l, |
78 static methodOop getInternalMethod(jobject method) { | 92 TYPE_MASK = 0xf00000000000000l |
79 return getInternalMethod(JNIHandles::resolve(method)); | 93 }; |
80 } | 94 |
81 static klassOop getInternalClass(jobject klass) { | 95 static void initializeObjects(); |
82 return getInternalClass(JNIHandles::resolve(klass)); | 96 static void cleanupLocalObjects(); |
83 } | 97 |
84 static symbolOop getInternalSymbol(jobject string) { | 98 static jlong addStub(address stub); |
85 return getInternalSymbol(JNIHandles::resolve(string)); | 99 static jlong add(Handle obj, CompilerObjectType type); |
86 } | 100 template <typename T> static jlong add(T obj); |
101 | |
102 static address getStub(jlong id); | |
103 template <typename T> static T get(jlong id); | |
104 | |
105 template <typename T> static T toString(symbolOop symbol, TRAPS); | |
106 static symbolOop toSymbol(jstring string); | |
87 }; | 107 }; |
108 | |
109 template <> inline jlong C1XObjects::add<methodOop>(methodOop obj){ | |
110 assert(obj != NULL && obj->is_method(), "trying to add NULL or mistyped object"); | |
111 return add(Handle(obj), METHOD); | |
112 } | |
113 template <> inline jlong C1XObjects::add<klassOop>(klassOop obj) { | |
114 assert(obj != NULL && obj->is_klass(), "trying to add NULL or mistyped object"); | |
115 return add(Handle(obj), CLASS); | |
116 } | |
117 template <> inline jlong C1XObjects::add<symbolOop>(symbolOop obj) { | |
118 assert(obj != NULL && obj->is_symbol(), "trying to add NULL or mistyped object"); | |
119 return add(Handle(obj), SYMBOL); | |
120 } | |
121 template <> inline jlong C1XObjects::add<constantPoolOop>(constantPoolOop obj) { | |
122 assert(obj != NULL && obj->is_constantPool(), "trying to add NULL or mistyped object"); | |
123 return add(Handle(obj), CONSTANT_POOL); | |
124 } | |
125 template <> inline jlong C1XObjects::add<oop>(oop obj) { | |
126 assert(obj != NULL && obj->is_oop(), "trying to add NULL or mistyped object"); | |
127 return add(Handle(obj), CONSTANT); | |
128 } | |
129 | |
130 template <> inline methodOop C1XObjects::get<methodOop>(jlong id){ | |
131 assert((id & TYPE_MASK) == METHOD, "METHOD expected"); | |
132 assert(getObject(id)->is_method(), "methodOop expected"); | |
133 return (methodOop)getObject(id); | |
134 } | |
135 template <> inline klassOop C1XObjects::get<klassOop>(jlong id) { | |
136 assert((id & TYPE_MASK) == CLASS, "CLASS expected"); | |
137 assert(getObject(id)->is_klass(), "klassOop expected"); | |
138 return (klassOop)getObject(id); | |
139 } | |
140 template <> inline symbolOop C1XObjects::get<symbolOop>(jlong id) { | |
141 assert((id & TYPE_MASK) == SYMBOL, "SYMBOL expected"); | |
142 assert(getObject(id)->is_symbol(), "symbolOop expected"); | |
143 return (symbolOop)getObject(id); | |
144 } | |
145 template <> inline constantPoolOop C1XObjects::get<constantPoolOop>(jlong id) { | |
146 assert((id & TYPE_MASK) == CONSTANT_POOL, "CONSTANT_POOL expected"); | |
147 assert(getObject(id)->is_constantPool(), "constantPoolOop expected"); | |
148 return (constantPoolOop)getObject(id); | |
149 } | |
150 template <> inline oop C1XObjects::get<oop>(jlong id) { | |
151 assert((id & TYPE_MASK) == CONSTANT, "CONSTANT expected"); | |
152 assert(getObject(id)->is_oop(true), "oop expected"); | |
153 return (oop)getObject(id); | |
154 } | |
155 | |
156 template <> inline Handle C1XObjects::toString<Handle>(symbolOop symbol, TRAPS) { | |
157 return java_lang_String::create_from_symbol(symbol, THREAD); | |
158 } | |
159 template <> inline oop C1XObjects::toString<oop>(symbolOop symbol, TRAPS) { | |
160 return toString<Handle>(symbol, THREAD)(); | |
161 } | |
162 template <> inline jstring C1XObjects::toString<jstring>(symbolOop symbol, TRAPS) { | |
163 return (jstring)JNIHandles::make_local(toString<oop>(symbol, THREAD)); | |
164 } | |
165 template <> inline jobject C1XObjects::toString<jobject>(symbolOop symbol, TRAPS) { | |
166 return JNIHandles::make_local(toString<oop>(symbol, THREAD)); | |
167 } | |
168 | |
169 inline symbolOop C1XObjects::toSymbol(jstring string) { | |
170 return java_lang_String::as_symbol_or_null(JNIHandles::resolve(string)); | |
171 } | |
88 | 172 |
89 // Tracing macros | 173 // Tracing macros |
90 | 174 |
91 #define IF_TRACE_C1X_1 if (TraceC1X >= 1) | 175 #define IF_TRACE_C1X_1 if (TraceC1X >= 1) |
92 #define IF_TRACE_C1X_2 if (TraceC1X >= 2) | 176 #define IF_TRACE_C1X_2 if (TraceC1X >= 2) |
97 #define TRACE_C1X_1 if (TraceC1X >= 1) tty->print("TraceC1X-1: "); if (TraceC1X >= 1) tty->print_cr | 181 #define TRACE_C1X_1 if (TraceC1X >= 1) tty->print("TraceC1X-1: "); if (TraceC1X >= 1) tty->print_cr |
98 #define TRACE_C1X_2 if (TraceC1X >= 2) tty->print(" TraceC1X-2: "); if (TraceC1X >= 2) tty->print_cr | 182 #define TRACE_C1X_2 if (TraceC1X >= 2) tty->print(" TraceC1X-2: "); if (TraceC1X >= 2) tty->print_cr |
99 #define TRACE_C1X_3 if (TraceC1X >= 3) tty->print(" TraceC1X-3: "); if (TraceC1X >= 3) tty->print_cr | 183 #define TRACE_C1X_3 if (TraceC1X >= 3) tty->print(" TraceC1X-3: "); if (TraceC1X >= 3) tty->print_cr |
100 #define TRACE_C1X_4 if (TraceC1X >= 4) tty->print(" TraceC1X-4: "); if (TraceC1X >= 4) tty->print_cr | 184 #define TRACE_C1X_4 if (TraceC1X >= 4) tty->print(" TraceC1X-4: "); if (TraceC1X >= 4) tty->print_cr |
101 #define TRACE_C1X_5 if (TraceC1X >= 5) tty->print(" TraceC1X-5: "); if (TraceC1X >= 5) tty->print_cr | 185 #define TRACE_C1X_5 if (TraceC1X >= 5) tty->print(" TraceC1X-5: "); if (TraceC1X >= 5) tty->print_cr |
186 | |
187 | |
188 // defines the structure of the CiTargetMethod - classes | |
189 // this will generate classes with accessors similar to javaClasses.hpp | |
190 | |
191 #define COMPILER_CLASSES_DO(start_class, end_class, char_field, int_field, long_field, oop_field) \ | |
192 start_class(HotSpotTypeResolved) \ | |
193 long_field(HotSpotTypeResolved, vmId) \ | |
194 end_class \ | |
195 start_class(HotSpotMethod) \ | |
196 long_field(HotSpotMethod, vmId) \ | |
197 end_class \ | |
198 start_class(HotSpotTargetMethod) \ | |
199 oop_field(HotSpotTargetMethod, targetMethod, "Lcom/sun/cri/ci/CiTargetMethod;") \ | |
200 oop_field(HotSpotTargetMethod, method, "Lcom/sun/hotspot/c1x/HotSpotMethod;") \ | |
201 oop_field(HotSpotTargetMethod, name, "Ljava/lang/String;") \ | |
202 oop_field(HotSpotTargetMethod, sites, "[Lcom/sun/cri/ci/CiTargetMethod$Site;") \ | |
203 end_class \ | |
204 start_class(CiTargetMethod) \ | |
205 int_field(CiTargetMethod, frameSize) \ | |
206 oop_field(CiTargetMethod, targetCode, "[B") \ | |
207 int_field(CiTargetMethod, targetCodeSize) \ | |
208 int_field(CiTargetMethod, referenceRegisterCount) \ | |
209 end_class \ | |
210 start_class(CiTargetMethod_Site) \ | |
211 int_field(CiTargetMethod_Site, pcOffset) \ | |
212 end_class \ | |
213 start_class(CiTargetMethod_Call) \ | |
214 oop_field(CiTargetMethod_Call, runtimeCall, "Lcom/sun/cri/ci/CiRuntimeCall;") \ | |
215 oop_field(CiTargetMethod_Call, method, "Lcom/sun/cri/ri/RiMethod;") \ | |
216 oop_field(CiTargetMethod_Call, symbol, "Ljava/lang/String;") \ | |
217 oop_field(CiTargetMethod_Call, globalStubID, "Ljava/lang/Object;") \ | |
218 oop_field(CiTargetMethod_Call, debugInfo, "Lcom/sun/cri/ci/CiDebugInfo;") \ | |
219 oop_field(CiTargetMethod_Call, stackMap, "[B") \ | |
220 oop_field(CiTargetMethod_Call, registerMap, "[B") \ | |
221 end_class \ | |
222 start_class(CiTargetMethod_DataPatch) \ | |
223 oop_field(CiTargetMethod_DataPatch, constant, "Lcom/sun/cri/ci/CiConstant;") \ | |
224 end_class \ | |
225 start_class(CiTargetMethod_Safepoint) \ | |
226 oop_field(CiTargetMethod_Safepoint, debugInfo, "Lcom/sun/cri/ci/CiDebugInfo;") \ | |
227 end_class \ | |
228 start_class(CiTargetMethod_ExceptionHandler) \ | |
229 int_field(CiTargetMethod_ExceptionHandler, handlerPos) \ | |
230 oop_field(CiTargetMethod_ExceptionHandler, exceptionType, "Lcom/sun/cri/ri/RiType;")\ | |
231 end_class \ | |
232 start_class(CiTargetMethod_Mark) \ | |
233 oop_field(CiTargetMethod_Mark, id, "Ljava/lang/Object;") \ | |
234 oop_field(CiTargetMethod_Mark, references, "[Lcom/sun/cri/ci/CiTargetMethod$Mark;") \ | |
235 end_class \ | |
236 start_class(CiDebugInfo) \ | |
237 oop_field(CiDebugInfo, codePos, "Lcom/sun/cri/ci/CiCodePos;") \ | |
238 oop_field(CiDebugInfo, frame, "Lcom/sun/cri/ci/CiDebugInfo$Frame;") \ | |
239 oop_field(CiDebugInfo, registerRefMap, "[B") \ | |
240 oop_field(CiDebugInfo, frameRefMap, "[B") \ | |
241 end_class \ | |
242 start_class(CiDebugInfo_Frame) \ | |
243 oop_field(CiDebugInfo_Frame, caller, "Lcom/sun/cri/ci/CiDebugInfo$Frame;") \ | |
244 oop_field(CiDebugInfo_Frame, codePos, "Lcom/sun/cri/ci/CiCodePos;") \ | |
245 oop_field(CiDebugInfo_Frame, values, "[Lcom/sun/cri/ci/CiValue;") \ | |
246 int_field(CiDebugInfo_Frame, numLocals) \ | |
247 int_field(CiDebugInfo_Frame, numStack) \ | |
248 int_field(CiDebugInfo_Frame, numLocks) \ | |
249 end_class \ | |
250 start_class(CiCodePos) \ | |
251 oop_field(CiCodePos, caller, "Lcom/sun/cri/ci/CiCodePos;") \ | |
252 oop_field(CiCodePos, method, "Lcom/sun/cri/ri/RiMethod;") \ | |
253 int_field(CiCodePos, bci) \ | |
254 end_class \ | |
255 start_class(CiConstant) \ | |
256 oop_field(CiConstant, kind, "Lcom/sun/cri/ci/CiKind;") \ | |
257 oop_field(CiConstant, object, "Ljava/lang/Object;") \ | |
258 long_field(CiConstant, primitive) \ | |
259 end_class \ | |
260 start_class(CiKind) \ | |
261 char_field(CiKind, typeChar) \ | |
262 end_class \ | |
263 start_class(CiRuntimeCall) \ | |
264 end_class \ | |
265 start_class(RiMethod) \ | |
266 end_class \ | |
267 start_class(CiRegisterValue) \ | |
268 end_class \ | |
269 start_class(CiStackSlot) \ | |
270 end_class \ | |
271 /* end*/ | |
272 | |
273 #define START_CLASS(name) \ | |
274 class name : AllStatic { \ | |
275 private: \ | |
276 friend class C1XCompiler; \ | |
277 static void check(oop obj) { assert(obj != NULL, "NULL field access"); assert(obj->is_a(SystemDictionary::name##_klass()), "wrong class, " #name " expected"); } \ | |
278 static void compute_offsets(); \ | |
279 public: \ | |
280 static klassOop klass() { return SystemDictionary::name##_klass(); } | |
281 | |
282 #define END_CLASS }; | |
283 | |
284 #define FIELD(name, type, accessor) \ | |
285 static int _##name##_offset; \ | |
286 static type name(oop obj) { check(obj); return obj->accessor(_##name##_offset); } \ | |
287 static type name(jobject obj) { check(JNIHandles::resolve(obj)); return JNIHandles::resolve(obj)->accessor(_##name##_offset); } \ | |
288 static void set_##name(oop obj, type x) { check(obj); obj->accessor##_put(_##name##_offset, x); } \ | |
289 static void set_##name(jobject obj, type x) { check(JNIHandles::resolve(obj)); JNIHandles::resolve(obj)->accessor##_put(_##name##_offset, x); } | |
290 | |
291 #define CHAR_FIELD(klass, name) FIELD(name, jchar, char_field) | |
292 #define INT_FIELD(klass, name) FIELD(name, jint, int_field) | |
293 #define LONG_FIELD(klass, name) FIELD(name, jlong, long_field) | |
294 #define OOP_FIELD(klass, name, signature) FIELD(name, oop, obj_field) | |
295 | |
296 COMPILER_CLASSES_DO(START_CLASS, END_CLASS, CHAR_FIELD, INT_FIELD, LONG_FIELD, OOP_FIELD) | |
297 #undef START_CLASS | |
298 #undef END_CLASS | |
299 #undef FIELD | |
300 #undef CHAR_FIELD | |
301 #undef INT_FIELD | |
302 #undef LONG_FIELD | |
303 #undef OOP_FIELD | |
304 | |
305 |