OLD | NEW |
---|---|
1 // Copyright 2011 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 |
11 // with the distribution. | 11 // with the distribution. |
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1283 | 1283 |
1284 ASSERT(mode == ALLOW_COPIED_DOUBLE_ELEMENTS); | 1284 ASSERT(mode == ALLOW_COPIED_DOUBLE_ELEMENTS); |
1285 if (GetElementsKind() == FAST_SMI_ONLY_ELEMENTS) { | 1285 if (GetElementsKind() == FAST_SMI_ONLY_ELEMENTS) { |
1286 return TransitionElementsKind(FAST_DOUBLE_ELEMENTS); | 1286 return TransitionElementsKind(FAST_DOUBLE_ELEMENTS); |
1287 } | 1287 } |
1288 | 1288 |
1289 return this; | 1289 return this; |
1290 } | 1290 } |
1291 | 1291 |
1292 | 1292 |
1293 MaybeObject* JSObject::GetElementsTransitionMap(Isolate* isolate, | |
1294 ElementsKind to_kind) { | |
1295 Map* current_map = map(); | |
1296 ElementsKind from_kind = current_map->elements_kind(); | |
1297 | |
1298 if (from_kind == to_kind) return current_map; | |
1299 | |
1300 Context* global_context = isolate->context()->global_context(); | |
1301 if (current_map == global_context->smi_js_array_map()) { | |
Jakob Kummerow
2012/01/23 17:16:55
What about the current_map == global_context->doub
danno
2012/01/26 21:32:34
The SMI -> Object transition is so frequent and ot
| |
1302 if (to_kind == FAST_ELEMENTS) { | |
1303 return global_context->object_js_array_map(); | |
1304 } else { | |
1305 if (to_kind == FAST_DOUBLE_ELEMENTS) { | |
1306 return global_context->double_js_array_map(); | |
1307 } else { | |
1308 ASSERT(to_kind == DICTIONARY_ELEMENTS); | |
1309 } | |
1310 } | |
1311 } | |
1312 return GetElementsTransitionMapSlow(to_kind); | |
1313 } | |
1314 | |
1315 | |
1293 void JSObject::set_map_and_elements(Map* new_map, | 1316 void JSObject::set_map_and_elements(Map* new_map, |
1294 FixedArrayBase* value, | 1317 FixedArrayBase* value, |
1295 WriteBarrierMode mode) { | 1318 WriteBarrierMode mode) { |
1296 ASSERT(value->HasValidElements()); | 1319 ASSERT(value->HasValidElements()); |
1297 #ifdef DEBUG | 1320 #ifdef DEBUG |
1298 ValidateSmiOnlyElements(); | 1321 ValidateSmiOnlyElements(); |
1299 #endif | 1322 #endif |
1300 if (new_map != NULL) { | 1323 if (new_map != NULL) { |
1301 if (mode == UPDATE_WRITE_BARRIER) { | 1324 if (mode == UPDATE_WRITE_BARRIER) { |
1302 set_map(new_map); | 1325 set_map(new_map); |
(...skipping 29 matching lines...) Expand all Loading... | |
1332 ASSERT(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array())); | 1355 ASSERT(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array())); |
1333 WRITE_FIELD(this, kElementsOffset, GetHeap()->empty_fixed_array()); | 1356 WRITE_FIELD(this, kElementsOffset, GetHeap()->empty_fixed_array()); |
1334 } | 1357 } |
1335 | 1358 |
1336 | 1359 |
1337 MaybeObject* JSObject::ResetElements() { | 1360 MaybeObject* JSObject::ResetElements() { |
1338 Object* obj; | 1361 Object* obj; |
1339 ElementsKind elements_kind = FLAG_smi_only_arrays | 1362 ElementsKind elements_kind = FLAG_smi_only_arrays |
1340 ? FAST_SMI_ONLY_ELEMENTS | 1363 ? FAST_SMI_ONLY_ELEMENTS |
1341 : FAST_ELEMENTS; | 1364 : FAST_ELEMENTS; |
1342 MaybeObject* maybe_obj = GetElementsTransitionMap(elements_kind); | 1365 MaybeObject* maybe_obj = GetElementsTransitionMap(GetIsolate(), |
1366 elements_kind); | |
1343 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 1367 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
1344 set_map(Map::cast(obj)); | 1368 set_map(Map::cast(obj)); |
1345 initialize_elements(); | 1369 initialize_elements(); |
1346 return this; | 1370 return this; |
1347 } | 1371 } |
1348 | 1372 |
1349 | 1373 |
1350 ACCESSORS(Oddball, to_string, String, kToStringOffset) | 1374 ACCESSORS(Oddball, to_string, String, kToStringOffset) |
1351 ACCESSORS(Oddball, to_number, Object, kToNumberOffset) | 1375 ACCESSORS(Oddball, to_number, Object, kToNumberOffset) |
1352 | 1376 |
(...skipping 2518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3871 Map* JSFunction::initial_map() { | 3895 Map* JSFunction::initial_map() { |
3872 return Map::cast(prototype_or_initial_map()); | 3896 return Map::cast(prototype_or_initial_map()); |
3873 } | 3897 } |
3874 | 3898 |
3875 | 3899 |
3876 void JSFunction::set_initial_map(Map* value) { | 3900 void JSFunction::set_initial_map(Map* value) { |
3877 set_prototype_or_initial_map(value); | 3901 set_prototype_or_initial_map(value); |
3878 } | 3902 } |
3879 | 3903 |
3880 | 3904 |
3905 MaybeObject* JSFunction::set_initial_map_and_cache_transitions( | |
3906 Map* initial_map) { | |
3907 Context* global_context = context()->global_context(); | |
3908 Object* array_function = | |
3909 global_context->get(Context::ARRAY_FUNCTION_INDEX); | |
3910 if (array_function->IsJSFunction() && | |
3911 this == JSFunction::cast(array_function)) { | |
3912 ASSERT(initial_map->elements_kind() == FAST_SMI_ONLY_ELEMENTS); | |
3913 | |
3914 MaybeObject* maybe_map = initial_map->CopyDropTransitions(); | |
3915 Map* new_double_map = NULL; | |
3916 if (!maybe_map->To<Map>(&new_double_map)) return maybe_map; | |
3917 new_double_map->set_elements_kind(FAST_DOUBLE_ELEMENTS); | |
3918 initial_map->AddElementsTransition(FAST_DOUBLE_ELEMENTS, new_double_map); | |
3919 | |
3920 maybe_map = initial_map->CopyDropTransitions(); | |
Jakob Kummerow
2012/01/23 17:16:55
I'd s/initial_map/new_double_map/ here to make it
danno
2012/01/26 21:32:34
Done.
| |
3921 Map* new_object_map = NULL; | |
3922 if (!maybe_map->To<Map>(&new_object_map)) return maybe_map; | |
3923 new_object_map->set_elements_kind(FAST_ELEMENTS); | |
3924 new_double_map->AddElementsTransition(FAST_ELEMENTS, new_object_map); | |
3925 | |
3926 global_context->set_smi_js_array_map(initial_map); | |
3927 global_context->set_double_js_array_map(new_double_map); | |
3928 global_context->set_object_js_array_map(new_object_map); | |
3929 } | |
3930 set_initial_map(initial_map); | |
3931 return this; | |
3932 } | |
3933 | |
3934 | |
3881 bool JSFunction::has_initial_map() { | 3935 bool JSFunction::has_initial_map() { |
3882 return prototype_or_initial_map()->IsMap(); | 3936 return prototype_or_initial_map()->IsMap(); |
3883 } | 3937 } |
3884 | 3938 |
3885 | 3939 |
3886 bool JSFunction::has_instance_prototype() { | 3940 bool JSFunction::has_instance_prototype() { |
3887 return has_initial_map() || !prototype_or_initial_map()->IsTheHole(); | 3941 return has_initial_map() || !prototype_or_initial_map()->IsTheHole(); |
3888 } | 3942 } |
3889 | 3943 |
3890 | 3944 |
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4783 #undef WRITE_INT_FIELD | 4837 #undef WRITE_INT_FIELD |
4784 #undef READ_SHORT_FIELD | 4838 #undef READ_SHORT_FIELD |
4785 #undef WRITE_SHORT_FIELD | 4839 #undef WRITE_SHORT_FIELD |
4786 #undef READ_BYTE_FIELD | 4840 #undef READ_BYTE_FIELD |
4787 #undef WRITE_BYTE_FIELD | 4841 #undef WRITE_BYTE_FIELD |
4788 | 4842 |
4789 | 4843 |
4790 } } // namespace v8::internal | 4844 } } // namespace v8::internal |
4791 | 4845 |
4792 #endif // V8_OBJECTS_INL_H_ | 4846 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |