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 address find_stub (bool is_vtable_stub, int vtable_index);
97 static void bookkeeping(MacroAssembler* masm, outputStream* out, VtableStub* s,
98 address npe_addr, address ame_addr, bool is_vtable_stub,
99 int index, int slop_bytes, int index_dependent_slop);
100 static int code_size_limit(bool is_vtable_stub);
101 static void check_and_set_size_limit(bool is_vtable_stub,
102 int code_size,
103 int padding);
104
105 public:
106 static address find_vtable_stub(int vtable_index) { return find_stub(true, vtable_index); }
107 static address find_itable_stub(int itable_index) { return find_stub(false, itable_index); }
108
109 static VtableStub* entry_point(address pc); // vtable stub entry point for a pc
110 static bool is_icholder_entry(address pc); // is the blob containing pc (which must be a vtable blob) an icholder?
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 static address _chunk; // For allocation
123 static address _chunk_end; // For allocation
124 static VMReg _receiver_location; // Where to find receiver
125
126 VtableStub* _next; // Pointer to next entry in hash table
127 const short _index; // vtable index
128 short _ame_offset; // Where an AbstractMethodError might occur
129 short _npe_offset; // Where a NullPointerException might occur
130 bool _is_vtable_stub; // True if vtable stub, false, is itable stub
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, short index)
136 : _next(nullptr), _index(index), _ame_offset(-1), _npe_offset(-1),
137 _is_vtable_stub(is_vtable_stub) {}
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) const {
150 return _index == index && _is_vtable_stub == is_vtable_stub;
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 = checked_cast<short>(npe_addr - code_begin());
157 _ame_offset = checked_cast<short>(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 is_abstract_method_error(address epc) { return epc == code_begin()+_ame_offset; }
179 bool is_null_pointer_exception(address epc) { return epc == code_begin()+_npe_offset; }
180
181 void print_on(outputStream* st) const;
182 void print() const;
183
184 };
185
186 #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 address find_stub (bool is_vtable_stub, int vtable_index, bool caller_is_c1);
97 static void bookkeeping(MacroAssembler* masm, outputStream* out, VtableStub* s,
98 address npe_addr, address ame_addr, bool is_vtable_stub,
99 int index, int slop_bytes, int index_dependent_slop);
100 static int code_size_limit(bool is_vtable_stub);
101 static void check_and_set_size_limit(bool is_vtable_stub,
102 int code_size,
103 int padding);
104
105 public:
106 static address find_vtable_stub(int vtable_index, bool caller_is_c1) { return find_stub(true, vtable_index, caller_is_c1); }
107 static address find_itable_stub(int itable_index, bool caller_is_c1) { return find_stub(false, itable_index, caller_is_c1); }
108
109 static VtableStub* entry_point(address pc); // vtable stub entry point for a pc
110 static bool is_icholder_entry(address pc); // is the blob containing pc (which must be a vtable blob) an icholder?
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 static address _chunk; // For allocation
123 static address _chunk_end; // For allocation
124 static VMReg _receiver_location; // Where to find receiver
125
126 VtableStub* _next; // Pointer to next entry in hash table
127 const short _index; // vtable index
128 short _ame_offset; // Where an AbstractMethodError might occur
129 short _npe_offset; // Where a NullPointerException might occur
130 bool _is_vtable_stub; // True if vtable stub, false, is itable stub
131 bool _caller_is_c1; // True if this is for a caller compiled by C1,
132 // which doesn't scalarize parameters.
133 /* code follows here */ // The vtableStub code
134
135 void* operator new(size_t size, int code_size) throw();
136
137 VtableStub(bool is_vtable_stub, short index, bool caller_is_c1)
138 : _next(nullptr), _index(index), _ame_offset(-1), _npe_offset(-1),
139 _is_vtable_stub(is_vtable_stub), _caller_is_c1(caller_is_c1) {}
140 VtableStub* next() const { return _next; }
141 int index() const { return _index; }
142 static VMReg receiver_location() { return _receiver_location; }
143 void set_next(VtableStub* n) { _next = n; }
144
145 public:
146 address code_begin() const { return (address)(this + 1); }
147 address code_end() const { return code_begin() + VtableStubs::code_size_limit(_is_vtable_stub); }
148 address entry_point() const { return code_begin(); }
149 static int entry_offset() { return sizeof(class VtableStub); }
150
151 bool matches(bool is_vtable_stub, int index, bool caller_is_c1) const {
152 return _index == index && _is_vtable_stub == is_vtable_stub && _caller_is_c1 == caller_is_c1;
153 }
154 bool contains(address pc) const { return code_begin() <= pc && pc < code_end(); }
155
156 private:
157 void set_exception_points(address npe_addr, address ame_addr) {
158 _npe_offset = checked_cast<short>(npe_addr - code_begin());
159 _ame_offset = checked_cast<short>(ame_addr - code_begin());
160 assert(is_abstract_method_error(ame_addr), "offset must be correct");
161 assert(is_null_pointer_exception(npe_addr), "offset must be correct");
162 assert(!is_abstract_method_error(npe_addr), "offset must be correct");
163 assert(!is_null_pointer_exception(ame_addr), "offset must be correct");
164 }
165
166 // platform-dependent routines
167 static int pd_code_alignment();
168 // CNC: Removed because vtable stubs are now made with an ideal graph
169 // static bool pd_disregard_arg_size();
170
171 static void align_chunk() {
172 uintptr_t off = (uintptr_t)( _chunk + sizeof(VtableStub) ) % pd_code_alignment();
173 if (off != 0) _chunk += pd_code_alignment() - off;
174 }
175
176 public:
177 // Query
178 bool is_itable_stub() { return !_is_vtable_stub; }
179 bool is_vtable_stub() { return _is_vtable_stub; }
180 bool caller_is_c1() { return _caller_is_c1; }
181 bool is_abstract_method_error(address epc) { return epc == code_begin()+_ame_offset; }
182 bool is_null_pointer_exception(address epc) { return epc == code_begin()+_npe_offset; }
183
184 void print_on(outputStream* st) const;
185 void print() const;
186
187 };
188
189 #endif // SHARE_CODE_VTABLESTUBS_HPP
|