Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 790 | 790 |
| 791 static HeapObject* AllocateUnaligned(NewSpace* space, int size) { | 791 static HeapObject* AllocateUnaligned(NewSpace* space, int size) { |
| 792 AllocationResult allocation = space->AllocateRawUnaligned(size); | 792 AllocationResult allocation = space->AllocateRawUnaligned(size); |
| 793 CHECK(!allocation.IsRetry()); | 793 CHECK(!allocation.IsRetry()); |
| 794 HeapObject* filler = NULL; | 794 HeapObject* filler = NULL; |
| 795 CHECK(allocation.To(&filler)); | 795 CHECK(allocation.To(&filler)); |
| 796 space->heap()->CreateFillerObjectAt(filler->address(), size); | 796 space->heap()->CreateFillerObjectAt(filler->address(), size); |
| 797 return filler; | 797 return filler; |
| 798 } | 798 } |
| 799 | 799 |
| 800 class Observer : public InlineAllocationObserver { | 800 class Observer : public AllocationObserver { |
| 801 public: | 801 public: |
| 802 explicit Observer(intptr_t step_size) | 802 Observer(Heap* heap, intptr_t step_size) |
| 803 : InlineAllocationObserver(step_size), count_(0) {} | 803 : AllocationObserver(heap, step_size), count_(0) {} |
| 804 | 804 |
| 805 void Step(int bytes_allocated, Address, size_t) override { count_++; } | 805 void Step(int bytes_allocated, Address, size_t) override { count_++; } |
| 806 | 806 |
| 807 int count() const { return count_; } | 807 int count() const { return count_; } |
| 808 | 808 |
| 809 private: | 809 private: |
| 810 int count_; | 810 int count_; |
| 811 }; | 811 }; |
| 812 | 812 |
| 813 | 813 |
| 814 UNINITIALIZED_TEST(InlineAllocationObserver) { | 814 UNINITIALIZED_TEST(AllocationObserver) { |
| 815 v8::Isolate::CreateParams create_params; | 815 v8::Isolate::CreateParams create_params; |
| 816 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 816 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| 817 v8::Isolate* isolate = v8::Isolate::New(create_params); | 817 v8::Isolate* isolate = v8::Isolate::New(create_params); |
| 818 { | 818 { |
| 819 v8::Isolate::Scope isolate_scope(isolate); | 819 v8::Isolate::Scope isolate_scope(isolate); |
| 820 v8::HandleScope handle_scope(isolate); | 820 v8::HandleScope handle_scope(isolate); |
| 821 v8::Context::New(isolate)->Enter(); | 821 v8::Context::New(isolate)->Enter(); |
| 822 | 822 |
| 823 Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate); | 823 Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate); |
| 824 | 824 |
| 825 NewSpace* new_space = i_isolate->heap()->new_space(); | 825 NewSpace* new_space = i_isolate->heap()->new_space(); |
| 826 | 826 |
| 827 Observer observer1(128); | 827 Observer observer1(i_isolate->heap(), 128); |
| 828 new_space->AddInlineAllocationObserver(&observer1); | 828 new_space->AddInlineAllocationObserver(&observer1); |
| 829 | 829 |
| 830 // The observer should not get notified if we have only allocated less than | 830 // The observer should not get notified if we have only allocated less than |
| 831 // 128 bytes. | 831 // 128 bytes. |
| 832 AllocateUnaligned(new_space, 64); | 832 AllocateUnaligned(new_space, 64); |
| 833 CHECK_EQ(observer1.count(), 0); | 833 CHECK_EQ(observer1.count(), 0); |
| 834 | 834 |
| 835 // The observer should get called when we have allocated exactly 128 bytes. | 835 // The observer should get called when we have allocated exactly 128 bytes. |
| 836 AllocateUnaligned(new_space, 64); | 836 AllocateUnaligned(new_space, 64); |
| 837 CHECK_EQ(observer1.count(), 1); | 837 CHECK_EQ(observer1.count(), 1); |
| 838 | 838 |
| 839 // Another >128 bytes should get another notification. | 839 // Another >128 bytes should get another notification. |
| 840 AllocateUnaligned(new_space, 136); | 840 AllocateUnaligned(new_space, 136); |
| 841 CHECK_EQ(observer1.count(), 2); | 841 CHECK_EQ(observer1.count(), 2); |
| 842 | 842 |
| 843 // Allocating a large object should get only one notification. | 843 // Allocating a large object should get only one notification. |
| 844 AllocateUnaligned(new_space, 1024); | 844 AllocateUnaligned(new_space, 1024); |
| 845 CHECK_EQ(observer1.count(), 3); | 845 CHECK_EQ(observer1.count(), 3); |
| 846 | 846 |
| 847 // Allocating another 2048 bytes in small objects should get 16 | 847 // Allocating another 2048 bytes in small objects should get 16 |
| 848 // notifications. | 848 // notifications. |
| 849 for (int i = 0; i < 64; ++i) { | 849 for (int i = 0; i < 64; ++i) { |
| 850 AllocateUnaligned(new_space, 32); | 850 AllocateUnaligned(new_space, 32); |
| 851 } | 851 } |
| 852 CHECK_EQ(observer1.count(), 19); | 852 CHECK_EQ(observer1.count(), 19); |
| 853 | 853 |
| 854 // Multiple observers should work. | 854 // Multiple observers should work. |
| 855 Observer observer2(96); | 855 Observer observer2(i_isolate->heap(), 96); |
| 856 new_space->AddInlineAllocationObserver(&observer2); | 856 new_space->AddInlineAllocationObserver(&observer2); |
| 857 | 857 |
| 858 AllocateUnaligned(new_space, 2048); | 858 AllocateUnaligned(new_space, 2048); |
| 859 CHECK_EQ(observer1.count(), 20); | 859 CHECK_EQ(observer1.count(), 20); |
| 860 CHECK_EQ(observer2.count(), 1); | 860 CHECK_EQ(observer2.count(), 1); |
| 861 | 861 |
| 862 AllocateUnaligned(new_space, 104); | 862 AllocateUnaligned(new_space, 104); |
| 863 CHECK_EQ(observer1.count(), 20); | 863 CHECK_EQ(observer1.count(), 20); |
| 864 CHECK_EQ(observer2.count(), 2); | 864 CHECK_EQ(observer2.count(), 2); |
| 865 | 865 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 900 v8::Isolate* isolate = v8::Isolate::New(create_params); | 900 v8::Isolate* isolate = v8::Isolate::New(create_params); |
| 901 { | 901 { |
| 902 v8::Isolate::Scope isolate_scope(isolate); | 902 v8::Isolate::Scope isolate_scope(isolate); |
| 903 v8::HandleScope handle_scope(isolate); | 903 v8::HandleScope handle_scope(isolate); |
| 904 v8::Context::New(isolate)->Enter(); | 904 v8::Context::New(isolate)->Enter(); |
| 905 | 905 |
| 906 Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate); | 906 Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate); |
| 907 | 907 |
| 908 NewSpace* new_space = i_isolate->heap()->new_space(); | 908 NewSpace* new_space = i_isolate->heap()->new_space(); |
| 909 | 909 |
| 910 Observer observer1(512); | 910 Observer observer1(i_isolate->heap(), 512); |
| 911 new_space->AddInlineAllocationObserver(&observer1); | 911 new_space->AddInlineAllocationObserver(&observer1); |
| 912 Observer observer2(576); | 912 Observer observer2(i_isolate->heap(), 576); |
| 913 new_space->AddInlineAllocationObserver(&observer2); | 913 new_space->AddInlineAllocationObserver(&observer2); |
| 914 | 914 |
| 915 for (int i = 0; i < 512; ++i) { | 915 for (int i = 0; i < 512; ++i) { |
| 916 AllocateUnaligned(new_space, 32); | 916 AllocateUnaligned(new_space, 32); |
| 917 } | 917 } |
| 918 | 918 |
| 919 new_space->RemoveInlineAllocationObserver(&observer1); | 919 new_space->RemoveInlineAllocationObserver(&observer1); |
| 920 new_space->RemoveInlineAllocationObserver(&observer2); | 920 new_space->RemoveInlineAllocationObserver(&observer2); |
| 921 | 921 |
| 922 CHECK_EQ(observer1.count(), 32); | 922 CHECK_EQ(observer1.count(), 32); |
| 923 CHECK_EQ(observer2.count(), 28); | 923 CHECK_EQ(observer2.count(), 28); |
| 924 } | 924 } |
| 925 isolate->Dispose(); | 925 isolate->Dispose(); |
|
ofrobots
2016/01/23 16:16:31
Add tests for old space, lo space, map space, code
mattloring
2016/01/26 00:42:48
Getting to these next, just wanted to hammer out t
| |
| 926 } | 926 } |
| 927 | 927 |
| 928 } // namespace internal | 928 } // namespace internal |
| 929 } // namespace v8 | 929 } // namespace v8 |
| OLD | NEW |