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 4245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4256 // These tests run for a long time and prevent us from running tests | 4256 // These tests run for a long time and prevent us from running tests |
4257 // that come after them so they cannot run in parallel. | 4257 // that come after them so they cannot run in parallel. |
4258 TEST(OutOfMemory) { | 4258 TEST(OutOfMemory) { |
4259 // It's not possible to read a snapshot into a heap with different dimensions. | 4259 // It's not possible to read a snapshot into a heap with different dimensions. |
4260 if (i::Snapshot::IsEnabled()) return; | 4260 if (i::Snapshot::IsEnabled()) return; |
4261 // Set heap limits. | 4261 // Set heap limits. |
4262 static const int K = 1024; | 4262 static const int K = 1024; |
4263 v8::ResourceConstraints constraints; | 4263 v8::ResourceConstraints constraints; |
4264 constraints.set_max_young_space_size(256 * K); | 4264 constraints.set_max_young_space_size(256 * K); |
4265 constraints.set_max_old_space_size(5 * K * K); | 4265 constraints.set_max_old_space_size(5 * K * K); |
4266 v8::SetResourceConstraints(&constraints); | 4266 v8::SetResourceConstraints(CcTest::isolate(), &constraints); |
4267 | 4267 |
4268 // Execute a script that causes out of memory. | 4268 // Execute a script that causes out of memory. |
4269 LocalContext context; | 4269 LocalContext context; |
4270 v8::HandleScope scope(context->GetIsolate()); | 4270 v8::HandleScope scope(context->GetIsolate()); |
4271 v8::V8::IgnoreOutOfMemoryException(); | 4271 v8::V8::IgnoreOutOfMemoryException(); |
4272 Local<Script> script = | 4272 Local<Script> script = |
4273 Script::Compile(String::New(js_code_causing_out_of_memory)); | 4273 Script::Compile(String::New(js_code_causing_out_of_memory)); |
4274 Local<Value> result = script->Run(); | 4274 Local<Value> result = script->Run(); |
4275 | 4275 |
4276 // Check for out of memory state. | 4276 // Check for out of memory state. |
(...skipping 20 matching lines...) Expand all Loading... |
4297 | 4297 |
4298 | 4298 |
4299 TEST(OutOfMemoryNested) { | 4299 TEST(OutOfMemoryNested) { |
4300 // It's not possible to read a snapshot into a heap with different dimensions. | 4300 // It's not possible to read a snapshot into a heap with different dimensions. |
4301 if (i::Snapshot::IsEnabled()) return; | 4301 if (i::Snapshot::IsEnabled()) return; |
4302 // Set heap limits. | 4302 // Set heap limits. |
4303 static const int K = 1024; | 4303 static const int K = 1024; |
4304 v8::ResourceConstraints constraints; | 4304 v8::ResourceConstraints constraints; |
4305 constraints.set_max_young_space_size(256 * K); | 4305 constraints.set_max_young_space_size(256 * K); |
4306 constraints.set_max_old_space_size(5 * K * K); | 4306 constraints.set_max_old_space_size(5 * K * K); |
4307 v8::SetResourceConstraints(&constraints); | 4307 v8::SetResourceConstraints(CcTest::isolate(), &constraints); |
4308 | 4308 |
4309 v8::HandleScope scope(CcTest::isolate()); | 4309 v8::HandleScope scope(CcTest::isolate()); |
4310 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4310 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
4311 templ->Set(v8_str("ProvokeOutOfMemory"), | 4311 templ->Set(v8_str("ProvokeOutOfMemory"), |
4312 v8::FunctionTemplate::New(ProvokeOutOfMemory)); | 4312 v8::FunctionTemplate::New(ProvokeOutOfMemory)); |
4313 LocalContext context(0, templ); | 4313 LocalContext context(0, templ); |
4314 v8::V8::IgnoreOutOfMemoryException(); | 4314 v8::V8::IgnoreOutOfMemoryException(); |
4315 Local<Value> result = CompileRun( | 4315 Local<Value> result = CompileRun( |
4316 "var thrown = false;" | 4316 "var thrown = false;" |
4317 "try {" | 4317 "try {" |
4318 " ProvokeOutOfMemory();" | 4318 " ProvokeOutOfMemory();" |
4319 "} catch (e) {" | 4319 "} catch (e) {" |
4320 " thrown = true;" | 4320 " thrown = true;" |
4321 "}"); | 4321 "}"); |
4322 // Check for out of memory state. | 4322 // Check for out of memory state. |
4323 CHECK(result.IsEmpty()); | 4323 CHECK(result.IsEmpty()); |
4324 CHECK(context->HasOutOfMemoryException()); | 4324 CHECK(context->HasOutOfMemoryException()); |
4325 } | 4325 } |
4326 | 4326 |
4327 | 4327 |
4328 TEST(HugeConsStringOutOfMemory) { | 4328 TEST(HugeConsStringOutOfMemory) { |
4329 // It's not possible to read a snapshot into a heap with different dimensions. | 4329 // It's not possible to read a snapshot into a heap with different dimensions. |
4330 if (i::Snapshot::IsEnabled()) return; | 4330 if (i::Snapshot::IsEnabled()) return; |
4331 // Set heap limits. | 4331 // Set heap limits. |
4332 static const int K = 1024; | 4332 static const int K = 1024; |
4333 v8::ResourceConstraints constraints; | 4333 v8::ResourceConstraints constraints; |
4334 constraints.set_max_young_space_size(256 * K); | 4334 constraints.set_max_young_space_size(256 * K); |
4335 constraints.set_max_old_space_size(4 * K * K); | 4335 constraints.set_max_old_space_size(4 * K * K); |
4336 v8::SetResourceConstraints(&constraints); | 4336 v8::SetResourceConstraints(CcTest::isolate(), &constraints); |
4337 | 4337 |
4338 // Execute a script that causes out of memory. | 4338 // Execute a script that causes out of memory. |
4339 v8::V8::IgnoreOutOfMemoryException(); | 4339 v8::V8::IgnoreOutOfMemoryException(); |
4340 | 4340 |
4341 LocalContext context; | 4341 LocalContext context; |
4342 v8::HandleScope scope(context->GetIsolate()); | 4342 v8::HandleScope scope(context->GetIsolate()); |
4343 | 4343 |
4344 // Build huge string. This should fail with out of memory exception. | 4344 // Build huge string. This should fail with out of memory exception. |
4345 Local<Value> result = CompileRun( | 4345 Local<Value> result = CompileRun( |
4346 "var str = Array.prototype.join.call({length: 513}, \"A\").toUpperCase();" | 4346 "var str = Array.prototype.join.call({length: 513}, \"A\").toUpperCase();" |
(...skipping 12818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17165 // We need at least 165kB for an x64 debug build with clang and ASAN. | 17165 // We need at least 165kB for an x64 debug build with clang and ASAN. |
17166 static const int stack_breathing_room = 256 * i::KB; | 17166 static const int stack_breathing_room = 256 * i::KB; |
17167 | 17167 |
17168 | 17168 |
17169 TEST(SetResourceConstraints) { | 17169 TEST(SetResourceConstraints) { |
17170 uint32_t* set_limit = ComputeStackLimit(stack_breathing_room); | 17170 uint32_t* set_limit = ComputeStackLimit(stack_breathing_room); |
17171 | 17171 |
17172 // Set stack limit. | 17172 // Set stack limit. |
17173 v8::ResourceConstraints constraints; | 17173 v8::ResourceConstraints constraints; |
17174 constraints.set_stack_limit(set_limit); | 17174 constraints.set_stack_limit(set_limit); |
17175 CHECK(v8::SetResourceConstraints(&constraints)); | 17175 CHECK(v8::SetResourceConstraints(CcTest::isolate(), &constraints)); |
17176 | 17176 |
17177 // Execute a script. | 17177 // Execute a script. |
17178 LocalContext env; | 17178 LocalContext env; |
17179 v8::HandleScope scope(env->GetIsolate()); | 17179 v8::HandleScope scope(env->GetIsolate()); |
17180 Local<v8::FunctionTemplate> fun_templ = | 17180 Local<v8::FunctionTemplate> fun_templ = |
17181 v8::FunctionTemplate::New(GetStackLimitCallback); | 17181 v8::FunctionTemplate::New(GetStackLimitCallback); |
17182 Local<Function> fun = fun_templ->GetFunction(); | 17182 Local<Function> fun = fun_templ->GetFunction(); |
17183 env->Global()->Set(v8_str("get_stack_limit"), fun); | 17183 env->Global()->Set(v8_str("get_stack_limit"), fun); |
17184 CompileRun("get_stack_limit();"); | 17184 CompileRun("get_stack_limit();"); |
17185 | 17185 |
17186 CHECK(stack_limit == set_limit); | 17186 CHECK(stack_limit == set_limit); |
17187 } | 17187 } |
17188 | 17188 |
17189 | 17189 |
17190 TEST(SetResourceConstraintsInThread) { | 17190 TEST(SetResourceConstraintsInThread) { |
17191 uint32_t* set_limit; | 17191 uint32_t* set_limit; |
17192 { | 17192 { |
17193 v8::Locker locker(CcTest::isolate()); | 17193 v8::Locker locker(CcTest::isolate()); |
17194 set_limit = ComputeStackLimit(stack_breathing_room); | 17194 set_limit = ComputeStackLimit(stack_breathing_room); |
17195 | 17195 |
17196 // Set stack limit. | 17196 // Set stack limit. |
17197 v8::ResourceConstraints constraints; | 17197 v8::ResourceConstraints constraints; |
17198 constraints.set_stack_limit(set_limit); | 17198 constraints.set_stack_limit(set_limit); |
17199 CHECK(v8::SetResourceConstraints(&constraints)); | 17199 CHECK(v8::SetResourceConstraints(CcTest::isolate(), &constraints)); |
17200 | 17200 |
17201 // Execute a script. | 17201 // Execute a script. |
17202 v8::HandleScope scope(CcTest::isolate()); | 17202 v8::HandleScope scope(CcTest::isolate()); |
17203 LocalContext env; | 17203 LocalContext env; |
17204 Local<v8::FunctionTemplate> fun_templ = | 17204 Local<v8::FunctionTemplate> fun_templ = |
17205 v8::FunctionTemplate::New(GetStackLimitCallback); | 17205 v8::FunctionTemplate::New(GetStackLimitCallback); |
17206 Local<Function> fun = fun_templ->GetFunction(); | 17206 Local<Function> fun = fun_templ->GetFunction(); |
17207 env->Global()->Set(v8_str("get_stack_limit"), fun); | 17207 env->Global()->Set(v8_str("get_stack_limit"), fun); |
17208 CompileRun("get_stack_limit();"); | 17208 CompileRun("get_stack_limit();"); |
17209 | 17209 |
(...skipping 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18639 switch (testCase_) { | 18639 switch (testCase_) { |
18640 case IgnoreOOM: | 18640 case IgnoreOOM: |
18641 v8::V8::IgnoreOutOfMemoryException(); | 18641 v8::V8::IgnoreOutOfMemoryException(); |
18642 break; | 18642 break; |
18643 | 18643 |
18644 case SetResourceConstraints: { | 18644 case SetResourceConstraints: { |
18645 static const int K = 1024; | 18645 static const int K = 1024; |
18646 v8::ResourceConstraints constraints; | 18646 v8::ResourceConstraints constraints; |
18647 constraints.set_max_young_space_size(256 * K); | 18647 constraints.set_max_young_space_size(256 * K); |
18648 constraints.set_max_old_space_size(4 * K * K); | 18648 constraints.set_max_old_space_size(4 * K * K); |
18649 v8::SetResourceConstraints(&constraints); | 18649 v8::SetResourceConstraints(CcTest::isolate(), &constraints); |
18650 break; | 18650 break; |
18651 } | 18651 } |
18652 | 18652 |
18653 case SetFatalHandler: | 18653 case SetFatalHandler: |
18654 v8::V8::SetFatalErrorHandler(NULL); | 18654 v8::V8::SetFatalErrorHandler(NULL); |
18655 break; | 18655 break; |
18656 | 18656 |
18657 case SetCounterFunction: | 18657 case SetCounterFunction: |
18658 v8::V8::SetCounterFunction(NULL); | 18658 v8::V8::SetCounterFunction(NULL); |
18659 break; | 18659 break; |
(...skipping 2152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20812 } | 20812 } |
20813 for (int i = 0; i < runs; i++) { | 20813 for (int i = 0; i < runs; i++) { |
20814 Local<String> expected; | 20814 Local<String> expected; |
20815 if (i != 0) { | 20815 if (i != 0) { |
20816 CHECK_EQ(v8_str("escape value"), values[i]); | 20816 CHECK_EQ(v8_str("escape value"), values[i]); |
20817 } else { | 20817 } else { |
20818 CHECK(values[i].IsEmpty()); | 20818 CHECK(values[i].IsEmpty()); |
20819 } | 20819 } |
20820 } | 20820 } |
20821 } | 20821 } |
OLD | NEW |