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 #ifndef ART_RUNTIME_GC_SPACE_ZYGOTE_SPACE_H_ 18 #define ART_RUNTIME_GC_SPACE_ZYGOTE_SPACE_H_ 19 20 #include "gc/accounting/space_bitmap.h" 21 #include "malloc_space.h" 22 #include "mem_map.h" 23 24 namespace art { 25 namespace gc { 26 27 namespace space { 28 29 // A zygote space is a space which you cannot allocate into or free from. 30 class ZygoteSpace FINAL : public ContinuousMemMapAllocSpace { 31 public: 32 // Returns the remaining storage in the out_map field. 33 static ZygoteSpace* Create(const std::string& name, MemMap* mem_map, 34 accounting::ContinuousSpaceBitmap* live_bitmap, 35 accounting::ContinuousSpaceBitmap* mark_bitmap) 36 REQUIRES_SHARED(Locks::mutator_lock_); 37 38 void Dump(std::ostream& os) const; 39 GetType()40 SpaceType GetType() const OVERRIDE { 41 return kSpaceTypeZygoteSpace; 42 } 43 AsZygoteSpace()44 ZygoteSpace* AsZygoteSpace() OVERRIDE { 45 return this; 46 } 47 48 mirror::Object* Alloc(Thread* self, size_t num_bytes, size_t* bytes_allocated, 49 size_t* usable_size, size_t* bytes_tl_bulk_allocated) OVERRIDE; 50 51 size_t AllocationSize(mirror::Object* obj, size_t* usable_size) OVERRIDE; 52 53 size_t Free(Thread* self, mirror::Object* ptr) OVERRIDE; 54 55 size_t FreeList(Thread* self, size_t num_ptrs, mirror::Object** ptrs) OVERRIDE; 56 57 // ZygoteSpaces don't have thread local state. RevokeThreadLocalBuffers(art::Thread *)58 size_t RevokeThreadLocalBuffers(art::Thread*) OVERRIDE { 59 return 0U; 60 } RevokeAllThreadLocalBuffers()61 size_t RevokeAllThreadLocalBuffers() OVERRIDE { 62 return 0U; 63 } 64 GetBytesAllocated()65 uint64_t GetBytesAllocated() { 66 return Size(); 67 } 68 GetObjectsAllocated()69 uint64_t GetObjectsAllocated() { 70 return objects_allocated_.LoadSequentiallyConsistent(); 71 } 72 73 void Clear() OVERRIDE; 74 CanMoveObjects()75 bool CanMoveObjects() const OVERRIDE { 76 return false; 77 } 78 79 void LogFragmentationAllocFailure(std::ostream& os, size_t failed_alloc_bytes) OVERRIDE 80 REQUIRES_SHARED(Locks::mutator_lock_); 81 82 protected: GetSweepCallback()83 virtual accounting::ContinuousSpaceBitmap::SweepCallback* GetSweepCallback() { 84 return &SweepCallback; 85 } 86 87 private: 88 ZygoteSpace(const std::string& name, MemMap* mem_map, size_t objects_allocated); 89 static void SweepCallback(size_t num_ptrs, mirror::Object** ptrs, void* arg); 90 91 AtomicInteger objects_allocated_; 92 93 friend class Space; 94 DISALLOW_COPY_AND_ASSIGN(ZygoteSpace); 95 }; 96 97 } // namespace space 98 } // namespace gc 99 } // namespace art 100 101 #endif // ART_RUNTIME_GC_SPACE_ZYGOTE_SPACE_H_ 102