< prev index next >

src/hotspot/share/code/vtableStubs.cpp

Print this page

192                            (int)(masm->pc() - s->code_begin()),
193                            stub_length,
194                            (int)(s->code_end() - masm->pc()));
195   }
196   guarantee(masm->pc() <= s->code_end(), "%s #%d: overflowed buffer, estimated len: %d, actual len: %d, overrun: %d",
197                                          name, index, stub_length,
198                                          (int)(masm->pc() - s->code_begin()),
199                                          (int)(masm->pc() - s->code_end()));
200   assert((masm->pc() + index_dependent_slop) <= s->code_end(), "%s #%d: spare space for 32-bit offset: required = %d, available = %d",
201                                          name, index, index_dependent_slop,
202                                          (int)(s->code_end() - masm->pc()));
203 
204   // After the first vtable/itable stub is generated, we have a much
205   // better estimate for the stub size. Remember/update this
206   // estimate after some sanity checks.
207   check_and_set_size_limit(is_vtable_stub, masm->offset(), slop_bytes);
208   s->set_exception_points(npe_addr, ame_addr);
209 }
210 
211 
212 address VtableStubs::find_stub(bool is_vtable_stub, int vtable_index) {
213   assert(vtable_index >= 0, "must be positive");
214 
215   VtableStub* s;
216   {
217     MutexLocker ml(VtableStubs_lock, Mutex::_no_safepoint_check_flag);
218     s = lookup(is_vtable_stub, vtable_index);
219     if (s == NULL) {
220       if (is_vtable_stub) {
221         s = create_vtable_stub(vtable_index);
222       } else {
223         s = create_itable_stub(vtable_index);
224       }
225 
226       // Creation of vtable or itable can fail if there is not enough free space in the code cache.
227       if (s == NULL) {
228         return NULL;
229       }
230 
231       enter(is_vtable_stub, vtable_index, s);
232       if (PrintAdapterHandlers) {
233         tty->print_cr("Decoding VtableStub %s[%d]@" INTX_FORMAT,
234                       is_vtable_stub? "vtbl": "itbl", vtable_index, p2i(VtableStub::receiver_location()));
235         Disassembler::decode(s->code_begin(), s->code_end());
236       }
237       // Notify JVMTI about this stub. The event will be recorded by the enclosing
238       // JvmtiDynamicCodeEventCollector and posted when this thread has released
239       // all locks. Only post this event if a new state is not required. Creating a new state would
240       // cause a safepoint and the caller of this code has a NoSafepointVerifier.
241       if (JvmtiExport::should_post_dynamic_code_generated()) {
242         JvmtiExport::post_dynamic_code_generated_while_holding_locks(is_vtable_stub? "vtable stub": "itable stub",
243                                                                      s->code_begin(), s->code_end());
244       }
245     }
246   }
247   return s->entry_point();
248 }
249 
250 
251 inline uint VtableStubs::hash(bool is_vtable_stub, int vtable_index){
252   // Assumption: receiver_location < 4 in most cases.
253   int hash = ((vtable_index << 2) ^ VtableStub::receiver_location()->value()) + vtable_index;



254   return (is_vtable_stub ? ~hash : hash)  & mask;
255 }
256 
257 
258 VtableStub* VtableStubs::lookup(bool is_vtable_stub, int vtable_index) {
259   assert_lock_strong(VtableStubs_lock);
260   unsigned hash = VtableStubs::hash(is_vtable_stub, vtable_index);
261   VtableStub* s = _table[hash];
262   while( s && !s->matches(is_vtable_stub, vtable_index)) s = s->next();
263   return s;
264 }
265 
266 
267 void VtableStubs::enter(bool is_vtable_stub, int vtable_index, VtableStub* s) {
268   assert_lock_strong(VtableStubs_lock);
269   assert(s->matches(is_vtable_stub, vtable_index), "bad vtable stub");
270   unsigned int h = VtableStubs::hash(is_vtable_stub, vtable_index);
271   // enter s at the beginning of the corresponding list
272   s->set_next(_table[h]);
273   _table[h] = s;
274   _number_of_vtable_stubs++;
275 }
276 
277 VtableStub* VtableStubs::entry_point(address pc) {
278   MutexLocker ml(VtableStubs_lock, Mutex::_no_safepoint_check_flag);
279   VtableStub* stub = (VtableStub*)(pc - VtableStub::entry_offset());
280   uint hash = VtableStubs::hash(stub->is_vtable_stub(), stub->index());
281   VtableStub* s;
282   for (s = _table[hash]; s != NULL && s != stub; s = s->next()) {}
283   return (s == stub) ? s : NULL;
284 }
285 
286 bool VtableStubs::contains(address pc) {
287   // simple solution for now - we may want to use
288   // a faster way if this function is called often
289   return stub_containing(pc) != NULL;
290 }
291 
292 
293 VtableStub* VtableStubs::stub_containing(address pc) {
294   // Note: No locking needed since any change to the data structure
295   //       happens with an atomic store into it (we don't care about
296   //       consistency with the _number_of_vtable_stubs counter).
297   for (int i = 0; i < N; i++) {
298     for (VtableStub* s = _table[i]; s != NULL; s = s->next()) {
299       if (s->contains(pc)) return s;
300     }

192                            (int)(masm->pc() - s->code_begin()),
193                            stub_length,
194                            (int)(s->code_end() - masm->pc()));
195   }
196   guarantee(masm->pc() <= s->code_end(), "%s #%d: overflowed buffer, estimated len: %d, actual len: %d, overrun: %d",
197                                          name, index, stub_length,
198                                          (int)(masm->pc() - s->code_begin()),
199                                          (int)(masm->pc() - s->code_end()));
200   assert((masm->pc() + index_dependent_slop) <= s->code_end(), "%s #%d: spare space for 32-bit offset: required = %d, available = %d",
201                                          name, index, index_dependent_slop,
202                                          (int)(s->code_end() - masm->pc()));
203 
204   // After the first vtable/itable stub is generated, we have a much
205   // better estimate for the stub size. Remember/update this
206   // estimate after some sanity checks.
207   check_and_set_size_limit(is_vtable_stub, masm->offset(), slop_bytes);
208   s->set_exception_points(npe_addr, ame_addr);
209 }
210 
211 
212 address VtableStubs::find_stub(bool is_vtable_stub, int vtable_index, bool caller_is_c1) {
213   assert(vtable_index >= 0, "must be positive");
214 
215   VtableStub* s;
216   {
217     MutexLocker ml(VtableStubs_lock, Mutex::_no_safepoint_check_flag);
218     s = lookup(is_vtable_stub, vtable_index, caller_is_c1);
219     if (s == NULL) {
220       if (is_vtable_stub) {
221         s = create_vtable_stub(vtable_index, caller_is_c1);
222       } else {
223         s = create_itable_stub(vtable_index, caller_is_c1);
224       }
225 
226       // Creation of vtable or itable can fail if there is not enough free space in the code cache.
227       if (s == NULL) {
228         return NULL;
229       }
230 
231       enter(is_vtable_stub, vtable_index, caller_is_c1, s);
232       if (PrintAdapterHandlers) {
233         tty->print_cr("Decoding VtableStub (%s) %s[%d]@" INTX_FORMAT, caller_is_c1 ? "c1" : "full opt",
234                       is_vtable_stub? "vtbl": "itbl", vtable_index, p2i(VtableStub::receiver_location()));
235         Disassembler::decode(s->code_begin(), s->code_end());
236       }
237       // Notify JVMTI about this stub. The event will be recorded by the enclosing
238       // JvmtiDynamicCodeEventCollector and posted when this thread has released
239       // all locks. Only post this event if a new state is not required. Creating a new state would
240       // cause a safepoint and the caller of this code has a NoSafepointVerifier.
241       if (JvmtiExport::should_post_dynamic_code_generated()) {
242         JvmtiExport::post_dynamic_code_generated_while_holding_locks(is_vtable_stub? "vtable stub": "itable stub",  // FIXME: need to pass caller_is_c1??
243                                                                      s->code_begin(), s->code_end());
244       }
245     }
246   }
247   return s->entry_point();
248 }
249 
250 
251 inline uint VtableStubs::hash(bool is_vtable_stub, int vtable_index, bool caller_is_c1) {
252   // Assumption: receiver_location < 4 in most cases.
253   int hash = ((vtable_index << 2) ^ VtableStub::receiver_location()->value()) + vtable_index;
254   if (caller_is_c1) {
255     hash = 7 - hash;
256   }
257   return (is_vtable_stub ? ~hash : hash)  & mask;
258 }
259 
260 
261 VtableStub* VtableStubs::lookup(bool is_vtable_stub, int vtable_index, bool caller_is_c1) {
262   assert_lock_strong(VtableStubs_lock);
263   unsigned hash = VtableStubs::hash(is_vtable_stub, vtable_index, caller_is_c1);
264   VtableStub* s = _table[hash];
265   while( s && !s->matches(is_vtable_stub, vtable_index, caller_is_c1)) s = s->next();
266   return s;
267 }
268 
269 
270 void VtableStubs::enter(bool is_vtable_stub, int vtable_index, bool caller_is_c1, VtableStub* s) {
271   assert_lock_strong(VtableStubs_lock);
272   assert(s->matches(is_vtable_stub, vtable_index, caller_is_c1), "bad vtable stub");
273   unsigned int h = VtableStubs::hash(is_vtable_stub, vtable_index, caller_is_c1);
274   // enter s at the beginning of the corresponding list
275   s->set_next(_table[h]);
276   _table[h] = s;
277   _number_of_vtable_stubs++;
278 }
279 
280 VtableStub* VtableStubs::entry_point(address pc) {
281   MutexLocker ml(VtableStubs_lock, Mutex::_no_safepoint_check_flag);
282   VtableStub* stub = (VtableStub*)(pc - VtableStub::entry_offset());
283   uint hash = VtableStubs::hash(stub->is_vtable_stub(), stub->index(), stub->caller_is_c1());
284   VtableStub* s;
285   for (s = _table[hash]; s != NULL && s != stub; s = s->next()) {}
286   return (s == stub) ? s : NULL;
287 }
288 
289 bool VtableStubs::contains(address pc) {
290   // simple solution for now - we may want to use
291   // a faster way if this function is called often
292   return stub_containing(pc) != NULL;
293 }
294 
295 
296 VtableStub* VtableStubs::stub_containing(address pc) {
297   // Note: No locking needed since any change to the data structure
298   //       happens with an atomic store into it (we don't care about
299   //       consistency with the _number_of_vtable_stubs counter).
300   for (int i = 0; i < N; i++) {
301     for (VtableStub* s = _table[i]; s != NULL; s = s->next()) {
302       if (s->contains(pc)) return s;
303     }
< prev index next >