< prev index next >

src/hotspot/share/code/vtableStubs.hpp

Print this page

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





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


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

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

184   bool is_abstract_method_error(address epc)     { return epc == code_begin()+_ame_offset; }
185   bool is_null_pointer_exception(address epc)    { return epc == code_begin()+_npe_offset; }
186 
187   void print_on(outputStream* st) const;
188   void print() const;
189 
190 };
191 
192 #endif // SHARE_CODE_VTABLESTUBS_HPP

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