< prev index next >

src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp

Print this page

 888 
 889     bind(no_reserved_zone_enabling);
 890   }
 891 
 892   verify_oop(R17_tos, state);
 893   verify_thread();
 894 
 895   merge_frames(/*top_frame_sp*/ R21_sender_SP, /*return_pc*/ R0, R11_scratch1, R12_scratch2);
 896   mtlr(R0);
 897   BLOCK_COMMENT("} remove_activation");
 898 }
 899 
 900 // Lock object
 901 //
 902 // Registers alive
 903 //   monitor - Address of the BasicObjectLock to be used for locking,
 904 //             which must be initialized with the object to lock.
 905 //   object  - Address of the object to be locked.
 906 //
 907 void InterpreterMacroAssembler::lock_object(Register monitor, Register object) {
 908   if (UseHeavyMonitors) {
 909     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), monitor);
 910   } else {
 911     // template code:
 912     //
 913     // markWord displaced_header = obj->mark().set_unlocked();
 914     // monitor->lock()->set_displaced_header(displaced_header);
 915     // if (Atomic::cmpxchg(/*addr*/obj->mark_addr(), /*cmp*/displaced_header, /*ex=*/monitor) == displaced_header) {
 916     //   // We stored the monitor address into the object's mark word.
 917     // } else if (THREAD->is_lock_owned((address)displaced_header))
 918     //   // Simple recursive case.
 919     //   monitor->lock()->set_displaced_header(NULL);
 920     // } else {
 921     //   // Slow path.
 922     //   InterpreterRuntime::monitorenter(THREAD, monitor);
 923     // }
 924 
 925     const Register displaced_header = R7_ARG5;
 926     const Register object_mark_addr = R8_ARG6;
 927     const Register current_header   = R9_ARG7;
 928     const Register tmp              = R10_ARG8;
 929 
 930     Label done;
 931     Label cas_failed, slow_case;
 932 
 933     assert_different_registers(displaced_header, object_mark_addr, current_header, tmp);
 934 
 935     // markWord displaced_header = obj->mark().set_unlocked();
 936 
 937     // Load markWord from object into displaced_header.
 938     ld(displaced_header, oopDesc::mark_offset_in_bytes(), object);
 939 
 940     if (DiagnoseSyncOnValueBasedClasses != 0) {
 941       load_klass(tmp, object);
 942       lwz(tmp, in_bytes(Klass::access_flags_offset()), tmp);
 943       testbitdi(CCR0, R0, tmp, exact_log2(JVM_ACC_IS_VALUE_BASED_CLASS));
 944       bne(CCR0, slow_case);
 945     }
 946 
 947     // Set displaced_header to be (markWord of object | UNLOCK_VALUE).
 948     ori(displaced_header, displaced_header, markWord::unlocked_value);
 949 
 950     // monitor->lock()->set_displaced_header(displaced_header);
 951 
 952     // Initialize the box (Must happen before we update the object mark!).
 953     std(displaced_header, BasicObjectLock::lock_offset_in_bytes() +
 954         BasicLock::displaced_header_offset_in_bytes(), monitor);
 955 
 956     // if (Atomic::cmpxchg(/*addr*/obj->mark_addr(), /*cmp*/displaced_header, /*ex=*/monitor) == displaced_header) {
 957 
 958     // Store stack address of the BasicObjectLock (this is monitor) into object.
 959     addi(object_mark_addr, object, oopDesc::mark_offset_in_bytes());
 960 
 961     // Must fence, otherwise, preceding store(s) may float below cmpxchg.
 962     // CmpxchgX sets CCR0 to cmpX(current, displaced).
 963     cmpxchgd(/*flag=*/CCR0,
 964              /*current_value=*/current_header,
 965              /*compare_value=*/displaced_header, /*exchange_value=*/monitor,
 966              /*where=*/object_mark_addr,
 967              MacroAssembler::MemBarRel | MacroAssembler::MemBarAcq,
 968              MacroAssembler::cmpxchgx_hint_acquire_lock(),
 969              noreg,
 970              &cas_failed,
 971              /*check without membar and ldarx first*/true);
 972 
 973     // If the compare-and-exchange succeeded, then we found an unlocked
 974     // object and we have now locked it.
 975     b(done);
 976     bind(cas_failed);
 977 
 978     // } else if (THREAD->is_lock_owned((address)displaced_header))
 979     //   // Simple recursive case.
 980     //   monitor->lock()->set_displaced_header(NULL);
 981 
 982     // We did not see an unlocked object so try the fast recursive case.
 983 
 984     // Check if owner is self by comparing the value in the markWord of object
 985     // (current_header) with the stack pointer.
 986     sub(current_header, current_header, R1_SP);
 987 
 988     assert(os::vm_page_size() > 0xfff, "page size too small - change the constant");
 989     load_const_optimized(tmp, ~(os::vm_page_size()-1) | markWord::lock_mask_in_place);
 990 
 991     and_(R0/*==0?*/, current_header, tmp);
 992     // If condition is true we are done and hence we can store 0 in the displaced
 993     // header indicating it is a recursive lock.
 994     bne(CCR0, slow_case);
 995     std(R0/*==0!*/, BasicObjectLock::lock_offset_in_bytes() +
 996         BasicLock::displaced_header_offset_in_bytes(), monitor);
 997     b(done);
 998 
 999     // } else {
1000     //   // Slow path.
1001     //   InterpreterRuntime::monitorenter(THREAD, monitor);
1002 
1003     // None of the above fast optimizations worked so we have to get into the
1004     // slow case of monitor enter.
1005     bind(slow_case);
1006     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), monitor);
1007     // }
1008     align(32, 12);
1009     bind(done);
1010   }
1011 }
1012 
1013 // Unlocks an object. Used in monitorexit bytecode and remove_activation.
1014 //
1015 // Registers alive
1016 //   monitor - Address of the BasicObjectLock to be used for locking,
1017 //             which must be initialized with the object to lock.
1018 //
1019 // Throw IllegalMonitorException if object is not locked by current thread.
1020 void InterpreterMacroAssembler::unlock_object(Register monitor) {
1021   if (UseHeavyMonitors) {
1022     call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor);
1023   } else {
1024 
1025     // template code:
1026     //
1027     // if ((displaced_header = monitor->displaced_header()) == NULL) {
1028     //   // Recursive unlock. Mark the monitor unlocked by setting the object field to NULL.
1029     //   monitor->set_obj(NULL);
1030     // } else if (Atomic::cmpxchg(obj->mark_addr(), monitor, displaced_header) == monitor) {
1031     //   // We swapped the unlocked mark in displaced_header into the object's mark word.
1032     //   monitor->set_obj(NULL);
1033     // } else {
1034     //   // Slow path.
1035     //   InterpreterRuntime::monitorexit(monitor);
1036     // }
1037 
1038     const Register object           = R7_ARG5;
1039     const Register displaced_header = R8_ARG6;
1040     const Register object_mark_addr = R9_ARG7;
1041     const Register current_header   = R10_ARG8;
1042 
1043     Label free_slot;
1044     Label slow_case;
1045 
1046     assert_different_registers(object, displaced_header, object_mark_addr, current_header);
1047 
1048     // Test first if we are in the fast recursive case.
1049     ld(displaced_header, BasicObjectLock::lock_offset_in_bytes() +
1050            BasicLock::displaced_header_offset_in_bytes(), monitor);
1051 
1052     // If the displaced header is zero, we have a recursive unlock.
1053     cmpdi(CCR0, displaced_header, 0);
1054     beq(CCR0, free_slot); // recursive unlock
1055 
1056     // } else if (Atomic::cmpxchg(obj->mark_addr(), monitor, displaced_header) == monitor) {
1057     //   // We swapped the unlocked mark in displaced_header into the object's mark word.
1058     //   monitor->set_obj(NULL);
1059 
1060     // If we still have a lightweight lock, unlock the object and be done.
1061 
1062     // The object address from the monitor is in object.
1063     ld(object, BasicObjectLock::obj_offset_in_bytes(), monitor);
1064     addi(object_mark_addr, object, oopDesc::mark_offset_in_bytes());
1065 
1066     // We have the displaced header in displaced_header. If the lock is still
1067     // lightweight, it will contain the monitor address and we'll store the
1068     // displaced header back into the object's mark word.
1069     // CmpxchgX sets CCR0 to cmpX(current, monitor).
1070     cmpxchgd(/*flag=*/CCR0,
1071              /*current_value=*/current_header,
1072              /*compare_value=*/monitor, /*exchange_value=*/displaced_header,
1073              /*where=*/object_mark_addr,
1074              MacroAssembler::MemBarRel,
1075              MacroAssembler::cmpxchgx_hint_release_lock(),
1076              noreg,
1077              &slow_case);
1078     b(free_slot);
1079 
1080     // } else {
1081     //   // Slow path.
1082     //   InterpreterRuntime::monitorexit(monitor);
1083 
1084     // The lock has been converted into a heavy lock and hence
1085     // we need to get into the slow case.
1086     bind(slow_case);
1087     call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor);
1088     // }
1089 
1090     Label done;
1091     b(done); // Monitor register may be overwritten! Runtime has already freed the slot.
1092 
1093     // Exchange worked, do monitor->set_obj(NULL);
1094     align(32, 12);
1095     bind(free_slot);
1096     li(R0, 0);
1097     std(R0, BasicObjectLock::obj_offset_in_bytes(), monitor);
1098     bind(done);
1099   }
1100 }
1101 
1102 // Load compiled (i2c) or interpreter entry when calling from interpreted and
1103 // do the call. Centralized so that all interpreter calls will do the same actions.
1104 // If jvmti single stepping is on for a thread we must not call compiled code.
1105 //
1106 // Input:
1107 //   - Rtarget_method: method to call
1108 //   - Rret_addr:      return address
1109 //   - 2 scratch regs
1110 //
1111 void InterpreterMacroAssembler::call_from_interpreter(Register Rtarget_method, Register Rret_addr,
1112                                                       Register Rscratch1, Register Rscratch2) {
1113   assert_different_registers(Rscratch1, Rscratch2, Rtarget_method, Rret_addr);
1114   // Assume we want to go compiled if available.
1115   const Register Rtarget_addr = Rscratch1;
1116   const Register Rinterp_only = Rscratch2;
1117 
1118   ld(Rtarget_addr, in_bytes(Method::from_interpreted_offset()), Rtarget_method);
1119 

 888 
 889     bind(no_reserved_zone_enabling);
 890   }
 891 
 892   verify_oop(R17_tos, state);
 893   verify_thread();
 894 
 895   merge_frames(/*top_frame_sp*/ R21_sender_SP, /*return_pc*/ R0, R11_scratch1, R12_scratch2);
 896   mtlr(R0);
 897   BLOCK_COMMENT("} remove_activation");
 898 }
 899 
 900 // Lock object
 901 //
 902 // Registers alive
 903 //   monitor - Address of the BasicObjectLock to be used for locking,
 904 //             which must be initialized with the object to lock.
 905 //   object  - Address of the object to be locked.
 906 //
 907 void InterpreterMacroAssembler::lock_object(Register monitor, Register object) {
 908   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), monitor);






































































































 909 }
 910 
 911 // Unlocks an object. Used in monitorexit bytecode and remove_activation.
 912 //
 913 // Registers alive
 914 //   monitor - Address of the BasicObjectLock to be used for locking,
 915 //             which must be initialized with the object to lock.
 916 //
 917 // Throw IllegalMonitorException if object is not locked by current thread.
 918 void InterpreterMacroAssembler::unlock_object(Register monitor) {
 919   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor);














































































 920 }
 921 
 922 // Load compiled (i2c) or interpreter entry when calling from interpreted and
 923 // do the call. Centralized so that all interpreter calls will do the same actions.
 924 // If jvmti single stepping is on for a thread we must not call compiled code.
 925 //
 926 // Input:
 927 //   - Rtarget_method: method to call
 928 //   - Rret_addr:      return address
 929 //   - 2 scratch regs
 930 //
 931 void InterpreterMacroAssembler::call_from_interpreter(Register Rtarget_method, Register Rret_addr,
 932                                                       Register Rscratch1, Register Rscratch2) {
 933   assert_different_registers(Rscratch1, Rscratch2, Rtarget_method, Rret_addr);
 934   // Assume we want to go compiled if available.
 935   const Register Rtarget_addr = Rscratch1;
 936   const Register Rinterp_only = Rscratch2;
 937 
 938   ld(Rtarget_addr, in_bytes(Method::from_interpreted_offset()), Rtarget_method);
 939 
< prev index next >