Commit f5b660ac authored by danno@chromium.org's avatar danno@chromium.org

Intel VTune integration for V8/d8

In this patch, we added the JIT code event handler for Vtune. Most of the code is in the
folder src/third_party/vtune. Two APIs are added in include/v8.h to get the requirement info
from V8.

We add the v8_enable_vtunejit parameter for GYP to enable these Vtune code compilation.
vTune::InitilizeVtuneForV8() is invoked in the embedder of V8 to make sure it's invokded if
vtune support is enabled.

Review URL: https://codereview.chromium.org/11574031
Patch from Chunyang Dai <chunyang.dai@intel.com>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14253 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5206b084
...@@ -83,6 +83,10 @@ endif ...@@ -83,6 +83,10 @@ endif
ifeq ($(gdbjit), on) ifeq ($(gdbjit), on)
GYPFLAGS += -Dv8_enable_gdbjit=1 GYPFLAGS += -Dv8_enable_gdbjit=1
endif endif
# vtunejit=on
ifeq ($(vtunejit), on)
GYPFLAGS += -Dv8_enable_vtunejit=1
endif
# vfp2=off # vfp2=off
ifeq ($(vfp2), off) ifeq ($(vfp2), off)
GYPFLAGS += -Dv8_can_use_vfp2_instructions=false GYPFLAGS += -Dv8_can_use_vfp2_instructions=false
...@@ -155,6 +159,10 @@ GYPFILES = build/all.gyp build/common.gypi build/standalone.gypi \ ...@@ -155,6 +159,10 @@ GYPFILES = build/all.gyp build/common.gypi build/standalone.gypi \
preparser/preparser.gyp samples/samples.gyp src/d8.gyp \ preparser/preparser.gyp samples/samples.gyp src/d8.gyp \
test/cctest/cctest.gyp tools/gyp/v8.gyp test/cctest/cctest.gyp tools/gyp/v8.gyp
# If vtunejit=on, the v8vtune.gyp will be appended.
ifeq ($(vtunejit), on)
GYPFILES += src/third_party/vtune/v8vtune.gyp
endif
# Generates all combinations of ARCHES and MODES, e.g. "ia32.release". # Generates all combinations of ARCHES and MODES, e.g. "ia32.release".
BUILDS = $(foreach mode,$(MODES),$(addsuffix .$(mode),$(ARCHES))) BUILDS = $(foreach mode,$(MODES),$(addsuffix .$(mode),$(ARCHES)))
ANDROID_BUILDS = $(foreach mode,$(MODES), \ ANDROID_BUILDS = $(foreach mode,$(MODES), \
......
...@@ -788,6 +788,17 @@ class V8EXPORT Script { ...@@ -788,6 +788,17 @@ class V8EXPORT Script {
* debugger API. * debugger API.
*/ */
void SetData(Handle<String> data); void SetData(Handle<String> data);
/**
* Returns the name value of one Script.
*/
Handle<Value> GetScriptName();
/**
* Returns zero based line number of the code_pos location in the script.
* -1 will be returned if no information available.
*/
int GetLineNumber(int code_pos);
}; };
......
...@@ -1852,6 +1852,34 @@ Local<Value> Script::Id() { ...@@ -1852,6 +1852,34 @@ Local<Value> Script::Id() {
} }
int Script::GetLineNumber(int code_pos) {
i::Isolate* isolate = i::Isolate::Current();
ON_BAILOUT(isolate, "v8::Script::GetLineNumber()", return -1);
LOG_API(isolate, "Script::GetLineNumber");
i::Handle<i::Object> obj = Utils::OpenHandle(this);
if (obj->IsScript()) {
i::Handle<i::Script> script = i::Handle<i::Script>(i::Script::cast(*obj));
return i::GetScriptLineNumber(script, code_pos);
} else {
return -1;
}
}
Handle<Value> Script::GetScriptName() {
i::Isolate* isolate = i::Isolate::Current();
ON_BAILOUT(isolate, "v8::Script::GetName()", return Handle<String>());
LOG_API(isolate, "Script::GetName");
i::Handle<i::Object> obj = Utils::OpenHandle(this);
if (obj->IsScript()) {
i::Object* name = i::Script::cast(*obj)->name();
return Utils::ToLocal(i::Handle<i::Object>(name, isolate));
} else {
return Handle<String>();
}
}
void Script::SetData(v8::Handle<String> data) { void Script::SetData(v8::Handle<String> data) {
i::Isolate* isolate = i::Isolate::Current(); i::Isolate* isolate = i::Isolate::Current();
ON_BAILOUT(isolate, "v8::Script::SetData()", return); ON_BAILOUT(isolate, "v8::Script::SetData()", return);
......
...@@ -45,6 +45,10 @@ ...@@ -45,6 +45,10 @@
#include "../include/v8-testing.h" #include "../include/v8-testing.h"
#endif // V8_SHARED #endif // V8_SHARED
#ifdef ENABLE_VTUNE_JIT_INTERFACE
#include "third_party/vtune/v8-vtune.h"
#endif
#include "d8.h" #include "d8.h"
#ifndef V8_SHARED #ifndef V8_SHARED
...@@ -1926,6 +1930,9 @@ int Shell::Main(int argc, char* argv[]) { ...@@ -1926,6 +1930,9 @@ int Shell::Main(int argc, char* argv[]) {
DumbLineEditor dumb_line_editor(isolate); DumbLineEditor dumb_line_editor(isolate);
{ {
Initialize(isolate); Initialize(isolate);
#ifdef ENABLE_VTUNE_JIT_INTERFACE
vTune::InitilizeVtuneForV8();
#endif
Symbols symbols(isolate); Symbols symbols(isolate);
InitializeDebugger(isolate); InitializeDebugger(isolate);
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
'includes': ['../build/common.gypi'], 'includes': ['../build/common.gypi'],
'variables': { 'variables': {
'console%': '', 'console%': '',
# Enable support for Intel VTune. Supported on ia32/x64 only
'v8_enable_vtunejit%': 0,
}, },
'targets': [ 'targets': [
{ {
...@@ -70,6 +72,11 @@ ...@@ -70,6 +72,11 @@
}], }],
], ],
}], }],
['v8_enable_vtunejit==1', {
'dependencies': [
'../src/third_party/vtune/v8vtune.gyp:v8_vtune',
],
}],
], ],
}, },
{ {
......
This diff is collapsed.
/*
This file is provided under a dual BSD/GPLv2 license. When using or
redistributing this file, you may do so under either license.
GPL LICENSE SUMMARY
Copyright(c) 2005-2012 Intel Corporation. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
The full GNU General Public License is included in this distribution
in the file called LICENSE.GPL.
Contact Information:
http://software.intel.com/en-us/articles/intel-vtune-amplifier-xe/
BSD LICENSE
Copyright(c) 2005-2012 Intel Corporation. All rights reserved.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Intel Corporation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _ITTNOTIFY_TYPES_H_
#define _ITTNOTIFY_TYPES_H_
typedef enum ___itt_group_id
{
__itt_group_none = 0,
__itt_group_legacy = 1<<0,
__itt_group_control = 1<<1,
__itt_group_thread = 1<<2,
__itt_group_mark = 1<<3,
__itt_group_sync = 1<<4,
__itt_group_fsync = 1<<5,
__itt_group_jit = 1<<6,
__itt_group_model = 1<<7,
__itt_group_splitter_min = 1<<7,
__itt_group_counter = 1<<8,
__itt_group_frame = 1<<9,
__itt_group_stitch = 1<<10,
__itt_group_heap = 1<<11,
__itt_group_splitter_max = 1<<12,
__itt_group_structure = 1<<12,
__itt_group_suppress = 1<<13,
__itt_group_all = -1
} __itt_group_id;
#pragma pack(push, 8)
typedef struct ___itt_group_list
{
__itt_group_id id;
const char* name;
} __itt_group_list;
#pragma pack(pop)
#define ITT_GROUP_LIST(varname) \
static __itt_group_list varname[] = { \
{ __itt_group_all, "all" }, \
{ __itt_group_control, "control" }, \
{ __itt_group_thread, "thread" }, \
{ __itt_group_mark, "mark" }, \
{ __itt_group_sync, "sync" }, \
{ __itt_group_fsync, "fsync" }, \
{ __itt_group_jit, "jit" }, \
{ __itt_group_model, "model" }, \
{ __itt_group_counter, "counter" }, \
{ __itt_group_frame, "frame" }, \
{ __itt_group_stitch, "stitch" }, \
{ __itt_group_heap, "heap" }, \
{ __itt_group_structure, "structure" }, \
{ __itt_group_suppress, "suppress" }, \
{ __itt_group_none, NULL } \
}
#endif /* _ITTNOTIFY_TYPES_H_ */
This diff is collapsed.
/*
This file is provided under a dual BSD/GPLv2 license. When using or
redistributing this file, you may do so under either license.
GPL LICENSE SUMMARY
Copyright (c) 2005-2012 Intel Corporation. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
The full GNU General Public License is included in this distribution
in the file called LICENSE.GPL.
Contact Information:
http://software.intel.com/en-us/articles/intel-vtune-amplifier-xe/
BSD LICENSE
Copyright (c) 2005-2012 Intel Corporation. All rights reserved.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Intel Corporation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __JITPROFILING_H__
#define __JITPROFILING_H__
/*
* Various constants used by functions
*/
/* event notification */
typedef enum iJIT_jvm_event
{
/* shutdown */
/*
* Program exiting EventSpecificData NA
*/
iJVM_EVENT_TYPE_SHUTDOWN = 2,
/* JIT profiling */
/*
* issued after method code jitted into memory but before code is executed
* EventSpecificData is an iJIT_Method_Load
*/
iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED=13,
/* issued before unload. Method code will no longer be executed, but code
* and info are still in memory. The VTune profiler may capture method
* code only at this point EventSpecificData is iJIT_Method_Id
*/
iJVM_EVENT_TYPE_METHOD_UNLOAD_START,
/* Method Profiling */
/* method name, Id and stack is supplied
* issued when a method is about to be entered EventSpecificData is
* iJIT_Method_NIDS
*/
iJVM_EVENT_TYPE_ENTER_NIDS = 19,
/* method name, Id and stack is supplied
* issued when a method is about to be left EventSpecificData is
* iJIT_Method_NIDS
*/
iJVM_EVENT_TYPE_LEAVE_NIDS
} iJIT_JVM_EVENT;
typedef enum _iJIT_ModeFlags
{
/* No need to Notify VTune, since VTune is not running */
iJIT_NO_NOTIFICATIONS = 0x0000,
/* when turned on the jit must call
* iJIT_NotifyEvent
* (
* iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED,
* )
* for all the method already jitted
*/
iJIT_BE_NOTIFY_ON_LOAD = 0x0001,
/* when turned on the jit must call
* iJIT_NotifyEvent
* (
* iJVM_EVENT_TYPE_METHOD_UNLOAD_FINISHED,
* ) for all the method that are unloaded
*/
iJIT_BE_NOTIFY_ON_UNLOAD = 0x0002,
/* when turned on the jit must instrument all
* the currently jited code with calls on
* method entries
*/
iJIT_BE_NOTIFY_ON_METHOD_ENTRY = 0x0004,
/* when turned on the jit must instrument all
* the currently jited code with calls
* on method exit
*/
iJIT_BE_NOTIFY_ON_METHOD_EXIT = 0x0008
} iJIT_ModeFlags;
/* Flags used by iJIT_IsProfilingActive() */
typedef enum _iJIT_IsProfilingActiveFlags
{
/* No profiler is running. Currently not used */
iJIT_NOTHING_RUNNING = 0x0000,
/* Sampling is running. This is the default value
* returned by iJIT_IsProfilingActive()
*/
iJIT_SAMPLING_ON = 0x0001,
/* Call Graph is running */
iJIT_CALLGRAPH_ON = 0x0002
} iJIT_IsProfilingActiveFlags;
/* Enumerator for the environment of methods*/
typedef enum _iJDEnvironmentType
{
iJDE_JittingAPI = 2
} iJDEnvironmentType;
/**********************************
* Data structures for the events *
**********************************/
/* structure for the events:
* iJVM_EVENT_TYPE_METHOD_UNLOAD_START
*/
typedef struct _iJIT_Method_Id
{
/* Id of the method (same as the one passed in
* the iJIT_Method_Load struct
*/
unsigned int method_id;
} *piJIT_Method_Id, iJIT_Method_Id;
/* structure for the events:
* iJVM_EVENT_TYPE_ENTER_NIDS,
* iJVM_EVENT_TYPE_LEAVE_NIDS,
* iJVM_EVENT_TYPE_EXCEPTION_OCCURRED_NIDS
*/
typedef struct _iJIT_Method_NIDS
{
/* unique method ID */
unsigned int method_id;
/* NOTE: no need to fill this field, it's filled by VTune */
unsigned int stack_id;
/* method name (just the method, without the class) */
char* method_name;
} *piJIT_Method_NIDS, iJIT_Method_NIDS;
/* structures for the events:
* iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED
*/
typedef struct _LineNumberInfo
{
/* x86 Offset from the begining of the method*/
unsigned int Offset;
/* source line number from the begining of the source file */
unsigned int LineNumber;
} *pLineNumberInfo, LineNumberInfo;
typedef struct _iJIT_Method_Load
{
/* unique method ID - can be any unique value, (except 0 - 999) */
unsigned int method_id;
/* method name (can be with or without the class and signature, in any case
* the class name will be added to it)
*/
char* method_name;
/* virtual address of that method - This determines the method range for the
* iJVM_EVENT_TYPE_ENTER/LEAVE_METHOD_ADDR events
*/
void* method_load_address;
/* Size in memory - Must be exact */
unsigned int method_size;
/* Line Table size in number of entries - Zero if none */
unsigned int line_number_size;
/* Pointer to the begining of the line numbers info array */
pLineNumberInfo line_number_table;
/* unique class ID */
unsigned int class_id;
/* class file name */
char* class_file_name;
/* source file name */
char* source_file_name;
/* bits supplied by the user for saving in the JIT file */
void* user_data;
/* the size of the user data buffer */
unsigned int user_data_size;
/* NOTE: no need to fill this field, it's filled by VTune */
iJDEnvironmentType env;
} *piJIT_Method_Load, iJIT_Method_Load;
/* API Functions */
#ifdef __cplusplus
extern "C" {
#endif
#ifndef CDECL
# if defined WIN32 || defined _WIN32
# define CDECL __cdecl
# else /* defined WIN32 || defined _WIN32 */
# if defined _M_X64 || defined _M_AMD64 || defined __x86_64__
# define CDECL /* not actual on x86_64 platform */
# else /* _M_X64 || _M_AMD64 || __x86_64__ */
# define CDECL __attribute__ ((cdecl))
# endif /* _M_X64 || _M_AMD64 || __x86_64__ */
# endif /* defined WIN32 || defined _WIN32 */
#endif /* CDECL */
#define JITAPI CDECL
/* called when the settings are changed with new settings */
typedef void (*iJIT_ModeChangedEx)(void *UserData, iJIT_ModeFlags Flags);
int JITAPI iJIT_NotifyEvent(iJIT_JVM_EVENT event_type, void *EventSpecificData);
/* The new mode call back routine */
void JITAPI iJIT_RegisterCallbackEx(void *userdata,
iJIT_ModeChangedEx NewModeCallBackFuncEx);
iJIT_IsProfilingActiveFlags JITAPI iJIT_IsProfilingActive(void);
void JITAPI FinalizeThread(void);
void JITAPI FinalizeProcess(void);
unsigned int JITAPI iJIT_GetNewMethodID(void);
#ifdef __cplusplus
}
#endif
#endif /* __JITPROFILING_H__ */
/*
This file is provided under a dual BSD/GPLv2 license. When using or
redistributing this file, you may do so under either license.
GPL LICENSE SUMMARY
Copyright(c) 2005-2012 Intel Corporation. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
The full GNU General Public License is included in this distribution
in the file called LICENSE.GPL.
Contact Information:
http://software.intel.com/en-us/articles/intel-vtune-amplifier-xe/
BSD LICENSE
Copyright(c) 2005-2012 Intel Corporation. All rights reserved.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Intel Corporation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef V8_VTUNE_H_
#define V8_VTUNE_H_
namespace vTune {
void InitilizeVtuneForV8();
} // namespace vTune
#endif // V8_VTUNE_H_
# Copyright 2012 the V8 project authors. All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
{
'includes': ['../../../build/common.gypi'],
'targets': [
{
'target_name': 'v8_vtune',
'type': 'static_library',
'dependencies': [
'../../../tools/gyp/v8.gyp:v8',
],
'sources': [
'ittnotify_config.h',
'ittnotify_types.h',
'jitprofiling.cc',
'jitprofiling.h',
'v8-vtune.h',
'vtune-jit.cc',
'vtune-jit.h',
],
'direct_dependent_settings': {
'defines': ['ENABLE_VTUNE_JIT_INTERFACE',],
'conditions': [
['OS != "win"', {
'libraries': ['-ldl',],
}],
],
},
},
],
}
/*
This file is provided under a dual BSD/GPLv2 license. When using or
redistributing this file, you may do so under either license.
GPL LICENSE SUMMARY
Copyright(c) 2005-2012 Intel Corporation. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
The full GNU General Public License is included in this distribution
in the file called LICENSE.GPL.
Contact Information:
http://software.intel.com/en-us/articles/intel-vtune-amplifier-xe/
BSD LICENSE
Copyright(c) 2005-2012 Intel Corporation. All rights reserved.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Intel Corporation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#ifdef WIN32
#include <hash_map>
using namespace std;
#else
// To avoid GCC 4.4 compilation warning about hash_map being deprecated.
#define OLD_DEPRECATED __DEPRECATED
#undef __DEPRECATED
#include <ext/hash_map>
#define __DEPRECATED OLD_DEPRECATED
using namespace __gnu_cxx;
#endif
#include <list>
#include "v8-vtune.h"
#include "vtune-jit.h"
namespace vTune {
namespace internal {
// This class is used to record the JITted code position info for JIT
// code profiling.
class JITCodeLineInfo {
public:
JITCodeLineInfo() { }
void SetPosition(intptr_t pc, int pos) {
AddCodeLineInfo(LineNumInfo(pc, pos));
}
struct LineNumInfo {
LineNumInfo(intptr_t pc, int pos)
: pc_(pc), pos_(pos) { }
intptr_t pc_;
int pos_;
};
std::list<LineNumInfo>* GetLineNumInfo() {
return &line_num_info_;
}
private:
void AddCodeLineInfo(const LineNumInfo& line_info) {
line_num_info_.push_back(line_info);
}
std::list<LineNumInfo> line_num_info_;
};
struct SameCodeObjects {
bool operator () (void* key1, void* key2) const {
return key1 == key2;
}
};
struct HashForCodeObject {
uint32_t operator () (void* code) const {
static const uintptr_t kGoldenRatio = 2654435761u;
uintptr_t hash = reinterpret_cast<uintptr_t>(code);
return static_cast<uint32_t>(hash * kGoldenRatio);
}
};
#ifdef WIN32
typedef hash_map<void*, void*> JitInfoMap;
#else
typedef hash_map<void*, void*, HashForCodeObject, SameCodeObjects> JitInfoMap;
#endif
static JitInfoMap* GetEntries() {
static JitInfoMap* entries;
if (entries == NULL) {
entries = new JitInfoMap();
}
return entries;
}
static bool IsLineInfoTagged(void* ptr) {
return 0 != (reinterpret_cast<intptr_t>(ptr));
}
static JITCodeLineInfo* UntagLineInfo(void* ptr) {
return reinterpret_cast<JITCodeLineInfo*>(
reinterpret_cast<intptr_t>(ptr));
}
// The parameter str is a mixed pattern which contains the
// function name and some other info. It comes from all the
// Logger::CodeCreateEvent(...) function. This funtion get the
// pure function name from the input parameter.
static char* GetFunctionNameFromMixedName(const char* str, int length) {
int index = 0;
int count = 0;
char* start_ptr = NULL;
while (str[index++] != ':' && (index < length)) {}
if (str[index] == '*' || str[index] == '~' ) index++;
if (index >= length) return NULL;
start_ptr = const_cast<char*>(str + index);
while (index < length && str[index++] != ' ') {
count++;
}
char* result = new char[count + 1];
memcpy(result, start_ptr, count);
result[count] = '\0';
return result;
}
// The JitCodeEventHandler for Vtune.
void VTUNEJITInterface::event_handler(const v8::JitCodeEvent* event) {
if (VTUNERUNNING && event != NULL) {
switch (event->type) {
case v8::JitCodeEvent::CODE_ADDED: {
char* temp_file_name = NULL;
char* temp_method_name =
GetFunctionNameFromMixedName(event->name.str,
static_cast<int>(event->name.len));
iJIT_Method_Load jmethod;
memset(&jmethod, 0, sizeof jmethod);
jmethod.method_id = iJIT_GetNewMethodID();
jmethod.method_load_address = event->code_start;
jmethod.method_size = static_cast<unsigned int>(event->code_len);
jmethod.method_name = temp_method_name;
Handle<Script> script = event->script;
if (*script != NULL) {
// Get the source file name and set it to jmethod.source_file_name
if ((*script->GetScriptName())->IsString()) {
Handle<String> script_name =
Handle<String>(String::Cast(*script->GetScriptName()));
temp_file_name = new char[script_name->Length() + 1];
script_name->WriteAscii(temp_file_name);
jmethod.source_file_name = temp_file_name;
}
JitInfoMap::iterator entry =
GetEntries()->find(event->code_start);
if (entry != GetEntries()->end() && IsLineInfoTagged(entry->first)) {
JITCodeLineInfo* line_info = UntagLineInfo(entry->second);
// Get the line_num_info and set it to jmethod.line_number_table
std::list<JITCodeLineInfo::LineNumInfo>* vtunelineinfo =
line_info->GetLineNumInfo();
jmethod.line_number_size = (unsigned int)vtunelineinfo->size();
jmethod.line_number_table =
reinterpret_cast<LineNumberInfo*>(
malloc(sizeof(LineNumberInfo)*jmethod.line_number_size));
std::list<JITCodeLineInfo::LineNumInfo>::iterator Iter;
int index = 0;
for (Iter = vtunelineinfo->begin();
Iter != vtunelineinfo->end();
Iter++) {
jmethod.line_number_table[index].Offset =
static_cast<unsigned int>(Iter->pc_);
jmethod.line_number_table[index++].LineNumber =
script->GetLineNumber(Iter->pos_)+1;
}
GetEntries()->erase(event->code_start);
}
}
iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED,
reinterpret_cast<void*>(&jmethod));
if (temp_method_name)
delete []temp_method_name;
if (temp_file_name)
delete []temp_file_name;
break;
}
// TODO(chunyang.dai@intel.com): code_move will be supported.
case v8::JitCodeEvent::CODE_MOVED:
break;
// Currently the CODE_REMOVED event is not issued.
case v8::JitCodeEvent::CODE_REMOVED:
break;
case v8::JitCodeEvent::CODE_ADD_LINE_POS_INFO: {
JITCodeLineInfo* line_info =
reinterpret_cast<JITCodeLineInfo*>(event->user_data);
if (line_info != NULL) {
line_info->SetPosition(static_cast<intptr_t>(event->line_info.offset),
static_cast<int>(event->line_info.pos));
}
break;
}
case v8::JitCodeEvent::CODE_START_LINE_INFO_RECORDING: {
v8::JitCodeEvent* temp_event = const_cast<v8::JitCodeEvent*>(event);
temp_event->user_data = new JITCodeLineInfo();
break;
}
case v8::JitCodeEvent::CODE_END_LINE_INFO_RECORDING: {
GetEntries()->insert(std::pair <void*, void*>(event->code_start, event->user_data));
break;
}
default:
break;
}
}
return;
}
} // namespace internal
void InitilizeVtuneForV8() {
if (v8::V8::Initialize()) {
v8::V8::SetFlagsFromString("--nocompact_code_space",
(int)strlen("--nocompact_code_space"));
v8::V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault,
vTune::internal::VTUNEJITInterface::event_handler);
}
}
} // namespace vTune
/*
This file is provided under a dual BSD/GPLv2 license. When using or
redistributing this file, you may do so under either license.
GPL LICENSE SUMMARY
Copyright(c) 2005-2012 Intel Corporation. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
The full GNU General Public License is included in this distribution
in the file called LICENSE.GPL.
Contact Information:
http://software.intel.com/en-us/articles/intel-vtune-amplifier-xe/
BSD LICENSE
Copyright(c) 2005-2012 Intel Corporation. All rights reserved.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Intel Corporation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef VTUNE_VTUNE_JIT_H_
#define VTUNE_VTUNE_JIT_H_
#include "jitprofiling.h"
#include "../../../include/v8.h"
#define VTUNERUNNING (iJIT_IsProfilingActive() == iJIT_SAMPLING_ON)
namespace vTune {
namespace internal {
using namespace v8;
class VTUNEJITInterface {
public:
static void event_handler(const v8::JitCodeEvent* event);
private:
//static Mutex* vtunemutex_;
};
} } // namespace vTune::internal
#endif // VTUNE_VTUNE_JIT_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment