1 /* |
1 /* |
2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * Copyright (c) 2016, 2018, SAP SE. All rights reserved. |
3 * Copyright (c) 2016, 2019, SAP SE. All rights reserved. |
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5 * |
5 * |
6 * This code is free software; you can redistribute it and/or modify it |
6 * This code is free software; you can redistribute it and/or modify it |
7 * under the terms of the GNU General Public License version 2 only, as |
7 * under the terms of the GNU General Public License version 2 only, as |
8 * published by the Free Software Foundation. |
8 * published by the Free Software Foundation. |
3128 temp1_reg, temp2_reg, &L_success, NULL); |
3128 temp1_reg, temp2_reg, &L_success, NULL); |
3129 BIND(failure); |
3129 BIND(failure); |
3130 BLOCK_COMMENT("} check_klass_subtype"); |
3130 BLOCK_COMMENT("} check_klass_subtype"); |
3131 } |
3131 } |
3132 |
3132 |
|
3133 void MacroAssembler::clinit_barrier(Register klass, Register thread, Label* L_fast_path, Label* L_slow_path) { |
|
3134 assert(L_fast_path != NULL || L_slow_path != NULL, "at least one is required"); |
|
3135 |
|
3136 Label L_fallthrough; |
|
3137 if (L_fast_path == NULL) { |
|
3138 L_fast_path = &L_fallthrough; |
|
3139 } else if (L_slow_path == NULL) { |
|
3140 L_slow_path = &L_fallthrough; |
|
3141 } |
|
3142 |
|
3143 // Fast path check: class is fully initialized |
|
3144 z_cli(Address(klass, InstanceKlass::init_state_offset()), InstanceKlass::fully_initialized); |
|
3145 z_bre(*L_fast_path); |
|
3146 |
|
3147 // Fast path check: current thread is initializer thread |
|
3148 z_cg(thread, Address(klass, InstanceKlass::init_thread_offset())); |
|
3149 if (L_slow_path == &L_fallthrough) { |
|
3150 z_bre(*L_fast_path); |
|
3151 } else if (L_fast_path == &L_fallthrough) { |
|
3152 z_brne(*L_slow_path); |
|
3153 } else { |
|
3154 Unimplemented(); |
|
3155 } |
|
3156 |
|
3157 bind(L_fallthrough); |
|
3158 } |
|
3159 |
3133 // Increment a counter at counter_address when the eq condition code is |
3160 // Increment a counter at counter_address when the eq condition code is |
3134 // set. Kills registers tmp1_reg and tmp2_reg and preserves the condition code. |
3161 // set. Kills registers tmp1_reg and tmp2_reg and preserves the condition code. |
3135 void MacroAssembler::increment_counter_eq(address counter_address, Register tmp1_reg, Register tmp2_reg) { |
3162 void MacroAssembler::increment_counter_eq(address counter_address, Register tmp1_reg, Register tmp2_reg) { |
3136 Label l; |
3163 Label l; |
3137 z_brne(l); |
3164 z_brne(l); |
3169 // Biased locking |
3196 // Biased locking |
3170 // See whether the lock is currently biased toward our thread and |
3197 // See whether the lock is currently biased toward our thread and |
3171 // whether the epoch is still valid. |
3198 // whether the epoch is still valid. |
3172 // Note that the runtime guarantees sufficient alignment of JavaThread |
3199 // Note that the runtime guarantees sufficient alignment of JavaThread |
3173 // pointers to allow age to be placed into low bits. |
3200 // pointers to allow age to be placed into low bits. |
3174 assert(markOopDesc::age_shift == markOopDesc::lock_bits + markOopDesc::biased_lock_bits, |
3201 assert(markWord::age_shift == markWord::lock_bits + markWord::biased_lock_bits, |
3175 "biased locking makes assumptions about bit layout"); |
3202 "biased locking makes assumptions about bit layout"); |
3176 z_lr(temp_reg, mark_reg); |
3203 z_lr(temp_reg, mark_reg); |
3177 z_nilf(temp_reg, markOopDesc::biased_lock_mask_in_place); |
3204 z_nilf(temp_reg, markWord::biased_lock_mask_in_place); |
3178 z_chi(temp_reg, markOopDesc::biased_lock_pattern); |
3205 z_chi(temp_reg, markWord::biased_lock_pattern); |
3179 z_brne(cas_label); // Try cas if object is not biased, i.e. cannot be biased locked. |
3206 z_brne(cas_label); // Try cas if object is not biased, i.e. cannot be biased locked. |
3180 |
3207 |
3181 load_prototype_header(temp_reg, obj_reg); |
3208 load_prototype_header(temp_reg, obj_reg); |
3182 load_const_optimized(temp2_reg, ~((int) markOopDesc::age_mask_in_place)); |
3209 load_const_optimized(temp2_reg, ~((int) markWord::age_mask_in_place)); |
3183 |
3210 |
3184 z_ogr(temp_reg, Z_thread); |
3211 z_ogr(temp_reg, Z_thread); |
3185 z_xgr(temp_reg, mark_reg); |
3212 z_xgr(temp_reg, mark_reg); |
3186 z_ngr(temp_reg, temp2_reg); |
3213 z_ngr(temp_reg, temp2_reg); |
3187 if (PrintBiasedLockingStatistics) { |
3214 if (PrintBiasedLockingStatistics) { |
3203 // header. |
3230 // header. |
3204 |
3231 |
3205 // If the low three bits in the xor result aren't clear, that means |
3232 // If the low three bits in the xor result aren't clear, that means |
3206 // the prototype header is no longer biased and we have to revoke |
3233 // the prototype header is no longer biased and we have to revoke |
3207 // the bias on this object. |
3234 // the bias on this object. |
3208 z_tmll(temp_reg, markOopDesc::biased_lock_mask_in_place); |
3235 z_tmll(temp_reg, markWord::biased_lock_mask_in_place); |
3209 z_brnaz(try_revoke_bias); |
3236 z_brnaz(try_revoke_bias); |
3210 |
3237 |
3211 // Biasing is still enabled for this data type. See whether the |
3238 // Biasing is still enabled for this data type. See whether the |
3212 // epoch of the current bias is still valid, meaning that the epoch |
3239 // epoch of the current bias is still valid, meaning that the epoch |
3213 // bits of the mark word are equal to the epoch bits of the |
3240 // bits of the mark word are equal to the epoch bits of the |
3215 // only change at a safepoint.) If not, attempt to rebias the object |
3242 // only change at a safepoint.) If not, attempt to rebias the object |
3216 // toward the current thread. Note that we must be absolutely sure |
3243 // toward the current thread. Note that we must be absolutely sure |
3217 // that the current epoch is invalid in order to do this because |
3244 // that the current epoch is invalid in order to do this because |
3218 // otherwise the manipulations it performs on the mark word are |
3245 // otherwise the manipulations it performs on the mark word are |
3219 // illegal. |
3246 // illegal. |
3220 z_tmll(temp_reg, markOopDesc::epoch_mask_in_place); |
3247 z_tmll(temp_reg, markWord::epoch_mask_in_place); |
3221 z_brnaz(try_rebias); |
3248 z_brnaz(try_rebias); |
3222 |
3249 |
3223 //---------------------------------------------------------------------------- |
3250 //---------------------------------------------------------------------------- |
3224 // The epoch of the current bias is still valid but we know nothing |
3251 // The epoch of the current bias is still valid but we know nothing |
3225 // about the owner; it might be set or it might be clear. Try to |
3252 // about the owner; it might be set or it might be clear. Try to |
3226 // acquire the bias of the object using an atomic operation. If this |
3253 // acquire the bias of the object using an atomic operation. If this |
3227 // fails we will go in to the runtime to revoke the object's bias. |
3254 // fails we will go in to the runtime to revoke the object's bias. |
3228 // Note that we first construct the presumed unbiased header so we |
3255 // Note that we first construct the presumed unbiased header so we |
3229 // don't accidentally blow away another thread's valid bias. |
3256 // don't accidentally blow away another thread's valid bias. |
3230 z_nilf(mark_reg, markOopDesc::biased_lock_mask_in_place | markOopDesc::age_mask_in_place | |
3257 z_nilf(mark_reg, markWord::biased_lock_mask_in_place | markWord::age_mask_in_place | |
3231 markOopDesc::epoch_mask_in_place); |
3258 markWord::epoch_mask_in_place); |
3232 z_lgr(temp_reg, Z_thread); |
3259 z_lgr(temp_reg, Z_thread); |
3233 z_llgfr(mark_reg, mark_reg); |
3260 z_llgfr(mark_reg, mark_reg); |
3234 z_ogr(temp_reg, mark_reg); |
3261 z_ogr(temp_reg, mark_reg); |
3235 |
3262 |
3236 assert(oopDesc::mark_offset_in_bytes() == 0, "offset of _mark is not 0"); |
3263 assert(oopDesc::mark_offset_in_bytes() == 0, "offset of _mark is not 0"); |
3258 // circumstances _only_, we are allowed to use the current header's |
3285 // circumstances _only_, we are allowed to use the current header's |
3259 // value as the comparison value when doing the cas to acquire the |
3286 // value as the comparison value when doing the cas to acquire the |
3260 // bias in the current epoch. In other words, we allow transfer of |
3287 // bias in the current epoch. In other words, we allow transfer of |
3261 // the bias from one thread to another directly in this situation. |
3288 // the bias from one thread to another directly in this situation. |
3262 |
3289 |
3263 z_nilf(mark_reg, markOopDesc::biased_lock_mask_in_place | markOopDesc::age_mask_in_place | markOopDesc::epoch_mask_in_place); |
3290 z_nilf(mark_reg, markWord::biased_lock_mask_in_place | markWord::age_mask_in_place | markWord::epoch_mask_in_place); |
3264 load_prototype_header(temp_reg, obj_reg); |
3291 load_prototype_header(temp_reg, obj_reg); |
3265 z_llgfr(mark_reg, mark_reg); |
3292 z_llgfr(mark_reg, mark_reg); |
3266 |
3293 |
3267 z_ogr(temp_reg, Z_thread); |
3294 z_ogr(temp_reg, Z_thread); |
3268 |
3295 |
3319 // lock, the object could not be rebiased toward another thread, so |
3346 // lock, the object could not be rebiased toward another thread, so |
3320 // the bias bit would be clear. |
3347 // the bias bit would be clear. |
3321 BLOCK_COMMENT("biased_locking_exit {"); |
3348 BLOCK_COMMENT("biased_locking_exit {"); |
3322 |
3349 |
3323 z_lg(temp_reg, 0, mark_addr); |
3350 z_lg(temp_reg, 0, mark_addr); |
3324 z_nilf(temp_reg, markOopDesc::biased_lock_mask_in_place); |
3351 z_nilf(temp_reg, markWord::biased_lock_mask_in_place); |
3325 |
3352 |
3326 z_chi(temp_reg, markOopDesc::biased_lock_pattern); |
3353 z_chi(temp_reg, markWord::biased_lock_pattern); |
3327 z_bre(done); |
3354 z_bre(done); |
3328 BLOCK_COMMENT("} biased_locking_exit"); |
3355 BLOCK_COMMENT("} biased_locking_exit"); |
3329 } |
3356 } |
3330 |
3357 |
3331 void MacroAssembler::compiler_fast_lock_object(Register oop, Register box, Register temp1, Register temp2, bool try_bias) { |
3358 void MacroAssembler::compiler_fast_lock_object(Register oop, Register box, Register temp1, Register temp2, bool try_bias) { |
3334 Register temp = temp2; |
3361 Register temp = temp2; |
3335 NearLabel done, object_has_monitor; |
3362 NearLabel done, object_has_monitor; |
3336 |
3363 |
3337 BLOCK_COMMENT("compiler_fast_lock_object {"); |
3364 BLOCK_COMMENT("compiler_fast_lock_object {"); |
3338 |
3365 |
3339 // Load markOop from oop into mark. |
3366 // Load markWord from oop into mark. |
3340 z_lg(displacedHeader, 0, oop); |
3367 z_lg(displacedHeader, 0, oop); |
3341 |
3368 |
3342 if (try_bias) { |
3369 if (try_bias) { |
3343 biased_locking_enter(oop, displacedHeader, temp, Z_R0, done); |
3370 biased_locking_enter(oop, displacedHeader, temp, Z_R0, done); |
3344 } |
3371 } |
3345 |
3372 |
3346 // Handle existing monitor. |
3373 // Handle existing monitor. |
3347 // The object has an existing monitor iff (mark & monitor_value) != 0. |
3374 // The object has an existing monitor iff (mark & monitor_value) != 0. |
3348 guarantee(Immediate::is_uimm16(markOopDesc::monitor_value), "must be half-word"); |
3375 guarantee(Immediate::is_uimm16(markWord::monitor_value), "must be half-word"); |
3349 z_lr(temp, displacedHeader); |
3376 z_lr(temp, displacedHeader); |
3350 z_nill(temp, markOopDesc::monitor_value); |
3377 z_nill(temp, markWord::monitor_value); |
3351 z_brne(object_has_monitor); |
3378 z_brne(object_has_monitor); |
3352 |
3379 |
3353 // Set mark to markOop | markOopDesc::unlocked_value. |
3380 // Set mark to markWord | markWord::unlocked_value. |
3354 z_oill(displacedHeader, markOopDesc::unlocked_value); |
3381 z_oill(displacedHeader, markWord::unlocked_value); |
3355 |
3382 |
3356 // Load Compare Value application register. |
3383 // Load Compare Value application register. |
3357 |
3384 |
3358 // Initialize the box (must happen before we update the object mark). |
3385 // Initialize the box (must happen before we update the object mark). |
3359 z_stg(displacedHeader, BasicLock::displaced_header_offset_in_bytes(), box); |
3386 z_stg(displacedHeader, BasicLock::displaced_header_offset_in_bytes(), box); |
3360 |
3387 |
3361 // Memory Fence (in cmpxchgd) |
3388 // Memory Fence (in cmpxchgd) |
3362 // Compare object markOop with mark and if equal exchange scratch1 with object markOop. |
3389 // Compare object markWord with mark and if equal exchange scratch1 with object markWord. |
3363 |
3390 |
3364 // If the compare-and-swap succeeded, then we found an unlocked object and we |
3391 // If the compare-and-swap succeeded, then we found an unlocked object and we |
3365 // have now locked it. |
3392 // have now locked it. |
3366 z_csg(displacedHeader, box, 0, oop); |
3393 z_csg(displacedHeader, box, 0, oop); |
3367 assert(currentHeader==displacedHeader, "must be same register"); // Identified two registers from z/Architecture. |
3394 assert(currentHeader==displacedHeader, "must be same register"); // Identified two registers from z/Architecture. |
3368 z_bre(done); |
3395 z_bre(done); |
3369 |
3396 |
3370 // We did not see an unlocked object so try the fast recursive case. |
3397 // We did not see an unlocked object so try the fast recursive case. |
3371 |
3398 |
3372 z_sgr(currentHeader, Z_SP); |
3399 z_sgr(currentHeader, Z_SP); |
3373 load_const_optimized(temp, (~(os::vm_page_size()-1) | markOopDesc::lock_mask_in_place)); |
3400 load_const_optimized(temp, (~(os::vm_page_size()-1) | markWord::lock_mask_in_place)); |
3374 |
3401 |
3375 z_ngr(currentHeader, temp); |
3402 z_ngr(currentHeader, temp); |
3376 // z_brne(done); |
3403 // z_brne(done); |
3377 // z_release(); |
3404 // z_release(); |
3378 z_stg(currentHeader/*==0 or not 0*/, BasicLock::displaced_header_offset_in_bytes(), box); |
3405 z_stg(currentHeader/*==0 or not 0*/, BasicLock::displaced_header_offset_in_bytes(), box); |
3379 |
3406 |
3380 z_bru(done); |
3407 z_bru(done); |
3381 |
3408 |
3382 Register zero = temp; |
3409 Register zero = temp; |
3383 Register monitor_tagged = displacedHeader; // Tagged with markOopDesc::monitor_value. |
3410 Register monitor_tagged = displacedHeader; // Tagged with markWord::monitor_value. |
3384 bind(object_has_monitor); |
3411 bind(object_has_monitor); |
3385 // The object's monitor m is unlocked iff m->owner == NULL, |
3412 // The object's monitor m is unlocked iff m->owner == NULL, |
3386 // otherwise m->owner may contain a thread or a stack address. |
3413 // otherwise m->owner may contain a thread or a stack address. |
3387 // |
3414 // |
3388 // Try to CAS m->owner from NULL to current thread. |
3415 // Try to CAS m->owner from NULL to current thread. |
3427 z_bre(done); |
3454 z_bre(done); |
3428 |
3455 |
3429 // Handle existing monitor. |
3456 // Handle existing monitor. |
3430 // The object has an existing monitor iff (mark & monitor_value) != 0. |
3457 // The object has an existing monitor iff (mark & monitor_value) != 0. |
3431 z_lg(currentHeader, oopDesc::mark_offset_in_bytes(), oop); |
3458 z_lg(currentHeader, oopDesc::mark_offset_in_bytes(), oop); |
3432 guarantee(Immediate::is_uimm16(markOopDesc::monitor_value), "must be half-word"); |
3459 guarantee(Immediate::is_uimm16(markWord::monitor_value), "must be half-word"); |
3433 z_nill(currentHeader, markOopDesc::monitor_value); |
3460 z_nill(currentHeader, markWord::monitor_value); |
3434 z_brne(object_has_monitor); |
3461 z_brne(object_has_monitor); |
3435 |
3462 |
3436 // Check if it is still a light weight lock, this is true if we see |
3463 // Check if it is still a light weight lock, this is true if we see |
3437 // the stack address of the basicLock in the markOop of the object |
3464 // the stack address of the basicLock in the markWord of the object |
3438 // copy box to currentHeader such that csg does not kill it. |
3465 // copy box to currentHeader such that csg does not kill it. |
3439 z_lgr(currentHeader, box); |
3466 z_lgr(currentHeader, box); |
3440 z_csg(currentHeader, displacedHeader, 0, oop); |
3467 z_csg(currentHeader, displacedHeader, 0, oop); |
3441 z_bru(done); // Csg sets CR as desired. |
3468 z_bru(done); // Csg sets CR as desired. |
3442 |
3469 |
4337 void MacroAssembler::resolve_oop_handle(Register result) { |
4364 void MacroAssembler::resolve_oop_handle(Register result) { |
4338 // OopHandle::resolve is an indirection. |
4365 // OopHandle::resolve is an indirection. |
4339 z_lg(result, 0, result); |
4366 z_lg(result, 0, result); |
4340 } |
4367 } |
4341 |
4368 |
4342 void MacroAssembler::load_mirror(Register mirror, Register method) { |
4369 void MacroAssembler::load_mirror_from_const_method(Register mirror, Register const_method) { |
4343 mem2reg_opt(mirror, Address(method, Method::const_offset())); |
4370 mem2reg_opt(mirror, Address(const_method, ConstMethod::constants_offset())); |
4344 mem2reg_opt(mirror, Address(mirror, ConstMethod::constants_offset())); |
|
4345 mem2reg_opt(mirror, Address(mirror, ConstantPool::pool_holder_offset_in_bytes())); |
4371 mem2reg_opt(mirror, Address(mirror, ConstantPool::pool_holder_offset_in_bytes())); |
4346 mem2reg_opt(mirror, Address(mirror, Klass::java_mirror_offset())); |
4372 mem2reg_opt(mirror, Address(mirror, Klass::java_mirror_offset())); |
4347 resolve_oop_handle(mirror); |
4373 resolve_oop_handle(mirror); |
|
4374 } |
|
4375 |
|
4376 void MacroAssembler::load_method_holder(Register holder, Register method) { |
|
4377 mem2reg_opt(holder, Address(method, Method::const_offset())); |
|
4378 mem2reg_opt(holder, Address(holder, ConstMethod::constants_offset())); |
|
4379 mem2reg_opt(holder, Address(holder, ConstantPool::pool_holder_offset_in_bytes())); |
4348 } |
4380 } |
4349 |
4381 |
4350 //--------------------------------------------------------------- |
4382 //--------------------------------------------------------------- |
4351 //--- Operations on arrays. |
4383 //--- Operations on arrays. |
4352 //--------------------------------------------------------------- |
4384 //--------------------------------------------------------------- |
5857 bool MacroAssembler::load_const_from_toc(Register dst, AddressLiteral& a, Register Rtoc) { |
5889 bool MacroAssembler::load_const_from_toc(Register dst, AddressLiteral& a, Register Rtoc) { |
5858 int tocOffset = store_const_in_toc(a); |
5890 int tocOffset = store_const_in_toc(a); |
5859 if (tocOffset == -1) return false; |
5891 if (tocOffset == -1) return false; |
5860 address tocPos = tocOffset + code()->consts()->start(); |
5892 address tocPos = tocOffset + code()->consts()->start(); |
5861 assert((address)code()->consts()->start() != NULL, "Please add CP address"); |
5893 assert((address)code()->consts()->start() != NULL, "Please add CP address"); |
5862 |
5894 relocate(a.rspec()); |
5863 load_long_pcrelative(dst, tocPos); |
5895 load_long_pcrelative(dst, tocPos); |
5864 return true; |
5896 return true; |
5865 } |
5897 } |
5866 |
5898 |
5867 bool MacroAssembler::load_oop_from_toc(Register dst, AddressLiteral& a, Register Rtoc) { |
5899 bool MacroAssembler::load_oop_from_toc(Register dst, AddressLiteral& a, Register Rtoc) { |