src/share/vm/utilities/stack.inline.hpp

changeset 3900
d2a62e0f25eb
parent 2314
f95d63e2154a
child 4153
b9a9ed0f8eeb
     1.1 --- a/src/share/vm/utilities/stack.inline.hpp	Wed Jun 27 15:23:36 2012 +0200
     1.2 +++ b/src/share/vm/utilities/stack.inline.hpp	Thu Jun 28 17:03:16 2012 -0400
     1.3 @@ -27,7 +27,7 @@
     1.4  
     1.5  #include "utilities/stack.hpp"
     1.6  
     1.7 -StackBase::StackBase(size_t segment_size, size_t max_cache_size,
     1.8 +template <MEMFLAGS F> StackBase<F>::StackBase(size_t segment_size, size_t max_cache_size,
     1.9                       size_t max_size):
    1.10    _seg_size(segment_size),
    1.11    _max_cache_size(max_cache_size),
    1.12 @@ -36,7 +36,7 @@
    1.13    assert(_max_size % _seg_size == 0, "not a multiple");
    1.14  }
    1.15  
    1.16 -size_t StackBase::adjust_max_size(size_t max_size, size_t seg_size)
    1.17 +template <MEMFLAGS F> size_t StackBase<F>::adjust_max_size(size_t max_size, size_t seg_size)
    1.18  {
    1.19    assert(seg_size > 0, "cannot be 0");
    1.20    assert(max_size >= seg_size || max_size == 0, "max_size too small");
    1.21 @@ -47,54 +47,54 @@
    1.22    return (max_size + seg_size - 1) / seg_size * seg_size;
    1.23  }
    1.24  
    1.25 -template <class E>
    1.26 -Stack<E>::Stack(size_t segment_size, size_t max_cache_size, size_t max_size):
    1.27 -  StackBase(adjust_segment_size(segment_size), max_cache_size, max_size)
    1.28 +template <class E, MEMFLAGS F>
    1.29 +Stack<E, F>::Stack(size_t segment_size, size_t max_cache_size, size_t max_size):
    1.30 +  StackBase<F>(adjust_segment_size(segment_size), max_cache_size, max_size)
    1.31  {
    1.32    reset(true);
    1.33  }
    1.34  
    1.35 -template <class E>
    1.36 -void Stack<E>::push(E item)
    1.37 +template <class E, MEMFLAGS F>
    1.38 +void Stack<E, F>::push(E item)
    1.39  {
    1.40    assert(!is_full(), "pushing onto a full stack");
    1.41 -  if (_cur_seg_size == _seg_size) {
    1.42 +  if (this->_cur_seg_size == this->_seg_size) {
    1.43      push_segment();
    1.44    }
    1.45 -  _cur_seg[_cur_seg_size] = item;
    1.46 -  ++_cur_seg_size;
    1.47 +  this->_cur_seg[this->_cur_seg_size] = item;
    1.48 +  ++this->_cur_seg_size;
    1.49  }
    1.50  
    1.51 -template <class E>
    1.52 -E Stack<E>::pop()
    1.53 +template <class E, MEMFLAGS F>
    1.54 +E Stack<E, F>::pop()
    1.55  {
    1.56    assert(!is_empty(), "popping from an empty stack");
    1.57 -  if (_cur_seg_size == 1) {
    1.58 -    E tmp = _cur_seg[--_cur_seg_size];
    1.59 +  if (this->_cur_seg_size == 1) {
    1.60 +    E tmp = _cur_seg[--this->_cur_seg_size];
    1.61      pop_segment();
    1.62      return tmp;
    1.63    }
    1.64 -  return _cur_seg[--_cur_seg_size];
    1.65 +  return this->_cur_seg[--this->_cur_seg_size];
    1.66  }
    1.67  
    1.68 -template <class E>
    1.69 -void Stack<E>::clear(bool clear_cache)
    1.70 +template <class E, MEMFLAGS F>
    1.71 +void Stack<E, F>::clear(bool clear_cache)
    1.72  {
    1.73    free_segments(_cur_seg);
    1.74    if (clear_cache) free_segments(_cache);
    1.75    reset(clear_cache);
    1.76  }
    1.77  
    1.78 -template <class E>
    1.79 -size_t Stack<E>::default_segment_size()
    1.80 +template <class E, MEMFLAGS F>
    1.81 +size_t Stack<E, F>::default_segment_size()
    1.82  {
    1.83    // Number of elements that fit in 4K bytes minus the size of two pointers
    1.84    // (link field and malloc header).
    1.85    return (4096 - 2 * sizeof(E*)) / sizeof(E);
    1.86  }
    1.87  
    1.88 -template <class E>
    1.89 -size_t Stack<E>::adjust_segment_size(size_t seg_size)
    1.90 +template <class E, MEMFLAGS F>
    1.91 +size_t Stack<E, F>::adjust_segment_size(size_t seg_size)
    1.92  {
    1.93    const size_t elem_sz = sizeof(E);
    1.94    const size_t ptr_sz = sizeof(E*);
    1.95 @@ -105,93 +105,93 @@
    1.96    return seg_size;
    1.97  }
    1.98  
    1.99 -template <class E>
   1.100 -size_t Stack<E>::link_offset() const
   1.101 +template <class E, MEMFLAGS F>
   1.102 +size_t Stack<E, F>::link_offset() const
   1.103  {
   1.104 -  return align_size_up(_seg_size * sizeof(E), sizeof(E*));
   1.105 +  return align_size_up(this->_seg_size * sizeof(E), sizeof(E*));
   1.106  }
   1.107  
   1.108 -template <class E>
   1.109 -size_t Stack<E>::segment_bytes() const
   1.110 +template <class E, MEMFLAGS F>
   1.111 +size_t Stack<E, F>::segment_bytes() const
   1.112  {
   1.113    return link_offset() + sizeof(E*);
   1.114  }
   1.115  
   1.116 -template <class E>
   1.117 -E** Stack<E>::link_addr(E* seg) const
   1.118 +template <class E, MEMFLAGS F>
   1.119 +E** Stack<E, F>::link_addr(E* seg) const
   1.120  {
   1.121    return (E**) ((char*)seg + link_offset());
   1.122  }
   1.123  
   1.124 -template <class E>
   1.125 -E* Stack<E>::get_link(E* seg) const
   1.126 +template <class E, MEMFLAGS F>
   1.127 +E* Stack<E, F>::get_link(E* seg) const
   1.128  {
   1.129    return *link_addr(seg);
   1.130  }
   1.131  
   1.132 -template <class E>
   1.133 -E* Stack<E>::set_link(E* new_seg, E* old_seg)
   1.134 +template <class E, MEMFLAGS F>
   1.135 +E* Stack<E, F>::set_link(E* new_seg, E* old_seg)
   1.136  {
   1.137    *link_addr(new_seg) = old_seg;
   1.138    return new_seg;
   1.139  }
   1.140  
   1.141 -template <class E>
   1.142 -E* Stack<E>::alloc(size_t bytes)
   1.143 +template <class E, MEMFLAGS F>
   1.144 +E* Stack<E, F>::alloc(size_t bytes)
   1.145  {
   1.146 -  return (E*) NEW_C_HEAP_ARRAY(char, bytes);
   1.147 +  return (E*) NEW_C_HEAP_ARRAY(char, bytes, F);
   1.148  }
   1.149  
   1.150 -template <class E>
   1.151 -void Stack<E>::free(E* addr, size_t bytes)
   1.152 +template <class E, MEMFLAGS F>
   1.153 +void Stack<E, F>::free(E* addr, size_t bytes)
   1.154  {
   1.155 -  FREE_C_HEAP_ARRAY(char, (char*) addr);
   1.156 +  FREE_C_HEAP_ARRAY(char, (char*) addr, F);
   1.157  }
   1.158  
   1.159 -template <class E>
   1.160 -void Stack<E>::push_segment()
   1.161 +template <class E, MEMFLAGS F>
   1.162 +void Stack<E, F>::push_segment()
   1.163  {
   1.164 -  assert(_cur_seg_size == _seg_size, "current segment is not full");
   1.165 +  assert(this->_cur_seg_size == this->_seg_size, "current segment is not full");
   1.166    E* next;
   1.167 -  if (_cache_size > 0) {
   1.168 +  if (this->_cache_size > 0) {
   1.169      // Use a cached segment.
   1.170      next = _cache;
   1.171      _cache = get_link(_cache);
   1.172 -    --_cache_size;
   1.173 +    --this->_cache_size;
   1.174    } else {
   1.175      next = alloc(segment_bytes());
   1.176      DEBUG_ONLY(zap_segment(next, true);)
   1.177    }
   1.178    const bool at_empty_transition = is_empty();
   1.179 -  _cur_seg = set_link(next, _cur_seg);
   1.180 -  _cur_seg_size = 0;
   1.181 -  _full_seg_size += at_empty_transition ? 0 : _seg_size;
   1.182 +  this->_cur_seg = set_link(next, _cur_seg);
   1.183 +  this->_cur_seg_size = 0;
   1.184 +  this->_full_seg_size += at_empty_transition ? 0 : this->_seg_size;
   1.185    DEBUG_ONLY(verify(at_empty_transition);)
   1.186  }
   1.187  
   1.188 -template <class E>
   1.189 -void Stack<E>::pop_segment()
   1.190 +template <class E, MEMFLAGS F>
   1.191 +void Stack<E, F>::pop_segment()
   1.192  {
   1.193 -  assert(_cur_seg_size == 0, "current segment is not empty");
   1.194 +  assert(this->_cur_seg_size == 0, "current segment is not empty");
   1.195    E* const prev = get_link(_cur_seg);
   1.196 -  if (_cache_size < _max_cache_size) {
   1.197 +  if (this->_cache_size < this->_max_cache_size) {
   1.198      // Add the current segment to the cache.
   1.199      DEBUG_ONLY(zap_segment(_cur_seg, false);)
   1.200      _cache = set_link(_cur_seg, _cache);
   1.201 -    ++_cache_size;
   1.202 +    ++this->_cache_size;
   1.203    } else {
   1.204      DEBUG_ONLY(zap_segment(_cur_seg, true);)
   1.205      free(_cur_seg, segment_bytes());
   1.206    }
   1.207    const bool at_empty_transition = prev == NULL;
   1.208 -  _cur_seg = prev;
   1.209 -  _cur_seg_size = _seg_size;
   1.210 -  _full_seg_size -= at_empty_transition ? 0 : _seg_size;
   1.211 +  this->_cur_seg = prev;
   1.212 +  this->_cur_seg_size = this->_seg_size;
   1.213 +  this->_full_seg_size -= at_empty_transition ? 0 : this->_seg_size;
   1.214    DEBUG_ONLY(verify(at_empty_transition);)
   1.215  }
   1.216  
   1.217 -template <class E>
   1.218 -void Stack<E>::free_segments(E* seg)
   1.219 +template <class E, MEMFLAGS F>
   1.220 +void Stack<E, F>::free_segments(E* seg)
   1.221  {
   1.222    const size_t bytes = segment_bytes();
   1.223    while (seg != NULL) {
   1.224 @@ -201,37 +201,37 @@
   1.225    }
   1.226  }
   1.227  
   1.228 -template <class E>
   1.229 -void Stack<E>::reset(bool reset_cache)
   1.230 +template <class E, MEMFLAGS F>
   1.231 +void Stack<E, F>::reset(bool reset_cache)
   1.232  {
   1.233 -  _cur_seg_size = _seg_size; // So push() will alloc a new segment.
   1.234 -  _full_seg_size = 0;
   1.235 +  this->_cur_seg_size = this->_seg_size; // So push() will alloc a new segment.
   1.236 +  this->_full_seg_size = 0;
   1.237    _cur_seg = NULL;
   1.238    if (reset_cache) {
   1.239 -    _cache_size = 0;
   1.240 +    this->_cache_size = 0;
   1.241      _cache = NULL;
   1.242    }
   1.243  }
   1.244  
   1.245  #ifdef ASSERT
   1.246 -template <class E>
   1.247 -void Stack<E>::verify(bool at_empty_transition) const
   1.248 +template <class E, MEMFLAGS F>
   1.249 +void Stack<E, F>::verify(bool at_empty_transition) const
   1.250  {
   1.251 -  assert(size() <= max_size(), "stack exceeded bounds");
   1.252 -  assert(cache_size() <= max_cache_size(), "cache exceeded bounds");
   1.253 -  assert(_cur_seg_size <= segment_size(), "segment index exceeded bounds");
   1.254 +  assert(size() <= this->max_size(), "stack exceeded bounds");
   1.255 +  assert(this->cache_size() <= this->max_cache_size(), "cache exceeded bounds");
   1.256 +  assert(this->_cur_seg_size <= this->segment_size(), "segment index exceeded bounds");
   1.257  
   1.258 -  assert(_full_seg_size % _seg_size == 0, "not a multiple");
   1.259 +  assert(this->_full_seg_size % this->_seg_size == 0, "not a multiple");
   1.260    assert(at_empty_transition || is_empty() == (size() == 0), "mismatch");
   1.261 -  assert((_cache == NULL) == (cache_size() == 0), "mismatch");
   1.262 +  assert((_cache == NULL) == (this->cache_size() == 0), "mismatch");
   1.263  
   1.264    if (is_empty()) {
   1.265 -    assert(_cur_seg_size == segment_size(), "sanity");
   1.266 +    assert(this->_cur_seg_size == this->segment_size(), "sanity");
   1.267    }
   1.268  }
   1.269  
   1.270 -template <class E>
   1.271 -void Stack<E>::zap_segment(E* seg, bool zap_link_field) const
   1.272 +template <class E, MEMFLAGS F>
   1.273 +void Stack<E, F>::zap_segment(E* seg, bool zap_link_field) const
   1.274  {
   1.275    if (!ZapStackSegments) return;
   1.276    const size_t zap_bytes = segment_bytes() - (zap_link_field ? 0 : sizeof(E*));
   1.277 @@ -243,28 +243,28 @@
   1.278  }
   1.279  #endif
   1.280  
   1.281 -template <class E>
   1.282 -E* ResourceStack<E>::alloc(size_t bytes)
   1.283 +template <class E, MEMFLAGS F>
   1.284 +E* ResourceStack<E, F>::alloc(size_t bytes)
   1.285  {
   1.286    return (E*) resource_allocate_bytes(bytes);
   1.287  }
   1.288  
   1.289 -template <class E>
   1.290 -void ResourceStack<E>::free(E* addr, size_t bytes)
   1.291 +template <class E, MEMFLAGS F>
   1.292 +void ResourceStack<E, F>::free(E* addr, size_t bytes)
   1.293  {
   1.294    resource_free_bytes((char*) addr, bytes);
   1.295  }
   1.296  
   1.297 -template <class E>
   1.298 -void StackIterator<E>::sync()
   1.299 +template <class E, MEMFLAGS F>
   1.300 +void StackIterator<E, F>::sync()
   1.301  {
   1.302    _full_seg_size = _stack._full_seg_size;
   1.303    _cur_seg_size = _stack._cur_seg_size;
   1.304    _cur_seg = _stack._cur_seg;
   1.305  }
   1.306  
   1.307 -template <class E>
   1.308 -E* StackIterator<E>::next_addr()
   1.309 +template <class E, MEMFLAGS F>
   1.310 +E* StackIterator<E, F>::next_addr()
   1.311  {
   1.312    assert(!is_empty(), "no items left");
   1.313    if (_cur_seg_size == 1) {

mercurial