blob: 8cd1a9f488967207da84633d86d0ea48565c3168 [file] [log] [blame]
Mathieu Chartiera1602f22014-01-13 17:19:19 -08001/*
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
23namespace art {
24namespace gc {
25
26namespace accounting {
27class SpaceBitmap;
28}
29
30namespace space {
31
32// An zygote space is a space which you cannot allocate into or free from.
Ian Rogers6fac4472014-02-25 17:01:10 -080033class ZygoteSpace FINAL : public ContinuousMemMapAllocSpace {
Mathieu Chartiera1602f22014-01-13 17:19:19 -080034 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;
Ian Rogers6fac4472014-02-25 17:01:10 -080042
43 SpaceType GetType() const OVERRIDE {
Mathieu Chartiera1602f22014-01-13 17:19:19 -080044 return kSpaceTypeZygoteSpace;
45 }
Ian Rogers6fac4472014-02-25 17:01:10 -080046
47 ZygoteSpace* AsZygoteSpace() OVERRIDE {
Mathieu Chartiera1602f22014-01-13 17:19:19 -080048 return this;
49 }
Ian Rogers6fac4472014-02-25 17:01:10 -080050
51 mirror::Object* Alloc(Thread* self, size_t num_bytes, size_t* bytes_allocated,
52 size_t* usable_size) OVERRIDE;
53
54 size_t AllocationSize(mirror::Object* obj, size_t* usable_size) OVERRIDE;
55
56 size_t Free(Thread* self, mirror::Object* ptr) OVERRIDE;
57
58 size_t FreeList(Thread* self, size_t num_ptrs, mirror::Object** ptrs) OVERRIDE;
59
60 // ZygoteSpaces don't have thread local state.
61 void RevokeThreadLocalBuffers(art::Thread*) OVERRIDE {
Mathieu Chartiera1602f22014-01-13 17:19:19 -080062 }
Ian Rogers6fac4472014-02-25 17:01:10 -080063 void RevokeAllThreadLocalBuffers() OVERRIDE {
Mathieu Chartiera1602f22014-01-13 17:19:19 -080064 }
Ian Rogers6fac4472014-02-25 17:01:10 -080065
66 uint64_t GetBytesAllocated() {
Mathieu Chartiera1602f22014-01-13 17:19:19 -080067 return Size();
68 }
Ian Rogers6fac4472014-02-25 17:01:10 -080069
70 uint64_t GetObjectsAllocated() {
Mathieu Chartiera1602f22014-01-13 17:19:19 -080071 return objects_allocated_;
72 }
73
Ian Rogers6fac4472014-02-25 17:01:10 -080074 void Clear();
75
Mathieu Chartiera1602f22014-01-13 17:19:19 -080076 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_