| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1023 | 1023 |
| 1024 GCTracer* tracer() { return tracer_; } | 1024 GCTracer* tracer() { return tracer_; } |
| 1025 | 1025 |
| 1026 private: | 1026 private: |
| 1027 Heap(); | 1027 Heap(); |
| 1028 | 1028 |
| 1029 // TODO(isolates): Technically this can be calculated directly from | 1029 // TODO(isolates): Technically this can be calculated directly from |
| 1030 // any pointer to Heap. | 1030 // any pointer to Heap. |
| 1031 Isolate* isolate_; | 1031 Isolate* isolate_; |
| 1032 | 1032 |
| 1033 static int reserved_semispace_size_; | 1033 int reserved_semispace_size_; |
| 1034 static int max_semispace_size_; | 1034 int max_semispace_size_; |
| 1035 static int initial_semispace_size_; | 1035 int initial_semispace_size_; |
| 1036 static int max_old_generation_size_; | 1036 int max_old_generation_size_; |
| 1037 static size_t code_range_size_; | 1037 size_t code_range_size_; |
| 1038 | 1038 |
| 1039 // For keeping track of how much data has survived | 1039 // For keeping track of how much data has survived |
| 1040 // scavenge since last new space expansion. | 1040 // scavenge since last new space expansion. |
| 1041 static int survived_since_last_expansion_; | 1041 int survived_since_last_expansion_; |
| 1042 | 1042 |
| 1043 static int always_allocate_scope_depth_; | 1043 int always_allocate_scope_depth_; |
| 1044 static int linear_allocation_scope_depth_; | 1044 int linear_allocation_scope_depth_; |
| 1045 | 1045 |
| 1046 // For keeping track of context disposals. | 1046 // For keeping track of context disposals. |
| 1047 static int contexts_disposed_; | 1047 int contexts_disposed_; |
| 1048 | 1048 |
| 1049 #if defined(V8_TARGET_ARCH_X64) | 1049 #if defined(V8_TARGET_ARCH_X64) |
| 1050 static const int kMaxObjectSizeInNewSpace = 512*KB; | 1050 static const int kMaxObjectSizeInNewSpace = 512*KB; |
| 1051 #else | 1051 #else |
| 1052 static const int kMaxObjectSizeInNewSpace = 256*KB; | 1052 static const int kMaxObjectSizeInNewSpace = 256*KB; |
| 1053 #endif | 1053 #endif |
| 1054 | 1054 |
| 1055 static NewSpace new_space_; | 1055 NewSpace new_space_; |
| 1056 static OldSpace* old_pointer_space_; | 1056 OldSpace* old_pointer_space_; |
| 1057 static OldSpace* old_data_space_; | 1057 OldSpace* old_data_space_; |
| 1058 static OldSpace* code_space_; | 1058 OldSpace* code_space_; |
| 1059 static MapSpace* map_space_; | 1059 MapSpace* map_space_; |
| 1060 static CellSpace* cell_space_; | 1060 CellSpace* cell_space_; |
| 1061 static LargeObjectSpace* lo_space_; | 1061 LargeObjectSpace* lo_space_; |
| 1062 static HeapState gc_state_; | 1062 HeapState gc_state_; |
| 1063 | 1063 |
| 1064 // Returns the size of object residing in non new spaces. | 1064 // Returns the size of object residing in non new spaces. |
| 1065 int PromotedSpaceSize(); | 1065 int PromotedSpaceSize(); |
| 1066 | 1066 |
| 1067 // Returns the amount of external memory registered since last global gc. | 1067 // Returns the amount of external memory registered since last global gc. |
| 1068 int PromotedExternalMemorySize(); | 1068 int PromotedExternalMemorySize(); |
| 1069 | 1069 |
| 1070 static int mc_count_; // how many mark-compact collections happened | 1070 int mc_count_; // how many mark-compact collections happened |
| 1071 static int ms_count_; // how many mark-sweep collections happened | 1071 int ms_count_; // how many mark-sweep collections happened |
| 1072 static int gc_count_; // how many gc happened | 1072 int gc_count_; // how many gc happened |
| 1073 | 1073 |
| 1074 // Total length of the strings we failed to flatten since the last GC. | 1074 // Total length of the strings we failed to flatten since the last GC. |
| 1075 static int unflattened_strings_length_; | 1075 int unflattened_strings_length_; |
| 1076 | 1076 |
| 1077 #define ROOT_ACCESSOR(type, name, camel_name) \ | 1077 #define ROOT_ACCESSOR(type, name, camel_name) \ |
| 1078 static inline void set_##name(type* value) { \ | 1078 inline void set_##name(type* value) { \ |
| 1079 roots_[k##camel_name##RootIndex] = value; \ | 1079 roots_[k##camel_name##RootIndex] = value; \ |
| 1080 } | 1080 } |
| 1081 ROOT_LIST(ROOT_ACCESSOR) | 1081 ROOT_LIST(ROOT_ACCESSOR) |
| 1082 #undef ROOT_ACCESSOR | 1082 #undef ROOT_ACCESSOR |
| 1083 | 1083 |
| 1084 #ifdef DEBUG | 1084 #ifdef DEBUG |
| 1085 static bool allocation_allowed_; | 1085 bool allocation_allowed_; |
| 1086 | 1086 |
| 1087 // If the --gc-interval flag is set to a positive value, this | 1087 // If the --gc-interval flag is set to a positive value, this |
| 1088 // variable holds the value indicating the number of allocations | 1088 // variable holds the value indicating the number of allocations |
| 1089 // remain until the next failure and garbage collection. | 1089 // remain until the next failure and garbage collection. |
| 1090 static int allocation_timeout_; | 1090 int allocation_timeout_; |
| 1091 | 1091 |
| 1092 // Do we expect to be able to handle allocation failure at this | 1092 // Do we expect to be able to handle allocation failure at this |
| 1093 // time? | 1093 // time? |
| 1094 static bool disallow_allocation_failure_; | 1094 bool disallow_allocation_failure_; |
| 1095 #endif // DEBUG | 1095 #endif // DEBUG |
| 1096 | 1096 |
| 1097 // Limit that triggers a global GC on the next (normally caused) GC. This | 1097 // Limit that triggers a global GC on the next (normally caused) GC. This |
| 1098 // is checked when we have already decided to do a GC to help determine | 1098 // is checked when we have already decided to do a GC to help determine |
| 1099 // which collector to invoke. | 1099 // which collector to invoke. |
| 1100 static int old_gen_promotion_limit_; | 1100 int old_gen_promotion_limit_; |
| 1101 | 1101 |
| 1102 // Limit that triggers a global GC as soon as is reasonable. This is | 1102 // Limit that triggers a global GC as soon as is reasonable. This is |
| 1103 // checked before expanding a paged space in the old generation and on | 1103 // checked before expanding a paged space in the old generation and on |
| 1104 // every allocation in large object space. | 1104 // every allocation in large object space. |
| 1105 static int old_gen_allocation_limit_; | 1105 int old_gen_allocation_limit_; |
| 1106 | 1106 |
| 1107 // Limit on the amount of externally allocated memory allowed | 1107 // Limit on the amount of externally allocated memory allowed |
| 1108 // between global GCs. If reached a global GC is forced. | 1108 // between global GCs. If reached a global GC is forced. |
| 1109 static int external_allocation_limit_; | 1109 int external_allocation_limit_; |
| 1110 | 1110 |
| 1111 // The amount of external memory registered through the API kept alive | 1111 // The amount of external memory registered through the API kept alive |
| 1112 // by global handles | 1112 // by global handles |
| 1113 static int amount_of_external_allocated_memory_; | 1113 int amount_of_external_allocated_memory_; |
| 1114 | 1114 |
| 1115 // Caches the amount of external memory registered at the last global gc. | 1115 // Caches the amount of external memory registered at the last global gc. |
| 1116 static int amount_of_external_allocated_memory_at_last_global_gc_; | 1116 int amount_of_external_allocated_memory_at_last_global_gc_; |
| 1117 | 1117 |
| 1118 // Indicates that an allocation has failed in the old generation since the | 1118 // Indicates that an allocation has failed in the old generation since the |
| 1119 // last GC. | 1119 // last GC. |
| 1120 static int old_gen_exhausted_; | 1120 int old_gen_exhausted_; |
| 1121 | 1121 |
| 1122 static Object* roots_[kRootListLength]; | 1122 Object* roots_[kRootListLength]; |
| 1123 | 1123 |
| 1124 struct StringTypeTable { | 1124 struct StringTypeTable { |
| 1125 InstanceType type; | 1125 InstanceType type; |
| 1126 int size; | 1126 int size; |
| 1127 RootListIndex index; | 1127 RootListIndex index; |
| 1128 }; | 1128 }; |
| 1129 | 1129 |
| 1130 struct ConstantSymbolTable { | 1130 struct ConstantSymbolTable { |
| 1131 const char* contents; | 1131 const char* contents; |
| 1132 RootListIndex index; | 1132 RootListIndex index; |
| 1133 }; | 1133 }; |
| 1134 | 1134 |
| 1135 struct StructTable { | 1135 struct StructTable { |
| 1136 InstanceType type; | 1136 InstanceType type; |
| 1137 int size; | 1137 int size; |
| 1138 RootListIndex index; | 1138 RootListIndex index; |
| 1139 }; | 1139 }; |
| 1140 | 1140 |
| 1141 static const StringTypeTable string_type_table[]; | 1141 static const StringTypeTable string_type_table[]; |
| 1142 static const ConstantSymbolTable constant_symbol_table[]; | 1142 static const ConstantSymbolTable constant_symbol_table[]; |
| 1143 static const StructTable struct_table[]; | 1143 static const StructTable struct_table[]; |
| 1144 | 1144 |
| 1145 // The special hidden symbol which is an empty string, but does not match | 1145 // The special hidden symbol which is an empty string, but does not match |
| 1146 // any string when looked up in properties. | 1146 // any string when looked up in properties. |
| 1147 static String* hidden_symbol_; | 1147 String* hidden_symbol_; |
| 1148 | 1148 |
| 1149 // GC callback function, called before and after mark-compact GC. | 1149 // GC callback function, called before and after mark-compact GC. |
| 1150 // Allocations in the callback function are disallowed. | 1150 // Allocations in the callback function are disallowed. |
| 1151 struct GCPrologueCallbackPair { | 1151 struct GCPrologueCallbackPair { |
| 1152 GCPrologueCallbackPair(GCPrologueCallback callback, GCType gc_type) | 1152 GCPrologueCallbackPair(GCPrologueCallback callback, GCType gc_type) |
| 1153 : callback(callback), gc_type(gc_type) { | 1153 : callback(callback), gc_type(gc_type) { |
| 1154 } | 1154 } |
| 1155 bool operator==(const GCPrologueCallbackPair& pair) const { | 1155 bool operator==(const GCPrologueCallbackPair& pair) const { |
| 1156 return pair.callback == callback; | 1156 return pair.callback == callback; |
| 1157 } | 1157 } |
| 1158 GCPrologueCallback callback; | 1158 GCPrologueCallback callback; |
| 1159 GCType gc_type; | 1159 GCType gc_type; |
| 1160 }; | 1160 }; |
| 1161 static List<GCPrologueCallbackPair> gc_prologue_callbacks_; | 1161 List<GCPrologueCallbackPair> gc_prologue_callbacks_; |
| 1162 | 1162 |
| 1163 struct GCEpilogueCallbackPair { | 1163 struct GCEpilogueCallbackPair { |
| 1164 GCEpilogueCallbackPair(GCEpilogueCallback callback, GCType gc_type) | 1164 GCEpilogueCallbackPair(GCEpilogueCallback callback, GCType gc_type) |
| 1165 : callback(callback), gc_type(gc_type) { | 1165 : callback(callback), gc_type(gc_type) { |
| 1166 } | 1166 } |
| 1167 bool operator==(const GCEpilogueCallbackPair& pair) const { | 1167 bool operator==(const GCEpilogueCallbackPair& pair) const { |
| 1168 return pair.callback == callback; | 1168 return pair.callback == callback; |
| 1169 } | 1169 } |
| 1170 GCEpilogueCallback callback; | 1170 GCEpilogueCallback callback; |
| 1171 GCType gc_type; | 1171 GCType gc_type; |
| 1172 }; | 1172 }; |
| 1173 static List<GCEpilogueCallbackPair> gc_epilogue_callbacks_; | 1173 List<GCEpilogueCallbackPair> gc_epilogue_callbacks_; |
| 1174 | 1174 |
| 1175 static GCCallback global_gc_prologue_callback_; | 1175 GCCallback global_gc_prologue_callback_; |
| 1176 static GCCallback global_gc_epilogue_callback_; | 1176 GCCallback global_gc_epilogue_callback_; |
| 1177 | 1177 |
| 1178 // Checks whether a global GC is necessary | 1178 // Checks whether a global GC is necessary |
| 1179 GarbageCollector SelectGarbageCollector(AllocationSpace space); | 1179 GarbageCollector SelectGarbageCollector(AllocationSpace space); |
| 1180 | 1180 |
| 1181 // Performs garbage collection | 1181 // Performs garbage collection |
| 1182 void PerformGarbageCollection(AllocationSpace space, | 1182 void PerformGarbageCollection(AllocationSpace space, |
| 1183 GarbageCollector collector, | 1183 GarbageCollector collector, |
| 1184 GCTracer* tracer); | 1184 GCTracer* tracer); |
| 1185 | 1185 |
| 1186 // Allocate an uninitialized object in map space. The behavior is identical | 1186 // Allocate an uninitialized object in map space. The behavior is identical |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1255 // Initializes a function with a shared part and prototype. | 1255 // Initializes a function with a shared part and prototype. |
| 1256 // Returns the function. | 1256 // Returns the function. |
| 1257 // Note: this code was factored out of AllocateFunction such that | 1257 // Note: this code was factored out of AllocateFunction such that |
| 1258 // other parts of the VM could use it. Specifically, a function that creates | 1258 // other parts of the VM could use it. Specifically, a function that creates |
| 1259 // instances of type JS_FUNCTION_TYPE benefit from the use of this function. | 1259 // instances of type JS_FUNCTION_TYPE benefit from the use of this function. |
| 1260 // Please note this does not perform a garbage collection. | 1260 // Please note this does not perform a garbage collection. |
| 1261 inline Object* InitializeFunction(JSFunction* function, | 1261 inline Object* InitializeFunction(JSFunction* function, |
| 1262 SharedFunctionInfo* shared, | 1262 SharedFunctionInfo* shared, |
| 1263 Object* prototype); | 1263 Object* prototype); |
| 1264 | 1264 |
| 1265 static GCTracer* tracer_; | 1265 GCTracer* tracer_; |
| 1266 | 1266 |
| 1267 | 1267 |
| 1268 // Initializes the number to string cache based on the max semispace size. | 1268 // Initializes the number to string cache based on the max semispace size. |
| 1269 Object* InitializeNumberStringCache(); | 1269 Object* InitializeNumberStringCache(); |
| 1270 // Flush the number to string cache. | 1270 // Flush the number to string cache. |
| 1271 void FlushNumberStringCache(); | 1271 void FlushNumberStringCache(); |
| 1272 | 1272 |
| 1273 // Flush code from functions we do not expect to use again. The code will | 1273 // Flush code from functions we do not expect to use again. The code will |
| 1274 // be replaced with a lazy compilable version. | 1274 // be replaced with a lazy compilable version. |
| 1275 void FlushCode(); | 1275 void FlushCode(); |
| (...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1976 // separate from old space strings. | 1976 // separate from old space strings. |
| 1977 static List<Object*> new_space_strings_; | 1977 static List<Object*> new_space_strings_; |
| 1978 static List<Object*> old_space_strings_; | 1978 static List<Object*> old_space_strings_; |
| 1979 }; | 1979 }; |
| 1980 | 1980 |
| 1981 } } // namespace v8::internal | 1981 } } // namespace v8::internal |
| 1982 | 1982 |
| 1983 #undef HEAP | 1983 #undef HEAP |
| 1984 | 1984 |
| 1985 #endif // V8_HEAP_H_ | 1985 #endif // V8_HEAP_H_ |
| OLD | NEW |