OLD | NEW |
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 Loading... |
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 8233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8284 | 8285 |
8285 | 8286 |
8286 static Object* Runtime_FunctionGetInferredName(Arguments args) { | 8287 static Object* Runtime_FunctionGetInferredName(Arguments args) { |
8287 NoHandleAllocation ha; | 8288 NoHandleAllocation ha; |
8288 ASSERT(args.length() == 1); | 8289 ASSERT(args.length() == 1); |
8289 | 8290 |
8290 CONVERT_CHECKED(JSFunction, f, args[0]); | 8291 CONVERT_CHECKED(JSFunction, f, args[0]); |
8291 return f->shared()->inferred_name(); | 8292 return f->shared()->inferred_name(); |
8292 } | 8293 } |
8293 | 8294 |
| 8295 |
| 8296 static int FindSharedFunctionInfosForScript(Script* script, |
| 8297 FixedArray* buffer) { |
| 8298 AssertNoAllocation no_allocations; |
| 8299 |
| 8300 int counter = 0; |
| 8301 int buffer_size = buffer->length(); |
| 8302 HeapIterator iterator; |
| 8303 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
| 8304 ASSERT(obj != NULL); |
| 8305 if (!obj->IsSharedFunctionInfo()) { |
| 8306 continue; |
| 8307 } |
| 8308 SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj); |
| 8309 if (shared->script() != script) { |
| 8310 continue; |
| 8311 } |
| 8312 if (counter < buffer_size) { |
| 8313 buffer->set(counter, shared); |
| 8314 } |
| 8315 counter++; |
| 8316 } |
| 8317 return counter; |
| 8318 } |
| 8319 |
| 8320 // For a script finds all SharedFunctionInfo's in the heap that points |
| 8321 // to this script. Returns JSArray of SharedFunctionInfo wrapped |
| 8322 // in OpaqueReferences. |
| 8323 static Object* Runtime_LiveEditFindSharedFunctionInfosForScript( |
| 8324 Arguments args) { |
| 8325 ASSERT(args.length() == 1); |
| 8326 HandleScope scope; |
| 8327 CONVERT_CHECKED(JSValue, script_value, args[0]); |
| 8328 |
| 8329 Handle<Script> script = Handle<Script>(Script::cast(script_value->value())); |
| 8330 |
| 8331 const int kBufferSize = 32; |
| 8332 |
| 8333 Handle<FixedArray> array; |
| 8334 array = Factory::NewFixedArray(kBufferSize); |
| 8335 int number = FindSharedFunctionInfosForScript(*script, *array); |
| 8336 if (number > kBufferSize) { |
| 8337 array = Factory::NewFixedArray(number); |
| 8338 FindSharedFunctionInfosForScript(*script, *array); |
| 8339 } |
| 8340 |
| 8341 Handle<JSArray> result = Factory::NewJSArrayWithElements(array); |
| 8342 result->set_length(Smi::FromInt(number)); |
| 8343 |
| 8344 LiveEdit::WrapSharedFunctionInfos(result); |
| 8345 |
| 8346 return *result; |
| 8347 } |
| 8348 |
| 8349 // For a script calculates compilation information about all its functions. |
| 8350 // The script source is explicitly specified by the second argument. |
| 8351 // The source of the actual script is not used, however it is important that |
| 8352 // all generated code keeps references to this particular instance of script. |
| 8353 // Returns a JSArray of compilation infos. The array is ordered so that |
| 8354 // each function with all its descendant is always stored in a continues range |
| 8355 // with the function itself going first. The root function is a script function. |
| 8356 static Object* Runtime_LiveEditGatherCompileInfo(Arguments args) { |
| 8357 ASSERT(args.length() == 2); |
| 8358 HandleScope scope; |
| 8359 CONVERT_CHECKED(JSValue, script, args[0]); |
| 8360 CONVERT_ARG_CHECKED(String, source, 1); |
| 8361 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value())); |
| 8362 |
| 8363 JSArray* result = LiveEdit::GatherCompileInfo(script_handle, source); |
| 8364 |
| 8365 if (Top::has_pending_exception()) { |
| 8366 return Failure::Exception(); |
| 8367 } |
| 8368 |
| 8369 return result; |
| 8370 } |
| 8371 |
| 8372 // Changes the source of the script to a new_source and creates a new |
| 8373 // script representing the old version of the script source. |
| 8374 static Object* Runtime_LiveEditReplaceScript(Arguments args) { |
| 8375 ASSERT(args.length() == 3); |
| 8376 HandleScope scope; |
| 8377 CONVERT_CHECKED(JSValue, original_script_value, args[0]); |
| 8378 CONVERT_ARG_CHECKED(String, new_source, 1); |
| 8379 CONVERT_ARG_CHECKED(String, old_script_name, 2); |
| 8380 Handle<Script> original_script = |
| 8381 Handle<Script>(Script::cast(original_script_value->value())); |
| 8382 |
| 8383 Handle<String> original_source(String::cast(original_script->source())); |
| 8384 |
| 8385 original_script->set_source(*new_source); |
| 8386 Handle<Script> old_script = Factory::NewScript(original_source); |
| 8387 old_script->set_name(*old_script_name); |
| 8388 old_script->set_line_offset(original_script->line_offset()); |
| 8389 old_script->set_column_offset(original_script->column_offset()); |
| 8390 old_script->set_data(original_script->data()); |
| 8391 old_script->set_type(original_script->type()); |
| 8392 old_script->set_context_data(original_script->context_data()); |
| 8393 old_script->set_compilation_type(original_script->compilation_type()); |
| 8394 old_script->set_eval_from_shared(original_script->eval_from_shared()); |
| 8395 old_script->set_eval_from_instructions_offset( |
| 8396 original_script->eval_from_instructions_offset()); |
| 8397 |
| 8398 |
| 8399 Debugger::OnAfterCompile(old_script, Debugger::SEND_WHEN_DEBUGGING); |
| 8400 |
| 8401 return *(GetScriptWrapper(old_script)); |
| 8402 } |
| 8403 |
| 8404 // Replaces code of SharedFunctionInfo with a new one. |
| 8405 static Object* Runtime_LiveEditReplaceFunctionCode(Arguments args) { |
| 8406 ASSERT(args.length() == 2); |
| 8407 HandleScope scope; |
| 8408 CONVERT_ARG_CHECKED(JSArray, new_compile_info, 0); |
| 8409 CONVERT_ARG_CHECKED(JSArray, shared_info, 1); |
| 8410 |
| 8411 LiveEdit::ReplaceFunctionCode(new_compile_info, shared_info); |
| 8412 |
| 8413 return Heap::undefined_value(); |
| 8414 } |
| 8415 |
| 8416 // Connects SharedFunctionInfo to another script. |
| 8417 static Object* Runtime_LiveEditRelinkFunctionToScript(Arguments args) { |
| 8418 ASSERT(args.length() == 2); |
| 8419 HandleScope scope; |
| 8420 CONVERT_ARG_CHECKED(JSArray, shared_info_array, 0); |
| 8421 CONVERT_ARG_CHECKED(JSValue, script_value, 1); |
| 8422 Handle<Script> script = Handle<Script>(Script::cast(script_value->value())); |
| 8423 |
| 8424 LiveEdit::RelinkFunctionToScript(shared_info_array, script); |
| 8425 |
| 8426 return Heap::undefined_value(); |
| 8427 } |
| 8428 |
| 8429 // Updates positions of a shared function info (first parameter) according |
| 8430 // to script source change. Text change is described in second parameter as |
| 8431 // array of groups of 3 numbers: |
| 8432 // (change_begin, change_end, change_end_new_position). |
| 8433 // Each group describes a change in text; groups are sorted by change_begin. |
| 8434 static Object* Runtime_LiveEditPatchFunctionPositions(Arguments args) { |
| 8435 ASSERT(args.length() == 2); |
| 8436 HandleScope scope; |
| 8437 CONVERT_ARG_CHECKED(JSArray, shared_array, 0); |
| 8438 CONVERT_ARG_CHECKED(JSArray, position_change_array, 1); |
| 8439 |
| 8440 LiveEdit::PatchFunctionPositions(shared_array, position_change_array); |
| 8441 |
| 8442 return Heap::undefined_value(); |
| 8443 } |
| 8444 |
| 8445 |
8294 #endif // ENABLE_DEBUGGER_SUPPORT | 8446 #endif // ENABLE_DEBUGGER_SUPPORT |
8295 | 8447 |
8296 #ifdef ENABLE_LOGGING_AND_PROFILING | 8448 #ifdef ENABLE_LOGGING_AND_PROFILING |
8297 | 8449 |
8298 static Object* Runtime_ProfilerResume(Arguments args) { | 8450 static Object* Runtime_ProfilerResume(Arguments args) { |
8299 NoHandleAllocation ha; | 8451 NoHandleAllocation ha; |
8300 ASSERT(args.length() == 2); | 8452 ASSERT(args.length() == 2); |
8301 | 8453 |
8302 CONVERT_CHECKED(Smi, smi_modules, args[0]); | 8454 CONVERT_CHECKED(Smi, smi_modules, args[0]); |
8303 CONVERT_CHECKED(Smi, smi_tag, args[1]); | 8455 CONVERT_CHECKED(Smi, smi_tag, args[1]); |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8559 } else { | 8711 } else { |
8560 // Handle last resort GC and make sure to allow future allocations | 8712 // Handle last resort GC and make sure to allow future allocations |
8561 // to grow the heap without causing GCs (if possible). | 8713 // to grow the heap without causing GCs (if possible). |
8562 Counters::gc_last_resort_from_js.Increment(); | 8714 Counters::gc_last_resort_from_js.Increment(); |
8563 Heap::CollectAllGarbage(false); | 8715 Heap::CollectAllGarbage(false); |
8564 } | 8716 } |
8565 } | 8717 } |
8566 | 8718 |
8567 | 8719 |
8568 } } // namespace v8::internal | 8720 } } // namespace v8::internal |
OLD | NEW |