Skip to content

Commit ff12ff5

Browse files
committed
8340453: C2: Improve encoding of LoadNKlass for compact headers
Reviewed-by: rcastanedalo, mli
1 parent 1866c0c commit ff12ff5

File tree

9 files changed

+26
-42
lines changed

9 files changed

+26
-42
lines changed

src/hotspot/cpu/aarch64/aarch64.ad

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5755,10 +5755,6 @@ opclass memory(indirect, indIndexScaled, indIndexScaledI2L, indIndexI2L, indInde
57555755
indirectN, indIndexScaledN, indIndexScaledI2LN, indIndexI2LN, indIndexN, indOffIN, indOffLN, indirectX2P, indOffX2P);
57565756

57575757

5758-
opclass memory_noindex(indirect,
5759-
indOffI1, indOffL1,indOffI2, indOffL2, indOffI4, indOffL4, indOffI8, indOffL8,
5760-
indirectN, indOffIN, indOffLN, indirectX2P, indOffX2P);
5761-
57625758
// iRegIorL2I is used for src inputs in rules for 32 bit int (I)
57635759
// operations. it allows the src to be either an iRegI or a (ConvL2I
57645760
// iRegL). in the latter case the l2i normally planted for a ConvL2I
@@ -6695,16 +6691,21 @@ instruct loadNKlass(iRegNNoSp dst, memory4 mem)
66956691
ins_pipe(iload_reg_mem);
66966692
%}
66976693

6698-
instruct loadNKlassCompactHeaders(iRegNNoSp dst, memory_noindex mem)
6694+
instruct loadNKlassCompactHeaders(iRegNNoSp dst, memory4 mem)
66996695
%{
67006696
match(Set dst (LoadNKlass mem));
67016697
predicate(!needs_acquiring_load(n) && UseCompactObjectHeaders);
67026698

67036699
ins_cost(4 * INSN_COST);
6704-
format %{ "load_narrow_klass_compact $dst, $mem\t# compressed class ptr" %}
6700+
format %{
6701+
"ldrw $dst, $mem\t# compressed class ptr, shifted\n\t"
6702+
"lsrw $dst, $dst, markWord::klass_shift_at_offset"
6703+
%}
67056704
ins_encode %{
6706-
assert($mem$$index$$Register == noreg, "must not have indexed address");
6707-
__ load_narrow_klass_compact_c2($dst$$Register, $mem$$base$$Register, $mem$$disp);
6705+
// inlined aarch64_enc_ldrw
6706+
loadStore(masm, &MacroAssembler::ldrw, $dst$$Register, $mem->opcode(),
6707+
as_Register($mem$$base), $mem$$index, $mem$$scale, $mem$$disp, 4);
6708+
__ lsrw($dst$$Register, $dst$$Register, markWord::klass_shift_at_offset);
67086709
%}
67096710
ins_pipe(iload_reg_mem);
67106711
%}

src/hotspot/cpu/aarch64/c2_MacroAssembler_aarch64.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,12 +2690,3 @@ bool C2_MacroAssembler::in_scratch_emit_size() {
26902690
}
26912691
return MacroAssembler::in_scratch_emit_size();
26922692
}
2693-
2694-
void C2_MacroAssembler::load_narrow_klass_compact_c2(Register dst, Register obj, int disp) {
2695-
// Note: Don't clobber obj anywhere in that method!
2696-
2697-
// The incoming address is pointing into obj-start + klass_offset_in_bytes. We need to extract
2698-
// obj-start, so that we can load from the object's mark-word instead.
2699-
ldr(dst, Address(obj, disp - oopDesc::klass_offset_in_bytes()));
2700-
lsr(dst, dst, markWord::klass_shift);
2701-
}

src/hotspot/cpu/aarch64/c2_MacroAssembler_aarch64.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,4 @@
186186
void vector_signum_sve(FloatRegister dst, FloatRegister src, FloatRegister zero,
187187
FloatRegister one, FloatRegister vtmp, PRegister pgtmp, SIMD_RegVariant T);
188188

189-
void load_narrow_klass_compact_c2(Register dst, Register obj, int disp);
190-
191189
#endif // CPU_AARCH64_C2_MACROASSEMBLER_AARCH64_HPP

src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7073,13 +7073,3 @@ void C2_MacroAssembler::vector_saturating_op(int ideal_opc, BasicType elem_bt, X
70737073
vector_saturating_op(ideal_opc, elem_bt, dst, src1, src2, vlen_enc);
70747074
}
70757075
}
7076-
7077-
#ifdef _LP64
7078-
void C2_MacroAssembler::load_narrow_klass_compact_c2(Register dst, Address src) {
7079-
// The incoming address is pointing into obj-start + klass_offset_in_bytes. We need to extract
7080-
// obj-start, so that we can load from the object's mark-word instead. Usually the address
7081-
// comes as obj-start in obj and klass_offset_in_bytes in disp.
7082-
movq(dst, src.plus_disp(-oopDesc::klass_offset_in_bytes()));
7083-
shrq(dst, markWord::klass_shift);
7084-
}
7085-
#endif

src/hotspot/cpu/x86/c2_MacroAssembler_x86.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,4 @@
583583

584584
void select_from_two_vectors_evex(BasicType elem_bt, XMMRegister dst, XMMRegister src1, XMMRegister src2, int vlen_enc);
585585

586-
#ifdef _LP64
587-
void load_narrow_klass_compact_c2(Register dst, Address src);
588-
#endif
589-
590586
#endif // CPU_X86_C2_MACROASSEMBLER_X86_HPP

src/hotspot/cpu/x86/x86_64.ad

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4368,11 +4368,15 @@ instruct loadNKlassCompactHeaders(rRegN dst, memory mem, rFlagsReg cr)
43684368
match(Set dst (LoadNKlass mem));
43694369
effect(KILL cr);
43704370
ins_cost(125); // XXX
4371-
format %{ "load_narrow_klass_compact $dst, $mem\t# compressed klass ptr" %}
4371+
format %{
4372+
"movl $dst, $mem\t# compressed klass ptr, shifted\n\t"
4373+
"shrl $dst, markWord::klass_shift_at_offset"
4374+
%}
43724375
ins_encode %{
4373-
__ load_narrow_klass_compact_c2($dst$$Register, $mem$$Address);
4376+
__ movl($dst$$Register, $mem$$Address);
4377+
__ shrl($dst$$Register, markWord::klass_shift_at_offset);
43744378
%}
4375-
ins_pipe(pipe_slow); // XXX
4379+
ins_pipe(ialu_reg_mem); // XXX
43764380
%}
43774381

43784382
// Load Float

src/hotspot/share/oops/markWord.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ class markWord {
133133
// We store the (narrow) Klass* in the bits 43 to 64.
134134

135135
// These are for bit-precise extraction of the narrow Klass* from the 64-bit Markword
136+
static constexpr int klass_offset_in_bytes = 4;
136137
static constexpr int klass_shift = hash_shift + hash_bits;
138+
static constexpr int klass_shift_at_offset = klass_shift - klass_offset_in_bytes * BitsPerByte;
137139
static constexpr int klass_bits = 22;
138140
static constexpr uintptr_t klass_mask = right_n_bits(klass_bits);
139141
static constexpr uintptr_t klass_mask_in_place = klass_mask << klass_shift;

src/hotspot/share/oops/oop.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,8 @@ class oopDesc {
332332
#ifdef _LP64
333333
if (UseCompactObjectHeaders) {
334334
// NOTE: The only places where this is used with compact headers are the C2
335-
// compiler and JVMCI, and even there we don't use it to access the (narrow)Klass*
336-
// directly. It is used only as a placeholder to identify the special memory slice
337-
// containing Klass* info. This value could be any value that is not a valid
338-
// field offset. Use an offset halfway into the markWord, as the markWord is never
339-
// partially loaded from C2 and JVMCI.
340-
return mark_offset_in_bytes() + 4;
335+
// compiler and JVMCI.
336+
return mark_offset_in_bytes() + markWord::klass_offset_in_bytes;
341337
} else
342338
#endif
343339
{

src/hotspot/share/opto/memnode.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,12 @@ class LoadKlassNode : public LoadPNode {
541541

542542
//------------------------------LoadNKlassNode---------------------------------
543543
// Load a narrow Klass from an object.
544+
// With compact headers, the input address (adr) does not point at the exact
545+
// header position where the (narrow) class pointer is located, but into the
546+
// middle of the mark word (see oopDesc::klass_offset_in_bytes()). This node
547+
// implicitly shifts the loaded value (markWord::klass_shift_at_offset bits) to
548+
// extract the actual class pointer. C2's type system is agnostic on whether the
549+
// input address directly points into the class pointer.
544550
class LoadNKlassNode : public LoadNNode {
545551
public:
546552
LoadNKlassNode(Node *c, Node *mem, Node *adr, const TypePtr *at, const TypeNarrowKlass *tk, MemOrd mo)

0 commit comments

Comments
 (0)