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

Side by Side Diff: src/heap.cc

Issue 3764011: Link all global contexts into a weak list. (Closed)
Patch Set: Created 10 years, 2 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
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "arm/regexp-macro-assembler-arm.h" 47 #include "arm/regexp-macro-assembler-arm.h"
48 #endif 48 #endif
49 49
50 50
51 namespace v8 { 51 namespace v8 {
52 namespace internal { 52 namespace internal {
53 53
54 54
55 String* Heap::hidden_symbol_; 55 String* Heap::hidden_symbol_;
56 Object* Heap::roots_[Heap::kRootListLength]; 56 Object* Heap::roots_[Heap::kRootListLength];
57 Object* Heap::global_contexts_list_;
57 58
58 NewSpace Heap::new_space_; 59 NewSpace Heap::new_space_;
59 OldSpace* Heap::old_pointer_space_ = NULL; 60 OldSpace* Heap::old_pointer_space_ = NULL;
60 OldSpace* Heap::old_data_space_ = NULL; 61 OldSpace* Heap::old_data_space_ = NULL;
61 OldSpace* Heap::code_space_ = NULL; 62 OldSpace* Heap::code_space_ = NULL;
62 MapSpace* Heap::map_space_ = NULL; 63 MapSpace* Heap::map_space_ = NULL;
63 CellSpace* Heap::cell_space_ = NULL; 64 CellSpace* Heap::cell_space_ = NULL;
64 LargeObjectSpace* Heap::lo_space_ = NULL; 65 LargeObjectSpace* Heap::lo_space_ = NULL;
65 66
66 intptr_t Heap::old_gen_promotion_limit_ = kMinimumPromotionLimit; 67 intptr_t Heap::old_gen_promotion_limit_ = kMinimumPromotionLimit;
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 for (HeapObject* cell = cell_iterator.next(); 1028 for (HeapObject* cell = cell_iterator.next();
1028 cell != NULL; cell = cell_iterator.next()) { 1029 cell != NULL; cell = cell_iterator.next()) {
1029 if (cell->IsJSGlobalPropertyCell()) { 1030 if (cell->IsJSGlobalPropertyCell()) {
1030 Address value_address = 1031 Address value_address =
1031 reinterpret_cast<Address>(cell) + 1032 reinterpret_cast<Address>(cell) +
1032 (JSGlobalPropertyCell::kValueOffset - kHeapObjectTag); 1033 (JSGlobalPropertyCell::kValueOffset - kHeapObjectTag);
1033 scavenge_visitor.VisitPointer(reinterpret_cast<Object**>(value_address)); 1034 scavenge_visitor.VisitPointer(reinterpret_cast<Object**>(value_address));
1034 } 1035 }
1035 } 1036 }
1036 1037
1038 // Scavenge object reachable from the global contexts list directly.
1039 scavenge_visitor.VisitPointer(BitCast<Object**>(&global_contexts_list_));
1040
1037 new_space_front = DoScavenge(&scavenge_visitor, new_space_front); 1041 new_space_front = DoScavenge(&scavenge_visitor, new_space_front);
1038 1042
1039 UpdateNewSpaceReferencesInExternalStringTable( 1043 UpdateNewSpaceReferencesInExternalStringTable(
1040 &UpdateNewSpaceReferenceInExternalStringTableEntry); 1044 &UpdateNewSpaceReferenceInExternalStringTableEntry);
1041 1045
1042 ASSERT(new_space_front == new_space_.top()); 1046 ASSERT(new_space_front == new_space_.top());
1043 1047
1044 // Set age mark. 1048 // Set age mark.
1045 new_space_.set_age_mark(new_space_.top()); 1049 new_space_.set_age_mark(new_space_.top());
1046 1050
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 // String got promoted. Move it to the old string list. 1098 // String got promoted. Move it to the old string list.
1095 ExternalStringTable::AddOldString(target); 1099 ExternalStringTable::AddOldString(target);
1096 } 1100 }
1097 } 1101 }
1098 1102
1099 ASSERT(last <= end); 1103 ASSERT(last <= end);
1100 ExternalStringTable::ShrinkNewStrings(static_cast<int>(last - start)); 1104 ExternalStringTable::ShrinkNewStrings(static_cast<int>(last - start));
1101 } 1105 }
1102 1106
1103 1107
1108 void Heap::ProcessWeakReferences(WeakObjectRetainer* retainer) {
1109 Object* head = undefined_value();
1110 Context* tail = NULL;
1111 Object* candidate = global_contexts_list_;
1112 while (!candidate->IsUndefined()) {
1113 // Check whether to keep the candidate in the list.
1114 Context* candidate_context = reinterpret_cast<Context*>(candidate);
1115 Object* retain = retainer->RetainAs(candidate);
1116 if (retain != NULL) {
1117 if (head->IsUndefined()) {
1118 // First element in the list.
1119 head = candidate_context;
1120 } else {
1121 // Subsequent elements in the list.
1122 ASSERT(tail != NULL);
1123 tail->set_unchecked(Context::NEXT_CONTEXT_LINK,
1124 candidate_context,
1125 UPDATE_WRITE_BARRIER);
1126 }
1127 // Retained context is new tail.
1128 tail = candidate_context;
1129 }
1130 // Move to next element in the list.
1131 candidate = candidate_context->get(Context::NEXT_CONTEXT_LINK);
1132 }
1133
1134 // Terminate the list if there is one or more elements.
1135 if (tail != NULL) {
1136 tail->set_unchecked(Context::NEXT_CONTEXT_LINK,
1137 Heap::undefined_value(),
1138 UPDATE_WRITE_BARRIER);
1139 }
1140
1141 // Update the head of the list of contexts.
1142 Heap::global_contexts_list_ = head;
1143 }
1144
1145
1104 class NewSpaceScavenger : public StaticNewSpaceVisitor<NewSpaceScavenger> { 1146 class NewSpaceScavenger : public StaticNewSpaceVisitor<NewSpaceScavenger> {
1105 public: 1147 public:
1106 static inline void VisitPointer(Object** p) { 1148 static inline void VisitPointer(Object** p) {
1107 Object* object = *p; 1149 Object* object = *p;
1108 if (!Heap::InNewSpace(object)) return; 1150 if (!Heap::InNewSpace(object)) return;
1109 Heap::ScavengeObject(reinterpret_cast<HeapObject**>(p), 1151 Heap::ScavengeObject(reinterpret_cast<HeapObject**>(p),
1110 reinterpret_cast<HeapObject*>(object)); 1152 reinterpret_cast<HeapObject*>(object));
1111 } 1153 }
1112 }; 1154 };
1113 1155
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 1192
1151 1193
1152 class ScavengingVisitor : public StaticVisitorBase { 1194 class ScavengingVisitor : public StaticVisitorBase {
1153 public: 1195 public:
1154 static void Initialize() { 1196 static void Initialize() {
1155 table_.Register(kVisitSeqAsciiString, &EvacuateSeqAsciiString); 1197 table_.Register(kVisitSeqAsciiString, &EvacuateSeqAsciiString);
1156 table_.Register(kVisitSeqTwoByteString, &EvacuateSeqTwoByteString); 1198 table_.Register(kVisitSeqTwoByteString, &EvacuateSeqTwoByteString);
1157 table_.Register(kVisitShortcutCandidate, &EvacuateShortcutCandidate); 1199 table_.Register(kVisitShortcutCandidate, &EvacuateShortcutCandidate);
1158 table_.Register(kVisitByteArray, &EvacuateByteArray); 1200 table_.Register(kVisitByteArray, &EvacuateByteArray);
1159 table_.Register(kVisitFixedArray, &EvacuateFixedArray); 1201 table_.Register(kVisitFixedArray, &EvacuateFixedArray);
1202 table_.Register(kVisitGlobalContext,
1203 &ObjectEvacuationStrategy<POINTER_OBJECT>::
1204 VisitSpecialized<Context::kSize>);
1160 1205
1161 typedef ObjectEvacuationStrategy<POINTER_OBJECT> PointerObject; 1206 typedef ObjectEvacuationStrategy<POINTER_OBJECT> PointerObject;
1162 1207
1163 table_.Register(kVisitConsString, 1208 table_.Register(kVisitConsString,
1164 &ObjectEvacuationStrategy<POINTER_OBJECT>:: 1209 &ObjectEvacuationStrategy<POINTER_OBJECT>::
1165 VisitSpecialized<ConsString::kSize>); 1210 VisitSpecialized<ConsString::kSize>);
1166 1211
1167 table_.Register(kVisitSharedFunctionInfo, 1212 table_.Register(kVisitSharedFunctionInfo,
1168 &ObjectEvacuationStrategy<POINTER_OBJECT>:: 1213 &ObjectEvacuationStrategy<POINTER_OBJECT>::
1169 VisitSpecialized<SharedFunctionInfo::kSize>); 1214 VisitSpecialized<SharedFunctionInfo::kSize>);
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
1640 obj = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); 1685 obj = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
1641 if (obj->IsFailure()) return false; 1686 if (obj->IsFailure()) return false;
1642 set_context_map(Map::cast(obj)); 1687 set_context_map(Map::cast(obj));
1643 1688
1644 obj = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); 1689 obj = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
1645 if (obj->IsFailure()) return false; 1690 if (obj->IsFailure()) return false;
1646 set_catch_context_map(Map::cast(obj)); 1691 set_catch_context_map(Map::cast(obj));
1647 1692
1648 obj = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); 1693 obj = AllocateMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel);
1649 if (obj->IsFailure()) return false; 1694 if (obj->IsFailure()) return false;
1650 set_global_context_map(Map::cast(obj)); 1695 Map* global_context_map = Map::cast(obj);
1696 global_context_map->set_visitor_id(StaticVisitorBase::kVisitGlobalContext);
1697 set_global_context_map(global_context_map);
1651 1698
1652 obj = AllocateMap(SHARED_FUNCTION_INFO_TYPE, 1699 obj = AllocateMap(SHARED_FUNCTION_INFO_TYPE,
1653 SharedFunctionInfo::kAlignedSize); 1700 SharedFunctionInfo::kAlignedSize);
1654 if (obj->IsFailure()) return false; 1701 if (obj->IsFailure()) return false;
1655 set_shared_function_info_map(Map::cast(obj)); 1702 set_shared_function_info_map(Map::cast(obj));
1656 1703
1657 ASSERT(!Heap::InNewSpace(Heap::empty_fixed_array())); 1704 ASSERT(!Heap::InNewSpace(Heap::empty_fixed_array()));
1658 return true; 1705 return true;
1659 } 1706 }
1660 1707
(...skipping 2568 matching lines...) Expand 10 before | Expand all | Expand 10 after
4229 if (lo_space_ == NULL) return false; 4276 if (lo_space_ == NULL) return false;
4230 if (!lo_space_->Setup()) return false; 4277 if (!lo_space_->Setup()) return false;
4231 4278
4232 if (create_heap_objects) { 4279 if (create_heap_objects) {
4233 // Create initial maps. 4280 // Create initial maps.
4234 if (!CreateInitialMaps()) return false; 4281 if (!CreateInitialMaps()) return false;
4235 if (!CreateApiObjects()) return false; 4282 if (!CreateApiObjects()) return false;
4236 4283
4237 // Create initial objects 4284 // Create initial objects
4238 if (!CreateInitialObjects()) return false; 4285 if (!CreateInitialObjects()) return false;
4286
4287 global_contexts_list_ = undefined_value();
4239 } 4288 }
4240 4289
4241 LOG(IntPtrTEvent("heap-capacity", Capacity())); 4290 LOG(IntPtrTEvent("heap-capacity", Capacity()));
4242 LOG(IntPtrTEvent("heap-available", Available())); 4291 LOG(IntPtrTEvent("heap-available", Available()));
4243 4292
4244 #ifdef ENABLE_LOGGING_AND_PROFILING 4293 #ifdef ENABLE_LOGGING_AND_PROFILING
4245 // This should be called only after initial objects have been created. 4294 // This should be called only after initial objects have been created.
4246 ProducerHeapProfile::Setup(); 4295 ProducerHeapProfile::Setup();
4247 #endif 4296 #endif
4248 4297
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
4996 void ExternalStringTable::TearDown() { 5045 void ExternalStringTable::TearDown() {
4997 new_space_strings_.Free(); 5046 new_space_strings_.Free();
4998 old_space_strings_.Free(); 5047 old_space_strings_.Free();
4999 } 5048 }
5000 5049
5001 5050
5002 List<Object*> ExternalStringTable::new_space_strings_; 5051 List<Object*> ExternalStringTable::new_space_strings_;
5003 List<Object*> ExternalStringTable::old_space_strings_; 5052 List<Object*> ExternalStringTable::old_space_strings_;
5004 5053
5005 } } // namespace v8::internal 5054 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698