< prev index next >

src/hotspot/share/code/vtableStubs.hpp

Print this page


  69 
  70 // VtableStubs creates the code stubs for compiled calls through vtables.
  71 // There is one stub per (vtable index, args_size) pair, and the stubs are
  72 // never deallocated. They don't need to be GCed because they contain no oops.
  73 class VtableStub;
  74 
  75 class VtableStubs : AllStatic {
  76  public:                                         // N must be public (some compilers need this for _table)
  77   enum {
  78     N    = 256,                                  // size of stub table; must be power of two
  79     mask = N - 1
  80   };
  81 
  82  private:
  83   friend class VtableStub;
  84   static VtableStub* _table[N];                  // table of existing stubs
  85   static int         _number_of_vtable_stubs;    // number of stubs created so far (for statistics)
  86   static int         _vtab_stub_size;            // current size estimate for vtable stub (quasi-constant)
  87   static int         _itab_stub_size;            // current size estimate for itable stub (quasi-constant)
  88 
  89   static VtableStub* create_vtable_stub(int vtable_index);
  90   static VtableStub* create_itable_stub(int vtable_index);
  91   static VtableStub* lookup            (bool is_vtable_stub, int vtable_index);
  92   static void        enter             (bool is_vtable_stub, int vtable_index, VtableStub* s);
  93   static inline uint hash              (bool is_vtable_stub, int vtable_index);
  94   static address     find_stub         (bool is_vtable_stub, int vtable_index);
  95   static void        bookkeeping(MacroAssembler* masm, outputStream* out, VtableStub* s,
  96                                  address npe_addr, address ame_addr,   bool is_vtable_stub,
  97                                  int     index,    int     slop_bytes, int  index_dependent_slop);
  98   static int         code_size_limit(bool is_vtable_stub);
  99   static void        check_and_set_size_limit(bool is_vtable_stub,
 100                                               int   code_size,
 101                                               int   padding);
 102 
 103  public:
 104   static address     find_vtable_stub(int vtable_index) { return find_stub(true,  vtable_index); }
 105   static address     find_itable_stub(int itable_index) { return find_stub(false, itable_index); }
 106 
 107   static VtableStub* entry_point(address pc);                        // vtable stub entry point for a pc
 108   static bool        contains(address pc);                           // is pc within any stub?
 109   static VtableStub* stub_containing(address pc);                    // stub containing pc or NULL
 110   static int         number_of_vtable_stubs() { return _number_of_vtable_stubs; }
 111   static void        initialize();
 112   static void        vtable_stub_do(void f(VtableStub*));            // iterates over all vtable stubs
 113 };
 114 
 115 
 116 class VtableStub {
 117  private:
 118   friend class VtableStubs;
 119 
 120   static address _chunk;             // For allocation
 121   static address _chunk_end;         // For allocation
 122   static VMReg   _receiver_location; // Where to find receiver
 123 
 124   VtableStub*    _next;              // Pointer to next entry in hash table
 125   const short    _index;             // vtable index
 126   short          _ame_offset;        // Where an AbstractMethodError might occur
 127   short          _npe_offset;        // Where a NullPointerException might occur
 128   bool           _is_vtable_stub;    // True if vtable stub, false, is itable stub


 129   /* code follows here */            // The vtableStub code
 130 
 131   void* operator new(size_t size, int code_size) throw();
 132 
 133   VtableStub(bool is_vtable_stub, int index)
 134         : _next(NULL), _index(index), _ame_offset(-1), _npe_offset(-1),
 135           _is_vtable_stub(is_vtable_stub) {}
 136   VtableStub* next() const                       { return _next; }
 137   int index() const                              { return _index; }
 138   static VMReg receiver_location()               { return _receiver_location; }
 139   void set_next(VtableStub* n)                   { _next = n; }
 140 
 141  public:
 142   address code_begin() const                     { return (address)(this + 1); }
 143   address code_end() const                       { return code_begin() + VtableStubs::code_size_limit(_is_vtable_stub); }
 144   address entry_point() const                    { return code_begin(); }
 145   static int entry_offset()                      { return sizeof(class VtableStub); }
 146 
 147   bool matches(bool is_vtable_stub, int index) const {
 148     return _index == index && _is_vtable_stub == is_vtable_stub;
 149   }
 150   bool contains(address pc) const                { return code_begin() <= pc && pc < code_end(); }
 151 
 152  private:
 153   void set_exception_points(address npe_addr, address ame_addr) {
 154     _npe_offset = npe_addr - code_begin();
 155     _ame_offset = ame_addr - code_begin();
 156     assert(is_abstract_method_error(ame_addr),   "offset must be correct");
 157     assert(is_null_pointer_exception(npe_addr),  "offset must be correct");
 158     assert(!is_abstract_method_error(npe_addr),  "offset must be correct");
 159     assert(!is_null_pointer_exception(ame_addr), "offset must be correct");
 160   }
 161 
 162   // platform-dependent routines
 163   static int  pd_code_alignment();
 164   // CNC: Removed because vtable stubs are now made with an ideal graph
 165   // static bool pd_disregard_arg_size();
 166 
 167   static void align_chunk() {
 168     uintptr_t off = (uintptr_t)( _chunk + sizeof(VtableStub) ) % pd_code_alignment();
 169     if (off != 0)  _chunk += pd_code_alignment() - off;
 170   }
 171 
 172  public:
 173   // Query
 174   bool is_itable_stub()                          { return !_is_vtable_stub; }
 175   bool is_vtable_stub()                          { return  _is_vtable_stub; }

 176   bool is_abstract_method_error(address epc)     { return epc == code_begin()+_ame_offset; }
 177   bool is_null_pointer_exception(address epc)    { return epc == code_begin()+_npe_offset; }
 178 
 179   void print_on(outputStream* st) const;
 180   void print() const                             { print_on(tty); }
 181 
 182 };
 183 
 184 #endif // SHARE_CODE_VTABLESTUBS_HPP


  69 
  70 // VtableStubs creates the code stubs for compiled calls through vtables.
  71 // There is one stub per (vtable index, args_size) pair, and the stubs are
  72 // never deallocated. They don't need to be GCed because they contain no oops.
  73 class VtableStub;
  74 
  75 class VtableStubs : AllStatic {
  76  public:                                         // N must be public (some compilers need this for _table)
  77   enum {
  78     N    = 256,                                  // size of stub table; must be power of two
  79     mask = N - 1
  80   };
  81 
  82  private:
  83   friend class VtableStub;
  84   static VtableStub* _table[N];                  // table of existing stubs
  85   static int         _number_of_vtable_stubs;    // number of stubs created so far (for statistics)
  86   static int         _vtab_stub_size;            // current size estimate for vtable stub (quasi-constant)
  87   static int         _itab_stub_size;            // current size estimate for itable stub (quasi-constant)
  88 
  89   static VtableStub* create_vtable_stub(int vtable_index, bool caller_is_c1);
  90   static VtableStub* create_itable_stub(int vtable_index, bool caller_is_c1);
  91   static VtableStub* lookup            (bool is_vtable_stub, int vtable_index, bool caller_is_c1);
  92   static void        enter             (bool is_vtable_stub, int vtable_index, bool caller_is_c1, VtableStub* s);
  93   static inline uint hash              (bool is_vtable_stub, int vtable_index, bool caller_is_c1);
  94   static address     find_stub         (bool is_vtable_stub, int vtable_index, bool caller_is_c1);
  95   static void        bookkeeping(MacroAssembler* masm, outputStream* out, VtableStub* s,
  96                                  address npe_addr, address ame_addr,   bool is_vtable_stub,
  97                                  int     index,    int     slop_bytes, int  index_dependent_slop);
  98   static int         code_size_limit(bool is_vtable_stub);
  99   static void        check_and_set_size_limit(bool is_vtable_stub,
 100                                               int   code_size,
 101                                               int   padding);
 102 
 103  public:
 104   static address     find_vtable_stub(int vtable_index, bool caller_is_c1) { return find_stub(true,  vtable_index, caller_is_c1); }
 105   static address     find_itable_stub(int itable_index, bool caller_is_c1) { return find_stub(false, itable_index, caller_is_c1); }
 106 
 107   static VtableStub* entry_point(address pc);                        // vtable stub entry point for a pc
 108   static bool        contains(address pc);                           // is pc within any stub?
 109   static VtableStub* stub_containing(address pc);                    // stub containing pc or NULL
 110   static int         number_of_vtable_stubs() { return _number_of_vtable_stubs; }
 111   static void        initialize();
 112   static void        vtable_stub_do(void f(VtableStub*));            // iterates over all vtable stubs
 113 };
 114 
 115 
 116 class VtableStub {
 117  private:
 118   friend class VtableStubs;
 119 
 120   static address _chunk;             // For allocation
 121   static address _chunk_end;         // For allocation
 122   static VMReg   _receiver_location; // Where to find receiver
 123 
 124   VtableStub*    _next;              // Pointer to next entry in hash table
 125   const short    _index;             // vtable index
 126   short          _ame_offset;        // Where an AbstractMethodError might occur
 127   short          _npe_offset;        // Where a NullPointerException might occur
 128   bool           _is_vtable_stub;    // True if vtable stub, false, is itable stub
 129   bool           _caller_is_c1;      // True if this is for a caller compiled by C1,
 130                                      // which doesn't scalarize parameters.
 131   /* code follows here */            // The vtableStub code
 132 
 133   void* operator new(size_t size, int code_size) throw();
 134 
 135   VtableStub(bool is_vtable_stub, int index, bool caller_is_c1)
 136         : _next(NULL), _index(index), _ame_offset(-1), _npe_offset(-1),
 137           _is_vtable_stub(is_vtable_stub), _caller_is_c1(caller_is_c1) {}
 138   VtableStub* next() const                       { return _next; }
 139   int index() const                              { return _index; }
 140   static VMReg receiver_location()               { return _receiver_location; }
 141   void set_next(VtableStub* n)                   { _next = n; }
 142 
 143  public:
 144   address code_begin() const                     { return (address)(this + 1); }
 145   address code_end() const                       { return code_begin() + VtableStubs::code_size_limit(_is_vtable_stub); }
 146   address entry_point() const                    { return code_begin(); }
 147   static int entry_offset()                      { return sizeof(class VtableStub); }
 148 
 149   bool matches(bool is_vtable_stub, int index, bool caller_is_c1) const {
 150     return _index == index && _is_vtable_stub == is_vtable_stub && _caller_is_c1 == caller_is_c1;
 151   }
 152   bool contains(address pc) const                { return code_begin() <= pc && pc < code_end(); }
 153 
 154  private:
 155   void set_exception_points(address npe_addr, address ame_addr) {
 156     _npe_offset = npe_addr - code_begin();
 157     _ame_offset = ame_addr - code_begin();
 158     assert(is_abstract_method_error(ame_addr),   "offset must be correct");
 159     assert(is_null_pointer_exception(npe_addr),  "offset must be correct");
 160     assert(!is_abstract_method_error(npe_addr),  "offset must be correct");
 161     assert(!is_null_pointer_exception(ame_addr), "offset must be correct");
 162   }
 163 
 164   // platform-dependent routines
 165   static int  pd_code_alignment();
 166   // CNC: Removed because vtable stubs are now made with an ideal graph
 167   // static bool pd_disregard_arg_size();
 168 
 169   static void align_chunk() {
 170     uintptr_t off = (uintptr_t)( _chunk + sizeof(VtableStub) ) % pd_code_alignment();
 171     if (off != 0)  _chunk += pd_code_alignment() - off;
 172   }
 173 
 174  public:
 175   // Query
 176   bool is_itable_stub()                          { return !_is_vtable_stub; }
 177   bool is_vtable_stub()                          { return  _is_vtable_stub; }
 178   bool caller_is_c1()                            { return  _caller_is_c1;   }
 179   bool is_abstract_method_error(address epc)     { return epc == code_begin()+_ame_offset; }
 180   bool is_null_pointer_exception(address epc)    { return epc == code_begin()+_npe_offset; }
 181 
 182   void print_on(outputStream* st) const;
 183   void print() const                             { print_on(tty); }
 184 
 185 };
 186 
 187 #endif // SHARE_CODE_VTABLESTUBS_HPP
< prev index next >