3851
3852 // make sure klass is initialized & doesn't have finalizer
3853 // make sure klass is fully initialized
3854 __ cmpb(Address(rcx, InstanceKlass::init_state_offset()), InstanceKlass::fully_initialized);
3855 __ jcc(Assembler::notEqual, slow_case);
3856
3857 // get instance_size in InstanceKlass (scaled to a count of bytes)
3858 __ movl(rdx, Address(rcx, Klass::layout_helper_offset()));
3859 // test to see if it has a finalizer or is malformed in some way
3860 __ testl(rdx, Klass::_lh_instance_slow_path_bit);
3861 __ jcc(Assembler::notZero, slow_case);
3862
3863 //
3864 // Allocate the instance
3865 // 1) Try to allocate in the TLAB
3866 // 2) if fail and the object is large allocate in the shared Eden
3867 // 3) if the above fails (or is not applicable), go to a slow case
3868 // (creates a new TLAB, etc.)
3869
3870 const bool allow_shared_alloc =
3871 Universe::heap()->supports_inline_contig_alloc();
3872
3873 const Register thread = LP64_ONLY(r15_thread) NOT_LP64(rcx);
3874 #ifndef _LP64
3875 if (UseTLAB || allow_shared_alloc) {
3876 __ get_thread(thread);
3877 }
3878 #endif // _LP64
3879
3880 if (UseTLAB) {
3881 __ movptr(rax, Address(thread, in_bytes(JavaThread::tlab_top_offset())));
3882 __ lea(rbx, Address(rax, rdx, Address::times_1));
3883 __ cmpptr(rbx, Address(thread, in_bytes(JavaThread::tlab_end_offset())));
3884 __ jcc(Assembler::above, allow_shared_alloc ? allocate_shared : slow_case);
3885 __ movptr(Address(thread, in_bytes(JavaThread::tlab_top_offset())), rbx);
3886 if (ZeroTLAB) {
3887 // the fields have been already cleared
3888 __ jmp(initialize_header);
3889 } else {
3890 // initialize both the header and fields
3891 __ jmp(initialize_object);
3892 }
3893 }
3894
3895 // Allocation in the shared Eden, if allowed.
3896 //
3897 // rdx: instance size in bytes
3898 if (allow_shared_alloc) {
3899 __ bind(allocate_shared);
3900
3901 ExternalAddress heap_top((address)Universe::heap()->top_addr());
3902 ExternalAddress heap_end((address)Universe::heap()->end_addr());
3903
3904 Label retry;
3905 __ bind(retry);
3906 __ movptr(rax, heap_top);
3907 __ lea(rbx, Address(rax, rdx, Address::times_1));
3908 __ cmpptr(rbx, heap_end);
3909 __ jcc(Assembler::above, slow_case);
3910
3911 // Compare rax, with the top addr, and if still equal, store the new
3912 // top addr in rbx, at the address of the top addr pointer. Sets ZF if was
3913 // equal, and clears it otherwise. Use lock prefix for atomicity on MPs.
3914 //
3915 // rax,: object begin
3916 // rbx,: object end
3917 // rdx: instance size in bytes
3918 __ locked_cmpxchgptr(rbx, heap_top);
3919
3920 // if someone beat us on the allocation, try again, otherwise continue
3921 __ jcc(Assembler::notEqual, retry);
3922
3923 __ incr_allocated_bytes(thread, rdx, 0);
3924 }
3925
3926 if (UseTLAB || Universe::heap()->supports_inline_contig_alloc()) {
3927 // The object is initialized before the header. If the object size is
3928 // zero, go directly to the header initialization.
3929 __ bind(initialize_object);
3930 __ decrement(rdx, sizeof(oopDesc));
3931 __ jcc(Assembler::zero, initialize_header);
3932
3933 // Initialize topmost object field, divide rdx by 8, check if odd and
3934 // test if zero.
3935 __ xorl(rcx, rcx); // use zero reg to clear memory (shorter code)
3936 __ shrl(rdx, LogBytesPerLong); // divide by 2*oopSize and set carry flag if odd
3937
3938 // rdx must have been multiple of 8
3939 #ifdef ASSERT
3940 // make sure rdx was multiple of 8
3941 Label L;
3942 // Ignore partial flag stall after shrl() since it is debug VM
3943 __ jccb(Assembler::carryClear, L);
3944 __ stop("object size is not multiple of 2 - adjust this code");
3945 __ bind(L);
3946 // rdx must be > 0, no extra check needed here
|
3851
3852 // make sure klass is initialized & doesn't have finalizer
3853 // make sure klass is fully initialized
3854 __ cmpb(Address(rcx, InstanceKlass::init_state_offset()), InstanceKlass::fully_initialized);
3855 __ jcc(Assembler::notEqual, slow_case);
3856
3857 // get instance_size in InstanceKlass (scaled to a count of bytes)
3858 __ movl(rdx, Address(rcx, Klass::layout_helper_offset()));
3859 // test to see if it has a finalizer or is malformed in some way
3860 __ testl(rdx, Klass::_lh_instance_slow_path_bit);
3861 __ jcc(Assembler::notZero, slow_case);
3862
3863 //
3864 // Allocate the instance
3865 // 1) Try to allocate in the TLAB
3866 // 2) if fail and the object is large allocate in the shared Eden
3867 // 3) if the above fails (or is not applicable), go to a slow case
3868 // (creates a new TLAB, etc.)
3869
3870 const bool allow_shared_alloc =
3871 GC::gc()->heap()->supports_inline_contig_alloc();
3872
3873 const Register thread = LP64_ONLY(r15_thread) NOT_LP64(rcx);
3874 #ifndef _LP64
3875 if (UseTLAB || allow_shared_alloc) {
3876 __ get_thread(thread);
3877 }
3878 #endif // _LP64
3879
3880 if (UseTLAB) {
3881 __ movptr(rax, Address(thread, in_bytes(JavaThread::tlab_top_offset())));
3882 __ lea(rbx, Address(rax, rdx, Address::times_1));
3883 __ cmpptr(rbx, Address(thread, in_bytes(JavaThread::tlab_end_offset())));
3884 __ jcc(Assembler::above, allow_shared_alloc ? allocate_shared : slow_case);
3885 __ movptr(Address(thread, in_bytes(JavaThread::tlab_top_offset())), rbx);
3886 if (ZeroTLAB) {
3887 // the fields have been already cleared
3888 __ jmp(initialize_header);
3889 } else {
3890 // initialize both the header and fields
3891 __ jmp(initialize_object);
3892 }
3893 }
3894
3895 // Allocation in the shared Eden, if allowed.
3896 //
3897 // rdx: instance size in bytes
3898 if (allow_shared_alloc) {
3899 __ bind(allocate_shared);
3900
3901 ExternalAddress heap_top((address)GC::gc()->heap()->top_addr());
3902 ExternalAddress heap_end((address)GC::gc()->heap()->end_addr());
3903
3904 Label retry;
3905 __ bind(retry);
3906 __ movptr(rax, heap_top);
3907 __ lea(rbx, Address(rax, rdx, Address::times_1));
3908 __ cmpptr(rbx, heap_end);
3909 __ jcc(Assembler::above, slow_case);
3910
3911 // Compare rax, with the top addr, and if still equal, store the new
3912 // top addr in rbx, at the address of the top addr pointer. Sets ZF if was
3913 // equal, and clears it otherwise. Use lock prefix for atomicity on MPs.
3914 //
3915 // rax,: object begin
3916 // rbx,: object end
3917 // rdx: instance size in bytes
3918 __ locked_cmpxchgptr(rbx, heap_top);
3919
3920 // if someone beat us on the allocation, try again, otherwise continue
3921 __ jcc(Assembler::notEqual, retry);
3922
3923 __ incr_allocated_bytes(thread, rdx, 0);
3924 }
3925
3926 if (UseTLAB || GC::gc()->heap()->supports_inline_contig_alloc()) {
3927 // The object is initialized before the header. If the object size is
3928 // zero, go directly to the header initialization.
3929 __ bind(initialize_object);
3930 __ decrement(rdx, sizeof(oopDesc));
3931 __ jcc(Assembler::zero, initialize_header);
3932
3933 // Initialize topmost object field, divide rdx by 8, check if odd and
3934 // test if zero.
3935 __ xorl(rcx, rcx); // use zero reg to clear memory (shorter code)
3936 __ shrl(rdx, LogBytesPerLong); // divide by 2*oopSize and set carry flag if odd
3937
3938 // rdx must have been multiple of 8
3939 #ifdef ASSERT
3940 // make sure rdx was multiple of 8
3941 Label L;
3942 // Ignore partial flag stall after shrl() since it is debug VM
3943 __ jccb(Assembler::carryClear, L);
3944 __ stop("object size is not multiple of 2 - adjust this code");
3945 __ bind(L);
3946 // rdx must be > 0, no extra check needed here
|