Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: src/objects.cc

Issue 10782026: Always fix up the enumeration indices when turning to fast mode. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12456 matching lines...) Expand 10 before | Expand all | Expand 10 after
12467 return heap->undefined_value(); 12467 return heap->undefined_value();
12468 } 12468 }
12469 12469
12470 12470
12471 MaybeObject* StringDictionary::TransformPropertiesToFastFor( 12471 MaybeObject* StringDictionary::TransformPropertiesToFastFor(
12472 JSObject* obj, int unused_property_fields) { 12472 JSObject* obj, int unused_property_fields) {
12473 // Make sure we preserve dictionary representation if there are too many 12473 // Make sure we preserve dictionary representation if there are too many
12474 // descriptors. 12474 // descriptors.
12475 if (NumberOfElements() > DescriptorArray::kMaxNumberOfDescriptors) return obj; 12475 if (NumberOfElements() > DescriptorArray::kMaxNumberOfDescriptors) return obj;
12476 12476
12477 // Figure out if it is necessary to generate new enumeration indices. 12477 MaybeObject* maybe_result = GenerateNewEnumerationIndices();
12478 int max_enumeration_index = 12478 if (maybe_result->IsFailure()) return maybe_result;
12479 NextEnumerationIndex() +
danno 2012/07/17 09:55:02 nit: put this on previous line, adjust spacing bel
12480 (DescriptorArray::kMaxNumberOfDescriptors -
12481 NumberOfElements());
12482 if (!PropertyDetails::IsValidIndex(max_enumeration_index)) {
12483 Object* result;
12484 { MaybeObject* maybe_result = GenerateNewEnumerationIndices();
12485 if (!maybe_result->ToObject(&result)) return maybe_result;
12486 }
12487 }
12488 12479
12489 int instance_descriptor_length = 0; 12480 int instance_descriptor_length = 0;
12490 int number_of_fields = 0; 12481 int number_of_fields = 0;
12491 12482
12492 Heap* heap = GetHeap(); 12483 Heap* heap = GetHeap();
12493 12484
12494 // Compute the length of the instance descriptor. 12485 // Compute the length of the instance descriptor.
12495 int capacity = Capacity(); 12486 int capacity = Capacity();
12496 for (int i = 0; i < capacity; i++) { 12487 for (int i = 0; i < capacity; i++) {
12497 Object* k = KeyAt(i); 12488 Object* k = KeyAt(i);
12498 if (IsKey(k)) { 12489 if (IsKey(k)) {
12499 Object* value = ValueAt(i); 12490 Object* value = ValueAt(i);
12500 PropertyType type = DetailsAt(i).type(); 12491 PropertyType type = DetailsAt(i).type();
12501 ASSERT(type != FIELD); 12492 ASSERT(type != FIELD);
12502 instance_descriptor_length++; 12493 instance_descriptor_length++;
12503 if (type == NORMAL && 12494 if (type == NORMAL &&
12504 (!value->IsJSFunction() || heap->InNewSpace(value))) { 12495 (!value->IsJSFunction() || heap->InNewSpace(value))) {
12505 number_of_fields += 1; 12496 number_of_fields += 1;
12506 } 12497 }
12507 } 12498 }
12508 } 12499 }
12509 12500
12510 // Allocate the instance descriptor. 12501 // Allocate the instance descriptor.
12511 DescriptorArray* descriptors; 12502 DescriptorArray* descriptors;
12512 { MaybeObject* maybe_descriptors = 12503 MaybeObject* maybe_descriptors =
12513 DescriptorArray::Allocate(instance_descriptor_length, 12504 DescriptorArray::Allocate(instance_descriptor_length,
12514 DescriptorArray::MAY_BE_SHARED); 12505 DescriptorArray::MAY_BE_SHARED);
12515 if (!maybe_descriptors->To<DescriptorArray>(&descriptors)) { 12506 if (!maybe_descriptors->To(&descriptors)) {
12516 return maybe_descriptors; 12507 return maybe_descriptors;
12517 }
12518 } 12508 }
12519 12509
12520 FixedArray::WhitenessWitness witness(descriptors); 12510 FixedArray::WhitenessWitness witness(descriptors);
12521 12511
12522 int inobject_props = obj->map()->inobject_properties(); 12512 int inobject_props = obj->map()->inobject_properties();
12523 int number_of_allocated_fields = 12513 int number_of_allocated_fields =
12524 number_of_fields + unused_property_fields - inobject_props; 12514 number_of_fields + unused_property_fields - inobject_props;
12525 if (number_of_allocated_fields < 0) { 12515 if (number_of_allocated_fields < 0) {
12526 // There is enough inobject space for all fields (including unused). 12516 // There is enough inobject space for all fields (including unused).
12527 number_of_allocated_fields = 0; 12517 number_of_allocated_fields = 0;
12528 unused_property_fields = inobject_props - number_of_fields; 12518 unused_property_fields = inobject_props - number_of_fields;
12529 } 12519 }
12530 12520
12531 // Allocate the fixed array for the fields. 12521 // Allocate the fixed array for the fields.
12532 Object* fields; 12522 FixedArray* fields;
12533 MaybeObject* maybe_fields = 12523 MaybeObject* maybe_fields =
12534 heap->AllocateFixedArray(number_of_allocated_fields); 12524 heap->AllocateFixedArray(number_of_allocated_fields);
12535 if (!maybe_fields->ToObject(&fields)) return maybe_fields; 12525 if (!maybe_fields->To(&fields)) return maybe_fields;
12536 12526
12537 // Fill in the instance descriptor and the fields. 12527 // Fill in the instance descriptor and the fields.
12538 int next_descriptor = 0; 12528 int next_descriptor = 0;
12539 int current_offset = 0; 12529 int current_offset = 0;
12540 for (int i = 0; i < capacity; i++) { 12530 for (int i = 0; i < capacity; i++) {
12541 Object* k = KeyAt(i); 12531 Object* k = KeyAt(i);
12542 if (IsKey(k)) { 12532 if (IsKey(k)) {
12543 Object* value = ValueAt(i); 12533 Object* value = ValueAt(i);
12544 // Ensure the key is a symbol before writing into the instance descriptor. 12534 // Ensure the key is a symbol before writing into the instance descriptor.
12545 String* key; 12535 String* key;
12546 MaybeObject* maybe_key = heap->LookupSymbol(String::cast(k)); 12536 MaybeObject* maybe_key = heap->LookupSymbol(String::cast(k));
12547 if (!maybe_key->To(&key)) return maybe_key; 12537 if (!maybe_key->To(&key)) return maybe_key;
12548 12538
12549 PropertyDetails details = DetailsAt(i); 12539 PropertyDetails details = DetailsAt(i);
12550 PropertyType type = details.type(); 12540 PropertyType type = details.type();
12551 12541
12552 if (value->IsJSFunction() && !heap->InNewSpace(value)) { 12542 if (value->IsJSFunction() && !heap->InNewSpace(value)) {
12553 ConstantFunctionDescriptor d(key, 12543 ConstantFunctionDescriptor d(key,
12554 JSFunction::cast(value), 12544 JSFunction::cast(value),
12555 details.attributes(), 12545 details.attributes(),
12556 details.index()); 12546 details.index());
12557 descriptors->Set(next_descriptor, &d, witness); 12547 descriptors->Set(next_descriptor, &d, witness);
12558 } else if (type == NORMAL) { 12548 } else if (type == NORMAL) {
12559 if (current_offset < inobject_props) { 12549 if (current_offset < inobject_props) {
12560 obj->InObjectPropertyAtPut(current_offset, 12550 obj->InObjectPropertyAtPut(current_offset,
12561 value, 12551 value,
12562 UPDATE_WRITE_BARRIER); 12552 UPDATE_WRITE_BARRIER);
12563 } else { 12553 } else {
12564 int offset = current_offset - inobject_props; 12554 int offset = current_offset - inobject_props;
12565 FixedArray::cast(fields)->set(offset, value); 12555 fields->set(offset, value);
12566 } 12556 }
12567 FieldDescriptor d(key, 12557 FieldDescriptor d(key,
12568 current_offset++, 12558 current_offset++,
12569 details.attributes(), 12559 details.attributes(),
12570 details.index()); 12560 details.index());
12571 descriptors->Set(next_descriptor, &d, witness); 12561 descriptors->Set(next_descriptor, &d, witness);
12572 } else if (type == CALLBACKS) { 12562 } else if (type == CALLBACKS) {
12573 CallbacksDescriptor d(key, 12563 CallbacksDescriptor d(key,
12574 value, 12564 value,
12575 details.attributes(), 12565 details.attributes(),
(...skipping 11 matching lines...) Expand all
12587 // Allocate new map. 12577 // Allocate new map.
12588 Map* new_map; 12578 Map* new_map;
12589 MaybeObject* maybe_new_map = obj->map()->CopyReplaceDescriptors(descriptors); 12579 MaybeObject* maybe_new_map = obj->map()->CopyReplaceDescriptors(descriptors);
12590 if (!maybe_new_map->To(&new_map)) return maybe_new_map; 12580 if (!maybe_new_map->To(&new_map)) return maybe_new_map;
12591 12581
12592 new_map->set_unused_property_fields(unused_property_fields); 12582 new_map->set_unused_property_fields(unused_property_fields);
12593 12583
12594 // Transform the object. 12584 // Transform the object.
12595 obj->set_map(new_map); 12585 obj->set_map(new_map);
12596 12586
12597 obj->set_properties(FixedArray::cast(fields)); 12587 obj->set_properties(fields);
12598 ASSERT(obj->IsJSObject()); 12588 ASSERT(obj->IsJSObject());
12599 12589
12600 // Check that it really works. 12590 // Check that it really works.
12601 ASSERT(obj->HasFastProperties()); 12591 ASSERT(obj->HasFastProperties());
12602 12592
12603 return obj; 12593 return obj;
12604 } 12594 }
12605 12595
12606 12596
12607 bool ObjectHashSet::Contains(Object* key) { 12597 bool ObjectHashSet::Contains(Object* key) {
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
13101 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); 13091 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER);
13102 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); 13092 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER);
13103 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); 13093 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER);
13104 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); 13094 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER);
13105 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); 13095 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER);
13106 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); 13096 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER);
13107 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); 13097 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER);
13108 } 13098 }
13109 13099
13110 } } // namespace v8::internal 13100 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698