Fri, 26 Jun 2009 07:26:10 -0700
5057225: Remove useless I2L conversions
Summary: The optimizer should be told to normalize (AndL (ConvI2L x) 0xFF) to (ConvI2L (AndI x 0xFF)), and then the existing matcher rule will work for free.
Reviewed-by: kvn
1 /*
2 * Copyright 1997-2009 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 *
23 */
25 #include "incls/_precompiled.incl"
26 #include "incls/_interpreter_x86_32.cpp.incl"
28 #define __ _masm->
30 // Initialize the sentinel used to distinguish an interpreter return address.
31 const int Interpreter::return_sentinel = 0xfeedbeed;
33 //------------------------------------------------------------------------------------------------------------------------
35 address AbstractInterpreterGenerator::generate_slow_signature_handler() {
36 address entry = __ pc();
37 // rbx,: method
38 // rcx: temporary
39 // rdi: pointer to locals
40 // rsp: end of copied parameters area
41 __ mov(rcx, rsp);
42 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::slow_signature_handler), rbx, rdi, rcx);
43 __ ret(0);
44 return entry;
45 }
48 //
49 // Various method entries (that c++ and asm interpreter agree upon)
50 //------------------------------------------------------------------------------------------------------------------------
51 //
52 //
54 // Empty method, generate a very fast return.
56 address InterpreterGenerator::generate_empty_entry(void) {
58 // rbx,: methodOop
59 // rcx: receiver (unused)
60 // rsi: previous interpreter state (C++ interpreter) must preserve
61 // rsi: sender sp must set sp to this value on return
63 if (!UseFastEmptyMethods) return NULL;
65 address entry_point = __ pc();
67 // If we need a safepoint check, generate full interpreter entry.
68 Label slow_path;
69 ExternalAddress state(SafepointSynchronize::address_of_state());
70 __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
71 SafepointSynchronize::_not_synchronized);
72 __ jcc(Assembler::notEqual, slow_path);
74 // do nothing for empty methods (do not even increment invocation counter)
75 // Code: _return
76 // _return
77 // return w/o popping parameters
78 __ pop(rax);
79 __ mov(rsp, rsi);
80 __ jmp(rax);
82 __ bind(slow_path);
83 (void) generate_normal_entry(false);
84 return entry_point;
85 }
87 address InterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) {
89 // rbx,: methodOop
90 // rcx: scratrch
91 // rsi: sender sp
93 if (!InlineIntrinsics) return NULL; // Generate a vanilla entry
95 address entry_point = __ pc();
97 // These don't need a safepoint check because they aren't virtually
98 // callable. We won't enter these intrinsics from compiled code.
99 // If in the future we added an intrinsic which was virtually callable
100 // we'd have to worry about how to safepoint so that this code is used.
102 // mathematical functions inlined by compiler
103 // (interpreter must provide identical implementation
104 // in order to avoid monotonicity bugs when switching
105 // from interpreter to compiler in the middle of some
106 // computation)
107 //
108 // stack: [ ret adr ] <-- rsp
109 // [ lo(arg) ]
110 // [ hi(arg) ]
111 //
113 // Note: For JDK 1.2 StrictMath doesn't exist and Math.sin/cos/sqrt are
114 // native methods. Interpreter::method_kind(...) does a check for
115 // native methods first before checking for intrinsic methods and
116 // thus will never select this entry point. Make sure it is not
117 // called accidentally since the SharedRuntime entry points will
118 // not work for JDK 1.2.
119 //
120 // We no longer need to check for JDK 1.2 since it's EOL'ed.
121 // The following check existed in pre 1.6 implementation,
122 // if (Universe::is_jdk12x_version()) {
123 // __ should_not_reach_here();
124 // }
125 // Universe::is_jdk12x_version() always returns false since
126 // the JDK version is not yet determined when this method is called.
127 // This method is called during interpreter_init() whereas
128 // JDK version is only determined when universe2_init() is called.
130 // Note: For JDK 1.3 StrictMath exists and Math.sin/cos/sqrt are
131 // java methods. Interpreter::method_kind(...) will select
132 // this entry point for the corresponding methods in JDK 1.3.
133 // get argument
134 if (TaggedStackInterpreter) {
135 __ pushl(Address(rsp, 3*wordSize)); // push hi (and note rsp -= wordSize)
136 __ pushl(Address(rsp, 2*wordSize)); // push lo
137 __ fld_d(Address(rsp, 0)); // get double in ST0
138 __ addptr(rsp, 2*wordSize);
139 } else {
140 __ fld_d(Address(rsp, 1*wordSize));
141 }
142 switch (kind) {
143 case Interpreter::java_lang_math_sin :
144 __ trigfunc('s');
145 break;
146 case Interpreter::java_lang_math_cos :
147 __ trigfunc('c');
148 break;
149 case Interpreter::java_lang_math_tan :
150 __ trigfunc('t');
151 break;
152 case Interpreter::java_lang_math_sqrt:
153 __ fsqrt();
154 break;
155 case Interpreter::java_lang_math_abs:
156 __ fabs();
157 break;
158 case Interpreter::java_lang_math_log:
159 __ flog();
160 // Store to stack to convert 80bit precision back to 64bits
161 __ push_fTOS();
162 __ pop_fTOS();
163 break;
164 case Interpreter::java_lang_math_log10:
165 __ flog10();
166 // Store to stack to convert 80bit precision back to 64bits
167 __ push_fTOS();
168 __ pop_fTOS();
169 break;
170 default :
171 ShouldNotReachHere();
172 }
174 // return double result in xmm0 for interpreter and compilers.
175 if (UseSSE >= 2) {
176 __ subptr(rsp, 2*wordSize);
177 __ fstp_d(Address(rsp, 0));
178 __ movdbl(xmm0, Address(rsp, 0));
179 __ addptr(rsp, 2*wordSize);
180 }
182 // done, result in FPU ST(0) or XMM0
183 __ pop(rdi); // get return address
184 __ mov(rsp, rsi); // set sp to sender sp
185 __ jmp(rdi);
187 return entry_point;
188 }
191 // Abstract method entry
192 // Attempt to execute abstract method. Throw exception
193 address InterpreterGenerator::generate_abstract_entry(void) {
195 // rbx,: methodOop
196 // rcx: receiver (unused)
197 // rsi: previous interpreter state (C++ interpreter) must preserve
199 // rsi: sender SP
201 address entry_point = __ pc();
203 // abstract method entry
205 // pop return address, reset last_sp to NULL
206 __ empty_expression_stack();
207 __ restore_bcp(); // rsi must be correct for exception handler (was destroyed)
208 __ restore_locals(); // make sure locals pointer is correct as well (was destroyed)
210 // throw exception
211 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
212 // the call_VM checks for exception, so we should never return here.
213 __ should_not_reach_here();
215 return entry_point;
216 }
219 // Method handle invoker
220 // Dispatch a method of the form java.dyn.MethodHandles::invoke(...)
221 address InterpreterGenerator::generate_method_handle_entry(void) {
222 if (!EnableMethodHandles) {
223 return generate_abstract_entry();
224 }
226 address entry_point = MethodHandles::generate_method_handle_interpreter_entry(_masm);
228 return entry_point;
229 }
232 // This method tells the deoptimizer how big an interpreted frame must be:
233 int AbstractInterpreter::size_activation(methodOop method,
234 int tempcount,
235 int popframe_extra_args,
236 int moncount,
237 int callee_param_count,
238 int callee_locals,
239 bool is_top_frame) {
240 return layout_activation(method,
241 tempcount,
242 popframe_extra_args,
243 moncount,
244 callee_param_count,
245 callee_locals,
246 (frame*) NULL,
247 (frame*) NULL,
248 is_top_frame);
249 }
251 void Deoptimization::unwind_callee_save_values(frame* f, vframeArray* vframe_array) {
253 // This code is sort of the equivalent of C2IAdapter::setup_stack_frame back in
254 // the days we had adapter frames. When we deoptimize a situation where a
255 // compiled caller calls a compiled caller will have registers it expects
256 // to survive the call to the callee. If we deoptimize the callee the only
257 // way we can restore these registers is to have the oldest interpreter
258 // frame that we create restore these values. That is what this routine
259 // will accomplish.
261 // At the moment we have modified c2 to not have any callee save registers
262 // so this problem does not exist and this routine is just a place holder.
264 assert(f->is_interpreted_frame(), "must be interpreted");
265 }