1
1
/*
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.
3
3
* Copyright (c) 2014, 2020, Red Hat Inc. All rights reserved.
4
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
5
*
@@ -51,13 +51,18 @@ void NativeInstruction::wrote(int offset) {
51
51
}
52
52
53
53
address 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
+ }
56
61
57
62
// Do we use a trampoline stub for this call?
58
63
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 () ;
61
66
if (nm->stub_contains (destination) && is_NativeCallTrampolineStub_at (destination)) {
62
67
// Yes we do, so get the destination from the trampoline stub.
63
68
const address trampoline_stub_addr = destination;
@@ -72,12 +77,8 @@ address NativeCall::destination() const {
72
77
// call instruction at all times.
73
78
//
74
79
// 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 ()) ||
81
82
CompiledICLocker::is_safe (addr_at (0 )),
82
83
" concurrent code patching" );
83
84
@@ -104,22 +105,18 @@ void NativeCall::set_destination_mt_safe(address dest, bool assert_lock) {
104
105
}
105
106
106
107
address NativeCall::get_trampoline () {
107
- address call_addr = addr_at ( 0 );
108
+ address call_addr = instruction_address ( );
108
109
109
110
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 ();
111
113
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) &&
115
116
is_NativeCallTrampolineStub_at (bl_destination))
116
117
return bl_destination;
117
118
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);
123
120
}
124
121
125
122
// Inserts a native call instruction at a given pc
0 commit comments