annotate src/share/vm/utilities/stack.hpp @ 1836:894b1d7c7e01

6423256: GC stacks should use a better data structure 6942771: SEGV in ParScanThreadState::take_from_overflow_stack Reviewed-by: apetrusenko, ysr, pbk
author jcoomes
date Tue, 28 Sep 2010 15:56:15 -0700
parents
children f95d63e2154a
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 /*
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
2 * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
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 *
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
21 * have any questions.
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
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
25 // Class Stack (below) grows and shrinks by linking together "segments" which
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
26 // are allocated on demand. Segments are arrays of the element type (E) plus an
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
27 // extra pointer-sized field to store the segment link. Recently emptied
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
28 // segments are kept in a cache and reused.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
29 //
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
30 // Notes/caveats:
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
31 //
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
32 // The size of an element must either evenly divide the size of a pointer or be
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
33 // a multiple of the size of a pointer.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
34 //
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
35 // Destructors are not called for elements popped off the stack, so element
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
36 // types which rely on destructors for things like reference counting will not
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
37 // work properly.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
38 //
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
39 // Class Stack allocates segments from the C heap. However, two protected
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
40 // virtual methods are used to alloc/free memory which subclasses can override:
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
41 //
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
42 // virtual void* alloc(size_t bytes);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
43 // virtual void free(void* addr, size_t bytes);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
44 //
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
45 // The alloc() method must return storage aligned for any use. The
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
46 // implementation in class Stack assumes that alloc() will terminate the process
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
47 // if the allocation fails.
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 template <class E> class StackIterator;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
50
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
51 // StackBase holds common data/methods that don't depend on the element type,
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
52 // factored out to reduce template code duplication.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
53 class StackBase
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
54 {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
55 public:
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
56 size_t segment_size() const { return _seg_size; } // Elements per segment.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
57 size_t max_size() const { return _max_size; } // Max elements allowed.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
58 size_t max_cache_size() const { return _max_cache_size; } // Max segments
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
59 // allowed in cache.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
60
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
61 size_t cache_size() const { return _cache_size; } // Segments in the cache.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
62
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
63 protected:
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
64 // The ctor arguments correspond to the like-named functions above.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
65 // segment_size: number of items per segment
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
66 // max_cache_size: maxmium number of *segments* to cache
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
67 // max_size: maximum number of items allowed, rounded to a multiple of
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
68 // the segment size (0 == unlimited)
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
69 inline StackBase(size_t segment_size, size_t max_cache_size, size_t max_size);
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 // Round max_size to a multiple of the segment size. Treat 0 as unlimited.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
72 static inline size_t adjust_max_size(size_t max_size, size_t seg_size);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
73
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
74 protected:
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
75 const size_t _seg_size; // Number of items per segment.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
76 const size_t _max_size; // Maximum number of items allowed in the stack.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
77 const size_t _max_cache_size; // Maximum number of segments to cache.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
78 size_t _cur_seg_size; // Number of items in the current segment.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
79 size_t _full_seg_size; // Number of items in already-filled segments.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
80 size_t _cache_size; // Number of segments in the cache.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
81 };
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 #ifdef __GNUC__
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
84 #define inline
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
85 #endif // __GNUC__
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 template <class E>
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
88 class Stack: public StackBase
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
89 {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
90 public:
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
91 friend class StackIterator<E>;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
92
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
93 // segment_size: number of items per segment
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
94 // max_cache_size: maxmium number of *segments* to cache
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
95 // max_size: maximum number of items allowed, rounded to a multiple of
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
96 // the segment size (0 == unlimited)
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
97 inline Stack(size_t segment_size = default_segment_size(),
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
98 size_t max_cache_size = 4, size_t max_size = 0);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
99 inline ~Stack() { clear(true); }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
100
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
101 inline bool is_empty() const { return _cur_seg == NULL; }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
102 inline bool is_full() const { return _full_seg_size >= max_size(); }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
103
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
104 // Performance sensitive code should use is_empty() instead of size() == 0 and
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
105 // is_full() instead of size() == max_size(). Using a conditional here allows
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
106 // just one var to be updated when pushing/popping elements instead of two;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
107 // _full_seg_size is updated only when pushing/popping segments.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
108 inline size_t size() const {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
109 return is_empty() ? 0 : _full_seg_size + _cur_seg_size;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
110 }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
111
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
112 inline void push(E elem);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
113 inline E pop();
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
114
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
115 // Clear everything from the stack, releasing the associated memory. If
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
116 // clear_cache is true, also release any cached segments.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
117 void clear(bool clear_cache = false);
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 static inline size_t default_segment_size();
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
120
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
121 protected:
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
122 // Each segment includes space for _seg_size elements followed by a link
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
123 // (pointer) to the previous segment; the space is allocated as a single block
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
124 // of size segment_bytes(). _seg_size is rounded up if necessary so the link
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
125 // is properly aligned. The C struct for the layout would be:
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
126 //
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
127 // struct segment {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
128 // E elements[_seg_size];
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
129 // E* link;
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
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
132 // Round up seg_size to keep the link field aligned.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
133 static inline size_t adjust_segment_size(size_t seg_size);
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 // Methods for allocation size and getting/setting the link.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
136 inline size_t link_offset() const; // Byte offset of link field.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
137 inline size_t segment_bytes() const; // Segment size in bytes.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
138 inline E** link_addr(E* seg) const; // Address of the link field.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
139 inline E* get_link(E* seg) const; // Extract the link from seg.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
140 inline E* set_link(E* new_seg, E* old_seg); // new_seg.link = old_seg.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
141
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
142 virtual E* alloc(size_t bytes);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
143 virtual void free(E* addr, size_t bytes);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
144
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
145 void push_segment();
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
146 void pop_segment();
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
147
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
148 void free_segments(E* seg); // Free all segments in the list.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
149 inline void reset(bool reset_cache); // Reset all data fields.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
150
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
151 DEBUG_ONLY(void verify(bool at_empty_transition) const;)
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
152 DEBUG_ONLY(void zap_segment(E* seg, bool zap_link_field) const;)
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
153
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
154 private:
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
155 E* _cur_seg; // Current segment.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
156 E* _cache; // Segment cache to avoid ping-ponging.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
157 };
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
158
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
159 template <class E> class ResourceStack: public Stack<E>, public ResourceObj
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
160 {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
161 public:
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
162 // If this class becomes widely used, it may make sense to save the Thread
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
163 // and use it when allocating segments.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
164 ResourceStack(size_t segment_size = Stack<E>::default_segment_size()):
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
165 Stack<E>(segment_size, max_uintx)
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
166 { }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
167
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
168 // Set the segment pointers to NULL so the parent dtor does not free them;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
169 // that must be done by the ResourceMark code.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
170 ~ResourceStack() { Stack<E>::reset(true); }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
171
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
172 protected:
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
173 virtual E* alloc(size_t bytes);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
174 virtual void free(E* addr, size_t bytes);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
175
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
176 private:
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
177 void clear(bool clear_cache = false);
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
178 };
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
179
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
180 template <class E>
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
181 class StackIterator: public StackObj
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
182 {
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
183 public:
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
184 StackIterator(Stack<E>& stack): _stack(stack) { sync(); }
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 Stack<E>& stack() const { return _stack; }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
187
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
188 bool is_empty() const { return _cur_seg == NULL; }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
189
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
190 E next() { return *next_addr(); }
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
191 E* next_addr();
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
192
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
193 void sync(); // Sync the iterator's state to the stack's current state.
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
194
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
195 private:
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
196 Stack<E>& _stack;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
197 size_t _cur_seg_size;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
198 E* _cur_seg;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
199 size_t _full_seg_size;
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
200 };
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 #ifdef __GNUC__
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
203 #undef inline
894b1d7c7e01 6423256: GC stacks should use a better data structure
jcoomes
parents:
diff changeset
204 #endif // __GNUC__