93 public:
94 G1StringDedupEntryCache();
95 ~G1StringDedupEntryCache();
96
97 // Get a table entry from the cache freelist, or allocate a new
98 // entry if the cache is empty.
99 G1StringDedupEntry* alloc();
100
101 // Insert a table entry into the cache freelist.
102 void free(G1StringDedupEntry* entry, uint worker_id);
103
104 // Returns current number of entries in the cache.
105 size_t size();
106
107 // If the cache has grown above the given max size, trim it down
108 // and deallocate the memory occupied by trimmed of entries.
109 void trim(size_t max_size);
110 };
111
112 G1StringDedupEntryCache::G1StringDedupEntryCache() {
113 _nlists = MAX2(ParallelGCThreads, (size_t)1);
114 _lists = PaddedArray<G1StringDedupEntryFreeList, mtGC>::create_unfreeable((uint)_nlists);
115 }
116
117 G1StringDedupEntryCache::~G1StringDedupEntryCache() {
118 ShouldNotReachHere();
119 }
120
121 G1StringDedupEntry* G1StringDedupEntryCache::alloc() {
122 for (size_t i = 0; i < _nlists; i++) {
123 G1StringDedupEntry* entry = _lists[i].remove();
124 if (entry != NULL) {
125 return entry;
126 }
127 }
128 return new G1StringDedupEntry();
129 }
130
131 void G1StringDedupEntryCache::free(G1StringDedupEntry* entry, uint worker_id) {
132 assert(entry->obj() != NULL, "Double free");
133 assert(worker_id < _nlists, "Invalid worker id");
|
93 public:
94 G1StringDedupEntryCache();
95 ~G1StringDedupEntryCache();
96
97 // Get a table entry from the cache freelist, or allocate a new
98 // entry if the cache is empty.
99 G1StringDedupEntry* alloc();
100
101 // Insert a table entry into the cache freelist.
102 void free(G1StringDedupEntry* entry, uint worker_id);
103
104 // Returns current number of entries in the cache.
105 size_t size();
106
107 // If the cache has grown above the given max size, trim it down
108 // and deallocate the memory occupied by trimmed of entries.
109 void trim(size_t max_size);
110 };
111
112 G1StringDedupEntryCache::G1StringDedupEntryCache() {
113 _nlists = MAX2(ParallelGCThreads, (uintx)1);
114 _lists = PaddedArray<G1StringDedupEntryFreeList, mtGC>::create_unfreeable((uint)_nlists);
115 }
116
117 G1StringDedupEntryCache::~G1StringDedupEntryCache() {
118 ShouldNotReachHere();
119 }
120
121 G1StringDedupEntry* G1StringDedupEntryCache::alloc() {
122 for (size_t i = 0; i < _nlists; i++) {
123 G1StringDedupEntry* entry = _lists[i].remove();
124 if (entry != NULL) {
125 return entry;
126 }
127 }
128 return new G1StringDedupEntry();
129 }
130
131 void G1StringDedupEntryCache::free(G1StringDedupEntry* entry, uint worker_id) {
132 assert(entry->obj() != NULL, "Double free");
133 assert(worker_id < _nlists, "Invalid worker id");
|