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

Side by Side Diff: src/heap.cc

Issue 149324: * Move almost all roots into an array ready for use by a constant-pool... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 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
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 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 25 matching lines...) Expand all
36 #include "global-handles.h" 36 #include "global-handles.h"
37 #include "mark-compact.h" 37 #include "mark-compact.h"
38 #include "natives.h" 38 #include "natives.h"
39 #include "scanner.h" 39 #include "scanner.h"
40 #include "scopeinfo.h" 40 #include "scopeinfo.h"
41 #include "v8threads.h" 41 #include "v8threads.h"
42 42
43 namespace v8 { 43 namespace v8 {
44 namespace internal { 44 namespace internal {
45 45
46 #define ROOT_ALLOCATION(type, name) type* Heap::name##_;
47 ROOT_LIST(ROOT_ALLOCATION)
48 #undef ROOT_ALLOCATION
49
50
51 #define STRUCT_ALLOCATION(NAME, Name, name) Map* Heap::name##_map_;
52 STRUCT_LIST(STRUCT_ALLOCATION)
53 #undef STRUCT_ALLOCATION
54
55
56 #define SYMBOL_ALLOCATION(name, string) String* Heap::name##_;
57 SYMBOL_LIST(SYMBOL_ALLOCATION)
58 #undef SYMBOL_ALLOCATION
59 46
60 String* Heap::hidden_symbol_; 47 String* Heap::hidden_symbol_;
48 Object* Heap::roots_[Heap::kRootListLength];
49
61 50
62 NewSpace Heap::new_space_; 51 NewSpace Heap::new_space_;
63 OldSpace* Heap::old_pointer_space_ = NULL; 52 OldSpace* Heap::old_pointer_space_ = NULL;
64 OldSpace* Heap::old_data_space_ = NULL; 53 OldSpace* Heap::old_data_space_ = NULL;
65 OldSpace* Heap::code_space_ = NULL; 54 OldSpace* Heap::code_space_ = NULL;
66 MapSpace* Heap::map_space_ = NULL; 55 MapSpace* Heap::map_space_ = NULL;
67 LargeObjectSpace* Heap::lo_space_ = NULL; 56 LargeObjectSpace* Heap::lo_space_ = NULL;
68 57
69 static const int kMinimumPromotionLimit = 2*MB; 58 static const int kMinimumPromotionLimit = 2*MB;
70 static const int kMinimumAllocationLimit = 8*MB; 59 static const int kMinimumAllocationLimit = 8*MB;
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 } 266 }
278 267
279 if (FLAG_print_global_handles) GlobalHandles::Print(); 268 if (FLAG_print_global_handles) GlobalHandles::Print();
280 if (FLAG_print_handles) PrintHandles(); 269 if (FLAG_print_handles) PrintHandles();
281 if (FLAG_gc_verbose) Print(); 270 if (FLAG_gc_verbose) Print();
282 if (FLAG_code_stats) ReportCodeStatistics("After GC"); 271 if (FLAG_code_stats) ReportCodeStatistics("After GC");
283 #endif 272 #endif
284 273
285 Counters::alive_after_last_gc.Set(SizeOfObjects()); 274 Counters::alive_after_last_gc.Set(SizeOfObjects());
286 275
287 SymbolTable* symbol_table = SymbolTable::cast(Heap::symbol_table_); 276 SymbolTable* symbol_table = SymbolTable::cast(Heap::symbol_table());
288 Counters::symbol_table_capacity.Set(symbol_table->Capacity()); 277 Counters::symbol_table_capacity.Set(symbol_table->Capacity());
289 Counters::number_of_symbols.Set(symbol_table->NumberOfElements()); 278 Counters::number_of_symbols.Set(symbol_table->NumberOfElements());
290 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) 279 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING)
291 ReportStatisticsAfterGC(); 280 ReportStatisticsAfterGC();
292 #endif 281 #endif
293 #ifdef ENABLE_DEBUGGER_SUPPORT 282 #ifdef ENABLE_DEBUGGER_SUPPORT
294 Debug::AfterGarbageCollection(); 283 Debug::AfterGarbageCollection();
295 #endif 284 #endif
296 } 285 }
297 286
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 ScavengeObject(p, *p); 994 ScavengeObject(p, *p);
1006 } 995 }
1007 996
1008 997
1009 Object* Heap::AllocatePartialMap(InstanceType instance_type, 998 Object* Heap::AllocatePartialMap(InstanceType instance_type,
1010 int instance_size) { 999 int instance_size) {
1011 Object* result = AllocateRawMap(Map::kSize); 1000 Object* result = AllocateRawMap(Map::kSize);
1012 if (result->IsFailure()) return result; 1001 if (result->IsFailure()) return result;
1013 1002
1014 // Map::cast cannot be used due to uninitialized map field. 1003 // Map::cast cannot be used due to uninitialized map field.
1015 reinterpret_cast<Map*>(result)->set_map(meta_map()); 1004 reinterpret_cast<Map*>(result)->set_map(raw_unchecked_meta_map());
1016 reinterpret_cast<Map*>(result)->set_instance_type(instance_type); 1005 reinterpret_cast<Map*>(result)->set_instance_type(instance_type);
1017 reinterpret_cast<Map*>(result)->set_instance_size(instance_size); 1006 reinterpret_cast<Map*>(result)->set_instance_size(instance_size);
1018 reinterpret_cast<Map*>(result)->set_inobject_properties(0); 1007 reinterpret_cast<Map*>(result)->set_inobject_properties(0);
1019 reinterpret_cast<Map*>(result)->set_unused_property_fields(0); 1008 reinterpret_cast<Map*>(result)->set_unused_property_fields(0);
1020 return result; 1009 return result;
1021 } 1010 }
1022 1011
1023 1012
1024 Object* Heap::AllocateMap(InstanceType instance_type, int instance_size) { 1013 Object* Heap::AllocateMap(InstanceType instance_type, int instance_size) {
1025 Object* result = AllocateRawMap(Map::kSize); 1014 Object* result = AllocateRawMap(Map::kSize);
1026 if (result->IsFailure()) return result; 1015 if (result->IsFailure()) return result;
1027 1016
1028 Map* map = reinterpret_cast<Map*>(result); 1017 Map* map = reinterpret_cast<Map*>(result);
1029 map->set_map(meta_map()); 1018 map->set_map(meta_map());
1030 map->set_instance_type(instance_type); 1019 map->set_instance_type(instance_type);
1031 map->set_prototype(null_value()); 1020 map->set_prototype(null_value());
1032 map->set_constructor(null_value()); 1021 map->set_constructor(null_value());
1033 map->set_instance_size(instance_size); 1022 map->set_instance_size(instance_size);
1034 map->set_inobject_properties(0); 1023 map->set_inobject_properties(0);
1035 map->set_instance_descriptors(empty_descriptor_array()); 1024 map->set_instance_descriptors(empty_descriptor_array());
1036 map->set_code_cache(empty_fixed_array()); 1025 map->set_code_cache(empty_fixed_array());
1037 map->set_unused_property_fields(0); 1026 map->set_unused_property_fields(0);
1038 map->set_bit_field(0); 1027 map->set_bit_field(0);
1039 map->set_bit_field2(0); 1028 map->set_bit_field2(0);
1040 return map; 1029 return map;
1041 } 1030 }
1042 1031
1043 1032
1033 const Heap::StringTypeTable Heap::string_type_table[] = {
1034 #define STRING_TYPE_ELEMENT(type, size, name, camel_name) \
1035 {type, size, k##camel_name##MapRootIndex},
1036 STRING_TYPE_LIST(STRING_TYPE_ELEMENT)
1037 #undef STRING_TYPE_ELEMENT
1038 };
1039
1040
1041 const Heap::ConstantSymbolTable Heap::constant_symbol_table[] = {
1042 #define CONSTANT_SYMBOL_ELEMENT(name, contents) \
1043 {contents, k##name##RootIndex},
1044 SYMBOL_LIST(CONSTANT_SYMBOL_ELEMENT)
1045 #undef CONSTANT_SYMBOL_ELEMENT
1046 };
1047
1048
1049 const Heap::StructTable Heap::struct_table[] = {
1050 #define STRUCT_TABLE_ELEMENT(NAME, Name, name) \
1051 { NAME##_TYPE, Name::kSize, k##Name##MapRootIndex },
1052 STRUCT_LIST(STRUCT_TABLE_ELEMENT)
1053 #undef STRUCT_TABLE_ELEMENT
1054 };
1055
1056
1044 bool Heap::CreateInitialMaps() { 1057 bool Heap::CreateInitialMaps() {
1045 Object* obj = AllocatePartialMap(MAP_TYPE, Map::kSize); 1058 Object* obj = AllocatePartialMap(MAP_TYPE, Map::kSize);
1046 if (obj->IsFailure()) return false; 1059 if (obj->IsFailure()) return false;
1047 1060
1048 // Map::cast cannot be used due to uninitialized map field. 1061 // Map::cast cannot be used due to uninitialized map field.
1049 meta_map_ = reinterpret_cast<Map*>(obj); 1062 Map* new_meta_map = reinterpret_cast<Map*>(obj);
1050 meta_map()->set_map(meta_map()); 1063 roots_[kMetaMapRootIndex] = new_meta_map;
Kasper Lund 2009/07/08 12:42:37 How about automagically generating a private sette
Erik Corry 2009/07/08 14:19:50 Done.
1064 new_meta_map->set_map(new_meta_map);
1051 1065
1052 obj = AllocatePartialMap(FIXED_ARRAY_TYPE, FixedArray::kHeaderSize); 1066 obj = AllocatePartialMap(FIXED_ARRAY_TYPE, FixedArray::kHeaderSize);
1053 if (obj->IsFailure()) return false; 1067 if (obj->IsFailure()) return false;
1054 fixed_array_map_ = Map::cast(obj); 1068 roots_[kFixedArrayMapRootIndex] = Map::cast(obj);
1055 1069
1056 obj = AllocatePartialMap(ODDBALL_TYPE, Oddball::kSize); 1070 obj = AllocatePartialMap(ODDBALL_TYPE, Oddball::kSize);
1057 if (obj->IsFailure()) return false; 1071 if (obj->IsFailure()) return false;
1058 oddball_map_ = Map::cast(obj); 1072 roots_[kOddballMapRootIndex] = Map::cast(obj);
1059 1073
1060 obj = AllocatePartialMap(JS_GLOBAL_PROPERTY_CELL_TYPE, 1074 obj = AllocatePartialMap(JS_GLOBAL_PROPERTY_CELL_TYPE,
1061 JSGlobalPropertyCell::kSize); 1075 JSGlobalPropertyCell::kSize);
1062 if (obj->IsFailure()) return false; 1076 if (obj->IsFailure()) return false;
1063 global_property_cell_map_ = Map::cast(obj); 1077 roots_[kGlobalPropertyCellMapRootIndex] = Map::cast(obj);
1064 1078
1065 // Allocate the empty array 1079 // Allocate the empty array
1066 obj = AllocateEmptyFixedArray(); 1080 obj = AllocateEmptyFixedArray();
1067 if (obj->IsFailure()) return false; 1081 if (obj->IsFailure()) return false;
1068 empty_fixed_array_ = FixedArray::cast(obj); 1082 roots_[kEmptyFixedArrayRootIndex] = FixedArray::cast(obj);
1069 1083
1070 obj = Allocate(oddball_map(), OLD_DATA_SPACE); 1084 obj = Allocate(oddball_map(), OLD_DATA_SPACE);
1071 if (obj->IsFailure()) return false; 1085 if (obj->IsFailure()) return false;
1072 null_value_ = obj; 1086 roots_[kNullValueRootIndex] = obj;
1073 1087
1074 // Allocate the empty descriptor array. AllocateMap can now be used. 1088 // Allocate the empty descriptor array. AllocateMap can now be used.
1075 obj = AllocateEmptyFixedArray(); 1089 obj = AllocateEmptyFixedArray();
1076 if (obj->IsFailure()) return false; 1090 if (obj->IsFailure()) return false;
1077 // There is a check against empty_descriptor_array() in cast(). 1091 // There is a check against empty_descriptor_array() in cast().
1078 empty_descriptor_array_ = reinterpret_cast<DescriptorArray*>(obj); 1092 roots_[kEmptyDescriptorArrayRootIndex] =
1093 reinterpret_cast<DescriptorArray*>(obj);
1079 1094
1080 // Fix the instance_descriptors for the existing maps. 1095 // Fix the instance_descriptors for the existing maps.
1081 meta_map()->set_instance_descriptors(empty_descriptor_array()); 1096 meta_map()->set_instance_descriptors(empty_descriptor_array());
1082 meta_map()->set_code_cache(empty_fixed_array()); 1097 meta_map()->set_code_cache(empty_fixed_array());
1083 1098
1084 fixed_array_map()->set_instance_descriptors(empty_descriptor_array()); 1099 fixed_array_map()->set_instance_descriptors(empty_descriptor_array());
1085 fixed_array_map()->set_code_cache(empty_fixed_array()); 1100 fixed_array_map()->set_code_cache(empty_fixed_array());
1086 1101
1087 oddball_map()->set_instance_descriptors(empty_descriptor_array()); 1102 oddball_map()->set_instance_descriptors(empty_descriptor_array());
1088 oddball_map()->set_code_cache(empty_fixed_array()); 1103 oddball_map()->set_code_cache(empty_fixed_array());
1089 1104
1090 global_property_cell_map()->set_instance_descriptors( 1105 global_property_cell_map()->set_instance_descriptors(
1091 empty_descriptor_array()); 1106 empty_descriptor_array());
1092 global_property_cell_map()->set_code_cache(empty_fixed_array()); 1107 global_property_cell_map()->set_code_cache(empty_fixed_array());
1093 1108
1094 // Fix prototype object for existing maps. 1109 // Fix prototype object for existing maps.
1095 meta_map()->set_prototype(null_value()); 1110 meta_map()->set_prototype(null_value());
1096 meta_map()->set_constructor(null_value()); 1111 meta_map()->set_constructor(null_value());
1097 1112
1098 fixed_array_map()->set_prototype(null_value()); 1113 fixed_array_map()->set_prototype(null_value());
1099 fixed_array_map()->set_constructor(null_value()); 1114 fixed_array_map()->set_constructor(null_value());
1100 oddball_map()->set_prototype(null_value()); 1115 oddball_map()->set_prototype(null_value());
1101 oddball_map()->set_constructor(null_value()); 1116 oddball_map()->set_constructor(null_value());
1102 1117
1103 global_property_cell_map()->set_prototype(null_value()); 1118 global_property_cell_map()->set_prototype(null_value());
1104 global_property_cell_map()->set_constructor(null_value()); 1119 global_property_cell_map()->set_constructor(null_value());
1105 1120
1106 obj = AllocateMap(HEAP_NUMBER_TYPE, HeapNumber::kSize); 1121 obj = AllocateMap(HEAP_NUMBER_TYPE, HeapNumber::kSize);
1107 if (obj->IsFailure()) return false; 1122 if (obj->IsFailure()) return false;
1108 heap_number_map_ = Map::cast(obj); 1123 roots_[kHeapNumberMapRootIndex] = Map::cast(obj);
1109 1124
1110 obj = AllocateMap(PROXY_TYPE, Proxy::kSize); 1125 obj = AllocateMap(PROXY_TYPE, Proxy::kSize);
1111 if (obj->IsFailure()) return false; 1126 if (obj->IsFailure()) return false;
1112 proxy_map_ = Map::cast(obj); 1127 roots_[kProxyMapRootIndex] = Map::cast(obj);
1113 1128
1114 #define ALLOCATE_STRING_MAP(type, size, name) \ 1129 for (unsigned i = 0; i < ARRAY_SIZE(string_type_table); i++) {
1115 obj = AllocateMap(type, size); \ 1130 const StringTypeTable& entry = string_type_table[i];
1116 if (obj->IsFailure()) return false; \ 1131 obj = AllocateMap(entry.type, entry.size);
1117 name##_map_ = Map::cast(obj); 1132 if (obj->IsFailure()) return false;
1118 STRING_TYPE_LIST(ALLOCATE_STRING_MAP); 1133 roots_[entry.index] = Map::cast(obj);
1119 #undef ALLOCATE_STRING_MAP 1134 }
1120 1135
1121 obj = AllocateMap(SHORT_STRING_TYPE, SeqTwoByteString::kAlignedSize); 1136 obj = AllocateMap(SHORT_STRING_TYPE, SeqTwoByteString::kSize);
1122 if (obj->IsFailure()) return false; 1137 if (obj->IsFailure()) return false;
1123 undetectable_short_string_map_ = Map::cast(obj); 1138 roots_[kUndetectableShortStringMapRootIndex] = Map::cast(obj);
1124 undetectable_short_string_map_->set_is_undetectable(); 1139 Map::cast(obj)->set_is_undetectable();
1125 1140
1126 obj = AllocateMap(MEDIUM_STRING_TYPE, SeqTwoByteString::kAlignedSize); 1141 obj = AllocateMap(MEDIUM_STRING_TYPE, SeqTwoByteString::kSize);
1127 if (obj->IsFailure()) return false; 1142 if (obj->IsFailure()) return false;
1128 undetectable_medium_string_map_ = Map::cast(obj); 1143 roots_[kUndetectableMediumStringMapRootIndex] = Map::cast(obj);
1129 undetectable_medium_string_map_->set_is_undetectable(); 1144 Map::cast(obj)->set_is_undetectable();
1130 1145
1131 obj = AllocateMap(LONG_STRING_TYPE, SeqTwoByteString::kAlignedSize); 1146 obj = AllocateMap(LONG_STRING_TYPE, SeqTwoByteString::kSize);
1132 if (obj->IsFailure()) return false; 1147 if (obj->IsFailure()) return false;
1133 undetectable_long_string_map_ = Map::cast(obj); 1148 roots_[kUndetectableLongStringMapRootIndex] = Map::cast(obj);
1134 undetectable_long_string_map_->set_is_undetectable(); 1149 Map::cast(obj)->set_is_undetectable();
1135 1150
1136 obj = AllocateMap(SHORT_ASCII_STRING_TYPE, SeqAsciiString::kAlignedSize); 1151 obj = AllocateMap(SHORT_ASCII_STRING_TYPE, SeqAsciiString::kSize);
1137 if (obj->IsFailure()) return false; 1152 if (obj->IsFailure()) return false;
1138 undetectable_short_ascii_string_map_ = Map::cast(obj); 1153 roots_[kUndetectableShortAsciiStringMapRootIndex] = Map::cast(obj);
1139 undetectable_short_ascii_string_map_->set_is_undetectable(); 1154 Map::cast(obj)->set_is_undetectable();
1140 1155
1141 obj = AllocateMap(MEDIUM_ASCII_STRING_TYPE, SeqAsciiString::kAlignedSize); 1156 obj = AllocateMap(MEDIUM_ASCII_STRING_TYPE, SeqAsciiString::kSize);
1142 if (obj->IsFailure()) return false; 1157 if (obj->IsFailure()) return false;
1143 undetectable_medium_ascii_string_map_ = Map::cast(obj); 1158 roots_[kUndetectableMediumAsciiStringMapRootIndex] = Map::cast(obj);
1144 undetectable_medium_ascii_string_map_->set_is_undetectable(); 1159 Map::cast(obj)->set_is_undetectable();
1145 1160
1146 obj = AllocateMap(LONG_ASCII_STRING_TYPE, SeqAsciiString::kAlignedSize); 1161 obj = AllocateMap(LONG_ASCII_STRING_TYPE, SeqAsciiString::kSize);
1147 if (obj->IsFailure()) return false; 1162 if (obj->IsFailure()) return false;
1148 undetectable_long_ascii_string_map_ = Map::cast(obj); 1163 roots_[kUndetectableLongAsciiStringMapRootIndex] = Map::cast(obj);
1149 undetectable_long_ascii_string_map_->set_is_undetectable(); 1164 Map::cast(obj)->set_is_undetectable();
1150 1165
1151 obj = AllocateMap(BYTE_ARRAY_TYPE, Array::kAlignedSize); 1166 obj = AllocateMap(BYTE_ARRAY_TYPE, Array::kAlignedSize);
1152 if (obj->IsFailure()) return false; 1167 if (obj->IsFailure()) return false;
1153 byte_array_map_ = Map::cast(obj); 1168 roots_[kByteArrayMapRootIndex] = Map::cast(obj);
1154 1169
1155 obj = AllocateMap(CODE_TYPE, Code::kHeaderSize); 1170 obj = AllocateMap(CODE_TYPE, Code::kHeaderSize);
1156 if (obj->IsFailure()) return false; 1171 if (obj->IsFailure()) return false;
1157 code_map_ = Map::cast(obj); 1172 roots_[kCodeMapRootIndex] = Map::cast(obj);
1158 1173
1159 obj = AllocateMap(FILLER_TYPE, kPointerSize); 1174 obj = AllocateMap(FILLER_TYPE, kPointerSize);
1160 if (obj->IsFailure()) return false; 1175 if (obj->IsFailure()) return false;
1161 one_word_filler_map_ = Map::cast(obj); 1176 roots_[kOneWordFillerMapRootIndex] = Map::cast(obj);
1162 1177
1163 obj = AllocateMap(FILLER_TYPE, 2 * kPointerSize); 1178 obj = AllocateMap(FILLER_TYPE, 2 * kPointerSize);
1164 if (obj->IsFailure()) return false; 1179 if (obj->IsFailure()) return false;
1165 two_word_filler_map_ = Map::cast(obj); 1180 roots_[kTwoWordFillerMapRootIndex] = Map::cast(obj);
1166 1181
1167 #define ALLOCATE_STRUCT_MAP(NAME, Name, name) \ 1182 for (unsigned i = 0; i < ARRAY_SIZE(struct_table); i++) {
1168 obj = AllocateMap(NAME##_TYPE, Name::kSize); \ 1183 const StructTable& entry = struct_table[i];
1169 if (obj->IsFailure()) return false; \ 1184 obj = AllocateMap(entry.type, entry.size);
1170 name##_map_ = Map::cast(obj); 1185 if (obj->IsFailure()) return false;
1171 STRUCT_LIST(ALLOCATE_STRUCT_MAP) 1186 roots_[entry.index] = Map::cast(obj);
1172 #undef ALLOCATE_STRUCT_MAP 1187 }
1173 1188
1174 obj = AllocateMap(FIXED_ARRAY_TYPE, HeapObject::kHeaderSize); 1189 obj = AllocateMap(FIXED_ARRAY_TYPE, HeapObject::kHeaderSize);
1175 if (obj->IsFailure()) return false; 1190 if (obj->IsFailure()) return false;
1176 hash_table_map_ = Map::cast(obj); 1191 roots_[kHashTableMapRootIndex] = Map::cast(obj);
1177 1192
1178 obj = AllocateMap(FIXED_ARRAY_TYPE, HeapObject::kHeaderSize); 1193 obj = AllocateMap(FIXED_ARRAY_TYPE, HeapObject::kHeaderSize);
1179 if (obj->IsFailure()) return false; 1194 if (obj->IsFailure()) return false;
1180 context_map_ = Map::cast(obj); 1195 roots_[kContextMapRootIndex] = Map::cast(obj);
1181 1196
1182 obj = AllocateMap(FIXED_ARRAY_TYPE, HeapObject::kHeaderSize); 1197 obj = AllocateMap(FIXED_ARRAY_TYPE, HeapObject::kHeaderSize);
1183 if (obj->IsFailure()) return false; 1198 if (obj->IsFailure()) return false;
1184 catch_context_map_ = Map::cast(obj); 1199 roots_[kCatchContextMapRootIndex] = Map::cast(obj);
1185 1200
1186 obj = AllocateMap(FIXED_ARRAY_TYPE, HeapObject::kHeaderSize); 1201 obj = AllocateMap(FIXED_ARRAY_TYPE, HeapObject::kHeaderSize);
1187 if (obj->IsFailure()) return false; 1202 if (obj->IsFailure()) return false;
1188 global_context_map_ = Map::cast(obj); 1203 roots_[kGlobalContextMapRootIndex] = Map::cast(obj);
1189 1204
1190 obj = AllocateMap(JS_FUNCTION_TYPE, JSFunction::kSize); 1205 obj = AllocateMap(JS_FUNCTION_TYPE, JSFunction::kSize);
1191 if (obj->IsFailure()) return false; 1206 if (obj->IsFailure()) return false;
1192 boilerplate_function_map_ = Map::cast(obj); 1207 roots_[kBoilerplateFunctionMapRootIndex] = Map::cast(obj);
1193 1208
1194 obj = AllocateMap(SHARED_FUNCTION_INFO_TYPE, SharedFunctionInfo::kSize); 1209 obj = AllocateMap(SHARED_FUNCTION_INFO_TYPE, SharedFunctionInfo::kSize);
1195 if (obj->IsFailure()) return false; 1210 if (obj->IsFailure()) return false;
1196 shared_function_info_map_ = Map::cast(obj); 1211 roots_[kSharedFunctionInfoMapRootIndex] = Map::cast(obj);
1197 1212
1198 ASSERT(!Heap::InNewSpace(Heap::empty_fixed_array())); 1213 ASSERT(!Heap::InNewSpace(Heap::empty_fixed_array()));
1199 return true; 1214 return true;
1200 } 1215 }
1201 1216
1202 1217
1203 Object* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) { 1218 Object* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) {
1204 // Statically ensure that it is safe to allocate heap numbers in paged 1219 // Statically ensure that it is safe to allocate heap numbers in paged
1205 // spaces. 1220 // spaces.
1206 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize); 1221 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 if (result->IsFailure()) return result; 1262 if (result->IsFailure()) return result;
1248 return Oddball::cast(result)->Initialize(to_string, to_number); 1263 return Oddball::cast(result)->Initialize(to_string, to_number);
1249 } 1264 }
1250 1265
1251 1266
1252 bool Heap::CreateApiObjects() { 1267 bool Heap::CreateApiObjects() {
1253 Object* obj; 1268 Object* obj;
1254 1269
1255 obj = AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 1270 obj = AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
1256 if (obj->IsFailure()) return false; 1271 if (obj->IsFailure()) return false;
1257 neander_map_ = Map::cast(obj); 1272 roots_[kNeanderMapRootIndex] = Map::cast(obj);
1258 1273
1259 obj = Heap::AllocateJSObjectFromMap(neander_map_); 1274 obj = Heap::AllocateJSObjectFromMap(neander_map());
1260 if (obj->IsFailure()) return false; 1275 if (obj->IsFailure()) return false;
1261 Object* elements = AllocateFixedArray(2); 1276 Object* elements = AllocateFixedArray(2);
1262 if (elements->IsFailure()) return false; 1277 if (elements->IsFailure()) return false;
1263 FixedArray::cast(elements)->set(0, Smi::FromInt(0)); 1278 FixedArray::cast(elements)->set(0, Smi::FromInt(0));
1264 JSObject::cast(obj)->set_elements(FixedArray::cast(elements)); 1279 JSObject::cast(obj)->set_elements(FixedArray::cast(elements));
1265 message_listeners_ = JSObject::cast(obj); 1280 roots_[kMessageListenersRootIndex] = JSObject::cast(obj);
1266 1281
1267 return true; 1282 return true;
1268 } 1283 }
1269 1284
1270 1285
1271 void Heap::CreateCEntryStub() { 1286 void Heap::CreateCEntryStub() {
1272 CEntryStub stub; 1287 CEntryStub stub;
1273 c_entry_code_ = *stub.GetCode(); 1288 roots_[kCEntryCodeRootIndex] = *stub.GetCode();
1274 } 1289 }
1275 1290
1276 1291
1277 void Heap::CreateCEntryDebugBreakStub() { 1292 void Heap::CreateCEntryDebugBreakStub() {
1278 CEntryDebugBreakStub stub; 1293 CEntryDebugBreakStub stub;
1279 c_entry_debug_break_code_ = *stub.GetCode(); 1294 roots_[kCEntryDebugBreakCodeRootIndex] = *stub.GetCode();
1280 } 1295 }
1281 1296
1282 1297
1283 void Heap::CreateJSEntryStub() { 1298 void Heap::CreateJSEntryStub() {
1284 JSEntryStub stub; 1299 JSEntryStub stub;
1285 js_entry_code_ = *stub.GetCode(); 1300 roots_[kJsEntryCodeRootIndex] = *stub.GetCode();
1286 } 1301 }
1287 1302
1288 1303
1289 void Heap::CreateJSConstructEntryStub() { 1304 void Heap::CreateJSConstructEntryStub() {
1290 JSConstructEntryStub stub; 1305 JSConstructEntryStub stub;
1291 js_construct_entry_code_ = *stub.GetCode(); 1306 roots_[kJsConstructEntryCodeRootIndex] = *stub.GetCode();
1292 } 1307 }
1293 1308
1294 1309
1295 void Heap::CreateFixedStubs() { 1310 void Heap::CreateFixedStubs() {
1296 // Here we create roots for fixed stubs. They are needed at GC 1311 // Here we create roots for fixed stubs. They are needed at GC
1297 // for cooking and uncooking (check out frames.cc). 1312 // for cooking and uncooking (check out frames.cc).
1298 // The eliminates the need for doing dictionary lookup in the 1313 // The eliminates the need for doing dictionary lookup in the
1299 // stub cache for these stubs. 1314 // stub cache for these stubs.
1300 HandleScope scope; 1315 HandleScope scope;
1301 // gcc-4.4 has problem generating correct code of following snippet: 1316 // gcc-4.4 has problem generating correct code of following snippet:
(...skipping 10 matching lines...) Expand all
1312 Heap::CreateJSConstructEntryStub(); 1327 Heap::CreateJSConstructEntryStub();
1313 } 1328 }
1314 1329
1315 1330
1316 bool Heap::CreateInitialObjects() { 1331 bool Heap::CreateInitialObjects() {
1317 Object* obj; 1332 Object* obj;
1318 1333
1319 // The -0 value must be set before NumberFromDouble works. 1334 // The -0 value must be set before NumberFromDouble works.
1320 obj = AllocateHeapNumber(-0.0, TENURED); 1335 obj = AllocateHeapNumber(-0.0, TENURED);
1321 if (obj->IsFailure()) return false; 1336 if (obj->IsFailure()) return false;
1322 minus_zero_value_ = obj; 1337 roots_[kMinusZeroValueRootIndex] = obj;
1323 ASSERT(signbit(minus_zero_value_->Number()) != 0); 1338 ASSERT(signbit(minus_zero_value()->Number()) != 0);
1324 1339
1325 obj = AllocateHeapNumber(OS::nan_value(), TENURED); 1340 obj = AllocateHeapNumber(OS::nan_value(), TENURED);
1326 if (obj->IsFailure()) return false; 1341 if (obj->IsFailure()) return false;
1327 nan_value_ = obj; 1342 roots_[kNanValueRootIndex] = obj;
1328 1343
1329 obj = Allocate(oddball_map(), OLD_DATA_SPACE); 1344 obj = Allocate(oddball_map(), OLD_DATA_SPACE);
1330 if (obj->IsFailure()) return false; 1345 if (obj->IsFailure()) return false;
1331 undefined_value_ = obj; 1346 roots_[kUndefinedValueRootIndex] = obj;
1332 ASSERT(!InNewSpace(undefined_value())); 1347 ASSERT(!InNewSpace(undefined_value()));
1333 1348
1334 // Allocate initial symbol table. 1349 // Allocate initial symbol table.
1335 obj = SymbolTable::Allocate(kInitialSymbolTableSize); 1350 obj = SymbolTable::Allocate(kInitialSymbolTableSize);
1336 if (obj->IsFailure()) return false; 1351 if (obj->IsFailure()) return false;
1337 symbol_table_ = obj; 1352 roots_[kSymbolTableRootIndex] = obj;
1338 1353
1339 // Assign the print strings for oddballs after creating symboltable. 1354 // Assign the print strings for oddballs after creating symboltable.
1340 Object* symbol = LookupAsciiSymbol("undefined"); 1355 Object* symbol = LookupAsciiSymbol("undefined");
1341 if (symbol->IsFailure()) return false; 1356 if (symbol->IsFailure()) return false;
1342 Oddball::cast(undefined_value_)->set_to_string(String::cast(symbol)); 1357 Oddball::cast(undefined_value())->set_to_string(String::cast(symbol));
1343 Oddball::cast(undefined_value_)->set_to_number(nan_value_); 1358 Oddball::cast(undefined_value())->set_to_number(nan_value());
1344 1359
1345 // Assign the print strings for oddballs after creating symboltable. 1360 // Assign the print strings for oddballs after creating symboltable.
1346 symbol = LookupAsciiSymbol("null"); 1361 symbol = LookupAsciiSymbol("null");
1347 if (symbol->IsFailure()) return false; 1362 if (symbol->IsFailure()) return false;
1348 Oddball::cast(null_value_)->set_to_string(String::cast(symbol)); 1363 Oddball::cast(null_value())->set_to_string(String::cast(symbol));
1349 Oddball::cast(null_value_)->set_to_number(Smi::FromInt(0)); 1364 Oddball::cast(null_value())->set_to_number(Smi::FromInt(0));
1350 1365
1351 // Allocate the null_value 1366 // Allocate the null_value
1352 obj = Oddball::cast(null_value())->Initialize("null", Smi::FromInt(0)); 1367 obj = Oddball::cast(null_value())->Initialize("null", Smi::FromInt(0));
1353 if (obj->IsFailure()) return false; 1368 if (obj->IsFailure()) return false;
1354 1369
1355 obj = CreateOddball(oddball_map(), "true", Smi::FromInt(1)); 1370 obj = CreateOddball(oddball_map(), "true", Smi::FromInt(1));
1356 if (obj->IsFailure()) return false; 1371 if (obj->IsFailure()) return false;
1357 true_value_ = obj; 1372 roots_[kTrueValueRootIndex] = obj;
1358 1373
1359 obj = CreateOddball(oddball_map(), "false", Smi::FromInt(0)); 1374 obj = CreateOddball(oddball_map(), "false", Smi::FromInt(0));
1360 if (obj->IsFailure()) return false; 1375 if (obj->IsFailure()) return false;
1361 false_value_ = obj; 1376 roots_[kFalseValueRootIndex] = obj;
1362 1377
1363 obj = CreateOddball(oddball_map(), "hole", Smi::FromInt(-1)); 1378 obj = CreateOddball(oddball_map(), "hole", Smi::FromInt(-1));
1364 if (obj->IsFailure()) return false; 1379 if (obj->IsFailure()) return false;
1365 the_hole_value_ = obj; 1380 roots_[kTheHoleValueRootIndex] = obj;
1366 1381
1367 // Allocate the empty string. 1382 // Allocate the empty string.
1368 obj = AllocateRawAsciiString(0, TENURED); 1383 obj = AllocateRawAsciiString(0, TENURED);
1369 if (obj->IsFailure()) return false; 1384 if (obj->IsFailure()) return false;
1370 empty_string_ = String::cast(obj); 1385 roots_[kEmptyStringRootIndex] = String::cast(obj);
1371 1386
1372 #define SYMBOL_INITIALIZE(name, string) \ 1387 for (unsigned i = 0; i < ARRAY_SIZE(constant_symbol_table); i++) {
1373 obj = LookupAsciiSymbol(string); \ 1388 obj = LookupAsciiSymbol(constant_symbol_table[i].contents);
1374 if (obj->IsFailure()) return false; \ 1389 if (obj->IsFailure()) return false;
1375 (name##_) = String::cast(obj); 1390 roots_[constant_symbol_table[i].index] = String::cast(obj);
1376 SYMBOL_LIST(SYMBOL_INITIALIZE) 1391 }
1377 #undef SYMBOL_INITIALIZE
1378 1392
1379 // Allocate the hidden symbol which is used to identify the hidden properties 1393 // Allocate the hidden symbol which is used to identify the hidden properties
1380 // in JSObjects. The hash code has a special value so that it will not match 1394 // in JSObjects. The hash code has a special value so that it will not match
1381 // the empty string when searching for the property. It cannot be part of the 1395 // the empty string when searching for the property. It cannot be part of the
1382 // SYMBOL_LIST because it needs to be allocated manually with the special 1396 // loop above because it needs to be allocated manually with the special
1383 // hash code in place. The hash code for the hidden_symbol is zero to ensure 1397 // hash code in place. The hash code for the hidden_symbol is zero to ensure
1384 // that it will always be at the first entry in property descriptors. 1398 // that it will always be at the first entry in property descriptors.
1385 obj = AllocateSymbol(CStrVector(""), 0, String::kHashComputedMask); 1399 obj = AllocateSymbol(CStrVector(""), 0, String::kHashComputedMask);
1386 if (obj->IsFailure()) return false; 1400 if (obj->IsFailure()) return false;
1387 hidden_symbol_ = String::cast(obj); 1401 hidden_symbol_ = String::cast(obj);
1388 1402
1389 // Allocate the proxy for __proto__. 1403 // Allocate the proxy for __proto__.
1390 obj = AllocateProxy((Address) &Accessors::ObjectPrototype); 1404 obj = AllocateProxy((Address) &Accessors::ObjectPrototype);
1391 if (obj->IsFailure()) return false; 1405 if (obj->IsFailure()) return false;
1392 prototype_accessors_ = Proxy::cast(obj); 1406 roots_[kPrototypeAccessorsRootIndex] = Proxy::cast(obj);
1393 1407
1394 // Allocate the code_stubs dictionary. 1408 // Allocate the code_stubs dictionary.
1395 obj = NumberDictionary::Allocate(4); 1409 obj = NumberDictionary::Allocate(4);
1396 if (obj->IsFailure()) return false; 1410 if (obj->IsFailure()) return false;
1397 code_stubs_ = NumberDictionary::cast(obj); 1411 roots_[kCodeStubsRootIndex] = NumberDictionary::cast(obj);
1398 1412
1399 // Allocate the non_monomorphic_cache used in stub-cache.cc 1413 // Allocate the non_monomorphic_cache used in stub-cache.cc
1400 obj = NumberDictionary::Allocate(4); 1414 obj = NumberDictionary::Allocate(4);
1401 if (obj->IsFailure()) return false; 1415 if (obj->IsFailure()) return false;
1402 non_monomorphic_cache_ = NumberDictionary::cast(obj); 1416 roots_[kNonMonomorphicCacheRootIndex] = NumberDictionary::cast(obj);
1403 1417
1404 CreateFixedStubs(); 1418 CreateFixedStubs();
1405 1419
1406 // Allocate the number->string conversion cache 1420 // Allocate the number->string conversion cache
1407 obj = AllocateFixedArray(kNumberStringCacheSize * 2); 1421 obj = AllocateFixedArray(kNumberStringCacheSize * 2);
1408 if (obj->IsFailure()) return false; 1422 if (obj->IsFailure()) return false;
1409 number_string_cache_ = FixedArray::cast(obj); 1423 roots_[kNumberStringCacheRootIndex] = FixedArray::cast(obj);
1410 1424
1411 // Allocate cache for single character strings. 1425 // Allocate cache for single character strings.
1412 obj = AllocateFixedArray(String::kMaxAsciiCharCode+1); 1426 obj = AllocateFixedArray(String::kMaxAsciiCharCode+1);
1413 if (obj->IsFailure()) return false; 1427 if (obj->IsFailure()) return false;
1414 single_character_string_cache_ = FixedArray::cast(obj); 1428 roots_[kSingleCharacterStringCacheRootIndex] = FixedArray::cast(obj);
1415 1429
1416 // Allocate cache for external strings pointing to native source code. 1430 // Allocate cache for external strings pointing to native source code.
1417 obj = AllocateFixedArray(Natives::GetBuiltinsCount()); 1431 obj = AllocateFixedArray(Natives::GetBuiltinsCount());
1418 if (obj->IsFailure()) return false; 1432 if (obj->IsFailure()) return false;
1419 natives_source_cache_ = FixedArray::cast(obj); 1433 roots_[kNativesSourceCacheRootIndex] = FixedArray::cast(obj);
1420 1434
1421 // Handling of script id generation is in Factory::NewScript. 1435 // Handling of script id generation is in Factory::NewScript.
1422 last_script_id_ = undefined_value(); 1436 roots_[kLastScriptIdRootIndex] = undefined_value();
1423 1437
1424 // Initialize keyed lookup cache. 1438 // Initialize keyed lookup cache.
1425 KeyedLookupCache::Clear(); 1439 KeyedLookupCache::Clear();
1426 1440
1427 // Initialize context slot cache. 1441 // Initialize context slot cache.
1428 ContextSlotCache::Clear(); 1442 ContextSlotCache::Clear();
1429 1443
1430 // Initialize descriptor cache. 1444 // Initialize descriptor cache.
1431 DescriptorLookupCache::Clear(); 1445 DescriptorLookupCache::Clear();
1432 1446
(...skipping 17 matching lines...) Expand all
1450 1464
1451 1465
1452 1466
1453 Object* Heap::GetNumberStringCache(Object* number) { 1467 Object* Heap::GetNumberStringCache(Object* number) {
1454 int hash; 1468 int hash;
1455 if (number->IsSmi()) { 1469 if (number->IsSmi()) {
1456 hash = smi_get_hash(Smi::cast(number)); 1470 hash = smi_get_hash(Smi::cast(number));
1457 } else { 1471 } else {
1458 hash = double_get_hash(number->Number()); 1472 hash = double_get_hash(number->Number());
1459 } 1473 }
1460 Object* key = number_string_cache_->get(hash * 2); 1474 Object* key = number_string_cache()->get(hash * 2);
1461 if (key == number) { 1475 if (key == number) {
1462 return String::cast(number_string_cache_->get(hash * 2 + 1)); 1476 return String::cast(number_string_cache()->get(hash * 2 + 1));
1463 } else if (key->IsHeapNumber() && 1477 } else if (key->IsHeapNumber() &&
1464 number->IsHeapNumber() && 1478 number->IsHeapNumber() &&
1465 key->Number() == number->Number()) { 1479 key->Number() == number->Number()) {
1466 return String::cast(number_string_cache_->get(hash * 2 + 1)); 1480 return String::cast(number_string_cache()->get(hash * 2 + 1));
1467 } 1481 }
1468 return undefined_value(); 1482 return undefined_value();
1469 } 1483 }
1470 1484
1471 1485
1472 void Heap::SetNumberStringCache(Object* number, String* string) { 1486 void Heap::SetNumberStringCache(Object* number, String* string) {
1473 int hash; 1487 int hash;
1474 if (number->IsSmi()) { 1488 if (number->IsSmi()) {
1475 hash = smi_get_hash(Smi::cast(number)); 1489 hash = smi_get_hash(Smi::cast(number));
1476 number_string_cache_->set(hash * 2, number, SKIP_WRITE_BARRIER); 1490 number_string_cache()->set(hash * 2, number, SKIP_WRITE_BARRIER);
1477 } else { 1491 } else {
1478 hash = double_get_hash(number->Number()); 1492 hash = double_get_hash(number->Number());
1479 number_string_cache_->set(hash * 2, number); 1493 number_string_cache()->set(hash * 2, number);
1480 } 1494 }
1481 number_string_cache_->set(hash * 2 + 1, string); 1495 number_string_cache()->set(hash * 2 + 1, string);
1482 } 1496 }
1483 1497
1484 1498
1485 Object* Heap::SmiOrNumberFromDouble(double value, 1499 Object* Heap::SmiOrNumberFromDouble(double value,
1486 bool new_object, 1500 bool new_object,
1487 PretenureFlag pretenure) { 1501 PretenureFlag pretenure) {
1488 // We need to distinguish the minus zero value and this cannot be 1502 // We need to distinguish the minus zero value and this cannot be
1489 // done after conversion to int. Doing this by comparing bit 1503 // done after conversion to int. Doing this by comparing bit
1490 // patterns is faster than using fpclassify() et al. 1504 // patterns is faster than using fpclassify() et al.
1491 static const DoubleRepresentation plus_zero(0.0); 1505 static const DoubleRepresentation plus_zero(0.0);
1492 static const DoubleRepresentation minus_zero(-0.0); 1506 static const DoubleRepresentation minus_zero(-0.0);
1493 static const DoubleRepresentation nan(OS::nan_value()); 1507 static const DoubleRepresentation nan(OS::nan_value());
1494 ASSERT(minus_zero_value_ != NULL); 1508 ASSERT(minus_zero_value() != NULL);
1495 ASSERT(sizeof(plus_zero.value) == sizeof(plus_zero.bits)); 1509 ASSERT(sizeof(plus_zero.value) == sizeof(plus_zero.bits));
1496 1510
1497 DoubleRepresentation rep(value); 1511 DoubleRepresentation rep(value);
1498 if (rep.bits == plus_zero.bits) return Smi::FromInt(0); // not uncommon 1512 if (rep.bits == plus_zero.bits) return Smi::FromInt(0); // not uncommon
1499 if (rep.bits == minus_zero.bits) { 1513 if (rep.bits == minus_zero.bits) {
1500 return new_object ? AllocateHeapNumber(-0.0, pretenure) 1514 return new_object ? AllocateHeapNumber(-0.0, pretenure)
1501 : minus_zero_value_; 1515 : minus_zero_value();
1502 } 1516 }
1503 if (rep.bits == nan.bits) { 1517 if (rep.bits == nan.bits) {
1504 return new_object 1518 return new_object
1505 ? AllocateHeapNumber(OS::nan_value(), pretenure) 1519 ? AllocateHeapNumber(OS::nan_value(), pretenure)
1506 : nan_value_; 1520 : nan_value();
1507 } 1521 }
1508 1522
1509 // Try to represent the value as a tagged small integer. 1523 // Try to represent the value as a tagged small integer.
1510 int int_value = FastD2I(value); 1524 int int_value = FastD2I(value);
1511 if (value == FastI2D(int_value) && Smi::IsValid(int_value)) { 1525 if (value == FastI2D(int_value) && Smi::IsValid(int_value)) {
1512 return Smi::FromInt(int_value); 1526 return Smi::FromInt(int_value);
1513 } 1527 }
1514 1528
1515 // Materialize the value in the heap. 1529 // Materialize the value in the heap.
1516 return AllocateHeapNumber(value, pretenure); 1530 return AllocateHeapNumber(value, pretenure);
(...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after
2748 while (Space* space = spaces.next()) { 2762 while (Space* space = spaces.next()) {
2749 space->Verify(); 2763 space->Verify();
2750 } 2764 }
2751 } 2765 }
2752 #endif // DEBUG 2766 #endif // DEBUG
2753 2767
2754 2768
2755 Object* Heap::LookupSymbol(Vector<const char> string) { 2769 Object* Heap::LookupSymbol(Vector<const char> string) {
2756 Object* symbol = NULL; 2770 Object* symbol = NULL;
2757 Object* new_table = 2771 Object* new_table =
2758 SymbolTable::cast(symbol_table_)->LookupSymbol(string, &symbol); 2772 SymbolTable::cast(symbol_table())->LookupSymbol(string, &symbol);
2759 if (new_table->IsFailure()) return new_table; 2773 if (new_table->IsFailure()) return new_table;
2760 symbol_table_ = new_table; 2774 roots_[kSymbolTableRootIndex] = new_table;
2761 ASSERT(symbol != NULL); 2775 ASSERT(symbol != NULL);
2762 return symbol; 2776 return symbol;
2763 } 2777 }
2764 2778
2765 2779
2766 Object* Heap::LookupSymbol(String* string) { 2780 Object* Heap::LookupSymbol(String* string) {
2767 if (string->IsSymbol()) return string; 2781 if (string->IsSymbol()) return string;
2768 Object* symbol = NULL; 2782 Object* symbol = NULL;
2769 Object* new_table = 2783 Object* new_table =
2770 SymbolTable::cast(symbol_table_)->LookupString(string, &symbol); 2784 SymbolTable::cast(symbol_table())->LookupString(string, &symbol);
2771 if (new_table->IsFailure()) return new_table; 2785 if (new_table->IsFailure()) return new_table;
2772 symbol_table_ = new_table; 2786 roots_[kSymbolTableRootIndex] = new_table;
2773 ASSERT(symbol != NULL); 2787 ASSERT(symbol != NULL);
2774 return symbol; 2788 return symbol;
2775 } 2789 }
2776 2790
2777 2791
2778 bool Heap::LookupSymbolIfExists(String* string, String** symbol) { 2792 bool Heap::LookupSymbolIfExists(String* string, String** symbol) {
2779 if (string->IsSymbol()) { 2793 if (string->IsSymbol()) {
2780 *symbol = string; 2794 *symbol = string;
2781 return true; 2795 return true;
2782 } 2796 }
2783 SymbolTable* table = SymbolTable::cast(symbol_table_); 2797 SymbolTable* table = SymbolTable::cast(symbol_table());
2784 return table->LookupSymbolIfExists(string, symbol); 2798 return table->LookupSymbolIfExists(string, symbol);
2785 } 2799 }
2786 2800
2787 2801
2788 #ifdef DEBUG 2802 #ifdef DEBUG
2789 void Heap::ZapFromSpace() { 2803 void Heap::ZapFromSpace() {
2790 ASSERT(HAS_HEAP_OBJECT_TAG(kFromSpaceZapValue)); 2804 ASSERT(HAS_HEAP_OBJECT_TAG(kFromSpaceZapValue));
2791 for (Address a = new_space_.FromSpaceLow(); 2805 for (Address a = new_space_.FromSpaceLow();
2792 a < new_space_.FromSpaceHigh(); 2806 a < new_space_.FromSpaceHigh();
2793 a += kPointerSize) { 2807 a += kPointerSize) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2861 2875
2862 2876
2863 #ifdef DEBUG 2877 #ifdef DEBUG
2864 #define SYNCHRONIZE_TAG(tag) v->Synchronize(tag) 2878 #define SYNCHRONIZE_TAG(tag) v->Synchronize(tag)
2865 #else 2879 #else
2866 #define SYNCHRONIZE_TAG(tag) 2880 #define SYNCHRONIZE_TAG(tag)
2867 #endif 2881 #endif
2868 2882
2869 void Heap::IterateRoots(ObjectVisitor* v) { 2883 void Heap::IterateRoots(ObjectVisitor* v) {
2870 IterateStrongRoots(v); 2884 IterateStrongRoots(v);
2871 v->VisitPointer(reinterpret_cast<Object**>(&symbol_table_)); 2885 v->VisitPointer(reinterpret_cast<Object**>(&roots_[kSymbolTableRootIndex]));
2872 SYNCHRONIZE_TAG("symbol_table"); 2886 SYNCHRONIZE_TAG("symbol_table");
2873 } 2887 }
2874 2888
2875 2889
2876 void Heap::IterateStrongRoots(ObjectVisitor* v) { 2890 void Heap::IterateStrongRoots(ObjectVisitor* v) {
2877 #define ROOT_ITERATE(type, name) \ 2891 v->VisitPointers(&roots_[0], &roots_[kStrongRootListLength]);
2878 v->VisitPointer(bit_cast<Object**, type**>(&name##_));
2879 STRONG_ROOT_LIST(ROOT_ITERATE);
2880 #undef ROOT_ITERATE
2881 SYNCHRONIZE_TAG("strong_root_list"); 2892 SYNCHRONIZE_TAG("strong_root_list");
2882 2893
2883 #define STRUCT_MAP_ITERATE(NAME, Name, name) \
2884 v->VisitPointer(bit_cast<Object**, Map**>(&name##_map_));
2885 STRUCT_LIST(STRUCT_MAP_ITERATE);
2886 #undef STRUCT_MAP_ITERATE
2887 SYNCHRONIZE_TAG("struct_map");
2888
2889 #define SYMBOL_ITERATE(name, string) \
2890 v->VisitPointer(bit_cast<Object**, String**>(&name##_));
2891 SYMBOL_LIST(SYMBOL_ITERATE)
2892 #undef SYMBOL_ITERATE
2893 v->VisitPointer(bit_cast<Object**, String**>(&hidden_symbol_)); 2894 v->VisitPointer(bit_cast<Object**, String**>(&hidden_symbol_));
2894 SYNCHRONIZE_TAG("symbol"); 2895 SYNCHRONIZE_TAG("symbol");
2895 2896
2896 Bootstrapper::Iterate(v); 2897 Bootstrapper::Iterate(v);
2897 SYNCHRONIZE_TAG("bootstrapper"); 2898 SYNCHRONIZE_TAG("bootstrapper");
2898 Top::Iterate(v); 2899 Top::Iterate(v);
2899 SYNCHRONIZE_TAG("top"); 2900 SYNCHRONIZE_TAG("top");
2900 2901
2901 #ifdef ENABLE_DEBUGGER_SUPPORT 2902 #ifdef ENABLE_DEBUGGER_SUPPORT
2902 Debug::Iterate(v); 2903 Debug::Iterate(v);
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
3359 #undef DEF_TYPE_NAME 3360 #undef DEF_TYPE_NAME
3360 3361
3361 HeapIterator iterator; 3362 HeapIterator iterator;
3362 while (iterator.has_next()) { 3363 while (iterator.has_next()) {
3363 CollectStats(iterator.next(), info); 3364 CollectStats(iterator.next(), info);
3364 } 3365 }
3365 3366
3366 // Lump all the string types together. 3367 // Lump all the string types together.
3367 int string_number = 0; 3368 int string_number = 0;
3368 int string_bytes = 0; 3369 int string_bytes = 0;
3369 #define INCREMENT_SIZE(type, size, name) \ 3370 #define INCREMENT_SIZE(type, size, name, camel_name) \
3370 string_number += info[type].number(); \ 3371 string_number += info[type].number(); \
3371 string_bytes += info[type].bytes(); 3372 string_bytes += info[type].bytes();
3372 STRING_TYPE_LIST(INCREMENT_SIZE) 3373 STRING_TYPE_LIST(INCREMENT_SIZE)
3373 #undef INCREMENT_SIZE 3374 #undef INCREMENT_SIZE
3374 if (string_bytes > 0) { 3375 if (string_bytes > 0) {
3375 LOG(HeapSampleItemEvent("STRING_TYPE", string_number, string_bytes)); 3376 LOG(HeapSampleItemEvent("STRING_TYPE", string_number, string_bytes));
3376 } 3377 }
3377 3378
3378 for (int i = FIRST_NONSTRING_TYPE; i <= LAST_TYPE; ++i) { 3379 for (int i = FIRST_NONSTRING_TYPE; i <= LAST_TYPE; ++i) {
3379 if (info[i].bytes() > 0) { 3380 if (info[i].bytes() > 0) {
3380 LOG(HeapSampleItemEvent(info[i].name(), info[i].number(), 3381 LOG(HeapSampleItemEvent(info[i].name(), info[i].number(),
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
3657 #ifdef DEBUG 3658 #ifdef DEBUG
3658 bool Heap::GarbageCollectionGreedyCheck() { 3659 bool Heap::GarbageCollectionGreedyCheck() {
3659 ASSERT(FLAG_gc_greedy); 3660 ASSERT(FLAG_gc_greedy);
3660 if (Bootstrapper::IsActive()) return true; 3661 if (Bootstrapper::IsActive()) return true;
3661 if (disallow_allocation_failure()) return true; 3662 if (disallow_allocation_failure()) return true;
3662 return CollectGarbage(0, NEW_SPACE); 3663 return CollectGarbage(0, NEW_SPACE);
3663 } 3664 }
3664 #endif 3665 #endif
3665 3666
3666 } } // namespace v8::internal 3667 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698