src/hotspot/share/utilities/stack.inline.hpp
author naoto
Tue, 09 Jul 2019 08:05:38 -0700
changeset 55627 9c1885fb2a42
parent 53244 9807daeb47c4
permissions -rw-r--r--
8227127: Era designator not displayed correctly using the COMPAT provider Reviewed-by: rriggs
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
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51334
diff changeset
     2
 * Copyright (c) 2009, 2019, 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
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51334
diff changeset
    25
#ifndef SHARE_UTILITIES_STACK_INLINE_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51334
diff changeset
    26
#define SHARE_UTILITIES_STACK_INLINE_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    27
49360
886acec3b4c6 8199275: Fix inclusions of allocation.inline.hpp
stefank
parents: 47216
diff changeset
    28
#include "memory/allocation.inline.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    29
#include "utilities/align.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    30
#include "utilities/stack.hpp"
46682
b646732e1473 8184762: ZapStackSegments should use optimized memset
shade
parents: 46625
diff changeset
    31
#include "utilities/copy.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    32
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    33
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
    34
                     size_t max_size):
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    35
  _seg_size(segment_size),
51334
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 49360
diff changeset
    36
  _max_size(adjust_max_size(max_size, segment_size)),
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 49360
diff changeset
    37
  _max_cache_size(max_cache_size)
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    38
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    39
  assert(_max_size % _seg_size == 0, "not a multiple");
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
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    42
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
    43
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    44
  assert(seg_size > 0, "cannot be 0");
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    45
  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
    46
  const size_t limit = max_uintx - (seg_size - 1);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    47
  if (max_size == 0 || max_size > limit) {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    48
    max_size = limit;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    49
  }
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    50
  return (max_size + seg_size - 1) / seg_size * seg_size;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    51
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    52
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    53
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    54
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
    55
  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
    56
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    57
  reset(true);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    58
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    59
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    60
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    61
void Stack<E, F>::push(E item)
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    62
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    63
  assert(!is_full(), "pushing onto a full stack");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    64
  if (this->_cur_seg_size == this->_seg_size) {
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    65
    push_segment();
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    66
  }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    67
  this->_cur_seg[this->_cur_seg_size] = item;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    68
  ++this->_cur_seg_size;
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    69
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    70
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    71
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    72
E Stack<E, F>::pop()
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    73
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    74
  assert(!is_empty(), "popping from an empty stack");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    75
  if (this->_cur_seg_size == 1) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    76
    E tmp = _cur_seg[--this->_cur_seg_size];
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    77
    pop_segment();
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    78
    return tmp;
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
  return this->_cur_seg[--this->_cur_seg_size];
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    81
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    82
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    83
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    84
void Stack<E, F>::clear(bool clear_cache)
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    85
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    86
  free_segments(_cur_seg);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    87
  if (clear_cache) free_segments(_cache);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    88
  reset(clear_cache);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    89
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    90
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    91
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    92
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
    93
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    94
  const size_t elem_sz = sizeof(E);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    95
  const size_t ptr_sz = sizeof(E*);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    96
  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
    97
  if (elem_sz < ptr_sz) {
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 37092
diff changeset
    98
    return align_up(seg_size * elem_sz, ptr_sz) / elem_sz;
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    99
  }
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   100
  return seg_size;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   101
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   102
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   103
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   104
size_t Stack<E, F>::link_offset() const
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   105
{
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 37092
diff changeset
   106
  return align_up(this->_seg_size * sizeof(E), sizeof(E*));
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   107
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   108
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   109
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   110
size_t Stack<E, F>::segment_bytes() const
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   111
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   112
  return link_offset() + sizeof(E*);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   113
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   114
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   115
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   116
E** Stack<E, F>::link_addr(E* seg) const
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   117
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   118
  return (E**) ((char*)seg + link_offset());
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   119
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   120
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   121
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   122
E* Stack<E, F>::get_link(E* seg) const
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   123
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   124
  return *link_addr(seg);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   125
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   126
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   127
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   128
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
   129
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   130
  *link_addr(new_seg) = old_seg;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   131
  return new_seg;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   132
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   133
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   134
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   135
E* Stack<E, F>::alloc(size_t bytes)
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   136
{
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   137
  return (E*) NEW_C_HEAP_ARRAY(char, bytes, F);
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   138
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   139
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   140
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   141
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
   142
{
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 13963
diff changeset
   143
  FREE_C_HEAP_ARRAY(char, (char*) addr);
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   144
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   145
37092
0e56e3c9d545 8151593: Cleanup definition/usage of INLINE/NOINLINE macros and add xlC support
simonis
parents: 32606
diff changeset
   146
// Stack is used by the GC code and in some hot paths a lot of the Stack
0e56e3c9d545 8151593: Cleanup definition/usage of INLINE/NOINLINE macros and add xlC support
simonis
parents: 32606
diff changeset
   147
// code gets inlined. This is generally good, but when too much code has
0e56e3c9d545 8151593: Cleanup definition/usage of INLINE/NOINLINE macros and add xlC support
simonis
parents: 32606
diff changeset
   148
// been inlined, no further inlining is allowed by GCC. Therefore we need
0e56e3c9d545 8151593: Cleanup definition/usage of INLINE/NOINLINE macros and add xlC support
simonis
parents: 32606
diff changeset
   149
// to prevent parts of the slow path in Stack to be inlined to allow other
0e56e3c9d545 8151593: Cleanup definition/usage of INLINE/NOINLINE macros and add xlC support
simonis
parents: 32606
diff changeset
   150
// code to be.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   151
template <class E, MEMFLAGS F>
32606
fdaa30d06ada 8129417: Oop iteration clean-up to remove oop_ms_follow_contents
sjohanss
parents: 30176
diff changeset
   152
NOINLINE 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*));
46682
b646732e1473 8184762: ZapStackSegments should use optimized memset
shade
parents: 46625
diff changeset
   238
  Copy::fill_to_bytes(seg, zap_bytes, badStackSegVal);
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   239
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   240
#endif
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   241
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   242
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   243
E* ResourceStack<E, F>::alloc(size_t bytes)
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   244
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   245
  return (E*) resource_allocate_bytes(bytes);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   246
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   247
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   248
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   249
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
   250
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   251
  resource_free_bytes((char*) addr, bytes);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   252
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   253
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   254
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   255
void StackIterator<E, F>::sync()
6762
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
  _full_seg_size = _stack._full_seg_size;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   258
  _cur_seg_size = _stack._cur_seg_size;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   259
  _cur_seg = _stack._cur_seg;
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
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   262
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   263
E* StackIterator<E, F>::next_addr()
6762
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
  assert(!is_empty(), "no items left");
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   266
  if (_cur_seg_size == 1) {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   267
    E* addr = _cur_seg;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   268
    _cur_seg = _stack.get_link(_cur_seg);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   269
    _cur_seg_size = _stack.segment_size();
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   270
    _full_seg_size -= _stack.segment_size();
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   271
    return addr;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   272
  }
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   273
  return _cur_seg + --_cur_seg_size;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   274
}
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
   275
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51334
diff changeset
   276
#endif // SHARE_UTILITIES_STACK_INLINE_HPP