hotspot/src/share/vm/interpreter/templateInterpreter.cpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 2534 08dac9ce0cd7
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2007 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
#include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include "incls/_templateInterpreter.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
#ifndef CC_INTERP
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
# define __ _masm->
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
void TemplateInterpreter::initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  if (_code != NULL) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  // assertions
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  assert((int)Bytecodes::number_of_codes <= (int)DispatchTable::length,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
         "dispatch table too small");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  AbstractInterpreter::initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  TemplateTable::initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  // generate interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  { ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    TraceTime timer("Interpreter generation", TraceStartupTime);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    int code_size = InterpreterCodeSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    NOT_PRODUCT(code_size *= 4;)  // debug uses extra interpreter code space
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    _code = new StubQueue(new InterpreterCodeletInterface, code_size, NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
                          "Interpreter");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    InterpreterGenerator g(_code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    if (PrintInterpreter) print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // initialize dispatch table
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  _active_table = _normal_table;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
// Implementation of EntryPoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
EntryPoint::EntryPoint() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  assert(number_of_states == 9, "check the code below");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  _entry[btos] = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  _entry[ctos] = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  _entry[stos] = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  _entry[atos] = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  _entry[itos] = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  _entry[ltos] = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  _entry[ftos] = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  _entry[dtos] = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  _entry[vtos] = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
EntryPoint::EntryPoint(address bentry, address centry, address sentry, address aentry, address ientry, address lentry, address fentry, address dentry, address ventry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  assert(number_of_states == 9, "check the code below");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  _entry[btos] = bentry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  _entry[ctos] = centry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  _entry[stos] = sentry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  _entry[atos] = aentry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  _entry[itos] = ientry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  _entry[ltos] = lentry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  _entry[ftos] = fentry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  _entry[dtos] = dentry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  _entry[vtos] = ventry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
void EntryPoint::set_entry(TosState state, address entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  assert(0 <= state && state < number_of_states, "state out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  _entry[state] = entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
address EntryPoint::entry(TosState state) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  assert(0 <= state && state < number_of_states, "state out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  return _entry[state];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
void EntryPoint::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  tty->print("[");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  for (int i = 0; i < number_of_states; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    if (i > 0) tty->print(", ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    tty->print(INTPTR_FORMAT, _entry[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  tty->print("]");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
bool EntryPoint::operator == (const EntryPoint& y) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  int i = number_of_states;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  while (i-- > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    if (_entry[i] != y._entry[i]) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
// Implementation of DispatchTable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
EntryPoint DispatchTable::entry(int i) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  assert(0 <= i && i < length, "index out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  return
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    EntryPoint(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      _table[btos][i],
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
      _table[ctos][i],
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      _table[stos][i],
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      _table[atos][i],
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
      _table[itos][i],
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
      _table[ltos][i],
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      _table[ftos][i],
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
      _table[dtos][i],
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      _table[vtos][i]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
void DispatchTable::set_entry(int i, EntryPoint& entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  assert(0 <= i && i < length, "index out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  assert(number_of_states == 9, "check the code below");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  _table[btos][i] = entry.entry(btos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  _table[ctos][i] = entry.entry(ctos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  _table[stos][i] = entry.entry(stos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  _table[atos][i] = entry.entry(atos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  _table[itos][i] = entry.entry(itos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  _table[ltos][i] = entry.entry(ltos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  _table[ftos][i] = entry.entry(ftos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  _table[dtos][i] = entry.entry(dtos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  _table[vtos][i] = entry.entry(vtos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
bool DispatchTable::operator == (DispatchTable& y) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  int i = length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  while (i-- > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    EntryPoint t = y.entry(i); // for compiler compatibility (BugId 4150096)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    if (!(entry(i) == t)) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
address    TemplateInterpreter::_remove_activation_entry                    = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
address    TemplateInterpreter::_remove_activation_preserving_args_entry    = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
address    TemplateInterpreter::_throw_ArrayIndexOutOfBoundsException_entry = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
address    TemplateInterpreter::_throw_ArrayStoreException_entry            = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
address    TemplateInterpreter::_throw_ArithmeticException_entry            = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
address    TemplateInterpreter::_throw_ClassCastException_entry             = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
address    TemplateInterpreter::_throw_NullPointerException_entry           = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
address    TemplateInterpreter::_throw_StackOverflowError_entry             = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
address    TemplateInterpreter::_throw_exception_entry                      = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
EntryPoint TemplateInterpreter::_trace_code;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
#endif // !PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
EntryPoint TemplateInterpreter::_return_entry[TemplateInterpreter::number_of_return_entries];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
EntryPoint TemplateInterpreter::_earlyret_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
EntryPoint TemplateInterpreter::_deopt_entry [TemplateInterpreter::number_of_deopt_entries ];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
EntryPoint TemplateInterpreter::_continuation_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
EntryPoint TemplateInterpreter::_safept_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
address    TemplateInterpreter::_return_3_addrs_by_index[TemplateInterpreter::number_of_return_addrs];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
address    TemplateInterpreter::_return_5_addrs_by_index[TemplateInterpreter::number_of_return_addrs];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
DispatchTable TemplateInterpreter::_active_table;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
DispatchTable TemplateInterpreter::_normal_table;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
DispatchTable TemplateInterpreter::_safept_table;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
address    TemplateInterpreter::_wentry_point[DispatchTable::length];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
TemplateInterpreterGenerator::TemplateInterpreterGenerator(StubQueue* _code): AbstractInterpreterGenerator(_code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  _unimplemented_bytecode    = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  _illegal_bytecode_sequence = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
static const BasicType types[Interpreter::number_of_result_handlers] = {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  T_BOOLEAN,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  T_CHAR   ,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  T_BYTE   ,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  T_SHORT  ,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  T_INT    ,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  T_LONG   ,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  T_VOID   ,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  T_FLOAT  ,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  T_DOUBLE ,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  T_OBJECT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
void TemplateInterpreterGenerator::generate_all() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  AbstractInterpreterGenerator::generate_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  { CodeletMark cm(_masm, "error exits");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    _unimplemented_bytecode    = generate_error_exit("unimplemented bytecode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    _illegal_bytecode_sequence = generate_error_exit("illegal bytecode sequence - method not verified");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  if (TraceBytecodes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    CodeletMark cm(_masm, "bytecode tracing support");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    Interpreter::_trace_code =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      EntryPoint(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
        generate_trace_code(btos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
        generate_trace_code(ctos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
        generate_trace_code(stos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
        generate_trace_code(atos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
        generate_trace_code(itos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
        generate_trace_code(ltos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
        generate_trace_code(ftos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
        generate_trace_code(dtos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
        generate_trace_code(vtos)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
      );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
#endif // !PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  { CodeletMark cm(_masm, "return entry points");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    for (int i = 0; i < Interpreter::number_of_return_entries; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
      Interpreter::_return_entry[i] =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
        EntryPoint(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
          generate_return_entry_for(itos, i),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
          generate_return_entry_for(itos, i),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
          generate_return_entry_for(itos, i),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
          generate_return_entry_for(atos, i),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
          generate_return_entry_for(itos, i),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
          generate_return_entry_for(ltos, i),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
          generate_return_entry_for(ftos, i),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
          generate_return_entry_for(dtos, i),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
          generate_return_entry_for(vtos, i)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
        );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  { CodeletMark cm(_masm, "earlyret entry points");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    Interpreter::_earlyret_entry =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
      EntryPoint(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
        generate_earlyret_entry_for(btos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
        generate_earlyret_entry_for(ctos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
        generate_earlyret_entry_for(stos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
        generate_earlyret_entry_for(atos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
        generate_earlyret_entry_for(itos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
        generate_earlyret_entry_for(ltos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
        generate_earlyret_entry_for(ftos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
        generate_earlyret_entry_for(dtos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
        generate_earlyret_entry_for(vtos)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
      );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  { CodeletMark cm(_masm, "deoptimization entry points");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    for (int i = 0; i < Interpreter::number_of_deopt_entries; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
      Interpreter::_deopt_entry[i] =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
        EntryPoint(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
          generate_deopt_entry_for(itos, i),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
          generate_deopt_entry_for(itos, i),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
          generate_deopt_entry_for(itos, i),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
          generate_deopt_entry_for(atos, i),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
          generate_deopt_entry_for(itos, i),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
          generate_deopt_entry_for(ltos, i),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
          generate_deopt_entry_for(ftos, i),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
          generate_deopt_entry_for(dtos, i),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
          generate_deopt_entry_for(vtos, i)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
        );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  { CodeletMark cm(_masm, "result handlers for native calls");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    // The various result converter stublets.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    int is_generated[Interpreter::number_of_result_handlers];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    memset(is_generated, 0, sizeof(is_generated));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    for (int i = 0; i < Interpreter::number_of_result_handlers; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
      BasicType type = types[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
      if (!is_generated[Interpreter::BasicType_as_index(type)]++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
        Interpreter::_native_abi_to_tosca[Interpreter::BasicType_as_index(type)] = generate_result_handler_for(type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  for (int j = 0; j < number_of_states; j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    const TosState states[] = {btos, ctos, stos, itos, ltos, ftos, dtos, atos, vtos};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    Interpreter::_return_3_addrs_by_index[Interpreter::TosState_as_index(states[j])] = Interpreter::return_entry(states[j], 3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    Interpreter::_return_5_addrs_by_index[Interpreter::TosState_as_index(states[j])] = Interpreter::return_entry(states[j], 5);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  { CodeletMark cm(_masm, "continuation entry points");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    Interpreter::_continuation_entry =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
      EntryPoint(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
        generate_continuation_for(btos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
        generate_continuation_for(ctos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
        generate_continuation_for(stos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
        generate_continuation_for(atos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
        generate_continuation_for(itos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
        generate_continuation_for(ltos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
        generate_continuation_for(ftos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
        generate_continuation_for(dtos),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
        generate_continuation_for(vtos)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
      );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  { CodeletMark cm(_masm, "safepoint entry points");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    Interpreter::_safept_entry =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
      EntryPoint(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
        generate_safept_entry_for(btos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
        generate_safept_entry_for(ctos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
        generate_safept_entry_for(stos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
        generate_safept_entry_for(atos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
        generate_safept_entry_for(itos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
        generate_safept_entry_for(ltos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
        generate_safept_entry_for(ftos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
        generate_safept_entry_for(dtos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
        generate_safept_entry_for(vtos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
      );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  { CodeletMark cm(_masm, "exception handling");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    // (Note: this is not safepoint safe because thread may return to compiled code)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    generate_throw_exception();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  { CodeletMark cm(_masm, "throw exception entrypoints");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
    Interpreter::_throw_ArrayIndexOutOfBoundsException_entry = generate_ArrayIndexOutOfBounds_handler("java/lang/ArrayIndexOutOfBoundsException");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
    Interpreter::_throw_ArrayStoreException_entry            = generate_klass_exception_handler("java/lang/ArrayStoreException"                 );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    Interpreter::_throw_ArithmeticException_entry            = generate_exception_handler("java/lang/ArithmeticException"           , "/ by zero");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
    Interpreter::_throw_ClassCastException_entry             = generate_ClassCastException_handler();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    Interpreter::_throw_NullPointerException_entry           = generate_exception_handler("java/lang/NullPointerException"          , NULL       );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    Interpreter::_throw_StackOverflowError_entry             = generate_StackOverflowError_handler();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
#define method_entry(kind)                                                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  { CodeletMark cm(_masm, "method entry point (kind = " #kind ")");                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    Interpreter::_entry_table[Interpreter::kind] = generate_method_entry(Interpreter::kind);  \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  // all non-native method kinds
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  method_entry(zerolocals)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  method_entry(zerolocals_synchronized)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  method_entry(empty)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  method_entry(accessor)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  method_entry(abstract)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  method_entry(java_lang_math_sin  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  method_entry(java_lang_math_cos  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  method_entry(java_lang_math_tan  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  method_entry(java_lang_math_abs  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  method_entry(java_lang_math_sqrt )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  method_entry(java_lang_math_log  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  method_entry(java_lang_math_log10)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  // all native method kinds (must be one contiguous block)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  Interpreter::_native_entry_begin = Interpreter::code()->code_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  method_entry(native)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  method_entry(native_synchronized)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  Interpreter::_native_entry_end = Interpreter::code()->code_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
#undef method_entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  // Bytecodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  set_entry_points_for_all_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  set_safepoints_for_all_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
address TemplateInterpreterGenerator::generate_error_exit(const char* msg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  address entry = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  __ stop(msg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
void TemplateInterpreterGenerator::set_entry_points_for_all_bytes() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  for (int i = 0; i < DispatchTable::length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
    Bytecodes::Code code = (Bytecodes::Code)i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    if (Bytecodes::is_defined(code)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
      set_entry_points(code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
      set_unimplemented(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
void TemplateInterpreterGenerator::set_safepoints_for_all_bytes() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  for (int i = 0; i < DispatchTable::length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
    Bytecodes::Code code = (Bytecodes::Code)i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
    if (Bytecodes::is_defined(code)) Interpreter::_safept_table.set_entry(code, Interpreter::_safept_entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
void TemplateInterpreterGenerator::set_unimplemented(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  address e = _unimplemented_bytecode;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  EntryPoint entry(e, e, e, e, e, e, e, e, e);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  Interpreter::_normal_table.set_entry(i, entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  Interpreter::_wentry_point[i] = _unimplemented_bytecode;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
void TemplateInterpreterGenerator::set_entry_points(Bytecodes::Code code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  CodeletMark cm(_masm, Bytecodes::name(code), code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  // initialize entry points
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  assert(_unimplemented_bytecode    != NULL, "should have been generated before");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  assert(_illegal_bytecode_sequence != NULL, "should have been generated before");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  address bep = _illegal_bytecode_sequence;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  address cep = _illegal_bytecode_sequence;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  address sep = _illegal_bytecode_sequence;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
  address aep = _illegal_bytecode_sequence;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  address iep = _illegal_bytecode_sequence;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  address lep = _illegal_bytecode_sequence;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  address fep = _illegal_bytecode_sequence;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  address dep = _illegal_bytecode_sequence;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  address vep = _unimplemented_bytecode;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  address wep = _unimplemented_bytecode;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  // code for short & wide version of bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  if (Bytecodes::is_defined(code)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
    Template* t = TemplateTable::template_for(code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
    assert(t->is_valid(), "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
    set_short_entry_points(t, bep, cep, sep, aep, iep, lep, fep, dep, vep);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  if (Bytecodes::wide_is_defined(code)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
    Template* t = TemplateTable::template_for_wide(code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    assert(t->is_valid(), "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
    set_wide_entry_point(t, wep);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  // set entry points
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  EntryPoint entry(bep, cep, sep, aep, iep, lep, fep, dep, vep);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  Interpreter::_normal_table.set_entry(code, entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  Interpreter::_wentry_point[code] = wep;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
void TemplateInterpreterGenerator::set_wide_entry_point(Template* t, address& wep) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  assert(t->is_valid(), "template must exist");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  assert(t->tos_in() == vtos, "only vtos tos_in supported for wide instructions")
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  wep = __ pc(); generate_and_dispatch(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
void TemplateInterpreterGenerator::set_short_entry_points(Template* t, address& bep, address& cep, address& sep, address& aep, address& iep, address& lep, address& fep, address& dep, address& vep) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  assert(t->is_valid(), "template must exist");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  switch (t->tos_in()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    case btos: vep = __ pc(); __ pop(btos); bep = __ pc(); generate_and_dispatch(t); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
    case ctos: vep = __ pc(); __ pop(ctos); sep = __ pc(); generate_and_dispatch(t); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
    case stos: vep = __ pc(); __ pop(stos); sep = __ pc(); generate_and_dispatch(t); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
    case atos: vep = __ pc(); __ pop(atos); aep = __ pc(); generate_and_dispatch(t); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
    case itos: vep = __ pc(); __ pop(itos); iep = __ pc(); generate_and_dispatch(t); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    case ltos: vep = __ pc(); __ pop(ltos); lep = __ pc(); generate_and_dispatch(t); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
    case ftos: vep = __ pc(); __ pop(ftos); fep = __ pc(); generate_and_dispatch(t); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    case dtos: vep = __ pc(); __ pop(dtos); dep = __ pc(); generate_and_dispatch(t); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
    case vtos: set_vtos_entry_points(t, bep, cep, sep, aep, iep, lep, fep, dep, vep);     break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
    default  : ShouldNotReachHere();                                                 break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
void TemplateInterpreterGenerator::generate_and_dispatch(Template* t, TosState tos_out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  if (PrintBytecodeHistogram)                                    histogram_bytecode(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  // debugging code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  if (CountBytecodes || TraceBytecodes || StopInterpreterAt > 0) count_bytecode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  if (PrintBytecodePairHistogram)                                histogram_bytecode_pair(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  if (TraceBytecodes)                                            trace_bytecode(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  if (StopInterpreterAt > 0)                                     stop_interpreter_at();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  __ verify_FPU(1, t->tos_in());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
#endif // !PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  int step;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  if (!t->does_dispatch()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
    step = t->is_wide() ? Bytecodes::wide_length_for(t->bytecode()) : Bytecodes::length_for(t->bytecode());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
    if (tos_out == ilgl) tos_out = t->tos_out();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
    // compute bytecode size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
    assert(step > 0, "just checkin'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
    // setup stuff for dispatching next bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
    if (ProfileInterpreter && VerifyDataPointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
        && methodDataOopDesc::bytecode_has_profile(t->bytecode())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
      __ verify_method_data_pointer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
    __ dispatch_prolog(tos_out, step);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  // generate template
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  t->generate(_masm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
  // advance
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  if (t->does_dispatch()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
    // make sure execution doesn't go beyond this point if code is broken
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
    __ should_not_reach_here();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
    // dispatch to next bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
    __ dispatch_epilog(tos_out, step);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
// Entry points
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
address TemplateInterpreter::return_entry(TosState state, int length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  guarantee(0 <= length && length < Interpreter::number_of_return_entries, "illegal length");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  return _return_entry[length].entry(state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
address TemplateInterpreter::deopt_entry(TosState state, int length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
  guarantee(0 <= length && length < Interpreter::number_of_deopt_entries, "illegal length");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  return _deopt_entry[length].entry(state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
// Suport for invokes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
int TemplateInterpreter::TosState_as_index(TosState state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
  assert( state < number_of_states , "Invalid state in TosState_as_index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
  assert(0 <= (int)state && (int)state < TemplateInterpreter::number_of_return_addrs, "index out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
  return (int)state;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
// Safepoint suppport
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
static inline void copy_table(address* from, address* to, int size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
  // Copy non-overlapping tables. The copy has to occur word wise for MT safety.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
  while (size-- > 0) *to++ = *from++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
void TemplateInterpreter::notice_safepoints() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
  if (!_notice_safepoints) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
    // switch to safepoint dispatch table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
    _notice_safepoints = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
    copy_table((address*)&_safept_table, (address*)&_active_table, sizeof(_active_table) / sizeof(address));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
// switch from the dispatch table which notices safepoints back to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
// normal dispatch table.  So that we can notice single stepping points,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
// keep the safepoint dispatch table if we are single stepping in JVMTI.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
// Note that the should_post_single_step test is exactly as fast as the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
// JvmtiExport::_enabled test and covers both cases.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
void TemplateInterpreter::ignore_safepoints() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
  if (_notice_safepoints) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
    if (!JvmtiExport::should_post_single_step()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
      // switch to normal dispatch table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
      _notice_safepoints = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
      copy_table((address*)&_normal_table, (address*)&_active_table, sizeof(_active_table) / sizeof(address));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
// If deoptimization happens, this method returns the point where to continue in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
// interpreter. For calls (invokexxxx, newxxxx) the continuation is at next
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
// bci and the top of stack is in eax/edx/FPU tos.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
// For putfield/getfield, put/getstatic, the continuation is at the same
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
// bci and the TOS is on stack.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
// Note: deopt_entry(type, 0) means reexecute bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
//       deopt_entry(type, length) means continue at next bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
address TemplateInterpreter::continuation_for(methodOop method, address bcp, int callee_parameters, bool is_top_frame, bool& use_next_mdp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  assert(method->contains(bcp), "just checkin'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
  Bytecodes::Code code   = Bytecodes::java_code_at(bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
  if (code == Bytecodes::_return) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
      // This is used for deopt during registration of finalizers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
      // during Object.<init>.  We simply need to resume execution at
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
      // the standard return vtos bytecode to pop the frame normally.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
      // reexecuting the real bytecode would cause double registration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
      // of the finalizable object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
      assert(is_top_frame, "must be on top");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
      return _normal_table.entry(Bytecodes::_return).entry(vtos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
    return AbstractInterpreter::continuation_for(method, bcp, callee_parameters, is_top_frame, use_next_mdp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
#endif // !CC_INTERP