Skip to content

Commit 34edc73

Browse files
Vladimir KozlovRealFYang
Vladimir Kozlov
andcommitted
8337396: Cleanup usage of ExternalAddess
Co-authored-by: Fei Yang <fyang@openjdk.org> Reviewed-by: vlivanov, adinn
1 parent 7deee74 commit 34edc73

10 files changed

+117
-35
lines changed

src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ void MacroAssembler::reserved_stack_check() {
736736
br(Assembler::LO, no_reserved_zone_enabling);
737737

738738
enter(); // LR and FP are live.
739-
lea(rscratch1, CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone));
739+
lea(rscratch1, RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone)));
740740
mov(c_rarg0, rthread);
741741
blr(rscratch1);
742742
leave();
@@ -1879,7 +1879,7 @@ void MacroAssembler::_verify_oop(Register reg, const char* s, const char* file,
18791879
movptr(rscratch1, (uintptr_t)(address)b);
18801880

18811881
// call indirectly to solve generation ordering problem
1882-
lea(rscratch2, ExternalAddress(StubRoutines::verify_oop_subroutine_entry_address()));
1882+
lea(rscratch2, RuntimeAddress(StubRoutines::verify_oop_subroutine_entry_address()));
18831883
ldr(rscratch2, Address(rscratch2));
18841884
blr(rscratch2);
18851885

@@ -1918,7 +1918,7 @@ void MacroAssembler::_verify_oop_addr(Address addr, const char* s, const char* f
19181918
movptr(rscratch1, (uintptr_t)(address)b);
19191919

19201920
// call indirectly to solve generation ordering problem
1921-
lea(rscratch2, ExternalAddress(StubRoutines::verify_oop_subroutine_entry_address()));
1921+
lea(rscratch2, RuntimeAddress(StubRoutines::verify_oop_subroutine_entry_address()));
19221922
ldr(rscratch2, Address(rscratch2));
19231923
blr(rscratch2);
19241924

@@ -6454,7 +6454,7 @@ void MacroAssembler::verify_cross_modify_fence_not_required() {
64546454
Label fence_not_required;
64556455
cbz(rscratch1, fence_not_required);
64566456
// If it does then fail.
6457-
lea(rscratch1, CAST_FROM_FN_PTR(address, JavaThread::verify_cross_modify_fence_failure));
6457+
lea(rscratch1, RuntimeAddress(CAST_FROM_FN_PTR(address, JavaThread::verify_cross_modify_fence_failure)));
64586458
mov(c_rarg0, rthread);
64596459
blr(rscratch1);
64606460
bind(fence_not_required);

src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7045,7 +7045,7 @@ class StubGenerator: public StubCodeGenerator {
70457045
Label thaw_success;
70467046
// rscratch2 contains the size of the frames to thaw, 0 if overflow or no more frames
70477047
__ cbnz(rscratch2, thaw_success);
7048-
__ lea(rscratch1, ExternalAddress(StubRoutines::throw_StackOverflowError_entry()));
7048+
__ lea(rscratch1, RuntimeAddress(StubRoutines::throw_StackOverflowError_entry()));
70497049
__ br(rscratch1);
70507050
__ bind(thaw_success);
70517051

src/hotspot/cpu/aarch64/templateInterpreterGenerator_aarch64.cpp

Lines changed: 6 additions & 6 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
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -1337,8 +1337,8 @@ address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
13371337
{
13381338
Label L;
13391339
__ ldr(r10, Address(rmethod, Method::native_function_offset()));
1340-
address unsatisfied = (SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
1341-
__ mov(rscratch2, unsatisfied);
1340+
ExternalAddress unsatisfied(SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
1341+
__ lea(rscratch2, unsatisfied);
13421342
__ ldr(rscratch2, rscratch2);
13431343
__ cmp(r10, rscratch2);
13441344
__ br(Assembler::NE, L);
@@ -1432,7 +1432,7 @@ address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
14321432
// hand.
14331433
//
14341434
__ mov(c_rarg0, rthread);
1435-
__ mov(rscratch2, CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans));
1435+
__ lea(rscratch2, RuntimeAddress(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans)));
14361436
__ blr(rscratch2);
14371437
__ get_method(rmethod);
14381438
__ reinit_heapbase();
@@ -1482,7 +1482,7 @@ address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
14821482

14831483
__ push_call_clobbered_registers();
14841484
__ mov(c_rarg0, rthread);
1485-
__ mov(rscratch2, CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages));
1485+
__ lea(rscratch2, RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages)));
14861486
__ blr(rscratch2);
14871487
__ pop_call_clobbered_registers();
14881488

@@ -2085,7 +2085,7 @@ void TemplateInterpreterGenerator::trace_bytecode(Template* t) {
20852085

20862086
assert(Interpreter::trace_code(t->tos_in()) != nullptr,
20872087
"entry must have been generated");
2088-
__ bl(Interpreter::trace_code(t->tos_in()));
2088+
__ bl(RuntimeAddress(Interpreter::trace_code(t->tos_in())));
20892089
__ reinit_heapbase();
20902090
}
20912091

src/hotspot/cpu/riscv/macroAssembler_riscv.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ void MacroAssembler::_verify_oop(Register reg, const char* s, const char* file,
547547
}
548548

549549
// call indirectly to solve generation ordering problem
550-
ExternalAddress target(StubRoutines::verify_oop_subroutine_entry_address());
550+
RuntimeAddress target(StubRoutines::verify_oop_subroutine_entry_address());
551551
relocate(target.rspec(), [&] {
552552
int32_t offset;
553553
la(t1, target.target(), offset);
@@ -592,7 +592,7 @@ void MacroAssembler::_verify_oop_addr(Address addr, const char* s, const char* f
592592
}
593593

594594
// call indirectly to solve generation ordering problem
595-
ExternalAddress target(StubRoutines::verify_oop_subroutine_entry_address());
595+
RuntimeAddress target(StubRoutines::verify_oop_subroutine_entry_address());
596596
relocate(target.rspec(), [&] {
597597
int32_t offset;
598598
la(t1, target.target(), offset);

src/hotspot/cpu/riscv/stubGenerator_riscv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3774,7 +3774,7 @@ class StubGenerator: public StubCodeGenerator {
37743774
Label thaw_success;
37753775
// t1 contains the size of the frames to thaw, 0 if overflow or no more frames
37763776
__ bnez(t1, thaw_success);
3777-
__ la(t0, ExternalAddress(StubRoutines::throw_StackOverflowError_entry()));
3777+
__ la(t0, RuntimeAddress(StubRoutines::throw_StackOverflowError_entry()));
37783778
__ jr(t0);
37793779
__ bind(thaw_success);
37803780

src/hotspot/cpu/riscv/templateInterpreterGenerator_riscv.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,8 +1111,8 @@ address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
11111111
{
11121112
Label L;
11131113
__ ld(x28, Address(xmethod, Method::native_function_offset()));
1114-
address unsatisfied = (SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
1115-
__ mv(t, unsatisfied);
1114+
ExternalAddress unsatisfied(SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
1115+
__ la(t, unsatisfied);
11161116
__ load_long_misaligned(t1, Address(t, 0), t0, 2); // 2 bytes aligned, but not 4 or 8
11171117

11181118
__ bne(x28, t1, L);
@@ -1815,7 +1815,7 @@ void TemplateInterpreterGenerator::trace_bytecode(Template* t) {
18151815
// the tosca in-state for the given template.
18161816

18171817
assert(Interpreter::trace_code(t->tos_in()) != nullptr, "entry must have been generated");
1818-
__ call(Interpreter::trace_code(t->tos_in()));
1818+
__ rt_call(Interpreter::trace_code(t->tos_in()));
18191819
__ reinit_heapbase();
18201820
}
18211821

src/hotspot/cpu/x86/stubGenerator_x86_64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3702,7 +3702,7 @@ address StubGenerator::generate_cont_thaw(const char* label, Continuation::thaw_
37023702
Label L_thaw_success;
37033703
__ testptr(rbx, rbx);
37043704
__ jccb(Assembler::notZero, L_thaw_success);
3705-
__ jump(ExternalAddress(StubRoutines::throw_StackOverflowError_entry()));
3705+
__ jump(RuntimeAddress(StubRoutines::throw_StackOverflowError_entry()));
37063706
__ bind(L_thaw_success);
37073707

37083708
// Make room for the thawed frames and align the stack.

src/hotspot/cpu/x86/templateInterpreterGenerator_x86.cpp

Lines changed: 3 additions & 3 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
* 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
@@ -178,7 +178,7 @@ address TemplateInterpreterGenerator::generate_exception_handler_common(
178178
rarg, rarg2);
179179
}
180180
// throw exception
181-
__ jump(ExternalAddress(Interpreter::throw_exception_entry()));
181+
__ jump(RuntimeAddress(Interpreter::throw_exception_entry()));
182182
return entry;
183183
}
184184

@@ -546,7 +546,7 @@ void TemplateInterpreterGenerator::generate_stack_overflow_check(void) {
546546
// Note: the restored frame is not necessarily interpreted.
547547
// Use the shared runtime version of the StackOverflowError.
548548
assert(StubRoutines::throw_StackOverflowError_entry() != nullptr, "stub not yet generated");
549-
__ jump(ExternalAddress(StubRoutines::throw_StackOverflowError_entry()));
549+
__ jump(RuntimeAddress(StubRoutines::throw_StackOverflowError_entry()));
550550
// all done with frame size check
551551
__ bind(after_frame_check_pop);
552552
NOT_LP64(__ pop(rsi));

src/hotspot/cpu/x86/templateTable_x86.cpp

Lines changed: 9 additions & 9 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
* 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
@@ -774,7 +774,7 @@ void TemplateTable::index_check_without_pop(Register array, Register index) {
774774
__ jccb(Assembler::below, skip);
775775
// Pass array to create more detailed exceptions.
776776
__ mov(NOT_LP64(rax) LP64_ONLY(c_rarg1), array);
777-
__ jump(ExternalAddress(Interpreter::_throw_ArrayIndexOutOfBoundsException_entry));
777+
__ jump(RuntimeAddress(Interpreter::_throw_ArrayIndexOutOfBoundsException_entry));
778778
__ bind(skip);
779779
}
780780

@@ -1152,7 +1152,7 @@ void TemplateTable::aastore() {
11521152

11531153
// Come here on failure
11541154
// object is at TOS
1155-
__ jump(ExternalAddress(Interpreter::_throw_ArrayStoreException_entry));
1155+
__ jump(RuntimeAddress(Interpreter::_throw_ArrayStoreException_entry));
11561156

11571157
// Come here on success
11581158
__ bind(ok_is_subtype);
@@ -1432,7 +1432,7 @@ void TemplateTable::ldiv() {
14321432
// generate explicit div0 check
14331433
__ testq(rcx, rcx);
14341434
__ jump_cc(Assembler::zero,
1435-
ExternalAddress(Interpreter::_throw_ArithmeticException_entry));
1435+
RuntimeAddress(Interpreter::_throw_ArithmeticException_entry));
14361436
// Note: could xor rax and rcx and compare with (-1 ^ min_int). If
14371437
// they are not equal, one could do a normal division (no correction
14381438
// needed), which may speed up this implementation for the common case.
@@ -1445,7 +1445,7 @@ void TemplateTable::ldiv() {
14451445
// check if y = 0
14461446
__ orl(rax, rdx);
14471447
__ jump_cc(Assembler::zero,
1448-
ExternalAddress(Interpreter::_throw_ArithmeticException_entry));
1448+
RuntimeAddress(Interpreter::_throw_ArithmeticException_entry));
14491449
__ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::ldiv));
14501450
__ addptr(rsp, 4 * wordSize); // take off temporaries
14511451
#endif
@@ -1458,7 +1458,7 @@ void TemplateTable::lrem() {
14581458
__ pop_l(rax);
14591459
__ testq(rcx, rcx);
14601460
__ jump_cc(Assembler::zero,
1461-
ExternalAddress(Interpreter::_throw_ArithmeticException_entry));
1461+
RuntimeAddress(Interpreter::_throw_ArithmeticException_entry));
14621462
// Note: could xor rax and rcx and compare with (-1 ^ min_int). If
14631463
// they are not equal, one could do a normal division (no correction
14641464
// needed), which may speed up this implementation for the common case.
@@ -1472,7 +1472,7 @@ void TemplateTable::lrem() {
14721472
// check if y = 0
14731473
__ orl(rax, rdx);
14741474
__ jump_cc(Assembler::zero,
1475-
ExternalAddress(Interpreter::_throw_ArithmeticException_entry));
1475+
RuntimeAddress(Interpreter::_throw_ArithmeticException_entry));
14761476
__ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::lrem));
14771477
__ addptr(rsp, 4 * wordSize);
14781478
#endif
@@ -4222,7 +4222,7 @@ void TemplateTable::checkcast() {
42224222
// Come here on failure
42234223
__ push_ptr(rdx);
42244224
// object is at TOS
4225-
__ jump(ExternalAddress(Interpreter::_throw_ClassCastException_entry));
4225+
__ jump(RuntimeAddress(Interpreter::_throw_ClassCastException_entry));
42264226

42274227
// Come here on success
42284228
__ bind(ok_is_subtype);
@@ -4340,7 +4340,7 @@ void TemplateTable::_breakpoint() {
43404340
void TemplateTable::athrow() {
43414341
transition(atos, vtos);
43424342
__ null_check(rax);
4343-
__ jump(ExternalAddress(Interpreter::throw_exception_entry()));
4343+
__ jump(RuntimeAddress(Interpreter::throw_exception_entry()));
43444344
}
43454345

43464346
//-----------------------------------------------------------------------------

src/hotspot/share/code/oopRecorder.cpp

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "oops/oop.inline.hpp"
3333
#include "runtime/jniHandles.inline.hpp"
3434
#include "runtime/mutexLocker.hpp"
35+
#include "runtime/os.hpp"
3536
#include "utilities/copy.hpp"
3637

3738
#ifdef ASSERT
@@ -220,6 +221,11 @@ ExternalsRecorder* ExternalsRecorder::_recorder = nullptr;
220221

221222
ExternalsRecorder::ExternalsRecorder(): _arena(mtCode), _externals(&_arena) {}
222223

224+
#ifndef PRODUCT
225+
static int total_access_count = 0;
226+
static GrowableArray<int>* extern_hist = nullptr;
227+
#endif
228+
223229
void ExternalsRecorder_init() {
224230
ExternalsRecorder::initialize();
225231
}
@@ -228,30 +234,106 @@ void ExternalsRecorder::initialize() {
228234
// After Mutex and before CodeCache are initialized
229235
assert(_recorder == nullptr, "should initialize only once");
230236
_recorder = new ExternalsRecorder();
237+
#ifndef PRODUCT
238+
if (PrintNMethodStatistics) {
239+
Arena* arena = &_recorder->_arena;
240+
extern_hist = new(arena) GrowableArray<int>(arena, 512, 512, 0);
241+
}
242+
#endif
231243
}
232244

233245
int ExternalsRecorder::find_index(address adr) {
234-
MutexLocker ml(ExternalsRecorder_lock, Mutex::_no_safepoint_check_flag);
235246
assert(_recorder != nullptr, "sanity");
236-
return _recorder->_externals.find_index(adr);
247+
MutexLocker ml(ExternalsRecorder_lock, Mutex::_no_safepoint_check_flag);
248+
int index = _recorder->_externals.find_index(adr);
249+
#ifndef PRODUCT
250+
if (PrintNMethodStatistics) {
251+
total_access_count++;
252+
int n = extern_hist->at_grow(index, 0);
253+
extern_hist->at_put(index, (n + 1));
254+
}
255+
#endif
256+
return index;
237257
}
238258

239259
address ExternalsRecorder::at(int index) {
260+
assert(_recorder != nullptr, "sanity");
240261
// find_index() may resize array by reallocating it and freeing old,
241262
// we need loock here to make sure we not accessing to old freed array.
242263
MutexLocker ml(ExternalsRecorder_lock, Mutex::_no_safepoint_check_flag);
243-
assert(_recorder != nullptr, "sanity");
244264
return _recorder->_externals.at(index);
245265
}
246266

247267
int ExternalsRecorder::count() {
248-
MutexLocker ml(ExternalsRecorder_lock, Mutex::_no_safepoint_check_flag);
249268
assert(_recorder != nullptr, "sanity");
269+
MutexLocker ml(ExternalsRecorder_lock, Mutex::_no_safepoint_check_flag);
250270
return _recorder->_externals.count();
251271
}
252272

253273
#ifndef PRODUCT
274+
extern "C" {
275+
// Order from large to small values
276+
static int count_cmp(const void *i, const void *j) {
277+
int a = *(int*)i;
278+
int b = *(int*)j;
279+
return a < b ? 1 : a > b ? -1 : 0;
280+
}
281+
}
282+
254283
void ExternalsRecorder::print_statistics() {
255-
tty->print_cr("External addresses table: %d entries", count());
284+
int cnt = count();
285+
tty->print_cr("External addresses table: %d entries, %d accesses", cnt, total_access_count);
286+
{ // Print most accessed entries in the table.
287+
int* array = NEW_C_HEAP_ARRAY(int, (2 * cnt), mtCode);
288+
for (int i = 0; i < cnt; i++) {
289+
array[(2 * i) + 0] = extern_hist->at(i);
290+
array[(2 * i) + 1] = i;
291+
}
292+
// Reverse sort to have "hottest" addresses first.
293+
qsort(array, cnt, 2*sizeof(int), count_cmp);
294+
// Print all entries with Verbose flag otherwise only top 5.
295+
int limit = (Verbose || cnt <= 5) ? cnt : 5;
296+
int j = 0;
297+
for (int i = 0; i < limit; i++) {
298+
int index = array[(2 * i) + 1];
299+
int n = extern_hist->at(index);
300+
if (n > 0) {
301+
address addr = at(index);
302+
tty->print("%d: %8d " INTPTR_FORMAT " :", j++, n, p2i(addr));
303+
if (addr != nullptr) {
304+
if (StubRoutines::contains(addr)) {
305+
StubCodeDesc* desc = StubCodeDesc::desc_for(addr);
306+
if (desc == nullptr) {
307+
desc = StubCodeDesc::desc_for(addr + frame::pc_return_offset);
308+
}
309+
const char* stub_name = (desc != nullptr) ? desc->name() : "<unknown>";
310+
tty->print(" stub: %s", stub_name);
311+
} else {
312+
ResourceMark rm;
313+
const int buflen = 1024;
314+
char* buf = NEW_RESOURCE_ARRAY(char, buflen);
315+
int offset = 0;
316+
if (os::dll_address_to_function_name(addr, buf, buflen, &offset)) {
317+
tty->print(" extn: %s", buf);
318+
if (offset != 0) {
319+
tty->print("+%d", offset);
320+
}
321+
} else {
322+
if (CodeCache::contains((void*)addr)) {
323+
// Something in CodeCache
324+
tty->print(" in CodeCache");
325+
} else {
326+
// It could be string
327+
memcpy(buf, (char*)addr, 80);
328+
buf[80] = '\0';
329+
tty->print(" '%s'", buf);
330+
}
331+
}
332+
}
333+
}
334+
tty->cr();
335+
}
336+
}
337+
}
256338
}
257339
#endif

0 commit comments

Comments
 (0)