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

Side by Side Diff: src/runtime.cc

Issue 18404009: Refactor JavaScriptFrame::function() to return a JSFunction* and remove associated casts. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Remove implicit ASSERT. Created 7 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/liveedit.cc ('k') | src/runtime-profiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2779 matching lines...) Expand 10 before | Expand all | Expand 10 after
2790 return isolate->heap()->undefined_value(); 2790 return isolate->heap()->undefined_value();
2791 } 2791 }
2792 2792
2793 2793
2794 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSGeneratorObject) { 2794 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSGeneratorObject) {
2795 SealHandleScope shs(isolate); 2795 SealHandleScope shs(isolate);
2796 ASSERT(args.length() == 0); 2796 ASSERT(args.length() == 0);
2797 2797
2798 JavaScriptFrameIterator it(isolate); 2798 JavaScriptFrameIterator it(isolate);
2799 JavaScriptFrame* frame = it.frame(); 2799 JavaScriptFrame* frame = it.frame();
2800 JSFunction* function = JSFunction::cast(frame->function()); 2800 JSFunction* function = frame->function();
2801 RUNTIME_ASSERT(function->shared()->is_generator()); 2801 RUNTIME_ASSERT(function->shared()->is_generator());
2802 2802
2803 JSGeneratorObject* generator; 2803 JSGeneratorObject* generator;
2804 if (frame->IsConstructor()) { 2804 if (frame->IsConstructor()) {
2805 generator = JSGeneratorObject::cast(frame->receiver()); 2805 generator = JSGeneratorObject::cast(frame->receiver());
2806 } else { 2806 } else {
2807 MaybeObject* maybe_generator = 2807 MaybeObject* maybe_generator =
2808 isolate->heap()->AllocateJSGeneratorObject(function); 2808 isolate->heap()->AllocateJSGeneratorObject(function);
2809 if (!maybe_generator->To(&generator)) return maybe_generator; 2809 if (!maybe_generator->To(&generator)) return maybe_generator;
2810 } 2810 }
2811 generator->set_function(function); 2811 generator->set_function(function);
2812 generator->set_context(Context::cast(frame->context())); 2812 generator->set_context(Context::cast(frame->context()));
2813 generator->set_receiver(frame->receiver()); 2813 generator->set_receiver(frame->receiver());
2814 generator->set_continuation(0); 2814 generator->set_continuation(0);
2815 generator->set_operand_stack(isolate->heap()->empty_fixed_array()); 2815 generator->set_operand_stack(isolate->heap()->empty_fixed_array());
2816 generator->set_stack_handler_index(-1); 2816 generator->set_stack_handler_index(-1);
2817 2817
2818 return generator; 2818 return generator;
2819 } 2819 }
2820 2820
2821 2821
2822 RUNTIME_FUNCTION(MaybeObject*, Runtime_SuspendJSGeneratorObject) { 2822 RUNTIME_FUNCTION(MaybeObject*, Runtime_SuspendJSGeneratorObject) {
2823 SealHandleScope shs(isolate); 2823 SealHandleScope shs(isolate);
2824 ASSERT(args.length() == 1); 2824 ASSERT(args.length() == 1);
2825 CONVERT_ARG_CHECKED(JSGeneratorObject, generator_object, 0); 2825 CONVERT_ARG_CHECKED(JSGeneratorObject, generator_object, 0);
2826 2826
2827 JavaScriptFrameIterator stack_iterator(isolate); 2827 JavaScriptFrameIterator stack_iterator(isolate);
2828 JavaScriptFrame* frame = stack_iterator.frame(); 2828 JavaScriptFrame* frame = stack_iterator.frame();
2829 RUNTIME_ASSERT(JSFunction::cast(frame->function())->shared()->is_generator()); 2829 RUNTIME_ASSERT(frame->function()->shared()->is_generator());
2830 ASSERT_EQ(JSFunction::cast(frame->function()), generator_object->function()); 2830 ASSERT_EQ(frame->function(), generator_object->function());
2831 2831
2832 // The caller should have saved the context and continuation already. 2832 // The caller should have saved the context and continuation already.
2833 ASSERT_EQ(generator_object->context(), Context::cast(frame->context())); 2833 ASSERT_EQ(generator_object->context(), Context::cast(frame->context()));
2834 ASSERT_LT(0, generator_object->continuation()); 2834 ASSERT_LT(0, generator_object->continuation());
2835 2835
2836 // We expect there to be at least two values on the operand stack: the return 2836 // We expect there to be at least two values on the operand stack: the return
2837 // value of the yield expression, and the argument to this runtime call. 2837 // value of the yield expression, and the argument to this runtime call.
2838 // Neither of those should be saved. 2838 // Neither of those should be saved.
2839 int operands_count = frame->ComputeOperandsCount(); 2839 int operands_count = frame->ComputeOperandsCount();
2840 ASSERT_GE(operands_count, 2); 2840 ASSERT_GE(operands_count, 2);
(...skipping 2884 matching lines...) Expand 10 before | Expand all | Expand 10 after
5725 if (index < n) { 5725 if (index < n) {
5726 return frame->GetParameter(index); 5726 return frame->GetParameter(index);
5727 } else { 5727 } else {
5728 return isolate->initial_object_prototype()->GetElement(index); 5728 return isolate->initial_object_prototype()->GetElement(index);
5729 } 5729 }
5730 } 5730 }
5731 5731
5732 // Handle special arguments properties. 5732 // Handle special arguments properties.
5733 if (key->Equals(isolate->heap()->length_string())) return Smi::FromInt(n); 5733 if (key->Equals(isolate->heap()->length_string())) return Smi::FromInt(n);
5734 if (key->Equals(isolate->heap()->callee_string())) { 5734 if (key->Equals(isolate->heap()->callee_string())) {
5735 Object* function = frame->function(); 5735 JSFunction* function = frame->function();
5736 if (function->IsJSFunction() && 5736 if (!function->shared()->is_classic_mode()) {
5737 !JSFunction::cast(function)->shared()->is_classic_mode()) {
5738 return isolate->Throw(*isolate->factory()->NewTypeError( 5737 return isolate->Throw(*isolate->factory()->NewTypeError(
5739 "strict_arguments_callee", HandleVector<Object>(NULL, 0))); 5738 "strict_arguments_callee", HandleVector<Object>(NULL, 0)));
5740 } 5739 }
5741 return function; 5740 return function;
5742 } 5741 }
5743 5742
5744 // Lookup in the initial Object.prototype object. 5743 // Lookup in the initial Object.prototype object.
5745 return isolate->initial_object_prototype()->GetProperty(*key); 5744 return isolate->initial_object_prototype()->GetProperty(*key);
5746 } 5745 }
5747 5746
(...skipping 2466 matching lines...) Expand 10 before | Expand all | Expand 10 after
8214 8213
8215 ASSERT(deoptimizer->compiled_code_kind() == Code::OPTIMIZED_FUNCTION); 8214 ASSERT(deoptimizer->compiled_code_kind() == Code::OPTIMIZED_FUNCTION);
8216 8215
8217 // Make sure to materialize objects before causing any allocation. 8216 // Make sure to materialize objects before causing any allocation.
8218 JavaScriptFrameIterator it(isolate); 8217 JavaScriptFrameIterator it(isolate);
8219 deoptimizer->MaterializeHeapObjects(&it); 8218 deoptimizer->MaterializeHeapObjects(&it);
8220 delete deoptimizer; 8219 delete deoptimizer;
8221 8220
8222 JavaScriptFrame* frame = it.frame(); 8221 JavaScriptFrame* frame = it.frame();
8223 RUNTIME_ASSERT(frame->function()->IsJSFunction()); 8222 RUNTIME_ASSERT(frame->function()->IsJSFunction());
8224 Handle<JSFunction> function(JSFunction::cast(frame->function()), isolate); 8223 Handle<JSFunction> function(frame->function(), isolate);
8225 Handle<Code> optimized_code(function->code()); 8224 Handle<Code> optimized_code(function->code());
8226 RUNTIME_ASSERT((type != Deoptimizer::EAGER && 8225 RUNTIME_ASSERT((type != Deoptimizer::EAGER &&
8227 type != Deoptimizer::SOFT) || function->IsOptimized()); 8226 type != Deoptimizer::SOFT) || function->IsOptimized());
8228 8227
8229 // Avoid doing too much work when running with --always-opt and keep 8228 // Avoid doing too much work when running with --always-opt and keep
8230 // the optimized code around. 8229 // the optimized code around.
8231 if (FLAG_always_opt || type == Deoptimizer::LAZY) { 8230 if (FLAG_always_opt || type == Deoptimizer::LAZY) {
8232 return isolate->heap()->undefined_value(); 8231 return isolate->heap()->undefined_value();
8233 } 8232 }
8234 8233
8235 // Find other optimized activations of the function or functions that 8234 // Find other optimized activations of the function or functions that
8236 // share the same optimized code. 8235 // share the same optimized code.
8237 bool has_other_activations = false; 8236 bool has_other_activations = false;
8238 while (!it.done()) { 8237 while (!it.done()) {
8239 JavaScriptFrame* frame = it.frame(); 8238 JavaScriptFrame* frame = it.frame();
8240 JSFunction* other_function = JSFunction::cast(frame->function()); 8239 JSFunction* other_function = frame->function();
8241 if (frame->is_optimized() && other_function->code() == function->code()) { 8240 if (frame->is_optimized() && other_function->code() == function->code()) {
8242 has_other_activations = true; 8241 has_other_activations = true;
8243 break; 8242 break;
8244 } 8243 }
8245 it.Advance(); 8244 it.Advance();
8246 } 8245 }
8247 8246
8248 if (!has_other_activations) { 8247 if (!has_other_activations) {
8249 ActivationsFinder activations_finder(*function); 8248 ActivationsFinder activations_finder(*function);
8250 isolate->thread_manager()->IterateArchivedThreads(&activations_finder); 8249 isolate->thread_manager()->IterateArchivedThreads(&activations_finder);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
8346 } 8345 }
8347 8346
8348 8347
8349 RUNTIME_FUNCTION(MaybeObject*, Runtime_NeverOptimize) { 8348 RUNTIME_FUNCTION(MaybeObject*, Runtime_NeverOptimize) {
8350 HandleScope scope(isolate); 8349 HandleScope scope(isolate);
8351 8350
8352 if (args.length() == 0) { 8351 if (args.length() == 0) {
8353 // Disable optimization for the calling function. 8352 // Disable optimization for the calling function.
8354 JavaScriptFrameIterator it(isolate); 8353 JavaScriptFrameIterator it(isolate);
8355 if (!it.done()) { 8354 if (!it.done()) {
8356 JSFunction *function = JSFunction::cast(it.frame()->function()); 8355 it.frame()->function()->shared()->set_optimization_disabled(true);
8357 function->shared()->set_optimization_disabled(true);
8358 } 8356 }
8359 return isolate->heap()->undefined_value(); 8357 return isolate->heap()->undefined_value();
8360 } 8358 }
8361 8359
8362 // Disable optimization for the functions passed. 8360 // Disable optimization for the functions passed.
8363 for (int i = 0; i < args.length(); i++) { 8361 for (int i = 0; i < args.length(); i++) {
8364 CONVERT_ARG_CHECKED(JSFunction, function, i); 8362 CONVERT_ARG_CHECKED(JSFunction, function, i);
8365 function->shared()->set_optimization_disabled(true); 8363 function->shared()->set_optimization_disabled(true);
8366 } 8364 }
8367 return isolate->heap()->undefined_value(); 8365 return isolate->heap()->undefined_value();
(...skipping 2860 matching lines...) Expand 10 before | Expand all | Expand 10 after
11228 static bool SetLocalVariableValue(Isolate* isolate, 11226 static bool SetLocalVariableValue(Isolate* isolate,
11229 JavaScriptFrame* frame, 11227 JavaScriptFrame* frame,
11230 int inlined_jsframe_index, 11228 int inlined_jsframe_index,
11231 Handle<String> variable_name, 11229 Handle<String> variable_name,
11232 Handle<Object> new_value) { 11230 Handle<Object> new_value) {
11233 if (inlined_jsframe_index != 0 || frame->is_optimized()) { 11231 if (inlined_jsframe_index != 0 || frame->is_optimized()) {
11234 // Optimized frames are not supported. 11232 // Optimized frames are not supported.
11235 return false; 11233 return false;
11236 } 11234 }
11237 11235
11238 Handle<JSFunction> function(JSFunction::cast(frame->function())); 11236 Handle<JSFunction> function(frame->function());
11239 Handle<SharedFunctionInfo> shared(function->shared()); 11237 Handle<SharedFunctionInfo> shared(function->shared());
11240 Handle<ScopeInfo> scope_info(shared->scope_info()); 11238 Handle<ScopeInfo> scope_info(shared->scope_info());
11241 11239
11242 bool default_result = false; 11240 bool default_result = false;
11243 11241
11244 // Parameters. 11242 // Parameters.
11245 for (int i = 0; i < scope_info->ParameterCount(); ++i) { 11243 for (int i = 0; i < scope_info->ParameterCount(); ++i) {
11246 if (scope_info->ParameterName(i)->Equals(*variable_name)) { 11244 if (scope_info->ParameterName(i)->Equals(*variable_name)) {
11247 frame->SetParameterValue(i, *new_value); 11245 frame->SetParameterValue(i, *new_value);
11248 // Argument might be shadowed in heap context, don't stop here. 11246 // Argument might be shadowed in heap context, don't stop here.
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
11475 ScopeTypeBlock, 11473 ScopeTypeBlock,
11476 ScopeTypeModule 11474 ScopeTypeModule
11477 }; 11475 };
11478 11476
11479 ScopeIterator(Isolate* isolate, 11477 ScopeIterator(Isolate* isolate,
11480 JavaScriptFrame* frame, 11478 JavaScriptFrame* frame,
11481 int inlined_jsframe_index) 11479 int inlined_jsframe_index)
11482 : isolate_(isolate), 11480 : isolate_(isolate),
11483 frame_(frame), 11481 frame_(frame),
11484 inlined_jsframe_index_(inlined_jsframe_index), 11482 inlined_jsframe_index_(inlined_jsframe_index),
11485 function_(JSFunction::cast(frame->function())), 11483 function_(frame->function()),
11486 context_(Context::cast(frame->context())), 11484 context_(Context::cast(frame->context())),
11487 nested_scope_chain_(4), 11485 nested_scope_chain_(4),
11488 failed_(false) { 11486 failed_(false) {
11489 11487
11490 // Catch the case when the debugger stops in an internal function. 11488 // Catch the case when the debugger stops in an internal function.
11491 Handle<SharedFunctionInfo> shared_info(function_->shared()); 11489 Handle<SharedFunctionInfo> shared_info(function_->shared());
11492 Handle<ScopeInfo> scope_info(shared_info->scope_info()); 11490 Handle<ScopeInfo> scope_info(shared_info->scope_info());
11493 if (shared_info->script() == isolate->heap()->undefined_value()) { 11491 if (shared_info->script() == isolate->heap()->undefined_value()) {
11494 while (context_->closure() == *function_) { 11492 while (context_->closure() == *function_) {
11495 context_ = Handle<Context>(context_->previous(), isolate_); 11493 context_ = Handle<Context>(context_->previous(), isolate_);
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
11856 if (!maybe_check->ToObject(&check)) return maybe_check; 11854 if (!maybe_check->ToObject(&check)) return maybe_check;
11857 } 11855 }
11858 CONVERT_SMI_ARG_CHECKED(wrapped_id, 1); 11856 CONVERT_SMI_ARG_CHECKED(wrapped_id, 1);
11859 11857
11860 // Get the frame where the debugging is performed. 11858 // Get the frame where the debugging is performed.
11861 StackFrame::Id id = UnwrapFrameId(wrapped_id); 11859 StackFrame::Id id = UnwrapFrameId(wrapped_id);
11862 JavaScriptFrameIterator frame_it(isolate, id); 11860 JavaScriptFrameIterator frame_it(isolate, id);
11863 JavaScriptFrame* frame = frame_it.frame(); 11861 JavaScriptFrame* frame = frame_it.frame();
11864 11862
11865 Handle<SharedFunctionInfo> shared = 11863 Handle<SharedFunctionInfo> shared =
11866 Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared()); 11864 Handle<SharedFunctionInfo>(frame->function()->shared());
11867 Handle<DebugInfo> debug_info = Debug::GetDebugInfo(shared); 11865 Handle<DebugInfo> debug_info = Debug::GetDebugInfo(shared);
11868 11866
11869 int len = 0; 11867 int len = 0;
11870 Handle<JSArray> array(isolate->factory()->NewJSArray(10)); 11868 Handle<JSArray> array(isolate->factory()->NewJSArray(10));
11871 // Find the break point where execution has stopped. 11869 // Find the break point where execution has stopped.
11872 BreakLocationIterator break_location_iterator(debug_info, 11870 BreakLocationIterator break_location_iterator(debug_info,
11873 ALL_BREAK_LOCATIONS); 11871 ALL_BREAK_LOCATIONS);
11874 11872
11875 break_location_iterator.FindBreakLocationFromAddress(frame->pc()); 11873 break_location_iterator.FindBreakLocationFromAddress(frame->pc());
11876 int current_statement_pos = break_location_iterator.statement_position(); 11874 int current_statement_pos = break_location_iterator.statement_position();
(...skipping 2141 matching lines...) Expand 10 before | Expand all | Expand 10 after
14018 // Handle last resort GC and make sure to allow future allocations 14016 // Handle last resort GC and make sure to allow future allocations
14019 // to grow the heap without causing GCs (if possible). 14017 // to grow the heap without causing GCs (if possible).
14020 isolate->counters()->gc_last_resort_from_js()->Increment(); 14018 isolate->counters()->gc_last_resort_from_js()->Increment();
14021 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 14019 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
14022 "Runtime::PerformGC"); 14020 "Runtime::PerformGC");
14023 } 14021 }
14024 } 14022 }
14025 14023
14026 14024
14027 } } // namespace v8::internal 14025 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/liveedit.cc ('k') | src/runtime-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698