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

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

Issue 1312553003: [heap] Prevent direct access to ExternalStringTable. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@local_cleanup-heap-root-set-1
Patch Set: Addressed comments. Created 5 years, 4 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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 void Heap::UpdateAllocationsHash(uint32_t value) { 316 void Heap::UpdateAllocationsHash(uint32_t value) {
317 uint16_t c1 = static_cast<uint16_t>(value); 317 uint16_t c1 = static_cast<uint16_t>(value);
318 uint16_t c2 = static_cast<uint16_t>(value >> 16); 318 uint16_t c2 = static_cast<uint16_t>(value >> 16);
319 raw_allocations_hash_ = 319 raw_allocations_hash_ =
320 StringHasher::AddCharacterCore(raw_allocations_hash_, c1); 320 StringHasher::AddCharacterCore(raw_allocations_hash_, c1);
321 raw_allocations_hash_ = 321 raw_allocations_hash_ =
322 StringHasher::AddCharacterCore(raw_allocations_hash_, c2); 322 StringHasher::AddCharacterCore(raw_allocations_hash_, c2);
323 } 323 }
324 324
325 325
326 void Heap::RegisterExternalString(String* string) {
327 external_string_table_.AddString(string);
328 }
329
330
326 void Heap::FinalizeExternalString(String* string) { 331 void Heap::FinalizeExternalString(String* string) {
327 DCHECK(string->IsExternalString()); 332 DCHECK(string->IsExternalString());
328 v8::String::ExternalStringResourceBase** resource_addr = 333 v8::String::ExternalStringResourceBase** resource_addr =
329 reinterpret_cast<v8::String::ExternalStringResourceBase**>( 334 reinterpret_cast<v8::String::ExternalStringResourceBase**>(
330 reinterpret_cast<byte*>(string) + ExternalString::kResourceOffset - 335 reinterpret_cast<byte*>(string) + ExternalString::kResourceOffset -
331 kHeapObjectTag); 336 kHeapObjectTag);
332 337
333 // Dispose of the C++ object if it has not already been disposed. 338 // Dispose of the C++ object if it has not already been disposed.
334 if (*resource_addr != NULL) { 339 if (*resource_addr != NULL) {
335 (*resource_addr)->Dispose(); 340 (*resource_addr)->Dispose();
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 #define CALL_HEAP_FUNCTION(ISOLATE, FUNCTION_CALL, TYPE) \ 606 #define CALL_HEAP_FUNCTION(ISOLATE, FUNCTION_CALL, TYPE) \
602 CALL_AND_RETRY_OR_DIE(ISOLATE, FUNCTION_CALL, \ 607 CALL_AND_RETRY_OR_DIE(ISOLATE, FUNCTION_CALL, \
603 return Handle<TYPE>(TYPE::cast(__object__), ISOLATE), \ 608 return Handle<TYPE>(TYPE::cast(__object__), ISOLATE), \
604 return Handle<TYPE>()) 609 return Handle<TYPE>())
605 610
606 611
607 #define CALL_HEAP_FUNCTION_VOID(ISOLATE, FUNCTION_CALL) \ 612 #define CALL_HEAP_FUNCTION_VOID(ISOLATE, FUNCTION_CALL) \
608 CALL_AND_RETRY_OR_DIE(ISOLATE, FUNCTION_CALL, return, return) 613 CALL_AND_RETRY_OR_DIE(ISOLATE, FUNCTION_CALL, return, return)
609 614
610 615
611 void ExternalStringTable::AddString(String* string) { 616 void Heap::ExternalStringTable::AddString(String* string) {
612 DCHECK(string->IsExternalString()); 617 DCHECK(string->IsExternalString());
613 if (heap_->InNewSpace(string)) { 618 if (heap_->InNewSpace(string)) {
614 new_space_strings_.Add(string); 619 new_space_strings_.Add(string);
615 } else { 620 } else {
616 old_space_strings_.Add(string); 621 old_space_strings_.Add(string);
617 } 622 }
618 } 623 }
619 624
620 625
621 void ExternalStringTable::Iterate(ObjectVisitor* v) { 626 void Heap::ExternalStringTable::Iterate(ObjectVisitor* v) {
622 if (!new_space_strings_.is_empty()) { 627 if (!new_space_strings_.is_empty()) {
623 Object** start = &new_space_strings_[0]; 628 Object** start = &new_space_strings_[0];
624 v->VisitPointers(start, start + new_space_strings_.length()); 629 v->VisitPointers(start, start + new_space_strings_.length());
625 } 630 }
626 if (!old_space_strings_.is_empty()) { 631 if (!old_space_strings_.is_empty()) {
627 Object** start = &old_space_strings_[0]; 632 Object** start = &old_space_strings_[0];
628 v->VisitPointers(start, start + old_space_strings_.length()); 633 v->VisitPointers(start, start + old_space_strings_.length());
629 } 634 }
630 } 635 }
631 636
632 637
633 // Verify() is inline to avoid ifdef-s around its calls in release 638 // Verify() is inline to avoid ifdef-s around its calls in release
634 // mode. 639 // mode.
635 void ExternalStringTable::Verify() { 640 void Heap::ExternalStringTable::Verify() {
636 #ifdef DEBUG 641 #ifdef DEBUG
637 for (int i = 0; i < new_space_strings_.length(); ++i) { 642 for (int i = 0; i < new_space_strings_.length(); ++i) {
638 Object* obj = Object::cast(new_space_strings_[i]); 643 Object* obj = Object::cast(new_space_strings_[i]);
639 DCHECK(heap_->InNewSpace(obj)); 644 DCHECK(heap_->InNewSpace(obj));
640 DCHECK(obj != heap_->the_hole_value()); 645 DCHECK(obj != heap_->the_hole_value());
641 } 646 }
642 for (int i = 0; i < old_space_strings_.length(); ++i) { 647 for (int i = 0; i < old_space_strings_.length(); ++i) {
643 Object* obj = Object::cast(old_space_strings_[i]); 648 Object* obj = Object::cast(old_space_strings_[i]);
644 DCHECK(!heap_->InNewSpace(obj)); 649 DCHECK(!heap_->InNewSpace(obj));
645 DCHECK(obj != heap_->the_hole_value()); 650 DCHECK(obj != heap_->the_hole_value());
646 } 651 }
647 #endif 652 #endif
648 } 653 }
649 654
650 655
651 void ExternalStringTable::AddOldString(String* string) { 656 void Heap::ExternalStringTable::AddOldString(String* string) {
652 DCHECK(string->IsExternalString()); 657 DCHECK(string->IsExternalString());
653 DCHECK(!heap_->InNewSpace(string)); 658 DCHECK(!heap_->InNewSpace(string));
654 old_space_strings_.Add(string); 659 old_space_strings_.Add(string);
655 } 660 }
656 661
657 662
658 void ExternalStringTable::ShrinkNewStrings(int position) { 663 void Heap::ExternalStringTable::ShrinkNewStrings(int position) {
659 new_space_strings_.Rewind(position); 664 new_space_strings_.Rewind(position);
660 #ifdef VERIFY_HEAP 665 #ifdef VERIFY_HEAP
661 if (FLAG_verify_heap) { 666 if (FLAG_verify_heap) {
662 Verify(); 667 Verify();
663 } 668 }
664 #endif 669 #endif
665 } 670 }
666 671
667 672
668 int DescriptorLookupCache::Lookup(Map* source, Name* name) { 673 int DescriptorLookupCache::Lookup(Map* source, Name* name) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 784
780 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) { 785 void VerifySmisVisitor::VisitPointers(Object** start, Object** end) {
781 for (Object** current = start; current < end; current++) { 786 for (Object** current = start; current < end; current++) {
782 CHECK((*current)->IsSmi()); 787 CHECK((*current)->IsSmi());
783 } 788 }
784 } 789 }
785 } 790 }
786 } // namespace v8::internal 791 } // namespace v8::internal
787 792
788 #endif // V8_HEAP_HEAP_INL_H_ 793 #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