< prev index next >

src/share/vm/code/vtableStubs.cpp

Print this page
rev 9019 : [mq]: format.patch


  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "code/vtableStubs.hpp"
  27 #include "compiler/compileBroker.hpp"
  28 #include "compiler/disassembler.hpp"
  29 #include "memory/allocation.inline.hpp"
  30 #include "memory/resourceArea.hpp"
  31 #include "oops/instanceKlass.hpp"
  32 #include "oops/klassVtable.hpp"
  33 #include "oops/oop.inline.hpp"
  34 #include "prims/forte.hpp"
  35 #include "prims/jvmtiExport.hpp"
  36 #include "runtime/handles.inline.hpp"
  37 #include "runtime/mutexLocker.hpp"
  38 #include "runtime/sharedRuntime.hpp"
  39 #ifdef COMPILER2
  40 #include "opto/matcher.hpp"
  41 #endif
  42 
  43 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
  44 
  45 // -----------------------------------------------------------------------------------------
  46 // Implementation of VtableStub
  47 
  48 address VtableStub::_chunk             = NULL;
  49 address VtableStub::_chunk_end         = NULL;
  50 VMReg   VtableStub::_receiver_location = VMRegImpl::Bad();
  51 
  52 
  53 void* VtableStub::operator new(size_t size, int code_size) throw() {
  54   assert(size == sizeof(VtableStub), "mismatched size");
  55   // compute real VtableStub size (rounded to nearest word)
  56   const int real_size = round_to(code_size + sizeof(VtableStub), wordSize);
  57   // malloc them in chunks to minimize header overhead
  58   const int chunk_factor = 32;
  59   if (_chunk == NULL || _chunk + real_size > _chunk_end) {
  60     const int bytes = chunk_factor * real_size + pd_code_alignment();
  61 
  62    // There is a dependency on the name of the blob in src/share/vm/prims/jvmtiCodeBlobEvents.cpp
  63    // If changing the name, update the other file accordingly.
  64     BufferBlob* blob = BufferBlob::create("vtable chunks", bytes);
  65     if (blob == NULL) {
  66       return NULL;
  67     }
  68     _chunk = blob->content_begin();
  69     _chunk_end = _chunk + bytes;
  70     Forte::register_stub("vtable stub", _chunk, _chunk_end);
  71     align_chunk();
  72   }
  73   assert(_chunk + real_size <= _chunk_end, "bad allocation");
  74   void* res = _chunk;
  75   _chunk += real_size;
  76   align_chunk();
  77  return res;
  78 }
  79 
  80 
  81 void VtableStub::print_on(outputStream* st) const {
  82   st->print("vtable stub (index = %d, receiver_location = %d, code = [" INTPTR_FORMAT ", " INTPTR_FORMAT "[)",
  83              index(), receiver_location(), code_begin(), code_end());


  84 }
  85 
  86 
  87 // -----------------------------------------------------------------------------------------
  88 // Implementation of VtableStubs
  89 //
  90 // For each hash value there's a linked list of vtable stubs (with that
  91 // hash value). Each list is anchored in a little hash _table, indexed
  92 // by that hash value.
  93 
  94 VtableStub* VtableStubs::_table[VtableStubs::N];
  95 int VtableStubs::_number_of_vtable_stubs = 0;
  96 
  97 
  98 void VtableStubs::initialize() {
  99   VtableStub::_receiver_location = SharedRuntime::name_for_receiver();
 100   {
 101     MutexLocker ml(VtableStubs_lock);
 102     assert(_number_of_vtable_stubs == 0, "potential performance bug: VtableStubs initialized more than once");
 103     assert(is_power_of_2(N), "N must be a power of 2");


 109 
 110 
 111 address VtableStubs::find_stub(bool is_vtable_stub, int vtable_index) {
 112   assert(vtable_index >= 0, "must be positive");
 113 
 114   VtableStub* s = ShareVtableStubs ? lookup(is_vtable_stub, vtable_index) : NULL;
 115   if (s == NULL) {
 116     if (is_vtable_stub) {
 117       s = create_vtable_stub(vtable_index);
 118     } else {
 119       s = create_itable_stub(vtable_index);
 120     }
 121 
 122     // Creation of vtable or itable can fail if there is not enough free space in the code cache.
 123     if (s == NULL) {
 124       return NULL;
 125     }
 126 
 127     enter(is_vtable_stub, vtable_index, s);
 128     if (PrintAdapterHandlers) {
 129       tty->print_cr("Decoding VtableStub %s[%d]@%d",
 130                     is_vtable_stub? "vtbl": "itbl", vtable_index, VtableStub::receiver_location());

 131       Disassembler::decode(s->code_begin(), s->code_end());
 132     }
 133     // Notify JVMTI about this stub. The event will be recorded by the enclosing
 134     // JvmtiDynamicCodeEventCollector and posted when this thread has released
 135     // all locks.
 136     if (JvmtiExport::should_post_dynamic_code_generated()) {
 137       JvmtiExport::post_dynamic_code_generated_while_holding_locks(is_vtable_stub? "vtable stub": "itable stub",
 138                                                                    s->code_begin(), s->code_end());
 139     }
 140   }
 141   return s->entry_point();
 142 }
 143 
 144 
 145 inline uint VtableStubs::hash(bool is_vtable_stub, int vtable_index){
 146   // Assumption: receiver_location < 4 in most cases.
 147   int hash = ((vtable_index << 2) ^ VtableStub::receiver_location()->value()) + vtable_index;
 148   return (is_vtable_stub ? ~hash : hash)  & mask;
 149 }
 150 


 207         for (VtableStub* s = _table[i]; s != NULL; s = s->next()) {
 208             f(s);
 209         }
 210     }
 211 }
 212 
 213 
 214 //-----------------------------------------------------------------------------------------------------
 215 // Non-product code
 216 #ifndef PRODUCT
 217 
 218 extern "C" void bad_compiled_vtable_index(JavaThread* thread, oop receiver, int index) {
 219   ResourceMark rm;
 220   HandleMark hm;
 221   Klass* klass = receiver->klass();
 222   InstanceKlass* ik = InstanceKlass::cast(klass);
 223   klassVtable* vt = ik->vtable();
 224   ik->print();
 225   fatal("bad compiled vtable dispatch: receiver " INTPTR_FORMAT ", "
 226         "index %d (vtable length %d)",
 227         (address)receiver, index, vt->length());
 228 }
 229 
 230 #endif // PRODUCT


  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "code/vtableStubs.hpp"
  27 #include "compiler/compileBroker.hpp"
  28 #include "compiler/disassembler.hpp"
  29 #include "memory/allocation.inline.hpp"
  30 #include "memory/resourceArea.hpp"
  31 #include "oops/instanceKlass.hpp"
  32 #include "oops/klassVtable.hpp"
  33 #include "oops/oop.inline.hpp"
  34 #include "prims/forte.hpp"
  35 #include "prims/jvmtiExport.hpp"
  36 #include "runtime/handles.inline.hpp"
  37 #include "runtime/mutexLocker.hpp"
  38 #include "runtime/sharedRuntime.hpp"
  39 #ifdef COMPILER2
  40 #include "opto/matcher.hpp"
  41 #endif
  42 


  43 // -----------------------------------------------------------------------------------------
  44 // Implementation of VtableStub
  45 
  46 address VtableStub::_chunk             = NULL;
  47 address VtableStub::_chunk_end         = NULL;
  48 VMReg   VtableStub::_receiver_location = VMRegImpl::Bad();
  49 
  50 
  51 void* VtableStub::operator new(size_t size, int code_size) throw() {
  52   assert(size == sizeof(VtableStub), "mismatched size");
  53   // compute real VtableStub size (rounded to nearest word)
  54   const int real_size = round_to(code_size + sizeof(VtableStub), wordSize);
  55   // malloc them in chunks to minimize header overhead
  56   const int chunk_factor = 32;
  57   if (_chunk == NULL || _chunk + real_size > _chunk_end) {
  58     const int bytes = chunk_factor * real_size + pd_code_alignment();
  59 
  60    // There is a dependency on the name of the blob in src/share/vm/prims/jvmtiCodeBlobEvents.cpp
  61    // If changing the name, update the other file accordingly.
  62     BufferBlob* blob = BufferBlob::create("vtable chunks", bytes);
  63     if (blob == NULL) {
  64       return NULL;
  65     }
  66     _chunk = blob->content_begin();
  67     _chunk_end = _chunk + bytes;
  68     Forte::register_stub("vtable stub", _chunk, _chunk_end);
  69     align_chunk();
  70   }
  71   assert(_chunk + real_size <= _chunk_end, "bad allocation");
  72   void* res = _chunk;
  73   _chunk += real_size;
  74   align_chunk();
  75  return res;
  76 }
  77 
  78 
  79 void VtableStub::print_on(outputStream* st) const {
  80   st->print("vtable stub (index = %d, receiver_location = %s/" INTX_FORMAT ", code = "
  81             "[" INTPTR_FORMAT ", " INTPTR_FORMAT "[)",
  82             index(), receiver_location()->name(), receiver_location()->value(),
  83             p2i(code_begin()), p2i(code_end()));
  84 }
  85 
  86 
  87 // -----------------------------------------------------------------------------------------
  88 // Implementation of VtableStubs
  89 //
  90 // For each hash value there's a linked list of vtable stubs (with that
  91 // hash value). Each list is anchored in a little hash _table, indexed
  92 // by that hash value.
  93 
  94 VtableStub* VtableStubs::_table[VtableStubs::N];
  95 int VtableStubs::_number_of_vtable_stubs = 0;
  96 
  97 
  98 void VtableStubs::initialize() {
  99   VtableStub::_receiver_location = SharedRuntime::name_for_receiver();
 100   {
 101     MutexLocker ml(VtableStubs_lock);
 102     assert(_number_of_vtable_stubs == 0, "potential performance bug: VtableStubs initialized more than once");
 103     assert(is_power_of_2(N), "N must be a power of 2");


 109 
 110 
 111 address VtableStubs::find_stub(bool is_vtable_stub, int vtable_index) {
 112   assert(vtable_index >= 0, "must be positive");
 113 
 114   VtableStub* s = ShareVtableStubs ? lookup(is_vtable_stub, vtable_index) : NULL;
 115   if (s == NULL) {
 116     if (is_vtable_stub) {
 117       s = create_vtable_stub(vtable_index);
 118     } else {
 119       s = create_itable_stub(vtable_index);
 120     }
 121 
 122     // Creation of vtable or itable can fail if there is not enough free space in the code cache.
 123     if (s == NULL) {
 124       return NULL;
 125     }
 126 
 127     enter(is_vtable_stub, vtable_index, s);
 128     if (PrintAdapterHandlers) {
 129       tty->print_cr("Decoding VtableStub %s[%d]@%s/" INTX_FORMAT "",
 130                     is_vtable_stub? "vtbl": "itbl", vtable_index, 
 131                     VtableStub::receiver_location()->name(), VtableStub::receiver_location()->value());
 132       Disassembler::decode(s->code_begin(), s->code_end());
 133     }
 134     // Notify JVMTI about this stub. The event will be recorded by the enclosing
 135     // JvmtiDynamicCodeEventCollector and posted when this thread has released
 136     // all locks.
 137     if (JvmtiExport::should_post_dynamic_code_generated()) {
 138       JvmtiExport::post_dynamic_code_generated_while_holding_locks(is_vtable_stub? "vtable stub": "itable stub",
 139                                                                    s->code_begin(), s->code_end());
 140     }
 141   }
 142   return s->entry_point();
 143 }
 144 
 145 
 146 inline uint VtableStubs::hash(bool is_vtable_stub, int vtable_index){
 147   // Assumption: receiver_location < 4 in most cases.
 148   int hash = ((vtable_index << 2) ^ VtableStub::receiver_location()->value()) + vtable_index;
 149   return (is_vtable_stub ? ~hash : hash)  & mask;
 150 }
 151 


 208         for (VtableStub* s = _table[i]; s != NULL; s = s->next()) {
 209             f(s);
 210         }
 211     }
 212 }
 213 
 214 
 215 //-----------------------------------------------------------------------------------------------------
 216 // Non-product code
 217 #ifndef PRODUCT
 218 
 219 extern "C" void bad_compiled_vtable_index(JavaThread* thread, oop receiver, int index) {
 220   ResourceMark rm;
 221   HandleMark hm;
 222   Klass* klass = receiver->klass();
 223   InstanceKlass* ik = InstanceKlass::cast(klass);
 224   klassVtable* vt = ik->vtable();
 225   ik->print();
 226   fatal("bad compiled vtable dispatch: receiver " INTPTR_FORMAT ", "
 227         "index %d (vtable length %d)",
 228         p2i(receiver), index, vt->length());
 229 }
 230 
 231 #endif // PRODUCT
< prev index next >