comparison src/share/vm/runtime/deoptimization.cpp @ 44:52fed2ec0afb

6667620: (Escape Analysis) fix deoptimization for scalar replaced objects Summary: Deoptimization code for reallocation and relocking scalar replaced objects has to be fixed. Reviewed-by: rasbold, never
author kvn
date Tue, 11 Mar 2008 11:25:13 -0700
parents a61af66fc99e
children d3cd40645d0d
comparison
equal deleted inserted replaced
43:d821d920b465 44:52fed2ec0afb
139 chunk->push(compiledVFrame::cast(vf)); 139 chunk->push(compiledVFrame::cast(vf));
140 140
141 #ifdef COMPILER2 141 #ifdef COMPILER2
142 // Reallocate the non-escaping objects and restore their fields. Then 142 // Reallocate the non-escaping objects and restore their fields. Then
143 // relock objects if synchronization on them was eliminated. 143 // relock objects if synchronization on them was eliminated.
144 if (DoEscapeAnalysis && EliminateAllocations) { 144 if (DoEscapeAnalysis) {
145 GrowableArray<ScopeValue*>* objects = chunk->at(0)->scope()->objects(); 145 if (EliminateAllocations) {
146 bool reallocated = false; 146 GrowableArray<ScopeValue*>* objects = chunk->at(0)->scope()->objects();
147 if (objects != NULL) { 147 bool reallocated = false;
148 JRT_BLOCK 148 if (objects != NULL) {
149 reallocated = realloc_objects(thread, &deoptee, objects, THREAD); 149 JRT_BLOCK
150 JRT_END 150 reallocated = realloc_objects(thread, &deoptee, objects, THREAD);
151 } 151 JRT_END
152 if (reallocated) { 152 }
153 reassign_fields(&deoptee, &map, objects); 153 if (reallocated) {
154 #ifndef PRODUCT 154 reassign_fields(&deoptee, &map, objects);
155 if (TraceDeoptimization) {
156 ttyLocker ttyl;
157 tty->print_cr("REALLOC OBJECTS in thread " INTPTR_FORMAT, thread);
158 print_objects(objects);
159 }
160 #endif
161 }
162 for (int i = 0; i < chunk->length(); i++) {
163 GrowableArray<MonitorValue*>* monitors = chunk->at(i)->scope()->monitors();
164 if (monitors != NULL) {
165 relock_objects(&deoptee, &map, monitors);
166 #ifndef PRODUCT 155 #ifndef PRODUCT
167 if (TraceDeoptimization) { 156 if (TraceDeoptimization) {
168 ttyLocker ttyl; 157 ttyLocker ttyl;
169 tty->print_cr("RELOCK OBJECTS in thread " INTPTR_FORMAT, thread); 158 tty->print_cr("REALLOC OBJECTS in thread " INTPTR_FORMAT, thread);
170 for (int j = 0; i < monitors->length(); i++) { 159 print_objects(objects);
171 MonitorValue* mv = monitors->at(i); 160 }
172 if (mv->eliminated()) { 161 #endif
173 StackValue* owner = StackValue::create_stack_value(&deoptee, &map, mv->owner()); 162 }
174 tty->print_cr(" object <" INTPTR_FORMAT "> locked", owner->get_obj()()); 163 }
164 if (EliminateLocks) {
165 for (int i = 0; i < chunk->length(); i++) {
166 GrowableArray<MonitorValue*>* monitors = chunk->at(i)->scope()->monitors();
167 if (monitors != NULL) {
168 relock_objects(&deoptee, &map, monitors);
169 #ifndef PRODUCT
170 if (TraceDeoptimization) {
171 ttyLocker ttyl;
172 tty->print_cr("RELOCK OBJECTS in thread " INTPTR_FORMAT, thread);
173 for (int j = 0; j < monitors->length(); j++) {
174 MonitorValue* mv = monitors->at(j);
175 if (mv->eliminated()) {
176 StackValue* owner = StackValue::create_stack_value(&deoptee, &map, mv->owner());
177 tty->print_cr(" object <" INTPTR_FORMAT "> locked", owner->get_obj()());
178 }
175 } 179 }
176 } 180 }
181 #endif
177 } 182 }
178 #endif
179 } 183 }
180 } 184 }
181 } 185 }
182 #endif // COMPILER2 186 #endif // COMPILER2
183 // Ensure that no safepoint is taken after pointers have been stored 187 // Ensure that no safepoint is taken after pointers have been stored
654 658
655 int i() const { return _i; } 659 int i() const { return _i; }
656 660
657 661
658 void do_field(fieldDescriptor* fd) { 662 void do_field(fieldDescriptor* fd) {
663 intptr_t val;
659 StackValue* value = 664 StackValue* value =
660 StackValue::create_stack_value(_fr, _reg_map, _sv->field_at(i())); 665 StackValue::create_stack_value(_fr, _reg_map, _sv->field_at(i()));
661 int offset = fd->offset(); 666 int offset = fd->offset();
662 switch (fd->field_type()) { 667 switch (fd->field_type()) {
663 case T_OBJECT: case T_ARRAY: 668 case T_OBJECT: case T_ARRAY:
667 672
668 case T_LONG: case T_DOUBLE: { 673 case T_LONG: case T_DOUBLE: {
669 assert(value->type() == T_INT, "Agreement."); 674 assert(value->type() == T_INT, "Agreement.");
670 StackValue* low = 675 StackValue* low =
671 StackValue::create_stack_value(_fr, _reg_map, _sv->field_at(++_i)); 676 StackValue::create_stack_value(_fr, _reg_map, _sv->field_at(++_i));
677 #ifdef _LP64
678 jlong res = (jlong)low->get_int();
679 #else
680 #ifdef SPARC
681 // For SPARC we have to swap high and low words.
682 jlong res = jlong_from((jint)low->get_int(), (jint)value->get_int());
683 #else
672 jlong res = jlong_from((jint)value->get_int(), (jint)low->get_int()); 684 jlong res = jlong_from((jint)value->get_int(), (jint)low->get_int());
685 #endif //SPARC
686 #endif
673 _obj->long_field_put(offset, res); 687 _obj->long_field_put(offset, res);
674 break; 688 break;
675 } 689 }
676 690 // Have to cast to INT (32 bits) pointer to avoid little/big-endian problem.
677 case T_INT: case T_FLOAT: // 4 bytes. 691 case T_INT: case T_FLOAT: // 4 bytes.
678 assert(value->type() == T_INT, "Agreement."); 692 assert(value->type() == T_INT, "Agreement.");
679 _obj->int_field_put(offset, (jint)value->get_int()); 693 val = value->get_int();
694 _obj->int_field_put(offset, (jint)*((jint*)&val));
680 break; 695 break;
681 696
682 case T_SHORT: case T_CHAR: // 2 bytes 697 case T_SHORT: case T_CHAR: // 2 bytes
683 assert(value->type() == T_INT, "Agreement."); 698 assert(value->type() == T_INT, "Agreement.");
684 _obj->short_field_put(offset, (jshort)value->get_int()); 699 val = value->get_int();
700 _obj->short_field_put(offset, (jshort)*((jint*)&val));
685 break; 701 break;
686 702
687 case T_BOOLEAN: // 1 byte 703 case T_BOOLEAN: case T_BYTE: // 1 byte
688 assert(value->type() == T_INT, "Agreement."); 704 assert(value->type() == T_INT, "Agreement.");
689 _obj->bool_field_put(offset, (jboolean)value->get_int()); 705 val = value->get_int();
706 _obj->bool_field_put(offset, (jboolean)*((jint*)&val));
690 break; 707 break;
691 708
692 default: 709 default:
693 ShouldNotReachHere(); 710 ShouldNotReachHere();
694 } 711 }
696 } 713 }
697 }; 714 };
698 715
699 // restore elements of an eliminated type array 716 // restore elements of an eliminated type array
700 void Deoptimization::reassign_type_array_elements(frame* fr, RegisterMap* reg_map, ObjectValue* sv, typeArrayOop obj, BasicType type) { 717 void Deoptimization::reassign_type_array_elements(frame* fr, RegisterMap* reg_map, ObjectValue* sv, typeArrayOop obj, BasicType type) {
701 StackValue* low;
702 jlong lval;
703 int index = 0; 718 int index = 0;
719 intptr_t val;
704 720
705 for (int i = 0; i < sv->field_size(); i++) { 721 for (int i = 0; i < sv->field_size(); i++) {
706 StackValue* value = StackValue::create_stack_value(fr, reg_map, sv->field_at(i)); 722 StackValue* value = StackValue::create_stack_value(fr, reg_map, sv->field_at(i));
707 switch(type) { 723 switch(type) {
708 case T_BOOLEAN: obj->bool_at_put (index, (jboolean) value->get_int()); break; 724 case T_LONG: case T_DOUBLE: {
709 case T_BYTE: obj->byte_at_put (index, (jbyte) value->get_int()); break; 725 assert(value->type() == T_INT, "Agreement.");
710 case T_CHAR: obj->char_at_put (index, (jchar) value->get_int()); break; 726 StackValue* low =
711 case T_SHORT: obj->short_at_put(index, (jshort) value->get_int()); break; 727 StackValue::create_stack_value(fr, reg_map, sv->field_at(++i));
712 case T_INT: obj->int_at_put (index, (jint) value->get_int()); break; 728 #ifdef _LP64
713 case T_FLOAT: obj->float_at_put(index, (jfloat) value->get_int()); break; 729 jlong res = (jlong)low->get_int();
714 case T_LONG: 730 #else
715 case T_DOUBLE: 731 #ifdef SPARC
716 low = StackValue::create_stack_value(fr, reg_map, sv->field_at(++i)); 732 // For SPARC we have to swap high and low words.
717 lval = jlong_from((jint)value->get_int(), (jint)low->get_int()); 733 jlong res = jlong_from((jint)low->get_int(), (jint)value->get_int());
718 sv->value()->long_field_put(index, lval); 734 #else
719 break; 735 jlong res = jlong_from((jint)value->get_int(), (jint)low->get_int());
736 #endif //SPARC
737 #endif
738 obj->long_at_put(index, res);
739 break;
740 }
741
742 // Have to cast to INT (32 bits) pointer to avoid little/big-endian problem.
743 case T_INT: case T_FLOAT: // 4 bytes.
744 assert(value->type() == T_INT, "Agreement.");
745 val = value->get_int();
746 obj->int_at_put(index, (jint)*((jint*)&val));
747 break;
748
749 case T_SHORT: case T_CHAR: // 2 bytes
750 assert(value->type() == T_INT, "Agreement.");
751 val = value->get_int();
752 obj->short_at_put(index, (jshort)*((jint*)&val));
753 break;
754
755 case T_BOOLEAN: case T_BYTE: // 1 byte
756 assert(value->type() == T_INT, "Agreement.");
757 val = value->get_int();
758 obj->bool_at_put(index, (jboolean)*((jint*)&val));
759 break;
760
720 default: 761 default:
721 ShouldNotReachHere(); 762 ShouldNotReachHere();
722 } 763 }
723 index++; 764 index++;
724 } 765 }