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

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

Issue 1372063002: [heap] Move CALL_HEAP_FUNCTION macro into factory.cc file. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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
« no previous file with comments | « src/heap/heap-inl.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 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 19 matching lines...) Expand all
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 #include "test/cctest/heap-tester.h"
34 34
35 35
36 using namespace v8::internal; 36 using namespace v8::internal;
37 37
38 38
39 AllocationResult v8::internal::HeapTester::AllocateAfterFailures() { 39 AllocationResult v8::internal::HeapTester::AllocateAfterFailures() {
40 static int attempts = 0;
41
42 // The first 4 times we simulate a full heap, by returning retry.
43 if (++attempts < 4) return AllocationResult::Retry();
44
45 // Expose some private stuff on Heap.
46 Heap* heap = CcTest::heap(); 40 Heap* heap = CcTest::heap();
47 41
48 // Now that we have returned 'retry' 4 times, we are in a last-chance
49 // scenario, with always_allocate. See CALL_AND_RETRY. Test that all
50 // allocations succeed.
51
52 // New space. 42 // New space.
53 SimulateFullSpace(heap->new_space()); 43 SimulateFullSpace(heap->new_space());
54 heap->AllocateByteArray(100).ToObjectChecked(); 44 heap->AllocateByteArray(100).ToObjectChecked();
55 heap->AllocateFixedArray(100, NOT_TENURED).ToObjectChecked(); 45 heap->AllocateFixedArray(100, NOT_TENURED).ToObjectChecked();
56 46
57 // Make sure we can allocate through optimized allocation functions 47 // Make sure we can allocate through optimized allocation functions
58 // for specific kinds. 48 // for specific kinds.
59 heap->AllocateFixedArray(100).ToObjectChecked(); 49 heap->AllocateFixedArray(100).ToObjectChecked();
60 heap->AllocateHeapNumber(0.42).ToObjectChecked(); 50 heap->AllocateHeapNumber(0.42).ToObjectChecked();
61 Object* object = heap->AllocateJSObject( 51 Object* object = heap->AllocateJSObject(
(...skipping 30 matching lines...) Expand all
92 heap->AllocateFixedArray(100, TENURED).ToObjectChecked(); 82 heap->AllocateFixedArray(100, TENURED).ToObjectChecked();
93 heap->CopyCode(CcTest::i_isolate()->builtins()->builtin( 83 heap->CopyCode(CcTest::i_isolate()->builtins()->builtin(
94 Builtins::kIllegal)).ToObjectChecked(); 84 Builtins::kIllegal)).ToObjectChecked();
95 85
96 // Return success. 86 // Return success.
97 return heap->true_value(); 87 return heap->true_value();
98 } 88 }
99 89
100 90
101 Handle<Object> v8::internal::HeapTester::TestAllocateAfterFailures() { 91 Handle<Object> v8::internal::HeapTester::TestAllocateAfterFailures() {
102 CALL_HEAP_FUNCTION(CcTest::i_isolate(), AllocateAfterFailures(), Object); 92 // Similar to what the CALL_AND_RETRY macro does in the last-resort case, we
93 // are wrapping the allocator function in an AlwaysAllocateScope. Test that
94 // all allocations succeed immediately without any retry.
95 CcTest::heap()->CollectAllAvailableGarbage("panic");
96 AlwaysAllocateScope scope(CcTest::i_isolate());
97 return handle(AllocateAfterFailures().ToObjectChecked(), CcTest::i_isolate());
103 } 98 }
104 99
105 100
106 HEAP_TEST(StressHandles) { 101 HEAP_TEST(StressHandles) {
107 v8::HandleScope scope(CcTest::isolate()); 102 v8::HandleScope scope(CcTest::isolate());
108 v8::Handle<v8::Context> env = v8::Context::New(CcTest::isolate()); 103 v8::Handle<v8::Context> env = v8::Context::New(CcTest::isolate());
109 env->Enter(); 104 env->Enter();
110 Handle<Object> o = TestAllocateAfterFailures(); 105 Handle<Object> o = TestAllocateAfterFailures();
111 CHECK(o->IsTrue()); 106 CHECK(o->IsTrue());
112 env->Exit(); 107 env->Exit();
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 code_range.FreeRawMemory(blocks[index].base, blocks[index].size); 235 code_range.FreeRawMemory(blocks[index].base, blocks[index].size);
241 current_allocated -= blocks[index].size; 236 current_allocated -= blocks[index].size;
242 if (index < blocks.length() - 1) { 237 if (index < blocks.length() - 1) {
243 blocks[index] = blocks.RemoveLast(); 238 blocks[index] = blocks.RemoveLast();
244 } else { 239 } else {
245 blocks.RemoveLast(); 240 blocks.RemoveLast();
246 } 241 }
247 } 242 }
248 } 243 }
249 } 244 }
OLDNEW
« no previous file with comments | « src/heap/heap-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698