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 7497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7508 return code->optimizable(); | 7508 return code->optimizable(); |
7509 } | 7509 } |
7510 | 7510 |
7511 | 7511 |
7512 MaybeObject* JSObject::OptimizeAsPrototype() { | 7512 MaybeObject* JSObject::OptimizeAsPrototype() { |
7513 if (IsGlobalObject()) return this; | 7513 if (IsGlobalObject()) return this; |
7514 | 7514 |
7515 // Make sure prototypes are fast objects and their maps have the bit set | 7515 // Make sure prototypes are fast objects and their maps have the bit set |
7516 // so they remain fast. | 7516 // so they remain fast. |
7517 Map* proto_map = map(); | 7517 Map* proto_map = map(); |
7518 if (!proto_map->used_for_prototype()) { | 7518 if (!HasFastProperties()) { |
7519 if (!HasFastProperties()) { | 7519 MaybeObject* new_proto = TransformToFastProperties(0); |
7520 MaybeObject* new_proto = TransformToFastProperties(0); | 7520 if (new_proto->IsFailure()) return new_proto; |
7521 if (new_proto->IsFailure()) return new_proto; | 7521 ASSERT(new_proto == this); |
7522 ASSERT(new_proto == this); | 7522 proto_map = map(); |
7523 proto_map = map(); | |
7524 if (!proto_map->is_shared()) { | |
7525 proto_map->set_used_for_prototype(true); | |
7526 } | |
7527 } else { | |
7528 Heap* heap = GetHeap(); | |
7529 // We use the hole value as a singleton key in the prototype transition | |
7530 // map so that we don't multiply the number of maps unnecessarily. | |
7531 Map* new_map = | |
7532 proto_map->GetPrototypeTransition(heap->the_hole_value()); | |
7533 if (new_map == NULL) { | |
7534 MaybeObject* maybe_new_map = | |
7535 proto_map->CopyDropTransitions(DescriptorArray::MAY_BE_SHARED); | |
7536 if (!maybe_new_map->To<Map>(&new_map)) return maybe_new_map; | |
7537 new_map->set_used_for_prototype(true); | |
7538 MaybeObject* ok = | |
7539 proto_map->PutPrototypeTransition(heap->the_hole_value(), | |
7540 new_map); | |
7541 if (ok->IsFailure()) return ok; | |
7542 } | |
7543 ASSERT(!proto_map->is_shared() && !new_map->is_shared()); | |
7544 set_map(new_map); | |
7545 } | |
7546 } | 7523 } |
7547 return this; | 7524 return this; |
7548 } | 7525 } |
7549 | 7526 |
7550 | 7527 |
7551 MaybeObject* JSFunction::SetInstancePrototype(Object* value) { | 7528 MaybeObject* JSFunction::SetInstancePrototype(Object* value) { |
7552 ASSERT(value->IsJSReceiver()); | 7529 ASSERT(value->IsJSReceiver()); |
7553 Heap* heap = GetHeap(); | 7530 Heap* heap = GetHeap(); |
7554 | 7531 |
7555 // First some logic for the map of the prototype to make sure the | 7532 // First some logic for the map of the prototype to make sure it is in fast |
7556 // used_for_prototype flag is set. | 7533 // mode. |
7557 if (value->IsJSObject()) { | 7534 if (value->IsJSObject()) { |
7558 MaybeObject* ok = JSObject::cast(value)->OptimizeAsPrototype(); | 7535 MaybeObject* ok = JSObject::cast(value)->OptimizeAsPrototype(); |
7559 if (ok->IsFailure()) return ok; | 7536 if (ok->IsFailure()) return ok; |
7560 } | 7537 } |
7561 | 7538 |
7562 // Now some logic for the maps of the objects that are created by using this | 7539 // Now some logic for the maps of the objects that are created by using this |
7563 // function as a constructor. | 7540 // function as a constructor. |
7564 if (has_initial_map()) { | 7541 if (has_initial_map()) { |
7565 // If the function has allocated the initial map | 7542 // If the function has allocated the initial map |
7566 // replace it with a copy containing the new prototype. | 7543 // replace it with a copy containing the new prototype. |
(...skipping 5639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13206 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); | 13183 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); |
13207 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); | 13184 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); |
13208 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); | 13185 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); |
13209 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); | 13186 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); |
13210 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); | 13187 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); |
13211 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); | 13188 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); |
13212 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); | 13189 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); |
13213 } | 13190 } |
13214 | 13191 |
13215 } } // namespace v8::internal | 13192 } } // namespace v8::internal |
OLD | NEW |