Skip to content

Commit

Permalink
8335946: DTrace code snippets should be generated when DTrace flags a…
Browse files Browse the repository at this point in the history
…re enabled
  • Loading branch information
kuaiwei committed Jul 9, 2024
1 parent 3f37c57 commit 1ec9889
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 114 deletions.
6 changes: 2 additions & 4 deletions src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1418,8 +1418,7 @@ void InterpreterMacroAssembler::notify_method_entry() {
bind(L);
}

{
SkipIfEqual skip(this, &DTraceMethodProbes, false);
if (DTraceMethodProbes) {
get_method(c_rarg1);
call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
rthread, c_rarg1);
Expand Down Expand Up @@ -1458,8 +1457,7 @@ void InterpreterMacroAssembler::notify_method_exit(
pop(state);
}

{
SkipIfEqual skip(this, &DTraceMethodProbes, false);
if (DTraceMethodProbes) {
push(state);
get_method(c_rarg1);
call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
Expand Down
71 changes: 33 additions & 38 deletions src/hotspot/cpu/aarch64/sharedRuntime_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1754,11 +1754,8 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
__ set_last_Java_frame(sp, noreg, native_return, rscratch1);

Label dtrace_method_entry, dtrace_method_entry_done;
{
uint64_t offset;
__ adrp(rscratch1, ExternalAddress((address)&DTraceMethodProbes), offset);
__ ldrb(rscratch1, Address(rscratch1, offset));
__ cbnzw(rscratch1, dtrace_method_entry);
if (DTraceMethodProbes) {
__ b(dtrace_method_entry);
__ bind(dtrace_method_entry_done);
}

Expand Down Expand Up @@ -1990,11 +1987,8 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
}

Label dtrace_method_exit, dtrace_method_exit_done;
{
uint64_t offset;
__ adrp(rscratch1, ExternalAddress((address)&DTraceMethodProbes), offset);
__ ldrb(rscratch1, Address(rscratch1, offset));
__ cbnzw(rscratch1, dtrace_method_exit);
if (DTraceMethodProbes) {
__ b(dtrace_method_exit);
__ bind(dtrace_method_exit_done);
}

Expand Down Expand Up @@ -2138,37 +2132,38 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
}

// SLOW PATH dtrace support
{
__ block_comment("dtrace entry {");
__ bind(dtrace_method_entry);

// We have all of the arguments setup at this point. We must not touch any register
// argument registers at this point (what if we save/restore them there are no oop?

save_args(masm, total_c_args, c_arg, out_regs);
__ mov_metadata(c_rarg1, method());
__ call_VM_leaf(
CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
rthread, c_rarg1);
restore_args(masm, total_c_args, c_arg, out_regs);
__ b(dtrace_method_entry_done);
__ block_comment("} dtrace entry");
}
if (DTraceMethodProbes) {
{
__ block_comment("dtrace entry {");
__ bind(dtrace_method_entry);

// We have all of the arguments setup at this point. We must not touch any register
// argument registers at this point (what if we save/restore them there are no oop?

save_args(masm, total_c_args, c_arg, out_regs);
__ mov_metadata(c_rarg1, method());
__ call_VM_leaf(
CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
rthread, c_rarg1);
restore_args(masm, total_c_args, c_arg, out_regs);
__ b(dtrace_method_entry_done);
__ block_comment("} dtrace entry");
}

{
__ block_comment("dtrace exit {");
__ bind(dtrace_method_exit);
save_native_result(masm, ret_type, stack_slots);
__ mov_metadata(c_rarg1, method());
__ call_VM_leaf(
CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
rthread, c_rarg1);
restore_native_result(masm, ret_type, stack_slots);
__ b(dtrace_method_exit_done);
__ block_comment("} dtrace exit");
{
__ block_comment("dtrace exit {");
__ bind(dtrace_method_exit);
save_native_result(masm, ret_type, stack_slots);
__ mov_metadata(c_rarg1, method());
__ call_VM_leaf(
CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
rthread, c_rarg1);
restore_native_result(masm, ret_type, stack_slots);
__ b(dtrace_method_exit_done);
__ block_comment("} dtrace exit");
}
}


__ flush();

nmethod *nm = nmethod::new_native_nmethod(method,
Expand Down
3 changes: 1 addition & 2 deletions src/hotspot/cpu/aarch64/templateTable_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3648,8 +3648,7 @@ void TemplateTable::_new() {
__ store_klass_gap(r0, zr); // zero klass gap for compressed oops
__ store_klass(r0, r4); // store klass last

{
SkipIfEqual skip(_masm, &DTraceAllocProbes, false);
if (DTraceAllocProbes) {
// Trigger dtrace event for fastpath
__ push(atos); // save the return value
__ call_VM_leaf(
Expand Down
9 changes: 5 additions & 4 deletions src/hotspot/cpu/ppc/templateTable_ppc_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3859,10 +3859,11 @@ void TemplateTable::_new() {
__ store_klass(RallocatedObject, RinstanceKlass, Rscratch); // klass (last for cms)

// Check and trigger dtrace event.
SkipIfEqualZero::skip_to_label_if_equal_zero(_masm, Rscratch, &DTraceAllocProbes, Ldone);
__ push(atos);
__ call_VM_leaf(CAST_FROM_FN_PTR(address, static_cast<int (*)(oopDesc*)>(SharedRuntime::dtrace_object_alloc)));
__ pop(atos);
if (DTraceAllocProbes) {
__ push(atos);
__ call_VM_leaf(CAST_FROM_FN_PTR(address, static_cast<int (*)(oopDesc*)>(SharedRuntime::dtrace_object_alloc)));
__ pop(atos);
}

__ b(Ldone);
}
Expand Down
6 changes: 2 additions & 4 deletions src/hotspot/cpu/riscv/interp_masm_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1467,8 +1467,7 @@ void InterpreterMacroAssembler::notify_method_entry() {
bind(L);
}

{
SkipIfEqual skip(this, &DTraceMethodProbes, false);
if (DTraceMethodProbes) {
get_method(c_rarg1);
call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
xthread, c_rarg1);
Expand Down Expand Up @@ -1506,8 +1505,7 @@ void InterpreterMacroAssembler::notify_method_exit(
pop(state);
}

{
SkipIfEqual skip(this, &DTraceMethodProbes, false);
if (DTraceMethodProbes) {
push(state);
get_method(c_rarg1);
call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
Expand Down
78 changes: 34 additions & 44 deletions src/hotspot/cpu/riscv/sharedRuntime_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1638,14 +1638,8 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
__ set_last_Java_frame(sp, noreg, native_return, t0);

Label dtrace_method_entry, dtrace_method_entry_done;
{
ExternalAddress target((address)&DTraceMethodProbes);
__ relocate(target.rspec(), [&] {
int32_t offset;
__ la(t0, target.target(), offset);
__ lbu(t0, Address(t0, offset));
});
__ bnez(t0, dtrace_method_entry);
if (DTraceMethodProbes) {
__ j(dtrace_method_entry);
__ bind(dtrace_method_entry_done);
}

Expand Down Expand Up @@ -1861,14 +1855,8 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
}

Label dtrace_method_exit, dtrace_method_exit_done;
{
ExternalAddress target((address)&DTraceMethodProbes);
__ relocate(target.rspec(), [&] {
int32_t offset;
__ la(t0, target.target(), offset);
__ lbu(t0, Address(t0, offset));
});
__ bnez(t0, dtrace_method_exit);
if (DTraceMethodProbes) {
__ j(dtrace_method_exit);
__ bind(dtrace_method_exit_done);
}

Expand Down Expand Up @@ -2009,34 +1997,36 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
}

// SLOW PATH dtrace support
{
__ block_comment("dtrace entry {");
__ bind(dtrace_method_entry);

// We have all of the arguments setup at this point. We must not touch any register
// argument registers at this point (what if we save/restore them there are no oop?

save_args(masm, total_c_args, c_arg, out_regs);
__ mov_metadata(c_rarg1, method());
__ call_VM_leaf(
CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
xthread, c_rarg1);
restore_args(masm, total_c_args, c_arg, out_regs);
__ j(dtrace_method_entry_done);
__ block_comment("} dtrace entry");
}

{
__ block_comment("dtrace exit {");
__ bind(dtrace_method_exit);
save_native_result(masm, ret_type, stack_slots);
__ mov_metadata(c_rarg1, method());
__ call_VM_leaf(
CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
xthread, c_rarg1);
restore_native_result(masm, ret_type, stack_slots);
__ j(dtrace_method_exit_done);
__ block_comment("} dtrace exit");
if (DTraceMethodProbes) {
{
__ block_comment("dtrace entry {");
__ bind(dtrace_method_entry);

// We have all of the arguments setup at this point. We must not touch any register
// argument registers at this point (what if we save/restore them there are no oop?

save_args(masm, total_c_args, c_arg, out_regs);
__ mov_metadata(c_rarg1, method());
__ call_VM_leaf(
CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
xthread, c_rarg1);
restore_args(masm, total_c_args, c_arg, out_regs);
__ j(dtrace_method_entry_done);
__ block_comment("} dtrace entry");
}

{
__ block_comment("dtrace exit {");
__ bind(dtrace_method_exit);
save_native_result(masm, ret_type, stack_slots);
__ mov_metadata(c_rarg1, method());
__ call_VM_leaf(
CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
xthread, c_rarg1);
restore_native_result(masm, ret_type, stack_slots);
__ j(dtrace_method_exit_done);
__ block_comment("} dtrace exit");
}
}

__ flush();
Expand Down
3 changes: 1 addition & 2 deletions src/hotspot/cpu/riscv/templateTable_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3592,8 +3592,7 @@ void TemplateTable::_new() {
__ store_klass_gap(x10, zr); // zero klass gap for compressed oops
__ store_klass(x10, x14); // store klass last

{
SkipIfEqual skip(_masm, &DTraceAllocProbes, false);
if (DTraceAllocProbes) {
// Trigger dtrace event for fastpath
__ push(atos); // save the return value
__ call_VM_leaf(CAST_FROM_FN_PTR(address, static_cast<int (*)(oopDesc*)>(SharedRuntime::dtrace_object_alloc)), x10);
Expand Down
3 changes: 1 addition & 2 deletions src/hotspot/cpu/s390/templateTable_s390.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3976,8 +3976,7 @@ void TemplateTable::_new() {
__ store_klass_gap(Rzero, RallocatedObject); // Zero klass gap for compressed oops.
__ store_klass(iklass, RallocatedObject); // Store klass last.

{
SkipIfEqual skip(_masm, &DTraceAllocProbes, false, Z_ARG5 /*scratch*/);
if (DTraceAllocProbes) {
// Trigger dtrace event for fastpath.
__ push(atos); // Save the return value.
__ call_VM_leaf(CAST_FROM_FN_PTR(address, static_cast<int (*)(oopDesc*)>(SharedRuntime::dtrace_object_alloc)), RallocatedObject);
Expand Down
6 changes: 2 additions & 4 deletions src/hotspot/cpu/x86/interp_masm_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1955,8 +1955,7 @@ void InterpreterMacroAssembler::notify_method_entry() {
bind(L);
}

{
SkipIfEqual skip(this, &DTraceMethodProbes, false, rscratch1);
if (DTraceMethodProbes) {
NOT_LP64(get_thread(rthread);)
get_method(rarg);
call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
Expand Down Expand Up @@ -2000,8 +1999,7 @@ void InterpreterMacroAssembler::notify_method_exit(
pop(state);
}

{
SkipIfEqual skip(this, &DTraceMethodProbes, false, rscratch1);
if (DTraceMethodProbes) {
push(state);
NOT_LP64(get_thread(rthread);)
get_method(rarg);
Expand Down
6 changes: 2 additions & 4 deletions src/hotspot/cpu/x86/sharedRuntime_x86_32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1612,8 +1612,7 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
// We have all of the arguments setup at this point. We must not touch any register
// argument registers at this point (what if we save/restore them there are no oop?

{
SkipIfEqual skip_if(masm, &DTraceMethodProbes, 0, noreg);
if (DTraceMethodProbes) {
__ mov_metadata(rax, method());
__ call_VM_leaf(
CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
Expand Down Expand Up @@ -1857,8 +1856,7 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
__ bind(fast_done);
}

{
SkipIfEqual skip_if(masm, &DTraceMethodProbes, 0, noreg);
if (DTraceMethodProbes) {
// Tell dtrace about this method exit
save_native_result(masm, ret_type, stack_slots);
__ mov_metadata(rax, method());
Expand Down
6 changes: 2 additions & 4 deletions src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2200,8 +2200,7 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
// We have all of the arguments setup at this point. We must not touch any register
// argument registers at this point (what if we save/restore them there are no oop?

{
SkipIfEqual skip(masm, &DTraceMethodProbes, false, rscratch1);
if (DTraceMethodProbes) {
// protect the args we've loaded
save_args(masm, total_c_args, c_arg, out_regs);
__ mov_metadata(c_rarg1, method());
Expand Down Expand Up @@ -2439,8 +2438,7 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,

__ bind(fast_done);
}
{
SkipIfEqual skip(masm, &DTraceMethodProbes, false, rscratch1);
if (DTraceMethodProbes) {
save_native_result(masm, ret_type, stack_slots);
__ mov_metadata(c_rarg1, method());
__ call_VM_leaf(
Expand Down
3 changes: 1 addition & 2 deletions src/hotspot/cpu/x86/templateTable_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4123,8 +4123,7 @@ void TemplateTable::_new() {
#endif
__ store_klass(rax, rcx, rscratch1); // klass

{
SkipIfEqual skip_if(_masm, &DTraceAllocProbes, 0, rscratch1);
if (DTraceAllocProbes) {
// Trigger dtrace event for fastpath
__ push(atos);
__ call_VM_leaf(
Expand Down

0 comments on commit 1ec9889

Please sign in to comment.