2942 if (reachable(src)) {
2943 Assembler::divss(dst, as_Address(src));
2944 } else {
2945 lea(rscratch1, src);
2946 Assembler::divss(dst, Address(rscratch1, 0));
2947 }
2948 }
2949
2950 // !defined(COMPILER2) is because of stupid core builds
2951 #if !defined(_LP64) || defined(COMPILER1) || !defined(COMPILER2) || INCLUDE_JVMCI
2952 void MacroAssembler::empty_FPU_stack() {
2953 if (VM_Version::supports_mmx()) {
2954 emms();
2955 } else {
2956 for (int i = 8; i-- > 0; ) ffree(i);
2957 }
2958 }
2959 #endif // !LP64 || C1 || !C2 || INCLUDE_JVMCI
2960
2961
2962 // Defines obj, preserves var_size_in_bytes
2963 void MacroAssembler::eden_allocate(Register obj,
2964 Register var_size_in_bytes,
2965 int con_size_in_bytes,
2966 Register t1,
2967 Label& slow_case) {
2968 assert(obj == rax, "obj must be in rax, for cmpxchg");
2969 assert_different_registers(obj, var_size_in_bytes, t1);
2970 if (!Universe::heap()->supports_inline_contig_alloc()) {
2971 jmp(slow_case);
2972 } else {
2973 Register end = t1;
2974 Label retry;
2975 bind(retry);
2976 ExternalAddress heap_top((address) Universe::heap()->top_addr());
2977 movptr(obj, heap_top);
2978 if (var_size_in_bytes == noreg) {
2979 lea(end, Address(obj, con_size_in_bytes));
2980 } else {
2981 lea(end, Address(obj, var_size_in_bytes, Address::times_1));
2982 }
2983 // if end < obj then we wrapped around => object too long => slow case
2984 cmpptr(end, obj);
2985 jcc(Assembler::below, slow_case);
2986 cmpptr(end, ExternalAddress((address) Universe::heap()->end_addr()));
2987 jcc(Assembler::above, slow_case);
2988 // Compare obj with the top addr, and if still equal, store the new top addr in
2989 // end at the address of the top addr pointer. Sets ZF if was equal, and clears
2990 // it otherwise. Use lock prefix for atomicity on MPs.
2991 locked_cmpxchgptr(end, heap_top);
2992 jcc(Assembler::notEqual, retry);
2993 }
2994 }
2995
2996 void MacroAssembler::enter() {
2997 push(rbp);
2998 mov(rbp, rsp);
2999 }
3000
3001 // A 5 byte nop that is safe for patching (see patch_verified_entry)
3002 void MacroAssembler::fat_nop() {
3003 if (UseAddressNop) {
3004 addr_nop_5();
3005 } else {
3006 emit_int8(0x26); // es:
3007 emit_int8(0x2e); // cs:
3008 emit_int8(0x64); // fs:
3009 emit_int8(0x65); // gs:
3010 emit_int8((unsigned char)0x90);
3011 }
3012 }
3013
3014 void MacroAssembler::fcmp(Register tmp) {
3015 fcmp(tmp, 1, true, true);
5293
5294 // C++ bool manipulation
5295 void MacroAssembler::testbool(Register dst) {
5296 if(sizeof(bool) == 1)
5297 testb(dst, 0xff);
5298 else if(sizeof(bool) == 2) {
5299 // testw implementation needed for two byte bools
5300 ShouldNotReachHere();
5301 } else if(sizeof(bool) == 4)
5302 testl(dst, dst);
5303 else
5304 // unsupported
5305 ShouldNotReachHere();
5306 }
5307
5308 void MacroAssembler::testptr(Register dst, Register src) {
5309 LP64_ONLY(testq(dst, src)) NOT_LP64(testl(dst, src));
5310 }
5311
5312 // Defines obj, preserves var_size_in_bytes, okay for t2 == var_size_in_bytes.
5313 void MacroAssembler::tlab_allocate(Register obj,
5314 Register var_size_in_bytes,
5315 int con_size_in_bytes,
5316 Register t1,
5317 Register t2,
5318 Label& slow_case) {
5319 assert_different_registers(obj, t1, t2);
5320 assert_different_registers(obj, var_size_in_bytes, t1);
5321 Register end = t2;
5322 Register thread = NOT_LP64(t1) LP64_ONLY(r15_thread);
5323
5324 verify_tlab();
5325
5326 NOT_LP64(get_thread(thread));
5327
5328 movptr(obj, Address(thread, JavaThread::tlab_top_offset()));
5329 if (var_size_in_bytes == noreg) {
5330 lea(end, Address(obj, con_size_in_bytes));
5331 } else {
5332 lea(end, Address(obj, var_size_in_bytes, Address::times_1));
5333 }
5334 cmpptr(end, Address(thread, JavaThread::tlab_end_offset()));
5335 jcc(Assembler::above, slow_case);
5336
5337 // update the tlab top pointer
5338 movptr(Address(thread, JavaThread::tlab_top_offset()), end);
5339
5340 // recover var_size_in_bytes if necessary
5341 if (var_size_in_bytes == end) {
5342 subptr(var_size_in_bytes, obj);
5343 }
5344 verify_tlab();
5345 }
5346
5347 // Preserves the contents of address, destroys the contents length_in_bytes and temp.
5348 void MacroAssembler::zero_memory(Register address, Register length_in_bytes, int offset_in_bytes, Register temp) {
5349 assert(address != length_in_bytes && address != temp && temp != length_in_bytes, "registers must be different");
5350 assert((offset_in_bytes & (BytesPerWord - 1)) == 0, "offset must be a multiple of BytesPerWord");
5351 Label done;
5352
5353 testptr(length_in_bytes, length_in_bytes);
5354 jcc(Assembler::zero, done);
5355
5356 // initialize topmost word, divide index by 2, check if odd and test if zero
5357 // note: for the remaining code to work, index must be a multiple of BytesPerWord
5358 #ifdef ASSERT
5359 {
5360 Label L;
5361 testptr(length_in_bytes, BytesPerWord - 1);
5362 jcc(Assembler::zero, L);
5363 stop("length must be a multiple of BytesPerWord");
5364 bind(L);
5381 // => if it is even, we don't need to check for 0 again
5382 jcc(Assembler::carryClear, even);
5383 // clear topmost word (no jump would be needed if conditional assignment worked here)
5384 movptr(Address(address, index, Address::times_8, offset_in_bytes - 0*BytesPerWord), temp);
5385 // index could be 0 now, must check again
5386 jcc(Assembler::zero, done);
5387 bind(even);
5388 }
5389 #endif // !_LP64
5390 // initialize remaining object fields: index is a multiple of 2 now
5391 {
5392 Label loop;
5393 bind(loop);
5394 movptr(Address(address, index, Address::times_8, offset_in_bytes - 1*BytesPerWord), temp);
5395 NOT_LP64(movptr(Address(address, index, Address::times_8, offset_in_bytes - 2*BytesPerWord), temp);)
5396 decrement(index);
5397 jcc(Assembler::notZero, loop);
5398 }
5399
5400 bind(done);
5401 }
5402
5403 void MacroAssembler::incr_allocated_bytes(Register thread,
5404 Register var_size_in_bytes,
5405 int con_size_in_bytes,
5406 Register t1) {
5407 if (!thread->is_valid()) {
5408 #ifdef _LP64
5409 thread = r15_thread;
5410 #else
5411 assert(t1->is_valid(), "need temp reg");
5412 thread = t1;
5413 get_thread(thread);
5414 #endif
5415 }
5416
5417 #ifdef _LP64
5418 if (var_size_in_bytes->is_valid()) {
5419 addq(Address(thread, in_bytes(JavaThread::allocated_bytes_offset())), var_size_in_bytes);
5420 } else {
5421 addq(Address(thread, in_bytes(JavaThread::allocated_bytes_offset())), con_size_in_bytes);
5422 }
5423 #else
5424 if (var_size_in_bytes->is_valid()) {
5425 addl(Address(thread, in_bytes(JavaThread::allocated_bytes_offset())), var_size_in_bytes);
5426 } else {
5427 addl(Address(thread, in_bytes(JavaThread::allocated_bytes_offset())), con_size_in_bytes);
5428 }
5429 adcl(Address(thread, in_bytes(JavaThread::allocated_bytes_offset())+4), 0);
5430 #endif
5431 }
5432
5433 // Look up the method for a megamorphic invokeinterface call.
5434 // The target method is determined by <intf_klass, itable_index>.
5435 // The receiver klass is in recv_klass.
5436 // On success, the result will be in method_result, and execution falls through.
5437 // On failure, execution transfers to the given label.
5438 void MacroAssembler::lookup_interface_method(Register recv_klass,
5439 Register intf_klass,
5440 RegisterOrConstant itable_index,
5441 Register method_result,
5442 Register scan_temp,
5443 Label& L_no_such_interface,
5444 bool return_method) {
5445 assert_different_registers(recv_klass, intf_klass, scan_temp);
5446 assert_different_registers(method_result, intf_klass, scan_temp);
5447 assert(recv_klass != method_result || !return_method,
5448 "recv_klass can be destroyed when method isn't needed");
5449
5450 assert(itable_index.is_constant() || itable_index.as_register() == method_result,
|
2942 if (reachable(src)) {
2943 Assembler::divss(dst, as_Address(src));
2944 } else {
2945 lea(rscratch1, src);
2946 Assembler::divss(dst, Address(rscratch1, 0));
2947 }
2948 }
2949
2950 // !defined(COMPILER2) is because of stupid core builds
2951 #if !defined(_LP64) || defined(COMPILER1) || !defined(COMPILER2) || INCLUDE_JVMCI
2952 void MacroAssembler::empty_FPU_stack() {
2953 if (VM_Version::supports_mmx()) {
2954 emms();
2955 } else {
2956 for (int i = 8; i-- > 0; ) ffree(i);
2957 }
2958 }
2959 #endif // !LP64 || C1 || !C2 || INCLUDE_JVMCI
2960
2961
2962 void MacroAssembler::enter() {
2963 push(rbp);
2964 mov(rbp, rsp);
2965 }
2966
2967 // A 5 byte nop that is safe for patching (see patch_verified_entry)
2968 void MacroAssembler::fat_nop() {
2969 if (UseAddressNop) {
2970 addr_nop_5();
2971 } else {
2972 emit_int8(0x26); // es:
2973 emit_int8(0x2e); // cs:
2974 emit_int8(0x64); // fs:
2975 emit_int8(0x65); // gs:
2976 emit_int8((unsigned char)0x90);
2977 }
2978 }
2979
2980 void MacroAssembler::fcmp(Register tmp) {
2981 fcmp(tmp, 1, true, true);
5259
5260 // C++ bool manipulation
5261 void MacroAssembler::testbool(Register dst) {
5262 if(sizeof(bool) == 1)
5263 testb(dst, 0xff);
5264 else if(sizeof(bool) == 2) {
5265 // testw implementation needed for two byte bools
5266 ShouldNotReachHere();
5267 } else if(sizeof(bool) == 4)
5268 testl(dst, dst);
5269 else
5270 // unsupported
5271 ShouldNotReachHere();
5272 }
5273
5274 void MacroAssembler::testptr(Register dst, Register src) {
5275 LP64_ONLY(testq(dst, src)) NOT_LP64(testl(dst, src));
5276 }
5277
5278 // Defines obj, preserves var_size_in_bytes, okay for t2 == var_size_in_bytes.
5279 void MacroAssembler::tlab_allocate(Register thread, Register obj,
5280 Register var_size_in_bytes,
5281 int con_size_in_bytes,
5282 Register t1,
5283 Register t2,
5284 Label& slow_case) {
5285 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
5286 bs->tlab_allocate(this, thread, obj, var_size_in_bytes, con_size_in_bytes, t1, t2, slow_case);
5287 }
5288
5289 // Defines obj, preserves var_size_in_bytes
5290 void MacroAssembler::eden_allocate(Register thread, Register obj,
5291 Register var_size_in_bytes,
5292 int con_size_in_bytes,
5293 Register t1,
5294 Label& slow_case) {
5295 BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
5296 bs->eden_allocate(this, thread, obj, var_size_in_bytes, con_size_in_bytes, t1, slow_case);
5297 }
5298
5299 // Preserves the contents of address, destroys the contents length_in_bytes and temp.
5300 void MacroAssembler::zero_memory(Register address, Register length_in_bytes, int offset_in_bytes, Register temp) {
5301 assert(address != length_in_bytes && address != temp && temp != length_in_bytes, "registers must be different");
5302 assert((offset_in_bytes & (BytesPerWord - 1)) == 0, "offset must be a multiple of BytesPerWord");
5303 Label done;
5304
5305 testptr(length_in_bytes, length_in_bytes);
5306 jcc(Assembler::zero, done);
5307
5308 // initialize topmost word, divide index by 2, check if odd and test if zero
5309 // note: for the remaining code to work, index must be a multiple of BytesPerWord
5310 #ifdef ASSERT
5311 {
5312 Label L;
5313 testptr(length_in_bytes, BytesPerWord - 1);
5314 jcc(Assembler::zero, L);
5315 stop("length must be a multiple of BytesPerWord");
5316 bind(L);
5333 // => if it is even, we don't need to check for 0 again
5334 jcc(Assembler::carryClear, even);
5335 // clear topmost word (no jump would be needed if conditional assignment worked here)
5336 movptr(Address(address, index, Address::times_8, offset_in_bytes - 0*BytesPerWord), temp);
5337 // index could be 0 now, must check again
5338 jcc(Assembler::zero, done);
5339 bind(even);
5340 }
5341 #endif // !_LP64
5342 // initialize remaining object fields: index is a multiple of 2 now
5343 {
5344 Label loop;
5345 bind(loop);
5346 movptr(Address(address, index, Address::times_8, offset_in_bytes - 1*BytesPerWord), temp);
5347 NOT_LP64(movptr(Address(address, index, Address::times_8, offset_in_bytes - 2*BytesPerWord), temp);)
5348 decrement(index);
5349 jcc(Assembler::notZero, loop);
5350 }
5351
5352 bind(done);
5353 }
5354
5355 // Look up the method for a megamorphic invokeinterface call.
5356 // The target method is determined by <intf_klass, itable_index>.
5357 // The receiver klass is in recv_klass.
5358 // On success, the result will be in method_result, and execution falls through.
5359 // On failure, execution transfers to the given label.
5360 void MacroAssembler::lookup_interface_method(Register recv_klass,
5361 Register intf_klass,
5362 RegisterOrConstant itable_index,
5363 Register method_result,
5364 Register scan_temp,
5365 Label& L_no_such_interface,
5366 bool return_method) {
5367 assert_different_registers(recv_klass, intf_klass, scan_temp);
5368 assert_different_registers(method_result, intf_klass, scan_temp);
5369 assert(recv_klass != method_result || !return_method,
5370 "recv_klass can be destroyed when method isn't needed");
5371
5372 assert(itable_index.is_constant() || itable_index.as_register() == method_result,
|