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

Side by Side Diff: src/runtime.cc

Issue 2943002: Reimplement stack manipulations for LiveEdit (Closed)
Patch Set: follow codereview Created 10 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
« no previous file with comments | « src/runtime.h ('k') | src/scopeinfo.h » ('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 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 8472 matching lines...) Expand 10 before | Expand all | Expand 10 after
8483 Handle<Object> frame_id(WrapFrameId(it.frame()->id())); 8483 Handle<Object> frame_id(WrapFrameId(it.frame()->id()));
8484 8484
8485 // Find source position. 8485 // Find source position.
8486 int position = it.frame()->code()->SourcePosition(it.frame()->pc()); 8486 int position = it.frame()->code()->SourcePosition(it.frame()->pc());
8487 8487
8488 // Check for constructor frame. 8488 // Check for constructor frame.
8489 bool constructor = it.frame()->IsConstructor(); 8489 bool constructor = it.frame()->IsConstructor();
8490 8490
8491 // Get code and read scope info from it for local variable information. 8491 // Get code and read scope info from it for local variable information.
8492 Handle<Code> code(it.frame()->code()); 8492 Handle<Code> code(it.frame()->code());
8493 ScopeInfo<> info(*code); 8493 FunctionScopeState scope_state = LiveEdit::IsAtFrameResetPatch(it.frame())
8494 ? FUNCTION_SCOPE_NOT_ENTERED : FUNCTION_SCOPE_NORMAL;
8495 ScopeInfo<> info(*code, scope_state);
8494 8496
8495 // Get the context. 8497 // Get the context.
8496 Handle<Context> context(Context::cast(it.frame()->context())); 8498 Handle<Context> context(Context::cast(it.frame()->context()));
8497 8499
8498 // Get the locals names and values into a temporary array. 8500 // Get the locals names and values into a temporary array.
8499 // 8501 //
8500 // TODO(1240907): Hide compiler-introduced stack variables 8502 // TODO(1240907): Hide compiler-introduced stack variables
8501 // (e.g. .result)? For users of the debugger, they will probably be 8503 // (e.g. .result)? For users of the debugger, they will probably be
8502 // confusing. 8504 // confusing.
8503 Handle<FixedArray> locals = Factory::NewFixedArray(info.NumberOfLocals() * 2); 8505 Handle<FixedArray> locals = Factory::NewFixedArray(info.NumberOfLocals() * 2);
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
8680 } 8682 }
8681 } 8683 }
8682 } 8684 }
8683 8685
8684 8686
8685 // Create a plain JSObject which materializes the local scope for the specified 8687 // Create a plain JSObject which materializes the local scope for the specified
8686 // frame. 8688 // frame.
8687 static Handle<JSObject> MaterializeLocalScope(JavaScriptFrame* frame) { 8689 static Handle<JSObject> MaterializeLocalScope(JavaScriptFrame* frame) {
8688 Handle<JSFunction> function(JSFunction::cast(frame->function())); 8690 Handle<JSFunction> function(JSFunction::cast(frame->function()));
8689 Handle<Code> code(function->code()); 8691 Handle<Code> code(function->code());
8690 ScopeInfo<> scope_info(*code); 8692
8693 FunctionScopeState scope_state = LiveEdit::IsAtFrameResetPatch(frame)
8694 ? FUNCTION_SCOPE_NOT_ENTERED : FUNCTION_SCOPE_NORMAL;
8695 ScopeInfo<> scope_info(*code, scope_state);
8691 8696
8692 // Allocate and initialize a JSObject with all the arguments, stack locals 8697 // Allocate and initialize a JSObject with all the arguments, stack locals
8693 // heap locals and extension properties of the debugged function. 8698 // heap locals and extension properties of the debugged function.
8694 Handle<JSObject> local_scope = Factory::NewJSObject(Top::object_function()); 8699 Handle<JSObject> local_scope = Factory::NewJSObject(Top::object_function());
8695 8700
8696 // First fill all parameters. 8701 // First fill all parameters.
8697 for (int i = 0; i < scope_info.number_of_parameters(); ++i) { 8702 for (int i = 0; i < scope_info.number_of_parameters(); ++i) {
8698 SetProperty(local_scope, 8703 SetProperty(local_scope,
8699 scope_info.parameter_name(i), 8704 scope_info.parameter_name(i),
8700 Handle<Object>(frame->GetParameter(i)), NONE); 8705 Handle<Object>(frame->GetParameter(i)), NONE);
(...skipping 30 matching lines...) Expand all
8731 return local_scope; 8736 return local_scope;
8732 } 8737 }
8733 8738
8734 8739
8735 // Create a plain JSObject which materializes the closure content for the 8740 // Create a plain JSObject which materializes the closure content for the
8736 // context. 8741 // context.
8737 static Handle<JSObject> MaterializeClosure(Handle<Context> context) { 8742 static Handle<JSObject> MaterializeClosure(Handle<Context> context) {
8738 ASSERT(context->is_function_context()); 8743 ASSERT(context->is_function_context());
8739 8744
8740 Handle<Code> code(context->closure()->code()); 8745 Handle<Code> code(context->closure()->code());
8741 ScopeInfo<> scope_info(*code); 8746 ScopeInfo<> scope_info(*code, FUNCTION_SCOPE_NORMAL);
8742 8747
8743 // Allocate and initialize a JSObject with all the content of theis function 8748 // Allocate and initialize a JSObject with all the content of theis function
8744 // closure. 8749 // closure.
8745 Handle<JSObject> closure_scope = Factory::NewJSObject(Top::object_function()); 8750 Handle<JSObject> closure_scope = Factory::NewJSObject(Top::object_function());
8746 8751
8747 // Check whether the arguments shadow object exists. 8752 // Check whether the arguments shadow object exists.
8748 int arguments_shadow_index = 8753 int arguments_shadow_index =
8749 ScopeInfo<>::ContextSlotIndex(*code, 8754 ScopeInfo<>::ContextSlotIndex(*code,
8750 Heap::arguments_shadow_symbol(), 8755 Heap::arguments_shadow_symbol(),
8751 NULL); 8756 NULL);
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
8920 void DebugPrint() { 8925 void DebugPrint() {
8921 switch (Type()) { 8926 switch (Type()) {
8922 case ScopeIterator::ScopeTypeGlobal: 8927 case ScopeIterator::ScopeTypeGlobal:
8923 PrintF("Global:\n"); 8928 PrintF("Global:\n");
8924 CurrentContext()->Print(); 8929 CurrentContext()->Print();
8925 break; 8930 break;
8926 8931
8927 case ScopeIterator::ScopeTypeLocal: { 8932 case ScopeIterator::ScopeTypeLocal: {
8928 PrintF("Local:\n"); 8933 PrintF("Local:\n");
8929 Handle<Code> code(function_->code()); 8934 Handle<Code> code(function_->code());
8930 ScopeInfo<> scope_info(*code); 8935 ScopeInfo<> scope_info(*code, FUNCTION_SCOPE_NORMAL);
8931 scope_info.Print(); 8936 scope_info.Print();
8932 if (!CurrentContext().is_null()) { 8937 if (!CurrentContext().is_null()) {
8933 CurrentContext()->Print(); 8938 CurrentContext()->Print();
8934 if (CurrentContext()->has_extension()) { 8939 if (CurrentContext()->has_extension()) {
8935 Handle<JSObject> extension = 8940 Handle<JSObject> extension =
8936 Handle<JSObject>(CurrentContext()->extension()); 8941 Handle<JSObject>(CurrentContext()->extension());
8937 if (extension->IsJSContextExtensionObject()) { 8942 if (extension->IsJSContextExtensionObject()) {
8938 extension->Print(); 8943 extension->Print();
8939 } 8944 }
8940 } 8945 }
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
9512 9517
9513 // Handle the processing of break. 9518 // Handle the processing of break.
9514 DisableBreak disable_break_save(disable_break); 9519 DisableBreak disable_break_save(disable_break);
9515 9520
9516 // Get the frame where the debugging is performed. 9521 // Get the frame where the debugging is performed.
9517 StackFrame::Id id = UnwrapFrameId(wrapped_id); 9522 StackFrame::Id id = UnwrapFrameId(wrapped_id);
9518 JavaScriptFrameIterator it(id); 9523 JavaScriptFrameIterator it(id);
9519 JavaScriptFrame* frame = it.frame(); 9524 JavaScriptFrame* frame = it.frame();
9520 Handle<JSFunction> function(JSFunction::cast(frame->function())); 9525 Handle<JSFunction> function(JSFunction::cast(frame->function()));
9521 Handle<Code> code(function->code()); 9526 Handle<Code> code(function->code());
9522 ScopeInfo<> sinfo(*code); 9527 FunctionScopeState scope_state = LiveEdit::IsAtFrameResetPatch(frame)
9528 ? FUNCTION_SCOPE_NOT_ENTERED : FUNCTION_SCOPE_NORMAL;
9529 ScopeInfo<> sinfo(*code, scope_state);
9523 9530
9524 // Traverse the saved contexts chain to find the active context for the 9531 // Traverse the saved contexts chain to find the active context for the
9525 // selected frame. 9532 // selected frame.
9526 SaveContext* save = Top::save_context(); 9533 SaveContext* save = Top::save_context();
9527 while (save != NULL && !save->below(frame)) { 9534 while (save != NULL && !save->below(frame)) {
9528 save = save->prev(); 9535 save = save->prev();
9529 } 9536 }
9530 ASSERT(save != NULL); 9537 ASSERT(save != NULL);
9531 SaveContext savex; 9538 SaveContext savex;
9532 Top::set_context(*(save->context())); 9539 Top::set_context(*(save->context()));
9533 9540
9534 // Create the (empty) function replacing the function on the stack frame for 9541 // Create the (empty) function replacing the function on the stack frame for
9535 // the purpose of evaluating in the context created below. It is important 9542 // the purpose of evaluating in the context created below. It is important
9536 // that this function does not describe any parameters and local variables 9543 // that this function does not describe any parameters and local variables
9537 // in the context. If it does then this will cause problems with the lookup 9544 // in the context. If it does then this will cause problems with the lookup
9538 // in Context::Lookup, where context slots for parameters and local variables 9545 // in Context::Lookup, where context slots for parameters and local variables
9539 // are looked at before the extension object. 9546 // are looked at before the extension object.
9540 Handle<JSFunction> go_between = 9547 Handle<JSFunction> go_between =
9541 Factory::NewFunction(Factory::empty_string(), Factory::undefined_value()); 9548 Factory::NewFunction(Factory::empty_string(), Factory::undefined_value());
9542 go_between->set_context(function->context()); 9549 go_between->set_context(function->context());
9543 #ifdef DEBUG 9550 #ifdef DEBUG
9544 ScopeInfo<> go_between_sinfo(go_between->shared()->code()); 9551 ScopeInfo<> go_between_sinfo(go_between->shared()->code(),
9552 FUNCTION_SCOPE_NORMAL);
9545 ASSERT(go_between_sinfo.number_of_parameters() == 0); 9553 ASSERT(go_between_sinfo.number_of_parameters() == 0);
9546 ASSERT(go_between_sinfo.number_of_context_slots() == 0); 9554 ASSERT(go_between_sinfo.number_of_context_slots() == 0);
9547 #endif 9555 #endif
9548 9556
9549 // Materialize the content of the local scope into a JSObject. 9557 // Materialize the content of the local scope into a JSObject.
9550 Handle<JSObject> local_scope = MaterializeLocalScope(frame); 9558 Handle<JSObject> local_scope = MaterializeLocalScope(frame);
9551 9559
9552 // Allocate a new context for the debug evaluation and set the extension 9560 // Allocate a new context for the debug evaluation and set the extension
9553 // object build. 9561 // object build.
9554 Handle<Context> context = 9562 Handle<Context> context =
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
10024 if (old_script->IsScript()) { 10032 if (old_script->IsScript()) {
10025 Handle<Script> script_handle(Script::cast(old_script)); 10033 Handle<Script> script_handle(Script::cast(old_script));
10026 return *(GetScriptWrapper(script_handle)); 10034 return *(GetScriptWrapper(script_handle));
10027 } else { 10035 } else {
10028 return Heap::null_value(); 10036 return Heap::null_value();
10029 } 10037 }
10030 } 10038 }
10031 10039
10032 // Replaces code of SharedFunctionInfo with a new one. 10040 // Replaces code of SharedFunctionInfo with a new one.
10033 static Object* Runtime_LiveEditReplaceFunctionCode(Arguments args) { 10041 static Object* Runtime_LiveEditReplaceFunctionCode(Arguments args) {
10034 ASSERT(args.length() == 2); 10042 ASSERT(args.length() == 3);
10035 HandleScope scope; 10043 HandleScope scope;
10036 CONVERT_ARG_CHECKED(JSArray, new_compile_info, 0); 10044 CONVERT_ARG_CHECKED(JSArray, new_compile_info, 0);
10037 CONVERT_ARG_CHECKED(JSArray, shared_info, 1); 10045 CONVERT_ARG_CHECKED(JSArray, shared_info, 1);
10046 ByteArray* stack_drop_data;
10047 if (args[2]->IsUndefined()) {
10048 stack_drop_data = NULL;
10049 } else {
10050 CONVERT_CHECKED(JSValue, stack_drop_data_wrapped, args[2]);
10051 CONVERT_CHECKED(ByteArray, stack_drop_data_temp,
10052 stack_drop_data_wrapped->value());
10053 stack_drop_data = stack_drop_data_temp;
10054 }
10055 Handle<ByteArray> stack_drop_data_handle;
10056 if (stack_drop_data != NULL) {
10057 stack_drop_data_handle = Handle<ByteArray>(stack_drop_data);
10058 }
10038 10059
10039 return LiveEdit::ReplaceFunctionCode(new_compile_info, shared_info); 10060 return LiveEdit::ReplaceFunctionCode(new_compile_info, shared_info,
10061 stack_drop_data_handle);
10040 } 10062 }
10041 10063
10042 // Connects SharedFunctionInfo to another script. 10064 // Connects SharedFunctionInfo to another script.
10043 static Object* Runtime_LiveEditFunctionSetScript(Arguments args) { 10065 static Object* Runtime_LiveEditFunctionSetScript(Arguments args) {
10044 ASSERT(args.length() == 2); 10066 ASSERT(args.length() == 2);
10045 HandleScope scope; 10067 HandleScope scope;
10046 Handle<Object> function_object(args[0]); 10068 Handle<Object> function_object(args[0]);
10047 Handle<Object> script_object(args[1]); 10069 Handle<Object> script_object(args[1]);
10048 10070
10049 if (function_object->IsJSValue()) { 10071 if (function_object->IsJSValue()) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
10092 CONVERT_ARG_CHECKED(JSArray, position_change_array, 1); 10114 CONVERT_ARG_CHECKED(JSArray, position_change_array, 1);
10093 10115
10094 return LiveEdit::PatchFunctionPositions(shared_array, position_change_array); 10116 return LiveEdit::PatchFunctionPositions(shared_array, position_change_array);
10095 } 10117 }
10096 10118
10097 10119
10098 // For array of SharedFunctionInfo's (each wrapped in JSValue) 10120 // For array of SharedFunctionInfo's (each wrapped in JSValue)
10099 // checks that none of them have activations on stacks (of any thread). 10121 // checks that none of them have activations on stacks (of any thread).
10100 // Returns array of the same length with corresponding results of 10122 // Returns array of the same length with corresponding results of
10101 // LiveEdit::FunctionPatchabilityStatus type. 10123 // LiveEdit::FunctionPatchabilityStatus type.
10102 static Object* Runtime_LiveEditCheckAndDropActivations(Arguments args) { 10124 static Object* Runtime_LiveEditCheckActivations(Arguments args) {
10103 ASSERT(args.length() == 2); 10125 ASSERT(args.length() == 1);
10104 HandleScope scope; 10126 HandleScope scope;
10105 CONVERT_ARG_CHECKED(JSArray, shared_array, 0); 10127 CONVERT_ARG_CHECKED(JSArray, shared_array, 0);
10106 CONVERT_BOOLEAN_CHECKED(do_drop, args[1]);
10107 10128
10108 return *LiveEdit::CheckAndDropActivations(shared_array, do_drop); 10129 return *LiveEdit::CheckActivations(shared_array);
10109 } 10130 }
10110 10131
10111 // Compares 2 strings line-by-line and returns diff in form of JSArray of 10132 // Compares 2 strings line-by-line and returns diff in form of JSArray of
10112 // triplets (pos1, pos1_end, pos2_end) describing list of diff chunks. 10133 // triplets (pos1, pos1_end, pos2_end) describing list of diff chunks.
10113 static Object* Runtime_LiveEditCompareStringsLinewise(Arguments args) { 10134 static Object* Runtime_LiveEditCompareStringsLinewise(Arguments args) {
10114 ASSERT(args.length() == 2); 10135 ASSERT(args.length() == 2);
10115 HandleScope scope; 10136 HandleScope scope;
10116 CONVERT_ARG_CHECKED(String, s1, 0); 10137 CONVERT_ARG_CHECKED(String, s1, 0);
10117 CONVERT_ARG_CHECKED(String, s2, 1); 10138 CONVERT_ARG_CHECKED(String, s2, 1);
10118 10139
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
10544 } else { 10565 } else {
10545 // Handle last resort GC and make sure to allow future allocations 10566 // Handle last resort GC and make sure to allow future allocations
10546 // to grow the heap without causing GCs (if possible). 10567 // to grow the heap without causing GCs (if possible).
10547 Counters::gc_last_resort_from_js.Increment(); 10568 Counters::gc_last_resort_from_js.Increment();
10548 Heap::CollectAllGarbage(false); 10569 Heap::CollectAllGarbage(false);
10549 } 10570 }
10550 } 10571 }
10551 10572
10552 10573
10553 } } // namespace v8::internal 10574 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | src/scopeinfo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698