1 /*
  2  * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "classfile/vmSymbols.hpp"
 27 #include "code/vmreg.inline.hpp"
 28 #include "interpreter/bytecode.hpp"
 29 #include "interpreter/interpreter.hpp"
 30 #include "memory/allocation.inline.hpp"
 31 #include "memory/resourceArea.hpp"
 32 #include "oops/methodData.hpp"
 33 #include "oops/oop.inline.hpp"
 34 #include "prims/jvmtiThreadState.hpp"
 35 #include "prims/methodHandles.hpp"
 36 #include "runtime/frame.inline.hpp"
 37 #include "runtime/handles.inline.hpp"
 38 #include "runtime/monitorChunk.hpp"
 39 #include "runtime/sharedRuntime.hpp"
 40 #include "runtime/vframe.hpp"
 41 #include "runtime/vframeArray.hpp"
 42 #include "runtime/vframe_hp.hpp"
 43 #include "utilities/copy.hpp"
 44 #include "utilities/events.hpp"
 45 #ifdef COMPILER2
 46 #include "opto/runtime.hpp"
 47 #endif
 48 
 49 int vframeArrayElement:: bci(void) const { return (_bci == SynchronizationEntryBCI ? 0 : _bci); }
 50 
 51 void vframeArrayElement::free_monitors(JavaThread* jt) {
 52   if (_monitors != NULL) {
 53      MonitorChunk* chunk = _monitors;
 54      _monitors = NULL;
 55      jt->remove_monitor_chunk(chunk);
 56      delete chunk;
 57   }
 58 }
 59 
 60 void vframeArrayElement::fill_in(compiledVFrame* vf, bool realloc_failures) {
 61 
 62 // Copy the information from the compiled vframe to the
 63 // interpreter frame we will be creating to replace vf
 64 
 65   _method = vf->method();
 66   _bci    = vf->raw_bci();
 67   _reexecute = vf->should_reexecute();
 68 #ifdef ASSERT
 69   _removed_monitors = false;
 70 #endif
 71 
 72   int index;
 73 
 74   {
 75     Thread* current_thread = Thread::current();
 76     ResourceMark rm(current_thread);
 77     HandleMark hm(current_thread);
 78 
 79     // Get the monitors off-stack
 80 
 81     GrowableArray<MonitorInfo*>* list = vf->monitors();
 82     if (list->is_empty()) {
 83       _monitors = NULL;
 84     } else {
 85 
 86       // Allocate monitor chunk
 87       _monitors = new MonitorChunk(list->length());
 88       vf->thread()->add_monitor_chunk(_monitors);
 89 
 90       // Migrate the BasicLocks from the stack to the monitor chunk
 91       for (index = 0; index < list->length(); index++) {
 92         MonitorInfo* monitor = list->at(index);
 93         assert(!monitor->owner_is_scalar_replaced() || realloc_failures, "object should be reallocated already");
 94         BasicObjectLock* dest = _monitors->at(index);
 95         if (monitor->owner_is_scalar_replaced()) {
 96           dest->set_obj(NULL);
 97         } else {
 98           assert(monitor->owner() == NULL || !monitor->owner()->is_unlocked(), "object must be null or locked");
 99           dest->set_obj(monitor->owner());
100           monitor->lock()->move_to(monitor->owner(), dest->lock());
101         }
102       }
103     }
104   }
105 
106   // Convert the vframe locals and expressions to off stack
107   // values. Because we will not gc all oops can be converted to
108   // intptr_t (i.e. a stack slot) and we are fine. This is
109   // good since we are inside a HandleMark and the oops in our
110   // collection would go away between packing them here and
111   // unpacking them in unpack_on_stack.
112 
113   // First the locals go off-stack
114 
115   // FIXME this seems silly it creates a StackValueCollection
116   // in order to get the size to then copy them and
117   // convert the types to intptr_t size slots. Seems like it
118   // could do it in place... Still uses less memory than the
119   // old way though
120 
121   StackValueCollection *locs = vf->locals();
122   _locals = new StackValueCollection(locs->size());
123   for(index = 0; index < locs->size(); index++) {
124     StackValue* value = locs->at(index);
125     switch(value->type()) {
126       case T_OBJECT:
127         assert(!value->obj_is_scalar_replaced() || realloc_failures, "object should be reallocated already");
128         // preserve object type
129         _locals->add( new StackValue(cast_from_oop<intptr_t>((value->get_obj()())), T_OBJECT ));
130         break;
131       case T_CONFLICT:
132         // A dead local.  Will be initialized to null/zero.
133         _locals->add( new StackValue());
134         break;
135       case T_INT:
136         _locals->add( new StackValue(value->get_int()));
137         break;
138       default:
139         ShouldNotReachHere();
140     }
141   }
142 
143   // Now the expressions off-stack
144   // Same silliness as above
145 
146   StackValueCollection *exprs = vf->expressions();
147   _expressions = new StackValueCollection(exprs->size());
148   for(index = 0; index < exprs->size(); index++) {
149     StackValue* value = exprs->at(index);
150     switch(value->type()) {
151       case T_OBJECT:
152         assert(!value->obj_is_scalar_replaced() || realloc_failures, "object should be reallocated already");
153         // preserve object type
154         _expressions->add( new StackValue(cast_from_oop<intptr_t>((value->get_obj()())), T_OBJECT ));
155         break;
156       case T_CONFLICT:
157         // A dead stack element.  Will be initialized to null/zero.
158         // This can occur when the compiler emits a state in which stack
159         // elements are known to be dead (because of an imminent exception).
160         _expressions->add( new StackValue());
161         break;
162       case T_INT:
163         _expressions->add( new StackValue(value->get_int()));
164         break;
165       default:
166         ShouldNotReachHere();
167     }
168   }
169 }
170 
171 int unpack_counter = 0;
172 
173 void vframeArrayElement::unpack_on_stack(int caller_actual_parameters,
174                                          int callee_parameters,
175                                          int callee_locals,
176                                          frame* caller,
177                                          bool is_top_frame,
178                                          bool is_bottom_frame,
179                                          int exec_mode) {
180   JavaThread* thread = JavaThread::current();
181 
182   bool realloc_failure_exception = thread->frames_to_pop_failed_realloc() > 0;
183 
184   // Look at bci and decide on bcp and continuation pc
185   address bcp;
186   // C++ interpreter doesn't need a pc since it will figure out what to do when it
187   // begins execution
188   address pc;
189   bool use_next_mdp = false; // true if we should use the mdp associated with the next bci
190                              // rather than the one associated with bcp
191   if (raw_bci() == SynchronizationEntryBCI) {
192     // We are deoptimizing while hanging in prologue code for synchronized method
193     bcp = method()->bcp_from(0); // first byte code
194     pc  = Interpreter::deopt_entry(vtos, 0); // step = 0 since we don't skip current bytecode
195   } else if (should_reexecute()) { //reexecute this bytecode
196     assert(is_top_frame, "reexecute allowed only for the top frame");
197     bcp = method()->bcp_from(bci());
198     pc  = Interpreter::deopt_reexecute_entry(method(), bcp);
199   } else {
200     bcp = method()->bcp_from(bci());
201     pc  = Interpreter::deopt_continue_after_entry(method(), bcp, callee_parameters, is_top_frame);
202     use_next_mdp = true;
203   }
204   assert(Bytecodes::is_defined(*bcp), "must be a valid bytecode");
205 
206   // Monitorenter and pending exceptions:
207   //
208   // For Compiler2, there should be no pending exception when deoptimizing at monitorenter
209   // because there is no safepoint at the null pointer check (it is either handled explicitly
210   // or prior to the monitorenter) and asynchronous exceptions are not made "pending" by the
211   // runtime interface for the slow case (see JRT_ENTRY_FOR_MONITORENTER).  If an asynchronous
212   // exception was processed, the bytecode pointer would have to be extended one bytecode beyond
213   // the monitorenter to place it in the proper exception range.
214   //
215   // For Compiler1, deoptimization can occur while throwing a NullPointerException at monitorenter,
216   // in which case bcp should point to the monitorenter since it is within the exception's range.
217   //
218   // For realloc failure exception we just pop frames, skip the guarantee.
219 
220   assert(*bcp != Bytecodes::_monitorenter || is_top_frame, "a _monitorenter must be a top frame");
221   assert(thread->deopt_compiled_method() != NULL, "compiled method should be known");
222   guarantee(realloc_failure_exception || !(thread->deopt_compiled_method()->is_compiled_by_c2() &&
223               *bcp == Bytecodes::_monitorenter             &&
224               exec_mode == Deoptimization::Unpack_exception),
225             "shouldn't get exception during monitorenter");
226 
227   int popframe_preserved_args_size_in_bytes = 0;
228   int popframe_preserved_args_size_in_words = 0;
229   if (is_top_frame) {
230     JvmtiThreadState *state = thread->jvmti_thread_state();
231     if (JvmtiExport::can_pop_frame() &&
232         (thread->has_pending_popframe() || thread->popframe_forcing_deopt_reexecution())) {
233       if (thread->has_pending_popframe()) {
234         // Pop top frame after deoptimization
235         pc = Interpreter::remove_activation_preserving_args_entry();
236       } else {
237         // Reexecute invoke in top frame
238         pc = Interpreter::deopt_entry(vtos, 0);
239         use_next_mdp = false;
240         popframe_preserved_args_size_in_bytes = in_bytes(thread->popframe_preserved_args_size());
241         // Note: the PopFrame-related extension of the expression stack size is done in
242         // Deoptimization::fetch_unroll_info_helper
243         popframe_preserved_args_size_in_words = in_words(thread->popframe_preserved_args_size_in_words());
244       }
245     } else if (!realloc_failure_exception && JvmtiExport::can_force_early_return() && state != NULL &&
246                state->is_earlyret_pending()) {
247       // Force early return from top frame after deoptimization
248       pc = Interpreter::remove_activation_early_entry(state->earlyret_tos());
249     } else {
250       if (realloc_failure_exception && JvmtiExport::can_force_early_return() && state != NULL && state->is_earlyret_pending()) {
251         state->clr_earlyret_pending();
252         state->set_earlyret_oop(NULL);
253         state->clr_earlyret_value();
254       }
255       // Possibly override the previous pc computation of the top (youngest) frame
256       switch (exec_mode) {
257       case Deoptimization::Unpack_deopt:
258         // use what we've got
259         break;
260       case Deoptimization::Unpack_exception:
261         // exception is pending
262         pc = SharedRuntime::raw_exception_handler_for_return_address(thread, pc);
263         // [phh] We're going to end up in some handler or other, so it doesn't
264         // matter what mdp we point to.  See exception_handler_for_exception()
265         // in interpreterRuntime.cpp.
266         break;
267       case Deoptimization::Unpack_uncommon_trap:
268       case Deoptimization::Unpack_reexecute:
269         // redo last byte code
270         pc  = Interpreter::deopt_entry(vtos, 0);
271         use_next_mdp = false;
272         break;
273       default:
274         ShouldNotReachHere();
275       }
276     }
277   }
278 
279   // Setup the interpreter frame
280 
281   assert(method() != NULL, "method must exist");
282   int temps = expressions()->size();
283 
284   int locks = monitors() == NULL ? 0 : monitors()->number_of_monitors();
285 
286   Interpreter::layout_activation(method(),
287                                  temps + callee_parameters,
288                                  popframe_preserved_args_size_in_words,
289                                  locks,
290                                  caller_actual_parameters,
291                                  callee_parameters,
292                                  callee_locals,
293                                  caller,
294                                  iframe(),
295                                  is_top_frame,
296                                  is_bottom_frame);
297 
298   // Update the pc in the frame object and overwrite the temporary pc
299   // we placed in the skeletal frame now that we finally know the
300   // exact interpreter address we should use.
301 
302   _frame.patch_pc(thread, pc);
303 
304   assert (!method()->is_synchronized() || locks > 0 || _removed_monitors || raw_bci() == SynchronizationEntryBCI, "synchronized methods must have monitors");
305 
306   BasicObjectLock* top = iframe()->interpreter_frame_monitor_begin();
307   for (int index = 0; index < locks; index++) {
308     top = iframe()->previous_monitor_in_interpreter_frame(top);
309     BasicObjectLock* src = _monitors->at(index);
310     top->set_obj(src->obj());
311     src->lock()->move_to(src->obj(), top->lock());
312   }
313   if (ProfileInterpreter) {
314     iframe()->interpreter_frame_set_mdp(0); // clear out the mdp.
315   }
316   iframe()->interpreter_frame_set_bcp(bcp);
317   if (ProfileInterpreter) {
318     MethodData* mdo = method()->method_data();
319     if (mdo != NULL) {
320       int bci = iframe()->interpreter_frame_bci();
321       if (use_next_mdp) ++bci;
322       address mdp = mdo->bci_to_dp(bci);
323       iframe()->interpreter_frame_set_mdp(mdp);
324     }
325   }
326 
327   if (PrintDeoptimizationDetails) {
328     tty->print_cr("Expressions size: %d", expressions()->size());
329   }
330 
331   // Unpack expression stack
332   // If this is an intermediate frame (i.e. not top frame) then this
333   // only unpacks the part of the expression stack not used by callee
334   // as parameters. The callee parameters are unpacked as part of the
335   // callee locals.
336   int i;
337   for(i = 0; i < expressions()->size(); i++) {
338     StackValue *value = expressions()->at(i);
339     intptr_t*   addr  = iframe()->interpreter_frame_expression_stack_at(i);
340     switch(value->type()) {
341       case T_INT:
342         *addr = value->get_int();
343 #ifndef PRODUCT
344         if (PrintDeoptimizationDetails) {
345           tty->print_cr("Reconstructed expression %d (INT): %d", i, (int)(*addr));
346         }
347 #endif
348         break;
349       case T_OBJECT:
350         *addr = value->get_int(T_OBJECT);
351 #ifndef PRODUCT
352         if (PrintDeoptimizationDetails) {
353           tty->print("Reconstructed expression %d (OBJECT): ", i);
354           oop o = cast_to_oop((address)(*addr));
355           if (o == NULL) {
356             tty->print_cr("NULL");
357           } else {
358             ResourceMark rm;
359             tty->print_raw_cr(o->klass()->name()->as_C_string());
360           }
361         }
362 #endif
363         break;
364       case T_CONFLICT:
365         // A dead stack slot.  Initialize to null in case it is an oop.
366         *addr = NULL_WORD;
367         break;
368       default:
369         ShouldNotReachHere();
370     }
371   }
372 
373 
374   // Unpack the locals
375   for(i = 0; i < locals()->size(); i++) {
376     StackValue *value = locals()->at(i);
377     intptr_t* addr  = iframe()->interpreter_frame_local_at(i);
378     switch(value->type()) {
379       case T_INT:
380         *addr = value->get_int();
381 #ifndef PRODUCT
382         if (PrintDeoptimizationDetails) {
383           tty->print_cr("Reconstructed local %d (INT): %d", i, (int)(*addr));
384         }
385 #endif
386         break;
387       case T_OBJECT:
388         *addr = value->get_int(T_OBJECT);
389 #ifndef PRODUCT
390         if (PrintDeoptimizationDetails) {
391           tty->print("Reconstructed local %d (OBJECT): ", i);
392           oop o = cast_to_oop((address)(*addr));
393           if (o == NULL) {
394             tty->print_cr("NULL");
395           } else {
396             ResourceMark rm;
397             tty->print_raw_cr(o->klass()->name()->as_C_string());
398           }
399         }
400 #endif
401         break;
402       case T_CONFLICT:
403         // A dead location. If it is an oop then we need a NULL to prevent GC from following it
404         *addr = NULL_WORD;
405         break;
406       default:
407         ShouldNotReachHere();
408     }
409   }
410 
411   if (is_top_frame && JvmtiExport::can_pop_frame() && thread->popframe_forcing_deopt_reexecution()) {
412     // An interpreted frame was popped but it returns to a deoptimized
413     // frame. The incoming arguments to the interpreted activation
414     // were preserved in thread-local storage by the
415     // remove_activation_preserving_args_entry in the interpreter; now
416     // we put them back into the just-unpacked interpreter frame.
417     // Note that this assumes that the locals arena grows toward lower
418     // addresses.
419     if (popframe_preserved_args_size_in_words != 0) {
420       void* saved_args = thread->popframe_preserved_args();
421       assert(saved_args != NULL, "must have been saved by interpreter");
422 #ifdef ASSERT
423       assert(popframe_preserved_args_size_in_words <=
424              iframe()->interpreter_frame_expression_stack_size()*Interpreter::stackElementWords,
425              "expression stack size should have been extended");
426 #endif // ASSERT
427       int top_element = iframe()->interpreter_frame_expression_stack_size()-1;
428       intptr_t* base;
429       if (frame::interpreter_frame_expression_stack_direction() < 0) {
430         base = iframe()->interpreter_frame_expression_stack_at(top_element);
431       } else {
432         base = iframe()->interpreter_frame_expression_stack();
433       }
434       Copy::conjoint_jbytes(saved_args,
435                             base,
436                             popframe_preserved_args_size_in_bytes);
437       thread->popframe_free_preserved_args();
438     }
439   }
440 
441 #ifndef PRODUCT
442   if (PrintDeoptimizationDetails) {
443     ttyLocker ttyl;
444     tty->print_cr("[%d Interpreted Frame]", ++unpack_counter);
445     iframe()->print_on(tty);
446     RegisterMap map(thread);
447     vframe* f = vframe::new_vframe(iframe(), &map, thread);
448     f->print();
449 
450     tty->print_cr("locals size     %d", locals()->size());
451     tty->print_cr("expression size %d", expressions()->size());
452 
453     method()->print_value();
454     tty->cr();
455     // method()->print_codes();
456   } else if (TraceDeoptimization) {
457     tty->print("     ");
458     method()->print_value();
459     Bytecodes::Code code = Bytecodes::java_code_at(method(), bcp);
460     int bci = method()->bci_from(bcp);
461     tty->print(" - %s", Bytecodes::name(code));
462     tty->print(" @ bci %d ", bci);
463     tty->print_cr("sp = " PTR_FORMAT, p2i(iframe()->sp()));
464   }
465 #endif // PRODUCT
466 
467   // The expression stack and locals are in the resource area don't leave
468   // a dangling pointer in the vframeArray we leave around for debug
469   // purposes
470 
471   _locals = _expressions = NULL;
472 
473 }
474 
475 int vframeArrayElement::on_stack_size(int callee_parameters,
476                                       int callee_locals,
477                                       bool is_top_frame,
478                                       int popframe_extra_stack_expression_els) const {
479   assert(method()->max_locals() == locals()->size(), "just checking");
480   int locks = monitors() == NULL ? 0 : monitors()->number_of_monitors();
481   int temps = expressions()->size();
482   return Interpreter::size_activation(method()->max_stack(),
483                                       temps + callee_parameters,
484                                       popframe_extra_stack_expression_els,
485                                       locks,
486                                       callee_parameters,
487                                       callee_locals,
488                                       is_top_frame);
489 }
490 
491 
492 intptr_t* vframeArray::unextended_sp() const {

493   return _original.unextended_sp();
494 }
495 
496 vframeArray* vframeArray::allocate(JavaThread* thread, int frame_size, GrowableArray<compiledVFrame*>* chunk,
497                                    RegisterMap *reg_map, frame sender, frame caller, frame self,
498                                    bool realloc_failures) {
499 
500   // Allocate the vframeArray
501   vframeArray * result = (vframeArray*) AllocateHeap(sizeof(vframeArray) + // fixed part
502                                                      sizeof(vframeArrayElement) * (chunk->length() - 1), // variable part
503                                                      mtCompiler);
504   result->_frames = chunk->length();
505   result->_owner_thread = thread;
506   result->_sender = sender;
507   result->_caller = caller;
508   result->_original = self;
509   result->set_unroll_block(NULL); // initialize it
510   result->fill_in(thread, frame_size, chunk, reg_map, realloc_failures);
511   return result;
512 }
513 
514 void vframeArray::fill_in(JavaThread* thread,
515                           int frame_size,
516                           GrowableArray<compiledVFrame*>* chunk,
517                           const RegisterMap *reg_map,
518                           bool realloc_failures) {
519   // Set owner first, it is used when adding monitor chunks
520 
521   _frame_size = frame_size;
522   for(int i = 0; i < chunk->length(); i++) {
523     element(i)->fill_in(chunk->at(i), realloc_failures);
524   }
525 
526   // Copy registers for callee-saved registers
527   if (reg_map != NULL) {
528     for(int i = 0; i < RegisterMap::reg_count; i++) {
529 #ifdef AMD64
530       // The register map has one entry for every int (32-bit value), so
531       // 64-bit physical registers have two entries in the map, one for
532       // each half.  Ignore the high halves of 64-bit registers, just like
533       // frame::oopmapreg_to_location does.
534       //
535       // [phh] FIXME: this is a temporary hack!  This code *should* work
536       // correctly w/o this hack, possibly by changing RegisterMap::pd_location
537       // in frame_amd64.cpp and the values of the phantom high half registers
538       // in amd64.ad.
539       //      if (VMReg::Name(i) < SharedInfo::stack0 && is_even(i)) {
540         intptr_t* src = (intptr_t*) reg_map->location(VMRegImpl::as_VMReg(i));
541         _callee_registers[i] = src != NULL ? *src : NULL_WORD;
542         //      } else {
543         //      jint* src = (jint*) reg_map->location(VMReg::Name(i));
544         //      _callee_registers[i] = src != NULL ? *src : NULL_WORD;
545         //      }
546 #else
547       jint* src = (jint*) reg_map->location(VMRegImpl::as_VMReg(i));
548       _callee_registers[i] = src != NULL ? *src : NULL_WORD;
549 #endif
550       if (src == NULL) {
551         set_location_valid(i, false);
552       } else {
553         set_location_valid(i, true);
554         jint* dst = (jint*) register_location(i);
555         *dst = *src;
556       }
557     }
558   }
559 }
560 
561 void vframeArray::unpack_to_stack(frame &unpack_frame, int exec_mode, int caller_actual_parameters) {
562   // stack picture
563   //   unpack_frame
564   //   [new interpreter frames ] (frames are skeletal but walkable)
565   //   caller_frame
566   //
567   //  This routine fills in the missing data for the skeletal interpreter frames
568   //  in the above picture.
569 
570   // Find the skeletal interpreter frames to unpack into
571   JavaThread* current = JavaThread::current();
572   RegisterMap map(current, false);
573   // Get the youngest frame we will unpack (last to be unpacked)
574   frame me = unpack_frame.sender(&map);
575   int index;
576   for (index = 0; index < frames(); index++ ) {
577     *element(index)->iframe() = me;
578     // Get the caller frame (possibly skeletal)
579     me = me.sender(&map);
580   }
581 
582   // Do the unpacking of interpreter frames; the frame at index 0 represents the top activation, so it has no callee
583   // Unpack the frames from the oldest (frames() -1) to the youngest (0)
584   frame* caller_frame = &me;
585   for (index = frames() - 1; index >= 0 ; index--) {
586     vframeArrayElement* elem = element(index);  // caller
587     int callee_parameters, callee_locals;
588     if (index == 0) {
589       callee_parameters = callee_locals = 0;
590     } else {
591       methodHandle caller(current, elem->method());
592       methodHandle callee(current, element(index - 1)->method());
593       Bytecode_invoke inv(caller, elem->bci());
594       // invokedynamic instructions don't have a class but obviously don't have a MemberName appendix.
595       // NOTE:  Use machinery here that avoids resolving of any kind.
596       const bool has_member_arg =
597           !inv.is_invokedynamic() && MethodHandles::has_member_arg(inv.klass(), inv.name());
598       callee_parameters = callee->size_of_parameters() + (has_member_arg ? 1 : 0);
599       callee_locals     = callee->max_locals();
600     }
601     elem->unpack_on_stack(caller_actual_parameters,
602                           callee_parameters,
603                           callee_locals,
604                           caller_frame,
605                           index == 0,
606                           index == frames() - 1,
607                           exec_mode);
608     if (index == frames() - 1) {
609       Deoptimization::unwind_callee_save_values(elem->iframe(), this);
610     }
611     caller_frame = elem->iframe();
612     caller_actual_parameters = callee_parameters;
613   }
614   deallocate_monitor_chunks();
615 }
616 
617 void vframeArray::deallocate_monitor_chunks() {
618   JavaThread* jt = JavaThread::current();
619   for (int index = 0; index < frames(); index++ ) {
620      element(index)->free_monitors(jt);
621   }
622 }
623 
624 #ifndef PRODUCT
625 
626 bool vframeArray::structural_compare(JavaThread* thread, GrowableArray<compiledVFrame*>* chunk) {
627   if (owner_thread() != thread) return false;
628   int index = 0;
629 #if 0 // FIXME can't do this comparison
630 
631   // Compare only within vframe array.
632   for (deoptimizedVFrame* vf = deoptimizedVFrame::cast(vframe_at(first_index())); vf; vf = vf->deoptimized_sender_or_null()) {
633     if (index >= chunk->length() || !vf->structural_compare(chunk->at(index))) return false;
634     index++;
635   }
636   if (index != chunk->length()) return false;
637 #endif
638 
639   return true;
640 }
641 
642 #endif
643 
644 address vframeArray::register_location(int i) const {
645   assert(0 <= i && i < RegisterMap::reg_count, "index out of bounds");
646   return (address) & _callee_registers[i];
647 }
648 
649 
650 #ifndef PRODUCT
651 
652 // Printing
653 
654 // Note: we cannot have print_on as const, as we allocate inside the method
655 void vframeArray::print_on_2(outputStream* st)  {
656   st->print_cr(" - sp: " INTPTR_FORMAT, p2i(sp()));
657   st->print(" - thread: ");
658   Thread::current()->print();
659   st->print_cr(" - frame size: %d", frame_size());
660   for (int index = 0; index < frames() ; index++ ) {
661     element(index)->print(st);
662   }
663 }
664 
665 void vframeArrayElement::print(outputStream* st) {
666   st->print_cr(" - interpreter_frame -> sp: " INTPTR_FORMAT, p2i(iframe()->sp()));
667 }
668 
669 void vframeArray::print_value_on(outputStream* st) const {
670   st->print_cr("vframeArray [%d] ", frames());
671 }
672 
673 
674 #endif
--- EOF ---