Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Unified Diff: src/compiler.cc

Issue 6793013: Cache optimized code on shared function info. Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/deoptimizer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler.cc
diff --git a/src/compiler.cc b/src/compiler.cc
index dea94fabdd0f45067555d78cc92faa9dff4e333c..b621d7c91e6dc454f2b9004580116bb0b96f3065 100755
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -584,6 +584,44 @@ Handle<SharedFunctionInfo> Compiler::CompileEval(Handle<String> source,
}
+static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared,
+ Handle<Context> global_context,
+ Handle<Code> code) {
+ ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION);
+ ASSERT(global_context->IsGlobalContext());
+
+ Object* value = shared->optimized_code_map();
+ Handle<FixedArray> new_map;
+ if (value->IsSmi()) {
+ // No optimized code map.
+ ASSERT_EQ(0, Smi::cast(value)->value());
+ new_map = FACTORY->NewFixedArray(2);
+ new_map->set(0, *global_context);
+ new_map->set(1, *code);
+ } else {
+ Handle<FixedArray> old_map(FixedArray::cast(value));
+ ASSERT_EQ(NULL, shared->SearchOptimizedCodeMap(*global_context));
+ int old_length = old_map->length();
+ int new_length = old_length + 2;
+ new_map = FACTORY->NewFixedArray(new_length);
+ for (int i = 0; i < old_length; i += 2) {
+ new_map->set(i, old_map->get(i));
+ new_map->set(i + 1, old_map->get(i + 1));
+ }
+ new_map->set(old_length, *global_context);
+ new_map->set(old_length + 1, *code);
+ }
+#ifdef DEBUG
+ for (int i = 0; i < new_map->length(); i += 2) {
+ ASSERT(new_map->get(i)->IsGlobalContext());
+ ASSERT(new_map->get(i + 1)->IsCode());
+ ASSERT(Code::cast(new_map->get(i + 1))->kind() == Code::OPTIMIZED_FUNCTION);
+ }
+#endif
+ shared->set_optimized_code_map(*new_map);
+}
+
+
bool Compiler::CompileLazy(CompilationInfo* info) {
CompilationZoneScope zone_scope(DELETE_ON_EXIT);
@@ -597,6 +635,18 @@ bool Compiler::CompileLazy(CompilationInfo* info) {
int compiled_size = shared->end_position() - shared->start_position();
isolate->counters()->total_compile_size()->Increment(compiled_size);
+ if (FLAG_cache_optimized_code
+ && info->IsOptimizing() && info->osr_ast_id() == -1) {
+ Handle<JSFunction> function = info->closure();
+ ASSERT(!function.is_null());
+ Handle<Context> global_context(function->context()->global_context());
+ Code* code = function->shared()->SearchOptimizedCodeMap(*global_context);
+ if (code != NULL) {
+ function->ReplaceCode(code);
+ return true;
+ }
+ }
+
// Generate the AST for the lazily compiled function.
if (ParserApi::Parse(info)) {
// Measure how long it takes to do the lazy compilation; only take the
@@ -622,6 +672,13 @@ bool Compiler::CompileLazy(CompilationInfo* info) {
if (info->IsOptimizing()) {
function->ReplaceCode(*code);
+ if (FLAG_cache_optimized_code
+ && code->kind() == Code::OPTIMIZED_FUNCTION
+ && info->osr_ast_id() == -1) {
+ Handle<SharedFunctionInfo> shared(function->shared());
+ Handle<Context> global_context(function->context()->global_context());
+ AddToOptimizedCodeMap(shared, global_context, code);
+ }
} else {
// Update the shared function info with the compiled code and the
// scope info. Please note, that the order of the shared function
« no previous file with comments | « no previous file | src/deoptimizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698