79 CompiledICHolder* icholder = (CompiledICHolder*)_cached_value; |
80 CompiledICHolder* icholder = (CompiledICHolder*)_cached_value; |
80 icholder->claim(); |
81 icholder->claim(); |
81 return icholder; |
82 return icholder; |
82 } |
83 } |
83 bool is_optimized() const { return _is_optimized; } |
84 bool is_optimized() const { return _is_optimized; } |
84 bool to_interpreter() const { return _to_interpreter; } |
85 bool to_interpreter() const { return _to_interpreter; } |
|
86 bool to_aot() const { return _to_aot; } |
85 |
87 |
86 void set_compiled_entry(address entry, Klass* klass, bool is_optimized) { |
88 void set_compiled_entry(address entry, Klass* klass, bool is_optimized) { |
87 _entry = entry; |
89 _entry = entry; |
88 _cached_value = (void*)klass; |
90 _cached_value = (void*)klass; |
89 _to_interpreter = false; |
91 _to_interpreter = false; |
|
92 _to_aot = false; |
90 _is_icholder = false; |
93 _is_icholder = false; |
91 _is_optimized = is_optimized; |
94 _is_optimized = is_optimized; |
92 _release_icholder = false; |
95 _release_icholder = false; |
93 } |
96 } |
94 |
97 |
95 void set_interpreter_entry(address entry, Method* method) { |
98 void set_interpreter_entry(address entry, Method* method) { |
96 _entry = entry; |
99 _entry = entry; |
97 _cached_value = (void*)method; |
100 _cached_value = (void*)method; |
98 _to_interpreter = true; |
101 _to_interpreter = true; |
|
102 _to_aot = false; |
|
103 _is_icholder = false; |
|
104 _is_optimized = true; |
|
105 _release_icholder = false; |
|
106 } |
|
107 |
|
108 void set_aot_entry(address entry, Method* method) { |
|
109 _entry = entry; |
|
110 _cached_value = (void*)method; |
|
111 _to_interpreter = false; |
|
112 _to_aot = true; |
99 _is_icholder = false; |
113 _is_icholder = false; |
100 _is_optimized = true; |
114 _is_optimized = true; |
101 _release_icholder = false; |
115 _release_icholder = false; |
102 } |
116 } |
103 |
117 |
104 void set_icholder_entry(address entry, CompiledICHolder* icholder) { |
118 void set_icholder_entry(address entry, CompiledICHolder* icholder) { |
105 _entry = entry; |
119 _entry = entry; |
106 _cached_value = (void*)icholder; |
120 _cached_value = (void*)icholder; |
107 _to_interpreter = true; |
121 _to_interpreter = true; |
|
122 _to_aot = false; |
108 _is_icholder = true; |
123 _is_icholder = true; |
109 _is_optimized = false; |
124 _is_optimized = false; |
110 _release_icholder = true; |
125 _release_icholder = true; |
111 } |
126 } |
112 |
127 |
113 CompiledICInfo(): _entry(NULL), _cached_value(NULL), _is_icholder(false), |
128 CompiledICInfo(): _entry(NULL), _cached_value(NULL), _is_icholder(false), |
114 _to_interpreter(false), _is_optimized(false), _release_icholder(false) { |
129 _to_interpreter(false), _to_aot(false), _is_optimized(false), _release_icholder(false) { |
115 } |
130 } |
116 ~CompiledICInfo() { |
131 ~CompiledICInfo() { |
117 // In rare cases the info is computed but not used, so release any |
132 // In rare cases the info is computed but not used, so release any |
118 // CompiledICHolder* that was created |
133 // CompiledICHolder* that was created |
119 if (_release_icholder) { |
134 if (_release_icholder) { |
123 delete icholder; |
138 delete icholder; |
124 } |
139 } |
125 } |
140 } |
126 }; |
141 }; |
127 |
142 |
|
143 class NativeCallWrapper: public ResourceObj { |
|
144 public: |
|
145 virtual address destination() const = 0; |
|
146 virtual address instruction_address() const = 0; |
|
147 virtual address next_instruction_address() const = 0; |
|
148 virtual address return_address() const = 0; |
|
149 virtual address get_resolve_call_stub(bool is_optimized) const = 0; |
|
150 virtual void set_destination_mt_safe(address dest) = 0; |
|
151 virtual void set_to_interpreted(const methodHandle& method, CompiledICInfo& info) = 0; |
|
152 virtual void verify() const = 0; |
|
153 virtual void verify_resolve_call(address dest) const = 0; |
|
154 |
|
155 virtual bool is_call_to_interpreted(address dest) const = 0; |
|
156 virtual bool is_safe_for_patching() const = 0; |
|
157 |
|
158 virtual NativeInstruction* get_load_instruction(virtual_call_Relocation* r) const = 0; |
|
159 |
|
160 virtual void *get_data(NativeInstruction* instruction) const = 0; |
|
161 virtual void set_data(NativeInstruction* instruction, intptr_t data) = 0; |
|
162 }; |
|
163 |
128 class CompiledIC: public ResourceObj { |
164 class CompiledIC: public ResourceObj { |
129 friend class InlineCacheBuffer; |
165 friend class InlineCacheBuffer; |
130 friend class ICStub; |
166 friend class ICStub; |
131 |
167 |
132 |
|
133 private: |
168 private: |
134 NativeCall* _ic_call; // the call instruction |
169 NativeCallWrapper* _call; |
135 NativeMovConstReg* _value; // patchable value cell for this IC |
170 NativeInstruction* _value; // patchable value cell for this IC |
136 bool _is_optimized; // an optimized virtual call (i.e., no compiled IC) |
171 bool _is_optimized; // an optimized virtual call (i.e., no compiled IC) |
|
172 CompiledMethod* _method; |
137 |
173 |
138 CompiledIC(CompiledMethod* cm, NativeCall* ic_call); |
174 CompiledIC(CompiledMethod* cm, NativeCall* ic_call); |
139 CompiledIC(RelocIterator* iter); |
175 CompiledIC(RelocIterator* iter); |
140 |
176 |
141 void initialize_from_iter(RelocIterator* iter); |
177 void initialize_from_iter(RelocIterator* iter); |
175 friend CompiledIC* CompiledIC_at(RelocIterator* reloc_iter); |
211 friend CompiledIC* CompiledIC_at(RelocIterator* reloc_iter); |
176 |
212 |
177 // This is used to release CompiledICHolder*s from nmethods that |
213 // This is used to release CompiledICHolder*s from nmethods that |
178 // are about to be freed. The callsite might contain other stale |
214 // are about to be freed. The callsite might contain other stale |
179 // values of other kinds so it must be careful. |
215 // values of other kinds so it must be careful. |
180 static void cleanup_call_site(virtual_call_Relocation* call_site); |
216 static void cleanup_call_site(virtual_call_Relocation* call_site, const CompiledMethod* cm); |
181 static bool is_icholder_call_site(virtual_call_Relocation* call_site); |
217 static bool is_icholder_call_site(virtual_call_Relocation* call_site, const CompiledMethod* cm); |
182 |
218 |
183 // Return the cached_metadata/destination associated with this inline cache. If the cache currently points |
219 // Return the cached_metadata/destination associated with this inline cache. If the cache currently points |
184 // to a transition stub, it will read the values from the transition stub. |
220 // to a transition stub, it will read the values from the transition stub. |
185 void* cached_value() const; |
221 void* cached_value() const; |
186 CompiledICHolder* cached_icholder() const { |
222 CompiledICHolder* cached_icholder() const { |
221 // Returns true if successful and false otherwise. The call can fail if memory |
265 // Returns true if successful and false otherwise. The call can fail if memory |
222 // allocation in the code cache fails. |
266 // allocation in the code cache fails. |
223 bool set_to_megamorphic(CallInfo* call_info, Bytecodes::Code bytecode, TRAPS); |
267 bool set_to_megamorphic(CallInfo* call_info, Bytecodes::Code bytecode, TRAPS); |
224 |
268 |
225 static void compute_monomorphic_entry(const methodHandle& method, KlassHandle receiver_klass, |
269 static void compute_monomorphic_entry(const methodHandle& method, KlassHandle receiver_klass, |
226 bool is_optimized, bool static_bound, CompiledICInfo& info, TRAPS); |
270 bool is_optimized, bool static_bound, bool caller_is_nmethod, |
|
271 CompiledICInfo& info, TRAPS); |
227 |
272 |
228 // Location |
273 // Location |
229 address instruction_address() const { return _ic_call->instruction_address(); } |
274 address instruction_address() const { return _call->instruction_address(); } |
230 |
275 |
231 // Misc |
276 // Misc |
232 void print() PRODUCT_RETURN; |
277 void print() PRODUCT_RETURN; |
233 void print_compiled_ic() PRODUCT_RETURN; |
278 void print_compiled_ic() PRODUCT_RETURN; |
234 void verify() PRODUCT_RETURN; |
279 void verify() PRODUCT_RETURN; |
276 // Clean: Calls directly to runtime method for fixup |
321 // Clean: Calls directly to runtime method for fixup |
277 // Compiled code: Calls directly to compiled code |
322 // Compiled code: Calls directly to compiled code |
278 // Interpreted code: Calls to stub that set Method* reference |
323 // Interpreted code: Calls to stub that set Method* reference |
279 // |
324 // |
280 // |
325 // |
281 class CompiledStaticCall; |
|
282 |
326 |
283 class StaticCallInfo { |
327 class StaticCallInfo { |
284 private: |
328 private: |
285 address _entry; // Entrypoint |
329 address _entry; // Entrypoint |
286 methodHandle _callee; // Callee (used when calling interpreter) |
330 methodHandle _callee; // Callee (used when calling interpreter) |
287 bool _to_interpreter; // call to interpreted method (otherwise compiled) |
331 bool _to_interpreter; // call to interpreted method (otherwise compiled) |
|
332 bool _to_aot; // call to aot method (otherwise compiled) |
288 |
333 |
289 friend class CompiledStaticCall; |
334 friend class CompiledStaticCall; |
|
335 friend class CompiledDirectStaticCall; |
|
336 friend class CompiledPltStaticCall; |
290 public: |
337 public: |
291 address entry() const { return _entry; } |
338 address entry() const { return _entry; } |
292 methodHandle callee() const { return _callee; } |
339 methodHandle callee() const { return _callee; } |
293 }; |
340 }; |
294 |
341 |
295 |
342 class CompiledStaticCall : public ResourceObj { |
296 class CompiledStaticCall: public NativeCall { |
|
297 friend class CompiledIC; |
|
298 |
|
299 // Also used by CompiledIC |
|
300 void set_to_interpreted(methodHandle callee, address entry); |
|
301 bool is_optimized_virtual(); |
|
302 |
|
303 public: |
343 public: |
304 friend CompiledStaticCall* compiledStaticCall_before(address return_addr); |
|
305 friend CompiledStaticCall* compiledStaticCall_at(address native_call); |
|
306 friend CompiledStaticCall* compiledStaticCall_at(Relocation* call_site); |
|
307 |
|
308 // Code |
344 // Code |
309 static address emit_to_interp_stub(CodeBuffer &cbuf, address mark = NULL); |
345 static address emit_to_interp_stub(CodeBuffer &cbuf, address mark = NULL); |
310 static int to_interp_stub_size(); |
346 static int to_interp_stub_size(); |
311 static int reloc_to_interp_stub(); |
347 static int reloc_to_interp_stub(); |
312 |
348 static void emit_to_aot_stub(CodeBuffer &cbuf, address mark = NULL); |
313 // State |
349 static int to_aot_stub_size(); |
314 bool is_clean() const; |
350 static int reloc_to_aot_stub(); |
315 bool is_call_to_compiled() const; |
351 |
316 bool is_call_to_interpreted() const; |
352 // Compute entry point given a method |
|
353 static void compute_entry(const methodHandle& m, bool caller_is_nmethod, StaticCallInfo& info); |
|
354 |
|
355 public: |
|
356 // Clean static call (will force resolving on next use) |
|
357 virtual address destination() const = 0; |
317 |
358 |
318 // Clean static call (will force resolving on next use) |
359 // Clean static call (will force resolving on next use) |
319 void set_to_clean(); |
360 void set_to_clean(); |
320 |
361 |
321 // Set state. The entry must be the same, as computed by compute_entry. |
362 // Set state. The entry must be the same, as computed by compute_entry. |
322 // Computation and setting is split up, since the actions are separate during |
363 // Computation and setting is split up, since the actions are separate during |
323 // a OptoRuntime::resolve_xxx. |
364 // a OptoRuntime::resolve_xxx. |
324 void set(const StaticCallInfo& info); |
365 void set(const StaticCallInfo& info); |
325 |
366 |
326 // Compute entry point given a method |
367 // State |
327 static void compute_entry(const methodHandle& m, StaticCallInfo& info); |
368 bool is_clean() const; |
|
369 bool is_call_to_compiled() const; |
|
370 virtual bool is_call_to_interpreted() const = 0; |
|
371 |
|
372 virtual address instruction_address() const = 0; |
|
373 protected: |
|
374 virtual address resolve_call_stub() const = 0; |
|
375 virtual void set_destination_mt_safe(address dest) = 0; |
|
376 #if INCLUDE_AOT |
|
377 virtual void set_to_far(const methodHandle& callee, address entry) = 0; |
|
378 #endif |
|
379 virtual void set_to_interpreted(const methodHandle& callee, address entry) = 0; |
|
380 virtual const char* name() const = 0; |
|
381 |
|
382 void set_to_compiled(address entry); |
|
383 }; |
|
384 |
|
385 class CompiledDirectStaticCall : public CompiledStaticCall { |
|
386 private: |
|
387 friend class CompiledIC; |
|
388 friend class DirectNativeCallWrapper; |
|
389 |
|
390 // Also used by CompiledIC |
|
391 void set_to_interpreted(const methodHandle& callee, address entry); |
|
392 #if INCLUDE_AOT |
|
393 void set_to_far(const methodHandle& callee, address entry); |
|
394 #endif |
|
395 address instruction_address() const { return _call->instruction_address(); } |
|
396 void set_destination_mt_safe(address dest) { _call->set_destination_mt_safe(dest); } |
|
397 |
|
398 NativeCall* _call; |
|
399 |
|
400 CompiledDirectStaticCall(NativeCall* call) : _call(call) {} |
|
401 |
|
402 public: |
|
403 static inline CompiledDirectStaticCall* before(address return_addr) { |
|
404 CompiledDirectStaticCall* st = new CompiledDirectStaticCall(nativeCall_before(return_addr)); |
|
405 st->verify(); |
|
406 return st; |
|
407 } |
|
408 |
|
409 static inline CompiledDirectStaticCall* at(address native_call) { |
|
410 CompiledDirectStaticCall* st = new CompiledDirectStaticCall(nativeCall_at(native_call)); |
|
411 st->verify(); |
|
412 return st; |
|
413 } |
|
414 |
|
415 static inline CompiledDirectStaticCall* at(Relocation* call_site) { |
|
416 return at(call_site->addr()); |
|
417 } |
|
418 |
|
419 // Delegation |
|
420 address destination() const { return _call->destination(); } |
|
421 |
|
422 // State |
|
423 virtual bool is_call_to_interpreted() const; |
|
424 bool is_call_to_far() const; |
328 |
425 |
329 // Stub support |
426 // Stub support |
330 address find_stub(); |
427 static address find_stub_for(address instruction, bool is_aot); |
|
428 address find_stub(bool is_aot); |
331 static void set_stub_to_clean(static_stub_Relocation* static_stub); |
429 static void set_stub_to_clean(static_stub_Relocation* static_stub); |
332 |
430 |
333 // Misc. |
431 // Misc. |
334 void print() PRODUCT_RETURN; |
432 void print() PRODUCT_RETURN; |
335 void verify() PRODUCT_RETURN; |
433 void verify() PRODUCT_RETURN; |
336 }; |
434 |
337 |
435 protected: |
338 |
436 virtual address resolve_call_stub() const; |
339 inline CompiledStaticCall* compiledStaticCall_before(address return_addr) { |
437 virtual const char* name() const { return "CompiledDirectStaticCall"; } |
340 CompiledStaticCall* st = (CompiledStaticCall*)nativeCall_before(return_addr); |
438 }; |
341 st->verify(); |
|
342 return st; |
|
343 } |
|
344 |
|
345 inline CompiledStaticCall* compiledStaticCall_at(address native_call) { |
|
346 CompiledStaticCall* st = (CompiledStaticCall*)native_call; |
|
347 st->verify(); |
|
348 return st; |
|
349 } |
|
350 |
|
351 inline CompiledStaticCall* compiledStaticCall_at(Relocation* call_site) { |
|
352 return compiledStaticCall_at(call_site->addr()); |
|
353 } |
|
354 |
439 |
355 #endif // SHARE_VM_CODE_COMPILEDIC_HPP |
440 #endif // SHARE_VM_CODE_COMPILEDIC_HPP |