src/hotspot/cpu/x86/nativeInst_x86.hpp
author coleenp
Thu, 10 Jan 2019 15:13:51 -0500
changeset 53244 9807daeb47c4
parent 53149 259c36ef27df
child 58932 8623f75be895
permissions -rw-r--r--
8216167: Update include guards to reflect correct directories Summary: Use script and some manual fixup to fix directores names in include guards. Reviewed-by: lfoltan, eosterlund, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53149
259c36ef27df 8215731: Move forward class definitions out of globalDefinitions.hpp
coleenp
parents: 50102
diff changeset
     2
 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1076
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1076
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1076
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 53149
diff changeset
    25
#ifndef CPU_X86_NATIVEINST_X86_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 53149
diff changeset
    26
#define CPU_X86_NATIVEINST_X86_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "asm/assembler.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "runtime/icache.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "runtime/os.hpp"
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
    31
#include "runtime/safepointMechanism.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// We have interfaces for the following instructions:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// - NativeInstruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// - - NativeCall
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// - - NativeMovConstReg
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// - - NativeMovConstRegPatching
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// - - NativeMovRegMem
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// - - NativeMovRegMemPatching
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// - - NativeJump
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
    41
// - - NativeFarJump
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// - - NativeIllegalOpCode
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// - - NativeGeneralJump
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// - - NativeReturn
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// - - NativeReturnX (return with argument)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// - - NativePushConst
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// - - NativeTstRegMem
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// The base class for different kinds of native instruction abstractions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
// Provides the primitive operations to manipulate code relative to this.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
49364
601146c66cad 8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents: 49027
diff changeset
    52
class NativeInstruction {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  friend class Relocation;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  enum Intel_specific_constants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    nop_instruction_code        = 0x90,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    nop_instruction_size        =    1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  bool is_nop()                        { return ubyte_at(0) == nop_instruction_code; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  inline bool is_call();
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
    63
  inline bool is_call_reg();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  inline bool is_illegal();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  inline bool is_return();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  inline bool is_jump();
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
    67
  inline bool is_jump_reg();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
    68
  inline bool is_far_jump();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  inline bool is_cond_jump();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  inline bool is_safepoint_poll();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  inline bool is_mov_literal64();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  address addr_at(int offset) const    { return address(this) + offset; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  s_char sbyte_at(int offset) const    { return *(s_char*) addr_at(offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  u_char ubyte_at(int offset) const    { return *(u_char*) addr_at(offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  jint int_at(int offset) const         { return *(jint*) addr_at(offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  intptr_t ptr_at(int offset) const    { return *(intptr_t*) addr_at(offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  oop  oop_at (int offset) const       { return *(oop*) addr_at(offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  void set_char_at(int offset, char c)        { *addr_at(offset) = (u_char)c; wrote(offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  void set_int_at(int offset, jint  i)        { *(jint*)addr_at(offset) = i;  wrote(offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  void set_ptr_at (int offset, intptr_t  ptr) { *(intptr_t*) addr_at(offset) = ptr;  wrote(offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  void set_oop_at (int offset, oop  o)        { *(oop*) addr_at(offset) = o;  wrote(offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  // This doesn't really do anything on Intel, but it is the place where
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  // cache invalidation belongs, generically:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  void wrote(int offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  // unit test stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  static void test() {}                 // override for testing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  inline friend NativeInstruction* nativeInstruction_at(address address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
inline NativeInstruction* nativeInstruction_at(address address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  NativeInstruction* inst = (NativeInstruction*)address;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  //inst->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  return inst;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   111
class NativePltCall: public NativeInstruction {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   112
public:
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   113
  enum Intel_specific_constants {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   114
    instruction_code           = 0xE8,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   115
    instruction_size           =    5,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   116
    instruction_offset         =    0,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   117
    displacement_offset        =    1,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   118
    return_address_offset      =    5
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   119
  };
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   120
  address instruction_address() const { return addr_at(instruction_offset); }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   121
  address next_instruction_address() const { return addr_at(return_address_offset); }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   122
  address displacement_address() const { return addr_at(displacement_offset); }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   123
  int displacement() const { return (jint) int_at(displacement_offset); }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   124
  address return_address() const { return addr_at(return_address_offset); }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   125
  address destination() const;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   126
  address plt_entry() const;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   127
  address plt_jump() const;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   128
  address plt_load_got() const;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   129
  address plt_resolve_call() const;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   130
  address plt_c2i_stub() const;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   131
  void set_stub_to_clean();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   132
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   133
  void  reset_to_plt_resolve_call();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   134
  void  set_destination_mt_safe(address dest);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   135
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   136
  void verify() const;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   137
};
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   138
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   139
inline NativePltCall* nativePltCall_at(address address) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   140
  NativePltCall* call = (NativePltCall*) address;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   141
#ifdef ASSERT
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   142
  call->verify();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   143
#endif
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   144
  return call;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   145
}
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   146
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   147
inline NativePltCall* nativePltCall_before(address addr) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   148
  address at = addr - NativePltCall::instruction_size;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   149
  return nativePltCall_at(at);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   150
}
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   151
53149
259c36ef27df 8215731: Move forward class definitions out of globalDefinitions.hpp
coleenp
parents: 50102
diff changeset
   152
class NativeCall;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
inline NativeCall* nativeCall_at(address address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
// The NativeCall is an abstraction for accessing/manipulating native call imm32/rel32off
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
// instructions (used to manipulate inline caches, primitive & dll calls, etc.).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
class NativeCall: public NativeInstruction {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  enum Intel_specific_constants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    instruction_code            = 0xE8,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    instruction_size            =    5,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    instruction_offset          =    0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    displacement_offset         =    1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    return_address_offset       =    5
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  enum { cache_line_size = BytesPerWord };  // conservative estimate!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  address instruction_address() const       { return addr_at(instruction_offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  address next_instruction_address() const  { return addr_at(return_address_offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  int   displacement() const                { return (jint) int_at(displacement_offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  address displacement_address() const      { return addr_at(displacement_offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  address return_address() const            { return addr_at(return_address_offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  address destination() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  void  set_destination(address dest)       {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
#ifdef AMD64
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   177
    intptr_t disp = dest - return_address();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   178
    guarantee(disp == (intptr_t)(jint)disp, "must be 32-bit offset");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    set_int_at(displacement_offset, dest - return_address());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  void  set_destination_mt_safe(address dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  void  verify_alignment() { assert((intptr_t)addr_at(displacement_offset) % BytesPerInt == 0, "must be aligned"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  void  verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  void  print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  inline friend NativeCall* nativeCall_at(address address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  inline friend NativeCall* nativeCall_before(address return_address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  static bool is_call_at(address instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    return ((*instr) & 0xFF) == NativeCall::instruction_code;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  static bool is_call_before(address return_address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    return is_call_at(return_address - NativeCall::return_address_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  static bool is_call_to(address instr, address target) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    return nativeInstruction_at(instr)->is_call() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
      nativeCall_at(instr)->destination() == target;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   205
#if INCLUDE_AOT
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   206
  static bool is_far_call(address instr, address target) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   207
    intptr_t disp = target - (instr + sizeof(int32_t));
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   208
    return !Assembler::is_simm32(disp);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   209
  }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   210
#endif
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   211
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  // MT-safe patching of a call instruction.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  static void insert(address code_pos, address entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  static void replace_mt_safe(address instr_addr, address code_buffer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
inline NativeCall* nativeCall_at(address address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  NativeCall* call = (NativeCall*)(address - NativeCall::instruction_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  call->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  return call;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
inline NativeCall* nativeCall_before(address return_address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  NativeCall* call = (NativeCall*)(return_address - NativeCall::return_address_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  call->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  return call;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   234
class NativeCallReg: public NativeInstruction {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   235
 public:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   236
  enum Intel_specific_constants {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   237
    instruction_code            = 0xFF,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   238
    instruction_offset          =    0,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   239
    return_address_offset_norex =    2,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   240
    return_address_offset_rex   =    3
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   241
  };
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   242
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   243
  int next_instruction_offset() const  {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   244
    if (ubyte_at(0) == NativeCallReg::instruction_code) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   245
      return return_address_offset_norex;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   246
    } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   247
      return return_address_offset_rex;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   248
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   249
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   250
};
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   251
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
// An interface for accessing/manipulating native mov reg, imm32 instructions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
// (used to manipulate inlined 32bit data dll calls, etc.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
class NativeMovConstReg: public NativeInstruction {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  static const bool has_rex = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  static const int rex_size = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  static const bool has_rex = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  static const int rex_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  enum Intel_specific_constants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    instruction_code            = 0xB8,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    instruction_size            =    1 + rex_size + wordSize,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    instruction_offset          =    0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    data_offset                 =    1 + rex_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    next_instruction_offset     =    instruction_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    register_mask               = 0x07
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  address instruction_address() const       { return addr_at(instruction_offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  address next_instruction_address() const  { return addr_at(next_instruction_offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  intptr_t data() const                     { return ptr_at(data_offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  void  set_data(intptr_t x)                { set_ptr_at(data_offset, x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  void  verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  void  print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  // unit test stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  static void test() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  inline friend NativeMovConstReg* nativeMovConstReg_at(address address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  inline friend NativeMovConstReg* nativeMovConstReg_before(address address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
inline NativeMovConstReg* nativeMovConstReg_at(address address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  NativeMovConstReg* test = (NativeMovConstReg*)(address - NativeMovConstReg::instruction_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  test->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  return test;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
inline NativeMovConstReg* nativeMovConstReg_before(address address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  NativeMovConstReg* test = (NativeMovConstReg*)(address - NativeMovConstReg::instruction_size - NativeMovConstReg::instruction_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  test->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  return test;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
class NativeMovConstRegPatching: public NativeMovConstReg {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    friend NativeMovConstRegPatching* nativeMovConstRegPatching_at(address address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    NativeMovConstRegPatching* test = (NativeMovConstRegPatching*)(address - instruction_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
      test->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    return test;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
// An interface for accessing/manipulating native moves of the form:
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   316
//      mov[b/w/l/q] [reg + offset], reg   (instruction_code_reg2mem)
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   317
//      mov[b/w/l/q] reg, [reg+offset]     (instruction_code_mem2reg
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   318
//      mov[s/z]x[w/b/q] [reg + offset], reg
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
//      fld_s  [reg+offset]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
//      fld_d  [reg+offset]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
//      fstp_s [reg + offset]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
//      fstp_d [reg + offset]
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   323
//      mov_literal64  scratch,<pointer> ; mov[b/w/l/q] 0(scratch),reg | mov[b/w/l/q] reg,0(scratch)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
// Warning: These routines must be able to handle any instruction sequences
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
// that are generated as a result of the load/store byte,word,long
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
// macros.  For example: The load_unsigned_byte instruction generates
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
// an xor reg,reg inst prior to generating the movb instruction.  This
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
// class must skip the xor instruction.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
class NativeMovRegMem: public NativeInstruction {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  enum Intel_specific_constants {
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   334
    instruction_prefix_wide_lo          = Assembler::REX,
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   335
    instruction_prefix_wide_hi          = Assembler::REX_WRXB,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    instruction_code_xor                = 0x33,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
    instruction_extended_prefix         = 0x0F,
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   338
    instruction_code_mem2reg_movslq     = 0x63,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    instruction_code_mem2reg_movzxb     = 0xB6,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
    instruction_code_mem2reg_movsxb     = 0xBE,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
    instruction_code_mem2reg_movzxw     = 0xB7,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    instruction_code_mem2reg_movsxw     = 0xBF,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
    instruction_operandsize_prefix      = 0x66,
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   344
    instruction_code_reg2mem            = 0x89,
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   345
    instruction_code_mem2reg            = 0x8b,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    instruction_code_reg2memb           = 0x88,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    instruction_code_mem2regb           = 0x8a,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    instruction_code_float_s            = 0xd9,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    instruction_code_float_d            = 0xdd,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    instruction_code_long_volatile      = 0xdf,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    instruction_code_xmm_ss_prefix      = 0xf3,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    instruction_code_xmm_sd_prefix      = 0xf2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    instruction_code_xmm_code           = 0x0f,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
    instruction_code_xmm_load           = 0x10,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
    instruction_code_xmm_store          = 0x11,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    instruction_code_xmm_lpd            = 0x12,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
50102
454fa295105c 8202976: Add C1 lea patching support for x86
pliden
parents: 49621
diff changeset
   358
    instruction_code_lea                = 0x8d,
454fa295105c 8202976: Add C1 lea patching support for x86
pliden
parents: 49621
diff changeset
   359
11427
bf248009cbbe 7116452: Add support for AVX instructions
kvn
parents: 8871
diff changeset
   360
    instruction_VEX_prefix_2bytes       = Assembler::VEX_2bytes,
bf248009cbbe 7116452: Add support for AVX instructions
kvn
parents: 8871
diff changeset
   361
    instruction_VEX_prefix_3bytes       = Assembler::VEX_3bytes,
44518
46f88691d812 8178033: C1 crashes with -XX:UseAVX = 3: "not a mov [reg+offs], reg instruction"
thartmann
parents: 42650
diff changeset
   362
    instruction_EVEX_prefix_4bytes      = Assembler::EVEX_4bytes,
11427
bf248009cbbe 7116452: Add support for AVX instructions
kvn
parents: 8871
diff changeset
   363
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    instruction_size                    = 4,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    instruction_offset                  = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
    data_offset                         = 2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    next_instruction_offset             = 4
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   370
  // helper
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   371
  int instruction_start() const;
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   372
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   373
  address instruction_address() const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   375
  address next_instruction_address() const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   377
  int   offset() const;
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   378
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   379
  void  set_offset(int x);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  void  add_offset_in_bytes(int add_offset)     { set_offset ( ( offset() + add_offset ) ); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  void verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  void print ();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  // unit test stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  static void test() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  inline friend NativeMovRegMem* nativeMovRegMem_at (address address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
inline NativeMovRegMem* nativeMovRegMem_at (address address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  NativeMovRegMem* test = (NativeMovRegMem*)(address - NativeMovRegMem::instruction_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  test->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  return test;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
// An interface for accessing/manipulating native leal instruction of form:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
//        leal reg, [reg + offset]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
class NativeLoadAddress: public NativeMovRegMem {
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   406
#ifdef AMD64
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   407
  static const bool has_rex = true;
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   408
  static const int rex_size = 1;
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   409
#else
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   410
  static const bool has_rex = false;
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   411
  static const int rex_size = 0;
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   412
#endif // AMD64
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  enum Intel_specific_constants {
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   415
    instruction_prefix_wide             = Assembler::REX_W,
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   416
    instruction_prefix_wide_extended    = Assembler::REX_WB,
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   417
    lea_instruction_code                = 0x8D,
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   418
    mov64_instruction_code              = 0xB8
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  void verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  void print ();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  // unit test stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  static void test() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  friend NativeLoadAddress* nativeLoadAddress_at (address address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
    NativeLoadAddress* test = (NativeLoadAddress*)(address - instruction_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
    #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
      test->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
    #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
    return test;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   437
// destination is rbx or rax
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   438
// mov rbx, [rip + offset]
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   439
class NativeLoadGot: public NativeInstruction {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   440
#ifdef AMD64
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   441
  static const bool has_rex = true;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   442
  static const int rex_size = 1;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   443
#else
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   444
  static const bool has_rex = false;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   445
  static const int rex_size = 0;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   446
#endif
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   447
public:
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   448
  enum Intel_specific_constants {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   449
    rex_prefix = 0x48,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   450
    instruction_code = 0x8b,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   451
    modrm_rbx_code = 0x1d,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   452
    modrm_rax_code = 0x05,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   453
    instruction_length = 6 + rex_size,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   454
    offset_offset = 2 + rex_size
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   455
  };
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   456
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   457
  address instruction_address() const { return addr_at(0); }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   458
  address rip_offset_address() const { return addr_at(offset_offset); }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   459
  int rip_offset() const { return int_at(offset_offset); }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   460
  address return_address() const { return addr_at(instruction_length); }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   461
  address got_address() const { return return_address() + rip_offset(); }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   462
  address next_instruction_address() const { return return_address(); }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   463
  intptr_t data() const;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   464
  void set_data(intptr_t data) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   465
    intptr_t *addr = (intptr_t *) got_address();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   466
    *addr = data;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   467
  }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   468
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   469
  void verify() const;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   470
private:
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   471
  void report_and_fail() const;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   472
};
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   473
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   474
inline NativeLoadGot* nativeLoadGot_at(address addr) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   475
  NativeLoadGot* load = (NativeLoadGot*) addr;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   476
#ifdef ASSERT
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   477
  load->verify();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   478
#endif
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   479
  return load;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   480
}
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   481
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
// jump rel32off
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
class NativeJump: public NativeInstruction {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  enum Intel_specific_constants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    instruction_code            = 0xe9,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
    instruction_size            =    5,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
    instruction_offset          =    0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    data_offset                 =    1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
    next_instruction_offset     =    5
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  address instruction_address() const       { return addr_at(instruction_offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  address next_instruction_address() const  { return addr_at(next_instruction_offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  address jump_destination() const          {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
     address dest = (int_at(data_offset)+next_instruction_address());
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   498
     // 32bit used to encode unresolved jmp as jmp -1
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   499
     // 64bit can't produce this so it used jump to self.
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   500
     // Now 32bit and 64bit use jump to self as the unresolved address
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   501
     // which the inline cache code (and relocs) know about
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   502
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
     // return -1 if jump to self
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
    dest = (dest == (address) this) ? (address) -1 : dest;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
    return dest;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
  void  set_jump_destination(address dest)  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
    intptr_t val = dest - next_instruction_address();
1076
a4f1c0615381 6744422: incorrect handling of -1 in set_jump_destination
never
parents: 1066
diff changeset
   510
    if (dest == (address) -1) {
a4f1c0615381 6744422: incorrect handling of -1 in set_jump_destination
never
parents: 1066
diff changeset
   511
      val = -5; // jump to self
a4f1c0615381 6744422: incorrect handling of -1 in set_jump_destination
never
parents: 1066
diff changeset
   512
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
#ifdef AMD64
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   514
    assert((labs(val)  & 0xFFFFFFFF00000000) == 0 || dest == (address)-1, "must be 32bit offset or -1");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
    set_int_at(data_offset, (jint)val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
  inline friend NativeJump* nativeJump_at(address address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  void verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
  // Unit testing stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
  static void test() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
  // Insertion of native jump instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  static void insert(address code_pos, address entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
  // MT-safe insertion of native jump at verified method entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
  static void check_verified_entry_alignment(address entry, address verified_entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  static void patch_verified_entry(address entry, address verified_entry, address dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
inline NativeJump* nativeJump_at(address address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
  NativeJump* jump = (NativeJump*)(address - NativeJump::instruction_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
  jump->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
  return jump;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   542
// far jump reg
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   543
class NativeFarJump: public NativeInstruction {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   544
 public:
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   545
  address jump_destination() const;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   546
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   547
  // Creation
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   548
  inline friend NativeFarJump* nativeFarJump_at(address address);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   549
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   550
  void verify();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   551
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   552
  // Unit testing stuff
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   553
  static void test() {}
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   554
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   555
};
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   556
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   557
inline NativeFarJump* nativeFarJump_at(address address) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   558
  NativeFarJump* jump = (NativeFarJump*)(address);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   559
#ifdef ASSERT
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   560
  jump->verify();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   561
#endif
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   562
  return jump;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   563
}
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   564
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
// Handles all kinds of jump on Intel. Long/far, conditional/unconditional
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
class NativeGeneralJump: public NativeInstruction {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  enum Intel_specific_constants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
    // Constants does not apply, since the lengths and offsets depends on the actual jump
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
    // used
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
    // Instruction codes:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
    //   Unconditional jumps: 0xE9    (rel32off), 0xEB (rel8off)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
    //   Conditional jumps:   0x0F8x  (rel32off), 0x7x (rel8off)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
    unconditional_long_jump  = 0xe9,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
    unconditional_short_jump = 0xeb,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
    instruction_size = 5
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  address instruction_address() const       { return addr_at(0); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  address jump_destination()    const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
  inline friend NativeGeneralJump* nativeGeneralJump_at(address address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
  // Insertion of native general jump instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
  static void insert_unconditional(address code_pos, address entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
  static void replace_mt_safe(address instr_addr, address code_buffer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  void verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
inline NativeGeneralJump* nativeGeneralJump_at(address address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
  NativeGeneralJump* jump = (NativeGeneralJump*)(address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  debug_only(jump->verify();)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  return jump;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   598
class NativeGotJump: public NativeInstruction {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   599
public:
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   600
  enum Intel_specific_constants {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   601
    instruction_code = 0xff,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   602
    instruction_offset = 0,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   603
    instruction_size = 6,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   604
    rip_offset = 2
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   605
  };
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   606
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   607
  void verify() const;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   608
  address instruction_address() const { return addr_at(instruction_offset); }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   609
  address destination() const;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   610
  address return_address() const { return addr_at(instruction_size); }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   611
  int got_offset() const { return (jint) int_at(rip_offset); }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   612
  address got_address() const { return return_address() + got_offset(); }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   613
  address next_instruction_address() const { return addr_at(instruction_size); }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   614
  bool is_GotJump() const { return ubyte_at(0) == instruction_code; }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   615
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   616
  void set_jump_destination(address dest)  {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   617
    address *got_entry = (address *) got_address();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   618
    *got_entry = dest;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   619
  }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   620
};
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   621
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   622
inline NativeGotJump* nativeGotJump_at(address addr) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   623
  NativeGotJump* jump = (NativeGotJump*)(addr);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   624
  debug_only(jump->verify());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   625
  return jump;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   626
}
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   627
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
class NativePopReg : public NativeInstruction {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
  enum Intel_specific_constants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
    instruction_code            = 0x58,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
    instruction_size            =    1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
    instruction_offset          =    0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
    data_offset                 =    1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
    next_instruction_offset     =    1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
  // Insert a pop instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
  static void insert(address code_pos, Register reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
class NativeIllegalInstruction: public NativeInstruction {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
  enum Intel_specific_constants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
    instruction_code            = 0x0B0F,    // Real byte order is: 0x0F, 0x0B
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
    instruction_size            =    2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
    instruction_offset          =    0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
    next_instruction_offset     =    2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
  // Insert illegal opcode as specific address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
  static void insert(address code_pos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
// return instruction that does not pop values of the stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
class NativeReturn: public NativeInstruction {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
  enum Intel_specific_constants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
    instruction_code            = 0xC3,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
    instruction_size            =    1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
    instruction_offset          =    0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
    next_instruction_offset     =    1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
// return instruction that does pop values of the stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
class NativeReturnX: public NativeInstruction {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
  enum Intel_specific_constants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
    instruction_code            = 0xC2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
    instruction_size            =    2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
    instruction_offset          =    0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
    next_instruction_offset     =    2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
// Simple test vs memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
class NativeTstRegMem: public NativeInstruction {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
  enum Intel_specific_constants {
8871
5c3b26c4119e 6964776: c2 should ensure the polling page is reachable on 64 bit
iveresov
parents: 7397
diff changeset
   682
    instruction_rex_prefix_mask = 0xF0,
5c3b26c4119e 6964776: c2 should ensure the polling page is reachable on 64 bit
iveresov
parents: 7397
diff changeset
   683
    instruction_rex_prefix      = Assembler::REX,
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   684
    instruction_rex_b_prefix    = Assembler::REX_B,
8871
5c3b26c4119e 6964776: c2 should ensure the polling page is reachable on 64 bit
iveresov
parents: 7397
diff changeset
   685
    instruction_code_memXregl   = 0x85,
5c3b26c4119e 6964776: c2 should ensure the polling page is reachable on 64 bit
iveresov
parents: 7397
diff changeset
   686
    modrm_mask                  = 0x38, // select reg from the ModRM byte
5c3b26c4119e 6964776: c2 should ensure the polling page is reachable on 64 bit
iveresov
parents: 7397
diff changeset
   687
    modrm_reg                   = 0x00  // rax
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
inline bool NativeInstruction::is_illegal()      { return (short)int_at(0) == (short)NativeIllegalInstruction::instruction_code; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
inline bool NativeInstruction::is_call()         { return ubyte_at(0) == NativeCall::instruction_code; }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   693
inline bool NativeInstruction::is_call_reg()     { return ubyte_at(0) == NativeCallReg::instruction_code ||
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   694
                                                          (ubyte_at(1) == NativeCallReg::instruction_code &&
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   695
                                                           (ubyte_at(0) == Assembler::REX || ubyte_at(0) == Assembler::REX_B)); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
inline bool NativeInstruction::is_return()       { return ubyte_at(0) == NativeReturn::instruction_code ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
                                                          ubyte_at(0) == NativeReturnX::instruction_code; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
inline bool NativeInstruction::is_jump()         { return ubyte_at(0) == NativeJump::instruction_code ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
                                                          ubyte_at(0) == 0xEB; /* short jump */ }
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   700
inline bool NativeInstruction::is_jump_reg()     {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   701
  int pos = 0;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   702
  if (ubyte_at(0) == Assembler::REX_B) pos = 1;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   703
  return ubyte_at(pos) == 0xFF && (ubyte_at(pos + 1) & 0xF0) == 0xE0;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   704
}
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   705
inline bool NativeInstruction::is_far_jump()     { return is_mov_literal64(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
inline bool NativeInstruction::is_cond_jump()    { return (int_at(0) & 0xF0FF) == 0x800F /* long jump */ ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
                                                          (ubyte_at(0) & 0xF0) == 0x70;  /* short jump */ }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
inline bool NativeInstruction::is_safepoint_poll() {
49027
8dc742d9bbab 8195112: x86 (32 bit): implementation for Thread-local handshakes
mdoerr
parents: 48200
diff changeset
   709
  if (SafepointMechanism::uses_thread_local_poll()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
#ifdef AMD64
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   711
    const bool has_rex_prefix = ubyte_at(0) == NativeTstRegMem::instruction_rex_b_prefix;
48200
ed5680f2656a 8193009: compiler/c2/Test7029152.java crashes with SIGILL in java.lang.StringLatin1.indexOf with -XX:+UseJVMCICompiler
dlong
parents: 47881
diff changeset
   712
    const int test_offset = has_rex_prefix ? 1 : 0;
49027
8dc742d9bbab 8195112: x86 (32 bit): implementation for Thread-local handshakes
mdoerr
parents: 48200
diff changeset
   713
#else
8dc742d9bbab 8195112: x86 (32 bit): implementation for Thread-local handshakes
mdoerr
parents: 48200
diff changeset
   714
    const int test_offset = 0;
8dc742d9bbab 8195112: x86 (32 bit): implementation for Thread-local handshakes
mdoerr
parents: 48200
diff changeset
   715
#endif
48200
ed5680f2656a 8193009: compiler/c2/Test7029152.java crashes with SIGILL in java.lang.StringLatin1.indexOf with -XX:+UseJVMCICompiler
dlong
parents: 47881
diff changeset
   716
    const bool is_test_opcode = ubyte_at(test_offset) == NativeTstRegMem::instruction_code_memXregl;
ed5680f2656a 8193009: compiler/c2/Test7029152.java crashes with SIGILL in java.lang.StringLatin1.indexOf with -XX:+UseJVMCICompiler
dlong
parents: 47881
diff changeset
   717
    const bool is_rax_target = (ubyte_at(test_offset + 1) & NativeTstRegMem::modrm_mask) == NativeTstRegMem::modrm_reg;
ed5680f2656a 8193009: compiler/c2/Test7029152.java crashes with SIGILL in java.lang.StringLatin1.indexOf with -XX:+UseJVMCICompiler
dlong
parents: 47881
diff changeset
   718
    return is_test_opcode && is_rax_target;
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47216
diff changeset
   719
  }
49027
8dc742d9bbab 8195112: x86 (32 bit): implementation for Thread-local handshakes
mdoerr
parents: 48200
diff changeset
   720
#ifdef AMD64
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   721
  // Try decoding a near safepoint first:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   722
  if (ubyte_at(0) == NativeTstRegMem::instruction_code_memXregl &&
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   723
      ubyte_at(1) == 0x05) { // 00 rax 101
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   724
    address fault = addr_at(6) + int_at(2);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   725
    NOT_JVMCI(assert(!Assembler::is_polling_page_far(), "unexpected poll encoding");)
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   726
    return os::is_poll_address(fault);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   727
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   728
  // Now try decoding a far safepoint:
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   729
  // two cases, depending on the choice of the base register in the address.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   730
  if (((ubyte_at(0) & NativeTstRegMem::instruction_rex_prefix_mask) == NativeTstRegMem::instruction_rex_prefix &&
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   731
       ubyte_at(1) == NativeTstRegMem::instruction_code_memXregl &&
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   732
       (ubyte_at(2) & NativeTstRegMem::modrm_mask) == NativeTstRegMem::modrm_reg) ||
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 44518
diff changeset
   733
      (ubyte_at(0) == NativeTstRegMem::instruction_code_memXregl &&
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 44518
diff changeset
   734
       (ubyte_at(1) & NativeTstRegMem::modrm_mask) == NativeTstRegMem::modrm_reg)) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   735
    NOT_JVMCI(assert(Assembler::is_polling_page_far(), "unexpected poll encoding");)
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   736
    return true;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   737
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 28947
diff changeset
   738
  return false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
#else
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   740
  return ( ubyte_at(0) == NativeMovRegMem::instruction_code_mem2reg ||
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
           ubyte_at(0) == NativeTstRegMem::instruction_code_memXregl ) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
           (ubyte_at(1)&0xC7) == 0x05 && /* Mod R/M == disp32 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
           (os::is_poll_address((address)int_at(2)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
inline bool NativeInstruction::is_mov_literal64() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
  return ((ubyte_at(0) == Assembler::REX_W || ubyte_at(0) == Assembler::REX_WB) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
          (ubyte_at(1) & (0xff ^ NativeMovConstReg::register_mask)) == 0xB8);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
}
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   755
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 53149
diff changeset
   756
#endif // CPU_X86_NATIVEINST_X86_HPP