dex_compilation_unit.h revision 7940e44f4517de5e2634a7e07d58d0fb26160513
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_SRC_COMPILER_DEX_DEX_COMPILATION_UNIT_H_
18#define ART_SRC_COMPILER_DEX_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;
32
33class DexCompilationUnit {
34 public:
35  DexCompilationUnit(CompilationUnit* cu);
36
37  DexCompilationUnit(CompilationUnit* cu, jobject class_loader, ClassLinker* class_linker,
38                     const DexFile& dex_file, const DexFile::CodeItem* code_item,
39                     uint32_t class_def_idx, uint32_t method_idx, uint32_t access_flags);
40
41  CompilationUnit* GetCompilationUnit() const {
42    return cu_;
43  }
44
45  jobject GetClassLoader() const {
46    return class_loader_;
47  }
48
49  ClassLinker* GetClassLinker() const {
50    return class_linker_;
51  }
52
53  const DexFile* GetDexFile() const {
54    return dex_file_;
55  }
56
57  uint32_t GetClassDefIndex() const {
58    return class_def_idx_;
59  }
60
61  uint32_t GetDexMethodIndex() const {
62    return dex_method_idx_;
63  }
64
65  const DexFile::CodeItem* GetCodeItem() const {
66    return code_item_;
67  }
68
69  const char* GetShorty() const {
70    const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_);
71    return dex_file_->GetMethodShorty(method_id);
72  }
73
74  const char* GetShorty(uint32_t* shorty_len) const {
75    const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_);
76    return dex_file_->GetMethodShorty(method_id, shorty_len);
77  }
78
79  uint32_t GetAccessFlags() const {
80    return access_flags_;
81  }
82
83  bool IsNative() const {
84    return ((access_flags_ & kAccNative) != 0);
85  }
86
87  bool IsStatic() const {
88    return ((access_flags_ & kAccStatic) != 0);
89  }
90
91  bool IsSynchronized() const {
92    return ((access_flags_ & kAccSynchronized) != 0);
93  }
94
95  const std::string& GetSymbol();
96
97 private:
98  CompilationUnit* const cu_;
99
100  const jobject class_loader_;
101
102  ClassLinker* const class_linker_;
103
104  const DexFile* const dex_file_;
105
106  const DexFile::CodeItem* const code_item_;
107  const uint32_t class_def_idx_;
108  const uint32_t dex_method_idx_;
109  const uint32_t access_flags_;
110
111  std::string symbol_;
112};
113
114} // namespace art
115
116#endif  // ART_SRC_COMPILER_DEX_DEX_COMPILATION_UNIT_H_
117