1066 * In the unlikely case index 0 is 5-aligned for example, it would then be possible to
1067 * write a long to index 3.
1068 */
1069 static jbyte* check_alignment_get_addr(typeArrayOop obj, int index, int expected_alignment) {
1070 jbyte* res = obj->byte_at_addr(index);
1071 assert((((intptr_t) res) % expected_alignment) == 0, "Non-aligned write");
1072 return res;
1073 }
1074
1075 static void byte_array_put(typeArrayOop obj, intptr_t val, int index, int byte_count) {
1076 switch (byte_count) {
1077 case 1:
1078 obj->byte_at_put(index, (jbyte) *((jint *) &val));
1079 break;
1080 case 2:
1081 *((jshort *) check_alignment_get_addr(obj, index, 2)) = (jshort) *((jint *) &val);
1082 break;
1083 case 4:
1084 *((jint *) check_alignment_get_addr(obj, index, 4)) = (jint) *((jint *) &val);
1085 break;
1086 case 8: {
1087 #ifdef _LP64
1088 jlong res = (jlong) *((jlong *) &val);
1089 #else
1090 #ifdef SPARC
1091 // For SPARC we have to swap high and low words.
1092 jlong v = (jlong) *((jlong *) &val);
1093 jlong res = 0;
1094 res |= ((v & (jlong) 0xffffffff) << 32);
1095 res |= ((v >> 32) & (jlong) 0xffffffff);
1096 #else
1097 jlong res = (jlong) *((jlong *) &val);
1098 #endif // SPARC
1099 #endif
1100 *((jlong *) check_alignment_get_addr(obj, index, 8)) = res;
1101 break;
1102 }
1103 default:
1104 ShouldNotReachHere();
1105 }
1106 }
1107 #endif // INCLUDE_JVMCI
1108
1109
1110 // restore elements of an eliminated type array
1111 void Deoptimization::reassign_type_array_elements(frame* fr, RegisterMap* reg_map, ObjectValue* sv, typeArrayOop obj, BasicType type) {
1112 int index = 0;
1113 intptr_t val;
1114
1115 for (int i = 0; i < sv->field_size(); i++) {
1116 StackValue* value = StackValue::create_stack_value(fr, reg_map, sv->field_at(i));
1117 switch(type) {
1118 case T_LONG: case T_DOUBLE: {
1119 assert(value->type() == T_INT, "Agreement.");
1120 StackValue* low =
1121 StackValue::create_stack_value(fr, reg_map, sv->field_at(++i));
1122 #ifdef _LP64
1123 jlong res = (jlong)low->get_int();
1124 #else
1125 #ifdef SPARC
1126 // For SPARC we have to swap high and low words.
1127 jlong res = jlong_from((jint)low->get_int(), (jint)value->get_int());
1128 #else
1129 jlong res = jlong_from((jint)value->get_int(), (jint)low->get_int());
1130 #endif //SPARC
1131 #endif
1132 obj->long_at_put(index, res);
1133 break;
1134 }
1135
1136 // Have to cast to INT (32 bits) pointer to avoid little/big-endian problem.
1137 case T_INT: case T_FLOAT: { // 4 bytes.
1138 assert(value->type() == T_INT, "Agreement.");
1139 bool big_value = false;
1140 if (i + 1 < sv->field_size() && type == T_INT) {
1141 if (sv->field_at(i)->is_location()) {
1142 Location::Type type = ((LocationValue*) sv->field_at(i))->location().type();
1143 if (type == Location::dbl || type == Location::lng) {
1144 big_value = true;
1145 }
1146 } else if (sv->field_at(i)->is_constant_int()) {
1147 ScopeValue* next_scope_field = sv->field_at(i + 1);
1148 if (next_scope_field->is_constant_long() || next_scope_field->is_constant_double()) {
1149 big_value = true;
1150 }
1151 }
1152 }
1153
1154 if (big_value) {
1155 StackValue* low = StackValue::create_stack_value(fr, reg_map, sv->field_at(++i));
1156 #ifdef _LP64
1157 jlong res = (jlong)low->get_int();
1158 #else
1159 #ifdef SPARC
1160 // For SPARC we have to swap high and low words.
1161 jlong res = jlong_from((jint)low->get_int(), (jint)value->get_int());
1162 #else
1163 jlong res = jlong_from((jint)value->get_int(), (jint)low->get_int());
1164 #endif //SPARC
1165 #endif
1166 obj->int_at_put(index, (jint)*((jint*)&res));
1167 obj->int_at_put(++index, (jint)*(((jint*)&res) + 1));
1168 } else {
1169 val = value->get_int();
1170 obj->int_at_put(index, (jint)*((jint*)&val));
1171 }
1172 break;
1173 }
1174
1175 case T_SHORT:
1176 assert(value->type() == T_INT, "Agreement.");
1177 val = value->get_int();
1178 obj->short_at_put(index, (jshort)*((jint*)&val));
1179 break;
1180
1181 case T_CHAR:
1182 assert(value->type() == T_INT, "Agreement.");
1183 val = value->get_int();
1184 obj->char_at_put(index, (jchar)*((jint*)&val));
1289 }
1290
1291 if (big_value) {
1292 i++;
1293 assert(i < fields->length(), "second T_INT field needed");
1294 assert(fields->at(i)._type == T_INT, "T_INT field needed");
1295 } else {
1296 val = value->get_int();
1297 obj->int_field_put(offset, (jint)*((jint*)&val));
1298 break;
1299 }
1300 }
1301 /* no break */
1302
1303 case T_LONG: case T_DOUBLE: {
1304 assert(value->type() == T_INT, "Agreement.");
1305 StackValue* low = StackValue::create_stack_value(fr, reg_map, sv->field_at(++svIndex));
1306 #ifdef _LP64
1307 jlong res = (jlong)low->get_int();
1308 #else
1309 #ifdef SPARC
1310 // For SPARC we have to swap high and low words.
1311 jlong res = jlong_from((jint)low->get_int(), (jint)value->get_int());
1312 #else
1313 jlong res = jlong_from((jint)value->get_int(), (jint)low->get_int());
1314 #endif //SPARC
1315 #endif
1316 obj->long_field_put(offset, res);
1317 break;
1318 }
1319
1320 case T_SHORT:
1321 assert(value->type() == T_INT, "Agreement.");
1322 val = value->get_int();
1323 obj->short_field_put(offset, (jshort)*((jint*)&val));
1324 break;
1325
1326 case T_CHAR:
1327 assert(value->type() == T_INT, "Agreement.");
1328 val = value->get_int();
1329 obj->char_field_put(offset, (jchar)*((jint*)&val));
1330 break;
1331
1332 case T_BYTE:
1333 assert(value->type() == T_INT, "Agreement.");
1334 val = value->get_int();
|
1066 * In the unlikely case index 0 is 5-aligned for example, it would then be possible to
1067 * write a long to index 3.
1068 */
1069 static jbyte* check_alignment_get_addr(typeArrayOop obj, int index, int expected_alignment) {
1070 jbyte* res = obj->byte_at_addr(index);
1071 assert((((intptr_t) res) % expected_alignment) == 0, "Non-aligned write");
1072 return res;
1073 }
1074
1075 static void byte_array_put(typeArrayOop obj, intptr_t val, int index, int byte_count) {
1076 switch (byte_count) {
1077 case 1:
1078 obj->byte_at_put(index, (jbyte) *((jint *) &val));
1079 break;
1080 case 2:
1081 *((jshort *) check_alignment_get_addr(obj, index, 2)) = (jshort) *((jint *) &val);
1082 break;
1083 case 4:
1084 *((jint *) check_alignment_get_addr(obj, index, 4)) = (jint) *((jint *) &val);
1085 break;
1086 case 8:
1087 *((jlong *) check_alignment_get_addr(obj, index, 8)) = (jlong) *((jlong *) &val);
1088 break;
1089 default:
1090 ShouldNotReachHere();
1091 }
1092 }
1093 #endif // INCLUDE_JVMCI
1094
1095
1096 // restore elements of an eliminated type array
1097 void Deoptimization::reassign_type_array_elements(frame* fr, RegisterMap* reg_map, ObjectValue* sv, typeArrayOop obj, BasicType type) {
1098 int index = 0;
1099 intptr_t val;
1100
1101 for (int i = 0; i < sv->field_size(); i++) {
1102 StackValue* value = StackValue::create_stack_value(fr, reg_map, sv->field_at(i));
1103 switch(type) {
1104 case T_LONG: case T_DOUBLE: {
1105 assert(value->type() == T_INT, "Agreement.");
1106 StackValue* low =
1107 StackValue::create_stack_value(fr, reg_map, sv->field_at(++i));
1108 #ifdef _LP64
1109 jlong res = (jlong)low->get_int();
1110 #else
1111 jlong res = jlong_from((jint)value->get_int(), (jint)low->get_int());
1112 #endif
1113 obj->long_at_put(index, res);
1114 break;
1115 }
1116
1117 // Have to cast to INT (32 bits) pointer to avoid little/big-endian problem.
1118 case T_INT: case T_FLOAT: { // 4 bytes.
1119 assert(value->type() == T_INT, "Agreement.");
1120 bool big_value = false;
1121 if (i + 1 < sv->field_size() && type == T_INT) {
1122 if (sv->field_at(i)->is_location()) {
1123 Location::Type type = ((LocationValue*) sv->field_at(i))->location().type();
1124 if (type == Location::dbl || type == Location::lng) {
1125 big_value = true;
1126 }
1127 } else if (sv->field_at(i)->is_constant_int()) {
1128 ScopeValue* next_scope_field = sv->field_at(i + 1);
1129 if (next_scope_field->is_constant_long() || next_scope_field->is_constant_double()) {
1130 big_value = true;
1131 }
1132 }
1133 }
1134
1135 if (big_value) {
1136 StackValue* low = StackValue::create_stack_value(fr, reg_map, sv->field_at(++i));
1137 #ifdef _LP64
1138 jlong res = (jlong)low->get_int();
1139 #else
1140 jlong res = jlong_from((jint)value->get_int(), (jint)low->get_int());
1141 #endif
1142 obj->int_at_put(index, (jint)*((jint*)&res));
1143 obj->int_at_put(++index, (jint)*(((jint*)&res) + 1));
1144 } else {
1145 val = value->get_int();
1146 obj->int_at_put(index, (jint)*((jint*)&val));
1147 }
1148 break;
1149 }
1150
1151 case T_SHORT:
1152 assert(value->type() == T_INT, "Agreement.");
1153 val = value->get_int();
1154 obj->short_at_put(index, (jshort)*((jint*)&val));
1155 break;
1156
1157 case T_CHAR:
1158 assert(value->type() == T_INT, "Agreement.");
1159 val = value->get_int();
1160 obj->char_at_put(index, (jchar)*((jint*)&val));
1265 }
1266
1267 if (big_value) {
1268 i++;
1269 assert(i < fields->length(), "second T_INT field needed");
1270 assert(fields->at(i)._type == T_INT, "T_INT field needed");
1271 } else {
1272 val = value->get_int();
1273 obj->int_field_put(offset, (jint)*((jint*)&val));
1274 break;
1275 }
1276 }
1277 /* no break */
1278
1279 case T_LONG: case T_DOUBLE: {
1280 assert(value->type() == T_INT, "Agreement.");
1281 StackValue* low = StackValue::create_stack_value(fr, reg_map, sv->field_at(++svIndex));
1282 #ifdef _LP64
1283 jlong res = (jlong)low->get_int();
1284 #else
1285 jlong res = jlong_from((jint)value->get_int(), (jint)low->get_int());
1286 #endif
1287 obj->long_field_put(offset, res);
1288 break;
1289 }
1290
1291 case T_SHORT:
1292 assert(value->type() == T_INT, "Agreement.");
1293 val = value->get_int();
1294 obj->short_field_put(offset, (jshort)*((jint*)&val));
1295 break;
1296
1297 case T_CHAR:
1298 assert(value->type() == T_INT, "Agreement.");
1299 val = value->get_int();
1300 obj->char_field_put(offset, (jchar)*((jint*)&val));
1301 break;
1302
1303 case T_BYTE:
1304 assert(value->type() == T_INT, "Agreement.");
1305 val = value->get_int();
|