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) 2014, 2020, Red Hat Inc. All rights reserved.
44 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55 *
@@ -51,13 +51,18 @@ void NativeInstruction::wrote(int offset) {
5151}
5252
5353address NativeCall::destination () const {
54- address addr = (address)this ;
55- address destination = instruction_address () + displacement ();
54+ address addr = instruction_address ();
55+ address destination = addr + displacement ();
56+
57+ // Performance optimization: no need to call find_blob() if it is a self-call
58+ if (destination == addr) {
59+ return destination;
60+ }
5661
5762 // Do we use a trampoline stub for this call?
5863 CodeBlob* cb = CodeCache::find_blob (addr);
59- assert (cb && cb->is_nmethod (), " sanity " );
60- nmethod *nm = (nmethod *)cb ;
64+ assert (cb != nullptr && cb->is_nmethod (), " nmethod expected " );
65+ nmethod *nm = cb-> as_nmethod () ;
6166 if (nm->stub_contains (destination) && is_NativeCallTrampolineStub_at (destination)) {
6267 // Yes we do, so get the destination from the trampoline stub.
6368 const address trampoline_stub_addr = destination;
@@ -72,12 +77,8 @@ address NativeCall::destination() const {
7277// call instruction at all times.
7378//
7479// Used in the runtime linkage of calls; see class CompiledIC.
75- //
76- // Add parameter assert_lock to switch off assertion
77- // during code generation, where no patching lock is needed.
78- void NativeCall::set_destination_mt_safe (address dest, bool assert_lock) {
79- assert (!assert_lock ||
80- (Patching_lock->is_locked () || SafepointSynchronize::is_at_safepoint ()) ||
80+ void NativeCall::set_destination_mt_safe (address dest) {
81+ assert ((Patching_lock->is_locked () || SafepointSynchronize::is_at_safepoint ()) ||
8182 CompiledICLocker::is_safe (addr_at (0 )),
8283 " concurrent code patching" );
8384
@@ -104,22 +105,18 @@ void NativeCall::set_destination_mt_safe(address dest, bool assert_lock) {
104105}
105106
106107address NativeCall::get_trampoline () {
107- address call_addr = addr_at ( 0 );
108+ address call_addr = instruction_address ( );
108109
109110 CodeBlob *code = CodeCache::find_blob (call_addr);
110- assert (code != nullptr , " Could not find the containing code blob" );
111+ assert (code != nullptr && code->is_nmethod (), " nmethod expected" );
112+ nmethod* nm = code->as_nmethod ();
111113
112- address bl_destination
113- = MacroAssembler::pd_call_destination (call_addr);
114- if (code->contains (bl_destination) &&
114+ address bl_destination = call_addr + displacement ();
115+ if (nm->stub_contains (bl_destination) &&
115116 is_NativeCallTrampolineStub_at (bl_destination))
116117 return bl_destination;
117118
118- if (code->is_nmethod ()) {
119- return trampoline_stub_Relocation::get_trampoline_for (call_addr, (nmethod*)code);
120- }
121-
122- return nullptr ;
119+ return trampoline_stub_Relocation::get_trampoline_for (call_addr, nm);
123120}
124121
125122// Inserts a native call instruction at a given pc
0 commit comments