immune_region.cc revision 8d562103c3a3452fb15ef4b1c64df767b70507a4
1/* 2 * Copyright (C) 2014 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 17#include "immune_region.h" 18 19#include "gc/space/space-inl.h" 20#include "mirror/object.h" 21 22namespace art { 23namespace gc { 24namespace collector { 25 26ImmuneRegion::ImmuneRegion() { 27 Reset(); 28} 29 30void ImmuneRegion::Reset() { 31 begin_ = nullptr; 32 end_ = nullptr; 33} 34 35bool ImmuneRegion::AddContinuousSpace(space::ContinuousSpace* space) { 36 // Bind live to mark bitmap if necessary. 37 if (space->GetLiveBitmap() != space->GetMarkBitmap()) { 38 CHECK(space->IsContinuousMemMapAllocSpace()); 39 space->AsContinuousMemMapAllocSpace()->BindLiveToMarkBitmap(); 40 } 41 mirror::Object* space_begin = reinterpret_cast<mirror::Object*>(space->Begin()); 42 mirror::Object* space_limit = reinterpret_cast<mirror::Object*>(space->Limit()); 43 if (IsEmpty()) { 44 begin_ = space_begin; 45 end_ = space_limit; 46 } else { 47 if (space_limit <= begin_) { // Space is before the immune region. 48 begin_ = space_begin; 49 } else if (space_begin >= end_) { // Space is after the immune region. 50 end_ = space_limit; 51 } else { 52 return false; 53 } 54 } 55 return true; 56} 57 58bool ImmuneRegion::ContainsSpace(const space::ContinuousSpace* space) const { 59 return 60 begin_ <= reinterpret_cast<mirror::Object*>(space->Begin()) && 61 end_ >= reinterpret_cast<mirror::Object*>(space->Limit()); 62} 63 64} // namespace collector 65} // namespace gc 66} // namespace art 67