• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "base/mem_map.h"
21 #include "gc/accounting/space_bitmap.h"
22 #include "malloc_space.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,
34                              MemMap&& mem_map,
35                              accounting::ContinuousSpaceBitmap* live_bitmap,
36                              accounting::ContinuousSpaceBitmap* mark_bitmap)
37       REQUIRES_SHARED(Locks::mutator_lock_);
38 
39   void Dump(std::ostream& os) const override;
40 
GetType()41   SpaceType GetType() const override {
42     return kSpaceTypeZygoteSpace;
43   }
44 
AsZygoteSpace()45   ZygoteSpace* AsZygoteSpace() override {
46     return this;
47   }
48 
49   mirror::Object* Alloc(Thread* self, size_t num_bytes, size_t* bytes_allocated,
50                         size_t* usable_size, size_t* bytes_tl_bulk_allocated) override;
51 
52   size_t AllocationSize(mirror::Object* obj, size_t* usable_size) override;
53 
54   size_t Free(Thread* self, mirror::Object* ptr) override;
55 
56   size_t FreeList(Thread* self, size_t num_ptrs, mirror::Object** ptrs) override;
57 
58   // ZygoteSpaces don't have thread local state.
RevokeThreadLocalBuffers(art::Thread *)59   size_t RevokeThreadLocalBuffers(art::Thread*) override {
60     return 0U;
61   }
RevokeAllThreadLocalBuffers()62   size_t RevokeAllThreadLocalBuffers() override {
63     return 0U;
64   }
65 
GetBytesAllocated()66   uint64_t GetBytesAllocated() override {
67     return Size();
68   }
69 
GetObjectsAllocated()70   uint64_t GetObjectsAllocated() override {
71     return objects_allocated_.load();
72   }
73 
74   void Clear() override;
75 
CanMoveObjects()76   bool CanMoveObjects() const override {
77     return false;
78   }
79 
80   void LogFragmentationAllocFailure(std::ostream& os, size_t failed_alloc_bytes) override
81       REQUIRES_SHARED(Locks::mutator_lock_);
82 
83  protected:
GetSweepCallback()84   accounting::ContinuousSpaceBitmap::SweepCallback* GetSweepCallback() override {
85     return &SweepCallback;
86   }
87 
88  private:
89   ZygoteSpace(const std::string& name, MemMap&& mem_map, size_t objects_allocated);
90   static void SweepCallback(size_t num_ptrs, mirror::Object** ptrs, void* arg);
91 
92   AtomicInteger objects_allocated_;
93 
94   friend class Space;
95   DISALLOW_COPY_AND_ASSIGN(ZygoteSpace);
96 };
97 
98 }  // namespace space
99 }  // namespace gc
100 }  // namespace art
101 
102 #endif  // ART_RUNTIME_GC_SPACE_ZYGOTE_SPACE_H_
103