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

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

Issue 1406393005: [test] Move away from deprecated API for heap-related tests. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Move delta between last PS1 and PS2 to new API Created 5 years, 1 month 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 | « no previous file | test/cctest/test-heap.cc » ('j') | 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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
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 // TODO(jochen): Remove this after the setting is turned on globally.
29 #define V8_IMMINENT_DEPRECATION_WARNINGS
30
28 #include "src/v8.h" 31 #include "src/v8.h"
29 #include "test/cctest/cctest.h" 32 #include "test/cctest/cctest.h"
30 33
31 #include "src/accessors.h" 34 #include "src/accessors.h"
32 #include "src/api.h" 35 #include "src/api.h"
33 #include "test/cctest/heap-tester.h" 36 #include "test/cctest/heap-tester.h"
34 37
35 38
36 using namespace v8::internal; 39 using namespace v8::internal;
37 40
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // are wrapping the allocator function in an AlwaysAllocateScope. Test that 95 // are wrapping the allocator function in an AlwaysAllocateScope. Test that
93 // all allocations succeed immediately without any retry. 96 // all allocations succeed immediately without any retry.
94 CcTest::heap()->CollectAllAvailableGarbage("panic"); 97 CcTest::heap()->CollectAllAvailableGarbage("panic");
95 AlwaysAllocateScope scope(CcTest::i_isolate()); 98 AlwaysAllocateScope scope(CcTest::i_isolate());
96 return handle(AllocateAfterFailures().ToObjectChecked(), CcTest::i_isolate()); 99 return handle(AllocateAfterFailures().ToObjectChecked(), CcTest::i_isolate());
97 } 100 }
98 101
99 102
100 HEAP_TEST(StressHandles) { 103 HEAP_TEST(StressHandles) {
101 v8::HandleScope scope(CcTest::isolate()); 104 v8::HandleScope scope(CcTest::isolate());
102 v8::Handle<v8::Context> env = v8::Context::New(CcTest::isolate()); 105 v8::Local<v8::Context> env = v8::Context::New(CcTest::isolate());
103 env->Enter(); 106 env->Enter();
104 Handle<Object> o = TestAllocateAfterFailures(); 107 Handle<Object> o = TestAllocateAfterFailures();
105 CHECK(o->IsTrue()); 108 CHECK(o->IsTrue());
106 env->Exit(); 109 env->Exit();
107 } 110 }
108 111
109 112
110 void TestGetter( 113 void TestGetter(
111 v8::Local<v8::Name> name, 114 v8::Local<v8::Name> name,
112 const v8::PropertyCallbackInfo<v8::Value>& info) { 115 const v8::PropertyCallbackInfo<v8::Value>& info) {
(...skipping 17 matching lines...) Expand all
130 Handle<String> name = isolate->factory()->NewStringFromStaticChars("get"); 133 Handle<String> name = isolate->factory()->NewStringFromStaticChars("get");
131 return Accessors::MakeAccessor(isolate, name, &TestGetter, &TestSetter, 134 return Accessors::MakeAccessor(isolate, name, &TestGetter, &TestSetter,
132 attributes); 135 attributes);
133 } 136 }
134 137
135 138
136 TEST(StressJS) { 139 TEST(StressJS) {
137 Isolate* isolate = CcTest::i_isolate(); 140 Isolate* isolate = CcTest::i_isolate();
138 Factory* factory = isolate->factory(); 141 Factory* factory = isolate->factory();
139 v8::HandleScope scope(CcTest::isolate()); 142 v8::HandleScope scope(CcTest::isolate());
140 v8::Handle<v8::Context> env = v8::Context::New(CcTest::isolate()); 143 v8::Local<v8::Context> env = v8::Context::New(CcTest::isolate());
141 env->Enter(); 144 env->Enter();
142 Handle<JSFunction> function = factory->NewFunction( 145 Handle<JSFunction> function = factory->NewFunction(
143 factory->function_string()); 146 factory->function_string());
144 // Force the creation of an initial map and set the code to 147 // Force the creation of an initial map and set the code to
145 // something empty. 148 // something empty.
146 factory->NewJSObject(function); 149 factory->NewJSObject(function);
147 function->ReplaceCode(CcTest::i_isolate()->builtins()->builtin( 150 function->ReplaceCode(CcTest::i_isolate()->builtins()->builtin(
148 Builtins::kEmptyFunction)); 151 Builtins::kEmptyFunction));
149 // Patch the map to have an accessor for "get". 152 // Patch the map to have an accessor for "get".
150 Handle<Map> map(function->initial_map()); 153 Handle<Map> map(function->initial_map());
151 Handle<DescriptorArray> instance_descriptors(map->instance_descriptors()); 154 Handle<DescriptorArray> instance_descriptors(map->instance_descriptors());
152 DCHECK(instance_descriptors->IsEmpty()); 155 DCHECK(instance_descriptors->IsEmpty());
153 156
154 PropertyAttributes attrs = static_cast<PropertyAttributes>(0); 157 PropertyAttributes attrs = static_cast<PropertyAttributes>(0);
155 Handle<AccessorInfo> foreign = TestAccessorInfo(isolate, attrs); 158 Handle<AccessorInfo> foreign = TestAccessorInfo(isolate, attrs);
156 Map::EnsureDescriptorSlack(map, 1); 159 Map::EnsureDescriptorSlack(map, 1);
157 160
158 AccessorConstantDescriptor d(Handle<Name>(Name::cast(foreign->name())), 161 AccessorConstantDescriptor d(Handle<Name>(Name::cast(foreign->name())),
159 foreign, attrs); 162 foreign, attrs);
160 map->AppendDescriptor(&d); 163 map->AppendDescriptor(&d);
161 164
162 // Add the Foo constructor the global object. 165 // Add the Foo constructor the global object.
163 env->Global()->Set(v8::String::NewFromUtf8(CcTest::isolate(), "Foo"), 166 CHECK(env->Global()
164 v8::Utils::CallableToLocal(function)); 167 ->Set(env, v8::String::NewFromUtf8(CcTest::isolate(), "Foo",
168 v8::NewStringType::kNormal)
169 .ToLocalChecked(),
170 v8::Utils::CallableToLocal(function))
171 .FromJust());
165 // Call the accessor through JavaScript. 172 // Call the accessor through JavaScript.
166 v8::Handle<v8::Value> result = v8::Script::Compile( 173 v8::Local<v8::Value> result =
167 v8::String::NewFromUtf8(CcTest::isolate(), "(new Foo).get"))->Run(); 174 v8::Script::Compile(
168 CHECK_EQ(true, result->BooleanValue()); 175 env, v8::String::NewFromUtf8(CcTest::isolate(), "(new Foo).get",
176 v8::NewStringType::kNormal)
177 .ToLocalChecked())
178 .ToLocalChecked()
179 ->Run(env)
180 .ToLocalChecked();
181 CHECK_EQ(true, result->BooleanValue(env).FromJust());
169 env->Exit(); 182 env->Exit();
170 } 183 }
171 184
172 185
173 // CodeRange test. 186 // CodeRange test.
174 // Tests memory management in a CodeRange by allocating and freeing blocks, 187 // Tests memory management in a CodeRange by allocating and freeing blocks,
175 // using a pseudorandom generator to choose block sizes geometrically 188 // using a pseudorandom generator to choose block sizes geometrically
176 // distributed between 2 * Page::kPageSize and 2^5 + 1 * Page::kPageSize. 189 // distributed between 2 * Page::kPageSize and 2^5 + 1 * Page::kPageSize.
177 // Ensure that the freed chunks are collected and reused by allocating (in 190 // Ensure that the freed chunks are collected and reused by allocating (in
178 // total) more than the size of the CodeRange. 191 // total) more than the size of the CodeRange.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 code_range.FreeRawMemory(blocks[index].base, blocks[index].size); 247 code_range.FreeRawMemory(blocks[index].base, blocks[index].size);
235 current_allocated -= blocks[index].size; 248 current_allocated -= blocks[index].size;
236 if (index < blocks.length() - 1) { 249 if (index < blocks.length() - 1) {
237 blocks[index] = blocks.RemoveLast(); 250 blocks[index] = blocks.RemoveLast();
238 } else { 251 } else {
239 blocks.RemoveLast(); 252 blocks.RemoveLast();
240 } 253 }
241 } 254 }
242 } 255 }
243 } 256 }
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698