From 57e7a3fbeae56f39f9434b4a97dd915fa14af93d Mon Sep 17 00:00:00 2001 From: Ioi Lam Date: Mon, 15 May 2023 16:33:37 +0000 Subject: [PATCH] 8307959: Remove explicit type casts from SerializeClosure::do_xxx() calls Reviewed-by: matsaave, ccheung --- src/hotspot/share/cds/archiveUtils.cpp | 5 ++++ src/hotspot/share/cds/archiveUtils.hpp | 5 ++++ src/hotspot/share/cds/cppVtables.cpp | 2 +- src/hotspot/share/cds/heapShared.cpp | 2 +- src/hotspot/share/cds/lambdaFormInvokers.cpp | 2 +- .../share/classfile/classLoaderDataShared.cpp | 6 ++--- .../share/classfile/compactHashtable.cpp | 4 ++-- .../share/classfile/javaClassesImpl.hpp | 6 ++--- src/hotspot/share/classfile/stringTable.cpp | 2 +- .../classfile/systemDictionaryShared.cpp | 2 +- src/hotspot/share/memory/iterator.hpp | 6 +++++ src/hotspot/share/memory/universe.cpp | 24 +++++++++++-------- src/hotspot/share/memory/universe.hpp | 5 ++-- .../share/oops/instanceMirrorKlass.cpp | 2 +- .../share/oops/instanceStackChunkKlass.cpp | 2 +- 15 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/hotspot/share/cds/archiveUtils.cpp b/src/hotspot/share/cds/archiveUtils.cpp index 952f69749b3..bda205055eb 100644 --- a/src/hotspot/share/cds/archiveUtils.cpp +++ b/src/hotspot/share/cds/archiveUtils.cpp @@ -301,6 +301,11 @@ void ReadClosure::do_u4(u4* p) { *p = (u4)(uintx(obj)); } +void ReadClosure::do_int(int* p) { + intptr_t obj = nextPtr(); + *p = (int)(intx(obj)); +} + void ReadClosure::do_bool(bool* p) { intptr_t obj = nextPtr(); *p = (bool)(uintx(obj)); diff --git a/src/hotspot/share/cds/archiveUtils.hpp b/src/hotspot/share/cds/archiveUtils.hpp index d5526dce4df..27f5344677e 100644 --- a/src/hotspot/share/cds/archiveUtils.hpp +++ b/src/hotspot/share/cds/archiveUtils.hpp @@ -192,6 +192,10 @@ public: _dump_region->append_intptr_t((intptr_t)(*p)); } + void do_int(int* p) { + _dump_region->append_intptr_t((intptr_t)(*p)); + } + void do_bool(bool *p) { _dump_region->append_intptr_t((intptr_t)(*p)); } @@ -221,6 +225,7 @@ public: void do_ptr(void** p); void do_u4(u4* p); + void do_int(int* p); void do_bool(bool *p); void do_tag(int tag); void do_oop(oop *p); diff --git a/src/hotspot/share/cds/cppVtables.cpp b/src/hotspot/share/cds/cppVtables.cpp index d91c930f17c..05144f474c2 100644 --- a/src/hotspot/share/cds/cppVtables.cpp +++ b/src/hotspot/share/cds/cppVtables.cpp @@ -228,7 +228,7 @@ char* CppVtables::dumptime_init(ArchiveBuilder* builder) { } void CppVtables::serialize(SerializeClosure* soc) { - soc->do_ptr((void**)&_index); + soc->do_ptr(&_index); if (soc->reading()) { CPP_VTABLE_TYPES_DO(INITIALIZE_VTABLE); } diff --git a/src/hotspot/share/cds/heapShared.cpp b/src/hotspot/share/cds/heapShared.cpp index 1302d587747..9f618f9d245 100644 --- a/src/hotspot/share/cds/heapShared.cpp +++ b/src/hotspot/share/cds/heapShared.cpp @@ -855,7 +855,7 @@ void HeapShared::serialize_root(SerializeClosure* soc) { void HeapShared::serialize_tables(SerializeClosure* soc) { #ifndef PRODUCT - soc->do_ptr((void**)&_archived_ArchiveHeapTestClass); + soc->do_ptr(&_archived_ArchiveHeapTestClass); if (soc->reading() && _archived_ArchiveHeapTestClass != nullptr) { _test_class_name = _archived_ArchiveHeapTestClass->adr_at(0); setup_test_class(_test_class_name); diff --git a/src/hotspot/share/cds/lambdaFormInvokers.cpp b/src/hotspot/share/cds/lambdaFormInvokers.cpp index b759215fe44..70a9017977b 100644 --- a/src/hotspot/share/cds/lambdaFormInvokers.cpp +++ b/src/hotspot/share/cds/lambdaFormInvokers.cpp @@ -266,5 +266,5 @@ void LambdaFormInvokers::read_static_archive_invokers() { } void LambdaFormInvokers::serialize(SerializeClosure* soc) { - soc->do_ptr((void**)&_static_archive_invokers); + soc->do_ptr(&_static_archive_invokers); } diff --git a/src/hotspot/share/classfile/classLoaderDataShared.cpp b/src/hotspot/share/classfile/classLoaderDataShared.cpp index 9d7a5049859..3ac1b164c52 100644 --- a/src/hotspot/share/classfile/classLoaderDataShared.cpp +++ b/src/hotspot/share/classfile/classLoaderDataShared.cpp @@ -56,8 +56,8 @@ public: void init_archived_entries(ClassLoaderData* loader_data); void serialize(SerializeClosure* f) { - f->do_ptr((void**)&_packages); - f->do_ptr((void**)&_modules); + f->do_ptr(&_packages); + f->do_ptr(&_modules); } void restore(ClassLoaderData* loader_data, bool do_entries, bool do_oops); @@ -169,7 +169,7 @@ void ClassLoaderDataShared::serialize(SerializeClosure* f) { _archived_boot_loader_data.serialize(f); _archived_platform_loader_data.serialize(f); _archived_system_loader_data.serialize(f); - f->do_ptr((void**)&_archived_javabase_moduleEntry); + f->do_ptr(&_archived_javabase_moduleEntry); if (f->reading() && MetaspaceShared::use_full_module_graph()) { // Must be done before ClassLoader::create_javabase() diff --git a/src/hotspot/share/classfile/compactHashtable.cpp b/src/hotspot/share/classfile/compactHashtable.cpp index f20741a78f7..c20c709dcf1 100644 --- a/src/hotspot/share/classfile/compactHashtable.cpp +++ b/src/hotspot/share/classfile/compactHashtable.cpp @@ -213,8 +213,8 @@ void SimpleCompactHashtable::serialize_header(SerializeClosure* soc) { // calculate_header_size() accordingly. soc->do_u4(&_entry_count); soc->do_u4(&_bucket_count); - soc->do_ptr((void**)&_buckets); - soc->do_ptr((void**)&_entries); + soc->do_ptr(&_buckets); + soc->do_ptr(&_entries); if (soc->reading()) { _base_address = (address)SharedBaseAddress; } diff --git a/src/hotspot/share/classfile/javaClassesImpl.hpp b/src/hotspot/share/classfile/javaClassesImpl.hpp index 2ae6ec34845..87a332d6682 100644 --- a/src/hotspot/share/classfile/javaClassesImpl.hpp +++ b/src/hotspot/share/classfile/javaClassesImpl.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2023, 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 @@ -47,12 +47,12 @@ #if INCLUDE_CDS #define INJECTED_FIELD_SERIALIZE_OFFSET(klass, name, signature, may_be_java) \ - f->do_u4((u4*)&_##name##_offset); + f->do_int(&_##name##_offset); #endif #if INCLUDE_CDS #define FIELD_SERIALIZE_OFFSET(offset, klass, name, signature, is_static) \ - f->do_u4((u4*)&offset) + f->do_int(&offset) #endif #define FIELD_COMPUTE_OFFSET(offset, klass, name, signature, is_static) \ diff --git a/src/hotspot/share/classfile/stringTable.cpp b/src/hotspot/share/classfile/stringTable.cpp index a2a567c7903..89381b1a785 100644 --- a/src/hotspot/share/classfile/stringTable.cpp +++ b/src/hotspot/share/classfile/stringTable.cpp @@ -932,6 +932,6 @@ void StringTable::serialize_shared_table_header(SerializeClosure* soc) { } soc->do_bool(&_is_two_dimensional_shared_strings_array); - soc->do_u4((u4*)(&_shared_strings_array_root_index)); + soc->do_int(&_shared_strings_array_root_index); } #endif //INCLUDE_CDS_JAVA_HEAP diff --git a/src/hotspot/share/classfile/systemDictionaryShared.cpp b/src/hotspot/share/classfile/systemDictionaryShared.cpp index ecbb10da5e2..e3561b39fd0 100644 --- a/src/hotspot/share/classfile/systemDictionaryShared.cpp +++ b/src/hotspot/share/classfile/systemDictionaryShared.cpp @@ -1268,7 +1268,7 @@ void SystemDictionaryShared::serialize_dictionary_headers(SerializeClosure* soc, void SystemDictionaryShared::serialize_vm_classes(SerializeClosure* soc) { for (auto id : EnumRange{}) { - soc->do_ptr((void**)vmClasses::klass_addr_at(id)); + soc->do_ptr(vmClasses::klass_addr_at(id)); } } diff --git a/src/hotspot/share/memory/iterator.hpp b/src/hotspot/share/memory/iterator.hpp index b936cac4abd..67fbcd8f23c 100644 --- a/src/hotspot/share/memory/iterator.hpp +++ b/src/hotspot/share/memory/iterator.hpp @@ -341,6 +341,9 @@ public: // Read/write the 32-bit unsigned integer pointed to by p. virtual void do_u4(u4* p) = 0; + // Read/write the int pointed to by p. + virtual void do_int(int* p) = 0; + // Read/write the bool pointed to by p. virtual void do_bool(bool* p) = 0; @@ -359,6 +362,9 @@ public: bool writing() { return !reading(); } + + // Useful alias + template void do_ptr(T** p) { do_ptr((void**)p); } }; class SymbolClosure : public StackObj { diff --git a/src/hotspot/share/memory/universe.cpp b/src/hotspot/share/memory/universe.cpp index 90511dee2bc..ad87e988f3e 100644 --- a/src/hotspot/share/memory/universe.cpp +++ b/src/hotspot/share/memory/universe.cpp @@ -261,25 +261,25 @@ void Universe::serialize(SerializeClosure* f) { #if INCLUDE_CDS_JAVA_HEAP for (int i = T_BOOLEAN; i < T_VOID+1; i++) { - f->do_u4((u4*)&_archived_basic_type_mirror_indices[i]); + f->do_int(&_archived_basic_type_mirror_indices[i]); // if f->reading(): We can't call HeapShared::get_root() yet, as the heap // contents may need to be relocated. _basic_type_mirrors[i] will be // updated later in Universe::update_archived_basic_type_mirrors(). } #endif - f->do_ptr((void**)&_fillerArrayKlassObj); + f->do_ptr(&_fillerArrayKlassObj); for (int i = 0; i < T_LONG+1; i++) { - f->do_ptr((void**)&_typeArrayKlassObjs[i]); + f->do_ptr(&_typeArrayKlassObjs[i]); } - f->do_ptr((void**)&_objectArrayKlassObj); - f->do_ptr((void**)&_the_array_interfaces_array); - f->do_ptr((void**)&_the_empty_int_array); - f->do_ptr((void**)&_the_empty_short_array); - f->do_ptr((void**)&_the_empty_method_array); - f->do_ptr((void**)&_the_empty_klass_array); - f->do_ptr((void**)&_the_empty_instance_klass_array); + f->do_ptr(&_objectArrayKlassObj); + f->do_ptr(&_the_array_interfaces_array); + f->do_ptr(&_the_empty_int_array); + f->do_ptr(&_the_empty_short_array); + f->do_ptr(&_the_empty_method_array); + f->do_ptr(&_the_empty_klass_array); + f->do_ptr(&_the_empty_instance_klass_array); _finalizer_register_cache->serialize(f); _loader_addClass_cache->serialize(f); _throw_illegal_access_error_cache->serialize(f); @@ -1268,6 +1268,10 @@ Method* LatestMethodCache::get_method() { return m; } +void LatestMethodCache::serialize(SerializeClosure* f) { + f->do_ptr(&_klass); +} + #ifdef ASSERT // Release dummy object(s) at bottom of heap bool Universe::release_fullgc_alot_dummy() { diff --git a/src/hotspot/share/memory/universe.hpp b/src/hotspot/share/memory/universe.hpp index 9cbb7ecd3f5..aee154a98bc 100644 --- a/src/hotspot/share/memory/universe.hpp +++ b/src/hotspot/share/memory/universe.hpp @@ -43,6 +43,7 @@ class CollectedHeap; class DeferredObjAllocEvent; class OopStorage; class ReservedHeapSpace; +class SerializeClosure; // A helper class for caching a Method* when the user of the cache // only cares about the latest version of the Method*. This cache safely @@ -67,9 +68,7 @@ class LatestMethodCache : public CHeapObj { // CDS support. Replace the klass in this with the archive version // could use this for Enhanced Class Redefinition also. - void serialize(SerializeClosure* f) { - f->do_ptr((void**)&_klass); - } + void serialize(SerializeClosure* f); void metaspace_pointers_do(MetaspaceClosure* it); }; diff --git a/src/hotspot/share/oops/instanceMirrorKlass.cpp b/src/hotspot/share/oops/instanceMirrorKlass.cpp index 2cb0b953d14..be1d9596747 100644 --- a/src/hotspot/share/oops/instanceMirrorKlass.cpp +++ b/src/hotspot/share/oops/instanceMirrorKlass.cpp @@ -69,6 +69,6 @@ int InstanceMirrorKlass::compute_static_oop_field_count(oop obj) { #if INCLUDE_CDS void InstanceMirrorKlass::serialize_offsets(SerializeClosure* f) { - f->do_u4((u4*)&_offset_of_static_fields); + f->do_int(&_offset_of_static_fields); } #endif diff --git a/src/hotspot/share/oops/instanceStackChunkKlass.cpp b/src/hotspot/share/oops/instanceStackChunkKlass.cpp index 62c9c89767e..9f1b4d7253d 100644 --- a/src/hotspot/share/oops/instanceStackChunkKlass.cpp +++ b/src/hotspot/share/oops/instanceStackChunkKlass.cpp @@ -46,7 +46,7 @@ int InstanceStackChunkKlass::_offset_of_stack = 0; #if INCLUDE_CDS void InstanceStackChunkKlass::serialize_offsets(SerializeClosure* f) { - f->do_u4((u4*)&_offset_of_stack); + f->do_int(&_offset_of_stack); } #endif