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

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

Issue 214883002: Two-threaded parser (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « src/scanner-character-streams.cc ('k') | tools/gyp/v8.gyp » ('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
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 CcTest::i_isolate()->stack_guard()->SetStackLimit( 145 CcTest::i_isolate()->stack_guard()->SetStackLimit(
146 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 146 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
147 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); 147 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
148 for (int i = 0; tests[i]; i++) { 148 for (int i = 0; tests[i]; i++) {
149 const i::byte* source = 149 const i::byte* source =
150 reinterpret_cast<const i::byte*>(tests[i]); 150 reinterpret_cast<const i::byte*>(tests[i]);
151 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(tests[i])); 151 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(tests[i]));
152 i::CompleteParserRecorder log; 152 i::CompleteParserRecorder log;
153 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 153 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
154 scanner.Initialize(&stream); 154 scanner.Initialize(&stream);
155 i::PreParser preparser(&scanner, &log, stack_limit); 155 i::PreParser preparser(&scanner, &log, stack_limit, NULL);
156 preparser.set_allow_lazy(true); 156 preparser.set_allow_lazy(true);
157 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 157 i::PreParser::PreParseResult result = preparser.PreParseProgram();
158 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 158 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
159 i::ScriptData data(log.ExtractData()); 159 i::ScriptData data(log.ExtractData());
160 CHECK(!data.has_error()); 160 CHECK(!data.has_error());
161 } 161 }
162 162
163 for (int i = 0; fail_tests[i]; i++) { 163 for (int i = 0; fail_tests[i]; i++) {
164 const i::byte* source = 164 const i::byte* source =
165 reinterpret_cast<const i::byte*>(fail_tests[i]); 165 reinterpret_cast<const i::byte*>(fail_tests[i]);
166 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(fail_tests[i])); 166 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(fail_tests[i]));
167 i::CompleteParserRecorder log; 167 i::CompleteParserRecorder log;
168 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 168 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
169 scanner.Initialize(&stream); 169 scanner.Initialize(&stream);
170 i::PreParser preparser(&scanner, &log, stack_limit); 170 i::PreParser preparser(&scanner, &log, stack_limit, NULL);
171 preparser.set_allow_lazy(true); 171 preparser.set_allow_lazy(true);
172 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 172 i::PreParser::PreParseResult result = preparser.PreParseProgram();
173 // Even in the case of a syntax error, kPreParseSuccess is returned. 173 // Even in the case of a syntax error, kPreParseSuccess is returned.
174 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 174 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
175 i::ScriptData data(log.ExtractData()); 175 i::ScriptData data(log.ExtractData());
176 CHECK(data.has_error()); 176 CHECK(data.has_error());
177 } 177 }
178 } 178 }
179 179
180 180
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); 296 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
297 for (int i = 0; programs[i]; i++) { 297 for (int i = 0; programs[i]; i++) {
298 const char* program = programs[i]; 298 const char* program = programs[i];
299 i::Utf8ToUtf16CharacterStream stream( 299 i::Utf8ToUtf16CharacterStream stream(
300 reinterpret_cast<const i::byte*>(program), 300 reinterpret_cast<const i::byte*>(program),
301 static_cast<unsigned>(strlen(program))); 301 static_cast<unsigned>(strlen(program)));
302 i::CompleteParserRecorder log; 302 i::CompleteParserRecorder log;
303 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 303 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
304 scanner.Initialize(&stream); 304 scanner.Initialize(&stream);
305 305
306 i::PreParser preparser(&scanner, &log, stack_limit); 306 i::PreParser preparser(&scanner, &log, stack_limit, NULL);
307 preparser.set_allow_lazy(true); 307 preparser.set_allow_lazy(true);
308 preparser.set_allow_natives_syntax(true); 308 preparser.set_allow_natives_syntax(true);
309 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 309 i::PreParser::PreParseResult result = preparser.PreParseProgram();
310 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 310 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
311 i::ScriptData data(log.ExtractData()); 311 i::ScriptData data(log.ExtractData());
312 CHECK(!data.has_error()); 312 CHECK(!data.has_error());
313 } 313 }
314 } 314 }
315 315
316 316
(...skipping 14 matching lines...) Expand all
331 for (int i = 0; programs[i]; i++) { 331 for (int i = 0; programs[i]; i++) {
332 const char* program = programs[i]; 332 const char* program = programs[i];
333 i::Utf8ToUtf16CharacterStream stream( 333 i::Utf8ToUtf16CharacterStream stream(
334 reinterpret_cast<const i::byte*>(program), 334 reinterpret_cast<const i::byte*>(program),
335 static_cast<unsigned>(strlen(program))); 335 static_cast<unsigned>(strlen(program)));
336 i::CompleteParserRecorder log; 336 i::CompleteParserRecorder log;
337 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 337 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
338 scanner.Initialize(&stream); 338 scanner.Initialize(&stream);
339 339
340 // Preparser defaults to disallowing natives syntax. 340 // Preparser defaults to disallowing natives syntax.
341 i::PreParser preparser(&scanner, &log, stack_limit); 341 i::PreParser preparser(&scanner, &log, stack_limit, NULL);
342 preparser.set_allow_lazy(true); 342 preparser.set_allow_lazy(true);
343 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 343 i::PreParser::PreParseResult result = preparser.PreParseProgram();
344 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 344 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
345 i::ScriptData data(log.ExtractData()); 345 i::ScriptData data(log.ExtractData());
346 // Data contains syntax error. 346 // Data contains syntax error.
347 CHECK(data.has_error()); 347 CHECK(data.has_error());
348 } 348 }
349 } 349 }
350 350
351 351
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 // Before fix, didn't check *ok after Expect(Token::Identifier, ok), 400 // Before fix, didn't check *ok after Expect(Token::Identifier, ok),
401 // and then used the invalid currently scanned literal. This always 401 // and then used the invalid currently scanned literal. This always
402 // failed in debug mode, and sometimes crashed in release mode. 402 // failed in debug mode, and sometimes crashed in release mode.
403 403
404 i::Utf8ToUtf16CharacterStream stream( 404 i::Utf8ToUtf16CharacterStream stream(
405 reinterpret_cast<const i::byte*>(program), 405 reinterpret_cast<const i::byte*>(program),
406 static_cast<unsigned>(strlen(program))); 406 static_cast<unsigned>(strlen(program)));
407 i::CompleteParserRecorder log; 407 i::CompleteParserRecorder log;
408 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 408 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
409 scanner.Initialize(&stream); 409 scanner.Initialize(&stream);
410 i::PreParser preparser(&scanner, &log, 410 i::PreParser preparser(
411 CcTest::i_isolate()->stack_guard()->real_climit()); 411 &scanner, &log, CcTest::i_isolate()->stack_guard()->real_climit(), NULL);
412 preparser.set_allow_lazy(true); 412 preparser.set_allow_lazy(true);
413 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 413 i::PreParser::PreParseResult result = preparser.PreParseProgram();
414 // Even in the case of a syntax error, kPreParseSuccess is returned. 414 // Even in the case of a syntax error, kPreParseSuccess is returned.
415 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 415 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
416 i::ScriptData data(log.ExtractData()); 416 i::ScriptData data(log.ExtractData());
417 CHECK(data.has_error()); 417 CHECK(data.has_error());
418 } 418 }
419 419
420 420
421 TEST(Regress928) { 421 TEST(Regress928) {
(...skipping 12 matching lines...) Expand all
434 const char* program = 434 const char* program =
435 "try { } catch (e) { var foo = function () { /* first */ } }" 435 "try { } catch (e) { var foo = function () { /* first */ } }"
436 "var bar = function () { /* second */ }"; 436 "var bar = function () { /* second */ }";
437 437
438 v8::HandleScope handles(CcTest::isolate()); 438 v8::HandleScope handles(CcTest::isolate());
439 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(program); 439 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(program);
440 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); 440 i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
441 i::CompleteParserRecorder log; 441 i::CompleteParserRecorder log;
442 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 442 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
443 scanner.Initialize(&stream); 443 scanner.Initialize(&stream);
444 i::PreParser preparser(&scanner, &log, 444 i::PreParser preparser(
445 CcTest::i_isolate()->stack_guard()->real_climit()); 445 &scanner, &log, CcTest::i_isolate()->stack_guard()->real_climit(), NULL);
446 preparser.set_allow_lazy(true); 446 preparser.set_allow_lazy(true);
447 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 447 i::PreParser::PreParseResult result = preparser.PreParseProgram();
448 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 448 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
449 i::ScriptData data(log.ExtractData()); 449 i::ScriptData data(log.ExtractData());
450 CHECK(!data.has_error()); 450 CHECK(!data.has_error());
451 data.Initialize(); 451 data.Initialize();
452 452
453 int first_function = 453 int first_function =
454 static_cast<int>(strstr(program, "function") - program); 454 static_cast<int>(strstr(program, "function") - program);
455 int first_lbrace = first_function + i::StrLength("function () "); 455 int first_lbrace = first_function + i::StrLength("function () ");
(...skipping 26 matching lines...) Expand all
482 482
483 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); 483 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
484 484
485 i::Utf8ToUtf16CharacterStream stream( 485 i::Utf8ToUtf16CharacterStream stream(
486 reinterpret_cast<const i::byte*>(program.get()), 486 reinterpret_cast<const i::byte*>(program.get()),
487 static_cast<unsigned>(kProgramSize)); 487 static_cast<unsigned>(kProgramSize));
488 i::CompleteParserRecorder log; 488 i::CompleteParserRecorder log;
489 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 489 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
490 scanner.Initialize(&stream); 490 scanner.Initialize(&stream);
491 491
492 i::PreParser preparser(&scanner, &log, stack_limit); 492 i::PreParser preparser(&scanner, &log, stack_limit, NULL);
493 preparser.set_allow_lazy(true); 493 preparser.set_allow_lazy(true);
494 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 494 i::PreParser::PreParseResult result = preparser.PreParseProgram();
495 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result); 495 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result);
496 } 496 }
497 497
498 498
499 class TestExternalResource: public v8::String::ExternalStringResource { 499 class TestExternalResource: public v8::String::ExternalStringResource {
500 public: 500 public:
501 explicit TestExternalResource(uint16_t* data, int length) 501 explicit TestExternalResource(uint16_t* data, int length)
502 : data_(data), length_(static_cast<size_t>(length)) { } 502 : data_(data), length_(static_cast<size_t>(length)) { }
(...skipping 29 matching lines...) Expand all
532 uc16_buffer[i] = static_cast<i::uc16>(ascii_source[i]); 532 uc16_buffer[i] = static_cast<i::uc16>(ascii_source[i]);
533 } 533 }
534 i::Vector<const char> ascii_vector(ascii_source, static_cast<int>(length)); 534 i::Vector<const char> ascii_vector(ascii_source, static_cast<int>(length));
535 i::Handle<i::String> ascii_string = 535 i::Handle<i::String> ascii_string =
536 factory->NewStringFromAscii(ascii_vector).ToHandleChecked(); 536 factory->NewStringFromAscii(ascii_vector).ToHandleChecked();
537 TestExternalResource resource(uc16_buffer.get(), length); 537 TestExternalResource resource(uc16_buffer.get(), length);
538 i::Handle<i::String> uc16_string( 538 i::Handle<i::String> uc16_string(
539 factory->NewExternalStringFromTwoByte(&resource).ToHandleChecked()); 539 factory->NewExternalStringFromTwoByte(&resource).ToHandleChecked());
540 540
541 i::ExternalTwoByteStringUtf16CharacterStream uc16_stream( 541 i::ExternalTwoByteStringUtf16CharacterStream uc16_stream(
542 i::Handle<i::ExternalTwoByteString>::cast(uc16_string), start, end); 542 i::Handle<i::ExternalTwoByteString>::cast(uc16_string)->GetTwoByteData(0),
543 start, end);
543 i::GenericStringUtf16CharacterStream string_stream(ascii_string, start, end); 544 i::GenericStringUtf16CharacterStream string_stream(ascii_string, start, end);
544 i::Utf8ToUtf16CharacterStream utf8_stream( 545 i::Utf8ToUtf16CharacterStream utf8_stream(
545 reinterpret_cast<const i::byte*>(ascii_source), end); 546 reinterpret_cast<const i::byte*>(ascii_source), end);
546 utf8_stream.SeekForward(start); 547 utf8_stream.SeekForward(start);
547 548
548 unsigned i = start; 549 unsigned i = start;
549 while (i < end) { 550 while (i < end) {
550 // Read streams one char at a time 551 // Read streams one char at a time
551 CHECK_EQU(i, uc16_stream.pos()); 552 CHECK_EQU(i, uc16_stream.pos());
552 CHECK_EQU(i, string_stream.pos()); 553 CHECK_EQU(i, string_stream.pos());
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 i::Isolate* isolate = CcTest::i_isolate(); 1206 i::Isolate* isolate = CcTest::i_isolate();
1206 i::Factory* factory = isolate->factory(); 1207 i::Factory* factory = isolate->factory();
1207 1208
1208 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); 1209 uintptr_t stack_limit = isolate->stack_guard()->real_climit();
1209 1210
1210 // Preparse the data. 1211 // Preparse the data.
1211 i::CompleteParserRecorder log; 1212 i::CompleteParserRecorder log;
1212 { 1213 {
1213 i::Scanner scanner(isolate->unicode_cache()); 1214 i::Scanner scanner(isolate->unicode_cache());
1214 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); 1215 i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
1215 i::PreParser preparser(&scanner, &log, stack_limit); 1216 i::PreParser preparser(&scanner, &log, stack_limit, NULL);
1216 SetParserFlags(&preparser, flags); 1217 SetParserFlags(&preparser, flags);
1217 scanner.Initialize(&stream); 1218 scanner.Initialize(&stream);
1218 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 1219 i::PreParser::PreParseResult result = preparser.PreParseProgram();
1219 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 1220 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
1220 } 1221 }
1221 i::ScriptData data(log.ExtractData()); 1222 i::ScriptData data(log.ExtractData());
1222 1223
1223 // Parse the data 1224 // Parse the data
1224 i::FunctionLiteral* function; 1225 i::FunctionLiteral* function;
1225 { 1226 {
(...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after
2449 RunParserSyncTest(assignment_context_data, bad_statement_data_common, kError); 2450 RunParserSyncTest(assignment_context_data, bad_statement_data_common, kError);
2450 RunParserSyncTest(assignment_context_data, bad_statement_data_for_assignment, 2451 RunParserSyncTest(assignment_context_data, bad_statement_data_for_assignment,
2451 kError); 2452 kError);
2452 2453
2453 RunParserSyncTest(prefix_context_data, good_statement_data, kSuccess); 2454 RunParserSyncTest(prefix_context_data, good_statement_data, kSuccess);
2454 RunParserSyncTest(prefix_context_data, bad_statement_data_common, kError); 2455 RunParserSyncTest(prefix_context_data, bad_statement_data_common, kError);
2455 2456
2456 RunParserSyncTest(postfix_context_data, good_statement_data, kSuccess); 2457 RunParserSyncTest(postfix_context_data, good_statement_data, kSuccess);
2457 RunParserSyncTest(postfix_context_data, bad_statement_data_common, kError); 2458 RunParserSyncTest(postfix_context_data, bad_statement_data_common, kError);
2458 } 2459 }
2460
2461
2462 TEST(ParallelParsing) {
2463 // Make lazy parsing and parallel parsing work for short scripts.
2464 i::FLAG_min_preparse_length = 0;
2465 i::FLAG_min_parallel_parse_length = 0;
2466
2467 v8::Isolate* isolate = CcTest::isolate();
2468 v8::HandleScope handles(isolate);
2469 v8::Local<v8::Context> context = v8::Context::New(isolate);
2470 v8::Context::Scope context_scope(context);
2471 int marker;
2472 CcTest::i_isolate()->stack_guard()->SetStackLimit(
2473 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
2474
2475 const char* code =
2476 "var outside_var = 8;\n"
2477 "function this_is_lazy() { return 5 + outside_var; }\n"
2478 "(function not_lazy() { return this_is_lazy(); })()";
2479 v8::ScriptCompiler::Source source(v8::String::NewExternal(
2480 isolate, new ScriptResource(code, i::StrLength(code))));
2481 v8::TryCatch try_catch;
2482 v8::Handle<v8::Script> script = v8::ScriptCompiler::Compile(
2483 isolate, &source, v8::ScriptCompiler::kProduceDataToCache);
2484 CHECK(!script.IsEmpty());
2485 CHECK(!try_catch.HasCaught());
2486 v8::Local<v8::Value> result = script->Run();
2487 CHECK(result->IsInt32());
2488 CHECK_EQ(13, result->Int32Value());
2489 }
2490
2491
2492 TEST(ParallelParsingErrorInLazyFunction) {
2493 // Make lazy parsing and parallel parsing work for short scripts.
2494 i::FLAG_min_preparse_length = 0;
2495 i::FLAG_min_parallel_parse_length = 0;
2496
2497 v8::Isolate* isolate = CcTest::isolate();
2498 v8::HandleScope handles(isolate);
2499 v8::Local<v8::Context> context = v8::Context::New(isolate);
2500 v8::Context::Scope context_scope(context);
2501 int marker;
2502 CcTest::i_isolate()->stack_guard()->SetStackLimit(
2503 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
2504
2505 // Compile code which has error inside a lazy function. Check that we get an
2506 // error.
2507 const char* code =
2508 "function this_is_lazy() { 1 2 3 error }";
2509 v8::ScriptCompiler::Source source(v8::String::NewExternal(
2510 isolate, new ScriptResource(code, i::StrLength(code))));
2511 v8::TryCatch try_catch;
2512 v8::Handle<v8::Script> script = v8::ScriptCompiler::Compile(
2513 isolate, &source, v8::ScriptCompiler::kProduceDataToCache);
2514 CHECK(try_catch.HasCaught());
2515 v8::String::Utf8Value exception(try_catch.Exception());
2516 CHECK_EQ("SyntaxError: Unexpected number", *exception);
2517 CHECK(script.IsEmpty());
2518 }
OLDNEW
« no previous file with comments | « src/scanner-character-streams.cc ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698