src/hotspot/share/utilities/growableArray.hpp
author stefank
Tue, 28 Nov 2017 21:43:45 +0100
changeset 48157 7c4d43c26352
parent 47778 46cb6af585d4
child 49658 8237a91c1cca
permissions -rw-r--r--
8192061: Clean up allocation.inline.hpp includes Reviewed-by: eosterlund, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
46448
b5350a83520b 8153646: Move vm/utilities/array.hpp to vm/oops
hseigel
parents: 42650
diff changeset
     2
 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
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.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
    25
#ifndef SHARE_VM_UTILITIES_GROWABLEARRAY_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
    26
#define SHARE_VM_UTILITIES_GROWABLEARRAY_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
    28
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
    29
#include "utilities/debug.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
    30
#include "utilities/globalDefinitions.hpp"
48157
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47778
diff changeset
    31
#include "utilities/ostream.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
    32
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// A growable array.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
/*************************************************************************/
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
/*                                                                       */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
/*     WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING   */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
/*                                                                       */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
/* Should you use GrowableArrays to contain handles you must be certain  */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
/* the the GrowableArray does not outlive the HandleMark that contains   */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
/* the handles. Since GrowableArrays are typically resource allocated    */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
/* the following is an example of INCORRECT CODE,                        */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
/*                                                                       */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
/* ResourceMark rm;                                                      */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
/* GrowableArray<Handle>* arr = new GrowableArray<Handle>(size);         */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
/* if (blah) {                                                           */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
/*    while (...) {                                                      */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
/*      HandleMark hm;                                                   */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
/*      ...                                                              */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
/*      Handle h(THREAD, some_oop);                                      */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
/*      arr->append(h);                                                  */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
/*    }                                                                  */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
/* }                                                                     */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
/* if (arr->length() != 0 ) {                                            */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
/*    oop bad_oop = arr->at(0)(); // Handle is BAD HERE.                 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
/*    ...                                                                */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
/* }                                                                     */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
/*                                                                       */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
/* If the GrowableArrays you are creating is C_Heap allocated then it    */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
/* hould not old handles since the handles could trivially try and       */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
/* outlive their HandleMark. In some situations you might need to do     */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
/* this and it would be legal but be very careful and see if you can do  */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
/* the code in some other manner.                                        */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
/*                                                                       */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
/*************************************************************************/
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
// To call default constructor the placement operator new() is used.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
// It should be empty (it only returns the passed void* pointer).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
// The definition of placement operator new(size_t, void*) in the <new>.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
#include <new>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
// Need the correct linkage to call qsort without warnings
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
extern "C" {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  typedef int (*_sort_Fn)(const void *, const void *);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
class GenericGrowableArray : public ResourceObj {
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 7397
diff changeset
    79
  friend class VMStructs;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 7397
diff changeset
    80
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  int    _len;          // current length
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  int    _max;          // maximum length
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  Arena* _arena;        // Indicates where allocation occurs:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
                        //   0 means default ResourceArea
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
                        //   1 means on C heap
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
                        //   otherwise, allocate in _arena
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12158
diff changeset
    88
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12158
diff changeset
    89
  MEMFLAGS   _memflags;   // memory type if allocation in C heap
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12158
diff changeset
    90
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  int    _nesting;      // resource area nesting at creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  void   set_nesting();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  void   check_nesting();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
#define  set_nesting();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
#define  check_nesting();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  // Where are we going to allocate memory?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  bool on_C_heap() { return _arena == (Arena*)1; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  bool on_stack () { return _arena == NULL;      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  bool on_arena () { return _arena >  (Arena*)1;  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // This GA will use the resource stack for storage if c_heap==false,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  // Else it will use the C heap.  Use clear_and_deallocate to avoid leaks.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12158
diff changeset
   107
  GenericGrowableArray(int initial_size, int initial_len, bool c_heap, MEMFLAGS flags = mtNone) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    _len = initial_len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    _max = initial_size;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12158
diff changeset
   110
    _memflags = flags;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12158
diff changeset
   111
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12158
diff changeset
   112
    // memory type has to be specified for C heap allocation
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12158
diff changeset
   113
    assert(!(c_heap && flags == mtNone), "memory type not specified for C heap object");
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12158
diff changeset
   114
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    assert(_len >= 0 && _len <= _max, "initial_len too big");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    _arena = (c_heap ? (Arena*)1 : NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    set_nesting();
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   118
    assert(!on_C_heap() || allocated_on_C_heap(), "growable array must be on C heap if elements are");
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   119
    assert(!on_stack() ||
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   120
           (allocated_on_res_area() || allocated_on_stack()),
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   121
           "growable array must be on stack if elements are not on arena and not on C heap");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  // This GA will use the given arena for storage.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // Consider using new(arena) GrowableArray<T> to allocate the header.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  GenericGrowableArray(Arena* arena, int initial_size, int initial_len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    _len = initial_len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    _max = initial_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    assert(_len >= 0 && _len <= _max, "initial_len too big");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    _arena = arena;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12158
diff changeset
   131
    _memflags = mtNone;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12158
diff changeset
   132
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    assert(on_arena(), "arena has taken on reserved value 0 or 1");
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   134
    // Relax next assert to allow object allocation on resource area,
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   135
    // on stack or embedded into an other object.
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   136
    assert(allocated_on_arena() || allocated_on_stack(),
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   137
           "growable array must be on arena or on stack if elements are on arena");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  void* raw_allocate(int elementSize);
1551
b431de37a22c 6770949: minor tweaks before 6655638
jrose
parents: 1
diff changeset
   141
b431de37a22c 6770949: minor tweaks before 6655638
jrose
parents: 1
diff changeset
   142
  // some uses pass the Thread explicitly for speed (4990299 tuning)
b431de37a22c 6770949: minor tweaks before 6655638
jrose
parents: 1
diff changeset
   143
  void* raw_allocate(Thread* thread, int elementSize) {
b431de37a22c 6770949: minor tweaks before 6655638
jrose
parents: 1
diff changeset
   144
    assert(on_stack(), "fast ResourceObj path only");
b431de37a22c 6770949: minor tweaks before 6655638
jrose
parents: 1
diff changeset
   145
    return (void*)resource_allocate_bytes(thread, elementSize * _max);
b431de37a22c 6770949: minor tweaks before 6655638
jrose
parents: 1
diff changeset
   146
  }
48157
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47778
diff changeset
   147
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47778
diff changeset
   148
  void free_C_heap(void* elements);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
24010
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   151
template<class E> class GrowableArrayIterator;
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   152
template<class E, class UnaryPredicate> class GrowableArrayFilterIterator;
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   153
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
template<class E> class GrowableArray : public GenericGrowableArray {
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 7397
diff changeset
   155
  friend class VMStructs;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 7397
diff changeset
   156
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  E*     _data;         // data array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  void grow(int j);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  void raw_at_put_grow(int i, const E& p, const E& fill);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  void  clear_and_deallocate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
 public:
1551
b431de37a22c 6770949: minor tweaks before 6655638
jrose
parents: 1
diff changeset
   164
  GrowableArray(Thread* thread, int initial_size) : GenericGrowableArray(initial_size, 0, false) {
b431de37a22c 6770949: minor tweaks before 6655638
jrose
parents: 1
diff changeset
   165
    _data = (E*)raw_allocate(thread, sizeof(E));
b431de37a22c 6770949: minor tweaks before 6655638
jrose
parents: 1
diff changeset
   166
    for (int i = 0; i < _max; i++) ::new ((void*)&_data[i]) E();
b431de37a22c 6770949: minor tweaks before 6655638
jrose
parents: 1
diff changeset
   167
  }
b431de37a22c 6770949: minor tweaks before 6655638
jrose
parents: 1
diff changeset
   168
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12158
diff changeset
   169
  GrowableArray(int initial_size, bool C_heap = false, MEMFLAGS F = mtInternal)
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12158
diff changeset
   170
    : GenericGrowableArray(initial_size, 0, C_heap, F) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    _data = (E*)raw_allocate(sizeof(E));
30125
8ba6e8e367e9 8074895: os::getenv is inadequate
jmanson
parents: 24946
diff changeset
   172
// Needed for Visual Studio 2012 and older
35849
f095845829c9 8145740: Visual Studio pragmas should be guarded by ifdef _MSC_VER
dholmes
parents: 33160
diff changeset
   173
#ifdef _MSC_VER
30125
8ba6e8e367e9 8074895: os::getenv is inadequate
jmanson
parents: 24946
diff changeset
   174
#pragma warning(suppress: 4345)
35849
f095845829c9 8145740: Visual Studio pragmas should be guarded by ifdef _MSC_VER
dholmes
parents: 33160
diff changeset
   175
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    for (int i = 0; i < _max; i++) ::new ((void*)&_data[i]) E();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12158
diff changeset
   179
  GrowableArray(int initial_size, int initial_len, const E& filler, bool C_heap = false, MEMFLAGS memflags = mtInternal)
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12158
diff changeset
   180
    : GenericGrowableArray(initial_size, initial_len, C_heap, memflags) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    _data = (E*)raw_allocate(sizeof(E));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    int i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    for (; i < _len; i++) ::new ((void*)&_data[i]) E(filler);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    for (; i < _max; i++) ::new ((void*)&_data[i]) E();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  GrowableArray(Arena* arena, int initial_size, int initial_len, const E& filler) : GenericGrowableArray(arena, initial_size, initial_len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    _data = (E*)raw_allocate(sizeof(E));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    int i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    for (; i < _len; i++) ::new ((void*)&_data[i]) E(filler);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    for (; i < _max; i++) ::new ((void*)&_data[i]) E();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  GrowableArray() : GenericGrowableArray(2, 0, false) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    _data = (E*)raw_allocate(sizeof(E));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    ::new ((void*)&_data[0]) E();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    ::new ((void*)&_data[1]) E();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
                                // Does nothing for resource and arena objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  ~GrowableArray()              { if (on_C_heap()) clear_and_deallocate(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  void  clear()                 { _len = 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  int   length() const          { return _len; }
19339
d247781beec7 7145569: G1: optimize nmethods scanning
johnc
parents: 14385
diff changeset
   205
  int   max_length() const      { return _max; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  void  trunc_to(int l)         { assert(l <= _len,"cannot increase length"); _len = l; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  bool  is_empty() const        { return _len == 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  bool  is_nonempty() const     { return _len != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  bool  is_full() const         { return _len == _max; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  DEBUG_ONLY(E* data_addr() const      { return _data; })
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  void print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
1551
b431de37a22c 6770949: minor tweaks before 6655638
jrose
parents: 1
diff changeset
   214
  int append(const E& elem) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    check_nesting();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    if (_len == _max) grow(_len);
1551
b431de37a22c 6770949: minor tweaks before 6655638
jrose
parents: 1
diff changeset
   217
    int idx = _len++;
b431de37a22c 6770949: minor tweaks before 6655638
jrose
parents: 1
diff changeset
   218
    _data[idx] = elem;
b431de37a22c 6770949: minor tweaks before 6655638
jrose
parents: 1
diff changeset
   219
    return idx;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
12158
f24f2560da32 7147744: CTW: assert(false) failed: infinite EA connection graph build
kvn
parents: 10547
diff changeset
   222
  bool append_if_missing(const E& elem) {
f24f2560da32 7147744: CTW: assert(false) failed: infinite EA connection graph build
kvn
parents: 10547
diff changeset
   223
    // Returns TRUE if elem is added.
f24f2560da32 7147744: CTW: assert(false) failed: infinite EA connection graph build
kvn
parents: 10547
diff changeset
   224
    bool missed = !contains(elem);
f24f2560da32 7147744: CTW: assert(false) failed: infinite EA connection graph build
kvn
parents: 10547
diff changeset
   225
    if (missed) append(elem);
f24f2560da32 7147744: CTW: assert(false) failed: infinite EA connection graph build
kvn
parents: 10547
diff changeset
   226
    return missed;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents: 13728
diff changeset
   229
  E& at(int i) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents: 13728
diff changeset
   230
    assert(0 <= i && i < _len, "illegal index");
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents: 13728
diff changeset
   231
    return _data[i];
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents: 13728
diff changeset
   232
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents: 13728
diff changeset
   233
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents: 13728
diff changeset
   234
  E const& at(int i) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    assert(0 <= i && i < _len, "illegal index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    return _data[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  E* adr_at(int i) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    assert(0 <= i && i < _len, "illegal index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    return &_data[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  E first() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    assert(_len > 0, "empty list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    return _data[0];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  E top() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    assert(_len > 0, "empty list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    return _data[_len-1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36315
diff changeset
   254
  E last() const {
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36315
diff changeset
   255
    return top();
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36315
diff changeset
   256
  }
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36315
diff changeset
   257
24010
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   258
  GrowableArrayIterator<E> begin() const {
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   259
    return GrowableArrayIterator<E>(this, 0);
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   260
  }
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   261
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   262
  GrowableArrayIterator<E> end() const {
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   263
    return GrowableArrayIterator<E>(this, length());
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   264
  }
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   265
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  void push(const E& elem) { append(elem); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  E pop() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    assert(_len > 0, "empty list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    return _data[--_len];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  void at_put(int i, const E& elem) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    assert(0 <= i && i < _len, "illegal index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    _data[i] = elem;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  E at_grow(int i, const E& fill = E()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
    assert(0 <= i, "negative index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    check_nesting();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    if (i >= _len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
      if (i >= _max) grow(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
      for (int j = _len; j <= i; j++)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
        _data[j] = fill;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
      _len = i+1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    return _data[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  void at_put_grow(int i, const E& elem, const E& fill = E()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
    assert(0 <= i, "negative index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    check_nesting();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    raw_at_put_grow(i, elem, fill);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  bool contains(const E& elem) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    for (int i = 0; i < _len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
      if (_data[i] == elem) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  int  find(const E& elem) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    for (int i = 0; i < _len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
      if (_data[i] == elem) return i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   310
  int  find_from_end(const E& elem) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   311
    for (int i = _len-1; i >= 0; i--) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   312
      if (_data[i] == elem) return i;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   313
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   314
    return -1;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   315
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   316
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  int  find(void* token, bool f(void*, E)) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    for (int i = 0; i < _len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
      if (f(token, _data[i])) return i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   324
  int  find_from_end(void* token, bool f(void*, E)) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    // start at the end of the array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    for (int i = _len-1; i >= 0; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
      if (f(token, _data[i])) return i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  void remove(const E& elem) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    for (int i = 0; i < _len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
      if (_data[i] == elem) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
        for (int j = i + 1; j < _len; j++) _data[j-1] = _data[j];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
        _len--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
12158
f24f2560da32 7147744: CTW: assert(false) failed: infinite EA connection graph build
kvn
parents: 10547
diff changeset
   343
  // The order is preserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  void remove_at(int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    assert(0 <= index && index < _len, "illegal index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    for (int j = index + 1; j < _len; j++) _data[j-1] = _data[j];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    _len--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
12158
f24f2560da32 7147744: CTW: assert(false) failed: infinite EA connection graph build
kvn
parents: 10547
diff changeset
   350
  // The order is changed.
f24f2560da32 7147744: CTW: assert(false) failed: infinite EA connection graph build
kvn
parents: 10547
diff changeset
   351
  void delete_at(int index) {
f24f2560da32 7147744: CTW: assert(false) failed: infinite EA connection graph build
kvn
parents: 10547
diff changeset
   352
    assert(0 <= index && index < _len, "illegal index");
f24f2560da32 7147744: CTW: assert(false) failed: infinite EA connection graph build
kvn
parents: 10547
diff changeset
   353
    if (index < --_len) {
f24f2560da32 7147744: CTW: assert(false) failed: infinite EA connection graph build
kvn
parents: 10547
diff changeset
   354
      // Replace removed element with last one.
f24f2560da32 7147744: CTW: assert(false) failed: infinite EA connection graph build
kvn
parents: 10547
diff changeset
   355
      _data[index] = _data[_len];
f24f2560da32 7147744: CTW: assert(false) failed: infinite EA connection graph build
kvn
parents: 10547
diff changeset
   356
    }
f24f2560da32 7147744: CTW: assert(false) failed: infinite EA connection graph build
kvn
parents: 10547
diff changeset
   357
  }
f24f2560da32 7147744: CTW: assert(false) failed: infinite EA connection graph build
kvn
parents: 10547
diff changeset
   358
4450
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 1623
diff changeset
   359
  // inserts the given element before the element at index i
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 1623
diff changeset
   360
  void insert_before(const int idx, const E& elem) {
24946
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents: 24010
diff changeset
   361
    assert(0 <= idx && idx <= _len, "illegal index");
4450
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 1623
diff changeset
   362
    check_nesting();
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 1623
diff changeset
   363
    if (_len == _max) grow(_len);
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 1623
diff changeset
   364
    for (int j = _len - 1; j >= idx; j--) {
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 1623
diff changeset
   365
      _data[j + 1] = _data[j];
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 1623
diff changeset
   366
    }
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 1623
diff changeset
   367
    _len++;
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 1623
diff changeset
   368
    _data[idx] = elem;
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 1623
diff changeset
   369
  }
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 1623
diff changeset
   370
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36315
diff changeset
   371
  void insert_before(const int idx, const GrowableArray<E>* array) {
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36315
diff changeset
   372
    assert(0 <= idx && idx <= _len, "illegal index");
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36315
diff changeset
   373
    check_nesting();
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36315
diff changeset
   374
    int array_len = array->length();
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36315
diff changeset
   375
    int new_len = _len + array_len;
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36315
diff changeset
   376
    if (new_len >= _max) grow(new_len);
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36315
diff changeset
   377
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36315
diff changeset
   378
    for (int j = _len - 1; j >= idx; j--) {
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36315
diff changeset
   379
      _data[j + array_len] = _data[j];
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36315
diff changeset
   380
    }
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36315
diff changeset
   381
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36315
diff changeset
   382
    for (int j = 0; j < array_len; j++) {
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36315
diff changeset
   383
      _data[idx + j] = array->_data[j];
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36315
diff changeset
   384
    }
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36315
diff changeset
   385
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36315
diff changeset
   386
    _len += array_len;
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36315
diff changeset
   387
  }
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 36315
diff changeset
   388
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  void appendAll(const GrowableArray<E>* l) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
    for (int i = 0; i < l->_len; i++) {
24946
24b68ccf3fc4 8026796: Make replace_in_map() on parent maps generic
roland
parents: 24010
diff changeset
   391
      raw_at_put_grow(_len, l->_data[i], E());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  void sort(int f(E*,E*)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    qsort(_data, length(), sizeof(E), (_sort_Fn)f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  // sort by fixed-stride sub arrays:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  void sort(int f(E*,E*), int stride) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
    qsort(_data, length() / stride, sizeof(E) * stride, (_sort_Fn)f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   402
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   403
  // Binary search and insertion utility.  Search array for element
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   404
  // matching key according to the static compare function.  Insert
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   405
  // that element is not already in the list.  Assumes the list is
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   406
  // already sorted according to compare function.
47778
46cb6af585d4 8189425: Minor updates in support of closed changes
egahlin
parents: 47216
diff changeset
   407
  template <int compare(const E&, const E&)> E insert_sorted(const E& key) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   408
    bool found;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   409
    int location = find_sorted<E, compare>(key, found);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   410
    if (!found) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   411
      insert_before(location, key);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   412
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   413
    return at(location);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   414
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   415
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   416
  template <typename K, int compare(const K&, const E&)> int find_sorted(const K& key, bool& found) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   417
    found = false;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   418
    int min = 0;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   419
    int max = length() - 1;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   420
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   421
    while (max >= min) {
36315
150a415079ae 8007986: GrowableArray should implement binary search
roland
parents: 35849
diff changeset
   422
      int mid = (int)(((uint)max + min) / 2);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   423
      E value = at(mid);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   424
      int diff = compare(key, value);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   425
      if (diff > 0) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   426
        min = mid + 1;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   427
      } else if (diff < 0) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   428
        max = mid - 1;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   429
      } else {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   430
        found = true;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   431
        return mid;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   432
      }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   433
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   434
    return min;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 30125
diff changeset
   435
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
// Global GrowableArray methods (one instance in the library per each 'E' type).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
template<class E> void GrowableArray<E>::grow(int j) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
    // grow the array by doubling its size (amortized growth)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
    int old_max = _max;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
    if (_max == 0) _max = 1; // prevent endless loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    while (j >= _max) _max = _max*2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
    // j < _max
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
    E* newData = (E*)raw_allocate(sizeof(E));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
    int i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
    for (     ; i < _len; i++) ::new ((void*)&newData[i]) E(_data[i]);
30125
8ba6e8e367e9 8074895: os::getenv is inadequate
jmanson
parents: 24946
diff changeset
   449
// Needed for Visual Studio 2012 and older
35849
f095845829c9 8145740: Visual Studio pragmas should be guarded by ifdef _MSC_VER
dholmes
parents: 33160
diff changeset
   450
#ifdef _MSC_VER
30125
8ba6e8e367e9 8074895: os::getenv is inadequate
jmanson
parents: 24946
diff changeset
   451
#pragma warning(suppress: 4345)
35849
f095845829c9 8145740: Visual Studio pragmas should be guarded by ifdef _MSC_VER
dholmes
parents: 33160
diff changeset
   452
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    for (     ; i < _max; i++) ::new ((void*)&newData[i]) E();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
    for (i = 0; i < old_max; i++) _data[i].~E();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
    if (on_C_heap() && _data != NULL) {
48157
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47778
diff changeset
   456
      free_C_heap(_data);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
    _data = newData;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
template<class E> void GrowableArray<E>::raw_at_put_grow(int i, const E& p, const E& fill) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
    if (i >= _len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
      if (i >= _max) grow(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
      for (int j = _len; j < i; j++)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
        _data[j] = fill;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
      _len = i+1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
    _data[i] = p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
// This function clears and deallocate the data in the growable array that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
// has been allocated on the C heap.  It's not public - called by the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
// destructor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
template<class E> void GrowableArray<E>::clear_and_deallocate() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
    assert(on_C_heap(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
           "clear_and_deallocate should only be called when on C heap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
    clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
    if (_data != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
      for (int i = 0; i < _max; i++) _data[i].~E();
48157
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47778
diff changeset
   480
      free_C_heap(_data);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
      _data = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
template<class E> void GrowableArray<E>::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    tty->print("Growable Array " INTPTR_FORMAT, this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    tty->print(": length %ld (_max %ld) { ", _len, _max);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
    for (int i = 0; i < _len; i++) tty->print(INTPTR_FORMAT " ", *(intptr_t*)&(_data[i]));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
    tty->print("}\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
}
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
   491
24010
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   492
// Custom STL-style iterator to iterate over GrowableArrays
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   493
// It is constructed by invoking GrowableArray::begin() and GrowableArray::end()
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   494
template<class E> class GrowableArrayIterator : public StackObj {
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   495
  friend class GrowableArray<E>;
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   496
  template<class F, class UnaryPredicate> friend class GrowableArrayFilterIterator;
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   497
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   498
 private:
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   499
  const GrowableArray<E>* _array; // GrowableArray we iterate over
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   500
  int _position;                  // The current position in the GrowableArray
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   501
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   502
  // Private constructor used in GrowableArray::begin() and GrowableArray::end()
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   503
  GrowableArrayIterator(const GrowableArray<E>* array, int position) : _array(array), _position(position) {
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   504
    assert(0 <= position && position <= _array->length(), "illegal position");
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   505
  }
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   506
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   507
 public:
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 38051
diff changeset
   508
  GrowableArrayIterator() : _array(NULL), _position(0) { }
24010
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   509
  GrowableArrayIterator<E>& operator++()  { ++_position; return *this; }
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   510
  E operator*()                           { return _array->at(_position); }
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   511
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   512
  bool operator==(const GrowableArrayIterator<E>& rhs)  {
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   513
    assert(_array == rhs._array, "iterator belongs to different array");
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   514
    return _position == rhs._position;
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   515
  }
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   516
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   517
  bool operator!=(const GrowableArrayIterator<E>& rhs)  {
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   518
    assert(_array == rhs._array, "iterator belongs to different array");
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   519
    return _position != rhs._position;
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   520
  }
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   521
};
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   522
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   523
// Custom STL-style iterator to iterate over elements of a GrowableArray that satisfy a given predicate
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   524
template<class E, class UnaryPredicate> class GrowableArrayFilterIterator : public StackObj {
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   525
  friend class GrowableArray<E>;
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   526
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   527
 private:
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   528
  const GrowableArray<E>* _array;   // GrowableArray we iterate over
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   529
  int _position;                    // Current position in the GrowableArray
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   530
  UnaryPredicate _predicate;        // Unary predicate the elements of the GrowableArray should satisfy
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   531
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   532
 public:
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   533
  GrowableArrayFilterIterator(const GrowableArrayIterator<E>& begin, UnaryPredicate filter_predicate)
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   534
   : _array(begin._array), _position(begin._position), _predicate(filter_predicate) {
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   535
    // Advance to first element satisfying the predicate
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   536
    while(_position != _array->length() && !_predicate(_array->at(_position))) {
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   537
      ++_position;
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   538
    }
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   539
  }
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   540
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   541
  GrowableArrayFilterIterator<E, UnaryPredicate>& operator++() {
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   542
    do {
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   543
      // Advance to next element satisfying the predicate
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   544
      ++_position;
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   545
    } while(_position != _array->length() && !_predicate(_array->at(_position)));
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   546
    return *this;
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   547
  }
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   548
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   549
  E operator*()   { return _array->at(_position); }
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   550
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   551
  bool operator==(const GrowableArrayIterator<E>& rhs)  {
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   552
    assert(_array == rhs._array, "iterator belongs to different array");
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   553
    return _position == rhs._position;
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   554
  }
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   555
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   556
  bool operator!=(const GrowableArrayIterator<E>& rhs)  {
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   557
    assert(_array == rhs._array, "iterator belongs to different array");
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   558
    return _position != rhs._position;
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   559
  }
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   560
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   561
  bool operator==(const GrowableArrayFilterIterator<E, UnaryPredicate>& rhs)  {
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   562
    assert(_array == rhs._array, "iterator belongs to different array");
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   563
    return _position == rhs._position;
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   564
  }
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   565
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   566
  bool operator!=(const GrowableArrayFilterIterator<E, UnaryPredicate>& rhs)  {
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   567
    assert(_array == rhs._array, "iterator belongs to different array");
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   568
    return _position != rhs._position;
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   569
  }
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   570
};
e1761df99d5f 8039498: Add iterators to GrowableArray
anoll
parents: 22234
diff changeset
   571
46448
b5350a83520b 8153646: Move vm/utilities/array.hpp to vm/oops
hseigel
parents: 42650
diff changeset
   572
// Arrays for basic types
b5350a83520b 8153646: Move vm/utilities/array.hpp to vm/oops
hseigel
parents: 42650
diff changeset
   573
typedef GrowableArray<int> intArray;
b5350a83520b 8153646: Move vm/utilities/array.hpp to vm/oops
hseigel
parents: 42650
diff changeset
   574
typedef GrowableArray<int> intStack;
b5350a83520b 8153646: Move vm/utilities/array.hpp to vm/oops
hseigel
parents: 42650
diff changeset
   575
typedef GrowableArray<bool> boolArray;
b5350a83520b 8153646: Move vm/utilities/array.hpp to vm/oops
hseigel
parents: 42650
diff changeset
   576
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6180
diff changeset
   577
#endif // SHARE_VM_UTILITIES_GROWABLEARRAY_HPP