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