Mercurial > hg > graal-compiler
comparison src/share/vm/utilities/growableArray.hpp @ 6197:d2a62e0f25eb
6995781: Native Memory Tracking (Phase 1)
7151532: DCmd for hotspot native memory tracking
Summary: Implementation of native memory tracking phase 1, which tracks VM native memory usage, and related DCmd
Reviewed-by: acorn, coleenp, fparain
author | zgu |
---|---|
date | Thu, 28 Jun 2012 17:03:16 -0400 |
parents | ee138854b3a6 |
children | da91efe96a93 |
comparison
equal
deleted
inserted
replaced
6174:74533f63b116 | 6197:d2a62e0f25eb |
---|---|
84 int _max; // maximum length | 84 int _max; // maximum length |
85 Arena* _arena; // Indicates where allocation occurs: | 85 Arena* _arena; // Indicates where allocation occurs: |
86 // 0 means default ResourceArea | 86 // 0 means default ResourceArea |
87 // 1 means on C heap | 87 // 1 means on C heap |
88 // otherwise, allocate in _arena | 88 // otherwise, allocate in _arena |
89 | |
90 MEMFLAGS _memflags; // memory type if allocation in C heap | |
91 | |
89 #ifdef ASSERT | 92 #ifdef ASSERT |
90 int _nesting; // resource area nesting at creation | 93 int _nesting; // resource area nesting at creation |
91 void set_nesting(); | 94 void set_nesting(); |
92 void check_nesting(); | 95 void check_nesting(); |
93 #else | 96 #else |
100 bool on_stack () { return _arena == NULL; } | 103 bool on_stack () { return _arena == NULL; } |
101 bool on_arena () { return _arena > (Arena*)1; } | 104 bool on_arena () { return _arena > (Arena*)1; } |
102 | 105 |
103 // This GA will use the resource stack for storage if c_heap==false, | 106 // This GA will use the resource stack for storage if c_heap==false, |
104 // Else it will use the C heap. Use clear_and_deallocate to avoid leaks. | 107 // Else it will use the C heap. Use clear_and_deallocate to avoid leaks. |
105 GenericGrowableArray(int initial_size, int initial_len, bool c_heap) { | 108 GenericGrowableArray(int initial_size, int initial_len, bool c_heap, MEMFLAGS flags = mtNone) { |
106 _len = initial_len; | 109 _len = initial_len; |
107 _max = initial_size; | 110 _max = initial_size; |
111 _memflags = flags; | |
112 | |
113 // memory type has to be specified for C heap allocation | |
114 assert(!(c_heap && flags == mtNone), "memory type not specified for C heap object"); | |
115 | |
108 assert(_len >= 0 && _len <= _max, "initial_len too big"); | 116 assert(_len >= 0 && _len <= _max, "initial_len too big"); |
109 _arena = (c_heap ? (Arena*)1 : NULL); | 117 _arena = (c_heap ? (Arena*)1 : NULL); |
110 set_nesting(); | 118 set_nesting(); |
111 assert(!on_C_heap() || allocated_on_C_heap(), "growable array must be on C heap if elements are"); | 119 assert(!on_C_heap() || allocated_on_C_heap(), "growable array must be on C heap if elements are"); |
112 assert(!on_stack() || | 120 assert(!on_stack() || |
119 GenericGrowableArray(Arena* arena, int initial_size, int initial_len) { | 127 GenericGrowableArray(Arena* arena, int initial_size, int initial_len) { |
120 _len = initial_len; | 128 _len = initial_len; |
121 _max = initial_size; | 129 _max = initial_size; |
122 assert(_len >= 0 && _len <= _max, "initial_len too big"); | 130 assert(_len >= 0 && _len <= _max, "initial_len too big"); |
123 _arena = arena; | 131 _arena = arena; |
132 _memflags = mtNone; | |
133 | |
124 assert(on_arena(), "arena has taken on reserved value 0 or 1"); | 134 assert(on_arena(), "arena has taken on reserved value 0 or 1"); |
125 // Relax next assert to allow object allocation on resource area, | 135 // Relax next assert to allow object allocation on resource area, |
126 // on stack or embedded into an other object. | 136 // on stack or embedded into an other object. |
127 assert(allocated_on_arena() || allocated_on_stack(), | 137 assert(allocated_on_arena() || allocated_on_stack(), |
128 "growable array must be on arena or on stack if elements are on arena"); | 138 "growable array must be on arena or on stack if elements are on arena"); |
150 GrowableArray(Thread* thread, int initial_size) : GenericGrowableArray(initial_size, 0, false) { | 160 GrowableArray(Thread* thread, int initial_size) : GenericGrowableArray(initial_size, 0, false) { |
151 _data = (E*)raw_allocate(thread, sizeof(E)); | 161 _data = (E*)raw_allocate(thread, sizeof(E)); |
152 for (int i = 0; i < _max; i++) ::new ((void*)&_data[i]) E(); | 162 for (int i = 0; i < _max; i++) ::new ((void*)&_data[i]) E(); |
153 } | 163 } |
154 | 164 |
155 GrowableArray(int initial_size, bool C_heap = false) : GenericGrowableArray(initial_size, 0, C_heap) { | 165 GrowableArray(int initial_size, bool C_heap = false, MEMFLAGS F = mtInternal) |
166 : GenericGrowableArray(initial_size, 0, C_heap, F) { | |
156 _data = (E*)raw_allocate(sizeof(E)); | 167 _data = (E*)raw_allocate(sizeof(E)); |
157 for (int i = 0; i < _max; i++) ::new ((void*)&_data[i]) E(); | 168 for (int i = 0; i < _max; i++) ::new ((void*)&_data[i]) E(); |
158 } | 169 } |
159 | 170 |
160 GrowableArray(int initial_size, int initial_len, const E& filler, bool C_heap = false) : GenericGrowableArray(initial_size, initial_len, C_heap) { | 171 GrowableArray(int initial_size, int initial_len, const E& filler, bool C_heap = false, MEMFLAGS memflags = mtInternal) |
172 : GenericGrowableArray(initial_size, initial_len, C_heap, memflags) { | |
161 _data = (E*)raw_allocate(sizeof(E)); | 173 _data = (E*)raw_allocate(sizeof(E)); |
162 int i = 0; | 174 int i = 0; |
163 for (; i < _len; i++) ::new ((void*)&_data[i]) E(filler); | 175 for (; i < _len; i++) ::new ((void*)&_data[i]) E(filler); |
164 for (; i < _max; i++) ::new ((void*)&_data[i]) E(); | 176 for (; i < _max; i++) ::new ((void*)&_data[i]) E(); |
165 } | 177 } |