annotate src/share/vm/interpreter/templateInterpreter.cpp @ 2700:38fa55e5e792

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