RFR: 8139457: Array bases are aligned at HeapWord granularity

Thomas Stuefe stuefe at openjdk.org
Mon Nov 21 11:07:25 UTC 2022


On Tue, 8 Nov 2022 20:18:09 GMT, Roman Kennke <rkennke at openjdk.org> wrote:

> See [JDK-8139457](https://bugs.openjdk.org/browse/JDK-8139457) for details.
> 
> Basically, when running with -XX:-UseCompressedClassPointers, arrays will have a gap between the length field and the first array element, because array elements will only start at word-aligned offsets. This is not necessary for smaller-than-word elements.
> 
> Also, while it is not very important now, it will become very important with Lilliput, which eliminates the Klass field and would always put the length field at offset 8, and leave a gap between offset 12 and 16.
> 
> Testing:
>  - [x] runtime/FieldLayout/ArrayBaseOffsets.java (x86_64, x86_32, aarch64, arm, riscv, s390)
>  - [x] bootcycle (x86_64, x86_32, aarch64, arm, riscv, s390)
>  - [x] tier1 (x86_64, x86_32, aarch64, riscv)
>  - [x] tier2 (x86_64, aarch64, riscv)
>  - [x] tier3 (x86_64, riscv)

This should make it work on ppc.


thomas at starfish:/shared/projects/openjdk/jdk-jdk/source$ git diff
diff --git a/src/hotspot/cpu/ppc/c1_MacroAssembler_ppc.cpp b/src/hotspot/cpu/ppc/c1_MacroAssembler_ppc.cpp
index 87b87e83e1a..4420c2ac4ca 100644
--- a/src/hotspot/cpu/ppc/c1_MacroAssembler_ppc.cpp
+++ b/src/hotspot/cpu/ppc/c1_MacroAssembler_ppc.cpp
@@ -361,6 +361,16 @@ void C1_MacroAssembler::allocate_array(
   const Register index = t3;
   addi(base, obj, base_offset_in_bytes);               // compute address of first element
   addi(index, arr_size, -(base_offset_in_bytes));      // compute index = number of bytes to clear
+
+  // Elements are not dword aligned. Zero out leading word.
+  if (!is_aligned(base_offset_in_bytes, BytesPerWord)) {
+    assert(is_aligned(base_offset_in_bytes, BytesPerInt), "weird alignment");
+    li(t1, 0);
+    stw(t1, 0, base);
+    addi(base, base, BytesPerInt);
+    // Note: initialize_body will align index down, no need to correct it here.
+  }
+
   initialize_body(base, index);
 
   if (CURRENT_ENV->dtrace_alloc_probes()) {



I did the zero-ing out up in `allocate_array` since I did not want to affect the object allocation path.

I ran several tests manually with and without UseCCP. Your test case runs also through. Our hardware is a bottleneck though, and currently Richard is using our test queue with his PPC Loom port. Therefore it may take a while until I manage to run more tests.

I tested s390, and it seems to work without a change. Did multiple tests with -UseCCP, as well as your test case. 

I think it works out of the box since C1_MacroAssembler::initialize_body() uses MVCLE to zero out memory, and that instruction works at the byte level, so no alignment restrictions for input pointers.

src/hotspot/share/oops/arrayOop.hpp line 77:

> 75:       return !UseCompressedOops;
> 76:     }
> 77: #endif

I'm confused why this is not needed today?

-------------

PR: https://git.openjdk.org/jdk/pull/11044


More information about the hotspot-dev mailing list