blob: 16872f41f3516362cf63660fcc8b3148876cc45c [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"
Mathieu Chartier736b5602015-09-02 14:54:11 -070023#include "dex_file.h"
24#include "handle.h"
25#include "jni.h"
Brian Carlstrom265091e2013-01-30 14:08:26 -080026
Logan Chien4dd96f52012-02-29 01:26:58 +080027namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080028namespace mirror {
Logan Chien4dd96f52012-02-29 01:26:58 +080029class ClassLoader;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080030class DexCache;
31} // namespace mirror
Logan Chien4dd96f52012-02-29 01:26:58 +080032class ClassLinker;
Ian Rogers33e95662013-05-20 20:29:14 -070033struct CompilationUnit;
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:
Brian Carlstrom93ba8932013-07-17 21:31:49 -070038 explicit DexCompilationUnit(CompilationUnit* cu);
Brian Carlstrom265091e2013-01-30 14:08:26 -080039
Mathieu Chartier736b5602015-09-02 14:54:11 -070040 DexCompilationUnit(CompilationUnit* cu,
41 jobject class_loader,
42 ClassLinker* class_linker,
43 const DexFile& dex_file,
44 const DexFile::CodeItem* code_item,
45 uint16_t class_def_idx,
46 uint32_t method_idx,
47 uint32_t access_flags,
48 const VerifiedMethod* verified_method,
49 Handle<mirror::DexCache> dex_cache);
Brian Carlstrom265091e2013-01-30 14:08:26 -080050
51 CompilationUnit* GetCompilationUnit() const {
52 return cu_;
Logan Chien4dd96f52012-02-29 01:26:58 +080053 }
54
Ian Rogers00f7d0e2012-07-19 15:28:27 -070055 jobject GetClassLoader() const {
Logan Chiendd361c92012-04-10 23:40:37 +080056 return class_loader_;
57 }
58
59 ClassLinker* GetClassLinker() const {
60 return class_linker_;
61 }
62
63 const DexFile* GetDexFile() const {
64 return dex_file_;
65 }
66
Ian Rogersee39a102013-09-19 02:56:49 -070067 uint16_t GetClassDefIndex() const {
TDYa127dc5daa02013-01-09 21:31:37 +080068 return class_def_idx_;
69 }
70
Logan Chiendd361c92012-04-10 23:40:37 +080071 uint32_t GetDexMethodIndex() const {
Ian Rogers89756f22013-03-04 16:40:02 -080072 return dex_method_idx_;
Logan Chiendd361c92012-04-10 23:40:37 +080073 }
74
75 const DexFile::CodeItem* GetCodeItem() const {
76 return code_item_;
77 }
78
Logan Chienbfe4ea42012-03-01 13:24:17 +080079 const char* GetShorty() const {
Ian Rogers89756f22013-03-04 16:40:02 -080080 const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_);
Logan Chien61c65dc2012-02-29 03:22:30 +080081 return dex_file_->GetMethodShorty(method_id);
82 }
83
Logan Chienbfe4ea42012-03-01 13:24:17 +080084 const char* GetShorty(uint32_t* shorty_len) const {
Ian Rogers89756f22013-03-04 16:40:02 -080085 const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_);
Logan Chien61c65dc2012-02-29 03:22:30 +080086 return dex_file_->GetMethodShorty(method_id, shorty_len);
87 }
88
Ian Rogers89756f22013-03-04 16:40:02 -080089 uint32_t GetAccessFlags() const {
90 return access_flags_;
91 }
92
Ian Rogersa49bdff2013-07-31 14:49:16 -070093 bool IsConstructor() const {
94 return ((access_flags_ & kAccConstructor) != 0);
95 }
96
Ian Rogers89756f22013-03-04 16:40:02 -080097 bool IsNative() const {
98 return ((access_flags_ & kAccNative) != 0);
99 }
100
Logan Chiendd361c92012-04-10 23:40:37 +0800101 bool IsStatic() const {
102 return ((access_flags_ & kAccStatic) != 0);
103 }
104
Ian Rogers89756f22013-03-04 16:40:02 -0800105 bool IsSynchronized() const {
106 return ((access_flags_ & kAccSynchronized) != 0);
107 }
108
Vladimir Marko2730db02014-01-27 11:15:17 +0000109 const VerifiedMethod* GetVerifiedMethod() const {
110 return verified_method_;
111 }
112
Mathieu Chartierab972ef2014-12-03 17:38:22 -0800113 void ClearVerifiedMethod() {
114 verified_method_ = nullptr;
115 }
116
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700117 const std::string& GetSymbol();
Brian Carlstrom265091e2013-01-30 14:08:26 -0800118
Mathieu Chartier736b5602015-09-02 14:54:11 -0700119 Handle<mirror::DexCache> GetDexCache() const {
120 return dex_cache_;
121 }
122
Ian Rogers89756f22013-03-04 16:40:02 -0800123 private:
Ian Rogers6282dc12013-04-18 15:54:02 -0700124 CompilationUnit* const cu_;
Brian Carlstrom265091e2013-01-30 14:08:26 -0800125
Ian Rogers89756f22013-03-04 16:40:02 -0800126 const jobject class_loader_;
Brian Carlstrom265091e2013-01-30 14:08:26 -0800127
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700128 ClassLinker* const class_linker_;
Logan Chien4dd96f52012-02-29 01:26:58 +0800129
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700130 const DexFile* const dex_file_;
Logan Chien4dd96f52012-02-29 01:26:58 +0800131
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700132 const DexFile::CodeItem* const code_item_;
Ian Rogersee39a102013-09-19 02:56:49 -0700133 const uint16_t class_def_idx_;
Ian Rogers89756f22013-03-04 16:40:02 -0800134 const uint32_t dex_method_idx_;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700135 const uint32_t access_flags_;
Mathieu Chartierab972ef2014-12-03 17:38:22 -0800136 const VerifiedMethod* verified_method_;
Brian Carlstrom265091e2013-01-30 14:08:26 -0800137
Mathieu Chartier736b5602015-09-02 14:54:11 -0700138 Handle<mirror::DexCache> dex_cache_;
139
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700140 std::string symbol_;
Logan Chien4dd96f52012-02-29 01:26:58 +0800141};
142
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700143} // namespace art
Logan Chien4dd96f52012-02-29 01:26:58 +0800144
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700145#endif // ART_COMPILER_DRIVER_DEX_COMPILATION_UNIT_H_