1 /*
   2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2018, SAP SE. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   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
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #include "precompiled.hpp"
  27 #include "asm/macroAssembler.inline.hpp"
  28 #include "registerSaver_s390.hpp"
  29 #include "gc/g1/g1CardTable.hpp"
  30 #include "gc/g1/g1BarrierSet.hpp"
  31 #include "gc/g1/g1BarrierSetAssembler.hpp"
  32 #include "gc/g1/heapRegion.hpp"
  33 #include "gc/shared/collectedHeap.hpp"
  34 #include "runtime/thread.hpp"
  35 #include "interpreter/interp_masm.hpp"
  36 
  37 #define __ masm->
  38 
  39 #define BLOCK_COMMENT(str) if (PrintAssembly) __ block_comment(str)
  40 
  41 void G1BarrierSetAssembler::gen_write_ref_array_pre_barrier(MacroAssembler* masm, DecoratorSet decorators,
  42                                                             Register addr, Register count) {
  43   bool dest_uninitialized = (decorators & AS_DEST_NOT_INITIALIZED) != 0;
  44 
  45   // With G1, don't generate the call if we statically know that the target is uninitialized.
  46   if (!dest_uninitialized) {
  47     // Is marking active?
  48     Label filtered;
  49     assert_different_registers(addr,  Z_R0_scratch);  // would be destroyed by push_frame()
  50     assert_different_registers(count, Z_R0_scratch);  // would be destroyed by push_frame()
  51     Register Rtmp1 = Z_R0_scratch;
  52     const int active_offset = in_bytes(JavaThread::satb_mark_queue_offset() +
  53                                        SATBMarkQueue::byte_offset_of_active());
  54     if (in_bytes(SATBMarkQueue::byte_width_of_active()) == 4) {
  55       __ load_and_test_int(Rtmp1, Address(Z_thread, active_offset));
  56     } else {
  57       guarantee(in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "Assumption");
  58       __ load_and_test_byte(Rtmp1, Address(Z_thread, active_offset));
  59     }
  60     __ z_bre(filtered); // Activity indicator is zero, so there is no marking going on currently.
  61 
  62     RegisterSaver::save_live_registers(masm, RegisterSaver::arg_registers); // Creates frame.
  63 
  64     if (UseCompressedOops) {
  65       __ call_VM_leaf(CAST_FROM_FN_PTR(address, G1BarrierSet::write_ref_array_pre_narrow_oop_entry), addr, count);
  66     } else {
  67       __ call_VM_leaf(CAST_FROM_FN_PTR(address, G1BarrierSet::write_ref_array_pre_oop_entry), addr, count);
  68     }
  69 
  70     RegisterSaver::restore_live_registers(masm, RegisterSaver::arg_registers);
  71 
  72     __ bind(filtered);
  73   }
  74 }
  75 
  76 void G1BarrierSetAssembler::gen_write_ref_array_post_barrier(MacroAssembler* masm, DecoratorSet decorators,
  77                                                              Register addr, Register count, bool do_return) {
  78   address entry_point = CAST_FROM_FN_PTR(address, G1BarrierSet::write_ref_array_post_entry);
  79   if (!do_return) {
  80     assert_different_registers(addr,  Z_R0_scratch);  // would be destroyed by push_frame()
  81     assert_different_registers(count, Z_R0_scratch);  // would be destroyed by push_frame()
  82     RegisterSaver::save_live_registers(masm, RegisterSaver::arg_registers); // Creates frame.
  83     __ call_VM_leaf(entry_point, addr, count);
  84     RegisterSaver::restore_live_registers(masm, RegisterSaver::arg_registers);
  85   } else {
  86     // Tail call: call c and return to stub caller.
  87     __ lgr_if_needed(Z_ARG1, addr);
  88     __ lgr_if_needed(Z_ARG2, count);
  89     __ load_const(Z_R1, entry_point);
  90     __ z_br(Z_R1); // Branch without linking, callee will return to stub caller.
  91   }
  92 }