1 /*
  2  * Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
  3  * Copyright (c) 2014, 2021, Red Hat Inc. 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 #ifndef CPU_AARCH64_C1_MACROASSEMBLER_AARCH64_HPP
 27 #define CPU_AARCH64_C1_MACROASSEMBLER_AARCH64_HPP
 28 
 29 using MacroAssembler::build_frame;
 30 using MacroAssembler::null_check;
 31 
 32 // C1_MacroAssembler contains high-level macros for C1
 33 
 34  private:
 35   int _rsp_offset;    // track rsp changes
 36   // initialization
 37   void pd_init() { _rsp_offset = 0; }
 38 
 39 
 40  public:
 41   void try_allocate(
 42     Register obj,                      // result: pointer to object after successful allocation
 43     Register var_size_in_bytes,        // object size in bytes if unknown at compile time; invalid otherwise
 44     int      con_size_in_bytes,        // object size in bytes if   known at compile time
 45     Register t1,                       // temp register
 46     Register t2,                       // temp register
 47     Label&   slow_case                 // continuation point if fast allocation fails
 48   );
 49 
 50   void initialize_header(Register obj, Register klass, Register len, Register t1, Register t2);
 51   void initialize_body(Register obj, Register len_in_bytes, int hdr_size_in_bytes, Register t1, Register t2);
 52 
 53   void float_cmp(bool is_float, int unordered_result,
 54                  FloatRegister f0, FloatRegister f1,
 55                  Register result);
 56 
 57   // locking
 58   // hdr     : must be r0, contents destroyed
 59   // obj     : must point to the object to lock, contents preserved
 60   // disp_hdr: must point to the displaced header location, contents preserved
 61   // returns code offset at which to add null check debug information
 62   int lock_object  (Register swap, Register obj, Register disp_hdr, Label& slow_case);
 63 
 64   // unlocking
 65   // hdr     : contents destroyed
 66   // obj     : must point to the object to lock, contents preserved
 67   // disp_hdr: must be r0 & must point to the displaced header location, contents destroyed
 68   void unlock_object(Register swap, Register obj, Register lock, Label& slow_case);
 69 
 70   void initialize_object(
 71     Register obj,                      // result: pointer to object after successful allocation
 72     Register klass,                    // object klass
 73     Register var_size_in_bytes,        // object size in bytes if unknown at compile time; invalid otherwise
 74     int      con_size_in_bytes,        // object size in bytes if   known at compile time
 75     Register t1,                       // temp register
 76     Register t2,                        // temp register
 77     bool     is_tlab_allocated         // the object was allocated in a TLAB; relevant for the implementation of ZeroTLAB
 78   );
 79 
 80   // allocation of fixed-size objects
 81   // (can also be used to allocate fixed-size arrays, by setting
 82   // hdr_size correctly and storing the array length afterwards)
 83   // obj        : will contain pointer to allocated object
 84   // t1, t2     : scratch registers - contents destroyed
 85   // header_size: size of object header in words
 86   // object_size: total size of object in words
 87   // slow_case  : exit to slow case implementation if fast allocation fails
 88   void allocate_object(Register obj, Register t1, Register t2, int header_size, int object_size, Register klass, Label& slow_case);
 89 
 90   enum {
 91     max_array_allocation_length = 0x00FFFFFF
 92   };
 93 
 94   // allocation of arrays
 95   // obj        : will contain pointer to allocated object
 96   // len        : array length in number of elements
 97   // t          : scratch register - contents destroyed
 98   // header_size: size of object header in words
 99   // f          : element scale factor
100   // slow_case  : exit to slow case implementation if fast allocation fails
101   void allocate_array(Register obj, Register len, Register t, Register t2, int base_offset_in_bytes, int f, Register klass, Label& slow_case);
102 
103   int  rsp_offset() const { return _rsp_offset; }
104   void set_rsp_offset(int n) { _rsp_offset = n; }
105 
106   void invalidate_registers(bool inv_r0, bool inv_r19, bool inv_r2, bool inv_r3, bool inv_r4, bool inv_r5) PRODUCT_RETURN;
107 
108   // This platform only uses signal-based null checks. The Label is not needed.
109   void null_check(Register r, Label *Lnull = nullptr) { MacroAssembler::null_check(r); }
110 
111   void load_parameter(int offset_in_words, Register reg);
112 
113 #endif // CPU_AARCH64_C1_MACROASSEMBLER_AARCH64_HPP