src/share/vm/runtime/vframeArray.cpp

Fri, 24 Jun 2016 17:12:13 +0800

author
aoqi<aoqi@loongson.cn>
date
Fri, 24 Jun 2016 17:12:13 +0800
changeset 25
873fd82b133d
parent 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

[Code Reorganization] Removed GC related modifications made by Loongson, for example, UseOldNUMA.

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

mercurial