From: sgjesse@chromium.org Date: Wed, 20 May 2009 20:28:33 +0000 (+0000) Subject: Disable compilation cache when debugger is active. X-Git-Tag: upstream/4.7.83~24046 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7a10634e90f560ebd57e1aa26e3159ca71919cd8;p=platform%2Fupstream%2Fv8.git Disable compilation cache when debugger is active. Added an option to control whether the compilation cache is enabled. Default value is true. BUG=343 Review URL: http://codereview.chromium.org/113625 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2021 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/compilation-cache.cc b/src/compilation-cache.cc index f9658e8..3ece42d 100644 --- a/src/compilation-cache.cc +++ b/src/compilation-cache.cc @@ -44,6 +44,12 @@ enum { }; +// Current enable state of the compilation cache. +static bool enabled = true; +static inline bool IsEnabled() { + return FLAG_compilation_cache && enabled; +} + // Keep separate tables for the different entry kinds. static Object* tables[NUMBER_OF_TABLE_ENTRIES] = { 0, }; @@ -138,6 +144,10 @@ Handle CompilationCache::LookupScript(Handle source, Handle name, int line_offset, int column_offset) { + if (!IsEnabled()) { + return Handle::null(); + } + // Use an int for the generation index, so value range propagation // in gcc 4.3+ won't assume it can only go up to LAST_ENTRY when in // fact it can go up to SCRIPT + NUMBER_OF_SCRIPT_GENERATIONS. @@ -185,6 +195,10 @@ Handle CompilationCache::LookupScript(Handle source, Handle CompilationCache::LookupEval(Handle source, Handle context, Entry entry) { + if (!IsEnabled()) { + return Handle::null(); + } + ASSERT(entry == EVAL_GLOBAL || entry == EVAL_CONTEXTUAL); Handle result = Lookup(source, context, entry); if (result.is_null()) { @@ -198,6 +212,10 @@ Handle CompilationCache::LookupEval(Handle source, Handle CompilationCache::LookupRegExp(Handle source, JSRegExp::Flags flags) { + if (!IsEnabled()) { + return Handle::null(); + } + Handle result = Lookup(source, flags); if (result.is_null()) { Counters::compilation_cache_misses.Increment(); @@ -210,6 +228,10 @@ Handle CompilationCache::LookupRegExp(Handle source, void CompilationCache::PutScript(Handle source, Handle boilerplate) { + if (!IsEnabled()) { + return; + } + HandleScope scope; ASSERT(boilerplate->IsBoilerplate()); Handle table = GetTable(SCRIPT); @@ -221,6 +243,10 @@ void CompilationCache::PutEval(Handle source, Handle context, Entry entry, Handle boilerplate) { + if (!IsEnabled()) { + return; + } + HandleScope scope; ASSERT(boilerplate->IsBoilerplate()); Handle table = GetTable(entry); @@ -232,6 +258,10 @@ void CompilationCache::PutEval(Handle source, void CompilationCache::PutRegExp(Handle source, JSRegExp::Flags flags, Handle data) { + if (!IsEnabled()) { + return; + } + HandleScope scope; Handle table = GetTable(REGEXP); CALL_HEAP_FUNCTION_VOID(table->PutRegExp(*source, flags, *data)); @@ -261,4 +291,15 @@ void CompilationCache::MarkCompactPrologue() { } +void CompilationCache::Enable() { + enabled = true; +} + + +void CompilationCache::Disable() { + enabled = false; + Clear(); +} + + } } // namespace v8::internal diff --git a/src/compilation-cache.h b/src/compilation-cache.h index b10b561..099b4ad 100644 --- a/src/compilation-cache.h +++ b/src/compilation-cache.h @@ -95,6 +95,11 @@ class CompilationCache { // take place. This is used to retire entries from the cache to // avoid keeping them alive too long without using them. static void MarkCompactPrologue(); + + // Enable/disable compilation cache. Used by debugger to disable compilation + // cache during debugging to make sure new scripts are always compiled. + static void Enable(); + static void Disable(); }; diff --git a/src/debug.cc b/src/debug.cc index 224b100..2f73ef2 100644 --- a/src/debug.cc +++ b/src/debug.cc @@ -31,6 +31,7 @@ #include "arguments.h" #include "bootstrapper.h" #include "code-stubs.h" +#include "compilation-cache.h" #include "compiler.h" #include "debug.h" #include "execution.h" @@ -2172,6 +2173,13 @@ void Debugger::SetEventListener(Handle callback, if (callback->IsUndefined()) { UnloadDebugger(); } + + // Disable the compilation cache when the debugger is active. + if (IsDebuggerActive()) { + CompilationCache::Disable(); + } else { + CompilationCache::Enable(); + } } @@ -2189,6 +2197,13 @@ void Debugger::SetMessageHandler(v8::Debug::MessageHandler2 handler) { ProcessCommand(Vector::empty()); } } + + // Disable the compilation cache when the debugger is active. + if (IsDebuggerActive()) { + CompilationCache::Disable(); + } else { + CompilationCache::Enable(); + } } diff --git a/src/flag-definitions.h b/src/flag-definitions.h index db49453..5a4a3c8 100644 --- a/src/flag-definitions.h +++ b/src/flag-definitions.h @@ -133,6 +133,9 @@ DEFINE_bool(strict, false, "strict error checking") DEFINE_int(min_preparse_length, 1024, "Minimum length for automatic enable preparsing") +// compilation-cache.cc +DEFINE_bool(compilation_cache, true, "enable compilation cache") + // debug.cc DEFINE_bool(remote_debugging, false, "enable remote debugging") DEFINE_bool(trace_debug_json, false, "trace debugging JSON request/response") diff --git a/test/cctest/test-debug.cc b/test/cctest/test-debug.cc index a075113..edd8506 100644 --- a/test/cctest/test-debug.cc +++ b/test/cctest/test-debug.cc @@ -1679,11 +1679,6 @@ TEST(ScriptBreakPointIgnoreCount) { } CHECK_EQ(5, break_point_hit_count); - // BUG(343): It should not really be necessary to clear the - // compilation cache here, but right now the debugger relies on the - // script being recompiled, not just fetched from the cache. - i::CompilationCache::Clear(); - // Reload the script and get f again checking that the ignore survives. v8::Script::Compile(script, &origin)->Run(); f = v8::Local::Cast(env->Global()->Get(v8::String::New("f"))); @@ -4592,7 +4587,6 @@ TEST(ScriptNameAndData) { v8::Handle script1 = v8::Script::Compile(script, &origin1); script1->SetData(v8::String::New("data")); script1->Run(); - v8::Script::Compile(script, &origin1)->Run(); v8::Local f; f = v8::Local::Cast(env->Global()->Get(v8::String::New("f"))); @@ -4601,6 +4595,15 @@ TEST(ScriptNameAndData) { CHECK_EQ("name", last_script_name_hit); CHECK_EQ("data", last_script_data_hit); + // Compile the same script again without setting data. As the compilation + // cache is disabled when debugging expect the data to be missing. + v8::Script::Compile(script, &origin1)->Run(); + f = v8::Local::Cast(env->Global()->Get(v8::String::New("f"))); + f->Call(env->Global(), 0, NULL); + CHECK_EQ(2, break_point_hit_count); + CHECK_EQ("name", last_script_name_hit); + CHECK_EQ("", last_script_data_hit); // Undefined results in empty string. + v8::Local data_obj_source = v8::String::New( "({ a: 'abc',\n" " b: 123,\n" @@ -4613,7 +4616,7 @@ TEST(ScriptNameAndData) { script2->SetData(data_obj); f = v8::Local::Cast(env->Global()->Get(v8::String::New("f"))); f->Call(env->Global(), 0, NULL); - CHECK_EQ(2, break_point_hit_count); + CHECK_EQ(3, break_point_hit_count); CHECK_EQ("new name", last_script_name_hit); CHECK_EQ("abc 123", last_script_data_hit); }