Skip to content

Commit bd67ac6

Browse files
Scott GibbonsJatin Bhateja
authored andcommitted
8329331: Intrinsify Unsafe::setMemory
Reviewed-by: sviswanathan, jbhateja, kvn
1 parent 185e711 commit bd67ac6

36 files changed

+502
-87
lines changed

src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8379,7 +8379,7 @@ class StubGenerator: public StubCodeGenerator {
83798379

83808380
// Initialize table for copy memory (arraycopy) check.
83818381
if (UnsafeCopyMemory::_table == nullptr) {
8382-
UnsafeCopyMemory::create_table(8);
8382+
UnsafeCopyMemory::create_table(8 + 4); // 8 for copyMemory; 4 for setMemory
83838383
}
83848384

83858385
if (UseCRC32Intrinsics) {

src/hotspot/cpu/arm/stubGenerator_arm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -3135,7 +3135,7 @@ class StubGenerator: public StubCodeGenerator {
31353135
StubRoutines::_throw_StackOverflowError_entry = generate_throw_exception("StackOverflowError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_StackOverflowError));
31363136

31373137
if (UnsafeCopyMemory::_table == nullptr) {
3138-
UnsafeCopyMemory::create_table(32);
3138+
UnsafeCopyMemory::create_table(32 + 4); // 32 for copyMemory; 4 for setMemory
31393139
}
31403140

31413141
// integer division used both by interpreter and compiler

src/hotspot/cpu/ppc/stubGenerator_ppc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2012, 2023 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -4746,7 +4746,7 @@ class StubGenerator: public StubCodeGenerator {
47464746
StubRoutines::_catch_exception_entry = generate_catch_exception();
47474747

47484748
if (UnsafeCopyMemory::_table == nullptr) {
4749-
UnsafeCopyMemory::create_table(8);
4749+
UnsafeCopyMemory::create_table(8 + 4); // 8 for copyMemory; 4 for setMemory
47504750
}
47514751

47524752
// Build this early so it's available for the interpreter.

src/hotspot/cpu/riscv/stubGenerator_riscv.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2014, 2020, Red Hat Inc. All rights reserved.
44
* Copyright (c) 2020, 2023, Huawei Technologies Co., Ltd. All rights reserved.
55
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -5501,7 +5501,7 @@ static const int64_t right_3_bits = right_n_bits(3);
55015501
StubRoutines::_forward_exception_entry = generate_forward_exception();
55025502

55035503
if (UnsafeCopyMemory::_table == nullptr) {
5504-
UnsafeCopyMemory::create_table(8);
5504+
UnsafeCopyMemory::create_table(8 + 4); // 8 for copyMemory; 4 for setMemory
55055505
}
55065506

55075507
StubRoutines::_call_stub_entry =

src/hotspot/cpu/x86/assembler_x86.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,7 @@ address Assembler::locate_operand(address inst, WhichOperand which) {
934934
case 0x6F: // movdq
935935
case 0x7F: // movdq
936936
case 0xAE: // ldmxcsr, stmxcsr, fxrstor, fxsave, clflush
937+
case 0xD6: // movq
937938
case 0xFE: // paddd
938939
debug_only(has_disp32 = true);
939940
break;

src/hotspot/cpu/x86/macroAssembler_x86.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6299,7 +6299,7 @@ void MacroAssembler::generate_fill(BasicType t, bool aligned,
62996299
orl(value, rtmp);
63006300
}
63016301

6302-
cmpl(count, 2<<shift); // Short arrays (< 8 bytes) fill by element
6302+
cmpptr(count, 2<<shift); // Short arrays (< 8 bytes) fill by element
63036303
jcc(Assembler::below, L_fill_4_bytes); // use unsigned cmp
63046304
if (!UseUnalignedLoadStores && !aligned && (t == T_BYTE || t == T_SHORT)) {
63056305
Label L_skip_align2;
@@ -6319,13 +6319,13 @@ void MacroAssembler::generate_fill(BasicType t, bool aligned,
63196319
jccb(Assembler::zero, L_skip_align2);
63206320
movw(Address(to, 0), value);
63216321
addptr(to, 2);
6322-
subl(count, 1<<(shift-1));
6322+
subptr(count, 1<<(shift-1));
63236323
BIND(L_skip_align2);
63246324
}
63256325
if (UseSSE < 2) {
63266326
Label L_fill_32_bytes_loop, L_check_fill_8_bytes, L_fill_8_bytes_loop, L_fill_8_bytes;
63276327
// Fill 32-byte chunks
6328-
subl(count, 8 << shift);
6328+
subptr(count, 8 << shift);
63296329
jcc(Assembler::less, L_check_fill_8_bytes);
63306330
align(16);
63316331

@@ -6336,10 +6336,10 @@ void MacroAssembler::generate_fill(BasicType t, bool aligned,
63366336
}
63376337

63386338
addptr(to, 32);
6339-
subl(count, 8 << shift);
6339+
subptr(count, 8 << shift);
63406340
jcc(Assembler::greaterEqual, L_fill_32_bytes_loop);
63416341
BIND(L_check_fill_8_bytes);
6342-
addl(count, 8 << shift);
6342+
addptr(count, 8 << shift);
63436343
jccb(Assembler::zero, L_exit);
63446344
jmpb(L_fill_8_bytes);
63456345

@@ -6351,7 +6351,7 @@ void MacroAssembler::generate_fill(BasicType t, bool aligned,
63516351
movl(Address(to, 4), value);
63526352
addptr(to, 8);
63536353
BIND(L_fill_8_bytes);
6354-
subl(count, 1 << (shift + 1));
6354+
subptr(count, 1 << (shift + 1));
63556355
jcc(Assembler::greaterEqual, L_fill_8_bytes_loop);
63566356
// fall through to fill 4 bytes
63576357
} else {
@@ -6362,7 +6362,7 @@ void MacroAssembler::generate_fill(BasicType t, bool aligned,
63626362
jccb(Assembler::zero, L_fill_32_bytes);
63636363
movl(Address(to, 0), value);
63646364
addptr(to, 4);
6365-
subl(count, 1<<shift);
6365+
subptr(count, 1<<shift);
63666366
}
63676367
BIND(L_fill_32_bytes);
63686368
{
@@ -6376,19 +6376,19 @@ void MacroAssembler::generate_fill(BasicType t, bool aligned,
63766376
Label L_fill_64_bytes_loop_avx3, L_check_fill_64_bytes_avx2;
63776377

63786378
// If number of bytes to fill < VM_Version::avx3_threshold(), perform fill using AVX2
6379-
cmpl(count, VM_Version::avx3_threshold());
6379+
cmpptr(count, VM_Version::avx3_threshold());
63806380
jccb(Assembler::below, L_check_fill_64_bytes_avx2);
63816381

63826382
vpbroadcastd(xtmp, xtmp, Assembler::AVX_512bit);
63836383

6384-
subl(count, 16 << shift);
6384+
subptr(count, 16 << shift);
63856385
jccb(Assembler::less, L_check_fill_32_bytes);
63866386
align(16);
63876387

63886388
BIND(L_fill_64_bytes_loop_avx3);
63896389
evmovdqul(Address(to, 0), xtmp, Assembler::AVX_512bit);
63906390
addptr(to, 64);
6391-
subl(count, 16 << shift);
6391+
subptr(count, 16 << shift);
63926392
jcc(Assembler::greaterEqual, L_fill_64_bytes_loop_avx3);
63936393
jmpb(L_check_fill_32_bytes);
63946394

@@ -6398,23 +6398,23 @@ void MacroAssembler::generate_fill(BasicType t, bool aligned,
63986398
Label L_fill_64_bytes_loop;
63996399
vpbroadcastd(xtmp, xtmp, Assembler::AVX_256bit);
64006400

6401-
subl(count, 16 << shift);
6401+
subptr(count, 16 << shift);
64026402
jcc(Assembler::less, L_check_fill_32_bytes);
64036403
align(16);
64046404

64056405
BIND(L_fill_64_bytes_loop);
64066406
vmovdqu(Address(to, 0), xtmp);
64076407
vmovdqu(Address(to, 32), xtmp);
64086408
addptr(to, 64);
6409-
subl(count, 16 << shift);
6409+
subptr(count, 16 << shift);
64106410
jcc(Assembler::greaterEqual, L_fill_64_bytes_loop);
64116411

64126412
BIND(L_check_fill_32_bytes);
6413-
addl(count, 8 << shift);
6413+
addptr(count, 8 << shift);
64146414
jccb(Assembler::less, L_check_fill_8_bytes);
64156415
vmovdqu(Address(to, 0), xtmp);
64166416
addptr(to, 32);
6417-
subl(count, 8 << shift);
6417+
subptr(count, 8 << shift);
64186418

64196419
BIND(L_check_fill_8_bytes);
64206420
// clean upper bits of YMM registers
@@ -6424,7 +6424,7 @@ void MacroAssembler::generate_fill(BasicType t, bool aligned,
64246424
// Fill 32-byte chunks
64256425
pshufd(xtmp, xtmp, 0);
64266426

6427-
subl(count, 8 << shift);
6427+
subptr(count, 8 << shift);
64286428
jcc(Assembler::less, L_check_fill_8_bytes);
64296429
align(16);
64306430

@@ -6441,12 +6441,12 @@ void MacroAssembler::generate_fill(BasicType t, bool aligned,
64416441
}
64426442

64436443
addptr(to, 32);
6444-
subl(count, 8 << shift);
6444+
subptr(count, 8 << shift);
64456445
jcc(Assembler::greaterEqual, L_fill_32_bytes_loop);
64466446

64476447
BIND(L_check_fill_8_bytes);
64486448
}
6449-
addl(count, 8 << shift);
6449+
addptr(count, 8 << shift);
64506450
jccb(Assembler::zero, L_exit);
64516451
jmpb(L_fill_8_bytes);
64526452

@@ -6457,7 +6457,7 @@ void MacroAssembler::generate_fill(BasicType t, bool aligned,
64576457
movq(Address(to, 0), xtmp);
64586458
addptr(to, 8);
64596459
BIND(L_fill_8_bytes);
6460-
subl(count, 1 << (shift + 1));
6460+
subptr(count, 1 << (shift + 1));
64616461
jcc(Assembler::greaterEqual, L_fill_8_bytes_loop);
64626462
}
64636463
}

src/hotspot/cpu/x86/stubGenerator_x86_32.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -4122,7 +4122,7 @@ class StubGenerator: public StubCodeGenerator {
41224122

41234123
// Initialize table for copy memory (arraycopy) check.
41244124
if (UnsafeCopyMemory::_table == nullptr) {
4125-
UnsafeCopyMemory::create_table(16);
4125+
UnsafeCopyMemory::create_table(16 + 4); // 16 for copyMemory; 4 for setMemory
41264126
}
41274127

41284128
StubRoutines::x86::_verify_mxcsr_entry = generate_verify_mxcsr();

src/hotspot/cpu/x86/stubGenerator_x86_64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4058,7 +4058,7 @@ void StubGenerator::generate_initial_stubs() {
40584058

40594059
// Initialize table for unsafe copy memeory check.
40604060
if (UnsafeCopyMemory::_table == nullptr) {
4061-
UnsafeCopyMemory::create_table(16);
4061+
UnsafeCopyMemory::create_table(16 + 4); // 16 for copyMemory; 4 for setMemory
40624062
}
40634063

40644064
// entry points that exist in all platforms Note: This is code

src/hotspot/cpu/x86/stubGenerator_x86_64.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,14 @@ class StubGenerator: public StubCodeGenerator {
268268
address byte_copy_entry, address short_copy_entry,
269269
address int_copy_entry, address long_copy_entry);
270270

271+
// Generate 'unsafe' set memory stub
272+
// Though just as safe as the other stubs, it takes an unscaled
273+
// size_t argument instead of an element count.
274+
//
275+
// Examines the alignment of the operands and dispatches
276+
// to an int, short, or byte copy loop.
277+
address generate_unsafe_setmemory(const char *name, address byte_copy_entry);
278+
271279
// Perform range checks on the proposed arraycopy.
272280
// Kills temp, but nothing else.
273281
// Also, clean the sign bits of src_pos and dst_pos.

0 commit comments

Comments
 (0)