annotate src/share/vm/libadt/vectset.hpp @ 18096:ca6d25be853b jdk8u25-b13

8044269: Analysis of archive files. Summary: Add checksum verification. Reviewed-by: iklam, dholmes, mschoene
author jiangli
date Tue, 12 Aug 2014 17:46:16 -0400
parents f350490a45fd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
2249
3763ca6579b7 7013538: Java memory leak with escape analysis
kvn
parents: 1972
diff changeset
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #ifndef SHARE_VM_LIBADT_VECTSET_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_LIBADT_VECTSET_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "libadt/set.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29
0
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // Vector Sets - An Abstract Data Type
a61af66fc99e Initial load
duke
parents:
diff changeset
31 //INTERFACE
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // These sets can grow or shrink, based on the initial size and the largest
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // element currently in them. Slow and bulky for sparse sets, these sets
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // are super for dense sets. They are fast and compact when dense.
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // TIME:
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // O(1) - Insert, Delete, Member, Sort
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // O(max_element) - Create, Clear, Size, Copy, Union, Intersect, Difference,
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // Equal, ChooseMember, Forall
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // SPACE: (max_element)/(8*sizeof(int))
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 //------------------------------VectorSet--------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
46 class VectorSet : public Set {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 friend class VectorSetI; // Friendly iterator class
a61af66fc99e Initial load
duke
parents:
diff changeset
48 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
49 uint size; // Size of data IN LONGWORDS (32bits)
a61af66fc99e Initial load
duke
parents:
diff changeset
50 uint32 *data; // The data, bit packed
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 void slamin( const VectorSet& s ); // Initialize one set with another
a61af66fc99e Initial load
duke
parents:
diff changeset
53 int compare(const VectorSet &s) const; // Compare set contents
a61af66fc99e Initial load
duke
parents:
diff changeset
54 void grow(uint newsize); // Grow vector to required bitsize
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
57 VectorSet(Arena *arena); // Creates a new, empty set.
a61af66fc99e Initial load
duke
parents:
diff changeset
58 VectorSet(const VectorSet &s) : Set(s._set_arena) {slamin(s);} // Set clone; deep-copy guts
a61af66fc99e Initial load
duke
parents:
diff changeset
59 Set &operator =(const Set &s); // Set clone; deep-copy guts
a61af66fc99e Initial load
duke
parents:
diff changeset
60 VectorSet &operator =(const VectorSet &s) // Set clone; deep-copy guts
a61af66fc99e Initial load
duke
parents:
diff changeset
61 { if( &s != this ) { slamin(s); } return *this; }
a61af66fc99e Initial load
duke
parents:
diff changeset
62 ~VectorSet() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
63 Set &clone(void) const { return *(new VectorSet(*this)); }
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 Set &operator <<=(uint elem); // Add member to set
a61af66fc99e Initial load
duke
parents:
diff changeset
66 VectorSet operator << (uint elem) // Add member to new set
a61af66fc99e Initial load
duke
parents:
diff changeset
67 { VectorSet foo(*this); foo <<= elem; return foo; }
a61af66fc99e Initial load
duke
parents:
diff changeset
68 Set &operator >>=(uint elem); // Delete member from set
a61af66fc99e Initial load
duke
parents:
diff changeset
69 VectorSet operator >> (uint elem) // Delete member from new set
a61af66fc99e Initial load
duke
parents:
diff changeset
70 { VectorSet foo(*this); foo >>= elem; return foo; }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 VectorSet &operator &=(const VectorSet &s); // Intersect sets into first set
a61af66fc99e Initial load
duke
parents:
diff changeset
73 Set &operator &=(const Set &s); // Intersect sets into first set
a61af66fc99e Initial load
duke
parents:
diff changeset
74 VectorSet operator & (const VectorSet &s) const
a61af66fc99e Initial load
duke
parents:
diff changeset
75 { VectorSet foo(*this); foo &= s; return foo; }
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 VectorSet &operator |=(const VectorSet &s); // Intersect sets into first set
a61af66fc99e Initial load
duke
parents:
diff changeset
78 Set &operator |=(const Set &s); // Intersect sets into first set
a61af66fc99e Initial load
duke
parents:
diff changeset
79 VectorSet operator | (const VectorSet &s) const
a61af66fc99e Initial load
duke
parents:
diff changeset
80 { VectorSet foo(*this); foo |= s; return foo; }
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 VectorSet &operator -=(const VectorSet &s); // Intersect sets into first set
a61af66fc99e Initial load
duke
parents:
diff changeset
83 Set &operator -=(const Set &s); // Intersect sets into first set
a61af66fc99e Initial load
duke
parents:
diff changeset
84 VectorSet operator - (const VectorSet &s) const
a61af66fc99e Initial load
duke
parents:
diff changeset
85 { VectorSet foo(*this); foo -= s; return foo; }
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 int operator ==(const VectorSet &s) const; // True if sets are equal
a61af66fc99e Initial load
duke
parents:
diff changeset
88 int operator ==(const Set &s) const; // True if sets are equal
a61af66fc99e Initial load
duke
parents:
diff changeset
89 int operator < (const VectorSet &s) const; // True if strict subset
a61af66fc99e Initial load
duke
parents:
diff changeset
90 int operator < (const Set &s) const; // True if strict subset
a61af66fc99e Initial load
duke
parents:
diff changeset
91 int operator <=(const VectorSet &s) const; // True if subset relation holds.
a61af66fc99e Initial load
duke
parents:
diff changeset
92 int operator <=(const Set &s) const; // True if subset relation holds.
a61af66fc99e Initial load
duke
parents:
diff changeset
93 int disjoint (const Set &s) const; // True if sets are disjoint
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 int operator [](uint elem) const; // Test for membership
a61af66fc99e Initial load
duke
parents:
diff changeset
96 uint getelem(void) const; // Return a random element
a61af66fc99e Initial load
duke
parents:
diff changeset
97 void Clear(void); // Clear a set
a61af66fc99e Initial load
duke
parents:
diff changeset
98 uint Size(void) const; // Number of elements in the Set.
a61af66fc99e Initial load
duke
parents:
diff changeset
99 void Sort(void); // Sort before iterating
a61af66fc99e Initial load
duke
parents:
diff changeset
100 int hash() const; // Hash function
2249
3763ca6579b7 7013538: Java memory leak with escape analysis
kvn
parents: 1972
diff changeset
101 void Reset(void) { // Reset a set
3763ca6579b7 7013538: Java memory leak with escape analysis
kvn
parents: 1972
diff changeset
102 memset( data, 0, size*sizeof(uint32) );
3763ca6579b7 7013538: Java memory leak with escape analysis
kvn
parents: 1972
diff changeset
103 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 /* Removed for MCC BUG
a61af66fc99e Initial load
duke
parents:
diff changeset
106 operator const VectorSet* (void) const { return this; } */
a61af66fc99e Initial load
duke
parents:
diff changeset
107 const VectorSet *asVectorSet() const { return this; }
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 // Expose internals for speed-critical fast iterators
a61af66fc99e Initial load
duke
parents:
diff changeset
110 uint word_size() const { return size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 uint32 *EXPOSE() const { return data; }
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // Fast inlined "test and set". Replaces the idiom:
a61af66fc99e Initial load
duke
parents:
diff changeset
114 // if( visited[idx] ) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // visited <<= idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 // With:
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // if( visited.test_set(idx) ) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 //
a61af66fc99e Initial load
duke
parents:
diff changeset
119 int test_set( uint elem ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 uint word = elem >> 5; // Get the longword offset
a61af66fc99e Initial load
duke
parents:
diff changeset
121 if( word >= size ) // Beyond the last?
a61af66fc99e Initial load
duke
parents:
diff changeset
122 return test_set_grow(elem); // Then grow; set; return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 uint32 mask = 1L << (elem & 31); // Get bit mask
a61af66fc99e Initial load
duke
parents:
diff changeset
124 uint32 datum = data[word] & mask;// Get bit
a61af66fc99e Initial load
duke
parents:
diff changeset
125 data[word] |= mask; // Set bit
a61af66fc99e Initial load
duke
parents:
diff changeset
126 return datum; // Return bit
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128 int test_set_grow( uint elem ) { // Insert & return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 (*this) <<= elem; // Insert into set
a61af66fc99e Initial load
duke
parents:
diff changeset
130 return 0; // Return 0!
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // Fast inlined test
a61af66fc99e Initial load
duke
parents:
diff changeset
134 int test( uint elem ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 uint word = elem >> 5; // Get the longword offset
a61af66fc99e Initial load
duke
parents:
diff changeset
136 if( word >= size ) return 0; // Beyond the last?
a61af66fc99e Initial load
duke
parents:
diff changeset
137 uint32 mask = 1L << (elem & 31); // Get bit mask
a61af66fc99e Initial load
duke
parents:
diff changeset
138 return data[word] & mask; // Get bit
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 // Fast inlined set
a61af66fc99e Initial load
duke
parents:
diff changeset
142 void set( uint elem ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 uint word = elem >> 5; // Get the longword offset
a61af66fc99e Initial load
duke
parents:
diff changeset
144 if( word >= size ) { // Beyond the last?
a61af66fc99e Initial load
duke
parents:
diff changeset
145 test_set_grow(elem); // Then grow and set
a61af66fc99e Initial load
duke
parents:
diff changeset
146 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 uint32 mask = 1L << (elem & 31); // Get bit mask
a61af66fc99e Initial load
duke
parents:
diff changeset
148 data[word] |= mask; // Set bit
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 private:
4051
f350490a45fd 7105611: Set::print() is broken
kvn
parents: 2249
diff changeset
154 SetI_ *iterate(uint&) const;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
155 };
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 //------------------------------Iteration--------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // Loop thru all elements of the set, setting "elem" to the element numbers
a61af66fc99e Initial load
duke
parents:
diff changeset
159 // in random order. Inserted or deleted elements during this operation may
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // or may not be iterated over; untouched elements will be affected once.
a61af66fc99e Initial load
duke
parents:
diff changeset
161 // Usage: for( VectorSetI i(s); i.test(); i++ ) { body = i.elem; }
a61af66fc99e Initial load
duke
parents:
diff changeset
162
2249
3763ca6579b7 7013538: Java memory leak with escape analysis
kvn
parents: 1972
diff changeset
163 class VectorSetI : public StackObj {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
164 friend class VectorSet;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 const VectorSet *s;
a61af66fc99e Initial load
duke
parents:
diff changeset
166 uint i, j;
a61af66fc99e Initial load
duke
parents:
diff changeset
167 uint32 mask;
a61af66fc99e Initial load
duke
parents:
diff changeset
168 uint next(void);
2249
3763ca6579b7 7013538: Java memory leak with escape analysis
kvn
parents: 1972
diff changeset
169
3763ca6579b7 7013538: Java memory leak with escape analysis
kvn
parents: 1972
diff changeset
170 public:
3763ca6579b7 7013538: Java memory leak with escape analysis
kvn
parents: 1972
diff changeset
171 uint elem; // The publically accessible element
3763ca6579b7 7013538: Java memory leak with escape analysis
kvn
parents: 1972
diff changeset
172
3763ca6579b7 7013538: Java memory leak with escape analysis
kvn
parents: 1972
diff changeset
173 VectorSetI( const VectorSet *vset ) :
3763ca6579b7 7013538: Java memory leak with escape analysis
kvn
parents: 1972
diff changeset
174 s(vset),
3763ca6579b7 7013538: Java memory leak with escape analysis
kvn
parents: 1972
diff changeset
175 i((uint)-1L),
3763ca6579b7 7013538: Java memory leak with escape analysis
kvn
parents: 1972
diff changeset
176 j((uint)-1L),
3763ca6579b7 7013538: Java memory leak with escape analysis
kvn
parents: 1972
diff changeset
177 mask((unsigned)(1L<<31)) {
3763ca6579b7 7013538: Java memory leak with escape analysis
kvn
parents: 1972
diff changeset
178 elem = next();
3763ca6579b7 7013538: Java memory leak with escape analysis
kvn
parents: 1972
diff changeset
179 }
3763ca6579b7 7013538: Java memory leak with escape analysis
kvn
parents: 1972
diff changeset
180
3763ca6579b7 7013538: Java memory leak with escape analysis
kvn
parents: 1972
diff changeset
181 void operator ++(void) { elem = next(); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
182 int test(void) { return i < s->size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
183 };
a61af66fc99e Initial load
duke
parents:
diff changeset
184
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
185 #endif // SHARE_VM_LIBADT_VECTSET_HPP