| Index: src/third_party/vtune/vtune-jit.cc
|
| ===================================================================
|
| --- src/third_party/vtune/vtune-jit.cc (revision 0)
|
| +++ src/third_party/vtune/vtune-jit.cc (revision 0)
|
| @@ -0,0 +1,263 @@
|
| +/*
|
| + 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.
|
| +*/
|
| +#ifdef ENABLE_VTUNE_JIT_INTERFACE
|
| +#include <string.h>
|
| +#include "vtune-jit.h"
|
| +#include "../../factory.h"
|
| +#include "../../global-handles.h"
|
| +
|
| +namespace v8 {
|
| +namespace internal {
|
| +
|
| +Mutex* VTUNEJITInterface::vtunemutex_ = OS::CreateMutex();
|
| +
|
| +static bool SameCodeObjects(void* key1, void* key2) {
|
| + return key1 == key2;
|
| +}
|
| +
|
| +
|
| +static HashMap* GetEntries() {
|
| + static HashMap* entries;
|
| + if (entries == NULL) {
|
| + entries = new HashMap(&SameCodeObjects);
|
| + }
|
| + return entries;
|
| +}
|
| +
|
| +static uint32_t HashForCodeObject(Code* code) {
|
| + static const uintptr_t kGoldenRatio = 2654435761u;
|
| + uintptr_t hash = reinterpret_cast<uintptr_t>(code->address());
|
| + return static_cast<uint32_t>((hash >> kCodeAlignmentBits) * kGoldenRatio);
|
| +}
|
| +
|
| +
|
| +static const intptr_t kLineInfoTag = 0x1;
|
| +
|
| +static bool IsSourceInfoAvailable(Handle<Script> script) {
|
| + return !script.is_null() &&
|
| + script->source()->IsString() &&
|
| + script->HasValidSource() &&
|
| + script->name()->IsString();
|
| +}
|
| +
|
| +static bool IsLineInfoTagged(void* ptr) {
|
| + return 0 != (reinterpret_cast<intptr_t>(ptr));
|
| +}
|
| +
|
| +
|
| +static void* TagLineInfo(VtuneJITLineInfo* ptr) {
|
| + return reinterpret_cast<void*>(reinterpret_cast<intptr_t>(ptr));
|
| +}
|
| +
|
| +
|
| +static VtuneJITLineInfo* UntagLineInfo(void* ptr) {
|
| + return reinterpret_cast<VtuneJITLineInfo*>(
|
| + reinterpret_cast<intptr_t>(ptr));
|
| +}
|
| +
|
| +
|
| +void VTUNEJITInterface::AddCode(const char* methodname,
|
| + Code* code,
|
| + Handle<Script> script) {
|
| + if (VTUNERUNNING) {
|
| + ScopedLock lock(vtunemutex_);
|
| +
|
| + iJIT_Method_Load jmethod;
|
| + memset(&jmethod, 0, sizeof jmethod);
|
| + Handle<String> filename = Handle<String>(String::cast(script->name()));
|
| + SmartArrayPointer<char> filename_cstring = filename->ToCString(
|
| + DISALLOW_NULLS);
|
| +
|
| + jmethod.method_id = iJIT_GetNewMethodID();
|
| + jmethod.method_name = const_cast<char*>(methodname);
|
| + jmethod.source_file_name = *filename_cstring;
|
| + jmethod.method_load_address = code->instruction_start();
|
| + jmethod.method_size = code->instruction_end() - code->instruction_start();
|
| + VTUNEDEBUG(PrintF("Filename: %s MethodName: %s\n",
|
| + *filename_cstring,
|
| + methodname));
|
| +
|
| + // Look for lineinfo
|
| + HashMap::Entry* entry = GetEntries()->Lookup(code,
|
| + HashForCodeObject(code),
|
| + false);
|
| + if (entry == NULL) {
|
| + iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED,
|
| + reinterpret_cast<void*>(&jmethod));
|
| + return;
|
| + }
|
| +
|
| + if (IsLineInfoTagged(entry->value) && IsSourceInfoAvailable(script)) {
|
| + // Init Script Line Ends
|
| + GetScriptLineNumber(script, 0);
|
| + VtuneJITLineInfo *vtunejitlineinfo_ = UntagLineInfo(entry->value);
|
| + List<LineNumberInfo>* vtunelineinfo = vtunejitlineinfo_->vtunelineinfo();
|
| +
|
| + jmethod.line_number_size = vtunelineinfo->length();
|
| + jmethod.line_number_table = reinterpret_cast<LineNumberInfo*>(malloc(
|
| + sizeof(LineNumberInfo)*jmethod.line_number_size));
|
| + // populate the lineinfo for the code. Filter it before
|
| + for (int e = 0; e < vtunelineinfo->length(); e++) {
|
| + LineNumberInfo line_info = vtunelineinfo->at(e);
|
| + jmethod.line_number_table[e].Offset = line_info.Offset;
|
| + jmethod.line_number_table[e].LineNumber = GetScriptLineNumberSafe(
|
| + script,
|
| + line_info.LineNumber)+1;
|
| + }
|
| + delete vtunelineinfo;
|
| + }
|
| + GetEntries()->Remove(code, HashForCodeObject(code));
|
| +
|
| + /* Send method load notification */
|
| + iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED,
|
| + reinterpret_cast<void*>(&jmethod));
|
| + }
|
| +}
|
| +
|
| +void VTUNEJITInterface::AddCode(const char* methodname,
|
| + Code* code) {
|
| + if (VTUNERUNNING) {
|
| + ScopedLock lock(vtunemutex_);
|
| +
|
| + /* Fill method information */
|
| + iJIT_Method_Load jmethod;
|
| + memset(&jmethod, 0, sizeof jmethod);
|
| + jmethod.method_id = iJIT_GetNewMethodID();
|
| + jmethod.method_name = const_cast<char *>(methodname);
|
| + jmethod.method_load_address = code->instruction_start();
|
| + jmethod.method_size = code->instruction_end() - code->instruction_start();
|
| + VTUNEDEBUG(PrintF("Filename: %s MethodName: %s Size: %d\n",
|
| + "jitter", methodname, jmethod.method_size));
|
| +
|
| + /* Send method load notification */
|
| + iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED,
|
| + reinterpret_cast<void*>(&jmethod));
|
| + }
|
| +}
|
| +
|
| +void VTUNEJITInterface::AddCode(const char* methodname,
|
| + Handle<Code> code) {
|
| + if (VTUNERUNNING) {
|
| + ScopedLock lock(vtunemutex_);
|
| +
|
| + /* Fill method information */
|
| + iJIT_Method_Load jmethod;
|
| + memset(&jmethod, 0, sizeof jmethod);
|
| + jmethod.method_id = iJIT_GetNewMethodID();
|
| + jmethod.method_name = const_cast<char *>(methodname);
|
| + jmethod.method_load_address = code->instruction_start();
|
| + jmethod.method_size = code->instruction_end() - code->instruction_start();
|
| + VTUNEDEBUG(PrintF("Filename: %s MethodName: %s\n", "Jitter2", methodname));
|
| +
|
| + /* Send method load notification */
|
| + iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED,
|
| + reinterpret_cast<void*>(&jmethod));
|
| + }
|
| +}
|
| +
|
| +
|
| +void VTUNEJITInterface::AddCode(Handle<String> methodname,
|
| + Handle<Code> code) {
|
| + if (!methodname.is_null()) {
|
| + SmartArrayPointer<char> name_cstring;
|
| + name_cstring = methodname->ToCString(DISALLOW_NULLS);
|
| + AddCode(*name_cstring, *code);
|
| + } else {
|
| + AddCode("", *code);
|
| + }
|
| +}
|
| +
|
| +
|
| +void VTUNEJITInterface::AddCode(Handle<String> methodname,
|
| + Handle<Code> code,
|
| + Handle<Script> script) {
|
| + if (!methodname.is_null()) {
|
| + SmartArrayPointer<char> name_cstring;
|
| + name_cstring = methodname->ToCString(DISALLOW_NULLS);
|
| + AddCode(*name_cstring, *code, script);
|
| + } else {
|
| + AddCode("", *code, script);
|
| + }
|
| +}
|
| +
|
| +void VTUNEJITInterface::AddCode(String *methodname, Code* code) {
|
| + AddCode(methodname != NULL ?
|
| + *methodname->ToCString(DISALLOW_NULLS) : NULL, code);
|
| +}
|
| +
|
| +void VTUNEJITInterface::AddCode(Code* code) {
|
| + const char *unknown_string = "unknown";
|
| + AddCode(unknown_string, code);
|
| +}
|
| +
|
| +void VTUNEJITInterface::AddCode(Handle<Code> code) {
|
| + const char *unknown_string = "unknown";
|
| + AddCode(unknown_string, code);
|
| +}
|
| +
|
| +void VTUNEJITInterface::RegisterDetailedLineInfo(Code* code,
|
| + VtuneJITLineInfo* line_info) {
|
| + ScopedLock lock(vtunemutex_);
|
| + HashMap::Entry* entry = GetEntries()->Lookup(code,
|
| + HashForCodeObject(code),
|
| + true);
|
| + ASSERT(entry->value == NULL);
|
| + entry->value = TagLineInfo(line_info);
|
| +}
|
| +}}
|
| +#endif
|
|
|