| 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
|
|
|