OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 Handle<FixedArray> Factory::NewFixedArrayWithHoles(int size, | 52 Handle<FixedArray> Factory::NewFixedArrayWithHoles(int size, |
53 PretenureFlag pretenure) { | 53 PretenureFlag pretenure) { |
54 ASSERT(0 <= size); | 54 ASSERT(0 <= size); |
55 CALL_HEAP_FUNCTION( | 55 CALL_HEAP_FUNCTION( |
56 isolate(), | 56 isolate(), |
57 isolate()->heap()->AllocateFixedArrayWithHoles(size, pretenure), | 57 isolate()->heap()->AllocateFixedArrayWithHoles(size, pretenure), |
58 FixedArray); | 58 FixedArray); |
59 } | 59 } |
60 | 60 |
61 | 61 |
62 Handle<FixedArray> Factory::NewFixedDoubleArray(int size, | 62 Handle<FixedDoubleArray> Factory::NewFixedDoubleArray(int size, |
63 PretenureFlag pretenure) { | 63 PretenureFlag pretenure) { |
64 ASSERT(0 <= size); | 64 ASSERT(0 <= size); |
65 CALL_HEAP_FUNCTION( | 65 CALL_HEAP_FUNCTION( |
66 isolate(), | 66 isolate(), |
67 isolate()->heap()->AllocateUninitializedFixedDoubleArray(size, pretenure), | 67 isolate()->heap()->AllocateUninitializedFixedDoubleArray(size, pretenure), |
68 FixedArray); | 68 FixedDoubleArray); |
69 } | 69 } |
70 | 70 |
71 | 71 |
72 Handle<StringDictionary> Factory::NewStringDictionary(int at_least_space_for) { | 72 Handle<StringDictionary> Factory::NewStringDictionary(int at_least_space_for) { |
73 ASSERT(0 <= at_least_space_for); | 73 ASSERT(0 <= at_least_space_for); |
74 CALL_HEAP_FUNCTION(isolate(), | 74 CALL_HEAP_FUNCTION(isolate(), |
75 StringDictionary::Allocate(at_least_space_for), | 75 StringDictionary::Allocate(at_least_space_for), |
76 StringDictionary); | 76 StringDictionary); |
77 } | 77 } |
78 | 78 |
79 | 79 |
80 Handle<NumberDictionary> Factory::NewNumberDictionary(int at_least_space_for) { | 80 Handle<NumberDictionary> Factory::NewNumberDictionary(int at_least_space_for) { |
81 ASSERT(0 <= at_least_space_for); | 81 ASSERT(0 <= at_least_space_for); |
82 CALL_HEAP_FUNCTION(isolate(), | 82 CALL_HEAP_FUNCTION(isolate(), |
83 NumberDictionary::Allocate(at_least_space_for), | 83 NumberDictionary::Allocate(at_least_space_for), |
84 NumberDictionary); | 84 NumberDictionary); |
85 } | 85 } |
86 | 86 |
87 | 87 |
| 88 Handle<ObjectHashSet> Factory::NewObjectHashSet(int at_least_space_for) { |
| 89 ASSERT(0 <= at_least_space_for); |
| 90 CALL_HEAP_FUNCTION(isolate(), |
| 91 ObjectHashSet::Allocate(at_least_space_for), |
| 92 ObjectHashSet); |
| 93 } |
| 94 |
| 95 |
88 Handle<ObjectHashTable> Factory::NewObjectHashTable(int at_least_space_for) { | 96 Handle<ObjectHashTable> Factory::NewObjectHashTable(int at_least_space_for) { |
89 ASSERT(0 <= at_least_space_for); | 97 ASSERT(0 <= at_least_space_for); |
90 CALL_HEAP_FUNCTION(isolate(), | 98 CALL_HEAP_FUNCTION(isolate(), |
91 ObjectHashTable::Allocate(at_least_space_for), | 99 ObjectHashTable::Allocate(at_least_space_for), |
92 ObjectHashTable); | 100 ObjectHashTable); |
93 } | 101 } |
94 | 102 |
95 | 103 |
96 Handle<DescriptorArray> Factory::NewDescriptorArray(int number_of_descriptors) { | 104 Handle<DescriptorArray> Factory::NewDescriptorArray(int number_of_descriptors) { |
97 ASSERT(0 <= number_of_descriptors); | 105 ASSERT(0 <= number_of_descriptors); |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 src->GetElementsTransitionMap(elements_kind), | 472 src->GetElementsTransitionMap(elements_kind), |
465 Map); | 473 Map); |
466 } | 474 } |
467 | 475 |
468 | 476 |
469 Handle<FixedArray> Factory::CopyFixedArray(Handle<FixedArray> array) { | 477 Handle<FixedArray> Factory::CopyFixedArray(Handle<FixedArray> array) { |
470 CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedArray); | 478 CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedArray); |
471 } | 479 } |
472 | 480 |
473 | 481 |
| 482 Handle<FixedDoubleArray> Factory::CopyFixedDoubleArray( |
| 483 Handle<FixedDoubleArray> array) { |
| 484 CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedDoubleArray); |
| 485 } |
| 486 |
| 487 |
474 Handle<JSFunction> Factory::BaseNewFunctionFromSharedFunctionInfo( | 488 Handle<JSFunction> Factory::BaseNewFunctionFromSharedFunctionInfo( |
475 Handle<SharedFunctionInfo> function_info, | 489 Handle<SharedFunctionInfo> function_info, |
476 Handle<Map> function_map, | 490 Handle<Map> function_map, |
477 PretenureFlag pretenure) { | 491 PretenureFlag pretenure) { |
478 CALL_HEAP_FUNCTION( | 492 CALL_HEAP_FUNCTION( |
479 isolate(), | 493 isolate(), |
480 isolate()->heap()->AllocateFunction(*function_map, | 494 isolate()->heap()->AllocateFunction(*function_map, |
481 *function_info, | 495 *function_info, |
482 isolate()->heap()->the_hole_value(), | 496 isolate()->heap()->the_hole_value(), |
483 pretenure), | 497 pretenure), |
484 JSFunction); | 498 JSFunction); |
485 } | 499 } |
486 | 500 |
487 | 501 |
488 Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( | 502 Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( |
489 Handle<SharedFunctionInfo> function_info, | 503 Handle<SharedFunctionInfo> function_info, |
490 Handle<Context> context, | 504 Handle<Context> context, |
491 PretenureFlag pretenure) { | 505 PretenureFlag pretenure) { |
492 Handle<JSFunction> result = BaseNewFunctionFromSharedFunctionInfo( | 506 Handle<JSFunction> result = BaseNewFunctionFromSharedFunctionInfo( |
493 function_info, | 507 function_info, |
494 function_info->strict_mode() | 508 function_info->strict_mode() |
495 ? isolate()->strict_mode_function_map() | 509 ? isolate()->strict_mode_function_map() |
496 : isolate()->function_map(), | 510 : isolate()->function_map(), |
497 pretenure); | 511 pretenure); |
498 | 512 |
499 result->set_context(*context); | 513 result->set_context(*context); |
500 int number_of_literals = function_info->num_literals(); | 514 if (!function_info->bound()) { |
501 Handle<FixedArray> literals = NewFixedArray(number_of_literals, pretenure); | 515 int number_of_literals = function_info->num_literals(); |
502 if (number_of_literals > 0) { | 516 Handle<FixedArray> literals = NewFixedArray(number_of_literals, pretenure); |
503 // Store the object, regexp and array functions in the literals | 517 if (number_of_literals > 0) { |
504 // array prefix. These functions will be used when creating | 518 // Store the object, regexp and array functions in the literals |
505 // object, regexp and array literals in this function. | 519 // array prefix. These functions will be used when creating |
506 literals->set(JSFunction::kLiteralGlobalContextIndex, | 520 // object, regexp and array literals in this function. |
507 context->global_context()); | 521 literals->set(JSFunction::kLiteralGlobalContextIndex, |
| 522 context->global_context()); |
| 523 } |
| 524 result->set_literals(*literals); |
| 525 } else { |
| 526 result->set_function_bindings(isolate()->heap()->empty_fixed_array()); |
508 } | 527 } |
509 result->set_literals(*literals); | |
510 result->set_next_function_link(isolate()->heap()->undefined_value()); | 528 result->set_next_function_link(isolate()->heap()->undefined_value()); |
511 | 529 |
512 if (V8::UseCrankshaft() && | 530 if (V8::UseCrankshaft() && |
513 FLAG_always_opt && | 531 FLAG_always_opt && |
514 result->is_compiled() && | 532 result->is_compiled() && |
515 !function_info->is_toplevel() && | 533 !function_info->is_toplevel() && |
516 function_info->allows_lazy_compilation()) { | 534 function_info->allows_lazy_compilation()) { |
517 result->MarkForLazyRecompilation(); | 535 result->MarkForLazyRecompilation(); |
518 } | 536 } |
519 return result; | 537 return result; |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 Handle<DescriptorArray> array, | 832 Handle<DescriptorArray> array, |
815 Handle<Object> descriptors) { | 833 Handle<Object> descriptors) { |
816 v8::NeanderArray callbacks(descriptors); | 834 v8::NeanderArray callbacks(descriptors); |
817 int nof_callbacks = callbacks.length(); | 835 int nof_callbacks = callbacks.length(); |
818 Handle<DescriptorArray> result = | 836 Handle<DescriptorArray> result = |
819 NewDescriptorArray(array->number_of_descriptors() + nof_callbacks); | 837 NewDescriptorArray(array->number_of_descriptors() + nof_callbacks); |
820 | 838 |
821 // Number of descriptors added to the result so far. | 839 // Number of descriptors added to the result so far. |
822 int descriptor_count = 0; | 840 int descriptor_count = 0; |
823 | 841 |
| 842 // Ensure that marking will not progress and change color of objects. |
| 843 DescriptorArray::WhitenessWitness witness(*result); |
| 844 |
824 // Copy the descriptors from the array. | 845 // Copy the descriptors from the array. |
825 for (int i = 0; i < array->number_of_descriptors(); i++) { | 846 for (int i = 0; i < array->number_of_descriptors(); i++) { |
826 if (array->GetType(i) != NULL_DESCRIPTOR) { | 847 if (array->GetType(i) != NULL_DESCRIPTOR) { |
827 result->CopyFrom(descriptor_count++, *array, i); | 848 result->CopyFrom(descriptor_count++, *array, i, witness); |
828 } | 849 } |
829 } | 850 } |
830 | 851 |
831 // Number of duplicates detected. | 852 // Number of duplicates detected. |
832 int duplicates = 0; | 853 int duplicates = 0; |
833 | 854 |
834 // Fill in new callback descriptors. Process the callbacks from | 855 // Fill in new callback descriptors. Process the callbacks from |
835 // back to front so that the last callback with a given name takes | 856 // back to front so that the last callback with a given name takes |
836 // precedence over previously added callbacks with that name. | 857 // precedence over previously added callbacks with that name. |
837 for (int i = nof_callbacks - 1; i >= 0; i--) { | 858 for (int i = nof_callbacks - 1; i >= 0; i--) { |
838 Handle<AccessorInfo> entry = | 859 Handle<AccessorInfo> entry = |
839 Handle<AccessorInfo>(AccessorInfo::cast(callbacks.get(i))); | 860 Handle<AccessorInfo>(AccessorInfo::cast(callbacks.get(i))); |
840 // Ensure the key is a symbol before writing into the instance descriptor. | 861 // Ensure the key is a symbol before writing into the instance descriptor. |
841 Handle<String> key = | 862 Handle<String> key = |
842 SymbolFromString(Handle<String>(String::cast(entry->name()))); | 863 SymbolFromString(Handle<String>(String::cast(entry->name()))); |
843 // Check if a descriptor with this name already exists before writing. | 864 // Check if a descriptor with this name already exists before writing. |
844 if (result->LinearSearch(*key, descriptor_count) == | 865 if (result->LinearSearch(*key, descriptor_count) == |
845 DescriptorArray::kNotFound) { | 866 DescriptorArray::kNotFound) { |
846 CallbacksDescriptor desc(*key, *entry, entry->property_attributes()); | 867 CallbacksDescriptor desc(*key, *entry, entry->property_attributes()); |
847 result->Set(descriptor_count, &desc); | 868 result->Set(descriptor_count, &desc, witness); |
848 descriptor_count++; | 869 descriptor_count++; |
849 } else { | 870 } else { |
850 duplicates++; | 871 duplicates++; |
851 } | 872 } |
852 } | 873 } |
853 | 874 |
854 // If duplicates were detected, allocate a result of the right size | 875 // If duplicates were detected, allocate a result of the right size |
855 // and transfer the elements. | 876 // and transfer the elements. |
856 if (duplicates > 0) { | 877 if (duplicates > 0) { |
857 int number_of_descriptors = result->number_of_descriptors() - duplicates; | 878 int number_of_descriptors = result->number_of_descriptors() - duplicates; |
858 Handle<DescriptorArray> new_result = | 879 Handle<DescriptorArray> new_result = |
859 NewDescriptorArray(number_of_descriptors); | 880 NewDescriptorArray(number_of_descriptors); |
860 for (int i = 0; i < number_of_descriptors; i++) { | 881 for (int i = 0; i < number_of_descriptors; i++) { |
861 new_result->CopyFrom(i, *result, i); | 882 new_result->CopyFrom(i, *result, i, witness); |
862 } | 883 } |
863 result = new_result; | 884 result = new_result; |
864 } | 885 } |
865 | 886 |
866 // Sort the result before returning. | 887 // Sort the result before returning. |
867 result->Sort(); | 888 result->Sort(witness); |
868 return result; | 889 return result; |
869 } | 890 } |
870 | 891 |
871 | 892 |
872 Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor, | 893 Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor, |
873 PretenureFlag pretenure) { | 894 PretenureFlag pretenure) { |
874 CALL_HEAP_FUNCTION( | 895 CALL_HEAP_FUNCTION( |
875 isolate(), | 896 isolate(), |
876 isolate()->heap()->AllocateJSObject(*constructor, pretenure), JSObject); | 897 isolate()->heap()->AllocateJSObject(*constructor, pretenure), JSObject); |
877 } | 898 } |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1337 | 1358 |
1338 | 1359 |
1339 Handle<Object> Factory::ToBoolean(bool value) { | 1360 Handle<Object> Factory::ToBoolean(bool value) { |
1340 return Handle<Object>(value | 1361 return Handle<Object>(value |
1341 ? isolate()->heap()->true_value() | 1362 ? isolate()->heap()->true_value() |
1342 : isolate()->heap()->false_value()); | 1363 : isolate()->heap()->false_value()); |
1343 } | 1364 } |
1344 | 1365 |
1345 | 1366 |
1346 } } // namespace v8::internal | 1367 } } // namespace v8::internal |
OLD | NEW |