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

Side by Side Diff: test/cctest/test-spaces.cc

Issue 1404523002: [heap] inline allocation steps refactor (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Use virtual functions instead of callbacks Created 5 years, 2 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
« src/heap/spaces.h ('K') | « test/cctest/cctest.h ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 638
639 // Turn the allocation into a proper object so isolate teardown won't 639 // Turn the allocation into a proper object so isolate teardown won't
640 // crash. 640 // crash.
641 HeapObject* free_space = NULL; 641 HeapObject* free_space = NULL;
642 CHECK(allocation.To(&free_space)); 642 CHECK(allocation.To(&free_space));
643 new_space->heap()->CreateFillerObjectAt(free_space->address(), 80); 643 new_space->heap()->CreateFillerObjectAt(free_space->address(), 80);
644 } 644 }
645 } 645 }
646 isolate->Dispose(); 646 isolate->Dispose();
647 } 647 }
648
649
650 static HeapObject* AllocateUnaligned(NewSpace* space, int size) {
651 AllocationResult allocation = space->AllocateRawUnaligned(size);
652 CHECK(!allocation.IsRetry());
653 HeapObject* filler = NULL;
654 CHECK(allocation.To(&filler));
655 space->heap()->CreateFillerObjectAt(filler->address(), size);
656 return filler;
657 }
658
659 class Observer : public InlineAllocationObserver {
660 public:
661 explicit Observer(intptr_t step_size)
662 : InlineAllocationObserver(step_size), count_(0) {}
663
664 virtual void Step(int bytes_allocated) { count_++; }
665
666 int count() const { return count_; }
667
668 private:
669 int count_;
670 };
671
672
673 UNINITIALIZED_TEST(InlineAllocationObserver) {
674 v8::Isolate::CreateParams create_params;
675 create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
676 v8::Isolate* isolate = v8::Isolate::New(create_params);
677 {
678 v8::Isolate::Scope isolate_scope(isolate);
679 v8::HandleScope handle_scope(isolate);
680 v8::Context::New(isolate)->Enter();
681
682 Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate);
683
684 NewSpace* new_space = i_isolate->heap()->new_space();
685
686 Observer observer1(128);
687 new_space->AddInlineAllocationObserver(&observer1);
688
689 // The observer should not get notified until we have allocated a 128 bytes.
690 AllocateUnaligned(new_space, 64);
691 CHECK_EQ(observer1.count(), 0);
692
693 // The observer should get notified when have allocated precisely 128 bytes.
694 AllocateUnaligned(new_space, 64);
695 CHECK_EQ(observer1.count(), 1);
696
697 // Another 128 bytes should get another notification.
698 AllocateUnaligned(new_space, 128);
699 CHECK_EQ(observer1.count(), 2);
700
701 // Allocating a large object should get only one notification.
702 AllocateUnaligned(new_space, 1024);
703 CHECK_EQ(observer1.count(), 3);
704
705 // Allocating another 2048 bytes in small objects should get 16
706 // notifications.
707 for (int i = 0; i < 64; ++i) {
708 AllocateUnaligned(new_space, 32);
709 }
710 CHECK_EQ(observer1.count(), 19);
711
712 // Multiple observers should work.
713 Observer observer2(96);
714 new_space->AddInlineAllocationObserver(&observer2);
715
716 AllocateUnaligned(new_space, 2048);
717 CHECK_EQ(observer1.count(), 20);
718 CHECK_EQ(observer2.count(), 1);
719
720 AllocateUnaligned(new_space, 96);
721 CHECK_EQ(observer1.count(), 20);
722 CHECK_EQ(observer2.count(), 2);
723
724 // Callback should stop getting called after an observer is removed.
725 new_space->RemoveInlineAllocationObserver(&observer1);
726
727 AllocateUnaligned(new_space, 384);
728 CHECK_EQ(observer1.count(), 20); // no more notifications.
729 CHECK_EQ(observer2.count(), 3); // this one is still active.
730
731 new_space->RemoveInlineAllocationObserver(&observer2);
732 AllocateUnaligned(new_space, 384);
733 CHECK_EQ(observer1.count(), 20);
734 CHECK_EQ(observer2.count(), 3);
735 }
736 isolate->Dispose();
737 }
OLDNEW
« src/heap/spaces.h ('K') | « test/cctest/cctest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698