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