blob: 0fc112304c027c99c4ee5e35ef821eaf0b2b2529 [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
20#include <stdint.h>
21
Brian Carlstrom265091e2013-01-30 14:08:26 -080022#include "dex_file.h"
23#include "jni.h"
24
Logan Chien4dd96f52012-02-29 01:26:58 +080025namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080026namespace mirror {
Logan Chien4dd96f52012-02-29 01:26:58 +080027class ClassLoader;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080028class DexCache;
29} // namespace mirror
Logan Chien4dd96f52012-02-29 01:26:58 +080030class ClassLinker;
Brian Carlstrom265091e2013-01-30 14:08:26 -080031class CompilationUnit;
Logan Chien4dd96f52012-02-29 01:26:58 +080032
Ian Rogers89756f22013-03-04 16:40:02 -080033class DexCompilationUnit {
Logan Chien4dd96f52012-02-29 01:26:58 +080034 public:
Brian Carlstrom265091e2013-01-30 14:08:26 -080035 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_;
Logan Chien4dd96f52012-02-29 01:26:58 +080043 }
44
Ian Rogers00f7d0e2012-07-19 15:28:27 -070045 jobject GetClassLoader() const {
Logan Chiendd361c92012-04-10 23:40:37 +080046 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
TDYa127dc5daa02013-01-09 21:31:37 +080057 uint32_t GetClassDefIndex() const {
58 return class_def_idx_;
59 }
60
Logan Chiendd361c92012-04-10 23:40:37 +080061 uint32_t GetDexMethodIndex() const {
Ian Rogers89756f22013-03-04 16:40:02 -080062 return dex_method_idx_;
Logan Chiendd361c92012-04-10 23:40:37 +080063 }
64
65 const DexFile::CodeItem* GetCodeItem() const {
66 return code_item_;
67 }
68
Logan Chienbfe4ea42012-03-01 13:24:17 +080069 const char* GetShorty() const {
Ian Rogers89756f22013-03-04 16:40:02 -080070 const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_);
Logan Chien61c65dc2012-02-29 03:22:30 +080071 return dex_file_->GetMethodShorty(method_id);
72 }
73
Logan Chienbfe4ea42012-03-01 13:24:17 +080074 const char* GetShorty(uint32_t* shorty_len) const {
Ian Rogers89756f22013-03-04 16:40:02 -080075 const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_);
Logan Chien61c65dc2012-02-29 03:22:30 +080076 return dex_file_->GetMethodShorty(method_id, shorty_len);
77 }
78
Ian Rogers89756f22013-03-04 16:40:02 -080079 uint32_t GetAccessFlags() const {
80 return access_flags_;
81 }
82
83 bool IsNative() const {
84 return ((access_flags_ & kAccNative) != 0);
85 }
86
Logan Chiendd361c92012-04-10 23:40:37 +080087 bool IsStatic() const {
88 return ((access_flags_ & kAccStatic) != 0);
89 }
90
Ian Rogers89756f22013-03-04 16:40:02 -080091 bool IsSynchronized() const {
92 return ((access_flags_ & kAccSynchronized) != 0);
93 }
94
Brian Carlstrom265091e2013-01-30 14:08:26 -080095 const std::string& GetSymbol() const {
96 return symbol_;
97 }
98
Ian Rogers89756f22013-03-04 16:40:02 -080099 private:
Brian Carlstrom265091e2013-01-30 14:08:26 -0800100 CompilationUnit* cu_;
101
Ian Rogers89756f22013-03-04 16:40:02 -0800102 const jobject class_loader_;
Brian Carlstrom265091e2013-01-30 14:08:26 -0800103
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700104 ClassLinker* const class_linker_;
Logan Chien4dd96f52012-02-29 01:26:58 +0800105
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700106 const DexFile* const dex_file_;
Logan Chien4dd96f52012-02-29 01:26:58 +0800107
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700108 const DexFile::CodeItem* const code_item_;
TDYa127dc5daa02013-01-09 21:31:37 +0800109 const uint32_t class_def_idx_;
Ian Rogers89756f22013-03-04 16:40:02 -0800110 const uint32_t dex_method_idx_;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700111 const uint32_t access_flags_;
Brian Carlstrom265091e2013-01-30 14:08:26 -0800112
113 const std::string symbol_;
Logan Chien4dd96f52012-02-29 01:26:58 +0800114};
115
116} // namespace art
117
Ian Rogers89756f22013-03-04 16:40:02 -0800118#endif // ART_SRC_COMPILER_DEX_DEX_COMPILATION_UNIT_H_