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 1387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1398 ASSERT(args.length() == 2); | 1398 ASSERT(args.length() == 2); |
1399 | 1399 |
1400 CONVERT_ARG_CHECKED(JSFunction, target, 0); | 1400 CONVERT_ARG_CHECKED(JSFunction, target, 0); |
1401 Handle<Object> code = args.at<Object>(1); | 1401 Handle<Object> code = args.at<Object>(1); |
1402 | 1402 |
1403 Handle<Context> context(target->context()); | 1403 Handle<Context> context(target->context()); |
1404 | 1404 |
1405 if (!code->IsNull()) { | 1405 if (!code->IsNull()) { |
1406 RUNTIME_ASSERT(code->IsJSFunction()); | 1406 RUNTIME_ASSERT(code->IsJSFunction()); |
1407 Handle<JSFunction> fun = Handle<JSFunction>::cast(code); | 1407 Handle<JSFunction> fun = Handle<JSFunction>::cast(code); |
1408 SetExpectedNofProperties(target, fun->shared()->expected_nof_properties()); | 1408 Handle<SharedFunctionInfo> shared(fun->shared()); |
1409 if (!fun->is_compiled() && !CompileLazy(fun, KEEP_EXCEPTION)) { | 1409 SetExpectedNofProperties(target, shared->expected_nof_properties()); |
| 1410 |
| 1411 if (!EnsureCompiled(shared, KEEP_EXCEPTION)) { |
1410 return Failure::Exception(); | 1412 return Failure::Exception(); |
1411 } | 1413 } |
1412 // Set the code, formal parameter count, and the length of the target | 1414 // Set the code, formal parameter count, and the length of the target |
1413 // function. | 1415 // function. |
1414 target->set_code(fun->code()); | 1416 target->set_code(fun->code()); |
1415 target->shared()->set_length(fun->shared()->length()); | 1417 target->shared()->set_length(shared->length()); |
1416 target->shared()->set_formal_parameter_count( | 1418 target->shared()->set_formal_parameter_count( |
1417 fun->shared()->formal_parameter_count()); | 1419 shared->formal_parameter_count()); |
1418 // Set the source code of the target function to undefined. | 1420 // Set the source code of the target function to undefined. |
1419 // SetCode is only used for built-in constructors like String, | 1421 // SetCode is only used for built-in constructors like String, |
1420 // Array, and Object, and some web code | 1422 // Array, and Object, and some web code |
1421 // doesn't like seeing source code for constructors. | 1423 // doesn't like seeing source code for constructors. |
1422 target->shared()->set_script(Heap::undefined_value()); | 1424 target->shared()->set_script(Heap::undefined_value()); |
1423 // Clear the optimization hints related to the compiled code as these are no | 1425 // Clear the optimization hints related to the compiled code as these are no |
1424 // longer valid when the code is overwritten. | 1426 // longer valid when the code is overwritten. |
1425 target->shared()->ClearThisPropertyAssignmentsInfo(); | 1427 target->shared()->ClearThisPropertyAssignmentsInfo(); |
1426 context = Handle<Context>(fun->context()); | 1428 context = Handle<Context>(fun->context()); |
1427 | 1429 |
(...skipping 3391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4819 // the shared part of the function. Since the receiver is | 4821 // the shared part of the function. Since the receiver is |
4820 // ignored anyway, we use the global object as the receiver | 4822 // ignored anyway, we use the global object as the receiver |
4821 // instead of a new JSFunction object. This way, errors are | 4823 // instead of a new JSFunction object. This way, errors are |
4822 // reported the same way whether or not 'Function' is called | 4824 // reported the same way whether or not 'Function' is called |
4823 // using 'new'. | 4825 // using 'new'. |
4824 return Top::context()->global(); | 4826 return Top::context()->global(); |
4825 } | 4827 } |
4826 } | 4828 } |
4827 | 4829 |
4828 // The function should be compiled for the optimization hints to be available. | 4830 // The function should be compiled for the optimization hints to be available. |
4829 if (!function->shared()->is_compiled()) { | 4831 Handle<SharedFunctionInfo> shared(function->shared()); |
4830 CompileLazyShared(Handle<SharedFunctionInfo>(function->shared()), | 4832 EnsureCompiled(shared, CLEAR_EXCEPTION); |
4831 CLEAR_EXCEPTION, | |
4832 0); | |
4833 LOG(FunctionCreateEvent(*function)); | |
4834 } | |
4835 | 4833 |
4836 bool first_allocation = !function->has_initial_map(); | 4834 bool first_allocation = !function->has_initial_map(); |
4837 Handle<JSObject> result = Factory::NewJSObject(function); | 4835 Handle<JSObject> result = Factory::NewJSObject(function); |
4838 if (first_allocation) { | 4836 if (first_allocation) { |
4839 Handle<Map> map = Handle<Map>(function->initial_map()); | 4837 Handle<Map> map = Handle<Map>(function->initial_map()); |
4840 Handle<Code> stub = Handle<Code>( | 4838 Handle<Code> stub = Handle<Code>( |
4841 ComputeConstructStub(Handle<SharedFunctionInfo>(function->shared()))); | 4839 ComputeConstructStub(Handle<SharedFunctionInfo>(function->shared()))); |
4842 function->shared()->set_construct_stub(*stub); | 4840 function->shared()->set_construct_stub(*stub); |
4843 } | 4841 } |
4844 | 4842 |
(...skipping 18 matching lines...) Expand all Loading... |
4863 #endif | 4861 #endif |
4864 | 4862 |
4865 // Compile the target function. Here we compile using CompileLazyInLoop in | 4863 // Compile the target function. Here we compile using CompileLazyInLoop in |
4866 // order to get the optimized version. This helps code like delta-blue | 4864 // order to get the optimized version. This helps code like delta-blue |
4867 // that calls performance-critical routines through constructors. A | 4865 // that calls performance-critical routines through constructors. A |
4868 // constructor call doesn't use a CallIC, it uses a LoadIC followed by a | 4866 // constructor call doesn't use a CallIC, it uses a LoadIC followed by a |
4869 // direct call. Since the in-loop tracking takes place through CallICs | 4867 // direct call. Since the in-loop tracking takes place through CallICs |
4870 // this means that things called through constructors are never known to | 4868 // this means that things called through constructors are never known to |
4871 // be in loops. We compile them as if they are in loops here just in case. | 4869 // be in loops. We compile them as if they are in loops here just in case. |
4872 ASSERT(!function->is_compiled()); | 4870 ASSERT(!function->is_compiled()); |
4873 if (!CompileLazyInLoop(function, KEEP_EXCEPTION)) { | 4871 if (!CompileLazyInLoop(function, Handle<Object>::null(), KEEP_EXCEPTION)) { |
4874 return Failure::Exception(); | 4872 return Failure::Exception(); |
4875 } | 4873 } |
4876 | 4874 |
4877 return function->code(); | 4875 return function->code(); |
4878 } | 4876 } |
4879 | 4877 |
4880 | 4878 |
4881 static Object* Runtime_GetCalledFunction(Arguments args) { | 4879 static Object* Runtime_GetCalledFunction(Arguments args) { |
4882 HandleScope scope; | 4880 HandleScope scope; |
4883 ASSERT(args.length() == 0); | 4881 ASSERT(args.length() == 0); |
(...skipping 2387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7271 } | 7269 } |
7272 } | 7270 } |
7273 | 7271 |
7274 // If the candidate found is compiled we are done. NOTE: when lazy | 7272 // If the candidate found is compiled we are done. NOTE: when lazy |
7275 // compilation of inner functions is introduced some additional checking | 7273 // compilation of inner functions is introduced some additional checking |
7276 // needs to be done here to compile inner functions. | 7274 // needs to be done here to compile inner functions. |
7277 done = target->is_compiled(); | 7275 done = target->is_compiled(); |
7278 if (!done) { | 7276 if (!done) { |
7279 // If the candidate is not compiled compile it to reveal any inner | 7277 // If the candidate is not compiled compile it to reveal any inner |
7280 // functions which might contain the requested source position. | 7278 // functions which might contain the requested source position. |
7281 CompileLazyShared(target, KEEP_EXCEPTION, 0); | 7279 CompileLazyShared(target, KEEP_EXCEPTION); |
7282 } | 7280 } |
7283 } | 7281 } |
7284 | 7282 |
7285 return *target; | 7283 return *target; |
7286 } | 7284 } |
7287 | 7285 |
7288 | 7286 |
7289 // Change the state of a break point in a script. NOTE: Regarding performance | 7287 // Change the state of a break point in a script. NOTE: Regarding performance |
7290 // see the NOTE for GetScriptFromScriptData. | 7288 // see the NOTE for GetScriptFromScriptData. |
7291 // args[0]: script to set break point in | 7289 // args[0]: script to set break point in |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7857 return Heap::undefined_value(); | 7855 return Heap::undefined_value(); |
7858 } | 7856 } |
7859 | 7857 |
7860 | 7858 |
7861 static Object* Runtime_DebugDisassembleFunction(Arguments args) { | 7859 static Object* Runtime_DebugDisassembleFunction(Arguments args) { |
7862 #ifdef DEBUG | 7860 #ifdef DEBUG |
7863 HandleScope scope; | 7861 HandleScope scope; |
7864 ASSERT(args.length() == 1); | 7862 ASSERT(args.length() == 1); |
7865 // Get the function and make sure it is compiled. | 7863 // Get the function and make sure it is compiled. |
7866 CONVERT_ARG_CHECKED(JSFunction, func, 0); | 7864 CONVERT_ARG_CHECKED(JSFunction, func, 0); |
7867 if (!func->is_compiled() && !CompileLazy(func, KEEP_EXCEPTION)) { | 7865 Handle<SharedFunctionInfo> shared(func->shared()); |
| 7866 if (!EnsureCompiled(shared, KEEP_EXCEPTION)) { |
7868 return Failure::Exception(); | 7867 return Failure::Exception(); |
7869 } | 7868 } |
7870 func->code()->PrintLn(); | 7869 func->code()->PrintLn(); |
7871 #endif // DEBUG | 7870 #endif // DEBUG |
7872 return Heap::undefined_value(); | 7871 return Heap::undefined_value(); |
7873 } | 7872 } |
7874 | 7873 |
7875 | 7874 |
7876 static Object* Runtime_DebugDisassembleConstructor(Arguments args) { | 7875 static Object* Runtime_DebugDisassembleConstructor(Arguments args) { |
7877 #ifdef DEBUG | 7876 #ifdef DEBUG |
7878 HandleScope scope; | 7877 HandleScope scope; |
7879 ASSERT(args.length() == 1); | 7878 ASSERT(args.length() == 1); |
7880 // Get the function and make sure it is compiled. | 7879 // Get the function and make sure it is compiled. |
7881 CONVERT_ARG_CHECKED(JSFunction, func, 0); | 7880 CONVERT_ARG_CHECKED(JSFunction, func, 0); |
7882 if (!func->is_compiled() && !CompileLazy(func, KEEP_EXCEPTION)) { | 7881 Handle<SharedFunctionInfo> shared(func->shared()); |
| 7882 if (!EnsureCompiled(shared, KEEP_EXCEPTION)) { |
7883 return Failure::Exception(); | 7883 return Failure::Exception(); |
7884 } | 7884 } |
7885 func->shared()->construct_stub()->PrintLn(); | 7885 shared->construct_stub()->PrintLn(); |
7886 #endif // DEBUG | 7886 #endif // DEBUG |
7887 return Heap::undefined_value(); | 7887 return Heap::undefined_value(); |
7888 } | 7888 } |
7889 | 7889 |
7890 | 7890 |
7891 static Object* Runtime_FunctionGetInferredName(Arguments args) { | 7891 static Object* Runtime_FunctionGetInferredName(Arguments args) { |
7892 NoHandleAllocation ha; | 7892 NoHandleAllocation ha; |
7893 ASSERT(args.length() == 1); | 7893 ASSERT(args.length() == 1); |
7894 | 7894 |
7895 CONVERT_CHECKED(JSFunction, f, args[0]); | 7895 CONVERT_CHECKED(JSFunction, f, args[0]); |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8163 } else { | 8163 } else { |
8164 // Handle last resort GC and make sure to allow future allocations | 8164 // Handle last resort GC and make sure to allow future allocations |
8165 // to grow the heap without causing GCs (if possible). | 8165 // to grow the heap without causing GCs (if possible). |
8166 Counters::gc_last_resort_from_js.Increment(); | 8166 Counters::gc_last_resort_from_js.Increment(); |
8167 Heap::CollectAllGarbage(false); | 8167 Heap::CollectAllGarbage(false); |
8168 } | 8168 } |
8169 } | 8169 } |
8170 | 8170 |
8171 | 8171 |
8172 } } // namespace v8::internal | 8172 } } // namespace v8::internal |
OLD | NEW |