LCOV - app.info - js/src/assembler/assembler/RepatchBuffer.h

LCOV - code coverage report
| Current view: | directory - js/src/assembler/assembler - RepatchBuffer.h (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 35 | 35 | 100.0 %
| Date: | 2012-04-07 | Functions: | 9 | 9 | 100.0 %

           1                 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
           2                 :  * vim: set ts=8 sw=4 et tw=79:
           3                 :  *
           4                 :  * ***** BEGIN LICENSE BLOCK *****
           5                 :  * Copyright (C) 2009 Apple Inc. All rights reserved.
           6                 :  *
           7                 :  * Redistribution and use in source and binary forms, with or without
           8                 :  * modification, are permitted provided that the following conditions
           9                 :  * are met:
          10                 :  * 1. Redistributions of source code must retain the above copyright
          11                 :  *    notice, this list of conditions and the following disclaimer.
          12                 :  * 2. Redistributions in binary form must reproduce the above copyright
          13                 :  *    notice, this list of conditions and the following disclaimer in the
          14                 :  *    documentation and/or other materials provided with the distribution.
          15                 :  *
          16                 :  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
          17                 :  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
          18                 :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
          19                 :  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
          20                 :  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
          21                 :  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
          22                 :  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
          23                 :  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
          24                 :  * 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                 :  * ***** END LICENSE BLOCK ***** */
          29                 :
          30                 : #ifndef RepatchBuffer_h
          31                 : #define RepatchBuffer_h
          32                 :
          33                 : #include "assembler/wtf/Platform.h"
          34                 :
          35                 : #if ENABLE_ASSEMBLER
          36                 :
          37                 : #include <assembler/MacroAssembler.h>
          38                 : #include <moco/MocoStubs.h> //MOCO
          39                 :
          40                 : namespace JSC {
          41                 :
          42                 : // RepatchBuffer:
          43                 : //
          44                 : // This class is used to modify code after code generation has been completed,
          45                 : // and after the code has potentially already been executed.  This mechanism is
          46                 : // used to apply optimizations to the code.
          47                 : //
          48                 : class RepatchBuffer {
          49                 :     typedef MacroAssemblerCodePtr CodePtr;
          50                 :
          51                 : public:
          52          262751 :     RepatchBuffer(const MacroAssemblerCodeRef &ref)
          53                 :     {
          54          262751 :         m_start = ref.m_code.executableAddress();
          55          262751 :         m_size = ref.m_size;
          56          262751 :         mprot = true;
          57                 :
          58          262751 :         if (mprot)
          59          262751 :             ExecutableAllocator::makeWritable(m_start, m_size);
          60          262751 :     }
          61                 :
          62           48702 :     RepatchBuffer(const JITCode &code)
          63                 :     {
          64           48702 :         m_start = code.start();
          65           48702 :         m_size = code.size();
          66           48702 :         mprot = true;
          67                 :
          68           48702 :         if (mprot)
          69           48702 :             ExecutableAllocator::makeWritable(m_start, m_size);
          70           48702 :     }
          71                 :
          72          311453 :     ~RepatchBuffer()
          73                 :     {
          74          311453 :         if (mprot)
          75          311453 :             ExecutableAllocator::makeExecutable(m_start, m_size);
          76          311453 :     }
          77                 :
          78           91555 :     void relink(CodeLocationJump jump, CodeLocationLabel destination)
          79                 :     {
          80           91555 :         MacroAssembler::repatchJump(jump, destination);
          81           91555 :     }
          82                 :
          83            7386 :     bool canRelink(CodeLocationJump jump, CodeLocationLabel destination)
          84                 :     {
          85            7386 :         return MacroAssembler::canRepatchJump(jump, destination);
          86                 :     }
          87                 :
          88                 :     void relink(CodeLocationCall call, CodeLocationLabel destination)
          89                 :     {
          90                 :         MacroAssembler::repatchCall(call, destination);
          91                 :     }
          92                 :
          93           18039 :     void relink(CodeLocationCall call, FunctionPtr destination)
          94                 :     {
          95           18039 :         MacroAssembler::repatchCall(call, destination);
          96           18039 :     }
          97                 :
          98                 :     void relink(CodeLocationNearCall nearCall, CodePtr destination)
          99                 :     {
         100                 :         MacroAssembler::repatchNearCall(nearCall, CodeLocationLabel(destination));
         101                 :     }
         102                 :
         103                 :     void relink(CodeLocationNearCall nearCall, CodeLocationLabel destination)
         104                 :     {
         105                 :         MacroAssembler::repatchNearCall(nearCall, destination);
         106                 :     }
         107                 :
         108          418422 :     void repatch(CodeLocationDataLabel32 dataLabel32, int32_t value)
         109                 :     {
         110          418422 :         MacroAssembler::repatchInt32(dataLabel32, value);
         111          418422 :     }
         112                 :
         113          220479 :     void repatch(CodeLocationDataLabelPtr dataLabelPtr, const void* value)
         114                 :     {
         115          220479 :         MacroAssembler::repatchPointer(dataLabelPtr, (void*) value);
         116          220479 :     }
         117                 :
         118            9977 :     void repatchLoadPtrToLEA(CodeLocationInstruction instruction)
         119                 :     {
         120            9977 :         MacroAssembler::repatchLoadPtrToLEA(instruction);
         121            9977 :     }
         122                 :
         123                 :     void repatchLEAToLoadPtr(CodeLocationInstruction instruction)
         124                 :     {
         125                 :         MacroAssembler::repatchLEAToLoadPtr(instruction);
         126                 :     }
         127                 :
         128                 :     void relinkCallerToTrampoline(ReturnAddressPtr returnAddress, CodeLocationLabel label)
         129                 :     {
         130                 :         relink(CodeLocationCall(CodePtr(returnAddress)), label);
         131                 :     }
         132                 :
         133                 :     void relinkCallerToTrampoline(ReturnAddressPtr returnAddress, CodePtr newCalleeFunction)
         134                 :     {
         135                 :         relinkCallerToTrampoline(returnAddress, CodeLocationLabel(newCalleeFunction));
         136                 :     }
         137                 :
         138                 :     void relinkCallerToFunction(ReturnAddressPtr returnAddress, FunctionPtr function)
         139                 :     {
         140                 :         relink(CodeLocationCall(CodePtr(returnAddress)), function);
         141                 :     }
         142                 :
         143                 :     void relinkNearCallerToTrampoline(ReturnAddressPtr returnAddress, CodeLocationLabel label)
         144                 :     {
         145                 :         relink(CodeLocationNearCall(CodePtr(returnAddress)), label);
         146                 :     }
         147                 :
         148                 :     void relinkNearCallerToTrampoline(ReturnAddressPtr returnAddress, CodePtr newCalleeFunction)
         149                 :     {
         150                 :         relinkNearCallerToTrampoline(returnAddress, CodeLocationLabel(newCalleeFunction));
         151                 :     }
         152                 :
         153                 : protected:
         154                 :     void* m_start;
         155                 :     size_t m_size;
         156                 :     bool mprot;
         157                 : };
         158                 :
         159                 : } // namespace JSC
         160                 :
         161                 : #endif // ENABLE(ASSEMBLER)
         162                 :
         163                 : #endif // RepatchBuffer_h

Generated by: LCOV version 1.7