1a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier/* 2a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier * Copyright (C) 2014 The Android Open Source Project 3a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier * 4a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier * Licensed under the Apache License, Version 2.0 (the "License"); 5a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier * you may not use this file except in compliance with the License. 6a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier * You may obtain a copy of the License at 7a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier * 8a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier * http://www.apache.org/licenses/LICENSE-2.0 9a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier * 10a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier * Unless required by applicable law or agreed to in writing, software 11a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier * distributed under the License is distributed on an "AS IS" BASIS, 12a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier * See the License for the specific language governing permissions and 14a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier * limitations under the License. 15a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier */ 16a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier 17a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier#ifndef ART_RUNTIME_GC_SPACE_ZYGOTE_SPACE_H_ 18a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier#define ART_RUNTIME_GC_SPACE_ZYGOTE_SPACE_H_ 19a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier 20a8e8f9c0a8e259a807d7b99a148d14104c24209dMathieu Chartier#include "gc/accounting/space_bitmap.h" 21a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier#include "malloc_space.h" 22a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier#include "mem_map.h" 23a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier 24a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartiernamespace art { 25a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartiernamespace gc { 26a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier 27a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartiernamespace space { 28a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier 29a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier// An zygote space is a space which you cannot allocate into or free from. 306fac447555dc94a935b78198479cce645c837b89Ian Rogersclass ZygoteSpace FINAL : public ContinuousMemMapAllocSpace { 31a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier public: 32a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier // Returns the remaining storage in the out_map field. 33a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier static ZygoteSpace* Create(const std::string& name, MemMap* mem_map, 34a8e8f9c0a8e259a807d7b99a148d14104c24209dMathieu Chartier accounting::ContinuousSpaceBitmap* live_bitmap, 35a8e8f9c0a8e259a807d7b99a148d14104c24209dMathieu Chartier accounting::ContinuousSpaceBitmap* mark_bitmap) 36a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 37a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier 38a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier void Dump(std::ostream& os) const; 396fac447555dc94a935b78198479cce645c837b89Ian Rogers 406fac447555dc94a935b78198479cce645c837b89Ian Rogers SpaceType GetType() const OVERRIDE { 41a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier return kSpaceTypeZygoteSpace; 42a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier } 436fac447555dc94a935b78198479cce645c837b89Ian Rogers 446fac447555dc94a935b78198479cce645c837b89Ian Rogers ZygoteSpace* AsZygoteSpace() OVERRIDE { 45a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier return this; 46a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier } 476fac447555dc94a935b78198479cce645c837b89Ian Rogers 486fac447555dc94a935b78198479cce645c837b89Ian Rogers mirror::Object* Alloc(Thread* self, size_t num_bytes, size_t* bytes_allocated, 496fac447555dc94a935b78198479cce645c837b89Ian Rogers size_t* usable_size) OVERRIDE; 506fac447555dc94a935b78198479cce645c837b89Ian Rogers 516fac447555dc94a935b78198479cce645c837b89Ian Rogers size_t AllocationSize(mirror::Object* obj, size_t* usable_size) OVERRIDE; 526fac447555dc94a935b78198479cce645c837b89Ian Rogers 536fac447555dc94a935b78198479cce645c837b89Ian Rogers size_t Free(Thread* self, mirror::Object* ptr) OVERRIDE; 546fac447555dc94a935b78198479cce645c837b89Ian Rogers 556fac447555dc94a935b78198479cce645c837b89Ian Rogers size_t FreeList(Thread* self, size_t num_ptrs, mirror::Object** ptrs) OVERRIDE; 566fac447555dc94a935b78198479cce645c837b89Ian Rogers 576fac447555dc94a935b78198479cce645c837b89Ian Rogers // ZygoteSpaces don't have thread local state. 586fac447555dc94a935b78198479cce645c837b89Ian Rogers void RevokeThreadLocalBuffers(art::Thread*) OVERRIDE { 59a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier } 606fac447555dc94a935b78198479cce645c837b89Ian Rogers void RevokeAllThreadLocalBuffers() OVERRIDE { 61a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier } 626fac447555dc94a935b78198479cce645c837b89Ian Rogers 636fac447555dc94a935b78198479cce645c837b89Ian Rogers uint64_t GetBytesAllocated() { 64a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier return Size(); 65a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier } 666fac447555dc94a935b78198479cce645c837b89Ian Rogers 676fac447555dc94a935b78198479cce645c837b89Ian Rogers uint64_t GetObjectsAllocated() { 683e5cf305db800b2989ad57b7cde8fb3cc9fa1b9eIan Rogers return objects_allocated_.LoadSequentiallyConsistent(); 69a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier } 70a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier 7115d3402bbf8265eb1165694da2e4117eb128f3bcMathieu Chartier void Clear() OVERRIDE; 7231f441464c0c8f840aba37e236ad133f30308d70Mathieu Chartier 7331f441464c0c8f840aba37e236ad133f30308d70Mathieu Chartier bool CanMoveObjects() const OVERRIDE { 7431f441464c0c8f840aba37e236ad133f30308d70Mathieu Chartier return false; 7531f441464c0c8f840aba37e236ad133f30308d70Mathieu Chartier } 766fac447555dc94a935b78198479cce645c837b89Ian Rogers 7738c488bcd41ba632a646d7a1d790ec71a2fcf6faMathieu Chartier void LogFragmentationAllocFailure(std::ostream& os, size_t failed_alloc_bytes) OVERRIDE 7838c488bcd41ba632a646d7a1d790ec71a2fcf6faMathieu Chartier SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 7938c488bcd41ba632a646d7a1d790ec71a2fcf6faMathieu Chartier 80a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier protected: 81a8e8f9c0a8e259a807d7b99a148d14104c24209dMathieu Chartier virtual accounting::ContinuousSpaceBitmap::SweepCallback* GetSweepCallback() { 82a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier return &SweepCallback; 83a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier } 84a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier 85a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier private: 86a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier ZygoteSpace(const std::string& name, MemMap* mem_map, size_t objects_allocated); 87a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier static void SweepCallback(size_t num_ptrs, mirror::Object** ptrs, void* arg); 88a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier 89a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier AtomicInteger objects_allocated_; 90a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier 91a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier friend class Space; 92a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier DISALLOW_COPY_AND_ASSIGN(ZygoteSpace); 93a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier}; 94a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier 95a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier} // namespace space 96a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier} // namespace gc 97a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier} // namespace art 98a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier 99a1602f28c0e3127ad511712d4b08db89737ae901Mathieu Chartier#endif // ART_RUNTIME_GC_SPACE_ZYGOTE_SPACE_H_ 100