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 19 matching lines...) Expand all Loading... |
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 MaybeObject* AllocateAfterFailures() { | 37 static MaybeObject* AllocateAfterFailures() { |
38 static int attempts = 0; | 38 static int attempts = 0; |
39 if (++attempts < 3) return Failure::RetryAfterGC(); | 39 if (++attempts < 3) return Failure::RetryAfterGC(); |
40 Heap* heap = Isolate::Current()->heap(); | 40 Heap* heap = CcTest::i_isolate()->heap(); |
41 | 41 |
42 // New space. | 42 // New space. |
43 SimulateFullSpace(heap->new_space()); | 43 SimulateFullSpace(heap->new_space()); |
44 CHECK(!heap->AllocateByteArray(100)->IsFailure()); | 44 CHECK(!heap->AllocateByteArray(100)->IsFailure()); |
45 CHECK(!heap->AllocateFixedArray(100, NOT_TENURED)->IsFailure()); | 45 CHECK(!heap->AllocateFixedArray(100, NOT_TENURED)->IsFailure()); |
46 | 46 |
47 // Make sure we can allocate through optimized allocation functions | 47 // Make sure we can allocate through optimized allocation functions |
48 // for specific kinds. | 48 // for specific kinds. |
49 CHECK(!heap->AllocateFixedArray(100)->IsFailure()); | 49 CHECK(!heap->AllocateFixedArray(100)->IsFailure()); |
50 CHECK(!heap->AllocateHeapNumber(0.42)->IsFailure()); | 50 CHECK(!heap->AllocateHeapNumber(0.42)->IsFailure()); |
51 CHECK(!heap->AllocateArgumentsObject(Smi::FromInt(87), 10)->IsFailure()); | 51 CHECK(!heap->AllocateArgumentsObject(Smi::FromInt(87), 10)->IsFailure()); |
52 Object* object = heap->AllocateJSObject( | 52 Object* object = heap->AllocateJSObject( |
53 *Isolate::Current()->object_function())->ToObjectChecked(); | 53 *CcTest::i_isolate()->object_function())->ToObjectChecked(); |
54 CHECK(!heap->CopyJSObject(JSObject::cast(object))->IsFailure()); | 54 CHECK(!heap->CopyJSObject(JSObject::cast(object))->IsFailure()); |
55 | 55 |
56 // Old data space. | 56 // Old data space. |
57 SimulateFullSpace(heap->old_data_space()); | 57 SimulateFullSpace(heap->old_data_space()); |
58 CHECK(!heap->AllocateRawOneByteString(100, TENURED)->IsFailure()); | 58 CHECK(!heap->AllocateRawOneByteString(100, TENURED)->IsFailure()); |
59 | 59 |
60 // Old pointer space. | 60 // Old pointer space. |
61 SimulateFullSpace(heap->old_pointer_space()); | 61 SimulateFullSpace(heap->old_pointer_space()); |
62 CHECK(!heap->AllocateFixedArray(10000, TENURED)->IsFailure()); | 62 CHECK(!heap->AllocateFixedArray(10000, TENURED)->IsFailure()); |
63 | 63 |
(...skipping 10 matching lines...) Expand all Loading... |
74 IsFailure()); | 74 IsFailure()); |
75 | 75 |
76 // Map space. | 76 // Map space. |
77 SimulateFullSpace(heap->map_space()); | 77 SimulateFullSpace(heap->map_space()); |
78 int instance_size = JSObject::kHeaderSize; | 78 int instance_size = JSObject::kHeaderSize; |
79 CHECK(!heap->AllocateMap(JS_OBJECT_TYPE, instance_size)->IsFailure()); | 79 CHECK(!heap->AllocateMap(JS_OBJECT_TYPE, instance_size)->IsFailure()); |
80 | 80 |
81 // Test that we can allocate in old pointer space and code space. | 81 // Test that we can allocate in old pointer space and code space. |
82 SimulateFullSpace(heap->code_space()); | 82 SimulateFullSpace(heap->code_space()); |
83 CHECK(!heap->AllocateFixedArray(100, TENURED)->IsFailure()); | 83 CHECK(!heap->AllocateFixedArray(100, TENURED)->IsFailure()); |
84 CHECK(!heap->CopyCode(Isolate::Current()->builtins()->builtin( | 84 CHECK(!heap->CopyCode(CcTest::i_isolate()->builtins()->builtin( |
85 Builtins::kIllegal))->IsFailure()); | 85 Builtins::kIllegal))->IsFailure()); |
86 | 86 |
87 // Return success. | 87 // Return success. |
88 return Smi::FromInt(42); | 88 return Smi::FromInt(42); |
89 } | 89 } |
90 | 90 |
91 | 91 |
92 static Handle<Object> Test() { | 92 static Handle<Object> Test() { |
93 CALL_HEAP_FUNCTION(Isolate::Current(), AllocateAfterFailures(), Object); | 93 CALL_HEAP_FUNCTION(CcTest::i_isolate(), AllocateAfterFailures(), Object); |
94 } | 94 } |
95 | 95 |
96 | 96 |
97 TEST(StressHandles) { | 97 TEST(StressHandles) { |
98 v8::HandleScope scope(CcTest::isolate()); | 98 v8::HandleScope scope(CcTest::isolate()); |
99 v8::Handle<v8::Context> env = v8::Context::New(CcTest::isolate()); | 99 v8::Handle<v8::Context> env = v8::Context::New(CcTest::isolate()); |
100 env->Enter(); | 100 env->Enter(); |
101 Handle<Object> o = Test(); | 101 Handle<Object> o = Test(); |
102 CHECK(o->IsSmi() && Smi::cast(*o)->value() == 42); | 102 CHECK(o->IsSmi() && Smi::cast(*o)->value() == 42); |
103 env->Exit(); | 103 env->Exit(); |
104 } | 104 } |
105 | 105 |
106 | 106 |
107 static MaybeObject* TestAccessorGet(Isolate* isolate, Object* object, void*) { | 107 static MaybeObject* TestAccessorGet(Isolate* isolate, Object* object, void*) { |
108 return AllocateAfterFailures(); | 108 return AllocateAfterFailures(); |
109 } | 109 } |
110 | 110 |
111 | 111 |
112 const AccessorDescriptor kDescriptor = { | 112 const AccessorDescriptor kDescriptor = { |
113 TestAccessorGet, | 113 TestAccessorGet, |
114 0, | 114 0, |
115 0 | 115 0 |
116 }; | 116 }; |
117 | 117 |
118 | 118 |
119 TEST(StressJS) { | 119 TEST(StressJS) { |
120 Isolate* isolate = Isolate::Current(); | 120 Isolate* isolate = CcTest::i_isolate(); |
121 Factory* factory = isolate->factory(); | 121 Factory* factory = isolate->factory(); |
122 v8::HandleScope scope(CcTest::isolate()); | 122 v8::HandleScope scope(CcTest::isolate()); |
123 v8::Handle<v8::Context> env = v8::Context::New(CcTest::isolate()); | 123 v8::Handle<v8::Context> env = v8::Context::New(CcTest::isolate()); |
124 env->Enter(); | 124 env->Enter(); |
125 Handle<JSFunction> function = | 125 Handle<JSFunction> function = |
126 factory->NewFunction(factory->function_string(), factory->null_value()); | 126 factory->NewFunction(factory->function_string(), factory->null_value()); |
127 // Force the creation of an initial map and set the code to | 127 // Force the creation of an initial map and set the code to |
128 // something empty. | 128 // something empty. |
129 factory->NewJSObject(function); | 129 factory->NewJSObject(function); |
130 function->ReplaceCode(Isolate::Current()->builtins()->builtin( | 130 function->ReplaceCode(CcTest::i_isolate()->builtins()->builtin( |
131 Builtins::kEmptyFunction)); | 131 Builtins::kEmptyFunction)); |
132 // Patch the map to have an accessor for "get". | 132 // Patch the map to have an accessor for "get". |
133 Handle<Map> map(function->initial_map()); | 133 Handle<Map> map(function->initial_map()); |
134 Handle<DescriptorArray> instance_descriptors(map->instance_descriptors()); | 134 Handle<DescriptorArray> instance_descriptors(map->instance_descriptors()); |
135 Handle<Foreign> foreign = factory->NewForeign(&kDescriptor); | 135 Handle<Foreign> foreign = factory->NewForeign(&kDescriptor); |
136 Handle<String> name = | 136 Handle<String> name = |
137 factory->NewStringFromAscii(Vector<const char>("get", 3)); | 137 factory->NewStringFromAscii(Vector<const char>("get", 3)); |
138 ASSERT(instance_descriptors->IsEmpty()); | 138 ASSERT(instance_descriptors->IsEmpty()); |
139 | 139 |
140 Handle<DescriptorArray> new_descriptors = factory->NewDescriptorArray(0, 1); | 140 Handle<DescriptorArray> new_descriptors = factory->NewDescriptorArray(0, 1); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 if (index < blocks.length() - 1) { | 219 if (index < blocks.length() - 1) { |
220 blocks[index] = blocks.RemoveLast(); | 220 blocks[index] = blocks.RemoveLast(); |
221 } else { | 221 } else { |
222 blocks.RemoveLast(); | 222 blocks.RemoveLast(); |
223 } | 223 } |
224 } | 224 } |
225 } | 225 } |
226 | 226 |
227 code_range.TearDown(); | 227 code_range.TearDown(); |
228 } | 228 } |
OLD | NEW |