153 // If any code changes between the end of the verified entry where the entry
154 // barrier resides, and the completion of the frame, then
155 // NativeNMethodCmpBarrier::verify() will immediately complain when it does
156 // not find the expected native instruction at this offset, which needs updating.
157 // Note that this offset is invariant of PreserveFramePointer.
158 static int entry_barrier_offset(nmethod* nm) {
159 if (nm->is_compiled_by_c2()) {
160 return -14;
161 } else {
162 return -15;
163 }
164 }
165
166 static NativeNMethodCmpBarrier* native_nmethod_barrier(nmethod* nm) {
167 address barrier_address = nm->code_begin() + nm->frame_complete_offset() + entry_barrier_offset(nm);
168 NativeNMethodCmpBarrier* barrier = reinterpret_cast<NativeNMethodCmpBarrier*>(barrier_address);
169 barrier->verify();
170 return barrier;
171 }
172
173 void BarrierSetNMethod::set_guard_value(nmethod* nm, int value, int bit_mask) {
174 if (!supports_entry_barrier(nm)) {
175 return;
176 }
177
178 NativeNMethodCmpBarrier* cmp = native_nmethod_barrier(nm);
179 cmp->set_immediate(value, bit_mask);
180 }
181
182 int BarrierSetNMethod::guard_value(nmethod* nm) {
183 if (!supports_entry_barrier(nm)) {
184 return disarmed_guard_value();
185 }
186
187 NativeNMethodCmpBarrier* cmp = native_nmethod_barrier(nm);
188 return cmp->get_immediate();
189 }
|
153 // If any code changes between the end of the verified entry where the entry
154 // barrier resides, and the completion of the frame, then
155 // NativeNMethodCmpBarrier::verify() will immediately complain when it does
156 // not find the expected native instruction at this offset, which needs updating.
157 // Note that this offset is invariant of PreserveFramePointer.
158 static int entry_barrier_offset(nmethod* nm) {
159 if (nm->is_compiled_by_c2()) {
160 return -14;
161 } else {
162 return -15;
163 }
164 }
165
166 static NativeNMethodCmpBarrier* native_nmethod_barrier(nmethod* nm) {
167 address barrier_address = nm->code_begin() + nm->frame_complete_offset() + entry_barrier_offset(nm);
168 NativeNMethodCmpBarrier* barrier = reinterpret_cast<NativeNMethodCmpBarrier*>(barrier_address);
169 barrier->verify();
170 return barrier;
171 }
172
173 static void set_immediate(nmethod* nm, jint val, int bit_mask) {
174 NativeNMethodCmpBarrier* cmp1 = native_nmethod_barrier(nm);
175 cmp1->set_immediate(val, bit_mask);
176
177 if (!nm->is_osr_method() && nm->method()->has_scalarized_args()) {
178 // nmethods with scalarized arguments have multiple entry points that each have an own nmethod entry barrier
179 assert(nm->verified_entry_point() != nm->verified_inline_entry_point(), "scalarized entry point not found");
180 address method_body = nm->is_compiled_by_c1() ? nm->verified_inline_entry_point() : nm->verified_entry_point();
181 address entry_point2 = nm->is_compiled_by_c1() ? nm->verified_entry_point() : nm->verified_inline_entry_point();
182
183 int barrier_offset = reinterpret_cast<address>(cmp1) - method_body;
184 NativeNMethodCmpBarrier* cmp2 = reinterpret_cast<NativeNMethodCmpBarrier*>(entry_point2 + barrier_offset);
185 assert(cmp1 != cmp2, "sanity");
186 DEBUG_ONLY(cmp2->verify());
187 cmp2->set_immediate(val, bit_mask);
188
189 if (method_body != nm->verified_inline_ro_entry_point() && entry_point2 != nm->verified_inline_ro_entry_point()) {
190 NativeNMethodCmpBarrier* cmp3 = reinterpret_cast<NativeNMethodCmpBarrier*>(nm->verified_inline_ro_entry_point() + barrier_offset);
191 assert(cmp1 != cmp3 && cmp2 != cmp3, "sanity");
192 DEBUG_ONLY(cmp3->verify());
193 cmp3->set_immediate(val, bit_mask);
194 }
195 }
196 }
197
198 void BarrierSetNMethod::set_guard_value(nmethod* nm, int value, int bit_mask) {
199 if (!supports_entry_barrier(nm)) {
200 return;
201 }
202
203 set_immediate(nm, value, bit_mask);
204 }
205
206 int BarrierSetNMethod::guard_value(nmethod* nm) {
207 if (!supports_entry_barrier(nm)) {
208 return disarmed_guard_value();
209 }
210
211 NativeNMethodCmpBarrier* cmp = native_nmethod_barrier(nm);
212 return cmp->get_immediate();
213 }
|