immune_region.cc revision 0e54cd0d8fc635d3dc8bf88a465fdade151a098f
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 SetBegin(nullptr); 32 SetEnd(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 SetBegin(space_begin); 45 SetEnd(space_limit); 46 } else { 47 if (space_limit <= begin_) { // Space is before the immune region. 48 SetBegin(space_begin); 49 } else if (space_begin >= end_) { // Space is after the immune region. 50 SetEnd(space_limit); 51 } else { 52 return false; 53 } 54 } 55 return true; 56} 57 58bool ImmuneRegion::ContainsSpace(const space::ContinuousSpace* space) const { 59 bool contains = 60 begin_ <= reinterpret_cast<mirror::Object*>(space->Begin()) && 61 end_ >= reinterpret_cast<mirror::Object*>(space->Limit()); 62 if (kIsDebugBuild && contains) { 63 // A bump pointer space shoult not be in the immune region. 64 DCHECK(space->GetType() != space::kSpaceTypeBumpPointerSpace); 65 } 66 return contains; 67} 68 69} // namespace collector 70} // namespace gc 71} // namespace art 72