RFR(s): Wrong alignment in CDS related Klass* reallocating code
Fedor Burdun
fedor.burdun at azul.com
Fri May 17 13:51:19 UTC 2019
Hello all,
I've found an inconsistency in CDS related Klass* reallocating code, in method
static void ArchiveCompactor::allocate(MetaspaceClosure::Ref* ref, bool read_only) (src/hotspot/share/memory/metaspaceShared.cpp:1122)
the alignment = BytesPerWord has been used, that is fine for 64bit platforms, but may cause problems on 32bit ones.
For example, in case of ARM gcc compiles accessors for u8/long long types using ldrd/strd instructions that requires a double-word alignment on ARMv5TE and older.
Moreover the method (although it used only for compressed oops)
inline bool check_klass_alignment(Klass* obj) in src/hotspot/share/oops/klass.inline.hpp
checks classes to be aligned to KlassAlignment const, not to the BytesPerWord one.
So I would like to suggest the fix below:
diff --git a/src/hotspot/share/memory/metaspaceShared.cpp b/src/hotspot/share/memory/metaspaceShared.cpp
--- a/src/hotspot/share/memory/metaspaceShared.cpp
+++ b/src/hotspot/share/memory/metaspaceShared.cpp
@@ -1123,7 +1123,7 @@
address obj = ref->obj();
int bytes = ref->size() * BytesPerWord;
char* p;
- size_t alignment = BytesPerWord;
+ size_t alignment = KlassAlignmentInBytes;
char* oldtop;
char* newtop;
Thanks,
Fedor
More information about the hotspot-runtime-dev
mailing list