OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** \mainpage V8 API Reference Guide | 5 /** \mainpage V8 API Reference Guide |
6 * | 6 * |
7 * V8 is Google's open source JavaScript engine. | 7 * V8 is Google's open source JavaScript engine. |
8 * | 8 * |
9 * This set of documents provides reference material generated from the | 9 * This set of documents provides reference material generated from the |
10 * V8 header file, include/v8.h. | 10 * V8 header file, include/v8.h. |
11 * | 11 * |
12 * For other documentation see http://code.google.com/apis/v8/ | 12 * For other documentation see http://code.google.com/apis/v8/ |
13 */ | 13 */ |
14 | 14 |
15 #ifndef INCLUDE_V8_H_ | 15 #ifndef INCLUDE_V8_H_ |
16 #define INCLUDE_V8_H_ | 16 #define INCLUDE_V8_H_ |
17 | 17 |
18 #include <stddef.h> | 18 #include <stddef.h> |
19 #include <stdint.h> | 19 #include <stdint.h> |
20 #include <stdio.h> | 20 #include <stdio.h> |
21 #include <utility> | |
22 #include <vector> | |
21 | 23 |
22 #include "v8-version.h" // NOLINT(build/include) | 24 #include "v8-version.h" // NOLINT(build/include) |
23 #include "v8config.h" // NOLINT(build/include) | 25 #include "v8config.h" // NOLINT(build/include) |
24 | 26 |
25 // We reserve the V8_* prefix for macros defined in V8 public API and | 27 // We reserve the V8_* prefix for macros defined in V8 public API and |
26 // assume there are no name conflicts with the embedder's code. | 28 // assume there are no name conflicts with the embedder's code. |
27 | 29 |
28 #ifdef V8_OS_WIN | 30 #ifdef V8_OS_WIN |
29 | 31 |
30 // Setup for Windows DLL export/import. When building the V8 DLL the | 32 // Setup for Windows DLL export/import. When building the V8 DLL the |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
587 typename WeakCallbackInfo<P>::Callback callback, | 589 typename WeakCallbackInfo<P>::Callback callback, |
588 WeakCallbackType type); | 590 WeakCallbackType type); |
589 | 591 |
590 template<typename P> | 592 template<typename P> |
591 V8_INLINE P* ClearWeak(); | 593 V8_INLINE P* ClearWeak(); |
592 | 594 |
593 // TODO(dcarney): remove this. | 595 // TODO(dcarney): remove this. |
594 V8_INLINE void ClearWeak() { ClearWeak<void>(); } | 596 V8_INLINE void ClearWeak() { ClearWeak<void>(); } |
595 | 597 |
596 /** | 598 /** |
599 * Allows the embedder to tell the v8 garbage collector that a certain object | |
600 * is alive. Only allowed when the embedder is asked to trace its heap by | |
601 * EmbedderHeapTracer. | |
602 */ | |
603 V8_INLINE void RegisterExternalReference(Isolate* isolate); | |
Hannes Payer (out of office)
2016/03/31 12:31:38
RegisterExternallyReferencedObject
| |
604 | |
605 /** | |
597 * Marks the reference to this object independent. Garbage collector is free | 606 * Marks the reference to this object independent. Garbage collector is free |
598 * to ignore any object groups containing this object. Weak callback for an | 607 * to ignore any object groups containing this object. Weak callback for an |
599 * independent handle should not assume that it will be preceded by a global | 608 * independent handle should not assume that it will be preceded by a global |
600 * GC prologue callback or followed by a global GC epilogue callback. | 609 * GC prologue callback or followed by a global GC epilogue callback. |
601 */ | 610 */ |
602 V8_INLINE void MarkIndependent(); | 611 V8_INLINE void MarkIndependent(); |
603 | 612 |
604 /** | 613 /** |
605 * Marks the reference to this object partially dependent. Partially dependent | 614 * Marks the reference to this object partially dependent. Partially dependent |
606 * handles only depend on other partially dependent handles and these | 615 * handles only depend on other partially dependent handles and these |
(...skipping 4747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5354 * Memory pressure level for the MemoryPressureNotification. | 5363 * Memory pressure level for the MemoryPressureNotification. |
5355 * kNone hints V8 that there is no memory pressure. | 5364 * kNone hints V8 that there is no memory pressure. |
5356 * kModerate hints V8 to speed up incremental garbage collection at the cost of | 5365 * kModerate hints V8 to speed up incremental garbage collection at the cost of |
5357 * of higher latency due to garbage collection pauses. | 5366 * of higher latency due to garbage collection pauses. |
5358 * kCritical hints V8 to free memory as soon as possible. Garbage collection | 5367 * kCritical hints V8 to free memory as soon as possible. Garbage collection |
5359 * pauses at this level will be large. | 5368 * pauses at this level will be large. |
5360 */ | 5369 */ |
5361 enum class MemoryPressureLevel { kNone, kModerate, kCritical }; | 5370 enum class MemoryPressureLevel { kNone, kModerate, kCritical }; |
5362 | 5371 |
5363 /** | 5372 /** |
5373 * Interface for tracing through the embedder heap. During the v8 garbage | |
5374 * collection, v8 collects hidden fields of all potential wrappers, and at the | |
5375 * end of its marking phase iterates the collection and asks the embedder to | |
5376 * trace through its heap and call PersistentBase::RegisterExternalReference on | |
5377 * each js object reachable from any of the given wrappers. | |
5378 * | |
5379 * Before the first call to the TraceWrappableFrom function v8 will call | |
5380 * TraceRoots. When the v8 garbage collection is finished, v8 will call | |
5381 * ClearTracingMarks. | |
5382 */ | |
5383 class EmbedderHeapTracer { | |
5384 public: | |
5385 /** | |
5386 * V8 will call this method at the beginning of the gc cycle. | |
5387 */ | |
5388 virtual void TraceRoots(Isolate* isolate) = 0; | |
5389 | |
5390 /** | |
5391 * V8 will call this method with internal fields of a potential wrappers. | |
5392 * Embedder is expected to trace its heap (synchronously) and call | |
5393 * PersistentBase::RegisterExternalReference() on all wrappers reachable from | |
5394 * any of the given wrappers. | |
5395 */ | |
5396 virtual void TraceWrappableFrom( | |
5397 Isolate* isolate, | |
5398 const std::vector<std::pair<void*, void*> >& internal_fields) = 0; | |
5399 /** | |
5400 * V8 will call this method at the end of the gc cycle. Allocation is *not* | |
5401 * allowed in the ClearTracingMarks. | |
5402 */ | |
5403 virtual void ClearTracingMarks(Isolate* isolate) = 0; | |
5404 | |
5405 protected: | |
5406 virtual ~EmbedderHeapTracer() = default; | |
5407 }; | |
5408 | |
5409 /** | |
5364 * Isolate represents an isolated instance of the V8 engine. V8 isolates have | 5410 * Isolate represents an isolated instance of the V8 engine. V8 isolates have |
5365 * completely separate states. Objects from one isolate must not be used in | 5411 * completely separate states. Objects from one isolate must not be used in |
5366 * other isolates. The embedder can create multiple isolates and use them in | 5412 * other isolates. The embedder can create multiple isolates and use them in |
5367 * parallel in multiple threads. An isolate can be entered by at most one | 5413 * parallel in multiple threads. An isolate can be entered by at most one |
5368 * thread at any given time. The Locker/Unlocker API must be used to | 5414 * thread at any given time. The Locker/Unlocker API must be used to |
5369 * synchronize. | 5415 * synchronize. |
5370 */ | 5416 */ |
5371 class V8_EXPORT Isolate { | 5417 class V8_EXPORT Isolate { |
5372 public: | 5418 public: |
5373 /** | 5419 /** |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5822 void AddGCPrologueCallback(GCCallback callback, | 5868 void AddGCPrologueCallback(GCCallback callback, |
5823 GCType gc_type_filter = kGCTypeAll); | 5869 GCType gc_type_filter = kGCTypeAll); |
5824 | 5870 |
5825 /** | 5871 /** |
5826 * This function removes callback which was installed by | 5872 * This function removes callback which was installed by |
5827 * AddGCPrologueCallback function. | 5873 * AddGCPrologueCallback function. |
5828 */ | 5874 */ |
5829 void RemoveGCPrologueCallback(GCCallback callback); | 5875 void RemoveGCPrologueCallback(GCCallback callback); |
5830 | 5876 |
5831 /** | 5877 /** |
5878 * Sets the embedder heap tracer for the isolate. | |
5879 */ | |
5880 void SetEmbedderHeapTracer(EmbedderHeapTracer* tracer); | |
5881 | |
5882 /** | |
5832 * Enables the host application to receive a notification after a | 5883 * Enables the host application to receive a notification after a |
5833 * garbage collection. Allocations are allowed in the callback function, | 5884 * garbage collection. Allocations are allowed in the callback function, |
5834 * but the callback is not re-entrant: if the allocation inside it will | 5885 * but the callback is not re-entrant: if the allocation inside it will |
5835 * trigger the garbage collection, the callback won't be called again. | 5886 * trigger the garbage collection, the callback won't be called again. |
5836 * It is possible to specify the GCType filter for your callback. But it is | 5887 * It is possible to specify the GCType filter for your callback. But it is |
5837 * not possible to register the same callback function two times with | 5888 * not possible to register the same callback function two times with |
5838 * different GCType filters. | 5889 * different GCType filters. |
5839 */ | 5890 */ |
5840 void AddGCEpilogueCallback(GCCallback callback, | 5891 void AddGCEpilogueCallback(GCCallback callback, |
5841 GCType gc_type_filter = kGCTypeAll); | 5892 GCType gc_type_filter = kGCTypeAll); |
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6578 static void ShutdownPlatform(); | 6629 static void ShutdownPlatform(); |
6579 | 6630 |
6580 private: | 6631 private: |
6581 V8(); | 6632 V8(); |
6582 | 6633 |
6583 static internal::Object** GlobalizeReference(internal::Isolate* isolate, | 6634 static internal::Object** GlobalizeReference(internal::Isolate* isolate, |
6584 internal::Object** handle); | 6635 internal::Object** handle); |
6585 static internal::Object** CopyPersistent(internal::Object** handle); | 6636 static internal::Object** CopyPersistent(internal::Object** handle); |
6586 static void DisposeGlobal(internal::Object** global_handle); | 6637 static void DisposeGlobal(internal::Object** global_handle); |
6587 typedef WeakCallbackData<Value, void>::Callback WeakCallback; | 6638 typedef WeakCallbackData<Value, void>::Callback WeakCallback; |
6639 static void RegisterExternallyReferencedObject(internal::Object** object, | |
6640 internal::Isolate* isolate); | |
6588 static void MakeWeak(internal::Object** global_handle, void* data, | 6641 static void MakeWeak(internal::Object** global_handle, void* data, |
6589 WeakCallback weak_callback); | 6642 WeakCallback weak_callback); |
6590 static void MakeWeak(internal::Object** global_handle, void* data, | 6643 static void MakeWeak(internal::Object** global_handle, void* data, |
6591 WeakCallbackInfo<void>::Callback weak_callback, | 6644 WeakCallbackInfo<void>::Callback weak_callback, |
6592 WeakCallbackType type); | 6645 WeakCallbackType type); |
6593 static void MakeWeak(internal::Object** global_handle, void* data, | 6646 static void MakeWeak(internal::Object** global_handle, void* data, |
6594 // Must be 0 or -1. | 6647 // Must be 0 or -1. |
6595 int internal_field_index1, | 6648 int internal_field_index1, |
6596 // Must be 1 or -1. | 6649 // Must be 1 or -1. |
6597 int internal_field_index2, | 6650 int internal_field_index2, |
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7595 } | 7648 } |
7596 | 7649 |
7597 | 7650 |
7598 template <class T> | 7651 template <class T> |
7599 template <typename P> | 7652 template <typename P> |
7600 P* PersistentBase<T>::ClearWeak() { | 7653 P* PersistentBase<T>::ClearWeak() { |
7601 return reinterpret_cast<P*>( | 7654 return reinterpret_cast<P*>( |
7602 V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_))); | 7655 V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_))); |
7603 } | 7656 } |
7604 | 7657 |
7658 template <class T> | |
7659 void PersistentBase<T>::RegisterExternalReference(Isolate* isolate) { | |
7660 if (IsEmpty()) return; | |
7661 V8::RegisterExternallyReferencedObject( | |
7662 reinterpret_cast<internal::Object**>(this->val_), | |
7663 reinterpret_cast<internal::Isolate*>(isolate)); | |
7664 } | |
7605 | 7665 |
7606 template <class T> | 7666 template <class T> |
7607 void PersistentBase<T>::MarkIndependent() { | 7667 void PersistentBase<T>::MarkIndependent() { |
7608 typedef internal::Internals I; | 7668 typedef internal::Internals I; |
7609 if (this->IsEmpty()) return; | 7669 if (this->IsEmpty()) return; |
7610 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), | 7670 I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
7611 true, | 7671 true, |
7612 I::kNodeIsIndependentShift); | 7672 I::kNodeIsIndependentShift); |
7613 } | 7673 } |
7614 | 7674 |
(...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8687 */ | 8747 */ |
8688 | 8748 |
8689 | 8749 |
8690 } // namespace v8 | 8750 } // namespace v8 |
8691 | 8751 |
8692 | 8752 |
8693 #undef TYPE_CHECK | 8753 #undef TYPE_CHECK |
8694 | 8754 |
8695 | 8755 |
8696 #endif // INCLUDE_V8_H_ | 8756 #endif // INCLUDE_V8_H_ |
OLD | NEW |