Reviewers: Vyacheslav Egorov,
Message:
PTAL.
Description:
Increase eval compilation cache hits.
This CL introduces two changes to the eval compilation cache. Firstly,
instead of checking for SharedFunctionInfo equivalence to ensure
equivalence of direct eval call sites we now check for Script and
scope start position equivalence.
Furthermore, we increase the cache hits by allowing to share global
eval code for direct and indirect call sites, e.g. in the case
var x = eval; x("12"); eval("12");
BUG=v8:1854
TEST=existing tests in mjsunit
Please review this at http://codereview.chromium.org/8879010/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/compilation-cache.h
M src/compilation-cache.cc
M src/objects.cc
Index: src/compilation-cache.cc
diff --git a/src/compilation-cache.cc b/src/compilation-cache.cc
index
82cc2231a36326a38191a95cf2c80fea3112fbff..db4ce5f2a493dbaf70a1cbf43e800742de2d4cdc
100644
--- a/src/compilation-cache.cc
+++ b/src/compilation-cache.cc
@@ -404,8 +404,9 @@ Handle<SharedFunctionInfo> CompilationCache::LookupEval(
Handle<SharedFunctionInfo> result;
if (is_global) {
+ ASSERT(context->IsGlobalContext());
result = eval_global_.Lookup(
- source, context, language_mode, scope_position);
+ source, context, language_mode, RelocInfo::kNoPosition);
} else {
ASSERT(scope_position != RelocInfo::kNoPosition);
result = eval_contextual_.Lookup(
@@ -446,7 +447,8 @@ void CompilationCache::PutEval(Handle<String> source,
HandleScope scope(isolate());
if (is_global) {
- eval_global_.Put(source, context, function_info, scope_position);
+ ASSERT(context->IsGlobalContext());
+ eval_global_.Put(source, context, function_info,
RelocInfo::kNoPosition);
} else {
ASSERT(scope_position != RelocInfo::kNoPosition);
eval_contextual_.Put(source, context, function_info, scope_position);
Index: src/compilation-cache.h
diff --git a/src/compilation-cache.h b/src/compilation-cache.h
index
31f290968068ceb0610c383417808f109e07be7f..4ea8f203a3454d6f63dc64f2e537613085bc58a8
100644
--- a/src/compilation-cache.h
+++ b/src/compilation-cache.h
@@ -128,14 +128,19 @@ class CompilationCacheScript : public
CompilationSubCache {
// considers the following pieces of information when checking for matching
// entries:
// 1. The source string.
-// 2. The shared function info of the calling function.
+// 2. The script of the calling function.
// 3. Whether the source should be compiled as strict code or as non-strict
// code.
// Note: Currently there are clients of CompileEval that always compile
// non-strict code even if the calling function is a strict mode
function.
// More specifically these are the CompileString, DebugEvaluate and
// DebugEvaluateGlobal runtime functions.
-// 4. The start position of the calling scope.
+// 4. The start position of the calling scope in the script source code.
+// Note: The script plus the start position of the calling scope
uniquely
+// determine the shape of the outer scope of the eval call.
+// Note: For eval calls in global context RelocInfo::kNoPosition is
always
+// used as the scope position to enable sharing between direct and
indirect
+// global eval calls.
class CompilationCacheEval: public CompilationSubCache {
public:
CompilationCacheEval(Isolate* isolate, int generations)
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index
5c8a8987054a7d0c2096599337e5ff8c26fddf7d..7d73c0727007e29678285a8b40f2f1d6de51f13f
100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -10308,7 +10308,7 @@ class StringSharedKey : public HashTableKey {
if (!other->IsFixedArray()) return false;
FixedArray* other_array = FixedArray::cast(other);
SharedFunctionInfo* shared =
SharedFunctionInfo::cast(other_array->get(0));
- if (shared != shared_) return false;
+ if (shared->script() != shared_->script()) return false;
int language_unchecked = Smi::cast(other_array->get(2))->value();
ASSERT(language_unchecked == CLASSIC_MODE ||
language_unchecked == STRICT_MODE ||
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev