Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 1 | /* |
| 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 Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 17 | #include "art_method-inl.h" |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 18 | #include "base/callee_save_type.h" |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 19 | #include "callee_save_frame.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 20 | #include "class_linker-inl.h" |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 21 | #include "class_table-inl.h" |
Ian Rogers | fa46d3e | 2013-05-15 00:16:04 -0700 | [diff] [blame] | 22 | #include "dex_file-inl.h" |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 23 | #include "dex_file_types.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 24 | #include "entrypoints/entrypoint_utils-inl.h" |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 25 | #include "gc/heap.h" |
| 26 | #include "mirror/class-inl.h" |
| 27 | #include "mirror/class_loader.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 28 | #include "mirror/object-inl.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 29 | #include "mirror/object_array-inl.h" |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 30 | #include "oat_file.h" |
| 31 | #include "runtime.h" |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 32 | |
| 33 | namespace art { |
| 34 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 35 | static inline void BssWriteBarrier(ArtMethod* outer_method) REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | a1467d0 | 2017-02-22 09:22:50 -0800 | [diff] [blame] | 36 | // For AOT code, we need a write barrier for the class loader that holds the |
| 37 | // GC roots in the .bss. |
| 38 | const DexFile* dex_file = outer_method->GetDexFile(); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 39 | if (dex_file != nullptr && |
| 40 | dex_file->GetOatDexFile() != nullptr && |
| 41 | !dex_file->GetOatDexFile()->GetOatFile()->GetBssGcRoots().empty()) { |
Vladimir Marko | 9b03cb4 | 2017-02-16 16:37:03 +0000 | [diff] [blame] | 42 | ObjPtr<mirror::ClassLoader> class_loader = outer_method->GetClassLoader(); |
| 43 | if (kIsDebugBuild) { |
| 44 | ClassTable* class_table = |
| 45 | Runtime::Current()->GetClassLinker()->ClassTableForClassLoader(class_loader); |
| 46 | CHECK(class_table != nullptr && |
| 47 | !class_table->InsertOatFile(dex_file->GetOatDexFile()->GetOatFile())) |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 48 | << "Oat file with .bss GC roots was not registered in class table: " |
| 49 | << dex_file->GetOatDexFile()->GetOatFile()->GetLocation(); |
Vladimir Marko | 9b03cb4 | 2017-02-16 16:37:03 +0000 | [diff] [blame] | 50 | } |
Mathieu Chartier | a1467d0 | 2017-02-22 09:22:50 -0800 | [diff] [blame] | 51 | if (class_loader != nullptr) { |
| 52 | // Note that we emit the barrier before the compiled code stores the String or Class |
| 53 | // as a GC root. This is OK as there is no suspend point point in between. |
| 54 | Runtime::Current()->GetHeap()->WriteBarrierEveryFieldOf(class_loader); |
| 55 | } else { |
| 56 | Runtime::Current()->GetClassLinker()->WriteBarrierForBootOatFileBssRoots( |
| 57 | dex_file->GetOatDexFile()->GetOatFile()); |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 58 | } |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
Nicolas Geoffray | 7ea6a17 | 2015-05-19 18:58:54 +0100 | [diff] [blame] | 62 | extern "C" mirror::Class* artInitializeStaticStorageFromCode(uint32_t type_idx, Thread* self) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 63 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | e2645d3 | 2012-04-11 14:42:42 -0700 | [diff] [blame] | 64 | // Called to ensure static storage base is initialized for direct static field reads and writes. |
| 65 | // A class may be accessing another class' fields when it doesn't have access, as access has been |
| 66 | // given by inheritance. |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 67 | ScopedQuickEntrypointChecks sqec(self); |
Mingyao Yang | 0a87a65 | 2017-04-12 13:43:15 -0700 | [diff] [blame^] | 68 | auto caller_and_outer = GetCalleeSaveMethodCallerAndOuterMethod( |
| 69 | self, CalleeSaveType::kSaveEverythingForClinit); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 70 | ArtMethod* caller = caller_and_outer.caller; |
| 71 | mirror::Class* result = |
| 72 | ResolveVerifyAndClinit(dex::TypeIndex(type_idx), caller, self, true, false); |
| 73 | if (LIKELY(result != nullptr)) { |
| 74 | BssWriteBarrier(caller_and_outer.outer_method); |
| 75 | } |
| 76 | return result; |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Nicolas Geoffray | 7ea6a17 | 2015-05-19 18:58:54 +0100 | [diff] [blame] | 79 | extern "C" mirror::Class* artInitializeTypeFromCode(uint32_t type_idx, Thread* self) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 80 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | e2645d3 | 2012-04-11 14:42:42 -0700 | [diff] [blame] | 81 | // Called when method->dex_cache_resolved_types_[] misses. |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 82 | ScopedQuickEntrypointChecks sqec(self); |
Mingyao Yang | 0a87a65 | 2017-04-12 13:43:15 -0700 | [diff] [blame^] | 83 | auto caller_and_outer = GetCalleeSaveMethodCallerAndOuterMethod( |
| 84 | self, CalleeSaveType::kSaveEverythingForClinit); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 85 | ArtMethod* caller = caller_and_outer.caller; |
| 86 | mirror::Class* result = |
| 87 | ResolveVerifyAndClinit(dex::TypeIndex(type_idx), caller, self, false, false); |
| 88 | if (LIKELY(result != nullptr)) { |
| 89 | BssWriteBarrier(caller_and_outer.outer_method); |
| 90 | } |
| 91 | return result; |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Nicolas Geoffray | 7ea6a17 | 2015-05-19 18:58:54 +0100 | [diff] [blame] | 94 | extern "C" mirror::Class* artInitializeTypeAndVerifyAccessFromCode(uint32_t type_idx, Thread* self) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 95 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 96 | // Called when caller isn't guaranteed to have access to a type and the dex cache may be |
Ian Rogers | e2645d3 | 2012-04-11 14:42:42 -0700 | [diff] [blame] | 97 | // unpopulated. |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 98 | ScopedQuickEntrypointChecks sqec(self); |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 99 | auto caller_and_outer = GetCalleeSaveMethodCallerAndOuterMethod(self, |
| 100 | CalleeSaveType::kSaveEverything); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 101 | ArtMethod* caller = caller_and_outer.caller; |
| 102 | mirror::Class* result = |
| 103 | ResolveVerifyAndClinit(dex::TypeIndex(type_idx), caller, self, false, true); |
| 104 | if (LIKELY(result != nullptr)) { |
| 105 | BssWriteBarrier(caller_and_outer.outer_method); |
| 106 | } |
| 107 | return result; |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Nicolas Geoffray | 7ea6a17 | 2015-05-19 18:58:54 +0100 | [diff] [blame] | 110 | extern "C" mirror::String* artResolveStringFromCode(int32_t string_idx, Thread* self) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 111 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 112 | ScopedQuickEntrypointChecks sqec(self); |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 113 | auto caller_and_outer = GetCalleeSaveMethodCallerAndOuterMethod(self, |
| 114 | CalleeSaveType::kSaveEverything); |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 115 | ArtMethod* caller = caller_and_outer.caller; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 116 | mirror::String* result = ResolveStringFromCode(caller, dex::StringIndex(string_idx)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 117 | if (LIKELY(result != nullptr)) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 118 | BssWriteBarrier(caller_and_outer.outer_method); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 119 | } |
| 120 | return result; |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | } // namespace art |