src/cpu/sparc/vm/templateInterpreterGenerator_sparc.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8144534.02 Sdiff src/cpu/sparc/vm

src/cpu/sparc/vm/templateInterpreterGenerator_sparc.cpp

Print this page




1385 
1386   if (inc_counter) {
1387     if (ProfileInterpreter) {
1388       // We have decided to profile this method in the interpreter
1389       __ bind(profile_method);
1390 
1391       __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method));
1392       __ set_method_data_pointer_for_bcp();
1393       __ ba_short(profile_method_continue);
1394     }
1395 
1396     // handle invocation counter overflow
1397     __ bind(invocation_counter_overflow);
1398     generate_counter_overflow(Lcontinue);
1399   }
1400 
1401 
1402   return entry;
1403 }
1404 
1405 static int size_activation_helper(int callee_extra_locals, int max_stack, int monitor_size) {
1406 
1407   // Figure out the size of an interpreter frame (in words) given that we have a fully allocated
1408   // expression stack, the callee will have callee_extra_locals (so we can account for
1409   // frame extension) and monitor_size for monitors. Basically we need to calculate
1410   // this exactly like generate_fixed_frame/generate_compute_interpreter_state.
1411   //
1412   //
1413   // The big complicating thing here is that we must ensure that the stack stays properly
1414   // aligned. This would be even uglier if monitor size wasn't modulo what the stack
1415   // needs to be aligned for). We are given that the sp (fp) is already aligned by
1416   // the caller so we must ensure that it is properly aligned for our callee.
1417   //
1418   const int rounded_vm_local_words =
1419        round_to(frame::interpreter_frame_vm_local_words,WordsPerLong);
1420   // callee_locals and max_stack are counts, not the size in frame.
1421   const int locals_size =
1422        round_to(callee_extra_locals * Interpreter::stackElementWords, WordsPerLong);
1423   const int max_stack_words = max_stack * Interpreter::stackElementWords;
1424   return (round_to((max_stack_words
1425                    + rounded_vm_local_words
1426                    + frame::memory_parameter_word_sp_offset), WordsPerLong)
1427                    // already rounded
1428                    + locals_size + monitor_size);
1429 }
1430 
1431 // How much stack a method top interpreter activation needs in words.
1432 int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
1433 
1434   // See call_stub code
1435   int call_stub_size  = round_to(7 + frame::memory_parameter_word_sp_offset,
1436                                  WordsPerLong);    // 7 + register save area
1437 
1438   // Save space for one monitor to get into the interpreted method in case
1439   // the method is synchronized
1440   int monitor_size    = method->is_synchronized() ?
1441                                 1*frame::interpreter_frame_monitor_size() : 0;
1442   return size_activation_helper(method->max_locals(), method->max_stack(),
1443                                 monitor_size) + call_stub_size;
1444 }
1445 
1446 int AbstractInterpreter::size_activation(int max_stack,
1447                                          int temps,
1448                                          int extra_args,
1449                                          int monitors,
1450                                          int callee_params,
1451                                          int callee_locals,
1452                                          bool is_top_frame) {
1453   // Note: This calculation must exactly parallel the frame setup
1454   // in InterpreterGenerator::generate_fixed_frame.
1455 
1456   int monitor_size           = monitors * frame::interpreter_frame_monitor_size();
1457 
1458   assert(monitor_size == round_to(monitor_size, WordsPerLong), "must align");
1459 
1460   //
1461   // Note: if you look closely this appears to be doing something much different
1462   // than generate_fixed_frame. What is happening is this. On sparc we have to do
1463   // this dance with interpreter_sp_adjustment because the window save area would
1464   // appear just below the bottom (tos) of the caller's java expression stack. Because
1465   // the interpreter want to have the locals completely contiguous generate_fixed_frame
1466   // will adjust the caller's sp for the "extra locals" (max_locals - parameter_size).
1467   // Now in generate_fixed_frame the extension of the caller's sp happens in the callee.
1468   // In this code the opposite occurs the caller adjusts it's own stack base on the callee.
1469   // This is mostly ok but it does cause a problem when we get to the initial frame (the oldest)
1470   // because the oldest frame would have adjust its callers frame and yet that frame
1471   // already exists and isn't part of this array of frames we are unpacking. So at first
1472   // glance this would seem to mess up that frame. However Deoptimization::fetch_unroll_info_helper()
1473   // will after it calculates all of the frame's on_stack_size()'s will then figure out the
1474   // amount to adjust the caller of the initial (oldest) frame and the calculation will all
1475   // add up. It does seem like it simpler to account for the adjustment here (and remove the
1476   // callee... parameters here). However this would mean that this routine would have to take
1477   // the caller frame as input so we could adjust its sp (and set it's interpreter_sp_adjustment)
1478   // and run the calling loop in the reverse order. This would also would appear to mean making
1479   // this code aware of what the interactions are when that initial caller fram was an osr or
1480   // other adapter frame. deoptimization is complicated enough and  hard enough to debug that
1481   // there is no sense in messing working code.
1482   //
1483 
1484   int rounded_cls = round_to((callee_locals - callee_params), WordsPerLong);
1485   assert(rounded_cls == round_to(rounded_cls, WordsPerLong), "must align");
1486 
1487   int raw_frame_size = size_activation_helper(rounded_cls, max_stack, monitor_size);
1488 
1489   return raw_frame_size;
1490 }
1491 
1492 void AbstractInterpreter::layout_activation(Method* method,
1493                                             int tempcount,
1494                                             int popframe_extra_args,
1495                                             int moncount,
1496                                             int caller_actual_parameters,
1497                                             int callee_param_count,
1498                                             int callee_local_count,
1499                                             frame* caller,
1500                                             frame* interpreter_frame,
1501                                             bool is_top_frame,
1502                                             bool is_bottom_frame) {
1503   // Set up the following variables:
1504   //   - Lmethod
1505   //   - Llocals
1506   //   - Lmonitors (to the indicated number of monitors)
1507   //   - Lesp (to the indicated number of temps)
1508   // The frame caller on entry is a description of the caller of the
1509   // frame we are about to layout. We are guaranteed that we will be
1510   // able to fill in a new interpreter frame as its callee (i.e. the
1511   // stack space is allocated and the amount was determined by an
1512   // earlier call to the size_activation() method).  On return caller
1513   // while describe the interpreter frame we just layed out.
1514 
1515   // The skeleton frame must already look like an interpreter frame
1516   // even if not fully filled out.
1517   assert(interpreter_frame->is_interpreted_frame(), "Must be interpreted frame");
1518 
1519   int rounded_vm_local_words = round_to(frame::interpreter_frame_vm_local_words,WordsPerLong);
1520   int monitor_size           = moncount * frame::interpreter_frame_monitor_size();
1521   assert(monitor_size == round_to(monitor_size, WordsPerLong), "must align");
1522 
1523   intptr_t* fp = interpreter_frame->fp();
1524 
1525   JavaThread* thread = JavaThread::current();
1526   RegisterMap map(thread, false);
1527   // More verification that skeleton frame is properly walkable
1528   assert(fp == caller->sp(), "fp must match");
1529 
1530   intptr_t* montop     = fp - rounded_vm_local_words;
1531 
1532   // preallocate monitors (cf. __ add_monitor_to_stack)
1533   intptr_t* monitors = montop - monitor_size;
1534 
1535   // preallocate stack space
1536   intptr_t*  esp = monitors - 1 -
1537     (tempcount * Interpreter::stackElementWords) -
1538     popframe_extra_args;
1539 
1540   int local_words = method->max_locals() * Interpreter::stackElementWords;
1541   NEEDS_CLEANUP;
1542   intptr_t* locals;
1543   if (caller->is_interpreted_frame()) {
1544     // Can force the locals area to end up properly overlapping the top of the expression stack.
1545     intptr_t* Lesp_ptr = caller->interpreter_frame_tos_address() - 1;
1546     // Note that this computation means we replace size_of_parameters() values from the caller
1547     // interpreter frame's expression stack with our argument locals
1548     int parm_words  = caller_actual_parameters * Interpreter::stackElementWords;
1549     locals = Lesp_ptr + parm_words;
1550     int delta = local_words - parm_words;
1551     int computed_sp_adjustment = (delta > 0) ? round_to(delta, WordsPerLong) : 0;
1552     *interpreter_frame->register_addr(I5_savedSP)    = (intptr_t) (fp + computed_sp_adjustment) - STACK_BIAS;
1553     if (!is_bottom_frame) {
1554       // Llast_SP is set below for the current frame to SP (with the
1555       // extra space for the callee's locals). Here we adjust
1556       // Llast_SP for the caller's frame, removing the extra space
1557       // for the current method's locals.
1558       *caller->register_addr(Llast_SP) = *interpreter_frame->register_addr(I5_savedSP);
1559     } else {
1560       assert(*caller->register_addr(Llast_SP) >= *interpreter_frame->register_addr(I5_savedSP), "strange Llast_SP");
1561     }
1562   } else {
1563     assert(caller->is_compiled_frame() || caller->is_entry_frame(), "only possible cases");
1564     // Don't have Lesp available; lay out locals block in the caller
1565     // adjacent to the register window save area.
1566     //
1567     // Compiled frames do not allocate a varargs area which is why this if
1568     // statement is needed.
1569     //
1570     if (caller->is_compiled_frame()) {
1571       locals = fp + frame::register_save_words + local_words - 1;
1572     } else {
1573       locals = fp + frame::memory_parameter_word_sp_offset + local_words - 1;
1574     }
1575     if (!caller->is_entry_frame()) {
1576       // Caller wants his own SP back
1577       int caller_frame_size = caller->cb()->frame_size();
1578       *interpreter_frame->register_addr(I5_savedSP) = (intptr_t)(caller->fp() - caller_frame_size) - STACK_BIAS;
1579     }
1580   }
1581   if (TraceDeoptimization) {
1582     if (caller->is_entry_frame()) {
1583       // make sure I5_savedSP and the entry frames notion of saved SP
1584       // agree.  This assertion duplicate a check in entry frame code
1585       // but catches the failure earlier.
1586       assert(*caller->register_addr(Lscratch) == *interpreter_frame->register_addr(I5_savedSP),
1587              "would change callers SP");
1588     }
1589     if (caller->is_entry_frame()) {
1590       tty->print("entry ");
1591     }
1592     if (caller->is_compiled_frame()) {
1593       tty->print("compiled ");
1594       if (caller->is_deoptimized_frame()) {
1595         tty->print("(deopt) ");
1596       }
1597     }
1598     if (caller->is_interpreted_frame()) {
1599       tty->print("interpreted ");
1600     }
1601     tty->print_cr("caller fp=" INTPTR_FORMAT " sp=" INTPTR_FORMAT, p2i(caller->fp()), p2i(caller->sp()));
1602     tty->print_cr("save area = " INTPTR_FORMAT ", " INTPTR_FORMAT, p2i(caller->sp()), p2i(caller->sp() + 16));
1603     tty->print_cr("save area = " INTPTR_FORMAT ", " INTPTR_FORMAT, p2i(caller->fp()), p2i(caller->fp() + 16));
1604     tty->print_cr("interpreter fp=" INTPTR_FORMAT ", " INTPTR_FORMAT, p2i(interpreter_frame->fp()), p2i(interpreter_frame->sp()));
1605     tty->print_cr("save area = " INTPTR_FORMAT ", " INTPTR_FORMAT, p2i(interpreter_frame->sp()), p2i(interpreter_frame->sp() + 16));
1606     tty->print_cr("save area = " INTPTR_FORMAT ", " INTPTR_FORMAT, p2i(interpreter_frame->fp()), p2i(interpreter_frame->fp() + 16));
1607     tty->print_cr("Llocals = " INTPTR_FORMAT, p2i(locals));
1608     tty->print_cr("Lesp = " INTPTR_FORMAT, p2i(esp));
1609     tty->print_cr("Lmonitors = " INTPTR_FORMAT, p2i(monitors));
1610   }
1611 
1612   if (method->max_locals() > 0) {
1613     assert(locals < caller->sp() || locals >= (caller->sp() + 16), "locals in save area");
1614     assert(locals < caller->fp() || locals > (caller->fp() + 16), "locals in save area");
1615     assert(locals < interpreter_frame->sp() || locals > (interpreter_frame->sp() + 16), "locals in save area");
1616     assert(locals < interpreter_frame->fp() || locals >= (interpreter_frame->fp() + 16), "locals in save area");
1617   }
1618 #ifdef _LP64
1619   assert(*interpreter_frame->register_addr(I5_savedSP) & 1, "must be odd");
1620 #endif
1621 
1622   *interpreter_frame->register_addr(Lmethod)     = (intptr_t) method;
1623   *interpreter_frame->register_addr(Llocals)     = (intptr_t) locals;
1624   *interpreter_frame->register_addr(Lmonitors)   = (intptr_t) monitors;
1625   *interpreter_frame->register_addr(Lesp)        = (intptr_t) esp;
1626   // Llast_SP will be same as SP as there is no adapter space
1627   *interpreter_frame->register_addr(Llast_SP)    = (intptr_t) interpreter_frame->sp() - STACK_BIAS;
1628   *interpreter_frame->register_addr(LcpoolCache) = (intptr_t) method->constants()->cache();
1629 #ifdef FAST_DISPATCH
1630   *interpreter_frame->register_addr(IdispatchTables) = (intptr_t) Interpreter::dispatch_table();
1631 #endif
1632 
1633 
1634 #ifdef ASSERT
1635   BasicObjectLock* mp = (BasicObjectLock*)monitors;
1636 
1637   assert(interpreter_frame->interpreter_frame_method() == method, "method matches");
1638   assert(interpreter_frame->interpreter_frame_local_at(9) == (intptr_t *)((intptr_t)locals - (9 * Interpreter::stackElementSize)), "locals match");
1639   assert(interpreter_frame->interpreter_frame_monitor_end()   == mp, "monitor_end matches");
1640   assert(((intptr_t *)interpreter_frame->interpreter_frame_monitor_begin()) == ((intptr_t *)mp)+monitor_size, "monitor_begin matches");
1641   assert(interpreter_frame->interpreter_frame_tos_address()-1 == esp, "esp matches");
1642 
1643   // check bounds
1644   intptr_t* lo = interpreter_frame->sp() + (frame::memory_parameter_word_sp_offset - 1);
1645   intptr_t* hi = interpreter_frame->fp() - rounded_vm_local_words;
1646   assert(lo < monitors && montop <= hi, "monitors in bounds");
1647   assert(lo <= esp && esp < monitors, "esp in bounds");
1648 #endif // ASSERT
1649 }
1650 
1651 //----------------------------------------------------------------------------------------------------
1652 // Exceptions
1653 void TemplateInterpreterGenerator::generate_throw_exception() {
1654 
1655   // Entry point in previous activation (i.e., if the caller was interpreted)
1656   Interpreter::_rethrow_exception_entry = __ pc();
1657   // O0: exception
1658 
1659   // entry point for exceptions thrown within interpreter code
1660   Interpreter::_throw_exception_entry = __ pc();
1661   __ verify_thread();
1662   // expression stack is undefined here
1663   // O0: exception, i.e. Oexception
1664   // Lbcp: exception bcp
1665   __ verify_oop(Oexception);
1666 
1667 
1668   // expression stack must be empty before entering the VM in case of an exception
1669   __ empty_expression_stack();
1670   // find exception handler address and preserve exception oop




1385 
1386   if (inc_counter) {
1387     if (ProfileInterpreter) {
1388       // We have decided to profile this method in the interpreter
1389       __ bind(profile_method);
1390 
1391       __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method));
1392       __ set_method_data_pointer_for_bcp();
1393       __ ba_short(profile_method_continue);
1394     }
1395 
1396     // handle invocation counter overflow
1397     __ bind(invocation_counter_overflow);
1398     generate_counter_overflow(Lcontinue);
1399   }
1400 
1401 
1402   return entry;
1403 }
1404 






















































































































































































































































1405 //----------------------------------------------------------------------------------------------------
1406 // Exceptions
1407 void TemplateInterpreterGenerator::generate_throw_exception() {
1408 
1409   // Entry point in previous activation (i.e., if the caller was interpreted)
1410   Interpreter::_rethrow_exception_entry = __ pc();
1411   // O0: exception
1412 
1413   // entry point for exceptions thrown within interpreter code
1414   Interpreter::_throw_exception_entry = __ pc();
1415   __ verify_thread();
1416   // expression stack is undefined here
1417   // O0: exception, i.e. Oexception
1418   // Lbcp: exception bcp
1419   __ verify_oop(Oexception);
1420 
1421 
1422   // expression stack must be empty before entering the VM in case of an exception
1423   __ empty_expression_stack();
1424   // find exception handler address and preserve exception oop


src/cpu/sparc/vm/templateInterpreterGenerator_sparc.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File