72
73 // save object being locked into the BasicObjectLock
74 str(obj, Address(disp_hdr, BasicObjectLock::obj_offset_in_bytes()));
75
76 null_check_offset = offset();
77
78 if (DiagnoseSyncOnValueBasedClasses != 0) {
79 load_klass(hdr, obj);
80 ldrw(hdr, Address(hdr, Klass::access_flags_offset()));
81 tstw(hdr, JVM_ACC_IS_VALUE_BASED_CLASS);
82 br(Assembler::NE, slow_case);
83 }
84
85 if (UseBiasedLocking) {
86 assert(scratch != noreg, "should have scratch register at this point");
87 biased_locking_enter(disp_hdr, obj, hdr, scratch, false, done, &slow_case);
88 }
89
90 // Load object header
91 ldr(hdr, Address(obj, hdr_offset));
92 // and mark it as unlocked
93 orr(hdr, hdr, markWord::unlocked_value);
94 // save unlocked object header into the displaced header location on the stack
95 str(hdr, Address(disp_hdr, 0));
96 // test if object header is still the same (i.e. unlocked), and if so, store the
97 // displaced header address in the object header - if it is not the same, get the
98 // object header instead
99 lea(rscratch2, Address(obj, hdr_offset));
100 cmpxchgptr(hdr, disp_hdr, rscratch2, rscratch1, done, /*fallthough*/NULL);
101 // if the object header was the same, we're done
102 // if the object header was not the same, it is now in the hdr register
103 // => test if it is a stack pointer into the same stack (recursive locking), i.e.:
104 //
105 // 1) (hdr & aligned_mask) == 0
106 // 2) sp <= hdr
107 // 3) hdr <= sp + page_size
108 //
109 // these 3 tests can be done by evaluating the following expression:
110 //
111 // (hdr - sp) & (aligned_mask - page_size)
112 //
113 // assuming both the stack pointer and page_size have their least
114 // significant 2 bits cleared and page_size is a power of 2
115 mov(rscratch1, sp);
116 sub(hdr, hdr, rscratch1);
117 ands(hdr, hdr, aligned_mask - os::vm_page_size());
118 // for recursive locking, the result is zero => save it in the displaced header
119 // location (NULL in the displaced hdr location indicates recursive locking)
120 str(hdr, Address(disp_hdr, 0));
121 // otherwise we don't care about the result and handle locking via runtime call
122 cbnz(hdr, slow_case);
123 // done
124 bind(done);
125 if (PrintBiasedLockingStatistics) {
126 lea(rscratch2, ExternalAddress((address)BiasedLocking::fast_path_entry_count_addr()));
127 addmw(Address(rscratch2, 0), 1, rscratch1);
128 }
129 return null_check_offset;
130 }
131
132
133 void C1_MacroAssembler::unlock_object(Register hdr, Register obj, Register disp_hdr, Label& slow_case) {
134 const int aligned_mask = BytesPerWord -1;
135 const int hdr_offset = oopDesc::mark_offset_in_bytes();
136 assert(hdr != obj && hdr != disp_hdr && obj != disp_hdr, "registers must be different");
137 Label done;
138
139 if (UseBiasedLocking) {
140 // load object
141 ldr(obj, Address(disp_hdr, BasicObjectLock::obj_offset_in_bytes()));
142 biased_locking_exit(obj, hdr, done);
143 }
144
145 // load displaced header
146 ldr(hdr, Address(disp_hdr, 0));
147 // if the loaded hdr is NULL we had recursive locking
148 // if we had recursive locking, we are done
149 cbz(hdr, done);
150 if (!UseBiasedLocking) {
151 // load object
152 ldr(obj, Address(disp_hdr, BasicObjectLock::obj_offset_in_bytes()));
153 }
154 verify_oop(obj);
155 // test if object header is pointing to the displaced header, and if so, restore
156 // the displaced header in the object - if the object header is not pointing to
157 // the displaced header, get the object header instead
158 // if the object header was not pointing to the displaced header,
159 // we do unlocking via runtime call
160 if (hdr_offset) {
161 lea(rscratch1, Address(obj, hdr_offset));
162 cmpxchgptr(disp_hdr, hdr, rscratch1, rscratch2, done, &slow_case);
163 } else {
164 cmpxchgptr(disp_hdr, hdr, obj, rscratch2, done, &slow_case);
165 }
166 // done
167 bind(done);
168 }
169
170
171 // Defines obj, preserves var_size_in_bytes
172 void C1_MacroAssembler::try_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2, Label& slow_case) {
173 if (UseTLAB) {
174 tlab_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, t2, slow_case);
175 } else {
176 eden_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, slow_case);
177 }
178 }
179
180 void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register t1, Register t2) {
181 assert_different_registers(obj, klass, len);
182 if (UseBiasedLocking && !len->is_valid()) {
183 assert_different_registers(obj, klass, len, t1, t2);
184 ldr(t1, Address(klass, Klass::prototype_header_offset()));
185 } else {
186 // This assumes that all prototype bits fit in an int32_t
187 mov(t1, (int32_t)(intptr_t)markWord::prototype().value());
188 }
189 str(t1, Address(obj, oopDesc::mark_offset_in_bytes()));
190
191 if (UseCompressedClassPointers) { // Take care not to kill klass
192 encode_klass_not_null(t1, klass);
193 strw(t1, Address(obj, oopDesc::klass_offset_in_bytes()));
194 } else {
195 str(klass, Address(obj, oopDesc::klass_offset_in_bytes()));
196 }
197
198 if (len->is_valid()) {
199 strw(len, Address(obj, arrayOopDesc::length_offset_in_bytes()));
200 } else if (UseCompressedClassPointers) {
201 store_klass_gap(obj, zr);
202 }
203 }
204
205 // preserves obj, destroys len_in_bytes
206 //
207 // Scratch registers: t1 = r10, t2 = r11
208 //
209 void C1_MacroAssembler::initialize_body(Register obj, Register len_in_bytes, int hdr_size_in_bytes, Register t1, Register t2) {
210 assert(hdr_size_in_bytes >= 0, "header size must be positive or 0");
211 assert(t1 == r10 && t2 == r11, "must be");
212
213 Label done;
214
215 // len_in_bytes is positive and ptr sized
216 subs(len_in_bytes, len_in_bytes, hdr_size_in_bytes);
217 br(Assembler::EQ, done);
218
219 // zero_words() takes ptr in r10 and count in words in r11
220 mov(rscratch1, len_in_bytes);
221 lea(t1, Address(obj, hdr_size_in_bytes));
222 lsr(t2, rscratch1, LogBytesPerWord);
223 zero_words(t1, t2);
224
225 bind(done);
226 }
227
228
229 void C1_MacroAssembler::allocate_object(Register obj, Register t1, Register t2, int header_size, int object_size, Register klass, Label& slow_case) {
230 assert_different_registers(obj, t1, t2); // XXX really?
231 assert(header_size >= 0 && object_size >= header_size, "illegal sizes");
232
233 try_allocate(obj, noreg, object_size * BytesPerWord, t1, t2, slow_case);
234
235 initialize_object(obj, klass, noreg, object_size * HeapWordSize, t1, t2, UseTLAB);
236 }
237
238 // Scratch registers: t1 = r10, t2 = r11
248 const Register index = t2;
249 if (var_size_in_bytes != noreg) {
250 mov(index, var_size_in_bytes);
251 initialize_body(obj, index, hdr_size_in_bytes, t1, t2);
252 } else if (con_size_in_bytes > hdr_size_in_bytes) {
253 con_size_in_bytes -= hdr_size_in_bytes;
254 lea(t1, Address(obj, hdr_size_in_bytes));
255 zero_words(t1, con_size_in_bytes / BytesPerWord);
256 }
257 }
258
259 membar(StoreStore);
260
261 if (CURRENT_ENV->dtrace_alloc_probes()) {
262 assert(obj == r0, "must be");
263 far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)));
264 }
265
266 verify_oop(obj);
267 }
268 void C1_MacroAssembler::allocate_array(Register obj, Register len, Register t1, Register t2, int header_size, int f, Register klass, Label& slow_case) {
269 assert_different_registers(obj, len, t1, t2, klass);
270
271 // determine alignment mask
272 assert(!(BytesPerWord & 1), "must be a multiple of 2 for masking code to work");
273
274 // check for negative or excessive length
275 mov(rscratch1, (int32_t)max_array_allocation_length);
276 cmp(len, rscratch1);
277 br(Assembler::HS, slow_case);
278
279 const Register arr_size = t2; // okay to be the same
280 // align object end
281 mov(arr_size, (int32_t)header_size * BytesPerWord + MinObjAlignmentInBytesMask);
282 add(arr_size, arr_size, len, ext::uxtw, f);
283 andr(arr_size, arr_size, ~MinObjAlignmentInBytesMask);
284
285 try_allocate(obj, arr_size, 0, t1, t2, slow_case);
286
287 initialize_header(obj, klass, len, t1, t2);
288
289 // clear rest of allocated space
290 initialize_body(obj, arr_size, header_size * BytesPerWord, t1, t2);
291
292 membar(StoreStore);
293
294 if (CURRENT_ENV->dtrace_alloc_probes()) {
295 assert(obj == r0, "must be");
296 far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)));
297 }
298
299 verify_oop(obj);
300 }
301
302
303 void C1_MacroAssembler::inline_cache_check(Register receiver, Register iCache) {
304 verify_oop(receiver);
305 // explicit NULL check not needed since load from [klass_offset] causes a trap
306 // check against inline cache
307 assert(!MacroAssembler::needs_explicit_null_check(oopDesc::klass_offset_in_bytes()), "must add explicit null check");
308
309 cmp_klass(receiver, iCache, rscratch1);
310 }
311
312
313 void C1_MacroAssembler::build_frame(int framesize, int bang_size_in_bytes) {
314 assert(bang_size_in_bytes >= framesize, "stack bang size incorrect");
315 // Make sure there is enough stack space for this method's activation.
316 // Note that we do this before creating a frame.
317 generate_stack_overflow_check(bang_size_in_bytes);
318 MacroAssembler::build_frame(framesize);
319
320 // Insert nmethod entry barrier into frame.
321 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
322 bs->nmethod_entry_barrier(this);
323 }
324
325 void C1_MacroAssembler::remove_frame(int framesize) {
326 MacroAssembler::remove_frame(framesize);
327 }
328
|
72
73 // save object being locked into the BasicObjectLock
74 str(obj, Address(disp_hdr, BasicObjectLock::obj_offset_in_bytes()));
75
76 null_check_offset = offset();
77
78 if (DiagnoseSyncOnValueBasedClasses != 0) {
79 load_klass(hdr, obj);
80 ldrw(hdr, Address(hdr, Klass::access_flags_offset()));
81 tstw(hdr, JVM_ACC_IS_VALUE_BASED_CLASS);
82 br(Assembler::NE, slow_case);
83 }
84
85 if (UseBiasedLocking) {
86 assert(scratch != noreg, "should have scratch register at this point");
87 biased_locking_enter(disp_hdr, obj, hdr, scratch, false, done, &slow_case);
88 }
89
90 // Load object header
91 ldr(hdr, Address(obj, hdr_offset));
92 if (LockingMode == LM_LIGHTWEIGHT) {
93 fast_lock(obj, hdr, rscratch1, rscratch2, slow_case);
94 } else {
95 // and mark it as unlocked
96 orr(hdr, hdr, markWord::unlocked_value);
97 // save unlocked object header into the displaced header location on the stack
98 str(hdr, Address(disp_hdr, 0));
99 // test if object header is still the same (i.e. unlocked), and if so, store the
100 // displaced header address in the object header - if it is not the same, get the
101 // object header instead
102 lea(rscratch2, Address(obj, hdr_offset));
103 cmpxchgptr(hdr, disp_hdr, rscratch2, rscratch1, done, /*fallthough*/NULL);
104 // if the object header was the same, we're done
105 // if the object header was not the same, it is now in the hdr register
106 // => test if it is a stack pointer into the same stack (recursive locking), i.e.:
107 //
108 // 1) (hdr & aligned_mask) == 0
109 // 2) sp <= hdr
110 // 3) hdr <= sp + page_size
111 //
112 // these 3 tests can be done by evaluating the following expression:
113 //
114 // (hdr - sp) & (aligned_mask - page_size)
115 //
116 // assuming both the stack pointer and page_size have their least
117 // significant 2 bits cleared and page_size is a power of 2
118 mov(rscratch1, sp);
119 sub(hdr, hdr, rscratch1);
120 ands(hdr, hdr, aligned_mask - os::vm_page_size());
121 // for recursive locking, the result is zero => save it in the displaced header
122 // location (NULL in the displaced hdr location indicates recursive locking)
123 str(hdr, Address(disp_hdr, 0));
124 // otherwise we don't care about the result and handle locking via runtime call
125 cbnz(hdr, slow_case);
126 // done
127 bind(done);
128 }
129 if (PrintBiasedLockingStatistics) {
130 lea(rscratch2, ExternalAddress((address)BiasedLocking::fast_path_entry_count_addr()));
131 addmw(Address(rscratch2, 0), 1, rscratch1);
132 }
133 return null_check_offset;
134 }
135
136
137 void C1_MacroAssembler::unlock_object(Register hdr, Register obj, Register disp_hdr, Label& slow_case) {
138 const int aligned_mask = BytesPerWord -1;
139 const int hdr_offset = oopDesc::mark_offset_in_bytes();
140 assert(hdr != obj && hdr != disp_hdr && obj != disp_hdr, "registers must be different");
141 Label done;
142
143 if (UseBiasedLocking) {
144 // load object
145 ldr(obj, Address(disp_hdr, BasicObjectLock::obj_offset_in_bytes()));
146 biased_locking_exit(obj, hdr, done);
147 }
148
149 if (LockingMode != LM_LIGHTWEIGHT) {
150 // load displaced header
151 ldr(hdr, Address(disp_hdr, 0));
152 // if the loaded hdr is null we had recursive locking
153 // if we had recursive locking, we are done
154 cbz(hdr, done);
155 }
156
157 if (!UseBiasedLocking) {
158 // load object
159 ldr(obj, Address(disp_hdr, BasicObjectLock::obj_offset_in_bytes()));
160 }
161 verify_oop(obj);
162
163 if (LockingMode == LM_LIGHTWEIGHT) {
164 ldr(hdr, Address(obj, oopDesc::mark_offset_in_bytes()));
165 // We cannot use tbnz here, the target might be too far away and cannot
166 // be encoded.
167 tst(hdr, markWord::monitor_value);
168 br(Assembler::NE, slow_case);
169 fast_unlock(obj, hdr, rscratch1, rscratch2, slow_case);
170 } else {
171 // test if object header is pointing to the displaced header, and if so, restore
172 // the displaced header in the object - if the object header is not pointing to
173 // the displaced header, get the object header instead
174 // if the object header was not pointing to the displaced header,
175 // we do unlocking via runtime call
176 if (hdr_offset) {
177 lea(rscratch1, Address(obj, hdr_offset));
178 cmpxchgptr(disp_hdr, hdr, rscratch1, rscratch2, done, &slow_case);
179 } else {
180 cmpxchgptr(disp_hdr, hdr, obj, rscratch2, done, &slow_case);
181 }
182 // done
183 bind(done);
184 }
185 }
186
187
188 // Defines obj, preserves var_size_in_bytes
189 void C1_MacroAssembler::try_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2, Label& slow_case) {
190 if (UseTLAB) {
191 tlab_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, t2, slow_case);
192 } else {
193 eden_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, slow_case);
194 }
195 }
196
197 void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register t1, Register t2) {
198 assert_different_registers(obj, klass, len);
199 if (UseCompactObjectHeaders || (UseBiasedLocking && !len->is_valid())) {
200 assert_different_registers(obj, klass, len, t1, t2);
201 ldr(t1, Address(klass, Klass::prototype_header_offset()));
202 } else {
203 // This assumes that all prototype bits fit in an int32_t
204 mov(t1, (int32_t)(intptr_t)markWord::prototype().value());
205 }
206 str(t1, Address(obj, oopDesc::mark_offset_in_bytes()));
207
208 if (!UseCompactObjectHeaders) {
209 if (UseCompressedClassPointers) { // Take care not to kill klass
210 encode_klass_not_null(t1, klass);
211 strw(t1, Address(obj, oopDesc::klass_offset_in_bytes()));
212 } else {
213 str(klass, Address(obj, oopDesc::klass_offset_in_bytes()));
214 }
215 }
216
217 if (len->is_valid()) {
218 strw(len, Address(obj, arrayOopDesc::length_offset_in_bytes()));
219 } else if (UseCompressedClassPointers && !UseCompactObjectHeaders) {
220 store_klass_gap(obj, zr);
221 }
222 }
223
224 // preserves obj, destroys len_in_bytes
225 //
226 // Scratch registers: t1 = r10, t2 = r11
227 //
228 void C1_MacroAssembler::initialize_body(Register obj, Register len_in_bytes, int hdr_size_in_bytes, Register t1, Register t2) {
229 assert(hdr_size_in_bytes >= 0, "header size must be positive or 0");
230 assert(t1 == r10 && t2 == r11, "must be");
231
232 Label done;
233
234 // len_in_bytes is positive and ptr sized
235 subs(len_in_bytes, len_in_bytes, hdr_size_in_bytes);
236 br(Assembler::EQ, done);
237
238 // Zero first 4 bytes, if start offset is not word aligned.
239 if (!is_aligned(hdr_size_in_bytes, BytesPerWord)) {
240 strw(zr, Address(obj, hdr_size_in_bytes));
241 hdr_size_in_bytes += BytesPerInt;
242 }
243
244 // zero_words() takes ptr in r10 and count in words in r11
245 mov(rscratch1, len_in_bytes);
246 lea(t1, Address(obj, hdr_size_in_bytes));
247 lsr(t2, rscratch1, LogBytesPerWord);
248 zero_words(t1, t2);
249
250 bind(done);
251 }
252
253
254 void C1_MacroAssembler::allocate_object(Register obj, Register t1, Register t2, int header_size, int object_size, Register klass, Label& slow_case) {
255 assert_different_registers(obj, t1, t2); // XXX really?
256 assert(header_size >= 0 && object_size >= header_size, "illegal sizes");
257
258 try_allocate(obj, noreg, object_size * BytesPerWord, t1, t2, slow_case);
259
260 initialize_object(obj, klass, noreg, object_size * HeapWordSize, t1, t2, UseTLAB);
261 }
262
263 // Scratch registers: t1 = r10, t2 = r11
273 const Register index = t2;
274 if (var_size_in_bytes != noreg) {
275 mov(index, var_size_in_bytes);
276 initialize_body(obj, index, hdr_size_in_bytes, t1, t2);
277 } else if (con_size_in_bytes > hdr_size_in_bytes) {
278 con_size_in_bytes -= hdr_size_in_bytes;
279 lea(t1, Address(obj, hdr_size_in_bytes));
280 zero_words(t1, con_size_in_bytes / BytesPerWord);
281 }
282 }
283
284 membar(StoreStore);
285
286 if (CURRENT_ENV->dtrace_alloc_probes()) {
287 assert(obj == r0, "must be");
288 far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)));
289 }
290
291 verify_oop(obj);
292 }
293 void C1_MacroAssembler::allocate_array(Register obj, Register len, Register t1, Register t2, int base_offset_in_bytes, int f, Register klass, Label& slow_case) {
294 assert_different_registers(obj, len, t1, t2, klass);
295
296 // determine alignment mask
297 assert(!(BytesPerWord & 1), "must be a multiple of 2 for masking code to work");
298
299 // check for negative or excessive length
300 mov(rscratch1, (int32_t)max_array_allocation_length);
301 cmp(len, rscratch1);
302 br(Assembler::HS, slow_case);
303
304 const Register arr_size = t2; // okay to be the same
305 // align object end
306 mov(arr_size, (int32_t)base_offset_in_bytes + MinObjAlignmentInBytesMask);
307 add(arr_size, arr_size, len, ext::uxtw, f);
308 andr(arr_size, arr_size, ~MinObjAlignmentInBytesMask);
309
310 try_allocate(obj, arr_size, 0, t1, t2, slow_case);
311
312 initialize_header(obj, klass, len, t1, t2);
313
314 // clear rest of allocated space
315 initialize_body(obj, arr_size, base_offset_in_bytes, t1, t2);
316
317 membar(StoreStore);
318
319 if (CURRENT_ENV->dtrace_alloc_probes()) {
320 assert(obj == r0, "must be");
321 far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)));
322 }
323
324 verify_oop(obj);
325 }
326
327
328 void C1_MacroAssembler::inline_cache_check(Register receiver, Register iCache) {
329 verify_oop(receiver);
330 // explicit NULL check not needed since load from [klass_offset] causes a trap
331 // check against inline cache
332 if (UseCompactObjectHeaders) {
333 assert(!MacroAssembler::needs_explicit_null_check(oopDesc::mark_offset_in_bytes()), "must add explicit null check");
334 } else {
335 assert(!MacroAssembler::needs_explicit_null_check(oopDesc::klass_offset_in_bytes()), "must add explicit null check");
336 }
337 cmp_klass(receiver, iCache, rscratch1);
338 }
339
340
341 void C1_MacroAssembler::build_frame(int framesize, int bang_size_in_bytes) {
342 assert(bang_size_in_bytes >= framesize, "stack bang size incorrect");
343 // Make sure there is enough stack space for this method's activation.
344 // Note that we do this before creating a frame.
345 generate_stack_overflow_check(bang_size_in_bytes);
346 MacroAssembler::build_frame(framesize);
347
348 // Insert nmethod entry barrier into frame.
349 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
350 bs->nmethod_entry_barrier(this);
351 }
352
353 void C1_MacroAssembler::remove_frame(int framesize) {
354 MacroAssembler::remove_frame(framesize);
355 }
356
|