Path: blob/master/src/hotspot/cpu/s390/c1_MacroAssembler_s390.cpp
40930 views
/*1* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2016 SAP SE. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "precompiled.hpp"26#include "asm/macroAssembler.inline.hpp"27#include "c1/c1_MacroAssembler.hpp"28#include "c1/c1_Runtime1.hpp"29#include "gc/shared/collectedHeap.hpp"30#include "gc/shared/tlab_globals.hpp"31#include "interpreter/interpreter.hpp"32#include "oops/arrayOop.hpp"33#include "oops/markWord.hpp"34#include "runtime/basicLock.hpp"35#include "runtime/biasedLocking.hpp"36#include "runtime/os.hpp"37#include "runtime/sharedRuntime.hpp"38#include "runtime/stubRoutines.hpp"3940void C1_MacroAssembler::inline_cache_check(Register receiver, Register iCache) {41Label ic_miss, ic_hit;42verify_oop(receiver, FILE_AND_LINE);43int klass_offset = oopDesc::klass_offset_in_bytes();4445if (!ImplicitNullChecks || MacroAssembler::needs_explicit_null_check(klass_offset)) {46if (VM_Version::has_CompareBranch()) {47z_cgij(receiver, 0, Assembler::bcondEqual, ic_miss);48} else {49z_ltgr(receiver, receiver);50z_bre(ic_miss);51}52}5354compare_klass_ptr(iCache, klass_offset, receiver, false);55z_bre(ic_hit);5657// If icache check fails, then jump to runtime routine.58// Note: RECEIVER must still contain the receiver!59load_const_optimized(Z_R1_scratch, AddressLiteral(SharedRuntime::get_ic_miss_stub()));60z_br(Z_R1_scratch);61align(CodeEntryAlignment);62bind(ic_hit);63}6465void C1_MacroAssembler::explicit_null_check(Register base) {66ShouldNotCallThis(); // unused67}6869void C1_MacroAssembler::build_frame(int frame_size_in_bytes, int bang_size_in_bytes) {70assert(bang_size_in_bytes >= frame_size_in_bytes, "stack bang size incorrect");71generate_stack_overflow_check(bang_size_in_bytes);72save_return_pc();73push_frame(frame_size_in_bytes);74}7576void C1_MacroAssembler::verified_entry() {77if (C1Breakpoint) z_illtrap(0xC1);78}7980void C1_MacroAssembler::lock_object(Register hdr, Register obj, Register disp_hdr, Label& slow_case) {81const int hdr_offset = oopDesc::mark_offset_in_bytes();82assert_different_registers(hdr, obj, disp_hdr);83NearLabel done;8485verify_oop(obj, FILE_AND_LINE);8687// Load object header.88z_lg(hdr, Address(obj, hdr_offset));8990// Save object being locked into the BasicObjectLock...91z_stg(obj, Address(disp_hdr, BasicObjectLock::obj_offset_in_bytes()));9293if (DiagnoseSyncOnValueBasedClasses != 0) {94load_klass(Z_R1_scratch, obj);95testbit(Address(Z_R1_scratch, Klass::access_flags_offset()), exact_log2(JVM_ACC_IS_VALUE_BASED_CLASS));96z_btrue(slow_case);97}9899if (UseBiasedLocking) {100biased_locking_enter(obj, hdr, Z_R1_scratch, Z_R0_scratch, done, &slow_case);101}102103// and mark it as unlocked.104z_oill(hdr, markWord::unlocked_value);105// Save unlocked object header into the displaced header location on the stack.106z_stg(hdr, Address(disp_hdr, (intptr_t)0));107// Test if object header is still the same (i.e. unlocked), and if so, store the108// displaced header address in the object header. If it is not the same, get the109// object header instead.110z_csg(hdr, disp_hdr, hdr_offset, obj);111// If the object header was the same, we're done.112if (PrintBiasedLockingStatistics) {113Unimplemented();114#if 0115cond_inc32(Assembler::equal,116ExternalAddress((address)BiasedLocking::fast_path_entry_count_addr()));117#endif118}119branch_optimized(Assembler::bcondEqual, done);120// If the object header was not the same, it is now in the hdr register.121// => Test if it is a stack pointer into the same stack (recursive locking), i.e.:122//123// 1) (hdr & markWord::lock_mask_in_place) == 0124// 2) rsp <= hdr125// 3) hdr <= rsp + page_size126//127// These 3 tests can be done by evaluating the following expression:128//129// (hdr - Z_SP) & (~(page_size-1) | markWord::lock_mask_in_place)130//131// assuming both the stack pointer and page_size have their least132// significant 2 bits cleared and page_size is a power of 2133z_sgr(hdr, Z_SP);134135load_const_optimized(Z_R0_scratch, (~(os::vm_page_size()-1) | markWord::lock_mask_in_place));136z_ngr(hdr, Z_R0_scratch); // AND sets CC (result eq/ne 0).137// For recursive locking, the result is zero. => Save it in the displaced header138// location (NULL in the displaced hdr location indicates recursive locking).139z_stg(hdr, Address(disp_hdr, (intptr_t)0));140// Otherwise we don't care about the result and handle locking via runtime call.141branch_optimized(Assembler::bcondNotZero, slow_case);142// done143bind(done);144}145146void C1_MacroAssembler::unlock_object(Register hdr, Register obj, Register disp_hdr, Label& slow_case) {147const int aligned_mask = BytesPerWord -1;148const int hdr_offset = oopDesc::mark_offset_in_bytes();149assert_different_registers(hdr, obj, disp_hdr);150NearLabel done;151152if (UseBiasedLocking) {153// Load object.154z_lg(obj, Address(disp_hdr, BasicObjectLock::obj_offset_in_bytes()));155biased_locking_exit(obj, hdr, done);156}157158// Load displaced header.159z_ltg(hdr, Address(disp_hdr, (intptr_t)0));160// If the loaded hdr is NULL we had recursive locking, and we are done.161z_bre(done);162if (!UseBiasedLocking) {163// Load object.164z_lg(obj, Address(disp_hdr, BasicObjectLock::obj_offset_in_bytes()));165}166verify_oop(obj, FILE_AND_LINE);167// Test if object header is pointing to the displaced header, and if so, restore168// the displaced header in the object. If the object header is not pointing to169// the displaced header, get the object header instead.170z_csg(disp_hdr, hdr, hdr_offset, obj);171// If the object header was not pointing to the displaced header,172// we do unlocking via runtime call.173branch_optimized(Assembler::bcondNotEqual, slow_case);174// done175bind(done);176}177178void C1_MacroAssembler::try_allocate(179Register obj, // result: Pointer to object after successful allocation.180Register var_size_in_bytes, // Object size in bytes if unknown at compile time; invalid otherwise.181int con_size_in_bytes, // Object size in bytes if known at compile time.182Register t1, // Temp register: Must be global register for incr_allocated_bytes.183Label& slow_case // Continuation point if fast allocation fails.184) {185if (UseTLAB) {186tlab_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, slow_case);187} else {188// Allocation in shared Eden not implemented, because sapjvm allocation trace does not allow it.189z_brul(slow_case);190}191}192193void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register Rzero, Register t1) {194assert_different_registers(obj, klass, len, t1, Rzero);195if (UseBiasedLocking && !len->is_valid()) {196assert_different_registers(obj, klass, len, t1);197z_lg(t1, Address(klass, Klass::prototype_header_offset()));198} else {199// This assumes that all prototype bits fit in an int32_t.200load_const_optimized(t1, (intx)markWord::prototype().value());201}202z_stg(t1, Address(obj, oopDesc::mark_offset_in_bytes()));203204if (len->is_valid()) {205// Length will be in the klass gap, if one exists.206z_st(len, Address(obj, arrayOopDesc::length_offset_in_bytes()));207} else if (UseCompressedClassPointers) {208store_klass_gap(Rzero, obj); // Zero klass gap for compressed oops.209}210store_klass(klass, obj, t1);211}212213void C1_MacroAssembler::initialize_body(Register objectFields, Register len_in_bytes, Register Rzero) {214Label done;215assert_different_registers(objectFields, len_in_bytes, Rzero);216217// Initialize object fields.218// See documentation for MVCLE instruction!!!219assert(objectFields->encoding()%2==0, "objectFields must be an even register");220assert(len_in_bytes->encoding() == (objectFields->encoding()+1), "objectFields and len_in_bytes must be a register pair");221assert(Rzero->encoding()%2==1, "Rzero must be an odd register");222223// Use Rzero as src length, then mvcle will copy nothing224// and fill the object with the padding value 0.225move_long_ext(objectFields, as_Register(Rzero->encoding()-1), 0);226bind(done);227}228229void C1_MacroAssembler::allocate_object(230Register obj, // Result: pointer to object after successful allocation.231Register t1, // temp register232Register t2, // temp register: Must be a global register for try_allocate.233int hdr_size, // object header size in words234int obj_size, // object size in words235Register klass, // object klass236Label& slow_case // Continuation point if fast allocation fails.237) {238assert_different_registers(obj, t1, t2, klass);239240// Allocate space and initialize header.241try_allocate(obj, noreg, obj_size * wordSize, t1, slow_case);242243initialize_object(obj, klass, noreg, obj_size * HeapWordSize, t1, t2);244}245246void C1_MacroAssembler::initialize_object(247Register obj, // result: Pointer to object after successful allocation.248Register klass, // object klass249Register var_size_in_bytes, // Object size in bytes if unknown at compile time; invalid otherwise.250int con_size_in_bytes, // Object size in bytes if known at compile time.251Register t1, // temp register252Register t2 // temp register253) {254assert((con_size_in_bytes & MinObjAlignmentInBytesMask) == 0,255"con_size_in_bytes is not multiple of alignment");256assert(var_size_in_bytes == noreg, "not implemented");257const int hdr_size_in_bytes = instanceOopDesc::header_size() * HeapWordSize;258259const Register Rzero = t2;260261z_xgr(Rzero, Rzero);262initialize_header(obj, klass, noreg, Rzero, t1);263264// Clear rest of allocated space.265const int threshold = 4 * BytesPerWord;266if (con_size_in_bytes <= threshold) {267// Use explicit null stores.268// code size = 6*n bytes (n = number of fields to clear)269for (int i = hdr_size_in_bytes; i < con_size_in_bytes; i += BytesPerWord)270z_stg(Rzero, Address(obj, i));271} else {272// Code size generated by initialize_body() is 16.273Register object_fields = Z_R0_scratch;274Register len_in_bytes = Z_R1_scratch;275z_la(object_fields, hdr_size_in_bytes, obj);276load_const_optimized(len_in_bytes, con_size_in_bytes - hdr_size_in_bytes);277initialize_body(object_fields, len_in_bytes, Rzero);278}279280// Dtrace support is unimplemented.281// if (CURRENT_ENV->dtrace_alloc_probes()) {282// assert(obj == rax, "must be");283// call(RuntimeAddress(Runtime1::entry_for (Runtime1::dtrace_object_alloc_id)));284// }285286verify_oop(obj, FILE_AND_LINE);287}288289void C1_MacroAssembler::allocate_array(290Register obj, // result: Pointer to array after successful allocation.291Register len, // array length292Register t1, // temp register293Register t2, // temp register294int hdr_size, // object header size in words295int elt_size, // element size in bytes296Register klass, // object klass297Label& slow_case // Continuation point if fast allocation fails.298) {299assert_different_registers(obj, len, t1, t2, klass);300301// Determine alignment mask.302assert(!(BytesPerWord & 1), "must be a multiple of 2 for masking code to work");303304// Check for negative or excessive length.305compareU64_and_branch(len, (int32_t)max_array_allocation_length, bcondHigh, slow_case);306307// Compute array size.308// Note: If 0 <= len <= max_length, len*elt_size + header + alignment is309// smaller or equal to the largest integer. Also, since top is always310// aligned, we can do the alignment here instead of at the end address311// computation.312const Register arr_size = t2;313switch (elt_size) {314case 1: lgr_if_needed(arr_size, len); break;315case 2: z_sllg(arr_size, len, 1); break;316case 4: z_sllg(arr_size, len, 2); break;317case 8: z_sllg(arr_size, len, 3); break;318default: ShouldNotReachHere();319}320add2reg(arr_size, hdr_size * wordSize + MinObjAlignmentInBytesMask); // Add space for header & alignment.321z_nill(arr_size, (~MinObjAlignmentInBytesMask) & 0xffff); // Align array size.322323try_allocate(obj, arr_size, 0, t1, slow_case);324325initialize_header(obj, klass, len, noreg, t1);326327// Clear rest of allocated space.328Label done;329Register object_fields = t1;330Register Rzero = Z_R1_scratch;331z_aghi(arr_size, -(hdr_size * BytesPerWord));332z_bre(done); // Jump if size of fields is zero.333z_la(object_fields, hdr_size * BytesPerWord, obj);334z_xgr(Rzero, Rzero);335initialize_body(object_fields, arr_size, Rzero);336bind(done);337338// Dtrace support is unimplemented.339// if (CURRENT_ENV->dtrace_alloc_probes()) {340// assert(obj == rax, "must be");341// call(RuntimeAddress(Runtime1::entry_for (Runtime1::dtrace_object_alloc_id)));342// }343344verify_oop(obj, FILE_AND_LINE);345}346347348#ifndef PRODUCT349350void C1_MacroAssembler::verify_stack_oop(int stack_offset) {351if (!VerifyOops) return;352verify_oop_addr(Address(Z_SP, stack_offset), FILE_AND_LINE);353}354355void C1_MacroAssembler::verify_not_null_oop(Register r) {356if (!VerifyOops) return;357NearLabel not_null;358compareU64_and_branch(r, (intptr_t)0, bcondNotEqual, not_null);359stop("non-null oop required");360bind(not_null);361verify_oop(r, FILE_AND_LINE);362}363364void C1_MacroAssembler::invalidate_registers(Register preserve1,365Register preserve2,366Register preserve3) {367Register dead_value = noreg;368for (int i = 0; i < FrameMap::nof_cpu_regs; i++) {369Register r = as_Register(i);370if (r != preserve1 && r != preserve2 && r != preserve3 && r != Z_SP && r != Z_thread) {371if (dead_value == noreg) {372load_const_optimized(r, 0xc1dead);373dead_value = r;374} else {375z_lgr(r, dead_value);376}377}378}379}380381#endif // !PRODUCT382383384