| 1 | /* |
| 2 | * Copyright (C) 2012 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "LinkBuffer.h" |
| 28 | |
| 29 | #if ENABLE(ASSEMBLER) |
| 30 | |
| 31 | #include "Options.h" |
| 32 | |
| 33 | namespace JSC { |
| 34 | |
| 35 | #if DUMP_LINK_STATISTICS |
| 36 | void LinkBuffer::dumpLinkStatistics(void* code, size_t initializeSize, size_t finalSize) |
| 37 | { |
| 38 | static unsigned linkCount = 0; |
| 39 | static unsigned totalInitialSize = 0; |
| 40 | static unsigned totalFinalSize = 0; |
| 41 | linkCount++; |
| 42 | totalInitialSize += initialSize; |
| 43 | totalFinalSize += finalSize; |
| 44 | dataLogF("link %p: orig %u, compact %u (delta %u, %.2f%%)\n" , |
| 45 | code, static_cast<unsigned>(initialSize), static_cast<unsigned>(finalSize), |
| 46 | static_cast<unsigned>(initialSize - finalSize), |
| 47 | 100.0 * (initialSize - finalSize) / initialSize); |
| 48 | dataLogF("\ttotal %u: orig %u, compact %u (delta %u, %.2f%%)\n" , |
| 49 | linkCount, totalInitialSize, totalFinalSize, totalInitialSize - totalFinalSize, |
| 50 | 100.0 * (totalInitialSize - totalFinalSize) / totalInitialSize); |
| 51 | } |
| 52 | #endif |
| 53 | |
| 54 | #if DUMP_CODE |
| 55 | void LinkBuffer::dumpCode(void* code, size_t size) |
| 56 | { |
| 57 | #if CPU(ARM_THUMB2) |
| 58 | // Dump the generated code in an asm file format that can be assembled and then disassembled |
| 59 | // for debugging purposes. For example, save this output as jit.s: |
| 60 | // gcc -arch armv7 -c jit.s |
| 61 | // otool -tv jit.o |
| 62 | static unsigned codeCount = 0; |
| 63 | unsigned short* tcode = static_cast<unsigned short*>(code); |
| 64 | size_t tsize = size / sizeof(short); |
| 65 | char nameBuf[128]; |
| 66 | snprintf(nameBuf, sizeof(nameBuf), "_jsc_jit%u" , codeCount++); |
| 67 | dataLogF("\t.syntax unified\n" |
| 68 | "\t.section\t__TEXT,__text,regular,pure_instructions\n" |
| 69 | "\t.globl\t%s\n" |
| 70 | "\t.align 2\n" |
| 71 | "\t.code 16\n" |
| 72 | "\t.thumb_func\t%s\n" |
| 73 | "# %p\n" |
| 74 | "%s:\n" , nameBuf, nameBuf, code, nameBuf); |
| 75 | |
| 76 | for (unsigned i = 0; i < tsize; i++) |
| 77 | dataLogF("\t.short\t0x%x\n" , tcode[i]); |
| 78 | #endif |
| 79 | } |
| 80 | #endif |
| 81 | |
| 82 | } // namespace JSC |
| 83 | |
| 84 | #endif // ENABLE(ASSEMBLER) |
| 85 | |
| 86 | |
| 87 | |