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 // An 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 SHARED_LOCKS_REQUIRED(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) 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 void RevokeThreadLocalBuffers(art::Thread*) OVERRIDE { 59 } RevokeAllThreadLocalBuffers()60 void RevokeAllThreadLocalBuffers() OVERRIDE { 61 } 62 GetBytesAllocated()63 uint64_t GetBytesAllocated() { 64 return Size(); 65 } 66 GetObjectsAllocated()67 uint64_t GetObjectsAllocated() { 68 return objects_allocated_.LoadSequentiallyConsistent(); 69 } 70 71 void Clear() OVERRIDE; 72 CanMoveObjects()73 bool CanMoveObjects() const OVERRIDE { 74 return false; 75 } 76 77 void LogFragmentationAllocFailure(std::ostream& os, size_t failed_alloc_bytes) OVERRIDE 78 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 79 80 protected: GetSweepCallback()81 virtual accounting::ContinuousSpaceBitmap::SweepCallback* GetSweepCallback() { 82 return &SweepCallback; 83 } 84 85 private: 86 ZygoteSpace(const std::string& name, MemMap* mem_map, size_t objects_allocated); 87 static void SweepCallback(size_t num_ptrs, mirror::Object** ptrs, void* arg); 88 89 AtomicInteger objects_allocated_; 90 91 friend class Space; 92 DISALLOW_COPY_AND_ASSIGN(ZygoteSpace); 93 }; 94 95 } // namespace space 96 } // namespace gc 97 } // namespace art 98 99 #endif // ART_RUNTIME_GC_SPACE_ZYGOTE_SPACE_H_ 100