| OLD | NEW |
| 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 // Make the global handle weak and set the callback parameter for the | 65 // Make the global handle weak and set the callback parameter for the |
| 66 // handle. When the garbage collector recognizes that only weak global | 66 // handle. When the garbage collector recognizes that only weak global |
| 67 // handles point to an object the handles are cleared and the callback | 67 // handles point to an object the handles are cleared and the callback |
| 68 // function is invoked (for each handle) with the handle and corresponding | 68 // function is invoked (for each handle) with the handle and corresponding |
| 69 // parameter as arguments. Note: cleared means set to Smi::FromInt(0). The | 69 // parameter as arguments. Note: cleared means set to Smi::FromInt(0). The |
| 70 // reason is that Smi::FromInt(0) does not change during garage collection. | 70 // reason is that Smi::FromInt(0) does not change during garage collection. |
| 71 static void MakeWeak(Object** location, | 71 static void MakeWeak(Object** location, |
| 72 void* parameter, | 72 void* parameter, |
| 73 WeakReferenceCallback callback); | 73 WeakReferenceCallback callback); |
| 74 static void MakeReallyWeak(Object** location, |
| 75 void* parameter, |
| 76 WeakReferenceCallback callback); |
| 74 | 77 |
| 75 // Returns the current number of weak handles. | 78 // Returns the current number of weak handles. |
| 76 static int NumberOfWeakHandles() { return number_of_weak_handles_; } | 79 static int NumberOfWeakHandles() { return number_of_weak_handles_; } |
| 77 | 80 |
| 78 // Returns the current number of weak handles to global objects. | |
| 79 // These handles are also included in NumberOfWeakHandles(). | |
| 80 static int NumberOfGlobalObjectWeakHandles() { | |
| 81 return number_of_global_object_weak_handles_; | |
| 82 } | |
| 83 | |
| 84 // Clear the weakness of a global handle. | 81 // Clear the weakness of a global handle. |
| 85 static void ClearWeakness(Object** location); | 82 static void ClearWeakness(Object** location); |
| 86 | 83 |
| 87 // Tells whether global handle is near death. | 84 // Tells whether global handle is near death. |
| 88 static bool IsNearDeath(Object** location); | 85 static bool IsNearDeath(Object** location); |
| 89 | 86 |
| 90 // Tells whether global handle is weak. | 87 // Tells whether global handle is weak. |
| 91 static bool IsWeak(Object** location); | 88 static bool IsWeak(Object** location); |
| 92 | 89 |
| 90 // Tells whether global handle is really weak. |
| 91 static bool IsReallyWeak(Object** location); |
| 92 |
| 93 // Process pending weak handles. | 93 // Process pending weak handles. |
| 94 static void PostGarbageCollectionProcessing(); | 94 static void PostGarbageCollectionProcessing(); |
| 95 | 95 |
| 96 // Iterates over all handles. | 96 // Iterates over all handles. |
| 97 static void IterateRoots(ObjectVisitor* v); | 97 static void IterateRoots(ObjectVisitor* v); |
| 98 | 98 |
| 99 // Iterates over all weak roots in heap. | 99 // Iterates over all weak roots in heap. |
| 100 static void IterateWeakRoots(ObjectVisitor* v); | 100 static void IterateWeakRoots(ObjectVisitor* v); |
| 101 | 101 |
| 102 // Find all weak handles satisfying the callback predicate, mark | 102 // Find all weak handles satisfying the callback predicate, mark |
| (...skipping 18 matching lines...) Expand all Loading... |
| 121 static void PrintStats(); | 121 static void PrintStats(); |
| 122 static void Print(); | 122 static void Print(); |
| 123 #endif | 123 #endif |
| 124 private: | 124 private: |
| 125 // Internal node structure, one for each global handle. | 125 // Internal node structure, one for each global handle. |
| 126 class Node; | 126 class Node; |
| 127 | 127 |
| 128 // Field always containing the number of weak and near-death handles. | 128 // Field always containing the number of weak and near-death handles. |
| 129 static int number_of_weak_handles_; | 129 static int number_of_weak_handles_; |
| 130 | 130 |
| 131 // Field always containing the number of weak and near-death handles | |
| 132 // to global objects. These objects are also included in | |
| 133 // number_of_weak_handles_. | |
| 134 static int number_of_global_object_weak_handles_; | |
| 135 | |
| 136 // Global handles are kept in a single linked list pointed to by head_. | 131 // Global handles are kept in a single linked list pointed to by head_. |
| 137 static Node* head_; | 132 static Node* head_; |
| 138 static Node* head() { return head_; } | 133 static Node* head() { return head_; } |
| 139 static void set_head(Node* value) { head_ = value; } | 134 static void set_head(Node* value) { head_ = value; } |
| 140 | 135 |
| 141 // Free list for DESTROYED global handles not yet deallocated. | 136 // Free list for DESTROYED global handles not yet deallocated. |
| 142 static Node* first_free_; | 137 static Node* first_free_; |
| 143 static Node* first_free() { return first_free_; } | 138 static Node* first_free() { return first_free_; } |
| 144 static void set_first_free(Node* value) { first_free_ = value; } | 139 static void set_first_free(Node* value) { first_free_ = value; } |
| 145 }; | 140 }; |
| 146 | 141 |
| 147 | 142 |
| 148 } } // namespace v8::internal | 143 } } // namespace v8::internal |
| 149 | 144 |
| 150 #endif // V8_GLOBAL_HANDLES_H_ | 145 #endif // V8_GLOBAL_HANDLES_H_ |
| OLD | NEW |