42 |
43 |
43 |
44 |
44 // Every time a compiled IC is changed or its type is being accessed, |
45 // Every time a compiled IC is changed or its type is being accessed, |
45 // either the CompiledIC_lock must be set or we must be at a safe point. |
46 // either the CompiledIC_lock must be set or we must be at a safe point. |
46 |
47 |
|
48 |
|
49 // Release the CompiledICHolder* associated with this call site is there is one. |
|
50 void CompiledIC::cleanup_call_site(virtual_call_Relocation* call_site) { |
|
51 // This call site might have become stale so inspect it carefully. |
|
52 NativeCall* call = nativeCall_at(call_site->addr()); |
|
53 if (is_icholder_entry(call->destination())) { |
|
54 NativeMovConstReg* value = nativeMovConstReg_at(call_site->cached_value()); |
|
55 InlineCacheBuffer::queue_for_release((CompiledICHolder*)value->data()); |
|
56 } |
|
57 } |
|
58 |
|
59 |
|
60 bool CompiledIC::is_icholder_call_site(virtual_call_Relocation* call_site) { |
|
61 // This call site might have become stale so inspect it carefully. |
|
62 NativeCall* call = nativeCall_at(call_site->addr()); |
|
63 return is_icholder_entry(call->destination()); |
|
64 } |
|
65 |
|
66 |
47 //----------------------------------------------------------------------------- |
67 //----------------------------------------------------------------------------- |
48 // Low-level access to an inline cache. Private, since they might not be |
68 // Low-level access to an inline cache. Private, since they might not be |
49 // MT-safe to use. |
69 // MT-safe to use. |
50 |
70 |
51 void CompiledIC::set_cached_oop(oop cache) { |
71 void* CompiledIC::cached_value() const { |
52 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
72 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
53 assert (!is_optimized(), "an optimized virtual call does not have a cached oop"); |
73 assert (!is_optimized(), "an optimized virtual call does not have a cached metadata"); |
54 assert (cache == NULL || cache != badOop, "invalid oop"); |
74 |
|
75 if (!is_in_transition_state()) { |
|
76 void* data = (void*)_value->data(); |
|
77 // If we let the metadata value here be initialized to zero... |
|
78 assert(data != NULL || Universe::non_oop_word() == NULL, |
|
79 "no raw nulls in CompiledIC metadatas, because of patching races"); |
|
80 return (data == (void*)Universe::non_oop_word()) ? NULL : data; |
|
81 } else { |
|
82 return InlineCacheBuffer::cached_value_for((CompiledIC *)this); |
|
83 } |
|
84 } |
|
85 |
|
86 |
|
87 void CompiledIC::internal_set_ic_destination(address entry_point, bool is_icstub, void* cache, bool is_icholder) { |
|
88 assert(entry_point != NULL, "must set legal entry point"); |
|
89 assert(CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
|
90 assert (!is_optimized() || cache == NULL, "an optimized virtual call does not have a cached metadata"); |
|
91 assert (cache == NULL || cache != (Metadata*)badOopVal, "invalid metadata"); |
|
92 |
|
93 assert(!is_icholder || is_icholder_entry(entry_point), "must be"); |
|
94 |
|
95 // Don't use ic_destination for this test since that forwards |
|
96 // through ICBuffer instead of returning the actual current state of |
|
97 // the CompiledIC. |
|
98 if (is_icholder_entry(_ic_call->destination())) { |
|
99 // When patching for the ICStub case the cached value isn't |
|
100 // overwritten until the ICStub copied into the CompiledIC during |
|
101 // the next safepoint. Make sure that the CompiledICHolder* is |
|
102 // marked for release at this point since it won't be identifiable |
|
103 // once the entry point is overwritten. |
|
104 InlineCacheBuffer::queue_for_release((CompiledICHolder*)_value->data()); |
|
105 } |
55 |
106 |
56 if (TraceCompiledIC) { |
107 if (TraceCompiledIC) { |
57 tty->print(" "); |
108 tty->print(" "); |
58 print_compiled_ic(); |
109 print_compiled_ic(); |
59 tty->print_cr(" changing oop to " INTPTR_FORMAT, (address)cache); |
110 tty->print(" changing destination to " INTPTR_FORMAT, entry_point); |
60 } |
111 if (!is_optimized()) { |
61 |
112 tty->print(" changing cached %s to " INTPTR_FORMAT, is_icholder ? "icholder" : "metadata", (address)cache); |
62 if (cache == NULL) cache = (oop)Universe::non_oop_word(); |
113 } |
63 |
114 if (is_icstub) { |
64 *_oop_addr = cache; |
115 tty->print(" (icstub)"); |
65 // fix up the relocations |
116 } |
66 RelocIterator iter = _oops; |
117 tty->cr(); |
67 while (iter.next()) { |
118 } |
68 if (iter.type() == relocInfo::oop_type) { |
119 |
69 oop_Relocation* r = iter.oop_reloc(); |
120 { |
70 if (r->oop_addr() == _oop_addr) |
|
71 r->fix_oop_relocation(); |
|
72 } |
|
73 } |
|
74 return; |
|
75 } |
|
76 |
|
77 |
|
78 oop CompiledIC::cached_oop() const { |
|
79 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
|
80 assert (!is_optimized(), "an optimized virtual call does not have a cached oop"); |
|
81 |
|
82 if (!is_in_transition_state()) { |
|
83 oop data = *_oop_addr; |
|
84 // If we let the oop value here be initialized to zero... |
|
85 assert(data != NULL || Universe::non_oop_word() == NULL, |
|
86 "no raw nulls in CompiledIC oops, because of patching races"); |
|
87 return (data == (oop)Universe::non_oop_word()) ? (oop)NULL : data; |
|
88 } else { |
|
89 return InlineCacheBuffer::cached_oop_for((CompiledIC *)this); |
|
90 } |
|
91 } |
|
92 |
|
93 |
|
94 void CompiledIC::set_ic_destination(address entry_point) { |
|
95 assert(entry_point != NULL, "must set legal entry point"); |
|
96 assert(CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
|
97 if (TraceCompiledIC) { |
|
98 tty->print(" "); |
|
99 print_compiled_ic(); |
|
100 tty->print_cr(" changing destination to " INTPTR_FORMAT, entry_point); |
|
101 } |
|
102 MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag); |
121 MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag); |
103 #ifdef ASSERT |
122 #ifdef ASSERT |
104 CodeBlob* cb = CodeCache::find_blob_unsafe(_ic_call); |
123 CodeBlob* cb = CodeCache::find_blob_unsafe(_ic_call); |
105 assert(cb != NULL && cb->is_nmethod(), "must be nmethod"); |
124 assert(cb != NULL && cb->is_nmethod(), "must be nmethod"); |
106 #endif |
125 #endif |
107 _ic_call->set_destination_mt_safe(entry_point); |
126 _ic_call->set_destination_mt_safe(entry_point); |
108 } |
127 } |
|
128 |
|
129 if (is_optimized() || is_icstub) { |
|
130 // Optimized call sites don't have a cache value and ICStub call |
|
131 // sites only change the entry point. Changing the value in that |
|
132 // case could lead to MT safety issues. |
|
133 assert(cache == NULL, "must be null"); |
|
134 return; |
|
135 } |
|
136 |
|
137 if (cache == NULL) cache = (void*)Universe::non_oop_word(); |
|
138 |
|
139 _value->set_data((intptr_t)cache); |
|
140 } |
|
141 |
|
142 |
|
143 void CompiledIC::set_ic_destination(ICStub* stub) { |
|
144 internal_set_ic_destination(stub->code_begin(), true, NULL, false); |
|
145 } |
|
146 |
109 |
147 |
110 |
148 |
111 address CompiledIC::ic_destination() const { |
149 address CompiledIC::ic_destination() const { |
112 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
150 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
113 if (!is_in_transition_state()) { |
151 if (!is_in_transition_state()) { |
138 |
181 |
139 void CompiledIC::set_to_megamorphic(CallInfo* call_info, Bytecodes::Code bytecode, TRAPS) { |
182 void CompiledIC::set_to_megamorphic(CallInfo* call_info, Bytecodes::Code bytecode, TRAPS) { |
140 methodHandle method = call_info->selected_method(); |
183 methodHandle method = call_info->selected_method(); |
141 bool is_invoke_interface = (bytecode == Bytecodes::_invokeinterface && !call_info->has_vtable_index()); |
184 bool is_invoke_interface = (bytecode == Bytecodes::_invokeinterface && !call_info->has_vtable_index()); |
142 assert(CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
185 assert(CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
143 assert(method->is_oop(), "cannot be NULL and must be oop"); |
|
144 assert(!is_optimized(), "cannot set an optimized virtual call to megamorphic"); |
186 assert(!is_optimized(), "cannot set an optimized virtual call to megamorphic"); |
145 assert(is_call_to_compiled() || is_call_to_interpreted(), "going directly to megamorphic?"); |
187 assert(is_call_to_compiled() || is_call_to_interpreted(), "going directly to megamorphic?"); |
146 |
188 |
147 address entry; |
189 address entry; |
148 if (is_invoke_interface) { |
190 if (is_invoke_interface) { |
149 int index = klassItable::compute_itable_index(call_info->resolved_method()()); |
191 int index = klassItable::compute_itable_index(call_info->resolved_method()()); |
150 entry = VtableStubs::create_stub(false, index, method()); |
192 entry = VtableStubs::create_stub(false, index, method()); |
151 assert(entry != NULL, "entry not computed"); |
193 assert(entry != NULL, "entry not computed"); |
152 klassOop k = call_info->resolved_method()->method_holder(); |
194 Klass* k = call_info->resolved_method()->method_holder(); |
153 assert(Klass::cast(k)->is_interface(), "sanity check"); |
195 assert(Klass::cast(k)->is_interface(), "sanity check"); |
154 InlineCacheBuffer::create_transition_stub(this, k, entry); |
196 InlineCacheBuffer::create_transition_stub(this, k, entry); |
155 } else { |
197 } else { |
156 // Can be different than method->vtable_index(), due to package-private etc. |
198 // Can be different than method->vtable_index(), due to package-private etc. |
157 int vtable_index = call_info->vtable_index(); |
199 int vtable_index = call_info->vtable_index(); |
190 // Use unsafe, since an inline cache might point to a zombie method. However, the zombie |
232 // Use unsafe, since an inline cache might point to a zombie method. However, the zombie |
191 // method is guaranteed to still exist, since we only remove methods after all inline caches |
233 // method is guaranteed to still exist, since we only remove methods after all inline caches |
192 // has been cleaned up |
234 // has been cleaned up |
193 CodeBlob* cb = CodeCache::find_blob_unsafe(ic_destination()); |
235 CodeBlob* cb = CodeCache::find_blob_unsafe(ic_destination()); |
194 bool is_monomorphic = (cb != NULL && cb->is_nmethod()); |
236 bool is_monomorphic = (cb != NULL && cb->is_nmethod()); |
195 // Check that the cached_oop is a klass for non-optimized monomorphic calls |
237 // Check that the cached_value is a klass for non-optimized monomorphic calls |
196 // This assertion is invalid for compiler1: a call that does not look optimized (no static stub) can be used |
238 // This assertion is invalid for compiler1: a call that does not look optimized (no static stub) can be used |
197 // for calling directly to vep without using the inline cache (i.e., cached_oop == NULL) |
239 // for calling directly to vep without using the inline cache (i.e., cached_value == NULL) |
198 #ifdef ASSERT |
240 #ifdef ASSERT |
199 #ifdef TIERED |
|
200 CodeBlob* caller = CodeCache::find_blob_unsafe(instruction_address()); |
241 CodeBlob* caller = CodeCache::find_blob_unsafe(instruction_address()); |
201 bool is_c1_method = caller->is_compiled_by_c1(); |
242 bool is_c1_method = caller->is_compiled_by_c1(); |
202 #else |
|
203 #ifdef COMPILER1 |
|
204 bool is_c1_method = true; |
|
205 #else |
|
206 bool is_c1_method = false; |
|
207 #endif // COMPILER1 |
|
208 #endif // TIERED |
|
209 assert( is_c1_method || |
243 assert( is_c1_method || |
210 !is_monomorphic || |
244 !is_monomorphic || |
211 is_optimized() || |
245 is_optimized() || |
212 (cached_oop() != NULL && cached_oop()->is_klass()), "sanity check"); |
246 (cached_metadata() != NULL && cached_metadata()->is_klass()), "sanity check"); |
213 #endif // ASSERT |
247 #endif // ASSERT |
214 return is_monomorphic; |
248 return is_monomorphic; |
215 } |
249 } |
216 |
250 |
217 |
251 |
255 entry = SharedRuntime::get_resolve_opt_virtual_call_stub(); |
289 entry = SharedRuntime::get_resolve_opt_virtual_call_stub(); |
256 } else { |
290 } else { |
257 entry = SharedRuntime::get_resolve_virtual_call_stub(); |
291 entry = SharedRuntime::get_resolve_virtual_call_stub(); |
258 } |
292 } |
259 |
293 |
260 // A zombie transition will always be safe, since the oop has already been set to NULL, so |
294 // A zombie transition will always be safe, since the metadata has already been set to NULL, so |
261 // we only need to patch the destination |
295 // we only need to patch the destination |
262 bool safe_transition = is_optimized() || SafepointSynchronize::is_at_safepoint(); |
296 bool safe_transition = is_optimized() || SafepointSynchronize::is_at_safepoint(); |
263 |
297 |
264 if (safe_transition) { |
298 if (safe_transition) { |
265 if (!is_optimized()) set_cached_oop(NULL); |
|
266 // Kill any leftover stub we might have too |
299 // Kill any leftover stub we might have too |
267 if (is_in_transition_state()) { |
300 if (is_in_transition_state()) { |
268 ICStub* old_stub = ICStub_from_destination_address(stub_address()); |
301 ICStub* old_stub = ICStub_from_destination_address(stub_address()); |
269 old_stub->clear(); |
302 old_stub->clear(); |
270 } |
303 } |
|
304 if (is_optimized()) { |
271 set_ic_destination(entry); |
305 set_ic_destination(entry); |
|
306 } else { |
|
307 set_ic_destination_and_value(entry, (void*)NULL); |
|
308 } |
272 } else { |
309 } else { |
273 // Unsafe transition - create stub. |
310 // Unsafe transition - create stub. |
274 InlineCacheBuffer::create_transition_stub(this, NULL, entry); |
311 InlineCacheBuffer::create_transition_stub(this, NULL, entry); |
275 } |
312 } |
276 // We can't check this anymore. With lazy deopt we could have already |
313 // We can't check this anymore. With lazy deopt we could have already |
287 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
324 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
288 bool is_clean = false; |
325 bool is_clean = false; |
289 address dest = ic_destination(); |
326 address dest = ic_destination(); |
290 is_clean = dest == SharedRuntime::get_resolve_opt_virtual_call_stub() || |
327 is_clean = dest == SharedRuntime::get_resolve_opt_virtual_call_stub() || |
291 dest == SharedRuntime::get_resolve_virtual_call_stub(); |
328 dest == SharedRuntime::get_resolve_virtual_call_stub(); |
292 assert(!is_clean || is_optimized() || cached_oop() == NULL, "sanity check"); |
329 assert(!is_clean || is_optimized() || cached_value() == NULL, "sanity check"); |
293 return is_clean; |
330 return is_clean; |
294 } |
331 } |
295 |
332 |
296 |
333 |
297 void CompiledIC::set_to_monomorphic(const CompiledICInfo& info) { |
334 void CompiledIC::set_to_monomorphic(CompiledICInfo& info) { |
298 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
335 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), ""); |
299 // Updating a cache to the wrong entry can cause bugs that are very hard |
336 // Updating a cache to the wrong entry can cause bugs that are very hard |
300 // to track down - if cache entry gets invalid - we just clean it. In |
337 // to track down - if cache entry gets invalid - we just clean it. In |
301 // this way it is always the same code path that is responsible for |
338 // this way it is always the same code path that is responsible for |
302 // updating and resolving an inline cache |
339 // updating and resolving an inline cache |
307 // |
344 // |
308 // In both of these cases the only thing being modifed is the jump/call target and these |
345 // In both of these cases the only thing being modifed is the jump/call target and these |
309 // transitions are mt_safe |
346 // transitions are mt_safe |
310 |
347 |
311 Thread *thread = Thread::current(); |
348 Thread *thread = Thread::current(); |
312 if (info._to_interpreter) { |
349 if (info.to_interpreter()) { |
313 // Call to interpreter |
350 // Call to interpreter |
314 if (info.is_optimized() && is_optimized()) { |
351 if (info.is_optimized() && is_optimized()) { |
315 assert(is_clean(), "unsafe IC path"); |
352 assert(is_clean(), "unsafe IC path"); |
316 MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag); |
353 MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag); |
317 // the call analysis (callee structure) specifies that the call is optimized |
354 // the call analysis (callee structure) specifies that the call is optimized |
318 // (either because of CHA or the static target is final) |
355 // (either because of CHA or the static target is final) |
319 // At code generation time, this call has been emitted as static call |
356 // At code generation time, this call has been emitted as static call |
320 // Call via stub |
357 // Call via stub |
321 assert(info.cached_oop().not_null() && info.cached_oop()->is_method(), "sanity check"); |
358 assert(info.cached_metadata() != NULL && info.cached_metadata()->is_method(), "sanity check"); |
322 CompiledStaticCall* csc = compiledStaticCall_at(instruction_address()); |
359 CompiledStaticCall* csc = compiledStaticCall_at(instruction_address()); |
323 methodHandle method (thread, (methodOop)info.cached_oop()()); |
360 methodHandle method (thread, (Method*)info.cached_metadata()); |
324 csc->set_to_interpreted(method, info.entry()); |
361 csc->set_to_interpreted(method, info.entry()); |
325 if (TraceICs) { |
362 if (TraceICs) { |
326 ResourceMark rm(thread); |
363 ResourceMark rm(thread); |
327 tty->print_cr ("IC@" INTPTR_FORMAT ": monomorphic to interpreter: %s", |
364 tty->print_cr ("IC@" INTPTR_FORMAT ": monomorphic to interpreter: %s", |
328 instruction_address(), |
365 instruction_address(), |
329 method->print_value_string()); |
366 method->print_value_string()); |
330 } |
367 } |
331 } else { |
368 } else { |
332 // Call via method-klass-holder |
369 // Call via method-klass-holder |
333 assert(info.cached_oop().not_null(), "must be set"); |
370 InlineCacheBuffer::create_transition_stub(this, info.claim_cached_icholder(), info.entry()); |
334 InlineCacheBuffer::create_transition_stub(this, info.cached_oop()(), info.entry()); |
|
335 |
|
336 if (TraceICs) { |
371 if (TraceICs) { |
337 ResourceMark rm(thread); |
372 ResourceMark rm(thread); |
338 tty->print_cr ("IC@" INTPTR_FORMAT ": monomorphic to interpreter via mkh", instruction_address()); |
373 tty->print_cr ("IC@" INTPTR_FORMAT ": monomorphic to interpreter via icholder ", instruction_address()); |
339 } |
374 } |
340 } |
375 } |
341 } else { |
376 } else { |
342 // Call to compiled code |
377 // Call to compiled code |
343 bool static_bound = info.is_optimized() || (info.cached_oop().is_null()); |
378 bool static_bound = info.is_optimized() || (info.cached_metadata() == NULL); |
344 #ifdef ASSERT |
379 #ifdef ASSERT |
345 CodeBlob* cb = CodeCache::find_blob_unsafe(info.entry()); |
380 CodeBlob* cb = CodeCache::find_blob_unsafe(info.entry()); |
346 assert (cb->is_nmethod(), "must be compiled!"); |
381 assert (cb->is_nmethod(), "must be compiled!"); |
347 #endif /* ASSERT */ |
382 #endif /* ASSERT */ |
348 |
383 |
350 // non-verified entry point |
385 // non-verified entry point |
351 bool safe = SafepointSynchronize::is_at_safepoint() || |
386 bool safe = SafepointSynchronize::is_at_safepoint() || |
352 (!is_in_transition_state() && (info.is_optimized() || static_bound || is_clean())); |
387 (!is_in_transition_state() && (info.is_optimized() || static_bound || is_clean())); |
353 |
388 |
354 if (!safe) { |
389 if (!safe) { |
355 InlineCacheBuffer::create_transition_stub(this, info.cached_oop()(), info.entry()); |
390 InlineCacheBuffer::create_transition_stub(this, info.cached_metadata(), info.entry()); |
356 } else { |
391 } else { |
|
392 if (is_optimized()) { |
357 set_ic_destination(info.entry()); |
393 set_ic_destination(info.entry()); |
358 if (!is_optimized()) set_cached_oop(info.cached_oop()()); |
394 } else { |
|
395 set_ic_destination_and_value(info.entry(), info.cached_metadata()); |
|
396 } |
359 } |
397 } |
360 |
398 |
361 if (TraceICs) { |
399 if (TraceICs) { |
362 ResourceMark rm(thread); |
400 ResourceMark rm(thread); |
363 assert(info.cached_oop() == NULL || info.cached_oop()()->is_klass(), "must be"); |
401 assert(info.cached_metadata() == NULL || info.cached_metadata()->is_klass(), "must be"); |
364 tty->print_cr ("IC@" INTPTR_FORMAT ": monomorphic to compiled (rcvr klass) %s: %s", |
402 tty->print_cr ("IC@" INTPTR_FORMAT ": monomorphic to compiled (rcvr klass) %s: %s", |
365 instruction_address(), |
403 instruction_address(), |
366 ((klassOop)info.cached_oop()())->print_value_string(), |
404 ((Klass*)info.cached_metadata())->print_value_string(), |
367 (safe) ? "" : "via stub"); |
405 (safe) ? "" : "via stub"); |
368 } |
406 } |
369 } |
407 } |
370 // We can't check this anymore. With lazy deopt we could have already |
408 // We can't check this anymore. With lazy deopt we could have already |
371 // cleaned this IC entry before we even return. This is possible if |
409 // cleaned this IC entry before we even return. This is possible if |
398 entry = method_code->entry_point(); |
434 entry = method_code->entry_point(); |
399 } |
435 } |
400 } |
436 } |
401 if (entry != NULL) { |
437 if (entry != NULL) { |
402 // Call to compiled code |
438 // Call to compiled code |
403 info._entry = entry; |
439 info.set_compiled_entry(entry, (static_bound || is_optimized) ? NULL : receiver_klass(), is_optimized); |
404 if (static_bound || is_optimized) { |
|
405 info._cached_oop = Handle(THREAD, (oop)NULL); |
|
406 } else { |
|
407 info._cached_oop = receiver_klass; |
|
408 } |
|
409 info._to_interpreter = false; |
|
410 } else { |
440 } else { |
411 // Note: the following problem exists with Compiler1: |
441 // Note: the following problem exists with Compiler1: |
412 // - at compile time we may or may not know if the destination is final |
442 // - at compile time we may or may not know if the destination is final |
413 // - if we know that the destination is final, we will emit an optimized |
443 // - if we know that the destination is final, we will emit an optimized |
414 // virtual call (no inline cache), and need a methodOop to make a call |
444 // virtual call (no inline cache), and need a Method* to make a call |
415 // to the interpreter |
445 // to the interpreter |
416 // - if we do not know if the destination is final, we emit a standard |
446 // - if we do not know if the destination is final, we emit a standard |
417 // virtual call, and use CompiledICHolder to call interpreted code |
447 // virtual call, and use CompiledICHolder to call interpreted code |
418 // (no static call stub has been generated) |
448 // (no static call stub has been generated) |
419 // However in that case we will now notice it is static_bound |
449 // However in that case we will now notice it is static_bound |
420 // and convert the call into what looks to be an optimized |
450 // and convert the call into what looks to be an optimized |
421 // virtual call. This causes problems in verifying the IC because |
451 // virtual call. This causes problems in verifying the IC because |
422 // it look vanilla but is optimized. Code in is_call_to_interpreted |
452 // it look vanilla but is optimized. Code in is_call_to_interpreted |
423 // is aware of this and weakens its asserts. |
453 // is aware of this and weakens its asserts. |
424 |
454 |
425 info._to_interpreter = true; |
|
426 // static_bound should imply is_optimized -- otherwise we have a |
455 // static_bound should imply is_optimized -- otherwise we have a |
427 // performance bug (statically-bindable method is called via |
456 // performance bug (statically-bindable method is called via |
428 // dynamically-dispatched call note: the reverse implication isn't |
457 // dynamically-dispatched call note: the reverse implication isn't |
429 // necessarily true -- the call may have been optimized based on compiler |
458 // necessarily true -- the call may have been optimized based on compiler |
430 // analysis (static_bound is only based on "final" etc.) |
459 // analysis (static_bound is only based on "final" etc.) |
441 assert(!static_bound || is_optimized, "static_bound should imply is_optimized"); |
470 assert(!static_bound || is_optimized, "static_bound should imply is_optimized"); |
442 #endif // TIERED |
471 #endif // TIERED |
443 #endif // COMPILER2 |
472 #endif // COMPILER2 |
444 if (is_optimized) { |
473 if (is_optimized) { |
445 // Use stub entry |
474 // Use stub entry |
446 info._entry = method()->get_c2i_entry(); |
475 info.set_interpreter_entry(method()->get_c2i_entry(), method()); |
447 info._cached_oop = method; |
|
448 } else { |
476 } else { |
449 // Use mkh entry |
477 // Use icholder entry |
450 oop holder = oopFactory::new_compiledICHolder(method, receiver_klass, CHECK); |
478 CompiledICHolder* holder = new CompiledICHolder(method(), receiver_klass()); |
451 info._cached_oop = Handle(THREAD, holder); |
479 info.set_icholder_entry(method()->get_c2i_unverified_entry(), holder); |
452 info._entry = method()->get_c2i_unverified_entry(); |
480 } |
453 } |
481 } |
454 } |
482 assert(info.is_optimized() == is_optimized, "must agree"); |
455 } |
483 } |
456 |
484 |
457 |
485 |
458 inline static RelocIterator parse_ic(nmethod* nm, address ic_call, oop* &_oop_addr, bool *is_optimized) { |
486 bool CompiledIC::is_icholder_entry(address entry) { |
459 address first_oop = NULL; |
487 CodeBlob* cb = CodeCache::find_blob_unsafe(entry); |
460 // Mergers please note: Sun SC5.x CC insists on an lvalue for a reference parameter. |
488 return (cb != NULL && cb->is_adapter_blob()); |
461 nmethod* tmp_nm = nm; |
489 } |
462 return virtual_call_Relocation::parse_ic(tmp_nm, ic_call, first_oop, _oop_addr, is_optimized); |
490 |
463 } |
491 |
464 |
492 CompiledIC::CompiledIC(nmethod* nm, NativeCall* call) |
465 CompiledIC::CompiledIC(NativeCall* ic_call) |
493 : _ic_call(call) |
466 : _ic_call(ic_call), |
|
467 _oops(parse_ic(NULL, ic_call->instruction_address(), _oop_addr, &_is_optimized)) |
|
468 { |
494 { |
469 } |
495 address ic_call = call->instruction_address(); |
470 |
496 |
471 |
497 assert(ic_call != NULL, "ic_call address must be set"); |
472 CompiledIC::CompiledIC(Relocation* ic_reloc) |
498 assert(nm != NULL, "must pass nmethod"); |
473 : _ic_call(nativeCall_at(ic_reloc->addr())), |
499 assert(nm->contains(ic_call), "must be in nmethod"); |
474 _oops(parse_ic(ic_reloc->code(), ic_reloc->addr(), _oop_addr, &_is_optimized)) |
500 |
475 { |
501 // search for the ic_call at the given address |
476 assert(ic_reloc->type() == relocInfo::virtual_call_type || |
502 RelocIterator iter(nm, ic_call, ic_call+1); |
477 ic_reloc->type() == relocInfo::opt_virtual_call_type, "wrong reloc. info"); |
503 bool ret = iter.next(); |
|
504 assert(ret == true, "relocInfo must exist at this address"); |
|
505 assert(iter.addr() == ic_call, "must find ic_call"); |
|
506 if (iter.type() == relocInfo::virtual_call_type) { |
|
507 virtual_call_Relocation* r = iter.virtual_call_reloc(); |
|
508 _is_optimized = false; |
|
509 _value = nativeMovConstReg_at(r->cached_value()); |
|
510 } else { |
|
511 assert(iter.type() == relocInfo::opt_virtual_call_type, "must be a virtual call"); |
|
512 _is_optimized = true; |
|
513 _value = NULL; |
|
514 } |
478 } |
515 } |
479 |
516 |
480 |
517 |
481 // ---------------------------------------------------------------------------- |
518 // ---------------------------------------------------------------------------- |
482 |
519 |