| Index: src/code-events.cc
|
| diff --git a/src/code-events.cc b/src/code-events.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d5bc7d76ebe492e2d43091fb022f089f22c6e0b0
|
| --- /dev/null
|
| +++ b/src/code-events.cc
|
| @@ -0,0 +1,124 @@
|
| +// 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.
|
| +
|
| +#include "v8.h"
|
| +
|
| +#include "code-events.h"
|
| +
|
| +namespace v8 {
|
| +namespace internal {
|
| +
|
| +static const char* CodeKindToString(Code::Kind kind) {
|
| + switch (kind) {
|
| +#define DEF_CASE(name) case Code::name: return #name;
|
| + CODE_KIND_LIST(DEF_CASE)
|
| +#undef DEF_CASE
|
| + default:
|
| + return "*UNKNOWN*";
|
| + }
|
| +}
|
| +
|
| +JitCodeEventHandler CodeEvents::event_handler_ = NULL;
|
| +
|
| +
|
| +void CodeEvents::AddCode(const char* name,
|
| + Code* code,
|
| + Script* script,
|
| + CompilationInfo* info) {
|
| + JitCodeEvent event = { JitCodeEvent::CODE_ADDED,
|
| + code->instruction_start(),
|
| + code->instruction_size() };
|
| + event.name = name;
|
| + event_handler_(&event);
|
| +}
|
| +
|
| +
|
| +void CodeEvents::AddCode(Handle<String> name,
|
| + Handle<Script> script,
|
| + Handle<Code> code,
|
| + CompilationInfo* info) {
|
| + if (!name.is_null()) {
|
| + SmartArrayPointer<char> name_cstring = name->ToCString(DISALLOW_NULLS);
|
| + AddCode(*name_cstring, *code, *script, info);
|
| + } else {
|
| + AddCode("", *code, *script, info);
|
| + }
|
| +}
|
| +
|
| +
|
| +void CodeEvents::AddCode(String* name, Code* code) {
|
| + AddCode(name != NULL ? *name->ToCString(DISALLOW_NULLS) : NULL, code);
|
| +}
|
| +
|
| +
|
| +void CodeEvents::AddCode(const char* name, Code* code) {
|
| + EmbeddedVector<char, 256> buffer;
|
| + StringBuilder builder(buffer.start(), buffer.length());
|
| +
|
| + builder.AddString(CodeKindToString(code->kind()));
|
| + if ((name != NULL) && (*name != '\0')) {
|
| + builder.AddString(": ");
|
| + builder.AddString(name);
|
| + } else {
|
| + builder.AddFormatted(": code object %p", static_cast<void*>(code));
|
| + }
|
| +
|
| + AddCode(builder.Finalize(), code, NULL, NULL);
|
| +}
|
| +
|
| +
|
| +void CodeEvents::AddCode(Code* code) {
|
| + AddCode("", code);
|
| +}
|
| +
|
| +void CodeEvents::MoveCode(Address src, Address dst) {
|
| + Code* src_code = Code::cast(HeapObject::FromAddress(src));
|
| +
|
| + JitCodeEvent event = { JitCodeEvent::CODE_MOVED,
|
| + src_code->instruction_start(),
|
| + src_code->instruction_size() };
|
| +
|
| + // Calculate the header size.
|
| + const size_t header_size =
|
| + src_code->instruction_start() - reinterpret_cast<byte*>(src_code);
|
| +
|
| + event.new_code_start = dst + header_size;
|
| +
|
| + event_handler_(&event);
|
| +}
|
| +
|
| +
|
| +void CodeEvents::RemoveCode(Code* code) {
|
| + JitCodeEvent event = { JitCodeEvent::CODE_REMOVED,
|
| + code->instruction_start(),
|
| + code->instruction_size() };
|
| +
|
| + event_handler_(&event);
|
| +}
|
| +
|
| +
|
| +} } // namespace v8::internal
|
|
|