OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 2915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2926 } | 2926 } |
2927 | 2927 |
2928 // Mark both, the source and the target, as un-flushable because the | 2928 // Mark both, the source and the target, as un-flushable because the |
2929 // shared unoptimized code makes them impossible to enqueue in a list. | 2929 // shared unoptimized code makes them impossible to enqueue in a list. |
2930 ASSERT(target_shared->code()->gc_metadata() == NULL); | 2930 ASSERT(target_shared->code()->gc_metadata() == NULL); |
2931 ASSERT(source_shared->code()->gc_metadata() == NULL); | 2931 ASSERT(source_shared->code()->gc_metadata() == NULL); |
2932 target_shared->set_dont_flush(true); | 2932 target_shared->set_dont_flush(true); |
2933 source_shared->set_dont_flush(true); | 2933 source_shared->set_dont_flush(true); |
2934 | 2934 |
2935 // Set the code, scope info, formal parameter count, and the length | 2935 // Set the code, scope info, formal parameter count, and the length |
2936 // of the target shared function info. Set the source code of the | 2936 // of the target shared function info. |
2937 // target function to undefined. SetCode is only used for built-in | |
2938 // constructors like String, Array, and Object, and some web code | |
2939 // doesn't like seeing source code for constructors. | |
2940 target_shared->ReplaceCode(source_shared->code()); | 2937 target_shared->ReplaceCode(source_shared->code()); |
2941 target_shared->set_scope_info(source_shared->scope_info()); | 2938 target_shared->set_scope_info(source_shared->scope_info()); |
2942 target_shared->set_length(source_shared->length()); | 2939 target_shared->set_length(source_shared->length()); |
2943 target_shared->set_formal_parameter_count( | 2940 target_shared->set_formal_parameter_count( |
2944 source_shared->formal_parameter_count()); | 2941 source_shared->formal_parameter_count()); |
2945 target_shared->set_script(isolate->heap()->undefined_value()); | 2942 target_shared->set_script(source_shared->script()); |
2946 | 2943 target_shared->set_start_position_and_type( |
2947 // Since we don't store the source we should never optimize this. | 2944 source_shared->start_position_and_type()); |
2948 target_shared->code()->set_optimizable(false); | 2945 target_shared->set_end_position(source_shared->end_position()); |
| 2946 bool was_native = target_shared->native(); |
| 2947 target_shared->set_compiler_hints(source_shared->compiler_hints()); |
| 2948 target_shared->set_native(was_native); |
2949 | 2949 |
2950 // Set the code of the target function. | 2950 // Set the code of the target function. |
2951 target->ReplaceCode(source_shared->code()); | 2951 target->ReplaceCode(source_shared->code()); |
2952 ASSERT(target->next_function_link()->IsUndefined()); | 2952 ASSERT(target->next_function_link()->IsUndefined()); |
2953 | 2953 |
2954 // Make sure we get a fresh copy of the literal vector to avoid cross | 2954 // Make sure we get a fresh copy of the literal vector to avoid cross |
2955 // context contamination. | 2955 // context contamination. |
2956 Handle<Context> context(source->context()); | 2956 Handle<Context> context(source->context()); |
2957 int number_of_literals = source->NumberOfLiterals(); | 2957 int number_of_literals = source->NumberOfLiterals(); |
2958 Handle<FixedArray> literals = | 2958 Handle<FixedArray> literals = |
(...skipping 5380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8339 | 8339 |
8340 | 8340 |
8341 bool AllowOptimization(Isolate* isolate, Handle<JSFunction> function) { | 8341 bool AllowOptimization(Isolate* isolate, Handle<JSFunction> function) { |
8342 // If the function is not compiled ignore the lazy | 8342 // If the function is not compiled ignore the lazy |
8343 // recompilation. This can happen if the debugger is activated and | 8343 // recompilation. This can happen if the debugger is activated and |
8344 // the function is returned to the not compiled state. | 8344 // the function is returned to the not compiled state. |
8345 if (!function->shared()->is_compiled()) return false; | 8345 if (!function->shared()->is_compiled()) return false; |
8346 | 8346 |
8347 // If the function is not optimizable or debugger is active continue using the | 8347 // If the function is not optimizable or debugger is active continue using the |
8348 // code from the full compiler. | 8348 // code from the full compiler. |
8349 if (!FLAG_crankshaft || | 8349 if (!isolate->use_crankshaft() || |
8350 function->shared()->optimization_disabled() || | 8350 function->shared()->optimization_disabled() || |
8351 isolate->DebuggerHasBreakPoints()) { | 8351 isolate->DebuggerHasBreakPoints()) { |
8352 if (FLAG_trace_opt) { | 8352 if (FLAG_trace_opt) { |
8353 PrintF("[failed to optimize "); | 8353 PrintF("[failed to optimize "); |
8354 function->PrintName(); | 8354 function->PrintName(); |
8355 PrintF(": is code optimizable: %s, is debugger enabled: %s]\n", | 8355 PrintF(": is code optimizable: %s, is debugger enabled: %s]\n", |
8356 function->shared()->optimization_disabled() ? "F" : "T", | 8356 function->shared()->optimization_disabled() ? "F" : "T", |
8357 isolate->DebuggerHasBreakPoints() ? "T" : "F"); | 8357 isolate->DebuggerHasBreakPoints() ? "T" : "F"); |
8358 } | 8358 } |
8359 return false; | 8359 return false; |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8621 ASSERT(args.length() == 1); | 8621 ASSERT(args.length() == 1); |
8622 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 8622 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
8623 return Smi::FromInt(function->shared()->opt_count()); | 8623 return Smi::FromInt(function->shared()->opt_count()); |
8624 } | 8624 } |
8625 | 8625 |
8626 | 8626 |
8627 static bool IsSuitableForOnStackReplacement(Isolate* isolate, | 8627 static bool IsSuitableForOnStackReplacement(Isolate* isolate, |
8628 Handle<JSFunction> function, | 8628 Handle<JSFunction> function, |
8629 Handle<Code> unoptimized) { | 8629 Handle<Code> unoptimized) { |
8630 // Keep track of whether we've succeeded in optimizing. | 8630 // Keep track of whether we've succeeded in optimizing. |
8631 if (!unoptimized->optimizable()) return false; | 8631 if (!isolate->use_crankshaft() || !unoptimized->optimizable()) return false; |
8632 // If we are trying to do OSR when there are already optimized | 8632 // If we are trying to do OSR when there are already optimized |
8633 // activations of the function, it means (a) the function is directly or | 8633 // activations of the function, it means (a) the function is directly or |
8634 // indirectly recursive and (b) an optimized invocation has been | 8634 // indirectly recursive and (b) an optimized invocation has been |
8635 // deoptimized so that we are currently in an unoptimized activation. | 8635 // deoptimized so that we are currently in an unoptimized activation. |
8636 // Check for optimized activations of this function. | 8636 // Check for optimized activations of this function. |
8637 for (JavaScriptFrameIterator it(isolate); !it.done(); it.Advance()) { | 8637 for (JavaScriptFrameIterator it(isolate); !it.done(); it.Advance()) { |
8638 JavaScriptFrame* frame = it.frame(); | 8638 JavaScriptFrame* frame = it.frame(); |
8639 if (frame->is_optimized() && frame->function() == *function) return false; | 8639 if (frame->is_optimized() && frame->function() == *function) return false; |
8640 } | 8640 } |
8641 | 8641 |
(...skipping 6224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14866 // Handle last resort GC and make sure to allow future allocations | 14866 // Handle last resort GC and make sure to allow future allocations |
14867 // to grow the heap without causing GCs (if possible). | 14867 // to grow the heap without causing GCs (if possible). |
14868 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14868 isolate->counters()->gc_last_resort_from_js()->Increment(); |
14869 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14869 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
14870 "Runtime::PerformGC"); | 14870 "Runtime::PerformGC"); |
14871 } | 14871 } |
14872 } | 14872 } |
14873 | 14873 |
14874 | 14874 |
14875 } } // namespace v8::internal | 14875 } } // namespace v8::internal |
OLD | NEW |