src/cpu/x86/vm/templateInterpreterGenerator_x86_32.cpp

Print this page




   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 "asm/macroAssembler.hpp"
  27 #include "interpreter/interp_masm.hpp"
  28 #include "interpreter/interpreter.hpp"

  29 #include "interpreter/templateInterpreterGenerator.hpp"
  30 #include "runtime/arguments.hpp"

  31 
  32 #define __ _masm->
  33 
  34 












  35 /**
  36  * Method entry for static native methods:
  37  *   int java.util.zip.CRC32.update(int crc, int b)
  38  */
  39 address TemplateInterpreterGenerator::generate_CRC32_update_entry() {
  40   if (UseCRC32Intrinsics) {
  41     address entry = __ pc();
  42 
  43     // rbx: Method*
  44     // rsi: senderSP must preserved for slow path, set SP to it on fast path
  45     // rdx: scratch
  46     // rdi: scratch
  47 
  48     Label slow_path;
  49     // If we need a safepoint check, generate full interpreter entry.
  50     ExternalAddress state(SafepointSynchronize::address_of_state());
  51     __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
  52              SafepointSynchronize::_not_synchronized);
  53     __ jcc(Assembler::notEqual, slow_path);
  54 


 283   if (UseSSE >= 2) {
 284     address entry = __ pc();
 285 
 286     // rsi: the sender's SP
 287 
 288     // Skip safepoint check (compiler intrinsic versions of this method
 289     // do not perform safepoint checks either).
 290 
 291     // Load the parameter (a floating-point value) into rax.
 292     __ movl(rdx, Address(rsp, 2*wordSize));
 293     __ movl(rax, Address(rsp, wordSize));
 294 
 295     // Return
 296     __ pop(rdi); // get return address
 297     __ mov(rsp, rsi); // set rsp to the sender's SP
 298     __ jmp(rdi);
 299     return entry;
 300   }
 301 
 302   return NULL;

































































































 303 }


   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 "asm/macroAssembler.hpp"
  27 #include "interpreter/interp_masm.hpp"
  28 #include "interpreter/interpreter.hpp"
  29 #include "interpreter/interpreterRuntime.hpp"
  30 #include "interpreter/templateInterpreterGenerator.hpp"
  31 #include "runtime/arguments.hpp"
  32 #include "runtime/sharedRuntime.hpp"
  33 
  34 #define __ _masm->
  35 
  36 
  37 address TemplateInterpreterGenerator::generate_slow_signature_handler() {
  38   address entry = __ pc();
  39   // rbx,: method
  40   // rcx: temporary
  41   // rdi: pointer to locals
  42   // rsp: end of copied parameters area
  43   __ mov(rcx, rsp);
  44   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::slow_signature_handler), rbx, rdi, rcx);
  45   __ ret(0);
  46   return entry;
  47 }
  48 
  49 /**
  50  * Method entry for static native methods:
  51  *   int java.util.zip.CRC32.update(int crc, int b)
  52  */
  53 address TemplateInterpreterGenerator::generate_CRC32_update_entry() {
  54   if (UseCRC32Intrinsics) {
  55     address entry = __ pc();
  56 
  57     // rbx: Method*
  58     // rsi: senderSP must preserved for slow path, set SP to it on fast path
  59     // rdx: scratch
  60     // rdi: scratch
  61 
  62     Label slow_path;
  63     // If we need a safepoint check, generate full interpreter entry.
  64     ExternalAddress state(SafepointSynchronize::address_of_state());
  65     __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
  66              SafepointSynchronize::_not_synchronized);
  67     __ jcc(Assembler::notEqual, slow_path);
  68 


 297   if (UseSSE >= 2) {
 298     address entry = __ pc();
 299 
 300     // rsi: the sender's SP
 301 
 302     // Skip safepoint check (compiler intrinsic versions of this method
 303     // do not perform safepoint checks either).
 304 
 305     // Load the parameter (a floating-point value) into rax.
 306     __ movl(rdx, Address(rsp, 2*wordSize));
 307     __ movl(rax, Address(rsp, wordSize));
 308 
 309     // Return
 310     __ pop(rdi); // get return address
 311     __ mov(rsp, rsi); // set rsp to the sender's SP
 312     __ jmp(rdi);
 313     return entry;
 314   }
 315 
 316   return NULL;
 317 }
 318 
 319 address TemplateInterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) {
 320 
 321   // rbx,: Method*
 322   // rcx: scratrch
 323   // rsi: sender sp
 324 
 325   if (!InlineIntrinsics) return NULL; // Generate a vanilla entry
 326 
 327   address entry_point = __ pc();
 328 
 329   // These don't need a safepoint check because they aren't virtually
 330   // callable. We won't enter these intrinsics from compiled code.
 331   // If in the future we added an intrinsic which was virtually callable
 332   // we'd have to worry about how to safepoint so that this code is used.
 333 
 334   // mathematical functions inlined by compiler
 335   // (interpreter must provide identical implementation
 336   // in order to avoid monotonicity bugs when switching
 337   // from interpreter to compiler in the middle of some
 338   // computation)
 339   //
 340   // stack: [ ret adr ] <-- rsp
 341   //        [ lo(arg) ]
 342   //        [ hi(arg) ]
 343   //
 344 
 345   __ fld_d(Address(rsp, 1*wordSize));
 346   switch (kind) {
 347     case Interpreter::java_lang_math_sin :
 348         __ trigfunc('s');
 349         break;
 350     case Interpreter::java_lang_math_cos :
 351         __ trigfunc('c');
 352         break;
 353     case Interpreter::java_lang_math_tan :
 354         __ trigfunc('t');
 355         break;
 356     case Interpreter::java_lang_math_sqrt:
 357         __ fsqrt();
 358         break;
 359     case Interpreter::java_lang_math_abs:
 360         __ fabs();
 361         break;
 362     case Interpreter::java_lang_math_log:
 363         __ subptr(rsp, 2 * wordSize);
 364         __ fstp_d(Address(rsp, 0));
 365         if (VM_Version::supports_sse2()) {
 366           __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::dlog())));
 367         }
 368         else {
 369           __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dlog)));
 370         }
 371         __ addptr(rsp, 2 * wordSize);
 372         break;
 373     case Interpreter::java_lang_math_log10:
 374         __ flog10();
 375         // Store to stack to convert 80bit precision back to 64bits
 376         __ push_fTOS();
 377         __ pop_fTOS();
 378         break;
 379     case Interpreter::java_lang_math_pow:
 380       __ fld_d(Address(rsp, 3*wordSize)); // second argument
 381       __ pow_with_fallback(0);
 382       // Store to stack to convert 80bit precision back to 64bits
 383       __ push_fTOS();
 384       __ pop_fTOS();
 385       break;
 386     case Interpreter::java_lang_math_exp:
 387       __ subptr(rsp, 2*wordSize);
 388       __ fstp_d(Address(rsp, 0));
 389       if (VM_Version::supports_sse2()) {
 390         __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::dexp())));
 391       } else {
 392         __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dexp)));
 393       }
 394       __ addptr(rsp, 2*wordSize);
 395     break;
 396     default                              :
 397         ShouldNotReachHere();
 398   }
 399 
 400   // return double result in xmm0 for interpreter and compilers.
 401   if (UseSSE >= 2) {
 402     __ subptr(rsp, 2*wordSize);
 403     __ fstp_d(Address(rsp, 0));
 404     __ movdbl(xmm0, Address(rsp, 0));
 405     __ addptr(rsp, 2*wordSize);
 406   }
 407 
 408   // done, result in FPU ST(0) or XMM0
 409   __ pop(rdi);                               // get return address
 410   __ mov(rsp, rsi);                          // set sp to sender sp
 411   __ jmp(rdi);
 412 
 413   return entry_point;
 414 }