< prev index next >

src/hotspot/cpu/x86/c1_MacroAssembler_x86.cpp

Print this page

146     // we do unlocking via runtime call
147     jcc(Assembler::notEqual, slow_case);
148     // done
149   }
150   bind(done);
151   dec_held_monitor_count();
152 }
153 
154 
155 // Defines obj, preserves var_size_in_bytes
156 void C1_MacroAssembler::try_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2, Label& slow_case) {
157   if (UseTLAB) {
158     tlab_allocate(noreg, obj, var_size_in_bytes, con_size_in_bytes, t1, t2, slow_case);
159   } else {
160     jmp(slow_case);
161   }
162 }
163 
164 
165 void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register t1, Register t2) {
166   assert_different_registers(obj, klass, len);
167   movptr(Address(obj, oopDesc::mark_offset_in_bytes()), checked_cast<int32_t>(markWord::prototype().value()));
168 #ifdef _LP64
169   if (UseCompressedClassPointers) { // Take care not to kill klass




170     movptr(t1, klass);
171     encode_klass_not_null(t1, rscratch1);
172     movl(Address(obj, oopDesc::klass_offset_in_bytes()), t1);
173   } else
174 #endif
175   {

176     movptr(Address(obj, oopDesc::klass_offset_in_bytes()), klass);
177   }
178 
179   if (len->is_valid()) {
180     movl(Address(obj, arrayOopDesc::length_offset_in_bytes()), len);
181   }
182 #ifdef _LP64
183   else if (UseCompressedClassPointers) {
184     xorptr(t1, t1);
185     store_klass_gap(obj, t1);
186   }
187 #endif
188 }
189 
190 
191 // preserves obj, destroys len_in_bytes
192 void C1_MacroAssembler::initialize_body(Register obj, Register len_in_bytes, int hdr_size_in_bytes, Register t1) {
193   assert(hdr_size_in_bytes >= 0, "header size must be positive or 0");
194   Label done;
195 
196   // len_in_bytes is positive and ptr sized
197   subptr(len_in_bytes, hdr_size_in_bytes);
198   zero_memory(obj, len_in_bytes, hdr_size_in_bytes, t1);
199   bind(done);
200 }
201 
202 
203 void C1_MacroAssembler::allocate_object(Register obj, Register t1, Register t2, int header_size, int object_size, Register klass, Label& slow_case) {
204   assert(obj == rax, "obj must be in rax, for cmpxchg");
205   assert_different_registers(obj, t1, t2); // XXX really?
206   assert(header_size >= 0 && object_size >= header_size, "illegal sizes");
207 
208   try_allocate(obj, noreg, object_size * BytesPerWord, t1, t2, slow_case);
209 
210   initialize_object(obj, klass, noreg, object_size * HeapWordSize, t1, t2, UseTLAB);
211 }
212 
213 void C1_MacroAssembler::initialize_object(Register obj, Register klass, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2, bool is_tlab_allocated) {
214   assert((con_size_in_bytes & MinObjAlignmentInBytesMask) == 0,
215          "con_size_in_bytes is not multiple of alignment");
216   const int hdr_size_in_bytes = instanceOopDesc::header_size() * HeapWordSize;

217 
218   initialize_header(obj, klass, noreg, t1, t2);
219 
220   if (!(UseTLAB && ZeroTLAB && is_tlab_allocated)) {
221     // clear rest of allocated space
222     const Register t1_zero = t1;
223     const Register index = t2;
224     const int threshold = 6 * BytesPerWord;   // approximate break even point for code size (see comments below)
225     if (var_size_in_bytes != noreg) {
226       mov(index, var_size_in_bytes);
227       initialize_body(obj, index, hdr_size_in_bytes, t1_zero);
228     } else if (con_size_in_bytes <= threshold) {
229       // use explicit null stores
230       // code size = 2 + 3*n bytes (n = number of fields to clear)
231       xorptr(t1_zero, t1_zero); // use t1_zero reg to clear memory (shorter code)
232       for (int i = hdr_size_in_bytes; i < con_size_in_bytes; i += BytesPerWord)
233         movptr(Address(obj, i), t1_zero);
234     } else if (con_size_in_bytes > hdr_size_in_bytes) {
235       // use loop to null out the fields
236       // code size = 16 bytes for even n (n = number of fields to clear)

244       { Label loop;
245         bind(loop);
246         movptr(Address(obj, index, Address::times_8, hdr_size_in_bytes - (1*BytesPerWord)),
247                t1_zero);
248         NOT_LP64(movptr(Address(obj, index, Address::times_8, hdr_size_in_bytes - (2*BytesPerWord)),
249                t1_zero);)
250         decrement(index);
251         jcc(Assembler::notZero, loop);
252       }
253     }
254   }
255 
256   if (CURRENT_ENV->dtrace_alloc_probes()) {
257     assert(obj == rax, "must be");
258     call(RuntimeAddress(Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)));
259   }
260 
261   verify_oop(obj);
262 }
263 
264 void C1_MacroAssembler::allocate_array(Register obj, Register len, Register t1, Register t2, int header_size, Address::ScaleFactor f, Register klass, Label& slow_case) {
265   assert(obj == rax, "obj must be in rax, for cmpxchg");
266   assert_different_registers(obj, len, t1, t2, klass);
267 
268   // determine alignment mask
269   assert(!(BytesPerWord & 1), "must be a multiple of 2 for masking code to work");
270 
271   // check for negative or excessive length
272   cmpptr(len, checked_cast<int32_t>(max_array_allocation_length));
273   jcc(Assembler::above, slow_case);
274 
275   const Register arr_size = t2; // okay to be the same
276   // align object end
277   movptr(arr_size, header_size * BytesPerWord + MinObjAlignmentInBytesMask);
278   lea(arr_size, Address(arr_size, len, f));
279   andptr(arr_size, ~MinObjAlignmentInBytesMask);
280 
281   try_allocate(obj, arr_size, 0, t1, t2, slow_case);
282 
283   initialize_header(obj, klass, len, t1, t2);
284 













285   // clear rest of allocated space
286   const Register len_zero = len;
287   initialize_body(obj, arr_size, header_size * BytesPerWord, len_zero);
288 
289   if (CURRENT_ENV->dtrace_alloc_probes()) {
290     assert(obj == rax, "must be");
291     call(RuntimeAddress(Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)));
292   }
293 
294   verify_oop(obj);
295 }
296 
297 
298 
299 void C1_MacroAssembler::inline_cache_check(Register receiver, Register iCache) {
300   verify_oop(receiver);
301   // explicit null check not needed since load from [klass_offset] causes a trap
302   // check against inline cache
303   assert(!MacroAssembler::needs_explicit_null_check(oopDesc::klass_offset_in_bytes()), "must add explicit null check");
304   int start_offset = offset();
305 
306   if (UseCompressedClassPointers) {
307     load_klass(rscratch1, receiver, rscratch2);
308     cmpptr(rscratch1, iCache);
309   } else {
310     cmpptr(iCache, Address(receiver, oopDesc::klass_offset_in_bytes()));
311   }
312   // if icache check fails, then jump to runtime routine
313   // Note: RECEIVER must still contain the receiver!
314   jump_cc(Assembler::notEqual,
315           RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
316   const int ic_cmp_size = LP64_ONLY(10) NOT_LP64(9);
317   assert(UseCompressedClassPointers || offset() - start_offset == ic_cmp_size, "check alignment in emit_method_entry");
318 }
319 
320 
321 void C1_MacroAssembler::build_frame(int frame_size_in_bytes, int bang_size_in_bytes) {
322   assert(bang_size_in_bytes >= frame_size_in_bytes, "stack bang size incorrect");
323   // Make sure there is enough stack space for this method's activation.

146     // we do unlocking via runtime call
147     jcc(Assembler::notEqual, slow_case);
148     // done
149   }
150   bind(done);
151   dec_held_monitor_count();
152 }
153 
154 
155 // Defines obj, preserves var_size_in_bytes
156 void C1_MacroAssembler::try_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2, Label& slow_case) {
157   if (UseTLAB) {
158     tlab_allocate(noreg, obj, var_size_in_bytes, con_size_in_bytes, t1, t2, slow_case);
159   } else {
160     jmp(slow_case);
161   }
162 }
163 
164 
165 void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register t1, Register t2) {
166   assert_different_registers(obj, klass, len, t1, t2);

167 #ifdef _LP64
168   if (UseCompactObjectHeaders) {
169     movptr(t1, Address(klass, Klass::prototype_header_offset()));
170     movptr(Address(obj, oopDesc::mark_offset_in_bytes()), t1);
171   } else if (UseCompressedClassPointers) { // Take care not to kill klass
172     movptr(Address(obj, oopDesc::mark_offset_in_bytes()), checked_cast<int32_t>(markWord::prototype().value()));
173     movptr(t1, klass);
174     encode_klass_not_null(t1, rscratch1);
175     movl(Address(obj, oopDesc::klass_offset_in_bytes()), t1);
176   } else
177 #endif
178   {
179     movptr(Address(obj, oopDesc::mark_offset_in_bytes()), checked_cast<int32_t>(markWord::prototype().value()));
180     movptr(Address(obj, oopDesc::klass_offset_in_bytes()), klass);
181   }
182 
183   if (len->is_valid()) {
184     movl(Address(obj, arrayOopDesc::length_offset_in_bytes()), len);
185   }
186 #ifdef _LP64
187   else if (UseCompressedClassPointers && !UseCompactObjectHeaders) {
188     xorptr(t1, t1);
189     store_klass_gap(obj, t1);
190   }
191 #endif
192 }
193 
194 
195 // preserves obj, destroys len_in_bytes
196 void C1_MacroAssembler::initialize_body(Register obj, Register len_in_bytes, int hdr_size_in_bytes, Register t1) {
197   assert(hdr_size_in_bytes >= 0, "header size must be positive or 0");
198   Label done;
199 
200   // len_in_bytes is positive and ptr sized
201   subptr(len_in_bytes, hdr_size_in_bytes);
202   zero_memory(obj, len_in_bytes, hdr_size_in_bytes, t1);
203   bind(done);
204 }
205 
206 
207 void C1_MacroAssembler::allocate_object(Register obj, Register t1, Register t2, int header_size, int object_size, Register klass, Label& slow_case) {
208   assert(obj == rax, "obj must be in rax, for cmpxchg");
209   assert_different_registers(obj, t1, t2); // XXX really?
210   assert(header_size >= 0 && object_size >= header_size, "illegal sizes");
211 
212   try_allocate(obj, noreg, object_size * BytesPerWord, t1, t2, slow_case);
213 
214   initialize_object(obj, klass, noreg, object_size * HeapWordSize, t1, t2, UseTLAB);
215 }
216 
217 void C1_MacroAssembler::initialize_object(Register obj, Register klass, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2, bool is_tlab_allocated) {
218   assert((con_size_in_bytes & MinObjAlignmentInBytesMask) == 0,
219          "con_size_in_bytes is not multiple of alignment");
220   const int hdr_size_in_bytes = instanceOopDesc::header_size() * HeapWordSize;
221   assert(!UseCompactObjectHeaders || hdr_size_in_bytes == 8, "check object headers size");
222 
223   initialize_header(obj, klass, noreg, t1, t2);
224 
225   if (!(UseTLAB && ZeroTLAB && is_tlab_allocated)) {
226     // clear rest of allocated space
227     const Register t1_zero = t1;
228     const Register index = t2;
229     const int threshold = 6 * BytesPerWord;   // approximate break even point for code size (see comments below)
230     if (var_size_in_bytes != noreg) {
231       mov(index, var_size_in_bytes);
232       initialize_body(obj, index, hdr_size_in_bytes, t1_zero);
233     } else if (con_size_in_bytes <= threshold) {
234       // use explicit null stores
235       // code size = 2 + 3*n bytes (n = number of fields to clear)
236       xorptr(t1_zero, t1_zero); // use t1_zero reg to clear memory (shorter code)
237       for (int i = hdr_size_in_bytes; i < con_size_in_bytes; i += BytesPerWord)
238         movptr(Address(obj, i), t1_zero);
239     } else if (con_size_in_bytes > hdr_size_in_bytes) {
240       // use loop to null out the fields
241       // code size = 16 bytes for even n (n = number of fields to clear)

249       { Label loop;
250         bind(loop);
251         movptr(Address(obj, index, Address::times_8, hdr_size_in_bytes - (1*BytesPerWord)),
252                t1_zero);
253         NOT_LP64(movptr(Address(obj, index, Address::times_8, hdr_size_in_bytes - (2*BytesPerWord)),
254                t1_zero);)
255         decrement(index);
256         jcc(Assembler::notZero, loop);
257       }
258     }
259   }
260 
261   if (CURRENT_ENV->dtrace_alloc_probes()) {
262     assert(obj == rax, "must be");
263     call(RuntimeAddress(Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)));
264   }
265 
266   verify_oop(obj);
267 }
268 
269 void C1_MacroAssembler::allocate_array(Register obj, Register len, Register t1, Register t2, int base_offset_in_bytes, Address::ScaleFactor f, Register klass, Label& slow_case) {
270   assert(obj == rax, "obj must be in rax, for cmpxchg");
271   assert_different_registers(obj, len, t1, t2, klass);
272 
273   // determine alignment mask
274   assert(!(BytesPerWord & 1), "must be a multiple of 2 for masking code to work");
275 
276   // check for negative or excessive length
277   cmpptr(len, checked_cast<int32_t>(max_array_allocation_length));
278   jcc(Assembler::above, slow_case);
279 
280   const Register arr_size = t2; // okay to be the same
281   // align object end
282   movptr(arr_size, base_offset_in_bytes + MinObjAlignmentInBytesMask);
283   lea(arr_size, Address(arr_size, len, f));
284   andptr(arr_size, ~MinObjAlignmentInBytesMask);
285 
286   try_allocate(obj, arr_size, 0, t1, t2, slow_case);
287 
288   initialize_header(obj, klass, len, t1, t2);
289 
290   // Clear leading 4 bytes, if necessary.
291   // TODO: This could perhaps go into initialize_body() and also clear the leading 4 bytes
292   // for non-array objects, thereby replacing the klass-gap clearing code in initialize_header().
293   int base_offset = base_offset_in_bytes;
294 #ifdef _LP64
295   if (!is_aligned(base_offset, BytesPerWord)) {
296     assert(is_aligned(base_offset, BytesPerInt), "must be 4-byte aligned");
297     movl(Address(obj, base_offset), 0);
298     base_offset += BytesPerInt;
299   }
300 #endif
301   assert(is_aligned(base_offset, BytesPerWord), "must be word aligned");
302 
303   // clear rest of allocated space
304   const Register len_zero = len;
305   initialize_body(obj, arr_size, base_offset, len_zero);
306 
307   if (CURRENT_ENV->dtrace_alloc_probes()) {
308     assert(obj == rax, "must be");
309     call(RuntimeAddress(Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)));
310   }
311 
312   verify_oop(obj);
313 }
314 
315 
316 
317 void C1_MacroAssembler::inline_cache_check(Register receiver, Register iCache) {
318   verify_oop(receiver);
319   // explicit null check not needed since load from [klass_offset] causes a trap
320   // check against inline cache. This is checked in Universe::genesis().

321   int start_offset = offset();
322 
323   if (UseCompressedClassPointers) {
324     load_klass(rscratch1, receiver, rscratch2);
325     cmpptr(rscratch1, iCache);
326   } else {
327     cmpptr(iCache, Address(receiver, oopDesc::klass_offset_in_bytes()));
328   }
329   // if icache check fails, then jump to runtime routine
330   // Note: RECEIVER must still contain the receiver!
331   jump_cc(Assembler::notEqual,
332           RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
333   const int ic_cmp_size = LP64_ONLY(10) NOT_LP64(9);
334   assert(UseCompressedClassPointers || offset() - start_offset == ic_cmp_size, "check alignment in emit_method_entry");
335 }
336 
337 
338 void C1_MacroAssembler::build_frame(int frame_size_in_bytes, int bang_size_in_bytes) {
339   assert(bang_size_in_bytes >= frame_size_in_bytes, "stack bang size incorrect");
340   // Make sure there is enough stack space for this method's activation.
< prev index next >