blob: 6a0218d03823e9f3c836ba378df78ad10c681b4f [file] [log] [blame]
Logan Chien4dd96f52012-02-29 01:26:58 +08001/*
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
Ian Rogers89756f22013-03-04 16:40:02 -080017#ifndef ART_SRC_COMPILER_DEX_DEX_COMPILATION_UNIT_H_
18#define ART_SRC_COMPILER_DEX_DEX_COMPILATION_UNIT_H_
Logan Chien4dd96f52012-02-29 01:26:58 +080019
Logan Chien61c65dc2012-02-29 03:22:30 +080020#include "dex_file.h"
21
Logan Chien4dd96f52012-02-29 01:26:58 +080022#include <stdint.h>
23
24namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080025namespace mirror {
Logan Chien4dd96f52012-02-29 01:26:58 +080026class ClassLoader;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080027class DexCache;
28} // namespace mirror
Logan Chien4dd96f52012-02-29 01:26:58 +080029class ClassLinker;
30class DexFile;
Logan Chien4dd96f52012-02-29 01:26:58 +080031
Ian Rogers89756f22013-03-04 16:40:02 -080032class DexCompilationUnit {
Logan Chien4dd96f52012-02-29 01:26:58 +080033 public:
Ian Rogers89756f22013-03-04 16:40:02 -080034 DexCompilationUnit(jobject class_loader, ClassLinker* class_linker, const DexFile& dex_file,
TDYa127dc5daa02013-01-09 21:31:37 +080035 const DexFile::CodeItem* code_item, uint32_t class_def_idx,
36 uint32_t method_idx, uint32_t access_flags)
Ian Rogers00f7d0e2012-07-19 15:28:27 -070037 : class_loader_(class_loader), class_linker_(class_linker), dex_file_(&dex_file),
Ian Rogers89756f22013-03-04 16:40:02 -080038 code_item_(code_item), class_def_idx_(class_def_idx), dex_method_idx_(method_idx),
TDYa127dc5daa02013-01-09 21:31:37 +080039 access_flags_(access_flags) {
Logan Chien4dd96f52012-02-29 01:26:58 +080040 }
41
Ian Rogers00f7d0e2012-07-19 15:28:27 -070042 jobject GetClassLoader() const {
Logan Chiendd361c92012-04-10 23:40:37 +080043 return class_loader_;
44 }
45
46 ClassLinker* GetClassLinker() const {
47 return class_linker_;
48 }
49
50 const DexFile* GetDexFile() const {
51 return dex_file_;
52 }
53
TDYa127dc5daa02013-01-09 21:31:37 +080054 uint32_t GetClassDefIndex() const {
55 return class_def_idx_;
56 }
57
Logan Chiendd361c92012-04-10 23:40:37 +080058 uint32_t GetDexMethodIndex() const {
Ian Rogers89756f22013-03-04 16:40:02 -080059 return dex_method_idx_;
Logan Chiendd361c92012-04-10 23:40:37 +080060 }
61
62 const DexFile::CodeItem* GetCodeItem() const {
63 return code_item_;
64 }
65
Logan Chienbfe4ea42012-03-01 13:24:17 +080066 const char* GetShorty() const {
Ian Rogers89756f22013-03-04 16:40:02 -080067 const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_);
Logan Chien61c65dc2012-02-29 03:22:30 +080068 return dex_file_->GetMethodShorty(method_id);
69 }
70
Logan Chienbfe4ea42012-03-01 13:24:17 +080071 const char* GetShorty(uint32_t* shorty_len) const {
Ian Rogers89756f22013-03-04 16:40:02 -080072 const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_);
Logan Chien61c65dc2012-02-29 03:22:30 +080073 return dex_file_->GetMethodShorty(method_id, shorty_len);
74 }
75
Ian Rogers89756f22013-03-04 16:40:02 -080076 uint32_t GetAccessFlags() const {
77 return access_flags_;
78 }
79
80 bool IsNative() const {
81 return ((access_flags_ & kAccNative) != 0);
82 }
83
Logan Chiendd361c92012-04-10 23:40:37 +080084 bool IsStatic() const {
85 return ((access_flags_ & kAccStatic) != 0);
86 }
87
Ian Rogers89756f22013-03-04 16:40:02 -080088 bool IsSynchronized() const {
89 return ((access_flags_ & kAccSynchronized) != 0);
90 }
91
92 private:
93 const jobject class_loader_;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070094 ClassLinker* const class_linker_;
Logan Chien4dd96f52012-02-29 01:26:58 +080095
Ian Rogers00f7d0e2012-07-19 15:28:27 -070096 const DexFile* const dex_file_;
Logan Chien4dd96f52012-02-29 01:26:58 +080097
Ian Rogers00f7d0e2012-07-19 15:28:27 -070098 const DexFile::CodeItem* const code_item_;
TDYa127dc5daa02013-01-09 21:31:37 +080099 const uint32_t class_def_idx_;
Ian Rogers89756f22013-03-04 16:40:02 -0800100 const uint32_t dex_method_idx_;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700101 const uint32_t access_flags_;
Logan Chien4dd96f52012-02-29 01:26:58 +0800102};
103
104} // namespace art
105
Ian Rogers89756f22013-03-04 16:40:02 -0800106#endif // ART_SRC_COMPILER_DEX_DEX_COMPILATION_UNIT_H_