src/cpu/x86/vm/c1_FpuStackSim_x86.cpp

Fri, 16 Aug 2019 16:50:17 +0200

author
eosterlund
date
Fri, 16 Aug 2019 16:50:17 +0200
changeset 9834
bb1da64b0492
parent 2314
f95d63e2154a
child 6876
710a3c8b516e
permissions
-rw-r--r--

8229345: Memory leak due to vtable stubs not being shared on SPARC
Reviewed-by: mdoerr, dholmes, kvn

duke@435 1 /*
stefank@2314 2 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "c1/c1_FpuStackSim.hpp"
stefank@2314 27 #include "c1/c1_FrameMap.hpp"
stefank@2314 28 #include "utilities/array.hpp"
stefank@2314 29 #include "utilities/ostream.hpp"
duke@435 30
duke@435 31 //--------------------------------------------------------
duke@435 32 // FpuStackSim
duke@435 33 //--------------------------------------------------------
duke@435 34
duke@435 35 // This class maps the FPU registers to their stack locations; it computes
duke@435 36 // the offsets between individual registers and simulates the FPU stack.
duke@435 37
duke@435 38 const int EMPTY = -1;
duke@435 39
duke@435 40 int FpuStackSim::regs_at(int i) const {
duke@435 41 assert(i >= 0 && i < FrameMap::nof_fpu_regs, "out of bounds");
duke@435 42 return _regs[i];
duke@435 43 }
duke@435 44
duke@435 45 void FpuStackSim::set_regs_at(int i, int val) {
duke@435 46 assert(i >= 0 && i < FrameMap::nof_fpu_regs, "out of bounds");
duke@435 47 _regs[i] = val;
duke@435 48 }
duke@435 49
duke@435 50 void FpuStackSim::dec_stack_size() {
duke@435 51 _stack_size--;
duke@435 52 assert(_stack_size >= 0, "FPU stack underflow");
duke@435 53 }
duke@435 54
duke@435 55 void FpuStackSim::inc_stack_size() {
duke@435 56 _stack_size++;
duke@435 57 assert(_stack_size <= FrameMap::nof_fpu_regs, "FPU stack overflow");
duke@435 58 }
duke@435 59
duke@435 60 FpuStackSim::FpuStackSim(Compilation* compilation)
duke@435 61 : _compilation(compilation)
duke@435 62 {
duke@435 63 _stack_size = 0;
duke@435 64 for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
duke@435 65 set_regs_at(i, EMPTY);
duke@435 66 }
duke@435 67 }
duke@435 68
duke@435 69
duke@435 70 void FpuStackSim::pop() {
duke@435 71 if (TraceFPUStack) { tty->print("FPU-pop "); print(); tty->cr(); }
duke@435 72 set_regs_at(tos_index(), EMPTY);
duke@435 73 dec_stack_size();
duke@435 74 }
duke@435 75
duke@435 76 void FpuStackSim::pop(int rnr) {
duke@435 77 if (TraceFPUStack) { tty->print("FPU-pop %d", rnr); print(); tty->cr(); }
duke@435 78 assert(regs_at(tos_index()) == rnr, "rnr is not on TOS");
duke@435 79 set_regs_at(tos_index(), EMPTY);
duke@435 80 dec_stack_size();
duke@435 81 }
duke@435 82
duke@435 83
duke@435 84 void FpuStackSim::push(int rnr) {
duke@435 85 if (TraceFPUStack) { tty->print("FPU-push %d", rnr); print(); tty->cr(); }
duke@435 86 assert(regs_at(stack_size()) == EMPTY, "should be empty");
duke@435 87 set_regs_at(stack_size(), rnr);
duke@435 88 inc_stack_size();
duke@435 89 }
duke@435 90
duke@435 91
duke@435 92 void FpuStackSim::swap(int offset) {
duke@435 93 if (TraceFPUStack) { tty->print("FPU-swap %d", offset); print(); tty->cr(); }
duke@435 94 int t = regs_at(tos_index() - offset);
duke@435 95 set_regs_at(tos_index() - offset, regs_at(tos_index()));
duke@435 96 set_regs_at(tos_index(), t);
duke@435 97 }
duke@435 98
duke@435 99
duke@435 100 int FpuStackSim::offset_from_tos(int rnr) const {
duke@435 101 for (int i = tos_index(); i >= 0; i--) {
duke@435 102 if (regs_at(i) == rnr) {
duke@435 103 return tos_index() - i;
duke@435 104 }
duke@435 105 }
duke@435 106 assert(false, "FpuStackSim: register not found");
duke@435 107 BAILOUT_("FpuStackSim: register not found", 0);
duke@435 108 }
duke@435 109
duke@435 110
duke@435 111 int FpuStackSim::get_slot(int tos_offset) const {
duke@435 112 return regs_at(tos_index() - tos_offset);
duke@435 113 }
duke@435 114
duke@435 115 void FpuStackSim::set_slot(int tos_offset, int rnr) {
duke@435 116 set_regs_at(tos_index() - tos_offset, rnr);
duke@435 117 }
duke@435 118
duke@435 119 void FpuStackSim::rename(int old_rnr, int new_rnr) {
duke@435 120 if (TraceFPUStack) { tty->print("FPU-rename %d %d", old_rnr, new_rnr); print(); tty->cr(); }
duke@435 121 if (old_rnr == new_rnr)
duke@435 122 return;
duke@435 123 bool found = false;
duke@435 124 for (int i = 0; i < stack_size(); i++) {
duke@435 125 assert(regs_at(i) != new_rnr, "should not see old occurrences of new_rnr on the stack");
duke@435 126 if (regs_at(i) == old_rnr) {
duke@435 127 set_regs_at(i, new_rnr);
duke@435 128 found = true;
duke@435 129 }
duke@435 130 }
duke@435 131 assert(found, "should have found at least one instance of old_rnr");
duke@435 132 }
duke@435 133
duke@435 134
duke@435 135 bool FpuStackSim::contains(int rnr) {
duke@435 136 for (int i = 0; i < stack_size(); i++) {
duke@435 137 if (regs_at(i) == rnr) {
duke@435 138 return true;
duke@435 139 }
duke@435 140 }
duke@435 141 return false;
duke@435 142 }
duke@435 143
duke@435 144 bool FpuStackSim::is_empty() {
duke@435 145 #ifdef ASSERT
duke@435 146 if (stack_size() == 0) {
duke@435 147 for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
duke@435 148 assert(regs_at(i) == EMPTY, "must be empty");
duke@435 149 }
duke@435 150 }
duke@435 151 #endif
duke@435 152 return stack_size() == 0;
duke@435 153 }
duke@435 154
duke@435 155
duke@435 156 bool FpuStackSim::slot_is_empty(int tos_offset) {
duke@435 157 return (regs_at(tos_index() - tos_offset) == EMPTY);
duke@435 158 }
duke@435 159
duke@435 160
duke@435 161 void FpuStackSim::clear() {
duke@435 162 if (TraceFPUStack) { tty->print("FPU-clear"); print(); tty->cr(); }
duke@435 163 for (int i = tos_index(); i >= 0; i--) {
duke@435 164 set_regs_at(i, EMPTY);
duke@435 165 }
duke@435 166 _stack_size = 0;
duke@435 167 }
duke@435 168
duke@435 169
duke@435 170 intArray* FpuStackSim::write_state() {
duke@435 171 intArray* res = new intArray(1 + FrameMap::nof_fpu_regs);
duke@435 172 (*res)[0] = stack_size();
duke@435 173 for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
duke@435 174 (*res)[1 + i] = regs_at(i);
duke@435 175 }
duke@435 176 return res;
duke@435 177 }
duke@435 178
duke@435 179
duke@435 180 void FpuStackSim::read_state(intArray* fpu_stack_state) {
duke@435 181 _stack_size = (*fpu_stack_state)[0];
duke@435 182 for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
duke@435 183 set_regs_at(i, (*fpu_stack_state)[1 + i]);
duke@435 184 }
duke@435 185 }
duke@435 186
duke@435 187
duke@435 188 #ifndef PRODUCT
duke@435 189 void FpuStackSim::print() {
duke@435 190 tty->print(" N=%d[", stack_size());\
duke@435 191 for (int i = 0; i < stack_size(); i++) {
duke@435 192 int reg = regs_at(i);
duke@435 193 if (reg != EMPTY) {
duke@435 194 tty->print("%d", reg);
duke@435 195 } else {
duke@435 196 tty->print("_");
duke@435 197 }
duke@435 198 };
duke@435 199 tty->print(" ]");
duke@435 200 }
duke@435 201 #endif

mercurial