8292891: ifdef-out some CDS-only functions

Reviewed-by: coleenp, ccheung, dholmes
This commit is contained in:
Ioi Lam 2022-08-29 23:20:21 +00:00
parent adb3d4f14a
commit 40b0ed5657
16 changed files with 45 additions and 23 deletions

View File

@ -111,7 +111,7 @@ void Rewriter::make_constant_pool_cache(TRAPS) {
_pool->initialize_resolved_references(loader_data, _resolved_references_map, _pool->initialize_resolved_references(loader_data, _resolved_references_map,
_resolved_reference_limit, _resolved_reference_limit,
THREAD); THREAD);
#if INCLUDE_CDS
if (!HAS_PENDING_EXCEPTION && Arguments::is_dumping_archive()) { if (!HAS_PENDING_EXCEPTION && Arguments::is_dumping_archive()) {
if (_pool->pool_holder()->is_shared()) { if (_pool->pool_holder()->is_shared()) {
assert(DynamicDumpSharedSpaces, "must be"); assert(DynamicDumpSharedSpaces, "must be");
@ -122,6 +122,7 @@ void Rewriter::make_constant_pool_cache(TRAPS) {
cache->save_for_archive(THREAD); cache->save_for_archive(THREAD);
} }
} }
#endif
// Clean up constant pool cache if initialize_resolved_references() failed. // Clean up constant pool cache if initialize_resolved_references() failed.
if (HAS_PENDING_EXCEPTION) { if (HAS_PENDING_EXCEPTION) {

View File

@ -199,6 +199,7 @@ traceid JfrTraceId::load_raw(jclass jc) {
return load(jc, true); return load(jc, true);
} }
#if INCLUDE_CDS
// used by CDS / APPCDS as part of "remove_unshareable_info" // used by CDS / APPCDS as part of "remove_unshareable_info"
void JfrTraceId::remove(const Klass* k) { void JfrTraceId::remove(const Klass* k) {
assert(k != NULL, "invariant"); assert(k != NULL, "invariant");
@ -230,6 +231,7 @@ void JfrTraceId::restore(const Klass* k) {
next_class_id(); next_class_id();
} }
} }
#endif // INCLUDE_CDS
bool JfrTraceId::in_visible_set(const jclass jc) { bool JfrTraceId::in_visible_set(const jclass jc) {
assert(jc != NULL, "invariant"); assert(jc != NULL, "invariant");

View File

@ -102,9 +102,11 @@ class JfrTraceId : public AllStatic {
static traceid load_raw(const PackageEntry* package); static traceid load_raw(const PackageEntry* package);
static traceid load_raw(const ClassLoaderData* cld); static traceid load_raw(const ClassLoaderData* cld);
#if INCLUDE_CDS
static void remove(const Klass* klass); static void remove(const Klass* klass);
static void remove(const Method* method); static void remove(const Method* method);
static void restore(const Klass* klass); static void restore(const Klass* klass);
#endif
// set of event classes made visible to java // set of event classes made visible to java
static bool in_visible_set(const Klass* k); static bool in_visible_set(const Klass* k);

View File

@ -270,6 +270,7 @@ class MetaspaceObj {
// non-shared or shared metaspace. // non-shared or shared metaspace.
static bool is_valid(const MetaspaceObj* p); static bool is_valid(const MetaspaceObj* p);
#if INCLUDE_CDS
static bool is_shared(const MetaspaceObj* p) { static bool is_shared(const MetaspaceObj* p) {
// If no shared metaspace regions are mapped, _shared_metaspace_{base,top} will // If no shared metaspace regions are mapped, _shared_metaspace_{base,top} will
// both be NULL and all values of p will be rejected quickly. // both be NULL and all values of p will be rejected quickly.
@ -277,6 +278,10 @@ class MetaspaceObj {
((void*)p) >= _shared_metaspace_base); ((void*)p) >= _shared_metaspace_base);
} }
bool is_shared() const { return MetaspaceObj::is_shared(this); } 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 void print_address_on(outputStream* st) const; // nonvirtual address printing

View File

@ -156,6 +156,7 @@ void ArrayKlass::metaspace_pointers_do(MetaspaceClosure* it) {
it->push((Klass**)&_lower_dimension); it->push((Klass**)&_lower_dimension);
} }
#if INCLUDE_CDS
void ArrayKlass::remove_unshareable_info() { void ArrayKlass::remove_unshareable_info() {
Klass::remove_unshareable_info(); Klass::remove_unshareable_info();
if (_higher_dimension != NULL) { if (_higher_dimension != NULL) {
@ -182,6 +183,7 @@ void ArrayKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle p
ak->restore_unshareable_info(loader_data, protection_domain, CHECK); ak->restore_unshareable_info(loader_data, protection_domain, CHECK);
} }
} }
#endif // INCLUDE_CDS
// Printing // Printing

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -114,10 +114,12 @@ class ArrayKlass: public Klass {
// JVMTI support // JVMTI support
jint jvmti_class_status() const; jint jvmti_class_status() const;
#if INCLUDE_CDS
// CDS support - remove and restore oops from metadata. Oops are not shared. // CDS support - remove and restore oops from metadata. Oops are not shared.
virtual void remove_unshareable_info(); virtual void remove_unshareable_info();
virtual void remove_java_mirror(); virtual void remove_java_mirror();
void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS); void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
#endif
// Printing // Printing
void print_on(outputStream* st) const; void print_on(outputStream* st) const;

View File

@ -329,6 +329,7 @@ void ConstantPool::add_dumped_interned_strings() {
} }
#endif #endif
#if INCLUDE_CDS
// CDS support. Create a new resolved_references array. // CDS support. Create a new resolved_references array.
void ConstantPool::restore_unshareable_info(TRAPS) { void ConstantPool::restore_unshareable_info(TRAPS) {
if (!_pool_holder->is_linked() && !_pool_holder->is_rewritten()) { if (!_pool_holder->is_linked() && !_pool_holder->is_rewritten()) {
@ -342,9 +343,6 @@ void ConstantPool::restore_unshareable_info(TRAPS) {
// Only create the new resolved references array if it hasn't been attempted before // Only create the new resolved references array if it hasn't been attempted before
if (resolved_references() != NULL) return; if (resolved_references() != NULL) return;
// restore the C++ vtable from the shared archive
restore_vtable();
if (vmClasses::Object_klass_loaded()) { if (vmClasses::Object_klass_loaded()) {
ClassLoaderData* loader_data = pool_holder()->class_loader_data(); ClassLoaderData* loader_data = pool_holder()->class_loader_data();
#if INCLUDE_CDS_JAVA_HEAP #if INCLUDE_CDS_JAVA_HEAP
@ -427,6 +425,7 @@ void ConstantPool::remove_unshareable_info() {
cache()->remove_unshareable_info(); cache()->remove_unshareable_info();
} }
} }
#endif // INCLUDE_CDS
int ConstantPool::cp_to_object_index(int cp_index) { int ConstantPool::cp_to_object_index(int cp_index) {
// this is harder don't do this so much. // this is harder don't do this so much.

View File

@ -691,17 +691,14 @@ class ConstantPool : public Metadata {
resolve_string_constants_impl(h_this, CHECK); resolve_string_constants_impl(h_this, CHECK);
} }
#if INCLUDE_CDS
// CDS support // CDS support
void archive_resolved_references() NOT_CDS_JAVA_HEAP_RETURN; void archive_resolved_references() NOT_CDS_JAVA_HEAP_RETURN;
void add_dumped_interned_strings() 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 resolve_class_constants(TRAPS) NOT_CDS_JAVA_HEAP_RETURN;
void remove_unshareable_info(); void remove_unshareable_info();
void restore_unshareable_info(TRAPS); void restore_unshareable_info(TRAPS);
// The ConstantPool vtable is restored by this call when the ConstantPool is #endif
// 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"); }
private: private:
enum { _no_index_sentinel = -1, _possible_index_sentinel = -2 }; enum { _no_index_sentinel = -1, _possible_index_sentinel = -2 };

View File

@ -684,18 +684,16 @@ void ConstantPoolCache::record_gc_epoch() {
_gc_epoch = CodeCache::gc_epoch(); _gc_epoch = CodeCache::gc_epoch();
} }
void ConstantPoolCache::save_for_archive(TRAPS) {
#if INCLUDE_CDS #if INCLUDE_CDS
void ConstantPoolCache::save_for_archive(TRAPS) {
ClassLoaderData* loader_data = constant_pool()->pool_holder()->class_loader_data(); ClassLoaderData* loader_data = constant_pool()->pool_holder()->class_loader_data();
_initial_entries = MetadataFactory::new_array<ConstantPoolCacheEntry>(loader_data, length(), CHECK); _initial_entries = MetadataFactory::new_array<ConstantPoolCacheEntry>(loader_data, length(), CHECK);
for (int i = 0; i < length(); i++) { for (int i = 0; i < length(); i++) {
_initial_entries->at_put(i, *entry_at(i)); _initial_entries->at_put(i, *entry_at(i));
} }
#endif
} }
void ConstantPoolCache::remove_unshareable_info() { void ConstantPoolCache::remove_unshareable_info() {
#if INCLUDE_CDS
Arguments::assert_is_dumping_archive(); Arguments::assert_is_dumping_archive();
// <this> is the copy to be written into the archive. It's in the ArchiveBuilder's "buffer space". // <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 // However, this->_initial_entries was not copied/relocated by the ArchiveBuilder, so it's
@ -708,8 +706,8 @@ void ConstantPoolCache::remove_unshareable_info() {
*entry_at(i) = _initial_entries->at(i); *entry_at(i) = _initial_entries->at(i);
} }
_initial_entries = NULL; _initial_entries = NULL;
#endif
} }
#endif // INCLUDE_CDS
void ConstantPoolCache::deallocate_contents(ClassLoaderData* data) { void ConstantPoolCache::deallocate_contents(ClassLoaderData* data) {
assert(!is_shared(), "shared caches are not deallocated"); assert(!is_shared(), "shared caches are not deallocated");

View File

@ -455,9 +455,11 @@ class ConstantPoolCache: public MetaspaceObj {
// Assembly code support // Assembly code support
static int resolved_references_offset_in_bytes() { return offset_of(ConstantPoolCache, _resolved_references); } static int resolved_references_offset_in_bytes() { return offset_of(ConstantPoolCache, _resolved_references); }
// CDS support #if INCLUDE_CDS
void remove_unshareable_info(); void remove_unshareable_info();
void save_for_archive(TRAPS); void save_for_archive(TRAPS);
#endif
private: private:
void walk_entries_for_initialization(bool check_only); void walk_entries_for_initialization(bool check_only);
void set_length(int length) { _length = length; } void set_length(int length) { _length = length; }

View File

@ -2451,6 +2451,7 @@ void InstanceKlass::metaspace_pointers_do(MetaspaceClosure* it) {
it->push(&_record_components); it->push(&_record_components);
} }
#if INCLUDE_CDS
void InstanceKlass::remove_unshareable_info() { void InstanceKlass::remove_unshareable_info() {
if (is_linked()) { if (is_linked()) {
@ -2651,6 +2652,7 @@ void InstanceKlass::assign_class_loader_type() {
set_shared_class_loader_type(ClassLoader::APP_LOADER); set_shared_class_loader_type(ClassLoader::APP_LOADER);
} }
} }
#endif // INCLUDE_CDS
#if INCLUDE_JVMTI #if INCLUDE_JVMTI
static void clear_all_breakpoints(Method* m) { static void clear_all_breakpoints(Method* m) {

View File

@ -1211,12 +1211,15 @@ private:
// log class name to classlist // log class name to classlist
void log_to_classlist() const; void log_to_classlist() const;
public: public:
#if INCLUDE_CDS
// CDS support - remove and restore oops from metadata. Oops are not shared. // CDS support - remove and restore oops from metadata. Oops are not shared.
virtual void remove_unshareable_info(); virtual void remove_unshareable_info();
virtual void remove_java_mirror(); virtual void remove_java_mirror();
void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, PackageEntry* pkg_entry, TRAPS); void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, PackageEntry* pkg_entry, TRAPS);
void init_shared_package_entry(); void init_shared_package_entry();
bool can_be_verified_at_dumptime() const; bool can_be_verified_at_dumptime() const;
#endif
jint compute_modifier_flags() const; jint compute_modifier_flags() const;

View File

@ -537,6 +537,7 @@ void Klass::metaspace_pointers_do(MetaspaceClosure* it) {
} }
} }
#if INCLUDE_CDS
void Klass::remove_unshareable_info() { void Klass::remove_unshareable_info() {
assert (Arguments::is_dumping_archive(), assert (Arguments::is_dumping_archive(),
"only called during CDS dump time"); "only called during CDS dump time");
@ -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); java_lang_Class::create_mirror(this, loader, module_handle, protection_domain, Handle(), CHECK);
} }
} }
#endif // INCLUDE_CDS
#if INCLUDE_CDS_JAVA_HEAP #if INCLUDE_CDS_JAVA_HEAP
oop Klass::archived_java_mirror() { oop Klass::archived_java_mirror() {

View File

@ -545,7 +545,9 @@ protected:
void set_vtable_length(int len) { _vtable_len= len; } void set_vtable_length(int len) { _vtable_len= len; }
vtableEntry* start_of_vtable() const; vtableEntry* start_of_vtable() const;
#if INCLUDE_CDS
void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS); void restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, TRAPS);
#endif
public: public:
Method* method_at_vtable(int index); Method* method_at_vtable(int index);
@ -554,6 +556,7 @@ protected:
return byte_offset_of(Klass, _vtable_len); return byte_offset_of(Klass, _vtable_len);
} }
#if INCLUDE_CDS
// CDS support - remove and restore oops from metadata. Oops are not shared. // CDS support - remove and restore oops from metadata. Oops are not shared.
virtual void remove_unshareable_info(); virtual void remove_unshareable_info();
virtual void remove_java_mirror(); virtual void remove_java_mirror();
@ -569,6 +572,7 @@ protected:
return true; return true;
} }
} }
#endif // INCLUDE_CDS
public: public:
// ALL FUNCTIONS BELOW THIS POINT ARE DISPATCHED FROM AN OOP // ALL FUNCTIONS BELOW THIS POINT ARE DISPATCHED FROM AN OOP

View File

@ -401,6 +401,7 @@ void Method::metaspace_pointers_do(MetaspaceClosure* it) {
NOT_PRODUCT(it->push(&_name);) NOT_PRODUCT(it->push(&_name);)
} }
#if INCLUDE_CDS
// Attempt to return method to original state. Clear any pointers // Attempt to return method to original state. Clear any pointers
// (to objects outside the shared spaces). We won't be able to predict // (to objects outside the shared spaces). We won't be able to predict
// where they should point in a new JVM. Further initialize some // where they should point in a new JVM. Further initialize some
@ -411,6 +412,11 @@ void Method::remove_unshareable_info() {
JFR_ONLY(REMOVE_METHOD_ID(this);) 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) { void Method::set_vtable_index(int index) {
if (is_shared() && !MetaspaceShared::remapped_readwrite() && method_holder()->verified_at_dump_time()) { if (is_shared() && !MetaspaceShared::remapped_readwrite() && method_holder()->verified_at_dump_time()) {
// At runtime initialize_vtable is rerun as part of link_class_impl() // At runtime initialize_vtable is rerun as part of link_class_impl()
@ -1259,10 +1265,6 @@ address Method::make_adapters(const methodHandle& mh, TRAPS) {
return adapter->get_c2i_entry(); 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 { address Method::from_compiled_entry_no_trampoline() const {
CompiledMethod *code = Atomic::load_acquire(&_code); CompiledMethod *code = Atomic::load_acquire(&_code);
if (code) { if (code) {

View File

@ -134,7 +134,10 @@ class Method : public Metadata {
virtual bool is_method() const { return true; } virtual bool is_method() const { return true; }
#if INCLUDE_CDS
void remove_unshareable_info();
void restore_unshareable_info(TRAPS); void restore_unshareable_info(TRAPS);
#endif
// accessors for instance variables // accessors for instance variables
@ -424,10 +427,6 @@ class Method : public Metadata {
int64_t compiled_invocation_count() const { return 0; } int64_t compiled_invocation_count() const { return 0; }
#endif // not PRODUCT #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 // nmethod/verified compiler entry
address verified_code_entry(); address verified_code_entry();
bool check_code() const; // Not inline to avoid circular ref bool check_code() const; // Not inline to avoid circular ref