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 #ifndef ART_RUNTIME_VERIFIER_REGISTER_LINE_INL_H_
18*795d594fSAndroid Build Coastguard Worker #define ART_RUNTIME_VERIFIER_REGISTER_LINE_INL_H_
19*795d594fSAndroid Build Coastguard Worker
20*795d594fSAndroid Build Coastguard Worker #include "register_line.h"
21*795d594fSAndroid Build Coastguard Worker
22*795d594fSAndroid Build Coastguard Worker #include "base/logging.h" // For VLOG.
23*795d594fSAndroid Build Coastguard Worker #include "method_verifier.h"
24*795d594fSAndroid Build Coastguard Worker #include "reg_type_cache-inl.h"
25*795d594fSAndroid Build Coastguard Worker
26*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN {
27*795d594fSAndroid Build Coastguard Worker namespace verifier {
28*795d594fSAndroid Build Coastguard Worker
29*795d594fSAndroid Build Coastguard Worker // Should we dump a warning on failures to verify balanced locking? That would be an indication to
30*795d594fSAndroid Build Coastguard Worker // developers that their code will be slow.
31*795d594fSAndroid Build Coastguard Worker static constexpr bool kDumpLockFailures = true;
32*795d594fSAndroid Build Coastguard Worker
GetRegisterTypeId(uint32_t vsrc)33*795d594fSAndroid Build Coastguard Worker inline uint16_t RegisterLine::GetRegisterTypeId(uint32_t vsrc) const {
34*795d594fSAndroid Build Coastguard Worker // The register index was validated during the static pass, so we don't need to check it here.
35*795d594fSAndroid Build Coastguard Worker DCHECK_LT(vsrc, num_regs_);
36*795d594fSAndroid Build Coastguard Worker return line_[vsrc];
37*795d594fSAndroid Build Coastguard Worker }
38*795d594fSAndroid Build Coastguard Worker
GetRegisterType(MethodVerifier * verifier,uint32_t vsrc)39*795d594fSAndroid Build Coastguard Worker inline const RegType& RegisterLine::GetRegisterType(MethodVerifier* verifier, uint32_t vsrc) const {
40*795d594fSAndroid Build Coastguard Worker return verifier->GetRegTypeCache()->GetFromId(GetRegisterTypeId(vsrc));
41*795d594fSAndroid Build Coastguard Worker }
42*795d594fSAndroid Build Coastguard Worker
43*795d594fSAndroid Build Coastguard Worker template <LockOp kLockOp>
SetRegisterTypeImpl(uint32_t vdst,uint16_t new_id)44*795d594fSAndroid Build Coastguard Worker inline void RegisterLine::SetRegisterTypeImpl(uint32_t vdst, uint16_t new_id) {
45*795d594fSAndroid Build Coastguard Worker DCHECK_LT(vdst, num_regs_);
46*795d594fSAndroid Build Coastguard Worker // Note: previously we failed when asked to set a conflict. However, conflicts are OK as long
47*795d594fSAndroid Build Coastguard Worker // as they are not accessed, and our backends can handle this nowadays.
48*795d594fSAndroid Build Coastguard Worker line_[vdst] = new_id;
49*795d594fSAndroid Build Coastguard Worker switch (kLockOp) {
50*795d594fSAndroid Build Coastguard Worker case LockOp::kClear:
51*795d594fSAndroid Build Coastguard Worker // Clear the monitor entry bits for this register.
52*795d594fSAndroid Build Coastguard Worker ClearAllRegToLockDepths(vdst);
53*795d594fSAndroid Build Coastguard Worker break;
54*795d594fSAndroid Build Coastguard Worker case LockOp::kKeep:
55*795d594fSAndroid Build Coastguard Worker break;
56*795d594fSAndroid Build Coastguard Worker }
57*795d594fSAndroid Build Coastguard Worker }
58*795d594fSAndroid Build Coastguard Worker
SetRegisterType(uint32_t vdst,RegType::Kind new_kind)59*795d594fSAndroid Build Coastguard Worker inline void RegisterLine::SetRegisterType(uint32_t vdst, RegType::Kind new_kind) {
60*795d594fSAndroid Build Coastguard Worker DCHECK(!RegType::IsLowHalf(new_kind));
61*795d594fSAndroid Build Coastguard Worker DCHECK(!RegType::IsHighHalf(new_kind));
62*795d594fSAndroid Build Coastguard Worker SetRegisterTypeImpl<LockOp::kClear>(vdst, RegTypeCache::IdForRegKind(new_kind));
63*795d594fSAndroid Build Coastguard Worker }
64*795d594fSAndroid Build Coastguard Worker
65*795d594fSAndroid Build Coastguard Worker template <LockOp kLockOp>
SetRegisterType(uint32_t vdst,const RegType & new_type)66*795d594fSAndroid Build Coastguard Worker inline void RegisterLine::SetRegisterType(uint32_t vdst, const RegType& new_type) {
67*795d594fSAndroid Build Coastguard Worker DCHECK(!new_type.IsLowHalf());
68*795d594fSAndroid Build Coastguard Worker DCHECK(!new_type.IsHighHalf());
69*795d594fSAndroid Build Coastguard Worker // Should only keep locks for reference types.
70*795d594fSAndroid Build Coastguard Worker DCHECK_IMPLIES(kLockOp == LockOp::kKeep, new_type.IsReferenceTypes());
71*795d594fSAndroid Build Coastguard Worker SetRegisterTypeImpl<kLockOp>(vdst, new_type.GetId());
72*795d594fSAndroid Build Coastguard Worker }
73*795d594fSAndroid Build Coastguard Worker
SetRegisterTypeWideImpl(uint32_t vdst,uint16_t new_id1,uint16_t new_id2)74*795d594fSAndroid Build Coastguard Worker inline void RegisterLine::SetRegisterTypeWideImpl(uint32_t vdst,
75*795d594fSAndroid Build Coastguard Worker uint16_t new_id1,
76*795d594fSAndroid Build Coastguard Worker uint16_t new_id2) {
77*795d594fSAndroid Build Coastguard Worker DCHECK_LT(vdst + 1, num_regs_);
78*795d594fSAndroid Build Coastguard Worker line_[vdst] = new_id1;
79*795d594fSAndroid Build Coastguard Worker line_[vdst + 1] = new_id2;
80*795d594fSAndroid Build Coastguard Worker // Clear the monitor entry bits for this register.
81*795d594fSAndroid Build Coastguard Worker ClearAllRegToLockDepths(vdst);
82*795d594fSAndroid Build Coastguard Worker ClearAllRegToLockDepths(vdst + 1);
83*795d594fSAndroid Build Coastguard Worker }
84*795d594fSAndroid Build Coastguard Worker
SetRegisterTypeWide(uint32_t vdst,RegType::Kind new_kind1,RegType::Kind new_kind2)85*795d594fSAndroid Build Coastguard Worker inline void RegisterLine::SetRegisterTypeWide(uint32_t vdst,
86*795d594fSAndroid Build Coastguard Worker RegType::Kind new_kind1,
87*795d594fSAndroid Build Coastguard Worker RegType::Kind new_kind2) {
88*795d594fSAndroid Build Coastguard Worker DCHECK(RegType::CheckWidePair(new_kind1, new_kind2));
89*795d594fSAndroid Build Coastguard Worker SetRegisterTypeWideImpl(
90*795d594fSAndroid Build Coastguard Worker vdst, RegTypeCache::IdForRegKind(new_kind1), RegTypeCache::IdForRegKind(new_kind2));
91*795d594fSAndroid Build Coastguard Worker }
92*795d594fSAndroid Build Coastguard Worker
SetRegisterTypeWide(uint32_t vdst,const RegType & new_type1,const RegType & new_type2)93*795d594fSAndroid Build Coastguard Worker inline void RegisterLine::SetRegisterTypeWide(uint32_t vdst,
94*795d594fSAndroid Build Coastguard Worker const RegType& new_type1,
95*795d594fSAndroid Build Coastguard Worker const RegType& new_type2) {
96*795d594fSAndroid Build Coastguard Worker DCHECK(new_type1.CheckWidePair(new_type2));
97*795d594fSAndroid Build Coastguard Worker SetRegisterTypeWideImpl(vdst, new_type1.GetId(), new_type2.GetId());
98*795d594fSAndroid Build Coastguard Worker }
99*795d594fSAndroid Build Coastguard Worker
SetResultTypeToUnknown(RegTypeCache * reg_types)100*795d594fSAndroid Build Coastguard Worker inline void RegisterLine::SetResultTypeToUnknown(RegTypeCache* reg_types) {
101*795d594fSAndroid Build Coastguard Worker result_[0] = reg_types->Undefined().GetId();
102*795d594fSAndroid Build Coastguard Worker result_[1] = result_[0];
103*795d594fSAndroid Build Coastguard Worker }
104*795d594fSAndroid Build Coastguard Worker
SetResultRegisterType(MethodVerifier * verifier,const RegType & new_type)105*795d594fSAndroid Build Coastguard Worker inline void RegisterLine::SetResultRegisterType(MethodVerifier* verifier, const RegType& new_type) {
106*795d594fSAndroid Build Coastguard Worker DCHECK(!new_type.IsLowHalf());
107*795d594fSAndroid Build Coastguard Worker DCHECK(!new_type.IsHighHalf());
108*795d594fSAndroid Build Coastguard Worker result_[0] = new_type.GetId();
109*795d594fSAndroid Build Coastguard Worker result_[1] = verifier->GetRegTypeCache()->Undefined().GetId();
110*795d594fSAndroid Build Coastguard Worker }
111*795d594fSAndroid Build Coastguard Worker
SetResultRegisterTypeWide(const RegType & new_type1,const RegType & new_type2)112*795d594fSAndroid Build Coastguard Worker inline void RegisterLine::SetResultRegisterTypeWide(const RegType& new_type1,
113*795d594fSAndroid Build Coastguard Worker const RegType& new_type2) {
114*795d594fSAndroid Build Coastguard Worker DCHECK(new_type1.CheckWidePair(new_type2));
115*795d594fSAndroid Build Coastguard Worker result_[0] = new_type1.GetId();
116*795d594fSAndroid Build Coastguard Worker result_[1] = new_type2.GetId();
117*795d594fSAndroid Build Coastguard Worker }
118*795d594fSAndroid Build Coastguard Worker
SetRegisterTypeForNewInstance(uint32_t vdst,const RegType & uninit_type,uint32_t dex_pc)119*795d594fSAndroid Build Coastguard Worker inline void RegisterLine::SetRegisterTypeForNewInstance(uint32_t vdst,
120*795d594fSAndroid Build Coastguard Worker const RegType& uninit_type,
121*795d594fSAndroid Build Coastguard Worker uint32_t dex_pc) {
122*795d594fSAndroid Build Coastguard Worker DCHECK_LT(vdst, num_regs_);
123*795d594fSAndroid Build Coastguard Worker DCHECK(NeedsAllocationDexPc(uninit_type));
124*795d594fSAndroid Build Coastguard Worker SetRegisterType<LockOp::kClear>(vdst, uninit_type);
125*795d594fSAndroid Build Coastguard Worker EnsureAllocationDexPcsAvailable();
126*795d594fSAndroid Build Coastguard Worker allocation_dex_pcs_[vdst] = dex_pc;
127*795d594fSAndroid Build Coastguard Worker }
128*795d594fSAndroid Build Coastguard Worker
CopyRegister1(MethodVerifier * verifier,uint32_t vdst,uint32_t vsrc,TypeCategory cat)129*795d594fSAndroid Build Coastguard Worker inline void RegisterLine::CopyRegister1(MethodVerifier* verifier, uint32_t vdst, uint32_t vsrc,
130*795d594fSAndroid Build Coastguard Worker TypeCategory cat) {
131*795d594fSAndroid Build Coastguard Worker DCHECK(cat == kTypeCategory1nr || cat == kTypeCategoryRef);
132*795d594fSAndroid Build Coastguard Worker const RegType& type = GetRegisterType(verifier, vsrc);
133*795d594fSAndroid Build Coastguard Worker if (type.IsLowHalf() || type.IsHighHalf()) {
134*795d594fSAndroid Build Coastguard Worker verifier->Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "Expected category1 register type not '"
135*795d594fSAndroid Build Coastguard Worker << type << "'";
136*795d594fSAndroid Build Coastguard Worker return;
137*795d594fSAndroid Build Coastguard Worker }
138*795d594fSAndroid Build Coastguard Worker // FIXME: If `vdst == vsrc`, we clear locking information before we try to copy it below. Adding
139*795d594fSAndroid Build Coastguard Worker // `move-object v1, v1` to the middle of `OK.runStraightLine()` in run-test 088 makes it fail.
140*795d594fSAndroid Build Coastguard Worker SetRegisterType<LockOp::kClear>(vdst, type);
141*795d594fSAndroid Build Coastguard Worker if (!type.IsConflict() && // Allow conflicts to be copied around.
142*795d594fSAndroid Build Coastguard Worker ((cat == kTypeCategory1nr && !type.IsCategory1Types()) ||
143*795d594fSAndroid Build Coastguard Worker (cat == kTypeCategoryRef && !type.IsReferenceTypes()))) {
144*795d594fSAndroid Build Coastguard Worker verifier->Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "copy1 v" << vdst << "<-v" << vsrc << " type=" << type
145*795d594fSAndroid Build Coastguard Worker << " cat=" << static_cast<int>(cat);
146*795d594fSAndroid Build Coastguard Worker } else if (cat == kTypeCategoryRef) {
147*795d594fSAndroid Build Coastguard Worker CopyRegToLockDepth(vdst, vsrc);
148*795d594fSAndroid Build Coastguard Worker if (allocation_dex_pcs_ != nullptr) {
149*795d594fSAndroid Build Coastguard Worker // Copy allocation dex pc for uninitialized types. (Copy unused value for other types.)
150*795d594fSAndroid Build Coastguard Worker allocation_dex_pcs_[vdst] = allocation_dex_pcs_[vsrc];
151*795d594fSAndroid Build Coastguard Worker }
152*795d594fSAndroid Build Coastguard Worker }
153*795d594fSAndroid Build Coastguard Worker }
154*795d594fSAndroid Build Coastguard Worker
CopyRegister2(MethodVerifier * verifier,uint32_t vdst,uint32_t vsrc)155*795d594fSAndroid Build Coastguard Worker inline void RegisterLine::CopyRegister2(MethodVerifier* verifier, uint32_t vdst, uint32_t vsrc) {
156*795d594fSAndroid Build Coastguard Worker const RegType& type_l = GetRegisterType(verifier, vsrc);
157*795d594fSAndroid Build Coastguard Worker const RegType& type_h = GetRegisterType(verifier, vsrc + 1);
158*795d594fSAndroid Build Coastguard Worker
159*795d594fSAndroid Build Coastguard Worker if (!type_l.CheckWidePair(type_h)) {
160*795d594fSAndroid Build Coastguard Worker verifier->Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "copy2 v" << vdst << "<-v" << vsrc
161*795d594fSAndroid Build Coastguard Worker << " type=" << type_l << "/" << type_h;
162*795d594fSAndroid Build Coastguard Worker } else {
163*795d594fSAndroid Build Coastguard Worker SetRegisterTypeWide(vdst, type_l, type_h);
164*795d594fSAndroid Build Coastguard Worker }
165*795d594fSAndroid Build Coastguard Worker }
166*795d594fSAndroid Build Coastguard Worker
NeedsAllocationDexPc(const RegType & reg_type)167*795d594fSAndroid Build Coastguard Worker inline bool RegisterLine::NeedsAllocationDexPc(const RegType& reg_type) {
168*795d594fSAndroid Build Coastguard Worker return reg_type.IsUninitializedReference() || reg_type.IsUnresolvedUninitializedReference();
169*795d594fSAndroid Build Coastguard Worker }
170*795d594fSAndroid Build Coastguard Worker
DCheckUniqueNewInstanceDexPc(MethodVerifier * verifier,uint32_t dex_pc)171*795d594fSAndroid Build Coastguard Worker inline void RegisterLine::DCheckUniqueNewInstanceDexPc(MethodVerifier* verifier, uint32_t dex_pc) {
172*795d594fSAndroid Build Coastguard Worker if (kIsDebugBuild && allocation_dex_pcs_ != nullptr) {
173*795d594fSAndroid Build Coastguard Worker // Note: We do not clear the `allocation_dex_pcs_` entries when copying data from
174*795d594fSAndroid Build Coastguard Worker // a register line without `allocation_dex_pcs_`, or when we merge types and find
175*795d594fSAndroid Build Coastguard Worker // a conflict, so the same dex pc can remain in the `allocation_dex_pcs_` array
176*795d594fSAndroid Build Coastguard Worker // but it cannot be recorded for a `new-instance` uninitialized type.
177*795d594fSAndroid Build Coastguard Worker RegTypeCache* reg_types = verifier->GetRegTypeCache();
178*795d594fSAndroid Build Coastguard Worker for (uint32_t i = 0; i != num_regs_; ++i) {
179*795d594fSAndroid Build Coastguard Worker if (NeedsAllocationDexPc(reg_types->GetFromId(line_[i]))) {
180*795d594fSAndroid Build Coastguard Worker CHECK_NE(allocation_dex_pcs_[i], dex_pc) << i << " " << reg_types->GetFromId(line_[i]);
181*795d594fSAndroid Build Coastguard Worker }
182*795d594fSAndroid Build Coastguard Worker }
183*795d594fSAndroid Build Coastguard Worker }
184*795d594fSAndroid Build Coastguard Worker }
185*795d594fSAndroid Build Coastguard Worker
EnsureAllocationDexPcsAvailable()186*795d594fSAndroid Build Coastguard Worker inline void RegisterLine::EnsureAllocationDexPcsAvailable() {
187*795d594fSAndroid Build Coastguard Worker DCHECK_NE(num_regs_, 0u);
188*795d594fSAndroid Build Coastguard Worker if (allocation_dex_pcs_ == nullptr) {
189*795d594fSAndroid Build Coastguard Worker ArenaAllocatorAdapter<uint32_t> allocator(monitors_.get_allocator());
190*795d594fSAndroid Build Coastguard Worker allocation_dex_pcs_ = allocator.allocate(num_regs_);
191*795d594fSAndroid Build Coastguard Worker std::fill_n(allocation_dex_pcs_, num_regs_, kNoDexPc);
192*795d594fSAndroid Build Coastguard Worker }
193*795d594fSAndroid Build Coastguard Worker }
194*795d594fSAndroid Build Coastguard Worker
VerifyMonitorStackEmpty(MethodVerifier * verifier)195*795d594fSAndroid Build Coastguard Worker inline void RegisterLine::VerifyMonitorStackEmpty(MethodVerifier* verifier) const {
196*795d594fSAndroid Build Coastguard Worker if (MonitorStackDepth() != 0) {
197*795d594fSAndroid Build Coastguard Worker verifier->Fail(VERIFY_ERROR_LOCKING, /*pending_exc=*/ false);
198*795d594fSAndroid Build Coastguard Worker if (kDumpLockFailures) {
199*795d594fSAndroid Build Coastguard Worker VLOG(verifier) << "expected empty monitor stack in "
200*795d594fSAndroid Build Coastguard Worker << verifier->GetMethodReference().PrettyMethod();
201*795d594fSAndroid Build Coastguard Worker }
202*795d594fSAndroid Build Coastguard Worker }
203*795d594fSAndroid Build Coastguard Worker }
204*795d594fSAndroid Build Coastguard Worker
ComputeSize(size_t num_regs)205*795d594fSAndroid Build Coastguard Worker inline size_t RegisterLine::ComputeSize(size_t num_regs) {
206*795d594fSAndroid Build Coastguard Worker return OFFSETOF_MEMBER(RegisterLine, line_) + num_regs * sizeof(uint16_t);
207*795d594fSAndroid Build Coastguard Worker }
208*795d594fSAndroid Build Coastguard Worker
Create(size_t num_regs,ArenaAllocator & allocator,RegTypeCache * reg_types)209*795d594fSAndroid Build Coastguard Worker inline RegisterLine* RegisterLine::Create(size_t num_regs,
210*795d594fSAndroid Build Coastguard Worker ArenaAllocator& allocator,
211*795d594fSAndroid Build Coastguard Worker RegTypeCache* reg_types) {
212*795d594fSAndroid Build Coastguard Worker void* memory = allocator.Alloc(ComputeSize(num_regs));
213*795d594fSAndroid Build Coastguard Worker return new (memory) RegisterLine(num_regs, allocator, reg_types);
214*795d594fSAndroid Build Coastguard Worker }
215*795d594fSAndroid Build Coastguard Worker
RegisterLine(size_t num_regs,ArenaAllocator & allocator,RegTypeCache * reg_types)216*795d594fSAndroid Build Coastguard Worker inline RegisterLine::RegisterLine(size_t num_regs,
217*795d594fSAndroid Build Coastguard Worker ArenaAllocator& allocator,
218*795d594fSAndroid Build Coastguard Worker RegTypeCache* reg_types)
219*795d594fSAndroid Build Coastguard Worker : num_regs_(num_regs),
220*795d594fSAndroid Build Coastguard Worker allocation_dex_pcs_(nullptr),
221*795d594fSAndroid Build Coastguard Worker monitors_(allocator.Adapter(kArenaAllocVerifier)),
222*795d594fSAndroid Build Coastguard Worker reg_to_lock_depths_(std::less<uint32_t>(),
223*795d594fSAndroid Build Coastguard Worker allocator.Adapter(kArenaAllocVerifier)),
224*795d594fSAndroid Build Coastguard Worker this_initialized_(false) {
225*795d594fSAndroid Build Coastguard Worker // `ArenaAllocator` guarantees zero-initialization.
226*795d594fSAndroid Build Coastguard Worker static_assert(RegTypeCache::kUndefinedCacheId == 0u);
227*795d594fSAndroid Build Coastguard Worker DCHECK(std::all_of(line_,
228*795d594fSAndroid Build Coastguard Worker line_ + num_regs_,
229*795d594fSAndroid Build Coastguard Worker [](auto id) { return id == RegTypeCache::kUndefinedCacheId;}));
230*795d594fSAndroid Build Coastguard Worker SetResultTypeToUnknown(reg_types);
231*795d594fSAndroid Build Coastguard Worker }
232*795d594fSAndroid Build Coastguard Worker
ClearRegToLockDepth(size_t reg,size_t depth)233*795d594fSAndroid Build Coastguard Worker inline void RegisterLine::ClearRegToLockDepth(size_t reg, size_t depth) {
234*795d594fSAndroid Build Coastguard Worker CHECK_LT(depth, 32u);
235*795d594fSAndroid Build Coastguard Worker DCHECK(IsSetLockDepth(reg, depth));
236*795d594fSAndroid Build Coastguard Worker auto it = reg_to_lock_depths_.find(reg);
237*795d594fSAndroid Build Coastguard Worker DCHECK(it != reg_to_lock_depths_.end());
238*795d594fSAndroid Build Coastguard Worker uint32_t depths = it->second ^ (1 << depth);
239*795d594fSAndroid Build Coastguard Worker if (depths != 0) {
240*795d594fSAndroid Build Coastguard Worker it->second = depths;
241*795d594fSAndroid Build Coastguard Worker } else {
242*795d594fSAndroid Build Coastguard Worker reg_to_lock_depths_.erase(it);
243*795d594fSAndroid Build Coastguard Worker }
244*795d594fSAndroid Build Coastguard Worker // Need to unlock every register at the same lock depth. These are aliased locks.
245*795d594fSAndroid Build Coastguard Worker uint32_t mask = 1 << depth;
246*795d594fSAndroid Build Coastguard Worker for (auto& pair : reg_to_lock_depths_) {
247*795d594fSAndroid Build Coastguard Worker if ((pair.second & mask) != 0) {
248*795d594fSAndroid Build Coastguard Worker VLOG(verifier) << "Also unlocking " << pair.first;
249*795d594fSAndroid Build Coastguard Worker pair.second ^= mask;
250*795d594fSAndroid Build Coastguard Worker }
251*795d594fSAndroid Build Coastguard Worker }
252*795d594fSAndroid Build Coastguard Worker }
253*795d594fSAndroid Build Coastguard Worker
operator()254*795d594fSAndroid Build Coastguard Worker inline void RegisterLineArenaDelete::operator()(RegisterLine* ptr) const {
255*795d594fSAndroid Build Coastguard Worker if (ptr != nullptr) {
256*795d594fSAndroid Build Coastguard Worker uint32_t num_regs = ptr->NumRegs();
257*795d594fSAndroid Build Coastguard Worker uint32_t* allocation_dex_pcs = ptr->allocation_dex_pcs_;
258*795d594fSAndroid Build Coastguard Worker ptr->~RegisterLine();
259*795d594fSAndroid Build Coastguard Worker ProtectMemory(ptr, RegisterLine::ComputeSize(num_regs));
260*795d594fSAndroid Build Coastguard Worker if (allocation_dex_pcs != nullptr) {
261*795d594fSAndroid Build Coastguard Worker struct AllocationDexPcsDelete : ArenaDelete<uint32_t> {
262*795d594fSAndroid Build Coastguard Worker void operator()(uint32_t* ptr, size_t size) {
263*795d594fSAndroid Build Coastguard Worker ProtectMemory(ptr, size);
264*795d594fSAndroid Build Coastguard Worker }
265*795d594fSAndroid Build Coastguard Worker };
266*795d594fSAndroid Build Coastguard Worker AllocationDexPcsDelete()(allocation_dex_pcs, num_regs * sizeof(*allocation_dex_pcs));
267*795d594fSAndroid Build Coastguard Worker }
268*795d594fSAndroid Build Coastguard Worker }
269*795d594fSAndroid Build Coastguard Worker }
270*795d594fSAndroid Build Coastguard Worker
271*795d594fSAndroid Build Coastguard Worker } // namespace verifier
272*795d594fSAndroid Build Coastguard Worker } // namespace art
273*795d594fSAndroid Build Coastguard Worker
274*795d594fSAndroid Build Coastguard Worker #endif // ART_RUNTIME_VERIFIER_REGISTER_LINE_INL_H_
275