hotspot/src/share/vm/utilities/stack.inline.hpp
author ccheung
Mon, 28 Aug 2017 15:34:04 -0700
changeset 47103 a993ec29ec75
parent 46682 b646732e1473
permissions -rw-r--r--
8186842: Use Java class loaders for creating the CDS archive Reviewed-by: coleenp, jiangli, iklam, mseledtsov Contributed-by: calvin.cheung@oracle.com, ioi.lam@oracle.com
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
/*
37092
0e56e3c9d545 8151593: Cleanup definition/usage of INLINE/NOINLINE macros and add xlC support
simonis
parents: 32606
diff changeset
     2
 * Copyright (c) 2009, 2016, 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
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    28
#include "utilities/align.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    29
#include "utilities/stack.hpp"
46682
b646732e1473 8184762: ZapStackSegments should use optimized memset
shade
parents: 46625
diff changeset
    30
#include "utilities/copy.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
    31
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    32
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
    33
                     size_t max_size):
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    34
  _seg_size(segment_size),
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    35
  _max_cache_size(max_cache_size),
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    36
  _max_size(adjust_max_size(max_size, segment_size))
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
  assert(_max_size % _seg_size == 0, "not a multiple");
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    39
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    40
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    41
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
    42
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    43
  assert(seg_size > 0, "cannot be 0");
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    44
  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
    45
  const size_t limit = max_uintx - (seg_size - 1);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    46
  if (max_size == 0 || max_size > limit) {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    47
    max_size = limit;
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
  return (max_size + seg_size - 1) / seg_size * seg_size;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    50
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    51
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    52
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    53
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
    54
  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
    55
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    56
  reset(true);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    57
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    58
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    59
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    60
void Stack<E, F>::push(E item)
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    61
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    62
  assert(!is_full(), "pushing onto a full stack");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    63
  if (this->_cur_seg_size == this->_seg_size) {
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    64
    push_segment();
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    65
  }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    66
  this->_cur_seg[this->_cur_seg_size] = item;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    67
  ++this->_cur_seg_size;
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    68
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    69
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    70
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    71
E Stack<E, F>::pop()
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    72
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    73
  assert(!is_empty(), "popping from an empty stack");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    74
  if (this->_cur_seg_size == 1) {
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    75
    E tmp = _cur_seg[--this->_cur_seg_size];
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    76
    pop_segment();
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    77
    return tmp;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    78
  }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    79
  return this->_cur_seg[--this->_cur_seg_size];
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    80
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    81
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    82
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    83
void Stack<E, F>::clear(bool clear_cache)
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    84
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    85
  free_segments(_cur_seg);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    86
  if (clear_cache) free_segments(_cache);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    87
  reset(clear_cache);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    88
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    89
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    90
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    91
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
    92
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    93
  const size_t elem_sz = sizeof(E);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    94
  const size_t ptr_sz = sizeof(E*);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    95
  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
    96
  if (elem_sz < ptr_sz) {
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 37092
diff changeset
    97
    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
    98
  }
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
    99
  return seg_size;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   100
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   101
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   102
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   103
size_t Stack<E, F>::link_offset() const
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   104
{
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 37092
diff changeset
   105
  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
   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>::segment_bytes() const
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   110
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   111
  return link_offset() + sizeof(E*);
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
E** Stack<E, F>::link_addr(E* seg) 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 (E**) ((char*)seg + link_offset());
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>::get_link(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 *link_addr(seg);
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>::set_link(E* new_seg, E* old_seg)
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
  *link_addr(new_seg) = old_seg;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   130
  return new_seg;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   131
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   132
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   133
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   134
E* Stack<E, F>::alloc(size_t bytes)
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   135
{
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   136
  return (E*) NEW_C_HEAP_ARRAY(char, bytes, F);
6762
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
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
   141
{
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 13963
diff changeset
   142
  FREE_C_HEAP_ARRAY(char, (char*) addr);
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
37092
0e56e3c9d545 8151593: Cleanup definition/usage of INLINE/NOINLINE macros and add xlC support
simonis
parents: 32606
diff changeset
   145
// 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
   146
// 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
   147
// 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
   148
// 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
   149
// code to be.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   150
template <class E, MEMFLAGS F>
32606
fdaa30d06ada 8129417: Oop iteration clean-up to remove oop_ms_follow_contents
sjohanss
parents: 30176
diff changeset
   151
NOINLINE void Stack<E, F>::push_segment()
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   152
{
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   153
  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
   154
  E* next;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   155
  if (this->_cache_size > 0) {
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   156
    // Use a cached segment.
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   157
    next = _cache;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   158
    _cache = get_link(_cache);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   159
    --this->_cache_size;
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   160
  } else {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   161
    next = alloc(segment_bytes());
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   162
    DEBUG_ONLY(zap_segment(next, true);)
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   163
  }
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   164
  const bool at_empty_transition = is_empty();
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   165
  this->_cur_seg = set_link(next, _cur_seg);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   166
  this->_cur_seg_size = 0;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   167
  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
   168
  DEBUG_ONLY(verify(at_empty_transition);)
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   169
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   170
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   171
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   172
void Stack<E, F>::pop_segment()
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   173
{
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   174
  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
   175
  E* const prev = get_link(_cur_seg);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   176
  if (this->_cache_size < this->_max_cache_size) {
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   177
    // Add the current segment to the cache.
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   178
    DEBUG_ONLY(zap_segment(_cur_seg, false);)
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   179
    _cache = set_link(_cur_seg, _cache);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   180
    ++this->_cache_size;
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   181
  } else {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   182
    DEBUG_ONLY(zap_segment(_cur_seg, true);)
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   183
    free(_cur_seg, segment_bytes());
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   184
  }
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   185
  const bool at_empty_transition = prev == NULL;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   186
  this->_cur_seg = prev;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   187
  this->_cur_seg_size = this->_seg_size;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   188
  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
   189
  DEBUG_ONLY(verify(at_empty_transition);)
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   190
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   191
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   192
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   193
void Stack<E, F>::free_segments(E* seg)
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   194
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   195
  const size_t bytes = segment_bytes();
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   196
  while (seg != NULL) {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   197
    E* const prev = get_link(seg);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   198
    free(seg, bytes);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   199
    seg = prev;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   200
  }
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
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   203
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   204
void Stack<E, F>::reset(bool reset_cache)
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   205
{
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   206
  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
   207
  this->_full_seg_size = 0;
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   208
  _cur_seg = NULL;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   209
  if (reset_cache) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   210
    this->_cache_size = 0;
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   211
    _cache = NULL;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   212
  }
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
#ifdef ASSERT
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   216
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   217
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
   218
{
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   219
  assert(size() <= this->max_size(), "stack exceeded bounds");
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   220
  assert(this->cache_size() <= this->max_cache_size(), "cache exceeded bounds");
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   221
  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
   222
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   223
  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
   224
  assert(at_empty_transition || is_empty() == (size() == 0), "mismatch");
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   225
  assert((_cache == NULL) == (this->cache_size() == 0), "mismatch");
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   226
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   227
  if (is_empty()) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   228
    assert(this->_cur_seg_size == this->segment_size(), "sanity");
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   229
  }
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
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   232
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   233
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
   234
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   235
  if (!ZapStackSegments) return;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   236
  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
   237
  Copy::fill_to_bytes(seg, zap_bytes, badStackSegVal);
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   238
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   239
#endif
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   240
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   241
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   242
E* ResourceStack<E, F>::alloc(size_t bytes)
6762
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
  return (E*) resource_allocate_bytes(bytes);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   245
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   246
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   247
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   248
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
   249
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   250
  resource_free_bytes((char*) addr, bytes);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   251
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   252
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   253
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   254
void StackIterator<E, F>::sync()
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   255
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   256
  _full_seg_size = _stack._full_seg_size;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   257
  _cur_seg_size = _stack._cur_seg_size;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   258
  _cur_seg = _stack._cur_seg;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   259
}
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   260
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   261
template <class E, MEMFLAGS F>
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   262
E* StackIterator<E, F>::next_addr()
6762
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   263
{
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   264
  assert(!is_empty(), "no items left");
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   265
  if (_cur_seg_size == 1) {
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   266
    E* addr = _cur_seg;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   267
    _cur_seg = _stack.get_link(_cur_seg);
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   268
    _cur_seg_size = _stack.segment_size();
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   269
    _full_seg_size -= _stack.segment_size();
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   270
    return addr;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   271
  }
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   272
  return _cur_seg + --_cur_seg_size;
f8d1b560700e 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
   273
}
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
   274
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6762
diff changeset
   275
#endif // SHARE_VM_UTILITIES_STACK_INLINE_HPP