< prev index next >

src/share/vm/runtime/deoptimization.cpp

Print this page




 918       InstanceKlass* ik = InstanceKlass::cast(k());
 919       FieldReassigner reassign(fr, reg_map, sv, obj());
 920       ik->do_nonstatic_fields(&reassign);
 921     } else if (k->oop_is_typeArray()) {
 922       TypeArrayKlass* ak = TypeArrayKlass::cast(k());
 923       reassign_type_array_elements(fr, reg_map, sv, (typeArrayOop) obj(), ak->element_type());
 924     } else if (k->oop_is_objArray()) {
 925       reassign_object_array_elements(fr, reg_map, sv, (objArrayOop) obj());
 926     }
 927   }
 928 }
 929 
 930 
 931 // relock objects for which synchronization was eliminated
 932 void Deoptimization::relock_objects(GrowableArray<MonitorInfo*>* monitors, JavaThread* thread, bool realloc_failures) {
 933   for (int i = 0; i < monitors->length(); i++) {
 934     MonitorInfo* mon_info = monitors->at(i);
 935     if (mon_info->eliminated()) {
 936       assert(!mon_info->owner_is_scalar_replaced() || realloc_failures, "reallocation was missed");
 937       if (!mon_info->owner_is_scalar_replaced()) {
 938         Handle obj = Handle(mon_info->owner());
 939         markOop mark = obj->mark();
 940         if (UseBiasedLocking && mark->has_bias_pattern()) {
 941           // New allocated objects may have the mark set to anonymously biased.
 942           // Also the deoptimized method may called methods with synchronization
 943           // where the thread-local object is bias locked to the current thread.
 944           assert(mark->is_biased_anonymously() ||
 945                  mark->biased_locker() == thread, "should be locked to current thread");
 946           // Reset mark word to unbiased prototype.
 947           markOop unbiased_prototype = markOopDesc::prototype()->set_age(mark->age());
 948           obj->set_mark(unbiased_prototype);
 949         }
 950         BasicLock* lock = mon_info->lock();
 951         ObjectSynchronizer::slow_enter(obj, lock, thread);
 952         assert(mon_info->owner()->is_locked(), "object must be locked now");
 953       }
 954     }
 955   }
 956 }
 957 
 958 


1041 
1042   return array;
1043 }
1044 
1045 #ifdef COMPILER2
1046 void Deoptimization::pop_frames_failed_reallocs(JavaThread* thread, vframeArray* array) {
1047   // Reallocation of some scalar replaced objects failed. Record
1048   // that we need to pop all the interpreter frames for the
1049   // deoptimized compiled frame.
1050   assert(thread->frames_to_pop_failed_realloc() == 0, "missed frames to pop?");
1051   thread->set_frames_to_pop_failed_realloc(array->frames());
1052   // Unlock all monitors here otherwise the interpreter will see a
1053   // mix of locked and unlocked monitors (because of failed
1054   // reallocations of synchronized objects) and be confused.
1055   for (int i = 0; i < array->frames(); i++) {
1056     MonitorChunk* monitors = array->element(i)->monitors();
1057     if (monitors != NULL) {
1058       for (int j = 0; j < monitors->number_of_monitors(); j++) {
1059         BasicObjectLock* src = monitors->at(j);
1060         if (src->obj() != NULL) {
1061           ObjectSynchronizer::fast_exit(src->obj(), src->lock(), thread);
1062         }
1063       }
1064       array->element(i)->free_monitors(thread);
1065 #ifdef ASSERT
1066       array->element(i)->set_removed_monitors();
1067 #endif
1068     }
1069   }
1070 }
1071 #endif
1072 
1073 static void collect_monitors(compiledVFrame* cvf, GrowableArray<Handle>* objects_to_revoke) {
1074   GrowableArray<MonitorInfo*>* monitors = cvf->monitors();
1075   for (int i = 0; i < monitors->length(); i++) {
1076     MonitorInfo* mon_info = monitors->at(i);
1077     if (!mon_info->eliminated() && mon_info->owner() != NULL) {
1078       objects_to_revoke->append(Handle(mon_info->owner()));
1079     }
1080   }
1081 }




 918       InstanceKlass* ik = InstanceKlass::cast(k());
 919       FieldReassigner reassign(fr, reg_map, sv, obj());
 920       ik->do_nonstatic_fields(&reassign);
 921     } else if (k->oop_is_typeArray()) {
 922       TypeArrayKlass* ak = TypeArrayKlass::cast(k());
 923       reassign_type_array_elements(fr, reg_map, sv, (typeArrayOop) obj(), ak->element_type());
 924     } else if (k->oop_is_objArray()) {
 925       reassign_object_array_elements(fr, reg_map, sv, (objArrayOop) obj());
 926     }
 927   }
 928 }
 929 
 930 
 931 // relock objects for which synchronization was eliminated
 932 void Deoptimization::relock_objects(GrowableArray<MonitorInfo*>* monitors, JavaThread* thread, bool realloc_failures) {
 933   for (int i = 0; i < monitors->length(); i++) {
 934     MonitorInfo* mon_info = monitors->at(i);
 935     if (mon_info->eliminated()) {
 936       assert(!mon_info->owner_is_scalar_replaced() || realloc_failures, "reallocation was missed");
 937       if (!mon_info->owner_is_scalar_replaced()) {
 938         Handle obj = Handle(oopDesc::bs()->write_barrier(mon_info->owner()));
 939         markOop mark = obj->mark();
 940         if (UseBiasedLocking && mark->has_bias_pattern()) {
 941           // New allocated objects may have the mark set to anonymously biased.
 942           // Also the deoptimized method may called methods with synchronization
 943           // where the thread-local object is bias locked to the current thread.
 944           assert(mark->is_biased_anonymously() ||
 945                  mark->biased_locker() == thread, "should be locked to current thread");
 946           // Reset mark word to unbiased prototype.
 947           markOop unbiased_prototype = markOopDesc::prototype()->set_age(mark->age());
 948           obj->set_mark(unbiased_prototype);
 949         }
 950         BasicLock* lock = mon_info->lock();
 951         ObjectSynchronizer::slow_enter(obj, lock, thread);
 952         assert(mon_info->owner()->is_locked(), "object must be locked now");
 953       }
 954     }
 955   }
 956 }
 957 
 958 


1041 
1042   return array;
1043 }
1044 
1045 #ifdef COMPILER2
1046 void Deoptimization::pop_frames_failed_reallocs(JavaThread* thread, vframeArray* array) {
1047   // Reallocation of some scalar replaced objects failed. Record
1048   // that we need to pop all the interpreter frames for the
1049   // deoptimized compiled frame.
1050   assert(thread->frames_to_pop_failed_realloc() == 0, "missed frames to pop?");
1051   thread->set_frames_to_pop_failed_realloc(array->frames());
1052   // Unlock all monitors here otherwise the interpreter will see a
1053   // mix of locked and unlocked monitors (because of failed
1054   // reallocations of synchronized objects) and be confused.
1055   for (int i = 0; i < array->frames(); i++) {
1056     MonitorChunk* monitors = array->element(i)->monitors();
1057     if (monitors != NULL) {
1058       for (int j = 0; j < monitors->number_of_monitors(); j++) {
1059         BasicObjectLock* src = monitors->at(j);
1060         if (src->obj() != NULL) {
1061           ObjectSynchronizer::fast_exit(oopDesc::bs()->write_barrier(src->obj()), src->lock(), thread);
1062         }
1063       }
1064       array->element(i)->free_monitors(thread);
1065 #ifdef ASSERT
1066       array->element(i)->set_removed_monitors();
1067 #endif
1068     }
1069   }
1070 }
1071 #endif
1072 
1073 static void collect_monitors(compiledVFrame* cvf, GrowableArray<Handle>* objects_to_revoke) {
1074   GrowableArray<MonitorInfo*>* monitors = cvf->monitors();
1075   for (int i = 0; i < monitors->length(); i++) {
1076     MonitorInfo* mon_info = monitors->at(i);
1077     if (!mon_info->eliminated() && mon_info->owner() != NULL) {
1078       objects_to_revoke->append(Handle(mon_info->owner()));
1079     }
1080   }
1081 }


< prev index next >