9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #include "precompiled.hpp"
27 #ifndef CC_INTERP
28 #include "asm/macroAssembler.inline.hpp"
29 #include "interpreter/bytecodeHistogram.hpp"
30 #include "interpreter/interpreter.hpp"
31 #include "interpreter/interpreterGenerator.hpp"
32 #include "interpreter/interpreterRuntime.hpp"
33 #include "interpreter/templateTable.hpp"
34 #include "oops/arrayOop.hpp"
35 #include "oops/methodData.hpp"
36 #include "oops/method.hpp"
37 #include "oops/oop.inline.hpp"
38 #include "prims/jvmtiExport.hpp"
39 #include "prims/jvmtiThreadState.hpp"
40 #include "runtime/arguments.hpp"
41 #include "runtime/deoptimization.hpp"
42 #include "runtime/frame.inline.hpp"
43 #include "runtime/sharedRuntime.hpp"
44 #include "runtime/stubRoutines.hpp"
45 #include "runtime/synchronizer.hpp"
46 #include "runtime/timer.hpp"
47 #include "runtime/vframeArray.hpp"
48 #include "utilities/debug.hpp"
1317
1318 if (entry_point) {
1319 return entry_point;
1320 }
1321
1322 return ((InterpreterGenerator*) this)->generate_normal_entry(synchronized);
1323 }
1324
1325 // These should never be compiled since the interpreter will prefer
1326 // the compiled version to the intrinsic version.
1327 bool AbstractInterpreter::can_be_compiled(methodHandle m) {
1328 return !math_entry_available(method_kind(m));
1329 }
1330
1331 // How much stack a method activation needs in stack slots.
1332 // We must calc this exactly like in generate_fixed_frame.
1333 // Note: This returns the conservative size assuming maximum alignment.
1334 int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
1335 const int max_alignment_size = 2;
1336 const int abi_scratch = frame::abi_reg_args_size;
1337 return method->max_locals() + method->max_stack() + frame::interpreter_frame_monitor_size() + max_alignment_size + abi_scratch;
1338 }
1339
1340 // Fills a sceletal interpreter frame generated during deoptimizations
1341 // and returns the frame size in slots.
1342 //
1343 // Parameters:
1344 //
1345 // interpreter_frame == NULL:
1346 // Only calculate the size of an interpreter activation, no actual layout.
1347 // Note: This calculation must exactly parallel the frame setup
1348 // in TemplateInterpreter::generate_normal_entry. But it does not
1349 // account for the SP alignment, that might further enhance the
1350 // frame size, depending on FP.
1351 //
1352 // interpreter_frame != NULL:
1353 // set up the method, locals, and monitors.
1354 // The frame interpreter_frame, if not NULL, is guaranteed to be the
1355 // right size, as determined by a previous call to this method.
1356 // It is also guaranteed to be walkable even though it is in a skeletal state
1357 //
1358 // is_top_frame == true:
1359 // We're processing the *oldest* interpreter frame!
1360 //
1361 // pop_frame_extra_args:
1362 // If this is != 0 we are returning to a deoptimized frame by popping
1363 // off the callee frame. We want to re-execute the call that called the
1364 // callee interpreted, but since the return to the interpreter would pop
1365 // the arguments off advance the esp by dummy popframe_extra_args slots.
1366 // Popping off those will establish the stack layout as it was before the call.
1367 //
1368 int AbstractInterpreter::layout_activation(Method* method,
1369 int tempcount,
1370 int popframe_extra_args,
1371 int moncount,
1372 int caller_actual_parameters,
1373 int callee_param_count,
1374 int callee_locals,
1375 frame* caller,
1376 frame* interpreter_frame,
1377 bool is_top_frame,
1378 bool is_bottom_frame) {
1379
1380 const int max_alignment_space = 2;
1381 const int abi_scratch = is_top_frame ? (frame::abi_reg_args_size / Interpreter::stackElementSize) :
1382 (frame::abi_minframe_size / Interpreter::stackElementSize) ;
1383 const int conservative_framesize_in_slots =
1384 method->max_stack() + callee_locals - callee_param_count +
1385 (moncount * frame::interpreter_frame_monitor_size()) + max_alignment_space +
1386 abi_scratch + frame::ijava_state_size / Interpreter::stackElementSize;
1387
1388 assert(!is_top_frame || conservative_framesize_in_slots * 8 > frame::abi_reg_args_size + frame::ijava_state_size, "frame too small");
1389
1390 if (interpreter_frame == NULL) {
1391 // Since we don't know the exact alignment, we return the conservative size.
1392 return (conservative_framesize_in_slots & -2);
1393 } else {
1394 // Now we know our caller, calc the exact frame layout and size.
1395 intptr_t* locals_base = (caller->is_interpreted_frame()) ?
1396 caller->interpreter_frame_esp() + caller_actual_parameters :
1397 caller->sp() + method->max_locals() - 1 + (frame::abi_minframe_size / Interpreter::stackElementSize) ;
1398
1399 intptr_t* monitor_base = caller->sp() - frame::ijava_state_size / Interpreter::stackElementSize ;
1400 intptr_t* monitor = monitor_base - (moncount * frame::interpreter_frame_monitor_size());
1401 intptr_t* esp_base = monitor - 1;
1402 intptr_t* esp = esp_base - tempcount - popframe_extra_args;
1403 intptr_t* sp = (intptr_t *) (((intptr_t) (esp_base- callee_locals + callee_param_count - method->max_stack()- abi_scratch)) & -StackAlignmentInBytes);
1404 intptr_t* sender_sp = caller->sp() + (frame::abi_minframe_size - frame::abi_reg_args_size) / Interpreter::stackElementSize;
1405 intptr_t* top_frame_sp = is_top_frame ? sp : sp + (frame::abi_minframe_size - frame::abi_reg_args_size) / Interpreter::stackElementSize;
1406
1407 interpreter_frame->interpreter_frame_set_method(method);
1408 interpreter_frame->interpreter_frame_set_locals(locals_base);
1409 interpreter_frame->interpreter_frame_set_cpcache(method->constants()->cache());
1410 interpreter_frame->interpreter_frame_set_esp(esp);
1411 interpreter_frame->interpreter_frame_set_monitor_end((BasicObjectLock *)monitor);
1412 interpreter_frame->interpreter_frame_set_top_frame_sp(top_frame_sp);
1413 if (!is_bottom_frame) {
1414 interpreter_frame->interpreter_frame_set_sender_sp(sender_sp);
1415 }
1416
1417 int framesize_in_slots = caller->sp() - sp;
1418 assert(!is_top_frame ||framesize_in_slots >= (frame::abi_reg_args_size / Interpreter::stackElementSize) + frame::ijava_state_size / Interpreter::stackElementSize, "frame too small");
1419 assert(framesize_in_slots <= conservative_framesize_in_slots, "exact frame size must be smaller than the convervative size!");
1420 return framesize_in_slots;
1421 }
1422 }
1423
1424 // =============================================================================
1425 // Exceptions
1426
1427 void TemplateInterpreterGenerator::generate_throw_exception() {
1428 Register Rexception = R17_tos,
1429 Rcontinuation = R3_RET;
1430
1431 // --------------------------------------------------------------------------
1432 // Entry point if an method returns with a pending exception (rethrow).
1433 Interpreter::_rethrow_exception_entry = __ pc();
1434 {
1435 __ restore_interpreter_state(R11_scratch1); // Sets R11_scratch1 = fp.
1436 __ ld(R12_scratch2, _ijava_state_neg(top_frame_sp), R11_scratch1);
1437 __ resize_frame_absolute(R12_scratch2, R11_scratch1, R0);
1438
1439 // Compiled code destroys templateTableBase, reload.
1440 __ load_const_optimized(R25_templateTableBase, (address)Interpreter::dispatch_table((TosState)0), R11_scratch1);
|
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #include "precompiled.hpp"
27 #ifndef CC_INTERP
28 #include "asm/macroAssembler.inline.hpp"
29 #include "ci/ciMethod.hpp"
30 #include "interpreter/bytecodeHistogram.hpp"
31 #include "interpreter/interpreter.hpp"
32 #include "interpreter/interpreterGenerator.hpp"
33 #include "interpreter/interpreterRuntime.hpp"
34 #include "interpreter/templateTable.hpp"
35 #include "oops/arrayOop.hpp"
36 #include "oops/methodData.hpp"
37 #include "oops/method.hpp"
38 #include "oops/oop.inline.hpp"
39 #include "prims/jvmtiExport.hpp"
40 #include "prims/jvmtiThreadState.hpp"
41 #include "runtime/arguments.hpp"
42 #include "runtime/deoptimization.hpp"
43 #include "runtime/frame.inline.hpp"
44 #include "runtime/sharedRuntime.hpp"
45 #include "runtime/stubRoutines.hpp"
46 #include "runtime/synchronizer.hpp"
47 #include "runtime/timer.hpp"
48 #include "runtime/vframeArray.hpp"
49 #include "utilities/debug.hpp"
1318
1319 if (entry_point) {
1320 return entry_point;
1321 }
1322
1323 return ((InterpreterGenerator*) this)->generate_normal_entry(synchronized);
1324 }
1325
1326 // These should never be compiled since the interpreter will prefer
1327 // the compiled version to the intrinsic version.
1328 bool AbstractInterpreter::can_be_compiled(methodHandle m) {
1329 return !math_entry_available(method_kind(m));
1330 }
1331
1332 // How much stack a method activation needs in stack slots.
1333 // We must calc this exactly like in generate_fixed_frame.
1334 // Note: This returns the conservative size assuming maximum alignment.
1335 int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
1336 const int max_alignment_size = 2;
1337 const int abi_scratch = frame::abi_reg_args_size;
1338 return method->max_locals() + method->max_stack() +
1339 frame::interpreter_frame_monitor_size() + max_alignment_size + abi_scratch;
1340 }
1341
1342 // Returns number of stackElementWords needed for the interpreter frame with the
1343 // given sections.
1344 // This overestimates the stack by one slot in case of alignments.
1345 int AbstractInterpreter::size_activation(int max_stack,
1346 int temps,
1347 int popframe_args,
1348 int monitors,
1349 int callee_params,
1350 int callee_locals,
1351 bool is_top_frame) {
1352 // Note: This calculation must exactly parallel the frame setup
1353 // in AbstractInterpreterGenerator::generate_method_entry.
1354 assert(Interpreter::stackElementWords == 1, "sanity");
1355 const int max_alignment_space = StackAlignmentInBytes / Interpreter::stackElementSize;
1356 const int abi_scratch = is_top_frame ? (frame::abi_reg_args_size / Interpreter::stackElementSize) :
1357 (frame::abi_minframe_size / Interpreter::stackElementSize);
1358 const int size =
1359 max_stack +
1360 (callee_locals - callee_params) +
1361 monitors * frame::interpreter_frame_monitor_size() +
1362 max_alignment_space +
1363 abi_scratch +
1364 frame::ijava_state_size / Interpreter::stackElementSize;
1365
1366 // Fixed size of an interpreter frame, align to 16-byte.
1367 return (size & -2);
1368 }
1369
1370 // Fills a sceletal interpreter frame generated during deoptimizations.
1371 //
1372 // Parameters:
1373 //
1374 // interpreter_frame != NULL:
1375 // set up the method, locals, and monitors.
1376 // The frame interpreter_frame, if not NULL, is guaranteed to be the
1377 // right size, as determined by a previous call to this method.
1378 // It is also guaranteed to be walkable even though it is in a skeletal state
1379 //
1380 // is_top_frame == true:
1381 // We're processing the *oldest* interpreter frame!
1382 //
1383 // pop_frame_extra_args:
1384 // If this is != 0 we are returning to a deoptimized frame by popping
1385 // off the callee frame. We want to re-execute the call that called the
1386 // callee interpreted, but since the return to the interpreter would pop
1387 // the arguments off advance the esp by dummy popframe_extra_args slots.
1388 // Popping off those will establish the stack layout as it was before the call.
1389 //
1390 void AbstractInterpreter::layout_activation(Method* method,
1391 int tempcount,
1392 int popframe_extra_args,
1393 int moncount,
1394 int caller_actual_parameters,
1395 int callee_param_count,
1396 int callee_locals_count,
1397 frame* caller,
1398 frame* interpreter_frame,
1399 bool is_top_frame,
1400 bool is_bottom_frame) {
1401
1402 const int abi_scratch = is_top_frame ? (frame::abi_reg_args_size / Interpreter::stackElementSize) :
1403 (frame::abi_minframe_size / Interpreter::stackElementSize);
1404
1405 intptr_t* locals_base = (caller->is_interpreted_frame()) ?
1406 caller->interpreter_frame_esp() + caller_actual_parameters :
1407 caller->sp() + method->max_locals() - 1 + (frame::abi_minframe_size / Interpreter::stackElementSize) ;
1408
1409 intptr_t* monitor_base = caller->sp() - frame::ijava_state_size / Interpreter::stackElementSize ;
1410 intptr_t* monitor = monitor_base - (moncount * frame::interpreter_frame_monitor_size());
1411 intptr_t* esp_base = monitor - 1;
1412 intptr_t* esp = esp_base - tempcount - popframe_extra_args;
1413 intptr_t* sp = (intptr_t *) (((intptr_t) (esp_base - callee_locals_count + callee_param_count - method->max_stack()- abi_scratch)) & -StackAlignmentInBytes);
1414 intptr_t* sender_sp = caller->sp() + (frame::abi_minframe_size - frame::abi_reg_args_size) / Interpreter::stackElementSize;
1415 intptr_t* top_frame_sp = is_top_frame ? sp : sp + (frame::abi_minframe_size - frame::abi_reg_args_size) / Interpreter::stackElementSize;
1416
1417 interpreter_frame->interpreter_frame_set_method(method);
1418 interpreter_frame->interpreter_frame_set_locals(locals_base);
1419 interpreter_frame->interpreter_frame_set_cpcache(method->constants()->cache());
1420 interpreter_frame->interpreter_frame_set_esp(esp);
1421 interpreter_frame->interpreter_frame_set_monitor_end((BasicObjectLock *)monitor);
1422 interpreter_frame->interpreter_frame_set_top_frame_sp(top_frame_sp);
1423 if (!is_bottom_frame) {
1424 interpreter_frame->interpreter_frame_set_sender_sp(sender_sp);
1425 }
1426 }
1427
1428 // =============================================================================
1429 // Exceptions
1430
1431 void TemplateInterpreterGenerator::generate_throw_exception() {
1432 Register Rexception = R17_tos,
1433 Rcontinuation = R3_RET;
1434
1435 // --------------------------------------------------------------------------
1436 // Entry point if an method returns with a pending exception (rethrow).
1437 Interpreter::_rethrow_exception_entry = __ pc();
1438 {
1439 __ restore_interpreter_state(R11_scratch1); // Sets R11_scratch1 = fp.
1440 __ ld(R12_scratch2, _ijava_state_neg(top_frame_sp), R11_scratch1);
1441 __ resize_frame_absolute(R12_scratch2, R11_scratch1, R0);
1442
1443 // Compiled code destroys templateTableBase, reload.
1444 __ load_const_optimized(R25_templateTableBase, (address)Interpreter::dispatch_table((TosState)0), R11_scratch1);
|