src/share/vm/runtime/vframeArray.cpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 7419
d3f3f7677537
parent 6876
710a3c8b516e
permissions
-rw-r--r--

merge

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

mercurial