src/share/vm/libadt/vectset.hpp

Mon, 12 Aug 2019 18:30:40 +0300

author
apetushkov
date
Mon, 12 Aug 2019 18:30:40 +0300
changeset 9858
b985cbb00e68
parent 3247
f350490a45fd
child 6876
710a3c8b516e
permissions
-rw-r--r--

8223147: JFR Backport
8199712: Flight Recorder
8203346: JFR: Inconsistent signature of jfr_add_string_constant
8195817: JFR.stop should require name of recording
8195818: JFR.start should increase autogenerated name by one
8195819: Remove recording=x from jcmd JFR.check output
8203921: JFR thread sampling is missing fixes from JDK-8194552
8203929: Limit amount of data for JFR.dump
8203664: JFR start failure after AppCDS archive created with JFR StartFlightRecording
8003209: JFR events for network utilization
8207392: [PPC64] Implement JFR profiling
8202835: jfr/event/os/TestSystemProcess.java fails on missing events
Summary: Backport JFR from JDK11. Initial integration
Reviewed-by: neugens

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

mercurial