src/hotspot/share/opto/stringopts.hpp
author vromero
Mon, 08 Oct 2018 06:52:41 -0700
changeset 52038 957de5be48bc
parent 47216 71c04702a3d5
child 53244 9807daeb47c4
permissions -rw-r--r--
8209407: VerifyError is thrown for inner class with lambda Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4450
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
     1
/*
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
     2
 * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
4450
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
     4
 *
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
     8
 *
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    13
 * accompanied this code).
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    14
 *
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4450
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4450
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4450
diff changeset
    21
 * questions.
4450
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    22
 *
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    23
 */
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#ifndef SHARE_VM_OPTO_STRINGOPTS_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_OPTO_STRINGOPTS_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "opto/node.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "opto/phaseX.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
4450
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    31
class StringConcat;
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    32
class IdealVariable;
4450
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    33
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    34
class PhaseStringOpts : public Phase {
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    35
  friend class StringConcat;
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    36
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    37
 private:
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    38
  PhaseGVN* _gvn;
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    39
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    40
  // List of dead nodes to clean up aggressively at the end
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    41
  Unique_Node_List dead_worklist;
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    42
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    43
  // Memory slices needed for code gen
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    44
  int byte_adr_idx;
4450
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    45
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    46
  // Integer.sizeTable - used for int to String conversion
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    47
  ciField* size_table_field;
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    48
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    49
  // A set for use by various stages
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    50
  VectorSet _visited;
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    51
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    52
  // Collect a list of all SB.toString calls
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    53
  Node_List collect_toString_calls();
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    54
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    55
  // Examine the use of the SB alloc to see if it can be replace with
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    56
  // a single string construction.
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    57
  StringConcat* build_candidate(CallStaticJavaNode* call);
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    58
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    59
  // Replace all the SB calls in concat with an optimization String allocation
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    60
  void replace_string_concat(StringConcat* concat);
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    61
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    62
  // Load the value of a static field, performing any constant folding.
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    63
  Node* fetch_static_field(GraphKit& kit, ciField* field);
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    64
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    65
  // Compute the number of characters required to represent the int value
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    66
  Node* int_stringSize(GraphKit& kit, Node* value);
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    67
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    68
  // Simplified version of Integer.getChars
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    69
  void getChars(GraphKit& kit, Node* arg, Node* dst_array, BasicType bt, Node* end, Node* final_merge, Node* final_mem, int merge_index = 0);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    70
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    71
  // Copy the characters representing arg into dst_array starting at start
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    72
  Node* int_getChars(GraphKit& kit, Node* arg, Node* dst_array, Node* dst_coder, Node* start, Node* size);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    73
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    74
  // Copy contents of the String str into dst_array starting at index start.
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    75
  Node* copy_string(GraphKit& kit, Node* str, Node* dst_array, Node* dst_coder, Node* start);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    76
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    77
  // Copy 'count' bytes/chars from src_array to dst_array starting at index start
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    78
  void arraycopy(GraphKit& kit, IdealKit& ideal, Node* src_array, Node* dst_array, BasicType elembt, Node* start, Node* count);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    79
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    80
  // Copy contents of constant src_array to dst_array by emitting individual stores
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    81
  void copy_constant_string(GraphKit& kit, IdealKit& ideal, ciTypeArray* src_array, IdealVariable& count,
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    82
                            bool src_is_byte, Node* dst_array, Node* dst_coder, Node* start);
4450
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    83
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    84
  // Copy contents of a Latin1 encoded string from src_array to dst_array
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    85
  void copy_latin1_string(GraphKit& kit, IdealKit& ideal, Node* src_array, IdealVariable& count,
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    86
                          Node* dst_array, Node* dst_coder, Node* start);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    87
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    88
  // Copy the char into dst_array at index start.
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    89
  Node* copy_char(GraphKit& kit, Node* val, Node* dst_array, Node* dst_coder, Node* start);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    90
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    91
  // Allocate a byte array of specified length.
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    92
  Node* allocate_byte_array(GraphKit& kit, IdealKit* ideal, Node* length);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    93
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    94
  // Returns the coder of a constant string
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    95
  jbyte get_constant_coder(GraphKit& kit, Node* str);
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    96
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    97
  // Returns the length of a constant string
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 12623
diff changeset
    98
  int get_constant_length(GraphKit& kit, Node* str);
4450
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
    99
36077
fa6d92de1c70 8149813: Move trusted final field handling from C2 LoadNode::Value to shared code
shade
parents: 33628
diff changeset
   100
  // Returns the value array of a constant string
fa6d92de1c70 8149813: Move trusted final field handling from C2 LoadNode::Value to shared code
shade
parents: 33628
diff changeset
   101
  ciTypeArray* get_constant_value(GraphKit& kit, Node* str);
fa6d92de1c70 8149813: Move trusted final field handling from C2 LoadNode::Value to shared code
shade
parents: 33628
diff changeset
   102
4450
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
   103
  // Clean up any leftover nodes
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
   104
  void record_dead_node(Node* node);
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
   105
  void remove_dead_nodes();
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
   106
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
   107
  PhaseGVN* gvn() { return _gvn; }
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
   108
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
   109
  enum {
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
   110
    // max length of constant string copy unrolling in copy_string
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
   111
    unroll_string_copy_length = 6
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
   112
  };
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
   113
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
   114
 public:
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
   115
  PhaseStringOpts(PhaseGVN* gvn, Unique_Node_List* worklist);
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents:
diff changeset
   116
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   117
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   118
#endif // SHARE_VM_OPTO_STRINGOPTS_HPP