src/cpu/x86/vm/c1_FpuStackSim_x86.cpp

Mon, 04 Jan 2010 18:38:08 +0100

author
twisti
date
Mon, 04 Jan 2010 18:38:08 +0100
changeset 1570
e66fd840cb6b
parent 435
a61af66fc99e
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
Summary: During the work for 6829187 we have fixed a number of basic bugs which are logically grouped with 6815692 and 6858164 but which must be reviewed and pushed separately.
Reviewed-by: kvn, never

duke@435 1 /*
duke@435 2 * Copyright 2005 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 # include "incls/_precompiled.incl"
duke@435 26 # include "incls/_c1_FpuStackSim_x86.cpp.incl"
duke@435 27
duke@435 28 //--------------------------------------------------------
duke@435 29 // FpuStackSim
duke@435 30 //--------------------------------------------------------
duke@435 31
duke@435 32 // This class maps the FPU registers to their stack locations; it computes
duke@435 33 // the offsets between individual registers and simulates the FPU stack.
duke@435 34
duke@435 35 const int EMPTY = -1;
duke@435 36
duke@435 37 int FpuStackSim::regs_at(int i) const {
duke@435 38 assert(i >= 0 && i < FrameMap::nof_fpu_regs, "out of bounds");
duke@435 39 return _regs[i];
duke@435 40 }
duke@435 41
duke@435 42 void FpuStackSim::set_regs_at(int i, int val) {
duke@435 43 assert(i >= 0 && i < FrameMap::nof_fpu_regs, "out of bounds");
duke@435 44 _regs[i] = val;
duke@435 45 }
duke@435 46
duke@435 47 void FpuStackSim::dec_stack_size() {
duke@435 48 _stack_size--;
duke@435 49 assert(_stack_size >= 0, "FPU stack underflow");
duke@435 50 }
duke@435 51
duke@435 52 void FpuStackSim::inc_stack_size() {
duke@435 53 _stack_size++;
duke@435 54 assert(_stack_size <= FrameMap::nof_fpu_regs, "FPU stack overflow");
duke@435 55 }
duke@435 56
duke@435 57 FpuStackSim::FpuStackSim(Compilation* compilation)
duke@435 58 : _compilation(compilation)
duke@435 59 {
duke@435 60 _stack_size = 0;
duke@435 61 for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
duke@435 62 set_regs_at(i, EMPTY);
duke@435 63 }
duke@435 64 }
duke@435 65
duke@435 66
duke@435 67 void FpuStackSim::pop() {
duke@435 68 if (TraceFPUStack) { tty->print("FPU-pop "); print(); tty->cr(); }
duke@435 69 set_regs_at(tos_index(), EMPTY);
duke@435 70 dec_stack_size();
duke@435 71 }
duke@435 72
duke@435 73 void FpuStackSim::pop(int rnr) {
duke@435 74 if (TraceFPUStack) { tty->print("FPU-pop %d", rnr); print(); tty->cr(); }
duke@435 75 assert(regs_at(tos_index()) == rnr, "rnr is not on TOS");
duke@435 76 set_regs_at(tos_index(), EMPTY);
duke@435 77 dec_stack_size();
duke@435 78 }
duke@435 79
duke@435 80
duke@435 81 void FpuStackSim::push(int rnr) {
duke@435 82 if (TraceFPUStack) { tty->print("FPU-push %d", rnr); print(); tty->cr(); }
duke@435 83 assert(regs_at(stack_size()) == EMPTY, "should be empty");
duke@435 84 set_regs_at(stack_size(), rnr);
duke@435 85 inc_stack_size();
duke@435 86 }
duke@435 87
duke@435 88
duke@435 89 void FpuStackSim::swap(int offset) {
duke@435 90 if (TraceFPUStack) { tty->print("FPU-swap %d", offset); print(); tty->cr(); }
duke@435 91 int t = regs_at(tos_index() - offset);
duke@435 92 set_regs_at(tos_index() - offset, regs_at(tos_index()));
duke@435 93 set_regs_at(tos_index(), t);
duke@435 94 }
duke@435 95
duke@435 96
duke@435 97 int FpuStackSim::offset_from_tos(int rnr) const {
duke@435 98 for (int i = tos_index(); i >= 0; i--) {
duke@435 99 if (regs_at(i) == rnr) {
duke@435 100 return tos_index() - i;
duke@435 101 }
duke@435 102 }
duke@435 103 assert(false, "FpuStackSim: register not found");
duke@435 104 BAILOUT_("FpuStackSim: register not found", 0);
duke@435 105 }
duke@435 106
duke@435 107
duke@435 108 int FpuStackSim::get_slot(int tos_offset) const {
duke@435 109 return regs_at(tos_index() - tos_offset);
duke@435 110 }
duke@435 111
duke@435 112 void FpuStackSim::set_slot(int tos_offset, int rnr) {
duke@435 113 set_regs_at(tos_index() - tos_offset, rnr);
duke@435 114 }
duke@435 115
duke@435 116 void FpuStackSim::rename(int old_rnr, int new_rnr) {
duke@435 117 if (TraceFPUStack) { tty->print("FPU-rename %d %d", old_rnr, new_rnr); print(); tty->cr(); }
duke@435 118 if (old_rnr == new_rnr)
duke@435 119 return;
duke@435 120 bool found = false;
duke@435 121 for (int i = 0; i < stack_size(); i++) {
duke@435 122 assert(regs_at(i) != new_rnr, "should not see old occurrences of new_rnr on the stack");
duke@435 123 if (regs_at(i) == old_rnr) {
duke@435 124 set_regs_at(i, new_rnr);
duke@435 125 found = true;
duke@435 126 }
duke@435 127 }
duke@435 128 assert(found, "should have found at least one instance of old_rnr");
duke@435 129 }
duke@435 130
duke@435 131
duke@435 132 bool FpuStackSim::contains(int rnr) {
duke@435 133 for (int i = 0; i < stack_size(); i++) {
duke@435 134 if (regs_at(i) == rnr) {
duke@435 135 return true;
duke@435 136 }
duke@435 137 }
duke@435 138 return false;
duke@435 139 }
duke@435 140
duke@435 141 bool FpuStackSim::is_empty() {
duke@435 142 #ifdef ASSERT
duke@435 143 if (stack_size() == 0) {
duke@435 144 for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
duke@435 145 assert(regs_at(i) == EMPTY, "must be empty");
duke@435 146 }
duke@435 147 }
duke@435 148 #endif
duke@435 149 return stack_size() == 0;
duke@435 150 }
duke@435 151
duke@435 152
duke@435 153 bool FpuStackSim::slot_is_empty(int tos_offset) {
duke@435 154 return (regs_at(tos_index() - tos_offset) == EMPTY);
duke@435 155 }
duke@435 156
duke@435 157
duke@435 158 void FpuStackSim::clear() {
duke@435 159 if (TraceFPUStack) { tty->print("FPU-clear"); print(); tty->cr(); }
duke@435 160 for (int i = tos_index(); i >= 0; i--) {
duke@435 161 set_regs_at(i, EMPTY);
duke@435 162 }
duke@435 163 _stack_size = 0;
duke@435 164 }
duke@435 165
duke@435 166
duke@435 167 intArray* FpuStackSim::write_state() {
duke@435 168 intArray* res = new intArray(1 + FrameMap::nof_fpu_regs);
duke@435 169 (*res)[0] = stack_size();
duke@435 170 for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
duke@435 171 (*res)[1 + i] = regs_at(i);
duke@435 172 }
duke@435 173 return res;
duke@435 174 }
duke@435 175
duke@435 176
duke@435 177 void FpuStackSim::read_state(intArray* fpu_stack_state) {
duke@435 178 _stack_size = (*fpu_stack_state)[0];
duke@435 179 for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
duke@435 180 set_regs_at(i, (*fpu_stack_state)[1 + i]);
duke@435 181 }
duke@435 182 }
duke@435 183
duke@435 184
duke@435 185 #ifndef PRODUCT
duke@435 186 void FpuStackSim::print() {
duke@435 187 tty->print(" N=%d[", stack_size());\
duke@435 188 for (int i = 0; i < stack_size(); i++) {
duke@435 189 int reg = regs_at(i);
duke@435 190 if (reg != EMPTY) {
duke@435 191 tty->print("%d", reg);
duke@435 192 } else {
duke@435 193 tty->print("_");
duke@435 194 }
duke@435 195 };
duke@435 196 tty->print(" ]");
duke@435 197 }
duke@435 198 #endif

mercurial