2014-03-24 14:43:41 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/v8.h"
|
2014-03-24 14:43:41 +00:00
|
|
|
|
2014-07-03 07:37:27 +00:00
|
|
|
#include "include/libplatform/libplatform.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/api.h"
|
|
|
|
#include "src/compiler.h"
|
2017-01-09 13:43:28 +00:00
|
|
|
#include "src/objects-inl.h"
|
2016-08-22 11:33:30 +00:00
|
|
|
#include "src/parsing/parse-info.h"
|
2016-11-30 13:21:11 +00:00
|
|
|
#include "src/parsing/parsing.h"
|
2015-11-26 16:22:34 +00:00
|
|
|
#include "src/parsing/preparse-data-format.h"
|
|
|
|
#include "src/parsing/preparse-data.h"
|
|
|
|
#include "src/parsing/preparser.h"
|
2016-08-22 11:33:30 +00:00
|
|
|
#include "src/parsing/scanner-character-streams.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "tools/shell-utils.h"
|
2014-03-24 14:43:41 +00:00
|
|
|
|
|
|
|
using namespace v8::internal;
|
|
|
|
|
2014-09-10 12:56:19 +00:00
|
|
|
class StringResource8 : public v8::String::ExternalOneByteStringResource {
|
2014-06-24 14:03:24 +00:00
|
|
|
public:
|
|
|
|
StringResource8(const char* data, int length)
|
|
|
|
: data_(data), length_(length) { }
|
|
|
|
virtual size_t length() const { return length_; }
|
|
|
|
virtual const char* data() const { return data_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const char* data_;
|
|
|
|
int length_;
|
|
|
|
};
|
|
|
|
|
2014-06-30 13:25:46 +00:00
|
|
|
std::pair<v8::base::TimeDelta, v8::base::TimeDelta> RunBaselineParser(
|
2014-03-24 14:43:41 +00:00
|
|
|
const char* fname, Encoding encoding, int repeat, v8::Isolate* isolate,
|
2015-07-06 07:11:40 +00:00
|
|
|
v8::Local<v8::Context> context) {
|
2014-03-24 14:43:41 +00:00
|
|
|
int length = 0;
|
|
|
|
const byte* source = ReadFileAndRepeat(fname, &length, repeat);
|
2015-07-06 07:11:40 +00:00
|
|
|
v8::Local<v8::String> source_handle;
|
2014-03-24 14:43:41 +00:00
|
|
|
switch (encoding) {
|
|
|
|
case UTF8: {
|
|
|
|
source_handle = v8::String::NewFromUtf8(
|
2015-07-06 07:11:40 +00:00
|
|
|
isolate, reinterpret_cast<const char*>(source),
|
|
|
|
v8::NewStringType::kNormal).ToLocalChecked();
|
2014-03-24 14:43:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case UTF16: {
|
2015-07-06 07:11:40 +00:00
|
|
|
source_handle =
|
|
|
|
v8::String::NewFromTwoByte(
|
|
|
|
isolate, reinterpret_cast<const uint16_t*>(source),
|
|
|
|
v8::NewStringType::kNormal, length / 2).ToLocalChecked();
|
2014-03-24 14:43:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LATIN1: {
|
2014-06-24 14:03:24 +00:00
|
|
|
StringResource8* string_resource =
|
|
|
|
new StringResource8(reinterpret_cast<const char*>(source), length);
|
2015-07-06 07:11:40 +00:00
|
|
|
source_handle = v8::String::NewExternalOneByte(isolate, string_resource)
|
|
|
|
.ToLocalChecked();
|
2014-03-24 14:43:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-06-30 13:25:46 +00:00
|
|
|
v8::base::TimeDelta parse_time1, parse_time2;
|
2015-05-15 01:47:15 +00:00
|
|
|
Handle<Script> script =
|
|
|
|
reinterpret_cast<i::Isolate*>(isolate)->factory()->NewScript(
|
|
|
|
v8::Utils::OpenHandle(*source_handle));
|
2014-04-11 11:44:49 +00:00
|
|
|
i::ScriptData* cached_data_impl = NULL;
|
2014-04-04 12:36:23 +00:00
|
|
|
// First round of parsing (produce data to cache).
|
|
|
|
{
|
Reland of land: [Parse] ParseInfo owns the parsing Zone. (patchset #1 id:1 of https://codereview.chromium.org/2683733002/ )
Reason for revert:
False alarm, bot hiccup
Original issue's description:
> Revert of Reland: [Parse] ParseInfo owns the parsing Zone. (patchset #7 id:140001 of https://codereview.chromium.org/2632123006/ )
>
> Reason for revert:
> Speculative revert because of revert needed for https://codereview.chromium.org/2632123006
>
> Original issue's description:
> > Reland: [Parse] ParseInfo owns the parsing Zone.
> >
> > Moves ownership of the parsing Zone to ParseInfo with a shared_ptr. This is
> > in preperation for enabling background compilation jobs for inner functions
> > share the AST in the outer-function's parse zone memory (read-only), with the
> > and zone being released when all compilation jobs have completed.
> >
> > BUG=v8:5203,v8:5215
> >
> > Review-Url: https://codereview.chromium.org/2632123006
> > Cr-Original-Commit-Position: refs/heads/master@{#42993}
> > Committed: https://chromium.googlesource.com/v8/v8/+/14fb337200d5da09c77438ddd40bea935b1dc823
> > Review-Url: https://codereview.chromium.org/2632123006
> > Cr-Commit-Position: refs/heads/master@{#42996}
> > Committed: https://chromium.googlesource.com/v8/v8/+/9e7d5a6065470ca03411d4c8dbc61d1be5c3f84a
>
> TBR=marja@chromium.org,mstarzinger@chromium.org,ahaas@chromium.org,verwaest@chromium.org,rmcilroy@chromium.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=v8:5203,v8:5215
>
> Review-Url: https://codereview.chromium.org/2683733002
> Cr-Commit-Position: refs/heads/master@{#43008}
> Committed: https://chromium.googlesource.com/v8/v8/+/9fe08ec067051c5b46e694568bd01c6dba44cc4d
TBR=marja@chromium.org,mstarzinger@chromium.org,ahaas@chromium.org,verwaest@chromium.org,rmcilroy@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=v8:5203,v8:5215
Review-Url: https://codereview.chromium.org/2679303003
Cr-Commit-Position: refs/heads/master@{#43015}
2017-02-07 20:46:47 +00:00
|
|
|
ParseInfo info(script);
|
2015-03-09 14:51:13 +00:00
|
|
|
info.set_cached_data(&cached_data_impl);
|
|
|
|
info.set_compile_options(v8::ScriptCompiler::kProduceParserCache);
|
2014-06-30 13:25:46 +00:00
|
|
|
v8::base::ElapsedTimer timer;
|
2014-03-24 14:43:41 +00:00
|
|
|
timer.Start();
|
2017-03-22 14:05:35 +00:00
|
|
|
bool success =
|
|
|
|
parsing::ParseProgram(&info, reinterpret_cast<i::Isolate*>(isolate));
|
2014-04-04 12:36:23 +00:00
|
|
|
parse_time1 = timer.Elapsed();
|
|
|
|
if (!success) {
|
|
|
|
fprintf(stderr, "Parsing failed\n");
|
2014-06-30 13:25:46 +00:00
|
|
|
return std::make_pair(v8::base::TimeDelta(), v8::base::TimeDelta());
|
2014-03-24 14:43:41 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-04 12:36:23 +00:00
|
|
|
// Second round of parsing (consume cached data).
|
|
|
|
{
|
Reland of land: [Parse] ParseInfo owns the parsing Zone. (patchset #1 id:1 of https://codereview.chromium.org/2683733002/ )
Reason for revert:
False alarm, bot hiccup
Original issue's description:
> Revert of Reland: [Parse] ParseInfo owns the parsing Zone. (patchset #7 id:140001 of https://codereview.chromium.org/2632123006/ )
>
> Reason for revert:
> Speculative revert because of revert needed for https://codereview.chromium.org/2632123006
>
> Original issue's description:
> > Reland: [Parse] ParseInfo owns the parsing Zone.
> >
> > Moves ownership of the parsing Zone to ParseInfo with a shared_ptr. This is
> > in preperation for enabling background compilation jobs for inner functions
> > share the AST in the outer-function's parse zone memory (read-only), with the
> > and zone being released when all compilation jobs have completed.
> >
> > BUG=v8:5203,v8:5215
> >
> > Review-Url: https://codereview.chromium.org/2632123006
> > Cr-Original-Commit-Position: refs/heads/master@{#42993}
> > Committed: https://chromium.googlesource.com/v8/v8/+/14fb337200d5da09c77438ddd40bea935b1dc823
> > Review-Url: https://codereview.chromium.org/2632123006
> > Cr-Commit-Position: refs/heads/master@{#42996}
> > Committed: https://chromium.googlesource.com/v8/v8/+/9e7d5a6065470ca03411d4c8dbc61d1be5c3f84a
>
> TBR=marja@chromium.org,mstarzinger@chromium.org,ahaas@chromium.org,verwaest@chromium.org,rmcilroy@chromium.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=v8:5203,v8:5215
>
> Review-Url: https://codereview.chromium.org/2683733002
> Cr-Commit-Position: refs/heads/master@{#43008}
> Committed: https://chromium.googlesource.com/v8/v8/+/9fe08ec067051c5b46e694568bd01c6dba44cc4d
TBR=marja@chromium.org,mstarzinger@chromium.org,ahaas@chromium.org,verwaest@chromium.org,rmcilroy@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=v8:5203,v8:5215
Review-Url: https://codereview.chromium.org/2679303003
Cr-Commit-Position: refs/heads/master@{#43015}
2017-02-07 20:46:47 +00:00
|
|
|
ParseInfo info(script);
|
2015-03-09 14:51:13 +00:00
|
|
|
info.set_cached_data(&cached_data_impl);
|
|
|
|
info.set_compile_options(v8::ScriptCompiler::kConsumeParserCache);
|
2014-06-30 13:25:46 +00:00
|
|
|
v8::base::ElapsedTimer timer;
|
2014-03-24 14:43:41 +00:00
|
|
|
timer.Start();
|
2017-03-22 14:05:35 +00:00
|
|
|
bool success =
|
|
|
|
parsing::ParseProgram(&info, reinterpret_cast<i::Isolate*>(isolate));
|
2014-04-04 12:36:23 +00:00
|
|
|
parse_time2 = timer.Elapsed();
|
2014-03-24 14:43:41 +00:00
|
|
|
if (!success) {
|
|
|
|
fprintf(stderr, "Parsing failed\n");
|
2014-06-30 13:25:46 +00:00
|
|
|
return std::make_pair(v8::base::TimeDelta(), v8::base::TimeDelta());
|
2014-03-24 14:43:41 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-04 12:36:23 +00:00
|
|
|
return std::make_pair(parse_time1, parse_time2);
|
2014-03-24 14:43:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
2014-09-19 08:01:35 +00:00
|
|
|
v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
|
2016-06-08 12:09:25 +00:00
|
|
|
v8::V8::InitializeICUDefaultLocation(argv[0]);
|
2014-07-03 07:57:29 +00:00
|
|
|
v8::Platform* platform = v8::platform::CreateDefaultPlatform();
|
2014-07-03 07:37:27 +00:00
|
|
|
v8::V8::InitializePlatform(platform);
|
2014-09-19 08:01:35 +00:00
|
|
|
v8::V8::Initialize();
|
2015-08-14 12:11:29 +00:00
|
|
|
v8::V8::InitializeExternalStartupData(argv[0]);
|
|
|
|
|
2014-03-24 14:43:41 +00:00
|
|
|
Encoding encoding = LATIN1;
|
|
|
|
std::vector<std::string> fnames;
|
|
|
|
std::string benchmark;
|
|
|
|
int repeat = 1;
|
|
|
|
for (int i = 0; i < argc; ++i) {
|
|
|
|
if (strcmp(argv[i], "--latin1") == 0) {
|
|
|
|
encoding = LATIN1;
|
|
|
|
} else if (strcmp(argv[i], "--utf8") == 0) {
|
|
|
|
encoding = UTF8;
|
|
|
|
} else if (strcmp(argv[i], "--utf16") == 0) {
|
|
|
|
encoding = UTF16;
|
|
|
|
} else if (strncmp(argv[i], "--benchmark=", 12) == 0) {
|
|
|
|
benchmark = std::string(argv[i]).substr(12);
|
|
|
|
} else if (strncmp(argv[i], "--repeat=", 9) == 0) {
|
|
|
|
std::string repeat_str = std::string(argv[i]).substr(9);
|
|
|
|
repeat = atoi(repeat_str.c_str());
|
|
|
|
} else if (i > 0 && argv[i][0] != '-') {
|
|
|
|
fnames.push_back(std::string(argv[i]));
|
|
|
|
}
|
|
|
|
}
|
2015-04-29 09:54:34 +00:00
|
|
|
v8::Isolate::CreateParams create_params;
|
2016-06-29 07:39:45 +00:00
|
|
|
create_params.array_buffer_allocator =
|
|
|
|
v8::ArrayBuffer::Allocator::NewDefaultAllocator();
|
2015-04-29 09:54:34 +00:00
|
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
2014-03-24 14:43:41 +00:00
|
|
|
{
|
2014-05-08 06:52:35 +00:00
|
|
|
v8::Isolate::Scope isolate_scope(isolate);
|
2014-03-24 14:43:41 +00:00
|
|
|
v8::HandleScope handle_scope(isolate);
|
2015-07-06 07:11:40 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
|
2014-03-24 14:43:41 +00:00
|
|
|
v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global);
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!context.IsEmpty());
|
2014-03-24 14:43:41 +00:00
|
|
|
{
|
|
|
|
v8::Context::Scope scope(context);
|
2014-04-04 12:36:23 +00:00
|
|
|
double first_parse_total = 0;
|
|
|
|
double second_parse_total = 0;
|
2014-03-24 14:43:41 +00:00
|
|
|
for (size_t i = 0; i < fnames.size(); i++) {
|
2014-06-30 13:25:46 +00:00
|
|
|
std::pair<v8::base::TimeDelta, v8::base::TimeDelta> time =
|
|
|
|
RunBaselineParser(fnames[i].c_str(), encoding, repeat, isolate,
|
|
|
|
context);
|
2014-04-04 12:36:23 +00:00
|
|
|
first_parse_total += time.first.InMillisecondsF();
|
|
|
|
second_parse_total += time.second.InMillisecondsF();
|
2014-03-24 14:43:41 +00:00
|
|
|
}
|
|
|
|
if (benchmark.empty()) benchmark = "Baseline";
|
2014-04-04 12:36:23 +00:00
|
|
|
printf("%s(FirstParseRunTime): %.f ms\n", benchmark.c_str(),
|
|
|
|
first_parse_total);
|
|
|
|
printf("%s(SecondParseRunTime): %.f ms\n", benchmark.c_str(),
|
|
|
|
second_parse_total);
|
2014-03-24 14:43:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
v8::V8::Dispose();
|
2014-07-03 07:37:27 +00:00
|
|
|
v8::V8::ShutdownPlatform();
|
|
|
|
delete platform;
|
2016-06-29 07:39:45 +00:00
|
|
|
delete create_params.array_buffer_allocator;
|
2014-03-24 14:43:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|