blob: 1c0127a5190d10c137c8bce64133ee41f8a131a8 [file] [log] [blame]
Shih-wei Liao2d831012011-09-28 22:06:53 -07001/*
Elliott Hughes0f3c5532012-03-30 14:51:51 -07002 * Copyright (C) 2012 The Android Open Source Project
Shih-wei Liao2d831012011-09-28 22:06:53 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Ian Rogers7655f292013-07-29 11:07:13 -070017#include "entrypoints/entrypoint_utils.h"
Shih-wei Liao2d831012011-09-28 22:06:53 -070018
Mathieu Chartierc7853442015-03-27 14:35:38 -070019#include "art_field-inl.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070020#include "art_method-inl.h"
Andreas Gampe542451c2016-07-26 09:02:02 -070021#include "base/enums.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070022#include "base/mutex.h"
David Brazdil2bb2fbd2018-11-13 18:24:26 +000023#include "base/sdk_version.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080024#include "class_linker-inl.h"
David Sehr9e734c72018-01-04 17:56:19 -080025#include "dex/dex_file-inl.h"
Vladimir Marko86c87522020-05-11 16:55:55 +010026#include "dex/method_reference.h"
Nicolas Geoffray1920c102015-09-29 18:00:03 +000027#include "entrypoints/entrypoint_utils-inl.h"
28#include "entrypoints/quick/callee_save_frame.h"
29#include "entrypoints/runtime_asm_entrypoints.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070030#include "gc/accounting/card_table-inl.h"
Vladimir Marko86c87522020-05-11 16:55:55 +010031#include "index_bss_mapping.h"
Vladimir Markoa3ad0cd2018-05-04 10:06:38 +010032#include "jni/java_vm_ext.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080033#include "mirror/class-inl.h"
Mathieu Chartierfc58af42015-04-16 18:00:39 -070034#include "mirror/method.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080035#include "mirror/object-inl.h"
36#include "mirror/object_array-inl.h"
Nicolas Geoffray1920c102015-09-29 18:00:03 +000037#include "nth_caller_visitor.h"
Vladimir Marko86c87522020-05-11 16:55:55 +010038#include "oat_file.h"
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010039#include "oat_quick_method_header.h"
Ian Rogersaf6e67a2013-01-16 08:38:37 -080040#include "reflection.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070041#include "scoped_thread_state_change-inl.h"
Elliott Hugheseac76672012-05-24 21:56:51 -070042#include "well_known_classes.h"
TDYa1275bb86012012-04-11 05:57:28 -070043
jeffhao41005dd2012-05-09 17:58:52 -070044namespace art {
45
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070046void CheckReferenceResult(Handle<mirror::Object> o, Thread* self) {
Andreas Gampefa4333d2017-02-14 11:10:34 -080047 if (o == nullptr) {
Ian Rogerse5877a12014-07-16 12:06:35 -070048 return;
49 }
Ian Rogerse5877a12014-07-16 12:06:35 -070050 // Make sure that the result is an instance of the type this method was expected to return.
Mathieu Chartierbe08cf52016-09-13 13:41:24 -070051 ArtMethod* method = self->GetCurrentMethod(nullptr);
Vladimir Markob45528c2017-07-27 14:14:28 +010052 ObjPtr<mirror::Class> return_type = method->ResolveReturnType();
Ian Rogerse5877a12014-07-16 12:06:35 -070053
54 if (!o->InstanceOf(return_type)) {
Ian Rogersc0542af2014-09-03 16:16:56 -070055 Runtime::Current()->GetJavaVM()->JniAbortF(nullptr,
56 "attempt to return an instance of %s from %s",
David Sehr709b0702016-10-13 09:12:37 -070057 o->PrettyTypeOf().c_str(),
58 method->PrettyMethod().c_str());
Ian Rogerse5877a12014-07-16 12:06:35 -070059 }
60}
61
Vladimir Marko4bb2af52019-03-22 11:09:19 +000062JValue InvokeProxyInvocationHandler(ScopedObjectAccessAlreadyRunnable& soa,
63 const char* shorty,
64 jobject rcvr_jobj,
65 jobject interface_method_jobj,
Ian Rogersaf6e67a2013-01-16 08:38:37 -080066 std::vector<jvalue>& args) {
67 DCHECK(soa.Env()->IsInstanceOf(rcvr_jobj, WellKnownClasses::java_lang_reflect_Proxy));
68
69 // Build argument array possibly triggering GC.
70 soa.Self()->AssertThreadSuspensionIsAllowable();
Mathieu Chartier2cebb242015-04-21 16:50:40 -070071 jobjectArray args_jobj = nullptr;
Ian Rogersaf6e67a2013-01-16 08:38:37 -080072 const JValue zero;
David Brazdil2bb2fbd2018-11-13 18:24:26 +000073 uint32_t target_sdk_version = Runtime::Current()->GetTargetSdkVersion();
Jeff Haof00571c2014-05-29 17:29:47 -070074 // Do not create empty arrays unless needed to maintain Dalvik bug compatibility.
David Brazdil2bb2fbd2018-11-13 18:24:26 +000075 if (args.size() > 0 || IsSdkVersionSetAndAtMost(target_sdk_version, SdkVersion::kL)) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -070076 args_jobj = soa.Env()->NewObjectArray(args.size(), WellKnownClasses::java_lang_Object, nullptr);
77 if (args_jobj == nullptr) {
Ian Rogersaf6e67a2013-01-16 08:38:37 -080078 CHECK(soa.Self()->IsExceptionPending());
79 return zero;
80 }
81 for (size_t i = 0; i < args.size(); ++i) {
82 if (shorty[i + 1] == 'L') {
Vladimir Marko35d5b8a2018-07-03 09:18:32 +010083 jobject val = args[i].l;
Ian Rogersaf6e67a2013-01-16 08:38:37 -080084 soa.Env()->SetObjectArrayElement(args_jobj, i, val);
85 } else {
86 JValue jv;
Vladimir Marko35d5b8a2018-07-03 09:18:32 +010087 jv.SetJ(args[i].j);
Vladimir Marko4bb2af52019-03-22 11:09:19 +000088 ObjPtr<mirror::Object> val = BoxPrimitive(Primitive::GetType(shorty[i + 1]), jv);
Mathieu Chartier2cebb242015-04-21 16:50:40 -070089 if (val == nullptr) {
Ian Rogersaf6e67a2013-01-16 08:38:37 -080090 CHECK(soa.Self()->IsExceptionPending());
91 return zero;
92 }
Mathieu Chartier0795f232016-09-27 18:43:30 -070093 soa.Decode<mirror::ObjectArray<mirror::Object>>(args_jobj)->Set<false>(i, val);
Ian Rogersaf6e67a2013-01-16 08:38:37 -080094 }
95 }
96 }
97
Mathieu Chartierfc58af42015-04-16 18:00:39 -070098 // Call Proxy.invoke(Proxy proxy, Method method, Object[] args).
Ian Rogersaf6e67a2013-01-16 08:38:37 -080099 jvalue invocation_args[3];
100 invocation_args[0].l = rcvr_jobj;
101 invocation_args[1].l = interface_method_jobj;
102 invocation_args[2].l = args_jobj;
103 jobject result =
Brian Carlstromea46f952013-07-30 01:26:50 -0700104 soa.Env()->CallStaticObjectMethodA(WellKnownClasses::java_lang_reflect_Proxy,
105 WellKnownClasses::java_lang_reflect_Proxy_invoke,
106 invocation_args);
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800107
108 // Unbox result and handle error conditions.
Ian Rogers62d6c772013-02-27 08:32:07 -0800109 if (LIKELY(!soa.Self()->IsExceptionPending())) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700110 if (shorty[0] == 'V' || (shorty[0] == 'L' && result == nullptr)) {
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800111 // Do nothing.
112 return zero;
113 } else {
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700114 ArtMethod* interface_method =
Mathieu Chartier0795f232016-09-27 18:43:30 -0700115 soa.Decode<mirror::Method>(interface_method_jobj)->GetArtMethod();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700116 // This can cause thread suspension.
Vladimir Markob45528c2017-07-27 14:14:28 +0100117 ObjPtr<mirror::Class> result_type = interface_method->ResolveReturnType();
Mathieu Chartier0795f232016-09-27 18:43:30 -0700118 ObjPtr<mirror::Object> result_ref = soa.Decode<mirror::Object>(result);
Ian Rogers62d6c772013-02-27 08:32:07 -0800119 JValue result_unboxed;
Vladimir Marko4bb2af52019-03-22 11:09:19 +0000120 if (!UnboxPrimitiveForResult(result_ref, result_type, &result_unboxed)) {
Ian Rogers530f71c2013-02-22 23:29:00 -0800121 DCHECK(soa.Self()->IsExceptionPending());
Ian Rogers62d6c772013-02-27 08:32:07 -0800122 return zero;
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800123 }
124 return result_unboxed;
125 }
126 } else {
127 // In the case of checked exceptions that aren't declared, the exception must be wrapped by
128 // a UndeclaredThrowableException.
Vladimir Marko423bebb2019-03-26 15:17:21 +0000129 ObjPtr<mirror::Throwable> exception = soa.Self()->GetException();
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800130 if (exception->IsCheckedException()) {
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800131 bool declares_exception = false;
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700132 {
133 ScopedAssertNoThreadSuspension ants(__FUNCTION__);
Mathieu Chartier0795f232016-09-27 18:43:30 -0700134 ObjPtr<mirror::Object> rcvr = soa.Decode<mirror::Object>(rcvr_jobj);
Vladimir Marko423bebb2019-03-26 15:17:21 +0000135 ObjPtr<mirror::Class> proxy_class = rcvr->GetClass();
Mathieu Chartier0795f232016-09-27 18:43:30 -0700136 ObjPtr<mirror::Method> interface_method = soa.Decode<mirror::Method>(interface_method_jobj);
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700137 ArtMethod* proxy_method = rcvr->GetClass()->FindVirtualMethodForInterface(
138 interface_method->GetArtMethod(), kRuntimePointerSize);
139 auto virtual_methods = proxy_class->GetVirtualMethodsSlice(kRuntimePointerSize);
140 size_t num_virtuals = proxy_class->NumVirtualMethods();
141 size_t method_size = ArtMethod::Size(kRuntimePointerSize);
142 // Rely on the fact that the methods are contiguous to determine the index of the method in
143 // the slice.
144 int throws_index = (reinterpret_cast<uintptr_t>(proxy_method) -
Vladimir Marko9ac77492017-06-14 18:07:03 +0100145 reinterpret_cast<uintptr_t>(&virtual_methods[0])) / method_size;
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700146 CHECK_LT(throws_index, static_cast<int>(num_virtuals));
Vladimir Marko423bebb2019-03-26 15:17:21 +0000147 ObjPtr<mirror::ObjectArray<mirror::Class>> declared_exceptions =
Narayan Kamath6b2dc312017-03-14 13:26:12 +0000148 proxy_class->GetProxyThrows()->Get(throws_index);
Vladimir Marko423bebb2019-03-26 15:17:21 +0000149 ObjPtr<mirror::Class> exception_class = exception->GetClass();
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700150 for (int32_t i = 0; i < declared_exceptions->GetLength() && !declares_exception; i++) {
Vladimir Marko423bebb2019-03-26 15:17:21 +0000151 ObjPtr<mirror::Class> declared_exception = declared_exceptions->Get(i);
Mathieu Chartierbe08cf52016-09-13 13:41:24 -0700152 declares_exception = declared_exception->IsAssignableFrom(exception_class);
153 }
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800154 }
155 if (!declares_exception) {
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000156 soa.Self()->ThrowNewWrappedException("Ljava/lang/reflect/UndeclaredThrowableException;",
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700157 nullptr);
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800158 }
159 }
160 return zero;
161 }
162}
Ian Rogers832336b2014-10-08 15:35:22 -0700163
Mathieu Chartieref41db72016-10-25 15:08:01 -0700164bool FillArrayData(ObjPtr<mirror::Object> obj, const Instruction::ArrayDataPayload* payload) {
Ian Rogers832336b2014-10-08 15:35:22 -0700165 DCHECK_EQ(payload->ident, static_cast<uint16_t>(Instruction::kArrayDataSignature));
166 if (UNLIKELY(obj == nullptr)) {
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000167 ThrowNullPointerException("null array in FILL_ARRAY_DATA");
Ian Rogers832336b2014-10-08 15:35:22 -0700168 return false;
169 }
Vladimir Marko4617d582019-03-28 13:48:31 +0000170 ObjPtr<mirror::Array> array = obj->AsArray();
Ian Rogers832336b2014-10-08 15:35:22 -0700171 DCHECK(!array->IsObjectArray());
172 if (UNLIKELY(static_cast<int32_t>(payload->element_count) > array->GetLength())) {
173 Thread* self = Thread::Current();
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000174 self->ThrowNewExceptionF("Ljava/lang/ArrayIndexOutOfBoundsException;",
Ian Rogers832336b2014-10-08 15:35:22 -0700175 "failed FILL_ARRAY_DATA; length=%d, index=%d",
176 array->GetLength(), payload->element_count);
177 return false;
178 }
179 // Copy data from dex file to memory assuming both are little endian.
180 uint32_t size_in_bytes = payload->element_count * payload->element_width;
181 memcpy(array->GetRawData(payload->element_width, 0), payload->data, size_in_bytes);
182 return true;
183}
184
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000185static inline std::pair<ArtMethod*, uintptr_t> DoGetCalleeSaveMethodOuterCallerAndPc(
Andreas Gampe8228cdf2017-05-30 15:03:54 -0700186 ArtMethod** sp, CalleeSaveType type) REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffray1920c102015-09-29 18:00:03 +0000187 DCHECK_EQ(*sp, Runtime::Current()->GetCalleeSaveMethod(type));
188
Vladimir Markod3083dd2018-05-17 08:43:47 +0100189 const size_t callee_frame_size = RuntimeCalleeSaveFrame::GetFrameSize(type);
Nicolas Geoffray1920c102015-09-29 18:00:03 +0000190 auto** caller_sp = reinterpret_cast<ArtMethod**>(
191 reinterpret_cast<uintptr_t>(sp) + callee_frame_size);
Vladimir Markod3083dd2018-05-17 08:43:47 +0100192 const size_t callee_return_pc_offset = RuntimeCalleeSaveFrame::GetReturnPcOffset(type);
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +0100193 uintptr_t caller_pc = *reinterpret_cast<uintptr_t*>(
194 (reinterpret_cast<uint8_t*>(sp) + callee_return_pc_offset));
Nicolas Geoffray1920c102015-09-29 18:00:03 +0000195 ArtMethod* outer_method = *caller_sp;
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000196 return std::make_pair(outer_method, caller_pc);
197}
198
199static inline ArtMethod* DoGetCalleeSaveMethodCaller(ArtMethod* outer_method,
200 uintptr_t caller_pc,
201 bool do_caller_check)
202 REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffray1920c102015-09-29 18:00:03 +0000203 ArtMethod* caller = outer_method;
Nicolas Geoffray63e47f42015-11-05 13:26:17 +0000204 if (LIKELY(caller_pc != reinterpret_cast<uintptr_t>(GetQuickInstrumentationExitPc()))) {
205 if (outer_method != nullptr) {
206 const OatQuickMethodHeader* current_code = outer_method->GetOatQuickMethodHeader(caller_pc);
Vladimir Marko9d07e3d2016-03-31 12:02:28 +0100207 DCHECK(current_code != nullptr);
Nicolas Geoffray013d1ee2019-12-04 16:18:15 +0000208 if (current_code->IsOptimized() &&
209 CodeInfo::HasInlineInfo(current_code->GetOptimizedCodeInfoPtr())) {
David Srbeckye42a4b92019-05-26 00:10:25 +0100210 uintptr_t native_pc_offset = current_code->NativeQuickPcOffset(caller_pc);
David Srbecky0d4567f2019-05-30 22:45:40 +0100211 CodeInfo code_info = CodeInfo::DecodeInlineInfoOnly(current_code);
David Srbeckye42a4b92019-05-26 00:10:25 +0100212 StackMap stack_map = code_info.GetStackMapForNativePcOffset(native_pc_offset);
213 DCHECK(stack_map.IsValid());
214 BitTableRange<InlineInfo> inline_infos = code_info.GetInlineInfosOf(stack_map);
215 if (!inline_infos.empty()) {
216 caller = GetResolvedMethod(outer_method, code_info, inline_infos);
217 }
Nicolas Geoffray1920c102015-09-29 18:00:03 +0000218 }
219 }
Nicolas Geoffray63e47f42015-11-05 13:26:17 +0000220 if (kIsDebugBuild && do_caller_check) {
221 // Note that do_caller_check is optional, as this method can be called by
222 // stubs, and tests without a proper call stack.
223 NthCallerVisitor visitor(Thread::Current(), 1, true);
224 visitor.WalkStack();
225 CHECK_EQ(caller, visitor.caller);
226 }
227 } else {
228 // We're instrumenting, just use the StackVisitor which knows how to
229 // handle instrumented frames.
Nicolas Geoffray1920c102015-09-29 18:00:03 +0000230 NthCallerVisitor visitor(Thread::Current(), 1, true);
231 visitor.WalkStack();
Nicolas Geoffray63e47f42015-11-05 13:26:17 +0000232 caller = visitor.caller;
Nicolas Geoffray1920c102015-09-29 18:00:03 +0000233 }
Nicolas Geoffray1920c102015-09-29 18:00:03 +0000234 return caller;
235}
236
Andreas Gampe8228cdf2017-05-30 15:03:54 -0700237ArtMethod* GetCalleeSaveMethodCaller(ArtMethod** sp, CalleeSaveType type, bool do_caller_check)
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000238 REQUIRES_SHARED(Locks::mutator_lock_) {
239 ScopedAssertNoThreadSuspension ants(__FUNCTION__);
240 auto outer_caller_and_pc = DoGetCalleeSaveMethodOuterCallerAndPc(sp, type);
241 ArtMethod* outer_method = outer_caller_and_pc.first;
242 uintptr_t caller_pc = outer_caller_and_pc.second;
243 ArtMethod* caller = DoGetCalleeSaveMethodCaller(outer_method, caller_pc, do_caller_check);
244 return caller;
245}
246
Andreas Gampe8228cdf2017-05-30 15:03:54 -0700247CallerAndOuterMethod GetCalleeSaveMethodCallerAndOuterMethod(Thread* self, CalleeSaveType type) {
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000248 CallerAndOuterMethod result;
249 ScopedAssertNoThreadSuspension ants(__FUNCTION__);
Vladimir Marko2196c652017-11-30 16:16:07 +0000250 ArtMethod** sp = self->GetManagedStack()->GetTopQuickFrameKnownNotTagged();
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000251 auto outer_caller_and_pc = DoGetCalleeSaveMethodOuterCallerAndPc(sp, type);
252 result.outer_method = outer_caller_and_pc.first;
253 uintptr_t caller_pc = outer_caller_and_pc.second;
254 result.caller =
Andreas Gampe98ea9d92018-10-19 14:06:15 -0700255 DoGetCalleeSaveMethodCaller(result.outer_method, caller_pc, /* do_caller_check= */ true);
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000256 return result;
257}
258
Andreas Gampe8228cdf2017-05-30 15:03:54 -0700259ArtMethod* GetCalleeSaveOuterMethod(Thread* self, CalleeSaveType type) {
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +0000260 ScopedAssertNoThreadSuspension ants(__FUNCTION__);
Vladimir Marko2196c652017-11-30 16:16:07 +0000261 ArtMethod** sp = self->GetManagedStack()->GetTopQuickFrameKnownNotTagged();
Nicolas Geoffray5b3c6c02017-01-19 14:22:26 +0000262 return DoGetCalleeSaveMethodOuterCallerAndPc(sp, type).first;
263}
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000264
Orion Hodsondbaa5c72018-05-10 08:22:46 +0100265ObjPtr<mirror::MethodHandle> ResolveMethodHandleFromCode(ArtMethod* referrer,
266 uint32_t method_handle_idx) {
267 Thread::PoisonObjectPointersIfDebug();
268 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
269 return class_linker->ResolveMethodHandle(Thread::Current(), method_handle_idx, referrer);
270}
271
Orion Hodson18259d72018-04-12 11:18:23 +0100272ObjPtr<mirror::MethodType> ResolveMethodTypeFromCode(ArtMethod* referrer,
Orion Hodson06d10a72018-05-14 08:53:38 +0100273 dex::ProtoIndex proto_idx) {
Orion Hodson18259d72018-04-12 11:18:23 +0100274 Thread::PoisonObjectPointersIfDebug();
275 ObjPtr<mirror::MethodType> method_type =
276 referrer->GetDexCache()->GetResolvedMethodType(proto_idx);
277 if (UNLIKELY(method_type == nullptr)) {
278 StackHandleScope<2> hs(Thread::Current());
279 Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache()));
280 Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referrer->GetClassLoader()));
281 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
282 method_type = class_linker->ResolveMethodType(hs.Self(), proto_idx, dex_cache, class_loader);
283 }
284 return method_type;
285}
286
Vladimir Marko86c87522020-05-11 16:55:55 +0100287void MaybeUpdateBssMethodEntry(ArtMethod* callee, MethodReference callee_reference) {
288 DCHECK(callee != nullptr);
289 if (callee_reference.dex_file->GetOatDexFile() != nullptr) {
290 size_t bss_offset = IndexBssMappingLookup::GetBssOffset(
291 callee_reference.dex_file->GetOatDexFile()->GetMethodBssMapping(),
292 callee_reference.index,
293 callee_reference.dex_file->NumMethodIds(),
294 static_cast<size_t>(kRuntimePointerSize));
295 if (bss_offset != IndexBssMappingLookup::npos) {
296 DCHECK_ALIGNED(bss_offset, static_cast<size_t>(kRuntimePointerSize));
297 const OatFile* oat_file = callee_reference.dex_file->GetOatDexFile()->GetOatFile();
298 ArtMethod** method_entry = reinterpret_cast<ArtMethod**>(const_cast<uint8_t*>(
299 oat_file->BssBegin() + bss_offset));
300 DCHECK_GE(method_entry, oat_file->GetBssMethods().data());
301 DCHECK_LT(method_entry,
302 oat_file->GetBssMethods().data() + oat_file->GetBssMethods().size());
303 std::atomic<ArtMethod*>* atomic_entry =
304 reinterpret_cast<std::atomic<ArtMethod*>*>(method_entry);
Nicolas Geoffrayec068092021-05-10 17:28:32 +0000305 if (kIsDebugBuild) {
306 ArtMethod* existing = atomic_entry->load(std::memory_order_acquire);
307 CHECK(existing->IsRuntimeMethod() || existing == callee);
308 }
Vladimir Marko86c87522020-05-11 16:55:55 +0100309 static_assert(sizeof(*method_entry) == sizeof(*atomic_entry), "Size check.");
310 atomic_entry->store(callee, std::memory_order_release);
311 }
312 }
313}
314
Shih-wei Liao2d831012011-09-28 22:06:53 -0700315} // namespace art