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 16 matching lines...) Expand all Loading... |
27 | 27 |
28 #include "v8.h" | 28 #include "v8.h" |
29 #include "accessors.h" | 29 #include "accessors.h" |
30 | 30 |
31 #include "cctest.h" | 31 #include "cctest.h" |
32 | 32 |
33 | 33 |
34 using namespace v8::internal; | 34 using namespace v8::internal; |
35 | 35 |
36 | 36 |
| 37 static inline void SimulateFullSpace(PagedSpace* space) { |
| 38 space->SetTop(space->limit(), space->limit()); |
| 39 space->ResetFreeList(); |
| 40 space->ClearStats(); |
| 41 } |
| 42 |
| 43 |
37 static MaybeObject* AllocateAfterFailures() { | 44 static MaybeObject* AllocateAfterFailures() { |
38 static int attempts = 0; | 45 static int attempts = 0; |
39 if (++attempts < 3) return Failure::RetryAfterGC(); | 46 if (++attempts < 3) return Failure::RetryAfterGC(); |
40 Heap* heap = Isolate::Current()->heap(); | 47 Heap* heap = Isolate::Current()->heap(); |
41 | 48 |
42 // New space. | 49 // New space. |
43 NewSpace* new_space = heap->new_space(); | 50 NewSpace* new_space = heap->new_space(); |
44 static const int kNewSpaceFillerSize = ByteArray::SizeFor(0); | 51 static const int kNewSpaceFillerSize = ByteArray::SizeFor(0); |
45 while (new_space->Available() > kNewSpaceFillerSize) { | 52 while (new_space->Available() > kNewSpaceFillerSize) { |
46 int available_before = static_cast<int>(new_space->Available()); | 53 int available_before = static_cast<int>(new_space->Available()); |
(...skipping 11 matching lines...) Expand all Loading... |
58 // Make sure we can allocate through optimized allocation functions | 65 // Make sure we can allocate through optimized allocation functions |
59 // for specific kinds. | 66 // for specific kinds. |
60 CHECK(!heap->AllocateFixedArray(100)->IsFailure()); | 67 CHECK(!heap->AllocateFixedArray(100)->IsFailure()); |
61 CHECK(!heap->AllocateHeapNumber(0.42)->IsFailure()); | 68 CHECK(!heap->AllocateHeapNumber(0.42)->IsFailure()); |
62 CHECK(!heap->AllocateArgumentsObject(Smi::FromInt(87), 10)->IsFailure()); | 69 CHECK(!heap->AllocateArgumentsObject(Smi::FromInt(87), 10)->IsFailure()); |
63 Object* object = heap->AllocateJSObject( | 70 Object* object = heap->AllocateJSObject( |
64 *Isolate::Current()->object_function())->ToObjectChecked(); | 71 *Isolate::Current()->object_function())->ToObjectChecked(); |
65 CHECK(!heap->CopyJSObject(JSObject::cast(object))->IsFailure()); | 72 CHECK(!heap->CopyJSObject(JSObject::cast(object))->IsFailure()); |
66 | 73 |
67 // Old data space. | 74 // Old data space. |
68 OldSpace* old_data_space = heap->old_data_space(); | 75 SimulateFullSpace(heap->old_data_space()); |
69 static const int kOldDataSpaceFillerSize = ByteArray::SizeFor(0); | |
70 while (old_data_space->Available() > kOldDataSpaceFillerSize) { | |
71 CHECK(!heap->AllocateByteArray(0, TENURED)->IsFailure()); | |
72 } | |
73 CHECK(!heap->AllocateRawAsciiString(100, TENURED)->IsFailure()); | 76 CHECK(!heap->AllocateRawAsciiString(100, TENURED)->IsFailure()); |
74 | 77 |
75 // Old pointer space. | 78 // Old pointer space. |
76 OldSpace* old_pointer_space = heap->old_pointer_space(); | 79 SimulateFullSpace(heap->old_pointer_space()); |
77 static const int kOldPointerSpaceFillerLength = 10000; | 80 CHECK(!heap->AllocateFixedArray(10000, TENURED)->IsFailure()); |
78 static const int kOldPointerSpaceFillerSize = FixedArray::SizeFor( | |
79 kOldPointerSpaceFillerLength); | |
80 while (old_pointer_space->Available() > kOldPointerSpaceFillerSize) { | |
81 CHECK(!heap->AllocateFixedArray(kOldPointerSpaceFillerLength, TENURED)-> | |
82 IsFailure()); | |
83 } | |
84 CHECK(!heap->AllocateFixedArray(kOldPointerSpaceFillerLength, TENURED)-> | |
85 IsFailure()); | |
86 | 81 |
87 // Large object space. | 82 // Large object space. |
88 static const int kLargeObjectSpaceFillerLength = 300000; | 83 static const int kLargeObjectSpaceFillerLength = 300000; |
89 static const int kLargeObjectSpaceFillerSize = FixedArray::SizeFor( | 84 static const int kLargeObjectSpaceFillerSize = FixedArray::SizeFor( |
90 kLargeObjectSpaceFillerLength); | 85 kLargeObjectSpaceFillerLength); |
91 ASSERT(kLargeObjectSpaceFillerSize > heap->old_pointer_space()->AreaSize()); | 86 ASSERT(kLargeObjectSpaceFillerSize > heap->old_pointer_space()->AreaSize()); |
92 while (heap->OldGenerationSpaceAvailable() > kLargeObjectSpaceFillerSize) { | 87 while (heap->OldGenerationSpaceAvailable() > kLargeObjectSpaceFillerSize) { |
93 CHECK(!heap->AllocateFixedArray(kLargeObjectSpaceFillerLength, TENURED)-> | 88 CHECK(!heap->AllocateFixedArray(kLargeObjectSpaceFillerLength, TENURED)-> |
94 IsFailure()); | 89 IsFailure()); |
95 } | 90 } |
96 CHECK(!heap->AllocateFixedArray(kLargeObjectSpaceFillerLength, TENURED)-> | 91 CHECK(!heap->AllocateFixedArray(kLargeObjectSpaceFillerLength, TENURED)-> |
97 IsFailure()); | 92 IsFailure()); |
98 | 93 |
99 // Map space. | 94 // Map space. |
100 MapSpace* map_space = heap->map_space(); | 95 SimulateFullSpace(heap->map_space()); |
101 static const int kMapSpaceFillerSize = Map::kSize; | |
102 InstanceType instance_type = JS_OBJECT_TYPE; | |
103 int instance_size = JSObject::kHeaderSize; | 96 int instance_size = JSObject::kHeaderSize; |
104 while (map_space->Available() > kMapSpaceFillerSize) { | 97 CHECK(!heap->AllocateMap(JS_OBJECT_TYPE, instance_size)->IsFailure()); |
105 CHECK(!heap->AllocateMap(instance_type, instance_size)->IsFailure()); | |
106 } | |
107 CHECK(!heap->AllocateMap(instance_type, instance_size)->IsFailure()); | |
108 | 98 |
109 // Test that we can allocate in old pointer space and code space. | 99 // Test that we can allocate in old pointer space and code space. |
110 CHECK(!heap->AllocateFixedArray(100, TENURED)->IsFailure()); | 100 CHECK(!heap->AllocateFixedArray(100, TENURED)->IsFailure()); |
111 CHECK(!heap->CopyCode(Isolate::Current()->builtins()->builtin( | 101 CHECK(!heap->CopyCode(Isolate::Current()->builtins()->builtin( |
112 Builtins::kIllegal))->IsFailure()); | 102 Builtins::kIllegal))->IsFailure()); |
113 | 103 |
114 // Return success. | 104 // Return success. |
115 return Smi::FromInt(42); | 105 return Smi::FromInt(42); |
116 } | 106 } |
117 | 107 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 blocks[index] = blocks.RemoveLast(); | 226 blocks[index] = blocks.RemoveLast(); |
237 } else { | 227 } else { |
238 blocks.RemoveLast(); | 228 blocks.RemoveLast(); |
239 } | 229 } |
240 } | 230 } |
241 } | 231 } |
242 | 232 |
243 code_range->TearDown(); | 233 code_range->TearDown(); |
244 delete code_range; | 234 delete code_range; |
245 } | 235 } |
OLD | NEW |