blob: 50fc62b699523e29248f7e279b05ea44c302bbba [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
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070020#include "gc/accounting/space_bitmap.h"
Mathieu Chartiera1602f22014-01-13 17:19:19 -080021#include "malloc_space.h"
22#include "mem_map.h"
23
24namespace art {
25namespace gc {
26
Mathieu Chartiera1602f22014-01-13 17:19:19 -080027namespace space {
28
29// An zygote space is a space which you cannot allocate into or free from.
Ian Rogers6fac4472014-02-25 17:01:10 -080030class ZygoteSpace FINAL : public ContinuousMemMapAllocSpace {
Mathieu Chartiera1602f22014-01-13 17:19:19 -080031 public:
32 // Returns the remaining storage in the out_map field.
33 static ZygoteSpace* Create(const std::string& name, MemMap* mem_map,
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070034 accounting::ContinuousSpaceBitmap* live_bitmap,
35 accounting::ContinuousSpaceBitmap* mark_bitmap)
Mathieu Chartiera1602f22014-01-13 17:19:19 -080036 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
37
38 void Dump(std::ostream& os) const;
Ian Rogers6fac4472014-02-25 17:01:10 -080039
40 SpaceType GetType() const OVERRIDE {
Mathieu Chartiera1602f22014-01-13 17:19:19 -080041 return kSpaceTypeZygoteSpace;
42 }
Ian Rogers6fac4472014-02-25 17:01:10 -080043
44 ZygoteSpace* AsZygoteSpace() OVERRIDE {
Mathieu Chartiera1602f22014-01-13 17:19:19 -080045 return this;
46 }
Ian Rogers6fac4472014-02-25 17:01:10 -080047
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.
58 void RevokeThreadLocalBuffers(art::Thread*) OVERRIDE {
Mathieu Chartiera1602f22014-01-13 17:19:19 -080059 }
Ian Rogers6fac4472014-02-25 17:01:10 -080060 void RevokeAllThreadLocalBuffers() OVERRIDE {
Mathieu Chartiera1602f22014-01-13 17:19:19 -080061 }
Ian Rogers6fac4472014-02-25 17:01:10 -080062
63 uint64_t GetBytesAllocated() {
Mathieu Chartiera1602f22014-01-13 17:19:19 -080064 return Size();
65 }
Ian Rogers6fac4472014-02-25 17:01:10 -080066
67 uint64_t GetObjectsAllocated() {
Mathieu Chartiera1602f22014-01-13 17:19:19 -080068 return objects_allocated_;
69 }
70
Mathieu Chartier15d34022014-02-26 17:16:38 -080071 void Clear() OVERRIDE;
Mathieu Chartier31f44142014-04-08 14:40:03 -070072
73 bool CanMoveObjects() const OVERRIDE {
74 return false;
75 }
Ian Rogers6fac4472014-02-25 17:01:10 -080076
Mathieu Chartiera1602f22014-01-13 17:19:19 -080077 protected:
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070078 virtual accounting::ContinuousSpaceBitmap::SweepCallback* GetSweepCallback() {
Mathieu Chartiera1602f22014-01-13 17:19:19 -080079 return &SweepCallback;
80 }
81
82 private:
83 ZygoteSpace(const std::string& name, MemMap* mem_map, size_t objects_allocated);
84 static void SweepCallback(size_t num_ptrs, mirror::Object** ptrs, void* arg);
85
86 AtomicInteger objects_allocated_;
87
88 friend class Space;
89 DISALLOW_COPY_AND_ASSIGN(ZygoteSpace);
90};
91
92} // namespace space
93} // namespace gc
94} // namespace art
95
96#endif // ART_RUNTIME_GC_SPACE_ZYGOTE_SPACE_H_