1 /*
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
3 * Copyright 2013, 2015 SAP AG. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
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 *
589 else {
590 __ std(R12_scratch2, _ijava_state_neg(monitors), R1_SP);
591 __ std(R12_scratch2, _ijava_state_neg(bcp), R1_SP);
592 __ std(R12_scratch2, _ijava_state_neg(mdx), R1_SP);
593 }
594 __ std(R11_scratch1, _ijava_state_neg(ijava_reserved), R1_SP);
595 __ std(R12_scratch2, _ijava_state_neg(esp), R1_SP);
596 __ std(R12_scratch2, _ijava_state_neg(lresult), R1_SP);
597 __ std(R12_scratch2, _ijava_state_neg(fresult), R1_SP);
598 #endif
599 __ subf(R12_scratch2, top_frame_size, R1_SP);
600 __ std(R0, _ijava_state_neg(oop_tmp), R1_SP);
601 __ std(R12_scratch2, _ijava_state_neg(top_frame_sp), R1_SP);
602
603 // Push top frame.
604 __ push_frame(top_frame_size, R11_scratch1);
605 }
606
607 // End of helpers
608
609
610 // Support abs and sqrt like in compiler.
611 // For others we can use a normal (native) entry.
612
613 inline bool math_entry_available(AbstractInterpreter::MethodKind kind) {
614 if (!InlineIntrinsics) return false;
615
616 return ((kind==Interpreter::java_lang_math_sqrt && VM_Version::has_fsqrt()) ||
617 (kind==Interpreter::java_lang_math_abs));
618 }
619
620 address TemplateInterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) {
621 if (!math_entry_available(kind)) {
622 NOT_PRODUCT(__ should_not_reach_here();)
623 return NULL;
624 }
625
626 address entry = __ pc();
627
628 __ lfd(F1_RET, Interpreter::stackElementSize, R15_esp);
629
630 // Pop c2i arguments (if any) off when we return.
631 #ifdef ASSERT
632 __ ld(R9_ARG7, 0, R1_SP);
633 __ ld(R10_ARG8, 0, R21_sender_SP);
634 __ cmpd(CCR0, R9_ARG7, R10_ARG8);
635 __ asm_assert_eq("backlink", 0x545);
636 #endif // ASSERT
637 __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started.
638
639 if (kind == Interpreter::java_lang_math_sqrt) {
640 __ fsqrt(F1_RET, F1_RET);
641 } else if (kind == Interpreter::java_lang_math_abs) {
1384
1385 StubRoutines::ppc64::generate_load_crc_table_addr(_masm, table);
1386
1387 // Performance measurements show the 1word and 2word variants to be almost equivalent,
1388 // with very light advantages for the 1word variant. We chose the 1word variant for
1389 // code compactness.
1390 __ kernel_crc32_1word(crc, data, dataLen, table, t0, t1, t2, t3, tc0, tc1, tc2, tc3);
1391
1392 // Restore caller sp for c2i case and return.
1393 __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started.
1394 __ blr();
1395
1396 // Generate a vanilla native entry as the slow path.
1397 BLOCK_COMMENT("} CRC32_updateBytes(Buffer)");
1398 BIND(slow_path);
1399 __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::native), R11_scratch1);
1400 return start;
1401 }
1402
1403 return NULL;
1404 }
1405
1406 // These should never be compiled since the interpreter will prefer
1407 // the compiled version to the intrinsic version.
1408 bool AbstractInterpreter::can_be_compiled(methodHandle m) {
1409 return !math_entry_available(method_kind(m));
1410 }
1411
1412 // How much stack a method activation needs in stack slots.
1413 // We must calc this exactly like in generate_fixed_frame.
1414 // Note: This returns the conservative size assuming maximum alignment.
1415 int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
1416 const int max_alignment_size = 2;
1417 const int abi_scratch = frame::abi_reg_args_size;
1418 return method->max_locals() + method->max_stack() +
1419 frame::interpreter_frame_monitor_size() + max_alignment_size + abi_scratch;
1420 }
1421
1422 // Returns number of stackElementWords needed for the interpreter frame with the
1423 // given sections.
1424 // This overestimates the stack by one slot in case of alignments.
1425 int AbstractInterpreter::size_activation(int max_stack,
1426 int temps,
1427 int extra_args,
1428 int monitors,
1429 int callee_params,
1430 int callee_locals,
1431 bool is_top_frame) {
1432 // Note: This calculation must exactly parallel the frame setup
1433 // in InterpreterGenerator::generate_fixed_frame.
1434 assert(Interpreter::stackElementWords == 1, "sanity");
1435 const int max_alignment_space = StackAlignmentInBytes / Interpreter::stackElementSize;
1436 const int abi_scratch = is_top_frame ? (frame::abi_reg_args_size / Interpreter::stackElementSize) :
1437 (frame::abi_minframe_size / Interpreter::stackElementSize);
1438 const int size =
1439 max_stack +
1440 (callee_locals - callee_params) +
1441 monitors * frame::interpreter_frame_monitor_size() +
1442 max_alignment_space +
1443 abi_scratch +
1444 frame::ijava_state_size / Interpreter::stackElementSize;
1445
1446 // Fixed size of an interpreter frame, align to 16-byte.
1447 return (size & -2);
1448 }
1449
1450 // Fills a sceletal interpreter frame generated during deoptimizations.
1451 //
1452 // Parameters:
1453 //
1454 // interpreter_frame != NULL:
1455 // set up the method, locals, and monitors.
1456 // The frame interpreter_frame, if not NULL, is guaranteed to be the
1457 // right size, as determined by a previous call to this method.
1458 // It is also guaranteed to be walkable even though it is in a skeletal state
1459 //
1460 // is_top_frame == true:
1461 // We're processing the *oldest* interpreter frame!
1462 //
1463 // pop_frame_extra_args:
1464 // If this is != 0 we are returning to a deoptimized frame by popping
1465 // off the callee frame. We want to re-execute the call that called the
1466 // callee interpreted, but since the return to the interpreter would pop
1467 // the arguments off advance the esp by dummy popframe_extra_args slots.
1468 // Popping off those will establish the stack layout as it was before the call.
1469 //
1470 void AbstractInterpreter::layout_activation(Method* method,
1471 int tempcount,
1472 int popframe_extra_args,
1473 int moncount,
1474 int caller_actual_parameters,
1475 int callee_param_count,
1476 int callee_locals_count,
1477 frame* caller,
1478 frame* interpreter_frame,
1479 bool is_top_frame,
1480 bool is_bottom_frame) {
1481
1482 const int abi_scratch = is_top_frame ? (frame::abi_reg_args_size / Interpreter::stackElementSize) :
1483 (frame::abi_minframe_size / Interpreter::stackElementSize);
1484
1485 intptr_t* locals_base = (caller->is_interpreted_frame()) ?
1486 caller->interpreter_frame_esp() + caller_actual_parameters :
1487 caller->sp() + method->max_locals() - 1 + (frame::abi_minframe_size / Interpreter::stackElementSize) ;
1488
1489 intptr_t* monitor_base = caller->sp() - frame::ijava_state_size / Interpreter::stackElementSize ;
1490 intptr_t* monitor = monitor_base - (moncount * frame::interpreter_frame_monitor_size());
1491 intptr_t* esp_base = monitor - 1;
1492 intptr_t* esp = esp_base - tempcount - popframe_extra_args;
1493 intptr_t* sp = (intptr_t *) (((intptr_t) (esp_base - callee_locals_count + callee_param_count - method->max_stack()- abi_scratch)) & -StackAlignmentInBytes);
1494 intptr_t* sender_sp = caller->sp() + (frame::abi_minframe_size - frame::abi_reg_args_size) / Interpreter::stackElementSize;
1495 intptr_t* top_frame_sp = is_top_frame ? sp : sp + (frame::abi_minframe_size - frame::abi_reg_args_size) / Interpreter::stackElementSize;
1496
1497 interpreter_frame->interpreter_frame_set_method(method);
1498 interpreter_frame->interpreter_frame_set_locals(locals_base);
1499 interpreter_frame->interpreter_frame_set_cpcache(method->constants()->cache());
1500 interpreter_frame->interpreter_frame_set_esp(esp);
1501 interpreter_frame->interpreter_frame_set_monitor_end((BasicObjectLock *)monitor);
1502 interpreter_frame->interpreter_frame_set_top_frame_sp(top_frame_sp);
1503 if (!is_bottom_frame) {
1504 interpreter_frame->interpreter_frame_set_sender_sp(sender_sp);
1505 }
1506 }
1507
1508 // =============================================================================
1509 // Exceptions
1510
1511 void TemplateInterpreterGenerator::generate_throw_exception() {
1512 Register Rexception = R17_tos,
1513 Rcontinuation = R3_RET;
1514
1515 // --------------------------------------------------------------------------
1516 // Entry point if an method returns with a pending exception (rethrow).
1517 Interpreter::_rethrow_exception_entry = __ pc();
1518 {
1519 __ restore_interpreter_state(R11_scratch1); // Sets R11_scratch1 = fp.
1520 __ ld(R12_scratch2, _ijava_state_neg(top_frame_sp), R11_scratch1);
1521 __ resize_frame_absolute(R12_scratch2, R11_scratch1, R0);
1522
1523 // Compiled code destroys templateTableBase, reload.
1524 __ load_const_optimized(R25_templateTableBase, (address)Interpreter::dispatch_table((TosState)0), R11_scratch1);
1525 }
|
1 /*
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2015 SAP AG. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
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 *
589 else {
590 __ std(R12_scratch2, _ijava_state_neg(monitors), R1_SP);
591 __ std(R12_scratch2, _ijava_state_neg(bcp), R1_SP);
592 __ std(R12_scratch2, _ijava_state_neg(mdx), R1_SP);
593 }
594 __ std(R11_scratch1, _ijava_state_neg(ijava_reserved), R1_SP);
595 __ std(R12_scratch2, _ijava_state_neg(esp), R1_SP);
596 __ std(R12_scratch2, _ijava_state_neg(lresult), R1_SP);
597 __ std(R12_scratch2, _ijava_state_neg(fresult), R1_SP);
598 #endif
599 __ subf(R12_scratch2, top_frame_size, R1_SP);
600 __ std(R0, _ijava_state_neg(oop_tmp), R1_SP);
601 __ std(R12_scratch2, _ijava_state_neg(top_frame_sp), R1_SP);
602
603 // Push top frame.
604 __ push_frame(top_frame_size, R11_scratch1);
605 }
606
607 // End of helpers
608
609 address TemplateInterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) {
610 if (!TemplateInterpreter::math_entry_available(kind)) {
611 NOT_PRODUCT(__ should_not_reach_here();)
612 return NULL;
613 }
614
615 address entry = __ pc();
616
617 __ lfd(F1_RET, Interpreter::stackElementSize, R15_esp);
618
619 // Pop c2i arguments (if any) off when we return.
620 #ifdef ASSERT
621 __ ld(R9_ARG7, 0, R1_SP);
622 __ ld(R10_ARG8, 0, R21_sender_SP);
623 __ cmpd(CCR0, R9_ARG7, R10_ARG8);
624 __ asm_assert_eq("backlink", 0x545);
625 #endif // ASSERT
626 __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started.
627
628 if (kind == Interpreter::java_lang_math_sqrt) {
629 __ fsqrt(F1_RET, F1_RET);
630 } else if (kind == Interpreter::java_lang_math_abs) {
1373
1374 StubRoutines::ppc64::generate_load_crc_table_addr(_masm, table);
1375
1376 // Performance measurements show the 1word and 2word variants to be almost equivalent,
1377 // with very light advantages for the 1word variant. We chose the 1word variant for
1378 // code compactness.
1379 __ kernel_crc32_1word(crc, data, dataLen, table, t0, t1, t2, t3, tc0, tc1, tc2, tc3);
1380
1381 // Restore caller sp for c2i case and return.
1382 __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started.
1383 __ blr();
1384
1385 // Generate a vanilla native entry as the slow path.
1386 BLOCK_COMMENT("} CRC32_updateBytes(Buffer)");
1387 BIND(slow_path);
1388 __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::native), R11_scratch1);
1389 return start;
1390 }
1391
1392 return NULL;
1393 }
1394
1395 // =============================================================================
1396 // Exceptions
1397
1398 void TemplateInterpreterGenerator::generate_throw_exception() {
1399 Register Rexception = R17_tos,
1400 Rcontinuation = R3_RET;
1401
1402 // --------------------------------------------------------------------------
1403 // Entry point if an method returns with a pending exception (rethrow).
1404 Interpreter::_rethrow_exception_entry = __ pc();
1405 {
1406 __ restore_interpreter_state(R11_scratch1); // Sets R11_scratch1 = fp.
1407 __ ld(R12_scratch2, _ijava_state_neg(top_frame_sp), R11_scratch1);
1408 __ resize_frame_absolute(R12_scratch2, R11_scratch1, R0);
1409
1410 // Compiled code destroys templateTableBase, reload.
1411 __ load_const_optimized(R25_templateTableBase, (address)Interpreter::dispatch_table((TosState)0), R11_scratch1);
1412 }
|