blob: 4d10de8237e5a38f49e4e5a9a0a9c35e5d65ebb0 [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)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070036 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiera1602f22014-01-13 17:19:19 -080037
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,
Hiroshi Yamauchi4460a842015-03-09 11:57:48 -070049 size_t* usable_size, size_t* bytes_tl_bulk_allocated) OVERRIDE;
Ian Rogers6fac4472014-02-25 17:01:10 -080050
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.
Hiroshi Yamauchi4460a842015-03-09 11:57:48 -070058 size_t RevokeThreadLocalBuffers(art::Thread*) OVERRIDE {
59 return 0U;
Mathieu Chartiera1602f22014-01-13 17:19:19 -080060 }
Hiroshi Yamauchi4460a842015-03-09 11:57:48 -070061 size_t RevokeAllThreadLocalBuffers() OVERRIDE {
62 return 0U;
Mathieu Chartiera1602f22014-01-13 17:19:19 -080063 }
Ian Rogers6fac4472014-02-25 17:01:10 -080064
65 uint64_t GetBytesAllocated() {
Mathieu Chartiera1602f22014-01-13 17:19:19 -080066 return Size();
67 }
Ian Rogers6fac4472014-02-25 17:01:10 -080068
69 uint64_t GetObjectsAllocated() {
Ian Rogers3e5cf302014-05-20 16:40:37 -070070 return objects_allocated_.LoadSequentiallyConsistent();
Mathieu Chartiera1602f22014-01-13 17:19:19 -080071 }
72
Mathieu Chartier15d34022014-02-26 17:16:38 -080073 void Clear() OVERRIDE;
Mathieu Chartier31f44142014-04-08 14:40:03 -070074
75 bool CanMoveObjects() const OVERRIDE {
76 return false;
77 }
Ian Rogers6fac4472014-02-25 17:01:10 -080078
Mathieu Chartierb363f662014-07-16 13:28:58 -070079 void LogFragmentationAllocFailure(std::ostream& os, size_t failed_alloc_bytes) OVERRIDE
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070080 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierb363f662014-07-16 13:28:58 -070081
Mathieu Chartiera1602f22014-01-13 17:19:19 -080082 protected:
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070083 virtual accounting::ContinuousSpaceBitmap::SweepCallback* GetSweepCallback() {
Mathieu Chartiera1602f22014-01-13 17:19:19 -080084 return &SweepCallback;
85 }
86
87 private:
88 ZygoteSpace(const std::string& name, MemMap* mem_map, size_t objects_allocated);
89 static void SweepCallback(size_t num_ptrs, mirror::Object** ptrs, void* arg);
90
91 AtomicInteger objects_allocated_;
92
93 friend class Space;
94 DISALLOW_COPY_AND_ASSIGN(ZygoteSpace);
95};
96
97} // namespace space
98} // namespace gc
99} // namespace art
100
101#endif // ART_RUNTIME_GC_SPACE_ZYGOTE_SPACE_H_