blob: b1259e1b8db1949b98d42829e8d8c30c9bc67f0b [file] [log] [blame]
Ian Rogers57b86d42012-03-27 16:05:41 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
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
Mathieu Chartiere401d142015-04-22 13:56:20 -070017#include "art_method-inl.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070018#include "callee_save_frame.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070019#include "entrypoints/entrypoint_utils-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080020#include "class_linker-inl.h"
Vladimir Markoaad75c62016-10-03 08:46:48 +000021#include "class_table-inl.h"
Ian Rogersfa46d3e2013-05-15 00:16:04 -070022#include "dex_file-inl.h"
Andreas Gampea5b09a62016-11-17 15:21:22 -080023#include "dex_file_types.h"
Vladimir Markoaad75c62016-10-03 08:46:48 +000024#include "gc/heap.h"
25#include "mirror/class-inl.h"
26#include "mirror/class_loader.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080027#include "mirror/object_array-inl.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070028#include "mirror/object-inl.h"
Vladimir Markoaad75c62016-10-03 08:46:48 +000029#include "oat_file.h"
30#include "runtime.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070031
32namespace art {
33
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +010034extern "C" mirror::Class* artInitializeStaticStorageFromCode(uint32_t type_idx, Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070035 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogerse2645d32012-04-11 14:42:42 -070036 // Called to ensure static storage base is initialized for direct static field reads and writes.
37 // A class may be accessing another class' fields when it doesn't have access, as access has been
38 // given by inheritance.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070039 ScopedQuickEntrypointChecks sqec(self);
Vladimir Markofd36f1f2016-08-03 18:49:58 +010040 auto* caller = GetCalleeSaveMethodCaller(self, Runtime::kSaveRefsOnly);
Andreas Gampea5b09a62016-11-17 15:21:22 -080041 return ResolveVerifyAndClinit(dex::TypeIndex(type_idx), caller, self, true, false);
Ian Rogers57b86d42012-03-27 16:05:41 -070042}
43
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +010044extern "C" mirror::Class* artInitializeTypeFromCode(uint32_t type_idx, Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070045 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogerse2645d32012-04-11 14:42:42 -070046 // Called when method->dex_cache_resolved_types_[] misses.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070047 ScopedQuickEntrypointChecks sqec(self);
Vladimir Markofd36f1f2016-08-03 18:49:58 +010048 auto* caller = GetCalleeSaveMethodCaller(self, Runtime::kSaveRefsOnly);
Andreas Gampea5b09a62016-11-17 15:21:22 -080049 return ResolveVerifyAndClinit(dex::TypeIndex(type_idx), caller, self, false, false);
Ian Rogers57b86d42012-03-27 16:05:41 -070050}
51
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +010052extern "C" mirror::Class* artInitializeTypeAndVerifyAccessFromCode(uint32_t type_idx, Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070053 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070054 // Called when caller isn't guaranteed to have access to a type and the dex cache may be
Ian Rogerse2645d32012-04-11 14:42:42 -070055 // unpopulated.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070056 ScopedQuickEntrypointChecks sqec(self);
Vladimir Markofd36f1f2016-08-03 18:49:58 +010057 auto* caller = GetCalleeSaveMethodCaller(self, Runtime::kSaveRefsOnly);
Andreas Gampea5b09a62016-11-17 15:21:22 -080058 return ResolveVerifyAndClinit(dex::TypeIndex(type_idx), caller, self, false, true);
Ian Rogers57b86d42012-03-27 16:05:41 -070059}
60
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +010061extern "C" mirror::String* artResolveStringFromCode(int32_t string_idx, Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070062 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070063 ScopedQuickEntrypointChecks sqec(self);
Vladimir Marko94ce9c22016-09-30 14:50:51 +010064 auto* caller = GetCalleeSaveMethodCaller(
65 self,
66 // TODO: Change art_quick_resolve_string on MIPS and MIPS64 to kSaveEverything.
67 (kRuntimeISA == kMips || kRuntimeISA == kMips64) ? Runtime::kSaveRefsOnly
68 : Runtime::kSaveEverything);
Vladimir Markoaad75c62016-10-03 08:46:48 +000069 mirror::String* result = ResolveStringFromCode(caller, string_idx);
70 if (LIKELY(result != nullptr)) {
Vladimir Marko82f3a202016-10-14 16:28:52 +010071 // For AOT code, we need a write barrier for the class loader that holds
72 // the GC roots in the .bss.
Vladimir Markoaad75c62016-10-03 08:46:48 +000073 const DexFile* dex_file = caller->GetDexFile();
74 if (dex_file != nullptr &&
75 dex_file->GetOatDexFile() != nullptr &&
76 !dex_file->GetOatDexFile()->GetOatFile()->GetBssGcRoots().empty()) {
77 mirror::ClassLoader* class_loader = caller->GetDeclaringClass()->GetClassLoader();
Vladimir Marko82f3a202016-10-14 16:28:52 +010078 DCHECK(class_loader != nullptr); // We do not use .bss GC roots for boot image.
Vladimir Marko1bc4b172016-10-24 16:53:39 +000079 DCHECK(
80 !class_loader->GetClassTable()->InsertOatFile(dex_file->GetOatDexFile()->GetOatFile()))
81 << "Oat file with .bss GC roots was not registered in class table: "
82 << dex_file->GetOatDexFile()->GetOatFile()->GetLocation();
Vladimir Markoaad75c62016-10-03 08:46:48 +000083 // Note that we emit the barrier before the compiled code stores the string as GC root.
84 // This is OK as there is no suspend point point in between.
85 Runtime::Current()->GetHeap()->WriteBarrierEveryFieldOf(class_loader);
86 }
87 }
88 return result;
Ian Rogers57b86d42012-03-27 16:05:41 -070089}
90
91} // namespace art