102 // 1) (hdr & aligned_mask) == 0
103 // 2) sp <= hdr
104 // 3) hdr <= sp + page_size
105 //
106 // these 3 tests can be done by evaluating the following expression:
107 //
108 // (hdr - sp) & (aligned_mask - page_size)
109 //
110 // assuming both the stack pointer and page_size have their least
111 // significant 2 bits cleared and page_size is a power of 2
112 mov(rscratch1, sp);
113 sub(hdr, hdr, rscratch1);
114 ands(hdr, hdr, aligned_mask - (int)os::vm_page_size());
115 // for recursive locking, the result is zero => save it in the displaced header
116 // location (null in the displaced hdr location indicates recursive locking)
117 str(hdr, Address(disp_hdr, 0));
118 // otherwise we don't care about the result and handle locking via runtime call
119 cbnz(hdr, slow_case);
120 // done
121 bind(done);
122 }
123 increment(Address(rthread, JavaThread::held_monitor_count_offset()));
124 return null_check_offset;
125 }
126
127
128 void C1_MacroAssembler::unlock_object(Register hdr, Register obj, Register disp_hdr, Register temp, Label& slow_case) {
129 const int aligned_mask = BytesPerWord -1;
130 const int hdr_offset = oopDesc::mark_offset_in_bytes();
131 assert_different_registers(hdr, obj, disp_hdr, temp, rscratch2);
132 Label done;
133
134 if (LockingMode != LM_LIGHTWEIGHT) {
135 // load displaced header
136 ldr(hdr, Address(disp_hdr, 0));
137 // if the loaded hdr is null we had recursive locking
138 // if we had recursive locking, we are done
139 cbz(hdr, done);
140 }
141
142 // load object
143 ldr(obj, Address(disp_hdr, BasicObjectLock::obj_offset()));
144 verify_oop(obj);
145
146 if (LockingMode == LM_LIGHTWEIGHT) {
147 lightweight_unlock(obj, hdr, temp, rscratch2, slow_case);
148 } else if (LockingMode == LM_LEGACY) {
149 // test if object header is pointing to the displaced header, and if so, restore
150 // the displaced header in the object - if the object header is not pointing to
151 // the displaced header, get the object header instead
152 // if the object header was not pointing to the displaced header,
153 // we do unlocking via runtime call
154 if (hdr_offset) {
155 lea(rscratch1, Address(obj, hdr_offset));
156 cmpxchgptr(disp_hdr, hdr, rscratch1, rscratch2, done, &slow_case);
157 } else {
158 cmpxchgptr(disp_hdr, hdr, obj, rscratch2, done, &slow_case);
159 }
160 // done
161 bind(done);
162 }
163 decrement(Address(rthread, JavaThread::held_monitor_count_offset()));
164 }
165
166
167 // Defines obj, preserves var_size_in_bytes
168 void C1_MacroAssembler::try_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2, Label& slow_case) {
169 if (UseTLAB) {
170 tlab_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, t2, slow_case);
171 } else {
172 b(slow_case);
173 }
174 }
175
176 void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register t1, Register t2) {
177 assert_different_registers(obj, klass, len);
178 // This assumes that all prototype bits fit in an int32_t
179 mov(t1, (int32_t)(intptr_t)markWord::prototype().value());
180 str(t1, Address(obj, oopDesc::mark_offset_in_bytes()));
181
182 if (UseCompressedClassPointers) { // Take care not to kill klass
183 encode_klass_not_null(t1, klass);
|
102 // 1) (hdr & aligned_mask) == 0
103 // 2) sp <= hdr
104 // 3) hdr <= sp + page_size
105 //
106 // these 3 tests can be done by evaluating the following expression:
107 //
108 // (hdr - sp) & (aligned_mask - page_size)
109 //
110 // assuming both the stack pointer and page_size have their least
111 // significant 2 bits cleared and page_size is a power of 2
112 mov(rscratch1, sp);
113 sub(hdr, hdr, rscratch1);
114 ands(hdr, hdr, aligned_mask - (int)os::vm_page_size());
115 // for recursive locking, the result is zero => save it in the displaced header
116 // location (null in the displaced hdr location indicates recursive locking)
117 str(hdr, Address(disp_hdr, 0));
118 // otherwise we don't care about the result and handle locking via runtime call
119 cbnz(hdr, slow_case);
120 // done
121 bind(done);
122 inc_held_monitor_count();
123 }
124 return null_check_offset;
125 }
126
127
128 void C1_MacroAssembler::unlock_object(Register hdr, Register obj, Register disp_hdr, Register temp, Label& slow_case) {
129 const int aligned_mask = BytesPerWord -1;
130 const int hdr_offset = oopDesc::mark_offset_in_bytes();
131 assert_different_registers(hdr, obj, disp_hdr, temp, rscratch2);
132 Label done;
133
134 if (LockingMode != LM_LIGHTWEIGHT) {
135 // load displaced header
136 ldr(hdr, Address(disp_hdr, 0));
137 // if the loaded hdr is null we had recursive locking
138 // if we had recursive locking, we are done
139 cbz(hdr, done);
140 }
141
142 // load object
143 ldr(obj, Address(disp_hdr, BasicObjectLock::obj_offset()));
144 verify_oop(obj);
145
146 if (LockingMode == LM_LIGHTWEIGHT) {
147 lightweight_unlock(obj, hdr, temp, rscratch2, slow_case);
148 } else if (LockingMode == LM_LEGACY) {
149 // test if object header is pointing to the displaced header, and if so, restore
150 // the displaced header in the object - if the object header is not pointing to
151 // the displaced header, get the object header instead
152 // if the object header was not pointing to the displaced header,
153 // we do unlocking via runtime call
154 if (hdr_offset) {
155 lea(rscratch1, Address(obj, hdr_offset));
156 cmpxchgptr(disp_hdr, hdr, rscratch1, rscratch2, done, &slow_case);
157 } else {
158 cmpxchgptr(disp_hdr, hdr, obj, rscratch2, done, &slow_case);
159 }
160 // done
161 bind(done);
162 dec_held_monitor_count();
163 }
164 }
165
166
167 // Defines obj, preserves var_size_in_bytes
168 void C1_MacroAssembler::try_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2, Label& slow_case) {
169 if (UseTLAB) {
170 tlab_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, t2, slow_case);
171 } else {
172 b(slow_case);
173 }
174 }
175
176 void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register t1, Register t2) {
177 assert_different_registers(obj, klass, len);
178 // This assumes that all prototype bits fit in an int32_t
179 mov(t1, (int32_t)(intptr_t)markWord::prototype().value());
180 str(t1, Address(obj, oopDesc::mark_offset_in_bytes()));
181
182 if (UseCompressedClassPointers) { // Take care not to kill klass
183 encode_klass_not_null(t1, klass);
|