@@ -1775,7 +1775,7 @@ class ThawBase : public StackObj {
1775
1775
inline void before_thaw_java_frame(const frame& hf, const frame& caller, bool bottom, int num_frame);
1776
1776
inline void after_thaw_java_frame(const frame& f, bool bottom);
1777
1777
inline void patch(frame& f, const frame& caller, bool bottom);
1778
- void clear_bitmap_bits(intptr_t* start, int range );
1778
+ void clear_bitmap_bits(address start, address end );
1779
1779
1780
1780
NOINLINE void recurse_thaw_interpreted_frame(const frame& hf, frame& caller, int num_frames);
1781
1781
void recurse_thaw_compiled_frame(const frame& hf, frame& caller, int num_frames, bool stub_caller);
@@ -2166,13 +2166,22 @@ inline void ThawBase::patch(frame& f, const frame& caller, bool bottom) {
2166
2166
assert(!bottom || (_cont.is_empty() != Continuation::is_cont_barrier_frame(f)), "");
2167
2167
}
2168
2168
2169
- void ThawBase::clear_bitmap_bits(intptr_t* start, int range) {
2169
+ void ThawBase::clear_bitmap_bits(address start, address end) {
2170
+ assert(is_aligned(start, wordSize), "should be aligned: " PTR_FORMAT, p2i(start));
2171
+ assert(is_aligned(end, VMRegImpl::stack_slot_size), "should be aligned: " PTR_FORMAT, p2i(end));
2172
+
2170
2173
// we need to clear the bits that correspond to arguments as they reside in the caller frame
2171
- // or they will keep objects that are otherwise unreachable alive
2172
- log_develop_trace(continuations)("clearing bitmap for " INTPTR_FORMAT " - " INTPTR_FORMAT, p2i(start), p2i(start+range));
2174
+ // or they will keep objects that are otherwise unreachable alive.
2175
+
2176
+ // Align `end` if UseCompressedOops is not set to avoid UB when calculating the bit index, since
2177
+ // `end` could be at an odd number of stack slots from `start`, i.e might not be oop aligned.
2178
+ // If that's the case the bit range corresponding to the last stack slot should not have bits set
2179
+ // anyways and we assert that before returning.
2180
+ address effective_end = UseCompressedOops ? end : align_down(end, wordSize);
2181
+ log_develop_trace(continuations)("clearing bitmap for " INTPTR_FORMAT " - " INTPTR_FORMAT, p2i(start), p2i(effective_end));
2173
2182
stackChunkOop chunk = _cont.tail();
2174
- chunk->bitmap().clear_range(chunk->bit_index_for(start),
2175
- chunk->bit_index_for(start+range) );
2183
+ chunk->bitmap().clear_range(chunk->bit_index_for(start), chunk->bit_index_for(effective_end));
2184
+ assert(chunk->bitmap().count_one_bits(chunk->bit_index_for(effective_end), chunk->bit_index_for(end)) == 0, "bits should not be set" );
2176
2185
}
2177
2186
2178
2187
NOINLINE void ThawBase::recurse_thaw_interpreted_frame(const frame& hf, frame& caller, int num_frames) {
@@ -2225,7 +2234,9 @@ NOINLINE void ThawBase::recurse_thaw_interpreted_frame(const frame& hf, frame& c
2225
2234
_cont.tail()->fix_thawed_frame(caller, SmallRegisterMap::instance);
2226
2235
} else if (_cont.tail()->has_bitmap() && locals > 0) {
2227
2236
assert(hf.is_heap_frame(), "should be");
2228
- clear_bitmap_bits(heap_frame_bottom - locals, locals);
2237
+ address start = (address)(heap_frame_bottom - locals);
2238
+ address end = (address)heap_frame_bottom;
2239
+ clear_bitmap_bits(start, end);
2229
2240
}
2230
2241
2231
2242
DEBUG_ONLY(after_thaw_java_frame(f, is_bottom_frame);)
@@ -2298,7 +2309,10 @@ void ThawBase::recurse_thaw_compiled_frame(const frame& hf, frame& caller, int n
2298
2309
// can only fix caller once this frame is thawed (due to callee saved regs); this happens on the stack
2299
2310
_cont.tail()->fix_thawed_frame(caller, SmallRegisterMap::instance);
2300
2311
} else if (_cont.tail()->has_bitmap() && added_argsize > 0) {
2301
- clear_bitmap_bits(heap_frame_top + ContinuationHelper::CompiledFrame::size(hf) + frame::metadata_words_at_top, added_argsize);
2312
+ address start = (address)(heap_frame_top + ContinuationHelper::CompiledFrame::size(hf) + frame::metadata_words_at_top);
2313
+ int stack_args_slots = f.cb()->as_compiled_method()->method()->num_stack_arg_slots(false /* rounded */);
2314
+ int argsize_in_bytes = stack_args_slots * VMRegImpl::stack_slot_size;
2315
+ clear_bitmap_bits(start, start + argsize_in_bytes);
2302
2316
}
2303
2317
2304
2318
DEBUG_ONLY(after_thaw_java_frame(f, is_bottom_frame);)
0 commit comments