annotate src/cpu/x86/vm/jniFastGetField_x86_64.cpp @ 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 dc7f315e41f7
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 2004-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 # include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 # include "incls/_jniFastGetField_x86_64.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 #define __ masm->
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 #define BUFFER_SIZE 30*wordSize
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // Instead of issuing lfence for LoadLoad barrier, we create data dependency
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // between loads, which is more efficient than lfence.
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // Common register usage:
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // rax/xmm0: result
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // c_rarg0: jni env
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // c_rarg1: obj
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // c_rarg2: jfield id
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 static const Register robj = r9;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 static const Register rcounter = r10;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 static const Register roffset = r11;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 static const Register rcounter_addr = r11;
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // Warning: do not use rip relative addressing after the first counter load
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // since that may scratch r10!
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 address JNI_FastGetField::generate_fast_get_int_field0(BasicType type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 const char *name;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 switch (type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 case T_BOOLEAN: name = "jni_fast_GetBooleanField"; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 case T_BYTE: name = "jni_fast_GetByteField"; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 case T_CHAR: name = "jni_fast_GetCharField"; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 case T_SHORT: name = "jni_fast_GetShortField"; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 case T_INT: name = "jni_fast_GetIntField"; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 case T_LONG: name = "jni_fast_GetLongField"; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 default: ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 BufferBlob* b = BufferBlob::create(name, BUFFER_SIZE);
a61af66fc99e Initial load
duke
parents:
diff changeset
62 address fast_entry = b->instructions_begin();
a61af66fc99e Initial load
duke
parents:
diff changeset
63 CodeBuffer cbuf(fast_entry, b->instructions_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
64 MacroAssembler* masm = new MacroAssembler(&cbuf);
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 Label slow;
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 ExternalAddress counter(SafepointSynchronize::safepoint_counter_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
69 __ mov32 (rcounter, counter);
a61af66fc99e Initial load
duke
parents:
diff changeset
70 __ movq (robj, c_rarg1);
a61af66fc99e Initial load
duke
parents:
diff changeset
71 __ testb (rcounter, 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
72 __ jcc (Assembler::notZero, slow);
a61af66fc99e Initial load
duke
parents:
diff changeset
73 if (os::is_MP()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 __ xorq (robj, rcounter);
a61af66fc99e Initial load
duke
parents:
diff changeset
75 __ xorq (robj, rcounter); // obj, since
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // robj ^ rcounter ^ rcounter == robj
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // robj is data dependent on rcounter.
a61af66fc99e Initial load
duke
parents:
diff changeset
78 }
a61af66fc99e Initial load
duke
parents:
diff changeset
79 __ movq (robj, Address(robj, 0)); // *obj
a61af66fc99e Initial load
duke
parents:
diff changeset
80 __ movq (roffset, c_rarg2);
a61af66fc99e Initial load
duke
parents:
diff changeset
81 __ shrq (roffset, 2); // offset
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 assert(count < LIST_CAPACITY, "LIST_CAPACITY too small");
a61af66fc99e Initial load
duke
parents:
diff changeset
84 speculative_load_pclist[count] = __ pc();
a61af66fc99e Initial load
duke
parents:
diff changeset
85 switch (type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 case T_BOOLEAN: __ movzbl (rax, Address(robj, roffset, Address::times_1)); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 case T_BYTE: __ movsbl (rax, Address(robj, roffset, Address::times_1)); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 case T_CHAR: __ movzwl (rax, Address(robj, roffset, Address::times_1)); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 case T_SHORT: __ movswl (rax, Address(robj, roffset, Address::times_1)); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 case T_INT: __ movl (rax, Address(robj, roffset, Address::times_1)); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 case T_LONG: __ movq (rax, Address(robj, roffset, Address::times_1)); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 default: ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 if (os::is_MP()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 __ lea(rcounter_addr, counter);
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // ca is data dependent on rax.
a61af66fc99e Initial load
duke
parents:
diff changeset
98 __ xorq (rcounter_addr, rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 __ xorq (rcounter_addr, rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
100 __ cmpl (rcounter, Address(rcounter_addr, 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
101 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 __ cmp32 (rcounter, counter);
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104 __ jcc (Assembler::notEqual, slow);
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 __ ret (0);
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 slowcase_entry_pclist[count++] = __ pc();
a61af66fc99e Initial load
duke
parents:
diff changeset
109 __ bind (slow);
a61af66fc99e Initial load
duke
parents:
diff changeset
110 address slow_case_addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 switch (type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 case T_BOOLEAN: slow_case_addr = jni_GetBooleanField_addr(); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 case T_BYTE: slow_case_addr = jni_GetByteField_addr(); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 case T_CHAR: slow_case_addr = jni_GetCharField_addr(); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 case T_SHORT: slow_case_addr = jni_GetShortField_addr(); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 case T_INT: slow_case_addr = jni_GetIntField_addr(); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 case T_LONG: slow_case_addr = jni_GetLongField_addr();
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // tail call
a61af66fc99e Initial load
duke
parents:
diff changeset
120 __ jump (ExternalAddress(slow_case_addr));
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 __ flush ();
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 return fast_entry;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 address JNI_FastGetField::generate_fast_get_boolean_field() {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 return generate_fast_get_int_field0(T_BOOLEAN);
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 address JNI_FastGetField::generate_fast_get_byte_field() {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 return generate_fast_get_int_field0(T_BYTE);
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 address JNI_FastGetField::generate_fast_get_char_field() {
a61af66fc99e Initial load
duke
parents:
diff changeset
136 return generate_fast_get_int_field0(T_CHAR);
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 address JNI_FastGetField::generate_fast_get_short_field() {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 return generate_fast_get_int_field0(T_SHORT);
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 address JNI_FastGetField::generate_fast_get_int_field() {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 return generate_fast_get_int_field0(T_INT);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 address JNI_FastGetField::generate_fast_get_long_field() {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 return generate_fast_get_int_field0(T_LONG);
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 address JNI_FastGetField::generate_fast_get_float_field0(BasicType type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 const char *name;
a61af66fc99e Initial load
duke
parents:
diff changeset
153 switch (type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 case T_FLOAT: name = "jni_fast_GetFloatField"; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
155 case T_DOUBLE: name = "jni_fast_GetDoubleField"; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 default: ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
159 BufferBlob* b = BufferBlob::create(name, BUFFER_SIZE);
a61af66fc99e Initial load
duke
parents:
diff changeset
160 address fast_entry = b->instructions_begin();
a61af66fc99e Initial load
duke
parents:
diff changeset
161 CodeBuffer cbuf(fast_entry, b->instructions_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
162 MacroAssembler* masm = new MacroAssembler(&cbuf);
a61af66fc99e Initial load
duke
parents:
diff changeset
163
a61af66fc99e Initial load
duke
parents:
diff changeset
164 Label slow;
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 ExternalAddress counter(SafepointSynchronize::safepoint_counter_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
167 __ mov32 (rcounter, counter);
a61af66fc99e Initial load
duke
parents:
diff changeset
168 __ movq (robj, c_rarg1);
a61af66fc99e Initial load
duke
parents:
diff changeset
169 __ testb (rcounter, 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
170 __ jcc (Assembler::notZero, slow);
a61af66fc99e Initial load
duke
parents:
diff changeset
171 if (os::is_MP()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 __ xorq (robj, rcounter);
a61af66fc99e Initial load
duke
parents:
diff changeset
173 __ xorq (robj, rcounter); // obj, since
a61af66fc99e Initial load
duke
parents:
diff changeset
174 // robj ^ rcounter ^ rcounter == robj
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // robj is data dependent on rcounter.
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177 __ movq (robj, Address(robj, 0)); // *obj
a61af66fc99e Initial load
duke
parents:
diff changeset
178 __ movq (roffset, c_rarg2);
a61af66fc99e Initial load
duke
parents:
diff changeset
179 __ shrq (roffset, 2); // offset
a61af66fc99e Initial load
duke
parents:
diff changeset
180
a61af66fc99e Initial load
duke
parents:
diff changeset
181 assert(count < LIST_CAPACITY, "LIST_CAPACITY too small");
a61af66fc99e Initial load
duke
parents:
diff changeset
182 speculative_load_pclist[count] = __ pc();
a61af66fc99e Initial load
duke
parents:
diff changeset
183 switch (type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 case T_FLOAT: __ movflt (xmm0, Address(robj, roffset, Address::times_1)); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
185 case T_DOUBLE: __ movdbl (xmm0, Address(robj, roffset, Address::times_1)); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
186 default: ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 if (os::is_MP()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 __ lea(rcounter_addr, counter);
a61af66fc99e Initial load
duke
parents:
diff changeset
191 __ movdq (rax, xmm0);
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // counter address is data dependent on xmm0.
a61af66fc99e Initial load
duke
parents:
diff changeset
193 __ xorq (rcounter_addr, rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
194 __ xorq (rcounter_addr, rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
195 __ cmpl (rcounter, Address(rcounter_addr, 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
196 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 __ cmp32 (rcounter, counter);
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199 __ jcc (Assembler::notEqual, slow);
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201 __ ret (0);
a61af66fc99e Initial load
duke
parents:
diff changeset
202
a61af66fc99e Initial load
duke
parents:
diff changeset
203 slowcase_entry_pclist[count++] = __ pc();
a61af66fc99e Initial load
duke
parents:
diff changeset
204 __ bind (slow);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 address slow_case_addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
206 switch (type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 case T_FLOAT: slow_case_addr = jni_GetFloatField_addr(); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
208 case T_DOUBLE: slow_case_addr = jni_GetDoubleField_addr();
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210 // tail call
a61af66fc99e Initial load
duke
parents:
diff changeset
211 __ jump (ExternalAddress(slow_case_addr));
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 __ flush ();
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 return fast_entry;
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218 address JNI_FastGetField::generate_fast_get_float_field() {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 return generate_fast_get_float_field0(T_FLOAT);
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222 address JNI_FastGetField::generate_fast_get_double_field() {
a61af66fc99e Initial load
duke
parents:
diff changeset
223 return generate_fast_get_float_field0(T_DOUBLE);
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }