hotspot/src/cpu/x86/vm/frame_x86.cpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 354 3b42d6fdcb82
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2007 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_frame_x86.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
void RegisterMap::check_location_valid() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// Profiling/safepoint support
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
bool frame::safe_for_sender(JavaThread *thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  address   sp = (address)_sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  address   fp = (address)_fp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  address   unextended_sp = (address)_unextended_sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  bool sp_safe = (sp != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
                 (sp <= thread->stack_base()) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
                 (sp >= thread->stack_base() - thread->stack_size()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  bool unextended_sp_safe = (unextended_sp != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
                 (unextended_sp <= thread->stack_base()) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
                 (unextended_sp >= thread->stack_base() - thread->stack_size()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  bool fp_safe = (fp != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
                 (fp <= thread->stack_base()) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
                 (fp >= thread->stack_base() - thread->stack_size()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  if (sp_safe && unextended_sp_safe && fp_safe) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    // Unfortunately we can only check frame complete for runtime stubs and nmethod
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    // other generic buffer blobs are more problematic so we just assume they are
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    // ok. adapter blobs never have a frame complete and are never ok.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    if (_cb != NULL && !_cb->is_frame_complete_at(_pc)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
      if (_cb->is_nmethod() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
        return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  // Note: fp == NULL is not really a prerequisite for this to be safe to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  // walk for c2. However we've modified the code such that if we get
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  // a failure with fp != NULL that we then try with FP == NULL.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // This is basically to mimic what a last_frame would look like if
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // c2 had generated it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  if (sp_safe && unextended_sp_safe && fp == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    // frame must be complete if fp == NULL as fp == NULL is only sensible
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    // if we are looking at a nmethod and frame complete assures us of that.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    if (_cb != NULL && _cb->is_frame_complete_at(_pc) && _cb->is_compiled_by_c2()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
        return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
void frame::patch_pc(Thread* thread, address pc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  if (TracePcPatching) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    tty->print_cr("patch_pc at address  0x%x [0x%x -> 0x%x] ", &((address *)sp())[-1], ((address *)sp())[-1], pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  ((address *)sp())[-1] = pc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  _cb = CodeCache::find_blob(pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  if (_cb != NULL && _cb->is_nmethod() && ((nmethod*)_cb)->is_deopt_pc(_pc)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    address orig = (((nmethod*)_cb)->get_original_pc(this));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    assert(orig == _pc, "expected original to be stored before patching");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    _deopt_state = is_deoptimized;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    // leave _pc as is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    _deopt_state = not_deoptimized;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    _pc = pc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
bool frame::is_interpreted_frame() const  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  return Interpreter::contains(pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
int frame::frame_size() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  RegisterMap map(JavaThread::current(), false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  frame sender = this->sender(&map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  return sender.sp() - sp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
intptr_t* frame::entry_frame_argument_at(int offset) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // convert offset to index to deal with tsi
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  // Entry frame's arguments are always in relation to unextended_sp()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  return &unextended_sp()[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
// sender_sp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
#ifdef CC_INTERP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
intptr_t* frame::interpreter_frame_sender_sp() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  assert(is_interpreted_frame(), "interpreted frame expected");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // QQQ why does this specialize method exist if frame::sender_sp() does same thing?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  // seems odd and if we always know interpreted vs. non then sender_sp() is really
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // doing too much work.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  return get_interpreterState()->sender_sp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
// monitor elements
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
BasicObjectLock* frame::interpreter_frame_monitor_begin() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  return get_interpreterState()->monitor_base();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
BasicObjectLock* frame::interpreter_frame_monitor_end() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  return (BasicObjectLock*) get_interpreterState()->stack_base();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
#else // CC_INTERP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
intptr_t* frame::interpreter_frame_sender_sp() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  assert(is_interpreted_frame(), "interpreted frame expected");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  return (intptr_t*) at(interpreter_frame_sender_sp_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
void frame::set_interpreter_frame_sender_sp(intptr_t* sender_sp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  assert(is_interpreted_frame(), "interpreted frame expected");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  ptr_at_put(interpreter_frame_sender_sp_offset, (intptr_t) sender_sp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
// monitor elements
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
BasicObjectLock* frame::interpreter_frame_monitor_begin() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  return (BasicObjectLock*) addr_at(interpreter_frame_monitor_block_bottom_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
BasicObjectLock* frame::interpreter_frame_monitor_end() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  BasicObjectLock* result = (BasicObjectLock*) *addr_at(interpreter_frame_monitor_block_top_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  // make sure the pointer points inside the frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  assert((intptr_t) fp() >  (intptr_t) result, "result must <  than frame pointer");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  assert((intptr_t) sp() <= (intptr_t) result, "result must >= than stack pointer");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
void frame::interpreter_frame_set_monitor_end(BasicObjectLock* value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  *((BasicObjectLock**)addr_at(interpreter_frame_monitor_block_top_offset)) = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
// Used by template based interpreter deoptimization
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
void frame::interpreter_frame_set_last_sp(intptr_t* sp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    *((intptr_t**)addr_at(interpreter_frame_last_sp_offset)) = sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
#endif // CC_INTERP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
frame frame::sender_for_entry_frame(RegisterMap* map) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  assert(map != NULL, "map must be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  // Java frame called from C; skip all C frames and return top C
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  // frame of that chunk as the sender
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  assert(!entry_frame_is_first(), "next Java fp must be non zero");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  map->clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  assert(map->include_argument_oops(), "should be set by clear");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  if (jfa->last_Java_pc() != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    frame fr(jfa->last_Java_sp(), jfa->last_Java_fp(), jfa->last_Java_pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    return fr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  frame fr(jfa->last_Java_sp(), jfa->last_Java_fp());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  return fr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
frame frame::sender_for_interpreter_frame(RegisterMap* map) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  // sp is the raw sp from the sender after adapter or interpreter extension
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  intptr_t* sp = (intptr_t*) addr_at(sender_sp_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  // This is the sp before any possible extension (adapter/locals).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  intptr_t* unextended_sp = interpreter_frame_sender_sp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  // The interpreter and compiler(s) always save EBP/RBP in a known
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  // location on entry. We must record where that location is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  // so this if EBP/RBP was live on callout from c2 we can find
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  // the saved copy no matter what it called.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  // Since the interpreter always saves EBP/RBP if we record where it is then
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  // we don't have to always save EBP/RBP on entry and exit to c2 compiled
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  // code, on entry will be enough.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
#ifdef COMPILER2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  if (map->update_map()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    map->set_location(rbp->as_VMReg(), (address) addr_at(link_offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    // this is weird "H" ought to be at a higher address however the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    // oopMaps seems to have the "H" regs at the same address and the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    // vanilla register.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    // XXXX make this go away
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    if (true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
      map->set_location(rbp->as_VMReg()->next(), (address)addr_at(link_offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
#endif /* COMPILER2 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  return frame(sp, unextended_sp, link(), sender_pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
//------------------------------sender_for_compiled_frame-----------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
frame frame::sender_for_compiled_frame(RegisterMap* map) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  assert(map != NULL, "map must be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  const bool c1_compiled = _cb->is_compiled_by_c1();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  // frame owned by optimizing compiler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  intptr_t* sender_sp = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  assert(_cb->frame_size() >= 0, "must have non-zero frame size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  sender_sp = unextended_sp() + _cb->frame_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  // On Intel the return_address is always the word on the stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  address sender_pc = (address) *(sender_sp-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  // This is the saved value of ebp which may or may not really be an fp.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  // it is only an fp if the sender is an interpreter frame (or c1?)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  intptr_t *saved_fp = (intptr_t*)*(sender_sp - frame::sender_sp_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  if (map->update_map()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    // Tell GC to use argument oopmaps for some runtime stubs that need it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    // For C1, the runtime stub might not have oop maps, so set this flag
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    // outside of update_register_map.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    if (_cb->oop_maps() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
      OopMapSet::update_register_map(this, map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    // Since the prolog does the save and restore of epb there is no oopmap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    // for it so we must fill in its location as if there was an oopmap entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    // since if our caller was compiled code there could be live jvm state in it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    map->set_location(rbp->as_VMReg(), (address) (sender_sp - frame::sender_sp_offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    // this is weird "H" ought to be at a higher address however the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    // oopMaps seems to have the "H" regs at the same address and the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    // vanilla register.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    // XXXX make this go away
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    if (true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
      map->set_location(rbp->as_VMReg()->next(), (address) (sender_sp - frame::sender_sp_offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  assert(sender_sp != sp(), "must have changed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  return frame(sender_sp, saved_fp, sender_pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
frame frame::sender(RegisterMap* map) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  // Default is we done have to follow them. The sender_for_xxx will
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  // update it accordingly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  map->set_include_argument_oops(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  if (is_entry_frame())       return sender_for_entry_frame(map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  if (is_interpreted_frame()) return sender_for_interpreter_frame(map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  assert(_cb == CodeCache::find_blob(pc()),"Must be the same");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  if (_cb != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    return sender_for_compiled_frame(map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  // Must be native-compiled frame, i.e. the marshaling code for native
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  // methods that exists in the core system.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  return frame(sender_sp(), link(), sender_pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
bool frame::interpreter_frame_equals_unpacked_fp(intptr_t* fp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  assert(is_interpreted_frame(), "must be interpreter frame");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  methodOop method = interpreter_frame_method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  // When unpacking an optimized frame the frame pointer is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  // adjusted with:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  int diff = (method->max_locals() - method->size_of_parameters()) *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
             Interpreter::stackElementWords();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  return _fp == (fp - diff);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
void frame::pd_gc_epilog() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  // nothing done here now
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
bool frame::is_interpreted_frame_valid() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
// QQQ
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
#ifdef CC_INTERP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  assert(is_interpreted_frame(), "Not an interpreted frame");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  // These are reasonable sanity checks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  if (fp() + interpreter_frame_initial_sp_offset < sp()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  // These are hacks to keep us out of trouble.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  // The problem with these is that they mask other problems
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  if (fp() <= sp()) {        // this attempts to deal with unsigned comparison above
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  if (fp() - sp() > 4096) {  // stack frames shouldn't be large.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
#endif // CC_INTERP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
#ifdef CC_INTERP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  // Needed for JVMTI. The result should always be in the interpreterState object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  assert(false, "NYI");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  interpreterState istate = get_interpreterState();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
#endif // CC_INTERP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  assert(is_interpreted_frame(), "interpreted frame expected");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  methodOop method = interpreter_frame_method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  BasicType type = method->result_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  intptr_t* tos_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  if (method->is_native()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
    // Prior to calling into the runtime to report the method_exit the possible
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    // return value is pushed to the native stack. If the result is a jfloat/jdouble
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    // then ST0 is saved before EAX/EDX. See the note in generate_native_result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
    tos_addr = (intptr_t*)sp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
    if (type == T_FLOAT || type == T_DOUBLE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    // QQQ seems like this code is equivalent on the two platforms
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
      // This is times two because we do a push(ltos) after pushing XMM0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
      // and that takes two interpreter stack slots.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
      tos_addr += 2 * Interpreter::stackElementWords();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
      tos_addr += 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    tos_addr = (intptr_t*)interpreter_frame_tos_address();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  switch (type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    case T_OBJECT  :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
    case T_ARRAY   : {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
      oop obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
      if (method->is_native()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
#ifdef CC_INTERP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
        obj = istate->_oop_temp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
        obj = (oop) at(interpreter_frame_oop_temp_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
#endif // CC_INTERP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
        oop* obj_p = (oop*)tos_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
        obj = (obj_p == NULL) ? (oop)NULL : *obj_p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
      assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
      *oop_result = obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
    case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
    case T_BYTE    : value_result->b = *(jbyte*)tos_addr; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
    case T_CHAR    : value_result->c = *(jchar*)tos_addr; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    case T_SHORT   : value_result->s = *(jshort*)tos_addr; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
    case T_INT     : value_result->i = *(jint*)tos_addr; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    case T_LONG    : value_result->j = *(jlong*)tos_addr; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
    case T_FLOAT   : {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
        value_result->f = *(jfloat*)tos_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
      if (method->is_native()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
        jdouble d = *(jdouble*)tos_addr;  // Result was in ST0 so need to convert to jfloat
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
        value_result->f = (jfloat)d;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
        value_result->f = *(jfloat*)tos_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
    case T_DOUBLE  : value_result->d = *(jdouble*)tos_addr; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
    case T_VOID    : /* Nothing to do */ break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
    default        : ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  return type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
intptr_t* frame::interpreter_frame_tos_at(jint offset) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  return &interpreter_frame_tos_address()[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
}