OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 13 matching lines...) Expand all Loading... |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #ifndef V8_GLOBAL_HANDLES_H_ | 28 #ifndef V8_GLOBAL_HANDLES_H_ |
29 #define V8_GLOBAL_HANDLES_H_ | 29 #define V8_GLOBAL_HANDLES_H_ |
30 | 30 |
31 #include "../include/v8.h" | 31 #include "../include/v8.h" |
32 #include "../include/v8-profiler.h" | 32 #include "../include/v8-profiler.h" |
33 | 33 |
| 34 #include "handles.h" |
34 #include "list.h" | 35 #include "list.h" |
35 #include "v8utils.h" | 36 #include "v8utils.h" |
36 | 37 |
37 namespace v8 { | 38 namespace v8 { |
38 namespace internal { | 39 namespace internal { |
39 | 40 |
40 class GCTracer; | 41 class GCTracer; |
41 class HeapStats; | 42 class HeapStats; |
42 class ObjectVisitor; | 43 class ObjectVisitor; |
43 | 44 |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 List<ObjectGroupConnection> object_group_connections_; | 325 List<ObjectGroupConnection> object_group_connections_; |
325 List<ObjectGroupRetainerInfo> retainer_infos_; | 326 List<ObjectGroupRetainerInfo> retainer_infos_; |
326 List<ObjectGroupConnection> implicit_ref_connections_; | 327 List<ObjectGroupConnection> implicit_ref_connections_; |
327 | 328 |
328 friend class Isolate; | 329 friend class Isolate; |
329 | 330 |
330 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); | 331 DISALLOW_COPY_AND_ASSIGN(GlobalHandles); |
331 }; | 332 }; |
332 | 333 |
333 | 334 |
| 335 class EternalHandles { |
| 336 public: |
| 337 enum SingletonHandle { |
| 338 I18N_TEMPLATE_ONE, |
| 339 I18N_TEMPLATE_TWO, |
| 340 |
| 341 NUMBER_OF_SINGLETON_HANDLES |
| 342 }; |
| 343 |
| 344 EternalHandles(); |
| 345 ~EternalHandles(); |
| 346 |
| 347 int NumberOfHandles() { return size_; } |
| 348 |
| 349 // Create an EternalHandle, returning the index. |
| 350 int Create(Isolate* isolate, Object* object); |
| 351 |
| 352 // Grab the handle for an existing EternalHandle. |
| 353 inline Handle<Object> Get(int index) { |
| 354 return Handle<Object>(GetLocation(index)); |
| 355 } |
| 356 |
| 357 // Grab the handle for an existing SingletonHandle. |
| 358 inline Handle<Object> GetSingleton(SingletonHandle singleton) { |
| 359 ASSERT(Exists(singleton)); |
| 360 return Get(singleton_handles_[singleton]); |
| 361 } |
| 362 |
| 363 // Checks whether a SingletonHandle has been assigned. |
| 364 inline bool Exists(SingletonHandle singleton) { |
| 365 return singleton_handles_[singleton] != kInvalidIndex; |
| 366 } |
| 367 |
| 368 // Assign a SingletonHandle to an empty slot and returns the handle. |
| 369 Handle<Object> CreateSingleton(Isolate* isolate, |
| 370 Object* object, |
| 371 SingletonHandle singleton) { |
| 372 ASSERT(singleton_handles_[singleton] == kInvalidIndex); |
| 373 singleton_handles_[singleton] = Create(isolate, object); |
| 374 return Get(singleton_handles_[singleton]); |
| 375 } |
| 376 |
| 377 // Iterates over all handles. |
| 378 void IterateAllRoots(ObjectVisitor* visitor); |
| 379 // Iterates over all handles which might be in new space. |
| 380 void IterateNewSpaceRoots(ObjectVisitor* visitor); |
| 381 // Rebuilds new space list. |
| 382 void PostGarbageCollectionProcessing(Heap* heap); |
| 383 |
| 384 private: |
| 385 static const int kInvalidIndex = -1; |
| 386 static const int kShift = 8; |
| 387 static const int kSize = 1 << kShift; |
| 388 static const int kMask = 0xff; |
| 389 |
| 390 // Gets the slot for an index |
| 391 inline Object** GetLocation(int index) { |
| 392 ASSERT(index >= 0 && index < size_); |
| 393 return &blocks_[index >> kShift][index & kMask]; |
| 394 } |
| 395 |
| 396 int size_; |
| 397 List<Object**> blocks_; |
| 398 List<int> new_space_indices_; |
| 399 int singleton_handles_[NUMBER_OF_SINGLETON_HANDLES]; |
| 400 |
| 401 DISALLOW_COPY_AND_ASSIGN(EternalHandles); |
| 402 }; |
| 403 |
| 404 |
334 } } // namespace v8::internal | 405 } } // namespace v8::internal |
335 | 406 |
336 #endif // V8_GLOBAL_HANDLES_H_ | 407 #endif // V8_GLOBAL_HANDLES_H_ |
OLD | NEW |