OLD | NEW |
---|---|
1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 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 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
389 /** | 389 /** |
390 *Checks if the handle holds the only reference to an object. | 390 *Checks if the handle holds the only reference to an object. |
391 */ | 391 */ |
392 inline bool IsNearDeath() const; | 392 inline bool IsNearDeath() const; |
393 | 393 |
394 /** | 394 /** |
395 * Returns true if the handle's reference is weak. | 395 * Returns true if the handle's reference is weak. |
396 */ | 396 */ |
397 inline bool IsWeak() const; | 397 inline bool IsWeak() const; |
398 | 398 |
399 /** | |
400 * Assigns a class ID to the handle. See RetainedObjectInfo | |
Vitaly Repeshko
2011/03/09 14:15:49
"a class" -> "a wrapper class"
mnaganov (inactive)
2011/03/09 15:26:32
Done.
| |
401 * interface description for details. | |
402 */ | |
403 inline void SetWrapperClassId(uint16_t class_id); | |
404 | |
399 private: | 405 private: |
400 friend class ImplementationUtilities; | 406 friend class ImplementationUtilities; |
401 friend class ObjectTemplate; | 407 friend class ObjectTemplate; |
402 }; | 408 }; |
403 | 409 |
404 | 410 |
411 /** | |
412 * Default value of persistent handle class ID. | |
413 */ | |
414 static const uint16_t kPersistentHandleNoClassId = 0; | |
415 | |
416 | |
405 /** | 417 /** |
406 * A stack-allocated class that governs a number of local handles. | 418 * A stack-allocated class that governs a number of local handles. |
407 * After a handle scope has been created, all local handles will be | 419 * After a handle scope has been created, all local handles will be |
408 * allocated within that handle scope until either the handle scope is | 420 * allocated within that handle scope until either the handle scope is |
409 * deleted or another handle scope is created. If there is already a | 421 * deleted or another handle scope is created. If there is already a |
410 * handle scope and a new one is created, all allocations will take | 422 * handle scope and a new one is created, all allocations will take |
411 * place in the new handle scope until it is deleted. After that, | 423 * place in the new handle scope until it is deleted. After that, |
412 * new handles will again be allocated in the original handle scope. | 424 * new handles will again be allocated in the original handle scope. |
413 * | 425 * |
414 * After the handle scope of a local handle has been deleted the | 426 * After the handle scope of a local handle has been deleted the |
(...skipping 2112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2527 size_t total_heap_size_; | 2539 size_t total_heap_size_; |
2528 size_t total_heap_size_executable_; | 2540 size_t total_heap_size_executable_; |
2529 size_t used_heap_size_; | 2541 size_t used_heap_size_; |
2530 size_t heap_size_limit_; | 2542 size_t heap_size_limit_; |
2531 | 2543 |
2532 friend class V8; | 2544 friend class V8; |
2533 }; | 2545 }; |
2534 | 2546 |
2535 | 2547 |
2536 /** | 2548 /** |
2549 * Interface for providing information about embedder's objects | |
Vitaly Repeshko
2011/03/09 14:15:49
Is there a good reason to keep this interface here
mnaganov (inactive)
2011/03/09 15:26:32
After I have moved to v8-profiler.h near HeapProfi
| |
2550 * held by global handles. This information is reported in two ways: | |
2551 * | |
2552 * 1. When calling AddObjectGroup, an embedder may pass | |
2553 * RetainedObjectInfo instance describing the group. To collect | |
2554 * this information while taking a heap snapshot, V8 calls GC | |
2555 * prologue and epilogue callbacks. | |
2556 * | |
2557 * 2. When a heap snapshot is collected, V8 additionally | |
2558 * requests RetainedObjectInfos for persistent handles that | |
2559 * were not previously reported via AddObjectGroup. | |
2560 * | |
2561 * Thus, if an embedder wants to provide information about native | |
2562 * objects for heap snapshots, he can do it in a GC prologue | |
2563 * handler, and / or by assigning wrapper class ids in the following way: | |
2564 * | |
2565 * 1. Bind a callback to class id by calling DefineWrapperClass. | |
2566 * 2. Call SetWrapperClassId on certain persistent handles. | |
2567 * | |
2568 * Returned RetainedObjectInfo instances are kept alive only during | |
Vitaly Repeshko
2011/03/09 14:15:49
Let's change the first sentence to "V8 takes owner
mnaganov (inactive)
2011/03/09 15:26:32
Done.
| |
2569 * snapshot collection. Afterwards, they are freed by calling the | |
2570 * Dispose class function. | |
2571 */ | |
2572 class V8EXPORT RetainedObjectInfo { // NOLINT | |
2573 public: | |
2574 /** Called by V8 when it no longer needs an instance. */ | |
2575 virtual void Dispose() = 0; | |
2576 | |
2577 /** Returns whether two instances are equivalent. */ | |
2578 virtual bool IsEquivalent(RetainedObjectInfo* other) = 0; | |
2579 | |
2580 /** | |
2581 * Returns hash value for the instance. Equivalent instances | |
2582 * must have the same hash value. | |
2583 */ | |
2584 virtual intptr_t GetHash() = 0; | |
2585 | |
2586 /** Returns human-readable label. */ | |
Vitaly Repeshko
2011/03/09 14:15:49
Please document the expected encoding (and whether
mnaganov (inactive)
2011/03/09 15:26:32
Done.
| |
2587 virtual const char* GetLabel() = 0; | |
2588 | |
2589 /** | |
2590 * Returns element count in case if a global handle retains | |
2591 * a subgraph by holding one of its nodes. | |
2592 */ | |
2593 virtual intptr_t GetElementCount() { return -1; } | |
2594 | |
2595 /** Returns embedder's object size in bytes. */ | |
2596 virtual intptr_t GetSizeInBytes() { return -1; } | |
2597 | |
2598 protected: | |
2599 RetainedObjectInfo() {} | |
2600 virtual ~RetainedObjectInfo() {} | |
2601 | |
2602 private: | |
2603 RetainedObjectInfo(const RetainedObjectInfo&); | |
2604 RetainedObjectInfo& operator=(const RetainedObjectInfo&); | |
2605 }; | |
2606 | |
2607 | |
2608 /** | |
2537 * Container class for static utility functions. | 2609 * Container class for static utility functions. |
2538 */ | 2610 */ |
2539 class V8EXPORT V8 { | 2611 class V8EXPORT V8 { |
2540 public: | 2612 public: |
2541 /** Set the callback to invoke in case of fatal errors. */ | 2613 /** Set the callback to invoke in case of fatal errors. */ |
2542 static void SetFatalErrorHandler(FatalErrorCallback that); | 2614 static void SetFatalErrorHandler(FatalErrorCallback that); |
2543 | 2615 |
2544 /** | 2616 /** |
2545 * Ignore out-of-memory exceptions. | 2617 * Ignore out-of-memory exceptions. |
2546 * | 2618 * |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2696 static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback); | 2768 static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback); |
2697 | 2769 |
2698 /** | 2770 /** |
2699 * Allows the host application to group objects together. If one | 2771 * Allows the host application to group objects together. If one |
2700 * object in the group is alive, all objects in the group are alive. | 2772 * object in the group is alive, all objects in the group are alive. |
2701 * After each garbage collection, object groups are removed. It is | 2773 * After each garbage collection, object groups are removed. It is |
2702 * intended to be used in the before-garbage-collection callback | 2774 * intended to be used in the before-garbage-collection callback |
2703 * function, for instance to simulate DOM tree connections among JS | 2775 * function, for instance to simulate DOM tree connections among JS |
2704 * wrapper objects. | 2776 * wrapper objects. |
2705 */ | 2777 */ |
2706 static void AddObjectGroup(Persistent<Value>* objects, size_t length); | 2778 static void AddObjectGroup(Persistent<Value>* objects, |
2779 size_t length, | |
2780 RetainedObjectInfo* info = NULL); | |
2707 | 2781 |
2708 /** | 2782 /** |
2709 * Initializes from snapshot if possible. Otherwise, attempts to | 2783 * Initializes from snapshot if possible. Otherwise, attempts to |
2710 * initialize from scratch. This function is called implicitly if | 2784 * initialize from scratch. This function is called implicitly if |
2711 * you use the API without calling it first. | 2785 * you use the API without calling it first. |
2712 */ | 2786 */ |
2713 static bool Initialize(); | 2787 static bool Initialize(); |
2714 | 2788 |
2715 /** | 2789 /** |
2716 * Adjusts the amount of registered external memory. Used to give | 2790 * Adjusts the amount of registered external memory. Used to give |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2905 V8(); | 2979 V8(); |
2906 | 2980 |
2907 static internal::Object** GlobalizeReference(internal::Object** handle); | 2981 static internal::Object** GlobalizeReference(internal::Object** handle); |
2908 static void DisposeGlobal(internal::Object** global_handle); | 2982 static void DisposeGlobal(internal::Object** global_handle); |
2909 static void MakeWeak(internal::Object** global_handle, | 2983 static void MakeWeak(internal::Object** global_handle, |
2910 void* data, | 2984 void* data, |
2911 WeakReferenceCallback); | 2985 WeakReferenceCallback); |
2912 static void ClearWeak(internal::Object** global_handle); | 2986 static void ClearWeak(internal::Object** global_handle); |
2913 static bool IsGlobalNearDeath(internal::Object** global_handle); | 2987 static bool IsGlobalNearDeath(internal::Object** global_handle); |
2914 static bool IsGlobalWeak(internal::Object** global_handle); | 2988 static bool IsGlobalWeak(internal::Object** global_handle); |
2989 static void SetWrapperClassId(internal::Object** global_handle, | |
2990 uint16_t class_id); | |
2915 | 2991 |
2916 template <class T> friend class Handle; | 2992 template <class T> friend class Handle; |
2917 template <class T> friend class Local; | 2993 template <class T> friend class Local; |
2918 template <class T> friend class Persistent; | 2994 template <class T> friend class Persistent; |
2919 friend class Context; | 2995 friend class Context; |
2920 }; | 2996 }; |
2921 | 2997 |
2922 | 2998 |
2923 /** | 2999 /** |
2924 * An external exception handler. | 3000 * An external exception handler. |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3553 V8::MakeWeak(reinterpret_cast<internal::Object**>(**this), | 3629 V8::MakeWeak(reinterpret_cast<internal::Object**>(**this), |
3554 parameters, | 3630 parameters, |
3555 callback); | 3631 callback); |
3556 } | 3632 } |
3557 | 3633 |
3558 template <class T> | 3634 template <class T> |
3559 void Persistent<T>::ClearWeak() { | 3635 void Persistent<T>::ClearWeak() { |
3560 V8::ClearWeak(reinterpret_cast<internal::Object**>(**this)); | 3636 V8::ClearWeak(reinterpret_cast<internal::Object**>(**this)); |
3561 } | 3637 } |
3562 | 3638 |
3639 template <class T> | |
3640 void Persistent<T>::SetWrapperClassId(uint16_t class_id) { | |
3641 V8::SetWrapperClassId(reinterpret_cast<internal::Object**>(**this), class_id); | |
3642 } | |
3563 | 3643 |
3564 Arguments::Arguments(internal::Object** implicit_args, | 3644 Arguments::Arguments(internal::Object** implicit_args, |
3565 internal::Object** values, int length, | 3645 internal::Object** values, int length, |
3566 bool is_construct_call) | 3646 bool is_construct_call) |
3567 : implicit_args_(implicit_args), | 3647 : implicit_args_(implicit_args), |
3568 values_(values), | 3648 values_(values), |
3569 length_(length), | 3649 length_(length), |
3570 is_construct_call_(is_construct_call) { } | 3650 is_construct_call_(is_construct_call) { } |
3571 | 3651 |
3572 | 3652 |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3837 | 3917 |
3838 | 3918 |
3839 } // namespace v8 | 3919 } // namespace v8 |
3840 | 3920 |
3841 | 3921 |
3842 #undef V8EXPORT | 3922 #undef V8EXPORT |
3843 #undef TYPE_CHECK | 3923 #undef TYPE_CHECK |
3844 | 3924 |
3845 | 3925 |
3846 #endif // V8_H_ | 3926 #endif // V8_H_ |
OLD | NEW |