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 *
23 */
24
25 #include "precompiled.hpp"
26 #include "interpreter/interpreter.hpp"
27 #include "interpreter/interpreterRuntime.hpp"
28 #include "interpreter/interp_masm.hpp"
29 #include "interpreter/templateInterpreter.hpp"
30 #include "interpreter/templateInterpreterGenerator.hpp"
31 #include "interpreter/templateTable.hpp"
32 #include "memory/resourceArea.hpp"
33 #include "runtime/timerTrace.hpp"
34
35 #ifndef CC_INTERP
36
37 # define __ _masm->
38
39 void TemplateInterpreter::initialize() {
40 if (_code != NULL) return;
41 // assertions
42 assert((int)Bytecodes::number_of_codes <= (int)DispatchTable::length,
43 "dispatch table too small");
44
45 AbstractInterpreter::initialize();
46
47 TemplateTable::initialize();
48
49 // generate interpreter
50 { ResourceMark rm;
51 TraceTime timer("Interpreter generation", TRACETIME_LOG(Info, startuptime));
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
284 void TemplateInterpreter::notice_safepoints() {
285 if (!_notice_safepoints) {
286 // switch to safepoint dispatch table
287 _notice_safepoints = true;
288 copy_table((address*)&_safept_table, (address*)&_active_table, sizeof(_active_table) / sizeof(address));
289 }
290 }
291
292 // switch from the dispatch table which notices safepoints back to the
293 // normal dispatch table. So that we can notice single stepping points,
294 // keep the safepoint dispatch table if we are single stepping in JVMTI.
295 // Note that the should_post_single_step test is exactly as fast as the
296 // JvmtiExport::_enabled test and covers both cases.
297 void TemplateInterpreter::ignore_safepoints() {
298 if (_notice_safepoints) {
299 if (!JvmtiExport::should_post_single_step()) {
300 // switch to normal dispatch table
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
|
1 /*
2 * Copyright (c) 1997, 2019, 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 *
23 */
24
25 #include "precompiled.hpp"
26 #include "interpreter/interpreter.hpp"
27 #include "interpreter/interpreterRuntime.hpp"
28 #include "interpreter/interp_masm.hpp"
29 #include "interpreter/templateInterpreter.hpp"
30 #include "interpreter/templateInterpreterGenerator.hpp"
31 #include "interpreter/templateTable.hpp"
32 #include "logging/log.hpp"
33 #include "memory/resourceArea.hpp"
34 #include "runtime/timerTrace.hpp"
35
36 #ifndef CC_INTERP
37
38 # define __ _masm->
39
40 void TemplateInterpreter::initialize() {
41 if (_code != NULL) return;
42 // assertions
43 assert((int)Bytecodes::number_of_codes <= (int)DispatchTable::length,
44 "dispatch table too small");
45
46 AbstractInterpreter::initialize();
47
48 TemplateTable::initialize();
49
50 // generate interpreter
51 { ResourceMark rm;
52 TraceTime timer("Interpreter generation", TRACETIME_LOG(Info, startuptime));
267 //------------------------------------------------------------------------------------------------------------------------
268 // Suport for invokes
269
270 int TemplateInterpreter::TosState_as_index(TosState state) {
271 assert( state < number_of_states , "Invalid state in TosState_as_index");
272 assert(0 <= (int)state && (int)state < TemplateInterpreter::number_of_return_addrs, "index out of bounds");
273 return (int)state;
274 }
275
276
277 //------------------------------------------------------------------------------------------------------------------------
278 // Safepoint suppport
279
280 static inline void copy_table(address* from, address* to, int size) {
281 // Copy non-overlapping tables. The copy has to occur word wise for MT safety.
282 while (size-- > 0) *to++ = *from++;
283 }
284
285 void TemplateInterpreter::notice_safepoints() {
286 if (!_notice_safepoints) {
287 log_debug(interpreter, safepoint)("switching active_table to safept_table.");
288 // switch to safepoint dispatch table
289 _notice_safepoints = true;
290 copy_table((address*)&_safept_table, (address*)&_active_table, sizeof(_active_table) / sizeof(address));
291 } else {
292 log_debug(interpreter, safepoint)("active_table is already safept_table; "
293 "notice_safepoints() call is no-op.");
294 }
295 }
296
297 // switch from the dispatch table which notices safepoints back to the
298 // normal dispatch table. So that we can notice single stepping points,
299 // keep the safepoint dispatch table if we are single stepping in JVMTI.
300 // Note that the should_post_single_step test is exactly as fast as the
301 // JvmtiExport::_enabled test and covers both cases.
302 void TemplateInterpreter::ignore_safepoints() {
303 if (_notice_safepoints) {
304 if (!JvmtiExport::should_post_single_step()) {
305 log_debug(interpreter, safepoint)("switching active_table to normal_table.");
306 // switch to normal dispatch table
307 _notice_safepoints = false;
308 copy_table((address*)&_normal_table, (address*)&_active_table, sizeof(_active_table) / sizeof(address));
309 } else {
310 log_debug(interpreter, safepoint)("single stepping is still active; "
311 "ignoring ignore_safepoints() call.");
312 }
313 } else {
314 log_debug(interpreter, safepoint)("active_table is already normal_table; "
315 "ignore_safepoints() call is no-op.");
316 }
317 }
318
319 //------------------------------------------------------------------------------------------------------------------------
320 // Deoptimization support
321
322 // If deoptimization happens, this function returns the point of next bytecode to continue execution
323 address TemplateInterpreter::deopt_continue_after_entry(Method* method, address bcp, int callee_parameters, bool is_top_frame) {
324 return AbstractInterpreter::deopt_continue_after_entry(method, bcp, callee_parameters, is_top_frame);
325 }
326
327 // If deoptimization happens, this function returns the point where the interpreter reexecutes
328 // the bytecode.
329 // Note: Bytecodes::_athrow (C1 only) and Bytecodes::_return are the special cases
330 // that do not return "Interpreter::deopt_entry(vtos, 0)"
331 address TemplateInterpreter::deopt_reexecute_entry(Method* method, address bcp) {
332 assert(method->contains(bcp), "just checkin'");
333 Bytecodes::Code code = Bytecodes::code_at(method, bcp);
334 if (code == Bytecodes::_return_register_finalizer) {
335 // This is used for deopt during registration of finalizers
|