blob: def90fa4e109564605a2b352636d6a17f9309dc1 [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"
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 {
Vladimir Markoa2c211c2018-11-01 09:50:52 +000029class Class;
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,
Andreas Gampe3f1dcd32018-12-28 09:39:56 -080041 const dex::CodeItem* code_item,
Mathieu Chartier736b5602015-09-02 14:54:11 -070042 uint16_t class_def_idx,
43 uint32_t method_idx,
44 uint32_t access_flags,
45 const VerifiedMethod* verified_method,
Vladimir Markoa2c211c2018-11-01 09:50:52 +000046 Handle<mirror::DexCache> dex_cache,
47 Handle<mirror::Class> compiling_class = Handle<mirror::Class>());
Brian Carlstrom265091e2013-01-30 14:08:26 -080048
Vladimir Marko8d6768d2017-03-14 10:13:21 +000049 Handle<mirror::ClassLoader> GetClassLoader() const {
Logan Chiendd361c92012-04-10 23:40:37 +080050 return class_loader_;
51 }
52
53 ClassLinker* GetClassLinker() const {
54 return class_linker_;
55 }
56
57 const DexFile* GetDexFile() const {
58 return dex_file_;
59 }
60
Ian Rogersee39a102013-09-19 02:56:49 -070061 uint16_t GetClassDefIndex() const {
TDYa127dc5daa02013-01-09 21:31:37 +080062 return class_def_idx_;
63 }
64
Logan Chiendd361c92012-04-10 23:40:37 +080065 uint32_t GetDexMethodIndex() const {
Ian Rogers89756f22013-03-04 16:40:02 -080066 return dex_method_idx_;
Logan Chiendd361c92012-04-10 23:40:37 +080067 }
68
Andreas Gampe3f1dcd32018-12-28 09:39:56 -080069 const dex::CodeItem* GetCodeItem() const {
Logan Chiendd361c92012-04-10 23:40:37 +080070 return code_item_;
71 }
72
Logan Chienbfe4ea42012-03-01 13:24:17 +080073 const char* GetShorty() const {
Andreas Gampe3f1dcd32018-12-28 09:39:56 -080074 const dex::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_);
Logan Chien61c65dc2012-02-29 03:22:30 +080075 return dex_file_->GetMethodShorty(method_id);
76 }
77
Logan Chienbfe4ea42012-03-01 13:24:17 +080078 const char* GetShorty(uint32_t* shorty_len) const {
Andreas Gampe3f1dcd32018-12-28 09:39:56 -080079 const dex::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_);
Logan Chien61c65dc2012-02-29 03:22:30 +080080 return dex_file_->GetMethodShorty(method_id, shorty_len);
81 }
82
Ian Rogers89756f22013-03-04 16:40:02 -080083 uint32_t GetAccessFlags() const {
84 return access_flags_;
85 }
86
Ian Rogersa49bdff2013-07-31 14:49:16 -070087 bool IsConstructor() const {
88 return ((access_flags_ & kAccConstructor) != 0);
89 }
90
Ian Rogers89756f22013-03-04 16:40:02 -080091 bool IsNative() const {
92 return ((access_flags_ & kAccNative) != 0);
93 }
94
Logan Chiendd361c92012-04-10 23:40:37 +080095 bool IsStatic() const {
96 return ((access_flags_ & kAccStatic) != 0);
97 }
98
Ian Rogers89756f22013-03-04 16:40:02 -080099 bool IsSynchronized() const {
100 return ((access_flags_ & kAccSynchronized) != 0);
101 }
102
Vladimir Marko2730db02014-01-27 11:15:17 +0000103 const VerifiedMethod* GetVerifiedMethod() const {
104 return verified_method_;
105 }
106
Mathieu Chartierab972ef2014-12-03 17:38:22 -0800107 void ClearVerifiedMethod() {
108 verified_method_ = nullptr;
109 }
110
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700111 const std::string& GetSymbol();
Brian Carlstrom265091e2013-01-30 14:08:26 -0800112
Mathieu Chartier736b5602015-09-02 14:54:11 -0700113 Handle<mirror::DexCache> GetDexCache() const {
114 return dex_cache_;
115 }
116
Mathieu Chartier73f21d42018-01-02 14:26:50 -0800117 const CodeItemDataAccessor& GetCodeItemAccessor() const {
118 return code_item_accessor_;
119 }
120
Vladimir Markoa2c211c2018-11-01 09:50:52 +0000121 Handle<mirror::Class> GetCompilingClass() const {
122 return compiling_class_;
123 }
124
Vladimir Markoc1c34522018-10-31 13:56:49 +0000125 // Does this <init> method require a constructor barrier (prior to the return)?
126 // The answer is "yes", if and only if the class has any instance final fields.
127 // (This must not be called for any non-<init> methods; the answer would be "no").
128 //
129 // ---
130 //
131 // JLS 17.5.1 "Semantics of final fields" mandates that all final fields are frozen at the end
132 // of the invoked constructor. The constructor barrier is a conservative implementation means of
133 // enforcing the freezes happen-before the object being constructed is observable by another
134 // thread.
135 //
136 // Note: This question only makes sense for instance constructors;
137 // static constructors (despite possibly having finals) never need
138 // a barrier.
139 //
140 // JLS 12.4.2 "Detailed Initialization Procedure" approximately describes
141 // class initialization as:
142 //
143 // lock(class.lock)
144 // class.state = initializing
145 // unlock(class.lock)
146 //
147 // invoke <clinit>
148 //
149 // lock(class.lock)
150 // class.state = initialized
151 // unlock(class.lock) <-- acts as a release
152 //
153 // The last operation in the above example acts as an atomic release
154 // for any stores in <clinit>, which ends up being stricter
155 // than what a constructor barrier needs.
156 //
157 // See also QuasiAtomic::ThreadFenceForConstructor().
158 bool RequiresConstructorBarrier() const;
159
Ian Rogers89756f22013-03-04 16:40:02 -0800160 private:
Vladimir Marko8d6768d2017-03-14 10:13:21 +0000161 const Handle<mirror::ClassLoader> class_loader_;
Brian Carlstrom265091e2013-01-30 14:08:26 -0800162
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700163 ClassLinker* const class_linker_;
Logan Chien4dd96f52012-02-29 01:26:58 +0800164
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700165 const DexFile* const dex_file_;
Logan Chien4dd96f52012-02-29 01:26:58 +0800166
Andreas Gampe3f1dcd32018-12-28 09:39:56 -0800167 const dex::CodeItem* const code_item_;
Ian Rogersee39a102013-09-19 02:56:49 -0700168 const uint16_t class_def_idx_;
Ian Rogers89756f22013-03-04 16:40:02 -0800169 const uint32_t dex_method_idx_;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700170 const uint32_t access_flags_;
Mathieu Chartierab972ef2014-12-03 17:38:22 -0800171 const VerifiedMethod* verified_method_;
Brian Carlstrom265091e2013-01-30 14:08:26 -0800172
Vladimir Marko8d6768d2017-03-14 10:13:21 +0000173 const Handle<mirror::DexCache> dex_cache_;
Mathieu Chartier736b5602015-09-02 14:54:11 -0700174
Mathieu Chartier73f21d42018-01-02 14:26:50 -0800175 const CodeItemDataAccessor code_item_accessor_;
176
Vladimir Markoa2c211c2018-11-01 09:50:52 +0000177 Handle<mirror::Class> compiling_class_;
178
Ian Rogers1bf8d4d2013-05-30 00:18:49 -0700179 std::string symbol_;
Logan Chien4dd96f52012-02-29 01:26:58 +0800180};
181
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700182} // namespace art
Logan Chien4dd96f52012-02-29 01:26:58 +0800183
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700184#endif // ART_COMPILER_DRIVER_DEX_COMPILATION_UNIT_H_