blob: c1ae3c938bff558eeee67a3cfd92044bee6904d5 [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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_COMPILER_DRIVER_DEX_COMPILATION_UNIT_H_
18#define ART_COMPILER_DRIVER_DEX_COMPILATION_UNIT_H_
Logan Chien4dd96f52012-02-29 01:26:58 +080019
20#include <stdint.h>
21
Vladimir Markoc91df2d2015-04-23 09:29:21 +000022#include "base/arena_object.h"
David Sehr9e734c72018-01-04 17:56:19 -080023#include "dex/code_item_accessors.h"
24#include "dex/dex_file.h"
Mathieu Chartier736b5602015-09-02 14:54:11 -070025#include "handle.h"
26#include "jni.h"
Brian Carlstrom265091e2013-01-30 14:08:26 -080027
Logan Chien4dd96f52012-02-29 01:26:58 +080028namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080029namespace mirror {
Logan Chien4dd96f52012-02-29 01:26:58 +080030class ClassLoader;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080031class DexCache;
32} // namespace mirror
Logan Chien4dd96f52012-02-29 01:26:58 +080033class ClassLinker;
Vladimir Marko2730db02014-01-27 11:15:17 +000034class VerifiedMethod;
Logan Chien4dd96f52012-02-29 01:26:58 +080035
Vladimir Markoc91df2d2015-04-23 09:29:21 +000036class DexCompilationUnit : public DeletableArenaObject<kArenaAllocMisc> {
Logan Chien4dd96f52012-02-29 01:26:58 +080037 public:
Vladimir Marko8d6768d2017-03-14 10:13:21 +000038 DexCompilationUnit(Handle<mirror::ClassLoader> class_loader,
Mathieu Chartier736b5602015-09-02 14:54:11 -070039 ClassLinker* class_linker,
40 const DexFile& dex_file,
41 const DexFile::CodeItem* code_item,
42 uint16_t class_def_idx,
43 uint32_t method_idx,
44 uint32_t access_flags,
45 const VerifiedMethod* verified_method,
46 Handle<mirror::DexCache> dex_cache);
Brian Carlstrom265091e2013-01-30 14:08:26 -080047
Vladimir Marko8d6768d2017-03-14 10:13:21 +000048 Handle<mirror::ClassLoader> GetClassLoader() const {
Logan Chiendd361c92012-04-10 23:40:37 +080049 return class_loader_;
50 }
51
52 ClassLinker* GetClassLinker() const {
53 return class_linker_;
54 }
55
56 const DexFile* GetDexFile() const {
57 return dex_file_;
58 }
59
Ian Rogersee39a102013-09-19 02:56:49 -070060 uint16_t GetClassDefIndex() const {
TDYa127dc5daa02013-01-09 21:31:37 +080061 return class_def_idx_;
62 }
63
Logan Chiendd361c92012-04-10 23:40:37 +080064 uint32_t GetDexMethodIndex() const {
Ian Rogers89756f22013-03-04 16:40:02 -080065 return dex_method_idx_;
Logan Chiendd361c92012-04-10 23:40:37 +080066 }
67
68 const DexFile::CodeItem* GetCodeItem() const {
69 return code_item_;
70 }
71
Logan Chienbfe4ea42012-03-01 13:24:17 +080072 const char* GetShorty() const {
Ian Rogers89756f22013-03-04 16:40:02 -080073 const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_);
Logan Chien61c65dc2012-02-29 03:22:30 +080074 return dex_file_->GetMethodShorty(method_id);
75 }
76
Logan Chienbfe4ea42012-03-01 13:24:17 +080077 const char* GetShorty(uint32_t* shorty_len) const {
Ian Rogers89756f22013-03-04 16:40:02 -080078 const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_);
Logan Chien61c65dc2012-02-29 03:22:30 +080079 return dex_file_->GetMethodShorty(method_id, shorty_len);
80 }
81
Ian Rogers89756f22013-03-04 16:40:02 -080082 uint32_t GetAccessFlags() const {
83 return access_flags_;
84 }
85
Ian Rogersa49bdff2013-07-31 14:49:16 -070086 bool IsConstructor() const {
87 return ((access_flags_ & kAccConstructor) != 0);
88 }
89
Ian Rogers89756f22013-03-04 16:40:02 -080090 bool IsNative() const {
91 return ((access_flags_ & kAccNative) != 0);
92 }
93
Logan Chiendd361c92012-04-10 23:40:37 +080094 bool IsStatic() const {
95 return ((access_flags_ & kAccStatic) != 0);
96 }
97
Ian Rogers89756f22013-03-04 16:40:02 -080098 bool IsSynchronized() const {
99 return ((access_flags_ & kAccSynchronized) != 0);
100 }
101
Vladimir Marko2730db02014-01-27 11:15:17 +0000102 const VerifiedMethod* GetVerifiedMethod() const {
103 return verified_method_;
104 }
105
Mathieu Chartierab972ef2014-12-03 17:38:22 -0800106 void ClearVerifiedMethod() {
107 verified_method_ = nullptr;
108 }
109
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700110 const std::string& GetSymbol();
Brian Carlstrom265091e2013-01-30 14:08:26 -0800111
Mathieu Chartier736b5602015-09-02 14:54:11 -0700112 Handle<mirror::DexCache> GetDexCache() const {
113 return dex_cache_;
114 }
115
Mathieu Chartier73f21d42018-01-02 14:26:50 -0800116 const CodeItemDataAccessor& GetCodeItemAccessor() const {
117 return code_item_accessor_;
118 }
119
Ian Rogers89756f22013-03-04 16:40:02 -0800120 private:
Vladimir Marko8d6768d2017-03-14 10:13:21 +0000121 const Handle<mirror::ClassLoader> class_loader_;
Brian Carlstrom265091e2013-01-30 14:08:26 -0800122
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700123 ClassLinker* const class_linker_;
Logan Chien4dd96f52012-02-29 01:26:58 +0800124
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700125 const DexFile* const dex_file_;
Logan Chien4dd96f52012-02-29 01:26:58 +0800126
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700127 const DexFile::CodeItem* const code_item_;
Ian Rogersee39a102013-09-19 02:56:49 -0700128 const uint16_t class_def_idx_;
Ian Rogers89756f22013-03-04 16:40:02 -0800129 const uint32_t dex_method_idx_;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700130 const uint32_t access_flags_;
Mathieu Chartierab972ef2014-12-03 17:38:22 -0800131 const VerifiedMethod* verified_method_;
Brian Carlstrom265091e2013-01-30 14:08:26 -0800132
Vladimir Marko8d6768d2017-03-14 10:13:21 +0000133 const Handle<mirror::DexCache> dex_cache_;
Mathieu Chartier736b5602015-09-02 14:54:11 -0700134
Mathieu Chartier73f21d42018-01-02 14:26:50 -0800135 const CodeItemDataAccessor code_item_accessor_;
136
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700137 std::string symbol_;
Logan Chien4dd96f52012-02-29 01:26:58 +0800138};
139
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700140} // namespace art
Logan Chien4dd96f52012-02-29 01:26:58 +0800141
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700142#endif // ART_COMPILER_DRIVER_DEX_COMPILATION_UNIT_H_