Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: include/v8.h

Issue 570993002: Introduce Isolate::CreateParams (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: updates Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.
(...skipping 4225 matching lines...) Expand 10 before | Expand all | Expand 10 after
4236 size_t used_heap_size_; 4236 size_t used_heap_size_;
4237 size_t heap_size_limit_; 4237 size_t heap_size_limit_;
4238 4238
4239 friend class V8; 4239 friend class V8;
4240 friend class Isolate; 4240 friend class Isolate;
4241 }; 4241 };
4242 4242
4243 4243
4244 class RetainedObjectInfo; 4244 class RetainedObjectInfo;
4245 4245
4246
4247 /**
4248 * FunctionEntryHook is the type of the profile entry hook called at entry to
4249 * any generated function when function-level profiling is enabled.
4250 *
4251 * \param function the address of the function that's being entered.
4252 * \param return_addr_location points to a location on stack where the machine
4253 * return address resides. This can be used to identify the caller of
4254 * \p function, and/or modified to divert execution when \p function exits.
4255 *
4256 * \note the entry hook must not cause garbage collection.
4257 */
4258 typedef void (*FunctionEntryHook)(uintptr_t function,
4259 uintptr_t return_addr_location);
4260
4261 /**
4262 * A JIT code event is issued each time code is added, moved or removed.
4263 *
4264 * \note removal events are not currently issued.
4265 */
4266 struct JitCodeEvent {
4267 enum EventType {
4268 CODE_ADDED,
4269 CODE_MOVED,
4270 CODE_REMOVED,
4271 CODE_ADD_LINE_POS_INFO,
4272 CODE_START_LINE_INFO_RECORDING,
4273 CODE_END_LINE_INFO_RECORDING
4274 };
4275 // Definition of the code position type. The "POSITION" type means the place
4276 // in the source code which are of interest when making stack traces to
4277 // pin-point the source location of a stack frame as close as possible.
4278 // The "STATEMENT_POSITION" means the place at the beginning of each
4279 // statement, and is used to indicate possible break locations.
4280 enum PositionType { POSITION, STATEMENT_POSITION };
4281
4282 // Type of event.
4283 EventType type;
4284 // Start of the instructions.
4285 void* code_start;
4286 // Size of the instructions.
4287 size_t code_len;
4288 // Script info for CODE_ADDED event.
4289 Handle<UnboundScript> script;
4290 // User-defined data for *_LINE_INFO_* event. It's used to hold the source
4291 // code line information which is returned from the
4292 // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
4293 // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
4294 void* user_data;
4295
4296 struct name_t {
4297 // Name of the object associated with the code, note that the string is not
4298 // zero-terminated.
4299 const char* str;
4300 // Number of chars in str.
4301 size_t len;
4302 };
4303
4304 struct line_info_t {
4305 // PC offset
4306 size_t offset;
4307 // Code postion
4308 size_t pos;
4309 // The position type.
4310 PositionType position_type;
4311 };
4312
4313 union {
4314 // Only valid for CODE_ADDED.
4315 struct name_t name;
4316
4317 // Only valid for CODE_ADD_LINE_POS_INFO
4318 struct line_info_t line_info;
4319
4320 // New location of instructions. Only valid for CODE_MOVED.
4321 void* new_code_start;
4322 };
4323 };
4324
4325 /**
4326 * Option flags passed to the SetJitCodeEventHandler function.
4327 */
4328 enum JitCodeEventOptions {
4329 kJitCodeEventDefault = 0,
4330 // Generate callbacks for already existent code.
4331 kJitCodeEventEnumExisting = 1
4332 };
4333
4334
4335 /**
4336 * Callback function passed to SetJitCodeEventHandler.
4337 *
4338 * \param event code add, move or removal event.
4339 */
4340 typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
4341
4342
4246 /** 4343 /**
4247 * Isolate represents an isolated instance of the V8 engine. V8 4344 * Isolate represents an isolated instance of the V8 engine. V8
4248 * isolates have completely separate states. Objects from one isolate 4345 * isolates have completely separate states. Objects from one isolate
4249 * must not be used in other isolates. When V8 is initialized a 4346 * must not be used in other isolates. When V8 is initialized a
4250 * default isolate is implicitly created and entered. The embedder 4347 * default isolate is implicitly created and entered. The embedder
4251 * can create additional isolates and use them in parallel in multiple 4348 * can create additional isolates and use them in parallel in multiple
4252 * threads. An isolate can be entered by at most one thread at any 4349 * threads. An isolate can be entered by at most one thread at any
4253 * given time. The Locker/Unlocker API must be used to synchronize. 4350 * given time. The Locker/Unlocker API must be used to synchronize.
4254 */ 4351 */
4255 class V8_EXPORT Isolate { 4352 class V8_EXPORT Isolate {
4256 public: 4353 public:
4257 /** 4354 /**
4355 * Initial configuration parameters for a new Isolate.
4356 */
4357 struct CreateParams {
4358 CreateParams() : entry_hook(NULL), code_event_handler(NULL) {}
4359
4360 /**
4361 * The optional entry_hook allows the host application to provide the
4362 * address of a function that's invoked on entry to every V8-generated
4363 * function. Note that entry_hook is invoked at the very start of each
4364 * generated function. Furthermore, if an entry_hook is given, V8 will
4365 * always run without a context snapshot.
4366 */
4367 FunctionEntryHook entry_hook;
4368
4369 /**
4370 * Allows the host application to provide the address of a function that is
4371 * notified each time code is added, moved or removed.
4372 */
4373 JitCodeEventHandler code_event_handler;
4374 };
4375
4376
4377 /**
4258 * Stack-allocated class which sets the isolate for all operations 4378 * Stack-allocated class which sets the isolate for all operations
4259 * executed within a local scope. 4379 * executed within a local scope.
4260 */ 4380 */
4261 class V8_EXPORT Scope { 4381 class V8_EXPORT Scope {
4262 public: 4382 public:
4263 explicit Scope(Isolate* isolate) : isolate_(isolate) { 4383 explicit Scope(Isolate* isolate) : isolate_(isolate) {
4264 isolate->Enter(); 4384 isolate->Enter();
4265 } 4385 }
4266 4386
4267 ~Scope() { isolate_->Exit(); } 4387 ~Scope() { isolate_->Exit(); }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
4355 UseCounterFeature feature); 4475 UseCounterFeature feature);
4356 4476
4357 4477
4358 /** 4478 /**
4359 * Creates a new isolate. Does not change the currently entered 4479 * Creates a new isolate. Does not change the currently entered
4360 * isolate. 4480 * isolate.
4361 * 4481 *
4362 * When an isolate is no longer used its resources should be freed 4482 * When an isolate is no longer used its resources should be freed
4363 * by calling Dispose(). Using the delete operator is not allowed. 4483 * by calling Dispose(). Using the delete operator is not allowed.
4364 */ 4484 */
4365 static Isolate* New(); 4485 static Isolate* New(const CreateParams& params = CreateParams());
4366 4486
4367 /** 4487 /**
4368 * Returns the entered isolate for the current thread or NULL in 4488 * Returns the entered isolate for the current thread or NULL in
4369 * case there is no current isolate. 4489 * case there is no current isolate.
4370 */ 4490 */
4371 static Isolate* GetCurrent(); 4491 static Isolate* GetCurrent();
4372 4492
4373 /** 4493 /**
4374 * Methods below this point require holding a lock (using Locker) in 4494 * Methods below this point require holding a lock (using Locker) in
4375 * a multi-threaded environment. 4495 * a multi-threaded environment.
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
4665 void LowMemoryNotification(); 4785 void LowMemoryNotification();
4666 4786
4667 /** 4787 /**
4668 * Optional notification that a context has been disposed. V8 uses 4788 * Optional notification that a context has been disposed. V8 uses
4669 * these notifications to guide the GC heuristic. Returns the number 4789 * these notifications to guide the GC heuristic. Returns the number
4670 * of context disposals - including this one - since the last time 4790 * of context disposals - including this one - since the last time
4671 * V8 had a chance to clean up. 4791 * V8 had a chance to clean up.
4672 */ 4792 */
4673 int ContextDisposedNotification(); 4793 int ContextDisposedNotification();
4674 4794
4795 /**
4796 * Allows the host application to provide the address of a function that is
4797 * notified each time code is added, moved or removed.
4798 *
4799 * \param options options for the JIT code event handler.
4800 * \param event_handler the JIT code event handler, which will be invoked
4801 * each time code is added, moved or removed.
4802 * \note \p event_handler won't get notified of existent code.
4803 * \note since code removal notifications are not currently issued, the
4804 * \p event_handler may get notifications of code that overlaps earlier
4805 * code notifications. This happens when code areas are reused, and the
4806 * earlier overlapping code areas should therefore be discarded.
4807 * \note the events passed to \p event_handler and the strings they point to
4808 * are not guaranteed to live past each call. The \p event_handler must
4809 * copy strings and other parameters it needs to keep around.
4810 * \note the set of events declared in JitCodeEvent::EventType is expected to
4811 * grow over time, and the JitCodeEvent structure is expected to accrue
4812 * new members. The \p event_handler function must ignore event codes
4813 * it does not recognize to maintain future compatibility.
4814 * \note Use Isolate::CreateParams to get events for code executed during
4815 * Isolate setup.
4816 */
4817 void SetJitCodeEventHandler(JitCodeEventOptions options,
4818 JitCodeEventHandler event_handler);
4819
4675 private: 4820 private:
4676 template<class K, class V, class Traits> friend class PersistentValueMap; 4821 template<class K, class V, class Traits> friend class PersistentValueMap;
4677 4822
4678 Isolate(); 4823 Isolate();
4679 Isolate(const Isolate&); 4824 Isolate(const Isolate&);
4680 ~Isolate(); 4825 ~Isolate();
4681 Isolate& operator=(const Isolate&); 4826 Isolate& operator=(const Isolate&);
4682 void* operator new(size_t size); 4827 void* operator new(size_t size);
4683 void operator delete(void*, size_t); 4828 void operator delete(void*, size_t);
4684 4829
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
4744 * \returns either return_addr_location, or else a pointer to the profiler's 4889 * \returns either return_addr_location, or else a pointer to the profiler's
4745 * copy of the original return address. 4890 * copy of the original return address.
4746 * 4891 *
4747 * \note the resolver function must not cause garbage collection. 4892 * \note the resolver function must not cause garbage collection.
4748 */ 4893 */
4749 typedef uintptr_t (*ReturnAddressLocationResolver)( 4894 typedef uintptr_t (*ReturnAddressLocationResolver)(
4750 uintptr_t return_addr_location); 4895 uintptr_t return_addr_location);
4751 4896
4752 4897
4753 /** 4898 /**
4754 * FunctionEntryHook is the type of the profile entry hook called at entry to
4755 * any generated function when function-level profiling is enabled.
4756 *
4757 * \param function the address of the function that's being entered.
4758 * \param return_addr_location points to a location on stack where the machine
4759 * return address resides. This can be used to identify the caller of
4760 * \p function, and/or modified to divert execution when \p function exits.
4761 *
4762 * \note the entry hook must not cause garbage collection.
4763 */
4764 typedef void (*FunctionEntryHook)(uintptr_t function,
4765 uintptr_t return_addr_location);
4766
4767
4768 /**
4769 * A JIT code event is issued each time code is added, moved or removed.
4770 *
4771 * \note removal events are not currently issued.
4772 */
4773 struct JitCodeEvent {
4774 enum EventType {
4775 CODE_ADDED,
4776 CODE_MOVED,
4777 CODE_REMOVED,
4778 CODE_ADD_LINE_POS_INFO,
4779 CODE_START_LINE_INFO_RECORDING,
4780 CODE_END_LINE_INFO_RECORDING
4781 };
4782 // Definition of the code position type. The "POSITION" type means the place
4783 // in the source code which are of interest when making stack traces to
4784 // pin-point the source location of a stack frame as close as possible.
4785 // The "STATEMENT_POSITION" means the place at the beginning of each
4786 // statement, and is used to indicate possible break locations.
4787 enum PositionType {
4788 POSITION,
4789 STATEMENT_POSITION
4790 };
4791
4792 // Type of event.
4793 EventType type;
4794 // Start of the instructions.
4795 void* code_start;
4796 // Size of the instructions.
4797 size_t code_len;
4798 // Script info for CODE_ADDED event.
4799 Handle<UnboundScript> script;
4800 // User-defined data for *_LINE_INFO_* event. It's used to hold the source
4801 // code line information which is returned from the
4802 // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
4803 // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
4804 void* user_data;
4805
4806 struct name_t {
4807 // Name of the object associated with the code, note that the string is not
4808 // zero-terminated.
4809 const char* str;
4810 // Number of chars in str.
4811 size_t len;
4812 };
4813
4814 struct line_info_t {
4815 // PC offset
4816 size_t offset;
4817 // Code postion
4818 size_t pos;
4819 // The position type.
4820 PositionType position_type;
4821 };
4822
4823 union {
4824 // Only valid for CODE_ADDED.
4825 struct name_t name;
4826
4827 // Only valid for CODE_ADD_LINE_POS_INFO
4828 struct line_info_t line_info;
4829
4830 // New location of instructions. Only valid for CODE_MOVED.
4831 void* new_code_start;
4832 };
4833 };
4834
4835 /**
4836 * Option flags passed to the SetJitCodeEventHandler function.
4837 */
4838 enum JitCodeEventOptions {
4839 kJitCodeEventDefault = 0,
4840 // Generate callbacks for already existent code.
4841 kJitCodeEventEnumExisting = 1
4842 };
4843
4844
4845 /**
4846 * Callback function passed to SetJitCodeEventHandler.
4847 *
4848 * \param event code add, move or removal event.
4849 */
4850 typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
4851
4852
4853 /**
4854 * Interface for iterating through all external resources in the heap. 4899 * Interface for iterating through all external resources in the heap.
4855 */ 4900 */
4856 class V8_EXPORT ExternalResourceVisitor { // NOLINT 4901 class V8_EXPORT ExternalResourceVisitor { // NOLINT
4857 public: 4902 public:
4858 virtual ~ExternalResourceVisitor() {} 4903 virtual ~ExternalResourceVisitor() {}
4859 virtual void VisitExternalString(Handle<String> string) {} 4904 virtual void VisitExternalString(Handle<String> string) {}
4860 }; 4905 };
4861 4906
4862 4907
4863 /** 4908 /**
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
5062 * invoked on entry to every V8-generated function. 5107 * invoked on entry to every V8-generated function.
5063 * Note that \p entry_hook is invoked at the very start of each 5108 * Note that \p entry_hook is invoked at the very start of each
5064 * generated function. 5109 * generated function.
5065 * 5110 *
5066 * \param isolate the isolate to operate on. 5111 * \param isolate the isolate to operate on.
5067 * \param entry_hook a function that will be invoked on entry to every 5112 * \param entry_hook a function that will be invoked on entry to every
5068 * V8-generated function. 5113 * V8-generated function.
5069 * \returns true on success on supported platforms, false on failure. 5114 * \returns true on success on supported platforms, false on failure.
5070 * \note Setting an entry hook can only be done very early in an isolates 5115 * \note Setting an entry hook can only be done very early in an isolates
5071 * lifetime, and once set, the entry hook cannot be revoked. 5116 * lifetime, and once set, the entry hook cannot be revoked.
5117 *
5118 * Deprecated, will be removed. Use Isolate::New(entry_hook) instead.
5072 */ 5119 */
5073 static bool SetFunctionEntryHook(Isolate* isolate, 5120 static bool SetFunctionEntryHook(Isolate* isolate,
5074 FunctionEntryHook entry_hook); 5121 FunctionEntryHook entry_hook);
5075 5122
5076 /** 5123 /**
5077 * Allows the host application to provide the address of a function that is 5124 * Allows the host application to provide the address of a function that is
5078 * notified each time code is added, moved or removed. 5125 * notified each time code is added, moved or removed.
5079 * 5126 *
5080 * \param options options for the JIT code event handler. 5127 * \param options options for the JIT code event handler.
5081 * \param event_handler the JIT code event handler, which will be invoked 5128 * \param event_handler the JIT code event handler, which will be invoked
5082 * each time code is added, moved or removed. 5129 * each time code is added, moved or removed.
5083 * \note \p event_handler won't get notified of existent code. 5130 * \note \p event_handler won't get notified of existent code.
5084 * \note since code removal notifications are not currently issued, the 5131 * \note since code removal notifications are not currently issued, the
5085 * \p event_handler may get notifications of code that overlaps earlier 5132 * \p event_handler may get notifications of code that overlaps earlier
5086 * code notifications. This happens when code areas are reused, and the 5133 * code notifications. This happens when code areas are reused, and the
5087 * earlier overlapping code areas should therefore be discarded. 5134 * earlier overlapping code areas should therefore be discarded.
5088 * \note the events passed to \p event_handler and the strings they point to 5135 * \note the events passed to \p event_handler and the strings they point to
5089 * are not guaranteed to live past each call. The \p event_handler must 5136 * are not guaranteed to live past each call. The \p event_handler must
5090 * copy strings and other parameters it needs to keep around. 5137 * copy strings and other parameters it needs to keep around.
5091 * \note the set of events declared in JitCodeEvent::EventType is expected to 5138 * \note the set of events declared in JitCodeEvent::EventType is expected to
5092 * grow over time, and the JitCodeEvent structure is expected to accrue 5139 * grow over time, and the JitCodeEvent structure is expected to accrue
5093 * new members. The \p event_handler function must ignore event codes 5140 * new members. The \p event_handler function must ignore event codes
5094 * it does not recognize to maintain future compatibility. 5141 * it does not recognize to maintain future compatibility.
5142 *
5143 * Deprecated, will be removed. Use Isolate::SetJitCodeEventHandler or
5144 * Isolate::CreateParams instead.
5095 */ 5145 */
5096 static void SetJitCodeEventHandler(JitCodeEventOptions options, 5146 static void SetJitCodeEventHandler(JitCodeEventOptions options,
5097 JitCodeEventHandler event_handler); 5147 JitCodeEventHandler event_handler);
5098 5148
5099 /** 5149 /**
5100 * Forcefully terminate the current thread of JavaScript execution 5150 * Forcefully terminate the current thread of JavaScript execution
5101 * in the given isolate. 5151 * in the given isolate.
5102 * 5152 *
5103 * This method can be used by any thread even if that thread has not 5153 * This method can be used by any thread even if that thread has not
5104 * acquired the V8 lock with a Locker object. 5154 * acquired the V8 lock with a Locker object.
(...skipping 1821 matching lines...) Expand 10 before | Expand all | Expand 10 after
6926 */ 6976 */
6927 6977
6928 6978
6929 } // namespace v8 6979 } // namespace v8
6930 6980
6931 6981
6932 #undef TYPE_CHECK 6982 #undef TYPE_CHECK
6933 6983
6934 6984
6935 #endif // V8_H_ 6985 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698