Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | |
| 2 // Redistribution and use in source and binary forms, with or without | |
| 3 // modification, are permitted provided that the following conditions are | |
| 4 // met: | |
| 5 // | |
| 6 // * Redistributions of source code must retain the above copyright | |
| 7 // notice, this list of conditions and the following disclaimer. | |
| 8 // * Redistributions in binary form must reproduce the above | |
| 9 // copyright notice, this list of conditions and the following | |
| 10 // disclaimer in the documentation and/or other materials provided | |
| 11 // with the distribution. | |
| 12 // * Neither the name of Google Inc. nor the names of its | |
| 13 // contributors may be used to endorse or promote products derived | |
| 14 // from this software without specific prior written permission. | |
| 15 // | |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 27 | |
| 28 #include "v8.h" | |
| 29 | |
| 30 #include "code-events.h" | |
| 31 | |
| 32 namespace v8 { | |
| 33 namespace internal { | |
| 34 | |
| 35 static const char* CodeKindToString(Code::Kind kind) { | |
| 36 switch (kind) { | |
| 37 #define DEF_CASE(name) case Code::name: return #name; | |
| 38 CODE_KIND_LIST(DEF_CASE) | |
| 39 #undef DEF_CASE | |
| 40 default: | |
| 41 return "*UNKNOWN*"; | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 JitCodeEventHandler CodeEvents::event_handler_ = NULL; | |
| 46 | |
| 47 | |
| 48 void CodeEvents::AddCode(const char* name, | |
| 49 Code* code, | |
| 50 Script* script, | |
| 51 CompilationInfo* info) { | |
| 52 JitCodeEvent event = { JitCodeEvent::CODE_ADDED, | |
| 53 code->instruction_start(), | |
| 54 code->instruction_size() }; | |
| 55 event.name = name; | |
| 56 event_handler_(&event); | |
| 57 } | |
| 58 | |
| 59 | |
| 60 void CodeEvents::AddCode(Handle<String> name, | |
| 61 Handle<Script> script, | |
| 62 Handle<Code> code, | |
| 63 CompilationInfo* info) { | |
| 64 if (!name.is_null()) { | |
| 65 SmartArrayPointer<char> name_cstring = name->ToCString(DISALLOW_NULLS); | |
| 66 AddCode(*name_cstring, *code, *script, info); | |
| 67 } else { | |
| 68 AddCode("", *code, *script, info); | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 | |
| 73 void CodeEvents::AddCode(String* name, Code* code) { | |
| 74 AddCode(name != NULL ? *name->ToCString(DISALLOW_NULLS) : NULL, code); | |
| 75 } | |
| 76 | |
| 77 | |
| 78 void CodeEvents::AddCode(const char* name, Code* code) { | |
| 79 EmbeddedVector<char, 256> buffer; | |
| 80 StringBuilder builder(buffer.start(), buffer.length()); | |
| 81 | |
| 82 builder.AddString(CodeKindToString(code->kind())); | |
| 83 if ((name != NULL) && (*name != '\0')) { | |
| 84 builder.AddString(": "); | |
| 85 builder.AddString(name); | |
| 86 } else { | |
| 87 builder.AddFormatted(": code object %p", static_cast<void*>(code)); | |
| 88 } | |
| 89 | |
| 90 AddCode(builder.Finalize(), code, NULL, NULL); | |
| 91 } | |
| 92 | |
| 93 | |
| 94 void CodeEvents::AddCode(Code* code) { | |
|
danno
2012/07/25 13:50:42
Can you handle this with default parameters with a
Sigurður Ásgeirsson
2012/07/25 14:38:35
I imagine I can, do you mind if I fold that into a
| |
| 95 AddCode("", code); | |
| 96 } | |
| 97 | |
| 98 void CodeEvents::MoveCode(Address src, Address dst) { | |
| 99 Code* src_code = Code::cast(HeapObject::FromAddress(src)); | |
| 100 | |
| 101 JitCodeEvent event = { JitCodeEvent::CODE_MOVED, | |
| 102 src_code->instruction_start(), | |
| 103 src_code->instruction_size() }; | |
| 104 | |
| 105 // Calculate the header size. | |
| 106 const size_t header_size = | |
| 107 src_code->instruction_start() - reinterpret_cast<byte*>(src_code); | |
| 108 | |
| 109 event.new_code_start = dst + header_size; | |
| 110 | |
| 111 event_handler_(&event); | |
| 112 } | |
| 113 | |
| 114 | |
| 115 void CodeEvents::RemoveCode(Code* code) { | |
| 116 JitCodeEvent event = { JitCodeEvent::CODE_REMOVED, | |
| 117 code->instruction_start(), | |
| 118 code->instruction_size() }; | |
| 119 | |
| 120 event_handler_(&event); | |
| 121 } | |
| 122 | |
| 123 | |
| 124 } } // namespace v8::internal | |
| OLD | NEW |