| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 26 matching lines...) Expand all Loading... |
| 37 #include "compiler.h" | 37 #include "compiler.h" |
| 38 #include "scanner-character-streams.h" | 38 #include "scanner-character-streams.h" |
| 39 #include "shell-utils.h" | 39 #include "shell-utils.h" |
| 40 #include "parser.h" | 40 #include "parser.h" |
| 41 #include "preparse-data-format.h" | 41 #include "preparse-data-format.h" |
| 42 #include "preparse-data.h" | 42 #include "preparse-data.h" |
| 43 #include "preparser.h" | 43 #include "preparser.h" |
| 44 | 44 |
| 45 using namespace v8::internal; | 45 using namespace v8::internal; |
| 46 | 46 |
| 47 class StringResource8 : public v8::String::ExternalAsciiStringResource { |
| 48 public: |
| 49 StringResource8(const char* data, int length) |
| 50 : data_(data), length_(length) { } |
| 51 |
| 52 virtual size_t length() const { return length_; } |
| 53 virtual const char* data() const { return data_; } |
| 54 |
| 55 private: |
| 56 const char* data_; |
| 57 int length_; |
| 58 }; |
| 59 |
| 60 |
| 47 std::pair<TimeDelta, TimeDelta> RunBaselineParser( | 61 std::pair<TimeDelta, TimeDelta> RunBaselineParser( |
| 48 const char* fname, Encoding encoding, int repeat, v8::Isolate* isolate, | 62 const char* fname, Encoding encoding, int repeat, v8::Isolate* isolate, |
| 49 v8::Handle<v8::Context> context) { | 63 v8::Handle<v8::Context> context) { |
| 50 int length = 0; | 64 int length = 0; |
| 51 const byte* source = ReadFileAndRepeat(fname, &length, repeat); | 65 const byte* source = ReadFileAndRepeat(fname, &length, repeat); |
| 52 v8::Handle<v8::String> source_handle; | 66 v8::Handle<v8::String> source_handle; |
| 53 switch (encoding) { | 67 switch (encoding) { |
| 54 case UTF8: { | 68 case UTF8: { |
| 55 source_handle = v8::String::NewFromUtf8( | 69 source_handle = v8::String::NewFromUtf8( |
| 56 isolate, reinterpret_cast<const char*>(source)); | 70 isolate, reinterpret_cast<const char*>(source)); |
| 57 break; | 71 break; |
| 58 } | 72 } |
| 59 case UTF16: { | 73 case UTF16: { |
| 60 source_handle = v8::String::NewFromTwoByte( | 74 source_handle = v8::String::NewFromTwoByte( |
| 61 isolate, reinterpret_cast<const uint16_t*>(source), | 75 isolate, reinterpret_cast<const uint16_t*>(source), |
| 62 v8::String::kNormalString, length / 2); | 76 v8::String::kNormalString, length / 2); |
| 63 break; | 77 break; |
| 64 } | 78 } |
| 65 case LATIN1: { | 79 case LATIN1: { |
| 66 source_handle = v8::String::NewFromOneByte(isolate, source); | 80 StringResource8* string_resource = |
| 81 new StringResource8(reinterpret_cast<const char*>(source), length); |
| 82 source_handle = v8::String::NewExternal(isolate, string_resource); |
| 67 break; | 83 break; |
| 68 } | 84 } |
| 69 } | 85 } |
| 70 TimeDelta parse_time1, parse_time2; | 86 TimeDelta parse_time1, parse_time2; |
| 71 Handle<Script> script = Isolate::Current()->factory()->NewScript( | 87 Handle<Script> script = Isolate::Current()->factory()->NewScript( |
| 72 v8::Utils::OpenHandle(*source_handle)); | 88 v8::Utils::OpenHandle(*source_handle)); |
| 73 i::ScriptData* cached_data_impl = NULL; | 89 i::ScriptData* cached_data_impl = NULL; |
| 74 // First round of parsing (produce data to cache). | 90 // First round of parsing (produce data to cache). |
| 75 { | 91 { |
| 76 CompilationInfoWithZone info(script); | 92 CompilationInfoWithZone info(script); |
| 77 info.MarkAsGlobal(); | 93 info.MarkAsGlobal(); |
| 78 info.SetCachedData(&cached_data_impl, i::PRODUCE_CACHED_DATA); | 94 info.SetCachedData(&cached_data_impl, i::PRODUCE_CACHED_DATA); |
| 79 ElapsedTimer timer; | 95 ElapsedTimer timer; |
| 80 timer.Start(); | 96 timer.Start(); |
| 81 // Allow lazy parsing; otherwise we won't produce cached data. | 97 // Allow lazy parsing; otherwise we won't produce cached data. |
| 82 bool success = Parser::Parse(&info, true); | 98 bool success = Parser::Parse(&info, true); |
| 83 parse_time1 = timer.Elapsed(); | 99 parse_time1 = timer.Elapsed(); |
| 84 if (!success) { | 100 if (!success) { |
| 85 fprintf(stderr, "Parsing failed\n"); | 101 fprintf(stderr, "Parsing failed\n"); |
| 86 return std::make_pair(TimeDelta(), TimeDelta()); | 102 return std::make_pair(TimeDelta(), TimeDelta()); |
| 87 } | 103 } |
| 104 if (!cached_data_impl) { |
| 105 fprintf(stderr, "Didn't produce cached data\n"); |
| 106 return std::make_pair(parse_time1, TimeDelta()); |
| 107 } |
| 88 } | 108 } |
| 89 // Second round of parsing (consume cached data). | 109 // Second round of parsing (consume cached data). |
| 90 { | 110 { |
| 91 CompilationInfoWithZone info(script); | 111 CompilationInfoWithZone info(script); |
| 92 info.MarkAsGlobal(); | 112 info.MarkAsGlobal(); |
| 93 info.SetCachedData(&cached_data_impl, i::CONSUME_CACHED_DATA); | 113 info.SetCachedData(&cached_data_impl, i::CONSUME_CACHED_DATA); |
| 94 ElapsedTimer timer; | 114 ElapsedTimer timer; |
| 95 timer.Start(); | 115 timer.Start(); |
| 96 // Allow lazy parsing; otherwise cached data won't help. | 116 // Allow lazy parsing; otherwise cached data won't help. |
| 97 bool success = Parser::Parse(&info, true); | 117 bool success = Parser::Parse(&info, true); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 if (benchmark.empty()) benchmark = "Baseline"; | 167 if (benchmark.empty()) benchmark = "Baseline"; |
| 148 printf("%s(FirstParseRunTime): %.f ms\n", benchmark.c_str(), | 168 printf("%s(FirstParseRunTime): %.f ms\n", benchmark.c_str(), |
| 149 first_parse_total); | 169 first_parse_total); |
| 150 printf("%s(SecondParseRunTime): %.f ms\n", benchmark.c_str(), | 170 printf("%s(SecondParseRunTime): %.f ms\n", benchmark.c_str(), |
| 151 second_parse_total); | 171 second_parse_total); |
| 152 } | 172 } |
| 153 } | 173 } |
| 154 v8::V8::Dispose(); | 174 v8::V8::Dispose(); |
| 155 return 0; | 175 return 0; |
| 156 } | 176 } |
| OLD | NEW |