Commit 22f2ef8f authored by Mythri's avatar Mythri Committed by Commit Bot

Add full code cache option to d8 shell.

Adds --cache=full-code-cache option to the d8 shell. Also cleanup
d8.cc to not use ProduceCodeCache and ProduceFullCodeCache options
from d8.

Bug: v8:7302
Change-Id: Ie2c25d6b1d85588f70b000ba72d6d6b19ecb61b6
Reviewed-on: https://chromium-review.googlesource.com/867033Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Mythri Alle <mythria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50614}
parent 7f6355cf
...@@ -621,7 +621,8 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source, ...@@ -621,7 +621,8 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source,
Local<Context> context(isolate->GetCurrentContext()); Local<Context> context(isolate->GetCurrentContext());
ScriptOrigin origin(name); ScriptOrigin origin(name);
if (options.compile_options == ScriptCompiler::kConsumeCodeCache) { if (options.compile_options == ScriptCompiler::kConsumeCodeCache ||
options.compile_options == ScriptCompiler::kConsumeParserCache) {
ScriptCompiler::CachedData* cached_code = ScriptCompiler::CachedData* cached_code =
LookupCodeCache(isolate, source); LookupCodeCache(isolate, source);
if (cached_code != nullptr) { if (cached_code != nullptr) {
...@@ -653,13 +654,9 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source, ...@@ -653,13 +654,9 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source,
context, background_compile_thread.streamed_source(), source, origin); context, background_compile_thread.streamed_source(), source, origin);
} else { } else {
ScriptCompiler::Source script_source(source, origin); ScriptCompiler::Source script_source(source, origin);
ScriptCompiler::CompileOptions compile_options = maybe_script = ScriptCompiler::Compile(context, &script_source,
options.cache_code_after_execute ? ScriptCompiler::kNoCompileOptions options.compile_options);
: options.compile_options; if (options.compile_options == ScriptCompiler::kProduceParserCache) {
maybe_script =
ScriptCompiler::Compile(context, &script_source, compile_options);
if (compile_options == ScriptCompiler::kProduceCodeCache ||
compile_options == ScriptCompiler::kProduceParserCache) {
StoreInCodeCache(isolate, source, script_source.GetCachedData()); StoreInCodeCache(isolate, source, script_source.GetCachedData());
} }
} }
...@@ -671,9 +668,17 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source, ...@@ -671,9 +668,17 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source,
return false; return false;
} }
if (options.code_cache_options ==
ShellOptions::CodeCacheOptions::kProduceCache) {
// Serialize and store it in memory for the next execution.
ScriptCompiler::CachedData* cached_data =
ScriptCompiler::CreateCodeCache(script->GetUnboundScript(), source);
StoreInCodeCache(isolate, source, cached_data);
delete cached_data;
}
maybe_result = script->Run(realm); maybe_result = script->Run(realm);
if (options.compile_options == ScriptCompiler::kProduceCodeCache && if (options.code_cache_options ==
options.cache_code_after_execute) { ShellOptions::CodeCacheOptions::kProduceCacheAfterExecute) {
// Serialize and store it in memory for the next execution. // Serialize and store it in memory for the next execution.
ScriptCompiler::CachedData* cached_data = ScriptCompiler::CachedData* cached_data =
ScriptCompiler::CreateCodeCache(script->GetUnboundScript(), source); ScriptCompiler::CreateCodeCache(script->GetUnboundScript(), source);
...@@ -2844,14 +2849,23 @@ bool Shell::SetOptions(int argc, char* argv[]) { ...@@ -2844,14 +2849,23 @@ bool Shell::SetOptions(int argc, char* argv[]) {
strncmp(argv[i], "--cache=", 8) == 0) { strncmp(argv[i], "--cache=", 8) == 0) {
const char* value = argv[i] + 7; const char* value = argv[i] + 7;
if (!*value || strncmp(value, "=code", 6) == 0) { if (!*value || strncmp(value, "=code", 6) == 0) {
options.compile_options = v8::ScriptCompiler::kProduceCodeCache; options.compile_options = v8::ScriptCompiler::kNoCompileOptions;
options.code_cache_options =
ShellOptions::CodeCacheOptions::kProduceCache;
} else if (strncmp(value, "=parse", 7) == 0) { } else if (strncmp(value, "=parse", 7) == 0) {
options.compile_options = v8::ScriptCompiler::kProduceParserCache; options.compile_options = v8::ScriptCompiler::kProduceParserCache;
} else if (strncmp(value, "=none", 6) == 0) { } else if (strncmp(value, "=none", 6) == 0) {
options.compile_options = v8::ScriptCompiler::kNoCompileOptions; options.compile_options = v8::ScriptCompiler::kNoCompileOptions;
} else if (strncmp(value, "=after-execute", 10) == 0) { options.code_cache_options =
options.compile_options = v8::ScriptCompiler::kProduceCodeCache; ShellOptions::CodeCacheOptions::kNoProduceCache;
options.cache_code_after_execute = true; } else if (strncmp(value, "=after-execute", 15) == 0) {
options.compile_options = v8::ScriptCompiler::kNoCompileOptions;
options.code_cache_options =
ShellOptions::CodeCacheOptions::kProduceCacheAfterExecute;
} else if (strncmp(value, "=full-code-cache", 17) == 0) {
options.compile_options = v8::ScriptCompiler::kEagerCompile;
options.code_cache_options =
ShellOptions::CodeCacheOptions::kProduceCache;
} else { } else {
printf("Unknown option to --cache.\n"); printf("Unknown option to --cache.\n");
return false; return false;
...@@ -3401,24 +3415,20 @@ int Shell::Main(int argc, char* argv[]) { ...@@ -3401,24 +3415,20 @@ int Shell::Main(int argc, char* argv[]) {
bool last_run = i == options.stress_runs - 1; bool last_run = i == options.stress_runs - 1;
result = RunMain(isolate, argc, argv, last_run); result = RunMain(isolate, argc, argv, last_run);
} }
} else if (options.compile_options == } else if (options.code_cache_options !=
v8::ScriptCompiler::kProduceCodeCache || ShellOptions::CodeCacheOptions::kNoProduceCache) {
options.compile_options ==
v8::ScriptCompiler::kProduceParserCache) {
printf("============ Run: Produce code cache ============\n"); printf("============ Run: Produce code cache ============\n");
// First run to produce the cache // First run to produce the cache
result = RunMain(isolate, argc, argv, false); result = RunMain(isolate, argc, argv, false);
// Change the options to consume cache // Change the options to consume cache
if (options.compile_options == v8::ScriptCompiler::kProduceCodeCache) { if (options.compile_options == v8::ScriptCompiler::kProduceParserCache) {
options.compile_options = v8::ScriptCompiler::kConsumeCodeCache;
} else if (options.compile_options ==
v8::ScriptCompiler::kProduceParserCache) {
options.compile_options = v8::ScriptCompiler::kConsumeParserCache; options.compile_options = v8::ScriptCompiler::kConsumeParserCache;
} else { } else {
// We only expect ProduceCodeCache or ProduceParserCache here. DCHECK(options.compile_options == v8::ScriptCompiler::kEagerCompile ||
// compile_options cannot be NoCompileOptions. options.compile_options ==
UNREACHABLE(); v8::ScriptCompiler::kNoCompileOptions);
options.compile_options = v8::ScriptCompiler::kConsumeCodeCache;
} }
printf("============ Run: Consume code cache ============\n"); printf("============ Run: Consume code cache ============\n");
......
...@@ -288,6 +288,12 @@ class Worker { ...@@ -288,6 +288,12 @@ class Worker {
class ShellOptions { class ShellOptions {
public: public:
enum CodeCacheOptions {
kNoProduceCache,
kProduceCache,
kProduceCacheAfterExecute
};
ShellOptions() ShellOptions()
: script_executed(false), : script_executed(false),
send_idle_notification(false), send_idle_notification(false),
...@@ -304,7 +310,7 @@ class ShellOptions { ...@@ -304,7 +310,7 @@ class ShellOptions {
num_isolates(1), num_isolates(1),
compile_options(v8::ScriptCompiler::kNoCompileOptions), compile_options(v8::ScriptCompiler::kNoCompileOptions),
stress_background_compile(false), stress_background_compile(false),
cache_code_after_execute(false), code_cache_options(CodeCacheOptions::kNoProduceCache),
isolate_sources(nullptr), isolate_sources(nullptr),
icu_data_file(nullptr), icu_data_file(nullptr),
natives_blob(nullptr), natives_blob(nullptr),
...@@ -339,7 +345,7 @@ class ShellOptions { ...@@ -339,7 +345,7 @@ class ShellOptions {
int num_isolates; int num_isolates;
v8::ScriptCompiler::CompileOptions compile_options; v8::ScriptCompiler::CompileOptions compile_options;
bool stress_background_compile; bool stress_background_compile;
bool cache_code_after_execute; CodeCacheOptions code_cache_options;
SourceGroup* isolate_sources; SourceGroup* isolate_sources;
const char* icu_data_file; const char* icu_data_file;
const char* natives_blob; const char* natives_blob;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment