Skip to content

Commit 40b0ed5

Browse files
committedAug 29, 2022
8292891: ifdef-out some CDS-only functions
Reviewed-by: coleenp, ccheung, dholmes
1 parent adb3d4f commit 40b0ed5

16 files changed

+45
-23
lines changed
 

‎src/hotspot/share/interpreter/rewriter.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void Rewriter::make_constant_pool_cache(TRAPS) {
111111
_pool->initialize_resolved_references(loader_data, _resolved_references_map,
112112
_resolved_reference_limit,
113113
THREAD);
114-
114+
#if INCLUDE_CDS
115115
if (!HAS_PENDING_EXCEPTION && Arguments::is_dumping_archive()) {
116116
if (_pool->pool_holder()->is_shared()) {
117117
assert(DynamicDumpSharedSpaces, "must be");
@@ -122,6 +122,7 @@ void Rewriter::make_constant_pool_cache(TRAPS) {
122122
cache->save_for_archive(THREAD);
123123
}
124124
}
125+
#endif
125126

126127
// Clean up constant pool cache if initialize_resolved_references() failed.
127128
if (HAS_PENDING_EXCEPTION) {

‎src/hotspot/share/jfr/recorder/checkpoint/types/traceid/jfrTraceId.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ traceid JfrTraceId::load_raw(jclass jc) {
199199
return load(jc, true);
200200
}
201201

202+
#if INCLUDE_CDS
202203
// used by CDS / APPCDS as part of "remove_unshareable_info"
203204
void JfrTraceId::remove(const Klass* k) {
204205
assert(k != NULL, "invariant");
@@ -230,6 +231,7 @@ void JfrTraceId::restore(const Klass* k) {
230231
next_class_id();
231232
}
232233
}
234+
#endif // INCLUDE_CDS
233235

234236
bool JfrTraceId::in_visible_set(const jclass jc) {
235237
assert(jc != NULL, "invariant");

‎src/hotspot/share/jfr/recorder/checkpoint/types/traceid/jfrTraceId.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@ class JfrTraceId : public AllStatic {
102102
static traceid load_raw(const PackageEntry* package);
103103
static traceid load_raw(const ClassLoaderData* cld);
104104

105+
#if INCLUDE_CDS
105106
static void remove(const Klass* klass);
106107
static void remove(const Method* method);
107108
static void restore(const Klass* klass);
109+
#endif
108110

109111
// set of event classes made visible to java
110112
static bool in_visible_set(const Klass* k);

‎src/hotspot/share/memory/allocation.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,18 @@ class MetaspaceObj {
270270
// non-shared or shared metaspace.
271271
static bool is_valid(const MetaspaceObj* p);
272272

273+
#if INCLUDE_CDS
273274
static bool is_shared(const MetaspaceObj* p) {
274275
// If no shared metaspace regions are mapped, _shared_metaspace_{base,top} will
275276
// both be NULL and all values of p will be rejected quickly.
276277
return (((void*)p) < _shared_metaspace_top &&
277278
((void*)p) >= _shared_metaspace_base);
278279
}
279280
bool is_shared() const { return MetaspaceObj::is_shared(this); }
281+
#else
282+
static bool is_shared(const MetaspaceObj* p) { return false; }
283+
bool is_shared() const { return false; }
284+
#endif
280285

281286
void print_address_on(outputStream* st) const; // nonvirtual address printing
282287

‎src/hotspot/share/oops/arrayKlass.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ void ArrayKlass::metaspace_pointers_do(MetaspaceClosure* it) {
156156
it->push((Klass**)&_lower_dimension);
157157
}
158158

159+
#if INCLUDE_CDS
159160
void ArrayKlass::remove_unshareable_info() {
160161
Klass::remove_unshareable_info();
161162
if (_higher_dimension != NULL) {
@@ -182,6 +183,7 @@ void ArrayKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle p
182183
ak->restore_unshareable_info(loader_data, protection_domain, CHECK);
183184
}
184185
}
186+
#endif // INCLUDE_CDS
185187

186188
// Printing
187189

‎src/hotspot/share/oops/arrayKlass.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2022, 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
@@ -114,10 +114,12 @@ class ArrayKlass: public Klass {
114114
// JVMTI support
115115
jint jvmti_class_status() const;
116116

117+
#if INCLUDE_CDS
117118
// CDS support - remove and restore oops from metadata. Oops are not shared.
118119
virtual void remove_unshareable_info();
119120
virtual void remove_java_mirror();
120121
void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
122+
#endif
121123

122124
// Printing
123125
void print_on(outputStream* st) const;

‎src/hotspot/share/oops/constantPool.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ void ConstantPool::add_dumped_interned_strings() {
329329
}
330330
#endif
331331

332+
#if INCLUDE_CDS
332333
// CDS support. Create a new resolved_references array.
333334
void ConstantPool::restore_unshareable_info(TRAPS) {
334335
if (!_pool_holder->is_linked() && !_pool_holder->is_rewritten()) {
@@ -342,9 +343,6 @@ void ConstantPool::restore_unshareable_info(TRAPS) {
342343
// Only create the new resolved references array if it hasn't been attempted before
343344
if (resolved_references() != NULL) return;
344345

345-
// restore the C++ vtable from the shared archive
346-
restore_vtable();
347-
348346
if (vmClasses::Object_klass_loaded()) {
349347
ClassLoaderData* loader_data = pool_holder()->class_loader_data();
350348
#if INCLUDE_CDS_JAVA_HEAP
@@ -427,6 +425,7 @@ void ConstantPool::remove_unshareable_info() {
427425
cache()->remove_unshareable_info();
428426
}
429427
}
428+
#endif // INCLUDE_CDS
430429

431430
int ConstantPool::cp_to_object_index(int cp_index) {
432431
// this is harder don't do this so much.

‎src/hotspot/share/oops/constantPool.hpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -691,17 +691,14 @@ class ConstantPool : public Metadata {
691691
resolve_string_constants_impl(h_this, CHECK);
692692
}
693693

694+
#if INCLUDE_CDS
694695
// CDS support
695696
void archive_resolved_references() NOT_CDS_JAVA_HEAP_RETURN;
696697
void add_dumped_interned_strings() NOT_CDS_JAVA_HEAP_RETURN;
697698
void resolve_class_constants(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
698699
void remove_unshareable_info();
699700
void restore_unshareable_info(TRAPS);
700-
// The ConstantPool vtable is restored by this call when the ConstantPool is
701-
// in the shared archive. See patch_klass_vtables() in metaspaceShared.cpp for
702-
// all the gory details. SA, dtrace and pstack helpers distinguish metadata
703-
// by their vtable.
704-
void restore_vtable() { guarantee(is_constantPool(), "vtable restored by this call"); }
701+
#endif
705702

706703
private:
707704
enum { _no_index_sentinel = -1, _possible_index_sentinel = -2 };

‎src/hotspot/share/oops/cpCache.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -684,18 +684,16 @@ void ConstantPoolCache::record_gc_epoch() {
684684
_gc_epoch = CodeCache::gc_epoch();
685685
}
686686

687-
void ConstantPoolCache::save_for_archive(TRAPS) {
688687
#if INCLUDE_CDS
688+
void ConstantPoolCache::save_for_archive(TRAPS) {
689689
ClassLoaderData* loader_data = constant_pool()->pool_holder()->class_loader_data();
690690
_initial_entries = MetadataFactory::new_array<ConstantPoolCacheEntry>(loader_data, length(), CHECK);
691691
for (int i = 0; i < length(); i++) {
692692
_initial_entries->at_put(i, *entry_at(i));
693693
}
694-
#endif
695694
}
696695

697696
void ConstantPoolCache::remove_unshareable_info() {
698-
#if INCLUDE_CDS
699697
Arguments::assert_is_dumping_archive();
700698
// <this> is the copy to be written into the archive. It's in the ArchiveBuilder's "buffer space".
701699
// However, this->_initial_entries was not copied/relocated by the ArchiveBuilder, so it's
@@ -708,8 +706,8 @@ void ConstantPoolCache::remove_unshareable_info() {
708706
*entry_at(i) = _initial_entries->at(i);
709707
}
710708
_initial_entries = NULL;
711-
#endif
712709
}
710+
#endif // INCLUDE_CDS
713711

714712
void ConstantPoolCache::deallocate_contents(ClassLoaderData* data) {
715713
assert(!is_shared(), "shared caches are not deallocated");

‎src/hotspot/share/oops/cpCache.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,11 @@ class ConstantPoolCache: public MetaspaceObj {
455455
// Assembly code support
456456
static int resolved_references_offset_in_bytes() { return offset_of(ConstantPoolCache, _resolved_references); }
457457

458-
// CDS support
458+
#if INCLUDE_CDS
459459
void remove_unshareable_info();
460460
void save_for_archive(TRAPS);
461+
#endif
462+
461463
private:
462464
void walk_entries_for_initialization(bool check_only);
463465
void set_length(int length) { _length = length; }

‎src/hotspot/share/oops/instanceKlass.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -2451,6 +2451,7 @@ void InstanceKlass::metaspace_pointers_do(MetaspaceClosure* it) {
24512451
it->push(&_record_components);
24522452
}
24532453

2454+
#if INCLUDE_CDS
24542455
void InstanceKlass::remove_unshareable_info() {
24552456

24562457
if (is_linked()) {
@@ -2651,6 +2652,7 @@ void InstanceKlass::assign_class_loader_type() {
26512652
set_shared_class_loader_type(ClassLoader::APP_LOADER);
26522653
}
26532654
}
2655+
#endif // INCLUDE_CDS
26542656

26552657
#if INCLUDE_JVMTI
26562658
static void clear_all_breakpoints(Method* m) {

‎src/hotspot/share/oops/instanceKlass.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -1211,12 +1211,15 @@ class InstanceKlass: public Klass {
12111211
// log class name to classlist
12121212
void log_to_classlist() const;
12131213
public:
1214+
1215+
#if INCLUDE_CDS
12141216
// CDS support - remove and restore oops from metadata. Oops are not shared.
12151217
virtual void remove_unshareable_info();
12161218
virtual void remove_java_mirror();
12171219
void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, PackageEntry* pkg_entry, TRAPS);
12181220
void init_shared_package_entry();
12191221
bool can_be_verified_at_dumptime() const;
1222+
#endif
12201223

12211224
jint compute_modifier_flags() const;
12221225

‎src/hotspot/share/oops/klass.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ void Klass::metaspace_pointers_do(MetaspaceClosure* it) {
537537
}
538538
}
539539

540+
#if INCLUDE_CDS
540541
void Klass::remove_unshareable_info() {
541542
assert (Arguments::is_dumping_archive(),
542543
"only called during CDS dump time");
@@ -627,6 +628,7 @@ void Klass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protec
627628
java_lang_Class::create_mirror(this, loader, module_handle, protection_domain, Handle(), CHECK);
628629
}
629630
}
631+
#endif // INCLUDE_CDS
630632

631633
#if INCLUDE_CDS_JAVA_HEAP
632634
oop Klass::archived_java_mirror() {

‎src/hotspot/share/oops/klass.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,9 @@ class Klass : public Metadata {
545545
void set_vtable_length(int len) { _vtable_len= len; }
546546

547547
vtableEntry* start_of_vtable() const;
548+
#if INCLUDE_CDS
548549
void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
550+
#endif
549551
public:
550552
Method* method_at_vtable(int index);
551553

@@ -554,6 +556,7 @@ class Klass : public Metadata {
554556
return byte_offset_of(Klass, _vtable_len);
555557
}
556558

559+
#if INCLUDE_CDS
557560
// CDS support - remove and restore oops from metadata. Oops are not shared.
558561
virtual void remove_unshareable_info();
559562
virtual void remove_java_mirror();
@@ -569,6 +572,7 @@ class Klass : public Metadata {
569572
return true;
570573
}
571574
}
575+
#endif // INCLUDE_CDS
572576

573577
public:
574578
// ALL FUNCTIONS BELOW THIS POINT ARE DISPATCHED FROM AN OOP

‎src/hotspot/share/oops/method.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ void Method::metaspace_pointers_do(MetaspaceClosure* it) {
401401
NOT_PRODUCT(it->push(&_name);)
402402
}
403403

404+
#if INCLUDE_CDS
404405
// Attempt to return method to original state. Clear any pointers
405406
// (to objects outside the shared spaces). We won't be able to predict
406407
// where they should point in a new JVM. Further initialize some
@@ -411,6 +412,11 @@ void Method::remove_unshareable_info() {
411412
JFR_ONLY(REMOVE_METHOD_ID(this);)
412413
}
413414

415+
void Method::restore_unshareable_info(TRAPS) {
416+
assert(is_method() && is_valid_method(this), "ensure C++ vtable is restored");
417+
}
418+
#endif
419+
414420
void Method::set_vtable_index(int index) {
415421
if (is_shared() && !MetaspaceShared::remapped_readwrite() && method_holder()->verified_at_dump_time()) {
416422
// At runtime initialize_vtable is rerun as part of link_class_impl()
@@ -1259,10 +1265,6 @@ address Method::make_adapters(const methodHandle& mh, TRAPS) {
12591265
return adapter->get_c2i_entry();
12601266
}
12611267

1262-
void Method::restore_unshareable_info(TRAPS) {
1263-
assert(is_method() && is_valid_method(this), "ensure C++ vtable is restored");
1264-
}
1265-
12661268
address Method::from_compiled_entry_no_trampoline() const {
12671269
CompiledMethod *code = Atomic::load_acquire(&_code);
12681270
if (code) {

‎src/hotspot/share/oops/method.hpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ class Method : public Metadata {
134134

135135
virtual bool is_method() const { return true; }
136136

137+
#if INCLUDE_CDS
138+
void remove_unshareable_info();
137139
void restore_unshareable_info(TRAPS);
140+
#endif
138141

139142
// accessors for instance variables
140143

@@ -424,10 +427,6 @@ class Method : public Metadata {
424427
int64_t compiled_invocation_count() const { return 0; }
425428
#endif // not PRODUCT
426429

427-
// Clear (non-shared space) pointers which could not be relevant
428-
// if this (shared) method were mapped into another JVM.
429-
void remove_unshareable_info();
430-
431430
// nmethod/verified compiler entry
432431
address verified_code_entry();
433432
bool check_code() const; // Not inline to avoid circular ref

0 commit comments

Comments
 (0)
Please sign in to comment.