annotate src/cpu/x86/vm/runtime_x86_32.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 1998-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
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27 #include "incls/_runtime_x86_32.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 #define __ masm->
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 ExceptionBlob* OptoRuntime::_exception_blob;
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 //------------------------------generate_exception_blob---------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // creates exception blob at the end
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // Using exception blob, this code is jumped from a compiled method.
a61af66fc99e Initial load
duke
parents:
diff changeset
36 //
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // Given an exception pc at a call we call into the runtime for the
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // handler in this method. This handler might merely restore state
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // (i.e. callee save registers) unwind the frame and jump to the
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // exception handler for the nmethod if there is no Java level handler
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // for the nmethod.
a61af66fc99e Initial load
duke
parents:
diff changeset
42 //
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // This code is entered with a jmp.
a61af66fc99e Initial load
duke
parents:
diff changeset
44 //
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // Arguments:
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // rax,: exception oop
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // rdx: exception pc
a61af66fc99e Initial load
duke
parents:
diff changeset
48 //
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // Results:
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // rax,: exception oop
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // rdx: exception pc in caller or ???
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // destination: exception handler of caller
a61af66fc99e Initial load
duke
parents:
diff changeset
53 //
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // Note: the exception pc MUST be at a call (precise debug information)
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // Only register rax, rdx, rcx are not callee saved.
a61af66fc99e Initial load
duke
parents:
diff changeset
56 //
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 void OptoRuntime::generate_exception_blob() {
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 // Capture info about frame layout
a61af66fc99e Initial load
duke
parents:
diff changeset
61 enum layout {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 thread_off, // last_java_sp
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // The frame sender code expects that rbp will be in the "natural" place and
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // will override any oopMap setting for it. We must therefore force the layout
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // so that it agrees with the frame sender code.
a61af66fc99e Initial load
duke
parents:
diff changeset
66 rbp_off,
a61af66fc99e Initial load
duke
parents:
diff changeset
67 return_off, // slot for return address
a61af66fc99e Initial load
duke
parents:
diff changeset
68 framesize
a61af66fc99e Initial load
duke
parents:
diff changeset
69 };
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // allocate space for the code
a61af66fc99e Initial load
duke
parents:
diff changeset
72 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // setup code generation tools
a61af66fc99e Initial load
duke
parents:
diff changeset
74 CodeBuffer buffer("exception_blob", 512, 512);
a61af66fc99e Initial load
duke
parents:
diff changeset
75 MacroAssembler* masm = new MacroAssembler(&buffer);
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 OopMapSet *oop_maps = new OopMapSet();
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 address start = __ pc();
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 __ pushl(rdx);
a61af66fc99e Initial load
duke
parents:
diff changeset
82 __ subl(rsp, return_off * wordSize); // Prolog!
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // rbp, location is implicitly known
a61af66fc99e Initial load
duke
parents:
diff changeset
85 __ movl(Address(rsp,rbp_off *wordSize),rbp);
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // Store exception in Thread object. We cannot pass any arguments to the
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // handle_exception call, since we do not want to make any assumption
a61af66fc99e Initial load
duke
parents:
diff changeset
89 // about the size of the frame where the exception happened in.
a61af66fc99e Initial load
duke
parents:
diff changeset
90 __ get_thread(rcx);
a61af66fc99e Initial load
duke
parents:
diff changeset
91 __ movl(Address(rcx, JavaThread::exception_oop_offset()), rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
92 __ movl(Address(rcx, JavaThread::exception_pc_offset()), rdx);
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 // This call does all the hard work. It checks if an exception handler
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // exists in the method.
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // If so, it returns the handler address.
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // If not, it prepares for stack-unwinding, restoring the callee-save
a61af66fc99e Initial load
duke
parents:
diff changeset
98 // registers of the frame being removed.
a61af66fc99e Initial load
duke
parents:
diff changeset
99 //
a61af66fc99e Initial load
duke
parents:
diff changeset
100 __ movl(Address(rsp, thread_off * wordSize), rcx); // Thread is first argument
a61af66fc99e Initial load
duke
parents:
diff changeset
101 __ set_last_Java_frame(rcx, noreg, noreg, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, OptoRuntime::handle_exception_C)));
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // No registers to map, rbp is known implicitly
a61af66fc99e Initial load
duke
parents:
diff changeset
106 oop_maps->add_gc_map( __ pc() - start, new OopMap( framesize, 0 ));
a61af66fc99e Initial load
duke
parents:
diff changeset
107 __ get_thread(rcx);
a61af66fc99e Initial load
duke
parents:
diff changeset
108 __ reset_last_Java_frame(rcx, false, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // Restore callee-saved registers
a61af66fc99e Initial load
duke
parents:
diff changeset
111 __ movl(rbp, Address(rsp, rbp_off * wordSize));
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 __ addl(rsp, return_off * wordSize); // Epilog!
a61af66fc99e Initial load
duke
parents:
diff changeset
114 __ popl(rdx); // Exception pc
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // rax,: exception handler for given <exception oop/exception pc>
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // We have a handler in rax, (could be deopt blob)
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // rdx - throwing pc, deopt blob will need it.
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 __ pushl(rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // rcx contains handler address
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 __ get_thread(rcx); // TLS
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // Get the exception
a61af66fc99e Initial load
duke
parents:
diff changeset
128 __ movl(rax, Address(rcx, JavaThread::exception_oop_offset()));
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // Get the exception pc in case we are deoptimized
a61af66fc99e Initial load
duke
parents:
diff changeset
130 __ movl(rdx, Address(rcx, JavaThread::exception_pc_offset()));
a61af66fc99e Initial load
duke
parents:
diff changeset
131 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
132 __ movl(Address(rcx, JavaThread::exception_handler_pc_offset()), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
133 __ movl(Address(rcx, JavaThread::exception_pc_offset()), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
134 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // Clear the exception oop so GC no longer processes it as a root.
a61af66fc99e Initial load
duke
parents:
diff changeset
136 __ movl(Address(rcx, JavaThread::exception_oop_offset()), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 __ popl(rcx);
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 // rax,: exception oop
a61af66fc99e Initial load
duke
parents:
diff changeset
141 // rcx: exception handler
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // rdx: exception pc
a61af66fc99e Initial load
duke
parents:
diff changeset
143 __ jmp (rcx);
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 // -------------
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // make sure all code is generated
a61af66fc99e Initial load
duke
parents:
diff changeset
147 masm->flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 _exception_blob = ExceptionBlob::create(&buffer, oop_maps, framesize);
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }