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 27 matching lines...) Expand all Loading... |
38 #include "dateparser-inl.h" | 38 #include "dateparser-inl.h" |
39 #include "debug.h" | 39 #include "debug.h" |
40 #include "execution.h" | 40 #include "execution.h" |
41 #include "jsregexp.h" | 41 #include "jsregexp.h" |
42 #include "platform.h" | 42 #include "platform.h" |
43 #include "runtime.h" | 43 #include "runtime.h" |
44 #include "scopeinfo.h" | 44 #include "scopeinfo.h" |
45 #include "v8threads.h" | 45 #include "v8threads.h" |
46 #include "smart-pointer.h" | 46 #include "smart-pointer.h" |
47 #include "parser.h" | 47 #include "parser.h" |
| 48 #include "stub-cache.h" |
48 | 49 |
49 namespace v8 { | 50 namespace v8 { |
50 namespace internal { | 51 namespace internal { |
51 | 52 |
52 | 53 |
53 #define RUNTIME_ASSERT(value) \ | 54 #define RUNTIME_ASSERT(value) \ |
54 if (!(value)) return Top::ThrowIllegalOperation(); | 55 if (!(value)) return Top::ThrowIllegalOperation(); |
55 | 56 |
56 // Cast the given object to a value of the specified type and store | 57 // Cast the given object to a value of the specified type and store |
57 // it in a variable with the given name. If the object is not of the | 58 // it in a variable with the given name. If the object is not of the |
(...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1228 // function. | 1229 // function. |
1229 target->set_code(fun->code()); | 1230 target->set_code(fun->code()); |
1230 target->shared()->set_length(fun->shared()->length()); | 1231 target->shared()->set_length(fun->shared()->length()); |
1231 target->shared()->set_formal_parameter_count( | 1232 target->shared()->set_formal_parameter_count( |
1232 fun->shared()->formal_parameter_count()); | 1233 fun->shared()->formal_parameter_count()); |
1233 // Set the source code of the target function to undefined. | 1234 // Set the source code of the target function to undefined. |
1234 // SetCode is only used for built-in constructors like String, | 1235 // SetCode is only used for built-in constructors like String, |
1235 // Array, and Object, and some web code | 1236 // Array, and Object, and some web code |
1236 // doesn't like seeing source code for constructors. | 1237 // doesn't like seeing source code for constructors. |
1237 target->shared()->set_script(Heap::undefined_value()); | 1238 target->shared()->set_script(Heap::undefined_value()); |
| 1239 // Clear the optimization hints related to the compiled code as these are no |
| 1240 // longer valid when the code is overwritten. |
| 1241 target->shared()->ClearThisPropertyAssignmentsInfo(); |
1238 context = Handle<Context>(fun->context()); | 1242 context = Handle<Context>(fun->context()); |
1239 | 1243 |
1240 // Make sure we get a fresh copy of the literal vector to avoid | 1244 // Make sure we get a fresh copy of the literal vector to avoid |
1241 // cross context contamination. | 1245 // cross context contamination. |
1242 int number_of_literals = fun->NumberOfLiterals(); | 1246 int number_of_literals = fun->NumberOfLiterals(); |
1243 Handle<FixedArray> literals = | 1247 Handle<FixedArray> literals = |
1244 Factory::NewFixedArray(number_of_literals, TENURED); | 1248 Factory::NewFixedArray(number_of_literals, TENURED); |
1245 if (number_of_literals > 0) { | 1249 if (number_of_literals > 0) { |
1246 // Insert the object, regexp and array functions in the literals | 1250 // Insert the object, regexp and array functions in the literals |
1247 // array prefix. These are the functions that will be used when | 1251 // array prefix. These are the functions that will be used when |
(...skipping 3071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4319 ASSERT(args.length() == 2); | 4323 ASSERT(args.length() == 2); |
4320 CONVERT_ARG_CHECKED(JSFunction, boilerplate, 0); | 4324 CONVERT_ARG_CHECKED(JSFunction, boilerplate, 0); |
4321 CONVERT_ARG_CHECKED(Context, context, 1); | 4325 CONVERT_ARG_CHECKED(Context, context, 1); |
4322 | 4326 |
4323 Handle<JSFunction> result = | 4327 Handle<JSFunction> result = |
4324 Factory::NewFunctionFromBoilerplate(boilerplate, context); | 4328 Factory::NewFunctionFromBoilerplate(boilerplate, context); |
4325 return *result; | 4329 return *result; |
4326 } | 4330 } |
4327 | 4331 |
4328 | 4332 |
4329 static Handle<Code> ComputeConstructStub(Handle<Map> map) { | 4333 static Code* ComputeConstructStub(Handle<SharedFunctionInfo> shared) { |
4330 // TODO(385): Change this to create a construct stub specialized for | 4334 // TODO(385): Change this to create a construct stub specialized for |
4331 // the given map to make allocation of simple objects - and maybe | 4335 // the given map to make allocation of simple objects - and maybe |
4332 // arrays - much faster. | 4336 // arrays - much faster. |
4333 return Handle<Code>(Builtins::builtin(Builtins::JSConstructStubGeneric)); | 4337 if (FLAG_inline_new |
| 4338 && shared->has_only_simple_this_property_assignments()) { |
| 4339 ConstructStubCompiler compiler; |
| 4340 Object* code = compiler.CompileConstructStub(*shared); |
| 4341 if (code->IsFailure()) { |
| 4342 return Builtins::builtin(Builtins::JSConstructStubGeneric); |
| 4343 } |
| 4344 return Code::cast(code); |
| 4345 } |
| 4346 |
| 4347 return Builtins::builtin(Builtins::JSConstructStubGeneric); |
4334 } | 4348 } |
4335 | 4349 |
4336 | 4350 |
4337 static Object* Runtime_NewObject(Arguments args) { | 4351 static Object* Runtime_NewObject(Arguments args) { |
4338 HandleScope scope; | 4352 HandleScope scope; |
4339 ASSERT(args.length() == 1); | 4353 ASSERT(args.length() == 1); |
4340 | 4354 |
4341 Handle<Object> constructor = args.at<Object>(0); | 4355 Handle<Object> constructor = args.at<Object>(0); |
4342 | 4356 |
4343 // If the constructor isn't a proper function we throw a type error. | 4357 // If the constructor isn't a proper function we throw a type error. |
(...skipping 24 matching lines...) Expand all Loading... |
4368 // ignored anyway, we use the global object as the receiver | 4382 // ignored anyway, we use the global object as the receiver |
4369 // instead of a new JSFunction object. This way, errors are | 4383 // instead of a new JSFunction object. This way, errors are |
4370 // reported the same way whether or not 'Function' is called | 4384 // reported the same way whether or not 'Function' is called |
4371 // using 'new'. | 4385 // using 'new'. |
4372 return Top::context()->global(); | 4386 return Top::context()->global(); |
4373 } | 4387 } |
4374 } | 4388 } |
4375 | 4389 |
4376 // The function should be compiled for the optimization hints to be available. | 4390 // The function should be compiled for the optimization hints to be available. |
4377 if (!function->shared()->is_compiled()) { | 4391 if (!function->shared()->is_compiled()) { |
4378 CompileLazyShared(Handle<SharedFunctionInfo>(function->shared()), | 4392 CompileLazyShared(Handle<SharedFunctionInfo>(function->shared()), |
4379 CLEAR_EXCEPTION, | 4393 CLEAR_EXCEPTION, |
4380 0); | 4394 0); |
4381 } | 4395 } |
4382 | 4396 |
4383 bool first_allocation = !function->has_initial_map(); | 4397 bool first_allocation = !function->has_initial_map(); |
4384 Handle<JSObject> result = Factory::NewJSObject(function); | 4398 Handle<JSObject> result = Factory::NewJSObject(function); |
4385 if (first_allocation) { | 4399 if (first_allocation) { |
4386 Handle<Map> map = Handle<Map>(function->initial_map()); | 4400 Handle<Map> map = Handle<Map>(function->initial_map()); |
4387 Handle<Code> stub = ComputeConstructStub(map); | 4401 Handle<Code> stub = Handle<Code>( |
| 4402 ComputeConstructStub(Handle<SharedFunctionInfo>(function->shared()))); |
4388 function->shared()->set_construct_stub(*stub); | 4403 function->shared()->set_construct_stub(*stub); |
4389 } | 4404 } |
| 4405 |
4390 Counters::constructed_objects.Increment(); | 4406 Counters::constructed_objects.Increment(); |
4391 Counters::constructed_objects_runtime.Increment(); | 4407 Counters::constructed_objects_runtime.Increment(); |
| 4408 |
4392 return *result; | 4409 return *result; |
4393 } | 4410 } |
4394 | 4411 |
4395 | 4412 |
4396 static Object* Runtime_LazyCompile(Arguments args) { | 4413 static Object* Runtime_LazyCompile(Arguments args) { |
4397 HandleScope scope; | 4414 HandleScope scope; |
4398 ASSERT(args.length() == 1); | 4415 ASSERT(args.length() == 1); |
4399 | 4416 |
4400 Handle<JSFunction> function = args.at<JSFunction>(0); | 4417 Handle<JSFunction> function = args.at<JSFunction>(0); |
4401 #ifdef DEBUG | 4418 #ifdef DEBUG |
(...skipping 2984 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7386 } | 7403 } |
7387 | 7404 |
7388 | 7405 |
7389 static Object* Runtime_SystemBreak(Arguments args) { | 7406 static Object* Runtime_SystemBreak(Arguments args) { |
7390 ASSERT(args.length() == 0); | 7407 ASSERT(args.length() == 0); |
7391 CPU::DebugBreak(); | 7408 CPU::DebugBreak(); |
7392 return Heap::undefined_value(); | 7409 return Heap::undefined_value(); |
7393 } | 7410 } |
7394 | 7411 |
7395 | 7412 |
7396 static Object* Runtime_FunctionGetAssemblerCode(Arguments args) { | 7413 static Object* Runtime_DebugDisassembleFunction(Arguments args) { |
7397 #ifdef DEBUG | 7414 #ifdef DEBUG |
7398 HandleScope scope; | 7415 HandleScope scope; |
7399 ASSERT(args.length() == 1); | 7416 ASSERT(args.length() == 1); |
7400 // Get the function and make sure it is compiled. | 7417 // Get the function and make sure it is compiled. |
7401 CONVERT_ARG_CHECKED(JSFunction, func, 0); | 7418 CONVERT_ARG_CHECKED(JSFunction, func, 0); |
7402 if (!func->is_compiled() && !CompileLazy(func, KEEP_EXCEPTION)) { | 7419 if (!func->is_compiled() && !CompileLazy(func, KEEP_EXCEPTION)) { |
7403 return Failure::Exception(); | 7420 return Failure::Exception(); |
7404 } | 7421 } |
7405 func->code()->PrintLn(); | 7422 func->code()->PrintLn(); |
7406 #endif // DEBUG | 7423 #endif // DEBUG |
7407 return Heap::undefined_value(); | 7424 return Heap::undefined_value(); |
7408 } | 7425 } |
7409 | 7426 |
7410 | 7427 |
| 7428 static Object* Runtime_DebugDisassembleConstructor(Arguments args) { |
| 7429 #ifdef DEBUG |
| 7430 HandleScope scope; |
| 7431 ASSERT(args.length() == 1); |
| 7432 // Get the function and make sure it is compiled. |
| 7433 CONVERT_ARG_CHECKED(JSFunction, func, 0); |
| 7434 if (!func->is_compiled() && !CompileLazy(func, KEEP_EXCEPTION)) { |
| 7435 return Failure::Exception(); |
| 7436 } |
| 7437 func->shared()->construct_stub()->PrintLn(); |
| 7438 #endif // DEBUG |
| 7439 return Heap::undefined_value(); |
| 7440 } |
| 7441 |
| 7442 |
7411 static Object* Runtime_FunctionGetInferredName(Arguments args) { | 7443 static Object* Runtime_FunctionGetInferredName(Arguments args) { |
7412 NoHandleAllocation ha; | 7444 NoHandleAllocation ha; |
7413 ASSERT(args.length() == 1); | 7445 ASSERT(args.length() == 1); |
7414 | 7446 |
7415 CONVERT_CHECKED(JSFunction, f, args[0]); | 7447 CONVERT_CHECKED(JSFunction, f, args[0]); |
7416 return f->shared()->inferred_name(); | 7448 return f->shared()->inferred_name(); |
7417 } | 7449 } |
7418 #endif // ENABLE_DEBUGGER_SUPPORT | 7450 #endif // ENABLE_DEBUGGER_SUPPORT |
7419 | 7451 |
7420 | 7452 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7639 } else { | 7671 } else { |
7640 // Handle last resort GC and make sure to allow future allocations | 7672 // Handle last resort GC and make sure to allow future allocations |
7641 // to grow the heap without causing GCs (if possible). | 7673 // to grow the heap without causing GCs (if possible). |
7642 Counters::gc_last_resort_from_js.Increment(); | 7674 Counters::gc_last_resort_from_js.Increment(); |
7643 Heap::CollectAllGarbage(false); | 7675 Heap::CollectAllGarbage(false); |
7644 } | 7676 } |
7645 } | 7677 } |
7646 | 7678 |
7647 | 7679 |
7648 } } // namespace v8::internal | 7680 } } // namespace v8::internal |
OLD | NEW |