comparison src/share/vm/code/vmreg.hpp @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children c5cbd367e4d1
comparison
equal deleted inserted replaced
-1:000000000000 0:a61af66fc99e
1 /*
2 * Copyright 1998-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
24
25 //------------------------------VMReg------------------------------------------
26 // The VM uses 'unwarped' stack slots; the compiler uses 'warped' stack slots.
27 // Register numbers below VMRegImpl::stack0 are the same for both. Register
28 // numbers above stack0 are either warped (in the compiler) or unwarped
29 // (in the VM). Unwarped numbers represent stack indices, offsets from
30 // the current stack pointer. Warped numbers are required during compilation
31 // when we do not yet know how big the frame will be.
32
33 class VMRegImpl;
34 typedef VMRegImpl* VMReg;
35
36 class VMRegImpl {
37 // friend class OopMap;
38 friend class VMStructs;
39 friend class OptoReg;
40 // friend class Location;
41 private:
42 enum {
43 BAD = -1
44 };
45
46
47
48 static VMReg stack0;
49 // Names for registers
50 static const char *regName[];
51 static const int register_count;
52
53
54 public:
55
56 static VMReg as_VMReg(int val, bool bad_ok = false) { assert(val > BAD || bad_ok, "invalid"); return (VMReg) (intptr_t) val; }
57
58 const char* name() {
59 if (is_reg()) {
60 return regName[value()];
61 } else if (!is_valid()) {
62 return "BAD";
63 } else {
64 // shouldn't really be called with stack
65 return "STACKED REG";
66 }
67 }
68 static VMReg Bad() { return (VMReg) (intptr_t) BAD; }
69 bool is_valid() { return ((intptr_t) this) != BAD; }
70 bool is_stack() { return (intptr_t) this >= (intptr_t) stack0; }
71 bool is_reg() { return is_valid() && !is_stack(); }
72
73 // A concrete register is a value that returns true for is_reg() and is
74 // also a register you could use in the assembler. On machines with
75 // 64bit registers only one half of the VMReg (and OptoReg) is considered
76 // concrete.
77 bool is_concrete();
78
79 // VMRegs are 4 bytes wide on all platforms
80 static const int stack_slot_size;
81 static const int slots_per_word;
82
83
84 // This really ought to check that the register is "real" in the sense that
85 // we don't try and get the VMReg number of a physical register that doesn't
86 // have an expressible part. That would be pd specific code
87 VMReg next() {
88 assert((is_reg() && value() < stack0->value() - 1) || is_stack(), "must be");
89 return (VMReg)(intptr_t)(value() + 1);
90 }
91 VMReg prev() {
92 assert((is_stack() && value() > stack0->value()) || (is_reg() && value() != 0), "must be");
93 return (VMReg)(intptr_t)(value() - 1);
94 }
95
96
97 intptr_t value() const {return (intptr_t) this; }
98
99 void print();
100
101 // bias a stack slot.
102 // Typically used to adjust a virtual frame slots by amounts that are offset by
103 // amounts that are part of the native abi. The VMReg must be a stack slot
104 // and the result must be also.
105
106 VMReg bias(int offset) {
107 assert(is_stack(), "must be");
108 // VMReg res = VMRegImpl::as_VMReg(value() + offset);
109 VMReg res = stack2reg(reg2stack() + offset);
110 assert(res->is_stack(), "must be");
111 return res;
112 }
113
114 // Convert register numbers to stack slots and vice versa
115 static VMReg stack2reg( int idx ) {
116 return (VMReg) (intptr_t) (stack0->value() + idx);
117 }
118
119 uintptr_t reg2stack() {
120 assert( is_stack(), "Not a stack-based register" );
121 return value() - stack0->value();
122 }
123
124 static void set_regName();
125
126 #include "incls/_vmreg_pd.hpp.incl"
127
128 };
129
130 //---------------------------VMRegPair-------------------------------------------
131 // Pairs of 32-bit registers for arguments.
132 // SharedRuntime::java_calling_convention will overwrite the structs with
133 // the calling convention's registers. VMRegImpl::Bad is returned for any
134 // unused 32-bit register. This happens for the unused high half of Int
135 // arguments, or for 32-bit pointers or for longs in the 32-bit sparc build
136 // (which are passed to natives in low 32-bits of e.g. O0/O1 and the high
137 // 32-bits of O0/O1 are set to VMRegImpl::Bad). Longs in one register & doubles
138 // always return a high and a low register, as do 64-bit pointers.
139 //
140 class VMRegPair {
141 private:
142 VMReg _second;
143 VMReg _first;
144 public:
145 void set_bad ( ) { _second=VMRegImpl::Bad(); _first=VMRegImpl::Bad(); }
146 void set1 ( VMReg v ) { _second=VMRegImpl::Bad(); _first=v; }
147 void set2 ( VMReg v ) { _second=v->next(); _first=v; }
148 void set_pair( VMReg second, VMReg first ) { _second= second; _first= first; }
149 void set_ptr ( VMReg ptr ) {
150 #ifdef _LP64
151 _second = ptr->next();
152 #else
153 _second = VMRegImpl::Bad();
154 #endif
155 _first = ptr;
156 }
157 // Return true if single register, even if the pair is really just adjacent stack slots
158 bool is_single_reg() {
159 return (_first->is_valid()) && (_first->value() + 1 == _second->value());
160 }
161
162 // Return true if single stack based "register" where the slot alignment matches input alignment
163 bool is_adjacent_on_stack(int alignment) {
164 return (_first->is_stack() && (_first->value() + 1 == _second->value()) && ((_first->value() & (alignment-1)) == 0));
165 }
166
167 // Return true if single stack based "register" where the slot alignment matches input alignment
168 bool is_adjacent_aligned_on_stack(int alignment) {
169 return (_first->is_stack() && (_first->value() + 1 == _second->value()) && ((_first->value() & (alignment-1)) == 0));
170 }
171
172 // Return true if single register but adjacent stack slots do not count
173 bool is_single_phys_reg() {
174 return (_first->is_reg() && (_first->value() + 1 == _second->value()));
175 }
176
177 VMReg second() const { return _second; }
178 VMReg first() const { return _first; }
179 VMRegPair(VMReg s, VMReg f) { _second = s; _first = f; }
180 VMRegPair(VMReg f) { _second = VMRegImpl::Bad(); _first = f; }
181 VMRegPair() { _second = VMRegImpl::Bad(); _first = VMRegImpl::Bad(); }
182 };