1 #ifdef USE_PRAGMA_IDENT_SRC
2 #pragma ident "@(#)jniFastGetField_x86_32.cpp 1.13 07/09/17 09:26:02 JVM"
3 #endif
4 /*
5 * Copyright 2004-2006 Sun Microsystems, Inc. All Rights Reserved.
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 *
8 * This code is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 only, as
10 * published by the Free Software Foundation.
11 *
12 * This code is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * version 2 for more details (a copy is included in the LICENSE file that
16 * accompanied this code).
17 *
18 * You should have received a copy of the GNU General Public License version
19 * 2 along with this work; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
24 * have any questions.
25 *
58 }
59 ResourceMark rm;
60 BufferBlob* b = BufferBlob::create(name, BUFFER_SIZE*wordSize);
61 address fast_entry = b->instructions_begin();
62 CodeBuffer cbuf(fast_entry, b->instructions_size());
63 MacroAssembler* masm = new MacroAssembler(&cbuf);
64
65 Label slow;
66
67 // stack layout: offset from rsp (in words):
68 // return pc 0
69 // jni env 1
70 // obj 2
71 // jfieldID 3
72
73 ExternalAddress counter(SafepointSynchronize::safepoint_counter_addr());
74 __ mov32 (rcx, counter);
75 __ testb (rcx, 1);
76 __ jcc (Assembler::notZero, slow);
77 if (os::is_MP()) {
78 __ movl (rax, rcx);
79 __ andl (rax, 1); // rax, must end up 0
80 __ movl (rdx, Address(rsp, rax, Address::times_1, 2*wordSize));
81 // obj, notice rax, is 0.
82 // rdx is data dependent on rcx.
83 } else {
84 __ movl (rdx, Address(rsp, 2*wordSize)); // obj
85 }
86 __ movl (rax, Address(rsp, 3*wordSize)); // jfieldID
87 __ movl (rdx, Address(rdx, 0)); // *obj
88 __ shrl (rax, 2); // offset
89
90 assert(count < LIST_CAPACITY, "LIST_CAPACITY too small");
91 speculative_load_pclist[count] = __ pc();
92 switch (type) {
93 case T_BOOLEAN: __ movzxb (rax, Address(rdx, rax, Address::times_1)); break;
94 case T_BYTE: __ movsxb (rax, Address(rdx, rax, Address::times_1)); break;
95 case T_CHAR: __ movzxw (rax, Address(rdx, rax, Address::times_1)); break;
96 case T_SHORT: __ movsxw (rax, Address(rdx, rax, Address::times_1)); break;
97 case T_INT: __ movl (rax, Address(rdx, rax, Address::times_1)); break;
98 default: ShouldNotReachHere();
99 }
100
101 Address ca1;
102 if (os::is_MP()) {
103 __ lea(rdx, counter);
104 __ xorl(rdx, rax);
105 __ xorl(rdx, rax);
106 __ cmp32(rcx, Address(rdx, 0));
107 // ca1 is the same as ca because
108 // rax, ^ counter_addr ^ rax, = address
109 // ca1 is data dependent on rax,.
110 } else {
111 __ cmp32(rcx, counter);
112 }
113 __ jcc (Assembler::notEqual, slow);
114
115 #ifndef _WINDOWS
116 __ ret (0);
117 #else
118 // __stdcall calling convention
119 __ ret (3*wordSize);
120 #endif
121
122 slowcase_entry_pclist[count++] = __ pc();
123 __ bind (slow);
124 address slow_case_addr;
125 switch (type) {
170
171 address JNI_FastGetField::generate_fast_get_long_field() {
172 const char *name = "jni_fast_GetLongField";
173 ResourceMark rm;
174 BufferBlob* b = BufferBlob::create(name, BUFFER_SIZE*wordSize);
175 address fast_entry = b->instructions_begin();
176 CodeBuffer cbuf(fast_entry, b->instructions_size());
177 MacroAssembler* masm = new MacroAssembler(&cbuf);
178
179 Label slow;
180
181 // stack layout: offset from rsp (in words):
182 // old rsi 0
183 // return pc 1
184 // jni env 2
185 // obj 3
186 // jfieldID 4
187
188 ExternalAddress counter(SafepointSynchronize::safepoint_counter_addr());
189
190 __ pushl (rsi);
191 __ mov32 (rcx, counter);
192 __ testb (rcx, 1);
193 __ jcc (Assembler::notZero, slow);
194 if (os::is_MP()) {
195 __ movl (rax, rcx);
196 __ andl (rax, 1); // rax, must end up 0
197 __ movl (rdx, Address(rsp, rax, Address::times_1, 3*wordSize));
198 // obj, notice rax, is 0.
199 // rdx is data dependent on rcx.
200 } else {
201 __ movl (rdx, Address(rsp, 3*wordSize)); // obj
202 }
203 __ movl (rsi, Address(rsp, 4*wordSize)); // jfieldID
204 __ movl (rdx, Address(rdx, 0)); // *obj
205 __ shrl (rsi, 2); // offset
206
207 assert(count < LIST_CAPACITY-1, "LIST_CAPACITY too small");
208 speculative_load_pclist[count++] = __ pc();
209 __ movl (rax, Address(rdx, rsi, Address::times_1));
210 speculative_load_pclist[count] = __ pc();
211 __ movl (rdx, Address(rdx, rsi, Address::times_1, 4));
212
213 if (os::is_MP()) {
214 __ lea (rsi, counter);
215 __ xorl (rsi, rdx);
216 __ xorl (rsi, rax);
217 __ xorl (rsi, rdx);
218 __ xorl (rsi, rax);
219 __ cmp32(rcx, Address(rsi, 0));
220 // ca1 is the same as ca because
221 // rax, ^ rdx ^ counter_addr ^ rax, ^ rdx = address
222 // ca1 is data dependent on both rax, and rdx.
223 } else {
224 __ cmp32(rcx, counter);
225 }
226 __ jcc (Assembler::notEqual, slow);
227
228 __ popl (rsi);
229
230 #ifndef _WINDOWS
231 __ ret (0);
232 #else
233 // __stdcall calling convention
234 __ ret (3*wordSize);
235 #endif
236
237 slowcase_entry_pclist[count-1] = __ pc();
238 slowcase_entry_pclist[count++] = __ pc();
239 __ bind (slow);
240 __ popl (rsi);
241 address slow_case_addr = jni_GetLongField_addr();;
242 // tail call
243 __ jump (ExternalAddress(slow_case_addr));
244
245 __ flush ();
246
247 #ifndef _WINDOWS
248 return fast_entry;
249 #else
250 jni_fast_GetLongField_fp = (GetLongField_t)fast_entry;
251 return os::win32::fast_jni_accessor_wrapper(T_LONG);
252 #endif
253 }
254
255 address JNI_FastGetField::generate_fast_get_float_field0(BasicType type) {
256 const char *name;
257 switch (type) {
258 case T_FLOAT: name = "jni_fast_GetFloatField"; break;
259 case T_DOUBLE: name = "jni_fast_GetDoubleField"; break;
260 default: ShouldNotReachHere();
262 ResourceMark rm;
263 BufferBlob* b = BufferBlob::create(name, BUFFER_SIZE*wordSize);
264 address fast_entry = b->instructions_begin();
265 CodeBuffer cbuf(fast_entry, b->instructions_size());
266 MacroAssembler* masm = new MacroAssembler(&cbuf);
267
268 Label slow_with_pop, slow;
269
270 // stack layout: offset from rsp (in words):
271 // return pc 0
272 // jni env 1
273 // obj 2
274 // jfieldID 3
275
276 ExternalAddress counter(SafepointSynchronize::safepoint_counter_addr());
277
278 __ mov32 (rcx, counter);
279 __ testb (rcx, 1);
280 __ jcc (Assembler::notZero, slow);
281 if (os::is_MP()) {
282 __ movl (rax, rcx);
283 __ andl (rax, 1); // rax, must end up 0
284 __ movl (rdx, Address(rsp, rax, Address::times_1, 2*wordSize));
285 // obj, notice rax, is 0.
286 // rdx is data dependent on rcx.
287 } else {
288 __ movl (rdx, Address(rsp, 2*wordSize)); // obj
289 }
290 __ movl (rax, Address(rsp, 3*wordSize)); // jfieldID
291 __ movl (rdx, Address(rdx, 0)); // *obj
292 __ shrl (rax, 2); // offset
293
294 assert(count < LIST_CAPACITY, "LIST_CAPACITY too small");
295 speculative_load_pclist[count] = __ pc();
296 switch (type) {
297 case T_FLOAT: __ fld_s (Address(rdx, rax, Address::times_1)); break;
298 case T_DOUBLE: __ fld_d (Address(rdx, rax, Address::times_1)); break;
299 default: ShouldNotReachHere();
300 }
301
302 Address ca1;
303 if (os::is_MP()) {
304 __ fst_s (Address(rsp, -4));
305 __ lea(rdx, counter);
306 __ movl (rax, Address(rsp, -4));
307 __ xorl(rdx, rax);
308 __ xorl(rdx, rax);
309 __ cmp32(rcx, Address(rdx, 0));
310 // rax, ^ counter_addr ^ rax, = address
311 // ca1 is data dependent on the field
312 // access.
313 } else {
314 __ cmp32(rcx, counter);
315 }
316 __ jcc (Assembler::notEqual, slow_with_pop);
317
318 #ifndef _WINDOWS
319 __ ret (0);
320 #else
321 // __stdcall calling convention
322 __ ret (3*wordSize);
323 #endif
324
325 __ bind (slow_with_pop);
326 // invalid load. pop FPU stack.
327 __ fstp_d (0);
328
340 __ flush ();
341
342 #ifndef _WINDOWS
343 return fast_entry;
344 #else
345 switch (type) {
346 case T_FLOAT: jni_fast_GetFloatField_fp = (GetFloatField_t)fast_entry; break;
347 case T_DOUBLE: jni_fast_GetDoubleField_fp = (GetDoubleField_t)fast_entry;
348 }
349 return os::win32::fast_jni_accessor_wrapper(type);
350 #endif
351 }
352
353 address JNI_FastGetField::generate_fast_get_float_field() {
354 return generate_fast_get_float_field0(T_FLOAT);
355 }
356
357 address JNI_FastGetField::generate_fast_get_double_field() {
358 return generate_fast_get_float_field0(T_DOUBLE);
359 }
360
|
1 /*
2 * Copyright 2004-2008 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
55 }
56 ResourceMark rm;
57 BufferBlob* b = BufferBlob::create(name, BUFFER_SIZE*wordSize);
58 address fast_entry = b->instructions_begin();
59 CodeBuffer cbuf(fast_entry, b->instructions_size());
60 MacroAssembler* masm = new MacroAssembler(&cbuf);
61
62 Label slow;
63
64 // stack layout: offset from rsp (in words):
65 // return pc 0
66 // jni env 1
67 // obj 2
68 // jfieldID 3
69
70 ExternalAddress counter(SafepointSynchronize::safepoint_counter_addr());
71 __ mov32 (rcx, counter);
72 __ testb (rcx, 1);
73 __ jcc (Assembler::notZero, slow);
74 if (os::is_MP()) {
75 __ mov(rax, rcx);
76 __ andptr(rax, 1); // rax, must end up 0
77 __ movptr(rdx, Address(rsp, rax, Address::times_1, 2*wordSize));
78 // obj, notice rax, is 0.
79 // rdx is data dependent on rcx.
80 } else {
81 __ movptr (rdx, Address(rsp, 2*wordSize)); // obj
82 }
83 __ movptr(rax, Address(rsp, 3*wordSize)); // jfieldID
84 __ movptr(rdx, Address(rdx, 0)); // *obj
85 __ shrptr (rax, 2); // offset
86
87 assert(count < LIST_CAPACITY, "LIST_CAPACITY too small");
88 speculative_load_pclist[count] = __ pc();
89 switch (type) {
90 case T_BOOLEAN: __ movzbl (rax, Address(rdx, rax, Address::times_1)); break;
91 case T_BYTE: __ movsbl (rax, Address(rdx, rax, Address::times_1)); break;
92 case T_CHAR: __ movzwl (rax, Address(rdx, rax, Address::times_1)); break;
93 case T_SHORT: __ movswl (rax, Address(rdx, rax, Address::times_1)); break;
94 case T_INT: __ movl (rax, Address(rdx, rax, Address::times_1)); break;
95 default: ShouldNotReachHere();
96 }
97
98 Address ca1;
99 if (os::is_MP()) {
100 __ lea(rdx, counter);
101 __ xorptr(rdx, rax);
102 __ xorptr(rdx, rax);
103 __ cmp32(rcx, Address(rdx, 0));
104 // ca1 is the same as ca because
105 // rax, ^ counter_addr ^ rax, = address
106 // ca1 is data dependent on rax,.
107 } else {
108 __ cmp32(rcx, counter);
109 }
110 __ jcc (Assembler::notEqual, slow);
111
112 #ifndef _WINDOWS
113 __ ret (0);
114 #else
115 // __stdcall calling convention
116 __ ret (3*wordSize);
117 #endif
118
119 slowcase_entry_pclist[count++] = __ pc();
120 __ bind (slow);
121 address slow_case_addr;
122 switch (type) {
167
168 address JNI_FastGetField::generate_fast_get_long_field() {
169 const char *name = "jni_fast_GetLongField";
170 ResourceMark rm;
171 BufferBlob* b = BufferBlob::create(name, BUFFER_SIZE*wordSize);
172 address fast_entry = b->instructions_begin();
173 CodeBuffer cbuf(fast_entry, b->instructions_size());
174 MacroAssembler* masm = new MacroAssembler(&cbuf);
175
176 Label slow;
177
178 // stack layout: offset from rsp (in words):
179 // old rsi 0
180 // return pc 1
181 // jni env 2
182 // obj 3
183 // jfieldID 4
184
185 ExternalAddress counter(SafepointSynchronize::safepoint_counter_addr());
186
187 __ push (rsi);
188 __ mov32 (rcx, counter);
189 __ testb (rcx, 1);
190 __ jcc (Assembler::notZero, slow);
191 if (os::is_MP()) {
192 __ mov(rax, rcx);
193 __ andptr(rax, 1); // rax, must end up 0
194 __ movptr(rdx, Address(rsp, rax, Address::times_1, 3*wordSize));
195 // obj, notice rax, is 0.
196 // rdx is data dependent on rcx.
197 } else {
198 __ movptr(rdx, Address(rsp, 3*wordSize)); // obj
199 }
200 __ movptr(rsi, Address(rsp, 4*wordSize)); // jfieldID
201 __ movptr(rdx, Address(rdx, 0)); // *obj
202 __ shrptr(rsi, 2); // offset
203
204 assert(count < LIST_CAPACITY-1, "LIST_CAPACITY too small");
205 speculative_load_pclist[count++] = __ pc();
206 __ movptr(rax, Address(rdx, rsi, Address::times_1));
207 #ifndef _LP64
208 speculative_load_pclist[count] = __ pc();
209 __ movl(rdx, Address(rdx, rsi, Address::times_1, 4));
210 #endif // _LP64
211
212 if (os::is_MP()) {
213 __ lea(rsi, counter);
214 __ xorptr(rsi, rdx);
215 __ xorptr(rsi, rax);
216 __ xorptr(rsi, rdx);
217 __ xorptr(rsi, rax);
218 __ cmp32(rcx, Address(rsi, 0));
219 // ca1 is the same as ca because
220 // rax, ^ rdx ^ counter_addr ^ rax, ^ rdx = address
221 // ca1 is data dependent on both rax, and rdx.
222 } else {
223 __ cmp32(rcx, counter);
224 }
225 __ jcc (Assembler::notEqual, slow);
226
227 __ pop (rsi);
228
229 #ifndef _WINDOWS
230 __ ret (0);
231 #else
232 // __stdcall calling convention
233 __ ret (3*wordSize);
234 #endif
235
236 slowcase_entry_pclist[count-1] = __ pc();
237 slowcase_entry_pclist[count++] = __ pc();
238 __ bind (slow);
239 __ pop (rsi);
240 address slow_case_addr = jni_GetLongField_addr();;
241 // tail call
242 __ jump (ExternalAddress(slow_case_addr));
243
244 __ flush ();
245
246 #ifndef _WINDOWS
247 return fast_entry;
248 #else
249 jni_fast_GetLongField_fp = (GetLongField_t)fast_entry;
250 return os::win32::fast_jni_accessor_wrapper(T_LONG);
251 #endif
252 }
253
254 address JNI_FastGetField::generate_fast_get_float_field0(BasicType type) {
255 const char *name;
256 switch (type) {
257 case T_FLOAT: name = "jni_fast_GetFloatField"; break;
258 case T_DOUBLE: name = "jni_fast_GetDoubleField"; break;
259 default: ShouldNotReachHere();
261 ResourceMark rm;
262 BufferBlob* b = BufferBlob::create(name, BUFFER_SIZE*wordSize);
263 address fast_entry = b->instructions_begin();
264 CodeBuffer cbuf(fast_entry, b->instructions_size());
265 MacroAssembler* masm = new MacroAssembler(&cbuf);
266
267 Label slow_with_pop, slow;
268
269 // stack layout: offset from rsp (in words):
270 // return pc 0
271 // jni env 1
272 // obj 2
273 // jfieldID 3
274
275 ExternalAddress counter(SafepointSynchronize::safepoint_counter_addr());
276
277 __ mov32 (rcx, counter);
278 __ testb (rcx, 1);
279 __ jcc (Assembler::notZero, slow);
280 if (os::is_MP()) {
281 __ mov(rax, rcx);
282 __ andptr(rax, 1); // rax, must end up 0
283 __ movptr(rdx, Address(rsp, rax, Address::times_1, 2*wordSize));
284 // obj, notice rax, is 0.
285 // rdx is data dependent on rcx.
286 } else {
287 __ movptr(rdx, Address(rsp, 2*wordSize)); // obj
288 }
289 __ movptr(rax, Address(rsp, 3*wordSize)); // jfieldID
290 __ movptr(rdx, Address(rdx, 0)); // *obj
291 __ shrptr(rax, 2); // offset
292
293 assert(count < LIST_CAPACITY, "LIST_CAPACITY too small");
294 speculative_load_pclist[count] = __ pc();
295 switch (type) {
296 #ifndef _LP64
297 case T_FLOAT: __ fld_s (Address(rdx, rax, Address::times_1)); break;
298 case T_DOUBLE: __ fld_d (Address(rdx, rax, Address::times_1)); break;
299 #else
300 case T_FLOAT: __ movflt (xmm0, Address(robj, roffset, Address::times_1)); break;
301 case T_DOUBLE: __ movdbl (xmm0, Address(robj, roffset, Address::times_1)); break;
302 #endif // _LP64
303 default: ShouldNotReachHere();
304 }
305
306 Address ca1;
307 if (os::is_MP()) {
308 __ fst_s (Address(rsp, -4));
309 __ lea(rdx, counter);
310 __ movl (rax, Address(rsp, -4));
311 // garbage hi-order bits on 64bit are harmless.
312 __ xorptr(rdx, rax);
313 __ xorptr(rdx, rax);
314 __ cmp32(rcx, Address(rdx, 0));
315 // rax, ^ counter_addr ^ rax, = address
316 // ca1 is data dependent on the field
317 // access.
318 } else {
319 __ cmp32(rcx, counter);
320 }
321 __ jcc (Assembler::notEqual, slow_with_pop);
322
323 #ifndef _WINDOWS
324 __ ret (0);
325 #else
326 // __stdcall calling convention
327 __ ret (3*wordSize);
328 #endif
329
330 __ bind (slow_with_pop);
331 // invalid load. pop FPU stack.
332 __ fstp_d (0);
333
345 __ flush ();
346
347 #ifndef _WINDOWS
348 return fast_entry;
349 #else
350 switch (type) {
351 case T_FLOAT: jni_fast_GetFloatField_fp = (GetFloatField_t)fast_entry; break;
352 case T_DOUBLE: jni_fast_GetDoubleField_fp = (GetDoubleField_t)fast_entry;
353 }
354 return os::win32::fast_jni_accessor_wrapper(type);
355 #endif
356 }
357
358 address JNI_FastGetField::generate_fast_get_float_field() {
359 return generate_fast_get_float_field0(T_FLOAT);
360 }
361
362 address JNI_FastGetField::generate_fast_get_double_field() {
363 return generate_fast_get_float_field0(T_DOUBLE);
364 }
|