Skip to content

Commit

Permalink
Damage control array alignment change to COH only
Browse files Browse the repository at this point in the history
  • Loading branch information
linade committed Jun 11, 2024
1 parent 0fa2d16 commit 3482e5b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/hotspot/share/oops/arrayOop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ class arrayOopDesc : public oopDesc {
// Returns the offset of the first element.
static int base_offset_in_bytes(BasicType type) {
size_t hs = header_size_in_bytes();
return (int)(element_type_should_be_aligned(type) ? align_up(hs, BytesPerLong) : hs);
// When we are not using UseCompactObjectHeaders, revert back to a more conservative alignment.
return (int)((!UseCompactObjectHeaders || element_type_should_be_aligned(type)) ? align_up(hs, BytesPerLong) : hs);
}

// Returns the address of the first element. The elements in the array will not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public long getObjectSize() {

public static long baseOffsetInBytes(BasicType type) {
long typeSizeInBytes = headerSizeInBytes();
if (elementTypeShouldBeAligned(type)) {
if (!VM.getVM().isCompactObjectHeadersEnabled() || elementTypeShouldBeAligned(type)) {
VM vm = VM.getVM();
return vm.alignUp(typeSizeInBytes, vm.getVM().getHeapWordSize());
} else {
Expand Down
16 changes: 8 additions & 8 deletions test/hotspot/gtest/oops/test_arrayOop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ TEST_VM(arrayOopDesc, base_offset) {
EXPECT_EQ(arrayOopDesc::base_offset_in_bytes(T_OBJECT), 16);
EXPECT_EQ(arrayOopDesc::base_offset_in_bytes(T_ARRAY), 16);
} else {
EXPECT_EQ(arrayOopDesc::base_offset_in_bytes(T_BOOLEAN), 20);
EXPECT_EQ(arrayOopDesc::base_offset_in_bytes(T_BYTE), 20);
EXPECT_EQ(arrayOopDesc::base_offset_in_bytes(T_SHORT), 20);
EXPECT_EQ(arrayOopDesc::base_offset_in_bytes(T_CHAR), 20);
EXPECT_EQ(arrayOopDesc::base_offset_in_bytes(T_INT), 20);
EXPECT_EQ(arrayOopDesc::base_offset_in_bytes(T_FLOAT), 20);
EXPECT_EQ(arrayOopDesc::base_offset_in_bytes(T_BOOLEAN), 24);
EXPECT_EQ(arrayOopDesc::base_offset_in_bytes(T_BYTE), 24);
EXPECT_EQ(arrayOopDesc::base_offset_in_bytes(T_SHORT), 24);
EXPECT_EQ(arrayOopDesc::base_offset_in_bytes(T_CHAR), 24);
EXPECT_EQ(arrayOopDesc::base_offset_in_bytes(T_INT), 24);
EXPECT_EQ(arrayOopDesc::base_offset_in_bytes(T_FLOAT), 24);
EXPECT_EQ(arrayOopDesc::base_offset_in_bytes(T_LONG), 24);
EXPECT_EQ(arrayOopDesc::base_offset_in_bytes(T_DOUBLE), 24);
if (UseCompressedOops) {
EXPECT_EQ(arrayOopDesc::base_offset_in_bytes(T_OBJECT), 20);
EXPECT_EQ(arrayOopDesc::base_offset_in_bytes(T_ARRAY), 20);
EXPECT_EQ(arrayOopDesc::base_offset_in_bytes(T_OBJECT), 24);
EXPECT_EQ(arrayOopDesc::base_offset_in_bytes(T_ARRAY), 24);
} else {
EXPECT_EQ(arrayOopDesc::base_offset_in_bytes(T_OBJECT), 24);
EXPECT_EQ(arrayOopDesc::base_offset_in_bytes(T_ARRAY), 24);
Expand Down
12 changes: 6 additions & 6 deletions test/hotspot/gtest/oops/test_objArrayOop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ TEST_VM(objArrayOop, osize) {
} x[] = {
// ObjAligInB, UseCCP, UseCoops, UseCOH, object size in heap words
#ifdef _LP64
{ 8, false, false, false, 4 }, // 20 byte header, 8 byte oops
{ 8, false, true, false, 3 }, // 20 byte header, 4 byte oops
{ 8, false, false, false, 4 }, // 24 byte header, 8 byte oops
{ 8, false, true, false, 4 }, // 24 byte header, 4 byte oops
{ 8, true, false, false, 3 }, // 16 byte header, 8 byte oops
{ 8, true, true, false, 3 }, // 16 byte header, 4 byte oops
{ 16, false, false, false, 4 }, // 20 byte header, 8 byte oops, 16-byte align
{ 16, false, true, false, 4 }, // 20 byte header, 4 byte oops, 16-byte align
{ 16, false, false, false, 4 }, // 24 byte header, 8 byte oops, 16-byte align
{ 16, false, true, false, 4 }, // 24 byte header, 4 byte oops, 16-byte align
{ 16, true, false, false, 4 }, // 16 byte header, 8 byte oops, 16-byte align
{ 16, true, true, false, 4 }, // 16 byte header, 4 byte oops, 16-byte align
{ 256, false, false, false, 32 }, // 20 byte header, 8 byte oops, 256-byte align
{ 256, false, true, false, 32 }, // 20 byte header, 4 byte oops, 256-byte align
{ 256, false, false, false, 32 }, // 24 byte header, 8 byte oops, 256-byte align
{ 256, false, true, false, 32 }, // 24 byte header, 4 byte oops, 256-byte align
{ 256, true, false, false, 32 }, // 16 byte header, 8 byte oops, 256-byte align
{ 256, true, true, false, 32 }, // 16 byte header, 4 byte oops, 256-byte align
{ 8, false, false, true, 3 }, // 16 byte header, 8 byte oops
Expand Down
2 changes: 1 addition & 1 deletion test/hotspot/jtreg/runtime/FieldLayout/BaseOffsets.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static class LIClass {
LONG_ARRAY_OFFSET = 16;
} else {
INT_OFFSET = 16;
INT_ARRAY_OFFSET = 20;
INT_ARRAY_OFFSET = 24;
LONG_ARRAY_OFFSET = 24;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public class GetObjectSizeIntrinsicsTest extends ASimpleInstrumentationTestCase
static final int LARGE_OBJ_ARRAY_SIZE = (4096/(int)REF_SIZE)*1024*1024 + 1024;

static final boolean CCP = WhiteBox.getWhiteBox().getBooleanVMFlag("UseCompressedClassPointers");
static final int ARRAY_HEADER_SIZE = CCP ? 16 : (Platform.is64bit() ? 20 : 16);
static final int ARRAY_HEADER_SIZE = CCP ? 16 : (Platform.is64bit() ? 24 : 16);

final String mode;

Expand Down

0 comments on commit 3482e5b

Please sign in to comment.