annotate src/cpu/x86/vm/nativeInst_x86.hpp @ 71:3d62cb85208d

6662967: Optimize I2D conversion on new x86 Summary: Use CVTDQ2PS and CVTDQ2PD for integer values conversions to float and double values on new AMD cpu. Reviewed-by: sgoldman, never
author kvn
date Wed, 19 Mar 2008 15:33:25 -0700
parents a61af66fc99e
children 018d5b58dd4f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 // We have interfaces for the following instructions:
a61af66fc99e Initial load
duke
parents:
diff changeset
26 // - NativeInstruction
a61af66fc99e Initial load
duke
parents:
diff changeset
27 // - - NativeCall
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // - - NativeMovConstReg
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // - - NativeMovConstRegPatching
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // - - NativeMovRegMem
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // - - NativeMovRegMemPatching
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // - - NativeJump
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // - - NativeIllegalOpCode
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // - - NativeGeneralJump
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // - - NativeReturn
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // - - NativeReturnX (return with argument)
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // - - NativePushConst
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // - - NativeTstRegMem
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // The base class for different kinds of native instruction abstractions.
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // Provides the primitive operations to manipulate code relative to this.
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 class NativeInstruction VALUE_OBJ_CLASS_SPEC {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 friend class Relocation;
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
47 enum Intel_specific_constants {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 nop_instruction_code = 0x90,
a61af66fc99e Initial load
duke
parents:
diff changeset
49 nop_instruction_size = 1
a61af66fc99e Initial load
duke
parents:
diff changeset
50 };
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 bool is_nop() { return ubyte_at(0) == nop_instruction_code; }
a61af66fc99e Initial load
duke
parents:
diff changeset
53 inline bool is_call();
a61af66fc99e Initial load
duke
parents:
diff changeset
54 inline bool is_illegal();
a61af66fc99e Initial load
duke
parents:
diff changeset
55 inline bool is_return();
a61af66fc99e Initial load
duke
parents:
diff changeset
56 inline bool is_jump();
a61af66fc99e Initial load
duke
parents:
diff changeset
57 inline bool is_cond_jump();
a61af66fc99e Initial load
duke
parents:
diff changeset
58 inline bool is_safepoint_poll();
a61af66fc99e Initial load
duke
parents:
diff changeset
59 inline bool is_mov_literal64();
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
62 address addr_at(int offset) const { return address(this) + offset; }
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 s_char sbyte_at(int offset) const { return *(s_char*) addr_at(offset); }
a61af66fc99e Initial load
duke
parents:
diff changeset
65 u_char ubyte_at(int offset) const { return *(u_char*) addr_at(offset); }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 jint int_at(int offset) const { return *(jint*) addr_at(offset); }
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 intptr_t ptr_at(int offset) const { return *(intptr_t*) addr_at(offset); }
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 oop oop_at (int offset) const { return *(oop*) addr_at(offset); }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 void set_char_at(int offset, char c) { *addr_at(offset) = (u_char)c; wrote(offset); }
a61af66fc99e Initial load
duke
parents:
diff changeset
75 void set_int_at(int offset, jint i) { *(jint*)addr_at(offset) = i; wrote(offset); }
a61af66fc99e Initial load
duke
parents:
diff changeset
76 void set_ptr_at (int offset, intptr_t ptr) { *(intptr_t*) addr_at(offset) = ptr; wrote(offset); }
a61af66fc99e Initial load
duke
parents:
diff changeset
77 void set_oop_at (int offset, oop o) { *(oop*) addr_at(offset) = o; wrote(offset); }
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // This doesn't really do anything on Intel, but it is the place where
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // cache invalidation belongs, generically:
a61af66fc99e Initial load
duke
parents:
diff changeset
81 void wrote(int offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // unit test stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
86 static void test() {} // override for testing
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 inline friend NativeInstruction* nativeInstruction_at(address address);
a61af66fc99e Initial load
duke
parents:
diff changeset
89 };
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 inline NativeInstruction* nativeInstruction_at(address address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 NativeInstruction* inst = (NativeInstruction*)address;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
94 //inst->verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
95 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
96 return inst;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 inline NativeCall* nativeCall_at(address address);
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // The NativeCall is an abstraction for accessing/manipulating native call imm32/rel32off
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // instructions (used to manipulate inline caches, primitive & dll calls, etc.).
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 class NativeCall: public NativeInstruction {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
105 enum Intel_specific_constants {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 instruction_code = 0xE8,
a61af66fc99e Initial load
duke
parents:
diff changeset
107 instruction_size = 5,
a61af66fc99e Initial load
duke
parents:
diff changeset
108 instruction_offset = 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
109 displacement_offset = 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
110 return_address_offset = 5
a61af66fc99e Initial load
duke
parents:
diff changeset
111 };
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 enum { cache_line_size = BytesPerWord }; // conservative estimate!
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 address instruction_address() const { return addr_at(instruction_offset); }
a61af66fc99e Initial load
duke
parents:
diff changeset
116 address next_instruction_address() const { return addr_at(return_address_offset); }
a61af66fc99e Initial load
duke
parents:
diff changeset
117 int displacement() const { return (jint) int_at(displacement_offset); }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 address displacement_address() const { return addr_at(displacement_offset); }
a61af66fc99e Initial load
duke
parents:
diff changeset
119 address return_address() const { return addr_at(return_address_offset); }
a61af66fc99e Initial load
duke
parents:
diff changeset
120 address destination() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
121 void set_destination(address dest) {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 #ifdef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
123 assert((labs((intptr_t) dest - (intptr_t) return_address()) &
a61af66fc99e Initial load
duke
parents:
diff changeset
124 0xFFFFFFFF00000000) == 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
125 "must be 32bit offset");
a61af66fc99e Initial load
duke
parents:
diff changeset
126 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
127 set_int_at(displacement_offset, dest - return_address());
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129 void set_destination_mt_safe(address dest);
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 void verify_alignment() { assert((intptr_t)addr_at(displacement_offset) % BytesPerInt == 0, "must be aligned"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
132 void verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
133 void print();
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // Creation
a61af66fc99e Initial load
duke
parents:
diff changeset
136 inline friend NativeCall* nativeCall_at(address address);
a61af66fc99e Initial load
duke
parents:
diff changeset
137 inline friend NativeCall* nativeCall_before(address return_address);
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 static bool is_call_at(address instr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 return ((*instr) & 0xFF) == NativeCall::instruction_code;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 static bool is_call_before(address return_address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 return is_call_at(return_address - NativeCall::return_address_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 static bool is_call_to(address instr, address target) {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 return nativeInstruction_at(instr)->is_call() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
149 nativeCall_at(instr)->destination() == target;
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // MT-safe patching of a call instruction.
a61af66fc99e Initial load
duke
parents:
diff changeset
153 static void insert(address code_pos, address entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 static void replace_mt_safe(address instr_addr, address code_buffer);
a61af66fc99e Initial load
duke
parents:
diff changeset
156 };
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 inline NativeCall* nativeCall_at(address address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
159 NativeCall* call = (NativeCall*)(address - NativeCall::instruction_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
160 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
161 call->verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
162 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
163 return call;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 inline NativeCall* nativeCall_before(address return_address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 NativeCall* call = (NativeCall*)(return_address - NativeCall::return_address_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
168 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
169 call->verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
170 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
171 return call;
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 // An interface for accessing/manipulating native mov reg, imm32 instructions.
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // (used to manipulate inlined 32bit data dll calls, etc.)
a61af66fc99e Initial load
duke
parents:
diff changeset
176 class NativeMovConstReg: public NativeInstruction {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 #ifdef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
178 static const bool has_rex = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
179 static const int rex_size = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
181 static const bool has_rex = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
182 static const int rex_size = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
183 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
184 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
185 enum Intel_specific_constants {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 instruction_code = 0xB8,
a61af66fc99e Initial load
duke
parents:
diff changeset
187 instruction_size = 1 + rex_size + wordSize,
a61af66fc99e Initial load
duke
parents:
diff changeset
188 instruction_offset = 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
189 data_offset = 1 + rex_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
190 next_instruction_offset = instruction_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
191 register_mask = 0x07
a61af66fc99e Initial load
duke
parents:
diff changeset
192 };
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 address instruction_address() const { return addr_at(instruction_offset); }
a61af66fc99e Initial load
duke
parents:
diff changeset
195 address next_instruction_address() const { return addr_at(next_instruction_offset); }
a61af66fc99e Initial load
duke
parents:
diff changeset
196 intptr_t data() const { return ptr_at(data_offset); }
a61af66fc99e Initial load
duke
parents:
diff changeset
197 void set_data(intptr_t x) { set_ptr_at(data_offset, x); }
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 void verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
200 void print();
a61af66fc99e Initial load
duke
parents:
diff changeset
201
a61af66fc99e Initial load
duke
parents:
diff changeset
202 // unit test stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
203 static void test() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
204
a61af66fc99e Initial load
duke
parents:
diff changeset
205 // Creation
a61af66fc99e Initial load
duke
parents:
diff changeset
206 inline friend NativeMovConstReg* nativeMovConstReg_at(address address);
a61af66fc99e Initial load
duke
parents:
diff changeset
207 inline friend NativeMovConstReg* nativeMovConstReg_before(address address);
a61af66fc99e Initial load
duke
parents:
diff changeset
208 };
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 inline NativeMovConstReg* nativeMovConstReg_at(address address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 NativeMovConstReg* test = (NativeMovConstReg*)(address - NativeMovConstReg::instruction_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
212 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
213 test->verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
214 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
215 return test;
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218 inline NativeMovConstReg* nativeMovConstReg_before(address address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 NativeMovConstReg* test = (NativeMovConstReg*)(address - NativeMovConstReg::instruction_size - NativeMovConstReg::instruction_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
220 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
221 test->verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
222 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
223 return test;
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }
a61af66fc99e Initial load
duke
parents:
diff changeset
225
a61af66fc99e Initial load
duke
parents:
diff changeset
226 class NativeMovConstRegPatching: public NativeMovConstReg {
a61af66fc99e Initial load
duke
parents:
diff changeset
227 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
228 friend NativeMovConstRegPatching* nativeMovConstRegPatching_at(address address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 NativeMovConstRegPatching* test = (NativeMovConstRegPatching*)(address - instruction_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
230 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
231 test->verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
232 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
233 return test;
a61af66fc99e Initial load
duke
parents:
diff changeset
234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
235 };
a61af66fc99e Initial load
duke
parents:
diff changeset
236
a61af66fc99e Initial load
duke
parents:
diff changeset
237 #ifndef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
238
a61af66fc99e Initial load
duke
parents:
diff changeset
239 // An interface for accessing/manipulating native moves of the form:
a61af66fc99e Initial load
duke
parents:
diff changeset
240 // mov[b/w/l] [reg + offset], reg (instruction_code_reg2mem)
a61af66fc99e Initial load
duke
parents:
diff changeset
241 // mov[b/w/l] reg, [reg+offset] (instruction_code_mem2reg
a61af66fc99e Initial load
duke
parents:
diff changeset
242 // mov[s/z]x[w/b] [reg + offset], reg
a61af66fc99e Initial load
duke
parents:
diff changeset
243 // fld_s [reg+offset]
a61af66fc99e Initial load
duke
parents:
diff changeset
244 // fld_d [reg+offset]
a61af66fc99e Initial load
duke
parents:
diff changeset
245 // fstp_s [reg + offset]
a61af66fc99e Initial load
duke
parents:
diff changeset
246 // fstp_d [reg + offset]
a61af66fc99e Initial load
duke
parents:
diff changeset
247 //
a61af66fc99e Initial load
duke
parents:
diff changeset
248 // Warning: These routines must be able to handle any instruction sequences
a61af66fc99e Initial load
duke
parents:
diff changeset
249 // that are generated as a result of the load/store byte,word,long
a61af66fc99e Initial load
duke
parents:
diff changeset
250 // macros. For example: The load_unsigned_byte instruction generates
a61af66fc99e Initial load
duke
parents:
diff changeset
251 // an xor reg,reg inst prior to generating the movb instruction. This
a61af66fc99e Initial load
duke
parents:
diff changeset
252 // class must skip the xor instruction.
a61af66fc99e Initial load
duke
parents:
diff changeset
253
a61af66fc99e Initial load
duke
parents:
diff changeset
254 class NativeMovRegMem: public NativeInstruction {
a61af66fc99e Initial load
duke
parents:
diff changeset
255 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
256 enum Intel_specific_constants {
a61af66fc99e Initial load
duke
parents:
diff changeset
257 instruction_code_xor = 0x33,
a61af66fc99e Initial load
duke
parents:
diff changeset
258 instruction_extended_prefix = 0x0F,
a61af66fc99e Initial load
duke
parents:
diff changeset
259 instruction_code_mem2reg_movzxb = 0xB6,
a61af66fc99e Initial load
duke
parents:
diff changeset
260 instruction_code_mem2reg_movsxb = 0xBE,
a61af66fc99e Initial load
duke
parents:
diff changeset
261 instruction_code_mem2reg_movzxw = 0xB7,
a61af66fc99e Initial load
duke
parents:
diff changeset
262 instruction_code_mem2reg_movsxw = 0xBF,
a61af66fc99e Initial load
duke
parents:
diff changeset
263 instruction_operandsize_prefix = 0x66,
a61af66fc99e Initial load
duke
parents:
diff changeset
264 instruction_code_reg2meml = 0x89,
a61af66fc99e Initial load
duke
parents:
diff changeset
265 instruction_code_mem2regl = 0x8b,
a61af66fc99e Initial load
duke
parents:
diff changeset
266 instruction_code_reg2memb = 0x88,
a61af66fc99e Initial load
duke
parents:
diff changeset
267 instruction_code_mem2regb = 0x8a,
a61af66fc99e Initial load
duke
parents:
diff changeset
268 instruction_code_float_s = 0xd9,
a61af66fc99e Initial load
duke
parents:
diff changeset
269 instruction_code_float_d = 0xdd,
a61af66fc99e Initial load
duke
parents:
diff changeset
270 instruction_code_long_volatile = 0xdf,
a61af66fc99e Initial load
duke
parents:
diff changeset
271 instruction_code_xmm_ss_prefix = 0xf3,
a61af66fc99e Initial load
duke
parents:
diff changeset
272 instruction_code_xmm_sd_prefix = 0xf2,
a61af66fc99e Initial load
duke
parents:
diff changeset
273 instruction_code_xmm_code = 0x0f,
a61af66fc99e Initial load
duke
parents:
diff changeset
274 instruction_code_xmm_load = 0x10,
a61af66fc99e Initial load
duke
parents:
diff changeset
275 instruction_code_xmm_store = 0x11,
a61af66fc99e Initial load
duke
parents:
diff changeset
276 instruction_code_xmm_lpd = 0x12,
a61af66fc99e Initial load
duke
parents:
diff changeset
277
a61af66fc99e Initial load
duke
parents:
diff changeset
278 instruction_size = 4,
a61af66fc99e Initial load
duke
parents:
diff changeset
279 instruction_offset = 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
280 data_offset = 2,
a61af66fc99e Initial load
duke
parents:
diff changeset
281 next_instruction_offset = 4
a61af66fc99e Initial load
duke
parents:
diff changeset
282 };
a61af66fc99e Initial load
duke
parents:
diff changeset
283
a61af66fc99e Initial load
duke
parents:
diff changeset
284 address instruction_address() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
285 if (*addr_at(instruction_offset) == instruction_operandsize_prefix &&
a61af66fc99e Initial load
duke
parents:
diff changeset
286 *addr_at(instruction_offset+1) != instruction_code_xmm_code) {
a61af66fc99e Initial load
duke
parents:
diff changeset
287 return addr_at(instruction_offset+1); // Not SSE instructions
a61af66fc99e Initial load
duke
parents:
diff changeset
288 }
a61af66fc99e Initial load
duke
parents:
diff changeset
289 else if (*addr_at(instruction_offset) == instruction_extended_prefix) {
a61af66fc99e Initial load
duke
parents:
diff changeset
290 return addr_at(instruction_offset+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
291 }
a61af66fc99e Initial load
duke
parents:
diff changeset
292 else if (*addr_at(instruction_offset) == instruction_code_xor) {
a61af66fc99e Initial load
duke
parents:
diff changeset
293 return addr_at(instruction_offset+2);
a61af66fc99e Initial load
duke
parents:
diff changeset
294 }
a61af66fc99e Initial load
duke
parents:
diff changeset
295 else return addr_at(instruction_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
296 }
a61af66fc99e Initial load
duke
parents:
diff changeset
297
a61af66fc99e Initial load
duke
parents:
diff changeset
298 address next_instruction_address() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
299 switch (*addr_at(instruction_offset)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
300 case instruction_operandsize_prefix:
a61af66fc99e Initial load
duke
parents:
diff changeset
301 if (*addr_at(instruction_offset+1) == instruction_code_xmm_code)
a61af66fc99e Initial load
duke
parents:
diff changeset
302 return instruction_address() + instruction_size; // SSE instructions
a61af66fc99e Initial load
duke
parents:
diff changeset
303 case instruction_extended_prefix:
a61af66fc99e Initial load
duke
parents:
diff changeset
304 return instruction_address() + instruction_size + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
305 case instruction_code_reg2meml:
a61af66fc99e Initial load
duke
parents:
diff changeset
306 case instruction_code_mem2regl:
a61af66fc99e Initial load
duke
parents:
diff changeset
307 case instruction_code_reg2memb:
a61af66fc99e Initial load
duke
parents:
diff changeset
308 case instruction_code_mem2regb:
a61af66fc99e Initial load
duke
parents:
diff changeset
309 case instruction_code_xor:
a61af66fc99e Initial load
duke
parents:
diff changeset
310 return instruction_address() + instruction_size + 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
311 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
312 return instruction_address() + instruction_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
313 }
a61af66fc99e Initial load
duke
parents:
diff changeset
314 }
a61af66fc99e Initial load
duke
parents:
diff changeset
315 int offset() const{
a61af66fc99e Initial load
duke
parents:
diff changeset
316 if (*addr_at(instruction_offset) == instruction_operandsize_prefix &&
a61af66fc99e Initial load
duke
parents:
diff changeset
317 *addr_at(instruction_offset+1) != instruction_code_xmm_code) {
a61af66fc99e Initial load
duke
parents:
diff changeset
318 return int_at(data_offset+1); // Not SSE instructions
a61af66fc99e Initial load
duke
parents:
diff changeset
319 }
a61af66fc99e Initial load
duke
parents:
diff changeset
320 else if (*addr_at(instruction_offset) == instruction_extended_prefix) {
a61af66fc99e Initial load
duke
parents:
diff changeset
321 return int_at(data_offset+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
322 }
a61af66fc99e Initial load
duke
parents:
diff changeset
323 else if (*addr_at(instruction_offset) == instruction_code_xor ||
a61af66fc99e Initial load
duke
parents:
diff changeset
324 *addr_at(instruction_offset) == instruction_code_xmm_ss_prefix ||
a61af66fc99e Initial load
duke
parents:
diff changeset
325 *addr_at(instruction_offset) == instruction_code_xmm_sd_prefix ||
a61af66fc99e Initial load
duke
parents:
diff changeset
326 *addr_at(instruction_offset) == instruction_operandsize_prefix) {
a61af66fc99e Initial load
duke
parents:
diff changeset
327 return int_at(data_offset+2);
a61af66fc99e Initial load
duke
parents:
diff changeset
328 }
a61af66fc99e Initial load
duke
parents:
diff changeset
329 else return int_at(data_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
331
a61af66fc99e Initial load
duke
parents:
diff changeset
332 void set_offset(int x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
333 if (*addr_at(instruction_offset) == instruction_operandsize_prefix &&
a61af66fc99e Initial load
duke
parents:
diff changeset
334 *addr_at(instruction_offset+1) != instruction_code_xmm_code) {
a61af66fc99e Initial load
duke
parents:
diff changeset
335 set_int_at(data_offset+1, x); // Not SSE instructions
a61af66fc99e Initial load
duke
parents:
diff changeset
336 }
a61af66fc99e Initial load
duke
parents:
diff changeset
337 else if (*addr_at(instruction_offset) == instruction_extended_prefix) {
a61af66fc99e Initial load
duke
parents:
diff changeset
338 set_int_at(data_offset+1, x);
a61af66fc99e Initial load
duke
parents:
diff changeset
339 }
a61af66fc99e Initial load
duke
parents:
diff changeset
340 else if (*addr_at(instruction_offset) == instruction_code_xor ||
a61af66fc99e Initial load
duke
parents:
diff changeset
341 *addr_at(instruction_offset) == instruction_code_xmm_ss_prefix ||
a61af66fc99e Initial load
duke
parents:
diff changeset
342 *addr_at(instruction_offset) == instruction_code_xmm_sd_prefix ||
a61af66fc99e Initial load
duke
parents:
diff changeset
343 *addr_at(instruction_offset) == instruction_operandsize_prefix) {
a61af66fc99e Initial load
duke
parents:
diff changeset
344 set_int_at(data_offset+2, x);
a61af66fc99e Initial load
duke
parents:
diff changeset
345 }
a61af66fc99e Initial load
duke
parents:
diff changeset
346 else set_int_at(data_offset, x);
a61af66fc99e Initial load
duke
parents:
diff changeset
347 }
a61af66fc99e Initial load
duke
parents:
diff changeset
348
a61af66fc99e Initial load
duke
parents:
diff changeset
349 void add_offset_in_bytes(int add_offset) { set_offset ( ( offset() + add_offset ) ); }
a61af66fc99e Initial load
duke
parents:
diff changeset
350 void copy_instruction_to(address new_instruction_address);
a61af66fc99e Initial load
duke
parents:
diff changeset
351
a61af66fc99e Initial load
duke
parents:
diff changeset
352 void verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
353 void print ();
a61af66fc99e Initial load
duke
parents:
diff changeset
354
a61af66fc99e Initial load
duke
parents:
diff changeset
355 // unit test stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
356 static void test() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
357
a61af66fc99e Initial load
duke
parents:
diff changeset
358 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
359 inline friend NativeMovRegMem* nativeMovRegMem_at (address address);
a61af66fc99e Initial load
duke
parents:
diff changeset
360 };
a61af66fc99e Initial load
duke
parents:
diff changeset
361
a61af66fc99e Initial load
duke
parents:
diff changeset
362 inline NativeMovRegMem* nativeMovRegMem_at (address address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
363 NativeMovRegMem* test = (NativeMovRegMem*)(address - NativeMovRegMem::instruction_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
364 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
365 test->verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
366 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
367 return test;
a61af66fc99e Initial load
duke
parents:
diff changeset
368 }
a61af66fc99e Initial load
duke
parents:
diff changeset
369
a61af66fc99e Initial load
duke
parents:
diff changeset
370 class NativeMovRegMemPatching: public NativeMovRegMem {
a61af66fc99e Initial load
duke
parents:
diff changeset
371 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
372 friend NativeMovRegMemPatching* nativeMovRegMemPatching_at (address address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
373 NativeMovRegMemPatching* test = (NativeMovRegMemPatching*)(address - instruction_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
374 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
375 test->verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
376 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
377 return test;
a61af66fc99e Initial load
duke
parents:
diff changeset
378 }
a61af66fc99e Initial load
duke
parents:
diff changeset
379 };
a61af66fc99e Initial load
duke
parents:
diff changeset
380
a61af66fc99e Initial load
duke
parents:
diff changeset
381
a61af66fc99e Initial load
duke
parents:
diff changeset
382
a61af66fc99e Initial load
duke
parents:
diff changeset
383 // An interface for accessing/manipulating native leal instruction of form:
a61af66fc99e Initial load
duke
parents:
diff changeset
384 // leal reg, [reg + offset]
a61af66fc99e Initial load
duke
parents:
diff changeset
385
a61af66fc99e Initial load
duke
parents:
diff changeset
386 class NativeLoadAddress: public NativeMovRegMem {
a61af66fc99e Initial load
duke
parents:
diff changeset
387 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
388 enum Intel_specific_constants {
a61af66fc99e Initial load
duke
parents:
diff changeset
389 instruction_code = 0x8D
a61af66fc99e Initial load
duke
parents:
diff changeset
390 };
a61af66fc99e Initial load
duke
parents:
diff changeset
391
a61af66fc99e Initial load
duke
parents:
diff changeset
392 void verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
393 void print ();
a61af66fc99e Initial load
duke
parents:
diff changeset
394
a61af66fc99e Initial load
duke
parents:
diff changeset
395 // unit test stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
396 static void test() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
397
a61af66fc99e Initial load
duke
parents:
diff changeset
398 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
399 friend NativeLoadAddress* nativeLoadAddress_at (address address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
400 NativeLoadAddress* test = (NativeLoadAddress*)(address - instruction_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
401 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
402 test->verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
403 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
404 return test;
a61af66fc99e Initial load
duke
parents:
diff changeset
405 }
a61af66fc99e Initial load
duke
parents:
diff changeset
406 };
a61af66fc99e Initial load
duke
parents:
diff changeset
407
a61af66fc99e Initial load
duke
parents:
diff changeset
408 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
409
a61af66fc99e Initial load
duke
parents:
diff changeset
410 // jump rel32off
a61af66fc99e Initial load
duke
parents:
diff changeset
411
a61af66fc99e Initial load
duke
parents:
diff changeset
412 class NativeJump: public NativeInstruction {
a61af66fc99e Initial load
duke
parents:
diff changeset
413 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
414 enum Intel_specific_constants {
a61af66fc99e Initial load
duke
parents:
diff changeset
415 instruction_code = 0xe9,
a61af66fc99e Initial load
duke
parents:
diff changeset
416 instruction_size = 5,
a61af66fc99e Initial load
duke
parents:
diff changeset
417 instruction_offset = 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
418 data_offset = 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
419 next_instruction_offset = 5
a61af66fc99e Initial load
duke
parents:
diff changeset
420 };
a61af66fc99e Initial load
duke
parents:
diff changeset
421
a61af66fc99e Initial load
duke
parents:
diff changeset
422 address instruction_address() const { return addr_at(instruction_offset); }
a61af66fc99e Initial load
duke
parents:
diff changeset
423 address next_instruction_address() const { return addr_at(next_instruction_offset); }
a61af66fc99e Initial load
duke
parents:
diff changeset
424 address jump_destination() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
425 address dest = (int_at(data_offset)+next_instruction_address());
a61af66fc99e Initial load
duke
parents:
diff changeset
426 #ifdef AMD64 // What is this about?
a61af66fc99e Initial load
duke
parents:
diff changeset
427 // return -1 if jump to self
a61af66fc99e Initial load
duke
parents:
diff changeset
428 dest = (dest == (address) this) ? (address) -1 : dest;
a61af66fc99e Initial load
duke
parents:
diff changeset
429 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
430 return dest;
a61af66fc99e Initial load
duke
parents:
diff changeset
431 }
a61af66fc99e Initial load
duke
parents:
diff changeset
432
a61af66fc99e Initial load
duke
parents:
diff changeset
433 void set_jump_destination(address dest) {
a61af66fc99e Initial load
duke
parents:
diff changeset
434 intptr_t val = dest - next_instruction_address();
a61af66fc99e Initial load
duke
parents:
diff changeset
435 #ifdef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
436 if (dest == (address) -1) { // can't encode jump to -1
a61af66fc99e Initial load
duke
parents:
diff changeset
437 val = -5; // jump to self
a61af66fc99e Initial load
duke
parents:
diff changeset
438 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
439 assert((labs(val) & 0xFFFFFFFF00000000) == 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
440 "must be 32bit offset");
a61af66fc99e Initial load
duke
parents:
diff changeset
441 }
a61af66fc99e Initial load
duke
parents:
diff changeset
442 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
443 set_int_at(data_offset, (jint)val);
a61af66fc99e Initial load
duke
parents:
diff changeset
444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
445
a61af66fc99e Initial load
duke
parents:
diff changeset
446 // Creation
a61af66fc99e Initial load
duke
parents:
diff changeset
447 inline friend NativeJump* nativeJump_at(address address);
a61af66fc99e Initial load
duke
parents:
diff changeset
448
a61af66fc99e Initial load
duke
parents:
diff changeset
449 void verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
450
a61af66fc99e Initial load
duke
parents:
diff changeset
451 // Unit testing stuff
a61af66fc99e Initial load
duke
parents:
diff changeset
452 static void test() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
453
a61af66fc99e Initial load
duke
parents:
diff changeset
454 // Insertion of native jump instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
455 static void insert(address code_pos, address entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
456 // MT-safe insertion of native jump at verified method entry
a61af66fc99e Initial load
duke
parents:
diff changeset
457 static void check_verified_entry_alignment(address entry, address verified_entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
458 static void patch_verified_entry(address entry, address verified_entry, address dest);
a61af66fc99e Initial load
duke
parents:
diff changeset
459 };
a61af66fc99e Initial load
duke
parents:
diff changeset
460
a61af66fc99e Initial load
duke
parents:
diff changeset
461 inline NativeJump* nativeJump_at(address address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
462 NativeJump* jump = (NativeJump*)(address - NativeJump::instruction_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
463 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
464 jump->verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
465 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
466 return jump;
a61af66fc99e Initial load
duke
parents:
diff changeset
467 }
a61af66fc99e Initial load
duke
parents:
diff changeset
468
a61af66fc99e Initial load
duke
parents:
diff changeset
469 // Handles all kinds of jump on Intel. Long/far, conditional/unconditional
a61af66fc99e Initial load
duke
parents:
diff changeset
470 class NativeGeneralJump: public NativeInstruction {
a61af66fc99e Initial load
duke
parents:
diff changeset
471 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
472 enum Intel_specific_constants {
a61af66fc99e Initial load
duke
parents:
diff changeset
473 // Constants does not apply, since the lengths and offsets depends on the actual jump
a61af66fc99e Initial load
duke
parents:
diff changeset
474 // used
a61af66fc99e Initial load
duke
parents:
diff changeset
475 // Instruction codes:
a61af66fc99e Initial load
duke
parents:
diff changeset
476 // Unconditional jumps: 0xE9 (rel32off), 0xEB (rel8off)
a61af66fc99e Initial load
duke
parents:
diff changeset
477 // Conditional jumps: 0x0F8x (rel32off), 0x7x (rel8off)
a61af66fc99e Initial load
duke
parents:
diff changeset
478 unconditional_long_jump = 0xe9,
a61af66fc99e Initial load
duke
parents:
diff changeset
479 unconditional_short_jump = 0xeb,
a61af66fc99e Initial load
duke
parents:
diff changeset
480 instruction_size = 5
a61af66fc99e Initial load
duke
parents:
diff changeset
481 };
a61af66fc99e Initial load
duke
parents:
diff changeset
482
a61af66fc99e Initial load
duke
parents:
diff changeset
483 address instruction_address() const { return addr_at(0); }
a61af66fc99e Initial load
duke
parents:
diff changeset
484 address jump_destination() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
485
a61af66fc99e Initial load
duke
parents:
diff changeset
486 // Creation
a61af66fc99e Initial load
duke
parents:
diff changeset
487 inline friend NativeGeneralJump* nativeGeneralJump_at(address address);
a61af66fc99e Initial load
duke
parents:
diff changeset
488
a61af66fc99e Initial load
duke
parents:
diff changeset
489 // Insertion of native general jump instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
490 static void insert_unconditional(address code_pos, address entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
491 static void replace_mt_safe(address instr_addr, address code_buffer);
a61af66fc99e Initial load
duke
parents:
diff changeset
492
a61af66fc99e Initial load
duke
parents:
diff changeset
493 void verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
494 };
a61af66fc99e Initial load
duke
parents:
diff changeset
495
a61af66fc99e Initial load
duke
parents:
diff changeset
496 inline NativeGeneralJump* nativeGeneralJump_at(address address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
497 NativeGeneralJump* jump = (NativeGeneralJump*)(address);
a61af66fc99e Initial load
duke
parents:
diff changeset
498 debug_only(jump->verify();)
a61af66fc99e Initial load
duke
parents:
diff changeset
499 return jump;
a61af66fc99e Initial load
duke
parents:
diff changeset
500 }
a61af66fc99e Initial load
duke
parents:
diff changeset
501
a61af66fc99e Initial load
duke
parents:
diff changeset
502 class NativePopReg : public NativeInstruction {
a61af66fc99e Initial load
duke
parents:
diff changeset
503 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
504 enum Intel_specific_constants {
a61af66fc99e Initial load
duke
parents:
diff changeset
505 instruction_code = 0x58,
a61af66fc99e Initial load
duke
parents:
diff changeset
506 instruction_size = 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
507 instruction_offset = 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
508 data_offset = 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
509 next_instruction_offset = 1
a61af66fc99e Initial load
duke
parents:
diff changeset
510 };
a61af66fc99e Initial load
duke
parents:
diff changeset
511
a61af66fc99e Initial load
duke
parents:
diff changeset
512 // Insert a pop instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
513 static void insert(address code_pos, Register reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
514 };
a61af66fc99e Initial load
duke
parents:
diff changeset
515
a61af66fc99e Initial load
duke
parents:
diff changeset
516
a61af66fc99e Initial load
duke
parents:
diff changeset
517 class NativeIllegalInstruction: public NativeInstruction {
a61af66fc99e Initial load
duke
parents:
diff changeset
518 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
519 enum Intel_specific_constants {
a61af66fc99e Initial load
duke
parents:
diff changeset
520 instruction_code = 0x0B0F, // Real byte order is: 0x0F, 0x0B
a61af66fc99e Initial load
duke
parents:
diff changeset
521 instruction_size = 2,
a61af66fc99e Initial load
duke
parents:
diff changeset
522 instruction_offset = 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
523 next_instruction_offset = 2
a61af66fc99e Initial load
duke
parents:
diff changeset
524 };
a61af66fc99e Initial load
duke
parents:
diff changeset
525
a61af66fc99e Initial load
duke
parents:
diff changeset
526 // Insert illegal opcode as specific address
a61af66fc99e Initial load
duke
parents:
diff changeset
527 static void insert(address code_pos);
a61af66fc99e Initial load
duke
parents:
diff changeset
528 };
a61af66fc99e Initial load
duke
parents:
diff changeset
529
a61af66fc99e Initial load
duke
parents:
diff changeset
530 // return instruction that does not pop values of the stack
a61af66fc99e Initial load
duke
parents:
diff changeset
531 class NativeReturn: public NativeInstruction {
a61af66fc99e Initial load
duke
parents:
diff changeset
532 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
533 enum Intel_specific_constants {
a61af66fc99e Initial load
duke
parents:
diff changeset
534 instruction_code = 0xC3,
a61af66fc99e Initial load
duke
parents:
diff changeset
535 instruction_size = 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
536 instruction_offset = 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
537 next_instruction_offset = 1
a61af66fc99e Initial load
duke
parents:
diff changeset
538 };
a61af66fc99e Initial load
duke
parents:
diff changeset
539 };
a61af66fc99e Initial load
duke
parents:
diff changeset
540
a61af66fc99e Initial load
duke
parents:
diff changeset
541 // return instruction that does pop values of the stack
a61af66fc99e Initial load
duke
parents:
diff changeset
542 class NativeReturnX: public NativeInstruction {
a61af66fc99e Initial load
duke
parents:
diff changeset
543 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
544 enum Intel_specific_constants {
a61af66fc99e Initial load
duke
parents:
diff changeset
545 instruction_code = 0xC2,
a61af66fc99e Initial load
duke
parents:
diff changeset
546 instruction_size = 2,
a61af66fc99e Initial load
duke
parents:
diff changeset
547 instruction_offset = 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
548 next_instruction_offset = 2
a61af66fc99e Initial load
duke
parents:
diff changeset
549 };
a61af66fc99e Initial load
duke
parents:
diff changeset
550 };
a61af66fc99e Initial load
duke
parents:
diff changeset
551
a61af66fc99e Initial load
duke
parents:
diff changeset
552 // Simple test vs memory
a61af66fc99e Initial load
duke
parents:
diff changeset
553 class NativeTstRegMem: public NativeInstruction {
a61af66fc99e Initial load
duke
parents:
diff changeset
554 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
555 enum Intel_specific_constants {
a61af66fc99e Initial load
duke
parents:
diff changeset
556 instruction_code_memXregl = 0x85
a61af66fc99e Initial load
duke
parents:
diff changeset
557 };
a61af66fc99e Initial load
duke
parents:
diff changeset
558 };
a61af66fc99e Initial load
duke
parents:
diff changeset
559
a61af66fc99e Initial load
duke
parents:
diff changeset
560 inline bool NativeInstruction::is_illegal() { return (short)int_at(0) == (short)NativeIllegalInstruction::instruction_code; }
a61af66fc99e Initial load
duke
parents:
diff changeset
561 inline bool NativeInstruction::is_call() { return ubyte_at(0) == NativeCall::instruction_code; }
a61af66fc99e Initial load
duke
parents:
diff changeset
562 inline bool NativeInstruction::is_return() { return ubyte_at(0) == NativeReturn::instruction_code ||
a61af66fc99e Initial load
duke
parents:
diff changeset
563 ubyte_at(0) == NativeReturnX::instruction_code; }
a61af66fc99e Initial load
duke
parents:
diff changeset
564 inline bool NativeInstruction::is_jump() { return ubyte_at(0) == NativeJump::instruction_code ||
a61af66fc99e Initial load
duke
parents:
diff changeset
565 ubyte_at(0) == 0xEB; /* short jump */ }
a61af66fc99e Initial load
duke
parents:
diff changeset
566 inline bool NativeInstruction::is_cond_jump() { return (int_at(0) & 0xF0FF) == 0x800F /* long jump */ ||
a61af66fc99e Initial load
duke
parents:
diff changeset
567 (ubyte_at(0) & 0xF0) == 0x70; /* short jump */ }
a61af66fc99e Initial load
duke
parents:
diff changeset
568 inline bool NativeInstruction::is_safepoint_poll() {
a61af66fc99e Initial load
duke
parents:
diff changeset
569 #ifdef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
570 return ubyte_at(0) == NativeTstRegMem::instruction_code_memXregl &&
a61af66fc99e Initial load
duke
parents:
diff changeset
571 ubyte_at(1) == 0x05 && // 00 rax 101
a61af66fc99e Initial load
duke
parents:
diff changeset
572 ((intptr_t) addr_at(6)) + int_at(2) == (intptr_t) os::get_polling_page();
a61af66fc99e Initial load
duke
parents:
diff changeset
573 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
574 return ( ubyte_at(0) == NativeMovRegMem::instruction_code_mem2regl ||
a61af66fc99e Initial load
duke
parents:
diff changeset
575 ubyte_at(0) == NativeTstRegMem::instruction_code_memXregl ) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
576 (ubyte_at(1)&0xC7) == 0x05 && /* Mod R/M == disp32 */
a61af66fc99e Initial load
duke
parents:
diff changeset
577 (os::is_poll_address((address)int_at(2)));
a61af66fc99e Initial load
duke
parents:
diff changeset
578 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
579 }
a61af66fc99e Initial load
duke
parents:
diff changeset
580
a61af66fc99e Initial load
duke
parents:
diff changeset
581 inline bool NativeInstruction::is_mov_literal64() {
a61af66fc99e Initial load
duke
parents:
diff changeset
582 #ifdef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
583 return ((ubyte_at(0) == Assembler::REX_W || ubyte_at(0) == Assembler::REX_WB) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
584 (ubyte_at(1) & (0xff ^ NativeMovConstReg::register_mask)) == 0xB8);
a61af66fc99e Initial load
duke
parents:
diff changeset
585 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
586 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
587 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
588 }