Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [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 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_COMPILER_DRIVER_DEX_COMPILATION_UNIT_H_ |
| 18 | #define ART_COMPILER_DRIVER_DEX_COMPILATION_UNIT_H_ |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 19 | |
| 20 | #include <stdint.h> |
| 21 | |
Vladimir Marko | c91df2d | 2015-04-23 09:29:21 +0000 | [diff] [blame] | 22 | #include "base/arena_object.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 23 | #include "dex/code_item_accessors.h" |
| 24 | #include "dex/dex_file.h" |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 25 | #include "handle.h" |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 26 | |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 27 | namespace art { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 28 | namespace mirror { |
Vladimir Marko | a2c211c | 2018-11-01 09:50:52 +0000 | [diff] [blame] | 29 | class Class; |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 30 | class ClassLoader; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 31 | class DexCache; |
| 32 | } // namespace mirror |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 33 | class ClassLinker; |
Vladimir Marko | 2730db0 | 2014-01-27 11:15:17 +0000 | [diff] [blame] | 34 | class VerifiedMethod; |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 35 | |
Vladimir Marko | c91df2d | 2015-04-23 09:29:21 +0000 | [diff] [blame] | 36 | class DexCompilationUnit : public DeletableArenaObject<kArenaAllocMisc> { |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 37 | public: |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 38 | DexCompilationUnit(Handle<mirror::ClassLoader> class_loader, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 39 | ClassLinker* class_linker, |
| 40 | const DexFile& dex_file, |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 41 | const dex::CodeItem* code_item, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 42 | uint16_t class_def_idx, |
| 43 | uint32_t method_idx, |
| 44 | uint32_t access_flags, |
| 45 | const VerifiedMethod* verified_method, |
Vladimir Marko | a2c211c | 2018-11-01 09:50:52 +0000 | [diff] [blame] | 46 | Handle<mirror::DexCache> dex_cache, |
| 47 | Handle<mirror::Class> compiling_class = Handle<mirror::Class>()); |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 48 | |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 49 | Handle<mirror::ClassLoader> GetClassLoader() const { |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 50 | return class_loader_; |
| 51 | } |
| 52 | |
| 53 | ClassLinker* GetClassLinker() const { |
| 54 | return class_linker_; |
| 55 | } |
| 56 | |
| 57 | const DexFile* GetDexFile() const { |
| 58 | return dex_file_; |
| 59 | } |
| 60 | |
Ian Rogers | ee39a10 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 61 | uint16_t GetClassDefIndex() const { |
TDYa127 | dc5daa0 | 2013-01-09 21:31:37 +0800 | [diff] [blame] | 62 | return class_def_idx_; |
| 63 | } |
| 64 | |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 65 | uint32_t GetDexMethodIndex() const { |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 66 | return dex_method_idx_; |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 67 | } |
| 68 | |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 69 | const dex::CodeItem* GetCodeItem() const { |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 70 | return code_item_; |
| 71 | } |
| 72 | |
Logan Chien | bfe4ea4 | 2012-03-01 13:24:17 +0800 | [diff] [blame] | 73 | const char* GetShorty() const { |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 74 | const dex::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_); |
Logan Chien | 61c65dc | 2012-02-29 03:22:30 +0800 | [diff] [blame] | 75 | return dex_file_->GetMethodShorty(method_id); |
| 76 | } |
| 77 | |
Logan Chien | bfe4ea4 | 2012-03-01 13:24:17 +0800 | [diff] [blame] | 78 | const char* GetShorty(uint32_t* shorty_len) const { |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 79 | const dex::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_); |
Logan Chien | 61c65dc | 2012-02-29 03:22:30 +0800 | [diff] [blame] | 80 | return dex_file_->GetMethodShorty(method_id, shorty_len); |
| 81 | } |
| 82 | |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 83 | uint32_t GetAccessFlags() const { |
| 84 | return access_flags_; |
| 85 | } |
| 86 | |
Ian Rogers | a49bdff | 2013-07-31 14:49:16 -0700 | [diff] [blame] | 87 | bool IsConstructor() const { |
| 88 | return ((access_flags_ & kAccConstructor) != 0); |
| 89 | } |
| 90 | |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 91 | bool IsNative() const { |
| 92 | return ((access_flags_ & kAccNative) != 0); |
| 93 | } |
| 94 | |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 95 | bool IsStatic() const { |
| 96 | return ((access_flags_ & kAccStatic) != 0); |
| 97 | } |
| 98 | |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 99 | bool IsSynchronized() const { |
| 100 | return ((access_flags_ & kAccSynchronized) != 0); |
| 101 | } |
| 102 | |
Vladimir Marko | 2730db0 | 2014-01-27 11:15:17 +0000 | [diff] [blame] | 103 | const VerifiedMethod* GetVerifiedMethod() const { |
| 104 | return verified_method_; |
| 105 | } |
| 106 | |
Mathieu Chartier | ab972ef | 2014-12-03 17:38:22 -0800 | [diff] [blame] | 107 | void ClearVerifiedMethod() { |
| 108 | verified_method_ = nullptr; |
| 109 | } |
| 110 | |
Ian Rogers | 1bf8d4d | 2013-05-30 00:18:49 -0700 | [diff] [blame] | 111 | const std::string& GetSymbol(); |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 112 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 113 | Handle<mirror::DexCache> GetDexCache() const { |
| 114 | return dex_cache_; |
| 115 | } |
| 116 | |
Mathieu Chartier | 73f21d4 | 2018-01-02 14:26:50 -0800 | [diff] [blame] | 117 | const CodeItemDataAccessor& GetCodeItemAccessor() const { |
| 118 | return code_item_accessor_; |
| 119 | } |
| 120 | |
Vladimir Marko | a2c211c | 2018-11-01 09:50:52 +0000 | [diff] [blame] | 121 | Handle<mirror::Class> GetCompilingClass() const { |
| 122 | return compiling_class_; |
| 123 | } |
| 124 | |
Vladimir Marko | c1c3452 | 2018-10-31 13:56:49 +0000 | [diff] [blame] | 125 | // Does this <init> method require a constructor barrier (prior to the return)? |
| 126 | // The answer is "yes", if and only if the class has any instance final fields. |
| 127 | // (This must not be called for any non-<init> methods; the answer would be "no"). |
| 128 | // |
| 129 | // --- |
| 130 | // |
| 131 | // JLS 17.5.1 "Semantics of final fields" mandates that all final fields are frozen at the end |
| 132 | // of the invoked constructor. The constructor barrier is a conservative implementation means of |
| 133 | // enforcing the freezes happen-before the object being constructed is observable by another |
| 134 | // thread. |
| 135 | // |
| 136 | // Note: This question only makes sense for instance constructors; |
| 137 | // static constructors (despite possibly having finals) never need |
| 138 | // a barrier. |
| 139 | // |
| 140 | // JLS 12.4.2 "Detailed Initialization Procedure" approximately describes |
| 141 | // class initialization as: |
| 142 | // |
| 143 | // lock(class.lock) |
| 144 | // class.state = initializing |
| 145 | // unlock(class.lock) |
| 146 | // |
| 147 | // invoke <clinit> |
| 148 | // |
| 149 | // lock(class.lock) |
| 150 | // class.state = initialized |
| 151 | // unlock(class.lock) <-- acts as a release |
| 152 | // |
| 153 | // The last operation in the above example acts as an atomic release |
| 154 | // for any stores in <clinit>, which ends up being stricter |
| 155 | // than what a constructor barrier needs. |
| 156 | // |
| 157 | // See also QuasiAtomic::ThreadFenceForConstructor(). |
| 158 | bool RequiresConstructorBarrier() const; |
| 159 | |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 160 | private: |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 161 | const Handle<mirror::ClassLoader> class_loader_; |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 162 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 163 | ClassLinker* const class_linker_; |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 164 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 165 | const DexFile* const dex_file_; |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 166 | |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 167 | const dex::CodeItem* const code_item_; |
Ian Rogers | ee39a10 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 168 | const uint16_t class_def_idx_; |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 169 | const uint32_t dex_method_idx_; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 170 | const uint32_t access_flags_; |
Mathieu Chartier | ab972ef | 2014-12-03 17:38:22 -0800 | [diff] [blame] | 171 | const VerifiedMethod* verified_method_; |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 172 | |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 173 | const Handle<mirror::DexCache> dex_cache_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 174 | |
Mathieu Chartier | 73f21d4 | 2018-01-02 14:26:50 -0800 | [diff] [blame] | 175 | const CodeItemDataAccessor code_item_accessor_; |
| 176 | |
Vladimir Marko | a2c211c | 2018-11-01 09:50:52 +0000 | [diff] [blame] | 177 | Handle<mirror::Class> compiling_class_; |
| 178 | |
Ian Rogers | 1bf8d4d | 2013-05-30 00:18:49 -0700 | [diff] [blame] | 179 | std::string symbol_; |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 180 | }; |
| 181 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 182 | } // namespace art |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 183 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 184 | #endif // ART_COMPILER_DRIVER_DEX_COMPILATION_UNIT_H_ |