1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/asm/register.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,278 @@ 1.4 +/* 1.5 + * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_ASM_REGISTER_HPP 1.29 +#define SHARE_VM_ASM_REGISTER_HPP 1.30 + 1.31 +#include "utilities/top.hpp" 1.32 + 1.33 +// Use AbstractRegister as shortcut 1.34 +class AbstractRegisterImpl; 1.35 +typedef AbstractRegisterImpl* AbstractRegister; 1.36 + 1.37 + 1.38 +// The super class for platform specific registers. Instead of using value objects, 1.39 +// registers are implemented as pointers. Subclassing is used so all registers can 1.40 +// use the debugging suport below. No virtual functions are used for efficiency. 1.41 +// They are canonicalized; i.e., registers are equal if their pointers are equal, 1.42 +// and vice versa. A concrete implementation may just map the register onto 'this'. 1.43 + 1.44 +class AbstractRegisterImpl { 1.45 + protected: 1.46 + int value() const { return (int)(intx)this; } 1.47 +}; 1.48 + 1.49 + 1.50 +// 1.51 +// Macros for use in defining Register instances. We'd like to be 1.52 +// able to simply define const instances of the RegisterImpl* for each 1.53 +// of the registers needed on a system in a header file. However many 1.54 +// compilers don't handle this very well and end up producing a 1.55 +// private definition in every file which includes the header file. 1.56 +// Along with the static constructors necessary for initialization it 1.57 +// can consume a significant amount of space in the result library. 1.58 +// 1.59 +// The following macros allow us to declare the instance in a .hpp and 1.60 +// produce an enumeration value which has the same number. Then in a 1.61 +// .cpp the the register instance can be defined using the enumeration 1.62 +// value. This avoids the use of static constructors and multiple 1.63 +// definitions per .cpp. In addition #defines for the register can be 1.64 +// produced so that the constant registers can be inlined. These 1.65 +// macros should not be used inside other macros, because you may get 1.66 +// multiple evaluations of the macros which can give bad results. 1.67 +// 1.68 +// Here are some example uses and expansions. Note that the macro 1.69 +// invocation is terminated with a ;. 1.70 +// 1.71 +// CONSTANT_REGISTER_DECLARATION(Register, G0, 0); 1.72 +// 1.73 +// extern const Register G0 ; 1.74 +// enum { G0_RegisterEnumValue = 0 } ; 1.75 +// 1.76 +// REGISTER_DECLARATION(Register, Gmethod, G5); 1.77 +// 1.78 +// extern const Register Gmethod ; 1.79 +// enum { Gmethod_RegisterEnumValue = G5_RegisterEnumValue } ; 1.80 +// 1.81 +// REGISTER_DEFINITION(Register, G0); 1.82 +// 1.83 +// const Register G0 = ( ( Register ) G0_RegisterEnumValue ) ; 1.84 +// 1.85 + 1.86 +#define AS_REGISTER(type,name) ((type)name##_##type##EnumValue) 1.87 + 1.88 +#define CONSTANT_REGISTER_DECLARATION(type, name, value) \ 1.89 +extern const type name; \ 1.90 +enum { name##_##type##EnumValue = (value) } 1.91 + 1.92 +#define REGISTER_DECLARATION(type, name, value) \ 1.93 +extern const type name; \ 1.94 +enum { name##_##type##EnumValue = value##_##type##EnumValue } 1.95 + 1.96 +#define REGISTER_DEFINITION(type, name) \ 1.97 +const type name = ((type)name##_##type##EnumValue) 1.98 + 1.99 +#ifdef TARGET_ARCH_x86 1.100 +# include "register_x86.hpp" 1.101 +#endif 1.102 +#ifdef TARGET_ARCH_sparc 1.103 +# include "register_sparc.hpp" 1.104 +#endif 1.105 +#ifdef TARGET_ARCH_zero 1.106 +# include "register_zero.hpp" 1.107 +#endif 1.108 +#ifdef TARGET_ARCH_arm 1.109 +# include "register_arm.hpp" 1.110 +#endif 1.111 +#ifdef TARGET_ARCH_ppc 1.112 +# include "register_ppc.hpp" 1.113 +#endif 1.114 + 1.115 + 1.116 +// Debugging support 1.117 + 1.118 +inline void assert_different_registers( 1.119 + AbstractRegister a, 1.120 + AbstractRegister b 1.121 +) { 1.122 + assert( 1.123 + a != b, 1.124 + err_msg_res("registers must be different: a=" INTPTR_FORMAT ", b=" INTPTR_FORMAT "", 1.125 + p2i(a), p2i(b)) 1.126 + ); 1.127 +} 1.128 + 1.129 + 1.130 +inline void assert_different_registers( 1.131 + AbstractRegister a, 1.132 + AbstractRegister b, 1.133 + AbstractRegister c 1.134 +) { 1.135 + assert( 1.136 + a != b && a != c 1.137 + && b != c, 1.138 + err_msg_res("registers must be different: a=" INTPTR_FORMAT ", b=" INTPTR_FORMAT 1.139 + ", c=" INTPTR_FORMAT "", 1.140 + p2i(a), p2i(b), p2i(c)) 1.141 + ); 1.142 +} 1.143 + 1.144 + 1.145 +inline void assert_different_registers( 1.146 + AbstractRegister a, 1.147 + AbstractRegister b, 1.148 + AbstractRegister c, 1.149 + AbstractRegister d 1.150 +) { 1.151 + assert( 1.152 + a != b && a != c && a != d 1.153 + && b != c && b != d 1.154 + && c != d, 1.155 + err_msg_res("registers must be different: a=" INTPTR_FORMAT ", b=" INTPTR_FORMAT 1.156 + ", c=" INTPTR_FORMAT ", d=" INTPTR_FORMAT "", 1.157 + p2i(a), p2i(b), p2i(c), p2i(d)) 1.158 + ); 1.159 +} 1.160 + 1.161 + 1.162 +inline void assert_different_registers( 1.163 + AbstractRegister a, 1.164 + AbstractRegister b, 1.165 + AbstractRegister c, 1.166 + AbstractRegister d, 1.167 + AbstractRegister e 1.168 +) { 1.169 + assert( 1.170 + a != b && a != c && a != d && a != e 1.171 + && b != c && b != d && b != e 1.172 + && c != d && c != e 1.173 + && d != e, 1.174 + err_msg_res("registers must be different: a=" INTPTR_FORMAT ", b=" INTPTR_FORMAT 1.175 + ", c=" INTPTR_FORMAT ", d=" INTPTR_FORMAT ", e=" INTPTR_FORMAT "", 1.176 + p2i(a), p2i(b), p2i(c), p2i(d), p2i(e)) 1.177 + ); 1.178 +} 1.179 + 1.180 + 1.181 +inline void assert_different_registers( 1.182 + AbstractRegister a, 1.183 + AbstractRegister b, 1.184 + AbstractRegister c, 1.185 + AbstractRegister d, 1.186 + AbstractRegister e, 1.187 + AbstractRegister f 1.188 +) { 1.189 + assert( 1.190 + a != b && a != c && a != d && a != e && a != f 1.191 + && b != c && b != d && b != e && b != f 1.192 + && c != d && c != e && c != f 1.193 + && d != e && d != f 1.194 + && e != f, 1.195 + err_msg_res("registers must be different: a=" INTPTR_FORMAT ", b=" INTPTR_FORMAT 1.196 + ", c=" INTPTR_FORMAT ", d=" INTPTR_FORMAT ", e=" INTPTR_FORMAT 1.197 + ", f=" INTPTR_FORMAT "", 1.198 + p2i(a), p2i(b), p2i(c), p2i(d), p2i(e), p2i(f)) 1.199 + ); 1.200 +} 1.201 + 1.202 + 1.203 +inline void assert_different_registers( 1.204 + AbstractRegister a, 1.205 + AbstractRegister b, 1.206 + AbstractRegister c, 1.207 + AbstractRegister d, 1.208 + AbstractRegister e, 1.209 + AbstractRegister f, 1.210 + AbstractRegister g 1.211 +) { 1.212 + assert( 1.213 + a != b && a != c && a != d && a != e && a != f && a != g 1.214 + && b != c && b != d && b != e && b != f && b != g 1.215 + && c != d && c != e && c != f && c != g 1.216 + && d != e && d != f && d != g 1.217 + && e != f && e != g 1.218 + && f != g, 1.219 + err_msg_res("registers must be different: a=" INTPTR_FORMAT ", b=" INTPTR_FORMAT 1.220 + ", c=" INTPTR_FORMAT ", d=" INTPTR_FORMAT ", e=" INTPTR_FORMAT 1.221 + ", f=" INTPTR_FORMAT ", g=" INTPTR_FORMAT "", 1.222 + p2i(a), p2i(b), p2i(c), p2i(d), p2i(e), p2i(f), p2i(g)) 1.223 + ); 1.224 +} 1.225 + 1.226 + 1.227 +inline void assert_different_registers( 1.228 + AbstractRegister a, 1.229 + AbstractRegister b, 1.230 + AbstractRegister c, 1.231 + AbstractRegister d, 1.232 + AbstractRegister e, 1.233 + AbstractRegister f, 1.234 + AbstractRegister g, 1.235 + AbstractRegister h 1.236 +) { 1.237 + assert( 1.238 + a != b && a != c && a != d && a != e && a != f && a != g && a != h 1.239 + && b != c && b != d && b != e && b != f && b != g && b != h 1.240 + && c != d && c != e && c != f && c != g && c != h 1.241 + && d != e && d != f && d != g && d != h 1.242 + && e != f && e != g && e != h 1.243 + && f != g && f != h 1.244 + && g != h, 1.245 + err_msg_res("registers must be different: a=" INTPTR_FORMAT ", b=" INTPTR_FORMAT 1.246 + ", c=" INTPTR_FORMAT ", d=" INTPTR_FORMAT ", e=" INTPTR_FORMAT 1.247 + ", f=" INTPTR_FORMAT ", g=" INTPTR_FORMAT ", h=" INTPTR_FORMAT "", 1.248 + p2i(a), p2i(b), p2i(c), p2i(d), p2i(e), p2i(f), p2i(g), p2i(h)) 1.249 + ); 1.250 +} 1.251 + 1.252 + 1.253 +inline void assert_different_registers( 1.254 + AbstractRegister a, 1.255 + AbstractRegister b, 1.256 + AbstractRegister c, 1.257 + AbstractRegister d, 1.258 + AbstractRegister e, 1.259 + AbstractRegister f, 1.260 + AbstractRegister g, 1.261 + AbstractRegister h, 1.262 + AbstractRegister i 1.263 +) { 1.264 + assert( 1.265 + a != b && a != c && a != d && a != e && a != f && a != g && a != h && a != i 1.266 + && b != c && b != d && b != e && b != f && b != g && b != h && b != i 1.267 + && c != d && c != e && c != f && c != g && c != h && c != i 1.268 + && d != e && d != f && d != g && d != h && d != i 1.269 + && e != f && e != g && e != h && e != i 1.270 + && f != g && f != h && f != i 1.271 + && g != h && g != i 1.272 + && h != i, 1.273 + err_msg_res("registers must be different: a=" INTPTR_FORMAT ", b=" INTPTR_FORMAT 1.274 + ", c=" INTPTR_FORMAT ", d=" INTPTR_FORMAT ", e=" INTPTR_FORMAT 1.275 + ", f=" INTPTR_FORMAT ", g=" INTPTR_FORMAT ", h=" INTPTR_FORMAT 1.276 + ", i=" INTPTR_FORMAT "", 1.277 + p2i(a), p2i(b), p2i(c), p2i(d), p2i(e), p2i(f), p2i(g), p2i(h), p2i(i)) 1.278 + ); 1.279 +} 1.280 + 1.281 +#endif // SHARE_VM_ASM_REGISTER_HPP