< prev index next >

src/hotspot/share/runtime/deoptimization.cpp

Print this page
rev 59103 : imported patch hotspot


1065  * In the unlikely case index 0 is 5-aligned for example, it would then be possible to
1066  * write a long to index 3.
1067  */
1068 static jbyte* check_alignment_get_addr(typeArrayOop obj, int index, int expected_alignment) {
1069     jbyte* res = obj->byte_at_addr(index);
1070     assert((((intptr_t) res) % expected_alignment) == 0, "Non-aligned write");
1071     return res;
1072 }
1073 
1074 static void byte_array_put(typeArrayOop obj, intptr_t val, int index, int byte_count) {
1075   switch (byte_count) {
1076     case 1:
1077       obj->byte_at_put(index, (jbyte) *((jint *) &val));
1078       break;
1079     case 2:
1080       *((jshort *) check_alignment_get_addr(obj, index, 2)) = (jshort) *((jint *) &val);
1081       break;
1082     case 4:
1083       *((jint *) check_alignment_get_addr(obj, index, 4)) = (jint) *((jint *) &val);
1084       break;
1085     case 8: {
1086 #ifdef _LP64
1087         jlong res = (jlong) *((jlong *) &val);
1088 #else
1089 #ifdef SPARC
1090       // For SPARC we have to swap high and low words.
1091       jlong v = (jlong) *((jlong *) &val);
1092       jlong res = 0;
1093       res |= ((v & (jlong) 0xffffffff) << 32);
1094       res |= ((v >> 32) & (jlong) 0xffffffff);
1095 #else
1096       jlong res = (jlong) *((jlong *) &val);
1097 #endif // SPARC
1098 #endif
1099       *((jlong *) check_alignment_get_addr(obj, index, 8)) = res;
1100       break;
1101   }
1102     default:
1103       ShouldNotReachHere();
1104   }
1105 }
1106 #endif // INCLUDE_JVMCI
1107 
1108 
1109 // restore elements of an eliminated type array
1110 void Deoptimization::reassign_type_array_elements(frame* fr, RegisterMap* reg_map, ObjectValue* sv, typeArrayOop obj, BasicType type) {
1111   int index = 0;
1112   intptr_t val;
1113 
1114   for (int i = 0; i < sv->field_size(); i++) {
1115     StackValue* value = StackValue::create_stack_value(fr, reg_map, sv->field_at(i));
1116     switch(type) {
1117     case T_LONG: case T_DOUBLE: {
1118       assert(value->type() == T_INT, "Agreement.");
1119       StackValue* low =
1120         StackValue::create_stack_value(fr, reg_map, sv->field_at(++i));
1121 #ifdef _LP64
1122       jlong res = (jlong)low->get_int();
1123 #else
1124 #ifdef SPARC
1125       // For SPARC we have to swap high and low words.
1126       jlong res = jlong_from((jint)low->get_int(), (jint)value->get_int());
1127 #else
1128       jlong res = jlong_from((jint)value->get_int(), (jint)low->get_int());
1129 #endif //SPARC
1130 #endif
1131       obj->long_at_put(index, res);
1132       break;
1133     }
1134 
1135     // Have to cast to INT (32 bits) pointer to avoid little/big-endian problem.
1136     case T_INT: case T_FLOAT: { // 4 bytes.
1137       assert(value->type() == T_INT, "Agreement.");
1138       bool big_value = false;
1139       if (i + 1 < sv->field_size() && type == T_INT) {
1140         if (sv->field_at(i)->is_location()) {
1141           Location::Type type = ((LocationValue*) sv->field_at(i))->location().type();
1142           if (type == Location::dbl || type == Location::lng) {
1143             big_value = true;
1144           }
1145         } else if (sv->field_at(i)->is_constant_int()) {
1146           ScopeValue* next_scope_field = sv->field_at(i + 1);
1147           if (next_scope_field->is_constant_long() || next_scope_field->is_constant_double()) {
1148             big_value = true;
1149           }
1150         }
1151       }
1152 
1153       if (big_value) {
1154         StackValue* low = StackValue::create_stack_value(fr, reg_map, sv->field_at(++i));
1155   #ifdef _LP64
1156         jlong res = (jlong)low->get_int();
1157   #else
1158   #ifdef SPARC
1159         // For SPARC we have to swap high and low words.
1160         jlong res = jlong_from((jint)low->get_int(), (jint)value->get_int());
1161   #else
1162         jlong res = jlong_from((jint)value->get_int(), (jint)low->get_int());
1163   #endif //SPARC
1164   #endif
1165         obj->int_at_put(index, (jint)*((jint*)&res));
1166         obj->int_at_put(++index, (jint)*(((jint*)&res) + 1));
1167       } else {
1168         val = value->get_int();
1169         obj->int_at_put(index, (jint)*((jint*)&val));
1170       }
1171       break;
1172     }
1173 
1174     case T_SHORT:
1175       assert(value->type() == T_INT, "Agreement.");
1176       val = value->get_int();
1177       obj->short_at_put(index, (jshort)*((jint*)&val));
1178       break;
1179 
1180     case T_CHAR:
1181       assert(value->type() == T_INT, "Agreement.");
1182       val = value->get_int();
1183       obj->char_at_put(index, (jchar)*((jint*)&val));


1288         }
1289 
1290         if (big_value) {
1291           i++;
1292           assert(i < fields->length(), "second T_INT field needed");
1293           assert(fields->at(i)._type == T_INT, "T_INT field needed");
1294         } else {
1295           val = value->get_int();
1296           obj->int_field_put(offset, (jint)*((jint*)&val));
1297           break;
1298         }
1299       }
1300         /* no break */
1301 
1302       case T_LONG: case T_DOUBLE: {
1303         assert(value->type() == T_INT, "Agreement.");
1304         StackValue* low = StackValue::create_stack_value(fr, reg_map, sv->field_at(++svIndex));
1305 #ifdef _LP64
1306         jlong res = (jlong)low->get_int();
1307 #else
1308 #ifdef SPARC
1309         // For SPARC we have to swap high and low words.
1310         jlong res = jlong_from((jint)low->get_int(), (jint)value->get_int());
1311 #else
1312         jlong res = jlong_from((jint)value->get_int(), (jint)low->get_int());
1313 #endif //SPARC
1314 #endif
1315         obj->long_field_put(offset, res);
1316         break;
1317       }
1318 
1319       case T_SHORT:
1320         assert(value->type() == T_INT, "Agreement.");
1321         val = value->get_int();
1322         obj->short_field_put(offset, (jshort)*((jint*)&val));
1323         break;
1324 
1325       case T_CHAR:
1326         assert(value->type() == T_INT, "Agreement.");
1327         val = value->get_int();
1328         obj->char_field_put(offset, (jchar)*((jint*)&val));
1329         break;
1330 
1331       case T_BYTE:
1332         assert(value->type() == T_INT, "Agreement.");
1333         val = value->get_int();




1065  * In the unlikely case index 0 is 5-aligned for example, it would then be possible to
1066  * write a long to index 3.
1067  */
1068 static jbyte* check_alignment_get_addr(typeArrayOop obj, int index, int expected_alignment) {
1069     jbyte* res = obj->byte_at_addr(index);
1070     assert((((intptr_t) res) % expected_alignment) == 0, "Non-aligned write");
1071     return res;
1072 }
1073 
1074 static void byte_array_put(typeArrayOop obj, intptr_t val, int index, int byte_count) {
1075   switch (byte_count) {
1076     case 1:
1077       obj->byte_at_put(index, (jbyte) *((jint *) &val));
1078       break;
1079     case 2:
1080       *((jshort *) check_alignment_get_addr(obj, index, 2)) = (jshort) *((jint *) &val);
1081       break;
1082     case 4:
1083       *((jint *) check_alignment_get_addr(obj, index, 4)) = (jint) *((jint *) &val);
1084       break;
1085     case 8:
1086       *((jlong *) check_alignment_get_addr(obj, index, 8)) = (jlong) *((jlong *) &val);













1087       break;

1088     default:
1089       ShouldNotReachHere();
1090   }
1091 }
1092 #endif // INCLUDE_JVMCI
1093 
1094 
1095 // restore elements of an eliminated type array
1096 void Deoptimization::reassign_type_array_elements(frame* fr, RegisterMap* reg_map, ObjectValue* sv, typeArrayOop obj, BasicType type) {
1097   int index = 0;
1098   intptr_t val;
1099 
1100   for (int i = 0; i < sv->field_size(); i++) {
1101     StackValue* value = StackValue::create_stack_value(fr, reg_map, sv->field_at(i));
1102     switch(type) {
1103     case T_LONG: case T_DOUBLE: {
1104       assert(value->type() == T_INT, "Agreement.");
1105       StackValue* low =
1106         StackValue::create_stack_value(fr, reg_map, sv->field_at(++i));
1107 #ifdef _LP64
1108       jlong res = (jlong)low->get_int();
1109 #else




1110       jlong res = jlong_from((jint)value->get_int(), (jint)low->get_int());

1111 #endif
1112       obj->long_at_put(index, res);
1113       break;
1114     }
1115 
1116     // Have to cast to INT (32 bits) pointer to avoid little/big-endian problem.
1117     case T_INT: case T_FLOAT: { // 4 bytes.
1118       assert(value->type() == T_INT, "Agreement.");
1119       bool big_value = false;
1120       if (i + 1 < sv->field_size() && type == T_INT) {
1121         if (sv->field_at(i)->is_location()) {
1122           Location::Type type = ((LocationValue*) sv->field_at(i))->location().type();
1123           if (type == Location::dbl || type == Location::lng) {
1124             big_value = true;
1125           }
1126         } else if (sv->field_at(i)->is_constant_int()) {
1127           ScopeValue* next_scope_field = sv->field_at(i + 1);
1128           if (next_scope_field->is_constant_long() || next_scope_field->is_constant_double()) {
1129             big_value = true;
1130           }
1131         }
1132       }
1133 
1134       if (big_value) {
1135         StackValue* low = StackValue::create_stack_value(fr, reg_map, sv->field_at(++i));
1136   #ifdef _LP64
1137         jlong res = (jlong)low->get_int();
1138   #else




1139         jlong res = jlong_from((jint)value->get_int(), (jint)low->get_int());

1140   #endif
1141         obj->int_at_put(index, (jint)*((jint*)&res));
1142         obj->int_at_put(++index, (jint)*(((jint*)&res) + 1));
1143       } else {
1144         val = value->get_int();
1145         obj->int_at_put(index, (jint)*((jint*)&val));
1146       }
1147       break;
1148     }
1149 
1150     case T_SHORT:
1151       assert(value->type() == T_INT, "Agreement.");
1152       val = value->get_int();
1153       obj->short_at_put(index, (jshort)*((jint*)&val));
1154       break;
1155 
1156     case T_CHAR:
1157       assert(value->type() == T_INT, "Agreement.");
1158       val = value->get_int();
1159       obj->char_at_put(index, (jchar)*((jint*)&val));


1264         }
1265 
1266         if (big_value) {
1267           i++;
1268           assert(i < fields->length(), "second T_INT field needed");
1269           assert(fields->at(i)._type == T_INT, "T_INT field needed");
1270         } else {
1271           val = value->get_int();
1272           obj->int_field_put(offset, (jint)*((jint*)&val));
1273           break;
1274         }
1275       }
1276         /* no break */
1277 
1278       case T_LONG: case T_DOUBLE: {
1279         assert(value->type() == T_INT, "Agreement.");
1280         StackValue* low = StackValue::create_stack_value(fr, reg_map, sv->field_at(++svIndex));
1281 #ifdef _LP64
1282         jlong res = (jlong)low->get_int();
1283 #else




1284         jlong res = jlong_from((jint)value->get_int(), (jint)low->get_int());

1285 #endif
1286         obj->long_field_put(offset, res);
1287         break;
1288       }
1289 
1290       case T_SHORT:
1291         assert(value->type() == T_INT, "Agreement.");
1292         val = value->get_int();
1293         obj->short_field_put(offset, (jshort)*((jint*)&val));
1294         break;
1295 
1296       case T_CHAR:
1297         assert(value->type() == T_INT, "Agreement.");
1298         val = value->get_int();
1299         obj->char_field_put(offset, (jchar)*((jint*)&val));
1300         break;
1301 
1302       case T_BYTE:
1303         assert(value->type() == T_INT, "Agreement.");
1304         val = value->get_int();


< prev index next >