< prev index next >

src/hotspot/share/code/vtableStubs.cpp

Print this page




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



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




 190                            (int)(masm->pc() - s->code_begin()),
 191                            stub_length,
 192                            (int)(s->code_end() - masm->pc()));
 193   }
 194   guarantee(masm->pc() <= s->code_end(), "%s #%d: overflowed buffer, estimated len: %d, actual len: %d, overrun: %d",
 195                                          name, index, stub_length,
 196                                          (int)(masm->pc() - s->code_begin()),
 197                                          (int)(masm->pc() - s->code_end()));
 198   assert((masm->pc() + index_dependent_slop) <= s->code_end(), "%s #%d: spare space for 32-bit offset: required = %d, available = %d",
 199                                          name, index, index_dependent_slop,
 200                                          (int)(s->code_end() - masm->pc()));
 201 
 202   // After the first vtable/itable stub is generated, we have a much
 203   // better estimate for the stub size. Remember/update this
 204   // estimate after some sanity checks.
 205   check_and_set_size_limit(is_vtable_stub, masm->offset(), slop_bytes);
 206   s->set_exception_points(npe_addr, ame_addr);
 207 }
 208 
 209 
 210 address VtableStubs::find_stub(bool is_vtable_stub, int vtable_index, bool caller_is_c1) {
 211   assert(vtable_index >= 0, "must be positive");
 212 
 213   VtableStub* s;
 214   {
 215     MutexLocker ml(VtableStubs_lock, Mutex::_no_safepoint_check_flag);
 216     s = ShareVtableStubs ? lookup(is_vtable_stub, vtable_index, caller_is_c1) : NULL;
 217     if (s == NULL) {
 218       if (is_vtable_stub) {
 219         s = create_vtable_stub(vtable_index, caller_is_c1);
 220       } else {
 221         s = create_itable_stub(vtable_index, caller_is_c1);
 222       }
 223 
 224       // Creation of vtable or itable can fail if there is not enough free space in the code cache.
 225       if (s == NULL) {
 226         return NULL;
 227       }
 228 
 229       enter(is_vtable_stub, vtable_index, caller_is_c1, s);
 230       if (PrintAdapterHandlers) {
 231         tty->print_cr("Decoding VtableStub (%s) %s[%d]@" INTX_FORMAT, caller_is_c1 ? "c1" : "full opt",
 232                       is_vtable_stub? "vtbl": "itbl", vtable_index, p2i(VtableStub::receiver_location()));
 233         Disassembler::decode(s->code_begin(), s->code_end());
 234       }
 235       // Notify JVMTI about this stub. The event will be recorded by the enclosing
 236       // JvmtiDynamicCodeEventCollector and posted when this thread has released
 237       // all locks.
 238       if (JvmtiExport::should_post_dynamic_code_generated()) {
 239         JvmtiExport::post_dynamic_code_generated_while_holding_locks(is_vtable_stub? "vtable stub": "itable stub",  // FIXME: need to pass caller_is_c1??
 240                                                                      s->code_begin(), s->code_end());
 241       }
 242     }
 243   }
 244   return s->entry_point();
 245 }
 246 
 247 
 248 inline uint VtableStubs::hash(bool is_vtable_stub, int vtable_index, bool caller_is_c1) {
 249   // Assumption: receiver_location < 4 in most cases.
 250   int hash = ((vtable_index << 2) ^ VtableStub::receiver_location()->value()) + vtable_index;
 251   if (caller_is_c1) {
 252     hash = 7 - hash;
 253   }
 254   return (is_vtable_stub ? ~hash : hash)  & mask;
 255 }
 256 
 257 
 258 VtableStub* VtableStubs::lookup(bool is_vtable_stub, int vtable_index, bool caller_is_c1) {
 259   assert_lock_strong(VtableStubs_lock);
 260   unsigned hash = VtableStubs::hash(is_vtable_stub, vtable_index, caller_is_c1);
 261   VtableStub* s = _table[hash];
 262   while( s && !s->matches(is_vtable_stub, vtable_index, caller_is_c1)) s = s->next();
 263   return s;
 264 }
 265 
 266 
 267 void VtableStubs::enter(bool is_vtable_stub, int vtable_index, bool caller_is_c1, VtableStub* s) {
 268   assert_lock_strong(VtableStubs_lock);
 269   assert(s->matches(is_vtable_stub, vtable_index, caller_is_c1), "bad vtable stub");
 270   unsigned int h = VtableStubs::hash(is_vtable_stub, vtable_index, caller_is_c1);
 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(), stub->caller_is_c1());
 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     }


< prev index next >