blob: 854927d747290960f09666b69670149590e7367b [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;
Vladimir Marko2730db02014-01-27 11:15:17 +000033class VerifiedMethod;
Logan Chien4dd96f52012-02-29 01:26:58 +080034
Vladimir Markoc91df2d2015-04-23 09:29:21 +000035class DexCompilationUnit : public DeletableArenaObject<kArenaAllocMisc> {
Logan Chien4dd96f52012-02-29 01:26:58 +080036 public:
Vladimir Markodf739842016-03-23 16:59:07 +000037 DexCompilationUnit(jobject class_loader,
Mathieu Chartier736b5602015-09-02 14:54:11 -070038 ClassLinker* class_linker,
39 const DexFile& dex_file,
40 const DexFile::CodeItem* code_item,
41 uint16_t class_def_idx,
42 uint32_t method_idx,
43 uint32_t access_flags,
44 const VerifiedMethod* verified_method,
45 Handle<mirror::DexCache> dex_cache);
Brian Carlstrom265091e2013-01-30 14:08:26 -080046
Ian Rogers00f7d0e2012-07-19 15:28:27 -070047 jobject GetClassLoader() const {
Logan Chiendd361c92012-04-10 23:40:37 +080048 return class_loader_;
49 }
50
51 ClassLinker* GetClassLinker() const {
52 return class_linker_;
53 }
54
55 const DexFile* GetDexFile() const {
56 return dex_file_;
57 }
58
Ian Rogersee39a102013-09-19 02:56:49 -070059 uint16_t GetClassDefIndex() const {
TDYa127dc5daa02013-01-09 21:31:37 +080060 return class_def_idx_;
61 }
62
Logan Chiendd361c92012-04-10 23:40:37 +080063 uint32_t GetDexMethodIndex() const {
Ian Rogers89756f22013-03-04 16:40:02 -080064 return dex_method_idx_;
Logan Chiendd361c92012-04-10 23:40:37 +080065 }
66
67 const DexFile::CodeItem* GetCodeItem() const {
68 return code_item_;
69 }
70
Logan Chienbfe4ea42012-03-01 13:24:17 +080071 const char* GetShorty() 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);
74 }
75
Logan Chienbfe4ea42012-03-01 13:24:17 +080076 const char* GetShorty(uint32_t* shorty_len) const {
Ian Rogers89756f22013-03-04 16:40:02 -080077 const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_);
Logan Chien61c65dc2012-02-29 03:22:30 +080078 return dex_file_->GetMethodShorty(method_id, shorty_len);
79 }
80
Ian Rogers89756f22013-03-04 16:40:02 -080081 uint32_t GetAccessFlags() const {
82 return access_flags_;
83 }
84
Ian Rogersa49bdff2013-07-31 14:49:16 -070085 bool IsConstructor() const {
86 return ((access_flags_ & kAccConstructor) != 0);
87 }
88
Ian Rogers89756f22013-03-04 16:40:02 -080089 bool IsNative() const {
90 return ((access_flags_ & kAccNative) != 0);
91 }
92
Logan Chiendd361c92012-04-10 23:40:37 +080093 bool IsStatic() const {
94 return ((access_flags_ & kAccStatic) != 0);
95 }
96
Ian Rogers89756f22013-03-04 16:40:02 -080097 bool IsSynchronized() const {
98 return ((access_flags_ & kAccSynchronized) != 0);
99 }
100
Vladimir Marko2730db02014-01-27 11:15:17 +0000101 const VerifiedMethod* GetVerifiedMethod() const {
102 return verified_method_;
103 }
104
Mathieu Chartierab972ef2014-12-03 17:38:22 -0800105 void ClearVerifiedMethod() {
106 verified_method_ = nullptr;
107 }
108
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700109 const std::string& GetSymbol();
Brian Carlstrom265091e2013-01-30 14:08:26 -0800110
Mathieu Chartier736b5602015-09-02 14:54:11 -0700111 Handle<mirror::DexCache> GetDexCache() const {
112 return dex_cache_;
113 }
114
Ian Rogers89756f22013-03-04 16:40:02 -0800115 private:
116 const jobject class_loader_;
Brian Carlstrom265091e2013-01-30 14:08:26 -0800117
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700118 ClassLinker* const class_linker_;
Logan Chien4dd96f52012-02-29 01:26:58 +0800119
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700120 const DexFile* const dex_file_;
Logan Chien4dd96f52012-02-29 01:26:58 +0800121
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700122 const DexFile::CodeItem* const code_item_;
Ian Rogersee39a102013-09-19 02:56:49 -0700123 const uint16_t class_def_idx_;
Ian Rogers89756f22013-03-04 16:40:02 -0800124 const uint32_t dex_method_idx_;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700125 const uint32_t access_flags_;
Mathieu Chartierab972ef2014-12-03 17:38:22 -0800126 const VerifiedMethod* verified_method_;
Brian Carlstrom265091e2013-01-30 14:08:26 -0800127
Mathieu Chartier736b5602015-09-02 14:54:11 -0700128 Handle<mirror::DexCache> dex_cache_;
129
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700130 std::string symbol_;
Logan Chien4dd96f52012-02-29 01:26:58 +0800131};
132
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700133} // namespace art
Logan Chien4dd96f52012-02-29 01:26:58 +0800134
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700135#endif // ART_COMPILER_DRIVER_DEX_COMPILATION_UNIT_H_