Mercurial > hg > truffle
comparison src/share/vm/libadt/vectset.hpp @ 2249:3763ca6579b7
7013538: Java memory leak with escape analysis
Summary: Don't allocate VectorSet iterator on C heap. Reuse resource storage in EA.
Reviewed-by: never
author | kvn |
---|---|
date | Mon, 07 Feb 2011 10:25:39 -0800 |
parents | f95d63e2154a |
children | f350490a45fd |
comparison
equal
deleted
inserted
replaced
2248:194c9fdee631 | 2249:3763ca6579b7 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
96 uint getelem(void) const; // Return a random element | 96 uint getelem(void) const; // Return a random element |
97 void Clear(void); // Clear a set | 97 void Clear(void); // Clear a set |
98 uint Size(void) const; // Number of elements in the Set. | 98 uint Size(void) const; // Number of elements in the Set. |
99 void Sort(void); // Sort before iterating | 99 void Sort(void); // Sort before iterating |
100 int hash() const; // Hash function | 100 int hash() const; // Hash function |
101 void Reset(void) { // Reset a set | |
102 memset( data, 0, size*sizeof(uint32) ); | |
103 } | |
101 | 104 |
102 /* Removed for MCC BUG | 105 /* Removed for MCC BUG |
103 operator const VectorSet* (void) const { return this; } */ | 106 operator const VectorSet* (void) const { return this; } */ |
104 const VectorSet *asVectorSet() const { return this; } | 107 const VectorSet *asVectorSet() const { return this; } |
105 | 108 |
146 } | 149 } |
147 } | 150 } |
148 | 151 |
149 | 152 |
150 private: | 153 private: |
151 friend class VSetI_; | 154 SetI_ *iterate(uint&) const { ShouldNotCallThis(); return NULL; } // Removed |
152 SetI_ *iterate(uint&) const; | |
153 }; | 155 }; |
154 | 156 |
155 //------------------------------Iteration-------------------------------------- | 157 //------------------------------Iteration-------------------------------------- |
156 // Loop thru all elements of the set, setting "elem" to the element numbers | 158 // Loop thru all elements of the set, setting "elem" to the element numbers |
157 // in random order. Inserted or deleted elements during this operation may | 159 // in random order. Inserted or deleted elements during this operation may |
158 // or may not be iterated over; untouched elements will be affected once. | 160 // or may not be iterated over; untouched elements will be affected once. |
159 // Usage: for( VectorSetI i(s); i.test(); i++ ) { body = i.elem; } | 161 // Usage: for( VectorSetI i(s); i.test(); i++ ) { body = i.elem; } |
160 | 162 |
161 class VSetI_ : public SetI_ { | 163 class VectorSetI : public StackObj { |
162 friend class VectorSet; | 164 friend class VectorSet; |
163 friend class VectorSetI; | |
164 const VectorSet *s; | 165 const VectorSet *s; |
165 uint i, j; | 166 uint i, j; |
166 uint32 mask; | 167 uint32 mask; |
167 VSetI_(const VectorSet *vset); | |
168 uint next(void); | 168 uint next(void); |
169 | |
170 public: | |
171 uint elem; // The publically accessible element | |
172 | |
173 VectorSetI( const VectorSet *vset ) : | |
174 s(vset), | |
175 i((uint)-1L), | |
176 j((uint)-1L), | |
177 mask((unsigned)(1L<<31)) { | |
178 elem = next(); | |
179 } | |
180 | |
181 void operator ++(void) { elem = next(); } | |
169 int test(void) { return i < s->size; } | 182 int test(void) { return i < s->size; } |
170 }; | 183 }; |
171 | 184 |
172 class VectorSetI : public SetI { | |
173 public: | |
174 VectorSetI( const VectorSet *s ) : SetI(s) { } | |
175 void operator ++(void) { elem = ((VSetI_*)impl)->next(); } | |
176 int test(void) { return ((VSetI_*)impl)->test(); } | |
177 }; | |
178 | |
179 #endif // SHARE_VM_LIBADT_VECTSET_HPP | 185 #endif // SHARE_VM_LIBADT_VECTSET_HPP |