Skip to content

Commit 1acad37

Browse files
author
Kim Barrett
committed
8227054: ServiceThread needs to know about all OopStorage objects
8227053: ServiceThread cleanup of OopStorage is missing some OopStorages provides named access and iteration. Reviewed-by: eosterlund, pliden, coleenp
1 parent de8d01d commit 1acad37

28 files changed

+724
-361
lines changed

src/hotspot/share/classfile/stringTable.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "classfile/systemDictionary.hpp"
3131
#include "gc/shared/collectedHeap.hpp"
3232
#include "gc/shared/oopStorage.inline.hpp"
33+
#include "gc/shared/oopStorageSet.hpp"
3334
#include "logging/log.hpp"
3435
#include "logging/logStream.hpp"
3536
#include "memory/allocation.inline.hpp"
@@ -86,7 +87,6 @@ volatile bool StringTable::_has_work = false;
8687
volatile bool StringTable::_needs_rehashing = false;
8788

8889
volatile size_t StringTable::_uncleaned_items_count = 0;
89-
OopStorage* StringTable::_weak_handles = NULL;
9090

9191
static size_t _current_size = 0;
9292
static volatile size_t _items_count = 0;
@@ -206,9 +206,6 @@ static size_t ceil_log2(size_t val) {
206206
}
207207

208208
void StringTable::create_table() {
209-
_weak_handles = new OopStorage("StringTable weak",
210-
StringTableWeakAlloc_lock,
211-
StringTableWeakActive_lock);
212209
size_t start_size_log_2 = ceil_log2(StringTableSize);
213210
_current_size = ((size_t)1) << start_size_log_2;
214211
log_trace(stringtable)("Start size: " SIZE_FORMAT " (" SIZE_FORMAT ")",
@@ -388,7 +385,7 @@ oop StringTable::do_intern(Handle string_or_null_h, const jchar* name,
388385

389386
void StringTable::oops_do(OopClosure* f) {
390387
assert(f != NULL, "No closure");
391-
_weak_handles->oops_do(f);
388+
OopStorageSet::string_table_weak()->oops_do(f);
392389
}
393390

394391
// Concurrent work

src/hotspot/share/classfile/stringTable.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
#ifndef SHARE_CLASSFILE_STRINGTABLE_HPP
2626
#define SHARE_CLASSFILE_STRINGTABLE_HPP
2727

28-
#include "gc/shared/oopStorage.hpp"
2928
#include "memory/allocation.hpp"
3029
#include "memory/padded.hpp"
3130
#include "oops/oop.hpp"
3231
#include "oops/weakHandle.hpp"
3332
#include "utilities/tableStatistics.hpp"
3433

3534
class CompactHashtableWriter;
35+
class JavaThread;
3636
class SerializeClosure;
3737

3838
class StringTable;
@@ -51,8 +51,6 @@ class StringTable : public CHeapObj<mtSymbol>{
5151
// Set if one bucket is out of balance due to hash algorithm deficiency
5252
static volatile bool _needs_rehashing;
5353

54-
static OopStorage* _weak_handles;
55-
5654
static void grow(JavaThread* jt);
5755
static void clean_dead_entries(JavaThread* jt);
5856

@@ -78,8 +76,6 @@ class StringTable : public CHeapObj<mtSymbol>{
7876
static size_t table_size();
7977
static TableStatistics get_table_statistics();
8078

81-
static OopStorage* weak_storage() { return _weak_handles; }
82-
8379
static void create_table();
8480

8581
static void do_concurrent_work(JavaThread* jt);

src/hotspot/share/classfile/systemDictionary.cpp

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "compiler/compileBroker.hpp"
4848
#include "gc/shared/gcTraceTime.inline.hpp"
4949
#include "gc/shared/oopStorage.inline.hpp"
50+
#include "gc/shared/oopStorageSet.hpp"
5051
#include "interpreter/bytecodeStream.hpp"
5152
#include "interpreter/interpreter.hpp"
5253
#include "jfr/jfrEvents.hpp"
@@ -114,10 +115,6 @@ bool SystemDictionary::_has_checkPackageAccess = false;
114115

115116
const int defaultProtectionDomainCacheSize = 1009;
116117

117-
OopStorage* SystemDictionary::_vm_global_oop_storage = NULL;
118-
OopStorage* SystemDictionary::_vm_weak_oop_storage = NULL;
119-
120-
121118
// ----------------------------------------------------------------------------
122119
// Java-level SystemLoader and PlatformLoader
123120

@@ -1855,7 +1852,7 @@ void SystemDictionary::oops_do(OopClosure* f, bool include_handles) {
18551852
invoke_method_table()->oops_do(f);
18561853

18571854
if (include_handles) {
1858-
vm_global_oop_storage()->oops_do(f);
1855+
OopStorageSet::vm_global()->oops_do(f);
18591856
}
18601857
}
18611858

@@ -2896,25 +2893,3 @@ int SystemDictionaryDCmd::num_arguments() {
28962893
return 0;
28972894
}
28982895
}
2899-
2900-
void SystemDictionary::initialize_oop_storage() {
2901-
_vm_global_oop_storage =
2902-
new OopStorage("VM Global Oop Handles",
2903-
VMGlobalAlloc_lock,
2904-
VMGlobalActive_lock);
2905-
2906-
_vm_weak_oop_storage =
2907-
new OopStorage("VM Weak Oop Handles",
2908-
VMWeakAlloc_lock,
2909-
VMWeakActive_lock);
2910-
}
2911-
2912-
OopStorage* SystemDictionary::vm_global_oop_storage() {
2913-
assert(_vm_global_oop_storage != NULL, "Uninitialized");
2914-
return _vm_global_oop_storage;
2915-
}
2916-
2917-
OopStorage* SystemDictionary::vm_weak_oop_storage() {
2918-
assert(_vm_weak_oop_storage != NULL, "Uninitialized");
2919-
return _vm_weak_oop_storage;
2920-
}

src/hotspot/share/classfile/systemDictionary.hpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ class SymbolPropertyTable;
8484
class ProtectionDomainCacheTable;
8585
class ProtectionDomainCacheEntry;
8686
class GCTimer;
87-
class OopStorage;
8887

8988
#define WK_KLASS_ENUM_NAME(kname) kname##_knum
9089

@@ -349,7 +348,7 @@ class SystemDictionary : AllStatic {
349348

350349
// Applies "f->do_oop" to all root oops in the system dictionary.
351350
// If include_handles is true (the default), then the handles in the
352-
// storage object returned by vm_global_oop_storage() are included.
351+
// vm_global OopStorage object are included.
353352
static void oops_do(OopClosure* f, bool include_handles = true);
354353

355354
// System loader lock
@@ -565,10 +564,6 @@ class SystemDictionary : AllStatic {
565564
// ProtectionDomain cache
566565
static ProtectionDomainCacheTable* _pd_cache_table;
567566

568-
// VM OopStorage objects.
569-
static OopStorage* _vm_global_oop_storage;
570-
static OopStorage* _vm_weak_oop_storage;
571-
572567
protected:
573568
static void validate_protection_domain(InstanceKlass* klass,
574569
Handle class_loader,
@@ -623,10 +618,6 @@ class SystemDictionary : AllStatic {
623618
return !m->is_public() && m->method_holder() == SystemDictionary::Object_klass();
624619
}
625620

626-
static void initialize_oop_storage();
627-
static OopStorage* vm_global_oop_storage();
628-
static OopStorage* vm_weak_oop_storage();
629-
630621
protected:
631622
// Setup link to hierarchy
632623
static void add_to_hierarchy(InstanceKlass* k, TRAPS);

src/hotspot/share/gc/shared/oopStorageParState.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -153,6 +153,8 @@ class OopStorage::BasicParState {
153153
bool concurrent);
154154
~BasicParState();
155155

156+
const OopStorage* storage() const { return _storage; }
157+
156158
template<bool is_const, typename F> void iterate(F f);
157159

158160
static uint default_estimated_thread_count(bool concurrent);
@@ -172,6 +174,7 @@ class OopStorage::ParState {
172174
_basic_state(storage, estimated_thread_count, concurrent)
173175
{}
174176

177+
const OopStorage* storage() const { return _basic_state.storage(); }
175178
template<typename F> void iterate(F f);
176179
template<typename Closure> void oops_do(Closure* cl);
177180
};
@@ -186,6 +189,7 @@ class OopStorage::ParState<false, false> {
186189
_basic_state(storage, estimated_thread_count, false)
187190
{}
188191

192+
const OopStorage* storage() const { return _basic_state.storage(); }
189193
template<typename F> void iterate(F f);
190194
template<typename Closure> void oops_do(Closure* cl);
191195
template<typename Closure> void weak_oops_do(Closure* cl);
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
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
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*
23+
*/
24+
25+
#include "precompiled.hpp"
26+
#include "gc/shared/oopStorage.hpp"
27+
#include "gc/shared/oopStorageSet.hpp"
28+
#include "runtime/mutex.hpp"
29+
#include "runtime/os.hpp"
30+
#include "utilities/debug.hpp"
31+
#include "utilities/globalDefinitions.hpp"
32+
#include "utilities/macros.hpp"
33+
34+
// +1 for NULL singular entry.
35+
OopStorage* OopStorageSet::storages[all_count + 1] = {};
36+
37+
static Mutex* make_oopstorage_mutex(const char* storage_name,
38+
const char* kind,
39+
int rank) {
40+
char name[256];
41+
os::snprintf(name, sizeof(name), "%s %s lock", storage_name, kind);
42+
return new PaddedMutex(rank, name, true, Mutex::_safepoint_check_never);
43+
}
44+
45+
static OopStorage* make_oopstorage(const char* name) {
46+
Mutex* alloc = make_oopstorage_mutex(name, "alloc", Mutex::oopstorage);
47+
Mutex* active = make_oopstorage_mutex(name, "active", Mutex::oopstorage - 1);
48+
return new OopStorage(name, alloc, active);
49+
}
50+
51+
void OopStorageSet::initialize() {
52+
storages[jni_global_index] = make_oopstorage("JNI global");
53+
storages[vm_global_index] = make_oopstorage("VM global");
54+
storages[jni_weak_index] = make_oopstorage("JNI weak");
55+
storages[vm_weak_index] = make_oopstorage("VM weak");
56+
storages[string_table_weak_index] = make_oopstorage("StringTable weak");
57+
storages[resolved_method_table_weak_index] =
58+
make_oopstorage("ResolvedMethodTable weak");
59+
60+
// Ensure we have all of them.
61+
STATIC_ASSERT(all_count == 6);
62+
assert(storages[singular_index] == NULL, "postcondition");
63+
#ifdef ASSERT
64+
for (uint i = all_start; i < all_end; ++i) {
65+
assert(storages[i] != NULL, "postcondition");
66+
}
67+
#endif // ASSERT
68+
}
69+
70+
void oopstorage_init() {
71+
OopStorageSet::initialize();
72+
}
73+
74+
#ifdef ASSERT
75+
76+
void OopStorageSet::verify_initialized(uint index) {
77+
assert(storages[index] != NULL, "oopstorage_init not yet called");
78+
}
79+
80+
void OopStorageSet::Iterator::verify_nonsingular() const {
81+
assert(_category != singular, "precondition");
82+
}
83+
84+
void OopStorageSet::Iterator::verify_category_match(const Iterator& other) const {
85+
verify_nonsingular();
86+
assert(_category == other._category, "precondition");
87+
}
88+
89+
void OopStorageSet::Iterator::verify_dereferenceable() const {
90+
verify_nonsingular();
91+
assert(!is_end(), "precondition");
92+
}
93+
94+
#endif // ASSERT

0 commit comments

Comments
 (0)