1 /*
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
178 }
179
180 address TemplateInterpreter::_remove_activation_entry = NULL;
181 address TemplateInterpreter::_remove_activation_preserving_args_entry = NULL;
182
183
184 address TemplateInterpreter::_throw_ArrayIndexOutOfBoundsException_entry = NULL;
185 address TemplateInterpreter::_throw_ArrayStoreException_entry = NULL;
186 address TemplateInterpreter::_throw_ArithmeticException_entry = NULL;
187 address TemplateInterpreter::_throw_ClassCastException_entry = NULL;
188 address TemplateInterpreter::_throw_NullPointerException_entry = NULL;
189 address TemplateInterpreter::_throw_StackOverflowError_entry = NULL;
190 address TemplateInterpreter::_throw_exception_entry = NULL;
191
192 #ifndef PRODUCT
193 EntryPoint TemplateInterpreter::_trace_code;
194 #endif // !PRODUCT
195 EntryPoint TemplateInterpreter::_return_entry[TemplateInterpreter::number_of_return_entries];
196 EntryPoint TemplateInterpreter::_earlyret_entry;
197 EntryPoint TemplateInterpreter::_deopt_entry [TemplateInterpreter::number_of_deopt_entries ];
198 EntryPoint TemplateInterpreter::_safept_entry;
199
200 address TemplateInterpreter::_invoke_return_entry[TemplateInterpreter::number_of_return_addrs];
201 address TemplateInterpreter::_invokeinterface_return_entry[TemplateInterpreter::number_of_return_addrs];
202 address TemplateInterpreter::_invokedynamic_return_entry[TemplateInterpreter::number_of_return_addrs];
203
204 DispatchTable TemplateInterpreter::_active_table;
205 DispatchTable TemplateInterpreter::_normal_table;
206 DispatchTable TemplateInterpreter::_safept_table;
207 address TemplateInterpreter::_wentry_point[DispatchTable::length];
208
209
210 //------------------------------------------------------------------------------------------------------------------------
211 // Entry points
212
213 /**
214 * Returns the return entry table for the given invoke bytecode.
215 */
216 address* TemplateInterpreter::invoke_return_entry_table_for(Bytecodes::Code code) {
217 switch (code) {
231 }
232
233 /**
234 * Returns the return entry address for the given top-of-stack state and bytecode.
235 */
236 address TemplateInterpreter::return_entry(TosState state, int length, Bytecodes::Code code) {
237 guarantee(0 <= length && length < Interpreter::number_of_return_entries, "illegal length");
238 const int index = TosState_as_index(state);
239 switch (code) {
240 case Bytecodes::_invokestatic:
241 case Bytecodes::_invokespecial:
242 case Bytecodes::_invokevirtual:
243 case Bytecodes::_invokehandle:
244 return _invoke_return_entry[index];
245 case Bytecodes::_invokeinterface:
246 return _invokeinterface_return_entry[index];
247 case Bytecodes::_invokedynamic:
248 return _invokedynamic_return_entry[index];
249 default:
250 assert(!Bytecodes::is_invoke(code), "invoke instructions should be handled separately: %s", Bytecodes::name(code));
251 return _return_entry[length].entry(state);
252 }
253 }
254
255
256 address TemplateInterpreter::deopt_entry(TosState state, int length) {
257 guarantee(0 <= length && length < Interpreter::number_of_deopt_entries, "illegal length");
258 return _deopt_entry[length].entry(state);
259 }
260
261 //------------------------------------------------------------------------------------------------------------------------
262 // Suport for invokes
263
264 int TemplateInterpreter::TosState_as_index(TosState state) {
265 assert( state < number_of_states , "Invalid state in TosState_as_index");
266 assert(0 <= (int)state && (int)state < TemplateInterpreter::number_of_return_addrs, "index out of bounds");
267 return (int)state;
268 }
269
270
271 //------------------------------------------------------------------------------------------------------------------------
272 // Safepoint suppport
273
274 static inline void copy_table(address* from, address* to, int size) {
275 // Copy non-overlapping tables. The copy has to occur word wise for MT safety.
276 while (size-- > 0) *to++ = *from++;
277 }
278
296 _notice_safepoints = false;
297 copy_table((address*)&_normal_table, (address*)&_active_table, sizeof(_active_table) / sizeof(address));
298 }
299 }
300 }
301
302 //------------------------------------------------------------------------------------------------------------------------
303 // Deoptimization support
304
305 // If deoptimization happens, this function returns the point of next bytecode to continue execution
306 address TemplateInterpreter::deopt_continue_after_entry(Method* method, address bcp, int callee_parameters, bool is_top_frame) {
307 return AbstractInterpreter::deopt_continue_after_entry(method, bcp, callee_parameters, is_top_frame);
308 }
309
310 // If deoptimization happens, this function returns the point where the interpreter reexecutes
311 // the bytecode.
312 // Note: Bytecodes::_athrow (C1 only) and Bytecodes::_return are the special cases
313 // that do not return "Interpreter::deopt_entry(vtos, 0)"
314 address TemplateInterpreter::deopt_reexecute_entry(Method* method, address bcp) {
315 assert(method->contains(bcp), "just checkin'");
316 Bytecodes::Code code = Bytecodes::java_code_at(method, bcp);
317 if (code == Bytecodes::_return) {
318 // This is used for deopt during registration of finalizers
319 // during Object.<init>. We simply need to resume execution at
320 // the standard return vtos bytecode to pop the frame normally.
321 // reexecuting the real bytecode would cause double registration
322 // of the finalizable object.
323 return _normal_table.entry(Bytecodes::_return).entry(vtos);
324 } else {
325 return AbstractInterpreter::deopt_reexecute_entry(method, bcp);
326 }
327 }
328
329 // If deoptimization happens, the interpreter should reexecute this bytecode.
330 // This function mainly helps the compilers to set up the reexecute bit.
331 bool TemplateInterpreter::bytecode_should_reexecute(Bytecodes::Code code) {
332 if (code == Bytecodes::_return) {
333 //Yes, we consider Bytecodes::_return as a special case of reexecution
334 return true;
335 } else {
336 return AbstractInterpreter::bytecode_should_reexecute(code);
337 }
338 }
339
340 InterpreterCodelet* TemplateInterpreter::codelet_containing(address pc) {
341 return (InterpreterCodelet*)_code->stub_containing(pc);
342 }
343
|
1 /*
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
178 }
179
180 address TemplateInterpreter::_remove_activation_entry = NULL;
181 address TemplateInterpreter::_remove_activation_preserving_args_entry = NULL;
182
183
184 address TemplateInterpreter::_throw_ArrayIndexOutOfBoundsException_entry = NULL;
185 address TemplateInterpreter::_throw_ArrayStoreException_entry = NULL;
186 address TemplateInterpreter::_throw_ArithmeticException_entry = NULL;
187 address TemplateInterpreter::_throw_ClassCastException_entry = NULL;
188 address TemplateInterpreter::_throw_NullPointerException_entry = NULL;
189 address TemplateInterpreter::_throw_StackOverflowError_entry = NULL;
190 address TemplateInterpreter::_throw_exception_entry = NULL;
191
192 #ifndef PRODUCT
193 EntryPoint TemplateInterpreter::_trace_code;
194 #endif // !PRODUCT
195 EntryPoint TemplateInterpreter::_return_entry[TemplateInterpreter::number_of_return_entries];
196 EntryPoint TemplateInterpreter::_earlyret_entry;
197 EntryPoint TemplateInterpreter::_deopt_entry [TemplateInterpreter::number_of_deopt_entries ];
198 address TemplateInterpreter::_deopt_reexecute_return_entry;
199 EntryPoint TemplateInterpreter::_safept_entry;
200
201 address TemplateInterpreter::_invoke_return_entry[TemplateInterpreter::number_of_return_addrs];
202 address TemplateInterpreter::_invokeinterface_return_entry[TemplateInterpreter::number_of_return_addrs];
203 address TemplateInterpreter::_invokedynamic_return_entry[TemplateInterpreter::number_of_return_addrs];
204
205 DispatchTable TemplateInterpreter::_active_table;
206 DispatchTable TemplateInterpreter::_normal_table;
207 DispatchTable TemplateInterpreter::_safept_table;
208 address TemplateInterpreter::_wentry_point[DispatchTable::length];
209
210
211 //------------------------------------------------------------------------------------------------------------------------
212 // Entry points
213
214 /**
215 * Returns the return entry table for the given invoke bytecode.
216 */
217 address* TemplateInterpreter::invoke_return_entry_table_for(Bytecodes::Code code) {
218 switch (code) {
232 }
233
234 /**
235 * Returns the return entry address for the given top-of-stack state and bytecode.
236 */
237 address TemplateInterpreter::return_entry(TosState state, int length, Bytecodes::Code code) {
238 guarantee(0 <= length && length < Interpreter::number_of_return_entries, "illegal length");
239 const int index = TosState_as_index(state);
240 switch (code) {
241 case Bytecodes::_invokestatic:
242 case Bytecodes::_invokespecial:
243 case Bytecodes::_invokevirtual:
244 case Bytecodes::_invokehandle:
245 return _invoke_return_entry[index];
246 case Bytecodes::_invokeinterface:
247 return _invokeinterface_return_entry[index];
248 case Bytecodes::_invokedynamic:
249 return _invokedynamic_return_entry[index];
250 default:
251 assert(!Bytecodes::is_invoke(code), "invoke instructions should be handled separately: %s", Bytecodes::name(code));
252 address entry = _return_entry[length].entry(state);
253 vmassert(entry != NULL, "unsupported return entry requested, length=%d state=%d", length, index);
254 return entry;
255 }
256 }
257
258
259 address TemplateInterpreter::deopt_entry(TosState state, int length) {
260 guarantee(0 <= length && length < Interpreter::number_of_deopt_entries, "illegal length");
261 address entry = _deopt_entry[length].entry(state);
262 vmassert(entry != NULL, "unsupported deopt entry requested, length=%d state=%d", length, TosState_as_index(state));
263 return entry;
264 }
265
266 //------------------------------------------------------------------------------------------------------------------------
267 // Suport for invokes
268
269 int TemplateInterpreter::TosState_as_index(TosState state) {
270 assert( state < number_of_states , "Invalid state in TosState_as_index");
271 assert(0 <= (int)state && (int)state < TemplateInterpreter::number_of_return_addrs, "index out of bounds");
272 return (int)state;
273 }
274
275
276 //------------------------------------------------------------------------------------------------------------------------
277 // Safepoint suppport
278
279 static inline void copy_table(address* from, address* to, int size) {
280 // Copy non-overlapping tables. The copy has to occur word wise for MT safety.
281 while (size-- > 0) *to++ = *from++;
282 }
283
301 _notice_safepoints = false;
302 copy_table((address*)&_normal_table, (address*)&_active_table, sizeof(_active_table) / sizeof(address));
303 }
304 }
305 }
306
307 //------------------------------------------------------------------------------------------------------------------------
308 // Deoptimization support
309
310 // If deoptimization happens, this function returns the point of next bytecode to continue execution
311 address TemplateInterpreter::deopt_continue_after_entry(Method* method, address bcp, int callee_parameters, bool is_top_frame) {
312 return AbstractInterpreter::deopt_continue_after_entry(method, bcp, callee_parameters, is_top_frame);
313 }
314
315 // If deoptimization happens, this function returns the point where the interpreter reexecutes
316 // the bytecode.
317 // Note: Bytecodes::_athrow (C1 only) and Bytecodes::_return are the special cases
318 // that do not return "Interpreter::deopt_entry(vtos, 0)"
319 address TemplateInterpreter::deopt_reexecute_entry(Method* method, address bcp) {
320 assert(method->contains(bcp), "just checkin'");
321 Bytecodes::Code code = Bytecodes::code_at(method, bcp);
322 if (code == Bytecodes::_return_register_finalizer) {
323 // This is used for deopt during registration of finalizers
324 // during Object.<init>. We simply need to resume execution at
325 // the standard return vtos bytecode to pop the frame normally.
326 // reexecuting the real bytecode would cause double registration
327 // of the finalizable object.
328 return Interpreter::deopt_reexecute_return_entry();
329 } else {
330 return AbstractInterpreter::deopt_reexecute_entry(method, bcp);
331 }
332 }
333
334 // If deoptimization happens, the interpreter should reexecute this bytecode.
335 // This function mainly helps the compilers to set up the reexecute bit.
336 bool TemplateInterpreter::bytecode_should_reexecute(Bytecodes::Code code) {
337 if (code == Bytecodes::_return) {
338 //Yes, we consider Bytecodes::_return as a special case of reexecution
339 return true;
340 } else {
341 return AbstractInterpreter::bytecode_should_reexecute(code);
342 }
343 }
344
345 InterpreterCodelet* TemplateInterpreter::codelet_containing(address pc) {
346 return (InterpreterCodelet*)_code->stub_containing(pc);
347 }
348
|