Mercurial > hg > graal-jvmci-8
comparison src/share/vm/opto/stringopts.cpp @ 6057:8f972594effc
6924259: Remove String.count/String.offset
Summary: Allow a version of String class that doesn't have count and offset fields.
Reviewed-by: never, coleenp
author | kvn |
---|---|
date | Mon, 14 May 2012 09:36:00 -0700 |
parents | df3d4a91f7f6 |
children | 751bd303aa45 |
comparison
equal
deleted
inserted
replaced
6054:56d1af561395 | 6057:8f972594effc |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
526 assert(false, "why can't we find Integer.sizeTable?"); | 526 assert(false, "why can't we find Integer.sizeTable?"); |
527 return; | 527 return; |
528 } | 528 } |
529 | 529 |
530 // Collect the types needed to talk about the various slices of memory | 530 // Collect the types needed to talk about the various slices of memory |
531 const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(), | |
532 false, NULL, 0); | |
533 | |
534 const TypePtr* value_field_type = string_type->add_offset(java_lang_String::value_offset_in_bytes()); | |
535 const TypePtr* offset_field_type = string_type->add_offset(java_lang_String::offset_offset_in_bytes()); | |
536 const TypePtr* count_field_type = string_type->add_offset(java_lang_String::count_offset_in_bytes()); | |
537 | |
538 value_field_idx = C->get_alias_index(value_field_type); | |
539 count_field_idx = C->get_alias_index(count_field_type); | |
540 offset_field_idx = C->get_alias_index(offset_field_type); | |
541 char_adr_idx = C->get_alias_index(TypeAryPtr::CHARS); | 531 char_adr_idx = C->get_alias_index(TypeAryPtr::CHARS); |
542 | 532 |
543 // For each locally allocated StringBuffer see if the usages can be | 533 // For each locally allocated StringBuffer see if the usages can be |
544 // collapsed into a single String construction. | 534 // collapsed into a single String construction. |
545 | 535 |
1172 } | 1162 } |
1173 | 1163 |
1174 | 1164 |
1175 Node* PhaseStringOpts::copy_string(GraphKit& kit, Node* str, Node* char_array, Node* start) { | 1165 Node* PhaseStringOpts::copy_string(GraphKit& kit, Node* str, Node* char_array, Node* start) { |
1176 Node* string = str; | 1166 Node* string = str; |
1177 Node* offset = kit.make_load(kit.control(), | 1167 Node* offset = kit.load_String_offset(kit.control(), string); |
1178 kit.basic_plus_adr(string, string, java_lang_String::offset_offset_in_bytes()), | 1168 Node* count = kit.load_String_length(kit.control(), string); |
1179 TypeInt::INT, T_INT, offset_field_idx); | 1169 Node* value = kit.load_String_value (kit.control(), string); |
1180 Node* count = kit.make_load(kit.control(), | |
1181 kit.basic_plus_adr(string, string, java_lang_String::count_offset_in_bytes()), | |
1182 TypeInt::INT, T_INT, count_field_idx); | |
1183 const TypeAryPtr* value_type = TypeAryPtr::make(TypePtr::NotNull, | |
1184 TypeAry::make(TypeInt::CHAR,TypeInt::POS), | |
1185 ciTypeArrayKlass::make(T_CHAR), true, 0); | |
1186 Node* value = kit.make_load(kit.control(), | |
1187 kit.basic_plus_adr(string, string, java_lang_String::value_offset_in_bytes()), | |
1188 value_type, T_OBJECT, value_field_idx); | |
1189 | 1170 |
1190 // copy the contents | 1171 // copy the contents |
1191 if (offset->is_Con() && count->is_Con() && value->is_Con() && count->get_int() < unroll_string_copy_length) { | 1172 if (offset->is_Con() && count->is_Con() && value->is_Con() && count->get_int() < unroll_string_copy_length) { |
1192 // For small constant strings just emit individual stores. | 1173 // For small constant strings just emit individual stores. |
1193 // A length of 6 seems like a good space/speed tradeof. | 1174 // A length of 6 seems like a good space/speed tradeof. |
1340 C->record_for_igvn(phi); | 1321 C->record_for_igvn(phi); |
1341 // replace the argument with the null checked version | 1322 // replace the argument with the null checked version |
1342 arg = phi; | 1323 arg = phi; |
1343 sc->set_argument(argi, arg); | 1324 sc->set_argument(argi, arg); |
1344 } | 1325 } |
1345 // Node* offset = kit.make_load(NULL, kit.basic_plus_adr(arg, arg, offset_offset), | 1326 |
1346 // TypeInt::INT, T_INT, offset_field_idx); | 1327 Node* count = kit.load_String_length(kit.control(), arg); |
1347 Node* count = kit.make_load(kit.control(), kit.basic_plus_adr(arg, arg, java_lang_String::count_offset_in_bytes()), | 1328 |
1348 TypeInt::INT, T_INT, count_field_idx); | |
1349 length = __ AddI(length, count); | 1329 length = __ AddI(length, count); |
1350 string_sizes->init_req(argi, NULL); | 1330 string_sizes->init_req(argi, NULL); |
1351 break; | 1331 break; |
1352 } | 1332 } |
1353 case StringConcat::CharMode: { | 1333 case StringConcat::CharMode: { |
1434 kit.jvms()->set_should_reexecute(true); | 1414 kit.jvms()->set_should_reexecute(true); |
1435 result = kit.new_instance(__ makecon(TypeKlassPtr::make(C->env()->String_klass()))); | 1415 result = kit.new_instance(__ makecon(TypeKlassPtr::make(C->env()->String_klass()))); |
1436 } | 1416 } |
1437 | 1417 |
1438 // Intialize the string | 1418 // Intialize the string |
1439 kit.store_to_memory(kit.control(), kit.basic_plus_adr(result, java_lang_String::offset_offset_in_bytes()), | 1419 if (java_lang_String::has_offset_field()) { |
1440 __ intcon(0), T_INT, offset_field_idx); | 1420 kit.store_String_offset(kit.control(), result, __ intcon(0)); |
1441 kit.store_to_memory(kit.control(), kit.basic_plus_adr(result, java_lang_String::count_offset_in_bytes()), | 1421 kit.store_String_length(kit.control(), result, length); |
1442 length, T_INT, count_field_idx); | 1422 } |
1443 kit.store_to_memory(kit.control(), kit.basic_plus_adr(result, java_lang_String::value_offset_in_bytes()), | 1423 kit.store_String_value(kit.control(), result, char_array); |
1444 char_array, T_OBJECT, value_field_idx); | |
1445 | 1424 |
1446 // hook up the outgoing control and result | 1425 // hook up the outgoing control and result |
1447 kit.replace_call(sc->end(), result); | 1426 kit.replace_call(sc->end(), result); |
1448 | 1427 |
1449 // Unhook any hook nodes | 1428 // Unhook any hook nodes |