| 1 | /* |
| 2 | * Copyright (c) 1999, 2019, Oracle and/or its affiliates. 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 it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 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 USA |
| 20 | * or visit www.oracle.com if you need additional information or have any |
| 21 | * questions. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #ifndef CPU_X86_C1_MACROASSEMBLER_X86_HPP |
| 26 | #define CPU_X86_C1_MACROASSEMBLER_X86_HPP |
| 27 | |
| 28 | // C1_MacroAssembler contains high-level macros for C1 |
| 29 | |
| 30 | private: |
| 31 | int _rsp_offset; // track rsp changes |
| 32 | // initialization |
| 33 | void pd_init() { _rsp_offset = 0; } |
| 34 | |
| 35 | public: |
| 36 | void try_allocate( |
| 37 | Register obj, // result: pointer to object after successful allocation |
| 38 | Register var_size_in_bytes, // object size in bytes if unknown at compile time; invalid otherwise |
| 39 | int con_size_in_bytes, // object size in bytes if known at compile time |
| 40 | Register t1, // temp register |
| 41 | Register t2, // temp register |
| 42 | Label& slow_case // continuation point if fast allocation fails |
| 43 | ); |
| 44 | |
| 45 | void (Register obj, Register klass, Register len, Register t1, Register t2); |
| 46 | void initialize_body(Register obj, Register len_in_bytes, int hdr_size_in_bytes, Register t1); |
| 47 | |
| 48 | // locking |
| 49 | // hdr : must be rax, contents destroyed |
| 50 | // obj : must point to the object to lock, contents preserved |
| 51 | // disp_hdr: must point to the displaced header location, contents preserved |
| 52 | // scratch : scratch register, contents destroyed |
| 53 | // returns code offset at which to add null check debug information |
| 54 | int lock_object (Register swap, Register obj, Register disp_hdr, Register scratch, Label& slow_case); |
| 55 | |
| 56 | // unlocking |
| 57 | // hdr : contents destroyed |
| 58 | // obj : must point to the object to lock, contents preserved |
| 59 | // disp_hdr: must be eax & must point to the displaced header location, contents destroyed |
| 60 | void unlock_object(Register swap, Register obj, Register lock, Label& slow_case); |
| 61 | |
| 62 | void initialize_object( |
| 63 | Register obj, // result: pointer to object after successful allocation |
| 64 | Register klass, // object klass |
| 65 | Register var_size_in_bytes, // object size in bytes if unknown at compile time; invalid otherwise |
| 66 | int con_size_in_bytes, // object size in bytes if known at compile time |
| 67 | Register t1, // temp register |
| 68 | Register t2, // temp register |
| 69 | bool is_tlab_allocated // the object was allocated in a TLAB; relevant for the implementation of ZeroTLAB |
| 70 | ); |
| 71 | |
| 72 | // allocation of fixed-size objects |
| 73 | // (can also be used to allocate fixed-size arrays, by setting |
| 74 | // hdr_size correctly and storing the array length afterwards) |
| 75 | // obj : must be rax, will contain pointer to allocated object |
| 76 | // t1, t2 : scratch registers - contents destroyed |
| 77 | // header_size: size of object header in words |
| 78 | // object_size: total size of object in words |
| 79 | // slow_case : exit to slow case implementation if fast allocation fails |
| 80 | void allocate_object(Register obj, Register t1, Register t2, int , int object_size, Register klass, Label& slow_case); |
| 81 | |
| 82 | enum { |
| 83 | max_array_allocation_length = 0x00FFFFFF |
| 84 | }; |
| 85 | |
| 86 | // allocation of arrays |
| 87 | // obj : must be rax, will contain pointer to allocated object |
| 88 | // len : array length in number of elements |
| 89 | // t : scratch register - contents destroyed |
| 90 | // header_size: size of object header in words |
| 91 | // f : element scale factor |
| 92 | // slow_case : exit to slow case implementation if fast allocation fails |
| 93 | void allocate_array(Register obj, Register len, Register t, Register t2, int , Address::ScaleFactor f, Register klass, Label& slow_case); |
| 94 | |
| 95 | int rsp_offset() const { return _rsp_offset; } |
| 96 | void set_rsp_offset(int n) { _rsp_offset = n; } |
| 97 | |
| 98 | // Note: NEVER push values directly, but only through following push_xxx functions; |
| 99 | // This helps us to track the rsp changes compared to the entry rsp (->_rsp_offset) |
| 100 | |
| 101 | void push_jint (jint i) { _rsp_offset++; push(i); } |
| 102 | void push_oop (jobject o) { _rsp_offset++; pushoop(o); } |
| 103 | // Seems to always be in wordSize |
| 104 | void push_addr (Address a) { _rsp_offset++; pushptr(a); } |
| 105 | void push_reg (Register r) { _rsp_offset++; push(r); } |
| 106 | void pop_reg (Register r) { _rsp_offset--; pop(r); assert(_rsp_offset >= 0, "stack offset underflow" ); } |
| 107 | |
| 108 | void dec_stack (int nof_words) { |
| 109 | _rsp_offset -= nof_words; |
| 110 | assert(_rsp_offset >= 0, "stack offset underflow" ); |
| 111 | addptr(rsp, wordSize * nof_words); |
| 112 | } |
| 113 | |
| 114 | void dec_stack_after_call (int nof_words) { |
| 115 | _rsp_offset -= nof_words; |
| 116 | assert(_rsp_offset >= 0, "stack offset underflow" ); |
| 117 | } |
| 118 | |
| 119 | void invalidate_registers(bool inv_rax, bool inv_rbx, bool inv_rcx, bool inv_rdx, bool inv_rsi, bool inv_rdi) PRODUCT_RETURN; |
| 120 | |
| 121 | // This platform only uses signal-based null checks. The Label is not needed. |
| 122 | void null_check(Register r, Label *Lnull = NULL) { MacroAssembler::null_check(r); } |
| 123 | |
| 124 | void load_parameter(int offset_in_words, Register reg); |
| 125 | |
| 126 | void save_live_registers_no_oop_map(bool save_fpu_registers); |
| 127 | void restore_live_registers_except_rax(bool restore_fpu_registers); |
| 128 | void restore_live_registers(bool restore_fpu_registers); |
| 129 | |
| 130 | #endif // CPU_X86_C1_MACROASSEMBLER_X86_HPP |
| 131 | |