Mathieu Chartier | a1602f2 | 2014-01-13 17:19:19 -0800 | [diff] [blame] | 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 "malloc_space.h" |
| 21 | #include "mem_map.h" |
| 22 | |
| 23 | namespace art { |
| 24 | namespace gc { |
| 25 | |
| 26 | namespace accounting { |
| 27 | class SpaceBitmap; |
| 28 | } |
| 29 | |
| 30 | namespace space { |
| 31 | |
| 32 | // An zygote space is a space which you cannot allocate into or free from. |
| 33 | class ZygoteSpace : public ContinuousMemMapAllocSpace { |
| 34 | public: |
| 35 | // Returns the remaining storage in the out_map field. |
| 36 | static ZygoteSpace* Create(const std::string& name, MemMap* mem_map, |
| 37 | accounting::SpaceBitmap* live_bitmap, |
| 38 | accounting::SpaceBitmap* mark_bitmap) |
| 39 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 40 | |
| 41 | void Dump(std::ostream& os) const; |
| 42 | virtual SpaceType GetType() const { |
| 43 | return kSpaceTypeZygoteSpace; |
| 44 | } |
| 45 | virtual ZygoteSpace* AsZygoteSpace() { |
| 46 | return this; |
| 47 | } |
| 48 | virtual mirror::Object* AllocWithGrowth(Thread* /*self*/, size_t /*num_bytes*/, |
| 49 | size_t* /*bytes_allocated*/) { |
| 50 | LOG(FATAL) << "Unimplemented"; |
| 51 | return nullptr; |
| 52 | } |
| 53 | virtual mirror::Object* Alloc(Thread* self, size_t num_bytes, size_t* bytes_allocated) { |
| 54 | LOG(FATAL) << "Unimplemented"; |
| 55 | return nullptr; |
| 56 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame^] | 57 | virtual size_t AllocationSize(mirror::Object* obj) { |
Mathieu Chartier | a1602f2 | 2014-01-13 17:19:19 -0800 | [diff] [blame] | 58 | LOG(FATAL) << "Unimplemented"; |
| 59 | return 0; |
| 60 | } |
| 61 | virtual size_t Free(Thread* self, mirror::Object* ptr) { |
| 62 | LOG(FATAL) << "Unimplemented"; |
| 63 | return 0; |
| 64 | } |
| 65 | virtual size_t FreeList(Thread* self, size_t num_ptrs, mirror::Object** ptrs) { |
| 66 | LOG(FATAL) << "Unimplemented"; |
| 67 | return 0; |
| 68 | } |
| 69 | virtual uint64_t GetBytesAllocated() { |
| 70 | return Size(); |
| 71 | } |
| 72 | virtual uint64_t GetObjectsAllocated() { |
| 73 | return objects_allocated_; |
| 74 | } |
| 75 | |
| 76 | protected: |
| 77 | virtual accounting::SpaceBitmap::SweepCallback* GetSweepCallback() { |
| 78 | return &SweepCallback; |
| 79 | } |
| 80 | |
| 81 | private: |
| 82 | ZygoteSpace(const std::string& name, MemMap* mem_map, size_t objects_allocated); |
| 83 | static void SweepCallback(size_t num_ptrs, mirror::Object** ptrs, void* arg); |
| 84 | |
| 85 | AtomicInteger objects_allocated_; |
| 86 | |
| 87 | friend class Space; |
| 88 | DISALLOW_COPY_AND_ASSIGN(ZygoteSpace); |
| 89 | }; |
| 90 | |
| 91 | } // namespace space |
| 92 | } // namespace gc |
| 93 | } // namespace art |
| 94 | |
| 95 | #endif // ART_RUNTIME_GC_SPACE_ZYGOTE_SPACE_H_ |