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