src/cpu/x86/vm/x86_64.ad

changeset 7854
e8260b6328fb
parent 6723
0bf37f737702
child 7994
04ff2f6cd0eb
child 8173
faef2a237329
     1.1 --- a/src/cpu/x86/vm/x86_64.ad	Fri Mar 27 10:57:42 2015 +0100
     1.2 +++ b/src/cpu/x86/vm/x86_64.ad	Fri May 29 10:58:45 2015 +0200
     1.3 @@ -166,42 +166,67 @@
     1.4  // 3) reg_class stack_slots( /* one chunk of stack-based "registers" */ )
     1.5  //
     1.6  
     1.7 -// Class for all pointer registers (including RSP)
     1.8 -reg_class any_reg(RAX, RAX_H,
     1.9 -                  RDX, RDX_H,
    1.10 -                  RBP, RBP_H,
    1.11 -                  RDI, RDI_H,
    1.12 -                  RSI, RSI_H,
    1.13 -                  RCX, RCX_H,
    1.14 -                  RBX, RBX_H,
    1.15 -                  RSP, RSP_H,
    1.16 -                  R8,  R8_H,
    1.17 -                  R9,  R9_H,
    1.18 -                  R10, R10_H,
    1.19 -                  R11, R11_H,
    1.20 -                  R12, R12_H,
    1.21 -                  R13, R13_H,
    1.22 -                  R14, R14_H,
    1.23 -                  R15, R15_H);
    1.24 -
    1.25 -// Class for all pointer registers except RSP
    1.26 -reg_class ptr_reg(RAX, RAX_H,
    1.27 -                  RDX, RDX_H,
    1.28 -                  RBP, RBP_H,
    1.29 -                  RDI, RDI_H,
    1.30 -                  RSI, RSI_H,
    1.31 -                  RCX, RCX_H,
    1.32 -                  RBX, RBX_H,
    1.33 -                  R8,  R8_H,
    1.34 -                  R9,  R9_H,
    1.35 -                  R10, R10_H,
    1.36 -                  R11, R11_H,
    1.37 -                  R13, R13_H,
    1.38 -                  R14, R14_H);
    1.39 -
    1.40 -// Class for all pointer registers except RAX and RSP
    1.41 -reg_class ptr_no_rax_reg(RDX, RDX_H,
    1.42 -                         RBP, RBP_H,
    1.43 +// Empty register class.
    1.44 +reg_class no_reg();
    1.45 +
    1.46 +// Class for all pointer registers (including RSP and RBP)
    1.47 +reg_class any_reg_with_rbp(RAX, RAX_H,
    1.48 +                           RDX, RDX_H,
    1.49 +                           RBP, RBP_H,               
    1.50 +                           RDI, RDI_H,
    1.51 +                           RSI, RSI_H,
    1.52 +                           RCX, RCX_H,
    1.53 +                           RBX, RBX_H,
    1.54 +                           RSP, RSP_H,
    1.55 +                           R8,  R8_H,
    1.56 +                           R9,  R9_H,
    1.57 +                           R10, R10_H,
    1.58 +                           R11, R11_H,
    1.59 +                           R12, R12_H,
    1.60 +                           R13, R13_H,
    1.61 +                           R14, R14_H,
    1.62 +                           R15, R15_H);
    1.63 +
    1.64 +// Class for all pointer registers (including RSP, but excluding RBP)
    1.65 +reg_class any_reg_no_rbp(RAX, RAX_H,
    1.66 +                         RDX, RDX_H,                
    1.67 +                         RDI, RDI_H,
    1.68 +                         RSI, RSI_H,
    1.69 +                         RCX, RCX_H,
    1.70 +                         RBX, RBX_H,
    1.71 +                         RSP, RSP_H,
    1.72 +                         R8,  R8_H,
    1.73 +                         R9,  R9_H,
    1.74 +                         R10, R10_H,
    1.75 +                         R11, R11_H,
    1.76 +                         R12, R12_H,
    1.77 +                         R13, R13_H,
    1.78 +                         R14, R14_H,
    1.79 +                         R15, R15_H);
    1.80 +
    1.81 +// Dynamic register class that selects at runtime between register classes
    1.82 +// any_reg_no_rbp and any_reg_with_rbp (depending on the value of the flag PreserveFramePointer). 
    1.83 +// Equivalent to: return PreserveFramePointer ? any_reg_no_rbp : any_reg_with_rbp;
    1.84 +reg_class_dynamic any_reg(any_reg_no_rbp, any_reg_with_rbp, %{ PreserveFramePointer %});
    1.85 +                  
    1.86 +// Class for all pointer registers (excluding RSP)
    1.87 +reg_class ptr_reg_with_rbp(RAX, RAX_H,
    1.88 +                           RDX, RDX_H,
    1.89 +                           RBP, RBP_H,
    1.90 +                           RDI, RDI_H,
    1.91 +                           RSI, RSI_H,
    1.92 +                           RCX, RCX_H,
    1.93 +                           RBX, RBX_H,
    1.94 +                           R8,  R8_H,
    1.95 +                           R9,  R9_H,
    1.96 +                           R10, R10_H,
    1.97 +                           R11, R11_H,
    1.98 +                           R13, R13_H,
    1.99 +                           R14, R14_H);
   1.100 +
   1.101 +// Class for all pointer registers (excluding RSP and RBP)
   1.102 +reg_class ptr_reg_no_rbp(RAX, RAX_H,
   1.103 +                         RDX, RDX_H,                         
   1.104                           RDI, RDI_H,
   1.105                           RSI, RSI_H,
   1.106                           RCX, RCX_H,
   1.107 @@ -213,31 +238,66 @@
   1.108                           R13, R13_H,
   1.109                           R14, R14_H);
   1.110  
   1.111 -reg_class ptr_no_rbp_reg(RDX, RDX_H,
   1.112 -                         RAX, RAX_H,
   1.113 -                         RDI, RDI_H,
   1.114 -                         RSI, RSI_H,
   1.115 -                         RCX, RCX_H,
   1.116 -                         RBX, RBX_H,
   1.117 -                         R8,  R8_H,
   1.118 -                         R9,  R9_H,
   1.119 -                         R10, R10_H,
   1.120 -                         R11, R11_H,
   1.121 -                         R13, R13_H,
   1.122 -                         R14, R14_H);
   1.123 -
   1.124 -// Class for all pointer registers except RAX, RBX and RSP
   1.125 -reg_class ptr_no_rax_rbx_reg(RDX, RDX_H,
   1.126 -                             RBP, RBP_H,
   1.127 -                             RDI, RDI_H,
   1.128 -                             RSI, RSI_H,
   1.129 -                             RCX, RCX_H,
   1.130 -                             R8,  R8_H,
   1.131 -                             R9,  R9_H,
   1.132 -                             R10, R10_H,
   1.133 -                             R11, R11_H,
   1.134 -                             R13, R13_H,
   1.135 -                             R14, R14_H);
   1.136 +// Dynamic register class that selects between ptr_reg_no_rbp and ptr_reg_with_rbp.
   1.137 +reg_class_dynamic ptr_reg(ptr_reg_no_rbp, ptr_reg_with_rbp, %{ PreserveFramePointer %});
   1.138 +
   1.139 +// Class for all pointer registers (excluding RAX and RSP)
   1.140 +reg_class ptr_no_rax_reg_with_rbp(RDX, RDX_H,
   1.141 +                                  RBP, RBP_H,
   1.142 +                                  RDI, RDI_H,
   1.143 +                                  RSI, RSI_H,
   1.144 +                                  RCX, RCX_H,
   1.145 +                                  RBX, RBX_H,
   1.146 +                                  R8,  R8_H,
   1.147 +                                  R9,  R9_H,
   1.148 +                                  R10, R10_H,
   1.149 +                                  R11, R11_H,
   1.150 +                                  R13, R13_H,
   1.151 +                                  R14, R14_H);
   1.152 +
   1.153 +// Class for all pointer registers (excluding RAX, RSP, and RBP)
   1.154 +reg_class ptr_no_rax_reg_no_rbp(RDX, RDX_H,
   1.155 +                                RDI, RDI_H,
   1.156 +                                RSI, RSI_H,
   1.157 +                                RCX, RCX_H,
   1.158 +                                RBX, RBX_H,
   1.159 +                                R8,  R8_H,
   1.160 +                                R9,  R9_H,
   1.161 +                                R10, R10_H,
   1.162 +                                R11, R11_H,
   1.163 +                                R13, R13_H,
   1.164 +                                R14, R14_H);
   1.165 +
   1.166 +// Dynamic register class that selects between ptr_no_rax_reg_no_rbp and ptr_no_rax_reg_with_rbp.
   1.167 +reg_class_dynamic ptr_no_rax_reg(ptr_no_rax_reg_no_rbp, ptr_no_rax_reg_with_rbp, %{ PreserveFramePointer %});
   1.168 +
   1.169 +// Class for all pointer registers (excluding RAX, RBX, and RSP)
   1.170 +reg_class ptr_no_rax_rbx_reg_with_rbp(RDX, RDX_H,
   1.171 +                                      RBP, RBP_H,
   1.172 +                                      RDI, RDI_H,
   1.173 +                                      RSI, RSI_H,
   1.174 +                                      RCX, RCX_H,
   1.175 +                                      R8,  R8_H,
   1.176 +                                      R9,  R9_H,
   1.177 +                                      R10, R10_H,
   1.178 +                                      R11, R11_H,
   1.179 +                                      R13, R13_H,
   1.180 +                                      R14, R14_H);
   1.181 +
   1.182 +// Class for all pointer registers (excluding RAX, RBX, RSP, and RBP)
   1.183 +reg_class ptr_no_rax_rbx_reg_no_rbp(RDX, RDX_H,
   1.184 +                                    RDI, RDI_H,
   1.185 +                                    RSI, RSI_H,
   1.186 +                                    RCX, RCX_H,
   1.187 +                                    R8,  R8_H,
   1.188 +                                    R9,  R9_H,
   1.189 +                                    R10, R10_H,
   1.190 +                                    R11, R11_H,
   1.191 +                                    R13, R13_H,
   1.192 +                                    R14, R14_H);
   1.193 +
   1.194 +// Dynamic register class that selects between ptr_no_rax_rbx_reg_no_rbp and ptr_no_rax_rbx_reg_with_rbp.
   1.195 +reg_class_dynamic ptr_no_rax_rbx_reg(ptr_no_rax_rbx_reg_no_rbp, ptr_no_rax_rbx_reg_with_rbp, %{ PreserveFramePointer %});
   1.196  
   1.197  // Singleton class for RAX pointer register
   1.198  reg_class ptr_rax_reg(RAX, RAX_H);
   1.199 @@ -251,59 +311,29 @@
   1.200  // Singleton class for RDI pointer register
   1.201  reg_class ptr_rdi_reg(RDI, RDI_H);
   1.202  
   1.203 -// Singleton class for RBP pointer register
   1.204 -reg_class ptr_rbp_reg(RBP, RBP_H);
   1.205 -
   1.206  // Singleton class for stack pointer
   1.207  reg_class ptr_rsp_reg(RSP, RSP_H);
   1.208  
   1.209  // Singleton class for TLS pointer
   1.210  reg_class ptr_r15_reg(R15, R15_H);
   1.211  
   1.212 -// Class for all long registers (except RSP)
   1.213 -reg_class long_reg(RAX, RAX_H,
   1.214 -                   RDX, RDX_H,
   1.215 -                   RBP, RBP_H,
   1.216 -                   RDI, RDI_H,
   1.217 -                   RSI, RSI_H,
   1.218 -                   RCX, RCX_H,
   1.219 -                   RBX, RBX_H,
   1.220 -                   R8,  R8_H,
   1.221 -                   R9,  R9_H,
   1.222 -                   R10, R10_H,
   1.223 -                   R11, R11_H,
   1.224 -                   R13, R13_H,
   1.225 -                   R14, R14_H);
   1.226 -
   1.227 -// Class for all long registers except RAX, RDX (and RSP)
   1.228 -reg_class long_no_rax_rdx_reg(RBP, RBP_H,
   1.229 -                              RDI, RDI_H,
   1.230 -                              RSI, RSI_H,
   1.231 -                              RCX, RCX_H,
   1.232 -                              RBX, RBX_H,
   1.233 -                              R8,  R8_H,
   1.234 -                              R9,  R9_H,
   1.235 -                              R10, R10_H,
   1.236 -                              R11, R11_H,
   1.237 -                              R13, R13_H,
   1.238 -                              R14, R14_H);
   1.239 -
   1.240 -// Class for all long registers except RCX (and RSP)
   1.241 -reg_class long_no_rcx_reg(RBP, RBP_H,
   1.242 -                          RDI, RDI_H,
   1.243 -                          RSI, RSI_H,
   1.244 -                          RAX, RAX_H,
   1.245 -                          RDX, RDX_H,
   1.246 -                          RBX, RBX_H,
   1.247 -                          R8,  R8_H,
   1.248 -                          R9,  R9_H,
   1.249 -                          R10, R10_H,
   1.250 -                          R11, R11_H,
   1.251 -                          R13, R13_H,
   1.252 -                          R14, R14_H);
   1.253 -
   1.254 -// Class for all long registers except RAX (and RSP)
   1.255 -reg_class long_no_rax_reg(RBP, RBP_H,
   1.256 +// Class for all long registers (excluding RSP)
   1.257 +reg_class long_reg_with_rbp(RAX, RAX_H,
   1.258 +                            RDX, RDX_H,
   1.259 +                            RBP, RBP_H,
   1.260 +                            RDI, RDI_H,
   1.261 +                            RSI, RSI_H,
   1.262 +                            RCX, RCX_H,
   1.263 +                            RBX, RBX_H,
   1.264 +                            R8,  R8_H,
   1.265 +                            R9,  R9_H,
   1.266 +                            R10, R10_H,
   1.267 +                            R11, R11_H,
   1.268 +                            R13, R13_H,
   1.269 +                            R14, R14_H);
   1.270 +
   1.271 +// Class for all long registers (excluding RSP and RBP)
   1.272 +reg_class long_reg_no_rbp(RAX, RAX_H,
   1.273                            RDX, RDX_H,
   1.274                            RDI, RDI_H,
   1.275                            RSI, RSI_H,
   1.276 @@ -316,6 +346,67 @@
   1.277                            R13, R13_H,
   1.278                            R14, R14_H);
   1.279  
   1.280 +// Dynamic register class that selects between long_reg_no_rbp and long_reg_with_rbp.
   1.281 +reg_class_dynamic long_reg(long_reg_no_rbp, long_reg_with_rbp, %{ PreserveFramePointer %});
   1.282 +
   1.283 +// Class for all long registers (excluding RAX, RDX and RSP)
   1.284 +reg_class long_no_rax_rdx_reg_with_rbp(RBP, RBP_H,
   1.285 +                                       RDI, RDI_H,
   1.286 +                                       RSI, RSI_H,
   1.287 +                                       RCX, RCX_H,
   1.288 +                                       RBX, RBX_H,
   1.289 +                                       R8,  R8_H,
   1.290 +                                       R9,  R9_H,
   1.291 +                                       R10, R10_H,
   1.292 +                                       R11, R11_H,
   1.293 +                                       R13, R13_H,
   1.294 +                                       R14, R14_H);
   1.295 +
   1.296 +// Class for all long registers (excluding RAX, RDX, RSP, and RBP)
   1.297 +reg_class long_no_rax_rdx_reg_no_rbp(RDI, RDI_H,
   1.298 +                                     RSI, RSI_H,
   1.299 +                                     RCX, RCX_H,
   1.300 +                                     RBX, RBX_H,
   1.301 +                                     R8,  R8_H,
   1.302 +                                     R9,  R9_H,
   1.303 +                                     R10, R10_H,
   1.304 +                                     R11, R11_H,
   1.305 +                                     R13, R13_H,
   1.306 +                                     R14, R14_H);
   1.307 +
   1.308 +// Dynamic register class that selects between long_no_rax_rdx_reg_no_rbp and long_no_rax_rdx_reg_with_rbp.
   1.309 +reg_class_dynamic long_no_rax_rdx_reg(long_no_rax_rdx_reg_no_rbp, long_no_rax_rdx_reg_with_rbp, %{ PreserveFramePointer %});
   1.310 +
   1.311 +// Class for all long registers (excluding RCX and RSP)
   1.312 +reg_class long_no_rcx_reg_with_rbp(RBP, RBP_H,
   1.313 +                                   RDI, RDI_H,
   1.314 +                                   RSI, RSI_H,
   1.315 +                                   RAX, RAX_H,
   1.316 +                                   RDX, RDX_H,
   1.317 +                                   RBX, RBX_H,
   1.318 +                                   R8,  R8_H,
   1.319 +                                   R9,  R9_H,
   1.320 +                                   R10, R10_H,
   1.321 +                                   R11, R11_H,
   1.322 +                                   R13, R13_H,
   1.323 +                                   R14, R14_H);
   1.324 +
   1.325 +// Class for all long registers (excluding RCX, RSP, and RBP)
   1.326 +reg_class long_no_rcx_reg_no_rbp(RDI, RDI_H,
   1.327 +                                 RSI, RSI_H,
   1.328 +                                 RAX, RAX_H,
   1.329 +                                 RDX, RDX_H,
   1.330 +                                 RBX, RBX_H,
   1.331 +                                 R8,  R8_H,
   1.332 +                                 R9,  R9_H,
   1.333 +                                 R10, R10_H,
   1.334 +                                 R11, R11_H,
   1.335 +                                 R13, R13_H,
   1.336 +                                 R14, R14_H);
   1.337 +
   1.338 +// Dynamic register class that selects between long_no_rcx_reg_no_rbp and long_no_rcx_reg_with_rbp.
   1.339 +reg_class_dynamic long_no_rcx_reg(long_no_rcx_reg_no_rbp, long_no_rcx_reg_with_rbp, %{ PreserveFramePointer %});
   1.340 +
   1.341  // Singleton class for RAX long register
   1.342  reg_class long_rax_reg(RAX, RAX_H);
   1.343  
   1.344 @@ -325,27 +416,27 @@
   1.345  // Singleton class for RDX long register
   1.346  reg_class long_rdx_reg(RDX, RDX_H);
   1.347  
   1.348 -// Class for all int registers (except RSP)
   1.349 -reg_class int_reg(RAX,
   1.350 -                  RDX,
   1.351 -                  RBP,
   1.352 -                  RDI,
   1.353 -                  RSI,
   1.354 -                  RCX,
   1.355 -                  RBX,
   1.356 -                  R8,
   1.357 -                  R9,
   1.358 -                  R10,
   1.359 -                  R11,
   1.360 -                  R13,
   1.361 -                  R14);
   1.362 -
   1.363 -// Class for all int registers except RCX (and RSP)
   1.364 -reg_class int_no_rcx_reg(RAX,
   1.365 +// Class for all int registers (excluding RSP)
   1.366 +reg_class int_reg_with_rbp(RAX,
   1.367 +                           RDX,
   1.368 +                           RBP,
   1.369 +                           RDI,
   1.370 +                           RSI,
   1.371 +                           RCX,
   1.372 +                           RBX,
   1.373 +                           R8,
   1.374 +                           R9,
   1.375 +                           R10,
   1.376 +                           R11,
   1.377 +                           R13,
   1.378 +                           R14);
   1.379 +
   1.380 +// Class for all int registers (excluding RSP and RBP)
   1.381 +reg_class int_reg_no_rbp(RAX,
   1.382                           RDX,
   1.383 -                         RBP,
   1.384                           RDI,
   1.385                           RSI,
   1.386 +                         RCX,
   1.387                           RBX,
   1.388                           R8,
   1.389                           R9,
   1.390 @@ -354,18 +445,66 @@
   1.391                           R13,
   1.392                           R14);
   1.393  
   1.394 -// Class for all int registers except RAX, RDX (and RSP)
   1.395 -reg_class int_no_rax_rdx_reg(RBP,
   1.396 -                             RDI,
   1.397 -                             RSI,
   1.398 -                             RCX,
   1.399 -                             RBX,
   1.400 -                             R8,
   1.401 -                             R9,
   1.402 -                             R10,
   1.403 -                             R11,
   1.404 -                             R13,
   1.405 -                             R14);
   1.406 +// Dynamic register class that selects between int_reg_no_rbp and int_reg_with_rbp.
   1.407 +reg_class_dynamic int_reg(int_reg_no_rbp, int_reg_with_rbp, %{ PreserveFramePointer %});
   1.408 +
   1.409 +// Class for all int registers (excluding RCX and RSP)
   1.410 +reg_class int_no_rcx_reg_with_rbp(RAX,
   1.411 +                                  RDX,
   1.412 +                                  RBP,
   1.413 +                                  RDI,
   1.414 +                                  RSI,
   1.415 +                                  RBX,
   1.416 +                                  R8,
   1.417 +                                  R9,
   1.418 +                                  R10,
   1.419 +                                  R11,
   1.420 +                                  R13,
   1.421 +                                  R14);
   1.422 +
   1.423 +// Class for all int registers (excluding RCX, RSP, and RBP)
   1.424 +reg_class int_no_rcx_reg_no_rbp(RAX,
   1.425 +                                RDX,
   1.426 +                                RDI,
   1.427 +                                RSI,
   1.428 +                                RBX,
   1.429 +                                R8,
   1.430 +                                R9,
   1.431 +                                R10,
   1.432 +                                R11,
   1.433 +                                R13,
   1.434 +                                R14);
   1.435 +
   1.436 +// Dynamic register class that selects between int_no_rcx_reg_no_rbp and int_no_rcx_reg_with_rbp.
   1.437 +reg_class_dynamic int_no_rcx_reg(int_no_rcx_reg_no_rbp, int_no_rcx_reg_with_rbp, %{ PreserveFramePointer %});
   1.438 +
   1.439 +// Class for all int registers (excluding RAX, RDX, and RSP)
   1.440 +reg_class int_no_rax_rdx_reg_with_rbp(RBP,
   1.441 +                                      RDI,
   1.442 +                                      RSI,
   1.443 +                                      RCX,
   1.444 +                                      RBX,
   1.445 +                                      R8,
   1.446 +                                      R9,
   1.447 +                                      R10,
   1.448 +                                      R11,
   1.449 +                                      R13,
   1.450 +                                      R14);
   1.451 +
   1.452 +// Class for all int registers (excluding RAX, RDX, RSP, and RBP)
   1.453 +reg_class int_no_rax_rdx_reg_no_rbp(RDI,
   1.454 +                                    RSI,
   1.455 +                                    RCX,
   1.456 +                                    RBX,
   1.457 +                                    R8,
   1.458 +                                    R9,
   1.459 +                                    R10,
   1.460 +                                    R11,
   1.461 +                                    R13,
   1.462 +                                    R14);
   1.463 +
   1.464 +// Dynamic register class that selects between int_no_rax_rdx_reg_no_rbp and int_no_rax_rdx_reg_with_rbp.
   1.465 +reg_class_dynamic int_no_rax_rdx_reg(int_no_rax_rdx_reg_no_rbp, int_no_rax_rdx_reg_with_rbp, %{ PreserveFramePointer %});
   1.466  
   1.467  // Singleton class for RAX int register
   1.468  reg_class int_rax_reg(RAX);
   1.469 @@ -396,9 +535,6 @@
   1.470  
   1.471  #define __ _masm.
   1.472  
   1.473 -static int preserve_SP_size() {
   1.474 -  return 3;  // rex.w, op, rm(reg/reg)
   1.475 -}
   1.476  static int clear_avx_size() {
   1.477    return (Compile::current()->max_vector_size() > 16) ? 3 : 0;  // vzeroupper
   1.478  }
   1.479 @@ -409,9 +545,7 @@
   1.480  int MachCallStaticJavaNode::ret_addr_offset()
   1.481  {
   1.482    int offset = 5; // 5 bytes from start of call to where return address points
   1.483 -  offset += clear_avx_size();
   1.484 -  if (_method_handle_invoke)
   1.485 -    offset += preserve_SP_size();
   1.486 +  offset += clear_avx_size();  
   1.487    return offset;
   1.488  }
   1.489  
   1.490 @@ -450,16 +584,6 @@
   1.491  
   1.492  // The address of the call instruction needs to be 4-byte aligned to
   1.493  // ensure that it does not span a cache line so that it can be patched.
   1.494 -int CallStaticJavaHandleNode::compute_padding(int current_offset) const
   1.495 -{
   1.496 -  current_offset += preserve_SP_size();   // skip mov rbp, rsp
   1.497 -  current_offset += clear_avx_size(); // skip vzeroupper
   1.498 -  current_offset += 1; // skip call opcode byte
   1.499 -  return round_to(current_offset, alignment_required()) - current_offset;
   1.500 -}
   1.501 -
   1.502 -// The address of the call instruction needs to be 4-byte aligned to
   1.503 -// ensure that it does not span a cache line so that it can be patched.
   1.504  int CallDynamicJavaDirectNode::compute_padding(int current_offset) const
   1.505  {
   1.506    current_offset += clear_avx_size(); // skip vzeroupper
   1.507 @@ -724,6 +848,10 @@
   1.508      st->print("# stack bang (%d bytes)", bangsize);
   1.509      st->print("\n\t");
   1.510      st->print("pushq   rbp\t# Save rbp");
   1.511 +    if (PreserveFramePointer) {
   1.512 +        st->print("\n\t");
   1.513 +        st->print("movq    rbp, rsp\t# Save the caller's SP into rbp");
   1.514 +    }
   1.515      if (framesize) {
   1.516        st->print("\n\t");
   1.517        st->print("subq    rsp, #%d\t# Create frame",framesize);
   1.518 @@ -732,7 +860,11 @@
   1.519      st->print("subq    rsp, #%d\t# Create frame",framesize);
   1.520      st->print("\n\t");
   1.521      framesize -= wordSize;
   1.522 -    st->print("movq    [rsp + #%d], rbp\t# Save rbp",framesize);
   1.523 +    st->print("movq    [rsp + #%d], rbp\t# Save rbp",framesize);    
   1.524 +    if (PreserveFramePointer) {
   1.525 +      st->print("\n\t");
   1.526 +      st->print("movq    rbp, [rsp + #%d]\t# Save the caller's SP into rbp", (framesize + wordSize));
   1.527 +    }
   1.528    }
   1.529  
   1.530    if (VerifyStackAtCalls) {
   1.531 @@ -1598,8 +1730,9 @@
   1.532    return LONG_RDX_REG_mask();
   1.533  }
   1.534  
   1.535 +// Register for saving SP into on method handle invokes. Not used on x86_64.
   1.536  const RegMask Matcher::method_handle_invoke_SP_save_mask() {
   1.537 -  return PTR_RBP_REG_mask();
   1.538 +    return NO_REG_mask();
   1.539  }
   1.540  
   1.541  %}
   1.542 @@ -3202,7 +3335,7 @@
   1.543  // Pointer Register
   1.544  operand any_RegP()
   1.545  %{
   1.546 -  constraint(ALLOC_IN_RC(any_reg));
   1.547 +  constraint(ALLOC_IN_RC(any_reg));  
   1.548    match(RegP);
   1.549    match(rax_RegP);
   1.550    match(rbx_RegP);
   1.551 @@ -3224,8 +3357,8 @@
   1.552    match(rbx_RegP);
   1.553    match(rdi_RegP);
   1.554    match(rsi_RegP);
   1.555 -  match(rbp_RegP);
   1.556 -  match(r15_RegP);  // See Q&A below about r15_RegP.
   1.557 +  match(rbp_RegP);  // See Q&A below about
   1.558 +  match(r15_RegP);  // r15_RegP and rbp_RegP.
   1.559  
   1.560    format %{ %}
   1.561    interface(REG_INTER);
   1.562 @@ -3241,11 +3374,14 @@
   1.563  
   1.564  // Question: Why is r15_RegP (the read-only TLS register) a match for rRegP?
   1.565  // Answer: Operand match rules govern the DFA as it processes instruction inputs.
   1.566 -// It's fine for an instruction input which expects rRegP to match a r15_RegP.
   1.567 +// It's fine for an instruction input that expects rRegP to match a r15_RegP.
   1.568  // The output of an instruction is controlled by the allocator, which respects
   1.569  // register class masks, not match rules.  Unless an instruction mentions
   1.570  // r15_RegP or any_RegP explicitly as its output, r15 will not be considered
   1.571  // by the allocator as an input.
   1.572 +// The same logic applies to rbp_RegP being a match for rRegP: If PreserveFramePointer==true,
   1.573 +// the RBP is used as a proper frame pointer and is not included in ptr_reg. As a
   1.574 +// result, RBP is not included in the output of the instruction either.
   1.575  
   1.576  operand no_rax_RegP()
   1.577  %{
   1.578 @@ -3259,9 +3395,11 @@
   1.579    interface(REG_INTER);
   1.580  %}
   1.581  
   1.582 +// This operand is not allowed to use RBP even if
   1.583 +// RBP is not used to hold the frame pointer.
   1.584  operand no_rbp_RegP()
   1.585  %{
   1.586 -  constraint(ALLOC_IN_RC(ptr_no_rbp_reg));
   1.587 +  constraint(ALLOC_IN_RC(ptr_reg_no_rbp));
   1.588    match(RegP);
   1.589    match(rbx_RegP);
   1.590    match(rsi_RegP);
   1.591 @@ -3338,16 +3476,6 @@
   1.592    interface(REG_INTER);
   1.593  %}
   1.594  
   1.595 -operand rbp_RegP()
   1.596 -%{
   1.597 -  constraint(ALLOC_IN_RC(ptr_rbp_reg));
   1.598 -  match(RegP);
   1.599 -  match(rRegP);
   1.600 -
   1.601 -  format %{ %}
   1.602 -  interface(REG_INTER);
   1.603 -%}
   1.604 -
   1.605  operand r15_RegP()
   1.606  %{
   1.607    constraint(ALLOC_IN_RC(ptr_r15_reg));
   1.608 @@ -11414,7 +11542,6 @@
   1.609  //       compute_padding() functions will have to be adjusted.
   1.610  instruct CallStaticJavaDirect(method meth) %{
   1.611    match(CallStaticJava);
   1.612 -  predicate(!((CallStaticJavaNode*) n)->is_method_handle_invoke());
   1.613    effect(USE meth);
   1.614  
   1.615    ins_cost(300);
   1.616 @@ -11425,27 +11552,6 @@
   1.617    ins_alignment(4);
   1.618  %}
   1.619  
   1.620 -// Call Java Static Instruction (method handle version)
   1.621 -// Note: If this code changes, the corresponding ret_addr_offset() and
   1.622 -//       compute_padding() functions will have to be adjusted.
   1.623 -instruct CallStaticJavaHandle(method meth, rbp_RegP rbp_mh_SP_save) %{
   1.624 -  match(CallStaticJava);
   1.625 -  predicate(((CallStaticJavaNode*) n)->is_method_handle_invoke());
   1.626 -  effect(USE meth);
   1.627 -  // RBP is saved by all callees (for interpreter stack correction).
   1.628 -  // We use it here for a similar purpose, in {preserve,restore}_SP.
   1.629 -
   1.630 -  ins_cost(300);
   1.631 -  format %{ "call,static/MethodHandle " %}
   1.632 -  opcode(0xE8); /* E8 cd */
   1.633 -  ins_encode(clear_avx, preserve_SP,
   1.634 -             Java_Static_Call(meth),
   1.635 -             restore_SP,
   1.636 -             call_epilog);
   1.637 -  ins_pipe(pipe_slow);
   1.638 -  ins_alignment(4);
   1.639 -%}
   1.640 -
   1.641  // Call Java Dynamic Instruction
   1.642  // Note: If this code changes, the corresponding ret_addr_offset() and
   1.643  //       compute_padding() functions will have to be adjusted.

mercurial