src/hotspot/share/opto/stringopts.cpp
changeset 51880 ec4c3c287ca7
parent 51705 8123901bc3d1
child 58962 2dcfc28a314d
equal deleted inserted replaced
51879:6ffa38b8da65 51880:ec4c3c287ca7
  1545   }
  1545   }
  1546 }
  1546 }
  1547 
  1547 
  1548 // Compress copy contents of the byte/char String str into dst_array starting at index start.
  1548 // Compress copy contents of the byte/char String str into dst_array starting at index start.
  1549 Node* PhaseStringOpts::copy_string(GraphKit& kit, Node* str, Node* dst_array, Node* dst_coder, Node* start) {
  1549 Node* PhaseStringOpts::copy_string(GraphKit& kit, Node* str, Node* dst_array, Node* dst_coder, Node* start) {
  1550   Node* src_array = kit.load_String_value(kit.control(), str);
  1550   Node* src_array = kit.load_String_value(str, true);
  1551   src_array = kit.access_resolve(src_array, ACCESS_READ);
  1551   src_array = kit.access_resolve(src_array, ACCESS_READ);
  1552 
  1552 
  1553   IdealKit ideal(&kit, true, true);
  1553   IdealKit ideal(&kit, true, true);
  1554   IdealVariable count(ideal); __ declarations_done();
  1554   IdealVariable count(ideal); __ declarations_done();
  1555 
  1555 
  1578     Node* size = kit.load_array_length(src_array);
  1578     Node* size = kit.load_array_length(src_array);
  1579     __ set(count, size);
  1579     __ set(count, size);
  1580     // Non-constant source string
  1580     // Non-constant source string
  1581     if (CompactStrings) {
  1581     if (CompactStrings) {
  1582       // Emit runtime check for coder
  1582       // Emit runtime check for coder
  1583       Node* coder = kit.load_String_coder(__ ctrl(), str);
  1583       Node* coder = kit.load_String_coder(str, true);
  1584       __ if_then(coder, BoolTest::eq, __ ConI(java_lang_String::CODER_LATIN1)); {
  1584       __ if_then(coder, BoolTest::eq, __ ConI(java_lang_String::CODER_LATIN1)); {
  1585         // Source is Latin1
  1585         // Source is Latin1
  1586         copy_latin1_string(kit, ideal, src_array, count, dst_array, dst_coder, start);
  1586         copy_latin1_string(kit, ideal, src_array, count, dst_array, dst_coder, start);
  1587       } __ else_();
  1587       } __ else_();
  1588     }
  1588     }
  1794         Node* arg_coder = NULL;
  1794         Node* arg_coder = NULL;
  1795         if (type == TypePtr::NULL_PTR) {
  1795         if (type == TypePtr::NULL_PTR) {
  1796           // replace the argument with the null checked version
  1796           // replace the argument with the null checked version
  1797           arg = null_string;
  1797           arg = null_string;
  1798           sc->set_argument(argi, arg);
  1798           sc->set_argument(argi, arg);
  1799           count = kit.load_String_length(kit.control(), arg);
  1799           count = kit.load_String_length(arg, true);
  1800           arg_coder = kit.load_String_coder(kit.control(), arg);
  1800           arg_coder = kit.load_String_coder(arg, true);
  1801         } else if (!type->higher_equal(TypeInstPtr::NOTNULL)) {
  1801         } else if (!type->higher_equal(TypeInstPtr::NOTNULL)) {
  1802           // s = s != null ? s : "null";
  1802           // s = s != null ? s : "null";
  1803           // length = length + (s.count - s.offset);
  1803           // length = length + (s.count - s.offset);
  1804           RegionNode *r = new RegionNode(3);
  1804           RegionNode *r = new RegionNode(3);
  1805           kit.gvn().set_type(r, Type::CONTROL);
  1805           kit.gvn().set_type(r, Type::CONTROL);
  1818           C->record_for_igvn(r);
  1818           C->record_for_igvn(r);
  1819           C->record_for_igvn(phi);
  1819           C->record_for_igvn(phi);
  1820           // replace the argument with the null checked version
  1820           // replace the argument with the null checked version
  1821           arg = phi;
  1821           arg = phi;
  1822           sc->set_argument(argi, arg);
  1822           sc->set_argument(argi, arg);
  1823           count = kit.load_String_length(kit.control(), arg);
  1823           count = kit.load_String_length(arg, true);
  1824           arg_coder = kit.load_String_coder(kit.control(), arg);
  1824           arg_coder = kit.load_String_coder(arg, true);
  1825         } else {
  1825         } else {
  1826           // A corresponding nullcheck will be connected during IGVN MemNode::Ideal_common_DU_postCCP
  1826           // A corresponding nullcheck will be connected during IGVN MemNode::Ideal_common_DU_postCCP
  1827           // kit.control might be a different test, that can be hoisted above the actual nullcheck
  1827           // kit.control might be a different test, that can be hoisted above the actual nullcheck
  1828           // in case, that the control input is not null, Ideal_common_DU_postCCP will not look for a nullcheck.
  1828           // in case, that the control input is not null, Ideal_common_DU_postCCP will not look for a nullcheck.
  1829           count = kit.load_String_length(NULL, arg);
  1829           count = kit.load_String_length(arg, false);
  1830           arg_coder = kit.load_String_coder(NULL, arg);
  1830           arg_coder = kit.load_String_coder(arg, false);
  1831         }
  1831         }
  1832         if (arg->is_Con()) {
  1832         if (arg->is_Con()) {
  1833           // Constant string. Get constant coder and length.
  1833           // Constant string. Get constant coder and length.
  1834           jbyte const_coder = get_constant_coder(kit, arg);
  1834           jbyte const_coder = get_constant_coder(kit, arg);
  1835           int const_length = get_constant_length(kit, arg);
  1835           int const_length = get_constant_length(kit, arg);
  1916     if (sc->num_arguments() == 1 &&
  1916     if (sc->num_arguments() == 1 &&
  1917         (sc->mode(0) == StringConcat::StringMode ||
  1917         (sc->mode(0) == StringConcat::StringMode ||
  1918          sc->mode(0) == StringConcat::StringNullCheckMode)) {
  1918          sc->mode(0) == StringConcat::StringNullCheckMode)) {
  1919       // Handle the case when there is only a single String argument.
  1919       // Handle the case when there is only a single String argument.
  1920       // In this case, we can just pull the value from the String itself.
  1920       // In this case, we can just pull the value from the String itself.
  1921       dst_array = kit.load_String_value(kit.control(), sc->argument(0));
  1921       dst_array = kit.load_String_value(sc->argument(0), true);
  1922     } else {
  1922     } else {
  1923       // Allocate destination byte array according to coder
  1923       // Allocate destination byte array according to coder
  1924       dst_array = allocate_byte_array(kit, NULL, __ LShiftI(length, coder));
  1924       dst_array = allocate_byte_array(kit, NULL, __ LShiftI(length, coder));
  1925 
  1925 
  1926       // Now copy the string representations into the final byte[]
  1926       // Now copy the string representations into the final byte[]
  1957       kit.jvms()->set_should_reexecute(true);
  1957       kit.jvms()->set_should_reexecute(true);
  1958       result = kit.new_instance(__ makecon(TypeKlassPtr::make(C->env()->String_klass())));
  1958       result = kit.new_instance(__ makecon(TypeKlassPtr::make(C->env()->String_klass())));
  1959     }
  1959     }
  1960 
  1960 
  1961     // Initialize the string
  1961     // Initialize the string
  1962     kit.store_String_value(kit.control(), result, dst_array);
  1962     kit.store_String_value(result, dst_array);
  1963     kit.store_String_coder(kit.control(), result, coder);
  1963     kit.store_String_coder(result, coder);
  1964 
  1964 
  1965     // The value field is final. Emit a barrier here to ensure that the effect
  1965     // The value field is final. Emit a barrier here to ensure that the effect
  1966     // of the initialization is committed to memory before any code publishes
  1966     // of the initialization is committed to memory before any code publishes
  1967     // a reference to the newly constructed object (see Parse::do_exits()).
  1967     // a reference to the newly constructed object (see Parse::do_exits()).
  1968     assert(AllocateNode::Ideal_allocation(result, _gvn) != NULL, "should be newly allocated");
  1968     assert(AllocateNode::Ideal_allocation(result, _gvn) != NULL, "should be newly allocated");