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

Side by Side Diff: src/runtime.cc

Issue 546125: A brutal approach to V8 script liveedit (Closed)
Patch Set: merge Created 10 years, 10 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') | test/mjsunit/debug-liveedit-1.js » ('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 20 matching lines...) Expand all
31 31
32 #include "accessors.h" 32 #include "accessors.h"
33 #include "api.h" 33 #include "api.h"
34 #include "arguments.h" 34 #include "arguments.h"
35 #include "compiler.h" 35 #include "compiler.h"
36 #include "cpu.h" 36 #include "cpu.h"
37 #include "dateparser-inl.h" 37 #include "dateparser-inl.h"
38 #include "debug.h" 38 #include "debug.h"
39 #include "execution.h" 39 #include "execution.h"
40 #include "jsregexp.h" 40 #include "jsregexp.h"
41 #include "liveedit.h"
41 #include "parser.h" 42 #include "parser.h"
42 #include "platform.h" 43 #include "platform.h"
43 #include "runtime.h" 44 #include "runtime.h"
44 #include "scopeinfo.h" 45 #include "scopeinfo.h"
45 #include "smart-pointer.h" 46 #include "smart-pointer.h"
46 #include "stub-cache.h" 47 #include "stub-cache.h"
47 #include "v8threads.h" 48 #include "v8threads.h"
48 49
49 namespace v8 { 50 namespace v8 {
50 namespace internal { 51 namespace internal {
(...skipping 7853 matching lines...) Expand 10 before | Expand all | Expand 10 after
7904 7905
7905 7906
7906 static Object* Runtime_FunctionGetInferredName(Arguments args) { 7907 static Object* Runtime_FunctionGetInferredName(Arguments args) {
7907 NoHandleAllocation ha; 7908 NoHandleAllocation ha;
7908 ASSERT(args.length() == 1); 7909 ASSERT(args.length() == 1);
7909 7910
7910 CONVERT_CHECKED(JSFunction, f, args[0]); 7911 CONVERT_CHECKED(JSFunction, f, args[0]);
7911 return f->shared()->inferred_name(); 7912 return f->shared()->inferred_name();
7912 } 7913 }
7913 7914
7915
7916 static int FindFunctionInfoForScript(Script* script,
7917 FixedArray* buffer) {
7918 AssertNoAllocation no_allocations;
7919
7920 int counter = 0;
7921 int buffer_size = buffer->length();
7922 HeapIterator iterator;
7923 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) {
7924 ASSERT(obj != NULL);
7925 if (!obj->IsSharedFunctionInfo()) {
7926 continue;
7927 }
7928 SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj);
7929 if (shared->script() != script) {
7930 continue;
7931 }
7932 if (counter < buffer_size) {
7933 buffer->set(counter, shared, SKIP_WRITE_BARRIER);
7934 }
7935 counter++;
7936 }
7937 return counter;
7938 }
7939
7940 static Object* Runtime_DebugChangeScriptLive(Arguments args) {
7941 ASSERT(args.length() == 4);
7942 HandleScope scope;
7943 CONVERT_CHECKED(JSValue, script, args[0]);
7944 CONVERT_NUMBER_CHECKED(int32_t, change_pos, Int32, args[1]);
7945 CONVERT_NUMBER_CHECKED(int32_t, orig_len, Int32, args[2]);
7946 CONVERT_ARG_CHECKED(String, new_str, 3);
7947
7948 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value()));
7949
7950 const int kBufferSize = 32;
7951
7952 Handle<FixedArray> array;
7953 array = Factory::NewFixedArray(kBufferSize);
7954 int number = FindFunctionInfoForScript(*script_handle, *array);
7955 if (number > kBufferSize) {
7956 array = Factory::NewFixedArray(number);
7957 FindFunctionInfoForScript(*script_handle, *array);
7958 }
7959
7960 int new_len = new_str->length();
7961
7962 int diff = new_len - orig_len;
7963
7964 i::Handle<String> orig_source =
7965 i::Handle<String>(String::cast(script_handle->source()));
7966
7967 int new_script_len = orig_source->length() + diff;
7968
7969 Object* str_object = Heap::AllocateRawTwoByteString(new_script_len);
7970 if (str_object->IsFailure()) {
7971 return Heap::undefined_value();
7972 }
7973
7974 i::Handle<FixedArray> param_array = Factory::NewFixedArray(3);
7975 param_array->set(0, *Factory::NewSubString(orig_source, 0, change_pos));
7976 param_array->set(1, *new_str);
7977 param_array->set(2, *Factory::NewSubString(orig_source, change_pos + orig_len,
7978 orig_source->length()));
7979
7980 i::Handle<SeqTwoByteString> answer =
7981 i::Handle<SeqTwoByteString>(SeqTwoByteString::cast(str_object));
7982
7983 StringBuilderConcatHelper(Heap::empty_string(),
7984 answer->GetChars(),
7985 *param_array,
7986 3);
7987
7988 ChangeScriptLive(script_handle, orig_source, answer,
7989 array, number,
7990 change_pos, orig_len, new_len);
7991
7992 return Heap::undefined_value();
7993 }
7994
7914 #endif // ENABLE_DEBUGGER_SUPPORT 7995 #endif // ENABLE_DEBUGGER_SUPPORT
7915 7996
7997
7998
7916 #ifdef ENABLE_LOGGING_AND_PROFILING 7999 #ifdef ENABLE_LOGGING_AND_PROFILING
7917 8000
7918 static Object* Runtime_ProfilerResume(Arguments args) { 8001 static Object* Runtime_ProfilerResume(Arguments args) {
7919 NoHandleAllocation ha; 8002 NoHandleAllocation ha;
7920 ASSERT(args.length() == 2); 8003 ASSERT(args.length() == 2);
7921 8004
7922 CONVERT_CHECKED(Smi, smi_modules, args[0]); 8005 CONVERT_CHECKED(Smi, smi_modules, args[0]);
7923 CONVERT_CHECKED(Smi, smi_tag, args[1]); 8006 CONVERT_CHECKED(Smi, smi_tag, args[1]);
7924 v8::V8::ResumeProfilerEx(smi_modules->value(), smi_tag->value()); 8007 v8::V8::ResumeProfilerEx(smi_modules->value(), smi_tag->value());
7925 return Heap::undefined_value(); 8008 return Heap::undefined_value();
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
8179 } else { 8262 } else {
8180 // Handle last resort GC and make sure to allow future allocations 8263 // Handle last resort GC and make sure to allow future allocations
8181 // to grow the heap without causing GCs (if possible). 8264 // to grow the heap without causing GCs (if possible).
8182 Counters::gc_last_resort_from_js.Increment(); 8265 Counters::gc_last_resort_from_js.Increment();
8183 Heap::CollectAllGarbage(false); 8266 Heap::CollectAllGarbage(false);
8184 } 8267 }
8185 } 8268 }
8186 8269
8187 8270
8188 } } // namespace v8::internal 8271 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | test/mjsunit/debug-liveedit-1.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698