< prev index next >

src/cpu/ppc/vm/templateInterpreter_ppc.cpp

Print this page
rev 8574 : 8131048: ppc: implement CRC32 intrinsic


  40 #include "runtime/arguments.hpp"
  41 #include "runtime/deoptimization.hpp"
  42 #include "runtime/frame.inline.hpp"
  43 #include "runtime/sharedRuntime.hpp"
  44 #include "runtime/stubRoutines.hpp"
  45 #include "runtime/synchronizer.hpp"
  46 #include "runtime/timer.hpp"
  47 #include "runtime/vframeArray.hpp"
  48 #include "utilities/debug.hpp"
  49 #include "utilities/macros.hpp"
  50 
  51 #undef __
  52 #define __ _masm->
  53 
  54 #ifdef PRODUCT
  55 #define BLOCK_COMMENT(str) /* nothing */
  56 #else
  57 #define BLOCK_COMMENT(str) __ block_comment(str)
  58 #endif
  59 
  60 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":")
  61 
  62 //-----------------------------------------------------------------------------
  63 
  64 // Actually we should never reach here since we do stack overflow checks before pushing any frame.
  65 address TemplateInterpreterGenerator::generate_StackOverflowError_handler() {
  66   address entry = __ pc();
  67   __ unimplemented("generate_StackOverflowError_handler");
  68   return entry;
  69 }
  70 
  71 address TemplateInterpreterGenerator::generate_ArrayIndexOutOfBounds_handler(const char* name) {
  72   address entry = __ pc();
  73   __ empty_expression_stack();
  74   __ load_const_optimized(R4_ARG2, (address) name);
  75   // Index is in R17_tos.
  76   __ mr(R5_ARG3, R17_tos);
  77   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException));
  78   return entry;
  79 }
  80 


 766 
 767   //=============================================================================
 768   // Increment invocation counter. On overflow, entry to JNI method
 769   // will be compiled.
 770   Label invocation_counter_overflow, continue_after_compile;
 771   if (inc_counter) {
 772     if (synchronized) {
 773       // Since at this point in the method invocation the exception handler
 774       // would try to exit the monitor of synchronized methods which hasn't
 775       // been entered yet, we set the thread local variable
 776       // _do_not_unlock_if_synchronized to true. If any exception was thrown by
 777       // runtime, exception handling i.e. unlock_if_synchronized_method will
 778       // check this thread local flag.
 779       // This flag has two effects, one is to force an unwind in the topmost
 780       // interpreter frame and not perform an unlock while doing so.
 781       __ li(R0, 1);
 782       __ stb(R0, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread);
 783     }
 784     generate_counter_incr(&invocation_counter_overflow, NULL, NULL);
 785 
 786     __ BIND(continue_after_compile);
 787     // Reset the _do_not_unlock_if_synchronized flag.
 788     if (synchronized) {
 789       __ li(R0, 0);
 790       __ stb(R0, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread);
 791     }
 792   }
 793 
 794   // access_flags = method->access_flags();
 795   // Load access flags.
 796   assert(access_flags->is_nonvolatile(),
 797          "access_flags must be in a non-volatile register");
 798   // Type check.
 799   assert(4 == sizeof(AccessFlags), "unexpected field size");
 800   __ lwz(access_flags, method_(access_flags));
 801 
 802   // We don't want to reload R19_method and access_flags after calls
 803   // to some helper functions.
 804   assert(R19_method->is_nonvolatile(),
 805          "R19_method must be a non-volatile register");
 806 


 826 
 827   __ cmpdi(CCR0, signature_handler_fd, 0);
 828   __ bne(CCR0, call_signature_handler);
 829 
 830   // Method has never been called. Either generate a specialized
 831   // handler or point to the slow one.
 832   //
 833   // Pass parameter 'false' to avoid exception check in call_VM.
 834   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), R19_method, false);
 835 
 836   // Check for an exception while looking up the target method. If we
 837   // incurred one, bail.
 838   __ ld(pending_exception, thread_(pending_exception));
 839   __ cmpdi(CCR0, pending_exception, 0);
 840   __ bne(CCR0, exception_return_sync_check); // Has pending exception.
 841 
 842   // Reload signature handler, it may have been created/assigned in the meanwhile.
 843   __ ld(signature_handler_fd, method_(signature_handler));
 844   __ twi_0(signature_handler_fd); // Order wrt. load of klass mirror and entry point (isync is below).
 845 
 846   __ BIND(call_signature_handler);
 847 
 848   // Before we call the signature handler we push a new frame to
 849   // protect the interpreter frame volatile registers when we return
 850   // from jni but before we can get back to Java.
 851 
 852   // First set the frame anchor while the SP/FP registers are
 853   // convenient and the slow signature handler can use this same frame
 854   // anchor.
 855 
 856   // We have a TOP_IJAVA_FRAME here, which belongs to us.
 857   __ set_top_ijava_frame_at_SP_as_last_Java_frame(R1_SP, R12_scratch2/*tmp*/);
 858 
 859   // Now the interpreter frame (and its call chain) have been
 860   // invalidated and flushed. We are now protected against eager
 861   // being enabled in native code. Even if it goes eager the
 862   // registers will be reloaded as clean and we will invalidate after
 863   // the call so no spurious flush should be possible.
 864 
 865   // Call signature handler and pass locals address.
 866   //


 896     __ testbitdi(CCR0, R0, access_flags, JVM_ACC_STATIC_BIT);
 897     __ bfalse(CCR0, method_is_not_static);
 898 
 899     // constants = method->constants();
 900     __ ld(R11_scratch1, in_bytes(Method::const_offset()), R19_method);
 901     __ ld(R11_scratch1, in_bytes(ConstMethod::constants_offset()), R11_scratch1);
 902     // pool_holder = method->constants()->pool_holder();
 903     __ ld(R11_scratch1/*pool_holder*/, ConstantPool::pool_holder_offset_in_bytes(),
 904           R11_scratch1/*constants*/);
 905 
 906     const int mirror_offset = in_bytes(Klass::java_mirror_offset());
 907 
 908     // mirror = pool_holder->klass_part()->java_mirror();
 909     __ ld(R0/*mirror*/, mirror_offset, R11_scratch1/*pool_holder*/);
 910     // state->_native_mirror = mirror;
 911 
 912     __ ld(R11_scratch1, 0, R1_SP);
 913     __ std(R0/*mirror*/, _ijava_state_neg(oop_tmp), R11_scratch1);
 914     // R4_ARG2 = &state->_oop_temp;
 915     __ addi(R4_ARG2, R11_scratch1, _ijava_state_neg(oop_tmp));
 916     __ BIND(method_is_not_static);
 917   }
 918 
 919   // At this point, arguments have been copied off the stack into
 920   // their JNI positions. Oops are boxed in-place on the stack, with
 921   // handles copied to arguments. The result handler address is in a
 922   // register.
 923 
 924   // Pass JNIEnv address as first parameter.
 925   __ addir(R3_ARG1, thread_(jni_environment));
 926 
 927   // Load the native_method entry before we change the thread state.
 928   __ ld(native_method_fd, method_(native_function));
 929 
 930   //=============================================================================
 931   // Transition from _thread_in_Java to _thread_in_native. As soon as
 932   // we make this change the safepoint code needs to be certain that
 933   // the last Java frame we established is good. The pc in that frame
 934   // just needs to be near here not an actual return address.
 935 
 936   // We use release_store_fence to update values like the thread state, where


1109   // Move native method result back into proper registers and return.
1110   // Invoke result handler (may unbox/promote).
1111   __ ld(R11_scratch1, 0, R1_SP);
1112   __ ld(R3_RET, _ijava_state_neg(lresult), R11_scratch1);
1113   __ lfd(F1_RET, _ijava_state_neg(fresult), R11_scratch1);
1114   __ call_stub(result_handler_addr);
1115 
1116   __ merge_frames(/*top_frame_sp*/ R21_sender_SP, /*return_pc*/ R0, R11_scratch1, R12_scratch2);
1117 
1118   // Must use the return pc which was loaded from the caller's frame
1119   // as the VM uses return-pc-patching for deoptimization.
1120   __ mtlr(R0);
1121   __ blr();
1122 
1123   //-----------------------------------------------------------------------------
1124   // An exception is pending. We call into the runtime only if the
1125   // caller was not interpreted. If it was interpreted the
1126   // interpreter will do the correct thing. If it isn't interpreted
1127   // (call stub/compiled code) we will change our return and continue.
1128 
1129   __ BIND(exception_return_sync_check);
1130 
1131   if (synchronized) {
1132     // Don't check for exceptions since we're still in the i2n frame. Do that
1133     // manually afterwards.
1134     unlock_method(false);
1135   }
1136   __ BIND(exception_return_sync_check_already_unlocked);
1137 
1138   const Register return_pc = R31;
1139 
1140   __ ld(return_pc, 0, R1_SP);
1141   __ ld(return_pc, _abi(lr), return_pc);
1142 
1143   // Get the address of the exception handler.
1144   __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address),
1145                   R16_thread,
1146                   return_pc /* return pc */);
1147   __ merge_frames(/*top_frame_sp*/ R21_sender_SP, noreg, R11_scratch1, R12_scratch2);
1148 
1149   // Load the PC of the the exception handler into LR.
1150   __ mtlr(R3_RET);
1151 
1152   // Load exception into R3_ARG1 and clear pending exception in thread.
1153   __ ld(R3_ARG1/*exception*/, thread_(pending_exception));
1154   __ li(R4_ARG2, 0);
1155   __ std(R4_ARG2, thread_(pending_exception));
1156 


1310   switch (kind) {
1311   case Interpreter::zerolocals             :                                                                             break;
1312   case Interpreter::zerolocals_synchronized: synchronized = true;                                                        break;
1313   case Interpreter::native                 : entry_point = ((InterpreterGenerator*) this)->generate_native_entry(false); break;
1314   case Interpreter::native_synchronized    : entry_point = ((InterpreterGenerator*) this)->generate_native_entry(true);  break;
1315   case Interpreter::empty                  : entry_point = ((InterpreterGenerator*) this)->generate_empty_entry();       break;
1316   case Interpreter::accessor               : entry_point = ((InterpreterGenerator*) this)->generate_accessor_entry();    break;
1317   case Interpreter::abstract               : entry_point = ((InterpreterGenerator*) this)->generate_abstract_entry();    break;
1318 
1319   case Interpreter::java_lang_math_sin     : // fall thru
1320   case Interpreter::java_lang_math_cos     : // fall thru
1321   case Interpreter::java_lang_math_tan     : // fall thru
1322   case Interpreter::java_lang_math_abs     : // fall thru
1323   case Interpreter::java_lang_math_log     : // fall thru
1324   case Interpreter::java_lang_math_log10   : // fall thru
1325   case Interpreter::java_lang_math_sqrt    : // fall thru
1326   case Interpreter::java_lang_math_pow     : // fall thru
1327   case Interpreter::java_lang_math_exp     : entry_point = ((InterpreterGenerator*) this)->generate_math_entry(kind);    break;
1328   case Interpreter::java_lang_ref_reference_get
1329                                            : entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break;



1330   default                                  : ShouldNotReachHere();                                                       break;
1331   }
1332 
1333   if (entry_point) {
1334     return entry_point;
1335   }
1336 
1337   return ((InterpreterGenerator*) this)->generate_normal_entry(synchronized);













































































































































































1338 }
1339 
1340 // These should never be compiled since the interpreter will prefer
1341 // the compiled version to the intrinsic version.
1342 bool AbstractInterpreter::can_be_compiled(methodHandle m) {
1343   return !math_entry_available(method_kind(m));
1344 }
1345 
1346 // How much stack a method activation needs in stack slots.
1347 // We must calc this exactly like in generate_fixed_frame.
1348 // Note: This returns the conservative size assuming maximum alignment.
1349 int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
1350   const int max_alignment_size = 2;
1351   const int abi_scratch = frame::abi_reg_args_size;
1352   return method->max_locals() + method->max_stack() +
1353          frame::interpreter_frame_monitor_size() + max_alignment_size + abi_scratch;
1354 }
1355 
1356 // Returns number of stackElementWords needed for the interpreter frame with the
1357 // given sections.




  40 #include "runtime/arguments.hpp"
  41 #include "runtime/deoptimization.hpp"
  42 #include "runtime/frame.inline.hpp"
  43 #include "runtime/sharedRuntime.hpp"
  44 #include "runtime/stubRoutines.hpp"
  45 #include "runtime/synchronizer.hpp"
  46 #include "runtime/timer.hpp"
  47 #include "runtime/vframeArray.hpp"
  48 #include "utilities/debug.hpp"
  49 #include "utilities/macros.hpp"
  50 
  51 #undef __
  52 #define __ _masm->
  53 
  54 #ifdef PRODUCT
  55 #define BLOCK_COMMENT(str) /* nothing */
  56 #else
  57 #define BLOCK_COMMENT(str) __ block_comment(str)
  58 #endif
  59 
  60 #define BIND(label)        __ bind(label); BLOCK_COMMENT(#label ":")
  61 
  62 //-----------------------------------------------------------------------------
  63 
  64 // Actually we should never reach here since we do stack overflow checks before pushing any frame.
  65 address TemplateInterpreterGenerator::generate_StackOverflowError_handler() {
  66   address entry = __ pc();
  67   __ unimplemented("generate_StackOverflowError_handler");
  68   return entry;
  69 }
  70 
  71 address TemplateInterpreterGenerator::generate_ArrayIndexOutOfBounds_handler(const char* name) {
  72   address entry = __ pc();
  73   __ empty_expression_stack();
  74   __ load_const_optimized(R4_ARG2, (address) name);
  75   // Index is in R17_tos.
  76   __ mr(R5_ARG3, R17_tos);
  77   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException));
  78   return entry;
  79 }
  80 


 766 
 767   //=============================================================================
 768   // Increment invocation counter. On overflow, entry to JNI method
 769   // will be compiled.
 770   Label invocation_counter_overflow, continue_after_compile;
 771   if (inc_counter) {
 772     if (synchronized) {
 773       // Since at this point in the method invocation the exception handler
 774       // would try to exit the monitor of synchronized methods which hasn't
 775       // been entered yet, we set the thread local variable
 776       // _do_not_unlock_if_synchronized to true. If any exception was thrown by
 777       // runtime, exception handling i.e. unlock_if_synchronized_method will
 778       // check this thread local flag.
 779       // This flag has two effects, one is to force an unwind in the topmost
 780       // interpreter frame and not perform an unlock while doing so.
 781       __ li(R0, 1);
 782       __ stb(R0, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread);
 783     }
 784     generate_counter_incr(&invocation_counter_overflow, NULL, NULL);
 785 
 786     BIND(continue_after_compile);
 787     // Reset the _do_not_unlock_if_synchronized flag.
 788     if (synchronized) {
 789       __ li(R0, 0);
 790       __ stb(R0, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread);
 791     }
 792   }
 793 
 794   // access_flags = method->access_flags();
 795   // Load access flags.
 796   assert(access_flags->is_nonvolatile(),
 797          "access_flags must be in a non-volatile register");
 798   // Type check.
 799   assert(4 == sizeof(AccessFlags), "unexpected field size");
 800   __ lwz(access_flags, method_(access_flags));
 801 
 802   // We don't want to reload R19_method and access_flags after calls
 803   // to some helper functions.
 804   assert(R19_method->is_nonvolatile(),
 805          "R19_method must be a non-volatile register");
 806 


 826 
 827   __ cmpdi(CCR0, signature_handler_fd, 0);
 828   __ bne(CCR0, call_signature_handler);
 829 
 830   // Method has never been called. Either generate a specialized
 831   // handler or point to the slow one.
 832   //
 833   // Pass parameter 'false' to avoid exception check in call_VM.
 834   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), R19_method, false);
 835 
 836   // Check for an exception while looking up the target method. If we
 837   // incurred one, bail.
 838   __ ld(pending_exception, thread_(pending_exception));
 839   __ cmpdi(CCR0, pending_exception, 0);
 840   __ bne(CCR0, exception_return_sync_check); // Has pending exception.
 841 
 842   // Reload signature handler, it may have been created/assigned in the meanwhile.
 843   __ ld(signature_handler_fd, method_(signature_handler));
 844   __ twi_0(signature_handler_fd); // Order wrt. load of klass mirror and entry point (isync is below).
 845 
 846   BIND(call_signature_handler);
 847 
 848   // Before we call the signature handler we push a new frame to
 849   // protect the interpreter frame volatile registers when we return
 850   // from jni but before we can get back to Java.
 851 
 852   // First set the frame anchor while the SP/FP registers are
 853   // convenient and the slow signature handler can use this same frame
 854   // anchor.
 855 
 856   // We have a TOP_IJAVA_FRAME here, which belongs to us.
 857   __ set_top_ijava_frame_at_SP_as_last_Java_frame(R1_SP, R12_scratch2/*tmp*/);
 858 
 859   // Now the interpreter frame (and its call chain) have been
 860   // invalidated and flushed. We are now protected against eager
 861   // being enabled in native code. Even if it goes eager the
 862   // registers will be reloaded as clean and we will invalidate after
 863   // the call so no spurious flush should be possible.
 864 
 865   // Call signature handler and pass locals address.
 866   //


 896     __ testbitdi(CCR0, R0, access_flags, JVM_ACC_STATIC_BIT);
 897     __ bfalse(CCR0, method_is_not_static);
 898 
 899     // constants = method->constants();
 900     __ ld(R11_scratch1, in_bytes(Method::const_offset()), R19_method);
 901     __ ld(R11_scratch1, in_bytes(ConstMethod::constants_offset()), R11_scratch1);
 902     // pool_holder = method->constants()->pool_holder();
 903     __ ld(R11_scratch1/*pool_holder*/, ConstantPool::pool_holder_offset_in_bytes(),
 904           R11_scratch1/*constants*/);
 905 
 906     const int mirror_offset = in_bytes(Klass::java_mirror_offset());
 907 
 908     // mirror = pool_holder->klass_part()->java_mirror();
 909     __ ld(R0/*mirror*/, mirror_offset, R11_scratch1/*pool_holder*/);
 910     // state->_native_mirror = mirror;
 911 
 912     __ ld(R11_scratch1, 0, R1_SP);
 913     __ std(R0/*mirror*/, _ijava_state_neg(oop_tmp), R11_scratch1);
 914     // R4_ARG2 = &state->_oop_temp;
 915     __ addi(R4_ARG2, R11_scratch1, _ijava_state_neg(oop_tmp));
 916     BIND(method_is_not_static);
 917   }
 918 
 919   // At this point, arguments have been copied off the stack into
 920   // their JNI positions. Oops are boxed in-place on the stack, with
 921   // handles copied to arguments. The result handler address is in a
 922   // register.
 923 
 924   // Pass JNIEnv address as first parameter.
 925   __ addir(R3_ARG1, thread_(jni_environment));
 926 
 927   // Load the native_method entry before we change the thread state.
 928   __ ld(native_method_fd, method_(native_function));
 929 
 930   //=============================================================================
 931   // Transition from _thread_in_Java to _thread_in_native. As soon as
 932   // we make this change the safepoint code needs to be certain that
 933   // the last Java frame we established is good. The pc in that frame
 934   // just needs to be near here not an actual return address.
 935 
 936   // We use release_store_fence to update values like the thread state, where


1109   // Move native method result back into proper registers and return.
1110   // Invoke result handler (may unbox/promote).
1111   __ ld(R11_scratch1, 0, R1_SP);
1112   __ ld(R3_RET, _ijava_state_neg(lresult), R11_scratch1);
1113   __ lfd(F1_RET, _ijava_state_neg(fresult), R11_scratch1);
1114   __ call_stub(result_handler_addr);
1115 
1116   __ merge_frames(/*top_frame_sp*/ R21_sender_SP, /*return_pc*/ R0, R11_scratch1, R12_scratch2);
1117 
1118   // Must use the return pc which was loaded from the caller's frame
1119   // as the VM uses return-pc-patching for deoptimization.
1120   __ mtlr(R0);
1121   __ blr();
1122 
1123   //-----------------------------------------------------------------------------
1124   // An exception is pending. We call into the runtime only if the
1125   // caller was not interpreted. If it was interpreted the
1126   // interpreter will do the correct thing. If it isn't interpreted
1127   // (call stub/compiled code) we will change our return and continue.
1128 
1129   BIND(exception_return_sync_check);
1130 
1131   if (synchronized) {
1132     // Don't check for exceptions since we're still in the i2n frame. Do that
1133     // manually afterwards.
1134     unlock_method(false);
1135   }
1136   BIND(exception_return_sync_check_already_unlocked);
1137 
1138   const Register return_pc = R31;
1139 
1140   __ ld(return_pc, 0, R1_SP);
1141   __ ld(return_pc, _abi(lr), return_pc);
1142 
1143   // Get the address of the exception handler.
1144   __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address),
1145                   R16_thread,
1146                   return_pc /* return pc */);
1147   __ merge_frames(/*top_frame_sp*/ R21_sender_SP, noreg, R11_scratch1, R12_scratch2);
1148 
1149   // Load the PC of the the exception handler into LR.
1150   __ mtlr(R3_RET);
1151 
1152   // Load exception into R3_ARG1 and clear pending exception in thread.
1153   __ ld(R3_ARG1/*exception*/, thread_(pending_exception));
1154   __ li(R4_ARG2, 0);
1155   __ std(R4_ARG2, thread_(pending_exception));
1156 


1310   switch (kind) {
1311   case Interpreter::zerolocals             :                                                                             break;
1312   case Interpreter::zerolocals_synchronized: synchronized = true;                                                        break;
1313   case Interpreter::native                 : entry_point = ((InterpreterGenerator*) this)->generate_native_entry(false); break;
1314   case Interpreter::native_synchronized    : entry_point = ((InterpreterGenerator*) this)->generate_native_entry(true);  break;
1315   case Interpreter::empty                  : entry_point = ((InterpreterGenerator*) this)->generate_empty_entry();       break;
1316   case Interpreter::accessor               : entry_point = ((InterpreterGenerator*) this)->generate_accessor_entry();    break;
1317   case Interpreter::abstract               : entry_point = ((InterpreterGenerator*) this)->generate_abstract_entry();    break;
1318 
1319   case Interpreter::java_lang_math_sin     : // fall thru
1320   case Interpreter::java_lang_math_cos     : // fall thru
1321   case Interpreter::java_lang_math_tan     : // fall thru
1322   case Interpreter::java_lang_math_abs     : // fall thru
1323   case Interpreter::java_lang_math_log     : // fall thru
1324   case Interpreter::java_lang_math_log10   : // fall thru
1325   case Interpreter::java_lang_math_sqrt    : // fall thru
1326   case Interpreter::java_lang_math_pow     : // fall thru
1327   case Interpreter::java_lang_math_exp     : entry_point = ((InterpreterGenerator*) this)->generate_math_entry(kind);    break;
1328   case Interpreter::java_lang_ref_reference_get
1329                                            : entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break;
1330   case Interpreter::java_util_zip_CRC32_update  : entry_point = ((InterpreterGenerator*)this)->generate_CRC32_update_entry(); break;
1331   case Interpreter::java_util_zip_CRC32_updateBytes : entry_point = ((InterpreterGenerator*)this)->generate_CRC32_updateBytes_entry(kind); break;
1332   case Interpreter::java_util_zip_CRC32_updateByteBuffer : break;
1333   default                                  : ShouldNotReachHere();                                                       break;
1334   }
1335 
1336   if (entry_point) {
1337     return entry_point;
1338   }
1339 
1340   return ((InterpreterGenerator*) this)->generate_normal_entry(synchronized);
1341 }
1342 
1343 // CRC32 Intrinsics.
1344 //
1345 // Contract on scratch and work registers.
1346 // =======================================
1347 //
1348 // On ppc, the register set {R2..R12} is available in the interpreter as scratch/work registers.
1349 // You should, however, keep in mind that {R3_ARG1..R10_ARG8} is the C-ABI argument register set.
1350 // You can't rely on these registers across calls.
1351 //
1352 // The generators for CRC32_update and for CRC32_updateBytes use the
1353 // scratch/work register set internally, passing the work registers
1354 // as arguments to the MacroAssembler emitters as required.
1355 //
1356 // R3_ARG1..R6_ARG4 are preset to hold the incoming java arguments.
1357 // Their contents is not constant but may change according to the requirements
1358 // of the emitted code.
1359 //
1360 // All other registers from the scratch/work register set are used "internally"
1361 // and contain garbage (i.e. unpredictable values) once blr() is reached.
1362 // Basically, only R3_RET contains a defined value which is the function result.
1363 //
1364 /**
1365  * Method entry for static native methods:
1366  *   int java.util.zip.CRC32.update(int crc, int b)
1367  */
1368 address InterpreterGenerator::generate_CRC32_update_entry() {
1369   address start = __ pc();  // Remember stub start address (is rtn value).
1370 
1371   if (UseCRC32Intrinsics) {
1372     Label slow_path;
1373 
1374     // Safepoint check
1375     const Register sync_state = R11_scratch1;
1376     int sync_state_offs = __ load_const_optimized(sync_state, SafepointSynchronize::address_of_state(), /*temp*/R0, true);
1377     __ lwz(sync_state, sync_state_offs, sync_state);
1378     __ cmpwi(CCR0, sync_state, SafepointSynchronize::_not_synchronized);
1379     __ bne(CCR0, slow_path);
1380 
1381     // We don't generate local frame and don't align stack because
1382     // we not even call stub code (we generate the code inline)
1383     // and there is no safepoint on this path.
1384 
1385     // Load java parameters.
1386     // R15_esp is callers operand stack pointer, i.e. it points to the parameters.
1387     const Register argP    = R15_esp;
1388     const Register crc     = R3_ARG1;  // crc value
1389     const Register data    = R4_ARG2;  // address of java byte value (kernel_crc32 needs address)
1390     const Register dataLen = R5_ARG3;  // source data len (1 byte). Not used because calling the single-byte emitter.
1391     const Register table   = R6_ARG4;  // address of crc32 table
1392     const Register tmp     = dataLen;  // Reuse unused len register to show we don't actually need a separate tmp here.
1393 
1394     BLOCK_COMMENT("CRC32_update {");
1395 
1396     // Arguments are reversed on java expression stack
1397 #ifdef VM_LITTLE_ENDIAN
1398     __ addi(data, argP, 0+1*wordSize); // (stack) address of byte value. Emitter expects address, not value.
1399                                        // Being passed as an int, the single byte is at offset +0.
1400 #else
1401     __ addi(data, argP, 3+1*wordSize); // (stack) address of byte value. Emitter expects address, not value.
1402                                        // Being passed from java as an int, the single byte is at offset +3.
1403 #endif
1404     __ lwz(crc,  2*wordSize, argP);    // Current crc state, zero extend to 64 bit to have a clean register.
1405 
1406     StubRoutines::ppc64::generate_load_crc_table_addr(_masm, table);
1407     __ kernel_crc32_singleByte(crc, data, dataLen, table, tmp);
1408 
1409     // Restore caller sp for c2i case and return.
1410     __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started.
1411     __ blr();
1412 
1413     // Generate a vanilla native entry as the slow path.
1414     BLOCK_COMMENT("} CRC32_update");
1415     BIND(slow_path);
1416   }
1417 
1418   (void) generate_native_entry(false);
1419 
1420   return start;
1421 }
1422 
1423 // CRC32 Intrinsics.
1424 /**
1425  * Method entry for static native methods:
1426  *   int java.util.zip.CRC32.updateBytes(     int crc, byte[] b,  int off, int len)
1427  *   int java.util.zip.CRC32.updateByteBuffer(int crc, long* buf, int off, int len)
1428  */
1429 address InterpreterGenerator::generate_CRC32_updateBytes_entry(AbstractInterpreter::MethodKind kind) {
1430   address start = __ pc();  // Remember stub start address (is rtn value).
1431 
1432   if (UseCRC32Intrinsics) {
1433     Label slow_path;
1434 
1435     // Safepoint check
1436     const Register sync_state = R11_scratch1;
1437     int sync_state_offs = __ load_const_optimized(sync_state, SafepointSynchronize::address_of_state(), /*temp*/R0, true);
1438     __ lwz(sync_state, sync_state_offs, sync_state);
1439     __ cmpwi(CCR0, sync_state, SafepointSynchronize::_not_synchronized);
1440     __ bne(CCR0, slow_path);
1441 
1442     // We don't generate local frame and don't align stack because
1443     // we not even call stub code (we generate the code inline)
1444     // and there is no safepoint on this path.
1445 
1446     // Load parameters.
1447     // Z_esp is callers operand stack pointer, i.e. it points to the parameters.
1448     const Register argP    = R15_esp;
1449     const Register crc     = R3_ARG1;  // crc value
1450     const Register data    = R4_ARG2;  // address of java byte array
1451     const Register dataLen = R5_ARG3;  // source data len
1452     const Register table   = R6_ARG4;  // address of crc32 table
1453 
1454     const Register t0      = R9;       // scratch registers for crc calculation
1455     const Register t1      = R10;
1456     const Register t2      = R11;
1457     const Register t3      = R12;
1458 
1459     const Register tc0     = R2;       // registers to hold pre-calculated column addresses
1460     const Register tc1     = R7;
1461     const Register tc2     = R8;
1462     const Register tc3     = table;    // table address is reconstructed at the end of kernel_crc32_* emitters
1463 
1464     const Register tmp     = t0;       // Only used very locally to calculate byte buffer address.
1465 
1466     // Arguments are reversed on java expression stack.
1467     // Calculate address of start element.
1468     if (kind == Interpreter::java_util_zip_CRC32_updateByteBuffer) { // Used for "updateByteBuffer direct".
1469       BLOCK_COMMENT("CRC32_updateByteBuffer {");
1470       // crc     @ (SP + 5W) (32bit)
1471       // buf     @ (SP + 3W) (64bit ptr to long array)
1472       // off     @ (SP + 2W) (32bit)
1473       // dataLen @ (SP + 1W) (32bit)
1474       // data = buf + off
1475       __ ld(  data,    3*wordSize, argP);  // start of byte buffer
1476       __ lwa( tmp,     2*wordSize, argP);  // byte buffer offset
1477       __ lwa( dataLen, 1*wordSize, argP);  // #bytes to process
1478       __ lwz( crc,     5*wordSize, argP);  // current crc state
1479       __ add( data, data, tmp);            // Add byte buffer offset.
1480     } else {                                                         // Used for "updateBytes update".
1481       BLOCK_COMMENT("CRC32_updateBytes {");
1482       // crc     @ (SP + 4W) (32bit)
1483       // buf     @ (SP + 3W) (64bit ptr to byte array)
1484       // off     @ (SP + 2W) (32bit)
1485       // dataLen @ (SP + 1W) (32bit)
1486       // data = buf + off + base_offset
1487       __ ld(  data,    3*wordSize, argP);  // start of byte buffer
1488       __ lwa( tmp,     2*wordSize, argP);  // byte buffer offset
1489       __ lwa( dataLen, 1*wordSize, argP);  // #bytes to process
1490       __ add( data, data, tmp);            // add byte buffer offset
1491       __ lwz( crc,     4*wordSize, argP);  // current crc state
1492       __ addi(data, data, arrayOopDesc::base_offset_in_bytes(T_BYTE));
1493     }
1494 
1495     StubRoutines::ppc64::generate_load_crc_table_addr(_masm, table);
1496 
1497     // Performance measurements show the 1word and 2word variants to be almost equivalent,
1498     // with very light advantages for the 1word variant. We chose the 1word variant for
1499     // code compactness.
1500     __ kernel_crc32_1word(crc, data, dataLen, table, t0, t1, t2, t3, tc0, tc1, tc2, tc3);
1501 
1502     // Restore caller sp for c2i case and return.
1503     __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started.
1504     __ blr();
1505 
1506     // Generate a vanilla native entry as the slow path.
1507     BLOCK_COMMENT("} CRC32_updateBytes(Buffer)");
1508     BIND(slow_path);
1509   }
1510 
1511   (void) generate_native_entry(false);
1512 
1513   return start;
1514 }
1515 
1516 // These should never be compiled since the interpreter will prefer
1517 // the compiled version to the intrinsic version.
1518 bool AbstractInterpreter::can_be_compiled(methodHandle m) {
1519   return !math_entry_available(method_kind(m));
1520 }
1521 
1522 // How much stack a method activation needs in stack slots.
1523 // We must calc this exactly like in generate_fixed_frame.
1524 // Note: This returns the conservative size assuming maximum alignment.
1525 int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
1526   const int max_alignment_size = 2;
1527   const int abi_scratch = frame::abi_reg_args_size;
1528   return method->max_locals() + method->max_stack() +
1529          frame::interpreter_frame_monitor_size() + max_alignment_size + abi_scratch;
1530 }
1531 
1532 // Returns number of stackElementWords needed for the interpreter frame with the
1533 // given sections.


< prev index next >