Mon, 13 Nov 2017 15:49:42 +0800
#5963 wrong frame offset (SP) in StackOverflowError handler
Summary: push/pop before/after bang_stack_with_offset is removed. compiler/6865265/StackOverflowBug.java passed.
This patch also includes code cleanup and code style fix.
aoqi@1 | 1 | /* |
aoqi@1 | 2 | * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
aoqi@1 | 3 | * Copyright (c) 2015, 2016, Loongson Technology. All rights reserved. |
aoqi@1 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@1 | 5 | * |
aoqi@1 | 6 | * This code is free software; you can redistribute it and/or modify it |
aoqi@1 | 7 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@1 | 8 | * published by the Free Software Foundation. |
aoqi@1 | 9 | * |
aoqi@1 | 10 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@1 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@1 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@1 | 13 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@1 | 14 | * accompanied this code). |
aoqi@1 | 15 | * |
aoqi@1 | 16 | * You should have received a copy of the GNU General Public License version |
aoqi@1 | 17 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@1 | 18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@1 | 19 | * |
aoqi@1 | 20 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@1 | 21 | * or visit www.oracle.com if you need additional information or have any |
aoqi@1 | 22 | * questions. |
aoqi@1 | 23 | * |
aoqi@1 | 24 | */ |
aoqi@1 | 25 | |
aoqi@1 | 26 | #include "precompiled.hpp" |
aoqi@1 | 27 | #include "interpreter/interpreter.hpp" |
aoqi@1 | 28 | #include "memory/resourceArea.hpp" |
aoqi@1 | 29 | #include "oops/markOop.hpp" |
aoqi@1 | 30 | #include "oops/method.hpp" |
aoqi@1 | 31 | #include "oops/oop.inline.hpp" |
aoqi@1 | 32 | #include "prims/methodHandles.hpp" |
aoqi@1 | 33 | #include "runtime/frame.inline.hpp" |
aoqi@1 | 34 | #include "runtime/handles.inline.hpp" |
aoqi@1 | 35 | #include "runtime/javaCalls.hpp" |
aoqi@1 | 36 | #include "runtime/monitorChunk.hpp" |
aoqi@1 | 37 | #include "runtime/signature.hpp" |
aoqi@1 | 38 | #include "runtime/stubCodeGenerator.hpp" |
aoqi@1 | 39 | #include "runtime/stubRoutines.hpp" |
aoqi@1 | 40 | #include "vmreg_mips.inline.hpp" |
aoqi@1 | 41 | #ifdef COMPILER1 |
aoqi@1 | 42 | #include "c1/c1_Runtime1.hpp" |
aoqi@1 | 43 | #include "runtime/vframeArray.hpp" |
aoqi@1 | 44 | #endif |
aoqi@1 | 45 | |
aoqi@1 | 46 | #ifdef ASSERT |
aoqi@1 | 47 | void RegisterMap::check_location_valid() { |
aoqi@1 | 48 | } |
aoqi@1 | 49 | #endif |
aoqi@1 | 50 | |
aoqi@1 | 51 | |
aoqi@1 | 52 | // Profiling/safepoint support |
aoqi@1 | 53 | // for Profiling - acting on another frame. walks sender frames |
aoqi@1 | 54 | // if valid. |
aoqi@1 | 55 | // frame profile_find_Java_sender_frame(JavaThread *thread); |
aoqi@1 | 56 | |
aoqi@1 | 57 | bool frame::safe_for_sender(JavaThread *thread) { |
aoqi@6880 | 58 | address sp = (address)_sp; |
aoqi@6880 | 59 | address fp = (address)_fp; |
aoqi@6880 | 60 | bool sp_safe = (sp != NULL && |
aoqi@6880 | 61 | (sp <= thread->stack_base()) && |
aoqi@6880 | 62 | (sp >= thread->stack_base() - thread->stack_size())); |
aoqi@6880 | 63 | bool fp_safe = (fp != NULL && |
aoqi@6880 | 64 | (fp <= thread->stack_base()) && |
aoqi@6880 | 65 | (fp >= thread->stack_base() - thread->stack_size())); |
aoqi@6880 | 66 | if (sp_safe && fp_safe) { |
aoqi@6880 | 67 | CodeBlob *cb = CodeCache::find_blob_unsafe(_pc); |
aoqi@6880 | 68 | // First check if frame is complete and tester is reliable |
aoqi@6880 | 69 | // Unfortunately we can only check frame complete for runtime stubs and nmethod |
aoqi@6880 | 70 | // other generic buffer blobs are more problematic so we just assume they are |
aoqi@6880 | 71 | // ok. adapter blobs never have a frame complete and are never ok. |
aoqi@6880 | 72 | if (cb != NULL && !cb->is_frame_complete_at(_pc)) { |
aoqi@6880 | 73 | if (cb->is_nmethod() || cb->is_adapter_blob() || cb->is_runtime_stub()) { |
aoqi@6880 | 74 | return false; |
aoqi@6880 | 75 | } |
aoqi@6880 | 76 | } |
aoqi@6880 | 77 | return true; |
aoqi@6880 | 78 | } |
aoqi@6880 | 79 | // Note: fp == NULL is not really a prerequisite for this to be safe to |
aoqi@6880 | 80 | // walk for c2. However we've modified the code such that if we get |
aoqi@6880 | 81 | // a failure with fp != NULL that we then try with FP == NULL. |
aoqi@6880 | 82 | // This is basically to mimic what a last_frame would look like if |
aoqi@6880 | 83 | // c2 had generated it. |
aoqi@6880 | 84 | if (sp_safe && fp == NULL) { |
aoqi@6880 | 85 | CodeBlob *cb = CodeCache::find_blob_unsafe(_pc); |
aoqi@6880 | 86 | // frame must be complete if fp == NULL as fp == NULL is only sensible |
aoqi@6880 | 87 | // if we are looking at a nmethod and frame complete assures us of that. |
aoqi@6880 | 88 | if (cb != NULL && cb->is_frame_complete_at(_pc) && cb->is_compiled_by_c2()) { |
aoqi@6880 | 89 | return true; |
aoqi@6880 | 90 | } |
aoqi@6880 | 91 | } |
aoqi@6880 | 92 | return false; |
aoqi@1 | 93 | } |
aoqi@1 | 94 | |
aoqi@1 | 95 | |
aoqi@1 | 96 | void frame::patch_pc(Thread* thread, address pc) { |
aoqi@6880 | 97 | if (TracePcPatching) { |
aoqi@6880 | 98 | tty->print_cr("patch_pc at address 0x%x [0x%x -> 0x%x] ", &((address *)_sp)[-1], ((address *)_sp)[-1], pc); |
aoqi@6880 | 99 | } |
aoqi@1 | 100 | |
aoqi@6880 | 101 | RegisterMap map((JavaThread *)thread, false); |
aoqi@6880 | 102 | frame check = ((JavaThread *)thread)->last_frame(); |
aoqi@6880 | 103 | if (id() != check.id()) |
aoqi@6880 | 104 | { |
aoqi@6880 | 105 | while (id() != check.sender(&map).id()) { |
aoqi@6880 | 106 | check = check.sender(&map); |
aoqi@6880 | 107 | } |
aoqi@6880 | 108 | if (check.is_interpreted_frame()) |
aoqi@6880 | 109 | *(check.fp() + 1) = (intptr_t)pc; |
aoqi@6880 | 110 | else |
aoqi@6880 | 111 | ((address *)_sp)[-1] = pc; |
aoqi@6880 | 112 | } |
aoqi@1 | 113 | |
aoqi@6880 | 114 | _cb = CodeCache::find_blob(pc); |
aoqi@6880 | 115 | if (_cb != NULL && _cb->is_nmethod() && ((nmethod*)_cb)->is_deopt_pc(_pc)) { |
aoqi@6880 | 116 | address orig = (((nmethod*)_cb)->get_original_pc(this)); |
aoqi@6880 | 117 | assert(orig == _pc, "expected original to be stored before patching"); |
aoqi@6880 | 118 | _deopt_state = is_deoptimized; |
aoqi@6880 | 119 | // leave _pc as is |
aoqi@6880 | 120 | } else { |
aoqi@6880 | 121 | _deopt_state = not_deoptimized; |
aoqi@6880 | 122 | _pc = pc; |
aoqi@6880 | 123 | } |
aoqi@1 | 124 | } |
aoqi@1 | 125 | |
aoqi@1 | 126 | bool frame::is_interpreted_frame() const { |
aoqi@6880 | 127 | return Interpreter::contains(pc()); |
aoqi@1 | 128 | } |
aoqi@1 | 129 | |
aoqi@1 | 130 | int frame::frame_size(RegisterMap* map) const { |
aoqi@6880 | 131 | frame sender = this->sender(map); |
aoqi@6880 | 132 | return sender.sp() - sp(); |
aoqi@1 | 133 | } |
aoqi@1 | 134 | |
aoqi@1 | 135 | intptr_t* frame::entry_frame_argument_at(int offset) const { |
aoqi@6880 | 136 | // convert offset to index to deal with tsi |
aoqi@6880 | 137 | int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize); |
aoqi@6880 | 138 | // Entry frame's arguments are always in relation to unextended_sp() |
aoqi@6880 | 139 | return &unextended_sp()[index]; |
aoqi@1 | 140 | } |
aoqi@1 | 141 | |
aoqi@1 | 142 | // sender_sp |
aoqi@1 | 143 | #ifdef CC_INTERP |
aoqi@1 | 144 | intptr_t* frame::interpreter_frame_sender_sp() const { |
aoqi@6880 | 145 | assert(is_interpreted_frame(), "interpreted frame expected"); |
aoqi@6880 | 146 | // QQQ why does this specialize method exist if frame::sender_sp() does same thing? |
aoqi@6880 | 147 | // seems odd and if we always know interpreted vs. non then sender_sp() is really |
aoqi@6880 | 148 | // doing too much work. |
aoqi@6880 | 149 | return get_interpreterState()->sender_sp(); |
aoqi@1 | 150 | } |
aoqi@1 | 151 | |
aoqi@1 | 152 | // monitor elements |
aoqi@1 | 153 | |
aoqi@1 | 154 | BasicObjectLock* frame::interpreter_frame_monitor_begin() const { |
aoqi@6880 | 155 | return get_interpreterState()->monitor_base(); |
aoqi@1 | 156 | } |
aoqi@1 | 157 | |
aoqi@1 | 158 | BasicObjectLock* frame::interpreter_frame_monitor_end() const { |
aoqi@6880 | 159 | return (BasicObjectLock*) get_interpreterState()->stack_base(); |
aoqi@1 | 160 | } |
aoqi@1 | 161 | |
aoqi@1 | 162 | #else // CC_INTERP |
aoqi@1 | 163 | |
aoqi@1 | 164 | intptr_t* frame::interpreter_frame_sender_sp() const { |
aoqi@6880 | 165 | assert(is_interpreted_frame(), "interpreted frame expected"); |
aoqi@6880 | 166 | return (intptr_t*) at(interpreter_frame_sender_sp_offset); |
aoqi@1 | 167 | } |
aoqi@1 | 168 | |
aoqi@1 | 169 | void frame::set_interpreter_frame_sender_sp(intptr_t* sender_sp) { |
aoqi@6880 | 170 | assert(is_interpreted_frame(), "interpreted frame expected"); |
aoqi@6880 | 171 | int_at_put(interpreter_frame_sender_sp_offset, (intptr_t) sender_sp); |
aoqi@1 | 172 | } |
aoqi@1 | 173 | |
aoqi@1 | 174 | |
aoqi@1 | 175 | // monitor elements |
aoqi@1 | 176 | |
aoqi@1 | 177 | BasicObjectLock* frame::interpreter_frame_monitor_begin() const { |
aoqi@6880 | 178 | return (BasicObjectLock*) addr_at(interpreter_frame_monitor_block_bottom_offset); |
aoqi@1 | 179 | } |
aoqi@1 | 180 | |
aoqi@1 | 181 | BasicObjectLock* frame::interpreter_frame_monitor_end() const { |
aoqi@6880 | 182 | BasicObjectLock* result = (BasicObjectLock*) *addr_at(interpreter_frame_monitor_block_top_offset); |
aoqi@6880 | 183 | // make sure the pointer points inside the frame |
aoqi@6880 | 184 | assert((intptr_t) fp() > (intptr_t) result, "result must < than frame pointer"); |
aoqi@6880 | 185 | assert((intptr_t) sp() <= (intptr_t) result, "result must >= than stack pointer"); |
aoqi@6880 | 186 | return result; |
aoqi@1 | 187 | } |
aoqi@1 | 188 | |
aoqi@1 | 189 | void frame::interpreter_frame_set_monitor_end(BasicObjectLock* value) { |
aoqi@6880 | 190 | *((BasicObjectLock**)addr_at(interpreter_frame_monitor_block_top_offset)) = value; |
aoqi@1 | 191 | } |
aoqi@1 | 192 | |
aoqi@1 | 193 | // Used by template based interpreter deoptimization |
aoqi@1 | 194 | void frame::interpreter_frame_set_last_sp(intptr_t* sp) { |
aoqi@6880 | 195 | *((intptr_t**)addr_at(interpreter_frame_last_sp_offset)) = sp; |
aoqi@1 | 196 | } |
aoqi@1 | 197 | #endif // CC_INTERP |
aoqi@1 | 198 | |
aoqi@1 | 199 | frame frame::sender_for_entry_frame(RegisterMap* map) const { |
aoqi@6880 | 200 | assert(map != NULL, "map must be set"); |
aoqi@6880 | 201 | // Java frame called from C; skip all C frames and return top C |
aoqi@6880 | 202 | // frame of that chunk as the sender |
aoqi@6880 | 203 | JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor(); |
aoqi@6880 | 204 | assert(!entry_frame_is_first(), "next Java fp must be non zero"); |
aoqi@6880 | 205 | assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack"); |
aoqi@6880 | 206 | map->clear(); |
aoqi@6880 | 207 | assert(map->include_argument_oops(), "should be set by clear"); |
aoqi@6880 | 208 | if (jfa->last_Java_pc() != NULL ) { |
aoqi@6880 | 209 | frame fr(jfa->last_Java_sp(), jfa->last_Java_fp(), jfa->last_Java_pc()); |
aoqi@6880 | 210 | return fr; |
aoqi@6880 | 211 | } |
aoqi@6880 | 212 | frame fr(jfa->last_Java_sp(), jfa->last_Java_fp()); |
aoqi@6880 | 213 | return fr; |
aoqi@1 | 214 | } |
aoqi@1 | 215 | |
aoqi@1 | 216 | frame frame::sender_for_interpreter_frame(RegisterMap* map) const { |
aoqi@1 | 217 | // sp is the raw sp from the sender after adapter or interpreter extension |
aoqi@1 | 218 | //intptr_t* sp = (intptr_t*) addr_at(sender_sp_offset); |
aoqi@1 | 219 | intptr_t* sp = (intptr_t*) at(interpreter_frame_sender_sp_offset); |
aoqi@1 | 220 | |
aoqi@1 | 221 | // This is the sp before any possible extension (adapter/locals). |
aoqi@1 | 222 | //intptr_t* unextended_sp = interpreter_frame_sender_sp(); |
aoqi@1 | 223 | |
aoqi@1 | 224 | // The interpreter and compiler(s) always save EBP/RBP in a known |
aoqi@1 | 225 | // location on entry. We must record where that location is |
aoqi@1 | 226 | // so this if EBP/RBP was live on callout from c2 we can find |
aoqi@1 | 227 | // the saved copy no matter what it called. |
aoqi@1 | 228 | |
aoqi@1 | 229 | // Since the interpreter always saves EBP/RBP if we record where it is then |
aoqi@1 | 230 | // we don't have to always save EBP/RBP on entry and exit to c2 compiled |
aoqi@1 | 231 | // code, on entry will be enough. |
aoqi@1 | 232 | #ifdef COMPILER2 |
aoqi@1 | 233 | //FIXME aoqi |
aoqi@1 | 234 | if (map->update_map()) { |
aoqi@1 | 235 | map->set_location(FP->as_VMReg(), (address) addr_at(link_offset)); |
aoqi@1 | 236 | } |
aoqi@1 | 237 | #endif /* COMPILER2 */ |
aoqi@1 | 238 | return frame(sp, link(), sender_pc()); |
aoqi@1 | 239 | } |
aoqi@1 | 240 | |
aoqi@1 | 241 | |
aoqi@1 | 242 | //------------------------------------------------------------------------------ |
aoqi@6880 | 243 | // frame::verify_deopt_original_pc |
aoqi@6880 | 244 | // |
aoqi@6880 | 245 | // Verifies the calculated original PC of a deoptimization PC for the |
aoqi@6880 | 246 | // given unextended SP. The unextended SP might also be the saved SP |
aoqi@6880 | 247 | // for MethodHandle call sites. |
aoqi@1 | 248 | #ifdef ASSERT |
aoqi@1 | 249 | void frame::verify_deopt_original_pc(nmethod* nm, intptr_t* unextended_sp, bool is_method_handle_return) { |
aoqi@1 | 250 | frame fr; |
aoqi@1 | 251 | |
aoqi@1 | 252 | // This is ugly but it's better than to change {get,set}_original_pc |
aoqi@6880 | 253 | // to take an SP value as argument. And it's only a debugging |
aoqi@6880 | 254 | // method anyway. |
aoqi@6880 | 255 | fr._unextended_sp = unextended_sp; |
aoqi@1 | 256 | |
aoqi@1 | 257 | address original_pc = nm->get_original_pc(&fr); |
aoqi@1 | 258 | assert(nm->insts_contains(original_pc), "original PC must be in nmethod"); |
aoqi@1 | 259 | assert(nm->is_method_handle_return(original_pc) == is_method_handle_return, "must be"); |
aoqi@1 | 260 | } |
aoqi@1 | 261 | #endif |
aoqi@1 | 262 | |
aoqi@1 | 263 | |
aoqi@6880 | 264 | //------------------------------------------------------------------------------ |
aoqi@6880 | 265 | // frame::adjust_unextended_sp |
aoqi@6880 | 266 | void frame::adjust_unextended_sp() { |
aoqi@6880 | 267 | // If we are returning to a compiled MethodHandle call site, the |
aoqi@6880 | 268 | // saved_fp will in fact be a saved value of the unextended SP. The |
aoqi@6880 | 269 | // simplest way to tell whether we are returning to such a call site |
aoqi@6880 | 270 | // is as follows: |
aoqi@6880 | 271 | |
aoqi@6880 | 272 | nmethod* sender_nm = (_cb == NULL) ? NULL : _cb->as_nmethod_or_null(); |
aoqi@6880 | 273 | if (sender_nm != NULL) { |
aoqi@6880 | 274 | // If the sender PC is a deoptimization point, get the original |
aoqi@6880 | 275 | // PC. For MethodHandle call site the unextended_sp is stored in |
aoqi@6880 | 276 | // saved_fp. |
aoqi@6880 | 277 | if (sender_nm->is_deopt_mh_entry(_pc)) { |
aoqi@6880 | 278 | DEBUG_ONLY(verify_deopt_mh_original_pc(sender_nm, _fp)); |
aoqi@6880 | 279 | _unextended_sp = _fp; |
aoqi@6880 | 280 | } |
aoqi@6880 | 281 | else if (sender_nm->is_deopt_entry(_pc)) { |
aoqi@6880 | 282 | DEBUG_ONLY(verify_deopt_original_pc(sender_nm, _unextended_sp)); |
aoqi@6880 | 283 | } |
aoqi@6880 | 284 | else if (sender_nm->is_method_handle_return(_pc)) { |
aoqi@6880 | 285 | _unextended_sp = _fp; |
aoqi@6880 | 286 | } |
aoqi@1 | 287 | } |
aoqi@6880 | 288 | } |
aoqi@1 | 289 | |
aoqi@1 | 290 | //------------------------------sender_for_compiled_frame----------------------- |
aoqi@1 | 291 | frame frame::sender_for_compiled_frame(RegisterMap* map) const { |
aoqi@6880 | 292 | assert(map != NULL, "map must be set"); |
aoqi@1 | 293 | |
aoqi@8009 | 294 | // frame owned by optimizing compiler |
aoqi@8009 | 295 | assert(_cb->frame_size() >= 0, "must have non-zero frame size"); |
aoqi@8009 | 296 | |
aoqi@8009 | 297 | intptr_t* sender_sp = sender_sp = sp() + _cb->frame_size(); |
aoqi@8009 | 298 | #ifdef ASSERT |
aoqi@6880 | 299 | const bool c1_compiled = _cb->is_compiled_by_c1(); |
aoqi@6880 | 300 | bool native = _cb->is_nmethod() && ((nmethod*)_cb)->is_native_method(); |
aoqi@6880 | 301 | if (c1_compiled && native) { |
aoqi@6880 | 302 | assert(sender_sp == fp() + frame::sender_sp_offset, "incorrect frame size"); |
aoqi@6880 | 303 | } |
aoqi@1 | 304 | #endif // ASSERT |
aoqi@6880 | 305 | // On Intel the return_address is always the word on the stack |
aoqi@6880 | 306 | // the fp in compiler points to sender fp, but in interpreter, fp points to return address, |
aoqi@6880 | 307 | // so getting sender for compiled frame is not same as interpreter frame. |
aoqi@6880 | 308 | // we hard code here temporarily |
aoqi@6880 | 309 | // spark |
aoqi@6880 | 310 | address sender_pc = (address) *(sender_sp-1); |
aoqi@1 | 311 | |
aoqi@8009 | 312 | intptr_t** saved_fp_addr = (intptr_t**) (sender_sp - frame::sender_sp_offset); |
aoqi@1 | 313 | |
aoqi@6880 | 314 | if (map->update_map()) { |
aoqi@6880 | 315 | // Tell GC to use argument oopmaps for some runtime stubs that need it. |
aoqi@6880 | 316 | // For C1, the runtime stub might not have oop maps, so set this flag |
aoqi@6880 | 317 | // outside of update_register_map. |
aoqi@6880 | 318 | map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread())); |
aoqi@6880 | 319 | if (_cb->oop_maps() != NULL) { |
aoqi@6880 | 320 | OopMapSet::update_register_map(this, map); |
aoqi@6880 | 321 | } |
aoqi@8009 | 322 | |
aoqi@6880 | 323 | // Since the prolog does the save and restore of epb there is no oopmap |
aoqi@6880 | 324 | // for it so we must fill in its location as if there was an oopmap entry |
aoqi@6880 | 325 | // since if our caller was compiled code there could be live jvm state in it. |
aoqi@8009 | 326 | map->set_location(FP->as_VMReg(), (address) saved_fp_addr); |
aoqi@6880 | 327 | } |
aoqi@6880 | 328 | assert(sender_sp != sp(), "must have changed"); |
aoqi@8009 | 329 | return frame(sender_sp, *saved_fp_addr, sender_pc); |
aoqi@1 | 330 | } |
aoqi@1 | 331 | |
aoqi@1 | 332 | frame frame::sender(RegisterMap* map) const { |
aoqi@6880 | 333 | // Default is we done have to follow them. The sender_for_xxx will |
aoqi@6880 | 334 | // update it accordingly |
aoqi@6880 | 335 | map->set_include_argument_oops(false); |
aoqi@1 | 336 | |
aoqi@6880 | 337 | if (is_entry_frame()) return sender_for_entry_frame(map); |
aoqi@6880 | 338 | if (is_interpreted_frame()) return sender_for_interpreter_frame(map); |
aoqi@6880 | 339 | assert(_cb == CodeCache::find_blob(pc()),"Must be the same"); |
aoqi@1 | 340 | |
aoqi@6880 | 341 | if (_cb != NULL) { |
aoqi@6880 | 342 | return sender_for_compiled_frame(map); |
aoqi@6880 | 343 | } |
aoqi@6880 | 344 | // Must be native-compiled frame, i.e. the marshaling code for native |
aoqi@6880 | 345 | // methods that exists in the core system. |
aoqi@6880 | 346 | return frame(sender_sp(), link(), sender_pc()); |
aoqi@1 | 347 | } |
aoqi@1 | 348 | |
aoqi@1 | 349 | |
aoqi@1 | 350 | bool frame::interpreter_frame_equals_unpacked_fp(intptr_t* fp) { |
aoqi@6880 | 351 | assert(is_interpreted_frame(), "must be interpreter frame"); |
aoqi@6880 | 352 | Method* method = interpreter_frame_method(); |
aoqi@6880 | 353 | // When unpacking an optimized frame the frame pointer is |
aoqi@6880 | 354 | // adjusted with: |
aoqi@6880 | 355 | int diff = (method->max_locals() - method->size_of_parameters()) * |
aoqi@6880 | 356 | Interpreter::stackElementWords; |
aoqi@6880 | 357 | printf("^^^^^^^^^^^^^^^adjust fp in deopt fp = 0%x \n", (intptr_t)(fp - diff)); |
aoqi@6880 | 358 | return _fp == (fp - diff); |
aoqi@1 | 359 | } |
aoqi@1 | 360 | |
aoqi@1 | 361 | void frame::pd_gc_epilog() { |
aoqi@6880 | 362 | // nothing done here now |
aoqi@1 | 363 | } |
aoqi@1 | 364 | |
aoqi@1 | 365 | bool frame::is_interpreted_frame_valid(JavaThread* thread) const { |
aoqi@6880 | 366 | // QQQ |
aoqi@1 | 367 | #ifdef CC_INTERP |
aoqi@1 | 368 | #else |
aoqi@6880 | 369 | assert(is_interpreted_frame(), "Not an interpreted frame"); |
aoqi@6880 | 370 | // These are reasonable sanity checks |
aoqi@6880 | 371 | if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) { |
aoqi@6880 | 372 | return false; |
aoqi@6880 | 373 | } |
aoqi@6880 | 374 | if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) { |
aoqi@6880 | 375 | return false; |
aoqi@6880 | 376 | } |
aoqi@6880 | 377 | if (fp() + interpreter_frame_initial_sp_offset < sp()) { |
aoqi@6880 | 378 | return false; |
aoqi@6880 | 379 | } |
aoqi@6880 | 380 | // These are hacks to keep us out of trouble. |
aoqi@6880 | 381 | // The problem with these is that they mask other problems |
aoqi@6880 | 382 | if (fp() <= sp()) { // this attempts to deal with unsigned comparison above |
aoqi@6880 | 383 | return false; |
aoqi@6880 | 384 | } |
aoqi@1 | 385 | |
aoqi@6880 | 386 | // do some validation of frame elements |
aoqi@1 | 387 | |
aoqi@6880 | 388 | // first the method |
aoqi@1 | 389 | |
aoqi@6880 | 390 | Method* m = *interpreter_frame_method_addr(); |
aoqi@1 | 391 | |
aoqi@6880 | 392 | // validate the method we'd find in this potential sender |
aoqi@6880 | 393 | if (!m->is_valid_method()) return false; |
aoqi@1 | 394 | |
aoqi@6880 | 395 | // stack frames shouldn't be much larger than max_stack elements |
aoqi@1 | 396 | |
aoqi@6880 | 397 | //if (fp() - sp() > 1024 + m->max_stack()*Interpreter::stackElementSize()) { |
aoqi@6880 | 398 | if (fp() - sp() > 4096) { // stack frames shouldn't be large. |
aoqi@6880 | 399 | return false; |
aoqi@6880 | 400 | } |
aoqi@1 | 401 | |
aoqi@6880 | 402 | // validate bci/bcx |
aoqi@1 | 403 | |
aoqi@6880 | 404 | intptr_t bcx = interpreter_frame_bcx(); |
aoqi@6880 | 405 | if (m->validate_bci_from_bcx(bcx) < 0) { |
aoqi@6880 | 406 | return false; |
aoqi@6880 | 407 | } |
aoqi@1 | 408 | |
aoqi@6880 | 409 | // validate ConstantPoolCache* |
aoqi@1 | 410 | |
aoqi@6880 | 411 | ConstantPoolCache* cp = *interpreter_frame_cache_addr(); |
aoqi@1 | 412 | |
aoqi@6880 | 413 | if (cp == NULL || !cp->is_metaspace_object()) return false; |
aoqi@1 | 414 | |
aoqi@6880 | 415 | // validate locals |
aoqi@1 | 416 | |
aoqi@6880 | 417 | address locals = (address) *interpreter_frame_locals_addr(); |
aoqi@1 | 418 | |
aoqi@6880 | 419 | if (locals > thread->stack_base() || locals < (address) fp()) return false; |
aoqi@1 | 420 | |
aoqi@6880 | 421 | // We'd have to be pretty unlucky to be mislead at this point |
aoqi@1 | 422 | |
aoqi@1 | 423 | #endif // CC_INTERP |
aoqi@6880 | 424 | return true; |
aoqi@1 | 425 | } |
aoqi@1 | 426 | |
aoqi@1 | 427 | BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) { |
aoqi@1 | 428 | #ifdef CC_INTERP |
aoqi@6880 | 429 | // Needed for JVMTI. The result should always be in the interpreterState object |
aoqi@6880 | 430 | assert(false, "NYI"); |
aoqi@6880 | 431 | interpreterState istate = get_interpreterState(); |
aoqi@1 | 432 | #endif // CC_INTERP |
aoqi@6880 | 433 | assert(is_interpreted_frame(), "interpreted frame expected"); |
aoqi@6880 | 434 | Method* method = interpreter_frame_method(); |
aoqi@6880 | 435 | BasicType type = method->result_type(); |
aoqi@1 | 436 | |
aoqi@6880 | 437 | intptr_t* tos_addr; |
aoqi@6880 | 438 | if (method->is_native()) { |
aoqi@6880 | 439 | // Prior to calling into the runtime to report the method_exit the possible |
aoqi@6880 | 440 | // return value is pushed to the native stack. If the result is a jfloat/jdouble |
aoqi@6880 | 441 | // then ST0 is saved before EAX/EDX. See the note in generate_native_result |
aoqi@6880 | 442 | tos_addr = (intptr_t*)sp(); |
aoqi@6880 | 443 | if (type == T_FLOAT || type == T_DOUBLE) { |
aoqi@6880 | 444 | // QQQ seems like this code is equivalent on the two platforms |
aoqi@1 | 445 | #ifdef AMD64 |
aoqi@6880 | 446 | // This is times two because we do a push(ltos) after pushing XMM0 |
aoqi@6880 | 447 | // and that takes two interpreter stack slots. |
aoqi@6880 | 448 | tos_addr += 2 * Interpreter::stackElementWords(); |
aoqi@1 | 449 | #else |
aoqi@6880 | 450 | tos_addr += 2; |
aoqi@1 | 451 | #endif // AMD64 |
aoqi@6880 | 452 | } |
aoqi@6880 | 453 | } else { |
aoqi@6880 | 454 | tos_addr = (intptr_t*)interpreter_frame_tos_address(); |
aoqi@6880 | 455 | } |
aoqi@1 | 456 | |
aoqi@6880 | 457 | switch (type) { |
aoqi@6880 | 458 | case T_OBJECT : |
aoqi@6880 | 459 | case T_ARRAY : { |
aoqi@6880 | 460 | oop obj; |
aoqi@6880 | 461 | if (method->is_native()) { |
aoqi@1 | 462 | #ifdef CC_INTERP |
aoqi@6880 | 463 | obj = istate->_oop_temp; |
aoqi@1 | 464 | #else |
aoqi@6880 | 465 | obj = cast_to_oop(at(interpreter_frame_oop_temp_offset)); |
aoqi@1 | 466 | #endif // CC_INTERP |
aoqi@6880 | 467 | } else { |
aoqi@6880 | 468 | oop* obj_p = (oop*)tos_addr; |
aoqi@6880 | 469 | obj = (obj_p == NULL) ? (oop)NULL : *obj_p; |
aoqi@6880 | 470 | } |
aoqi@6880 | 471 | assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check"); |
aoqi@6880 | 472 | *oop_result = obj; |
aoqi@6880 | 473 | break; |
aoqi@6880 | 474 | } |
aoqi@6880 | 475 | case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break; |
aoqi@6880 | 476 | case T_BYTE : value_result->b = *(jbyte*)tos_addr; break; |
aoqi@6880 | 477 | case T_CHAR : value_result->c = *(jchar*)tos_addr; break; |
aoqi@6880 | 478 | case T_SHORT : value_result->s = *(jshort*)tos_addr; break; |
aoqi@6880 | 479 | case T_INT : value_result->i = *(jint*)tos_addr; break; |
aoqi@6880 | 480 | case T_LONG : value_result->j = *(jlong*)tos_addr; break; |
aoqi@6880 | 481 | case T_FLOAT : { |
aoqi@1 | 482 | #ifdef AMD64 |
aoqi@6880 | 483 | value_result->f = *(jfloat*)tos_addr; |
aoqi@1 | 484 | #else |
aoqi@6880 | 485 | if (method->is_native()) { |
aoqi@6880 | 486 | jdouble d = *(jdouble*)tos_addr; // Result was in ST0 so need to convert to jfloat |
aoqi@6880 | 487 | value_result->f = (jfloat)d; |
aoqi@6880 | 488 | } else { |
aoqi@6880 | 489 | value_result->f = *(jfloat*)tos_addr; |
aoqi@6880 | 490 | } |
aoqi@1 | 491 | #endif // AMD64 |
aoqi@6880 | 492 | break; |
aoqi@6880 | 493 | } |
aoqi@6880 | 494 | case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break; |
aoqi@6880 | 495 | case T_VOID : /* Nothing to do */ break; |
aoqi@6880 | 496 | default : ShouldNotReachHere(); |
aoqi@6880 | 497 | } |
aoqi@1 | 498 | |
aoqi@6880 | 499 | return type; |
aoqi@1 | 500 | } |
aoqi@1 | 501 | |
aoqi@1 | 502 | |
aoqi@1 | 503 | intptr_t* frame::interpreter_frame_tos_at(jint offset) const { |
aoqi@6880 | 504 | int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize); |
aoqi@6880 | 505 | return &interpreter_frame_tos_address()[index]; |
aoqi@1 | 506 | } |
aoqi@1 | 507 | |
aoqi@1 | 508 | #ifndef PRODUCT |
aoqi@1 | 509 | |
aoqi@1 | 510 | #define DESCRIBE_FP_OFFSET(name) \ |
aoqi@1 | 511 | values.describe(frame_no, fp() + frame::name##_offset, #name) |
aoqi@1 | 512 | |
aoqi@1 | 513 | void frame::describe_pd(FrameValues& values, int frame_no) { |
aoqi@1 | 514 | if (is_interpreted_frame()) { |
aoqi@1 | 515 | DESCRIBE_FP_OFFSET(interpreter_frame_sender_sp); |
aoqi@1 | 516 | DESCRIBE_FP_OFFSET(interpreter_frame_last_sp); |
aoqi@1 | 517 | DESCRIBE_FP_OFFSET(interpreter_frame_method); |
aoqi@1 | 518 | DESCRIBE_FP_OFFSET(interpreter_frame_mdx); |
aoqi@1 | 519 | DESCRIBE_FP_OFFSET(interpreter_frame_cache); |
aoqi@1 | 520 | DESCRIBE_FP_OFFSET(interpreter_frame_locals); |
aoqi@1 | 521 | DESCRIBE_FP_OFFSET(interpreter_frame_bcx); |
aoqi@1 | 522 | DESCRIBE_FP_OFFSET(interpreter_frame_initial_sp); |
aoqi@1 | 523 | } |
aoqi@1 | 524 | } |
aoqi@1 | 525 | #endif |
aoqi@1 | 526 | |
aoqi@1 | 527 | intptr_t *frame::initial_deoptimization_info() { |
aoqi@1 | 528 | // used to reset the saved FP |
aoqi@6880 | 529 | return fp(); |
aoqi@6880 | 530 | } |
aoqi@1 | 531 | |
aoqi@1 | 532 | intptr_t* frame::real_fp() const { |
aoqi@1 | 533 | if (_cb != NULL) { |
aoqi@1 | 534 | // use the frame size if valid |
aoqi@6880 | 535 | int size = _cb->frame_size(); |
aoqi@1 | 536 | if (size > 0) { |
aoqi@1 | 537 | return unextended_sp() + size; |
aoqi@1 | 538 | } |
aoqi@1 | 539 | } |
aoqi@1 | 540 | // else rely on fp() |
aoqi@6880 | 541 | assert(! is_compiled_frame(), "unknown compiled frame size"); |
aoqi@1 | 542 | return fp(); |
aoqi@1 | 543 | } |
aoqi@7996 | 544 | |
aoqi@7996 | 545 | #ifndef PRODUCT |
aoqi@7996 | 546 | // This is a generic constructor which is only used by pns() in debug.cpp. |
aoqi@7996 | 547 | frame::frame(void* sp, void* fp, void* pc) { |
aoqi@7996 | 548 | init((intptr_t*)sp, (intptr_t*)fp, (address)pc); |
aoqi@7996 | 549 | } |
aoqi@7996 | 550 | #endif |