Skip to content

Commit

Permalink
Preserve old-space header when array-slicing
Browse files Browse the repository at this point in the history
  • Loading branch information
rkennke committed Jul 26, 2024
1 parent 878ba48 commit c1922b1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "gc/shared/partialArrayTaskStepper.hpp"

#include "oops/arrayOop.hpp"
#include "oops/oop.inline.hpp"
#include "runtime/atomic.hpp"

PartialArrayTaskStepper::Step
Expand Down Expand Up @@ -57,7 +58,10 @@ PartialArrayTaskStepper::start_impl(int length,

PartialArrayTaskStepper::Step
PartialArrayTaskStepper::start(arrayOop from, arrayOop to, int chunk_size) const {
return start_impl(from->length(), to->length_addr(), chunk_size);
if (to->size() > 2) {
from->set_slice_helper(to->length());
}
return start_impl(to->length(), to->length_addr(), chunk_size);
}

PartialArrayTaskStepper::Step
Expand Down Expand Up @@ -112,7 +116,7 @@ PartialArrayTaskStepper::next_impl(int length,

PartialArrayTaskStepper::Step
PartialArrayTaskStepper::next(arrayOop from, arrayOop to, int chunk_size) const {
return next_impl(from->length(), to->length_addr(), chunk_size);
return next_impl(from->get_slice_helper(), to->length_addr(), chunk_size);
}

#endif // SHARE_GC_SHARED_PARTIALARRAYTASKSTEPPER_INLINE_HPP
23 changes: 23 additions & 0 deletions src/hotspot/share/oops/arrayOop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ class arrayOopDesc : public oopDesc {
return reinterpret_cast<int*>(ptr + length_offset_in_bytes());
}

static int slice_helper_offset_in_bytes() {
if (UseCompactObjectHeaders) {
return 8;
} else {
return length_offset_in_bytes();
}
}

int* slice_helper_addr() {
char* ptr = cast_from_oop<char*>(const_cast<arrayOopDesc*>(this));
//assert(size() * BytesPerWord >= (size_t)slice_helper_offset_in_bytes() + BytesPerInt,
// "slice helper should fit");
return reinterpret_cast<int*>(ptr + slice_helper_offset_in_bytes());
}

// Given a type, return true if elements of that type must be aligned to 64-bit.
static bool element_type_should_be_aligned(BasicType type) {
#ifdef _LP64
Expand Down Expand Up @@ -131,6 +146,14 @@ class arrayOopDesc : public oopDesc {
*length_addr_impl(mem) = length;
}

void set_slice_helper(int val) {
*slice_helper_addr() = val;
}

int get_slice_helper() {
return *slice_helper_addr();
}

// Return the maximum length of an array of BasicType. The length can be passed
// to typeArrayOop::object_size(scale, length, header_size) without causing an
// overflow. We also need to make sure that this will not overflow a size_t on
Expand Down

0 comments on commit c1922b1

Please sign in to comment.