Skip to content

Commit f8ca6f6

Browse files
committed
8381554: RISC-V: Small refactoring for cmp_klass_compressed macro-assembler routine
Reviewed-by: fyang, gcao, wenanjian
1 parent 4bb7204 commit f8ca6f6

4 files changed

Lines changed: 49 additions & 40 deletions

File tree

src/hotspot/cpu/riscv/c1_LIRAssembler_arraycopy_riscv.cpp

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -240,35 +240,6 @@ void LIR_Assembler::arraycopy_type_check(Register src, Register src_pos, Registe
240240
}
241241
}
242242

243-
void LIR_Assembler::arraycopy_assert(Register src, Register dst, Register tmp, ciArrayKlass *default_type, int flags) {
244-
assert(default_type != nullptr, "null default_type!");
245-
BasicType basic_type = default_type->element_type()->basic_type();
246-
if (basic_type == T_ARRAY) { basic_type = T_OBJECT; }
247-
if (basic_type != T_OBJECT || !(flags & LIR_OpArrayCopy::type_check)) {
248-
// Sanity check the known type with the incoming class. For the
249-
// primitive case the types must match exactly with src.klass and
250-
// dst.klass each exactly matching the default type. For the
251-
// object array case, if no type check is needed then either the
252-
// dst type is exactly the expected type and the src type is a
253-
// subtype which we can't check or src is the same array as dst
254-
// but not necessarily exactly of type default_type.
255-
Label known_ok, halt;
256-
__ mov_metadata(tmp, default_type->constant_encoding());
257-
__ encode_klass_not_null(tmp);
258-
259-
if (basic_type != T_OBJECT) {
260-
__ cmp_klass_compressed(dst, tmp, t0, halt, false);
261-
__ cmp_klass_compressed(src, tmp, t0, known_ok, true);
262-
} else {
263-
__ cmp_klass_compressed(dst, tmp, t0, known_ok, true);
264-
__ beq(src, dst, known_ok);
265-
}
266-
__ bind(halt);
267-
__ stop("incorrect type information in arraycopy");
268-
__ bind(known_ok);
269-
}
270-
}
271-
272243
void LIR_Assembler::emit_arraycopy(LIR_OpArrayCopy* op) {
273244
ciArrayKlass *default_type = op->expected_type();
274245
Register src = op->src()->as_register();
@@ -299,7 +270,28 @@ void LIR_Assembler::emit_arraycopy(LIR_OpArrayCopy* op) {
299270
}
300271

301272
#ifdef ASSERT
302-
arraycopy_assert(src, dst, tmp, default_type, flags);
273+
if (basic_type != T_OBJECT || !(flags & LIR_OpArrayCopy::type_check)) {
274+
// Sanity check the known type with the incoming class. For the
275+
// primitive case the types must match exactly with src.klass and
276+
// dst.klass each exactly matching the default type. For the
277+
// object array case, if no type check is needed then either the
278+
// dst type is exactly the expected type and the src type is a
279+
// subtype which we can't check or src is the same array as dst
280+
// but not necessarily exactly of type default_type.
281+
Label known_ok, halt;
282+
__ mov_metadata(tmp, default_type->constant_encoding());
283+
284+
if (basic_type != T_OBJECT) {
285+
__ cmp_klass_bne(dst, tmp, t0, t1, halt);
286+
__ cmp_klass_beq(src, tmp, t0, t1, known_ok);
287+
} else {
288+
__ cmp_klass_beq(dst, tmp, t0, t1, known_ok);
289+
__ beq(src, dst, known_ok);
290+
}
291+
__ bind(halt);
292+
__ stop("incorrect type information in arraycopy");
293+
__ bind(known_ok);
294+
}
303295
#endif
304296

305297
#ifndef PRODUCT

src/hotspot/cpu/riscv/c1_LIRAssembler_arraycopy_riscv.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2026, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2020, 2021, Huawei Technologies Co., Ltd. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -39,7 +39,6 @@
3939
void arraycopy_type_check(Register src, Register src_pos, Register length,
4040
Register dst, Register dst_pos, Register tmp,
4141
CodeStub *stub, BasicType basic_type, int flags);
42-
void arraycopy_assert(Register src, Register dst, Register tmp, ciArrayKlass *default_type, int flags);
4342
void arraycopy_prepare_params(Register src, Register src_pos, Register length,
4443
Register dst, Register dst_pos, BasicType basic_type);
4544
void arraycopy_checkcast_prepare_params(Register src, Register src_pos, Register length,

src/hotspot/cpu/riscv/macroAssembler_riscv.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3511,17 +3511,30 @@ void MacroAssembler::orptr(Address adr, RegisterOrConstant src, Register tmp1, R
35113511
sd(tmp1, adr);
35123512
}
35133513

3514-
void MacroAssembler::cmp_klass_compressed(Register oop, Register trial_klass, Register tmp, Label &L, bool equal) {
3514+
void MacroAssembler::cmp_klass_beq(Register obj, Register klass,
3515+
Register tmp1, Register tmp2,
3516+
Label &L, bool is_far) {
3517+
assert_different_registers(obj, klass, tmp1, tmp2);
35153518
if (UseCompactObjectHeaders) {
3516-
load_narrow_klass_compact(tmp, oop);
3519+
load_narrow_klass_compact(tmp1, obj);
35173520
} else {
3518-
lwu(tmp, Address(oop, oopDesc::klass_offset_in_bytes()));
3521+
lwu(tmp1, Address(obj, oopDesc::klass_offset_in_bytes()));
35193522
}
3520-
if (equal) {
3521-
beq(trial_klass, tmp, L);
3523+
decode_klass_not_null(tmp1, tmp2);
3524+
beq(klass, tmp1, L, is_far);
3525+
}
3526+
3527+
void MacroAssembler::cmp_klass_bne(Register obj, Register klass,
3528+
Register tmp1, Register tmp2,
3529+
Label &L, bool is_far) {
3530+
assert_different_registers(obj, klass, tmp1, tmp2);
3531+
if (UseCompactObjectHeaders) {
3532+
load_narrow_klass_compact(tmp1, obj);
35223533
} else {
3523-
bne(trial_klass, tmp, L);
3534+
lwu(tmp1, Address(obj, oopDesc::klass_offset_in_bytes()));
35243535
}
3536+
decode_klass_not_null(tmp1, tmp2);
3537+
bne(klass, tmp1, L, is_far);
35253538
}
35263539

35273540
// Move an oop into a register.

src/hotspot/cpu/riscv/macroAssembler_riscv.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2014, 2020, Red Hat Inc. All rights reserved.
44
* Copyright (c) 2020, 2024, Huawei Technologies Co., Ltd. All rights reserved.
55
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -198,7 +198,12 @@ class MacroAssembler: public Assembler {
198198
void load_klass(Register dst, Register src, Register tmp = t0);
199199
void load_narrow_klass_compact(Register dst, Register src);
200200
void store_klass(Register dst, Register src, Register tmp = t0);
201-
void cmp_klass_compressed(Register oop, Register trial_klass, Register tmp, Label &L, bool equal);
201+
void cmp_klass_beq(Register obj, Register klass,
202+
Register tmp1, Register tmp2,
203+
Label &L, bool is_far = false);
204+
void cmp_klass_bne(Register obj, Register klass,
205+
Register tmp1, Register tmp2,
206+
Label &L, bool is_far = false);
202207

203208
void encode_klass_not_null(Register r, Register tmp = t0);
204209
void decode_klass_not_null(Register r, Register tmp = t0);

0 commit comments

Comments
 (0)