annotate src/cpu/x86/vm/c1_FpuStackSim_x86.cpp @ 1552:c18cbe5936b8

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