| 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 26 matching lines...) Expand all Loading... |
| 37 // A Handle provides a reference to an object that survives relocation by | 37 // A Handle provides a reference to an object that survives relocation by |
| 38 // the garbage collector. | 38 // the garbage collector. |
| 39 // Handles are only valid within a HandleScope. | 39 // Handles are only valid within a HandleScope. |
| 40 // When a handle is created for an object a cell is allocated in the heap. | 40 // When a handle is created for an object a cell is allocated in the heap. |
| 41 | 41 |
| 42 template<class T> | 42 template<class T> |
| 43 class Handle { | 43 class Handle { |
| 44 public: | 44 public: |
| 45 INLINE(explicit Handle(T** location)) { location_ = location; } | 45 INLINE(explicit Handle(T** location)) { location_ = location; } |
| 46 INLINE(explicit Handle(T* obj)); | 46 INLINE(explicit Handle(T* obj)); |
| 47 INLINE(explicit Handle(HeapObject* obj)); |
| 47 INLINE(Handle(T* obj, Isolate* isolate)); | 48 INLINE(Handle(T* obj, Isolate* isolate)); |
| 48 | 49 |
| 49 INLINE(Handle()) : location_(NULL) {} | 50 INLINE(Handle()) : location_(NULL) {} |
| 50 | 51 |
| 51 // Constructor for handling automatic up casting. | 52 // Constructor for handling automatic up casting. |
| 52 // Ex. Handle<JSFunction> can be passed when Handle<Object> is expected. | 53 // Ex. Handle<JSFunction> can be passed when Handle<Object> is expected. |
| 53 template <class S> Handle(Handle<S> handle) { | 54 template <class S> Handle(Handle<S> handle) { |
| 54 #ifdef DEBUG | 55 #ifdef DEBUG |
| 55 T* a = NULL; | 56 T* a = NULL; |
| 56 S* b = NULL; | 57 S* b = NULL; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // place in the new handle scope until it is deleted. After that, | 103 // place in the new handle scope until it is deleted. After that, |
| 103 // new handles will again be allocated in the original handle scope. | 104 // new handles will again be allocated in the original handle scope. |
| 104 // | 105 // |
| 105 // After the handle scope of a local handle has been deleted the | 106 // After the handle scope of a local handle has been deleted the |
| 106 // garbage collector will no longer track the object stored in the | 107 // garbage collector will no longer track the object stored in the |
| 107 // handle and may deallocate it. The behavior of accessing a handle | 108 // handle and may deallocate it. The behavior of accessing a handle |
| 108 // for which the handle scope has been deleted is undefined. | 109 // for which the handle scope has been deleted is undefined. |
| 109 class HandleScope { | 110 class HandleScope { |
| 110 public: | 111 public: |
| 111 inline HandleScope(); | 112 inline HandleScope(); |
| 113 explicit inline HandleScope(Isolate* isolate); |
| 112 | 114 |
| 113 ~HandleScope() { | 115 ~HandleScope() { |
| 114 Leave(&previous_); | 116 Leave(&previous_); |
| 115 } | 117 } |
| 116 | 118 |
| 117 // Counts the number of allocated handles. | 119 // Counts the number of allocated handles. |
| 118 static int NumberOfHandles(); | 120 static int NumberOfHandles(); |
| 119 | 121 |
| 120 // Creates a new handle with the given value. | 122 // Creates a new handle with the given value. |
| 121 template <typename T> | 123 template <typename T> |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 private: | 359 private: |
| 358 bool has_been_transformed_; // Tells whether the object has been transformed. | 360 bool has_been_transformed_; // Tells whether the object has been transformed. |
| 359 int unused_property_fields_; // Captures the unused number of field. | 361 int unused_property_fields_; // Captures the unused number of field. |
| 360 Handle<JSObject> object_; // The object being optimized. | 362 Handle<JSObject> object_; // The object being optimized. |
| 361 }; | 363 }; |
| 362 | 364 |
| 363 | 365 |
| 364 } } // namespace v8::internal | 366 } } // namespace v8::internal |
| 365 | 367 |
| 366 #endif // V8_HANDLES_H_ | 368 #endif // V8_HANDLES_H_ |
| OLD | NEW |