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 "dex_file.h"
23 #include "jni.h"
24 #include "base/arena_object.h"
25 
26 namespace art {
27 namespace mirror {
28 class ClassLoader;
29 class DexCache;
30 }  // namespace mirror
31 class ClassLinker;
32 struct CompilationUnit;
33 class VerifiedMethod;
34 
35 class DexCompilationUnit : public DeletableArenaObject<kArenaAllocMisc> {
36  public:
37   explicit DexCompilationUnit(CompilationUnit* cu);
38 
39   DexCompilationUnit(CompilationUnit* cu, jobject class_loader, ClassLinker* class_linker,
40                      const DexFile& dex_file, const DexFile::CodeItem* code_item,
41                      uint16_t class_def_idx, uint32_t method_idx, uint32_t access_flags,
42                      const VerifiedMethod* verified_method);
43 
GetCompilationUnit()44   CompilationUnit* GetCompilationUnit() const {
45     return cu_;
46   }
47 
GetClassLoader()48   jobject GetClassLoader() const {
49     return class_loader_;
50   }
51 
GetClassLinker()52   ClassLinker* GetClassLinker() const {
53     return class_linker_;
54   }
55 
GetDexFile()56   const DexFile* GetDexFile() const {
57     return dex_file_;
58   }
59 
GetClassDefIndex()60   uint16_t GetClassDefIndex() const {
61     return class_def_idx_;
62   }
63 
GetDexMethodIndex()64   uint32_t GetDexMethodIndex() const {
65     return dex_method_idx_;
66   }
67 
GetCodeItem()68   const DexFile::CodeItem* GetCodeItem() const {
69     return code_item_;
70   }
71 
GetShorty()72   const char* GetShorty() const {
73     const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_);
74     return dex_file_->GetMethodShorty(method_id);
75   }
76 
GetShorty(uint32_t * shorty_len)77   const char* GetShorty(uint32_t* shorty_len) const {
78     const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_);
79     return dex_file_->GetMethodShorty(method_id, shorty_len);
80   }
81 
GetAccessFlags()82   uint32_t GetAccessFlags() const {
83     return access_flags_;
84   }
85 
IsConstructor()86   bool IsConstructor() const {
87     return ((access_flags_ & kAccConstructor) != 0);
88   }
89 
IsNative()90   bool IsNative() const {
91     return ((access_flags_ & kAccNative) != 0);
92   }
93 
IsStatic()94   bool IsStatic() const {
95     return ((access_flags_ & kAccStatic) != 0);
96   }
97 
IsSynchronized()98   bool IsSynchronized() const {
99     return ((access_flags_ & kAccSynchronized) != 0);
100   }
101 
GetVerifiedMethod()102   const VerifiedMethod* GetVerifiedMethod() const {
103     return verified_method_;
104   }
105 
ClearVerifiedMethod()106   void ClearVerifiedMethod() {
107     verified_method_ = nullptr;
108   }
109 
110   const std::string& GetSymbol();
111 
112  private:
113   CompilationUnit* const cu_;
114 
115   const jobject class_loader_;
116 
117   ClassLinker* const class_linker_;
118 
119   const DexFile* const dex_file_;
120 
121   const DexFile::CodeItem* const code_item_;
122   const uint16_t class_def_idx_;
123   const uint32_t dex_method_idx_;
124   const uint32_t access_flags_;
125   const VerifiedMethod* verified_method_;
126 
127   std::string symbol_;
128 };
129 
130 }  // namespace art
131 
132 #endif  // ART_COMPILER_DRIVER_DEX_COMPILATION_UNIT_H_
133