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