Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.
/ jdk22 Public archive

Commit 01cb043

Browse files
committed
8320275: assert(_chunk->bitmap().at(index)) failed: Bit not set at index
Reviewed-by: dholmes Backport-of: e9e694f4ef7b080d7fe1ad5b2f2daa2fccd0456e
1 parent bb0e203 commit 01cb043

17 files changed

+72
-43
lines changed

src/hotspot/cpu/aarch64/sharedRuntime_aarch64.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ int SharedRuntime::java_calling_convention(const BasicType *sig_bt,
310310

311311
uint int_args = 0;
312312
uint fp_args = 0;
313-
uint stk_args = 0; // inc by 2 each time
313+
uint stk_args = 0;
314314

315315
for (int i = 0; i < total_args_passed; i++) {
316316
switch (sig_bt[i]) {
@@ -322,8 +322,9 @@ int SharedRuntime::java_calling_convention(const BasicType *sig_bt,
322322
if (int_args < Argument::n_int_register_parameters_j) {
323323
regs[i].set1(INT_ArgReg[int_args++]->as_VMReg());
324324
} else {
325+
stk_args = align_up(stk_args, 2);
325326
regs[i].set1(VMRegImpl::stack2reg(stk_args));
326-
stk_args += 2;
327+
stk_args += 1;
327328
}
328329
break;
329330
case T_VOID:
@@ -340,6 +341,7 @@ int SharedRuntime::java_calling_convention(const BasicType *sig_bt,
340341
if (int_args < Argument::n_int_register_parameters_j) {
341342
regs[i].set2(INT_ArgReg[int_args++]->as_VMReg());
342343
} else {
344+
stk_args = align_up(stk_args, 2);
343345
regs[i].set2(VMRegImpl::stack2reg(stk_args));
344346
stk_args += 2;
345347
}
@@ -348,15 +350,17 @@ int SharedRuntime::java_calling_convention(const BasicType *sig_bt,
348350
if (fp_args < Argument::n_float_register_parameters_j) {
349351
regs[i].set1(FP_ArgReg[fp_args++]->as_VMReg());
350352
} else {
353+
stk_args = align_up(stk_args, 2);
351354
regs[i].set1(VMRegImpl::stack2reg(stk_args));
352-
stk_args += 2;
355+
stk_args += 1;
353356
}
354357
break;
355358
case T_DOUBLE:
356359
assert((i + 1) < total_args_passed && sig_bt[i + 1] == T_VOID, "expecting half");
357360
if (fp_args < Argument::n_float_register_parameters_j) {
358361
regs[i].set2(FP_ArgReg[fp_args++]->as_VMReg());
359362
} else {
363+
stk_args = align_up(stk_args, 2);
360364
regs[i].set2(VMRegImpl::stack2reg(stk_args));
361365
stk_args += 2;
362366
}
@@ -367,7 +371,7 @@ int SharedRuntime::java_calling_convention(const BasicType *sig_bt,
367371
}
368372
}
369373

370-
return align_up(stk_args, 2);
374+
return stk_args;
371375
}
372376

373377
// Patch the callers callsite with entry to compiled code if it exists.

src/hotspot/cpu/arm/sharedRuntime_arm.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ int SharedRuntime::java_calling_convention(const BasicType *sig_bt,
441441
}
442442
}
443443

444-
if (slot & 1) slot++;
445444
return slot;
446445
}
447446

src/hotspot/cpu/ppc/sharedRuntime_ppc.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ int SharedRuntime::java_calling_convention(const BasicType *sig_bt,
734734
ShouldNotReachHere();
735735
}
736736
}
737-
return align_up(stk, 2);
737+
return stk;
738738
}
739739

740740
#if defined(COMPILER1) || defined(COMPILER2)

src/hotspot/cpu/riscv/sharedRuntime_riscv.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ int SharedRuntime::java_calling_convention(const BasicType *sig_bt,
266266

267267
uint int_args = 0;
268268
uint fp_args = 0;
269-
uint stk_args = 0; // inc by 2 each time
269+
uint stk_args = 0;
270270

271271
for (int i = 0; i < total_args_passed; i++) {
272272
switch (sig_bt[i]) {
@@ -278,8 +278,9 @@ int SharedRuntime::java_calling_convention(const BasicType *sig_bt,
278278
if (int_args < Argument::n_int_register_parameters_j) {
279279
regs[i].set1(INT_ArgReg[int_args++]->as_VMReg());
280280
} else {
281+
stk_args = align_up(stk_args, 2);
281282
regs[i].set1(VMRegImpl::stack2reg(stk_args));
282-
stk_args += 2;
283+
stk_args += 1;
283284
}
284285
break;
285286
case T_VOID:
@@ -295,6 +296,7 @@ int SharedRuntime::java_calling_convention(const BasicType *sig_bt,
295296
if (int_args < Argument::n_int_register_parameters_j) {
296297
regs[i].set2(INT_ArgReg[int_args++]->as_VMReg());
297298
} else {
299+
stk_args = align_up(stk_args, 2);
298300
regs[i].set2(VMRegImpl::stack2reg(stk_args));
299301
stk_args += 2;
300302
}
@@ -303,15 +305,17 @@ int SharedRuntime::java_calling_convention(const BasicType *sig_bt,
303305
if (fp_args < Argument::n_float_register_parameters_j) {
304306
regs[i].set1(FP_ArgReg[fp_args++]->as_VMReg());
305307
} else {
308+
stk_args = align_up(stk_args, 2);
306309
regs[i].set1(VMRegImpl::stack2reg(stk_args));
307-
stk_args += 2;
310+
stk_args += 1;
308311
}
309312
break;
310313
case T_DOUBLE:
311314
assert((i + 1) < total_args_passed && sig_bt[i + 1] == T_VOID, "expecting half");
312315
if (fp_args < Argument::n_float_register_parameters_j) {
313316
regs[i].set2(FP_ArgReg[fp_args++]->as_VMReg());
314317
} else {
318+
stk_args = align_up(stk_args, 2);
315319
regs[i].set2(VMRegImpl::stack2reg(stk_args));
316320
stk_args += 2;
317321
}
@@ -321,7 +325,7 @@ int SharedRuntime::java_calling_convention(const BasicType *sig_bt,
321325
}
322326
}
323327

324-
return align_up(stk_args, 2);
328+
return stk_args;
325329
}
326330

327331
// Patch the callers callsite with entry to compiled code if it exists.

src/hotspot/cpu/s390/sharedRuntime_s390.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ int SharedRuntime::java_calling_convention(const BasicType *sig_bt,
755755
ShouldNotReachHere();
756756
}
757757
}
758-
return align_up(stk, 2);
758+
return stk;
759759
}
760760

761761
int SharedRuntime::c_calling_convention(const BasicType *sig_bt,

src/hotspot/cpu/x86/sharedRuntime_x86_32.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,7 @@ int SharedRuntime::java_calling_convention(const BasicType *sig_bt,
528528
}
529529
}
530530

531-
// return value can be odd number of VMRegImpl stack slots make multiple of 2
532-
return align_up(stack, 2);
531+
return stack;
533532
}
534533

535534
// Patch the callers callsite with entry to compiled code if it exists.

src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ int SharedRuntime::java_calling_convention(const BasicType *sig_bt,
498498

499499
uint int_args = 0;
500500
uint fp_args = 0;
501-
uint stk_args = 0; // inc by 2 each time
501+
uint stk_args = 0;
502502

503503
for (int i = 0; i < total_args_passed; i++) {
504504
switch (sig_bt[i]) {
@@ -510,8 +510,9 @@ int SharedRuntime::java_calling_convention(const BasicType *sig_bt,
510510
if (int_args < Argument::n_int_register_parameters_j) {
511511
regs[i].set1(INT_ArgReg[int_args++]->as_VMReg());
512512
} else {
513+
stk_args = align_up(stk_args, 2);
513514
regs[i].set1(VMRegImpl::stack2reg(stk_args));
514-
stk_args += 2;
515+
stk_args += 1;
515516
}
516517
break;
517518
case T_VOID:
@@ -528,6 +529,7 @@ int SharedRuntime::java_calling_convention(const BasicType *sig_bt,
528529
if (int_args < Argument::n_int_register_parameters_j) {
529530
regs[i].set2(INT_ArgReg[int_args++]->as_VMReg());
530531
} else {
532+
stk_args = align_up(stk_args, 2);
531533
regs[i].set2(VMRegImpl::stack2reg(stk_args));
532534
stk_args += 2;
533535
}
@@ -536,15 +538,17 @@ int SharedRuntime::java_calling_convention(const BasicType *sig_bt,
536538
if (fp_args < Argument::n_float_register_parameters_j) {
537539
regs[i].set1(FP_ArgReg[fp_args++]->as_VMReg());
538540
} else {
541+
stk_args = align_up(stk_args, 2);
539542
regs[i].set1(VMRegImpl::stack2reg(stk_args));
540-
stk_args += 2;
543+
stk_args += 1;
541544
}
542545
break;
543546
case T_DOUBLE:
544547
assert((i + 1) < total_args_passed && sig_bt[i + 1] == T_VOID, "expecting half");
545548
if (fp_args < Argument::n_float_register_parameters_j) {
546549
regs[i].set2(FP_ArgReg[fp_args++]->as_VMReg());
547550
} else {
551+
stk_args = align_up(stk_args, 2);
548552
regs[i].set2(VMRegImpl::stack2reg(stk_args));
549553
stk_args += 2;
550554
}
@@ -555,7 +559,7 @@ int SharedRuntime::java_calling_convention(const BasicType *sig_bt,
555559
}
556560
}
557561

558-
return align_up(stk_args, 2);
562+
return stk_args;
559563
}
560564

561565
// Patch the callers callsite with entry to compiled code if it exists.

src/hotspot/share/c1/c1_FrameMap.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ CallingConvention* FrameMap::java_calling_convention(const BasicTypeArray* signa
7272
}
7373
}
7474

75-
intptr_t out_preserve = SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs);
75+
intptr_t out_preserve = align_up(SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs), 2);
7676
LIR_OprList* args = new LIR_OprList(signature->length());
7777
for (i = 0; i < sizeargs;) {
7878
BasicType t = sig_bt[i];

src/hotspot/share/code/nmethod.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3017,7 +3017,7 @@ void nmethod::print_nmethod_labels(outputStream* stream, address block_begin, bo
30173017
assert(sig_index == sizeargs, "");
30183018
}
30193019
const char* spname = "sp"; // make arch-specific?
3020-
intptr_t out_preserve = SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs);
3020+
SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs);
30213021
int stack_slot_offset = this->frame_size() * wordSize;
30223022
int tab1 = 14, tab2 = 24;
30233023
int sig_index = 0;

src/hotspot/share/oops/method.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,8 @@ class Method : public Metadata {
395395
void remove_unshareable_flags() NOT_CDS_RETURN;
396396

397397
// the number of argument reg slots that the compiled method uses on the stack.
398-
int num_stack_arg_slots() const { return constMethod()->num_stack_arg_slots(); }
398+
int num_stack_arg_slots(bool rounded = true) const {
399+
return rounded ? align_up(constMethod()->num_stack_arg_slots(), 2) : constMethod()->num_stack_arg_slots(); }
399400

400401
virtual void metaspace_pointers_do(MetaspaceClosure* iter);
401402
virtual MetaspaceObj::Type type() const { return MethodType; }

src/hotspot/share/oops/stackChunkOop.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class stackChunkOopDesc : public instanceOopDesc {
155155

156156
inline void* gc_data() const;
157157
inline BitMapView bitmap() const;
158-
inline BitMap::idx_t bit_index_for(intptr_t* p) const;
158+
inline BitMap::idx_t bit_index_for(address p) const;
159159
inline intptr_t* address_for_bit(BitMap::idx_t index) const;
160160
template <typename OopT> inline BitMap::idx_t bit_index_for(OopT* p) const;
161161
template <typename OopT> inline OopT* address_for_bit(BitMap::idx_t index) const;

src/hotspot/share/oops/stackChunkOop.inline.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,13 @@ inline BitMapView stackChunkOopDesc::bitmap() const {
256256
return bitmap;
257257
}
258258

259-
inline BitMap::idx_t stackChunkOopDesc::bit_index_for(intptr_t* p) const {
259+
inline BitMap::idx_t stackChunkOopDesc::bit_index_for(address p) const {
260260
return UseCompressedOops ? bit_index_for((narrowOop*)p) : bit_index_for((oop*)p);
261261
}
262262

263263
template <typename OopT>
264264
inline BitMap::idx_t stackChunkOopDesc::bit_index_for(OopT* p) const {
265+
assert(is_aligned(p, alignof(OopT)), "should be aligned: " PTR_FORMAT, p2i(p));
265266
assert(p >= (OopT*)start_address(), "Address not in chunk");
266267
return p - (OopT*)start_address();
267268
}

src/hotspot/share/prims/foreignGlobals.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ int ForeignGlobals::compute_out_arg_bytes(const GrowableArray<VMStorage>& out_re
140140

141141
int ForeignGlobals::java_calling_convention(const BasicType* signature, int num_args, GrowableArray<VMStorage>& out_regs) {
142142
VMRegPair* vm_regs = NEW_RESOURCE_ARRAY(VMRegPair, num_args);
143-
int slots = SharedRuntime::java_calling_convention(signature, vm_regs, num_args);
143+
int slots = align_up(SharedRuntime::java_calling_convention(signature, vm_regs, num_args), 2);
144144
for (int i = 0; i < num_args; i++) {
145145
VMRegPair pair = vm_regs[i];
146146
// note, we ignore second here. Signature should consist of register-size values. So there should be

src/hotspot/share/runtime/continuationFreezeThaw.cpp

+22-8
Original file line numberDiff line numberDiff line change
@@ -1775,7 +1775,7 @@ class ThawBase : public StackObj {
17751775
inline void before_thaw_java_frame(const frame& hf, const frame& caller, bool bottom, int num_frame);
17761776
inline void after_thaw_java_frame(const frame& f, bool bottom);
17771777
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);
17791779

17801780
NOINLINE void recurse_thaw_interpreted_frame(const frame& hf, frame& caller, int num_frames);
17811781
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) {
21662166
assert(!bottom || (_cont.is_empty() != Continuation::is_cont_barrier_frame(f)), "");
21672167
}
21682168

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+
21702173
// 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));
21732182
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");
21762185
}
21772186

21782187
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
22252234
_cont.tail()->fix_thawed_frame(caller, SmallRegisterMap::instance);
22262235
} else if (_cont.tail()->has_bitmap() && locals > 0) {
22272236
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);
22292240
}
22302241

22312242
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
22982309
// can only fix caller once this frame is thawed (due to callee saved regs); this happens on the stack
22992310
_cont.tail()->fix_thawed_frame(caller, SmallRegisterMap::instance);
23002311
} 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);
23022316
}
23032317

23042318
DEBUG_ONLY(after_thaw_java_frame(f, is_bottom_frame);)

src/hotspot/share/runtime/frame.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,7 @@ void frame::describe(FrameValues& values, int frame_no, const RegisterMap* reg_m
14391439
assert(sig_index == sizeargs, "");
14401440
}
14411441
int stack_arg_slots = SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs);
1442-
assert(stack_arg_slots == m->num_stack_arg_slots(), "");
1442+
assert(stack_arg_slots == m->num_stack_arg_slots(false /* rounded */), "");
14431443
int out_preserve = SharedRuntime::out_preserve_stack_slots();
14441444
int sig_index = 0;
14451445
int arg_index = (m->is_static() ? 0 : -1);

src/hotspot/share/runtime/sharedRuntime.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2004,7 +2004,7 @@ void SharedRuntime::check_member_name_argument_is_last_argument(const methodHand
20042004
assert(member_arg_pos >= 0 && member_arg_pos < total_args_passed, "oob");
20052005
assert(sig_bt[member_arg_pos] == T_OBJECT, "dispatch argument must be an object");
20062006

2007-
int comp_args_on_stack = java_calling_convention(sig_bt, regs_without_member_name, total_args_passed - 1);
2007+
java_calling_convention(sig_bt, regs_without_member_name, total_args_passed - 1);
20082008

20092009
for (int i = 0; i < member_arg_pos; i++) {
20102010
VMReg a = regs_with_member_name[i].first();
@@ -3102,7 +3102,7 @@ void AdapterHandlerLibrary::create_native_wrapper(const methodHandle& method) {
31023102
BasicType ret_type = si.return_type();
31033103

31043104
// Now get the compiled-Java arguments layout.
3105-
int comp_args_on_stack = SharedRuntime::java_calling_convention(sig_bt, regs, total_args_passed);
3105+
SharedRuntime::java_calling_convention(sig_bt, regs, total_args_passed);
31063106

31073107
// Generate the compiled-to-native wrapper code
31083108
nm = SharedRuntime::generate_native_wrapper(&_masm, method, compile_id, sig_bt, regs, ret_type);

0 commit comments

Comments
 (0)