heap.h revision b225890e02bc8d5864217743eaef306d5387e0e9
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 */ 16 17#ifndef ART_RUNTIME_GC_HEAP_H_ 18#define ART_RUNTIME_GC_HEAP_H_ 19 20#include <iosfwd> 21#include <string> 22#include <vector> 23 24#include "allocator_type.h" 25#include "atomic.h" 26#include "base/timing_logger.h" 27#include "gc/accounting/atomic_stack.h" 28#include "gc/accounting/card_table.h" 29#include "gc/gc_cause.h" 30#include "gc/collector/garbage_collector.h" 31#include "gc/collector/gc_type.h" 32#include "gc/collector_type.h" 33#include "globals.h" 34#include "gtest/gtest.h" 35#include "instruction_set.h" 36#include "jni.h" 37#include "object_callbacks.h" 38#include "offsets.h" 39#include "reference_processor.h" 40#include "safe_map.h" 41#include "thread_pool.h" 42#include "verify_object.h" 43 44namespace art { 45 46class ConditionVariable; 47class Mutex; 48class StackVisitor; 49class Thread; 50class TimingLogger; 51 52namespace mirror { 53 class Class; 54 class Object; 55} // namespace mirror 56 57namespace gc { 58 59class ReferenceProcessor; 60 61namespace accounting { 62 class HeapBitmap; 63 class ModUnionTable; 64 class RememberedSet; 65} // namespace accounting 66 67namespace collector { 68 class ConcurrentCopying; 69 class GarbageCollector; 70 class MarkCompact; 71 class MarkSweep; 72 class SemiSpace; 73} // namespace collector 74 75namespace allocator { 76 class RosAlloc; 77} // namespace allocator 78 79namespace space { 80 class AllocSpace; 81 class BumpPointerSpace; 82 class DiscontinuousSpace; 83 class DlMallocSpace; 84 class ImageSpace; 85 class LargeObjectSpace; 86 class MallocSpace; 87 class RosAllocSpace; 88 class Space; 89 class SpaceTest; 90 class ContinuousMemMapAllocSpace; 91} // namespace space 92 93class AgeCardVisitor { 94 public: 95 byte operator()(byte card) const { 96 if (card == accounting::CardTable::kCardDirty) { 97 return card - 1; 98 } else { 99 return 0; 100 } 101 } 102}; 103 104enum HomogeneousSpaceCompactResult { 105 // Success. 106 kSuccess, 107 // Reject due to disabled moving GC. 108 kErrorReject, 109 // System is shutting down. 110 kErrorVMShuttingDown, 111}; 112 113// If true, use rosalloc/RosAllocSpace instead of dlmalloc/DlMallocSpace 114static constexpr bool kUseRosAlloc = true; 115 116// If true, use thread-local allocation stack. 117static constexpr bool kUseThreadLocalAllocationStack = true; 118 119// The process state passed in from the activity manager, used to determine when to do trimming 120// and compaction. 121enum ProcessState { 122 kProcessStateJankPerceptible = 0, 123 kProcessStateJankImperceptible = 1, 124}; 125std::ostream& operator<<(std::ostream& os, const ProcessState& process_state); 126 127class Heap { 128 public: 129 // If true, measure the total allocation time. 130 static constexpr bool kMeasureAllocationTime = false; 131 // Primitive arrays larger than this size are put in the large object space. 132 static constexpr size_t kDefaultLargeObjectThreshold = 3 * kPageSize; 133 134 static constexpr size_t kDefaultStartingSize = kPageSize; 135 static constexpr size_t kDefaultInitialSize = 2 * MB; 136 static constexpr size_t kDefaultMaximumSize = 256 * MB; 137 static constexpr size_t kDefaultMaxFree = 2 * MB; 138 static constexpr size_t kDefaultMinFree = kDefaultMaxFree / 4; 139 static constexpr size_t kDefaultLongPauseLogThreshold = MsToNs(5); 140 static constexpr size_t kDefaultLongGCLogThreshold = MsToNs(100); 141 static constexpr size_t kDefaultTLABSize = 256 * KB; 142 static constexpr double kDefaultTargetUtilization = 0.5; 143 static constexpr double kDefaultHeapGrowthMultiplier = 2.0; 144 145 // Used so that we don't overflow the allocation time atomic integer. 146 static constexpr size_t kTimeAdjust = 1024; 147 148 // How often we allow heap trimming to happen (nanoseconds). 149 static constexpr uint64_t kHeapTrimWait = MsToNs(5000); 150 // How long we wait after a transition request to perform a collector transition (nanoseconds). 151 static constexpr uint64_t kCollectorTransitionWait = MsToNs(5000); 152 153 // Create a heap with the requested sizes. The possible empty 154 // image_file_names names specify Spaces to load based on 155 // ImageWriter output. 156 explicit Heap(size_t initial_size, size_t growth_limit, size_t min_free, 157 size_t max_free, double target_utilization, 158 double foreground_heap_growth_multiplier, size_t capacity, 159 const std::string& original_image_file_name, 160 InstructionSet image_instruction_set, 161 CollectorType foreground_collector_type, CollectorType background_collector_type, 162 size_t parallel_gc_threads, size_t conc_gc_threads, bool low_memory_mode, 163 size_t long_pause_threshold, size_t long_gc_threshold, 164 bool ignore_max_footprint, bool use_tlab, 165 bool verify_pre_gc_heap, bool verify_pre_sweeping_heap, bool verify_post_gc_heap, 166 bool verify_pre_gc_rosalloc, bool verify_pre_sweeping_rosalloc, 167 bool verify_post_gc_rosalloc, bool use_homogeneous_space_compaction, 168 uint64_t min_interval_homogeneous_space_compaction_by_oom); 169 170 ~Heap(); 171 172 // Allocates and initializes storage for an object instance. 173 template <bool kInstrumented, typename PreFenceVisitor> 174 mirror::Object* AllocObject(Thread* self, mirror::Class* klass, size_t num_bytes, 175 const PreFenceVisitor& pre_fence_visitor) 176 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { 177 return AllocObjectWithAllocator<kInstrumented, true>(self, klass, num_bytes, 178 GetCurrentAllocator(), 179 pre_fence_visitor); 180 } 181 182 template <bool kInstrumented, typename PreFenceVisitor> 183 mirror::Object* AllocNonMovableObject(Thread* self, mirror::Class* klass, size_t num_bytes, 184 const PreFenceVisitor& pre_fence_visitor) 185 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { 186 return AllocObjectWithAllocator<kInstrumented, true>(self, klass, num_bytes, 187 GetCurrentNonMovingAllocator(), 188 pre_fence_visitor); 189 } 190 191 template <bool kInstrumented, bool kCheckLargeObject, typename PreFenceVisitor> 192 ALWAYS_INLINE mirror::Object* AllocObjectWithAllocator( 193 Thread* self, mirror::Class* klass, size_t byte_count, AllocatorType allocator, 194 const PreFenceVisitor& pre_fence_visitor) 195 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 196 197 AllocatorType GetCurrentAllocator() const { 198 return current_allocator_; 199 } 200 201 AllocatorType GetCurrentNonMovingAllocator() const { 202 return current_non_moving_allocator_; 203 } 204 205 // Visit all of the live objects in the heap. 206 void VisitObjects(ObjectCallback callback, void* arg) 207 SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_, Locks::mutator_lock_); 208 209 void CheckPreconditionsForAllocObject(mirror::Class* c, size_t byte_count) 210 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 211 212 void RegisterNativeAllocation(JNIEnv* env, int bytes); 213 void RegisterNativeFree(JNIEnv* env, int bytes); 214 215 // Change the allocator, updates entrypoints. 216 void ChangeAllocator(AllocatorType allocator) 217 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_) 218 LOCKS_EXCLUDED(Locks::runtime_shutdown_lock_); 219 220 // Transition the garbage collector during runtime, may copy objects from one space to another. 221 void TransitionCollector(CollectorType collector_type); 222 223 // Change the collector to be one of the possible options (MS, CMS, SS). 224 void ChangeCollector(CollectorType collector_type) 225 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_); 226 227 // The given reference is believed to be to an object in the Java heap, check the soundness of it. 228 // TODO: NO_THREAD_SAFETY_ANALYSIS since we call this everywhere and it is impossible to find a 229 // proper lock ordering for it. 230 void VerifyObjectBody(mirror::Object* o) NO_THREAD_SAFETY_ANALYSIS; 231 232 // Check sanity of all live references. 233 void VerifyHeap() LOCKS_EXCLUDED(Locks::heap_bitmap_lock_); 234 // Returns how many failures occured. 235 size_t VerifyHeapReferences(bool verify_referents = true) 236 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_, Locks::mutator_lock_); 237 bool VerifyMissingCardMarks() 238 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_, Locks::mutator_lock_); 239 240 // A weaker test than IsLiveObject or VerifyObject that doesn't require the heap lock, 241 // and doesn't abort on error, allowing the caller to report more 242 // meaningful diagnostics. 243 bool IsValidObjectAddress(const mirror::Object* obj) const 244 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 245 246 // Faster alternative to IsHeapAddress since finding if an object is in the large object space is 247 // very slow. 248 bool IsNonDiscontinuousSpaceHeapAddress(const mirror::Object* obj) const 249 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 250 251 // Returns true if 'obj' is a live heap object, false otherwise (including for invalid addresses). 252 // Requires the heap lock to be held. 253 bool IsLiveObjectLocked(mirror::Object* obj, bool search_allocation_stack = true, 254 bool search_live_stack = true, bool sorted = false) 255 SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_, Locks::mutator_lock_); 256 257 // Returns true if there is any chance that the object (obj) will move. 258 bool IsMovableObject(const mirror::Object* obj) const; 259 260 // Enables us to compacting GC until objects are released. 261 void IncrementDisableMovingGC(Thread* self); 262 void DecrementDisableMovingGC(Thread* self); 263 264 // Clear all of the mark bits, doesn't clear bitmaps which have the same live bits as mark bits. 265 void ClearMarkedObjects() EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); 266 267 // Initiates an explicit garbage collection. 268 void CollectGarbage(bool clear_soft_references); 269 270 // Does a concurrent GC, should only be called by the GC daemon thread 271 // through runtime. 272 void ConcurrentGC(Thread* self) LOCKS_EXCLUDED(Locks::runtime_shutdown_lock_); 273 274 // Implements VMDebug.countInstancesOfClass and JDWP VM_InstanceCount. 275 // The boolean decides whether to use IsAssignableFrom or == when comparing classes. 276 void CountInstances(const std::vector<mirror::Class*>& classes, bool use_is_assignable_from, 277 uint64_t* counts) 278 LOCKS_EXCLUDED(Locks::heap_bitmap_lock_) 279 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 280 // Implements JDWP RT_Instances. 281 void GetInstances(mirror::Class* c, int32_t max_count, std::vector<mirror::Object*>& instances) 282 LOCKS_EXCLUDED(Locks::heap_bitmap_lock_) 283 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 284 // Implements JDWP OR_ReferringObjects. 285 void GetReferringObjects(mirror::Object* o, int32_t max_count, std::vector<mirror::Object*>& referring_objects) 286 LOCKS_EXCLUDED(Locks::heap_bitmap_lock_) 287 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 288 289 // Removes the growth limit on the alloc space so it may grow to its maximum capacity. Used to 290 // implement dalvik.system.VMRuntime.clearGrowthLimit. 291 void ClearGrowthLimit(); 292 293 // Target ideal heap utilization ratio, implements 294 // dalvik.system.VMRuntime.getTargetHeapUtilization. 295 double GetTargetHeapUtilization() const { 296 return target_utilization_; 297 } 298 299 // Data structure memory usage tracking. 300 void RegisterGCAllocation(size_t bytes); 301 void RegisterGCDeAllocation(size_t bytes); 302 303 // Set the heap's private space pointers to be the same as the space based on it's type. Public 304 // due to usage by tests. 305 void SetSpaceAsDefault(space::ContinuousSpace* continuous_space) 306 LOCKS_EXCLUDED(Locks::heap_bitmap_lock_); 307 void AddSpace(space::Space* space) LOCKS_EXCLUDED(Locks::heap_bitmap_lock_); 308 void RemoveSpace(space::Space* space) LOCKS_EXCLUDED(Locks::heap_bitmap_lock_); 309 310 // Set target ideal heap utilization ratio, implements 311 // dalvik.system.VMRuntime.setTargetHeapUtilization. 312 void SetTargetHeapUtilization(float target); 313 314 // For the alloc space, sets the maximum number of bytes that the heap is allowed to allocate 315 // from the system. Doesn't allow the space to exceed its growth limit. 316 void SetIdealFootprint(size_t max_allowed_footprint); 317 318 // Blocks the caller until the garbage collector becomes idle and returns the type of GC we 319 // waited for. 320 collector::GcType WaitForGcToComplete(GcCause cause, Thread* self) 321 LOCKS_EXCLUDED(gc_complete_lock_); 322 323 // Update the heap's process state to a new value, may cause compaction to occur. 324 void UpdateProcessState(ProcessState process_state); 325 326 const std::vector<space::ContinuousSpace*>& GetContinuousSpaces() const { 327 return continuous_spaces_; 328 } 329 330 const std::vector<space::DiscontinuousSpace*>& GetDiscontinuousSpaces() const { 331 return discontinuous_spaces_; 332 } 333 334 const collector::Iteration* GetCurrentGcIteration() const { 335 return ¤t_gc_iteration_; 336 } 337 collector::Iteration* GetCurrentGcIteration() { 338 return ¤t_gc_iteration_; 339 } 340 341 // Enable verification of object references when the runtime is sufficiently initialized. 342 void EnableObjectValidation() { 343 verify_object_mode_ = kVerifyObjectSupport; 344 if (verify_object_mode_ > kVerifyObjectModeDisabled) { 345 VerifyHeap(); 346 } 347 } 348 349 // Disable object reference verification for image writing. 350 void DisableObjectValidation() { 351 verify_object_mode_ = kVerifyObjectModeDisabled; 352 } 353 354 // Other checks may be performed if we know the heap should be in a sane state. 355 bool IsObjectValidationEnabled() const { 356 return verify_object_mode_ > kVerifyObjectModeDisabled; 357 } 358 359 // Returns true if low memory mode is enabled. 360 bool IsLowMemoryMode() const { 361 return low_memory_mode_; 362 } 363 364 // Returns the heap growth multiplier, this affects how much we grow the heap after a GC. 365 // Scales heap growth, min free, and max free. 366 double HeapGrowthMultiplier() const; 367 368 // Freed bytes can be negative in cases where we copy objects from a compacted space to a 369 // free-list backed space. 370 void RecordFree(uint64_t freed_objects, int64_t freed_bytes); 371 372 // Must be called if a field of an Object in the heap changes, and before any GC safe-point. 373 // The call is not needed if NULL is stored in the field. 374 void WriteBarrierField(const mirror::Object* dst, MemberOffset /*offset*/, 375 const mirror::Object* /*new_value*/) { 376 card_table_->MarkCard(dst); 377 } 378 379 // Write barrier for array operations that update many field positions 380 void WriteBarrierArray(const mirror::Object* dst, int /*start_offset*/, 381 size_t /*length TODO: element_count or byte_count?*/) { 382 card_table_->MarkCard(dst); 383 } 384 385 void WriteBarrierEveryFieldOf(const mirror::Object* obj) { 386 card_table_->MarkCard(obj); 387 } 388 389 accounting::CardTable* GetCardTable() const { 390 return card_table_.get(); 391 } 392 393 void AddFinalizerReference(Thread* self, mirror::Object** object); 394 395 // Returns the number of bytes currently allocated. 396 size_t GetBytesAllocated() const { 397 return num_bytes_allocated_.LoadSequentiallyConsistent(); 398 } 399 400 // Returns the number of objects currently allocated. 401 size_t GetObjectsAllocated() const LOCKS_EXCLUDED(Locks::heap_bitmap_lock_); 402 403 // Returns the total number of objects allocated since the heap was created. 404 uint64_t GetObjectsAllocatedEver() const; 405 406 // Returns the total number of bytes allocated since the heap was created. 407 uint64_t GetBytesAllocatedEver() const; 408 409 // Returns the total number of objects freed since the heap was created. 410 uint64_t GetObjectsFreedEver() const { 411 return total_objects_freed_ever_; 412 } 413 414 // Returns the total number of bytes freed since the heap was created. 415 uint64_t GetBytesFreedEver() const { 416 return total_bytes_freed_ever_; 417 } 418 419 // Implements java.lang.Runtime.maxMemory, returning the maximum amount of memory a program can 420 // consume. For a regular VM this would relate to the -Xmx option and would return -1 if no Xmx 421 // were specified. Android apps start with a growth limit (small heap size) which is 422 // cleared/extended for large apps. 423 size_t GetMaxMemory() const { 424 // There is some race conditions in the allocation code that can cause bytes allocated to 425 // become larger than growth_limit_ in rare cases. 426 return std::max(GetBytesAllocated(), growth_limit_); 427 } 428 429 // Implements java.lang.Runtime.totalMemory, returning approximate amount of memory currently 430 // consumed by an application. 431 size_t GetTotalMemory() const; 432 433 // Returns approximately how much free memory we have until the next GC happens. 434 size_t GetFreeMemoryUntilGC() const { 435 return max_allowed_footprint_ - GetBytesAllocated(); 436 } 437 438 // Returns approximately how much free memory we have until the next OOME happens. 439 size_t GetFreeMemoryUntilOOME() const { 440 return growth_limit_ - GetBytesAllocated(); 441 } 442 443 // Returns how much free memory we have until we need to grow the heap to perform an allocation. 444 // Similar to GetFreeMemoryUntilGC. Implements java.lang.Runtime.freeMemory. 445 size_t GetFreeMemory() const { 446 size_t byte_allocated = num_bytes_allocated_.LoadSequentiallyConsistent(); 447 size_t total_memory = GetTotalMemory(); 448 // Make sure we don't get a negative number. 449 return total_memory - std::min(total_memory, byte_allocated); 450 } 451 452 // get the space that corresponds to an object's address. Current implementation searches all 453 // spaces in turn. If fail_ok is false then failing to find a space will cause an abort. 454 // TODO: consider using faster data structure like binary tree. 455 space::ContinuousSpace* FindContinuousSpaceFromObject(const mirror::Object*, bool fail_ok) const; 456 space::DiscontinuousSpace* FindDiscontinuousSpaceFromObject(const mirror::Object*, 457 bool fail_ok) const; 458 space::Space* FindSpaceFromObject(const mirror::Object*, bool fail_ok) const; 459 460 void DumpForSigQuit(std::ostream& os) EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_); 461 462 // Do a pending heap transition or trim. 463 void DoPendingTransitionOrTrim() LOCKS_EXCLUDED(heap_trim_request_lock_); 464 465 // Trim the managed and native heaps by releasing unused memory back to the OS. 466 void Trim() LOCKS_EXCLUDED(heap_trim_request_lock_); 467 468 void RevokeThreadLocalBuffers(Thread* thread); 469 void RevokeRosAllocThreadLocalBuffers(Thread* thread); 470 void RevokeAllThreadLocalBuffers(); 471 void AssertAllBumpPointerSpaceThreadLocalBuffersAreRevoked(); 472 void RosAllocVerification(TimingLogger* timings, const char* name) 473 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_); 474 475 accounting::HeapBitmap* GetLiveBitmap() SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) { 476 return live_bitmap_.get(); 477 } 478 479 accounting::HeapBitmap* GetMarkBitmap() SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) { 480 return mark_bitmap_.get(); 481 } 482 483 accounting::ObjectStack* GetLiveStack() SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) { 484 return live_stack_.get(); 485 } 486 487 void PreZygoteFork() NO_THREAD_SAFETY_ANALYSIS; 488 489 // Mark and empty stack. 490 void FlushAllocStack() 491 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); 492 493 // Revoke all the thread-local allocation stacks. 494 void RevokeAllThreadLocalAllocationStacks(Thread* self) 495 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_) 496 LOCKS_EXCLUDED(Locks::runtime_shutdown_lock_, Locks::thread_list_lock_); 497 498 // Mark all the objects in the allocation stack in the specified bitmap. 499 // TODO: Refactor? 500 void MarkAllocStack(accounting::SpaceBitmap<kObjectAlignment>* bitmap1, 501 accounting::SpaceBitmap<kObjectAlignment>* bitmap2, 502 accounting::SpaceBitmap<kLargeObjectAlignment>* large_objects, 503 accounting::ObjectStack* stack) 504 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); 505 506 // Mark the specified allocation stack as live. 507 void MarkAllocStackAsLive(accounting::ObjectStack* stack) 508 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); 509 510 // Unbind any bound bitmaps. 511 void UnBindBitmaps() EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); 512 513 // DEPRECATED: Should remove in "near" future when support for multiple image spaces is added. 514 // Assumes there is only one image space. 515 space::ImageSpace* GetImageSpace() const; 516 517 // Permenantly disable compaction. 518 void DisableCompaction(); 519 520 space::DlMallocSpace* GetDlMallocSpace() const { 521 return dlmalloc_space_; 522 } 523 524 space::RosAllocSpace* GetRosAllocSpace() const { 525 return rosalloc_space_; 526 } 527 528 // Return the corresponding rosalloc space. 529 space::RosAllocSpace* GetRosAllocSpace(gc::allocator::RosAlloc* rosalloc) const; 530 531 space::MallocSpace* GetNonMovingSpace() const { 532 return non_moving_space_; 533 } 534 535 space::LargeObjectSpace* GetLargeObjectsSpace() const { 536 return large_object_space_; 537 } 538 539 // Returns the free list space that may contain movable objects (the 540 // one that's not the non-moving space), either rosalloc_space_ or 541 // dlmalloc_space_. 542 space::MallocSpace* GetPrimaryFreeListSpace() { 543 if (kUseRosAlloc) { 544 DCHECK(rosalloc_space_ != nullptr); 545 // reinterpret_cast is necessary as the space class hierarchy 546 // isn't known (#included) yet here. 547 return reinterpret_cast<space::MallocSpace*>(rosalloc_space_); 548 } else { 549 DCHECK(dlmalloc_space_ != nullptr); 550 return reinterpret_cast<space::MallocSpace*>(dlmalloc_space_); 551 } 552 } 553 554 std::string DumpSpaces() const WARN_UNUSED; 555 void DumpSpaces(std::ostream& stream) const; 556 557 // Dump object should only be used by the signal handler. 558 void DumpObject(std::ostream& stream, mirror::Object* obj) NO_THREAD_SAFETY_ANALYSIS; 559 // Safe version of pretty type of which check to make sure objects are heap addresses. 560 std::string SafeGetClassDescriptor(mirror::Class* klass) NO_THREAD_SAFETY_ANALYSIS; 561 std::string SafePrettyTypeOf(mirror::Object* obj) NO_THREAD_SAFETY_ANALYSIS; 562 563 // GC performance measuring 564 void DumpGcPerformanceInfo(std::ostream& os); 565 566 // Returns true if we currently care about pause times. 567 bool CareAboutPauseTimes() const { 568 return process_state_ == kProcessStateJankPerceptible; 569 } 570 571 // Thread pool. 572 void CreateThreadPool(); 573 void DeleteThreadPool(); 574 ThreadPool* GetThreadPool() { 575 return thread_pool_.get(); 576 } 577 size_t GetParallelGCThreadCount() const { 578 return parallel_gc_threads_; 579 } 580 size_t GetConcGCThreadCount() const { 581 return conc_gc_threads_; 582 } 583 accounting::ModUnionTable* FindModUnionTableFromSpace(space::Space* space); 584 void AddModUnionTable(accounting::ModUnionTable* mod_union_table); 585 586 accounting::RememberedSet* FindRememberedSetFromSpace(space::Space* space); 587 void AddRememberedSet(accounting::RememberedSet* remembered_set); 588 // Also deletes the remebered set. 589 void RemoveRememberedSet(space::Space* space); 590 591 bool IsCompilingBoot() const; 592 bool RunningOnValgrind() const { 593 return running_on_valgrind_; 594 } 595 bool HasImageSpace() const; 596 597 ReferenceProcessor* GetReferenceProcessor() { 598 return &reference_processor_; 599 } 600 601 private: 602 // Compact source space to target space. 603 void Compact(space::ContinuousMemMapAllocSpace* target_space, 604 space::ContinuousMemMapAllocSpace* source_space, 605 GcCause gc_cause) 606 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_); 607 608 void FinishGC(Thread* self, collector::GcType gc_type) LOCKS_EXCLUDED(gc_complete_lock_); 609 610 // Create a mem map with a preferred base address. 611 static MemMap* MapAnonymousPreferredAddress(const char* name, byte* request_begin, 612 size_t capacity, int prot_flags, 613 std::string* out_error_str); 614 615 bool SupportHSpaceCompaction() const { 616 // Returns true if we can do hspace compaction 617 return main_space_backup_ != nullptr; 618 } 619 620 static ALWAYS_INLINE bool AllocatorHasAllocationStack(AllocatorType allocator_type) { 621 return 622 allocator_type != kAllocatorTypeBumpPointer && 623 allocator_type != kAllocatorTypeTLAB; 624 } 625 static ALWAYS_INLINE bool AllocatorMayHaveConcurrentGC(AllocatorType allocator_type) { 626 return AllocatorHasAllocationStack(allocator_type); 627 } 628 static bool IsMovingGc(CollectorType collector_type) { 629 return collector_type == kCollectorTypeSS || collector_type == kCollectorTypeGSS || 630 collector_type == kCollectorTypeCC || collector_type == kCollectorTypeMC || 631 collector_type == kCollectorTypeHomogeneousSpaceCompact; 632 } 633 bool ShouldAllocLargeObject(mirror::Class* c, size_t byte_count) const 634 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 635 ALWAYS_INLINE void CheckConcurrentGC(Thread* self, size_t new_num_bytes_allocated, 636 mirror::Object** obj) 637 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 638 639 accounting::ObjectStack* GetMarkStack() { 640 return mark_stack_.get(); 641 } 642 643 // We don't force this to be inlined since it is a slow path. 644 template <bool kInstrumented, typename PreFenceVisitor> 645 mirror::Object* AllocLargeObject(Thread* self, mirror::Class* klass, size_t byte_count, 646 const PreFenceVisitor& pre_fence_visitor) 647 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 648 649 // Handles Allocate()'s slow allocation path with GC involved after 650 // an initial allocation attempt failed. 651 mirror::Object* AllocateInternalWithGc(Thread* self, AllocatorType allocator, size_t num_bytes, 652 size_t* bytes_allocated, size_t* usable_size, 653 mirror::Class** klass) 654 LOCKS_EXCLUDED(Locks::thread_suspend_count_lock_) 655 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 656 657 // Allocate into a specific space. 658 mirror::Object* AllocateInto(Thread* self, space::AllocSpace* space, mirror::Class* c, 659 size_t bytes) 660 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 661 662 // Need to do this with mutators paused so that somebody doesn't accidentally allocate into the 663 // wrong space. 664 void SwapSemiSpaces() EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_); 665 666 // Try to allocate a number of bytes, this function never does any GCs. Needs to be inlined so 667 // that the switch statement is constant optimized in the entrypoints. 668 template <const bool kInstrumented, const bool kGrow> 669 ALWAYS_INLINE mirror::Object* TryToAllocate(Thread* self, AllocatorType allocator_type, 670 size_t alloc_size, size_t* bytes_allocated, 671 size_t* usable_size) 672 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 673 674 void ThrowOutOfMemoryError(Thread* self, size_t byte_count, AllocatorType allocator_type) 675 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 676 677 template <bool kGrow> 678 bool IsOutOfMemoryOnAllocation(AllocatorType allocator_type, size_t alloc_size); 679 680 // Returns true if the address passed in is within the address range of a continuous space. 681 bool IsValidContinuousSpaceObjectAddress(const mirror::Object* obj) const 682 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 683 684 // Run the finalizers. 685 void RunFinalization(JNIEnv* env); 686 687 // Blocks the caller until the garbage collector becomes idle and returns the type of GC we 688 // waited for. 689 collector::GcType WaitForGcToCompleteLocked(GcCause cause, Thread* self) 690 EXCLUSIVE_LOCKS_REQUIRED(gc_complete_lock_); 691 692 void RequestCollectorTransition(CollectorType desired_collector_type, uint64_t delta_time) 693 LOCKS_EXCLUDED(heap_trim_request_lock_); 694 void RequestHeapTrim() LOCKS_EXCLUDED(Locks::runtime_shutdown_lock_); 695 void RequestConcurrentGCAndSaveObject(Thread* self, mirror::Object** obj) 696 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 697 void RequestConcurrentGC(Thread* self) 698 LOCKS_EXCLUDED(Locks::runtime_shutdown_lock_); 699 bool IsGCRequestPending() const; 700 701 // Sometimes CollectGarbageInternal decides to run a different Gc than you requested. Returns 702 // which type of Gc was actually ran. 703 collector::GcType CollectGarbageInternal(collector::GcType gc_plan, GcCause gc_cause, 704 bool clear_soft_references) 705 LOCKS_EXCLUDED(gc_complete_lock_, 706 Locks::heap_bitmap_lock_, 707 Locks::thread_suspend_count_lock_); 708 709 void PreGcVerification(collector::GarbageCollector* gc) 710 LOCKS_EXCLUDED(Locks::mutator_lock_); 711 void PreGcVerificationPaused(collector::GarbageCollector* gc) 712 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_); 713 void PrePauseRosAllocVerification(collector::GarbageCollector* gc) 714 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_); 715 void PreSweepingGcVerification(collector::GarbageCollector* gc) 716 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_); 717 void PostGcVerification(collector::GarbageCollector* gc) 718 LOCKS_EXCLUDED(Locks::mutator_lock_); 719 void PostGcVerificationPaused(collector::GarbageCollector* gc) 720 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_); 721 722 // Update the watermark for the native allocated bytes based on the current number of native 723 // bytes allocated and the target utilization ratio. 724 void UpdateMaxNativeFootprint(); 725 726 // Find a collector based on GC type. 727 collector::GarbageCollector* FindCollectorByGcType(collector::GcType gc_type); 728 729 // Create a new alloc space and compact default alloc space to it. 730 HomogeneousSpaceCompactResult PerformHomogeneousSpaceCompact(); 731 732 // Create the main free list malloc space, either a RosAlloc space or DlMalloc space. 733 void CreateMainMallocSpace(MemMap* mem_map, size_t initial_size, size_t growth_limit, 734 size_t capacity); 735 736 // Create a malloc space based on a mem map. Does not set the space as default. 737 space::MallocSpace* CreateMallocSpaceFromMemMap(MemMap* mem_map, size_t initial_size, 738 size_t growth_limit, size_t capacity, 739 const char* name, bool can_move_objects); 740 741 // Given the current contents of the alloc space, increase the allowed heap footprint to match 742 // the target utilization ratio. This should only be called immediately after a full garbage 743 // collection. 744 void GrowForUtilization(collector::GarbageCollector* collector_ran); 745 746 size_t GetPercentFree(); 747 748 static void VerificationCallback(mirror::Object* obj, void* arg) 749 SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_); 750 751 // Swap the allocation stack with the live stack. 752 void SwapStacks(Thread* self); 753 754 // Clear cards and update the mod union table. 755 void ProcessCards(TimingLogger* timings, bool use_rem_sets); 756 757 // Signal the heap trim daemon that there is something to do, either a heap transition or heap 758 // trim. 759 void SignalHeapTrimDaemon(Thread* self); 760 761 // Push an object onto the allocation stack. 762 void PushOnAllocationStack(Thread* self, mirror::Object** obj) 763 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 764 void PushOnAllocationStackWithInternalGC(Thread* self, mirror::Object** obj) 765 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 766 void PushOnThreadLocalAllocationStackWithInternalGC(Thread* thread, mirror::Object** obj) 767 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 768 769 // What kind of concurrency behavior is the runtime after? Currently true for concurrent mark 770 // sweep GC, false for other GC types. 771 bool IsGcConcurrent() const ALWAYS_INLINE { 772 return collector_type_ == kCollectorTypeCMS || collector_type_ == kCollectorTypeCC; 773 } 774 775 // All-known continuous spaces, where objects lie within fixed bounds. 776 std::vector<space::ContinuousSpace*> continuous_spaces_; 777 778 // All-known discontinuous spaces, where objects may be placed throughout virtual memory. 779 std::vector<space::DiscontinuousSpace*> discontinuous_spaces_; 780 781 // All-known alloc spaces, where objects may be or have been allocated. 782 std::vector<space::AllocSpace*> alloc_spaces_; 783 784 // A space where non-movable objects are allocated, when compaction is enabled it contains 785 // Classes, ArtMethods, ArtFields, and non moving objects. 786 space::MallocSpace* non_moving_space_; 787 788 // Space which we use for the kAllocatorTypeROSAlloc. 789 space::RosAllocSpace* rosalloc_space_; 790 791 // Space which we use for the kAllocatorTypeDlMalloc. 792 space::DlMallocSpace* dlmalloc_space_; 793 794 // The main space is the space which the GC copies to and from on process state updates. This 795 // space is typically either the dlmalloc_space_ or the rosalloc_space_. 796 space::MallocSpace* main_space_; 797 798 // The large object space we are currently allocating into. 799 space::LargeObjectSpace* large_object_space_; 800 801 // The card table, dirtied by the write barrier. 802 std::unique_ptr<accounting::CardTable> card_table_; 803 804 // A mod-union table remembers all of the references from the it's space to other spaces. 805 SafeMap<space::Space*, accounting::ModUnionTable*> mod_union_tables_; 806 807 // A remembered set remembers all of the references from the it's space to the target space. 808 SafeMap<space::Space*, accounting::RememberedSet*> remembered_sets_; 809 810 // The current collector type. 811 CollectorType collector_type_; 812 // Which collector we use when the app is in the foreground. 813 CollectorType foreground_collector_type_; 814 // Which collector we will use when the app is notified of a transition to background. 815 CollectorType background_collector_type_; 816 // Desired collector type, heap trimming daemon transitions the heap if it is != collector_type_. 817 CollectorType desired_collector_type_; 818 819 // Lock which guards heap trim requests. 820 Mutex* heap_trim_request_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; 821 // When we want to perform the next heap trim (nano seconds). 822 uint64_t last_trim_time_ GUARDED_BY(heap_trim_request_lock_); 823 // When we want to perform the next heap transition (nano seconds) or heap trim. 824 uint64_t heap_transition_or_trim_target_time_ GUARDED_BY(heap_trim_request_lock_); 825 // If we have a heap trim request pending. 826 bool heap_trim_request_pending_ GUARDED_BY(heap_trim_request_lock_); 827 828 // How many GC threads we may use for paused parts of garbage collection. 829 const size_t parallel_gc_threads_; 830 831 // How many GC threads we may use for unpaused parts of garbage collection. 832 const size_t conc_gc_threads_; 833 834 // Boolean for if we are in low memory mode. 835 const bool low_memory_mode_; 836 837 // If we get a pause longer than long pause log threshold, then we print out the GC after it 838 // finishes. 839 const size_t long_pause_log_threshold_; 840 841 // If we get a GC longer than long GC log threshold, then we print out the GC after it finishes. 842 const size_t long_gc_log_threshold_; 843 844 // If we ignore the max footprint it lets the heap grow until it hits the heap capacity, this is 845 // useful for benchmarking since it reduces time spent in GC to a low %. 846 const bool ignore_max_footprint_; 847 848 // Lock which guards zygote space creation. 849 Mutex zygote_creation_lock_; 850 851 // If we have a zygote space. 852 bool have_zygote_space_; 853 854 // Minimum allocation size of large object. 855 size_t large_object_threshold_; 856 857 // Guards access to the state of GC, associated conditional variable is used to signal when a GC 858 // completes. 859 Mutex* gc_complete_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; 860 std::unique_ptr<ConditionVariable> gc_complete_cond_ GUARDED_BY(gc_complete_lock_); 861 862 // Reference processor; 863 ReferenceProcessor reference_processor_; 864 865 // True while the garbage collector is running. 866 volatile CollectorType collector_type_running_ GUARDED_BY(gc_complete_lock_); 867 868 // Last Gc type we ran. Used by WaitForConcurrentGc to know which Gc was waited on. 869 volatile collector::GcType last_gc_type_ GUARDED_BY(gc_complete_lock_); 870 collector::GcType next_gc_type_; 871 872 // Maximum size that the heap can reach. 873 const size_t capacity_; 874 875 // The size the heap is limited to. This is initially smaller than capacity, but for largeHeap 876 // programs it is "cleared" making it the same as capacity. 877 size_t growth_limit_; 878 879 // When the number of bytes allocated exceeds the footprint TryAllocate returns NULL indicating 880 // a GC should be triggered. 881 size_t max_allowed_footprint_; 882 883 // The watermark at which a concurrent GC is requested by registerNativeAllocation. 884 size_t native_footprint_gc_watermark_; 885 886 // The watermark at which a GC is performed inside of registerNativeAllocation. 887 size_t native_footprint_limit_; 888 889 // Whether or not we need to run finalizers in the next native allocation. 890 bool native_need_to_run_finalization_; 891 892 // Whether or not we currently care about pause times. 893 ProcessState process_state_; 894 895 // When num_bytes_allocated_ exceeds this amount then a concurrent GC should be requested so that 896 // it completes ahead of an allocation failing. 897 size_t concurrent_start_bytes_; 898 899 // Since the heap was created, how many bytes have been freed. 900 uint64_t total_bytes_freed_ever_; 901 902 // Since the heap was created, how many objects have been freed. 903 uint64_t total_objects_freed_ever_; 904 905 // Number of bytes allocated. Adjusted after each allocation and free. 906 Atomic<size_t> num_bytes_allocated_; 907 908 // Bytes which are allocated and managed by native code but still need to be accounted for. 909 Atomic<size_t> native_bytes_allocated_; 910 911 // Data structure GC overhead. 912 Atomic<size_t> gc_memory_overhead_; 913 914 // Info related to the current or previous GC iteration. 915 collector::Iteration current_gc_iteration_; 916 917 // Heap verification flags. 918 const bool verify_missing_card_marks_; 919 const bool verify_system_weaks_; 920 const bool verify_pre_gc_heap_; 921 const bool verify_pre_sweeping_heap_; 922 const bool verify_post_gc_heap_; 923 const bool verify_mod_union_table_; 924 bool verify_pre_gc_rosalloc_; 925 bool verify_pre_sweeping_rosalloc_; 926 bool verify_post_gc_rosalloc_; 927 928 // RAII that temporarily disables the rosalloc verification during 929 // the zygote fork. 930 class ScopedDisableRosAllocVerification { 931 private: 932 Heap* const heap_; 933 const bool orig_verify_pre_gc_; 934 const bool orig_verify_pre_sweeping_; 935 const bool orig_verify_post_gc_; 936 937 public: 938 explicit ScopedDisableRosAllocVerification(Heap* heap) 939 : heap_(heap), 940 orig_verify_pre_gc_(heap_->verify_pre_gc_rosalloc_), 941 orig_verify_pre_sweeping_(heap_->verify_pre_sweeping_rosalloc_), 942 orig_verify_post_gc_(heap_->verify_post_gc_rosalloc_) { 943 heap_->verify_pre_gc_rosalloc_ = false; 944 heap_->verify_pre_sweeping_rosalloc_ = false; 945 heap_->verify_post_gc_rosalloc_ = false; 946 } 947 ~ScopedDisableRosAllocVerification() { 948 heap_->verify_pre_gc_rosalloc_ = orig_verify_pre_gc_; 949 heap_->verify_pre_sweeping_rosalloc_ = orig_verify_pre_sweeping_; 950 heap_->verify_post_gc_rosalloc_ = orig_verify_post_gc_; 951 } 952 }; 953 954 // Parallel GC data structures. 955 std::unique_ptr<ThreadPool> thread_pool_; 956 957 // The nanosecond time at which the last GC ended. 958 uint64_t last_gc_time_ns_; 959 960 // How many bytes were allocated at the end of the last GC. 961 uint64_t last_gc_size_; 962 963 // Estimated allocation rate (bytes / second). Computed between the time of the last GC cycle 964 // and the start of the current one. 965 uint64_t allocation_rate_; 966 967 // For a GC cycle, a bitmap that is set corresponding to the 968 std::unique_ptr<accounting::HeapBitmap> live_bitmap_ GUARDED_BY(Locks::heap_bitmap_lock_); 969 std::unique_ptr<accounting::HeapBitmap> mark_bitmap_ GUARDED_BY(Locks::heap_bitmap_lock_); 970 971 // Mark stack that we reuse to avoid re-allocating the mark stack. 972 std::unique_ptr<accounting::ObjectStack> mark_stack_; 973 974 // Allocation stack, new allocations go here so that we can do sticky mark bits. This enables us 975 // to use the live bitmap as the old mark bitmap. 976 const size_t max_allocation_stack_size_; 977 std::unique_ptr<accounting::ObjectStack> allocation_stack_; 978 979 // Second allocation stack so that we can process allocation with the heap unlocked. 980 std::unique_ptr<accounting::ObjectStack> live_stack_; 981 982 // Allocator type. 983 AllocatorType current_allocator_; 984 const AllocatorType current_non_moving_allocator_; 985 986 // Which GCs we run in order when we an allocation fails. 987 std::vector<collector::GcType> gc_plan_; 988 989 // Bump pointer spaces. 990 space::BumpPointerSpace* bump_pointer_space_; 991 // Temp space is the space which the semispace collector copies to. 992 space::BumpPointerSpace* temp_space_; 993 994 // Minimum free guarantees that you always have at least min_free_ free bytes after growing for 995 // utilization, regardless of target utilization ratio. 996 size_t min_free_; 997 998 // The ideal maximum free size, when we grow the heap for utilization. 999 size_t max_free_; 1000 1001 // Target ideal heap utilization ratio 1002 double target_utilization_; 1003 1004 // How much more we grow the heap when we are a foreground app instead of background. 1005 double foreground_heap_growth_multiplier_; 1006 1007 // Total time which mutators are paused or waiting for GC to complete. 1008 uint64_t total_wait_time_; 1009 1010 // Total number of objects allocated in microseconds. 1011 AtomicInteger total_allocation_time_; 1012 1013 // The current state of heap verification, may be enabled or disabled. 1014 VerifyObjectMode verify_object_mode_; 1015 1016 // Compacting GC disable count, prevents compacting GC from running iff > 0. 1017 size_t disable_moving_gc_count_ GUARDED_BY(gc_complete_lock_); 1018 1019 std::vector<collector::GarbageCollector*> garbage_collectors_; 1020 collector::SemiSpace* semi_space_collector_; 1021 collector::MarkCompact* mark_compact_collector_; 1022 collector::ConcurrentCopying* concurrent_copying_collector_; 1023 1024 const bool running_on_valgrind_; 1025 const bool use_tlab_; 1026 1027 // Pointer to the space which becomes the new main space when we do homogeneous space compaction. 1028 // Use unique_ptr since the space is only added during the homogeneous compaction phase. 1029 std::unique_ptr<space::MallocSpace> main_space_backup_; 1030 1031 // Minimal interval allowed between two homogeneous space compactions caused by OOM. 1032 uint64_t min_interval_homogeneous_space_compaction_by_oom_; 1033 1034 // Times of the last homogeneous space compaction caused by OOM. 1035 uint64_t last_time_homogeneous_space_compaction_by_oom_; 1036 1037 // Saved OOMs by homogeneous space compaction. 1038 Atomic<size_t> count_delayed_oom_; 1039 1040 // Count for requested homogeneous space compaction. 1041 Atomic<size_t> count_requested_homogeneous_space_compaction_; 1042 1043 // Count for ignored homogeneous space compaction. 1044 Atomic<size_t> count_ignored_homogeneous_space_compaction_; 1045 1046 // Count for performed homogeneous space compaction. 1047 Atomic<size_t> count_performed_homogeneous_space_compaction_; 1048 1049 // Whether or not we use homogeneous space compaction to avoid OOM errors. 1050 bool use_homogeneous_space_compaction_for_oom_; 1051 1052 friend class collector::GarbageCollector; 1053 friend class collector::MarkCompact; 1054 friend class collector::MarkSweep; 1055 friend class collector::SemiSpace; 1056 friend class ReferenceQueue; 1057 friend class VerifyReferenceCardVisitor; 1058 friend class VerifyReferenceVisitor; 1059 friend class VerifyObjectVisitor; 1060 friend class ScopedHeapFill; 1061 friend class ScopedHeapLock; 1062 friend class space::SpaceTest; 1063 1064 class AllocationTimer { 1065 private: 1066 Heap* heap_; 1067 mirror::Object** allocated_obj_ptr_; 1068 uint64_t allocation_start_time_; 1069 public: 1070 AllocationTimer(Heap* heap, mirror::Object** allocated_obj_ptr); 1071 ~AllocationTimer(); 1072 }; 1073 1074 DISALLOW_IMPLICIT_CONSTRUCTORS(Heap); 1075}; 1076 1077// ScopedHeapFill changes the bytes allocated counter to be equal to the growth limit. This 1078// causes the next allocation to perform a GC and possibly an OOM. It can be used to ensure that a 1079// GC happens in specific methods such as ThrowIllegalMonitorStateExceptionF in Monitor::Wait. 1080class ScopedHeapFill { 1081 public: 1082 explicit ScopedHeapFill(Heap* heap) 1083 : heap_(heap), 1084 delta_(heap_->GetMaxMemory() - heap_->GetBytesAllocated()) { 1085 heap_->num_bytes_allocated_.FetchAndAddSequentiallyConsistent(delta_); 1086 } 1087 ~ScopedHeapFill() { 1088 heap_->num_bytes_allocated_.FetchAndSubSequentiallyConsistent(delta_); 1089 } 1090 1091 private: 1092 Heap* const heap_; 1093 const int64_t delta_; 1094}; 1095 1096} // namespace gc 1097} // namespace art 1098 1099#endif // ART_RUNTIME_GC_HEAP_H_ 1100