Thu, 04 Sep 2014 16:53:27 -0700
8057531: refactor gc argument processing code slightly
Reviewed-by: mgerdin, tschatzl, jmasa
duke@435 | 1 | /* |
drchase@6680 | 2 | * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "classfile/vmSymbols.hpp" |
twisti@3969 | 27 | #include "interpreter/bytecode.hpp" |
stefank@2314 | 28 | #include "interpreter/interpreter.hpp" |
stefank@2314 | 29 | #include "memory/allocation.inline.hpp" |
stefank@2314 | 30 | #include "memory/resourceArea.hpp" |
stefank@2314 | 31 | #include "memory/universe.inline.hpp" |
coleenp@4037 | 32 | #include "oops/methodData.hpp" |
stefank@2314 | 33 | #include "oops/oop.inline.hpp" |
stefank@2314 | 34 | #include "prims/jvmtiThreadState.hpp" |
stefank@2314 | 35 | #include "runtime/handles.inline.hpp" |
stefank@2314 | 36 | #include "runtime/monitorChunk.hpp" |
stefank@2314 | 37 | #include "runtime/sharedRuntime.hpp" |
stefank@2314 | 38 | #include "runtime/vframe.hpp" |
stefank@2314 | 39 | #include "runtime/vframeArray.hpp" |
stefank@2314 | 40 | #include "runtime/vframe_hp.hpp" |
stefank@2314 | 41 | #include "utilities/events.hpp" |
stefank@2314 | 42 | #ifdef COMPILER2 |
stefank@2314 | 43 | #include "opto/runtime.hpp" |
stefank@2314 | 44 | #endif |
duke@435 | 45 | |
drchase@6680 | 46 | PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
duke@435 | 47 | |
duke@435 | 48 | int vframeArrayElement:: bci(void) const { return (_bci == SynchronizationEntryBCI ? 0 : _bci); } |
duke@435 | 49 | |
duke@435 | 50 | void vframeArrayElement::free_monitors(JavaThread* jt) { |
duke@435 | 51 | if (_monitors != NULL) { |
duke@435 | 52 | MonitorChunk* chunk = _monitors; |
duke@435 | 53 | _monitors = NULL; |
duke@435 | 54 | jt->remove_monitor_chunk(chunk); |
duke@435 | 55 | delete chunk; |
duke@435 | 56 | } |
duke@435 | 57 | } |
duke@435 | 58 | |
duke@435 | 59 | void vframeArrayElement::fill_in(compiledVFrame* vf) { |
duke@435 | 60 | |
duke@435 | 61 | // Copy the information from the compiled vframe to the |
duke@435 | 62 | // interpreter frame we will be creating to replace vf |
duke@435 | 63 | |
duke@435 | 64 | _method = vf->method(); |
duke@435 | 65 | _bci = vf->raw_bci(); |
cfang@1335 | 66 | _reexecute = vf->should_reexecute(); |
duke@435 | 67 | |
duke@435 | 68 | int index; |
duke@435 | 69 | |
duke@435 | 70 | // Get the monitors off-stack |
duke@435 | 71 | |
duke@435 | 72 | GrowableArray<MonitorInfo*>* list = vf->monitors(); |
duke@435 | 73 | if (list->is_empty()) { |
duke@435 | 74 | _monitors = NULL; |
duke@435 | 75 | } else { |
duke@435 | 76 | |
duke@435 | 77 | // Allocate monitor chunk |
duke@435 | 78 | _monitors = new MonitorChunk(list->length()); |
duke@435 | 79 | vf->thread()->add_monitor_chunk(_monitors); |
duke@435 | 80 | |
duke@435 | 81 | // Migrate the BasicLocks from the stack to the monitor chunk |
duke@435 | 82 | for (index = 0; index < list->length(); index++) { |
duke@435 | 83 | MonitorInfo* monitor = list->at(index); |
kvn@1253 | 84 | assert(!monitor->owner_is_scalar_replaced(), "object should be reallocated already"); |
duke@435 | 85 | assert(monitor->owner() == NULL || (!monitor->owner()->is_unlocked() && !monitor->owner()->has_bias_pattern()), "object must be null or locked, and unbiased"); |
duke@435 | 86 | BasicObjectLock* dest = _monitors->at(index); |
duke@435 | 87 | dest->set_obj(monitor->owner()); |
duke@435 | 88 | monitor->lock()->move_to(monitor->owner(), dest->lock()); |
duke@435 | 89 | } |
duke@435 | 90 | } |
duke@435 | 91 | |
duke@435 | 92 | // Convert the vframe locals and expressions to off stack |
duke@435 | 93 | // values. Because we will not gc all oops can be converted to |
duke@435 | 94 | // intptr_t (i.e. a stack slot) and we are fine. This is |
duke@435 | 95 | // good since we are inside a HandleMark and the oops in our |
duke@435 | 96 | // collection would go away between packing them here and |
duke@435 | 97 | // unpacking them in unpack_on_stack. |
duke@435 | 98 | |
duke@435 | 99 | // First the locals go off-stack |
duke@435 | 100 | |
duke@435 | 101 | // FIXME this seems silly it creates a StackValueCollection |
duke@435 | 102 | // in order to get the size to then copy them and |
duke@435 | 103 | // convert the types to intptr_t size slots. Seems like it |
duke@435 | 104 | // could do it in place... Still uses less memory than the |
duke@435 | 105 | // old way though |
duke@435 | 106 | |
duke@435 | 107 | StackValueCollection *locs = vf->locals(); |
duke@435 | 108 | _locals = new StackValueCollection(locs->size()); |
duke@435 | 109 | for(index = 0; index < locs->size(); index++) { |
duke@435 | 110 | StackValue* value = locs->at(index); |
duke@435 | 111 | switch(value->type()) { |
duke@435 | 112 | case T_OBJECT: |
kvn@1253 | 113 | assert(!value->obj_is_scalar_replaced(), "object should be reallocated already"); |
duke@435 | 114 | // preserve object type |
hseigel@5784 | 115 | _locals->add( new StackValue(cast_from_oop<intptr_t>((value->get_obj()())), T_OBJECT )); |
duke@435 | 116 | break; |
duke@435 | 117 | case T_CONFLICT: |
duke@435 | 118 | // A dead local. Will be initialized to null/zero. |
duke@435 | 119 | _locals->add( new StackValue()); |
duke@435 | 120 | break; |
duke@435 | 121 | case T_INT: |
duke@435 | 122 | _locals->add( new StackValue(value->get_int())); |
duke@435 | 123 | break; |
duke@435 | 124 | default: |
duke@435 | 125 | ShouldNotReachHere(); |
duke@435 | 126 | } |
duke@435 | 127 | } |
duke@435 | 128 | |
duke@435 | 129 | // Now the expressions off-stack |
duke@435 | 130 | // Same silliness as above |
duke@435 | 131 | |
duke@435 | 132 | StackValueCollection *exprs = vf->expressions(); |
duke@435 | 133 | _expressions = new StackValueCollection(exprs->size()); |
duke@435 | 134 | for(index = 0; index < exprs->size(); index++) { |
duke@435 | 135 | StackValue* value = exprs->at(index); |
duke@435 | 136 | switch(value->type()) { |
duke@435 | 137 | case T_OBJECT: |
kvn@1253 | 138 | assert(!value->obj_is_scalar_replaced(), "object should be reallocated already"); |
duke@435 | 139 | // preserve object type |
hseigel@5784 | 140 | _expressions->add( new StackValue(cast_from_oop<intptr_t>((value->get_obj()())), T_OBJECT )); |
duke@435 | 141 | break; |
duke@435 | 142 | case T_CONFLICT: |
duke@435 | 143 | // A dead stack element. Will be initialized to null/zero. |
duke@435 | 144 | // This can occur when the compiler emits a state in which stack |
duke@435 | 145 | // elements are known to be dead (because of an imminent exception). |
duke@435 | 146 | _expressions->add( new StackValue()); |
duke@435 | 147 | break; |
duke@435 | 148 | case T_INT: |
duke@435 | 149 | _expressions->add( new StackValue(value->get_int())); |
duke@435 | 150 | break; |
duke@435 | 151 | default: |
duke@435 | 152 | ShouldNotReachHere(); |
duke@435 | 153 | } |
duke@435 | 154 | } |
duke@435 | 155 | } |
duke@435 | 156 | |
duke@435 | 157 | int unpack_counter = 0; |
duke@435 | 158 | |
never@2901 | 159 | void vframeArrayElement::unpack_on_stack(int caller_actual_parameters, |
never@2901 | 160 | int callee_parameters, |
duke@435 | 161 | int callee_locals, |
duke@435 | 162 | frame* caller, |
duke@435 | 163 | bool is_top_frame, |
roland@4727 | 164 | bool is_bottom_frame, |
duke@435 | 165 | int exec_mode) { |
duke@435 | 166 | JavaThread* thread = (JavaThread*) Thread::current(); |
duke@435 | 167 | |
duke@435 | 168 | // Look at bci and decide on bcp and continuation pc |
duke@435 | 169 | address bcp; |
duke@435 | 170 | // C++ interpreter doesn't need a pc since it will figure out what to do when it |
duke@435 | 171 | // begins execution |
duke@435 | 172 | address pc; |
cfang@1335 | 173 | bool use_next_mdp = false; // true if we should use the mdp associated with the next bci |
cfang@1335 | 174 | // rather than the one associated with bcp |
duke@435 | 175 | if (raw_bci() == SynchronizationEntryBCI) { |
duke@435 | 176 | // We are deoptimizing while hanging in prologue code for synchronized method |
duke@435 | 177 | bcp = method()->bcp_from(0); // first byte code |
duke@435 | 178 | pc = Interpreter::deopt_entry(vtos, 0); // step = 0 since we don't skip current bytecode |
cfang@1335 | 179 | } else if (should_reexecute()) { //reexecute this bytecode |
cfang@1335 | 180 | assert(is_top_frame, "reexecute allowed only for the top frame"); |
cfang@1335 | 181 | bcp = method()->bcp_from(bci()); |
cfang@1335 | 182 | pc = Interpreter::deopt_reexecute_entry(method(), bcp); |
duke@435 | 183 | } else { |
duke@435 | 184 | bcp = method()->bcp_from(bci()); |
cfang@1335 | 185 | pc = Interpreter::deopt_continue_after_entry(method(), bcp, callee_parameters, is_top_frame); |
cfang@1335 | 186 | use_next_mdp = true; |
duke@435 | 187 | } |
duke@435 | 188 | assert(Bytecodes::is_defined(*bcp), "must be a valid bytecode"); |
duke@435 | 189 | |
duke@435 | 190 | // Monitorenter and pending exceptions: |
duke@435 | 191 | // |
duke@435 | 192 | // For Compiler2, there should be no pending exception when deoptimizing at monitorenter |
duke@435 | 193 | // because there is no safepoint at the null pointer check (it is either handled explicitly |
duke@435 | 194 | // or prior to the monitorenter) and asynchronous exceptions are not made "pending" by the |
duke@435 | 195 | // runtime interface for the slow case (see JRT_ENTRY_FOR_MONITORENTER). If an asynchronous |
duke@435 | 196 | // exception was processed, the bytecode pointer would have to be extended one bytecode beyond |
duke@435 | 197 | // the monitorenter to place it in the proper exception range. |
duke@435 | 198 | // |
duke@435 | 199 | // For Compiler1, deoptimization can occur while throwing a NullPointerException at monitorenter, |
duke@435 | 200 | // in which case bcp should point to the monitorenter since it is within the exception's range. |
duke@435 | 201 | |
duke@435 | 202 | assert(*bcp != Bytecodes::_monitorenter || is_top_frame, "a _monitorenter must be a top frame"); |
iveresov@2169 | 203 | assert(thread->deopt_nmethod() != NULL, "nmethod should be known"); |
iveresov@2169 | 204 | guarantee(!(thread->deopt_nmethod()->is_compiled_by_c2() && |
iveresov@2169 | 205 | *bcp == Bytecodes::_monitorenter && |
iveresov@2169 | 206 | exec_mode == Deoptimization::Unpack_exception), |
iveresov@2169 | 207 | "shouldn't get exception during monitorenter"); |
duke@435 | 208 | |
duke@435 | 209 | int popframe_preserved_args_size_in_bytes = 0; |
duke@435 | 210 | int popframe_preserved_args_size_in_words = 0; |
duke@435 | 211 | if (is_top_frame) { |
kvn@1690 | 212 | JvmtiThreadState *state = thread->jvmti_thread_state(); |
duke@435 | 213 | if (JvmtiExport::can_pop_frame() && |
duke@435 | 214 | (thread->has_pending_popframe() || thread->popframe_forcing_deopt_reexecution())) { |
duke@435 | 215 | if (thread->has_pending_popframe()) { |
duke@435 | 216 | // Pop top frame after deoptimization |
duke@435 | 217 | #ifndef CC_INTERP |
duke@435 | 218 | pc = Interpreter::remove_activation_preserving_args_entry(); |
duke@435 | 219 | #else |
duke@435 | 220 | // Do an uncommon trap type entry. c++ interpreter will know |
duke@435 | 221 | // to pop frame and preserve the args |
duke@435 | 222 | pc = Interpreter::deopt_entry(vtos, 0); |
duke@435 | 223 | use_next_mdp = false; |
duke@435 | 224 | #endif |
duke@435 | 225 | } else { |
duke@435 | 226 | // Reexecute invoke in top frame |
duke@435 | 227 | pc = Interpreter::deopt_entry(vtos, 0); |
duke@435 | 228 | use_next_mdp = false; |
duke@435 | 229 | popframe_preserved_args_size_in_bytes = in_bytes(thread->popframe_preserved_args_size()); |
duke@435 | 230 | // Note: the PopFrame-related extension of the expression stack size is done in |
duke@435 | 231 | // Deoptimization::fetch_unroll_info_helper |
duke@435 | 232 | popframe_preserved_args_size_in_words = in_words(thread->popframe_preserved_args_size_in_words()); |
duke@435 | 233 | } |
duke@435 | 234 | } else if (JvmtiExport::can_force_early_return() && state != NULL && state->is_earlyret_pending()) { |
duke@435 | 235 | // Force early return from top frame after deoptimization |
duke@435 | 236 | #ifndef CC_INTERP |
duke@435 | 237 | pc = Interpreter::remove_activation_early_entry(state->earlyret_tos()); |
duke@435 | 238 | #endif |
duke@435 | 239 | } else { |
duke@435 | 240 | // Possibly override the previous pc computation of the top (youngest) frame |
duke@435 | 241 | switch (exec_mode) { |
duke@435 | 242 | case Deoptimization::Unpack_deopt: |
duke@435 | 243 | // use what we've got |
duke@435 | 244 | break; |
duke@435 | 245 | case Deoptimization::Unpack_exception: |
duke@435 | 246 | // exception is pending |
twisti@1730 | 247 | pc = SharedRuntime::raw_exception_handler_for_return_address(thread, pc); |
duke@435 | 248 | // [phh] We're going to end up in some handler or other, so it doesn't |
duke@435 | 249 | // matter what mdp we point to. See exception_handler_for_exception() |
duke@435 | 250 | // in interpreterRuntime.cpp. |
duke@435 | 251 | break; |
duke@435 | 252 | case Deoptimization::Unpack_uncommon_trap: |
duke@435 | 253 | case Deoptimization::Unpack_reexecute: |
duke@435 | 254 | // redo last byte code |
duke@435 | 255 | pc = Interpreter::deopt_entry(vtos, 0); |
duke@435 | 256 | use_next_mdp = false; |
duke@435 | 257 | break; |
duke@435 | 258 | default: |
duke@435 | 259 | ShouldNotReachHere(); |
duke@435 | 260 | } |
duke@435 | 261 | } |
duke@435 | 262 | } |
duke@435 | 263 | |
duke@435 | 264 | // Setup the interpreter frame |
duke@435 | 265 | |
duke@435 | 266 | assert(method() != NULL, "method must exist"); |
duke@435 | 267 | int temps = expressions()->size(); |
duke@435 | 268 | |
duke@435 | 269 | int locks = monitors() == NULL ? 0 : monitors()->number_of_monitors(); |
duke@435 | 270 | |
duke@435 | 271 | Interpreter::layout_activation(method(), |
duke@435 | 272 | temps + callee_parameters, |
duke@435 | 273 | popframe_preserved_args_size_in_words, |
duke@435 | 274 | locks, |
never@2901 | 275 | caller_actual_parameters, |
duke@435 | 276 | callee_parameters, |
duke@435 | 277 | callee_locals, |
duke@435 | 278 | caller, |
duke@435 | 279 | iframe(), |
roland@4727 | 280 | is_top_frame, |
roland@4727 | 281 | is_bottom_frame); |
duke@435 | 282 | |
duke@435 | 283 | // Update the pc in the frame object and overwrite the temporary pc |
duke@435 | 284 | // we placed in the skeletal frame now that we finally know the |
duke@435 | 285 | // exact interpreter address we should use. |
duke@435 | 286 | |
duke@435 | 287 | _frame.patch_pc(thread, pc); |
duke@435 | 288 | |
duke@435 | 289 | assert (!method()->is_synchronized() || locks > 0, "synchronized methods must have monitors"); |
duke@435 | 290 | |
duke@435 | 291 | BasicObjectLock* top = iframe()->interpreter_frame_monitor_begin(); |
duke@435 | 292 | for (int index = 0; index < locks; index++) { |
duke@435 | 293 | top = iframe()->previous_monitor_in_interpreter_frame(top); |
duke@435 | 294 | BasicObjectLock* src = _monitors->at(index); |
duke@435 | 295 | top->set_obj(src->obj()); |
duke@435 | 296 | src->lock()->move_to(src->obj(), top->lock()); |
duke@435 | 297 | } |
duke@435 | 298 | if (ProfileInterpreter) { |
duke@435 | 299 | iframe()->interpreter_frame_set_mdx(0); // clear out the mdp. |
duke@435 | 300 | } |
duke@435 | 301 | iframe()->interpreter_frame_set_bcx((intptr_t)bcp); // cannot use bcp because frame is not initialized yet |
duke@435 | 302 | if (ProfileInterpreter) { |
coleenp@4037 | 303 | MethodData* mdo = method()->method_data(); |
duke@435 | 304 | if (mdo != NULL) { |
duke@435 | 305 | int bci = iframe()->interpreter_frame_bci(); |
duke@435 | 306 | if (use_next_mdp) ++bci; |
duke@435 | 307 | address mdp = mdo->bci_to_dp(bci); |
duke@435 | 308 | iframe()->interpreter_frame_set_mdp(mdp); |
duke@435 | 309 | } |
duke@435 | 310 | } |
duke@435 | 311 | |
duke@435 | 312 | // Unpack expression stack |
duke@435 | 313 | // If this is an intermediate frame (i.e. not top frame) then this |
duke@435 | 314 | // only unpacks the part of the expression stack not used by callee |
duke@435 | 315 | // as parameters. The callee parameters are unpacked as part of the |
duke@435 | 316 | // callee locals. |
duke@435 | 317 | int i; |
duke@435 | 318 | for(i = 0; i < expressions()->size(); i++) { |
duke@435 | 319 | StackValue *value = expressions()->at(i); |
duke@435 | 320 | intptr_t* addr = iframe()->interpreter_frame_expression_stack_at(i); |
duke@435 | 321 | switch(value->type()) { |
duke@435 | 322 | case T_INT: |
duke@435 | 323 | *addr = value->get_int(); |
duke@435 | 324 | break; |
duke@435 | 325 | case T_OBJECT: |
duke@435 | 326 | *addr = value->get_int(T_OBJECT); |
duke@435 | 327 | break; |
duke@435 | 328 | case T_CONFLICT: |
duke@435 | 329 | // A dead stack slot. Initialize to null in case it is an oop. |
duke@435 | 330 | *addr = NULL_WORD; |
duke@435 | 331 | break; |
duke@435 | 332 | default: |
duke@435 | 333 | ShouldNotReachHere(); |
duke@435 | 334 | } |
duke@435 | 335 | } |
duke@435 | 336 | |
duke@435 | 337 | |
duke@435 | 338 | // Unpack the locals |
duke@435 | 339 | for(i = 0; i < locals()->size(); i++) { |
duke@435 | 340 | StackValue *value = locals()->at(i); |
duke@435 | 341 | intptr_t* addr = iframe()->interpreter_frame_local_at(i); |
duke@435 | 342 | switch(value->type()) { |
duke@435 | 343 | case T_INT: |
duke@435 | 344 | *addr = value->get_int(); |
duke@435 | 345 | break; |
duke@435 | 346 | case T_OBJECT: |
duke@435 | 347 | *addr = value->get_int(T_OBJECT); |
duke@435 | 348 | break; |
duke@435 | 349 | case T_CONFLICT: |
duke@435 | 350 | // A dead location. If it is an oop then we need a NULL to prevent GC from following it |
duke@435 | 351 | *addr = NULL_WORD; |
duke@435 | 352 | break; |
duke@435 | 353 | default: |
duke@435 | 354 | ShouldNotReachHere(); |
duke@435 | 355 | } |
duke@435 | 356 | } |
duke@435 | 357 | |
duke@435 | 358 | if (is_top_frame && JvmtiExport::can_pop_frame() && thread->popframe_forcing_deopt_reexecution()) { |
duke@435 | 359 | // An interpreted frame was popped but it returns to a deoptimized |
duke@435 | 360 | // frame. The incoming arguments to the interpreted activation |
duke@435 | 361 | // were preserved in thread-local storage by the |
duke@435 | 362 | // remove_activation_preserving_args_entry in the interpreter; now |
duke@435 | 363 | // we put them back into the just-unpacked interpreter frame. |
duke@435 | 364 | // Note that this assumes that the locals arena grows toward lower |
duke@435 | 365 | // addresses. |
duke@435 | 366 | if (popframe_preserved_args_size_in_words != 0) { |
duke@435 | 367 | void* saved_args = thread->popframe_preserved_args(); |
duke@435 | 368 | assert(saved_args != NULL, "must have been saved by interpreter"); |
duke@435 | 369 | #ifdef ASSERT |
duke@435 | 370 | assert(popframe_preserved_args_size_in_words <= |
twisti@1861 | 371 | iframe()->interpreter_frame_expression_stack_size()*Interpreter::stackElementWords, |
duke@435 | 372 | "expression stack size should have been extended"); |
duke@435 | 373 | #endif // ASSERT |
duke@435 | 374 | int top_element = iframe()->interpreter_frame_expression_stack_size()-1; |
duke@435 | 375 | intptr_t* base; |
duke@435 | 376 | if (frame::interpreter_frame_expression_stack_direction() < 0) { |
duke@435 | 377 | base = iframe()->interpreter_frame_expression_stack_at(top_element); |
duke@435 | 378 | } else { |
duke@435 | 379 | base = iframe()->interpreter_frame_expression_stack(); |
duke@435 | 380 | } |
kvn@1958 | 381 | Copy::conjoint_jbytes(saved_args, |
kvn@1958 | 382 | base, |
kvn@1958 | 383 | popframe_preserved_args_size_in_bytes); |
duke@435 | 384 | thread->popframe_free_preserved_args(); |
duke@435 | 385 | } |
duke@435 | 386 | } |
duke@435 | 387 | |
duke@435 | 388 | #ifndef PRODUCT |
duke@435 | 389 | if (TraceDeoptimization && Verbose) { |
duke@435 | 390 | ttyLocker ttyl; |
duke@435 | 391 | tty->print_cr("[%d Interpreted Frame]", ++unpack_counter); |
duke@435 | 392 | iframe()->print_on(tty); |
duke@435 | 393 | RegisterMap map(thread); |
duke@435 | 394 | vframe* f = vframe::new_vframe(iframe(), &map, thread); |
duke@435 | 395 | f->print(); |
duke@435 | 396 | |
duke@435 | 397 | tty->print_cr("locals size %d", locals()->size()); |
duke@435 | 398 | tty->print_cr("expression size %d", expressions()->size()); |
duke@435 | 399 | |
duke@435 | 400 | method()->print_value(); |
duke@435 | 401 | tty->cr(); |
duke@435 | 402 | // method()->print_codes(); |
duke@435 | 403 | } else if (TraceDeoptimization) { |
duke@435 | 404 | tty->print(" "); |
duke@435 | 405 | method()->print_value(); |
never@2462 | 406 | Bytecodes::Code code = Bytecodes::java_code_at(method(), bcp); |
duke@435 | 407 | int bci = method()->bci_from(bcp); |
duke@435 | 408 | tty->print(" - %s", Bytecodes::name(code)); |
duke@435 | 409 | tty->print(" @ bci %d ", bci); |
duke@435 | 410 | tty->print_cr("sp = " PTR_FORMAT, iframe()->sp()); |
duke@435 | 411 | } |
duke@435 | 412 | #endif // PRODUCT |
duke@435 | 413 | |
duke@435 | 414 | // The expression stack and locals are in the resource area don't leave |
duke@435 | 415 | // a dangling pointer in the vframeArray we leave around for debug |
duke@435 | 416 | // purposes |
duke@435 | 417 | |
duke@435 | 418 | _locals = _expressions = NULL; |
duke@435 | 419 | |
duke@435 | 420 | } |
duke@435 | 421 | |
roland@6723 | 422 | int vframeArrayElement::on_stack_size(int callee_parameters, |
duke@435 | 423 | int callee_locals, |
duke@435 | 424 | bool is_top_frame, |
duke@435 | 425 | int popframe_extra_stack_expression_els) const { |
duke@435 | 426 | assert(method()->max_locals() == locals()->size(), "just checking"); |
duke@435 | 427 | int locks = monitors() == NULL ? 0 : monitors()->number_of_monitors(); |
duke@435 | 428 | int temps = expressions()->size(); |
roland@6723 | 429 | return Interpreter::size_activation(method()->max_stack(), |
duke@435 | 430 | temps + callee_parameters, |
duke@435 | 431 | popframe_extra_stack_expression_els, |
duke@435 | 432 | locks, |
duke@435 | 433 | callee_parameters, |
duke@435 | 434 | callee_locals, |
roland@6723 | 435 | is_top_frame); |
duke@435 | 436 | } |
duke@435 | 437 | |
duke@435 | 438 | |
duke@435 | 439 | |
duke@435 | 440 | vframeArray* vframeArray::allocate(JavaThread* thread, int frame_size, GrowableArray<compiledVFrame*>* chunk, |
duke@435 | 441 | RegisterMap *reg_map, frame sender, frame caller, frame self) { |
duke@435 | 442 | |
duke@435 | 443 | // Allocate the vframeArray |
duke@435 | 444 | vframeArray * result = (vframeArray*) AllocateHeap(sizeof(vframeArray) + // fixed part |
duke@435 | 445 | sizeof(vframeArrayElement) * (chunk->length() - 1), // variable part |
zgu@3900 | 446 | mtCompiler); |
duke@435 | 447 | result->_frames = chunk->length(); |
duke@435 | 448 | result->_owner_thread = thread; |
duke@435 | 449 | result->_sender = sender; |
duke@435 | 450 | result->_caller = caller; |
duke@435 | 451 | result->_original = self; |
duke@435 | 452 | result->set_unroll_block(NULL); // initialize it |
duke@435 | 453 | result->fill_in(thread, frame_size, chunk, reg_map); |
duke@435 | 454 | return result; |
duke@435 | 455 | } |
duke@435 | 456 | |
duke@435 | 457 | void vframeArray::fill_in(JavaThread* thread, |
duke@435 | 458 | int frame_size, |
duke@435 | 459 | GrowableArray<compiledVFrame*>* chunk, |
duke@435 | 460 | const RegisterMap *reg_map) { |
duke@435 | 461 | // Set owner first, it is used when adding monitor chunks |
duke@435 | 462 | |
duke@435 | 463 | _frame_size = frame_size; |
duke@435 | 464 | for(int i = 0; i < chunk->length(); i++) { |
duke@435 | 465 | element(i)->fill_in(chunk->at(i)); |
duke@435 | 466 | } |
duke@435 | 467 | |
duke@435 | 468 | // Copy registers for callee-saved registers |
duke@435 | 469 | if (reg_map != NULL) { |
duke@435 | 470 | for(int i = 0; i < RegisterMap::reg_count; i++) { |
duke@435 | 471 | #ifdef AMD64 |
duke@435 | 472 | // The register map has one entry for every int (32-bit value), so |
duke@435 | 473 | // 64-bit physical registers have two entries in the map, one for |
duke@435 | 474 | // each half. Ignore the high halves of 64-bit registers, just like |
duke@435 | 475 | // frame::oopmapreg_to_location does. |
duke@435 | 476 | // |
duke@435 | 477 | // [phh] FIXME: this is a temporary hack! This code *should* work |
duke@435 | 478 | // correctly w/o this hack, possibly by changing RegisterMap::pd_location |
duke@435 | 479 | // in frame_amd64.cpp and the values of the phantom high half registers |
duke@435 | 480 | // in amd64.ad. |
duke@435 | 481 | // if (VMReg::Name(i) < SharedInfo::stack0 && is_even(i)) { |
duke@435 | 482 | intptr_t* src = (intptr_t*) reg_map->location(VMRegImpl::as_VMReg(i)); |
duke@435 | 483 | _callee_registers[i] = src != NULL ? *src : NULL_WORD; |
duke@435 | 484 | // } else { |
duke@435 | 485 | // jint* src = (jint*) reg_map->location(VMReg::Name(i)); |
duke@435 | 486 | // _callee_registers[i] = src != NULL ? *src : NULL_WORD; |
duke@435 | 487 | // } |
duke@435 | 488 | #else |
duke@435 | 489 | jint* src = (jint*) reg_map->location(VMRegImpl::as_VMReg(i)); |
duke@435 | 490 | _callee_registers[i] = src != NULL ? *src : NULL_WORD; |
duke@435 | 491 | #endif |
duke@435 | 492 | if (src == NULL) { |
duke@435 | 493 | set_location_valid(i, false); |
duke@435 | 494 | } else { |
duke@435 | 495 | set_location_valid(i, true); |
duke@435 | 496 | jint* dst = (jint*) register_location(i); |
duke@435 | 497 | *dst = *src; |
duke@435 | 498 | } |
duke@435 | 499 | } |
duke@435 | 500 | } |
duke@435 | 501 | } |
duke@435 | 502 | |
never@2901 | 503 | void vframeArray::unpack_to_stack(frame &unpack_frame, int exec_mode, int caller_actual_parameters) { |
duke@435 | 504 | // stack picture |
duke@435 | 505 | // unpack_frame |
duke@435 | 506 | // [new interpreter frames ] (frames are skeletal but walkable) |
duke@435 | 507 | // caller_frame |
duke@435 | 508 | // |
duke@435 | 509 | // This routine fills in the missing data for the skeletal interpreter frames |
duke@435 | 510 | // in the above picture. |
duke@435 | 511 | |
duke@435 | 512 | // Find the skeletal interpreter frames to unpack into |
twisti@3969 | 513 | JavaThread* THREAD = JavaThread::current(); |
twisti@3969 | 514 | RegisterMap map(THREAD, false); |
duke@435 | 515 | // Get the youngest frame we will unpack (last to be unpacked) |
duke@435 | 516 | frame me = unpack_frame.sender(&map); |
duke@435 | 517 | int index; |
duke@435 | 518 | for (index = 0; index < frames(); index++ ) { |
duke@435 | 519 | *element(index)->iframe() = me; |
duke@435 | 520 | // Get the caller frame (possibly skeletal) |
duke@435 | 521 | me = me.sender(&map); |
duke@435 | 522 | } |
duke@435 | 523 | |
twisti@3969 | 524 | // Do the unpacking of interpreter frames; the frame at index 0 represents the top activation, so it has no callee |
twisti@3969 | 525 | // Unpack the frames from the oldest (frames() -1) to the youngest (0) |
roland@4727 | 526 | frame* caller_frame = &me; |
duke@435 | 527 | for (index = frames() - 1; index >= 0 ; index--) { |
twisti@3969 | 528 | vframeArrayElement* elem = element(index); // caller |
twisti@3969 | 529 | int callee_parameters, callee_locals; |
twisti@3969 | 530 | if (index == 0) { |
twisti@3969 | 531 | callee_parameters = callee_locals = 0; |
twisti@3969 | 532 | } else { |
twisti@3969 | 533 | methodHandle caller = elem->method(); |
twisti@3969 | 534 | methodHandle callee = element(index - 1)->method(); |
twisti@3969 | 535 | Bytecode_invoke inv(caller, elem->bci()); |
twisti@3969 | 536 | // invokedynamic instructions don't have a class but obviously don't have a MemberName appendix. |
twisti@3969 | 537 | // NOTE: Use machinery here that avoids resolving of any kind. |
twisti@3969 | 538 | const bool has_member_arg = |
twisti@3969 | 539 | !inv.is_invokedynamic() && MethodHandles::has_member_arg(inv.klass(), inv.name()); |
twisti@3969 | 540 | callee_parameters = callee->size_of_parameters() + (has_member_arg ? 1 : 0); |
twisti@3969 | 541 | callee_locals = callee->max_locals(); |
twisti@3969 | 542 | } |
twisti@3969 | 543 | elem->unpack_on_stack(caller_actual_parameters, |
twisti@3969 | 544 | callee_parameters, |
twisti@3969 | 545 | callee_locals, |
roland@4727 | 546 | caller_frame, |
twisti@3969 | 547 | index == 0, |
roland@4727 | 548 | index == frames() - 1, |
twisti@3969 | 549 | exec_mode); |
duke@435 | 550 | if (index == frames() - 1) { |
twisti@3969 | 551 | Deoptimization::unwind_callee_save_values(elem->iframe(), this); |
duke@435 | 552 | } |
roland@4727 | 553 | caller_frame = elem->iframe(); |
never@2901 | 554 | caller_actual_parameters = callee_parameters; |
duke@435 | 555 | } |
duke@435 | 556 | deallocate_monitor_chunks(); |
duke@435 | 557 | } |
duke@435 | 558 | |
duke@435 | 559 | void vframeArray::deallocate_monitor_chunks() { |
duke@435 | 560 | JavaThread* jt = JavaThread::current(); |
duke@435 | 561 | for (int index = 0; index < frames(); index++ ) { |
duke@435 | 562 | element(index)->free_monitors(jt); |
duke@435 | 563 | } |
duke@435 | 564 | } |
duke@435 | 565 | |
duke@435 | 566 | #ifndef PRODUCT |
duke@435 | 567 | |
duke@435 | 568 | bool vframeArray::structural_compare(JavaThread* thread, GrowableArray<compiledVFrame*>* chunk) { |
duke@435 | 569 | if (owner_thread() != thread) return false; |
duke@435 | 570 | int index = 0; |
duke@435 | 571 | #if 0 // FIXME can't do this comparison |
duke@435 | 572 | |
duke@435 | 573 | // Compare only within vframe array. |
duke@435 | 574 | for (deoptimizedVFrame* vf = deoptimizedVFrame::cast(vframe_at(first_index())); vf; vf = vf->deoptimized_sender_or_null()) { |
duke@435 | 575 | if (index >= chunk->length() || !vf->structural_compare(chunk->at(index))) return false; |
duke@435 | 576 | index++; |
duke@435 | 577 | } |
duke@435 | 578 | if (index != chunk->length()) return false; |
duke@435 | 579 | #endif |
duke@435 | 580 | |
duke@435 | 581 | return true; |
duke@435 | 582 | } |
duke@435 | 583 | |
duke@435 | 584 | #endif |
duke@435 | 585 | |
duke@435 | 586 | address vframeArray::register_location(int i) const { |
duke@435 | 587 | assert(0 <= i && i < RegisterMap::reg_count, "index out of bounds"); |
duke@435 | 588 | return (address) & _callee_registers[i]; |
duke@435 | 589 | } |
duke@435 | 590 | |
duke@435 | 591 | |
duke@435 | 592 | #ifndef PRODUCT |
duke@435 | 593 | |
duke@435 | 594 | // Printing |
duke@435 | 595 | |
duke@435 | 596 | // Note: we cannot have print_on as const, as we allocate inside the method |
duke@435 | 597 | void vframeArray::print_on_2(outputStream* st) { |
duke@435 | 598 | st->print_cr(" - sp: " INTPTR_FORMAT, sp()); |
duke@435 | 599 | st->print(" - thread: "); |
duke@435 | 600 | Thread::current()->print(); |
duke@435 | 601 | st->print_cr(" - frame size: %d", frame_size()); |
duke@435 | 602 | for (int index = 0; index < frames() ; index++ ) { |
duke@435 | 603 | element(index)->print(st); |
duke@435 | 604 | } |
duke@435 | 605 | } |
duke@435 | 606 | |
duke@435 | 607 | void vframeArrayElement::print(outputStream* st) { |
kvn@1690 | 608 | st->print_cr(" - interpreter_frame -> sp: " INTPTR_FORMAT, iframe()->sp()); |
duke@435 | 609 | } |
duke@435 | 610 | |
duke@435 | 611 | void vframeArray::print_value_on(outputStream* st) const { |
duke@435 | 612 | st->print_cr("vframeArray [%d] ", frames()); |
duke@435 | 613 | } |
duke@435 | 614 | |
duke@435 | 615 | |
duke@435 | 616 | #endif |