OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 12 matching lines...) Expand all Loading... |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include "src/v8.h" | 28 #include "src/v8.h" |
29 #include "test/cctest/cctest.h" | 29 #include "test/cctest/cctest.h" |
30 | 30 |
31 #include "src/accessors.h" | 31 #include "src/accessors.h" |
32 #include "src/api.h" | 32 #include "src/api.h" |
| 33 #include "test/cctest/heap-tester.h" |
33 | 34 |
34 | 35 |
35 using namespace v8::internal; | 36 using namespace v8::internal; |
36 | 37 |
37 | 38 |
38 static AllocationResult AllocateAfterFailures() { | 39 AllocationResult v8::internal::HeapTester::AllocateAfterFailures() { |
39 static int attempts = 0; | 40 static int attempts = 0; |
40 | 41 |
41 // The first 4 times we simulate a full heap, by returning retry. | 42 // The first 4 times we simulate a full heap, by returning retry. |
42 if (++attempts < 4) return AllocationResult::Retry(); | 43 if (++attempts < 4) return AllocationResult::Retry(); |
43 | 44 |
44 // Expose some private stuff on Heap. | 45 // Expose some private stuff on Heap. |
45 TestHeap* heap = CcTest::test_heap(); | 46 Heap* heap = CcTest::heap(); |
46 | 47 |
47 // Now that we have returned 'retry' 4 times, we are in a last-chance | 48 // Now that we have returned 'retry' 4 times, we are in a last-chance |
48 // scenario, with always_allocate. See CALL_AND_RETRY. Test that all | 49 // scenario, with always_allocate. See CALL_AND_RETRY. Test that all |
49 // allocations succeed. | 50 // allocations succeed. |
50 | 51 |
51 // New space. | 52 // New space. |
52 SimulateFullSpace(heap->new_space()); | 53 SimulateFullSpace(heap->new_space()); |
53 heap->AllocateByteArray(100).ToObjectChecked(); | 54 heap->AllocateByteArray(100).ToObjectChecked(); |
54 heap->AllocateFixedArray(100, NOT_TENURED).ToObjectChecked(); | 55 heap->AllocateFixedArray(100, NOT_TENURED).ToObjectChecked(); |
55 | 56 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 SimulateFullSpace(heap->code_space()); | 91 SimulateFullSpace(heap->code_space()); |
91 heap->AllocateFixedArray(100, TENURED).ToObjectChecked(); | 92 heap->AllocateFixedArray(100, TENURED).ToObjectChecked(); |
92 heap->CopyCode(CcTest::i_isolate()->builtins()->builtin( | 93 heap->CopyCode(CcTest::i_isolate()->builtins()->builtin( |
93 Builtins::kIllegal)).ToObjectChecked(); | 94 Builtins::kIllegal)).ToObjectChecked(); |
94 | 95 |
95 // Return success. | 96 // Return success. |
96 return heap->true_value(); | 97 return heap->true_value(); |
97 } | 98 } |
98 | 99 |
99 | 100 |
100 static Handle<Object> Test() { | 101 Handle<Object> v8::internal::HeapTester::TestAllocateAfterFailures() { |
101 CALL_HEAP_FUNCTION(CcTest::i_isolate(), AllocateAfterFailures(), Object); | 102 CALL_HEAP_FUNCTION(CcTest::i_isolate(), AllocateAfterFailures(), Object); |
102 } | 103 } |
103 | 104 |
104 | 105 |
105 TEST(StressHandles) { | 106 HEAP_TEST(StressHandles) { |
106 v8::HandleScope scope(CcTest::isolate()); | 107 v8::HandleScope scope(CcTest::isolate()); |
107 v8::Handle<v8::Context> env = v8::Context::New(CcTest::isolate()); | 108 v8::Handle<v8::Context> env = v8::Context::New(CcTest::isolate()); |
108 env->Enter(); | 109 env->Enter(); |
109 Handle<Object> o = Test(); | 110 Handle<Object> o = TestAllocateAfterFailures(); |
110 CHECK(o->IsTrue()); | 111 CHECK(o->IsTrue()); |
111 env->Exit(); | 112 env->Exit(); |
112 } | 113 } |
113 | 114 |
114 | 115 |
115 void TestGetter( | 116 void TestGetter( |
116 v8::Local<v8::Name> name, | 117 v8::Local<v8::Name> name, |
117 const v8::PropertyCallbackInfo<v8::Value>& info) { | 118 const v8::PropertyCallbackInfo<v8::Value>& info) { |
118 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); | 119 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); |
119 HandleScope scope(isolate); | 120 HandleScope scope(isolate); |
120 info.GetReturnValue().Set(v8::Utils::ToLocal(Test())); | 121 info.GetReturnValue().Set(v8::Utils::ToLocal( |
| 122 v8::internal::HeapTester::TestAllocateAfterFailures())); |
121 } | 123 } |
122 | 124 |
123 | 125 |
124 void TestSetter( | 126 void TestSetter( |
125 v8::Local<v8::Name> name, | 127 v8::Local<v8::Name> name, |
126 v8::Local<v8::Value> value, | 128 v8::Local<v8::Value> value, |
127 const v8::PropertyCallbackInfo<void>& info) { | 129 const v8::PropertyCallbackInfo<void>& info) { |
128 UNREACHABLE(); | 130 UNREACHABLE(); |
129 } | 131 } |
130 | 132 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 if (index < blocks.length() - 1) { | 239 if (index < blocks.length() - 1) { |
238 blocks[index] = blocks.RemoveLast(); | 240 blocks[index] = blocks.RemoveLast(); |
239 } else { | 241 } else { |
240 blocks.RemoveLast(); | 242 blocks.RemoveLast(); |
241 } | 243 } |
242 } | 244 } |
243 } | 245 } |
244 | 246 |
245 code_range.TearDown(); | 247 code_range.TearDown(); |
246 } | 248 } |
OLD | NEW |