Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: src/heap-inl.h

Issue 310393003: Move most of the implementation of AdjustAmountOfExternalMemory to v8.h (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: updates Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/heap.cc ('k') | src/isolate.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_HEAP_INL_H_ 5 #ifndef V8_HEAP_INL_H_
6 #define V8_HEAP_INL_H_ 6 #define V8_HEAP_INL_H_
7 7
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "src/heap.h" 10 #include "src/heap.h"
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 520
521 bool Heap::CollectGarbage(AllocationSpace space, 521 bool Heap::CollectGarbage(AllocationSpace space,
522 const char* gc_reason, 522 const char* gc_reason,
523 const v8::GCCallbackFlags callbackFlags) { 523 const v8::GCCallbackFlags callbackFlags) {
524 const char* collector_reason = NULL; 524 const char* collector_reason = NULL;
525 GarbageCollector collector = SelectGarbageCollector(space, &collector_reason); 525 GarbageCollector collector = SelectGarbageCollector(space, &collector_reason);
526 return CollectGarbage(collector, gc_reason, collector_reason, callbackFlags); 526 return CollectGarbage(collector, gc_reason, collector_reason, callbackFlags);
527 } 527 }
528 528
529 529
530 int64_t Heap::AdjustAmountOfExternalAllocatedMemory(
531 int64_t change_in_bytes) {
532 ASSERT(HasBeenSetUp());
533 int64_t amount = amount_of_external_allocated_memory_ + change_in_bytes;
534 if (change_in_bytes > 0) {
535 // Avoid overflow.
536 if (amount > amount_of_external_allocated_memory_) {
537 amount_of_external_allocated_memory_ = amount;
538 } else {
539 // Give up and reset the counters in case of an overflow.
540 amount_of_external_allocated_memory_ = 0;
541 amount_of_external_allocated_memory_at_last_global_gc_ = 0;
542 }
543 int64_t amount_since_last_global_gc = PromotedExternalMemorySize();
544 if (amount_since_last_global_gc > external_allocation_limit_) {
545 CollectAllGarbage(kNoGCFlags, "external memory allocation limit reached");
546 }
547 } else {
548 // Avoid underflow.
549 if (amount >= 0) {
550 amount_of_external_allocated_memory_ = amount;
551 } else {
552 // Give up and reset the counters in case of an underflow.
553 amount_of_external_allocated_memory_ = 0;
554 amount_of_external_allocated_memory_at_last_global_gc_ = 0;
555 }
556 }
557 if (FLAG_trace_external_memory) {
558 PrintPID("%8.0f ms: ", isolate()->time_millis_since_init());
559 PrintF("Adjust amount of external memory: delta=%6" V8_PTR_PREFIX "d KB, "
560 "amount=%6" V8_PTR_PREFIX "d KB, since_gc=%6" V8_PTR_PREFIX "d KB, "
561 "isolate=0x%08" V8PRIxPTR ".\n",
562 static_cast<intptr_t>(change_in_bytes / KB),
563 static_cast<intptr_t>(amount_of_external_allocated_memory_ / KB),
564 static_cast<intptr_t>(PromotedExternalMemorySize() / KB),
565 reinterpret_cast<intptr_t>(isolate()));
566 }
567 ASSERT(amount_of_external_allocated_memory_ >= 0);
568 return amount_of_external_allocated_memory_;
569 }
570
571
572 Isolate* Heap::isolate() { 530 Isolate* Heap::isolate() {
573 return reinterpret_cast<Isolate*>(reinterpret_cast<intptr_t>(this) - 531 return reinterpret_cast<Isolate*>(reinterpret_cast<intptr_t>(this) -
574 reinterpret_cast<size_t>(reinterpret_cast<Isolate*>(4)->heap()) + 4); 532 reinterpret_cast<size_t>(reinterpret_cast<Isolate*>(4)->heap()) + 4);
575 } 533 }
576 534
577 535
578 // Calls the FUNCTION_CALL function and retries it up to three times 536 // Calls the FUNCTION_CALL function and retries it up to three times
579 // to guarantee that any allocations performed during the call will 537 // to guarantee that any allocations performed during the call will
580 // succeed if there's enough memory. 538 // succeed if there's enough memory.
581 539
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 725
768 726
769 double GCTracer::SizeOfHeapObjects() { 727 double GCTracer::SizeOfHeapObjects() {
770 return (static_cast<double>(heap_->SizeOfObjects())) / MB; 728 return (static_cast<double>(heap_->SizeOfObjects())) / MB;
771 } 729 }
772 730
773 731
774 } } // namespace v8::internal 732 } } // namespace v8::internal
775 733
776 #endif // V8_HEAP_INL_H_ 734 #endif // V8_HEAP_INL_H_
OLDNEW
« no previous file with comments | « src/heap.cc ('k') | src/isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698