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

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

Issue 2316513002: [heap] Cleanup heap.h (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « src/heap/heap.cc ('k') | no next file » | 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_HEAP_INL_H_ 5 #ifndef V8_HEAP_HEAP_INL_H_
6 #define V8_HEAP_HEAP_INL_H_ 6 #define V8_HEAP_HEAP_INL_H_
7 7
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 /* The deserializer makes use of the fact that these common roots are */ \ 138 /* The deserializer makes use of the fact that these common roots are */ \
139 /* never in new space and never on a page that is being compacted. */ \ 139 /* never in new space and never on a page that is being compacted. */ \
140 DCHECK(!deserialization_complete() || \ 140 DCHECK(!deserialization_complete() || \
141 RootCanBeWrittenAfterInitialization(k##camel_name##RootIndex)); \ 141 RootCanBeWrittenAfterInitialization(k##camel_name##RootIndex)); \
142 DCHECK(k##camel_name##RootIndex >= kOldSpaceRoots || !InNewSpace(value)); \ 142 DCHECK(k##camel_name##RootIndex >= kOldSpaceRoots || !InNewSpace(value)); \
143 roots_[k##camel_name##RootIndex] = value; \ 143 roots_[k##camel_name##RootIndex] = value; \
144 } 144 }
145 ROOT_LIST(ROOT_ACCESSOR) 145 ROOT_LIST(ROOT_ACCESSOR)
146 #undef ROOT_ACCESSOR 146 #undef ROOT_ACCESSOR
147 147
148 PagedSpace* Heap::paged_space(int idx) {
149 switch (idx) {
150 case OLD_SPACE:
151 return old_space();
152 case MAP_SPACE:
153 return map_space();
154 case CODE_SPACE:
155 return code_space();
156 case NEW_SPACE:
157 case LO_SPACE:
158 UNREACHABLE();
159 }
160 return NULL;
161 }
162
163 Space* Heap::space(int idx) {
164 switch (idx) {
165 case NEW_SPACE:
166 return new_space();
167 case LO_SPACE:
168 return lo_space();
169 default:
170 return paged_space(idx);
171 }
172 }
173
174 Address* Heap::NewSpaceAllocationTopAddress() {
175 return new_space_.allocation_top_address();
176 }
177
178 Address* Heap::NewSpaceAllocationLimitAddress() {
179 return new_space_.allocation_limit_address();
180 }
181
182 Address* Heap::OldSpaceAllocationTopAddress() {
183 return old_space_->allocation_top_address();
184 }
185
186 Address* Heap::OldSpaceAllocationLimitAddress() {
187 return old_space_->allocation_limit_address();
188 }
189
190 bool Heap::HeapIsFullEnoughToStartIncrementalMarking(intptr_t limit) {
191 if (FLAG_stress_compaction && (gc_count_ & 1) != 0) return true;
192
193 intptr_t adjusted_allocation_limit = limit - new_space_.Capacity();
194
195 if (PromotedTotalSize() >= adjusted_allocation_limit) return true;
196
197 if (HighMemoryPressure()) return true;
198
199 return false;
200 }
201
202 void Heap::UpdateNewSpaceAllocationCounter() {
203 new_space_allocation_counter_ = NewSpaceAllocationCounter();
204 }
205
206 size_t Heap::NewSpaceAllocationCounter() {
207 return new_space_allocation_counter_ + new_space()->AllocatedSinceLastGC();
208 }
148 209
149 template <> 210 template <>
150 bool inline Heap::IsOneByte(Vector<const char> str, int chars) { 211 bool inline Heap::IsOneByte(Vector<const char> str, int chars) {
151 // TODO(dcarney): incorporate Latin-1 check when Latin-1 is supported? 212 // TODO(dcarney): incorporate Latin-1 check when Latin-1 is supported?
152 return chars == str.length(); 213 return chars == str.length();
153 } 214 }
154 215
155 216
156 template <> 217 template <>
157 bool inline Heap::IsOneByte(String* str, int chars) { 218 bool inline Heap::IsOneByte(String* str, int chars) {
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 467
407 // Dispose of the C++ object if it has not already been disposed. 468 // Dispose of the C++ object if it has not already been disposed.
408 if (*resource_addr != NULL) { 469 if (*resource_addr != NULL) {
409 (*resource_addr)->Dispose(); 470 (*resource_addr)->Dispose();
410 *resource_addr = NULL; 471 *resource_addr = NULL;
411 } 472 }
412 } 473 }
413 474
414 475
415 bool Heap::InNewSpace(Object* object) { 476 bool Heap::InNewSpace(Object* object) {
416 bool result = new_space_.Contains(object); 477 // Inlined check from NewSpace::Contains.
478 bool result =
479 object->IsHeapObject() &&
480 Page::FromAddress(HeapObject::cast(object)->address())->InNewSpace();
417 DCHECK(!result || // Either not in new space 481 DCHECK(!result || // Either not in new space
418 gc_state_ != NOT_IN_GC || // ... or in the middle of GC 482 gc_state_ != NOT_IN_GC || // ... or in the middle of GC
419 InToSpace(object)); // ... or in to-space (where we allocate). 483 InToSpace(object)); // ... or in to-space (where we allocate).
420 return result; 484 return result;
421 } 485 }
422 486
423 bool Heap::InFromSpace(Object* object) { 487 bool Heap::InFromSpace(Object* object) {
424 return new_space_.FromSpaceContains(object); 488 return object->IsHeapObject() &&
489 MemoryChunk::FromAddress(HeapObject::cast(object)->address())
490 ->IsFlagSet(Page::IN_FROM_SPACE);
425 } 491 }
426 492
427 493
428 bool Heap::InToSpace(Object* object) { 494 bool Heap::InToSpace(Object* object) {
429 return new_space_.ToSpaceContains(object); 495 return object->IsHeapObject() &&
496 MemoryChunk::FromAddress(HeapObject::cast(object)->address())
497 ->IsFlagSet(Page::IN_TO_SPACE);
430 } 498 }
431 499
432 bool Heap::InOldSpace(Object* object) { return old_space_->Contains(object); } 500 bool Heap::InOldSpace(Object* object) { return old_space_->Contains(object); }
433 501
434 bool Heap::InNewSpaceSlow(Address address) { 502 bool Heap::InNewSpaceSlow(Address address) {
435 return new_space_.ContainsSlow(address); 503 return new_space_.ContainsSlow(address);
436 } 504 }
437 505
438 bool Heap::InOldSpaceSlow(Address address) { 506 bool Heap::InOldSpaceSlow(Address address) {
439 return old_space_->ContainsSlow(address); 507 return old_space_->ContainsSlow(address);
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 905
838 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) { 906 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) {
839 for (Object** current = start; current < end; current++) { 907 for (Object** current = start; current < end; current++) {
840 CHECK((*current)->IsSmi()); 908 CHECK((*current)->IsSmi());
841 } 909 }
842 } 910 }
843 } // namespace internal 911 } // namespace internal
844 } // namespace v8 912 } // namespace v8
845 913
846 #endif // V8_HEAP_HEAP_INL_H_ 914 #endif // V8_HEAP_HEAP_INL_H_
OLDNEW
« no previous file with comments | « src/heap/heap.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698