src/share/vm/opto/stringopts.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8034812 Sdiff src/share/vm/opto

src/share/vm/opto/stringopts.cpp

Print this page




  53   Node_List           _constructors;   // List of constructors (many in case of stacked concat)
  54   Node_List           _control;        // List of control nodes that will be deleted
  55   Node_List           _uncommon_traps; // Uncommon traps that needs to be rewritten
  56                                        // to restart at the initial JVMState.
  57 
  58  public:
  59   // Mode for converting arguments to Strings
  60   enum {
  61     StringMode,
  62     IntMode,
  63     CharMode,
  64     StringNullCheckMode
  65   };
  66 
  67   StringConcat(PhaseStringOpts* stringopts, CallStaticJavaNode* end):
  68     _end(end),
  69     _begin(NULL),
  70     _multiple(false),
  71     _string_alloc(NULL),
  72     _stringopts(stringopts) {
  73     _arguments = new (_stringopts->C) Node(1);
  74     _arguments->del_req(0);
  75   }
  76 
  77   bool validate_mem_flow();
  78   bool validate_control_flow();
  79 
  80   void merge_add() {
  81 #if 0
  82     // XXX This is place holder code for reusing an existing String
  83     // allocation but the logic for checking the state safety is
  84     // probably inadequate at the moment.
  85     CallProjections endprojs;
  86     sc->end()->extract_projections(&endprojs, false);
  87     if (endprojs.resproj != NULL) {
  88       for (SimpleDUIterator i(endprojs.resproj); i.has_next(); i.next()) {
  89         CallStaticJavaNode *use = i.get()->isa_CallStaticJava();
  90         if (use != NULL && use->method() != NULL &&
  91             use->method()->intrinsic_id() == vmIntrinsics::_String_String &&
  92             use->in(TypeFunc::Parms + 1) == endprojs.resproj) {
  93           // Found useless new String(sb.toString()) so reuse the newly allocated String


 211                 _string_alloc != NULL,
 212                 _multiple);
 213       JVMState* p = _begin->jvms();
 214       while (p != NULL) {
 215         log->elem("jvms bci='%d' method='%d'", p->bci(), log->identify(p->method()));
 216         p = p->caller();
 217       }
 218       log->tail("replace_string_concat");
 219     }
 220   }
 221 
 222   void convert_uncommon_traps(GraphKit& kit, const JVMState* jvms) {
 223     for (uint u = 0; u < _uncommon_traps.size(); u++) {
 224       Node* uct = _uncommon_traps.at(u);
 225 
 226       // Build a new call using the jvms state of the allocate
 227       address call_addr = SharedRuntime::uncommon_trap_blob()->entry_point();
 228       const TypeFunc* call_type = OptoRuntime::uncommon_trap_Type();
 229       const TypePtr* no_memory_effects = NULL;
 230       Compile* C = _stringopts->C;
 231       CallStaticJavaNode* call = new (C) CallStaticJavaNode(call_type, call_addr, "uncommon_trap",
 232                                                             jvms->bci(), no_memory_effects);
 233       for (int e = 0; e < TypeFunc::Parms; e++) {
 234         call->init_req(e, uct->in(e));
 235       }
 236       // Set the trap request to record intrinsic failure if this trap
 237       // is taken too many times.  Ideally we would handle then traps by
 238       // doing the original bookkeeping in the MDO so that if it caused
 239       // the code to be thrown out we could still recompile and use the
 240       // optimization.  Failing the uncommon traps doesn't really mean
 241       // that the optimization is a bad idea but there's no other way to
 242       // do the MDO updates currently.
 243       int trap_request = Deoptimization::make_trap_request(Deoptimization::Reason_intrinsic,
 244                                                            Deoptimization::Action_make_not_entrant);
 245       call->init_req(TypeFunc::Parms, __ intcon(trap_request));
 246       kit.add_safepoint_edges(call);
 247 
 248       _stringopts->gvn()->transform(call);
 249       C->gvn_replace_by(uct, call);
 250       uct->disconnect_inputs(NULL, C);
 251     }


1110       ciObject* con = field->constant_value().as_object();
1111       // Do not "join" in the previous type; it doesn't add value,
1112       // and may yield a vacuous result if the field is of interface type.
1113       type = TypeOopPtr::make_from_constant(con, true)->isa_oopptr();
1114       assert(type != NULL, "field singleton type must be consistent");
1115       return __ makecon(type);
1116     } else {
1117       type = TypeOopPtr::make_from_klass(field_klass->as_klass());
1118     }
1119   } else {
1120     type = Type::get_const_basic_type(bt);
1121   }
1122 
1123   return kit.make_load(NULL, kit.basic_plus_adr(klass_node, field->offset_in_bytes()),
1124                        type, T_OBJECT,
1125                        C->get_alias_index(mirror_type->add_offset(field->offset_in_bytes())),
1126                        MemNode::unordered);
1127 }
1128 
1129 Node* PhaseStringOpts::int_stringSize(GraphKit& kit, Node* arg) {
1130   RegionNode *final_merge = new (C) RegionNode(3);
1131   kit.gvn().set_type(final_merge, Type::CONTROL);
1132   Node* final_size = new (C) PhiNode(final_merge, TypeInt::INT);
1133   kit.gvn().set_type(final_size, TypeInt::INT);
1134 
1135   IfNode* iff = kit.create_and_map_if(kit.control(),
1136                                       __ Bool(__ CmpI(arg, __ intcon(0x80000000)), BoolTest::ne),
1137                                       PROB_FAIR, COUNT_UNKNOWN);
1138   Node* is_min = __ IfFalse(iff);
1139   final_merge->init_req(1, is_min);
1140   final_size->init_req(1, __ intcon(11));
1141 
1142   kit.set_control(__ IfTrue(iff));
1143   if (kit.stopped()) {
1144     final_merge->init_req(2, C->top());
1145     final_size->init_req(2, C->top());
1146   } else {
1147 
1148     // int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
1149     RegionNode *r = new (C) RegionNode(3);
1150     kit.gvn().set_type(r, Type::CONTROL);
1151     Node *phi = new (C) PhiNode(r, TypeInt::INT);
1152     kit.gvn().set_type(phi, TypeInt::INT);
1153     Node *size = new (C) PhiNode(r, TypeInt::INT);
1154     kit.gvn().set_type(size, TypeInt::INT);
1155     Node* chk = __ CmpI(arg, __ intcon(0));
1156     Node* p = __ Bool(chk, BoolTest::lt);
1157     IfNode* iff = kit.create_and_map_if(kit.control(), p, PROB_FAIR, COUNT_UNKNOWN);
1158     Node* lessthan = __ IfTrue(iff);
1159     Node* greaterequal = __ IfFalse(iff);
1160     r->init_req(1, lessthan);
1161     phi->init_req(1, __ SubI(__ intcon(0), arg));
1162     size->init_req(1, __ intcon(1));
1163     r->init_req(2, greaterequal);
1164     phi->init_req(2, arg);
1165     size->init_req(2, __ intcon(0));
1166     kit.set_control(r);
1167     C->record_for_igvn(r);
1168     C->record_for_igvn(phi);
1169     C->record_for_igvn(size);
1170 
1171     // for (int i=0; ; i++)
1172     //   if (x <= sizeTable[i])
1173     //     return i+1;
1174 
1175     // Add loop predicate first.
1176     kit.add_predicate();
1177 
1178     RegionNode *loop = new (C) RegionNode(3);
1179     loop->init_req(1, kit.control());
1180     kit.gvn().set_type(loop, Type::CONTROL);
1181 
1182     Node *index = new (C) PhiNode(loop, TypeInt::INT);
1183     index->init_req(1, __ intcon(0));
1184     kit.gvn().set_type(index, TypeInt::INT);
1185     kit.set_control(loop);
1186     Node* sizeTable = fetch_static_field(kit, size_table_field);
1187 
1188     Node* value = kit.load_array_element(NULL, sizeTable, index, TypeAryPtr::INTS);
1189     C->record_for_igvn(value);
1190     Node* limit = __ CmpI(phi, value);
1191     Node* limitb = __ Bool(limit, BoolTest::le);
1192     IfNode* iff2 = kit.create_and_map_if(kit.control(), limitb, PROB_MIN, COUNT_UNKNOWN);
1193     Node* lessEqual = __ IfTrue(iff2);
1194     Node* greater = __ IfFalse(iff2);
1195 
1196     loop->init_req(2, greater);
1197     index->init_req(2, __ AddI(index, __ intcon(1)));
1198 
1199     kit.set_control(lessEqual);
1200     C->record_for_igvn(loop);
1201     C->record_for_igvn(index);
1202 
1203     final_merge->init_req(2, kit.control());
1204     final_size->init_req(2, __ AddI(__ AddI(index, size), __ intcon(1)));
1205   }
1206 
1207   kit.set_control(final_merge);
1208   C->record_for_igvn(final_merge);
1209   C->record_for_igvn(final_size);
1210 
1211   return final_size;
1212 }
1213 
1214 void PhaseStringOpts::int_getChars(GraphKit& kit, Node* arg, Node* char_array, Node* start, Node* end) {
1215   RegionNode *final_merge = new (C) RegionNode(4);
1216   kit.gvn().set_type(final_merge, Type::CONTROL);
1217   Node *final_mem = PhiNode::make(final_merge, kit.memory(char_adr_idx), Type::MEMORY, TypeAryPtr::CHARS);
1218   kit.gvn().set_type(final_mem, Type::MEMORY);
1219 
1220   // need to handle Integer.MIN_VALUE specially because negating doesn't make it positive
1221   {
1222     // i == MIN_VALUE
1223     IfNode* iff = kit.create_and_map_if(kit.control(),
1224                                         __ Bool(__ CmpI(arg, __ intcon(0x80000000)), BoolTest::ne),
1225                                         PROB_FAIR, COUNT_UNKNOWN);
1226 
1227     Node* old_mem = kit.memory(char_adr_idx);
1228 
1229     kit.set_control(__ IfFalse(iff));
1230     if (kit.stopped()) {
1231       // Statically not equal to MIN_VALUE so this path is dead
1232       final_merge->init_req(3, kit.control());
1233     } else {
1234       copy_string(kit, __ makecon(TypeInstPtr::make(C->env()->the_min_jint_string())),
1235                   char_array, start);


1245   // Simplified version of Integer.getChars
1246 
1247   // int q, r;
1248   // int charPos = index;
1249   Node* charPos = end;
1250 
1251   // char sign = 0;
1252 
1253   Node* i = arg;
1254   Node* sign = __ intcon(0);
1255 
1256   // if (i < 0) {
1257   //     sign = '-';
1258   //     i = -i;
1259   // }
1260   {
1261     IfNode* iff = kit.create_and_map_if(kit.control(),
1262                                         __ Bool(__ CmpI(arg, __ intcon(0)), BoolTest::lt),
1263                                         PROB_FAIR, COUNT_UNKNOWN);
1264 
1265     RegionNode *merge = new (C) RegionNode(3);
1266     kit.gvn().set_type(merge, Type::CONTROL);
1267     i = new (C) PhiNode(merge, TypeInt::INT);
1268     kit.gvn().set_type(i, TypeInt::INT);
1269     sign = new (C) PhiNode(merge, TypeInt::INT);
1270     kit.gvn().set_type(sign, TypeInt::INT);
1271 
1272     merge->init_req(1, __ IfTrue(iff));
1273     i->init_req(1, __ SubI(__ intcon(0), arg));
1274     sign->init_req(1, __ intcon('-'));
1275     merge->init_req(2, __ IfFalse(iff));
1276     i->init_req(2, arg);
1277     sign->init_req(2, __ intcon(0));
1278 
1279     kit.set_control(merge);
1280 
1281     C->record_for_igvn(merge);
1282     C->record_for_igvn(i);
1283     C->record_for_igvn(sign);
1284   }
1285 
1286   // for (;;) {
1287   //     q = i / 10;
1288   //     r = i - ((q << 3) + (q << 1));  // r = i-(q*10) ...
1289   //     buf [--charPos] = digits [r];
1290   //     i = q;
1291   //     if (i == 0) break;
1292   // }
1293 
1294   {
1295     // Add loop predicate first.
1296     kit.add_predicate();
1297 
1298     RegionNode *head = new (C) RegionNode(3);
1299     head->init_req(1, kit.control());
1300     kit.gvn().set_type(head, Type::CONTROL);
1301     Node *i_phi = new (C) PhiNode(head, TypeInt::INT);
1302     i_phi->init_req(1, i);
1303     kit.gvn().set_type(i_phi, TypeInt::INT);
1304     charPos = PhiNode::make(head, charPos);
1305     kit.gvn().set_type(charPos, TypeInt::INT);
1306     Node *mem = PhiNode::make(head, kit.memory(char_adr_idx), Type::MEMORY, TypeAryPtr::CHARS);
1307     kit.gvn().set_type(mem, Type::MEMORY);
1308     kit.set_control(head);
1309     kit.set_memory(mem, char_adr_idx);
1310 
1311     Node* q = __ DivI(NULL, i_phi, __ intcon(10));
1312     Node* r = __ SubI(i_phi, __ AddI(__ LShiftI(q, __ intcon(3)),
1313                                      __ LShiftI(q, __ intcon(1))));
1314     Node* m1 = __ SubI(charPos, __ intcon(1));
1315     Node* ch = __ AddI(r, __ intcon('0'));
1316 
1317     Node* st = __ store_to_memory(kit.control(), kit.array_element_address(char_array, m1, T_CHAR),
1318                                   ch, T_CHAR, char_adr_idx, MemNode::unordered);
1319 
1320 
1321     IfNode* iff = kit.create_and_map_if(head, __ Bool(__ CmpI(q, __ intcon(0)), BoolTest::ne),


1403 #endif
1404     Node* call = kit.make_runtime_call(GraphKit::RC_LEAF|GraphKit::RC_NO_FP,
1405                                        OptoRuntime::fast_arraycopy_Type(),
1406                                        CAST_FROM_FN_PTR(address, StubRoutines::jshort_disjoint_arraycopy()),
1407                                        "jshort_disjoint_arraycopy", TypeAryPtr::CHARS,
1408                                        src_ptr, dst_ptr, c, extra);
1409     start = __ AddI(start, count);
1410   }
1411   return start;
1412 }
1413 
1414 
1415 void PhaseStringOpts::replace_string_concat(StringConcat* sc) {
1416   // Log a little info about the transformation
1417   sc->maybe_log_transform();
1418 
1419   // pull the JVMState of the allocation into a SafePointNode to serve as
1420   // as a shim for the insertion of the new code.
1421   JVMState* jvms     = sc->begin()->jvms()->clone_shallow(C);
1422   uint size = sc->begin()->req();
1423   SafePointNode* map = new (C) SafePointNode(size, jvms);
1424 
1425   // copy the control and memory state from the final call into our
1426   // new starting state.  This allows any preceeding tests to feed
1427   // into the new section of code.
1428   for (uint i1 = 0; i1 < TypeFunc::Parms; i1++) {
1429     map->init_req(i1, sc->end()->in(i1));
1430   }
1431   // blow away old allocation arguments
1432   for (uint i1 = TypeFunc::Parms; i1 < jvms->debug_start(); i1++) {
1433     map->init_req(i1, C->top());
1434   }
1435   // Copy the rest of the inputs for the JVMState
1436   for (uint i1 = jvms->debug_start(); i1 < sc->begin()->req(); i1++) {
1437     map->init_req(i1, sc->begin()->in(i1));
1438   }
1439   // Make sure the memory state is a MergeMem for parsing.
1440   if (!map->in(TypeFunc::Memory)->is_MergeMem()) {
1441     map->set_req(TypeFunc::Memory, MergeMemNode::make(C, map->in(TypeFunc::Memory)));
1442   }
1443 


1448   // disconnect all the old StringBuilder calls from the graph
1449   sc->eliminate_unneeded_control();
1450 
1451   // At this point all the old work has been completely removed from
1452   // the graph and the saved JVMState exists at the point where the
1453   // final toString call used to be.
1454   GraphKit kit(jvms);
1455 
1456   // There may be uncommon traps which are still using the
1457   // intermediate states and these need to be rewritten to point at
1458   // the JVMState at the beginning of the transformation.
1459   sc->convert_uncommon_traps(kit, jvms);
1460 
1461   // Now insert the logic to compute the size of the string followed
1462   // by all the logic to construct array and resulting string.
1463 
1464   Node* null_string = __ makecon(TypeInstPtr::make(C->env()->the_null_string()));
1465 
1466   // Create a region for the overflow checks to merge into.
1467   int args = MAX2(sc->num_arguments(), 1);
1468   RegionNode* overflow = new (C) RegionNode(args);
1469   kit.gvn().set_type(overflow, Type::CONTROL);
1470 
1471   // Create a hook node to hold onto the individual sizes since they
1472   // are need for the copying phase.
1473   Node* string_sizes = new (C) Node(args);
1474 
1475   Node* length = __ intcon(0);
1476   for (int argi = 0; argi < sc->num_arguments(); argi++) {
1477     Node* arg = sc->argument(argi);
1478     switch (sc->mode(argi)) {
1479       case StringConcat::IntMode: {
1480         Node* string_size = int_stringSize(kit, arg);
1481 
1482         // accumulate total
1483         length = __ AddI(length, string_size);
1484 
1485         // Cache this value for the use by int_toString
1486         string_sizes->init_req(argi, string_size);
1487         break;
1488       }
1489       case StringConcat::StringNullCheckMode: {
1490         const Type* type = kit.gvn().type(arg);
1491         assert(type != TypePtr::NULL_PTR, "missing check");
1492         if (!type->higher_equal(TypeInstPtr::NOTNULL)) {
1493           // Null check with uncommont trap since


1497           Node* p = __ Bool(__ CmpP(arg, kit.null()), BoolTest::ne);
1498           IfNode* iff = kit.create_and_map_if(kit.control(), p, PROB_MIN, COUNT_UNKNOWN);
1499           overflow->add_req(__ IfFalse(iff));
1500           Node* notnull = __ IfTrue(iff);
1501           kit.set_control(notnull); // set control for the cast_not_null
1502           arg = kit.cast_not_null(arg, false);
1503           sc->set_argument(argi, arg);
1504         }
1505         assert(kit.gvn().type(arg)->higher_equal(TypeInstPtr::NOTNULL), "sanity");
1506         // Fallthrough to add string length.
1507       }
1508       case StringConcat::StringMode: {
1509         const Type* type = kit.gvn().type(arg);
1510         if (type == TypePtr::NULL_PTR) {
1511           // replace the argument with the null checked version
1512           arg = null_string;
1513           sc->set_argument(argi, arg);
1514         } else if (!type->higher_equal(TypeInstPtr::NOTNULL)) {
1515           // s = s != null ? s : "null";
1516           // length = length + (s.count - s.offset);
1517           RegionNode *r = new (C) RegionNode(3);
1518           kit.gvn().set_type(r, Type::CONTROL);
1519           Node *phi = new (C) PhiNode(r, type);
1520           kit.gvn().set_type(phi, phi->bottom_type());
1521           Node* p = __ Bool(__ CmpP(arg, kit.null()), BoolTest::ne);
1522           IfNode* iff = kit.create_and_map_if(kit.control(), p, PROB_MIN, COUNT_UNKNOWN);
1523           Node* notnull = __ IfTrue(iff);
1524           Node* isnull =  __ IfFalse(iff);
1525           kit.set_control(notnull); // set control for the cast_not_null
1526           r->init_req(1, notnull);
1527           phi->init_req(1, kit.cast_not_null(arg, false));
1528           r->init_req(2, isnull);
1529           phi->init_req(2, null_string);
1530           kit.set_control(r);
1531           C->record_for_igvn(r);
1532           C->record_for_igvn(phi);
1533           // replace the argument with the null checked version
1534           arg = phi;
1535           sc->set_argument(argi, arg);
1536         }
1537 
1538         Node* count = kit.load_String_length(kit.control(), arg);
1539 




  53   Node_List           _constructors;   // List of constructors (many in case of stacked concat)
  54   Node_List           _control;        // List of control nodes that will be deleted
  55   Node_List           _uncommon_traps; // Uncommon traps that needs to be rewritten
  56                                        // to restart at the initial JVMState.
  57 
  58  public:
  59   // Mode for converting arguments to Strings
  60   enum {
  61     StringMode,
  62     IntMode,
  63     CharMode,
  64     StringNullCheckMode
  65   };
  66 
  67   StringConcat(PhaseStringOpts* stringopts, CallStaticJavaNode* end):
  68     _end(end),
  69     _begin(NULL),
  70     _multiple(false),
  71     _string_alloc(NULL),
  72     _stringopts(stringopts) {
  73     _arguments = new Node(1);
  74     _arguments->del_req(0);
  75   }
  76 
  77   bool validate_mem_flow();
  78   bool validate_control_flow();
  79 
  80   void merge_add() {
  81 #if 0
  82     // XXX This is place holder code for reusing an existing String
  83     // allocation but the logic for checking the state safety is
  84     // probably inadequate at the moment.
  85     CallProjections endprojs;
  86     sc->end()->extract_projections(&endprojs, false);
  87     if (endprojs.resproj != NULL) {
  88       for (SimpleDUIterator i(endprojs.resproj); i.has_next(); i.next()) {
  89         CallStaticJavaNode *use = i.get()->isa_CallStaticJava();
  90         if (use != NULL && use->method() != NULL &&
  91             use->method()->intrinsic_id() == vmIntrinsics::_String_String &&
  92             use->in(TypeFunc::Parms + 1) == endprojs.resproj) {
  93           // Found useless new String(sb.toString()) so reuse the newly allocated String


 211                 _string_alloc != NULL,
 212                 _multiple);
 213       JVMState* p = _begin->jvms();
 214       while (p != NULL) {
 215         log->elem("jvms bci='%d' method='%d'", p->bci(), log->identify(p->method()));
 216         p = p->caller();
 217       }
 218       log->tail("replace_string_concat");
 219     }
 220   }
 221 
 222   void convert_uncommon_traps(GraphKit& kit, const JVMState* jvms) {
 223     for (uint u = 0; u < _uncommon_traps.size(); u++) {
 224       Node* uct = _uncommon_traps.at(u);
 225 
 226       // Build a new call using the jvms state of the allocate
 227       address call_addr = SharedRuntime::uncommon_trap_blob()->entry_point();
 228       const TypeFunc* call_type = OptoRuntime::uncommon_trap_Type();
 229       const TypePtr* no_memory_effects = NULL;
 230       Compile* C = _stringopts->C;
 231       CallStaticJavaNode* call = new CallStaticJavaNode(call_type, call_addr, "uncommon_trap",
 232                                                         jvms->bci(), no_memory_effects);
 233       for (int e = 0; e < TypeFunc::Parms; e++) {
 234         call->init_req(e, uct->in(e));
 235       }
 236       // Set the trap request to record intrinsic failure if this trap
 237       // is taken too many times.  Ideally we would handle then traps by
 238       // doing the original bookkeeping in the MDO so that if it caused
 239       // the code to be thrown out we could still recompile and use the
 240       // optimization.  Failing the uncommon traps doesn't really mean
 241       // that the optimization is a bad idea but there's no other way to
 242       // do the MDO updates currently.
 243       int trap_request = Deoptimization::make_trap_request(Deoptimization::Reason_intrinsic,
 244                                                            Deoptimization::Action_make_not_entrant);
 245       call->init_req(TypeFunc::Parms, __ intcon(trap_request));
 246       kit.add_safepoint_edges(call);
 247 
 248       _stringopts->gvn()->transform(call);
 249       C->gvn_replace_by(uct, call);
 250       uct->disconnect_inputs(NULL, C);
 251     }


1110       ciObject* con = field->constant_value().as_object();
1111       // Do not "join" in the previous type; it doesn't add value,
1112       // and may yield a vacuous result if the field is of interface type.
1113       type = TypeOopPtr::make_from_constant(con, true)->isa_oopptr();
1114       assert(type != NULL, "field singleton type must be consistent");
1115       return __ makecon(type);
1116     } else {
1117       type = TypeOopPtr::make_from_klass(field_klass->as_klass());
1118     }
1119   } else {
1120     type = Type::get_const_basic_type(bt);
1121   }
1122 
1123   return kit.make_load(NULL, kit.basic_plus_adr(klass_node, field->offset_in_bytes()),
1124                        type, T_OBJECT,
1125                        C->get_alias_index(mirror_type->add_offset(field->offset_in_bytes())),
1126                        MemNode::unordered);
1127 }
1128 
1129 Node* PhaseStringOpts::int_stringSize(GraphKit& kit, Node* arg) {
1130   RegionNode *final_merge = new RegionNode(3);
1131   kit.gvn().set_type(final_merge, Type::CONTROL);
1132   Node* final_size = new PhiNode(final_merge, TypeInt::INT);
1133   kit.gvn().set_type(final_size, TypeInt::INT);
1134 
1135   IfNode* iff = kit.create_and_map_if(kit.control(),
1136                                       __ Bool(__ CmpI(arg, __ intcon(0x80000000)), BoolTest::ne),
1137                                       PROB_FAIR, COUNT_UNKNOWN);
1138   Node* is_min = __ IfFalse(iff);
1139   final_merge->init_req(1, is_min);
1140   final_size->init_req(1, __ intcon(11));
1141 
1142   kit.set_control(__ IfTrue(iff));
1143   if (kit.stopped()) {
1144     final_merge->init_req(2, C->top());
1145     final_size->init_req(2, C->top());
1146   } else {
1147 
1148     // int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
1149     RegionNode *r = new RegionNode(3);
1150     kit.gvn().set_type(r, Type::CONTROL);
1151     Node *phi = new PhiNode(r, TypeInt::INT);
1152     kit.gvn().set_type(phi, TypeInt::INT);
1153     Node *size = new PhiNode(r, TypeInt::INT);
1154     kit.gvn().set_type(size, TypeInt::INT);
1155     Node* chk = __ CmpI(arg, __ intcon(0));
1156     Node* p = __ Bool(chk, BoolTest::lt);
1157     IfNode* iff = kit.create_and_map_if(kit.control(), p, PROB_FAIR, COUNT_UNKNOWN);
1158     Node* lessthan = __ IfTrue(iff);
1159     Node* greaterequal = __ IfFalse(iff);
1160     r->init_req(1, lessthan);
1161     phi->init_req(1, __ SubI(__ intcon(0), arg));
1162     size->init_req(1, __ intcon(1));
1163     r->init_req(2, greaterequal);
1164     phi->init_req(2, arg);
1165     size->init_req(2, __ intcon(0));
1166     kit.set_control(r);
1167     C->record_for_igvn(r);
1168     C->record_for_igvn(phi);
1169     C->record_for_igvn(size);
1170 
1171     // for (int i=0; ; i++)
1172     //   if (x <= sizeTable[i])
1173     //     return i+1;
1174 
1175     // Add loop predicate first.
1176     kit.add_predicate();
1177 
1178     RegionNode *loop = new RegionNode(3);
1179     loop->init_req(1, kit.control());
1180     kit.gvn().set_type(loop, Type::CONTROL);
1181 
1182     Node *index = new PhiNode(loop, TypeInt::INT);
1183     index->init_req(1, __ intcon(0));
1184     kit.gvn().set_type(index, TypeInt::INT);
1185     kit.set_control(loop);
1186     Node* sizeTable = fetch_static_field(kit, size_table_field);
1187 
1188     Node* value = kit.load_array_element(NULL, sizeTable, index, TypeAryPtr::INTS);
1189     C->record_for_igvn(value);
1190     Node* limit = __ CmpI(phi, value);
1191     Node* limitb = __ Bool(limit, BoolTest::le);
1192     IfNode* iff2 = kit.create_and_map_if(kit.control(), limitb, PROB_MIN, COUNT_UNKNOWN);
1193     Node* lessEqual = __ IfTrue(iff2);
1194     Node* greater = __ IfFalse(iff2);
1195 
1196     loop->init_req(2, greater);
1197     index->init_req(2, __ AddI(index, __ intcon(1)));
1198 
1199     kit.set_control(lessEqual);
1200     C->record_for_igvn(loop);
1201     C->record_for_igvn(index);
1202 
1203     final_merge->init_req(2, kit.control());
1204     final_size->init_req(2, __ AddI(__ AddI(index, size), __ intcon(1)));
1205   }
1206 
1207   kit.set_control(final_merge);
1208   C->record_for_igvn(final_merge);
1209   C->record_for_igvn(final_size);
1210 
1211   return final_size;
1212 }
1213 
1214 void PhaseStringOpts::int_getChars(GraphKit& kit, Node* arg, Node* char_array, Node* start, Node* end) {
1215   RegionNode *final_merge = new RegionNode(4);
1216   kit.gvn().set_type(final_merge, Type::CONTROL);
1217   Node *final_mem = PhiNode::make(final_merge, kit.memory(char_adr_idx), Type::MEMORY, TypeAryPtr::CHARS);
1218   kit.gvn().set_type(final_mem, Type::MEMORY);
1219 
1220   // need to handle Integer.MIN_VALUE specially because negating doesn't make it positive
1221   {
1222     // i == MIN_VALUE
1223     IfNode* iff = kit.create_and_map_if(kit.control(),
1224                                         __ Bool(__ CmpI(arg, __ intcon(0x80000000)), BoolTest::ne),
1225                                         PROB_FAIR, COUNT_UNKNOWN);
1226 
1227     Node* old_mem = kit.memory(char_adr_idx);
1228 
1229     kit.set_control(__ IfFalse(iff));
1230     if (kit.stopped()) {
1231       // Statically not equal to MIN_VALUE so this path is dead
1232       final_merge->init_req(3, kit.control());
1233     } else {
1234       copy_string(kit, __ makecon(TypeInstPtr::make(C->env()->the_min_jint_string())),
1235                   char_array, start);


1245   // Simplified version of Integer.getChars
1246 
1247   // int q, r;
1248   // int charPos = index;
1249   Node* charPos = end;
1250 
1251   // char sign = 0;
1252 
1253   Node* i = arg;
1254   Node* sign = __ intcon(0);
1255 
1256   // if (i < 0) {
1257   //     sign = '-';
1258   //     i = -i;
1259   // }
1260   {
1261     IfNode* iff = kit.create_and_map_if(kit.control(),
1262                                         __ Bool(__ CmpI(arg, __ intcon(0)), BoolTest::lt),
1263                                         PROB_FAIR, COUNT_UNKNOWN);
1264 
1265     RegionNode *merge = new RegionNode(3);
1266     kit.gvn().set_type(merge, Type::CONTROL);
1267     i = new PhiNode(merge, TypeInt::INT);
1268     kit.gvn().set_type(i, TypeInt::INT);
1269     sign = new PhiNode(merge, TypeInt::INT);
1270     kit.gvn().set_type(sign, TypeInt::INT);
1271 
1272     merge->init_req(1, __ IfTrue(iff));
1273     i->init_req(1, __ SubI(__ intcon(0), arg));
1274     sign->init_req(1, __ intcon('-'));
1275     merge->init_req(2, __ IfFalse(iff));
1276     i->init_req(2, arg);
1277     sign->init_req(2, __ intcon(0));
1278 
1279     kit.set_control(merge);
1280 
1281     C->record_for_igvn(merge);
1282     C->record_for_igvn(i);
1283     C->record_for_igvn(sign);
1284   }
1285 
1286   // for (;;) {
1287   //     q = i / 10;
1288   //     r = i - ((q << 3) + (q << 1));  // r = i-(q*10) ...
1289   //     buf [--charPos] = digits [r];
1290   //     i = q;
1291   //     if (i == 0) break;
1292   // }
1293 
1294   {
1295     // Add loop predicate first.
1296     kit.add_predicate();
1297 
1298     RegionNode *head = new RegionNode(3);
1299     head->init_req(1, kit.control());
1300     kit.gvn().set_type(head, Type::CONTROL);
1301     Node *i_phi = new PhiNode(head, TypeInt::INT);
1302     i_phi->init_req(1, i);
1303     kit.gvn().set_type(i_phi, TypeInt::INT);
1304     charPos = PhiNode::make(head, charPos);
1305     kit.gvn().set_type(charPos, TypeInt::INT);
1306     Node *mem = PhiNode::make(head, kit.memory(char_adr_idx), Type::MEMORY, TypeAryPtr::CHARS);
1307     kit.gvn().set_type(mem, Type::MEMORY);
1308     kit.set_control(head);
1309     kit.set_memory(mem, char_adr_idx);
1310 
1311     Node* q = __ DivI(NULL, i_phi, __ intcon(10));
1312     Node* r = __ SubI(i_phi, __ AddI(__ LShiftI(q, __ intcon(3)),
1313                                      __ LShiftI(q, __ intcon(1))));
1314     Node* m1 = __ SubI(charPos, __ intcon(1));
1315     Node* ch = __ AddI(r, __ intcon('0'));
1316 
1317     Node* st = __ store_to_memory(kit.control(), kit.array_element_address(char_array, m1, T_CHAR),
1318                                   ch, T_CHAR, char_adr_idx, MemNode::unordered);
1319 
1320 
1321     IfNode* iff = kit.create_and_map_if(head, __ Bool(__ CmpI(q, __ intcon(0)), BoolTest::ne),


1403 #endif
1404     Node* call = kit.make_runtime_call(GraphKit::RC_LEAF|GraphKit::RC_NO_FP,
1405                                        OptoRuntime::fast_arraycopy_Type(),
1406                                        CAST_FROM_FN_PTR(address, StubRoutines::jshort_disjoint_arraycopy()),
1407                                        "jshort_disjoint_arraycopy", TypeAryPtr::CHARS,
1408                                        src_ptr, dst_ptr, c, extra);
1409     start = __ AddI(start, count);
1410   }
1411   return start;
1412 }
1413 
1414 
1415 void PhaseStringOpts::replace_string_concat(StringConcat* sc) {
1416   // Log a little info about the transformation
1417   sc->maybe_log_transform();
1418 
1419   // pull the JVMState of the allocation into a SafePointNode to serve as
1420   // as a shim for the insertion of the new code.
1421   JVMState* jvms     = sc->begin()->jvms()->clone_shallow(C);
1422   uint size = sc->begin()->req();
1423   SafePointNode* map = new SafePointNode(size, jvms);
1424 
1425   // copy the control and memory state from the final call into our
1426   // new starting state.  This allows any preceeding tests to feed
1427   // into the new section of code.
1428   for (uint i1 = 0; i1 < TypeFunc::Parms; i1++) {
1429     map->init_req(i1, sc->end()->in(i1));
1430   }
1431   // blow away old allocation arguments
1432   for (uint i1 = TypeFunc::Parms; i1 < jvms->debug_start(); i1++) {
1433     map->init_req(i1, C->top());
1434   }
1435   // Copy the rest of the inputs for the JVMState
1436   for (uint i1 = jvms->debug_start(); i1 < sc->begin()->req(); i1++) {
1437     map->init_req(i1, sc->begin()->in(i1));
1438   }
1439   // Make sure the memory state is a MergeMem for parsing.
1440   if (!map->in(TypeFunc::Memory)->is_MergeMem()) {
1441     map->set_req(TypeFunc::Memory, MergeMemNode::make(C, map->in(TypeFunc::Memory)));
1442   }
1443 


1448   // disconnect all the old StringBuilder calls from the graph
1449   sc->eliminate_unneeded_control();
1450 
1451   // At this point all the old work has been completely removed from
1452   // the graph and the saved JVMState exists at the point where the
1453   // final toString call used to be.
1454   GraphKit kit(jvms);
1455 
1456   // There may be uncommon traps which are still using the
1457   // intermediate states and these need to be rewritten to point at
1458   // the JVMState at the beginning of the transformation.
1459   sc->convert_uncommon_traps(kit, jvms);
1460 
1461   // Now insert the logic to compute the size of the string followed
1462   // by all the logic to construct array and resulting string.
1463 
1464   Node* null_string = __ makecon(TypeInstPtr::make(C->env()->the_null_string()));
1465 
1466   // Create a region for the overflow checks to merge into.
1467   int args = MAX2(sc->num_arguments(), 1);
1468   RegionNode* overflow = new RegionNode(args);
1469   kit.gvn().set_type(overflow, Type::CONTROL);
1470 
1471   // Create a hook node to hold onto the individual sizes since they
1472   // are need for the copying phase.
1473   Node* string_sizes = new Node(args);
1474 
1475   Node* length = __ intcon(0);
1476   for (int argi = 0; argi < sc->num_arguments(); argi++) {
1477     Node* arg = sc->argument(argi);
1478     switch (sc->mode(argi)) {
1479       case StringConcat::IntMode: {
1480         Node* string_size = int_stringSize(kit, arg);
1481 
1482         // accumulate total
1483         length = __ AddI(length, string_size);
1484 
1485         // Cache this value for the use by int_toString
1486         string_sizes->init_req(argi, string_size);
1487         break;
1488       }
1489       case StringConcat::StringNullCheckMode: {
1490         const Type* type = kit.gvn().type(arg);
1491         assert(type != TypePtr::NULL_PTR, "missing check");
1492         if (!type->higher_equal(TypeInstPtr::NOTNULL)) {
1493           // Null check with uncommont trap since


1497           Node* p = __ Bool(__ CmpP(arg, kit.null()), BoolTest::ne);
1498           IfNode* iff = kit.create_and_map_if(kit.control(), p, PROB_MIN, COUNT_UNKNOWN);
1499           overflow->add_req(__ IfFalse(iff));
1500           Node* notnull = __ IfTrue(iff);
1501           kit.set_control(notnull); // set control for the cast_not_null
1502           arg = kit.cast_not_null(arg, false);
1503           sc->set_argument(argi, arg);
1504         }
1505         assert(kit.gvn().type(arg)->higher_equal(TypeInstPtr::NOTNULL), "sanity");
1506         // Fallthrough to add string length.
1507       }
1508       case StringConcat::StringMode: {
1509         const Type* type = kit.gvn().type(arg);
1510         if (type == TypePtr::NULL_PTR) {
1511           // replace the argument with the null checked version
1512           arg = null_string;
1513           sc->set_argument(argi, arg);
1514         } else if (!type->higher_equal(TypeInstPtr::NOTNULL)) {
1515           // s = s != null ? s : "null";
1516           // length = length + (s.count - s.offset);
1517           RegionNode *r = new RegionNode(3);
1518           kit.gvn().set_type(r, Type::CONTROL);
1519           Node *phi = new PhiNode(r, type);
1520           kit.gvn().set_type(phi, phi->bottom_type());
1521           Node* p = __ Bool(__ CmpP(arg, kit.null()), BoolTest::ne);
1522           IfNode* iff = kit.create_and_map_if(kit.control(), p, PROB_MIN, COUNT_UNKNOWN);
1523           Node* notnull = __ IfTrue(iff);
1524           Node* isnull =  __ IfFalse(iff);
1525           kit.set_control(notnull); // set control for the cast_not_null
1526           r->init_req(1, notnull);
1527           phi->init_req(1, kit.cast_not_null(arg, false));
1528           r->init_req(2, isnull);
1529           phi->init_req(2, null_string);
1530           kit.set_control(r);
1531           C->record_for_igvn(r);
1532           C->record_for_igvn(phi);
1533           // replace the argument with the null checked version
1534           arg = phi;
1535           sc->set_argument(argi, arg);
1536         }
1537 
1538         Node* count = kit.load_String_length(kit.control(), arg);
1539 


src/share/vm/opto/stringopts.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File