kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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-stubs.h" |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 31 | #include "codegen.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 32 | #include "debug.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 33 | #include "deoptimizer.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 34 | #include "disasm.h" |
| 35 | #include "disassembler.h" |
| 36 | #include "macro-assembler.h" |
| 37 | #include "serialize.h" |
| 38 | #include "string-stream.h" |
| 39 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 40 | namespace v8 { |
| 41 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | |
| 43 | #ifdef ENABLE_DISASSEMBLER |
| 44 | |
| 45 | void Disassembler::Dump(FILE* f, byte* begin, byte* end) { |
| 46 | for (byte* pc = begin; pc < end; pc++) { |
| 47 | if (f == NULL) { |
kmillikin@chromium.org | f05f291 | 2010-09-30 10:07:24 +0000 | [diff] [blame] | 48 | PrintF("%" V8PRIxPTR " %4" V8PRIdPTR " %02x\n", |
| 49 | reinterpret_cast<intptr_t>(pc), |
| 50 | pc - begin, |
| 51 | *pc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 52 | } else { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 53 | PrintF(f, "%" V8PRIxPTR " %4" V8PRIdPTR " %02x\n", |
| 54 | reinterpret_cast<uintptr_t>(pc), pc - begin, *pc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | |
| 60 | class V8NameConverter: public disasm::NameConverter { |
| 61 | public: |
| 62 | explicit V8NameConverter(Code* code) : code_(code) {} |
| 63 | virtual const char* NameOfAddress(byte* pc) const; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 64 | virtual const char* NameInCode(byte* addr) const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 65 | Code* code() const { return code_; } |
| 66 | private: |
| 67 | Code* code_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 68 | |
| 69 | EmbeddedVector<char, 128> v8_buffer_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | |
| 73 | const char* V8NameConverter::NameOfAddress(byte* pc) const { |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 74 | const char* name = code_->GetIsolate()->builtins()->Lookup(pc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 75 | if (name != NULL) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 76 | OS::SNPrintF(v8_buffer_, "%s (%p)", name, pc); |
| 77 | return v8_buffer_.start(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | if (code_ != NULL) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 81 | int offs = static_cast<int>(pc - code_->instruction_start()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 82 | // print as code offset, if it seems reasonable |
| 83 | if (0 <= offs && offs < code_->instruction_size()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 84 | OS::SNPrintF(v8_buffer_, "%d (%p)", offs, pc); |
| 85 | return v8_buffer_.start(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
| 89 | return disasm::NameConverter::NameOfAddress(pc); |
| 90 | } |
| 91 | |
| 92 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 93 | const char* V8NameConverter::NameInCode(byte* addr) const { |
| 94 | // The V8NameConverter is used for well known code, so we can "safely" |
| 95 | // dereference pointers in generated code. |
| 96 | return (code_ != NULL) ? reinterpret_cast<const char*>(addr) : ""; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 97 | } |
| 98 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 99 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 100 | static void DumpBuffer(FILE* f, StringBuilder* out) { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 101 | if (f == NULL) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 102 | PrintF("%s\n", out->Finalize()); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 103 | } else { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 104 | PrintF(f, "%s\n", out->Finalize()); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 105 | } |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 106 | out->Reset(); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 107 | } |
| 108 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 109 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 110 | static const int kOutBufferSize = 2048 + String::kMaxShortPrintLength; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 111 | static const int kRelocInfoPosition = 57; |
| 112 | |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 113 | static int DecodeIt(Isolate* isolate, |
| 114 | FILE* f, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 115 | const V8NameConverter& converter, |
| 116 | byte* begin, |
| 117 | byte* end) { |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 118 | SealHandleScope shs(isolate); |
| 119 | DisallowHeapAllocation no_alloc; |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 120 | ExternalReferenceEncoder ref_encoder(isolate); |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 121 | Heap* heap = isolate->heap(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 122 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 123 | v8::internal::EmbeddedVector<char, 128> decode_buffer; |
| 124 | v8::internal::EmbeddedVector<char, kOutBufferSize> out_buffer; |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 125 | StringBuilder out(out_buffer.start(), out_buffer.length()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 126 | byte* pc = begin; |
| 127 | disasm::Disassembler d(converter); |
| 128 | RelocIterator* it = NULL; |
| 129 | if (converter.code() != NULL) { |
| 130 | it = new RelocIterator(converter.code()); |
| 131 | } else { |
| 132 | // No relocation information when printing code stubs. |
| 133 | } |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 134 | int constants = -1; // no constants being decoded at the start |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 135 | |
| 136 | while (pc < end) { |
| 137 | // First decode instruction so that we know its length. |
| 138 | byte* prev_pc = pc; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 139 | if (constants > 0) { |
| 140 | OS::SNPrintF(decode_buffer, |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 141 | "%08x constant", |
| 142 | *reinterpret_cast<int32_t*>(pc)); |
| 143 | constants--; |
| 144 | pc += 4; |
| 145 | } else { |
| 146 | int num_const = d.ConstantPoolSizeAt(pc); |
| 147 | if (num_const >= 0) { |
| 148 | OS::SNPrintF(decode_buffer, |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 149 | "%08x constant pool begin", |
| 150 | *reinterpret_cast<int32_t*>(pc)); |
| 151 | constants = num_const; |
| 152 | pc += 4; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 153 | } else if (it != NULL && !it->done() && it->rinfo()->pc() == pc && |
| 154 | it->rinfo()->rmode() == RelocInfo::INTERNAL_REFERENCE) { |
| 155 | // raw pointer embedded in code stream, e.g., jump table |
| 156 | byte* ptr = *reinterpret_cast<byte**>(pc); |
| 157 | OS::SNPrintF(decode_buffer, |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 158 | "%08" V8PRIxPTR " jump table entry %4" V8PRIdPTR, |
| 159 | ptr, |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 160 | ptr - begin); |
| 161 | pc += 4; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 162 | } else { |
| 163 | decode_buffer[0] = '\0'; |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 164 | pc += d.InstructionDecode(decode_buffer, pc); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 165 | } |
| 166 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 167 | |
| 168 | // Collect RelocInfo for this instruction (prev_pc .. pc-1) |
| 169 | List<const char*> comments(4); |
| 170 | List<byte*> pcs(1); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 171 | List<RelocInfo::Mode> rmodes(1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 172 | List<intptr_t> datas(1); |
| 173 | if (it != NULL) { |
| 174 | while (!it->done() && it->rinfo()->pc() < pc) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 175 | if (RelocInfo::IsComment(it->rinfo()->rmode())) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 176 | // For comments just collect the text. |
| 177 | comments.Add(reinterpret_cast<const char*>(it->rinfo()->data())); |
| 178 | } else { |
| 179 | // For other reloc info collect all data. |
| 180 | pcs.Add(it->rinfo()->pc()); |
| 181 | rmodes.Add(it->rinfo()->rmode()); |
| 182 | datas.Add(it->rinfo()->data()); |
| 183 | } |
| 184 | it->next(); |
| 185 | } |
| 186 | } |
| 187 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 188 | // Comments. |
| 189 | for (int i = 0; i < comments.length(); i++) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 190 | out.AddFormatted(" %s", comments[i]); |
| 191 | DumpBuffer(f, &out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 192 | } |
| 193 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 194 | // Instruction address and instruction offset. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 195 | out.AddFormatted("%p %4d ", prev_pc, prev_pc - begin); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 196 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 197 | // Instruction. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 198 | out.AddFormatted("%s", decode_buffer.start()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 199 | |
| 200 | // Print all the reloc info for this instruction which are not comments. |
| 201 | for (int i = 0; i < pcs.length(); i++) { |
| 202 | // Put together the reloc info |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 203 | RelocInfo relocinfo(pcs[i], rmodes[i], datas[i], NULL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 204 | |
| 205 | // Indent the printing of the reloc info. |
| 206 | if (i == 0) { |
| 207 | // The first reloc info is printed after the disassembled instruction. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 208 | out.AddPadding(' ', kRelocInfoPosition - out.position()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 209 | } else { |
| 210 | // Additional reloc infos are printed on separate lines. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 211 | DumpBuffer(f, &out); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 212 | out.AddPadding(' ', kRelocInfoPosition); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 213 | } |
| 214 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 215 | RelocInfo::Mode rmode = relocinfo.rmode(); |
| 216 | if (RelocInfo::IsPosition(rmode)) { |
| 217 | if (RelocInfo::IsStatementPosition(rmode)) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 218 | out.AddFormatted(" ;; debug: statement %d", relocinfo.data()); |
| 219 | } else { |
| 220 | out.AddFormatted(" ;; debug: position %d", relocinfo.data()); |
| 221 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 222 | } else if (rmode == RelocInfo::EMBEDDED_OBJECT) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 223 | HeapStringAllocator allocator; |
| 224 | StringStream accumulator(&allocator); |
| 225 | relocinfo.target_object()->ShortPrint(&accumulator); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 226 | SmartArrayPointer<const char> obj_name = accumulator.ToCString(); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 227 | out.AddFormatted(" ;; object: %s", *obj_name); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 228 | } else if (rmode == RelocInfo::EXTERNAL_REFERENCE) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 229 | const char* reference_name = |
| 230 | ref_encoder.NameOfAddress(*relocinfo.target_reference_address()); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 231 | out.AddFormatted(" ;; external reference (%s)", reference_name); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 232 | } else if (RelocInfo::IsCodeTarget(rmode)) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 233 | out.AddFormatted(" ;; code:"); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 234 | if (rmode == RelocInfo::CONSTRUCT_CALL) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 235 | out.AddFormatted(" constructor,"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 236 | } |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 237 | Code* code = Code::GetCodeFromTargetAddress(relocinfo.target_address()); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 238 | Code::Kind kind = code->kind(); |
| 239 | if (code->is_inline_cache_stub()) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 240 | if (rmode == RelocInfo::CODE_TARGET_CONTEXT) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 241 | out.AddFormatted(" contextual,"); |
| 242 | } |
| 243 | InlineCacheState ic_state = code->ic_state(); |
| 244 | out.AddFormatted(" %s, %s", Code::Kind2String(kind), |
| 245 | Code::ICState2String(ic_state)); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 246 | if (ic_state == MONOMORPHIC) { |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 247 | Code::StubType type = code->type(); |
| 248 | out.AddFormatted(", %s", Code::StubType2String(type)); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 249 | } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 250 | if (kind == Code::CALL_IC || kind == Code::KEYED_CALL_IC) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 251 | out.AddFormatted(", argc = %d", code->arguments_count()); |
| 252 | } |
jkummerow@chromium.org | 32aa03c | 2013-10-01 08:21:50 +0000 | [diff] [blame] | 253 | } else if (kind == Code::STUB || kind == Code::HANDLER) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 254 | // Reverse lookup required as the minor key cannot be retrieved |
| 255 | // from the code object. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 256 | Object* obj = heap->code_stubs()->SlowReverseLookup(code); |
| 257 | if (obj != heap->undefined_value()) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 258 | ASSERT(obj->IsSmi()); |
| 259 | // Get the STUB key and extract major and minor key. |
| 260 | uint32_t key = Smi::cast(obj)->value(); |
| 261 | uint32_t minor_key = CodeStub::MinorKeyFromKey(key); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 262 | CodeStub::Major major_key = CodeStub::GetMajorKey(code); |
| 263 | ASSERT(major_key == CodeStub::MajorKeyFromKey(key)); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 264 | out.AddFormatted(" %s, %s, ", |
| 265 | Code::Kind2String(kind), |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 266 | CodeStub::MajorName(major_key, false)); |
| 267 | switch (major_key) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 268 | case CodeStub::CallFunction: { |
| 269 | int argc = |
| 270 | CallFunctionStub::ExtractArgcFromMinorKey(minor_key); |
| 271 | out.AddFormatted("argc = %d", argc); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 272 | break; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 273 | } |
| 274 | default: |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 275 | out.AddFormatted("minor: %d", minor_key); |
| 276 | } |
| 277 | } |
| 278 | } else { |
| 279 | out.AddFormatted(" %s", Code::Kind2String(kind)); |
| 280 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 281 | if (rmode == RelocInfo::CODE_TARGET_WITH_ID) { |
| 282 | out.AddFormatted(" (id = %d)", static_cast<int>(relocinfo.data())); |
| 283 | } |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 284 | } else if (RelocInfo::IsRuntimeEntry(rmode) && |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 285 | isolate->deoptimizer_data() != NULL) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 286 | // A runtime entry reloinfo might be a deoptimization bailout. |
| 287 | Address addr = relocinfo.target_address(); |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 288 | int id = Deoptimizer::GetDeoptimizationId(isolate, |
| 289 | addr, |
| 290 | Deoptimizer::EAGER); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 291 | if (id == Deoptimizer::kNotDeoptimizationEntry) { |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 292 | id = Deoptimizer::GetDeoptimizationId(isolate, |
| 293 | addr, |
| 294 | Deoptimizer::LAZY); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 295 | if (id == Deoptimizer::kNotDeoptimizationEntry) { |
danno@chromium.org | aefd607 | 2013-05-14 14:11:47 +0000 | [diff] [blame] | 296 | id = Deoptimizer::GetDeoptimizationId(isolate, |
| 297 | addr, |
| 298 | Deoptimizer::SOFT); |
| 299 | if (id == Deoptimizer::kNotDeoptimizationEntry) { |
| 300 | out.AddFormatted(" ;; %s", RelocInfo::RelocModeName(rmode)); |
| 301 | } else { |
| 302 | out.AddFormatted(" ;; soft deoptimization bailout %d", id); |
| 303 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 304 | } else { |
| 305 | out.AddFormatted(" ;; lazy deoptimization bailout %d", id); |
| 306 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 307 | } else { |
| 308 | out.AddFormatted(" ;; deoptimization bailout %d", id); |
| 309 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 310 | } else { |
| 311 | out.AddFormatted(" ;; %s", RelocInfo::RelocModeName(rmode)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 312 | } |
| 313 | } |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 314 | DumpBuffer(f, &out); |
| 315 | } |
| 316 | |
| 317 | // Emit comments following the last instruction (if any). |
| 318 | if (it != NULL) { |
| 319 | for ( ; !it->done(); it->next()) { |
| 320 | if (RelocInfo::IsComment(it->rinfo()->rmode())) { |
| 321 | out.AddFormatted(" %s", |
| 322 | reinterpret_cast<const char*>(it->rinfo()->data())); |
| 323 | DumpBuffer(f, &out); |
| 324 | } |
| 325 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | delete it; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 329 | return static_cast<int>(pc - begin); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 333 | int Disassembler::Decode(Isolate* isolate, FILE* f, byte* begin, byte* end) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 334 | V8NameConverter defaultConverter(NULL); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 335 | return DecodeIt(isolate, f, defaultConverter, begin, end); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 339 | // Called by Code::CodePrint. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 340 | void Disassembler::Decode(FILE* f, Code* code) { |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 341 | Isolate* isolate = code->GetIsolate(); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 342 | int decode_size = code->is_crankshafted() |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 343 | ? static_cast<int>(code->safepoint_table_offset()) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 344 | : code->instruction_size(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 345 | // If there might be a back edge table, stop before reaching it. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 346 | if (code->kind() == Code::FUNCTION) { |
| 347 | decode_size = |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 348 | Min(decode_size, static_cast<int>(code->back_edge_table_offset())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | byte* begin = code->instruction_start(); |
| 352 | byte* end = begin + decode_size; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 353 | V8NameConverter v8NameConverter(code); |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 354 | DecodeIt(isolate, f, v8NameConverter, begin, end); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 355 | } |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 356 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 357 | #else // ENABLE_DISASSEMBLER |
| 358 | |
| 359 | void Disassembler::Dump(FILE* f, byte* begin, byte* end) {} |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 360 | int Disassembler::Decode(Isolate* isolate, FILE* f, byte* begin, byte* end) { |
| 361 | return 0; |
| 362 | } |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 363 | |
| 364 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 365 | void Disassembler::Decode(FILE* f, Code* code) {} |
| 366 | |
| 367 | #endif // ENABLE_DISASSEMBLER |
| 368 | |
| 369 | } } // namespace v8::internal |