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

Side by Side Diff: src/objects.cc

Issue 1300333003: Introduce SharedFunctionInfo::Iterator and Script::Iterator. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix rebase Created 5 years, 4 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
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/objects.h" 5 #include "src/objects.h"
6 6
7 #include <iomanip> 7 #include <iomanip>
8 #include <sstream> 8 #include <sstream>
9 9
10 #include "src/accessors.h" 10 #include "src/accessors.h"
(...skipping 7798 matching lines...) Expand 10 before | Expand all | Expand 10 after
7809 Object* value = WeakCell::cast(element)->value(); 7809 Object* value = WeakCell::cast(element)->value();
7810 CompactionCallback::Callback(value, i - kFirstIndex, 7810 CompactionCallback::Callback(value, i - kFirstIndex,
7811 new_length - kFirstIndex); 7811 new_length - kFirstIndex);
7812 array->set(new_length++, element); 7812 array->set(new_length++, element);
7813 } 7813 }
7814 array->Shrink(new_length); 7814 array->Shrink(new_length);
7815 set_last_used_index(0); 7815 set_last_used_index(0);
7816 } 7816 }
7817 7817
7818 7818
7819 void WeakFixedArray::Iterator::Reset(Object* maybe_array) {
7820 if (maybe_array->IsWeakFixedArray()) {
7821 list_ = WeakFixedArray::cast(maybe_array);
7822 index_ = 0;
7823 #ifdef DEBUG
7824 last_used_index_ = list_->last_used_index();
7825 #endif // DEBUG
7826 }
7827 }
7828
7829
7819 void JSObject::PrototypeRegistryCompactionCallback::Callback(Object* value, 7830 void JSObject::PrototypeRegistryCompactionCallback::Callback(Object* value,
7820 int old_index, 7831 int old_index,
7821 int new_index) { 7832 int new_index) {
7822 DCHECK(value->IsMap() && Map::cast(value)->is_prototype_map()); 7833 DCHECK(value->IsMap() && Map::cast(value)->is_prototype_map());
7823 Map* map = Map::cast(value); 7834 Map* map = Map::cast(value);
7824 DCHECK(map->prototype_info()->IsPrototypeInfo()); 7835 DCHECK(map->prototype_info()->IsPrototypeInfo());
7825 PrototypeInfo* proto_info = PrototypeInfo::cast(map->prototype_info()); 7836 PrototypeInfo* proto_info = PrototypeInfo::cast(map->prototype_info());
7826 DCHECK_EQ(old_index, proto_info->registry_slot()); 7837 DCHECK_EQ(old_index, proto_info->registry_slot());
7827 proto_info->set_registry_slot(new_index); 7838 proto_info->set_registry_slot(new_index);
7828 } 7839 }
(...skipping 1830 matching lines...) Expand 10 before | Expand all | Expand 10 after
9659 Object* maybe_proto_info = map->prototype_info(); 9670 Object* maybe_proto_info = map->prototype_info();
9660 if (!maybe_proto_info->IsPrototypeInfo()) return; 9671 if (!maybe_proto_info->IsPrototypeInfo()) return;
9661 PrototypeInfo* proto_info = PrototypeInfo::cast(maybe_proto_info); 9672 PrototypeInfo* proto_info = PrototypeInfo::cast(maybe_proto_info);
9662 Object* maybe_cell = proto_info->validity_cell(); 9673 Object* maybe_cell = proto_info->validity_cell();
9663 if (maybe_cell->IsCell()) { 9674 if (maybe_cell->IsCell()) {
9664 // Just set the value; the cell will be replaced lazily. 9675 // Just set the value; the cell will be replaced lazily.
9665 Cell* cell = Cell::cast(maybe_cell); 9676 Cell* cell = Cell::cast(maybe_cell);
9666 cell->set_value(Smi::FromInt(Map::kPrototypeChainInvalid)); 9677 cell->set_value(Smi::FromInt(Map::kPrototypeChainInvalid));
9667 } 9678 }
9668 9679
9669 Object* maybe_array = proto_info->prototype_users(); 9680 WeakFixedArray::Iterator iterator(proto_info->prototype_users());
9670 if (!maybe_array->IsWeakFixedArray()) return; 9681 // For now, only maps register themselves as users.
9671 9682 Map* user;
9672 WeakFixedArray* users = WeakFixedArray::cast(maybe_array); 9683 while ((user = iterator.Next<Map>())) {
9673 for (int i = 0; i < users->Length(); ++i) {
9674 Object* maybe_user = users->Get(i);
9675 if (maybe_user->IsSmi()) continue;
9676
9677 // For now, only maps register themselves as users.
9678 Map* user = Map::cast(maybe_user);
9679 // Walk the prototype chain (backwards, towards leaf objects) if necessary. 9684 // Walk the prototype chain (backwards, towards leaf objects) if necessary.
9680 InvalidatePrototypeChainsInternal(user); 9685 InvalidatePrototypeChainsInternal(user);
9681 } 9686 }
9682 } 9687 }
9683 9688
9684 9689
9685 // static 9690 // static
9686 void JSObject::InvalidatePrototypeChains(Map* map) { 9691 void JSObject::InvalidatePrototypeChains(Map* map) {
9687 if (!FLAG_eliminate_prototype_chain_checks) return; 9692 if (!FLAG_eliminate_prototype_chain_checks) return;
9688 DisallowHeapAllocation no_gc; 9693 DisallowHeapAllocation no_gc;
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
10172 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor)); 10177 Handle<JSValue>::cast(isolate->factory()->NewJSObject(constructor));
10173 result->set_value(*script); 10178 result->set_value(*script);
10174 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(result); 10179 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(result);
10175 script->set_wrapper(*cell); 10180 script->set_wrapper(*cell);
10176 return result; 10181 return result;
10177 } 10182 }
10178 10183
10179 10184
10180 MaybeHandle<SharedFunctionInfo> Script::FindSharedFunctionInfo( 10185 MaybeHandle<SharedFunctionInfo> Script::FindSharedFunctionInfo(
10181 FunctionLiteral* fun) { 10186 FunctionLiteral* fun) {
10182 if (shared_function_infos()->IsWeakFixedArray()) { 10187 WeakFixedArray::Iterator iterator(shared_function_infos());
10183 WeakFixedArray* array = WeakFixedArray::cast(shared_function_infos()); 10188 SharedFunctionInfo* shared;
10184 for (int i = 0; i < array->Length(); i++) { 10189 while ((shared = iterator.Next<SharedFunctionInfo>())) {
10185 Object* obj = array->Get(i); 10190 if (fun->function_token_position() == shared->function_token_position() &&
10186 if (!obj->IsSharedFunctionInfo()) continue; 10191 fun->start_position() == shared->start_position()) {
10187 SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj); 10192 return Handle<SharedFunctionInfo>(shared);
10188 if (fun->function_token_position() == shared->function_token_position() &&
10189 fun->start_position() == shared->start_position()) {
10190 return Handle<SharedFunctionInfo>(shared);
10191 }
10192 } 10193 }
10193 } 10194 }
10194 return MaybeHandle<SharedFunctionInfo>(); 10195 return MaybeHandle<SharedFunctionInfo>();
10195 } 10196 }
10196 10197
10197 10198
10199 Script::Iterator::Iterator(Isolate* isolate)
10200 : iterator_(isolate->heap()->script_list()) {}
10201
10202
10203 Script* Script::Iterator::Next() { return iterator_.Next<Script>(); }
10204
10205
10206 SharedFunctionInfo::Iterator::Iterator(Isolate* isolate)
10207 : script_iterator_(isolate), sfi_iterator_(NULL) {
10208 NextScript();
10209 }
10210
10211
10212 bool SharedFunctionInfo::Iterator::NextScript() {
10213 Script* script = script_iterator_.Next();
10214 if (script == NULL) return false;
10215 sfi_iterator_.Reset(script->shared_function_infos());
10216 return true;
10217 }
10218
10219
10220 SharedFunctionInfo* SharedFunctionInfo::Iterator::Next() {
10221 do {
10222 SharedFunctionInfo* next = sfi_iterator_.Next<SharedFunctionInfo>();
10223 if (next != NULL) return next;
10224 } while (NextScript());
10225 return NULL;
10226 }
10227
10228
10198 void SharedFunctionInfo::SetScript(Handle<SharedFunctionInfo> shared, 10229 void SharedFunctionInfo::SetScript(Handle<SharedFunctionInfo> shared,
10199 Handle<Object> script_object) { 10230 Handle<Object> script_object) {
10200 if (shared->script() == *script_object) return; 10231 if (shared->script() == *script_object) return;
10201 // Remove shared function info from old script's list. 10232 // Remove shared function info from old script's list.
10202 if (shared->script()->IsScript()) { 10233 if (shared->script()->IsScript()) {
10203 Script* old_script = Script::cast(shared->script()); 10234 Script* old_script = Script::cast(shared->script());
10204 if (old_script->shared_function_infos()->IsWeakFixedArray()) { 10235 if (old_script->shared_function_infos()->IsWeakFixedArray()) {
10205 WeakFixedArray* list = 10236 WeakFixedArray* list =
10206 WeakFixedArray::cast(old_script->shared_function_infos()); 10237 WeakFixedArray::cast(old_script->shared_function_infos());
10207 list->Remove(shared); 10238 list->Remove(shared);
10208 } 10239 }
10209 } 10240 }
10210 // Add shared function info to new script's list. 10241 // Add shared function info to new script's list.
10211 if (script_object->IsScript()) { 10242 if (script_object->IsScript()) {
10212 Handle<Script> script = Handle<Script>::cast(script_object); 10243 Handle<Script> script = Handle<Script>::cast(script_object);
10213 Handle<Object> list(script->shared_function_infos(), shared->GetIsolate()); 10244 Handle<Object> list(script->shared_function_infos(), shared->GetIsolate());
10214 #ifdef DEBUG 10245 #ifdef DEBUG
10215 if (list->IsWeakFixedArray()) { 10246 {
10216 Handle<WeakFixedArray> array = Handle<WeakFixedArray>::cast(list); 10247 WeakFixedArray::Iterator iterator(*list);
10217 for (int i = 0; i < array->Length(); ++i) { 10248 SharedFunctionInfo* next;
10218 DCHECK(array->Get(i) != *shared); 10249 while ((next = iterator.Next<SharedFunctionInfo>())) {
10250 DCHECK_NE(next, *shared);
10219 } 10251 }
10220 } 10252 }
10221 #endif // DEBUG 10253 #endif // DEBUG
10222 list = WeakFixedArray::Add(list, shared); 10254 list = WeakFixedArray::Add(list, shared);
10223 script->set_shared_function_infos(*list); 10255 script->set_shared_function_infos(*list);
10224 } 10256 }
10225 // Finally set new script. 10257 // Finally set new script.
10226 shared->set_script(*script_object); 10258 shared->set_script(*script_object);
10227 } 10259 }
10228 10260
(...skipping 5439 matching lines...) Expand 10 before | Expand all | Expand 10 after
15668 if (cell->value() != *new_value) { 15700 if (cell->value() != *new_value) {
15669 cell->set_value(*new_value); 15701 cell->set_value(*new_value);
15670 Isolate* isolate = cell->GetIsolate(); 15702 Isolate* isolate = cell->GetIsolate();
15671 cell->dependent_code()->DeoptimizeDependentCodeGroup( 15703 cell->dependent_code()->DeoptimizeDependentCodeGroup(
15672 isolate, DependentCode::kPropertyCellChangedGroup); 15704 isolate, DependentCode::kPropertyCellChangedGroup);
15673 } 15705 }
15674 } 15706 }
15675 15707
15676 } // namespace internal 15708 } // namespace internal
15677 } // namespace v8 15709 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698