OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1087 // It seems that the same type of objects are likely to be accessed together, | 1087 // It seems that the same type of objects are likely to be accessed together, |
1088 // which means that we want to group objects by type. That's one reason | 1088 // which means that we want to group objects by type. That's one reason |
1089 // why we provide dedicated heaps for popular types (e.g., Node, CSSValue), | 1089 // why we provide dedicated heaps for popular types (e.g., Node, CSSValue), |
1090 // but it's not practical to prepare dedicated heaps for all types. | 1090 // but it's not practical to prepare dedicated heaps for all types. |
1091 // Thus we group objects by their sizes, hoping that this will approximately | 1091 // Thus we group objects by their sizes, hoping that this will approximately |
1092 // group objects by their types. | 1092 // group objects by their types. |
1093 // | 1093 // |
1094 // An exception to the use of sized heaps is made for class types that | 1094 // An exception to the use of sized heaps is made for class types that |
1095 // require prompt finalization after a garbage collection. That is, their | 1095 // require prompt finalization after a garbage collection. That is, their |
1096 // instances have to be finalized early and cannot be delayed until lazy | 1096 // instances have to be finalized early and cannot be delayed until lazy |
1097 // sweeping kicks in for their heap and page. The EAGERLY_SWEEP() | 1097 // sweeping kicks in for their heap and page. The EAGERLY_FINALIZE() |
1098 // macro is used to declare a class (and its derived classes) as being | 1098 // macro is used to declare a class (and its derived classes) as being |
1099 // in need of 'eager sweeping'. | 1099 // in need of eagerly finalized. Must be defined with 'public' visibility |
1100 // | 1100 // for a class. |
1101 // TODO(Oilpan): the notion of eagerly swept object is at least needed | |
1102 // during the transition to enabling Oilpan always. Once passed, re-evaluate | |
1103 // if there is a need to keep this facility. | |
1104 // | 1101 // |
1105 template<typename T, typename Enabled = void> | 1102 template<typename T, typename Enabled = void> |
1106 class HeapIndexTrait { | 1103 class HeapIndexTrait { |
1107 public: | 1104 public: |
1108 static int heapIndexForObject(size_t size) | 1105 static int heapIndexForObject(size_t size) |
1109 { | 1106 { |
1110 if (size < 64) { | 1107 if (size < 64) { |
1111 if (size < 32) | 1108 if (size < 32) |
1112 return NormalPage1HeapIndex; | 1109 return NormalPage1HeapIndex; |
1113 return NormalPage2HeapIndex; | 1110 return NormalPage2HeapIndex; |
1114 } | 1111 } |
1115 if (size < 128) | 1112 if (size < 128) |
1116 return NormalPage3HeapIndex; | 1113 return NormalPage3HeapIndex; |
1117 return NormalPage4HeapIndex; | 1114 return NormalPage4HeapIndex; |
1118 } | 1115 } |
1119 }; | 1116 }; |
1120 | 1117 |
1121 // TODO(Oilpan): enable this macro when enabling lazy sweeping, non-Oilpan. | 1118 // TODO(Oilpan): enable this macro when enabling lazy sweeping, non-Oilpan. |
1122 #if ENABLE(OILPAN) | 1119 #if ENABLE(OILPAN) |
1123 #define EAGERLY_SWEEP() typedef int IsEagerlySweptMarker | 1120 #define EAGERLY_FINALIZE() typedef int IsEagerlyFinalizedMarker |
1121 #define EAGERLY_FINALIZE_WILL_BE_REMOVED() | |
1124 #else | 1122 #else |
1125 #define EAGERLY_SWEEP() | 1123 #define EAGERLY_FINALIZE() |
1124 // TODO(Oilpan): define in terms of Oilpan's EAGERLY_FINALIZE() once lazy | |
1125 // sweeping is enabled non-Oilpan. | |
1126 #define EAGERLY_FINALIZE_WILL_BE_REMOVED() | |
1126 #endif | 1127 #endif |
1127 | 1128 |
1128 template<typename T> | 1129 template<typename T> |
1129 struct IsEagerlySweptType { | 1130 struct IsEagerlyFinalizedType { |
1130 private: | 1131 private: |
1131 typedef char YesType; | 1132 typedef char YesType; |
1132 struct NoType { | 1133 struct NoType { |
1133 char padding[8]; | 1134 char padding[8]; |
1134 }; | 1135 }; |
1135 | 1136 |
1136 template <typename U> static YesType checkMarker(typename U::IsEagerlySweptM arker*); | 1137 template <typename U> static YesType checkMarker(typename U::IsEagerlyFinali zedMarker*); |
1137 template <typename U> static NoType checkMarker(...); | 1138 template <typename U> static NoType checkMarker(...); |
1138 | 1139 |
1139 public: | 1140 public: |
1140 static const bool value = sizeof(checkMarker<T>(nullptr)) == sizeof(YesType) ; | 1141 static const bool value = sizeof(checkMarker<T>(nullptr)) == sizeof(YesType) ; |
1141 }; | 1142 }; |
1142 | 1143 |
1143 template<typename T> | 1144 template<typename T> |
1144 class HeapIndexTrait<T, typename WTF::EnableIf<IsEagerlySweptType<T>::value>::Ty pe> { | 1145 class HeapIndexTrait<T, typename WTF::EnableIf<IsEagerlyFinalizedType<T>::value> ::Type> { |
haraken
2015/05/26 13:06:35
Just to confirm:
class A : GarbageCollected<A> {
| |
1145 public: | 1146 public: |
1146 static int heapIndexForObject(size_t) | 1147 static int heapIndexForObject(size_t) |
1147 { | 1148 { |
1148 return EagerSweepHeapIndex; | 1149 return EagerSweepHeapIndex; |
1149 } | 1150 } |
1150 }; | 1151 }; |
1151 | 1152 |
1152 NO_SANITIZE_ADDRESS inline | 1153 NO_SANITIZE_ADDRESS inline |
1153 size_t HeapObjectHeader::size() const | 1154 size_t HeapObjectHeader::size() const |
1154 { | 1155 { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1293 size_t copySize = previousHeader->payloadSize(); | 1294 size_t copySize = previousHeader->payloadSize(); |
1294 if (copySize > size) | 1295 if (copySize > size) |
1295 copySize = size; | 1296 copySize = size; |
1296 memcpy(address, previous, copySize); | 1297 memcpy(address, previous, copySize); |
1297 return address; | 1298 return address; |
1298 } | 1299 } |
1299 | 1300 |
1300 } // namespace blink | 1301 } // namespace blink |
1301 | 1302 |
1302 #endif // Heap_h | 1303 #endif // Heap_h |
OLD | NEW |