blob: 84f57991c335303d9c1801f024c0efe600bcfcaf [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
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;
Ian Rogers33e95662013-05-20 20:29:14 -070031struct CompilationUnit;
Vladimir Marko2730db02014-01-27 11:15:17 +000032class VerifiedMethod;
Logan Chien4dd96f52012-02-29 01:26:58 +080033
Ian Rogers89756f22013-03-04 16:40:02 -080034class DexCompilationUnit {
Logan Chien4dd96f52012-02-29 01:26:58 +080035 public:
Brian Carlstrom93ba8932013-07-17 21:31:49 -070036 explicit DexCompilationUnit(CompilationUnit* cu);
Brian Carlstrom265091e2013-01-30 14:08:26 -080037
38 DexCompilationUnit(CompilationUnit* cu, jobject class_loader, ClassLinker* class_linker,
39 const DexFile& dex_file, const DexFile::CodeItem* code_item,
Vladimir Marko2730db02014-01-27 11:15:17 +000040 uint16_t class_def_idx, uint32_t method_idx, uint32_t access_flags,
41 const VerifiedMethod* verified_method);
Brian Carlstrom265091e2013-01-30 14:08:26 -080042
43 CompilationUnit* GetCompilationUnit() const {
44 return cu_;
Logan Chien4dd96f52012-02-29 01:26:58 +080045 }
46
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
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700105 const std::string& GetSymbol();
Brian Carlstrom265091e2013-01-30 14:08:26 -0800106
Ian Rogers89756f22013-03-04 16:40:02 -0800107 private:
Ian Rogers6282dc12013-04-18 15:54:02 -0700108 CompilationUnit* const cu_;
Brian Carlstrom265091e2013-01-30 14:08:26 -0800109
Ian Rogers89756f22013-03-04 16:40:02 -0800110 const jobject class_loader_;
Brian Carlstrom265091e2013-01-30 14:08:26 -0800111
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700112 ClassLinker* const class_linker_;
Logan Chien4dd96f52012-02-29 01:26:58 +0800113
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700114 const DexFile* const dex_file_;
Logan Chien4dd96f52012-02-29 01:26:58 +0800115
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700116 const DexFile::CodeItem* const code_item_;
Ian Rogersee39a102013-09-19 02:56:49 -0700117 const uint16_t class_def_idx_;
Ian Rogers89756f22013-03-04 16:40:02 -0800118 const uint32_t dex_method_idx_;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700119 const uint32_t access_flags_;
Vladimir Marko2730db02014-01-27 11:15:17 +0000120 const VerifiedMethod* const verified_method_;
Brian Carlstrom265091e2013-01-30 14:08:26 -0800121
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700122 std::string symbol_;
Logan Chien4dd96f52012-02-29 01:26:58 +0800123};
124
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700125} // namespace art
Logan Chien4dd96f52012-02-29 01:26:58 +0800126
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700127#endif // ART_COMPILER_DRIVER_DEX_COMPILATION_UNIT_H_