1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2013 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker *
4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker *
8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker *
10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker */
16*795d594fSAndroid Build Coastguard Worker
17*795d594fSAndroid Build Coastguard Worker #include "dex_compilation_unit.h"
18*795d594fSAndroid Build Coastguard Worker
19*795d594fSAndroid Build Coastguard Worker #include "art_field.h"
20*795d594fSAndroid Build Coastguard Worker #include "base/utils.h"
21*795d594fSAndroid Build Coastguard Worker #include "dex/class_accessor-inl.h"
22*795d594fSAndroid Build Coastguard Worker #include "dex/code_item_accessors-inl.h"
23*795d594fSAndroid Build Coastguard Worker #include "dex/descriptors_names.h"
24*795d594fSAndroid Build Coastguard Worker #include "mirror/class-inl.h"
25*795d594fSAndroid Build Coastguard Worker #include "mirror/dex_cache.h"
26*795d594fSAndroid Build Coastguard Worker #include "scoped_thread_state_change-inl.h"
27*795d594fSAndroid Build Coastguard Worker
28*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN {
29*795d594fSAndroid Build Coastguard Worker
DexCompilationUnit(Handle<mirror::ClassLoader> class_loader,ClassLinker * class_linker,const DexFile & dex_file,const dex::CodeItem * code_item,uint16_t class_def_idx,uint32_t method_idx,uint32_t access_flags,const VerifiedMethod * verified_method,Handle<mirror::DexCache> dex_cache,Handle<mirror::Class> compiling_class)30*795d594fSAndroid Build Coastguard Worker DexCompilationUnit::DexCompilationUnit(Handle<mirror::ClassLoader> class_loader,
31*795d594fSAndroid Build Coastguard Worker ClassLinker* class_linker,
32*795d594fSAndroid Build Coastguard Worker const DexFile& dex_file,
33*795d594fSAndroid Build Coastguard Worker const dex::CodeItem* code_item,
34*795d594fSAndroid Build Coastguard Worker uint16_t class_def_idx,
35*795d594fSAndroid Build Coastguard Worker uint32_t method_idx,
36*795d594fSAndroid Build Coastguard Worker uint32_t access_flags,
37*795d594fSAndroid Build Coastguard Worker const VerifiedMethod* verified_method,
38*795d594fSAndroid Build Coastguard Worker Handle<mirror::DexCache> dex_cache,
39*795d594fSAndroid Build Coastguard Worker Handle<mirror::Class> compiling_class)
40*795d594fSAndroid Build Coastguard Worker : class_loader_(class_loader),
41*795d594fSAndroid Build Coastguard Worker class_linker_(class_linker),
42*795d594fSAndroid Build Coastguard Worker dex_file_(&dex_file),
43*795d594fSAndroid Build Coastguard Worker code_item_(code_item),
44*795d594fSAndroid Build Coastguard Worker class_def_idx_(class_def_idx),
45*795d594fSAndroid Build Coastguard Worker dex_method_idx_(method_idx),
46*795d594fSAndroid Build Coastguard Worker access_flags_(access_flags),
47*795d594fSAndroid Build Coastguard Worker verified_method_(verified_method),
48*795d594fSAndroid Build Coastguard Worker dex_cache_(dex_cache),
49*795d594fSAndroid Build Coastguard Worker code_item_accessor_(dex_file, code_item),
50*795d594fSAndroid Build Coastguard Worker compiling_class_(compiling_class) {}
51*795d594fSAndroid Build Coastguard Worker
GetSymbol()52*795d594fSAndroid Build Coastguard Worker const std::string& DexCompilationUnit::GetSymbol() {
53*795d594fSAndroid Build Coastguard Worker if (symbol_.empty()) {
54*795d594fSAndroid Build Coastguard Worker symbol_ = "dex_";
55*795d594fSAndroid Build Coastguard Worker symbol_ += MangleForJni(dex_file_->PrettyMethod(dex_method_idx_));
56*795d594fSAndroid Build Coastguard Worker }
57*795d594fSAndroid Build Coastguard Worker return symbol_;
58*795d594fSAndroid Build Coastguard Worker }
59*795d594fSAndroid Build Coastguard Worker
RequiresConstructorBarrier() const60*795d594fSAndroid Build Coastguard Worker bool DexCompilationUnit::RequiresConstructorBarrier() const {
61*795d594fSAndroid Build Coastguard Worker // Constructor barriers are applicable only for <init> methods.
62*795d594fSAndroid Build Coastguard Worker DCHECK(!IsStatic());
63*795d594fSAndroid Build Coastguard Worker DCHECK(IsConstructor());
64*795d594fSAndroid Build Coastguard Worker
65*795d594fSAndroid Build Coastguard Worker // We require a constructor barrier if there are final instance fields.
66*795d594fSAndroid Build Coastguard Worker if (GetCompilingClass().GetReference() != nullptr && !GetCompilingClass().IsNull()) {
67*795d594fSAndroid Build Coastguard Worker // Decoding class data can be slow, so iterate over fields of the compiling class if resolved.
68*795d594fSAndroid Build Coastguard Worker ScopedObjectAccess soa(Thread::Current());
69*795d594fSAndroid Build Coastguard Worker ObjPtr<mirror::Class> compiling_class = GetCompilingClass().Get();
70*795d594fSAndroid Build Coastguard Worker for (size_t i = 0, size = compiling_class->NumInstanceFields(); i != size; ++i) {
71*795d594fSAndroid Build Coastguard Worker ArtField* field = compiling_class->GetInstanceField(i);
72*795d594fSAndroid Build Coastguard Worker if (field->IsFinal()) {
73*795d594fSAndroid Build Coastguard Worker return true;
74*795d594fSAndroid Build Coastguard Worker }
75*795d594fSAndroid Build Coastguard Worker }
76*795d594fSAndroid Build Coastguard Worker } else {
77*795d594fSAndroid Build Coastguard Worker // Iterate over field definitions in the class data.
78*795d594fSAndroid Build Coastguard Worker ClassAccessor accessor(*GetDexFile(), GetClassDefIndex());
79*795d594fSAndroid Build Coastguard Worker for (const ClassAccessor::Field& field : accessor.GetInstanceFields()) {
80*795d594fSAndroid Build Coastguard Worker if (field.IsFinal()) {
81*795d594fSAndroid Build Coastguard Worker return true;
82*795d594fSAndroid Build Coastguard Worker }
83*795d594fSAndroid Build Coastguard Worker }
84*795d594fSAndroid Build Coastguard Worker }
85*795d594fSAndroid Build Coastguard Worker return false;
86*795d594fSAndroid Build Coastguard Worker }
87*795d594fSAndroid Build Coastguard Worker
88*795d594fSAndroid Build Coastguard Worker } // namespace art
89