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

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

Issue 1448913003: [heap] make inline-allocation-observers precise (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Needed to remove the second instance of the limit alignment assertion Created 5 years, 1 month 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/spaces.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 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 816 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 NewSpace* new_space = i_isolate->heap()->new_space(); 827 NewSpace* new_space = i_isolate->heap()->new_space();
828 828
829 Observer observer1(128); 829 Observer observer1(128);
830 new_space->AddInlineAllocationObserver(&observer1); 830 new_space->AddInlineAllocationObserver(&observer1);
831 831
832 // The observer should not get notified if we have only allocated less than 832 // The observer should not get notified if we have only allocated less than
833 // 128 bytes. 833 // 128 bytes.
834 AllocateUnaligned(new_space, 64); 834 AllocateUnaligned(new_space, 64);
835 CHECK_EQ(observer1.count(), 0); 835 CHECK_EQ(observer1.count(), 0);
836 836
837 // The observer should not get called even when we have allocated exactly 837 // The observer should get called when we have allocated exactly 128 bytes.
838 // 128 bytes.
839 AllocateUnaligned(new_space, 64); 838 AllocateUnaligned(new_space, 64);
840 CHECK_EQ(observer1.count(), 0);
841
842 // The next allocation gets the notification.
843 AllocateUnaligned(new_space, 8);
844 CHECK_EQ(observer1.count(), 1); 839 CHECK_EQ(observer1.count(), 1);
845 840
846 // Another >128 bytes should get another notification. 841 // Another >128 bytes should get another notification.
847 AllocateUnaligned(new_space, 136); 842 AllocateUnaligned(new_space, 136);
848 CHECK_EQ(observer1.count(), 2); 843 CHECK_EQ(observer1.count(), 2);
849 844
850 // Allocating a large object should get only one notification. 845 // Allocating a large object should get only one notification.
851 AllocateUnaligned(new_space, 1024); 846 AllocateUnaligned(new_space, 1024);
852 CHECK_EQ(observer1.count(), 3); 847 CHECK_EQ(observer1.count(), 3);
853 848
854 // Allocating another 2048 bytes in small objects should get 12 849 // Allocating another 2048 bytes in small objects should get 16
855 // notifications. 850 // notifications.
856 for (int i = 0; i < 64; ++i) { 851 for (int i = 0; i < 64; ++i) {
857 AllocateUnaligned(new_space, 32); 852 AllocateUnaligned(new_space, 32);
858 } 853 }
859 CHECK_EQ(observer1.count(), 15); 854 CHECK_EQ(observer1.count(), 19);
860 855
861 // Multiple observers should work. 856 // Multiple observers should work.
862 Observer observer2(96); 857 Observer observer2(96);
863 new_space->AddInlineAllocationObserver(&observer2); 858 new_space->AddInlineAllocationObserver(&observer2);
864 859
865 AllocateUnaligned(new_space, 2048); 860 AllocateUnaligned(new_space, 2048);
866 CHECK_EQ(observer1.count(), 16); 861 CHECK_EQ(observer1.count(), 20);
867 CHECK_EQ(observer2.count(), 1); 862 CHECK_EQ(observer2.count(), 1);
868 863
869 AllocateUnaligned(new_space, 104); 864 AllocateUnaligned(new_space, 104);
870 CHECK_EQ(observer1.count(), 16); 865 CHECK_EQ(observer1.count(), 20);
871 CHECK_EQ(observer2.count(), 2); 866 CHECK_EQ(observer2.count(), 2);
872 867
873 // Callback should stop getting called after an observer is removed. 868 // Callback should stop getting called after an observer is removed.
874 new_space->RemoveInlineAllocationObserver(&observer1); 869 new_space->RemoveInlineAllocationObserver(&observer1);
875 870
876 AllocateUnaligned(new_space, 384); 871 AllocateUnaligned(new_space, 384);
877 CHECK_EQ(observer1.count(), 16); // no more notifications. 872 CHECK_EQ(observer1.count(), 20); // no more notifications.
878 CHECK_EQ(observer2.count(), 3); // this one is still active. 873 CHECK_EQ(observer2.count(), 3); // this one is still active.
879 874
880 new_space->RemoveInlineAllocationObserver(&observer2); 875 new_space->RemoveInlineAllocationObserver(&observer2);
881 AllocateUnaligned(new_space, 384); 876 AllocateUnaligned(new_space, 384);
882 CHECK_EQ(observer1.count(), 16); 877 CHECK_EQ(observer1.count(), 20);
883 CHECK_EQ(observer2.count(), 3); 878 CHECK_EQ(observer2.count(), 3);
884 } 879 }
885 isolate->Dispose(); 880 isolate->Dispose();
886 } 881 }
887 882
888 883
889 UNINITIALIZED_TEST(InlineAllocationObserverCadence) { 884 UNINITIALIZED_TEST(InlineAllocationObserverCadence) {
890 v8::Isolate::CreateParams create_params; 885 v8::Isolate::CreateParams create_params;
891 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); 886 create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
892 v8::Isolate* isolate = v8::Isolate::New(create_params); 887 v8::Isolate* isolate = v8::Isolate::New(create_params);
(...skipping 11 matching lines...) Expand all
904 Observer observer2(576); 899 Observer observer2(576);
905 new_space->AddInlineAllocationObserver(&observer2); 900 new_space->AddInlineAllocationObserver(&observer2);
906 901
907 for (int i = 0; i < 512; ++i) { 902 for (int i = 0; i < 512; ++i) {
908 AllocateUnaligned(new_space, 32); 903 AllocateUnaligned(new_space, 32);
909 } 904 }
910 905
911 new_space->RemoveInlineAllocationObserver(&observer1); 906 new_space->RemoveInlineAllocationObserver(&observer1);
912 new_space->RemoveInlineAllocationObserver(&observer2); 907 new_space->RemoveInlineAllocationObserver(&observer2);
913 908
914 CHECK_EQ(observer1.count(), 30); 909 CHECK_EQ(observer1.count(), 32);
915 CHECK_EQ(observer2.count(), 26); 910 CHECK_EQ(observer2.count(), 28);
916 } 911 }
917 isolate->Dispose(); 912 isolate->Dispose();
918 } 913 }
919 914
920 } // namespace internal 915 } // namespace internal
921 } // namespace v8 916 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/spaces.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698