| Index: src/compiler.cc
|
| ===================================================================
|
| --- src/compiler.cc (revision 11394)
|
| +++ src/compiler.cc (working copy)
|
| @@ -600,6 +600,44 @@
|
| }
|
|
|
|
|
| +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) {
|
| Isolate* isolate = info->isolate();
|
|
|
| @@ -614,6 +652,23 @@
|
| 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) {
|
| + if (FLAG_trace_opt) {
|
| + PrintF(" [Found optimized code for");
|
| + function->PrintName();
|
| + PrintF("\n");
|
| + }
|
| + function->ReplaceCode(code);
|
| + return true;
|
| + }
|
| + }
|
| +
|
| // Generate the AST for the lazily compiled function.
|
| if (ParserApi::Parse(info, kNoParsingFlags)) {
|
| // Measure how long it takes to do the lazy compilation; only take the
|
| @@ -645,6 +700,12 @@
|
| if (info->IsOptimizing()) {
|
| ASSERT(shared->scope_info() != ScopeInfo::Empty());
|
| function->ReplaceCode(*code);
|
| + if (FLAG_cache_optimized_code &&
|
| + code->kind() == Code::OPTIMIZED_FUNCTION) {
|
| + 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
|
|
|