2011-11-14 08:58:47 +00:00
|
|
|
// Copyright 2011 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-09-11 10:51:52 +00:00
|
|
|
|
2015-08-20 07:44:00 +00:00
|
|
|
#include "src/compilation-cache.h"
|
2008-09-11 10:51:52 +00:00
|
|
|
|
2015-08-20 07:44:00 +00:00
|
|
|
#include "src/counters.h"
|
|
|
|
#include "src/factory.h"
|
2016-06-30 09:26:30 +00:00
|
|
|
#include "src/globals.h"
|
2015-08-20 07:44:00 +00:00
|
|
|
#include "src/objects-inl.h"
|
2017-04-06 08:32:57 +00:00
|
|
|
#include "src/objects/compilation-cache-inl.h"
|
2017-04-25 13:32:18 +00:00
|
|
|
#include "src/visitors.h"
|
2008-09-11 10:51:52 +00:00
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-09-11 10:51:52 +00:00
|
|
|
|
2009-06-22 11:12:51 +00:00
|
|
|
// The number of generations for each sub cache.
|
|
|
|
static const int kRegExpGenerations = 2;
|
|
|
|
|
2009-10-12 12:42:20 +00:00
|
|
|
// Initial size of each compilation cache table allocated.
|
2009-06-22 11:12:51 +00:00
|
|
|
static const int kInitialCacheSize = 64;
|
|
|
|
|
2011-03-21 10:22:57 +00:00
|
|
|
CompilationCache::CompilationCache(Isolate* isolate)
|
|
|
|
: isolate_(isolate),
|
2017-02-06 10:18:05 +00:00
|
|
|
script_(isolate),
|
|
|
|
eval_global_(isolate),
|
|
|
|
eval_contextual_(isolate),
|
2011-03-21 10:22:57 +00:00
|
|
|
reg_exp_(isolate, kRegExpGenerations),
|
2011-06-29 14:56:08 +00:00
|
|
|
enabled_(true) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CompilationSubCache* subcaches[kSubCacheCount] =
|
|
|
|
{&script_, &eval_global_, &eval_contextual_, ®_exp_};
|
|
|
|
for (int i = 0; i < kSubCacheCount; ++i) {
|
|
|
|
subcaches_[i] = subcaches[i];
|
2010-03-04 11:27:28 +00:00
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
}
|
2011-03-18 19:41:05 +00:00
|
|
|
|
2011-06-29 14:56:08 +00:00
|
|
|
CompilationCache::~CompilationCache() {}
|
2009-05-20 20:28:33 +00:00
|
|
|
|
2009-06-22 11:12:51 +00:00
|
|
|
Handle<CompilationCacheTable> CompilationSubCache::GetTable(int generation) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(generation < generations_);
|
2008-09-11 10:51:52 +00:00
|
|
|
Handle<CompilationCacheTable> result;
|
2016-06-06 12:58:10 +00:00
|
|
|
if (tables_[generation]->IsUndefined(isolate())) {
|
2014-04-25 13:06:21 +00:00
|
|
|
result = CompilationCacheTable::New(isolate(), kInitialCacheSize);
|
2009-06-22 11:12:51 +00:00
|
|
|
tables_[generation] = *result;
|
2008-09-11 10:51:52 +00:00
|
|
|
} else {
|
2009-06-22 11:12:51 +00:00
|
|
|
CompilationCacheTable* table =
|
|
|
|
CompilationCacheTable::cast(tables_[generation]);
|
2011-03-21 10:22:57 +00:00
|
|
|
result = Handle<CompilationCacheTable>(table, isolate());
|
2008-09-11 10:51:52 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-06-22 11:12:51 +00:00
|
|
|
void CompilationSubCache::Age() {
|
2014-10-31 14:51:48 +00:00
|
|
|
// Don't directly age single-generation caches.
|
|
|
|
if (generations_ == 1) {
|
2016-06-06 12:58:10 +00:00
|
|
|
if (!tables_[0]->IsUndefined(isolate())) {
|
2014-10-31 14:51:48 +00:00
|
|
|
CompilationCacheTable::cast(tables_[0])->Age();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-22 11:12:51 +00:00
|
|
|
// Age the generations implicitly killing off the oldest.
|
|
|
|
for (int i = generations_ - 1; i > 0; i--) {
|
|
|
|
tables_[i] = tables_[i - 1];
|
2008-09-11 10:51:52 +00:00
|
|
|
}
|
2009-06-22 11:12:51 +00:00
|
|
|
|
|
|
|
// Set the first generation as unborn.
|
2011-03-21 10:22:57 +00:00
|
|
|
tables_[0] = isolate()->heap()->undefined_value();
|
2008-09-11 10:51:52 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 13:32:18 +00:00
|
|
|
void CompilationSubCache::Iterate(RootVisitor* v) {
|
|
|
|
v->VisitRootPointers(Root::kCompilationCache, &tables_[0],
|
|
|
|
&tables_[generations_]);
|
2009-06-22 11:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CompilationSubCache::Clear() {
|
2011-03-21 10:22:57 +00:00
|
|
|
MemsetPointer(tables_, isolate()->heap()->undefined_value(), generations_);
|
2009-02-24 13:11:53 +00:00
|
|
|
}
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
void CompilationSubCache::Remove(Handle<SharedFunctionInfo> function_info) {
|
|
|
|
// Probe the script generation tables. Make sure not to leak handles
|
|
|
|
// into the caller's handle scope.
|
2011-03-21 10:22:57 +00:00
|
|
|
{ HandleScope scope(isolate());
|
2010-12-07 11:31:57 +00:00
|
|
|
for (int generation = 0; generation < generations(); generation++) {
|
|
|
|
Handle<CompilationCacheTable> table = GetTable(generation);
|
|
|
|
table->Remove(*function_info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-06 10:18:05 +00:00
|
|
|
CompilationCacheScript::CompilationCacheScript(Isolate* isolate)
|
|
|
|
: CompilationSubCache(isolate, 1) {}
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2009-04-06 18:08:06 +00:00
|
|
|
// We only re-use a cached function for some script source code if the
|
|
|
|
// script originates from the same place. This is to avoid issues
|
|
|
|
// when reporting errors, etc.
|
2015-01-29 14:01:13 +00:00
|
|
|
bool CompilationCacheScript::HasOrigin(Handle<SharedFunctionInfo> function_info,
|
2017-10-04 22:48:12 +00:00
|
|
|
MaybeHandle<Object> maybe_name,
|
|
|
|
int line_offset, int column_offset,
|
2015-05-19 03:11:33 +00:00
|
|
|
ScriptOriginOptions resource_options) {
|
2009-04-06 18:08:06 +00:00
|
|
|
Handle<Script> script =
|
2011-03-21 10:22:57 +00:00
|
|
|
Handle<Script>(Script::cast(function_info->script()), isolate());
|
2009-04-06 18:08:06 +00:00
|
|
|
// If the script name isn't set, the boilerplate script should have
|
|
|
|
// an undefined name to have the same origin.
|
2017-10-04 22:48:12 +00:00
|
|
|
Handle<Object> name;
|
|
|
|
if (!maybe_name.ToHandle(&name)) {
|
2016-06-06 12:58:10 +00:00
|
|
|
return script->name()->IsUndefined(isolate());
|
2009-04-06 18:08:06 +00:00
|
|
|
}
|
|
|
|
// Do the fast bailout checks first.
|
2015-09-28 13:10:13 +00:00
|
|
|
if (line_offset != script->line_offset()) return false;
|
|
|
|
if (column_offset != script->column_offset()) return false;
|
2009-04-06 18:08:06 +00:00
|
|
|
// Check that both names are strings. If not, no match.
|
|
|
|
if (!name->IsString() || !script->name()->IsString()) return false;
|
2015-05-19 03:11:33 +00:00
|
|
|
// Are the origin_options same?
|
|
|
|
if (resource_options.Flags() != script->origin_options().Flags())
|
2015-01-29 14:01:13 +00:00
|
|
|
return false;
|
2009-04-06 18:08:06 +00:00
|
|
|
// Compare the two name strings for equality.
|
2014-04-11 07:27:25 +00:00
|
|
|
return String::Equals(Handle<String>::cast(name),
|
|
|
|
Handle<String>(String::cast(script->name())));
|
2009-04-06 18:08:06 +00:00
|
|
|
}
|
|
|
|
|
2009-05-15 06:45:50 +00:00
|
|
|
// TODO(245): Need to allow identical code from different contexts to
|
|
|
|
// be cached in the same script generation. Currently the first use
|
|
|
|
// will be cached, but subsequent code from different source / line
|
|
|
|
// won't.
|
2017-02-06 10:18:05 +00:00
|
|
|
InfoVectorPair CompilationCacheScript::Lookup(
|
2017-10-04 22:48:12 +00:00
|
|
|
Handle<String> source, MaybeHandle<Object> name, int line_offset,
|
2015-05-19 03:11:33 +00:00
|
|
|
int column_offset, ScriptOriginOptions resource_options,
|
|
|
|
Handle<Context> context, LanguageMode language_mode) {
|
2017-02-06 10:18:05 +00:00
|
|
|
InfoVectorPair result;
|
2009-05-15 06:45:50 +00:00
|
|
|
|
|
|
|
// Probe the script generation tables. Make sure not to leak handles
|
|
|
|
// into the caller's handle scope.
|
2011-03-21 10:22:57 +00:00
|
|
|
{ HandleScope scope(isolate());
|
2017-02-06 10:18:05 +00:00
|
|
|
const int generation = 0;
|
2017-10-18 09:06:55 +00:00
|
|
|
DCHECK_EQ(generations(), 1);
|
2017-02-06 10:18:05 +00:00
|
|
|
Handle<CompilationCacheTable> table = GetTable(generation);
|
|
|
|
InfoVectorPair probe = table->LookupScript(source, context, language_mode);
|
|
|
|
if (probe.has_shared()) {
|
|
|
|
Handle<SharedFunctionInfo> function_info(probe.shared(), isolate());
|
|
|
|
Handle<Cell> vector_handle;
|
|
|
|
if (probe.has_vector()) {
|
|
|
|
vector_handle = Handle<Cell>(probe.vector(), isolate());
|
|
|
|
}
|
|
|
|
// Break when we've found a suitable shared function info that
|
|
|
|
// matches the origin.
|
|
|
|
if (HasOrigin(function_info, name, line_offset, column_offset,
|
|
|
|
resource_options)) {
|
|
|
|
result = InfoVectorPair(*function_info,
|
|
|
|
probe.has_vector() ? *vector_handle : nullptr);
|
2009-05-15 06:45:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-22 07:30:25 +00:00
|
|
|
// Once outside the manacles of the handle scope, we need to recheck
|
2009-05-15 06:45:50 +00:00
|
|
|
// to see if we actually found a cached script. If so, we return a
|
|
|
|
// handle created in the caller's handle scope.
|
2017-02-06 10:18:05 +00:00
|
|
|
if (result.has_shared()) {
|
2017-03-30 14:50:41 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Since HasOrigin can allocate, we need to protect the SharedFunctionInfo
|
|
|
|
// and the FeedbackVector with handles during the call.
|
2017-02-06 10:18:05 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(result.shared(), isolate());
|
2017-03-30 14:50:41 +00:00
|
|
|
Handle<Cell> vector_handle;
|
|
|
|
if (result.has_vector()) {
|
|
|
|
vector_handle = Handle<Cell>(result.vector(), isolate());
|
|
|
|
}
|
2015-05-19 03:11:33 +00:00
|
|
|
DCHECK(
|
|
|
|
HasOrigin(shared, name, line_offset, column_offset, resource_options));
|
2017-03-30 14:50:41 +00:00
|
|
|
result =
|
|
|
|
InfoVectorPair(*shared, result.has_vector() ? *vector_handle : nullptr);
|
|
|
|
#endif
|
2011-03-21 10:22:57 +00:00
|
|
|
isolate()->counters()->compilation_cache_hits()->Increment();
|
2009-04-06 18:08:06 +00:00
|
|
|
} else {
|
2011-03-21 10:22:57 +00:00
|
|
|
isolate()->counters()->compilation_cache_misses()->Increment();
|
2009-04-06 18:08:06 +00:00
|
|
|
}
|
2017-02-06 10:18:05 +00:00
|
|
|
return result;
|
2008-09-11 10:51:52 +00:00
|
|
|
}
|
|
|
|
|
2017-02-06 10:18:05 +00:00
|
|
|
void CompilationCacheScript::Put(Handle<String> source, Handle<Context> context,
|
2015-02-12 16:29:42 +00:00
|
|
|
LanguageMode language_mode,
|
2017-02-06 10:18:05 +00:00
|
|
|
Handle<SharedFunctionInfo> function_info,
|
|
|
|
Handle<Cell> literals) {
|
2011-03-21 10:22:57 +00:00
|
|
|
HandleScope scope(isolate());
|
2014-04-08 12:33:08 +00:00
|
|
|
Handle<CompilationCacheTable> table = GetFirstTable();
|
2017-02-06 10:18:05 +00:00
|
|
|
SetFirstTable(CompilationCacheTable::PutScript(
|
|
|
|
table, source, context, language_mode, function_info, literals));
|
2009-06-22 11:12:51 +00:00
|
|
|
}
|
|
|
|
|
2017-02-06 10:18:05 +00:00
|
|
|
InfoVectorPair CompilationCacheEval::Lookup(
|
2014-10-28 10:00:37 +00:00
|
|
|
Handle<String> source, Handle<SharedFunctionInfo> outer_info,
|
Implement new Function.prototype.toString --harmony-function-tostring
For functions declared in source code, the .toString() representation
will be an excerpt of the source code.
* For functions declared with the "function" keyword, the excerpt
starts at the "function" or "async" keyword and ends at the final "}".
The previous behavior would start the excerpt at the "(" of the
parameter list, and prepend a canonical `"function " + name` or
similar, which would discard comments and formatting surrounding the
function's name. Anonymous functions declared as function expressions
no longer get the name "anonymous" in their toString representation.
* For methods, the excerpt starts at the "get", "set", "*" (for
generator methods), or property name, whichever comes first.
Previously, the toString representation for methods would use a
canonical prefix before the "(" of the parameter list. Note that any
"static" keyword is omitted.
* For arrow functions and class declarations, the excerpt is unchanged.
For functions created with the Function, GeneratorFunction, or
AsyncFunction constructors:
* The string separating the parameter text and body text is now
"\n) {\n", where previously it was "\n/*``*/) {\n" or ") {\n".
* At one point, newline normalization was required by the spec here,
but that was removed from the spec, and so this CL does not do it.
Included in this CL is a fix for CreateDynamicFunction parsing. ')'
and '`' characters in the parameter string are no longer disallowed,
and Function("a=function(", "}){") is no longer allowed.
BUG=v8:4958, v8:4230
Review-Url: https://codereview.chromium.org/2156303002
Cr-Commit-Position: refs/heads/master@{#43262}
2017-02-16 20:19:24 +00:00
|
|
|
Handle<Context> native_context, LanguageMode language_mode, int position) {
|
2014-04-09 09:01:38 +00:00
|
|
|
HandleScope scope(isolate());
|
2009-06-22 11:12:51 +00:00
|
|
|
// Make sure not to leak the table into the surrounding handle
|
|
|
|
// scope. Otherwise, we risk keeping old tables around even after
|
|
|
|
// having cleared the cache.
|
2017-02-06 10:18:05 +00:00
|
|
|
InfoVectorPair result;
|
|
|
|
const int generation = 0;
|
2017-10-18 09:06:55 +00:00
|
|
|
DCHECK_EQ(generations(), 1);
|
2017-02-06 10:18:05 +00:00
|
|
|
Handle<CompilationCacheTable> table = GetTable(generation);
|
|
|
|
result = table->LookupEval(source, outer_info, native_context, language_mode,
|
Implement new Function.prototype.toString --harmony-function-tostring
For functions declared in source code, the .toString() representation
will be an excerpt of the source code.
* For functions declared with the "function" keyword, the excerpt
starts at the "function" or "async" keyword and ends at the final "}".
The previous behavior would start the excerpt at the "(" of the
parameter list, and prepend a canonical `"function " + name` or
similar, which would discard comments and formatting surrounding the
function's name. Anonymous functions declared as function expressions
no longer get the name "anonymous" in their toString representation.
* For methods, the excerpt starts at the "get", "set", "*" (for
generator methods), or property name, whichever comes first.
Previously, the toString representation for methods would use a
canonical prefix before the "(" of the parameter list. Note that any
"static" keyword is omitted.
* For arrow functions and class declarations, the excerpt is unchanged.
For functions created with the Function, GeneratorFunction, or
AsyncFunction constructors:
* The string separating the parameter text and body text is now
"\n) {\n", where previously it was "\n/*``*/) {\n" or ") {\n".
* At one point, newline normalization was required by the spec here,
but that was removed from the spec, and so this CL does not do it.
Included in this CL is a fix for CreateDynamicFunction parsing. ')'
and '`' characters in the parameter string are no longer disallowed,
and Function("a=function(", "}){") is no longer allowed.
BUG=v8:4958, v8:4230
Review-Url: https://codereview.chromium.org/2156303002
Cr-Commit-Position: refs/heads/master@{#43262}
2017-02-16 20:19:24 +00:00
|
|
|
position);
|
2017-02-06 10:18:05 +00:00
|
|
|
if (result.has_shared()) {
|
2011-03-21 10:22:57 +00:00
|
|
|
isolate()->counters()->compilation_cache_hits()->Increment();
|
2009-06-22 11:12:51 +00:00
|
|
|
} else {
|
2011-03-21 10:22:57 +00:00
|
|
|
isolate()->counters()->compilation_cache_misses()->Increment();
|
2009-06-22 11:12:51 +00:00
|
|
|
}
|
2017-02-06 10:18:05 +00:00
|
|
|
return result;
|
2009-06-22 11:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CompilationCacheEval::Put(Handle<String> source,
|
2014-10-28 10:00:37 +00:00
|
|
|
Handle<SharedFunctionInfo> outer_info,
|
2011-11-14 08:58:47 +00:00
|
|
|
Handle<SharedFunctionInfo> function_info,
|
2017-02-06 10:18:05 +00:00
|
|
|
Handle<Context> native_context,
|
Implement new Function.prototype.toString --harmony-function-tostring
For functions declared in source code, the .toString() representation
will be an excerpt of the source code.
* For functions declared with the "function" keyword, the excerpt
starts at the "function" or "async" keyword and ends at the final "}".
The previous behavior would start the excerpt at the "(" of the
parameter list, and prepend a canonical `"function " + name` or
similar, which would discard comments and formatting surrounding the
function's name. Anonymous functions declared as function expressions
no longer get the name "anonymous" in their toString representation.
* For methods, the excerpt starts at the "get", "set", "*" (for
generator methods), or property name, whichever comes first.
Previously, the toString representation for methods would use a
canonical prefix before the "(" of the parameter list. Note that any
"static" keyword is omitted.
* For arrow functions and class declarations, the excerpt is unchanged.
For functions created with the Function, GeneratorFunction, or
AsyncFunction constructors:
* The string separating the parameter text and body text is now
"\n) {\n", where previously it was "\n/*``*/) {\n" or ") {\n".
* At one point, newline normalization was required by the spec here,
but that was removed from the spec, and so this CL does not do it.
Included in this CL is a fix for CreateDynamicFunction parsing. ')'
and '`' characters in the parameter string are no longer disallowed,
and Function("a=function(", "}){") is no longer allowed.
BUG=v8:4958, v8:4230
Review-Url: https://codereview.chromium.org/2156303002
Cr-Commit-Position: refs/heads/master@{#43262}
2017-02-16 20:19:24 +00:00
|
|
|
Handle<Cell> literals, int position) {
|
2011-03-21 10:22:57 +00:00
|
|
|
HandleScope scope(isolate());
|
2014-04-08 12:33:08 +00:00
|
|
|
Handle<CompilationCacheTable> table = GetFirstTable();
|
2017-02-06 10:18:05 +00:00
|
|
|
table =
|
|
|
|
CompilationCacheTable::PutEval(table, source, outer_info, function_info,
|
Implement new Function.prototype.toString --harmony-function-tostring
For functions declared in source code, the .toString() representation
will be an excerpt of the source code.
* For functions declared with the "function" keyword, the excerpt
starts at the "function" or "async" keyword and ends at the final "}".
The previous behavior would start the excerpt at the "(" of the
parameter list, and prepend a canonical `"function " + name` or
similar, which would discard comments and formatting surrounding the
function's name. Anonymous functions declared as function expressions
no longer get the name "anonymous" in their toString representation.
* For methods, the excerpt starts at the "get", "set", "*" (for
generator methods), or property name, whichever comes first.
Previously, the toString representation for methods would use a
canonical prefix before the "(" of the parameter list. Note that any
"static" keyword is omitted.
* For arrow functions and class declarations, the excerpt is unchanged.
For functions created with the Function, GeneratorFunction, or
AsyncFunction constructors:
* The string separating the parameter text and body text is now
"\n) {\n", where previously it was "\n/*``*/) {\n" or ") {\n".
* At one point, newline normalization was required by the spec here,
but that was removed from the spec, and so this CL does not do it.
Included in this CL is a fix for CreateDynamicFunction parsing. ')'
and '`' characters in the parameter string are no longer disallowed,
and Function("a=function(", "}){") is no longer allowed.
BUG=v8:4958, v8:4230
Review-Url: https://codereview.chromium.org/2156303002
Cr-Commit-Position: refs/heads/master@{#43262}
2017-02-16 20:19:24 +00:00
|
|
|
native_context, literals, position);
|
2014-04-08 12:33:08 +00:00
|
|
|
SetFirstTable(table);
|
2009-06-22 11:12:51 +00:00
|
|
|
}
|
|
|
|
|
2014-04-08 12:33:08 +00:00
|
|
|
MaybeHandle<FixedArray> CompilationCacheRegExp::Lookup(
|
|
|
|
Handle<String> source,
|
|
|
|
JSRegExp::Flags flags) {
|
2014-04-09 09:01:38 +00:00
|
|
|
HandleScope scope(isolate());
|
2009-06-22 11:12:51 +00:00
|
|
|
// Make sure not to leak the table into the surrounding handle
|
|
|
|
// scope. Otherwise, we risk keeping old tables around even after
|
|
|
|
// having cleared the cache.
|
2014-04-08 12:33:08 +00:00
|
|
|
Handle<Object> result = isolate()->factory()->undefined_value();
|
2009-06-22 11:12:51 +00:00
|
|
|
int generation;
|
2014-04-09 09:01:38 +00:00
|
|
|
for (generation = 0; generation < generations(); generation++) {
|
|
|
|
Handle<CompilationCacheTable> table = GetTable(generation);
|
|
|
|
result = table->LookupRegExp(source, flags);
|
|
|
|
if (result->IsFixedArray()) break;
|
2009-06-22 11:12:51 +00:00
|
|
|
}
|
|
|
|
if (result->IsFixedArray()) {
|
2014-04-08 12:33:08 +00:00
|
|
|
Handle<FixedArray> data = Handle<FixedArray>::cast(result);
|
2009-06-22 11:12:51 +00:00
|
|
|
if (generation != 0) {
|
|
|
|
Put(source, flags, data);
|
|
|
|
}
|
2011-03-21 10:22:57 +00:00
|
|
|
isolate()->counters()->compilation_cache_hits()->Increment();
|
2014-04-09 09:01:38 +00:00
|
|
|
return scope.CloseAndEscape(data);
|
2009-06-22 11:12:51 +00:00
|
|
|
} else {
|
2011-03-21 10:22:57 +00:00
|
|
|
isolate()->counters()->compilation_cache_misses()->Increment();
|
2014-04-08 12:33:08 +00:00
|
|
|
return MaybeHandle<FixedArray>();
|
2009-06-22 11:12:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompilationCacheRegExp::Put(Handle<String> source,
|
|
|
|
JSRegExp::Flags flags,
|
|
|
|
Handle<FixedArray> data) {
|
2011-03-21 10:22:57 +00:00
|
|
|
HandleScope scope(isolate());
|
2014-04-08 12:33:08 +00:00
|
|
|
Handle<CompilationCacheTable> table = GetFirstTable();
|
|
|
|
SetFirstTable(CompilationCacheTable::PutRegExp(table, source, flags, data));
|
2009-06-22 11:12:51 +00:00
|
|
|
}
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
void CompilationCache::Remove(Handle<SharedFunctionInfo> function_info) {
|
|
|
|
if (!IsEnabled()) return;
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
eval_global_.Remove(function_info);
|
|
|
|
eval_contextual_.Remove(function_info);
|
|
|
|
script_.Remove(function_info);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2017-02-06 10:18:05 +00:00
|
|
|
InfoVectorPair CompilationCache::LookupScript(
|
2017-10-04 22:48:12 +00:00
|
|
|
Handle<String> source, MaybeHandle<Object> name, int line_offset,
|
2015-05-19 03:11:33 +00:00
|
|
|
int column_offset, ScriptOriginOptions resource_options,
|
|
|
|
Handle<Context> context, LanguageMode language_mode) {
|
2017-02-06 10:18:05 +00:00
|
|
|
InfoVectorPair empty_result;
|
|
|
|
if (!IsEnabled()) return empty_result;
|
2009-06-22 11:12:51 +00:00
|
|
|
|
2014-04-08 12:33:08 +00:00
|
|
|
return script_.Lookup(source, name, line_offset, column_offset,
|
2015-05-19 03:11:33 +00:00
|
|
|
resource_options, context, language_mode);
|
2009-06-22 11:12:51 +00:00
|
|
|
}
|
|
|
|
|
2017-02-06 10:18:05 +00:00
|
|
|
InfoVectorPair CompilationCache::LookupEval(
|
2014-10-28 10:00:37 +00:00
|
|
|
Handle<String> source, Handle<SharedFunctionInfo> outer_info,
|
Implement new Function.prototype.toString --harmony-function-tostring
For functions declared in source code, the .toString() representation
will be an excerpt of the source code.
* For functions declared with the "function" keyword, the excerpt
starts at the "function" or "async" keyword and ends at the final "}".
The previous behavior would start the excerpt at the "(" of the
parameter list, and prepend a canonical `"function " + name` or
similar, which would discard comments and formatting surrounding the
function's name. Anonymous functions declared as function expressions
no longer get the name "anonymous" in their toString representation.
* For methods, the excerpt starts at the "get", "set", "*" (for
generator methods), or property name, whichever comes first.
Previously, the toString representation for methods would use a
canonical prefix before the "(" of the parameter list. Note that any
"static" keyword is omitted.
* For arrow functions and class declarations, the excerpt is unchanged.
For functions created with the Function, GeneratorFunction, or
AsyncFunction constructors:
* The string separating the parameter text and body text is now
"\n) {\n", where previously it was "\n/*``*/) {\n" or ") {\n".
* At one point, newline normalization was required by the spec here,
but that was removed from the spec, and so this CL does not do it.
Included in this CL is a fix for CreateDynamicFunction parsing. ')'
and '`' characters in the parameter string are no longer disallowed,
and Function("a=function(", "}){") is no longer allowed.
BUG=v8:4958, v8:4230
Review-Url: https://codereview.chromium.org/2156303002
Cr-Commit-Position: refs/heads/master@{#43262}
2017-02-16 20:19:24 +00:00
|
|
|
Handle<Context> context, LanguageMode language_mode, int position) {
|
2017-02-06 10:18:05 +00:00
|
|
|
InfoVectorPair result;
|
|
|
|
if (!IsEnabled()) return result;
|
2009-05-20 20:28:33 +00:00
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
if (context->IsNativeContext()) {
|
2017-02-06 10:18:05 +00:00
|
|
|
result = eval_global_.Lookup(source, outer_info, context, language_mode,
|
Implement new Function.prototype.toString --harmony-function-tostring
For functions declared in source code, the .toString() representation
will be an excerpt of the source code.
* For functions declared with the "function" keyword, the excerpt
starts at the "function" or "async" keyword and ends at the final "}".
The previous behavior would start the excerpt at the "(" of the
parameter list, and prepend a canonical `"function " + name` or
similar, which would discard comments and formatting surrounding the
function's name. Anonymous functions declared as function expressions
no longer get the name "anonymous" in their toString representation.
* For methods, the excerpt starts at the "get", "set", "*" (for
generator methods), or property name, whichever comes first.
Previously, the toString representation for methods would use a
canonical prefix before the "(" of the parameter list. Note that any
"static" keyword is omitted.
* For arrow functions and class declarations, the excerpt is unchanged.
For functions created with the Function, GeneratorFunction, or
AsyncFunction constructors:
* The string separating the parameter text and body text is now
"\n) {\n", where previously it was "\n/*``*/) {\n" or ") {\n".
* At one point, newline normalization was required by the spec here,
but that was removed from the spec, and so this CL does not do it.
Included in this CL is a fix for CreateDynamicFunction parsing. ')'
and '`' characters in the parameter string are no longer disallowed,
and Function("a=function(", "}){") is no longer allowed.
BUG=v8:4958, v8:4230
Review-Url: https://codereview.chromium.org/2156303002
Cr-Commit-Position: refs/heads/master@{#43262}
2017-02-16 20:19:24 +00:00
|
|
|
position);
|
2008-09-11 10:51:52 +00:00
|
|
|
} else {
|
2017-10-18 09:06:55 +00:00
|
|
|
DCHECK_NE(position, kNoSourcePosition);
|
2017-02-06 10:18:05 +00:00
|
|
|
Handle<Context> native_context(context->native_context(), isolate());
|
|
|
|
result = eval_contextual_.Lookup(source, outer_info, native_context,
|
Implement new Function.prototype.toString --harmony-function-tostring
For functions declared in source code, the .toString() representation
will be an excerpt of the source code.
* For functions declared with the "function" keyword, the excerpt
starts at the "function" or "async" keyword and ends at the final "}".
The previous behavior would start the excerpt at the "(" of the
parameter list, and prepend a canonical `"function " + name` or
similar, which would discard comments and formatting surrounding the
function's name. Anonymous functions declared as function expressions
no longer get the name "anonymous" in their toString representation.
* For methods, the excerpt starts at the "get", "set", "*" (for
generator methods), or property name, whichever comes first.
Previously, the toString representation for methods would use a
canonical prefix before the "(" of the parameter list. Note that any
"static" keyword is omitted.
* For arrow functions and class declarations, the excerpt is unchanged.
For functions created with the Function, GeneratorFunction, or
AsyncFunction constructors:
* The string separating the parameter text and body text is now
"\n) {\n", where previously it was "\n/*``*/) {\n" or ") {\n".
* At one point, newline normalization was required by the spec here,
but that was removed from the spec, and so this CL does not do it.
Included in this CL is a fix for CreateDynamicFunction parsing. ')'
and '`' characters in the parameter string are no longer disallowed,
and Function("a=function(", "}){") is no longer allowed.
BUG=v8:4958, v8:4230
Review-Url: https://codereview.chromium.org/2156303002
Cr-Commit-Position: refs/heads/master@{#43262}
2017-02-16 20:19:24 +00:00
|
|
|
language_mode, position);
|
2008-09-11 10:51:52 +00:00
|
|
|
}
|
2017-02-06 10:18:05 +00:00
|
|
|
|
2008-09-11 10:51:52 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-04-08 12:33:08 +00:00
|
|
|
MaybeHandle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source,
|
2014-09-19 07:36:05 +00:00
|
|
|
JSRegExp::Flags flags) {
|
2014-04-08 12:33:08 +00:00
|
|
|
if (!IsEnabled()) return MaybeHandle<FixedArray>();
|
2009-05-20 20:28:33 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
return reg_exp_.Lookup(source, flags);
|
2008-09-11 10:51:52 +00:00
|
|
|
}
|
|
|
|
|
2017-02-06 10:18:05 +00:00
|
|
|
void CompilationCache::PutScript(Handle<String> source, Handle<Context> context,
|
2015-02-12 16:29:42 +00:00
|
|
|
LanguageMode language_mode,
|
2017-02-06 10:18:05 +00:00
|
|
|
Handle<SharedFunctionInfo> function_info,
|
|
|
|
Handle<Cell> literals) {
|
2013-12-23 14:30:35 +00:00
|
|
|
if (!IsEnabled()) return;
|
2009-05-20 20:28:33 +00:00
|
|
|
|
2017-02-06 10:18:05 +00:00
|
|
|
script_.Put(source, context, language_mode, function_info, literals);
|
2009-03-03 13:35:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CompilationCache::PutEval(Handle<String> source,
|
2014-10-28 10:00:37 +00:00
|
|
|
Handle<SharedFunctionInfo> outer_info,
|
2009-03-03 13:35:05 +00:00
|
|
|
Handle<Context> context,
|
2011-11-14 08:58:47 +00:00
|
|
|
Handle<SharedFunctionInfo> function_info,
|
Implement new Function.prototype.toString --harmony-function-tostring
For functions declared in source code, the .toString() representation
will be an excerpt of the source code.
* For functions declared with the "function" keyword, the excerpt
starts at the "function" or "async" keyword and ends at the final "}".
The previous behavior would start the excerpt at the "(" of the
parameter list, and prepend a canonical `"function " + name` or
similar, which would discard comments and formatting surrounding the
function's name. Anonymous functions declared as function expressions
no longer get the name "anonymous" in their toString representation.
* For methods, the excerpt starts at the "get", "set", "*" (for
generator methods), or property name, whichever comes first.
Previously, the toString representation for methods would use a
canonical prefix before the "(" of the parameter list. Note that any
"static" keyword is omitted.
* For arrow functions and class declarations, the excerpt is unchanged.
For functions created with the Function, GeneratorFunction, or
AsyncFunction constructors:
* The string separating the parameter text and body text is now
"\n) {\n", where previously it was "\n/*``*/) {\n" or ") {\n".
* At one point, newline normalization was required by the spec here,
but that was removed from the spec, and so this CL does not do it.
Included in this CL is a fix for CreateDynamicFunction parsing. ')'
and '`' characters in the parameter string are no longer disallowed,
and Function("a=function(", "}){") is no longer allowed.
BUG=v8:4958, v8:4230
Review-Url: https://codereview.chromium.org/2156303002
Cr-Commit-Position: refs/heads/master@{#43262}
2017-02-16 20:19:24 +00:00
|
|
|
Handle<Cell> literals, int position) {
|
2013-12-23 14:30:35 +00:00
|
|
|
if (!IsEnabled()) return;
|
2009-05-20 20:28:33 +00:00
|
|
|
|
2011-03-21 10:22:57 +00:00
|
|
|
HandleScope scope(isolate());
|
2013-12-23 14:30:35 +00:00
|
|
|
if (context->IsNativeContext()) {
|
2017-02-06 10:18:05 +00:00
|
|
|
eval_global_.Put(source, outer_info, function_info, context, literals,
|
Implement new Function.prototype.toString --harmony-function-tostring
For functions declared in source code, the .toString() representation
will be an excerpt of the source code.
* For functions declared with the "function" keyword, the excerpt
starts at the "function" or "async" keyword and ends at the final "}".
The previous behavior would start the excerpt at the "(" of the
parameter list, and prepend a canonical `"function " + name` or
similar, which would discard comments and formatting surrounding the
function's name. Anonymous functions declared as function expressions
no longer get the name "anonymous" in their toString representation.
* For methods, the excerpt starts at the "get", "set", "*" (for
generator methods), or property name, whichever comes first.
Previously, the toString representation for methods would use a
canonical prefix before the "(" of the parameter list. Note that any
"static" keyword is omitted.
* For arrow functions and class declarations, the excerpt is unchanged.
For functions created with the Function, GeneratorFunction, or
AsyncFunction constructors:
* The string separating the parameter text and body text is now
"\n) {\n", where previously it was "\n/*``*/) {\n" or ") {\n".
* At one point, newline normalization was required by the spec here,
but that was removed from the spec, and so this CL does not do it.
Included in this CL is a fix for CreateDynamicFunction parsing. ')'
and '`' characters in the parameter string are no longer disallowed,
and Function("a=function(", "}){") is no longer allowed.
BUG=v8:4958, v8:4230
Review-Url: https://codereview.chromium.org/2156303002
Cr-Commit-Position: refs/heads/master@{#43262}
2017-02-16 20:19:24 +00:00
|
|
|
position);
|
2009-06-22 11:12:51 +00:00
|
|
|
} else {
|
2017-10-18 09:06:55 +00:00
|
|
|
DCHECK_NE(position, kNoSourcePosition);
|
2017-02-06 10:18:05 +00:00
|
|
|
Handle<Context> native_context(context->native_context(), isolate());
|
|
|
|
eval_contextual_.Put(source, outer_info, function_info, native_context,
|
Implement new Function.prototype.toString --harmony-function-tostring
For functions declared in source code, the .toString() representation
will be an excerpt of the source code.
* For functions declared with the "function" keyword, the excerpt
starts at the "function" or "async" keyword and ends at the final "}".
The previous behavior would start the excerpt at the "(" of the
parameter list, and prepend a canonical `"function " + name` or
similar, which would discard comments and formatting surrounding the
function's name. Anonymous functions declared as function expressions
no longer get the name "anonymous" in their toString representation.
* For methods, the excerpt starts at the "get", "set", "*" (for
generator methods), or property name, whichever comes first.
Previously, the toString representation for methods would use a
canonical prefix before the "(" of the parameter list. Note that any
"static" keyword is omitted.
* For arrow functions and class declarations, the excerpt is unchanged.
For functions created with the Function, GeneratorFunction, or
AsyncFunction constructors:
* The string separating the parameter text and body text is now
"\n) {\n", where previously it was "\n/*``*/) {\n" or ") {\n".
* At one point, newline normalization was required by the spec here,
but that was removed from the spec, and so this CL does not do it.
Included in this CL is a fix for CreateDynamicFunction parsing. ')'
and '`' characters in the parameter string are no longer disallowed,
and Function("a=function(", "}){") is no longer allowed.
BUG=v8:4958, v8:4230
Review-Url: https://codereview.chromium.org/2156303002
Cr-Commit-Position: refs/heads/master@{#43262}
2017-02-16 20:19:24 +00:00
|
|
|
literals, position);
|
2009-06-22 11:12:51 +00:00
|
|
|
}
|
2009-02-24 13:11:53 +00:00
|
|
|
}
|
|
|
|
|
2008-10-24 08:40:02 +00:00
|
|
|
void CompilationCache::PutRegExp(Handle<String> source,
|
|
|
|
JSRegExp::Flags flags,
|
|
|
|
Handle<FixedArray> data) {
|
2009-05-20 20:28:33 +00:00
|
|
|
if (!IsEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
reg_exp_.Put(source, flags, data);
|
2008-10-24 08:40:02 +00:00
|
|
|
}
|
|
|
|
|
2008-09-11 10:51:52 +00:00
|
|
|
void CompilationCache::Clear() {
|
2009-06-22 11:12:51 +00:00
|
|
|
for (int i = 0; i < kSubCacheCount; i++) {
|
2011-03-18 20:35:07 +00:00
|
|
|
subcaches_[i]->Clear();
|
2008-09-11 10:51:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-25 13:32:18 +00:00
|
|
|
void CompilationCache::Iterate(RootVisitor* v) {
|
2010-08-17 11:44:01 +00:00
|
|
|
for (int i = 0; i < kSubCacheCount; i++) {
|
2011-03-18 20:35:07 +00:00
|
|
|
subcaches_[i]->Iterate(v);
|
2010-08-17 11:44:01 +00:00
|
|
|
}
|
2010-06-07 15:39:10 +00:00
|
|
|
}
|
|
|
|
|
2009-05-15 06:45:50 +00:00
|
|
|
void CompilationCache::MarkCompactPrologue() {
|
2009-06-22 11:12:51 +00:00
|
|
|
for (int i = 0; i < kSubCacheCount; i++) {
|
2011-03-18 20:35:07 +00:00
|
|
|
subcaches_[i]->Age();
|
2009-05-15 06:45:50 +00:00
|
|
|
}
|
2008-09-11 10:51:52 +00:00
|
|
|
}
|
|
|
|
|
2009-05-20 20:28:33 +00:00
|
|
|
void CompilationCache::Enable() {
|
2011-03-18 20:35:07 +00:00
|
|
|
enabled_ = true;
|
2009-05-20 20:28:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CompilationCache::Disable() {
|
2011-03-18 20:35:07 +00:00
|
|
|
enabled_ = false;
|
2009-05-20 20:28:33 +00:00
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
2015-06-01 22:46:54 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|