hotspot/src/cpu/x86/vm/cppInterpreter_x86.cpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 1066 717c3345024f
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 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/_cppInterpreter_x86.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
#ifdef CC_INTERP
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// Routine exists to make tracebacks look decent in debugger
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// while we are recursed in the frame manager/c++ interpreter.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// We could use an address in the frame manager but having
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// frames look natural in the debugger is a plus.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
extern "C" void RecursiveInterpreterActivation(interpreterState istate )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
#define __ _masm->
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
#define STATE(field_name) (Address(state, byte_offset_of(BytecodeInterpreter, field_name)))
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
Label fast_accessor_slow_entry_path;  // fast accessor methods need to be able to jmp to unsynchronized
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
                                      // c++ interpreter entry point this holds that entry point label.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// NEEDED for JVMTI?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// address AbstractInterpreter::_remove_activation_preserving_args_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
static address unctrap_frame_manager_entry  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
static address deopt_frame_manager_return_atos  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
static address deopt_frame_manager_return_btos  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
static address deopt_frame_manager_return_itos  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
static address deopt_frame_manager_return_ltos  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
static address deopt_frame_manager_return_ftos  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
static address deopt_frame_manager_return_dtos  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
static address deopt_frame_manager_return_vtos  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
int AbstractInterpreter::BasicType_as_index(BasicType type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  int i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  switch (type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    case T_BOOLEAN: i = 0; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    case T_CHAR   : i = 1; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    case T_BYTE   : i = 2; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    case T_SHORT  : i = 3; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    case T_INT    : i = 4; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    case T_VOID   : i = 5; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    case T_FLOAT  : i = 8; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    case T_LONG   : i = 9; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    case T_DOUBLE : i = 6; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    case T_OBJECT : // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    case T_ARRAY  : i = 7; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    default       : ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, "index out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  return i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
// Is this pc anywhere within code owned by the interpreter?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
// This only works for pc that might possibly be exposed to frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
// walkers. It clearly misses all of the actual c++ interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
// implementation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
bool CppInterpreter::contains(address pc)            {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    return (_code->contains(pc) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
            pc == CAST_FROM_FN_PTR(address, RecursiveInterpreterActivation));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
address CppInterpreterGenerator::generate_result_handler_for(BasicType type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  const Register state   = rsi;                                    // current activation object, valid on entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  address entry = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  switch (type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    case T_BOOLEAN: __ c2bool(rax);            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    case T_CHAR   : __ andl(rax, 0xFFFF);      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    case T_BYTE   : __ sign_extend_byte (rax); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    case T_SHORT  : __ sign_extend_short(rax); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    case T_VOID   : // fall thru
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    case T_LONG   : // fall thru
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    case T_INT    : /* nothing to do */        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    case T_DOUBLE :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    case T_FLOAT  :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
      { const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
        __ popl(t);                            // remove return address first
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
        __ pop_dtos_to_rsp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
        // Must return a result for interpreter or compiler. In SSE
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
        // mode, results are returned in xmm0 and the FPU stack must
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
        // be empty.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
        if (type == T_FLOAT && UseSSE >= 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
          // Load ST0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
          __ fld_d(Address(rsp, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
          // Store as float and empty fpu stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
          __ fstp_s(Address(rsp, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
          // and reload
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
          __ movflt(xmm0, Address(rsp, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
        } else if (type == T_DOUBLE && UseSSE >= 2 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
          __ movdbl(xmm0, Address(rsp, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
          // restore ST0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
          __ fld_d(Address(rsp, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
        // and pop the temp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
        __ addl(rsp, 2 * wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
        __ pushl(t);                           // restore return address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    case T_OBJECT :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      // retrieve result from frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      __ movl(rax, STATE(_oop_temp));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
      // and verify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
      __ verify_oop(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    default       : ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  __ ret(0);                                   // return from result handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
// tosca based result to c++ interpreter stack based result.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
// Result goes to top of native stack.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
#undef EXTEND  // SHOULD NOT BE NEEDED
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
address CppInterpreterGenerator::generate_tosca_to_stack_converter(BasicType type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  // A result is in the tosca (abi result) from either a native method call or compiled
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // code. Place this result on the java expression stack so C++ interpreter can use it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  address entry = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  __ popl(t);                            // remove return address first
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  switch (type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    case T_VOID:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
       break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    case T_BOOLEAN:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
#ifdef EXTEND
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
      __ c2bool(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
      __ pushl(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    case T_CHAR   :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
#ifdef EXTEND
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      __ andl(rax, 0xFFFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
      __ pushl(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    case T_BYTE   :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
#ifdef EXTEND
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
      __ sign_extend_byte (rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
      __ pushl(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    case T_SHORT  :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
#ifdef EXTEND
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
      __ sign_extend_short(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
      __ pushl(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    case T_LONG    :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
      __ pushl(rdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
      __ pushl(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    case T_INT    :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
      __ pushl(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    case T_FLOAT  :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
      // Result is in ST(0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
      if ( UseSSE < 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
        __ push(ftos);                           // and save it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
        __ subl(rsp, wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
        __ movflt(Address(rsp, 0), xmm0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    case T_DOUBLE  :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
      if ( UseSSE < 2 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
        __ push(dtos);                           // put ST0 on java stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
        __ subl(rsp, 2*wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
        __ movdbl(Address(rsp, 0), xmm0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    case T_OBJECT :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
      __ verify_oop(rax);                      // verify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
      __ pushl(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    default       : ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  __ jmp(t);                                   // return from result handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
address CppInterpreterGenerator::generate_stack_to_stack_converter(BasicType type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  // A result is in the java expression stack of the interpreted method that has just
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  // returned. Place this result on the java expression stack of the caller.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  // The current interpreter activation in rsi is for the method just returning its
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  // result. So we know that the result of this method is on the top of the current
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  // execution stack (which is pre-pushed) and will be return to the top of the caller
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  // stack. The top of the callers stack is the bottom of the locals of the current
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  // activation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  // Because of the way activation are managed by the frame manager the value of rsp is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  // below both the stack top of the current activation and naturally the stack top
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  // of the calling activation. This enable this routine to leave the return address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  // to the frame manager on the stack and do a vanilla return.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  // On entry: rsi - interpreter state of activation returning a (potential) result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  // On Return: rsi - unchanged
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  //            rax - new stack top for caller activation (i.e. activation in _prev_link)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  // Can destroy rdx, rcx.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  address entry = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  const Register state   = rsi;                                    // current activation object, valid on entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  switch (type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    case T_VOID:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
      __ movl(rax, STATE(_locals));                                     // pop parameters get new stack value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
      __ addl(rax, wordSize);                                           // account for prepush before we return
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    case T_FLOAT  :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    case T_BOOLEAN:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    case T_CHAR   :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    case T_BYTE   :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    case T_SHORT  :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    case T_INT    :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
      // 1 word result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
      __ movl(rdx, STATE(_stack));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
      __ movl(rax, STATE(_locals));                                     // address for result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
      __ movl(rdx, Address(rdx, wordSize));                             // get result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
      __ movl(Address(rax, 0), rdx);                                    // and store it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    case T_LONG    :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    case T_DOUBLE  :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
      // return top two words on current expression stack to caller's expression stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
      // The caller's expression stack is adjacent to the current frame manager's intepretState
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
      // except we allocated one extra word for this intepretState so we won't overwrite it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
      // when we return a two word result.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
      __ movl(rax, STATE(_locals));                                     // address for result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
      __ movl(rcx, STATE(_stack));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
      __ subl(rax, wordSize);                                           // need addition word besides locals[0]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
      __ movl(rdx, Address(rcx, 2*wordSize));                           // get result word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
      __ movl(Address(rax, wordSize), rdx);                             // and store it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
      __ movl(rdx, Address(rcx, wordSize));                             // get result word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
      __ movl(Address(rax, 0), rdx);                                    // and store it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    case T_OBJECT :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
      __ movl(rdx, STATE(_stack));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
      __ movl(rax, STATE(_locals));                                     // address for result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
      __ movl(rdx, Address(rdx, wordSize));                             // get result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
      __ verify_oop(rdx);                                               // verify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
      __ movl(Address(rax, 0), rdx);                                    // and store it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    default       : ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  __ ret(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
address CppInterpreterGenerator::generate_stack_to_native_abi_converter(BasicType type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  // A result is in the java expression stack of the interpreted method that has just
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  // returned. Place this result in the native abi that the caller expects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  // Similar to generate_stack_to_stack_converter above. Called at a similar time from the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  // frame manager execept in this situation the caller is native code (c1/c2/call_stub)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  // and so rather than return result onto caller's java expression stack we return the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  // result in the expected location based on the native abi.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  // On entry: rsi - interpreter state of activation returning a (potential) result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  // On Return: rsi - unchanged
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  // Other registers changed [rax/rdx/ST(0) as needed for the result returned]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  address entry = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  const Register state   = rsi;                                    // current activation object, valid on entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  switch (type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    case T_VOID:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
       break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    case T_BOOLEAN:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    case T_CHAR   :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    case T_BYTE   :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    case T_SHORT  :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    case T_INT    :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
      __ movl(rdx, STATE(_stack));                                      // get top of stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
      __ movl(rax, Address(rdx, wordSize));                             // get result word 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    case T_LONG    :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
      __ movl(rdx, STATE(_stack));                                      // get top of stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
      __ movl(rax, Address(rdx, wordSize));                             // get result low word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
      __ movl(rdx, Address(rdx, 2*wordSize));                           // get result high word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    case T_FLOAT  :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
      __ movl(rdx, STATE(_stack));                                      // get top of stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
      if ( UseSSE >= 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
        __ movflt(xmm0, Address(rdx, wordSize));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
        __ fld_s(Address(rdx, wordSize));                               // pushd float result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    case T_DOUBLE  :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
      __ movl(rdx, STATE(_stack));                                      // get top of stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
      if ( UseSSE > 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
        __ movdbl(xmm0, Address(rdx, wordSize));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
        __ fld_d(Address(rdx, wordSize));                               // push double result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
    case T_OBJECT :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
      __ movl(rdx, STATE(_stack));                                      // get top of stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
      __ movl(rax, Address(rdx, wordSize));                             // get result word 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
      __ verify_oop(rax);                                               // verify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    default       : ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  __ ret(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
address CppInterpreter::return_entry(TosState state, int length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  // make it look good in the debugger
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  return CAST_FROM_FN_PTR(address, RecursiveInterpreterActivation);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
address CppInterpreter::deopt_entry(TosState state, int length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  address ret = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  if (length != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    switch (state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
      case atos: ret = deopt_frame_manager_return_atos; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
      case btos: ret = deopt_frame_manager_return_btos; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
      case ctos:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
      case stos:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
      case itos: ret = deopt_frame_manager_return_itos; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
      case ltos: ret = deopt_frame_manager_return_ltos; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
      case ftos: ret = deopt_frame_manager_return_ftos; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
      case dtos: ret = deopt_frame_manager_return_dtos; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
      case vtos: ret = deopt_frame_manager_return_vtos; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    ret = unctrap_frame_manager_entry;  // re-execute the bytecode ( e.g. uncommon trap)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  assert(ret != NULL, "Not initialized");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  return ret;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
// C++ Interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
void CppInterpreterGenerator::generate_compute_interpreter_state(const Register state,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
                                                                 const Register locals,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
                                                                 const Register sender_sp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
                                                                 bool native) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  // On entry the "locals" argument points to locals[0] (or where it would be in case no locals in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  // a static method). "state" contains any previous frame manager state which we must save a link
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  // to in the newly generated state object. On return "state" is a pointer to the newly allocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  // state object. We must allocate and initialize a new interpretState object and the method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  // expression stack. Because the returned result (if any) of the method will be placed on the caller's
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  // expression stack and this will overlap with locals[0] (and locals[1] if double/long) we must
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  // be sure to leave space on the caller's stack so that this result will not overwrite values when
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  // locals[0] and locals[1] do not exist (and in fact are return address and saved rbp). So when
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  // we are non-native we in essence ensure that locals[0-1] exist. We play an extra trick in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  // non-product builds and initialize this last local with the previous interpreterState as
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  // this makes things look real nice in the debugger.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  // State on entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  // Assumes locals == &locals[0]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  // Assumes state == any previous frame manager state (assuming call path from c++ interpreter)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  // Assumes rax = return address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  // rcx == senders_sp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  // rbx == method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  // Modifies rcx, rdx, rax
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  // Returns:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  // state == address of new interpreterState
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  // rsp == bottom of method's expression stack.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  const Address const_offset      (rbx, methodOopDesc::const_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  // On entry sp is the sender's sp. This includes the space for the arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  // that the sender pushed. If the sender pushed no args (a static) and the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  // caller returns a long then we need two words on the sender's stack which
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  // are not present (although when we return a restore full size stack the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  // space will be present). If we didn't allocate two words here then when
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  // we "push" the result of the caller's stack we would overwrite the return
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  // address and the saved rbp. Not good. So simply allocate 2 words now
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  // just to be safe. This is the "static long no_params() method" issue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  // See Lo.java for a testcase.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  // We don't need this for native calls because they return result in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  // register and the stack is expanded in the caller before we store
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  // the results on the stack.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  if (!native) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
#ifdef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
    __ subl(rsp, 2*wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
#else /* PRODUCT */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
    __ pushl((int)NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
    __ pushl(state);                         // make it look like a real argument
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
#endif /* PRODUCT */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  // Now that we are assure of space for stack result, setup typical linkage
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  __ pushl(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  __ enter();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  __ movl(rax, state);                                 // save current state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  __ leal(rsp, Address(rsp, -(int)sizeof(BytecodeInterpreter)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  __ movl(state, rsp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  // rsi == state/locals rax == prevstate
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  // initialize the "shadow" frame so that use since C++ interpreter not directly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  // recursive. Simpler to recurse but we can't trim expression stack as we call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  // new methods.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  __ movl(STATE(_locals), locals);                      // state->_locals = locals()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  __ movl(STATE(_self_link), state);                    // point to self
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  __ movl(STATE(_prev_link), rax);                      // state->_link = state on entry (NULL or previous state)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  __ movl(STATE(_sender_sp), sender_sp);                // state->_sender_sp = sender_sp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  __ get_thread(rax);                                   // get vm's javathread*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  __ movl(STATE(_thread), rax);                         // state->_bcp = codes()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  __ movl(rdx, Address(rbx, methodOopDesc::const_offset())); // get constantMethodOop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  __ leal(rdx, Address(rdx, constMethodOopDesc::codes_offset())); // get code base
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  if (native) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
    __ movl(STATE(_bcp), (intptr_t)NULL);               // state->_bcp = NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    __ movl(STATE(_bcp), rdx);                          // state->_bcp = codes()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  __ xorl(rdx, rdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  __ movl(STATE(_oop_temp), rdx);                       // state->_oop_temp = NULL (only really needed for native)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  __ movl(STATE(_mdx), rdx);                            // state->_mdx = NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  __ movl(rdx, Address(rbx, methodOopDesc::constants_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  __ movl(rdx, Address(rdx, constantPoolOopDesc::cache_offset_in_bytes()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  __ movl(STATE(_constants), rdx);                      // state->_constants = constants()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  __ movl(STATE(_method), rbx);                         // state->_method = method()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  __ movl(STATE(_msg), (int) BytecodeInterpreter::method_entry);   // state->_msg = initial method entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  __ movl(STATE(_result._to_call._callee), (int) NULL); // state->_result._to_call._callee_callee = NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  __ movl(STATE(_monitor_base), rsp);                   // set monitor block bottom (grows down) this would point to entry [0]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
                                                        // entries run from -1..x where &monitor[x] ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
    // Must not attempt to lock method until we enter interpreter as gc won't be able to find the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
    // initial frame. However we allocate a free monitor so we don't have to shuffle the expression stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    // immediately.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
    // synchronize method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
    const Address access_flags      (rbx, methodOopDesc::access_flags_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
    const int entry_size            = frame::interpreter_frame_monitor_size() * wordSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    Label not_synced;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    __ movl(rax, access_flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
    __ testl(rax, JVM_ACC_SYNCHRONIZED);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
    __ jcc(Assembler::zero, not_synced);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
    // Allocate initial monitor and pre initialize it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
    // get synchronization object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
    Label done;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
    const int mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    __ movl(rax, access_flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
    __ testl(rax, JVM_ACC_STATIC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    __ movl(rax, Address(locals, 0));                     // get receiver (assume this is frequent case)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
    __ jcc(Assembler::zero, done);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
    __ movl(rax, Address(rbx, methodOopDesc::constants_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
    __ movl(rax, Address(rax, constantPoolOopDesc::pool_holder_offset_in_bytes()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    __ movl(rax, Address(rax, mirror_offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    __ bind(done);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
    // add space for monitor & lock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
    __ subl(rsp, entry_size);                                             // add space for a monitor entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    __ movl(Address(rsp, BasicObjectLock::obj_offset_in_bytes()), rax);   // store object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
    __ bind(not_synced);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  __ movl(STATE(_stack_base), rsp);                                     // set expression stack base ( == &monitors[-count])
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  if (native) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
    __ movl(STATE(_stack), rsp);                                          // set current expression stack tos
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
    __ movl(STATE(_stack_limit), rsp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
    __ subl(rsp, wordSize);                                               // pre-push stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
    __ movl(STATE(_stack), rsp);                                          // set current expression stack tos
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
    // compute full expression stack limit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
    const Address size_of_stack    (rbx, methodOopDesc::max_stack_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
    __ load_unsigned_word(rdx, size_of_stack);                            // get size of expression stack in words
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
    __ negl(rdx);                                                         // so we can subtract in next step
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
    // Allocate expression stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
    __ leal(rsp, Address(rsp, rdx, Address::times_4));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
    __ movl(STATE(_stack_limit), rsp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
// Helpers for commoning out cases in the various type of method entries.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
// increment invocation count & check for overflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
// Note: checking for negative value instead of overflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
//       so we have a 'sticky' overflow test
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
// rbx,: method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
// rcx: invocation counter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
void InterpreterGenerator::generate_counter_incr(Label* overflow, Label* profile_method, Label* profile_method_continue) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
  const Address invocation_counter(rbx, methodOopDesc::invocation_counter_offset() + InvocationCounter::counter_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  const Address backedge_counter  (rbx, methodOopDesc::backedge_counter_offset() + InvocationCounter::counter_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
  if (ProfileInterpreter) { // %%% Merge this into methodDataOop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
    __ increment(Address(rbx,methodOopDesc::interpreter_invocation_counter_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  // Update standard invocation counters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
  __ movl(rax, backedge_counter);               // load backedge counter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
  __ increment(rcx, InvocationCounter::count_increment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
  __ andl(rax, InvocationCounter::count_mask_value);  // mask out the status bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
  __ movl(invocation_counter, rcx);             // save invocation count
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
  __ addl(rcx, rax);                            // add both counters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
  // profile_method is non-null only for interpreted method so
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  // profile_method != NULL == !native_call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  // BytecodeInterpreter only calls for native so code is elided.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
  __ cmp32(rcx,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
           ExternalAddress((address)&InvocationCounter::InterpreterInvocationLimit));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
  __ jcc(Assembler::aboveEqual, *overflow);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
void InterpreterGenerator::generate_counter_overflow(Label* do_continue) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
  // C++ interpreter on entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
  // rsi - new interpreter state pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
  // rbp - interpreter frame pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
  // rbx - method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
  // On return (i.e. jump to entry_point) [ back to invocation of interpreter ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
  // rbx, - method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
  // rcx - rcvr (assuming there is one)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  // top of stack return address of interpreter caller
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
  // rsp - sender_sp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
  // C++ interpreter only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
  // rsi - previous interpreter state pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  const Address size_of_parameters(rbx, methodOopDesc::size_of_parameters_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
  // InterpreterRuntime::frequency_counter_overflow takes one argument
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  // indicating if the counter overflow occurs at a backwards branch (non-NULL bcp).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
  // The call returns the address of the verified entry point for the method or NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
  // if the compilation did not complete (either went background or bailed out).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
  __ movl(rax, (int)false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
  __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  // for c++ interpreter can rsi really be munged?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  __ leal(rsi, Address(rbp, -sizeof(BytecodeInterpreter)));                                // restore state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  __ movl(rbx, Address(rsi, byte_offset_of(BytecodeInterpreter, _method)));                // restore method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  __ movl(rdi, Address(rsi, byte_offset_of(BytecodeInterpreter, _locals)));                // get locals pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  // Preserve invariant that rsi/rdi contain bcp/locals of sender frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
  // and jump to the interpreted entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
  __ jmp(*do_continue, relocInfo::none);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
void InterpreterGenerator::generate_stack_overflow_check(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  // see if we've got enough room on the stack for locals plus overhead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
  // the expression stack grows down incrementally, so the normal guard
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
  // page mechanism will work for that.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
  // Registers live on entry:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  // Asm interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
  // rdx: number of additional locals this frame needs (what we must check)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
  // rbx,: methodOop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
  // C++ Interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  // rsi: previous interpreter frame state object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
  // rdi: &locals[0]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
  // rcx: # of locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
  // rdx: number of additional locals this frame needs (what we must check)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
  // rbx: methodOop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
  // destroyed on exit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
  // rax,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
  // NOTE:  since the additional locals are also always pushed (wasn't obvious in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
  // generate_method_entry) so the guard should work for them too.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
  // monitor entry size: see picture of stack set (generate_method_entry) and frame_i486.hpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
  const int entry_size    = frame::interpreter_frame_monitor_size() * wordSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
  // total overhead size: entry_size + (saved rbp, thru expr stack bottom).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
  // be sure to change this if you add/subtract anything to/from the overhead area
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
  const int overhead_size = (int)sizeof(BytecodeInterpreter);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
  const int page_size = os::vm_page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
  Label after_frame_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
  // compute rsp as if this were going to be the last frame on
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
  // the stack before the red zone
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  Label after_frame_check_pop;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
  // save rsi == caller's bytecode ptr (c++ previous interp. state)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
  // QQQ problem here?? rsi overload????
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
  __ pushl(rsi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  const Register thread = rsi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
  __ get_thread(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
  const Address stack_base(thread, Thread::stack_base_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
  const Address stack_size(thread, Thread::stack_size_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
  // locals + overhead, in bytes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
    const Address size_of_stack    (rbx, methodOopDesc::max_stack_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
    // Always give one monitor to allow us to start interp if sync method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
    // Any additional monitors need a check when moving the expression stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
    const one_monitor = frame::interpreter_frame_monitor_size() * wordSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
  __ load_unsigned_word(rax, size_of_stack);                            // get size of expression stack in words
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
  __ leal(rax, Address(noreg, rax, Interpreter::stackElementScale(), one_monitor));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
  __ leal(rax, Address(rax, rdx, Interpreter::stackElementScale(), overhead_size));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
  Label stack_base_okay, stack_size_okay;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
  // verify that thread stack base is non-zero
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
  __ cmpl(stack_base, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
  __ jcc(Assembler::notEqual, stack_base_okay);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
  __ stop("stack base is zero");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
  __ bind(stack_base_okay);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
  // verify that thread stack size is non-zero
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
  __ cmpl(stack_size, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
  __ jcc(Assembler::notEqual, stack_size_okay);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
  __ stop("stack size is zero");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
  __ bind(stack_size_okay);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
  // Add stack base to locals and subtract stack size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
  __ addl(rax, stack_base);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
  __ subl(rax, stack_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
  // We should have a magic number here for the size of the c++ interpreter frame.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
  // We can't actually tell this ahead of time. The debug version size is around 3k
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
  // product is 1k and fastdebug is 4k
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
  const int slop = 6 * K;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
  // Use the maximum number of pages we might bang.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
  const int max_pages = StackShadowPages > (StackRedPages+StackYellowPages) ? StackShadowPages :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
                                                                              (StackRedPages+StackYellowPages);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
  // Only need this if we are stack banging which is temporary while
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
  // we're debugging.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
  __ addl(rax, slop + 2*max_pages * page_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
  // check against the current stack bottom
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
  __ cmpl(rsp, rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
  __ jcc(Assembler::above, after_frame_check_pop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
  __ popl(rsi);  // get saved bcp / (c++ prev state ).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
     // throw exception return address becomes throwing pc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
  __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
  // all done with frame size check
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
  __ bind(after_frame_check_pop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
  __ popl(rsi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
  __ bind(after_frame_check);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
// Find preallocated  monitor and lock method (C++ interpreter)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
// rbx - methodOop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
void InterpreterGenerator::lock_method(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
  // assumes state == rsi == pointer to current interpreterState
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
  // minimally destroys rax, rdx, rdi
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
  // synchronize method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
  const Register state = rsi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
  const int entry_size            = frame::interpreter_frame_monitor_size() * wordSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
  const Address access_flags      (rbx, methodOopDesc::access_flags_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
  // find initial monitor i.e. monitors[-1]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
  __ movl(rdx, STATE(_monitor_base));                                   // get monitor bottom limit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
  __ subl(rdx, entry_size);                                             // point to initial monitor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
  { Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
    __ movl(rax, access_flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
    __ testl(rax, JVM_ACC_SYNCHRONIZED);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
    __ jcc(Assembler::notZero, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
    __ stop("method doesn't need synchronization");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
  // get synchronization object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
  { Label done;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
    const int mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
    __ movl(rax, access_flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
    __ movl(rdi, STATE(_locals));                                       // prepare to get receiver (assume common case)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
    __ testl(rax, JVM_ACC_STATIC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
    __ movl(rax, Address(rdi, 0));                                      // get receiver (assume this is frequent case)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
    __ jcc(Assembler::zero, done);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
    __ movl(rax, Address(rbx, methodOopDesc::constants_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
    __ movl(rax, Address(rax, constantPoolOopDesc::pool_holder_offset_in_bytes()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
    __ movl(rax, Address(rax, mirror_offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
    __ bind(done);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
  { Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
    __ cmpl(rax, Address(rdx, BasicObjectLock::obj_offset_in_bytes()));   // correct object?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
    __ jcc(Assembler::equal, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
    __ stop("wrong synchronization lobject");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
  // can destroy rax, rdx, rcx, and (via call_VM) rdi!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
  __ lock_object(rdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
// Call an accessor method (assuming it is resolved, otherwise drop into vanilla (slow path) entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
address InterpreterGenerator::generate_accessor_entry(void) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
  // rbx,: methodOop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
  // rcx: receiver (preserve for slow entry into asm interpreter)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
  // rsi: senderSP must preserved for slow path, set SP to it on fast path
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
  Label xreturn_path;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
  // do fastpath for resolved accessor methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
  if (UseFastAccessorMethods) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
    address entry_point = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
    Label slow_path;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
    // If we need a safepoint check, generate full interpreter entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
    ExternalAddress state(SafepointSynchronize::address_of_state());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
    __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
             SafepointSynchronize::_not_synchronized);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
    __ jcc(Assembler::notEqual, slow_path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
    // ASM/C++ Interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
    // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites thereof; parameter size = 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
    // Note: We can only use this code if the getfield has been resolved
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
    //       and if we don't have a null-pointer exception => check for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
    //       these conditions first and use slow path if necessary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
    // rbx,: method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
    // rcx: receiver
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
    __ movl(rax, Address(rsp, wordSize));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
    // check if local 0 != NULL and read field
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
    __ testl(rax, rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
    __ jcc(Assembler::zero, slow_path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
    __ movl(rdi, Address(rbx, methodOopDesc::constants_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
    // read first instruction word and extract bytecode @ 1 and index @ 2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
    __ movl(rdx, Address(rbx, methodOopDesc::const_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
    __ movl(rdx, Address(rdx, constMethodOopDesc::codes_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
    // Shift codes right to get the index on the right.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
    // The bytecode fetched looks like <index><0xb4><0x2a>
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
    __ shrl(rdx, 2*BitsPerByte);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
    __ shll(rdx, exact_log2(in_words(ConstantPoolCacheEntry::size())));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
    __ movl(rdi, Address(rdi, constantPoolOopDesc::cache_offset_in_bytes()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
    // rax,: local 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
    // rbx,: method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
    // rcx: receiver - do not destroy since it is needed for slow path!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
    // rcx: scratch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
    // rdx: constant pool cache index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
    // rdi: constant pool cache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
    // rsi: sender sp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
    // check if getfield has been resolved and read constant pool cache entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
    // check the validity of the cache entry by testing whether _indices field
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
    // contains Bytecode::_getfield in b1 byte.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
    assert(in_words(ConstantPoolCacheEntry::size()) == 4, "adjust shift below");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
    __ movl(rcx,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
            Address(rdi,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
                    rdx,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
                    Address::times_4, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::indices_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
    __ shrl(rcx, 2*BitsPerByte);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
    __ andl(rcx, 0xFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
    __ cmpl(rcx, Bytecodes::_getfield);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
    __ jcc(Assembler::notEqual, slow_path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
    // Note: constant pool entry is not valid before bytecode is resolved
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
    __ movl(rcx,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
            Address(rdi,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
                    rdx,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
                    Address::times_4, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::f2_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
    __ movl(rdx,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
            Address(rdi,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
                    rdx,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
                    Address::times_4, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::flags_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
    Label notByte, notShort, notChar;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
    const Address field_address (rax, rcx, Address::times_1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
    // Need to differentiate between igetfield, agetfield, bgetfield etc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
    // because they are different sizes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
    // Use the type from the constant pool cache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
    __ shrl(rdx, ConstantPoolCacheEntry::tosBits);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
    // Make sure we don't need to mask rdx for tosBits after the above shift
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
    ConstantPoolCacheEntry::verify_tosBits();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
    __ cmpl(rdx, btos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
    __ jcc(Assembler::notEqual, notByte);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
    __ load_signed_byte(rax, field_address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
    __ jmp(xreturn_path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
    __ bind(notByte);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
    __ cmpl(rdx, stos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
    __ jcc(Assembler::notEqual, notShort);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
    __ load_signed_word(rax, field_address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
    __ jmp(xreturn_path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
    __ bind(notShort);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
    __ cmpl(rdx, ctos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
    __ jcc(Assembler::notEqual, notChar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
    __ load_unsigned_word(rax, field_address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
    __ jmp(xreturn_path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
    __ bind(notChar);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
    Label okay;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
    __ cmpl(rdx, atos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
    __ jcc(Assembler::equal, okay);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
    __ cmpl(rdx, itos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
    __ jcc(Assembler::equal, okay);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
    __ stop("what type is this?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
    __ bind(okay);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
    // All the rest are a 32 bit wordsize
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
    __ movl(rax, field_address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
    __ bind(xreturn_path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
    // _ireturn/_areturn
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
    __ popl(rdi);                              // get return address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
    __ movl(rsp, rsi);                         // set sp to sender sp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
    __ jmp(rdi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
    // generate a vanilla interpreter entry as the slow path
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
    __ bind(slow_path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
    // We will enter c++ interpreter looking like it was
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
    // called by the call_stub this will cause it to return
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
    // a tosca result to the invoker which might have been
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
    // the c++ interpreter itself.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
    __ jmp(fast_accessor_slow_entry_path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
    return entry_point;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
// C++ Interpreter stub for calling a native method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
// This sets up a somewhat different looking stack for calling the native method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
// than the typical interpreter frame setup but still has the pointer to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
// an interpreter state.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
address InterpreterGenerator::generate_native_entry(bool synchronized) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
  // determine code generation flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
  bool inc_counter  = UseCompiler || CountCompiledCalls;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
  // rbx: methodOop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
  // rcx: receiver (unused)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
  // rsi: previous interpreter state (if called from C++ interpreter) must preserve
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
  //      in any case. If called via c1/c2/call_stub rsi is junk (to use) but harmless
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
  //      to save/restore.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
  address entry_point = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
  const Address size_of_parameters(rbx, methodOopDesc::size_of_parameters_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
  const Address size_of_locals    (rbx, methodOopDesc::size_of_locals_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
  const Address invocation_counter(rbx, methodOopDesc::invocation_counter_offset() + InvocationCounter::counter_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
  const Address access_flags      (rbx, methodOopDesc::access_flags_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
  // rsi == state/locals rdi == prevstate
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
  const Register state = rsi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
  const Register locals = rdi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
  // get parameter size (always needed)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
  __ load_unsigned_word(rcx, size_of_parameters);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
  // rbx: methodOop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
  // rcx: size of parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
  __ popl(rax);                                       // get return address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
  // for natives the size of locals is zero
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
  // compute beginning of parameters /locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
  __ leal(locals, Address(rsp, rcx, Address::times_4, -wordSize));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
  // initialize fixed part of activation frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
  // Assumes rax = return address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
  // allocate and initialize new interpreterState and method expression stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
  // IN(locals) ->  locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
  // IN(state) -> previous frame manager state (NULL from stub/c1/c2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
  // destroys rax, rcx, rdx
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
  // OUT (state) -> new interpreterState
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
  // OUT(rsp) -> bottom of methods expression stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
  // save sender_sp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
  __ movl(rcx, rsi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
  // start with NULL previous state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
  __ movl(state, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
  generate_compute_interpreter_state(state, locals, rcx, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
  { Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
    __ movl(rax, STATE(_stack_base));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
    __ cmpl(rax, rsp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
    __ jcc(Assembler::equal, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
    __ stop("broken stack frame setup in interpreter");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
  if (inc_counter) __ movl(rcx, invocation_counter);  // (pre-)fetch invocation count
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
  __ movl(rax, STATE(_thread));                       // get thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
  // Since at this point in the method invocation the exception handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
  // would try to exit the monitor of synchronized methods which hasn't
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
  // been entered yet, we set the thread local variable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
  // _do_not_unlock_if_synchronized to true. The remove_activation will
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
  // check this flag.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
  const Address do_not_unlock_if_synchronized(rax,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
        in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
  __ movbool(do_not_unlock_if_synchronized, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
  // make sure method is native & not abstract
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
  __ movl(rax, access_flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
    Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
    __ testl(rax, JVM_ACC_NATIVE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
    __ jcc(Assembler::notZero, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
    __ stop("tried to execute non-native method as native");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
  { Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
    __ testl(rax, JVM_ACC_ABSTRACT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
    __ jcc(Assembler::zero, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
    __ stop("tried to execute abstract method in interpreter");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
  // increment invocation count & check for overflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
  Label invocation_counter_overflow;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
  if (inc_counter) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
    generate_counter_incr(&invocation_counter_overflow, NULL, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
  Label continue_after_compile;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
  __ bind(continue_after_compile);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
  bang_stack_shadow_pages(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
  // reset the _do_not_unlock_if_synchronized flag
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
  __ movl(rax, STATE(_thread));                       // get thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
  __ movbool(do_not_unlock_if_synchronized, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
  // check for synchronized native methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
  // Note: This must happen *after* invocation counter check, since
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
  //       when overflow happens, the method should not be locked.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
  if (synchronized) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
    // potentially kills rax, rcx, rdx, rdi
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
    lock_method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
    // no synchronization necessary
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
      { Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
        __ movl(rax, access_flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
        __ testl(rax, JVM_ACC_SYNCHRONIZED);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
        __ jcc(Assembler::zero, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
        __ stop("method needs synchronization");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
        __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
  // start execution
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
  // jvmti support
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
  __ notify_method_entry();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
  // work registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
  const Register method = rbx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
  const Register thread = rdi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
  const Register t      = rcx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
  // allocate space for parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
  __ movl(method, STATE(_method));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
  __ verify_oop(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
  __ load_unsigned_word(t, Address(method, methodOopDesc::size_of_parameters_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
  __ shll(t, 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
  __ addl(t, 2*wordSize);     // allocate two more slots for JNIEnv and possible mirror
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
  __ subl(rsp, t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
  __ andl(rsp, -(StackAlignmentInBytes)); // gcc needs 16 byte aligned stacks to do XMM intrinsics
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
  // get signature handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
    Label pending_exception_present;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
  { Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
    __ movl(t, Address(method, methodOopDesc::signature_handler_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
    __ testl(t, t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
    __ jcc(Assembler::notZero, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
    __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
    __ movl(method, STATE(_method));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
    __ cmpl(Address(thread, Thread::pending_exception_offset()), NULL_WORD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
    __ jcc(Assembler::notEqual, pending_exception_present);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
    __ verify_oop(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
    __ movl(t, Address(method, methodOopDesc::signature_handler_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
    Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
    __ pushl(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
    __ get_thread(t);                                   // get vm's javathread*
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
    __ cmpl(t, STATE(_thread));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
    __ jcc(Assembler::equal, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
    __ int3();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
    __ popl(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
#endif //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
  // call signature handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
  assert(InterpreterRuntime::SignatureHandlerGenerator::from() == rdi, "adjust this code");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
  assert(InterpreterRuntime::SignatureHandlerGenerator::to  () == rsp, "adjust this code");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
  assert(InterpreterRuntime::SignatureHandlerGenerator::temp() == t  , "adjust this code");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
  // The generated handlers do not touch RBX (the method oop).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
  // However, large signatures cannot be cached and are generated
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
  // each time here.  The slow-path generator will blow RBX
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
  // sometime, so we must reload it after the call.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
  __ movl(rdi, STATE(_locals));  // get the from pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
  __ call(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
  __ movl(method, STATE(_method));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
  __ verify_oop(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
  // result handler is in rax
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
  // set result handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
  __ movl(STATE(_result_handler), rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
  // pass mirror handle if static call
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
  { Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
    const int mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
    __ movl(t, Address(method, methodOopDesc::access_flags_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
    __ testl(t, JVM_ACC_STATIC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
    __ jcc(Assembler::zero, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
    // get mirror
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
    __ movl(t, Address(method, methodOopDesc:: constants_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
    __ movl(t, Address(t, constantPoolOopDesc::pool_holder_offset_in_bytes()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
    __ movl(t, Address(t, mirror_offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
    // copy mirror into activation object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
    __ movl(STATE(_oop_temp), t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
    // pass handle to mirror
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
    __ leal(t, STATE(_oop_temp));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
    __ movl(Address(rsp, wordSize), t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
    Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
    __ pushl(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
    __ get_thread(t);                                   // get vm's javathread*
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
    __ cmpl(t, STATE(_thread));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
    __ jcc(Assembler::equal, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
    __ int3();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
    __ popl(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
#endif //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
  // get native function entry point
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
  { Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
    __ movl(rax, Address(method, methodOopDesc::native_function_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
    __ testl(rax, rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
    __ jcc(Assembler::notZero, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
    __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
    __ movl(method, STATE(_method));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
    __ verify_oop(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
    __ movl(rax, Address(method, methodOopDesc::native_function_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
  // pass JNIEnv
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
  __ movl(thread, STATE(_thread));                       // get thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
  __ leal(t, Address(thread, JavaThread::jni_environment_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
  __ movl(Address(rsp, 0), t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
    Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
    __ pushl(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
    __ get_thread(t);                                   // get vm's javathread*
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
    __ cmpl(t, STATE(_thread));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
    __ jcc(Assembler::equal, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
    __ int3();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
    __ popl(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
#endif //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
  { Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
    __ movl(t, Address(thread, JavaThread::thread_state_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
    __ cmpl(t, _thread_in_Java);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
    __ jcc(Assembler::equal, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
    __ stop("Wrong thread state in native stub");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
  // Change state to native (we save the return address in the thread, since it might not
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
  // be pushed on the stack when we do a a stack traversal). It is enough that the pc()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
  // points into the right code segment. It does not have to be the correct return pc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
  __ set_last_Java_frame(thread, noreg, rbp, __ pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
  __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_native);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
  __ call(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
  // result potentially in rdx:rax or ST0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
  __ movl(method, STATE(_method));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
  __ movl(thread, STATE(_thread));                       // get thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
  // The potential result is in ST(0) & rdx:rax
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
  // With C++ interpreter we leave any possible result in ST(0) until we are in result handler and then
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
  // we do the appropriate stuff for returning the result. rdx:rax must always be saved because just about
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
  // anything we do here will destroy it, st(0) is only saved if we re-enter the vm where it would
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
  // be destroyed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
  // It is safe to do these pushes because state is _thread_in_native and return address will be found
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
  // via _last_native_pc and not via _last_jave_sp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
    // Must save the value of ST(0) since it could be destroyed before we get to result handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
    { Label Lpush, Lskip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
      ExternalAddress float_handler(AbstractInterpreter::result_handler(T_FLOAT));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
      ExternalAddress double_handler(AbstractInterpreter::result_handler(T_DOUBLE));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
      __ cmpptr(STATE(_result_handler), float_handler.addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
      __ jcc(Assembler::equal, Lpush);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
      __ cmpptr(STATE(_result_handler), double_handler.addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
      __ jcc(Assembler::notEqual, Lskip);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
      __ bind(Lpush);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
      __ push(dtos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
      __ bind(Lskip);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
  __ push(ltos);           // save rax:rdx for potential use by result handler.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
  // Either restore the MXCSR register after returning from the JNI Call
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
  // or verify that it wasn't changed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
  if (VM_Version::supports_sse()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
    if (RestoreMXCSROnJNICalls) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
      __ ldmxcsr(ExternalAddress(StubRoutines::addr_mxcsr_std()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
    else if (CheckJNICalls ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
      __ call(RuntimeAddress(StubRoutines::i486::verify_mxcsr_entry()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
  // Either restore the x87 floating pointer control word after returning
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
  // from the JNI call or verify that it wasn't changed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
  if (CheckJNICalls) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
    __ call(RuntimeAddress(StubRoutines::i486::verify_fpu_cntrl_wrd_entry()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
  // change thread state
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
  __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_native_trans);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
  if(os::is_MP()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
    // Write serialization page so VM thread can do a pseudo remote membar.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
    // We use the current thread pointer to calculate a thread specific
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
    // offset to write to within the page. This minimizes bus traffic
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
    // due to cache line collision.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
    __ serialize_memory(thread, rcx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
  // check for safepoint operation in progress and/or pending suspend requests
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
  { Label Continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
    __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
             SafepointSynchronize::_not_synchronized);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
    // threads running native code and they are expected to self-suspend
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
    // when leaving the _thread_in_native state. We need to check for
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
    // pending suspend requests here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
    Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
    __ jcc(Assembler::notEqual, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
    __ cmpl(Address(thread, JavaThread::suspend_flags_offset()), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
    __ jcc(Assembler::equal, Continue);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
    // Don't use call_VM as it will see a possible pending exception and forward it
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
    // and never return here preventing us from clearing _last_native_pc down below.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
    // Also can't use call_VM_leaf either as it will check to see if rsi & rdi are
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
    // preserved and correspond to the bcp/locals pointers. So we do a runtime call
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
    // by hand.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
    __ pushl(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
    __ call(RuntimeAddress(CAST_FROM_FN_PTR(address,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
                                            JavaThread::check_special_condition_for_native_trans)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
    __ increment(rsp, wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
    __ movl(method, STATE(_method));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
    __ verify_oop(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
    __ movl(thread, STATE(_thread));                       // get thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
    __ bind(Continue);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
  // change thread state
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
  __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_Java);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
  __ reset_last_Java_frame(thread, true, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
  // reset handle block
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
  __ movl(t, Address(thread, JavaThread::active_handles_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
  __ movl(Address(t, JNIHandleBlock::top_offset_in_bytes()), NULL_WORD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
  // If result was an oop then unbox and save it in the frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
  { Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
    Label no_oop, store_result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
      ExternalAddress oop_handler(AbstractInterpreter::result_handler(T_OBJECT));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
    __ cmpptr(STATE(_result_handler), oop_handler.addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
    __ jcc(Assembler::notEqual, no_oop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
    __ pop(ltos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
    __ testl(rax, rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
    __ jcc(Assembler::zero, store_result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
    // unbox
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
    __ movl(rax, Address(rax, 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
    __ bind(store_result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
    __ movl(STATE(_oop_temp), rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
    // keep stack depth as expected by pushing oop which will eventually be discarded
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
    __ push(ltos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
    __ bind(no_oop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
     Label no_reguard;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
     __ cmpl(Address(thread, JavaThread::stack_guard_state_offset()), JavaThread::stack_guard_yellow_disabled);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
     __ jcc(Assembler::notEqual, no_reguard);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
     __ pushad();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
     __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
     __ popad();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1284
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
     __ bind(no_reguard);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1288
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
  // QQQ Seems like for native methods we simply return and the caller will see the pending
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
  // exception and do the right thing. Certainly the interpreter will, don't know about
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
  // compiled methods.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
  // Seems that the answer to above is no this is wrong. The old code would see the exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
  // and forward it before doing the unlocking and notifying jvmdi that method has exited.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
  // This seems wrong need to investigate the spec.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
  // handle exceptions (exception handling will handle unlocking!)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
  { Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
    __ cmpl(Address(thread, Thread::pending_exception_offset()), NULL_WORD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
    __ jcc(Assembler::zero, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
    __ bind(pending_exception_present);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1302
    // There are potential results on the stack (rax/rdx, ST(0)) we ignore these and simply
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
    // return and let caller deal with exception. This skips the unlocking here which
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
    // seems wrong but seems to be what asm interpreter did. Can't find this in the spec.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
    // Note: must preverve method in rbx
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1307
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
    // remove activation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
    __ movl(t, STATE(_sender_sp));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
    __ leave();                                  // remove frame anchor
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
    __ popl(rdi);                                // get return address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
    __ movl(state, STATE(_prev_link));           // get previous state for return
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
    __ movl(rsp, t);                             // set sp to sender sp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1315
    __ pushl(rdi);                               // [ush throwing pc
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
    // The skips unlocking!! This seems to be what asm interpreter does but seems
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1317
    // very wrong. Not clear if this violates the spec.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1318
    __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1319
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1321
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1322
  // do unlocking if necessary
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
  { Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1324
    __ movl(t, Address(method, methodOopDesc::access_flags_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1325
    __ testl(t, JVM_ACC_SYNCHRONIZED);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1326
    __ jcc(Assembler::zero, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1327
    // the code below should be shared with interpreter macro assembler implementation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1328
    { Label unlock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1329
      // BasicObjectLock will be first in list, since this is a synchronized method. However, need
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
      // to check that the object has not been unlocked by an explicit monitorexit bytecode.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
      __ movl(rdx, STATE(_monitor_base));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1332
      __ subl(rdx, frame::interpreter_frame_monitor_size() * wordSize);  // address of initial monitor
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1333
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
      __ movl(t, Address(rdx, BasicObjectLock::obj_offset_in_bytes()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1335
      __ testl(t, t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1336
      __ jcc(Assembler::notZero, unlock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1337
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1338
      // Entry already unlocked, need to throw exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1339
      __ MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
      __ should_not_reach_here();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1342
      __ bind(unlock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1343
      __ unlock_object(rdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1344
      // unlock can blow rbx so restore it for path that needs it below
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1345
      __ movl(method, STATE(_method));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1346
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1347
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1348
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
  // jvmti support
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1351
  // Note: This must happen _after_ handling/throwing any exceptions since
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
  //       the exception handler code notifies the runtime of method exits
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
  //       too. If this happens before, method entry/exit notifications are
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1354
  //       not properly paired (was bug - gri 11/22/99).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
  __ notify_method_exit(vtos, InterpreterMacroAssembler::NotifyJVMTI);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1357
  // restore potential result in rdx:rax, call result handler to restore potential result in ST0 & handle result
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1358
  __ pop(ltos);                               // restore rax/rdx floating result if present still on stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
  __ movl(t, STATE(_result_handler));         // get result handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
  __ call(t);                                 // call result handler to convert to tosca form
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
  // remove activation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1363
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
  __ movl(t, STATE(_sender_sp));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
  __ leave();                                  // remove frame anchor
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1367
  __ popl(rdi);                                // get return address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
  __ movl(state, STATE(_prev_link));           // get previous state for return (if c++ interpreter was caller)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1369
  __ movl(rsp, t);                             // set sp to sender sp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
  __ jmp(rdi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1371
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1372
  // invocation counter overflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1373
  if (inc_counter) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1374
    // Handle overflow of counter and compile method
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1375
    __ bind(invocation_counter_overflow);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1376
    generate_counter_overflow(&continue_after_compile);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1377
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1378
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1379
  return entry_point;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1380
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
// Generate entries that will put a result type index into rcx
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1383
void CppInterpreterGenerator::generate_deopt_handling() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1385
  const Register state = rsi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1386
  Label return_from_deopt_common;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1387
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
  // Generate entries that will put a result type index into rcx
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1389
  // deopt needs to jump to here to enter the interpreter (return a result)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
  deopt_frame_manager_return_atos  = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1392
  // rax is live here
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1393
  __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_OBJECT));    // Result stub address array index
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
  __ jmp(return_from_deopt_common);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1396
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1397
  // deopt needs to jump to here to enter the interpreter (return a result)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
  deopt_frame_manager_return_btos  = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
  // rax is live here
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
  __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_BOOLEAN));    // Result stub address array index
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
  __ jmp(return_from_deopt_common);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1403
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1404
  // deopt needs to jump to here to enter the interpreter (return a result)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1405
  deopt_frame_manager_return_itos  = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1406
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1407
  // rax is live here
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1408
  __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_INT));    // Result stub address array index
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1409
  __ jmp(return_from_deopt_common);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1410
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1411
  // deopt needs to jump to here to enter the interpreter (return a result)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1412
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
  deopt_frame_manager_return_ltos  = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
  // rax,rdx are live here
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
  __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_LONG));    // Result stub address array index
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1416
  __ jmp(return_from_deopt_common);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1417
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
  // deopt needs to jump to here to enter the interpreter (return a result)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1419
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1420
  deopt_frame_manager_return_ftos  = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
  // st(0) is live here
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1422
  __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_FLOAT));    // Result stub address array index
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1423
  __ jmp(return_from_deopt_common);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1424
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1425
  // deopt needs to jump to here to enter the interpreter (return a result)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1426
  deopt_frame_manager_return_dtos  = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1427
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1428
  // st(0) is live here
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1429
  __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_DOUBLE));    // Result stub address array index
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
  __ jmp(return_from_deopt_common);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1431
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1432
  // deopt needs to jump to here to enter the interpreter (return a result)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1433
  deopt_frame_manager_return_vtos  = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1434
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1435
  __ movl(rcx, AbstractInterpreter::BasicType_as_index(T_VOID));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1436
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1437
  // Deopt return common
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1438
  // an index is present in rcx that lets us move any possible result being
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1439
  // return to the interpreter's stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
  // Because we have a full sized interpreter frame on the youngest
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
  // activation the stack is pushed too deep to share the tosca to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
  // stack converters directly. We shrink the stack to the desired
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1444
  // amount and then push result and then re-extend the stack.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1445
  // We could have the code in size_activation layout a short
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1446
  // frame for the top activation but that would look different
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1447
  // than say sparc (which needs a full size activation because
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1448
  // the windows are in the way. Really it could be short? QQQ
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1449
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1450
  __ bind(return_from_deopt_common);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1451
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1452
  __ leal(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1453
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1454
  // setup rsp so we can push the "result" as needed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1455
  __ movl(rsp, STATE(_stack));                                     // trim stack (is prepushed)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1456
  __ addl(rsp, wordSize);                                          // undo prepush
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1457
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1458
  ExternalAddress tosca_to_stack((address)CppInterpreter::_tosca_to_stack);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1459
  // Address index(noreg, rcx, Address::times_4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1460
  __ movptr(rcx, ArrayAddress(tosca_to_stack, Address(noreg, rcx, Address::times_4)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1461
  // __ movl(rcx, Address(noreg, rcx, Address::times_4, int(AbstractInterpreter::_tosca_to_stack)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1462
  __ call(rcx);                                                   // call result converter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1463
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1464
  __ movl(STATE(_msg), (int)BytecodeInterpreter::deopt_resume);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1465
  __ leal(rsp, Address(rsp, -wordSize));                           // prepush stack (result if any already present)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1466
  __ movl(STATE(_stack), rsp);                                     // inform interpreter of new stack depth (parameters removed,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1467
                                                                   // result if any on stack already )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1468
  __ movl(rsp, STATE(_stack_limit));                               // restore expression stack to full depth
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1469
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1470
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1471
// Generate the code to handle a more_monitors message from the c++ interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1472
void CppInterpreterGenerator::generate_more_monitors() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1473
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1474
  const Register state = rsi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1475
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1476
  Label entry, loop;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1477
  const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1478
  // 1. compute new pointers                   // rsp: old expression stack top
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1479
  __ movl(rdx, STATE(_stack_base));            // rdx: old expression stack bottom
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1480
  __ subl(rsp, entry_size);                    // move expression stack top limit
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1481
  __ subl(STATE(_stack), entry_size);          // update interpreter stack top
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1482
  __ movl(STATE(_stack_limit), rsp);           // inform interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1483
  __ subl(rdx, entry_size);                    // move expression stack bottom
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1484
  __ movl(STATE(_stack_base), rdx);            // inform interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1485
  __ movl(rcx, STATE(_stack));                 // set start value for copy loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1486
  __ jmp(entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1487
  // 2. move expression stack contents
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1488
  __ bind(loop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1489
  __ movl(rbx, Address(rcx, entry_size));      // load expression stack word from old location
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1490
  __ movl(Address(rcx, 0), rbx);               // and store it at new location
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1491
  __ addl(rcx, wordSize);                      // advance to next word
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1492
  __ bind(entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1493
  __ cmpl(rcx, rdx);                           // check if bottom reached
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1494
  __ jcc(Assembler::notEqual, loop);           // if not at bottom then copy next word
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1495
  // now zero the slot so we can find it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1496
  __ movl(Address(rdx, BasicObjectLock::obj_offset_in_bytes()), (int) NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1497
  __ movl(STATE(_msg), (int)BytecodeInterpreter::got_monitors);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1498
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1499
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1500
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1501
// Initial entry to C++ interpreter from the call_stub.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1502
// This entry point is called the frame manager since it handles the generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1503
// of interpreter activation frames via requests directly from the vm (via call_stub)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1504
// and via requests from the interpreter. The requests from the call_stub happen
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1505
// directly thru the entry point. Requests from the interpreter happen via returning
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1506
// from the interpreter and examining the message the interpreter has returned to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1507
// the frame manager. The frame manager can take the following requests:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1508
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1509
// NO_REQUEST - error, should never happen.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1510
// MORE_MONITORS - need a new monitor. Shuffle the expression stack on down and
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1511
//                 allocate a new monitor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1512
// CALL_METHOD - setup a new activation to call a new method. Very similar to what
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1513
//               happens during entry during the entry via the call stub.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1514
// RETURN_FROM_METHOD - remove an activation. Return to interpreter or call stub.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1515
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1516
// Arguments:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1517
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1518
// rbx: methodOop
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1519
// rcx: receiver - unused (retrieved from stack as needed)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1520
// rsi: previous frame manager state (NULL from the call_stub/c1/c2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1521
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1522
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1523
// Stack layout at entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1524
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1525
// [ return address     ] <--- rsp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1526
// [ parameter n        ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1527
//   ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1528
// [ parameter 1        ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1529
// [ expression stack   ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1530
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1531
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1532
// We are free to blow any registers we like because the call_stub which brought us here
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1533
// initially has preserved the callee save registers already.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1534
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1535
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1536
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1537
static address interpreter_frame_manager = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1538
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1539
address InterpreterGenerator::generate_normal_entry(bool synchronized) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1540
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1541
  // rbx: methodOop
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1542
  // rsi: sender sp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1543
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1544
  // Because we redispatch "recursive" interpreter entries thru this same entry point
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1545
  // the "input" register usage is a little strange and not what you expect coming
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1546
  // from the call_stub. From the call stub rsi/rdi (current/previous) interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1547
  // state are NULL but on "recursive" dispatches they are what you'd expect.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1548
  // rsi: current interpreter state (C++ interpreter) must preserve (null from call_stub/c1/c2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1549
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1550
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1551
  // A single frame manager is plenty as we don't specialize for synchronized. We could and
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1552
  // the code is pretty much ready. Would need to change the test below and for good measure
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1553
  // modify generate_interpreter_state to only do the (pre) sync stuff stuff for synchronized
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1554
  // routines. Not clear this is worth it yet.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1555
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1556
  if (interpreter_frame_manager) return interpreter_frame_manager;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1557
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1558
  address entry_point = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1559
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1560
  // Fast accessor methods share this entry point.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1561
  // This works because frame manager is in the same codelet
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1562
  if (UseFastAccessorMethods && !synchronized) __ bind(fast_accessor_slow_entry_path);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1563
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1564
  Label dispatch_entry_2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1565
  __ movl(rcx, rsi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
  __ movl(rsi, 0);                                                 // no current activation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1567
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1568
  __ jmp(dispatch_entry_2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1569
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1570
  const Register state   = rsi;                                    // current activation object, valid on entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1571
  const Register locals  = rdi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
  Label re_dispatch;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1574
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
  __ bind(re_dispatch);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1576
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1577
  // save sender sp (doesn't include return address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1578
  __ leal(rcx, Address(rsp, wordSize));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1579
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1580
  __ bind(dispatch_entry_2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1582
  // save sender sp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1583
  __ pushl(rcx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
  const Address size_of_parameters(rbx, methodOopDesc::size_of_parameters_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1586
  const Address size_of_locals    (rbx, methodOopDesc::size_of_locals_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1587
  const Address access_flags      (rbx, methodOopDesc::access_flags_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1589
  // const Address monitor_block_top (rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1590
  // const Address monitor_block_bot (rbp, frame::interpreter_frame_initial_sp_offset        * wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1591
  // const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset * wordSize - (int)sizeof(BasicObjectLock));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1592
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1593
  // get parameter size (always needed)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1594
  __ load_unsigned_word(rcx, size_of_parameters);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1595
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1596
  // rbx: methodOop
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1597
  // rcx: size of parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1598
  __ load_unsigned_word(rdx, size_of_locals);                      // get size of locals in words
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1599
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1600
  __ subl(rdx, rcx);                                               // rdx = no. of additional locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1601
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1602
  // see if we've got enough room on the stack for locals plus overhead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1603
  generate_stack_overflow_check();                                 // C++
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1604
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1605
  // c++ interpreter does not use stack banging or any implicit exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1606
  // leave for now to verify that check is proper.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1607
  bang_stack_shadow_pages(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1608
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1609
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1610
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1611
  // compute beginning of parameters (rdi)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1612
  __ leal(locals, Address(rsp, rcx, Address::times_4, wordSize));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1613
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1614
  // save sender's sp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1615
  // __ movl(rcx, rsp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1616
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1617
  // get sender's sp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1618
  __ popl(rcx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1619
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1620
  // get return address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1621
  __ popl(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1622
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1623
  // rdx - # of additional locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1624
  // allocate space for locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1625
  // explicitly initialize locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1626
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1627
    Label exit, loop;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1628
    __ testl(rdx, rdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1629
    __ jcc(Assembler::lessEqual, exit);               // do nothing if rdx <= 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1630
    __ bind(loop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1631
    __ pushl((int)NULL);                              // initialize local variables
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1632
    __ decrement(rdx);                                // until everything initialized
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1633
    __ jcc(Assembler::greater, loop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1634
    __ bind(exit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1635
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1636
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1637
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1638
  // Assumes rax = return address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1639
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1640
  // allocate and initialize new interpreterState and method expression stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1641
  // IN(locals) ->  locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1642
  // IN(state) -> any current interpreter activation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1643
  // destroys rax, rcx, rdx, rdi
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1644
  // OUT (state) -> new interpreterState
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1645
  // OUT(rsp) -> bottom of methods expression stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1646
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1647
  generate_compute_interpreter_state(state, locals, rcx, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1648
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1649
  // Call interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1650
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1651
  Label call_interpreter;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1652
  __ bind(call_interpreter);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1653
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1654
  // c++ interpreter does not use stack banging or any implicit exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1655
  // leave for now to verify that check is proper.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1656
  bang_stack_shadow_pages(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1657
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1658
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1659
  // Call interpreter enter here if message is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1660
  // set and we know stack size is valid
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1661
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1662
  Label call_interpreter_2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1663
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1664
  __ bind(call_interpreter_2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1665
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1666
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1667
    const Register thread  = rcx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1668
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1669
    __ pushl(state);                                                 // push arg to interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1670
    __ movl(thread, STATE(_thread));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1671
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1672
    // We can setup the frame anchor with everything we want at this point
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1673
    // as we are thread_in_Java and no safepoints can occur until we go to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1674
    // vm mode. We do have to clear flags on return from vm but that is it
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1675
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1676
    __ movl(Address(thread, JavaThread::last_Java_fp_offset()), rbp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1677
    __ movl(Address(thread, JavaThread::last_Java_sp_offset()), rsp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1678
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1679
    // Call the interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1680
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1681
    RuntimeAddress normal(CAST_FROM_FN_PTR(address, BytecodeInterpreter::run));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1682
    RuntimeAddress checking(CAST_FROM_FN_PTR(address, BytecodeInterpreter::runWithChecks));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1683
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1684
    __ call(JvmtiExport::can_post_interpreter_events() ? checking : normal);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1685
    __ popl(rax);                                                  // discard parameter to run
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1686
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1687
    // state is preserved since it is callee saved
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1688
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1689
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1690
    // reset_last_Java_frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1691
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1692
    __ movl(thread, STATE(_thread));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1693
    __ reset_last_Java_frame(thread, true, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1694
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1695
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1696
  // examine msg from interpreter to determine next action
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1697
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1698
  __ movl(rdx, STATE(_msg));                                       // Get new message
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1699
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1700
  Label call_method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1701
  Label return_from_interpreted_method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1702
  Label throw_exception;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1703
  Label bad_msg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1704
  Label do_OSR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1705
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1706
  __ cmpl(rdx, (int)BytecodeInterpreter::call_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1707
  __ jcc(Assembler::equal, call_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1708
  __ cmpl(rdx, (int)BytecodeInterpreter::return_from_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1709
  __ jcc(Assembler::equal, return_from_interpreted_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1710
  __ cmpl(rdx, (int)BytecodeInterpreter::do_osr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1711
  __ jcc(Assembler::equal, do_OSR);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1712
  __ cmpl(rdx, (int)BytecodeInterpreter::throwing_exception);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1713
  __ jcc(Assembler::equal, throw_exception);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1714
  __ cmpl(rdx, (int)BytecodeInterpreter::more_monitors);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1715
  __ jcc(Assembler::notEqual, bad_msg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1716
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1717
  // Allocate more monitor space, shuffle expression stack....
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1718
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1719
  generate_more_monitors();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1720
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1721
  __ jmp(call_interpreter);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1722
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1723
  // uncommon trap needs to jump to here to enter the interpreter (re-execute current bytecode)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1724
  unctrap_frame_manager_entry  = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1725
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1726
  // Load the registers we need.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1727
  __ leal(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1728
  __ movl(rsp, STATE(_stack_limit));                               // restore expression stack to full depth
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1729
  __ jmp(call_interpreter_2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1730
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1731
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1732
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1733
  //=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1734
  // Returning from a compiled method into a deopted method. The bytecode at the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1735
  // bcp has completed. The result of the bytecode is in the native abi (the tosca
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1736
  // for the template based interpreter). Any stack space that was used by the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1737
  // bytecode that has completed has been removed (e.g. parameters for an invoke)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1738
  // so all that we have to do is place any pending result on the expression stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1739
  // and resume execution on the next bytecode.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1740
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1741
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1742
  generate_deopt_handling();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1743
  __ jmp(call_interpreter);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1744
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1745
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1746
  // Current frame has caught an exception we need to dispatch to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1747
  // handler. We can get here because a native interpreter frame caught
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1748
  // an exception in which case there is no handler and we must rethrow
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1749
  // If it is a vanilla interpreted frame the we simply drop into the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1750
  // interpreter and let it do the lookup.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1751
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1752
  Interpreter::_rethrow_exception_entry = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1753
  // rax: exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1754
  // rdx: return address/pc that threw exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1755
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1756
  Label return_with_exception;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1757
  Label unwind_and_forward;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1758
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1759
  // restore state pointer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1760
  __ leal(state, Address(rbp,  -sizeof(BytecodeInterpreter)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1761
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1762
  __ movl(rbx, STATE(_method));                       // get method
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1763
  __ movl(rcx, STATE(_thread));                       // get thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1764
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1765
  // Store exception with interpreter will expect it
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1766
  __ movl(Address(rcx, Thread::pending_exception_offset()), rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1767
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1768
  // is current frame vanilla or native?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1769
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1770
  __ movl(rdx, access_flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1771
  __ testl(rdx, JVM_ACC_NATIVE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1772
  __ jcc(Assembler::zero, return_with_exception);     // vanilla interpreted frame, handle directly
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1773
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1774
  // We drop thru to unwind a native interpreted frame with a pending exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1775
  // We jump here for the initial interpreter frame with exception pending
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1776
  // We unwind the current acivation and forward it to our caller.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1777
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1778
  __ bind(unwind_and_forward);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1779
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1780
  // unwind rbp, return stack to unextended value and re-push return address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1781
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1782
  __ movl(rcx, STATE(_sender_sp));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1783
  __ leave();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1784
  __ popl(rdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1785
  __ movl(rsp, rcx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1786
  __ pushl(rdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1787
  __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1788
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1789
  // Return point from a call which returns a result in the native abi
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1790
  // (c1/c2/jni-native). This result must be processed onto the java
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1791
  // expression stack.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1792
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1793
  // A pending exception may be present in which case there is no result present
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1794
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1795
  Label resume_interpreter;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1796
  Label do_float;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1797
  Label do_double;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1798
  Label done_conv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1799
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1800
  address compiled_entry = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1801
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1802
  // The FPU stack is clean if UseSSE >= 2 but must be cleaned in other cases
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1803
  if (UseSSE < 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1804
    __ leal(state, Address(rbp,  -sizeof(BytecodeInterpreter)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1805
    __ movl(rbx, STATE(_result._to_call._callee));                     // get method just executed
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1806
    __ movl(rcx, Address(rbx, methodOopDesc::result_index_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1807
    __ cmpl(rcx, AbstractInterpreter::BasicType_as_index(T_FLOAT));    // Result stub address array index
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1808
    __ jcc(Assembler::equal, do_float);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1809
    __ cmpl(rcx, AbstractInterpreter::BasicType_as_index(T_DOUBLE));    // Result stub address array index
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1810
    __ jcc(Assembler::equal, do_double);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1811
#ifdef COMPILER2
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1812
    __ empty_FPU_stack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1813
#endif // COMPILER2
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1814
    __ jmp(done_conv);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1815
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1816
    __ bind(do_float);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1817
#ifdef COMPILER2
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1818
    for (int i = 1; i < 8; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1819
      __ ffree(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1820
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1821
#endif // COMPILER2
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1822
    __ jmp(done_conv);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1823
    __ bind(do_double);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1824
#ifdef COMPILER2
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1825
    for (int i = 1; i < 8; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1826
      __ ffree(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1827
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1828
#endif // COMPILER2
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1829
    __ jmp(done_conv);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1830
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1831
    __ MacroAssembler::verify_FPU(0, "generate_return_entry_for compiled");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1832
    __ jmp(done_conv);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1833
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1834
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1835
  // emit a sentinel we can test for when converting an interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1836
  // entry point to a compiled entry point.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1837
  __ a_long(Interpreter::return_sentinel);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1838
  __ a_long((int)compiled_entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1839
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1840
  // Return point to interpreter from compiled/native method
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1841
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1842
  InternalAddress return_from_native_method(__ pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1843
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1844
  __ bind(done_conv);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1845
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1846
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1847
  // Result if any is in tosca. The java expression stack is in the state that the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1848
  // calling convention left it (i.e. params may or may not be present)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1849
  // Copy the result from tosca and place it on java expression stack.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1850
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1851
  // Restore rsi as compiled code may not preserve it
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1852
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1853
  __ leal(state, Address(rbp,  -sizeof(BytecodeInterpreter)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1854
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1855
  // restore stack to what we had when we left (in case i2c extended it)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1856
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1857
  __ movl(rsp, STATE(_stack));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1858
  __ leal(rsp, Address(rsp, wordSize));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1859
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1860
  // If there is a pending exception then we don't really have a result to process
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1861
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1862
  __ movl(rcx, STATE(_thread));                       // get thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1863
  __ cmpl(Address(rcx, Thread::pending_exception_offset()), (int)NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1864
  __ jcc(Assembler::notZero, return_with_exception);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1865
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1866
  // get method just executed
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1867
  __ movl(rbx, STATE(_result._to_call._callee));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1868
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1869
  // callee left args on top of expression stack, remove them
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1870
  __ load_unsigned_word(rcx, Address(rbx, methodOopDesc::size_of_parameters_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1871
  __ leal(rsp, Address(rsp, rcx, Address::times_4));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1872
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1873
  __ movl(rcx, Address(rbx, methodOopDesc::result_index_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1874
  ExternalAddress tosca_to_stack((address)CppInterpreter::_tosca_to_stack);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1875
  // Address index(noreg, rax, Address::times_4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1876
  __ movptr(rcx, ArrayAddress(tosca_to_stack, Address(noreg, rcx, Address::times_4)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1877
  // __ movl(rcx, Address(noreg, rcx, Address::times_4, int(AbstractInterpreter::_tosca_to_stack)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1878
  __ call(rcx);                                               // call result converter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1879
  __ jmp(resume_interpreter);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1880
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1881
  // An exception is being caught on return to a vanilla interpreter frame.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1882
  // Empty the stack and resume interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1883
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1884
  __ bind(return_with_exception);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1885
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1886
  // Exception present, empty stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1887
  __ movl(rsp, STATE(_stack_base));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1888
  __ jmp(resume_interpreter);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1889
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1890
  // Return from interpreted method we return result appropriate to the caller (i.e. "recursive"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1891
  // interpreter call, or native) and unwind this interpreter activation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1892
  // All monitors should be unlocked.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1893
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1894
  __ bind(return_from_interpreted_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1895
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1896
  Label return_to_initial_caller;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1897
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1898
  __ movl(rbx, STATE(_method));                                     // get method just executed
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1899
  __ cmpl(STATE(_prev_link), (int)NULL);                            // returning from "recursive" interpreter call?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1900
  __ movl(rax, Address(rbx, methodOopDesc::result_index_offset())); // get result type index
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1901
  __ jcc(Assembler::equal, return_to_initial_caller);               // back to native code (call_stub/c1/c2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1902
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1903
  // Copy result to callers java stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1904
  ExternalAddress stack_to_stack((address)CppInterpreter::_stack_to_stack);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1905
  // Address index(noreg, rax, Address::times_4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1906
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1907
  __ movptr(rax, ArrayAddress(stack_to_stack, Address(noreg, rax, Address::times_4)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1908
  // __ movl(rax, Address(noreg, rax, Address::times_4, int(AbstractInterpreter::_stack_to_stack)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1909
  __ call(rax);                                                     // call result converter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1910
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1911
  Label unwind_recursive_activation;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1912
  __ bind(unwind_recursive_activation);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1913
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1914
  // returning to interpreter method from "recursive" interpreter call
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1915
  // result converter left rax pointing to top of the java stack for method we are returning
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1916
  // to. Now all we must do is unwind the state from the completed call
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1917
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1918
  __ movl(state, STATE(_prev_link));                                // unwind state
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1919
  __ leave();                                                       // pop the frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1920
  __ movl(rsp, rax);                                                // unwind stack to remove args
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1921
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1922
  // Resume the interpreter. The current frame contains the current interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1923
  // state object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1924
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1925
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1926
  __ bind(resume_interpreter);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1927
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1928
  // state == interpreterState object for method we are resuming
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1929
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1930
  __ movl(STATE(_msg), (int)BytecodeInterpreter::method_resume);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1931
  __ leal(rsp, Address(rsp, -wordSize));                           // prepush stack (result if any already present)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1932
  __ movl(STATE(_stack), rsp);                                     // inform interpreter of new stack depth (parameters removed,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1933
                                                                   // result if any on stack already )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1934
  __ movl(rsp, STATE(_stack_limit));                               // restore expression stack to full depth
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1935
  __ jmp(call_interpreter_2);                                      // No need to bang
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1936
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1937
  // interpreter returning to native code (call_stub/c1/c2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1938
  // convert result and unwind initial activation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1939
  // rax - result index
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1940
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1941
  __ bind(return_to_initial_caller);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1942
  ExternalAddress stack_to_native((address)CppInterpreter::_stack_to_native_abi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1943
  // Address index(noreg, rax, Address::times_4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1944
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1945
  __ movptr(rax, ArrayAddress(stack_to_native, Address(noreg, rax, Address::times_4)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1946
  __ call(rax);                                                    // call result converter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1947
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1948
  Label unwind_initial_activation;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1949
  __ bind(unwind_initial_activation);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1950
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1951
  // RETURN TO CALL_STUB/C1/C2 code (result if any in rax/rdx ST(0))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1952
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1953
  /* Current stack picture
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1954
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1955
        [ incoming parameters ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1956
        [ extra locals ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1957
        [ return address to CALL_STUB/C1/C2]
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1958
  fp -> [ CALL_STUB/C1/C2 fp ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1959
        BytecodeInterpreter object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1960
        expression stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1961
  sp ->
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1962
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1963
  */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1964
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1965
  // return restoring the stack to the original sender_sp value
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1966
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1967
  __ movl(rcx, STATE(_sender_sp));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1968
  __ leave();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1969
  __ popl(rdi);                                                     // get return address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1970
  // set stack to sender's sp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1971
  __ movl(rsp, rcx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1972
  __ jmp(rdi);                                                        // return to call_stub
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1973
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1974
  // OSR request, adjust return address to make current frame into adapter frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1975
  // and enter OSR nmethod
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1976
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1977
  __ bind(do_OSR);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1978
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1979
  Label remove_initial_frame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1980
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1981
  // We are going to pop this frame. Is there another interpreter frame underneath
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1982
  // it or is it callstub/compiled?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1983
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1984
  // Move buffer to the expected parameter location
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1985
  __ movl(rcx, STATE(_result._osr._osr_buf));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1986
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1987
  __ movl(rax, STATE(_result._osr._osr_entry));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1988
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1989
  __ cmpl(STATE(_prev_link), (int)NULL);                       // returning from "recursive" interpreter call?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1990
  __ jcc(Assembler::equal, remove_initial_frame);              // back to native code (call_stub/c1/c2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1991
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1992
  // __ movl(state, STATE(_prev_link));                           // unwind state
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1993
  __ movl(rsi, STATE(_sender_sp));                             // get sender's sp in expected register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1994
  __ leave();                                                  // pop the frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1995
  __ movl(rsp, rsi);                                           // trim any stack expansion
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1996
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1997
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1998
  // We know we are calling compiled so push specialized return
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1999
  // method uses specialized entry, push a return so we look like call stub setup
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2000
  // this path will handle fact that result is returned in registers and not
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2001
  // on the java stack.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2002
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2003
  __ pushptr(return_from_native_method.addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2004
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2005
  __ jmp(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2006
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2007
  __ bind(remove_initial_frame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2008
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2009
  __ movl(rdx, STATE(_sender_sp));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2010
  __ leave();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2011
  // get real return
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2012
  __ popl(rsi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2013
  // set stack to sender's sp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2014
  __ movl(rsp, rdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2015
  // repush real return
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2016
  __ pushl(rsi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2017
  // Enter OSR nmethod
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2018
  __ jmp(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2019
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2020
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2021
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2022
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2023
  // Call a new method. All we do is (temporarily) trim the expression stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2024
  // push a return address to bring us back to here and leap to the new entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2025
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2026
  __ bind(call_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2027
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2028
  // stack points to next free location and not top element on expression stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2029
  // method expects sp to be pointing to topmost element
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2030
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2031
  __ movl(rsp, STATE(_stack));                                       // pop args to c++ interpreter, set sp to java stack top
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2032
  __ leal(rsp, Address(rsp, wordSize));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2033
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2034
  __ movl(rbx, STATE(_result._to_call._callee));                     // get method to execute
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2035
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2036
  // don't need a return address if reinvoking interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2037
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2038
  // Make it look like call_stub calling conventions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2039
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2040
  // Get (potential) receiver
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2041
  __ load_unsigned_word(rcx, size_of_parameters);                     // get size of parameters in words
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2042
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2043
  ExternalAddress recursive(CAST_FROM_FN_PTR(address, RecursiveInterpreterActivation));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2044
  __ pushptr(recursive.addr());                                      // make it look good in the debugger
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2045
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2046
  InternalAddress entry(entry_point);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2047
  __ cmpptr(STATE(_result._to_call._callee_entry_point), entry.addr()); // returning to interpreter?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2048
  __ jcc(Assembler::equal, re_dispatch);                             // yes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2049
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2050
  __ popl(rax);                                                      // pop dummy address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2051
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2052
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2053
  // get specialized entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2054
  __ movl(rax, STATE(_result._to_call._callee_entry_point));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2055
  // set sender SP
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2056
  __ movl(rsi, rsp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2057
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2058
  // method uses specialized entry, push a return so we look like call stub setup
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2059
  // this path will handle fact that result is returned in registers and not
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2060
  // on the java stack.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2061
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2062
  __ pushptr(return_from_native_method.addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2063
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2064
  __ jmp(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2065
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2066
  __ bind(bad_msg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2067
  __ stop("Bad message from interpreter");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2068
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2069
  // Interpreted method "returned" with an exception pass it on...
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2070
  // Pass result, unwind activation and continue/return to interpreter/call_stub
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2071
  // We handle result (if any) differently based on return to interpreter or call_stub
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2072
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2073
  Label unwind_initial_with_pending_exception;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2074
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2075
  __ bind(throw_exception);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2076
  __ cmpl(STATE(_prev_link), (int)NULL);                            // returning from recursive interpreter call?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2077
  __ jcc(Assembler::equal, unwind_initial_with_pending_exception);  // no, back to native code (call_stub/c1/c2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2078
  __ movl(rax, STATE(_locals));                                     // pop parameters get new stack value
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2079
  __ addl(rax, wordSize);                                           // account for prepush before we return
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2080
  __ jmp(unwind_recursive_activation);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2081
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2082
  __ bind(unwind_initial_with_pending_exception);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2083
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2084
  // We will unwind the current (initial) interpreter frame and forward
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2085
  // the exception to the caller. We must put the exception in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2086
  // expected register and clear pending exception and then forward.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2087
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2088
  __ jmp(unwind_and_forward);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2089
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2090
  interpreter_frame_manager = entry_point;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2091
  return entry_point;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2092
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2093
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2094
address AbstractInterpreterGenerator::generate_method_entry(AbstractInterpreter::MethodKind kind) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2095
  // determine code generation flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2096
  bool synchronized = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2097
  address entry_point = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2098
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2099
  switch (kind) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2100
    case Interpreter::zerolocals             :                                                                             break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2101
    case Interpreter::zerolocals_synchronized: synchronized = true;                                                        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2102
    case Interpreter::native                 : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(false);  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2103
    case Interpreter::native_synchronized    : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(true);   break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2104
    case Interpreter::empty                  : entry_point = ((InterpreterGenerator*)this)->generate_empty_entry();        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2105
    case Interpreter::accessor               : entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry();     break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2106
    case Interpreter::abstract               : entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry();     break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2107
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2108
    case Interpreter::java_lang_math_sin     : // fall thru
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2109
    case Interpreter::java_lang_math_cos     : // fall thru
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2110
    case Interpreter::java_lang_math_tan     : // fall thru
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2111
    case Interpreter::java_lang_math_abs     : // fall thru
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2112
    case Interpreter::java_lang_math_log     : // fall thru
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2113
    case Interpreter::java_lang_math_log10   : // fall thru
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2114
    case Interpreter::java_lang_math_sqrt    : entry_point = ((InterpreterGenerator*)this)->generate_math_entry(kind);     break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2115
    default                                  : ShouldNotReachHere();                                                       break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2116
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2117
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2118
  if (entry_point) return entry_point;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2119
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2120
  return ((InterpreterGenerator*)this)->generate_normal_entry(synchronized);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2121
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2122
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2123
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2124
InterpreterGenerator::InterpreterGenerator(StubQueue* code)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2125
 : CppInterpreterGenerator(code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2126
   generate_all(); // down here so it can be "virtual"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2127
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2128
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2129
// Deoptimization helpers for C++ interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2130
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2131
// How much stack a method activation needs in words.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2132
int AbstractInterpreter::size_top_interpreter_activation(methodOop method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2133
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2134
  const int stub_code = 4;  // see generate_call_stub
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2135
  // Save space for one monitor to get into the interpreted method in case
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2136
  // the method is synchronized
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2137
  int monitor_size    = method->is_synchronized() ?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2138
                                1*frame::interpreter_frame_monitor_size() : 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2139
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2140
  // total static overhead size. Account for interpreter state object, return
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2141
  // address, saved rbp and 2 words for a "static long no_params() method" issue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2142
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2143
  const int overhead_size = sizeof(BytecodeInterpreter)/wordSize +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2144
    ( frame::sender_sp_offset - frame::link_offset) + 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2145
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2146
  const int method_stack = (method->max_locals() + method->max_stack()) *
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2147
                           Interpreter::stackElementWords();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2148
  return overhead_size + method_stack + stub_code;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2149
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2150
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2151
// returns the activation size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2152
static int size_activation_helper(int extra_locals_size, int monitor_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2153
  return (extra_locals_size +                  // the addition space for locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2154
          2*BytesPerWord +                     // return address and saved rbp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2155
          2*BytesPerWord +                     // "static long no_params() method" issue
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2156
          sizeof(BytecodeInterpreter) +               // interpreterState
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2157
          monitor_size);                       // monitors
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2158
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2159
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2160
void BytecodeInterpreter::layout_interpreterState(interpreterState to_fill,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2161
                                           frame* caller,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2162
                                           frame* current,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2163
                                           methodOop method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2164
                                           intptr_t* locals,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2165
                                           intptr_t* stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2166
                                           intptr_t* stack_base,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2167
                                           intptr_t* monitor_base,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2168
                                           intptr_t* frame_bottom,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2169
                                           bool is_top_frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2170
                                           )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2171
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2172
  // What about any vtable?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2173
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2174
  to_fill->_thread = JavaThread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2175
  // This gets filled in later but make it something recognizable for now
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2176
  to_fill->_bcp = method->code_base();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2177
  to_fill->_locals = locals;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2178
  to_fill->_constants = method->constants()->cache();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2179
  to_fill->_method = method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2180
  to_fill->_mdx = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2181
  to_fill->_stack = stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2182
  if (is_top_frame && JavaThread::current()->popframe_forcing_deopt_reexecution() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2183
    to_fill->_msg = deopt_resume2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2184
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2185
    to_fill->_msg = method_resume;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2186
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2187
  to_fill->_result._to_call._bcp_advance = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2188
  to_fill->_result._to_call._callee_entry_point = NULL; // doesn't matter to anyone
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2189
  to_fill->_result._to_call._callee = NULL; // doesn't matter to anyone
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2190
  to_fill->_prev_link = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2191
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2192
  to_fill->_sender_sp = caller->unextended_sp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2193
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2194
  if (caller->is_interpreted_frame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2195
    interpreterState prev  = caller->get_interpreterState();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2196
    to_fill->_prev_link = prev;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2197
    // *current->register_addr(GR_Iprev_state) = (intptr_t) prev;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2198
    // Make the prev callee look proper
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2199
    prev->_result._to_call._callee = method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2200
    if (*prev->_bcp == Bytecodes::_invokeinterface) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2201
      prev->_result._to_call._bcp_advance = 5;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2202
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2203
      prev->_result._to_call._bcp_advance = 3;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2204
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2205
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2206
  to_fill->_oop_temp = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2207
  to_fill->_stack_base = stack_base;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2208
  // Need +1 here because stack_base points to the word just above the first expr stack entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2209
  // and stack_limit is supposed to point to the word just below the last expr stack entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2210
  // See generate_compute_interpreter_state.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2211
  to_fill->_stack_limit = stack_base - (method->max_stack() + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2212
  to_fill->_monitor_base = (BasicObjectLock*) monitor_base;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2213
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2214
  to_fill->_self_link = to_fill;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2215
  assert(stack >= to_fill->_stack_limit && stack < to_fill->_stack_base,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2216
         "Stack top out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2217
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2218
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2219
int AbstractInterpreter::layout_activation(methodOop method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2220
                                                int tempcount,  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2221
                                                int popframe_extra_args,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2222
                                                int moncount,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2223
                                                int callee_param_count,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2224
                                                int callee_locals,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2225
                                                frame* caller,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2226
                                                frame* interpreter_frame,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2227
                                                bool is_top_frame) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2228
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2229
  assert(popframe_extra_args == 0, "FIX ME");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2230
  // NOTE this code must exactly mimic what InterpreterGenerator::generate_compute_interpreter_state()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2231
  // does as far as allocating an interpreter frame.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2232
  // If interpreter_frame!=NULL, set up the method, locals, and monitors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2233
  // The frame interpreter_frame, if not NULL, is guaranteed to be the right size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2234
  // as determined by a previous call to this method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2235
  // It is also guaranteed to be walkable even though it is in a skeletal state
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2236
  // NOTE: return size is in words not bytes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2237
  // NOTE: tempcount is the current size of the java expression stack. For top most
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2238
  //       frames we will allocate a full sized expression stack and not the curback
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2239
  //       version that non-top frames have.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2240
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2241
  // Calculate the amount our frame will be adjust by the callee. For top frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2242
  // this is zero.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2243
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2244
  // NOTE: ia64 seems to do this wrong (or at least backwards) in that it
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2245
  // calculates the extra locals based on itself. Not what the callee does
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2246
  // to it. So it ignores last_frame_adjust value. Seems suspicious as far
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2247
  // as getting sender_sp correct.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2248
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2249
  int extra_locals_size = (callee_locals - callee_param_count) * BytesPerWord;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2250
  int monitor_size = sizeof(BasicObjectLock) * moncount;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2251
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2252
  // First calculate the frame size without any java expression stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2253
  int short_frame_size = size_activation_helper(extra_locals_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2254
                                                monitor_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2255
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2256
  // Now with full size expression stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2257
  int full_frame_size = short_frame_size + method->max_stack() * BytesPerWord;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2258
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2259
  // and now with only live portion of the expression stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2260
  short_frame_size = short_frame_size + tempcount * BytesPerWord;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2261
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2262
  // the size the activation is right now. Only top frame is full size
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2263
  int frame_size = (is_top_frame ? full_frame_size : short_frame_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2264
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2265
  if (interpreter_frame != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2266
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2267
    assert(caller->unextended_sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2268
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2269
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2270
    // MUCHO HACK
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2271
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2272
    intptr_t* frame_bottom = (intptr_t*) ((intptr_t)interpreter_frame->sp() - (full_frame_size - frame_size));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2273
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2274
    /* Now fillin the interpreterState object */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2275
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2276
    // The state object is the first thing on the frame and easily located
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2277
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2278
    interpreterState cur_state = (interpreterState) ((intptr_t)interpreter_frame->fp() - sizeof(BytecodeInterpreter));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2279
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2280
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2281
    // Find the locals pointer. This is rather simple on x86 because there is no
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2282
    // confusing rounding at the callee to account for. We can trivially locate
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2283
    // our locals based on the current fp().
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2284
    // Note: the + 2 is for handling the "static long no_params() method" issue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2285
    // (too bad I don't really remember that issue well...)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2286
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2287
    intptr_t* locals;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2288
    // If the caller is interpreted we need to make sure that locals points to the first
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2289
    // argument that the caller passed and not in an area where the stack might have been extended.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2290
    // because the stack to stack to converter needs a proper locals value in order to remove the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2291
    // arguments from the caller and place the result in the proper location. Hmm maybe it'd be
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2292
    // simpler if we simply stored the result in the BytecodeInterpreter object and let the c++ code
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2293
    // adjust the stack?? HMMM QQQ
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2294
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2295
    if (caller->is_interpreted_frame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2296
      // locals must agree with the caller because it will be used to set the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2297
      // caller's tos when we return.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2298
      interpreterState prev  = caller->get_interpreterState();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2299
      // stack() is prepushed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2300
      locals = prev->stack() + method->size_of_parameters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2301
      // locals = caller->unextended_sp() + (method->size_of_parameters() - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2302
      if (locals != interpreter_frame->fp() + frame::sender_sp_offset + (method->max_locals() - 1) + 2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2303
        // os::breakpoint();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2304
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2305
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2306
      // this is where a c2i would have placed locals (except for the +2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2307
      locals = interpreter_frame->fp() + frame::sender_sp_offset + (method->max_locals() - 1) + 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2308
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2309
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2310
    intptr_t* monitor_base = (intptr_t*) cur_state;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2311
    intptr_t* stack_base = (intptr_t*) ((intptr_t) monitor_base - monitor_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2312
    /* +1 because stack is always prepushed */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2313
    intptr_t* stack = (intptr_t*) ((intptr_t) stack_base - (tempcount + 1) * BytesPerWord);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2314
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2315
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2316
    BytecodeInterpreter::layout_interpreterState(cur_state,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2317
                                          caller,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2318
                                          interpreter_frame,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2319
                                          method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2320
                                          locals,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2321
                                          stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2322
                                          stack_base,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2323
                                          monitor_base,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2324
                                          frame_bottom,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2325
                                          is_top_frame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2326
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2327
    // BytecodeInterpreter::pd_layout_interpreterState(cur_state, interpreter_return_address, interpreter_frame->fp());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2328
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2329
  return frame_size/BytesPerWord;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2330
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2331
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2332
#endif // CC_INTERP (all)