Skip to content

Commit

Permalink
8292891: ifdef-out some CDS-only functions
Browse files Browse the repository at this point in the history
Reviewed-by: coleenp, ccheung, dholmes
  • Loading branch information
iklam committed Aug 29, 2022
1 parent adb3d4f commit 40b0ed5
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/hotspot/share/interpreter/rewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void Rewriter::make_constant_pool_cache(TRAPS) {
_pool->initialize_resolved_references(loader_data, _resolved_references_map,
_resolved_reference_limit,
THREAD);

#if INCLUDE_CDS
if (!HAS_PENDING_EXCEPTION && Arguments::is_dumping_archive()) {
if (_pool->pool_holder()->is_shared()) {
assert(DynamicDumpSharedSpaces, "must be");
Expand All @@ -122,6 +122,7 @@ void Rewriter::make_constant_pool_cache(TRAPS) {
cache->save_for_archive(THREAD);
}
}
#endif

// Clean up constant pool cache if initialize_resolved_references() failed.
if (HAS_PENDING_EXCEPTION) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ traceid JfrTraceId::load_raw(jclass jc) {
return load(jc, true);
}

#if INCLUDE_CDS
// used by CDS / APPCDS as part of "remove_unshareable_info"
void JfrTraceId::remove(const Klass* k) {
assert(k != NULL, "invariant");
Expand Down Expand Up @@ -230,6 +231,7 @@ void JfrTraceId::restore(const Klass* k) {
next_class_id();
}
}
#endif // INCLUDE_CDS

bool JfrTraceId::in_visible_set(const jclass jc) {
assert(jc != NULL, "invariant");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ class JfrTraceId : public AllStatic {
static traceid load_raw(const PackageEntry* package);
static traceid load_raw(const ClassLoaderData* cld);

#if INCLUDE_CDS
static void remove(const Klass* klass);
static void remove(const Method* method);
static void restore(const Klass* klass);
#endif

// set of event classes made visible to java
static bool in_visible_set(const Klass* k);
Expand Down
5 changes: 5 additions & 0 deletions src/hotspot/share/memory/allocation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,18 @@ class MetaspaceObj {
// non-shared or shared metaspace.
static bool is_valid(const MetaspaceObj* p);

#if INCLUDE_CDS
static bool is_shared(const MetaspaceObj* p) {
// If no shared metaspace regions are mapped, _shared_metaspace_{base,top} will
// both be NULL and all values of p will be rejected quickly.
return (((void*)p) < _shared_metaspace_top &&
((void*)p) >= _shared_metaspace_base);
}
bool is_shared() const { return MetaspaceObj::is_shared(this); }
#else
static bool is_shared(const MetaspaceObj* p) { return false; }
bool is_shared() const { return false; }
#endif

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

Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/oops/arrayKlass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ void ArrayKlass::metaspace_pointers_do(MetaspaceClosure* it) {
it->push((Klass**)&_lower_dimension);
}

#if INCLUDE_CDS
void ArrayKlass::remove_unshareable_info() {
Klass::remove_unshareable_info();
if (_higher_dimension != NULL) {
Expand All @@ -182,6 +183,7 @@ void ArrayKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle p
ak->restore_unshareable_info(loader_data, protection_domain, CHECK);
}
}
#endif // INCLUDE_CDS

// Printing

Expand Down
4 changes: 3 additions & 1 deletion src/hotspot/share/oops/arrayKlass.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -114,10 +114,12 @@ class ArrayKlass: public Klass {
// JVMTI support
jint jvmti_class_status() const;

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

// Printing
void print_on(outputStream* st) const;
Expand Down
5 changes: 2 additions & 3 deletions src/hotspot/share/oops/constantPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ void ConstantPool::add_dumped_interned_strings() {
}
#endif

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

// restore the C++ vtable from the shared archive
restore_vtable();

if (vmClasses::Object_klass_loaded()) {
ClassLoaderData* loader_data = pool_holder()->class_loader_data();
#if INCLUDE_CDS_JAVA_HEAP
Expand Down Expand Up @@ -427,6 +425,7 @@ void ConstantPool::remove_unshareable_info() {
cache()->remove_unshareable_info();
}
}
#endif // INCLUDE_CDS

int ConstantPool::cp_to_object_index(int cp_index) {
// this is harder don't do this so much.
Expand Down
7 changes: 2 additions & 5 deletions src/hotspot/share/oops/constantPool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,17 +691,14 @@ class ConstantPool : public Metadata {
resolve_string_constants_impl(h_this, CHECK);
}

#if INCLUDE_CDS
// CDS support
void archive_resolved_references() NOT_CDS_JAVA_HEAP_RETURN;
void add_dumped_interned_strings() NOT_CDS_JAVA_HEAP_RETURN;
void resolve_class_constants(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
void remove_unshareable_info();
void restore_unshareable_info(TRAPS);
// The ConstantPool vtable is restored by this call when the ConstantPool is
// in the shared archive. See patch_klass_vtables() in metaspaceShared.cpp for
// all the gory details. SA, dtrace and pstack helpers distinguish metadata
// by their vtable.
void restore_vtable() { guarantee(is_constantPool(), "vtable restored by this call"); }
#endif

private:
enum { _no_index_sentinel = -1, _possible_index_sentinel = -2 };
Expand Down
6 changes: 2 additions & 4 deletions src/hotspot/share/oops/cpCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,18 +684,16 @@ void ConstantPoolCache::record_gc_epoch() {
_gc_epoch = CodeCache::gc_epoch();
}

void ConstantPoolCache::save_for_archive(TRAPS) {
#if INCLUDE_CDS
void ConstantPoolCache::save_for_archive(TRAPS) {
ClassLoaderData* loader_data = constant_pool()->pool_holder()->class_loader_data();
_initial_entries = MetadataFactory::new_array<ConstantPoolCacheEntry>(loader_data, length(), CHECK);
for (int i = 0; i < length(); i++) {
_initial_entries->at_put(i, *entry_at(i));
}
#endif
}

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

void ConstantPoolCache::deallocate_contents(ClassLoaderData* data) {
assert(!is_shared(), "shared caches are not deallocated");
Expand Down
4 changes: 3 additions & 1 deletion src/hotspot/share/oops/cpCache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,11 @@ class ConstantPoolCache: public MetaspaceObj {
// Assembly code support
static int resolved_references_offset_in_bytes() { return offset_of(ConstantPoolCache, _resolved_references); }

// CDS support
#if INCLUDE_CDS
void remove_unshareable_info();
void save_for_archive(TRAPS);
#endif

private:
void walk_entries_for_initialization(bool check_only);
void set_length(int length) { _length = length; }
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/oops/instanceKlass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2451,6 +2451,7 @@ void InstanceKlass::metaspace_pointers_do(MetaspaceClosure* it) {
it->push(&_record_components);
}

#if INCLUDE_CDS
void InstanceKlass::remove_unshareable_info() {

if (is_linked()) {
Expand Down Expand Up @@ -2651,6 +2652,7 @@ void InstanceKlass::assign_class_loader_type() {
set_shared_class_loader_type(ClassLoader::APP_LOADER);
}
}
#endif // INCLUDE_CDS

#if INCLUDE_JVMTI
static void clear_all_breakpoints(Method* m) {
Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/share/oops/instanceKlass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1211,12 +1211,15 @@ class InstanceKlass: public Klass {
// log class name to classlist
void log_to_classlist() const;
public:

#if INCLUDE_CDS
// CDS support - remove and restore oops from metadata. Oops are not shared.
virtual void remove_unshareable_info();
virtual void remove_java_mirror();
void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, PackageEntry* pkg_entry, TRAPS);
void init_shared_package_entry();
bool can_be_verified_at_dumptime() const;
#endif

jint compute_modifier_flags() const;

Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/oops/klass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ void Klass::metaspace_pointers_do(MetaspaceClosure* it) {
}
}

#if INCLUDE_CDS
void Klass::remove_unshareable_info() {
assert (Arguments::is_dumping_archive(),
"only called during CDS dump time");
Expand Down Expand Up @@ -627,6 +628,7 @@ void Klass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protec
java_lang_Class::create_mirror(this, loader, module_handle, protection_domain, Handle(), CHECK);
}
}
#endif // INCLUDE_CDS

#if INCLUDE_CDS_JAVA_HEAP
oop Klass::archived_java_mirror() {
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/share/oops/klass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,9 @@ class Klass : public Metadata {
void set_vtable_length(int len) { _vtable_len= len; }

vtableEntry* start_of_vtable() const;
#if INCLUDE_CDS
void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
#endif
public:
Method* method_at_vtable(int index);

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

#if INCLUDE_CDS
// CDS support - remove and restore oops from metadata. Oops are not shared.
virtual void remove_unshareable_info();
virtual void remove_java_mirror();
Expand All @@ -569,6 +572,7 @@ class Klass : public Metadata {
return true;
}
}
#endif // INCLUDE_CDS

public:
// ALL FUNCTIONS BELOW THIS POINT ARE DISPATCHED FROM AN OOP
Expand Down
10 changes: 6 additions & 4 deletions src/hotspot/share/oops/method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ void Method::metaspace_pointers_do(MetaspaceClosure* it) {
NOT_PRODUCT(it->push(&_name);)
}

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

void Method::restore_unshareable_info(TRAPS) {
assert(is_method() && is_valid_method(this), "ensure C++ vtable is restored");
}
#endif

void Method::set_vtable_index(int index) {
if (is_shared() && !MetaspaceShared::remapped_readwrite() && method_holder()->verified_at_dump_time()) {
// At runtime initialize_vtable is rerun as part of link_class_impl()
Expand Down Expand Up @@ -1259,10 +1265,6 @@ address Method::make_adapters(const methodHandle& mh, TRAPS) {
return adapter->get_c2i_entry();
}

void Method::restore_unshareable_info(TRAPS) {
assert(is_method() && is_valid_method(this), "ensure C++ vtable is restored");
}

address Method::from_compiled_entry_no_trampoline() const {
CompiledMethod *code = Atomic::load_acquire(&_code);
if (code) {
Expand Down
7 changes: 3 additions & 4 deletions src/hotspot/share/oops/method.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ class Method : public Metadata {

virtual bool is_method() const { return true; }

#if INCLUDE_CDS
void remove_unshareable_info();
void restore_unshareable_info(TRAPS);
#endif

// accessors for instance variables

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

// Clear (non-shared space) pointers which could not be relevant
// if this (shared) method were mapped into another JVM.
void remove_unshareable_info();

// nmethod/verified compiler entry
address verified_code_entry();
bool check_code() const; // Not inline to avoid circular ref
Expand Down

1 comment on commit 40b0ed5

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.