< prev index next >

src/hotspot/share/code/vtableStubs.hpp

Print this page

 72 // VtableStubs creates the code stubs for compiled calls through vtables.
 73 // There is one stub per (vtable index, args_size) pair, and the stubs are
 74 // never deallocated. They don't need to be GCed because they contain no oops.
 75 class VtableStub;
 76 
 77 class VtableStubs : AllStatic {
 78  public:                                         // N must be public (some compilers need this for _table)
 79   enum {
 80     N    = 256,                                  // size of stub table; must be power of two
 81     mask = N - 1
 82   };
 83 
 84   static_assert(is_power_of_2((int)N), "N must be a power of 2");
 85 
 86  private:
 87   friend class VtableStub;
 88   static VtableStub* volatile _table[N];                  // table of existing stubs
 89   static int         _vtab_stub_size;            // current size estimate for vtable stub (quasi-constant)
 90   static int         _itab_stub_size;            // current size estimate for itable stub (quasi-constant)
 91 
 92   static VtableStub* create_vtable_stub(int vtable_index);
 93   static VtableStub* create_itable_stub(int vtable_index);
 94   static VtableStub* lookup            (bool is_vtable_stub, int vtable_index);
 95   static void        enter             (bool is_vtable_stub, int vtable_index, VtableStub* s);
 96   static inline uint hash              (bool is_vtable_stub, int vtable_index);
 97   static inline uint unsafe_hash       (address entry_point);
 98   static address     find_stub         (bool is_vtable_stub, int vtable_index);
 99   static void        bookkeeping(MacroAssembler* masm, outputStream* out, VtableStub* s,
100                                  address npe_addr, address ame_addr,   bool is_vtable_stub,
101                                  int     index,    int     slop_bytes, int  index_dependent_slop);
102   static int         code_size_limit(bool is_vtable_stub);
103   static void        check_and_set_size_limit(bool is_vtable_stub,
104                                               int   code_size,
105                                               int   padding);
106 
107  public:
108   static address     find_vtable_stub(int vtable_index) { return find_stub(true,  vtable_index); }
109   static address     find_itable_stub(int itable_index) { return find_stub(false, itable_index); }
110 
111   static VtableStub* entry_point(address pc);                        // vtable stub entry point for a pc
112   static bool        contains(address pc);                           // is pc within any stub?
113   static VtableStub* stub_containing(address pc);                    // stub containing pc or nullptr
114   static void        initialize();
115 
116   template <typename F>
117   static void vtable_stub_do(F f);
118 };
119 
120 
121 class VtableStub {
122  private:
123   friend class VtableStubs;
124 
125   enum class Type : uint8_t {
126     itable_stub,
127     vtable_stub,
128   };
129 





130 
131   static address _chunk;             // For allocation
132   static address _chunk_end;         // For allocation
133   static VMReg   _receiver_location; // Where to find receiver
134 
135   VtableStub*    _next;              // Pointer to next entry in hash table
136   const short    _index;             // vtable index
137   short          _ame_offset;        // Where an AbstractMethodError might occur
138   short          _npe_offset;        // Where a NullPointerException might occur
139   Type           _type;              // Type, either vtable stub or itable stub


140   /* code follows here */            // The vtableStub code
141 
142   void* operator new(size_t size, int code_size) throw();
143 
144   VtableStub(bool is_vtable_stub, short index)
145         : _next(nullptr), _index(index), _ame_offset(-1), _npe_offset(-1),
146           _type(is_vtable_stub ? Type::vtable_stub : Type::itable_stub) {}

147   VtableStub* next() const                       { return _next; }
148   static VMReg receiver_location()               { return _receiver_location; }
149   void set_next(VtableStub* n)                   { _next = n; }
150 
151  public:
152   int index() const                              { return _index; }
153   int code_size() const                          { return VtableStubs::code_size_limit(is_vtable_stub()); }
154   address code_begin() const                     { return (address)(this + 1); }
155   address code_end() const                       { return code_begin() + code_size(); }
156   address entry_point() const                    { return code_begin(); }
157   static int entry_offset()                      { return sizeof(class VtableStub); }
158 
159   bool matches(bool is_vtable_stub, int index) const {
160     return _index == index && this->is_vtable_stub() == is_vtable_stub;
161   }
162   bool contains(address pc) const                { return code_begin() <= pc && pc < code_end(); }
163 
164  private:
165   void set_exception_points(address npe_addr, address ame_addr) {
166     _npe_offset = checked_cast<short>(npe_addr - code_begin());
167     _ame_offset = checked_cast<short>(ame_addr - code_begin());
168     assert(is_abstract_method_error(ame_addr),   "offset must be correct");
169     assert(is_null_pointer_exception(npe_addr),  "offset must be correct");
170     assert(!is_abstract_method_error(npe_addr),  "offset must be correct");
171     assert(!is_null_pointer_exception(ame_addr), "offset must be correct");
172   }
173 
174   // platform-dependent routines
175   static int  pd_code_alignment();
176   // CNC: Removed because vtable stubs are now made with an ideal graph
177   // static bool pd_disregard_arg_size();
178 
179   static void align_chunk() {
180     uintptr_t off = (uintptr_t)( _chunk + sizeof(VtableStub) ) % pd_code_alignment();
181     if (off != 0)  _chunk += pd_code_alignment() - off;
182   }
183 
184  public:
185   // Query
186   bool is_itable_stub() const                    { return _type == Type::itable_stub; }
187   bool is_vtable_stub() const                    { return _type == Type::vtable_stub; }

188   bool is_abstract_method_error(address epc)     { return epc == code_begin()+_ame_offset; }
189   bool is_null_pointer_exception(address epc)    { return epc == code_begin()+_npe_offset; }
190 
191   void print_on(outputStream* st) const;
192   void print() const;
193 
194 };
195 
196 template <typename F>
197 void VtableStubs::vtable_stub_do(F f) {
198   for (int i = 0; i < N; i++) {
199     for (VtableStub* s = AtomicAccess::load_acquire(&_table[i]); s != nullptr; s = s->next()) {
200       f(s);
201     }
202   }
203 }
204 
205 #endif // SHARE_CODE_VTABLESTUBS_HPP

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