Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | */ |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 16 | |
| 17 | #ifndef ART_SRC_HEAP_H_ |
| 18 | #define ART_SRC_HEAP_H_ |
| 19 | |
Elliott Hughes | c967f78 | 2012-04-16 10:23:15 -0700 | [diff] [blame] | 20 | #include <iosfwd> |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 21 | #include <string> |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 22 | #include <vector> |
| 23 | |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 24 | #include "atomic_integer.h" |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 25 | #include "gc/atomic_stack.h" |
| 26 | #include "gc/card_table.h" |
| 27 | #include "gc/heap_bitmap.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 28 | #include "globals.h" |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 29 | #include "gtest/gtest.h" |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 30 | #include "locks.h" |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 31 | #include "offsets.h" |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 32 | #include "safe_map.h" |
Mathieu Chartier | 0325e62 | 2012-09-05 14:22:51 -0700 | [diff] [blame] | 33 | #include "timing_logger.h" |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 34 | #include "thread_pool.h" |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 35 | |
Elliott Hughes | 3e465b1 | 2011-09-02 18:26:12 -0700 | [diff] [blame] | 36 | #define VERIFY_OBJECT_ENABLED 0 |
| 37 | |
Mathieu Chartier | dcf8d72 | 2012-08-02 14:55:54 -0700 | [diff] [blame] | 38 | // Fast verification means we do not verify the classes of objects. |
| 39 | #define VERIFY_OBJECT_FAST 1 |
| 40 | |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 41 | namespace art { |
| 42 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 43 | class AllocSpace; |
Brian Carlstrom | a40f9bc | 2011-07-26 21:26:07 -0700 | [diff] [blame] | 44 | class Class; |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 45 | class ConditionVariable; |
Mathieu Chartier | 1c23e1e | 2012-10-12 14:14:11 -0700 | [diff] [blame] | 46 | class DlMallocSpace; |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 47 | class GarbageCollector; |
Mathieu Chartier | 5301cd2 | 2012-05-31 12:11:36 -0700 | [diff] [blame] | 48 | class HeapBitmap; |
Brian Carlstrom | fddf6f6 | 2012-03-15 16:56:45 -0700 | [diff] [blame] | 49 | class ImageSpace; |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 50 | class LargeObjectSpace; |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 51 | class MarkSweep; |
Mathieu Chartier | b43b7d4 | 2012-06-19 13:15:09 -0700 | [diff] [blame] | 52 | class ModUnionTable; |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 53 | class Mutex; |
Brian Carlstrom | a40f9bc | 2011-07-26 21:26:07 -0700 | [diff] [blame] | 54 | class Object; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 55 | class Space; |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 56 | class SpaceTest; |
Ian Rogers | 40e3bac | 2012-11-20 00:09:14 -0800 | [diff] [blame] | 57 | class StackVisitor; |
Mathieu Chartier | 5301cd2 | 2012-05-31 12:11:36 -0700 | [diff] [blame] | 58 | class Thread; |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 59 | class TimingLogger; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 60 | |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 61 | typedef AtomicStack<Object*> ObjectStack; |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 62 | typedef std::vector<ContinuousSpace*> Spaces; |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 63 | |
Mathieu Chartier | d22d548 | 2012-11-06 17:14:12 -0800 | [diff] [blame] | 64 | class AgeCardVisitor { |
| 65 | public: |
| 66 | byte operator ()(byte card) const { |
| 67 | if (card == CardTable::kCardDirty) { |
| 68 | return card - 1; |
| 69 | } else { |
| 70 | return 0; |
| 71 | } |
| 72 | } |
| 73 | }; |
| 74 | |
Mathieu Chartier | 866fb2a | 2012-09-10 10:47:49 -0700 | [diff] [blame] | 75 | // The ordering of the enum matters, it is used to determine which GCs are run first. |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 76 | enum GcType { |
Mathieu Chartier | 866fb2a | 2012-09-10 10:47:49 -0700 | [diff] [blame] | 77 | // No Gc |
| 78 | kGcTypeNone, |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 79 | // Sticky mark bits "generational" GC. |
Mathieu Chartier | 0325e62 | 2012-09-05 14:22:51 -0700 | [diff] [blame] | 80 | kGcTypeSticky, |
| 81 | // Partial GC, over only the alloc space. |
| 82 | kGcTypePartial, |
Mathieu Chartier | 866fb2a | 2012-09-10 10:47:49 -0700 | [diff] [blame] | 83 | // Full GC |
| 84 | kGcTypeFull, |
Mathieu Chartier | 0325e62 | 2012-09-05 14:22:51 -0700 | [diff] [blame] | 85 | // Number of different Gc types. |
| 86 | kGcTypeMax, |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 87 | }; |
Mathieu Chartier | fd678be | 2012-08-30 14:50:54 -0700 | [diff] [blame] | 88 | std::ostream& operator<<(std::ostream& os, const GcType& policy); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 89 | |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 90 | enum GcCause { |
| 91 | kGcCauseForAlloc, |
| 92 | kGcCauseBackground, |
| 93 | kGcCauseExplicit, |
| 94 | }; |
| 95 | std::ostream& operator<<(std::ostream& os, const GcCause& policy); |
| 96 | |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 97 | class Heap { |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 98 | public: |
Mathieu Chartier | 0051be6 | 2012-10-12 17:47:11 -0700 | [diff] [blame] | 99 | static const size_t kDefaultInitialSize = 2 * MB; |
| 100 | static const size_t kDefaultMaximumSize = 32 * MB; |
| 101 | static const size_t kDefaultMaxFree = 2 * MB; |
| 102 | static const size_t kDefaultMinFree = kDefaultMaxFree / 4; |
| 103 | |
| 104 | // Default target utilization. |
| 105 | static const double kDefaultTargetUtilization; |
| 106 | |
Mathieu Chartier | 155dfe9 | 2012-10-09 14:24:49 -0700 | [diff] [blame] | 107 | // Used so that we don't overflow the allocation time atomic integer. |
| 108 | static const size_t kTimeAdjust = 1024; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 109 | |
Elliott Hughes | 410c0c8 | 2011-09-01 17:58:25 -0700 | [diff] [blame] | 110 | typedef void (RootVisitor)(const Object* root, void* arg); |
Mathieu Chartier | 6f1c949 | 2012-10-15 12:08:41 -0700 | [diff] [blame] | 111 | typedef void (VerifyRootVisitor)(const Object* root, void* arg, size_t vreg, |
Ian Rogers | 40e3bac | 2012-11-20 00:09:14 -0800 | [diff] [blame] | 112 | const StackVisitor* visitor); |
Elliott Hughes | c33a32b | 2011-10-11 18:18:07 -0700 | [diff] [blame] | 113 | typedef bool (IsMarkedTester)(const Object* object, void* arg); |
Brian Carlstrom | 7e93b50 | 2011-08-04 14:16:22 -0700 | [diff] [blame] | 114 | |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 115 | // Create a heap with the requested sizes. The possible empty |
| 116 | // image_file_names names specify Spaces to load based on |
| 117 | // ImageWriter output. |
Mathieu Chartier | 0051be6 | 2012-10-12 17:47:11 -0700 | [diff] [blame] | 118 | explicit Heap(size_t initial_size, size_t growth_limit, size_t min_free, |
| 119 | size_t max_free, double target_utilization, size_t capacity, |
| 120 | const std::string& original_image_file_name, bool concurrent_gc); |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 121 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 122 | ~Heap(); |
Brian Carlstrom | a7f4f48 | 2011-07-17 17:01:34 -0700 | [diff] [blame] | 123 | |
Brian Carlstrom | a40f9bc | 2011-07-26 21:26:07 -0700 | [diff] [blame] | 124 | // Allocates and initializes storage for an object instance. |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 125 | Object* AllocObject(Thread* self, Class* klass, size_t num_bytes) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 126 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | a7f4f48 | 2011-07-17 17:01:34 -0700 | [diff] [blame] | 127 | |
Elliott Hughes | a250199 | 2011-08-26 19:39:54 -0700 | [diff] [blame] | 128 | // Check sanity of given reference. Requires the heap lock. |
Elliott Hughes | 3e465b1 | 2011-09-02 18:26:12 -0700 | [diff] [blame] | 129 | #if VERIFY_OBJECT_ENABLED |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 130 | void VerifyObject(const Object* o); |
Elliott Hughes | 3e465b1 | 2011-09-02 18:26:12 -0700 | [diff] [blame] | 131 | #else |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 132 | void VerifyObject(const Object*) {} |
Elliott Hughes | 3e465b1 | 2011-09-02 18:26:12 -0700 | [diff] [blame] | 133 | #endif |
Ian Rogers | 408f79a | 2011-08-23 18:22:33 -0700 | [diff] [blame] | 134 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 135 | // Check sanity of all live references. Requires the heap lock. |
Ian Rogers | f0bbeab | 2012-10-10 18:26:27 -0700 | [diff] [blame] | 136 | void VerifyHeap() LOCKS_EXCLUDED(Locks::heap_bitmap_lock_); |
Mathieu Chartier | fd678be | 2012-08-30 14:50:54 -0700 | [diff] [blame] | 137 | static void RootMatchesObjectVisitor(const Object* root, void* arg); |
Mathieu Chartier | c7b83a0 | 2012-09-11 18:07:39 -0700 | [diff] [blame] | 138 | bool VerifyHeapReferences() |
| 139 | EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) |
| 140 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 141 | bool VerifyMissingCardMarks() |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 142 | EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) |
| 143 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 144 | |
Elliott Hughes | 6a5bd49 | 2011-10-28 14:33:57 -0700 | [diff] [blame] | 145 | // A weaker test than IsLiveObject or VerifyObject that doesn't require the heap lock, |
Elliott Hughes | a250199 | 2011-08-26 19:39:54 -0700 | [diff] [blame] | 146 | // and doesn't abort on error, allowing the caller to report more |
| 147 | // meaningful diagnostics. |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 148 | bool IsHeapAddress(const Object* obj); |
| 149 | |
Elliott Hughes | 6a5bd49 | 2011-10-28 14:33:57 -0700 | [diff] [blame] | 150 | // Returns true if 'obj' is a live heap object, false otherwise (including for invalid addresses). |
| 151 | // Requires the heap lock to be held. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 152 | bool IsLiveObjectLocked(const Object* obj) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 153 | SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); |
Elliott Hughes | a250199 | 2011-08-26 19:39:54 -0700 | [diff] [blame] | 154 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 155 | // Initiates an explicit garbage collection. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 156 | void CollectGarbage(bool clear_soft_references) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 157 | LOCKS_EXCLUDED(Locks::mutator_lock_); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 158 | |
Mathieu Chartier | 7664f5c | 2012-06-08 18:15:32 -0700 | [diff] [blame] | 159 | // Does a concurrent GC, should only be called by the GC daemon thread |
| 160 | // through runtime. |
Ian Rogers | f0bbeab | 2012-10-10 18:26:27 -0700 | [diff] [blame] | 161 | void ConcurrentGC(Thread* self) LOCKS_EXCLUDED(Locks::runtime_shutdown_lock_); |
Mathieu Chartier | 7664f5c | 2012-06-08 18:15:32 -0700 | [diff] [blame] | 162 | |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 163 | // Implements java.lang.Runtime.maxMemory. |
Mathieu Chartier | 155dfe9 | 2012-10-09 14:24:49 -0700 | [diff] [blame] | 164 | int64_t GetMaxMemory() const; |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 165 | // Implements java.lang.Runtime.totalMemory. |
Mathieu Chartier | 155dfe9 | 2012-10-09 14:24:49 -0700 | [diff] [blame] | 166 | int64_t GetTotalMemory() const; |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 167 | // Implements java.lang.Runtime.freeMemory. |
Mathieu Chartier | 155dfe9 | 2012-10-09 14:24:49 -0700 | [diff] [blame] | 168 | int64_t GetFreeMemory() const; |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 169 | |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 170 | // Implements VMDebug.countInstancesOfClass. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 171 | int64_t CountInstances(Class* c, bool count_assignable) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 172 | LOCKS_EXCLUDED(Locks::heap_bitmap_lock_) |
| 173 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 174 | |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 175 | // Removes the growth limit on the alloc space so it may grow to its maximum capacity. Used to |
| 176 | // implement dalvik.system.VMRuntime.clearGrowthLimit. |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 177 | void ClearGrowthLimit(); |
jeffhao | c116070 | 2011-10-27 15:48:45 -0700 | [diff] [blame] | 178 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 179 | // Target ideal heap utilization ratio, implements |
| 180 | // dalvik.system.VMRuntime.getTargetHeapUtilization. |
Mathieu Chartier | 0051be6 | 2012-10-12 17:47:11 -0700 | [diff] [blame] | 181 | double GetTargetHeapUtilization() const { |
| 182 | return target_utilization_; |
| 183 | } |
Mathieu Chartier | 155dfe9 | 2012-10-09 14:24:49 -0700 | [diff] [blame] | 184 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 185 | // Set target ideal heap utilization ratio, implements |
| 186 | // dalvik.system.VMRuntime.setTargetHeapUtilization. |
Mathieu Chartier | 155dfe9 | 2012-10-09 14:24:49 -0700 | [diff] [blame] | 187 | void SetTargetHeapUtilization(float target); |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 188 | |
| 189 | // For the alloc space, sets the maximum number of bytes that the heap is allowed to allocate |
| 190 | // from the system. Doesn't allow the space to exceed its growth limit. |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 191 | void SetIdealFootprint(size_t max_allowed_footprint); |
Elliott Hughes | 7ede61e | 2011-09-14 18:18:06 -0700 | [diff] [blame] | 192 | |
Mathieu Chartier | fc8cfac | 2012-06-19 11:56:36 -0700 | [diff] [blame] | 193 | // Blocks the caller until the garbage collector becomes idle and returns |
| 194 | // true if we waited for the GC to complete. |
Ian Rogers | f0bbeab | 2012-10-10 18:26:27 -0700 | [diff] [blame] | 195 | GcType WaitForConcurrentGcToComplete(Thread* self) LOCKS_EXCLUDED(gc_complete_lock_); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 196 | |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 197 | const Spaces& GetSpaces() const { |
| 198 | return spaces_; |
| 199 | } |
| 200 | |
| 201 | Spaces& GetSpaces() { |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 202 | return spaces_; |
| 203 | } |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 204 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 205 | void SetReferenceOffsets(MemberOffset reference_referent_offset, |
| 206 | MemberOffset reference_queue_offset, |
| 207 | MemberOffset reference_queueNext_offset, |
| 208 | MemberOffset reference_pendingNext_offset, |
| 209 | MemberOffset finalizer_reference_zombie_offset); |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 210 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 211 | Object* GetReferenceReferent(Object* reference); |
Ian Rogers | 23435d0 | 2012-09-24 11:23:12 -0700 | [diff] [blame] | 212 | void ClearReferenceReferent(Object* reference) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 213 | |
Elliott Hughes | adb460d | 2011-10-05 17:02:34 -0700 | [diff] [blame] | 214 | // Returns true if the reference object has not yet been enqueued. |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 215 | bool IsEnqueuable(const Object* ref); |
Ian Rogers | 23435d0 | 2012-09-24 11:23:12 -0700 | [diff] [blame] | 216 | void EnqueueReference(Object* ref, Object** list) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 217 | void EnqueuePendingReference(Object* ref, Object** list) |
| 218 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 219 | Object* DequeuePendingReference(Object** list) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 220 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 221 | MemberOffset GetReferencePendingNextOffset() { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 222 | DCHECK_NE(reference_pendingNext_offset_.Uint32Value(), 0U); |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 223 | return reference_pendingNext_offset_; |
| 224 | } |
| 225 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 226 | MemberOffset GetFinalizerReferenceZombieOffset() { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 227 | DCHECK_NE(finalizer_reference_zombie_offset_.Uint32Value(), 0U); |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 228 | return finalizer_reference_zombie_offset_; |
| 229 | } |
| 230 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 231 | void EnableObjectValidation() { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 232 | #if VERIFY_OBJECT_ENABLED |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 233 | VerifyHeap(); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 234 | #endif |
Elliott Hughes | 85d1545 | 2011-09-16 17:33:01 -0700 | [diff] [blame] | 235 | verify_objects_ = true; |
| 236 | } |
| 237 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 238 | void DisableObjectValidation() { |
Elliott Hughes | 85d1545 | 2011-09-16 17:33:01 -0700 | [diff] [blame] | 239 | verify_objects_ = false; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Ian Rogers | 23435d0 | 2012-09-24 11:23:12 -0700 | [diff] [blame] | 242 | bool IsObjectValidationEnabled() const { |
| 243 | return verify_objects_; |
| 244 | } |
| 245 | |
Mathieu Chartier | 037813d | 2012-08-23 16:44:59 -0700 | [diff] [blame] | 246 | void RecordFree(size_t freed_objects, size_t freed_bytes); |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 247 | |
Elliott Hughes | 5ea047b | 2011-09-13 14:38:18 -0700 | [diff] [blame] | 248 | // Must be called if a field of an Object in the heap changes, and before any GC safe-point. |
| 249 | // The call is not needed if NULL is stored in the field. |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 250 | void WriteBarrierField(const Object* dst, MemberOffset /*offset*/, const Object* /*new_value*/) { |
Mathieu Chartier | e35517a | 2012-10-30 18:49:55 -0700 | [diff] [blame] | 251 | card_table_->MarkCard(dst); |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | // Write barrier for array operations that update many field positions |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 255 | void WriteBarrierArray(const Object* dst, int /*start_offset*/, |
| 256 | size_t /*length TODO: element_count or byte_count?*/) { |
Mathieu Chartier | e35517a | 2012-10-30 18:49:55 -0700 | [diff] [blame] | 257 | card_table_->MarkCard(dst); |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 260 | CardTable* GetCardTable() { |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 261 | return card_table_.get(); |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 264 | void AddFinalizerReference(Thread* self, Object* object); |
Elliott Hughes | adb460d | 2011-10-05 17:02:34 -0700 | [diff] [blame] | 265 | |
Mathieu Chartier | 037813d | 2012-08-23 16:44:59 -0700 | [diff] [blame] | 266 | size_t GetBytesAllocated() const; |
| 267 | size_t GetObjectsAllocated() const; |
| 268 | size_t GetConcurrentStartSize() const; |
| 269 | size_t GetConcurrentMinFree() const; |
| 270 | size_t GetUsedMemorySize() const; |
Mathieu Chartier | 7664f5c | 2012-06-08 18:15:32 -0700 | [diff] [blame] | 271 | |
Mathieu Chartier | 155dfe9 | 2012-10-09 14:24:49 -0700 | [diff] [blame] | 272 | // Returns the total number of objects allocated since the heap was created. |
| 273 | size_t GetTotalObjectsAllocated() const; |
| 274 | |
| 275 | // Returns the total number of bytes allocated since the heap was created. |
| 276 | size_t GetTotalBytesAllocated() const; |
| 277 | |
| 278 | // Returns the total number of objects freed since the heap was created. |
| 279 | size_t GetTotalObjectsFreed() const; |
| 280 | |
| 281 | // Returns the total number of bytes freed since the heap was created. |
| 282 | size_t GetTotalBytesFreed() const; |
| 283 | |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 284 | // Functions for getting the bitmap which corresponds to an object's address. |
| 285 | // This is probably slow, TODO: use better data structure like binary tree . |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 286 | ContinuousSpace* FindSpaceFromObject(const Object*) const; |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 287 | |
Mathieu Chartier | 037813d | 2012-08-23 16:44:59 -0700 | [diff] [blame] | 288 | void DumpForSigQuit(std::ostream& os); |
Elliott Hughes | c967f78 | 2012-04-16 10:23:15 -0700 | [diff] [blame] | 289 | |
Mathieu Chartier | 3056d0c | 2012-10-19 10:49:56 -0700 | [diff] [blame] | 290 | void Trim(); |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 291 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 292 | HeapBitmap* GetLiveBitmap() SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) { |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 293 | return live_bitmap_.get(); |
| 294 | } |
| 295 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 296 | HeapBitmap* GetMarkBitmap() SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) { |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 297 | return mark_bitmap_.get(); |
| 298 | } |
| 299 | |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 300 | ObjectStack* GetLiveStack() SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) { |
| 301 | return live_stack_.get(); |
| 302 | } |
| 303 | |
Ian Rogers | f0bbeab | 2012-10-10 18:26:27 -0700 | [diff] [blame] | 304 | void PreZygoteFork() LOCKS_EXCLUDED(Locks::heap_bitmap_lock_); |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 305 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 306 | // Mark and empty stack. |
| 307 | void FlushAllocStack() |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 308 | EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 309 | |
Mathieu Chartier | c7b83a0 | 2012-09-11 18:07:39 -0700 | [diff] [blame] | 310 | // Mark all the objects in the allocation stack in the specified bitmap. |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 311 | void MarkAllocStack(SpaceBitmap* bitmap, SpaceSetMap* large_objects, ObjectStack* stack) |
Mathieu Chartier | c7b83a0 | 2012-09-11 18:07:39 -0700 | [diff] [blame] | 312 | EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 313 | |
Mathieu Chartier | c7b83a0 | 2012-09-11 18:07:39 -0700 | [diff] [blame] | 314 | // Unmark all the objects in the allocation stack in the specified bitmap. |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 315 | void UnMarkAllocStack(SpaceBitmap* bitmap, SpaceSetMap* large_objects, ObjectStack* stack) |
Mathieu Chartier | c7b83a0 | 2012-09-11 18:07:39 -0700 | [diff] [blame] | 316 | EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); |
Mathieu Chartier | fd678be | 2012-08-30 14:50:54 -0700 | [diff] [blame] | 317 | |
| 318 | // Update and mark mod union table based on gc type. |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 319 | void UpdateAndMarkModUnion(MarkSweep* mark_sweep, TimingLogger& timings, GcType gc_type) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 320 | EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); |
Mathieu Chartier | fd678be | 2012-08-30 14:50:54 -0700 | [diff] [blame] | 321 | |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 322 | // DEPRECATED: Should remove in "near" future when support for multiple image spaces is added. |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 323 | // Assumes there is only one image space. |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 324 | ImageSpace* GetImageSpace(); |
Mathieu Chartier | 1c23e1e | 2012-10-12 14:14:11 -0700 | [diff] [blame] | 325 | DlMallocSpace* GetAllocSpace(); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 326 | LargeObjectSpace* GetLargeObjectsSpace() { |
| 327 | return large_object_space_.get(); |
| 328 | } |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 329 | void DumpSpaces(); |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 330 | |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 331 | // UnReserve the address range where the oat file will be placed. |
| 332 | void UnReserveOatFileAddressRange(); |
| 333 | |
Mathieu Chartier | 155dfe9 | 2012-10-09 14:24:49 -0700 | [diff] [blame] | 334 | // GC performance measuring |
| 335 | void DumpGcPerformanceInfo(); |
| 336 | |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 337 | // Thread pool. |
| 338 | void CreateThreadPool(); |
| 339 | void DeleteThreadPool(); |
| 340 | ThreadPool* GetThreadPool() { |
| 341 | return thread_pool_.get(); |
| 342 | } |
| 343 | |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 344 | private: |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 345 | // Allocates uninitialized storage. Passing in a null space tries to place the object in the |
| 346 | // large object space. |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 347 | Object* Allocate(Thread* self, AllocSpace* space, size_t num_bytes) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 348 | LOCKS_EXCLUDED(Locks::thread_suspend_count_lock_) |
| 349 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | a639903 | 2012-06-11 18:49:50 -0700 | [diff] [blame] | 350 | |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 351 | // Try to allocate a number of bytes, this function never does any GCs. |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 352 | Object* TryToAllocate(Thread* self, AllocSpace* space, size_t alloc_size, bool grow) |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 353 | LOCKS_EXCLUDED(Locks::thread_suspend_count_lock_) |
| 354 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 355 | |
Elliott Hughes | adb460d | 2011-10-05 17:02:34 -0700 | [diff] [blame] | 356 | // Pushes a list of cleared references out to the managed heap. |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 357 | void EnqueueClearedReferences(Object** cleared_references); |
Elliott Hughes | adb460d | 2011-10-05 17:02:34 -0700 | [diff] [blame] | 358 | |
Ian Rogers | f0bbeab | 2012-10-10 18:26:27 -0700 | [diff] [blame] | 359 | void RequestHeapTrim() LOCKS_EXCLUDED(Locks::runtime_shutdown_lock_); |
| 360 | void RequestConcurrentGC(Thread* self) LOCKS_EXCLUDED(Locks::runtime_shutdown_lock_); |
Elliott Hughes | 8cf5bc0 | 2012-02-02 16:32:16 -0800 | [diff] [blame] | 361 | |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 362 | void RecordAllocation(size_t size, Object* object) |
| 363 | LOCKS_EXCLUDED(GlobalSynchronization::heap_bitmap_lock_) |
| 364 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 365 | |
Mathieu Chartier | 866fb2a | 2012-09-10 10:47:49 -0700 | [diff] [blame] | 366 | // Sometimes CollectGarbageInternal decides to run a different Gc than you requested. Returns |
| 367 | // which type of Gc was actually ran. |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 368 | GcType CollectGarbageInternal(GcType gc_plan, GcCause gc_cause, bool clear_soft_references) |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 369 | LOCKS_EXCLUDED(gc_complete_lock_, |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 370 | Locks::heap_bitmap_lock_, |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 371 | Locks::thread_suspend_count_lock_); |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 372 | |
| 373 | void PreGcVerification(GarbageCollector* gc); |
| 374 | void PreSweepingGcVerification(GarbageCollector* gc); |
| 375 | void PostGcVerification(GarbageCollector* gc); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 376 | |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 377 | // Given the current contents of the alloc space, increase the allowed heap footprint to match |
| 378 | // the target utilization ratio. This should only be called immediately after a full garbage |
| 379 | // collection. |
Mathieu Chartier | 65db880 | 2012-11-20 12:36:46 -0800 | [diff] [blame] | 380 | void GrowForUtilization(uint64_t gc_duration); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 381 | |
Mathieu Chartier | 637e348 | 2012-08-17 10:41:32 -0700 | [diff] [blame] | 382 | size_t GetPercentFree(); |
Elliott Hughes | c967f78 | 2012-04-16 10:23:15 -0700 | [diff] [blame] | 383 | |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 384 | void AddSpace(ContinuousSpace* space) LOCKS_EXCLUDED(Locks::heap_bitmap_lock_); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 385 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 386 | // No thread saftey analysis since we call this everywhere and it is impossible to find a proper |
| 387 | // lock ordering for it. |
Ian Rogers | f0bbeab | 2012-10-10 18:26:27 -0700 | [diff] [blame] | 388 | void VerifyObjectBody(const Object *obj) NO_THREAD_SAFETY_ANALYSIS; |
Elliott Hughes | 92b3b56 | 2011-09-08 16:32:26 -0700 | [diff] [blame] | 389 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 390 | static void VerificationCallback(Object* obj, void* arg) |
| 391 | SHARED_LOCKS_REQUIRED(GlobalSychronization::heap_bitmap_lock_); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 392 | |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 393 | // Swap the allocation stack with the live stack. |
Mathieu Chartier | c7b83a0 | 2012-09-11 18:07:39 -0700 | [diff] [blame] | 394 | void SwapStacks(); |
Mathieu Chartier | fd678be | 2012-08-30 14:50:54 -0700 | [diff] [blame] | 395 | |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 396 | // Clear cards and update the mod union table. |
Mathieu Chartier | d22d548 | 2012-11-06 17:14:12 -0800 | [diff] [blame] | 397 | void ProcessCards(TimingLogger& timings); |
Mathieu Chartier | 7469ebf | 2012-09-24 16:28:36 -0700 | [diff] [blame] | 398 | |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 399 | Spaces spaces_; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 400 | |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 401 | // A map that we use to temporarily reserve address range for the oat file. |
| 402 | UniquePtr<MemMap> oat_file_map_; |
| 403 | |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 404 | // The alloc space which we are currently allocating into. |
Mathieu Chartier | 1c23e1e | 2012-10-12 14:14:11 -0700 | [diff] [blame] | 405 | DlMallocSpace* alloc_space_; |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 406 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 407 | // The mod-union table remembers all of the references from the image space to the alloc / |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 408 | // zygote spaces. |
| 409 | UniquePtr<ModUnionTable> mod_union_table_; |
Mathieu Chartier | b43b7d4 | 2012-06-19 13:15:09 -0700 | [diff] [blame] | 410 | |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 411 | // This table holds all of the references from the zygote space to the alloc space. |
| 412 | UniquePtr<ModUnionTable> zygote_mod_union_table_; |
| 413 | |
| 414 | UniquePtr<CardTable> card_table_; |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 415 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 416 | // True for concurrent mark sweep GC, false for mark sweep. |
| 417 | const bool concurrent_gc_; |
| 418 | |
| 419 | // If we have a zygote space. |
| 420 | bool have_zygote_space_; |
| 421 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 422 | // Guards access to the state of GC, associated conditional variable is used to signal when a GC |
| 423 | // completes. |
| 424 | Mutex* gc_complete_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; |
| 425 | UniquePtr<ConditionVariable> gc_complete_cond_ GUARDED_BY(gc_complete_lock_); |
| 426 | |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 427 | // Reference queue lock |
| 428 | UniquePtr<Mutex> reference_queue_lock_; |
| 429 | |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 430 | // True while the garbage collector is running. |
Mathieu Chartier | 866fb2a | 2012-09-10 10:47:49 -0700 | [diff] [blame] | 431 | volatile bool is_gc_running_ GUARDED_BY(gc_complete_lock_); |
| 432 | |
| 433 | // Last Gc type we ran. Used by WaitForConcurrentGc to know which Gc was waited on. |
| 434 | volatile GcType last_gc_type_ GUARDED_BY(gc_complete_lock_); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 435 | |
Mathieu Chartier | 1c23e1e | 2012-10-12 14:14:11 -0700 | [diff] [blame] | 436 | // If enabled, causes Gc for alloc when heap size reaches the current footprint limit before the |
| 437 | // Gc updates it. |
| 438 | const bool enforce_heap_growth_rate_; |
| 439 | |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 440 | // Maximum size that the heap can reach. |
| 441 | size_t growth_limit_; |
Mathieu Chartier | 1c23e1e | 2012-10-12 14:14:11 -0700 | [diff] [blame] | 442 | size_t max_allowed_footprint_; |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 443 | |
Mathieu Chartier | 65db880 | 2012-11-20 12:36:46 -0800 | [diff] [blame] | 444 | // Minimum bytes before concurrent GC starts. |
Mathieu Chartier | 7664f5c | 2012-06-08 18:15:32 -0700 | [diff] [blame] | 445 | size_t concurrent_start_size_; |
| 446 | size_t concurrent_min_free_; |
Mathieu Chartier | 0051be6 | 2012-10-12 17:47:11 -0700 | [diff] [blame] | 447 | size_t concurrent_start_bytes_; |
Mathieu Chartier | 1c23e1e | 2012-10-12 14:14:11 -0700 | [diff] [blame] | 448 | |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 449 | // Number of bytes allocated since the last Gc, we use this to help determine when to schedule concurrent GCs. |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 450 | size_t sticky_gc_count_; |
Mathieu Chartier | 7664f5c | 2012-06-08 18:15:32 -0700 | [diff] [blame] | 451 | |
Mathieu Chartier | 155dfe9 | 2012-10-09 14:24:49 -0700 | [diff] [blame] | 452 | size_t total_bytes_freed_; |
| 453 | size_t total_objects_freed_; |
| 454 | |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 455 | // Primitive objects larger than this size are put in the large object space. |
| 456 | size_t large_object_threshold_; |
| 457 | |
| 458 | // Large object space. |
| 459 | UniquePtr<LargeObjectSpace> large_object_space_; |
| 460 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 461 | // Number of bytes allocated. Adjusted after each allocation and free. |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 462 | AtomicInteger num_bytes_allocated_; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 463 | |
Mathieu Chartier | fd678be | 2012-08-30 14:50:54 -0700 | [diff] [blame] | 464 | // Heap verification flags. |
Mathieu Chartier | c7b83a0 | 2012-09-11 18:07:39 -0700 | [diff] [blame] | 465 | const bool verify_missing_card_marks_; |
| 466 | const bool verify_system_weaks_; |
| 467 | const bool verify_pre_gc_heap_; |
| 468 | const bool verify_post_gc_heap_; |
Mathieu Chartier | fd678be | 2012-08-30 14:50:54 -0700 | [diff] [blame] | 469 | const bool verify_mod_union_table_; |
| 470 | |
Mathieu Chartier | 02b6a78 | 2012-10-26 13:51:26 -0700 | [diff] [blame] | 471 | // Parallel GC data structures. |
| 472 | UniquePtr<ThreadPool> thread_pool_; |
| 473 | |
Mathieu Chartier | c7b83a0 | 2012-09-11 18:07:39 -0700 | [diff] [blame] | 474 | // After how many GCs we force to do a partial GC instead of sticky mark bits GC. |
| 475 | const size_t partial_gc_frequency_; |
| 476 | |
| 477 | // Sticky mark bits GC has some overhead, so if we have less a few megabytes of AllocSpace then |
| 478 | // it's probably better to just do a partial GC. |
| 479 | const size_t min_alloc_space_size_for_sticky_gc_; |
| 480 | |
| 481 | // Minimum remaining size for sticky GC. Since sticky GC doesn't free up as much memory as a |
| 482 | // normal GC, it is important to not use it when we are almost out of memory. |
| 483 | const size_t min_remaining_space_for_sticky_gc_; |
| 484 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 485 | // Last trim time |
| 486 | uint64_t last_trim_time_; |
| 487 | |
Mathieu Chartier | 65db880 | 2012-11-20 12:36:46 -0800 | [diff] [blame] | 488 | // The time at which the last GC ended. |
| 489 | uint64_t last_gc_time_; |
| 490 | |
| 491 | // How many bytes were allocated at the end of the last GC. |
| 492 | uint64_t last_gc_size_; |
| 493 | |
| 494 | // Estimated allocation rate (bytes / second). |
| 495 | uint64_t allocation_rate_; |
| 496 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 497 | UniquePtr<HeapBitmap> live_bitmap_ GUARDED_BY(Locks::heap_bitmap_lock_); |
| 498 | UniquePtr<HeapBitmap> mark_bitmap_ GUARDED_BY(Locks::heap_bitmap_lock_); |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 499 | |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 500 | // Mark stack that we reuse to avoid re-allocating the mark stack. |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 501 | UniquePtr<ObjectStack> mark_stack_; |
Mathieu Chartier | 5301cd2 | 2012-05-31 12:11:36 -0700 | [diff] [blame] | 502 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 503 | // Allocation stack, new allocations go here so that we can do sticky mark bits. This enables us |
| 504 | // to use the live bitmap as the old mark bitmap. |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 505 | const size_t max_allocation_stack_size_; |
| 506 | UniquePtr<ObjectStack> allocation_stack_; |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 507 | |
| 508 | // Second allocation stack so that we can process allocation with the heap unlocked. |
Mathieu Chartier | d8195f1 | 2012-10-05 12:21:28 -0700 | [diff] [blame] | 509 | UniquePtr<ObjectStack> live_stack_; |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 510 | |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 511 | // offset of java.lang.ref.Reference.referent |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 512 | MemberOffset reference_referent_offset_; |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 513 | |
| 514 | // offset of java.lang.ref.Reference.queue |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 515 | MemberOffset reference_queue_offset_; |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 516 | |
| 517 | // offset of java.lang.ref.Reference.queueNext |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 518 | MemberOffset reference_queueNext_offset_; |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 519 | |
| 520 | // offset of java.lang.ref.Reference.pendingNext |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 521 | MemberOffset reference_pendingNext_offset_; |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 522 | |
| 523 | // offset of java.lang.ref.FinalizerReference.zombie |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 524 | MemberOffset finalizer_reference_zombie_offset_; |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 525 | |
Mathieu Chartier | 0051be6 | 2012-10-12 17:47:11 -0700 | [diff] [blame] | 526 | // Minimum free guarantees that you always have at least min_free_ free bytes after growing for |
| 527 | // utilization, regardless of target utilization ratio. |
| 528 | size_t min_free_; |
| 529 | |
| 530 | // The ideal maximum free size, when we grow the heap for utilization. |
| 531 | size_t max_free_; |
| 532 | |
Brian Carlstrom | 395520e | 2011-09-25 19:35:00 -0700 | [diff] [blame] | 533 | // Target ideal heap utilization ratio |
Mathieu Chartier | 0051be6 | 2012-10-12 17:47:11 -0700 | [diff] [blame] | 534 | double target_utilization_; |
Brian Carlstrom | 395520e | 2011-09-25 19:35:00 -0700 | [diff] [blame] | 535 | |
Mathieu Chartier | 155dfe9 | 2012-10-09 14:24:49 -0700 | [diff] [blame] | 536 | // Total time which mutators are paused or waiting for GC to complete. |
Mathieu Chartier | 155dfe9 | 2012-10-09 14:24:49 -0700 | [diff] [blame] | 537 | uint64_t total_wait_time_; |
| 538 | |
| 539 | // Total number of objects allocated in microseconds. |
| 540 | const bool measure_allocation_time_; |
| 541 | AtomicInteger total_allocation_time_; |
| 542 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 543 | bool verify_objects_; |
Mathieu Chartier | 2b82db4 | 2012-11-14 17:29:05 -0800 | [diff] [blame] | 544 | typedef std::vector<MarkSweep*> Collectors; |
| 545 | Collectors mark_sweep_collectors_; |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 546 | |
Mathieu Chartier | c7b83a0 | 2012-09-11 18:07:39 -0700 | [diff] [blame] | 547 | friend class MarkSweep; |
| 548 | friend class VerifyReferenceCardVisitor; |
Mathieu Chartier | fd678be | 2012-08-30 14:50:54 -0700 | [diff] [blame] | 549 | friend class VerifyReferenceVisitor; |
| 550 | friend class VerifyObjectVisitor; |
Mathieu Chartier | b43b7d4 | 2012-06-19 13:15:09 -0700 | [diff] [blame] | 551 | friend class ScopedHeapLock; |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 552 | FRIEND_TEST(SpaceTest, AllocAndFree); |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 553 | FRIEND_TEST(SpaceTest, AllocAndFreeList); |
Mathieu Chartier | cc236d7 | 2012-07-20 10:29:05 -0700 | [diff] [blame] | 554 | FRIEND_TEST(SpaceTest, ZygoteSpace); |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 555 | friend class SpaceTest; |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 556 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 557 | DISALLOW_IMPLICIT_CONSTRUCTORS(Heap); |
| 558 | }; |
| 559 | |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 560 | } // namespace art |
| 561 | |
| 562 | #endif // ART_SRC_HEAP_H_ |