|
| 1 | +/* |
| 2 | + * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * Copyright (c) 2015, 2023, Loongson Technology. 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 | + * |
| 24 | + */ |
| 25 | + |
| 26 | +#include "precompiled.hpp" |
| 27 | +#include "ci/ciMethod.hpp" |
| 28 | +#include "interpreter/interpreter.hpp" |
| 29 | +#include "oops/klass.inline.hpp" |
| 30 | +#include "runtime/frame.inline.hpp" |
| 31 | + |
| 32 | +int AbstractInterpreter::BasicType_as_index(BasicType type) { |
| 33 | + int i = 0; |
| 34 | + switch (type) { |
| 35 | + case T_BOOLEAN: i = 0; break; |
| 36 | + case T_CHAR : i = 1; break; |
| 37 | + case T_BYTE : i = 2; break; |
| 38 | + case T_SHORT : i = 3; break; |
| 39 | + case T_INT : i = 4; break; |
| 40 | + case T_LONG : |
| 41 | + case T_VOID : |
| 42 | + case T_FLOAT : |
| 43 | + case T_DOUBLE : i = 5; break; |
| 44 | + case T_OBJECT : |
| 45 | + case T_ARRAY : i = 6; break; |
| 46 | + default : ShouldNotReachHere(); |
| 47 | + } |
| 48 | + assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, |
| 49 | + "index out of bounds"); |
| 50 | + return i; |
| 51 | +} |
| 52 | + |
| 53 | +// How much stack a method activation needs in words. |
| 54 | +int AbstractInterpreter::size_top_interpreter_activation(Method* method) { |
| 55 | + const int entry_size = frame::interpreter_frame_monitor_size(); |
| 56 | + |
| 57 | + // total overhead size: entry_size + (saved fp thru expr stack |
| 58 | + // bottom). be sure to change this if you add/subtract anything |
| 59 | + // to/from the overhead area |
| 60 | + const int overhead_size = |
| 61 | + -(frame::interpreter_frame_initial_sp_offset) + entry_size; |
| 62 | + |
| 63 | + const int stub_code = frame::entry_frame_after_call_words; |
| 64 | + assert(method != nullptr, "invalid method"); |
| 65 | + const int method_stack = (method->max_locals() + method->max_stack()) * |
| 66 | + Interpreter::stackElementWords; |
| 67 | + return (overhead_size + method_stack + stub_code); |
| 68 | +} |
| 69 | + |
| 70 | +// asm based interpreter deoptimization helpers |
| 71 | +int AbstractInterpreter::size_activation(int max_stack, |
| 72 | + int temps, |
| 73 | + int extra_args, |
| 74 | + int monitors, |
| 75 | + int callee_params, |
| 76 | + int callee_locals, |
| 77 | + bool is_top_frame) { |
| 78 | + // Note: This calculation must exactly parallel the frame setup |
| 79 | + // in AbstractInterpreterGenerator::generate_method_entry. |
| 80 | + |
| 81 | + // fixed size of an interpreter frame: |
| 82 | + int overhead = frame::sender_sp_offset - |
| 83 | + frame::interpreter_frame_initial_sp_offset; |
| 84 | + // Our locals were accounted for by the caller (or last_frame_adjust |
| 85 | + // on the transition) Since the callee parameters already account |
| 86 | + // for the callee's params we only need to account for the extra |
| 87 | + // locals. |
| 88 | + int size = overhead + |
| 89 | + (callee_locals - callee_params)*Interpreter::stackElementWords + |
| 90 | + monitors * frame::interpreter_frame_monitor_size() + |
| 91 | + temps* Interpreter::stackElementWords + extra_args; |
| 92 | + |
| 93 | + return size; |
| 94 | +} |
| 95 | + |
| 96 | +void AbstractInterpreter::layout_activation(Method* method, |
| 97 | + int tempcount, |
| 98 | + int popframe_extra_args, |
| 99 | + int moncount, |
| 100 | + int caller_actual_parameters, |
| 101 | + int callee_param_count, |
| 102 | + int callee_locals, |
| 103 | + frame* caller, |
| 104 | + frame* interpreter_frame, |
| 105 | + bool is_top_frame, |
| 106 | + bool is_bottom_frame) { |
| 107 | + // Note: This calculation must exactly parallel the frame setup |
| 108 | + // in AbstractInterpreterGenerator::generate_method_entry. |
| 109 | + // If interpreter_frame!=nullptr, set up the method, locals, and monitors. |
| 110 | + // The frame interpreter_frame, if not null, is guaranteed to be the |
| 111 | + // right size, as determined by a previous call to this method. |
| 112 | + // It is also guaranteed to be walkable even though it is in a skeletal state |
| 113 | + |
| 114 | + // fixed size of an interpreter frame: |
| 115 | + |
| 116 | + int max_locals = method->max_locals() * Interpreter::stackElementWords; |
| 117 | + int extra_locals = (method->max_locals() - method->size_of_parameters()) * Interpreter::stackElementWords; |
| 118 | + |
| 119 | +#ifdef ASSERT |
| 120 | + assert(caller->sp() == interpreter_frame->sender_sp(), "Frame not properly walkable(2)"); |
| 121 | +#endif |
| 122 | + |
| 123 | + interpreter_frame->interpreter_frame_set_method(method); |
| 124 | + // NOTE the difference in using sender_sp and interpreter_frame_sender_sp |
| 125 | + // interpreter_frame_sender_sp is the original sp of the caller (the unextended_sp) |
| 126 | + // and sender_sp is fp+8 |
| 127 | + intptr_t* locals = interpreter_frame->sender_sp() + max_locals - 1; |
| 128 | + |
| 129 | +#ifdef ASSERT |
| 130 | + if (caller->is_interpreted_frame()) { |
| 131 | + assert(locals < caller->fp() + frame::interpreter_frame_initial_sp_offset, "bad placement"); |
| 132 | + } |
| 133 | +#endif |
| 134 | + |
| 135 | + interpreter_frame->interpreter_frame_set_locals(locals); |
| 136 | + BasicObjectLock* montop = interpreter_frame->interpreter_frame_monitor_begin(); |
| 137 | + BasicObjectLock* monbot = montop - moncount; |
| 138 | + interpreter_frame->interpreter_frame_set_monitor_end(montop - moncount); |
| 139 | + |
| 140 | + //set last sp; |
| 141 | + intptr_t* esp = (intptr_t*) monbot - tempcount*Interpreter::stackElementWords - |
| 142 | + popframe_extra_args; |
| 143 | + interpreter_frame->interpreter_frame_set_last_sp(esp); |
| 144 | + // All frames but the initial interpreter frame we fill in have a |
| 145 | + // value for sender_sp that allows walking the stack but isn't |
| 146 | + // truly correct. Correct the value here. |
| 147 | + // |
| 148 | + if (extra_locals != 0 && |
| 149 | + interpreter_frame->sender_sp() == interpreter_frame->interpreter_frame_sender_sp() ) { |
| 150 | + interpreter_frame->set_interpreter_frame_sender_sp(caller->sp() + extra_locals); |
| 151 | + } |
| 152 | + *interpreter_frame->interpreter_frame_cache_addr() = method->constants()->cache(); |
| 153 | + *interpreter_frame->interpreter_frame_mirror_addr() = method->method_holder()->java_mirror(); |
| 154 | +} |
| 155 | + |
0 commit comments