class RetainedObjectInfo;
+
+/**
+ * FunctionEntryHook is the type of the profile entry hook called at entry to
+ * any generated function when function-level profiling is enabled.
+ *
+ * \param function the address of the function that's being entered.
+ * \param return_addr_location points to a location on stack where the machine
+ * return address resides. This can be used to identify the caller of
+ * \p function, and/or modified to divert execution when \p function exits.
+ *
+ * \note the entry hook must not cause garbage collection.
+ */
+typedef void (*FunctionEntryHook)(uintptr_t function,
+ uintptr_t return_addr_location);
+
+/**
+ * A JIT code event is issued each time code is added, moved or removed.
+ *
+ * \note removal events are not currently issued.
+ */
+struct JitCodeEvent {
+ enum EventType {
+ CODE_ADDED,
+ CODE_MOVED,
+ CODE_REMOVED,
+ CODE_ADD_LINE_POS_INFO,
+ CODE_START_LINE_INFO_RECORDING,
+ CODE_END_LINE_INFO_RECORDING
+ };
+ // Definition of the code position type. The "POSITION" type means the place
+ // in the source code which are of interest when making stack traces to
+ // pin-point the source location of a stack frame as close as possible.
+ // The "STATEMENT_POSITION" means the place at the beginning of each
+ // statement, and is used to indicate possible break locations.
+ enum PositionType { POSITION, STATEMENT_POSITION };
+
+ // Type of event.
+ EventType type;
+ // Start of the instructions.
+ void* code_start;
+ // Size of the instructions.
+ size_t code_len;
+ // Script info for CODE_ADDED event.
+ Handle<UnboundScript> script;
+ // User-defined data for *_LINE_INFO_* event. It's used to hold the source
+ // code line information which is returned from the
+ // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
+ // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
+ void* user_data;
+
+ struct name_t {
+ // Name of the object associated with the code, note that the string is not
+ // zero-terminated.
+ const char* str;
+ // Number of chars in str.
+ size_t len;
+ };
+
+ struct line_info_t {
+ // PC offset
+ size_t offset;
+ // Code postion
+ size_t pos;
+ // The position type.
+ PositionType position_type;
+ };
+
+ union {
+ // Only valid for CODE_ADDED.
+ struct name_t name;
+
+ // Only valid for CODE_ADD_LINE_POS_INFO
+ struct line_info_t line_info;
+
+ // New location of instructions. Only valid for CODE_MOVED.
+ void* new_code_start;
+ };
+};
+
+/**
+ * Option flags passed to the SetJitCodeEventHandler function.
+ */
+enum JitCodeEventOptions {
+ kJitCodeEventDefault = 0,
+ // Generate callbacks for already existent code.
+ kJitCodeEventEnumExisting = 1
+};
+
+
+/**
+ * Callback function passed to SetJitCodeEventHandler.
+ *
+ * \param event code add, move or removal event.
+ */
+typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
+
+
/**
* Isolate represents an isolated instance of the V8 engine. V8
* isolates have completely separate states. Objects from one isolate
class V8_EXPORT Isolate {
public:
/**
+ * Initial configuration parameters for a new Isolate.
+ */
+ struct CreateParams {
+ CreateParams() : entry_hook(NULL), code_event_handler(NULL) {}
+
+ /**
+ * The optional entry_hook allows the host application to provide the
+ * address of a function that's invoked on entry to every V8-generated
+ * function. Note that entry_hook is invoked at the very start of each
+ * generated function. Furthermore, if an entry_hook is given, V8 will
+ * always run without a context snapshot.
+ */
+ FunctionEntryHook entry_hook;
+
+ /**
+ * Allows the host application to provide the address of a function that is
+ * notified each time code is added, moved or removed.
+ */
+ JitCodeEventHandler code_event_handler;
+ };
+
+
+ /**
* Stack-allocated class which sets the isolate for all operations
* executed within a local scope.
*/
* When an isolate is no longer used its resources should be freed
* by calling Dispose(). Using the delete operator is not allowed.
*/
- static Isolate* New();
+ static Isolate* New(const CreateParams& params = CreateParams());
/**
* Returns the entered isolate for the current thread or NULL in
*/
int ContextDisposedNotification();
+ /**
+ * Allows the host application to provide the address of a function that is
+ * notified each time code is added, moved or removed.
+ *
+ * \param options options for the JIT code event handler.
+ * \param event_handler the JIT code event handler, which will be invoked
+ * each time code is added, moved or removed.
+ * \note \p event_handler won't get notified of existent code.
+ * \note since code removal notifications are not currently issued, the
+ * \p event_handler may get notifications of code that overlaps earlier
+ * code notifications. This happens when code areas are reused, and the
+ * earlier overlapping code areas should therefore be discarded.
+ * \note the events passed to \p event_handler and the strings they point to
+ * are not guaranteed to live past each call. The \p event_handler must
+ * copy strings and other parameters it needs to keep around.
+ * \note the set of events declared in JitCodeEvent::EventType is expected to
+ * grow over time, and the JitCodeEvent structure is expected to accrue
+ * new members. The \p event_handler function must ignore event codes
+ * it does not recognize to maintain future compatibility.
+ * \note Use Isolate::CreateParams to get events for code executed during
+ * Isolate setup.
+ */
+ void SetJitCodeEventHandler(JitCodeEventOptions options,
+ JitCodeEventHandler event_handler);
+
private:
template<class K, class V, class Traits> friend class PersistentValueMap;
/**
- * FunctionEntryHook is the type of the profile entry hook called at entry to
- * any generated function when function-level profiling is enabled.
- *
- * \param function the address of the function that's being entered.
- * \param return_addr_location points to a location on stack where the machine
- * return address resides. This can be used to identify the caller of
- * \p function, and/or modified to divert execution when \p function exits.
- *
- * \note the entry hook must not cause garbage collection.
- */
-typedef void (*FunctionEntryHook)(uintptr_t function,
- uintptr_t return_addr_location);
-
-
-/**
- * A JIT code event is issued each time code is added, moved or removed.
- *
- * \note removal events are not currently issued.
- */
-struct JitCodeEvent {
- enum EventType {
- CODE_ADDED,
- CODE_MOVED,
- CODE_REMOVED,
- CODE_ADD_LINE_POS_INFO,
- CODE_START_LINE_INFO_RECORDING,
- CODE_END_LINE_INFO_RECORDING
- };
- // Definition of the code position type. The "POSITION" type means the place
- // in the source code which are of interest when making stack traces to
- // pin-point the source location of a stack frame as close as possible.
- // The "STATEMENT_POSITION" means the place at the beginning of each
- // statement, and is used to indicate possible break locations.
- enum PositionType {
- POSITION,
- STATEMENT_POSITION
- };
-
- // Type of event.
- EventType type;
- // Start of the instructions.
- void* code_start;
- // Size of the instructions.
- size_t code_len;
- // Script info for CODE_ADDED event.
- Handle<UnboundScript> script;
- // User-defined data for *_LINE_INFO_* event. It's used to hold the source
- // code line information which is returned from the
- // CODE_START_LINE_INFO_RECORDING event. And it's passed to subsequent
- // CODE_ADD_LINE_POS_INFO and CODE_END_LINE_INFO_RECORDING events.
- void* user_data;
-
- struct name_t {
- // Name of the object associated with the code, note that the string is not
- // zero-terminated.
- const char* str;
- // Number of chars in str.
- size_t len;
- };
-
- struct line_info_t {
- // PC offset
- size_t offset;
- // Code postion
- size_t pos;
- // The position type.
- PositionType position_type;
- };
-
- union {
- // Only valid for CODE_ADDED.
- struct name_t name;
-
- // Only valid for CODE_ADD_LINE_POS_INFO
- struct line_info_t line_info;
-
- // New location of instructions. Only valid for CODE_MOVED.
- void* new_code_start;
- };
-};
-
-/**
- * Option flags passed to the SetJitCodeEventHandler function.
- */
-enum JitCodeEventOptions {
- kJitCodeEventDefault = 0,
- // Generate callbacks for already existent code.
- kJitCodeEventEnumExisting = 1
-};
-
-
-/**
- * Callback function passed to SetJitCodeEventHandler.
- *
- * \param event code add, move or removal event.
- */
-typedef void (*JitCodeEventHandler)(const JitCodeEvent* event);
-
-
-/**
* Interface for iterating through all external resources in the heap.
*/
class V8_EXPORT ExternalResourceVisitor { // NOLINT
* \returns true on success on supported platforms, false on failure.
* \note Setting an entry hook can only be done very early in an isolates
* lifetime, and once set, the entry hook cannot be revoked.
+ *
+ * Deprecated, will be removed. Use Isolate::New(entry_hook) instead.
*/
static bool SetFunctionEntryHook(Isolate* isolate,
FunctionEntryHook entry_hook);
* grow over time, and the JitCodeEvent structure is expected to accrue
* new members. The \p event_handler function must ignore event codes
* it does not recognize to maintain future compatibility.
+ *
+ * Deprecated, will be removed. Use Isolate::SetJitCodeEventHandler or
+ * Isolate::CreateParams instead.
*/
static void SetJitCodeEventHandler(JitCodeEventOptions options,
JitCodeEventHandler event_handler);
void SetFunctionEntryHookTest::RunTest() {
// Work in a new isolate throughout.
- v8::Isolate* isolate = v8::Isolate::New();
-
- // Test setting the entry hook on the new isolate.
- CHECK(v8::V8::SetFunctionEntryHook(isolate, EntryHook));
-
- // Replacing the hook, once set should fail.
- CHECK_EQ(false, v8::V8::SetFunctionEntryHook(isolate, EntryHook));
+ v8::Isolate::CreateParams create_params;
+ create_params.entry_hook = EntryHook;
+ create_params.code_event_handler = JitEvent;
+ v8::Isolate* isolate = v8::Isolate::New(create_params);
{
v8::Isolate::Scope scope(isolate);
- v8::V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, JitEvent);
-
RunLoopInNewEnv(isolate);
// Check the exepected invocation counts.
// We should record no invocations in this isolate.
CHECK_EQ(0, static_cast<int>(invocations_.size()));
}
- // Since the isolate has been used, we shouldn't be able to set an entry
- // hook anymore.
- CHECK_EQ(false, v8::V8::SetFunctionEntryHook(isolate, EntryHook));
isolate->Dispose();
}
saw_bar = 0;
move_events = 0;
- V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, event_handler);
+ isolate->SetJitCodeEventHandler(v8::kJitCodeEventDefault, event_handler);
// Generate new code objects sparsely distributed across several
// different fragmented code-space pages.
// Force code movement.
heap->CollectAllAvailableGarbage("TestSetJitCodeEventHandler");
- V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL);
+ isolate->SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL);
CHECK_LE(kIterations, saw_bar);
CHECK_LT(0, move_events);
i::HashMap lineinfo(MatchPointers);
jitcode_line_info = &lineinfo;
- V8::SetJitCodeEventHandler(v8::kJitCodeEventEnumExisting, event_handler);
- V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL);
+ isolate->SetJitCodeEventHandler(v8::kJitCodeEventEnumExisting,
+ event_handler);
+ isolate->SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL);
jitcode_line_info = NULL;
// We expect that we got some events. Note that if we could get code removal