hotspot/src/share/vm/utilities/stack.inline.hpp
author zgu
Tue, 19 Aug 2014 08:34:25 -0400
changeset 26144 35e11b657728
parent 13963 e5b53c306fb5
child 27880 afb974a04396
permissions -rw-r--r--
8055007: NMT2: emptyStack missing in minimal build Summary: Refactored emptyStack to a static member of NativeCallStack, which is accessible in minimal build. Reviewed-by: coleenp, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
     1
/*
13963
e5b53c306fb5 7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents: 13195
diff changeset
     2
 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
     4
 *
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
     8
 *
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    13
 * accompanied this code).
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    14
 *
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    18
 *
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    21
 * questions.
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    22
 *
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    23
 */
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    25
#ifndef SHARE_VM_UTILITIES_STACK_INLINE_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    26
#define SHARE_VM_UTILITIES_STACK_INLINE_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    28
#include "utilities/stack.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    29
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    30
template <MEMFLAGS F> StackBase<F>::StackBase(size_t segment_size, size_t max_cache_size,
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    31
                     size_t max_size):
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    32
  _seg_size(segment_size),
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    33
  _max_cache_size(max_cache_size),
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    34
  _max_size(adjust_max_size(max_size, segment_size))
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    35
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    36
  assert(_max_size % _seg_size == 0, "not a multiple");
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    37
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    38
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    39
template <MEMFLAGS F> size_t StackBase<F>::adjust_max_size(size_t max_size, size_t seg_size)
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    40
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    41
  assert(seg_size > 0, "cannot be 0");
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    42
  assert(max_size >= seg_size || max_size == 0, "max_size too small");
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    43
  const size_t limit = max_uintx - (seg_size - 1);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    44
  if (max_size == 0 || max_size > limit) {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    45
    max_size = limit;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    46
  }
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    47
  return (max_size + seg_size - 1) / seg_size * seg_size;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    48
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    49
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    50
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    51
Stack<E, F>::Stack(size_t segment_size, size_t max_cache_size, size_t max_size):
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    52
  StackBase<F>(adjust_segment_size(segment_size), max_cache_size, max_size)
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    53
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    54
  reset(true);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    55
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    56
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    57
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    58
void Stack<E, F>::push(E item)
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    59
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    60
  assert(!is_full(), "pushing onto a full stack");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    61
  if (this->_cur_seg_size == this->_seg_size) {
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    62
    push_segment();
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    63
  }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    64
  this->_cur_seg[this->_cur_seg_size] = item;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    65
  ++this->_cur_seg_size;
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    66
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    67
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    68
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    69
E Stack<E, F>::pop()
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    70
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    71
  assert(!is_empty(), "popping from an empty stack");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    72
  if (this->_cur_seg_size == 1) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    73
    E tmp = _cur_seg[--this->_cur_seg_size];
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    74
    pop_segment();
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    75
    return tmp;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    76
  }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    77
  return this->_cur_seg[--this->_cur_seg_size];
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    78
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    79
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    80
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    81
void Stack<E, F>::clear(bool clear_cache)
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    82
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    83
  free_segments(_cur_seg);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    84
  if (clear_cache) free_segments(_cache);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    85
  reset(clear_cache);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    86
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    87
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    88
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    89
size_t Stack<E, F>::default_segment_size()
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    90
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    91
  // Number of elements that fit in 4K bytes minus the size of two pointers
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    92
  // (link field and malloc header).
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    93
  return (4096 - 2 * sizeof(E*)) / sizeof(E);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    94
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    95
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    96
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    97
size_t Stack<E, F>::adjust_segment_size(size_t seg_size)
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    98
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    99
  const size_t elem_sz = sizeof(E);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   100
  const size_t ptr_sz = sizeof(E*);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   101
  assert(elem_sz % ptr_sz == 0 || ptr_sz % elem_sz == 0, "bad element size");
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   102
  if (elem_sz < ptr_sz) {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   103
    return align_size_up(seg_size * elem_sz, ptr_sz) / elem_sz;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   104
  }
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   105
  return seg_size;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   106
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   107
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   108
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   109
size_t Stack<E, F>::link_offset() const
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   110
{
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   111
  return align_size_up(this->_seg_size * sizeof(E), sizeof(E*));
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   112
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   113
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   114
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   115
size_t Stack<E, F>::segment_bytes() const
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   116
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   117
  return link_offset() + sizeof(E*);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   118
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   119
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   120
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   121
E** Stack<E, F>::link_addr(E* seg) const
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   122
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   123
  return (E**) ((char*)seg + link_offset());
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   124
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   125
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   126
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   127
E* Stack<E, F>::get_link(E* seg) const
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   128
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   129
  return *link_addr(seg);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   130
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   131
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   132
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   133
E* Stack<E, F>::set_link(E* new_seg, E* old_seg)
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   134
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   135
  *link_addr(new_seg) = old_seg;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   136
  return new_seg;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   137
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   138
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   139
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   140
E* Stack<E, F>::alloc(size_t bytes)
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   141
{
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   142
  return (E*) NEW_C_HEAP_ARRAY(char, bytes, F);
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   143
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   144
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   145
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   146
void Stack<E, F>::free(E* addr, size_t bytes)
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   147
{
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   148
  FREE_C_HEAP_ARRAY(char, (char*) addr, F);
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   149
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   150
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   151
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   152
void Stack<E, F>::push_segment()
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   153
{
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   154
  assert(this->_cur_seg_size == this->_seg_size, "current segment is not full");
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   155
  E* next;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   156
  if (this->_cache_size > 0) {
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   157
    // Use a cached segment.
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   158
    next = _cache;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   159
    _cache = get_link(_cache);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   160
    --this->_cache_size;
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   161
  } else {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   162
    next = alloc(segment_bytes());
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   163
    DEBUG_ONLY(zap_segment(next, true);)
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   164
  }
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   165
  const bool at_empty_transition = is_empty();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   166
  this->_cur_seg = set_link(next, _cur_seg);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   167
  this->_cur_seg_size = 0;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   168
  this->_full_seg_size += at_empty_transition ? 0 : this->_seg_size;
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   169
  DEBUG_ONLY(verify(at_empty_transition);)
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   170
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   171
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   172
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   173
void Stack<E, F>::pop_segment()
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   174
{
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   175
  assert(this->_cur_seg_size == 0, "current segment is not empty");
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   176
  E* const prev = get_link(_cur_seg);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   177
  if (this->_cache_size < this->_max_cache_size) {
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   178
    // Add the current segment to the cache.
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   179
    DEBUG_ONLY(zap_segment(_cur_seg, false);)
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   180
    _cache = set_link(_cur_seg, _cache);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   181
    ++this->_cache_size;
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   182
  } else {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   183
    DEBUG_ONLY(zap_segment(_cur_seg, true);)
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   184
    free(_cur_seg, segment_bytes());
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   185
  }
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   186
  const bool at_empty_transition = prev == NULL;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   187
  this->_cur_seg = prev;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   188
  this->_cur_seg_size = this->_seg_size;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   189
  this->_full_seg_size -= at_empty_transition ? 0 : this->_seg_size;
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   190
  DEBUG_ONLY(verify(at_empty_transition);)
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   191
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   192
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   193
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   194
void Stack<E, F>::free_segments(E* seg)
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   195
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   196
  const size_t bytes = segment_bytes();
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   197
  while (seg != NULL) {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   198
    E* const prev = get_link(seg);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   199
    free(seg, bytes);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   200
    seg = prev;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   201
  }
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   202
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   203
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   204
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   205
void Stack<E, F>::reset(bool reset_cache)
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   206
{
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   207
  this->_cur_seg_size = this->_seg_size; // So push() will alloc a new segment.
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   208
  this->_full_seg_size = 0;
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   209
  _cur_seg = NULL;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   210
  if (reset_cache) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   211
    this->_cache_size = 0;
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   212
    _cache = NULL;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   213
  }
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   214
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   215
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   216
#ifdef ASSERT
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   217
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   218
void Stack<E, F>::verify(bool at_empty_transition) const
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   219
{
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   220
  assert(size() <= this->max_size(), "stack exceeded bounds");
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   221
  assert(this->cache_size() <= this->max_cache_size(), "cache exceeded bounds");
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   222
  assert(this->_cur_seg_size <= this->segment_size(), "segment index exceeded bounds");
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   223
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   224
  assert(this->_full_seg_size % this->_seg_size == 0, "not a multiple");
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   225
  assert(at_empty_transition || is_empty() == (size() == 0), "mismatch");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   226
  assert((_cache == NULL) == (this->cache_size() == 0), "mismatch");
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   227
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   228
  if (is_empty()) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   229
    assert(this->_cur_seg_size == this->segment_size(), "sanity");
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   230
  }
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   231
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   232
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   233
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   234
void Stack<E, F>::zap_segment(E* seg, bool zap_link_field) const
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   235
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   236
  if (!ZapStackSegments) return;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   237
  const size_t zap_bytes = segment_bytes() - (zap_link_field ? 0 : sizeof(E*));
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   238
  uint32_t* cur = (uint32_t*)seg;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   239
  const uint32_t* end = cur + zap_bytes / sizeof(uint32_t);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   240
  while (cur < end) {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   241
    *cur++ = 0xfadfaded;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   242
  }
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   243
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   244
#endif
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   245
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   246
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   247
E* ResourceStack<E, F>::alloc(size_t bytes)
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   248
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   249
  return (E*) resource_allocate_bytes(bytes);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   250
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   251
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   252
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   253
void ResourceStack<E, F>::free(E* addr, size_t bytes)
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   254
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   255
  resource_free_bytes((char*) addr, bytes);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   256
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   257
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   258
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   259
void StackIterator<E, F>::sync()
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   260
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   261
  _full_seg_size = _stack._full_seg_size;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   262
  _cur_seg_size = _stack._cur_seg_size;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   263
  _cur_seg = _stack._cur_seg;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   264
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   265
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   266
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   267
E* StackIterator<E, F>::next_addr()
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   268
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   269
  assert(!is_empty(), "no items left");
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   270
  if (_cur_seg_size == 1) {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   271
    E* addr = _cur_seg;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   272
    _cur_seg = _stack.get_link(_cur_seg);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   273
    _cur_seg_size = _stack.segment_size();
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   274
    _full_seg_size -= _stack.segment_size();
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   275
    return addr;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   276
  }
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   277
  return _cur_seg + --_cur_seg_size;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   278
}
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
   279
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
   280
#endif // SHARE_VM_UTILITIES_STACK_INLINE_HPP