1 /* 2 * Copyright (c) 1997, 2015, 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 "ci/ciMethod.hpp" 27 #include "interpreter/interpreter.hpp" 28 #include "runtime/frame.inline.hpp" 29 30 // Size of interpreter code. Increase if too small. Interpreter will 31 // fail with a guarantee ("not enough space for interpreter generation"); 32 // if too small. 33 // Run with +PrintInterpreter to get the VM to print out the size. 34 // Max size with JVMTI 35 #ifdef AMD64 36 int TemplateInterpreter::InterpreterCodeSize = 256 * 1024; 37 #else 38 int TemplateInterpreter::InterpreterCodeSize = 224 * 1024; 39 #endif // AMD64 40 41 // asm based interpreter deoptimization helpers 42 int AbstractInterpreter::size_activation(int max_stack, 43 int temps, 44 int extra_args, 45 int monitors, 46 int callee_params, 47 int callee_locals, 48 bool is_top_frame) { 49 // Note: This calculation must exactly parallel the frame setup 50 // in TemplateInterpreterGenerator::generate_fixed_frame. 51 52 // fixed size of an interpreter frame: 53 int overhead = frame::sender_sp_offset - 54 frame::interpreter_frame_initial_sp_offset; 55 // Our locals were accounted for by the caller (or last_frame_adjust 56 // on the transistion) Since the callee parameters already account 57 // for the callee's params we only need to account for the extra 58 // locals. 59 int size = overhead + 60 (callee_locals - callee_params)*Interpreter::stackElementWords + 61 monitors * frame::interpreter_frame_monitor_size() + 62 temps* Interpreter::stackElementWords + extra_args; 63 64 return size; 65 } 66 67 void AbstractInterpreter::layout_activation(Method* method, 68 int tempcount, 69 int popframe_extra_args, 70 int moncount, 71 int caller_actual_parameters, 72 int callee_param_count, 73 int callee_locals, 74 frame* caller, 75 frame* interpreter_frame, 76 bool is_top_frame, 77 bool is_bottom_frame) { 78 // The frame interpreter_frame is guaranteed to be the right size, 79 // as determined by a previous call to the size_activation() method. 80 // It is also guaranteed to be walkable even though it is in a 81 // skeletal state 82 83 int max_locals = method->max_locals() * Interpreter::stackElementWords; 84 int extra_locals = (method->max_locals() - method->size_of_parameters()) * 85 Interpreter::stackElementWords; 86 87 #ifdef ASSERT 88 assert(caller->sp() == interpreter_frame->sender_sp(), "Frame not properly walkable"); 89 #endif 90 91 interpreter_frame->interpreter_frame_set_method(method); 92 // NOTE the difference in using sender_sp and 93 // interpreter_frame_sender_sp interpreter_frame_sender_sp is 94 // the original sp of the caller (the unextended_sp) and 95 // sender_sp is fp+8/16 (32bit/64bit) XXX 96 intptr_t* locals = interpreter_frame->sender_sp() + max_locals - 1; 97 98 #ifdef ASSERT 99 if (caller->is_interpreted_frame()) { 100 assert(locals < caller->fp() + frame::interpreter_frame_initial_sp_offset, "bad placement"); 101 } 102 #endif 103 104 interpreter_frame->interpreter_frame_set_locals(locals); 105 BasicObjectLock* montop = interpreter_frame->interpreter_frame_monitor_begin(); 106 BasicObjectLock* monbot = montop - moncount; 107 interpreter_frame->interpreter_frame_set_monitor_end(monbot); 108 109 // Set last_sp 110 intptr_t* esp = (intptr_t*) monbot - 111 tempcount*Interpreter::stackElementWords - 112 popframe_extra_args; 113 interpreter_frame->interpreter_frame_set_last_sp(esp); 114 115 // All frames but the initial (oldest) interpreter frame we fill in have 116 // a value for sender_sp that allows walking the stack but isn't 117 // truly correct. Correct the value here. 118 if (extra_locals != 0 && 119 interpreter_frame->sender_sp() == 120 interpreter_frame->interpreter_frame_sender_sp()) { 121 interpreter_frame->set_interpreter_frame_sender_sp(caller->sp() + 122 extra_locals); 123 } 124 *interpreter_frame->interpreter_frame_cache_addr() = 125 method->constants()->cache(); 126 } 127 128 #ifndef _LP64 129 int AbstractInterpreter::BasicType_as_index(BasicType type) { 130 int i = 0; 131 switch (type) { 132 case T_BOOLEAN: i = 0; break; 133 case T_CHAR : i = 1; break; 134 case T_BYTE : i = 2; break; 135 case T_SHORT : i = 3; break; 136 case T_INT : // fall through 137 case T_LONG : // fall through 138 case T_VOID : i = 4; break; 139 case T_FLOAT : i = 5; break; // have to treat float and double separately for SSE 140 case T_DOUBLE : i = 6; break; 141 case T_OBJECT : // fall through 142 case T_ARRAY : i = 7; break; 143 default : ShouldNotReachHere(); 144 } 145 assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, "index out of bounds"); 146 return i; 147 } 148 #else 149 int AbstractInterpreter::BasicType_as_index(BasicType type) { 150 int i = 0; 151 switch (type) { 152 case T_BOOLEAN: i = 0; break; 153 case T_CHAR : i = 1; break; 154 case T_BYTE : i = 2; break; 155 case T_SHORT : i = 3; break; 156 case T_INT : i = 4; break; 157 case T_LONG : i = 5; break; 158 case T_VOID : i = 6; break; 159 case T_FLOAT : i = 7; break; 160 case T_DOUBLE : i = 8; break; 161 case T_OBJECT : i = 9; break; 162 case T_ARRAY : i = 9; break; 163 default : ShouldNotReachHere(); 164 } 165 assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, 166 "index out of bounds"); 167 return i; 168 } 169 #endif // _LP64 170 171 // These should never be compiled since the interpreter will prefer 172 // the compiled version to the intrinsic version. 173 bool AbstractInterpreter::can_be_compiled(methodHandle m) { 174 switch (method_kind(m)) { 175 case Interpreter::java_lang_math_sin : // fall thru 176 case Interpreter::java_lang_math_cos : // fall thru 177 case Interpreter::java_lang_math_tan : // fall thru 178 case Interpreter::java_lang_math_abs : // fall thru 179 case Interpreter::java_lang_math_log : // fall thru 180 case Interpreter::java_lang_math_log10 : // fall thru 181 case Interpreter::java_lang_math_sqrt : // fall thru 182 case Interpreter::java_lang_math_pow : // fall thru 183 case Interpreter::java_lang_math_exp : 184 return false; 185 default: 186 return true; 187 } 188 } 189 190 // How much stack a method activation needs in words. 191 int AbstractInterpreter::size_top_interpreter_activation(Method* method) { 192 const int entry_size = frame::interpreter_frame_monitor_size(); 193 194 // total overhead size: entry_size + (saved rbp thru expr stack 195 // bottom). be sure to change this if you add/subtract anything 196 // to/from the overhead area 197 const int overhead_size = 198 -(frame::interpreter_frame_initial_sp_offset) + entry_size; 199 200 #ifndef _LP64 201 const int stub_code = 4; // see generate_call_stub 202 #else 203 const int stub_code = frame::entry_frame_after_call_words; 204 #endif 205 206 const int method_stack = (method->max_locals() + method->max_stack()) * 207 Interpreter::stackElementWords; 208 return (overhead_size + method_stack + stub_code); 209 }