Skip to content

Commit

Permalink
Merge branch 'upstream-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Datadog Syncup Service committed Aug 9, 2024
2 parents 663df42 + 069e0ea commit 18f392f
Show file tree
Hide file tree
Showing 70 changed files with 982 additions and 212 deletions.
5 changes: 5 additions & 0 deletions make/common/native/Link.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ define CreateStaticLibrary
$(if $$($1_LINK_OBJS_RELATIVE), $$(CD) $$(OUTPUTDIR) ; ) \
$$($1_LD) $(LDFLAGS_CXX_PARTIAL_LINKING) $$($1_SYSROOT_LDFLAGS) \
-o $$($1_TARGET_RELOCATABLE) $$($1_LD_OBJ_ARG))
# 'ld -r' might invalidate the .llvm_addrsig section, and this will cause subsequent
# calls to lld (with '-Wl,--icf=safe') to fail when linking with this library, so
# remove that section.
$$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_objcopy_remove_llvm_addrsig_section, \
$$($1_OBJCOPY) --remove-section=.llvm_addrsig $$($1_TARGET_RELOCATABLE))
endif
$$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_run_ar, \
$(if $$($1_LINK_OBJS_RELATIVE), $$(CD) $$(OUTPUTDIR) ; ) \
Expand Down
13 changes: 13 additions & 0 deletions src/hotspot/cpu/riscv/assembler_riscv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,19 @@ enum Nf {

#undef INSN

#define INSN(NAME, op, width, umop, mop, mew, nf) \
void NAME(VectorRegister Vd_or_Vs3, Register Rs1, VectorMask vm = unmasked) { \
patch_VLdSt(op, Vd_or_Vs3, width, Rs1, umop, vm, mop, mew, nf); \
}

// Vector Unit-Stride Segment Load Instructions
INSN(vlseg3e8_v, 0b0000111, 0b000, 0b00000, 0b00, 0b0, g3);

// Vector Unit-Stride Segment Store Instructions
INSN(vsseg4e8_v, 0b0100111, 0b000, 0b00000, 0b00, 0b0, g4);

#undef INSN

#define INSN(NAME, op, width, mop, mew) \
void NAME(VectorRegister Vd, Register Rs1, VectorRegister Vs2, VectorMask vm = unmasked, Nf nf = g1) { \
patch_VLdSt(op, Vd, width, Rs1, Vs2->raw_encoding(), vm, mop, mew, nf); \
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/riscv/c1_LIRAssembler_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ void LIR_Assembler::const2mem(LIR_Opr src, LIR_Opr dest, BasicType type, CodeEmi
insn = &MacroAssembler::sw; break;
case T_OBJECT: // fall through
case T_ARRAY:
assert(c->as_jobject() == 0, "should be");
assert(c->as_jobject() == nullptr, "should be");
if (UseCompressedOops && !wide) {
insn = &MacroAssembler::sw;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/riscv/c1_Runtime1_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1066,4 +1066,4 @@ OopMapSet* Runtime1::generate_code_for(StubID id, StubAssembler* sasm) {

#undef __

const char *Runtime1::pd_name_for_address(address entry) { Unimplemented(); return 0; }
const char *Runtime1::pd_name_for_address(address entry) { Unimplemented(); }
2 changes: 1 addition & 1 deletion src/hotspot/cpu/riscv/frame_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void frame::patch_pc(Thread* thread, address pc) {

// Either the return address is the original one or we are going to
// patch in the same address that's already there.
assert(_pc == pc_old || pc == pc_old || pc_old == 0, "must be");
assert(_pc == pc_old || pc == pc_old || pc_old == nullptr, "must be");
DEBUG_ONLY(address old_pc = _pc;)
*pc_addr = pc;
_pc = pc; // must be set before call to get_deopt_original_pc
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/cpu/riscv/nativeInst_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ address NativeJump::jump_destination() const {
// load

// return -1 if jump to self or to 0
if ((dest == (address) this) || dest == 0) {
if ((dest == (address) this) || dest == nullptr) {
dest = (address) -1;
}

Expand Down Expand Up @@ -714,7 +714,7 @@ address NativeGeneralJump::jump_destination() const {
// a general jump

// return -1 if jump to self or to 0
if ((dest == (address) this) || dest == 0) {
if ((dest == (address) this) || dest == nullptr) {
dest = (address) -1;
}

Expand Down
223 changes: 223 additions & 0 deletions src/hotspot/cpu/riscv/stubGenerator_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5103,6 +5103,225 @@ class StubGenerator: public StubCodeGenerator {
return (address) start;
}

/**
* vector registers:
* input VectorRegister's: intputV1-V3, for m2 they could be v2, v4, v6, for m1 they could be v1, v2, v3
* index VectorRegister's: idxV1-V4, for m2 they could be v8, v10, v12, v14, for m1 they could be v4, v5, v6, v7
* output VectorRegister's: outputV1-V4, for m2 they could be v16, v18, v20, v22, for m1 they could be v8, v9, v10, v11
*
* NOTE: each field will occupy a vector register group
*/
void base64_vector_encode_round(Register src, Register dst, Register codec,
Register size, Register stepSrc, Register stepDst,
VectorRegister inputV1, VectorRegister inputV2, VectorRegister inputV3,
VectorRegister idxV1, VectorRegister idxV2, VectorRegister idxV3, VectorRegister idxV4,
VectorRegister outputV1, VectorRegister outputV2, VectorRegister outputV3, VectorRegister outputV4,
Assembler::LMUL lmul) {
// set vector register type/len
__ vsetvli(x0, size, Assembler::e8, lmul);

// segmented load src into v registers: mem(src) => vr(3)
__ vlseg3e8_v(inputV1, src);

// src = src + register_group_len_bytes * 3
__ add(src, src, stepSrc);

// encoding
// 1. compute index into lookup table: vr(3) => vr(4)
__ vsrl_vi(idxV1, inputV1, 2);

__ vsrl_vi(idxV2, inputV2, 2);
__ vsll_vi(inputV1, inputV1, 6);
__ vor_vv(idxV2, idxV2, inputV1);
__ vsrl_vi(idxV2, idxV2, 2);

__ vsrl_vi(idxV3, inputV3, 4);
__ vsll_vi(inputV2, inputV2, 4);
__ vor_vv(idxV3, inputV2, idxV3);
__ vsrl_vi(idxV3, idxV3, 2);

__ vsll_vi(idxV4, inputV3, 2);
__ vsrl_vi(idxV4, idxV4, 2);

// 2. indexed load: vr(4) => vr(4)
__ vluxei8_v(outputV1, codec, idxV1);
__ vluxei8_v(outputV2, codec, idxV2);
__ vluxei8_v(outputV3, codec, idxV3);
__ vluxei8_v(outputV4, codec, idxV4);

// segmented store encoded data in v registers back to dst: vr(4) => mem(dst)
__ vsseg4e8_v(outputV1, dst);

// dst = dst + register_group_len_bytes * 4
__ add(dst, dst, stepDst);
}

/**
* void j.u.Base64.Encoder.encodeBlock(byte[] src, int sp, int sl, byte[] dst, int dp, boolean isURL)
*
* Input arguments:
* c_rarg0 - src, source array
* c_rarg1 - sp, src start offset
* c_rarg2 - sl, src end offset
* c_rarg3 - dst, dest array
* c_rarg4 - dp, dst start offset
* c_rarg5 - isURL, Base64 or URL character set
*/
address generate_base64_encodeBlock() {
alignas(64) static const char toBase64[64] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
};

alignas(64) static const char toBase64URL[64] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_'
};

__ align(CodeEntryAlignment);
StubCodeMark mark(this, "StubRoutines", "encodeBlock");
address start = __ pc();
__ enter();

Register src = c_rarg0;
Register soff = c_rarg1;
Register send = c_rarg2;
Register dst = c_rarg3;
Register doff = c_rarg4;
Register isURL = c_rarg5;

Register codec = c_rarg6;
Register length = c_rarg7; // total length of src data in bytes

Label ProcessData, Exit;

// length should be multiple of 3
__ sub(length, send, soff);
// real src/dst to process data
__ add(src, src, soff);
__ add(dst, dst, doff);

// load the codec base address
__ la(codec, ExternalAddress((address) toBase64));
__ beqz(isURL, ProcessData);
__ la(codec, ExternalAddress((address) toBase64URL));
__ BIND(ProcessData);

// vector version
if (UseRVV) {
Label ProcessM2, ProcessM1, ProcessScalar;

Register size = soff;
Register stepSrcM1 = send;
Register stepSrcM2 = doff;
Register stepDst = isURL;

__ mv(size, MaxVectorSize * 2);
__ mv(stepSrcM1, MaxVectorSize * 3);
__ slli(stepSrcM2, stepSrcM1, 1);
__ mv(stepDst, MaxVectorSize * 2 * 4);

__ blt(length, stepSrcM2, ProcessM1);

__ BIND(ProcessM2);
base64_vector_encode_round(src, dst, codec,
size, stepSrcM2, stepDst,
v2, v4, v6, // inputs
v8, v10, v12, v14, // indexes
v16, v18, v20, v22, // outputs
Assembler::m2);

__ sub(length, length, stepSrcM2);
__ bge(length, stepSrcM2, ProcessM2);

__ BIND(ProcessM1);
__ blt(length, stepSrcM1, ProcessScalar);

__ srli(size, size, 1);
__ srli(stepDst, stepDst, 1);
base64_vector_encode_round(src, dst, codec,
size, stepSrcM1, stepDst,
v1, v2, v3, // inputs
v4, v5, v6, v7, // indexes
v8, v9, v10, v11, // outputs
Assembler::m1);
__ sub(length, length, stepSrcM1);

__ BIND(ProcessScalar);
}

// scalar version
{
Register byte1 = soff, byte0 = send, byte2 = doff;
Register combined24Bits = isURL;

__ beqz(length, Exit);

Label ScalarLoop;
__ BIND(ScalarLoop);
{
// plain: [byte0[7:0] : byte1[7:0] : byte2[7:0]] =>
// encoded: [byte0[7:2] : byte0[1:0]+byte1[7:4] : byte1[3:0]+byte2[7:6] : byte2[5:0]]

// load 3 bytes src data
__ lbu(byte0, Address(src, 0));
__ lbu(byte1, Address(src, 1));
__ lbu(byte2, Address(src, 2));
__ addi(src, src, 3);

// construct 24 bits from 3 bytes
__ slliw(byte0, byte0, 16);
__ slliw(byte1, byte1, 8);
__ orr(combined24Bits, byte0, byte1);
__ orr(combined24Bits, combined24Bits, byte2);

// get codec index and encode(ie. load from codec by index)
__ slliw(byte0, combined24Bits, 8);
__ srliw(byte0, byte0, 26);
__ add(byte0, codec, byte0);
__ lbu(byte0, byte0);

__ slliw(byte1, combined24Bits, 14);
__ srliw(byte1, byte1, 26);
__ add(byte1, codec, byte1);
__ lbu(byte1, byte1);

__ slliw(byte2, combined24Bits, 20);
__ srliw(byte2, byte2, 26);
__ add(byte2, codec, byte2);
__ lbu(byte2, byte2);

__ andi(combined24Bits, combined24Bits, 0x3f);
__ add(combined24Bits, codec, combined24Bits);
__ lbu(combined24Bits, combined24Bits);

// store 4 bytes encoded data
__ sb(byte0, Address(dst, 0));
__ sb(byte1, Address(dst, 1));
__ sb(byte2, Address(dst, 2));
__ sb(combined24Bits, Address(dst, 3));

__ sub(length, length, 3);
__ addi(dst, dst, 4);
// loop back
__ bnez(length, ScalarLoop);
}
}

__ BIND(Exit);

__ leave();
__ ret();

return (address) start;
}

void adler32_process_bytes(Register buff, Register s1, Register s2, VectorRegister vtable,
VectorRegister vzero, VectorRegister vbytes, VectorRegister vs1acc, VectorRegister vs2acc,
Register temp0, Register temp1, Register temp2, Register temp3,
Expand Down Expand Up @@ -5996,6 +6215,10 @@ static const int64_t right_3_bits = right_n_bits(3);
StubRoutines::_sha1_implCompressMB = generate_sha1_implCompress(true, "sha1_implCompressMB");
}

if (UseBASE64Intrinsics) {
StubRoutines::_base64_encodeBlock = generate_base64_encodeBlock();
}

if (UseAdler32Intrinsics) {
StubRoutines::_updateBytesAdler32 = generate_updateBytesAdler32();
}
Expand Down
5 changes: 5 additions & 0 deletions src/hotspot/cpu/riscv/vm_version_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ void VM_Version::c2_initialize() {
// as there are extra checks inside it which could disable UseRVV
// in some situations.

// Base64
if (FLAG_IS_DEFAULT(UseBASE64Intrinsics)) {
FLAG_SET_DEFAULT(UseBASE64Intrinsics, true);
}

if (FLAG_IS_DEFAULT(UseVectorizedHashCodeIntrinsic)) {
FLAG_SET_DEFAULT(UseVectorizedHashCodeIntrinsic, true);
}
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/os/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3463,6 +3463,7 @@ static char* map_or_reserve_memory_aligned(size_t size, size_t alignment, int fi
}

assert(aligned_base != nullptr, "Did not manage to re-map after %d attempts?", max_attempts);
assert(aligned_base != nullptr, "Did not manage to re-map after %d attempts (size %zu, alignment %zu, file descriptor %d)", max_attempts, size, alignment, file_desc);

return aligned_base;
}
Expand Down
3 changes: 1 addition & 2 deletions src/hotspot/share/gc/serial/generation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ class Generation: public CHeapObj<mtGC> {

public:
// Performance Counter support
virtual void update_counters() = 0;
virtual CollectorCounters* counters() { return _gc_counters; }
CollectorCounters* counters() { return _gc_counters; }

GCMemoryManager* gc_manager() const {
assert(_gc_manager != nullptr, "not initialized yet");
Expand Down
6 changes: 2 additions & 4 deletions src/hotspot/share/gc/z/zAddress.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -93,9 +93,7 @@ static void initialize_check_oop_function() {
#ifdef CHECK_UNHANDLED_OOPS
if (ZVerifyOops) {
// Enable extra verification of usages of oops in oopsHierarchy.hpp
check_oop_function = [](oopDesc* obj) {
(void)to_zaddress(obj);
};
check_oop_function = &check_is_valid_zaddress;
}
#endif
}
Expand Down
Loading

0 comments on commit 18f392f

Please sign in to comment.