annotate src/share/vm/utilities/stack.inline.hpp @ 14649:f6301b007a16

6498581: ThreadInterruptTest3 produces wrong output on Windows Summary: There is race condition between os::interrupt and os::is_interrupted on Windows. In JVM_Sleep(Thread.sleep), check if thread gets interrupted, it may see interrupted but not really interrupted so cause spurious waking up (early return from sleep). Fix by checking if interrupt event really gets set thus prevent false return. For intrinsic of _isInterrupted, on Windows, go fastpath only on bit not set. Reviewed-by: acorn, kvn Contributed-by: david.holmes@oracle.com, yumin.qi@oracle.com
author minqi
date Wed, 26 Feb 2014 15:20:41 -0800
parents b9a9ed0f8eeb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
1 /*
6842
b9a9ed0f8eeb 7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents: 6197
diff changeset
2 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
1836
894b1d7c7e01 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.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
4 *
894b1d7c7e01 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
894b1d7c7e01 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
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
7 * published by the Free Software Foundation.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
8 *
894b1d7c7e01 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
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
894b1d7c7e01 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
894b1d7c7e01 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
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
13 * accompanied this code).
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
14 *
894b1d7c7e01 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
894b1d7c7e01 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,
894b1d7c7e01 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.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
18 *
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1836
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1836
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1836
diff changeset
21 * questions.
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
22 *
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
23 */
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1836
diff changeset
25 #ifndef SHARE_VM_UTILITIES_STACK_INLINE_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1836
diff changeset
26 #define SHARE_VM_UTILITIES_STACK_INLINE_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1836
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1836
diff changeset
28 #include "utilities/stack.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1836
diff changeset
29
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
30 template <MEMFLAGS F> StackBase<F>::StackBase(size_t segment_size, size_t max_cache_size,
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
31 size_t max_size):
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
32 _seg_size(segment_size),
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
33 _max_cache_size(max_cache_size),
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
34 _max_size(adjust_max_size(max_size, segment_size))
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
35 {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
36 assert(_max_size % _seg_size == 0, "not a multiple");
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
37 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
38
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
39 template <MEMFLAGS F> size_t StackBase<F>::adjust_max_size(size_t max_size, size_t seg_size)
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
40 {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
41 assert(seg_size > 0, "cannot be 0");
894b1d7c7e01 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");
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
43 const size_t limit = max_uintx - (seg_size - 1);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
44 if (max_size == 0 || max_size > limit) {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
45 max_size = limit;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
46 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
47 return (max_size + seg_size - 1) / seg_size * seg_size;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
48 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
49
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
50 template <class E, MEMFLAGS F>
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
51 Stack<E, F>::Stack(size_t segment_size, size_t max_cache_size, size_t max_size):
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
52 StackBase<F>(adjust_segment_size(segment_size), max_cache_size, max_size)
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
53 {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
54 reset(true);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
55 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
56
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
57 template <class E, MEMFLAGS F>
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
58 void Stack<E, F>::push(E item)
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
59 {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
60 assert(!is_full(), "pushing onto a full stack");
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
61 if (this->_cur_seg_size == this->_seg_size) {
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
62 push_segment();
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
63 }
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
64 this->_cur_seg[this->_cur_seg_size] = item;
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
65 ++this->_cur_seg_size;
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
66 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
67
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
68 template <class E, MEMFLAGS F>
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
69 E Stack<E, F>::pop()
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
70 {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
71 assert(!is_empty(), "popping from an empty stack");
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
72 if (this->_cur_seg_size == 1) {
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
73 E tmp = _cur_seg[--this->_cur_seg_size];
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
74 pop_segment();
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
75 return tmp;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
76 }
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
77 return this->_cur_seg[--this->_cur_seg_size];
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
78 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
79
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
80 template <class E, MEMFLAGS F>
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
81 void Stack<E, F>::clear(bool clear_cache)
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
82 {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
83 free_segments(_cur_seg);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
84 if (clear_cache) free_segments(_cache);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
85 reset(clear_cache);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
86 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
87
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
88 template <class E, MEMFLAGS F>
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
89 size_t Stack<E, F>::default_segment_size()
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
90 {
894b1d7c7e01 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
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
92 // (link field and malloc header).
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
93 return (4096 - 2 * sizeof(E*)) / sizeof(E);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
94 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
95
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
96 template <class E, MEMFLAGS F>
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
97 size_t Stack<E, F>::adjust_segment_size(size_t seg_size)
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
98 {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
99 const size_t elem_sz = sizeof(E);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
100 const size_t ptr_sz = sizeof(E*);
894b1d7c7e01 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");
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
102 if (elem_sz < ptr_sz) {
894b1d7c7e01 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;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
104 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
105 return seg_size;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
106 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
107
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
108 template <class E, MEMFLAGS F>
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
109 size_t Stack<E, F>::link_offset() const
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
110 {
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
111 return align_size_up(this->_seg_size * sizeof(E), sizeof(E*));
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
112 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
113
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
114 template <class E, MEMFLAGS F>
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
115 size_t Stack<E, F>::segment_bytes() const
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
116 {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
117 return link_offset() + sizeof(E*);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
118 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
119
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
120 template <class E, MEMFLAGS F>
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
121 E** Stack<E, F>::link_addr(E* seg) const
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
122 {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
123 return (E**) ((char*)seg + link_offset());
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
124 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
125
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
126 template <class E, MEMFLAGS F>
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
127 E* Stack<E, F>::get_link(E* seg) const
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
128 {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
129 return *link_addr(seg);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
130 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
131
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
132 template <class E, MEMFLAGS F>
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
133 E* Stack<E, F>::set_link(E* new_seg, E* old_seg)
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
134 {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
135 *link_addr(new_seg) = old_seg;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
136 return new_seg;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
137 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
138
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
139 template <class E, MEMFLAGS F>
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
140 E* Stack<E, F>::alloc(size_t bytes)
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
141 {
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
142 return (E*) NEW_C_HEAP_ARRAY(char, bytes, F);
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
143 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
144
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
145 template <class E, MEMFLAGS F>
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
146 void Stack<E, F>::free(E* addr, size_t bytes)
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
147 {
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
148 FREE_C_HEAP_ARRAY(char, (char*) addr, F);
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
149 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
150
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
151 template <class E, MEMFLAGS F>
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
152 void Stack<E, F>::push_segment()
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
153 {
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
154 assert(this->_cur_seg_size == this->_seg_size, "current segment is not full");
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
155 E* next;
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
156 if (this->_cache_size > 0) {
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
157 // Use a cached segment.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
158 next = _cache;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
159 _cache = get_link(_cache);
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
160 --this->_cache_size;
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
161 } else {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
162 next = alloc(segment_bytes());
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
163 DEBUG_ONLY(zap_segment(next, true);)
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
164 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
165 const bool at_empty_transition = is_empty();
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
166 this->_cur_seg = set_link(next, _cur_seg);
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
167 this->_cur_seg_size = 0;
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
168 this->_full_seg_size += at_empty_transition ? 0 : this->_seg_size;
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
169 DEBUG_ONLY(verify(at_empty_transition);)
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
170 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
171
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
172 template <class E, MEMFLAGS F>
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
173 void Stack<E, F>::pop_segment()
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
174 {
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
175 assert(this->_cur_seg_size == 0, "current segment is not empty");
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
176 E* const prev = get_link(_cur_seg);
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
177 if (this->_cache_size < this->_max_cache_size) {
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
178 // Add the current segment to the cache.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
179 DEBUG_ONLY(zap_segment(_cur_seg, false);)
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
180 _cache = set_link(_cur_seg, _cache);
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
181 ++this->_cache_size;
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
182 } else {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
183 DEBUG_ONLY(zap_segment(_cur_seg, true);)
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
184 free(_cur_seg, segment_bytes());
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
185 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
186 const bool at_empty_transition = prev == NULL;
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
187 this->_cur_seg = prev;
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
188 this->_cur_seg_size = this->_seg_size;
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
189 this->_full_seg_size -= at_empty_transition ? 0 : this->_seg_size;
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
190 DEBUG_ONLY(verify(at_empty_transition);)
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
191 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
192
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
193 template <class E, MEMFLAGS F>
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
194 void Stack<E, F>::free_segments(E* seg)
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
195 {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
196 const size_t bytes = segment_bytes();
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
197 while (seg != NULL) {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
198 E* const prev = get_link(seg);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
199 free(seg, bytes);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
200 seg = prev;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
201 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
202 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
203
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
204 template <class E, MEMFLAGS F>
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
205 void Stack<E, F>::reset(bool reset_cache)
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
206 {
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
207 this->_cur_seg_size = this->_seg_size; // So push() will alloc a new segment.
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
208 this->_full_seg_size = 0;
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
209 _cur_seg = NULL;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
210 if (reset_cache) {
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
211 this->_cache_size = 0;
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
212 _cache = NULL;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
213 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
214 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
215
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
216 #ifdef ASSERT
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
217 template <class E, MEMFLAGS F>
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
218 void Stack<E, F>::verify(bool at_empty_transition) const
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
219 {
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
220 assert(size() <= this->max_size(), "stack exceeded bounds");
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
221 assert(this->cache_size() <= this->max_cache_size(), "cache exceeded bounds");
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
222 assert(this->_cur_seg_size <= this->segment_size(), "segment index exceeded bounds");
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
223
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
224 assert(this->_full_seg_size % this->_seg_size == 0, "not a multiple");
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
225 assert(at_empty_transition || is_empty() == (size() == 0), "mismatch");
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
226 assert((_cache == NULL) == (this->cache_size() == 0), "mismatch");
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
227
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
228 if (is_empty()) {
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
229 assert(this->_cur_seg_size == this->segment_size(), "sanity");
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
230 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
231 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
232
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
233 template <class E, MEMFLAGS F>
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
234 void Stack<E, F>::zap_segment(E* seg, bool zap_link_field) const
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
235 {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
236 if (!ZapStackSegments) return;
894b1d7c7e01 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*));
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
238 uint32_t* cur = (uint32_t*)seg;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
239 const uint32_t* end = cur + zap_bytes / sizeof(uint32_t);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
240 while (cur < end) {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
241 *cur++ = 0xfadfaded;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
242 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
243 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
244 #endif
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
245
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
246 template <class E, MEMFLAGS F>
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
247 E* ResourceStack<E, F>::alloc(size_t bytes)
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
248 {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
249 return (E*) resource_allocate_bytes(bytes);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
250 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
251
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
252 template <class E, MEMFLAGS F>
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
253 void ResourceStack<E, F>::free(E* addr, size_t bytes)
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
254 {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
255 resource_free_bytes((char*) addr, bytes);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
256 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
257
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
258 template <class E, MEMFLAGS F>
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
259 void StackIterator<E, F>::sync()
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
260 {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
261 _full_seg_size = _stack._full_seg_size;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
262 _cur_seg_size = _stack._cur_seg_size;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
263 _cur_seg = _stack._cur_seg;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
264 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
265
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
266 template <class E, MEMFLAGS F>
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
267 E* StackIterator<E, F>::next_addr()
1836
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
268 {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
269 assert(!is_empty(), "no items left");
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
270 if (_cur_seg_size == 1) {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
271 E* addr = _cur_seg;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
272 _cur_seg = _stack.get_link(_cur_seg);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
273 _cur_seg_size = _stack.segment_size();
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
274 _full_seg_size -= _stack.segment_size();
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
275 return addr;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
276 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
277 return _cur_seg + --_cur_seg_size;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
278 }
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1836
diff changeset
279
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1836
diff changeset
280 #endif // SHARE_VM_UTILITIES_STACK_INLINE_HPP