rev 50307 : [mq]: cont

   1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "interpreter/interpreter.hpp"
  27 #include "interpreter/interpreterRuntime.hpp"
  28 #include "interpreter/interp_masm.hpp"
  29 #include "interpreter/templateInterpreter.hpp"
  30 #include "interpreter/templateInterpreterGenerator.hpp"
  31 #include "interpreter/templateTable.hpp"
  32 #include "oops/methodData.hpp"
  33 
  34 #ifndef CC_INTERP
  35 
  36 # define __ _masm->
  37 
  38 TemplateInterpreterGenerator::TemplateInterpreterGenerator(StubQueue* _code): AbstractInterpreterGenerator(_code) {
  39   _unimplemented_bytecode    = NULL;
  40   _illegal_bytecode_sequence = NULL;
  41   generate_all();
  42 }
  43 
  44 static const BasicType types[Interpreter::number_of_result_handlers] = {
  45   T_BOOLEAN,
  46   T_CHAR   ,
  47   T_BYTE   ,
  48   T_SHORT  ,
  49   T_INT    ,
  50   T_LONG   ,
  51   T_VOID   ,
  52   T_FLOAT  ,
  53   T_DOUBLE ,
  54   T_OBJECT
  55 };
  56 
  57 void TemplateInterpreterGenerator::generate_all() {
  58   { CodeletMark cm(_masm, "slow signature handler");
  59     AbstractInterpreter::_slow_signature_handler = generate_slow_signature_handler();
  60   }
  61 
  62   { CodeletMark cm(_masm, "error exits");
  63     _unimplemented_bytecode    = generate_error_exit("unimplemented bytecode");
  64     _illegal_bytecode_sequence = generate_error_exit("illegal bytecode sequence - method not verified");
  65   }
  66 
  67 #ifndef PRODUCT
  68   if (TraceBytecodes) {
  69     CodeletMark cm(_masm, "bytecode tracing support");
  70     Interpreter::_trace_code =
  71       EntryPoint(
  72                  generate_trace_code(btos),
  73                  generate_trace_code(ztos),
  74                  generate_trace_code(ctos),
  75                  generate_trace_code(stos),
  76                  generate_trace_code(atos),
  77                  generate_trace_code(itos),
  78                  generate_trace_code(ltos),
  79                  generate_trace_code(ftos),
  80                  generate_trace_code(dtos),
  81                  generate_trace_code(vtos)
  82                  );
  83   }
  84 #endif // !PRODUCT
  85 
  86   { CodeletMark cm(_masm, "return entry points");
  87     const int index_size = sizeof(u2);
  88     Interpreter::_return_entry[0] = EntryPoint();
  89     for (int i = 1; i < Interpreter::number_of_return_entries; i++) {
  90       address return_itos = generate_return_entry_for(itos, i, index_size);
  91       Interpreter::_return_entry[i] =
  92         EntryPoint(
  93                    return_itos,
  94                    return_itos,
  95                    return_itos,
  96                    return_itos,
  97                    generate_return_entry_for(atos, i, index_size),
  98                    return_itos,
  99                    generate_return_entry_for(ltos, i, index_size),
 100                    generate_return_entry_for(ftos, i, index_size),
 101                    generate_return_entry_for(dtos, i, index_size),
 102                    generate_return_entry_for(vtos, i, index_size)
 103                    );
 104     }

















 105   }
 106 
 107   { CodeletMark cm(_masm, "invoke return entry points");
 108     // These states are in order specified in TosState, except btos/ztos/ctos/stos are
 109     // really the same as itos since there is no top of stack optimization for these types
 110     const TosState states[] = {itos, itos, itos, itos, itos, ltos, ftos, dtos, atos, vtos, ilgl};
 111     const int invoke_length = Bytecodes::length_for(Bytecodes::_invokestatic);
 112     const int invokeinterface_length = Bytecodes::length_for(Bytecodes::_invokeinterface);
 113     const int invokedynamic_length = Bytecodes::length_for(Bytecodes::_invokedynamic);
 114 
 115     for (int i = 0; i < Interpreter::number_of_return_addrs; i++) {
 116       TosState state = states[i];
 117       assert(state != ilgl, "states array is wrong above");
 118       Interpreter::_invoke_return_entry[i] = generate_return_entry_for(state, invoke_length, sizeof(u2));

 119       Interpreter::_invokeinterface_return_entry[i] = generate_return_entry_for(state, invokeinterface_length, sizeof(u2));
 120       Interpreter::_invokedynamic_return_entry[i] = generate_return_entry_for(state, invokedynamic_length, sizeof(u4));
 121     }
 122   }
 123 
 124   { CodeletMark cm(_masm, "earlyret entry points");
 125     Interpreter::_earlyret_entry =
 126       EntryPoint(
 127                  generate_earlyret_entry_for(btos),
 128                  generate_earlyret_entry_for(ztos),
 129                  generate_earlyret_entry_for(ctos),
 130                  generate_earlyret_entry_for(stos),
 131                  generate_earlyret_entry_for(atos),
 132                  generate_earlyret_entry_for(itos),
 133                  generate_earlyret_entry_for(ltos),
 134                  generate_earlyret_entry_for(ftos),
 135                  generate_earlyret_entry_for(dtos),
 136                  generate_earlyret_entry_for(vtos)
 137                  );
 138   }
 139 
 140   { CodeletMark cm(_masm, "result handlers for native calls");
 141     // The various result converter stublets.
 142     int is_generated[Interpreter::number_of_result_handlers];
 143     memset(is_generated, 0, sizeof(is_generated));
 144 
 145     for (int i = 0; i < Interpreter::number_of_result_handlers; i++) {
 146       BasicType type = types[i];
 147       if (!is_generated[Interpreter::BasicType_as_index(type)]++) {
 148         Interpreter::_native_abi_to_tosca[Interpreter::BasicType_as_index(type)] = generate_result_handler_for(type);
 149       }
 150     }
 151   }
 152 
 153 
 154   { CodeletMark cm(_masm, "safepoint entry points");
 155     Interpreter::_safept_entry =
 156       EntryPoint(
 157                  generate_safept_entry_for(btos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)),
 158                  generate_safept_entry_for(ztos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)),
 159                  generate_safept_entry_for(ctos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)),
 160                  generate_safept_entry_for(stos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)),
 161                  generate_safept_entry_for(atos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)),
 162                  generate_safept_entry_for(itos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)),
 163                  generate_safept_entry_for(ltos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)),
 164                  generate_safept_entry_for(ftos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)),
 165                  generate_safept_entry_for(dtos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)),
 166                  generate_safept_entry_for(vtos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint))
 167                  );
 168   }
 169 
 170   { CodeletMark cm(_masm, "exception handling");
 171     // (Note: this is not safepoint safe because thread may return to compiled code)
 172     generate_throw_exception();
 173   }
 174 
 175   { CodeletMark cm(_masm, "throw exception entrypoints");
 176     Interpreter::_throw_ArrayIndexOutOfBoundsException_entry = generate_ArrayIndexOutOfBounds_handler();
 177     Interpreter::_throw_ArrayStoreException_entry            = generate_klass_exception_handler("java/lang/ArrayStoreException");
 178     Interpreter::_throw_ArithmeticException_entry            = generate_exception_handler("java/lang/ArithmeticException", "/ by zero");
 179     Interpreter::_throw_ClassCastException_entry             = generate_ClassCastException_handler();
 180     Interpreter::_throw_NullPointerException_entry           = generate_exception_handler("java/lang/NullPointerException", NULL);
 181     Interpreter::_throw_StackOverflowError_entry             = generate_StackOverflowError_handler();
 182   }
 183 
 184 
 185 
 186 #define method_entry(kind)                                              \
 187   { CodeletMark cm(_masm, "method entry point (kind = " #kind ")"); \
 188     Interpreter::_entry_table[Interpreter::kind] = generate_method_entry(Interpreter::kind); \
 189     Interpreter::update_cds_entry_table(Interpreter::kind); \
 190   }
 191 
 192   // all non-native method kinds
 193   method_entry(zerolocals)
 194   method_entry(zerolocals_synchronized)
 195   method_entry(empty)
 196   method_entry(accessor)
 197   method_entry(abstract)
 198   method_entry(java_lang_math_sin  )
 199   method_entry(java_lang_math_cos  )
 200   method_entry(java_lang_math_tan  )
 201   method_entry(java_lang_math_abs  )
 202   method_entry(java_lang_math_sqrt )
 203   method_entry(java_lang_math_log  )
 204   method_entry(java_lang_math_log10)
 205   method_entry(java_lang_math_exp  )
 206   method_entry(java_lang_math_pow  )
 207   method_entry(java_lang_math_fmaF )
 208   method_entry(java_lang_math_fmaD )
 209   method_entry(java_lang_ref_reference_get)
 210 
 211   AbstractInterpreter::initialize_method_handle_entries();
 212 
 213   // all native method kinds (must be one contiguous block)
 214   Interpreter::_native_entry_begin = Interpreter::code()->code_end();
 215   method_entry(native)
 216   method_entry(native_synchronized)
 217   Interpreter::_native_entry_end = Interpreter::code()->code_end();
 218 
 219   method_entry(java_util_zip_CRC32_update)
 220   method_entry(java_util_zip_CRC32_updateBytes)
 221   method_entry(java_util_zip_CRC32_updateByteBuffer)
 222   method_entry(java_util_zip_CRC32C_updateBytes)
 223   method_entry(java_util_zip_CRC32C_updateDirectByteBuffer)
 224 
 225   method_entry(java_lang_Float_intBitsToFloat);
 226   method_entry(java_lang_Float_floatToRawIntBits);
 227   method_entry(java_lang_Double_longBitsToDouble);
 228   method_entry(java_lang_Double_doubleToRawLongBits);
 229 







 230 #undef method_entry
 231 
 232   // Bytecodes
 233   set_entry_points_for_all_bytes();
 234 
 235   // installation of code in other places in the runtime
 236   // (ExcutableCodeManager calls not needed to copy the entries)
 237   set_safepoints_for_all_bytes();
 238 
 239   { CodeletMark cm(_masm, "deoptimization entry points");
 240     Interpreter::_deopt_entry[0] = EntryPoint();
 241     Interpreter::_deopt_entry[0].set_entry(vtos, generate_deopt_entry_for(vtos, 0));
 242     for (int i = 1; i < Interpreter::number_of_deopt_entries; i++) {
 243       address deopt_itos = generate_deopt_entry_for(itos, i);
 244       Interpreter::_deopt_entry[i] =
 245         EntryPoint(
 246                    deopt_itos, /* btos */
 247                    deopt_itos, /* ztos */
 248                    deopt_itos, /* ctos */
 249                    deopt_itos, /* stos */
 250                    generate_deopt_entry_for(atos, i),
 251                    deopt_itos, /* itos */
 252                    generate_deopt_entry_for(ltos, i),
 253                    generate_deopt_entry_for(ftos, i),
 254                    generate_deopt_entry_for(dtos, i),
 255                    generate_deopt_entry_for(vtos, i)
 256                    );
 257     }
 258     address return_continuation = Interpreter::_normal_table.entry(Bytecodes::_return).entry(vtos);
 259     vmassert(return_continuation != NULL, "return entry not generated yet");
 260     Interpreter::_deopt_reexecute_return_entry = generate_deopt_entry_for(vtos, 0, return_continuation);
 261   }
 262 
 263 }
 264 
 265 //------------------------------------------------------------------------------------------------------------------------
 266 
 267 address TemplateInterpreterGenerator::generate_error_exit(const char* msg) {
 268   address entry = __ pc();
 269   __ stop(msg);
 270   return entry;
 271 }
 272 
 273 
 274 //------------------------------------------------------------------------------------------------------------------------
 275 
 276 void TemplateInterpreterGenerator::set_entry_points_for_all_bytes() {
 277   for (int i = 0; i < DispatchTable::length; i++) {
 278     Bytecodes::Code code = (Bytecodes::Code)i;
 279     if (Bytecodes::is_defined(code)) {
 280       set_entry_points(code);
 281     } else {
 282       set_unimplemented(i);
 283     }
 284   }
 285 }
 286 
 287 
 288 void TemplateInterpreterGenerator::set_safepoints_for_all_bytes() {
 289   for (int i = 0; i < DispatchTable::length; i++) {
 290     Bytecodes::Code code = (Bytecodes::Code)i;
 291     if (Bytecodes::is_defined(code)) Interpreter::_safept_table.set_entry(code, Interpreter::_safept_entry);
 292   }
 293 }
 294 
 295 
 296 void TemplateInterpreterGenerator::set_unimplemented(int i) {
 297   address e = _unimplemented_bytecode;
 298   EntryPoint entry(e, e, e, e, e, e, e, e, e, e);
 299   Interpreter::_normal_table.set_entry(i, entry);
 300   Interpreter::_wentry_point[i] = _unimplemented_bytecode;
 301 }
 302 
 303 
 304 void TemplateInterpreterGenerator::set_entry_points(Bytecodes::Code code) {
 305   CodeletMark cm(_masm, Bytecodes::name(code), code);
 306   // initialize entry points
 307   assert(_unimplemented_bytecode    != NULL, "should have been generated before");
 308   assert(_illegal_bytecode_sequence != NULL, "should have been generated before");
 309   address bep = _illegal_bytecode_sequence;
 310   address zep = _illegal_bytecode_sequence;
 311   address cep = _illegal_bytecode_sequence;
 312   address sep = _illegal_bytecode_sequence;
 313   address aep = _illegal_bytecode_sequence;
 314   address iep = _illegal_bytecode_sequence;
 315   address lep = _illegal_bytecode_sequence;
 316   address fep = _illegal_bytecode_sequence;
 317   address dep = _illegal_bytecode_sequence;
 318   address vep = _unimplemented_bytecode;
 319   address wep = _unimplemented_bytecode;
 320   // code for short & wide version of bytecode
 321   if (Bytecodes::is_defined(code)) {
 322     Template* t = TemplateTable::template_for(code);
 323     assert(t->is_valid(), "just checking");
 324     set_short_entry_points(t, bep, cep, sep, aep, iep, lep, fep, dep, vep);
 325   }
 326   if (Bytecodes::wide_is_defined(code)) {
 327     Template* t = TemplateTable::template_for_wide(code);
 328     assert(t->is_valid(), "just checking");
 329     set_wide_entry_point(t, wep);
 330   }
 331   // set entry points
 332   EntryPoint entry(bep, zep, cep, sep, aep, iep, lep, fep, dep, vep);
 333   Interpreter::_normal_table.set_entry(code, entry);
 334   Interpreter::_wentry_point[code] = wep;
 335 }
 336 
 337 
 338 void TemplateInterpreterGenerator::set_wide_entry_point(Template* t, address& wep) {
 339   assert(t->is_valid(), "template must exist");
 340   assert(t->tos_in() == vtos, "only vtos tos_in supported for wide instructions");
 341   wep = __ pc(); generate_and_dispatch(t);
 342 }
 343 
 344 
 345 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) {
 346   assert(t->is_valid(), "template must exist");
 347   switch (t->tos_in()) {
 348     case btos:
 349     case ztos:
 350     case ctos:
 351     case stos:
 352       ShouldNotReachHere();  // btos/ctos/stos should use itos.
 353       break;
 354     case atos: vep = __ pc(); __ pop(atos); aep = __ pc(); generate_and_dispatch(t); break;
 355     case itos: vep = __ pc(); __ pop(itos); iep = __ pc(); generate_and_dispatch(t); break;
 356     case ltos: vep = __ pc(); __ pop(ltos); lep = __ pc(); generate_and_dispatch(t); break;
 357     case ftos: vep = __ pc(); __ pop(ftos); fep = __ pc(); generate_and_dispatch(t); break;
 358     case dtos: vep = __ pc(); __ pop(dtos); dep = __ pc(); generate_and_dispatch(t); break;
 359     case vtos: set_vtos_entry_points(t, bep, cep, sep, aep, iep, lep, fep, dep, vep);     break;
 360     default  : ShouldNotReachHere();                                                 break;
 361   }
 362 }
 363 
 364 
 365 //------------------------------------------------------------------------------------------------------------------------
 366 
 367 void TemplateInterpreterGenerator::generate_and_dispatch(Template* t, TosState tos_out) {
 368   if (PrintBytecodeHistogram)                                    histogram_bytecode(t);
 369 #ifndef PRODUCT
 370   // debugging code
 371   if (CountBytecodes || TraceBytecodes || StopInterpreterAt > 0) count_bytecode();
 372   if (PrintBytecodePairHistogram)                                histogram_bytecode_pair(t);
 373   if (TraceBytecodes)                                            trace_bytecode(t);
 374   if (StopInterpreterAt > 0)                                     stop_interpreter_at();
 375   __ verify_FPU(1, t->tos_in());
 376 #endif // !PRODUCT
 377   int step = 0;
 378   if (!t->does_dispatch()) {
 379     step = t->is_wide() ? Bytecodes::wide_length_for(t->bytecode()) : Bytecodes::length_for(t->bytecode());
 380     if (tos_out == ilgl) tos_out = t->tos_out();
 381     // compute bytecode size
 382     assert(step > 0, "just checkin'");
 383     // setup stuff for dispatching next bytecode
 384     if (ProfileInterpreter && VerifyDataPointer
 385         && MethodData::bytecode_has_profile(t->bytecode())) {
 386       __ verify_method_data_pointer();
 387     }
 388     __ dispatch_prolog(tos_out, step);
 389   }
 390   // generate template
 391   t->generate(_masm);
 392   // advance
 393   if (t->does_dispatch()) {
 394 #ifdef ASSERT
 395     // make sure execution doesn't go beyond this point if code is broken
 396     __ should_not_reach_here();
 397 #endif // ASSERT
 398   } else {
 399     // dispatch to next bytecode
 400     __ dispatch_epilog(tos_out, step);
 401   }
 402 }
 403 
 404 // Generate method entries
 405 address TemplateInterpreterGenerator::generate_method_entry(
 406                                         AbstractInterpreter::MethodKind kind) {
 407   // determine code generation flags
 408   bool native = false;
 409   bool synchronized = false;
 410   address entry_point = NULL;
 411 
 412   switch (kind) {
 413   case Interpreter::zerolocals             :                                          break;
 414   case Interpreter::zerolocals_synchronized:                synchronized = true;      break;
 415   case Interpreter::native                 : native = true;                           break;
 416   case Interpreter::native_synchronized    : native = true; synchronized = true;      break;
 417   case Interpreter::empty                  : break;
 418   case Interpreter::accessor               : break;
 419   case Interpreter::abstract               : entry_point = generate_abstract_entry(); break;
 420 
 421   case Interpreter::java_lang_math_sin     : // fall thru
 422   case Interpreter::java_lang_math_cos     : // fall thru
 423   case Interpreter::java_lang_math_tan     : // fall thru
 424   case Interpreter::java_lang_math_abs     : // fall thru
 425   case Interpreter::java_lang_math_log     : // fall thru
 426   case Interpreter::java_lang_math_log10   : // fall thru
 427   case Interpreter::java_lang_math_sqrt    : // fall thru
 428   case Interpreter::java_lang_math_pow     : // fall thru
 429   case Interpreter::java_lang_math_exp     : // fall thru
 430   case Interpreter::java_lang_math_fmaD    : // fall thru
 431   case Interpreter::java_lang_math_fmaF    : entry_point = generate_math_entry(kind);      break;
 432   case Interpreter::java_lang_ref_reference_get
 433                                            : entry_point = generate_Reference_get_entry(); break;












 434   case Interpreter::java_util_zip_CRC32_update
 435                                            : native = true; entry_point = generate_CRC32_update_entry();  break;
 436   case Interpreter::java_util_zip_CRC32_updateBytes
 437                                            : // fall thru
 438   case Interpreter::java_util_zip_CRC32_updateByteBuffer
 439                                            : native = true; entry_point = generate_CRC32_updateBytes_entry(kind); break;
 440   case Interpreter::java_util_zip_CRC32C_updateBytes
 441                                            : // fall thru
 442   case Interpreter::java_util_zip_CRC32C_updateDirectByteBuffer
 443                                            : entry_point = generate_CRC32C_updateBytes_entry(kind); break;
 444 #ifdef IA32
 445   // On x86_32 platforms, a special entry is generated for the following four methods.
 446   // On other platforms the normal entry is used to enter these methods.
 447   case Interpreter::java_lang_Float_intBitsToFloat
 448                                            : native = true; entry_point = generate_Float_intBitsToFloat_entry(); break;
 449   case Interpreter::java_lang_Float_floatToRawIntBits
 450                                            : native = true; entry_point = generate_Float_floatToRawIntBits_entry(); break;
 451   case Interpreter::java_lang_Double_longBitsToDouble
 452                                            : native = true; entry_point = generate_Double_longBitsToDouble_entry(); break;
 453   case Interpreter::java_lang_Double_doubleToRawLongBits
 454                                            : native = true; entry_point = generate_Double_doubleToRawLongBits_entry(); break;
 455 #else
 456   case Interpreter::java_lang_Float_intBitsToFloat:
 457   case Interpreter::java_lang_Float_floatToRawIntBits:
 458   case Interpreter::java_lang_Double_longBitsToDouble:
 459   case Interpreter::java_lang_Double_doubleToRawLongBits:
 460     native = true;
 461     break;
 462 #endif // !IA32
 463   default:
 464     fatal("unexpected method kind: %d", kind);
 465     break;
 466   }
 467 
 468   if (entry_point) {
 469     return entry_point;
 470   }
 471 
 472   // We expect the normal and native entry points to be generated first so we can reuse them.
 473   if (native) {
 474     entry_point = Interpreter::entry_for_kind(synchronized ? Interpreter::native_synchronized : Interpreter::native);
 475     if (entry_point == NULL) {
 476       entry_point = generate_native_entry(synchronized);
 477     }
 478   } else {
 479     entry_point = Interpreter::entry_for_kind(synchronized ? Interpreter::zerolocals_synchronized : Interpreter::zerolocals);
 480     if (entry_point == NULL) {
 481       entry_point = generate_normal_entry(synchronized);
 482     }
 483   }
 484 
 485   return entry_point;
 486 }
 487 #endif // !CC_INTERP
--- EOF ---