OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 17 matching lines...) Expand all Loading... |
28 #include "v8.h" | 28 #include "v8.h" |
29 | 29 |
30 #include "api.h" | 30 #include "api.h" |
31 #include "arguments.h" | 31 #include "arguments.h" |
32 #include "bootstrapper.h" | 32 #include "bootstrapper.h" |
33 #include "builtins.h" | 33 #include "builtins.h" |
34 #include "gdb-jit.h" | 34 #include "gdb-jit.h" |
35 #include "ic-inl.h" | 35 #include "ic-inl.h" |
36 #include "heap-profiler.h" | 36 #include "heap-profiler.h" |
37 #include "mark-compact.h" | 37 #include "mark-compact.h" |
38 #include "stub-cache.h" | |
39 #include "vm-state-inl.h" | 38 #include "vm-state-inl.h" |
40 | 39 |
41 namespace v8 { | 40 namespace v8 { |
42 namespace internal { | 41 namespace internal { |
43 | 42 |
44 namespace { | 43 namespace { |
45 | 44 |
46 // Arguments object passed to C++ builtins. | 45 // Arguments object passed to C++ builtins. |
47 template <BuiltinExtraArguments extra_args> | 46 template <BuiltinExtraArguments extra_args> |
48 class BuiltinArguments : public Arguments { | 47 class BuiltinArguments : public Arguments { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 isolate->counters()->array_function_runtime()->Increment(); | 192 isolate->counters()->array_function_runtime()->Increment(); |
194 | 193 |
195 JSArray* array; | 194 JSArray* array; |
196 if (CalledAsConstructor(isolate)) { | 195 if (CalledAsConstructor(isolate)) { |
197 array = JSArray::cast((*args)[0]); | 196 array = JSArray::cast((*args)[0]); |
198 // Initialize elements and length in case later allocations fail so that the | 197 // Initialize elements and length in case later allocations fail so that the |
199 // array object is initialized in a valid state. | 198 // array object is initialized in a valid state. |
200 array->set_length(Smi::FromInt(0)); | 199 array->set_length(Smi::FromInt(0)); |
201 array->set_elements(heap->empty_fixed_array()); | 200 array->set_elements(heap->empty_fixed_array()); |
202 if (!FLAG_smi_only_arrays) { | 201 if (!FLAG_smi_only_arrays) { |
203 Context* native_context = isolate->context()->native_context(); | 202 Context* global_context = isolate->context()->global_context(); |
204 if (array->GetElementsKind() == GetInitialFastElementsKind() && | 203 if (array->GetElementsKind() == GetInitialFastElementsKind() && |
205 !native_context->js_array_maps()->IsUndefined()) { | 204 !global_context->js_array_maps()->IsUndefined()) { |
206 FixedArray* map_array = | 205 FixedArray* map_array = |
207 FixedArray::cast(native_context->js_array_maps()); | 206 FixedArray::cast(global_context->js_array_maps()); |
208 array->set_map(Map::cast(map_array-> | 207 array->set_map(Map::cast(map_array-> |
209 get(TERMINAL_FAST_ELEMENTS_KIND))); | 208 get(TERMINAL_FAST_ELEMENTS_KIND))); |
210 } | 209 } |
211 } | 210 } |
212 } else { | 211 } else { |
213 // Allocate the JS Array | 212 // Allocate the JS Array |
214 MaybeObject* maybe_obj = heap->AllocateJSObject(constructor); | 213 MaybeObject* maybe_obj = heap->AllocateJSObject(constructor); |
215 if (!maybe_obj->To(&array)) return maybe_obj; | 214 if (!maybe_obj->To(&array)) return maybe_obj; |
216 } | 215 } |
217 | 216 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 array->set_elements(elms); | 305 array->set_elements(elms); |
307 array->set_length(Smi::FromInt(number_of_elements)); | 306 array->set_length(Smi::FromInt(number_of_elements)); |
308 return array; | 307 return array; |
309 } | 308 } |
310 | 309 |
311 | 310 |
312 BUILTIN(InternalArrayCodeGeneric) { | 311 BUILTIN(InternalArrayCodeGeneric) { |
313 return ArrayCodeGenericCommon( | 312 return ArrayCodeGenericCommon( |
314 &args, | 313 &args, |
315 isolate, | 314 isolate, |
316 isolate->context()->native_context()->internal_array_function()); | 315 isolate->context()->global_context()->internal_array_function()); |
317 } | 316 } |
318 | 317 |
319 | 318 |
320 BUILTIN(ArrayCodeGeneric) { | 319 BUILTIN(ArrayCodeGeneric) { |
321 return ArrayCodeGenericCommon( | 320 return ArrayCodeGenericCommon( |
322 &args, | 321 &args, |
323 isolate, | 322 isolate, |
324 isolate->context()->native_context()->array_function()); | 323 isolate->context()->global_context()->array_function()); |
325 } | 324 } |
326 | 325 |
327 | 326 |
328 static void MoveElements(Heap* heap, | 327 static void MoveElements(Heap* heap, |
329 AssertNoAllocation* no_gc, | 328 AssertNoAllocation* no_gc, |
330 FixedArray* dst, | 329 FixedArray* dst, |
331 int dst_index, | 330 int dst_index, |
332 FixedArray* src, | 331 FixedArray* src, |
333 int src_index, | 332 int src_index, |
334 int len) { | 333 int len) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 } | 395 } |
397 | 396 |
398 HEAP_PROFILE(heap, ObjectMoveEvent(elms->address(), | 397 HEAP_PROFILE(heap, ObjectMoveEvent(elms->address(), |
399 elms->address() + size_delta)); | 398 elms->address() + size_delta)); |
400 return FixedArray::cast(HeapObject::FromAddress( | 399 return FixedArray::cast(HeapObject::FromAddress( |
401 elms->address() + to_trim * kPointerSize)); | 400 elms->address() + to_trim * kPointerSize)); |
402 } | 401 } |
403 | 402 |
404 | 403 |
405 static bool ArrayPrototypeHasNoElements(Heap* heap, | 404 static bool ArrayPrototypeHasNoElements(Heap* heap, |
406 Context* native_context, | 405 Context* global_context, |
407 JSObject* array_proto) { | 406 JSObject* array_proto) { |
408 // This method depends on non writability of Object and Array prototype | 407 // This method depends on non writability of Object and Array prototype |
409 // fields. | 408 // fields. |
410 if (array_proto->elements() != heap->empty_fixed_array()) return false; | 409 if (array_proto->elements() != heap->empty_fixed_array()) return false; |
411 // Object.prototype | 410 // Object.prototype |
412 Object* proto = array_proto->GetPrototype(); | 411 Object* proto = array_proto->GetPrototype(); |
413 if (proto == heap->null_value()) return false; | 412 if (proto == heap->null_value()) return false; |
414 array_proto = JSObject::cast(proto); | 413 array_proto = JSObject::cast(proto); |
415 if (array_proto != native_context->initial_object_prototype()) return false; | 414 if (array_proto != global_context->initial_object_prototype()) return false; |
416 if (array_proto->elements() != heap->empty_fixed_array()) return false; | 415 if (array_proto->elements() != heap->empty_fixed_array()) return false; |
417 return array_proto->GetPrototype()->IsNull(); | 416 return array_proto->GetPrototype()->IsNull(); |
418 } | 417 } |
419 | 418 |
420 | 419 |
421 MUST_USE_RESULT | 420 MUST_USE_RESULT |
422 static inline MaybeObject* EnsureJSArrayWithWritableFastElements( | 421 static inline MaybeObject* EnsureJSArrayWithWritableFastElements( |
423 Heap* heap, Object* receiver, Arguments* args, int first_added_arg) { | 422 Heap* heap, Object* receiver, Arguments* args, int first_added_arg) { |
424 if (!receiver->IsJSArray()) return NULL; | 423 if (!receiver->IsJSArray()) return NULL; |
425 JSArray* array = JSArray::cast(receiver); | 424 JSArray* array = JSArray::cast(receiver); |
(...skipping 29 matching lines...) Expand all Loading... |
455 args_length - first_added_arg, | 454 args_length - first_added_arg, |
456 DONT_ALLOW_DOUBLE_ELEMENTS); | 455 DONT_ALLOW_DOUBLE_ELEMENTS); |
457 if (maybe_array->IsFailure()) return maybe_array; | 456 if (maybe_array->IsFailure()) return maybe_array; |
458 return array->elements(); | 457 return array->elements(); |
459 } | 458 } |
460 | 459 |
461 | 460 |
462 static inline bool IsJSArrayFastElementMovingAllowed(Heap* heap, | 461 static inline bool IsJSArrayFastElementMovingAllowed(Heap* heap, |
463 JSArray* receiver) { | 462 JSArray* receiver) { |
464 if (!FLAG_clever_optimizations) return false; | 463 if (!FLAG_clever_optimizations) return false; |
465 Context* native_context = heap->isolate()->context()->native_context(); | 464 Context* global_context = heap->isolate()->context()->global_context(); |
466 JSObject* array_proto = | 465 JSObject* array_proto = |
467 JSObject::cast(native_context->array_function()->prototype()); | 466 JSObject::cast(global_context->array_function()->prototype()); |
468 return receiver->GetPrototype() == array_proto && | 467 return receiver->GetPrototype() == array_proto && |
469 ArrayPrototypeHasNoElements(heap, native_context, array_proto); | 468 ArrayPrototypeHasNoElements(heap, global_context, array_proto); |
470 } | 469 } |
471 | 470 |
472 | 471 |
473 MUST_USE_RESULT static MaybeObject* CallJsBuiltin( | 472 MUST_USE_RESULT static MaybeObject* CallJsBuiltin( |
474 Isolate* isolate, | 473 Isolate* isolate, |
475 const char* name, | 474 const char* name, |
476 BuiltinArguments<NO_EXTRA_ARGUMENTS> args) { | 475 BuiltinArguments<NO_EXTRA_ARGUMENTS> args) { |
477 HandleScope handleScope(isolate); | 476 HandleScope handleScope(isolate); |
478 | 477 |
479 Handle<Object> js_builtin = | 478 Handle<Object> js_builtin = |
480 GetProperty(Handle<JSObject>(isolate->native_context()->builtins()), | 479 GetProperty(Handle<JSObject>(isolate->global_context()->builtins()), |
481 name); | 480 name); |
482 Handle<JSFunction> function = Handle<JSFunction>::cast(js_builtin); | 481 Handle<JSFunction> function = Handle<JSFunction>::cast(js_builtin); |
483 int argc = args.length() - 1; | 482 int argc = args.length() - 1; |
484 ScopedVector<Handle<Object> > argv(argc); | 483 ScopedVector<Handle<Object> > argv(argc); |
485 for (int i = 0; i < argc; ++i) { | 484 for (int i = 0; i < argc; ++i) { |
486 argv[i] = args.at<Object>(i + 1); | 485 argv[i] = args.at<Object>(i + 1); |
487 } | 486 } |
488 bool pending_exception; | 487 bool pending_exception; |
489 Handle<Object> result = Execution::Call(function, | 488 Handle<Object> result = Execution::Call(function, |
490 args.receiver(), | 489 args.receiver(), |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 !IsJSArrayFastElementMovingAllowed(heap, array)) { | 699 !IsJSArrayFastElementMovingAllowed(heap, array)) { |
701 return CallJsBuiltin(isolate, "ArraySlice", args); | 700 return CallJsBuiltin(isolate, "ArraySlice", args); |
702 } | 701 } |
703 | 702 |
704 elms = FixedArray::cast(array->elements()); | 703 elms = FixedArray::cast(array->elements()); |
705 len = Smi::cast(array->length())->value(); | 704 len = Smi::cast(array->length())->value(); |
706 } else { | 705 } else { |
707 // Array.slice(arguments, ...) is quite a common idiom (notably more | 706 // Array.slice(arguments, ...) is quite a common idiom (notably more |
708 // than 50% of invocations in Web apps). Treat it in C++ as well. | 707 // than 50% of invocations in Web apps). Treat it in C++ as well. |
709 Map* arguments_map = | 708 Map* arguments_map = |
710 isolate->context()->native_context()->arguments_boilerplate()->map(); | 709 isolate->context()->global_context()->arguments_boilerplate()->map(); |
711 | 710 |
712 bool is_arguments_object_with_fast_elements = | 711 bool is_arguments_object_with_fast_elements = |
713 receiver->IsJSObject() | 712 receiver->IsJSObject() |
714 && JSObject::cast(receiver)->map() == arguments_map | 713 && JSObject::cast(receiver)->map() == arguments_map |
715 && JSObject::cast(receiver)->HasFastSmiOrObjectElements(); | 714 && JSObject::cast(receiver)->HasFastSmiOrObjectElements(); |
716 if (!is_arguments_object_with_fast_elements) { | 715 if (!is_arguments_object_with_fast_elements) { |
717 return CallJsBuiltin(isolate, "ArraySlice", args); | 716 return CallJsBuiltin(isolate, "ArraySlice", args); |
718 } | 717 } |
719 elms = FixedArray::cast(JSObject::cast(receiver)->elements()); | 718 elms = FixedArray::cast(JSObject::cast(receiver)->elements()); |
720 Object* len_obj = JSObject::cast(receiver) | 719 Object* len_obj = JSObject::cast(receiver) |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 | 936 |
938 // Set the length. | 937 // Set the length. |
939 array->set_length(Smi::FromInt(new_length)); | 938 array->set_length(Smi::FromInt(new_length)); |
940 | 939 |
941 return result_array; | 940 return result_array; |
942 } | 941 } |
943 | 942 |
944 | 943 |
945 BUILTIN(ArrayConcat) { | 944 BUILTIN(ArrayConcat) { |
946 Heap* heap = isolate->heap(); | 945 Heap* heap = isolate->heap(); |
947 Context* native_context = isolate->context()->native_context(); | 946 Context* global_context = isolate->context()->global_context(); |
948 JSObject* array_proto = | 947 JSObject* array_proto = |
949 JSObject::cast(native_context->array_function()->prototype()); | 948 JSObject::cast(global_context->array_function()->prototype()); |
950 if (!ArrayPrototypeHasNoElements(heap, native_context, array_proto)) { | 949 if (!ArrayPrototypeHasNoElements(heap, global_context, array_proto)) { |
951 return CallJsBuiltin(isolate, "ArrayConcat", args); | 950 return CallJsBuiltin(isolate, "ArrayConcat", args); |
952 } | 951 } |
953 | 952 |
954 // Iterate through all the arguments performing checks | 953 // Iterate through all the arguments performing checks |
955 // and calculating total length. | 954 // and calculating total length. |
956 int n_arguments = args.length(); | 955 int n_arguments = args.length(); |
957 int result_len = 0; | 956 int result_len = 0; |
958 ElementsKind elements_kind = GetInitialFastElementsKind(); | 957 ElementsKind elements_kind = GetInitialFastElementsKind(); |
959 for (int i = 0; i < n_arguments; i++) { | 958 for (int i = 0; i < n_arguments; i++) { |
960 Object* arg = args[i]; | 959 Object* arg = args[i]; |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1382 static void Generate_StoreIC_GlobalProxy(MacroAssembler* masm) { | 1381 static void Generate_StoreIC_GlobalProxy(MacroAssembler* masm) { |
1383 StoreIC::GenerateGlobalProxy(masm, kNonStrictMode); | 1382 StoreIC::GenerateGlobalProxy(masm, kNonStrictMode); |
1384 } | 1383 } |
1385 | 1384 |
1386 | 1385 |
1387 static void Generate_StoreIC_GlobalProxy_Strict(MacroAssembler* masm) { | 1386 static void Generate_StoreIC_GlobalProxy_Strict(MacroAssembler* masm) { |
1388 StoreIC::GenerateGlobalProxy(masm, kStrictMode); | 1387 StoreIC::GenerateGlobalProxy(masm, kStrictMode); |
1389 } | 1388 } |
1390 | 1389 |
1391 | 1390 |
1392 static void Generate_StoreIC_Setter_ForDeopt(MacroAssembler* masm) { | |
1393 StoreStubCompiler::GenerateStoreViaSetter(masm, Handle<JSFunction>()); | |
1394 } | |
1395 | |
1396 | |
1397 static void Generate_KeyedStoreIC_Generic(MacroAssembler* masm) { | 1391 static void Generate_KeyedStoreIC_Generic(MacroAssembler* masm) { |
1398 KeyedStoreIC::GenerateGeneric(masm, kNonStrictMode); | 1392 KeyedStoreIC::GenerateGeneric(masm, kNonStrictMode); |
1399 } | 1393 } |
1400 | 1394 |
1401 | 1395 |
1402 static void Generate_KeyedStoreIC_Generic_Strict(MacroAssembler* masm) { | 1396 static void Generate_KeyedStoreIC_Generic_Strict(MacroAssembler* masm) { |
1403 KeyedStoreIC::GenerateGeneric(masm, kStrictMode); | 1397 KeyedStoreIC::GenerateGeneric(masm, kStrictMode); |
1404 } | 1398 } |
1405 | 1399 |
1406 | 1400 |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1709 return Handle<Code>(code_address); \ | 1703 return Handle<Code>(code_address); \ |
1710 } | 1704 } |
1711 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1705 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
1712 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1706 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
1713 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1707 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
1714 #undef DEFINE_BUILTIN_ACCESSOR_C | 1708 #undef DEFINE_BUILTIN_ACCESSOR_C |
1715 #undef DEFINE_BUILTIN_ACCESSOR_A | 1709 #undef DEFINE_BUILTIN_ACCESSOR_A |
1716 | 1710 |
1717 | 1711 |
1718 } } // namespace v8::internal | 1712 } } // namespace v8::internal |
OLD | NEW |