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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 V(global_eval_symbol, "GlobalEval") \ | 195 V(global_eval_symbol, "GlobalEval") \ |
196 V(identity_hash_symbol, "v8::IdentityHash") \ | 196 V(identity_hash_symbol, "v8::IdentityHash") \ |
197 V(closure_symbol, "(closure)") | 197 V(closure_symbol, "(closure)") |
198 | 198 |
199 | 199 |
200 // Forward declaration of the GCTracer class. | 200 // Forward declaration of the GCTracer class. |
201 class GCTracer; | 201 class GCTracer; |
202 class HeapStats; | 202 class HeapStats; |
203 | 203 |
204 | 204 |
| 205 typedef String* (*ExternalStringTableUpdaterCallback)(Object** pointer); |
| 206 |
| 207 |
205 // The all static Heap captures the interface to the global object heap. | 208 // The all static Heap captures the interface to the global object heap. |
206 // All JavaScript contexts by this process share the same object heap. | 209 // All JavaScript contexts by this process share the same object heap. |
207 | 210 |
208 class Heap : public AllStatic { | 211 class Heap : public AllStatic { |
209 public: | 212 public: |
210 // Configure heap size before setup. Return false if the heap has been | 213 // Configure heap size before setup. Return false if the heap has been |
211 // setup already. | 214 // setup already. |
212 static bool ConfigureHeap(int max_semispace_size, int max_old_gen_size); | 215 static bool ConfigureHeap(int max_semispace_size, int max_old_gen_size); |
213 static bool ConfigureHeapDefault(); | 216 static bool ConfigureHeapDefault(); |
214 | 217 |
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 | 942 |
940 static Object* NumberToString(Object* number, | 943 static Object* NumberToString(Object* number, |
941 bool check_number_string_cache = true); | 944 bool check_number_string_cache = true); |
942 | 945 |
943 static Map* MapForExternalArrayType(ExternalArrayType array_type); | 946 static Map* MapForExternalArrayType(ExternalArrayType array_type); |
944 static RootListIndex RootIndexForExternalArrayType( | 947 static RootListIndex RootIndexForExternalArrayType( |
945 ExternalArrayType array_type); | 948 ExternalArrayType array_type); |
946 | 949 |
947 static void RecordStats(HeapStats* stats); | 950 static void RecordStats(HeapStats* stats); |
948 | 951 |
| 952 // Copy block of memory from src to dst. Size of block should be aligned |
| 953 // by pointer size. |
| 954 static inline void CopyBlock(Object** dst, Object** src, int byte_size); |
| 955 |
| 956 // Optimized version of memmove for blocks with pointer size aligned sizes and |
| 957 // pointer size aligned addresses. |
| 958 static inline void MoveBlock(Object** dst, Object** src, size_t byte_size); |
| 959 |
| 960 // Check new space expansion criteria and expand semispaces if it was hit. |
| 961 static void CheckNewSpaceExpansionCriteria(); |
| 962 |
| 963 static inline void IncrementYoungSurvivorsCounter(int survived) { |
| 964 survived_since_last_expansion_ += survived; |
| 965 } |
| 966 |
| 967 static void UpdateNewSpaceReferencesInExternalStringTable( |
| 968 ExternalStringTableUpdaterCallback updater_func); |
| 969 |
| 970 // Helper function that governs the promotion policy from new space to |
| 971 // old. If the object's old address lies below the new space's age |
| 972 // mark or if we've already filled the bottom 1/16th of the to space, |
| 973 // we try to promote this object. |
| 974 static inline bool ShouldBePromoted(Address old_address, int object_size); |
| 975 |
949 static int MaxObjectSizeInNewSpace() { return kMaxObjectSizeInNewSpace; } | 976 static int MaxObjectSizeInNewSpace() { return kMaxObjectSizeInNewSpace; } |
950 | 977 |
951 private: | 978 private: |
952 static int reserved_semispace_size_; | 979 static int reserved_semispace_size_; |
953 static int max_semispace_size_; | 980 static int max_semispace_size_; |
954 static int initial_semispace_size_; | 981 static int initial_semispace_size_; |
955 static int max_old_generation_size_; | 982 static int max_old_generation_size_; |
956 static size_t code_range_size_; | 983 static size_t code_range_size_; |
957 | 984 |
958 // For keeping track of how much data has survived | 985 // For keeping track of how much data has survived |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 | 1160 |
1134 static void CreateFixedStubs(); | 1161 static void CreateFixedStubs(); |
1135 | 1162 |
1136 static Object* CreateOddball(const char* to_string, Object* to_number); | 1163 static Object* CreateOddball(const char* to_string, Object* to_number); |
1137 | 1164 |
1138 // Allocate empty fixed array. | 1165 // Allocate empty fixed array. |
1139 static Object* AllocateEmptyFixedArray(); | 1166 static Object* AllocateEmptyFixedArray(); |
1140 | 1167 |
1141 // Performs a minor collection in new generation. | 1168 // Performs a minor collection in new generation. |
1142 static void Scavenge(); | 1169 static void Scavenge(); |
1143 static void ScavengeExternalStringTable(); | 1170 |
| 1171 static String* UpdateNewSpaceReferenceInExternalStringTableEntry( |
| 1172 Object** pointer); |
| 1173 |
1144 static Address DoScavenge(ObjectVisitor* scavenge_visitor, | 1174 static Address DoScavenge(ObjectVisitor* scavenge_visitor, |
1145 Address new_space_front); | 1175 Address new_space_front); |
1146 | 1176 |
1147 // Performs a major collection in the whole heap. | 1177 // Performs a major collection in the whole heap. |
1148 static void MarkCompact(GCTracer* tracer); | 1178 static void MarkCompact(GCTracer* tracer); |
1149 | 1179 |
1150 // Code to be run before and after mark-compact. | 1180 // Code to be run before and after mark-compact. |
1151 static void MarkCompactPrologue(bool is_compacting); | 1181 static void MarkCompactPrologue(bool is_compacting); |
1152 static void MarkCompactEpilogue(bool is_compacting); | 1182 static void MarkCompactEpilogue(bool is_compacting); |
1153 | 1183 |
1154 // Helper function used by CopyObject to copy a source object to an | 1184 // Helper function used by CopyObject to copy a source object to an |
1155 // allocated target object and update the forwarding pointer in the source | 1185 // allocated target object and update the forwarding pointer in the source |
1156 // object. Returns the target object. | 1186 // object. Returns the target object. |
1157 static inline HeapObject* MigrateObject(HeapObject* source, | 1187 static inline HeapObject* MigrateObject(HeapObject* source, |
1158 HeapObject* target, | 1188 HeapObject* target, |
1159 int size); | 1189 int size); |
1160 | 1190 |
1161 // Helper function that governs the promotion policy from new space to | |
1162 // old. If the object's old address lies below the new space's age | |
1163 // mark or if we've already filled the bottom 1/16th of the to space, | |
1164 // we try to promote this object. | |
1165 static inline bool ShouldBePromoted(Address old_address, int object_size); | |
1166 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) | 1191 #if defined(DEBUG) || defined(ENABLE_LOGGING_AND_PROFILING) |
1167 // Record the copy of an object in the NewSpace's statistics. | 1192 // Record the copy of an object in the NewSpace's statistics. |
1168 static void RecordCopiedObject(HeapObject* obj); | 1193 static void RecordCopiedObject(HeapObject* obj); |
1169 | 1194 |
1170 // Record statistics before and after garbage collection. | 1195 // Record statistics before and after garbage collection. |
1171 static void ReportStatisticsBeforeGC(); | 1196 static void ReportStatisticsBeforeGC(); |
1172 static void ReportStatisticsAfterGC(); | 1197 static void ReportStatisticsAfterGC(); |
1173 #endif | 1198 #endif |
1174 | 1199 |
1175 // Rebuild remembered set in an old space. | 1200 // Rebuild remembered set in an old space. |
1176 static void RebuildRSets(PagedSpace* space); | 1201 static void RebuildRSets(PagedSpace* space); |
1177 | 1202 |
1178 // Rebuild remembered set in the large object space. | 1203 // Rebuild remembered set in the large object space. |
1179 static void RebuildRSets(LargeObjectSpace* space); | 1204 static void RebuildRSets(LargeObjectSpace* space); |
1180 | 1205 |
1181 // Slow part of scavenge object. | 1206 // Slow part of scavenge object. |
1182 static void ScavengeObjectSlow(HeapObject** p, HeapObject* object); | 1207 static void ScavengeObjectSlow(HeapObject** p, HeapObject* object); |
1183 | 1208 |
1184 // Copy memory from src to dst. | |
1185 static inline void CopyBlock(Object** dst, Object** src, int byte_size); | |
1186 | |
1187 // Initializes a function with a shared part and prototype. | 1209 // Initializes a function with a shared part and prototype. |
1188 // Returns the function. | 1210 // Returns the function. |
1189 // Note: this code was factored out of AllocateFunction such that | 1211 // Note: this code was factored out of AllocateFunction such that |
1190 // other parts of the VM could use it. Specifically, a function that creates | 1212 // other parts of the VM could use it. Specifically, a function that creates |
1191 // instances of type JS_FUNCTION_TYPE benefit from the use of this function. | 1213 // instances of type JS_FUNCTION_TYPE benefit from the use of this function. |
1192 // Please note this does not perform a garbage collection. | 1214 // Please note this does not perform a garbage collection. |
1193 static inline Object* InitializeFunction(JSFunction* function, | 1215 static inline Object* InitializeFunction(JSFunction* function, |
1194 SharedFunctionInfo* shared, | 1216 SharedFunctionInfo* shared, |
1195 Object* prototype); | 1217 Object* prototype); |
1196 | 1218 |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1806 | 1828 |
1807 // To speed up scavenge collections new space string are kept | 1829 // To speed up scavenge collections new space string are kept |
1808 // separate from old space strings. | 1830 // separate from old space strings. |
1809 static List<Object*> new_space_strings_; | 1831 static List<Object*> new_space_strings_; |
1810 static List<Object*> old_space_strings_; | 1832 static List<Object*> old_space_strings_; |
1811 }; | 1833 }; |
1812 | 1834 |
1813 } } // namespace v8::internal | 1835 } } // namespace v8::internal |
1814 | 1836 |
1815 #endif // V8_HEAP_H_ | 1837 #endif // V8_HEAP_H_ |
OLD | NEW |