hotspot/src/share/vm/utilities/growableArray.hpp
changeset 1551 b431de37a22c
parent 1 489c9b5090e2
child 1623 a0dd9009e992
equal deleted inserted replaced
1550:be2fc37a817f 1551:b431de37a22c
   109     _arena = arena;
   109     _arena = arena;
   110     assert(on_arena(), "arena has taken on reserved value 0 or 1");
   110     assert(on_arena(), "arena has taken on reserved value 0 or 1");
   111   }
   111   }
   112 
   112 
   113   void* raw_allocate(int elementSize);
   113   void* raw_allocate(int elementSize);
       
   114 
       
   115   // some uses pass the Thread explicitly for speed (4990299 tuning)
       
   116   void* raw_allocate(Thread* thread, int elementSize) {
       
   117     assert(on_stack(), "fast ResourceObj path only");
       
   118     return (void*)resource_allocate_bytes(thread, elementSize * _max);
       
   119   }
   114 };
   120 };
   115 
   121 
   116 template<class E> class GrowableArray : public GenericGrowableArray {
   122 template<class E> class GrowableArray : public GenericGrowableArray {
   117  private:
   123  private:
   118   E*     _data;         // data array
   124   E*     _data;         // data array
   119 
   125 
   120   void grow(int j);
   126   void grow(int j);
   121   void raw_at_put_grow(int i, const E& p, const E& fill);
   127   void raw_at_put_grow(int i, const E& p, const E& fill);
   122   void  clear_and_deallocate();
   128   void  clear_and_deallocate();
   123  public:
   129  public:
       
   130   GrowableArray(Thread* thread, int initial_size) : GenericGrowableArray(initial_size, 0, false) {
       
   131     _data = (E*)raw_allocate(thread, sizeof(E));
       
   132     for (int i = 0; i < _max; i++) ::new ((void*)&_data[i]) E();
       
   133   }
       
   134 
   124   GrowableArray(int initial_size, bool C_heap = false) : GenericGrowableArray(initial_size, 0, C_heap) {
   135   GrowableArray(int initial_size, bool C_heap = false) : GenericGrowableArray(initial_size, 0, C_heap) {
   125     _data = (E*)raw_allocate(sizeof(E));
   136     _data = (E*)raw_allocate(sizeof(E));
   126     for (int i = 0; i < _max; i++) ::new ((void*)&_data[i]) E();
   137     for (int i = 0; i < _max; i++) ::new ((void*)&_data[i]) E();
   127   }
   138   }
   128 
   139 
   157   bool  is_full() const         { return _len == _max; }
   168   bool  is_full() const         { return _len == _max; }
   158   DEBUG_ONLY(E* data_addr() const      { return _data; })
   169   DEBUG_ONLY(E* data_addr() const      { return _data; })
   159 
   170 
   160   void print();
   171   void print();
   161 
   172 
   162   void append(const E& elem) {
   173   int append(const E& elem) {
   163     check_nesting();
   174     check_nesting();
   164     if (_len == _max) grow(_len);
   175     if (_len == _max) grow(_len);
   165     _data[_len++] = elem;
   176     int idx = _len++;
       
   177     _data[idx] = elem;
       
   178     return idx;
   166   }
   179   }
   167 
   180 
   168   void append_if_missing(const E& elem) {
   181   void append_if_missing(const E& elem) {
   169     if (!contains(elem)) append(elem);
   182     if (!contains(elem)) append(elem);
   170   }
   183   }