LCOV - code coverage report
Current view: directory - js/src/assembler/assembler - CodeLocation.h (source / functions) Found Hit Coverage
Test: app.info Lines: 35 33 94.3 %
Date: 2012-06-02 Functions: 18 17 94.4 %

       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 CodeLocation_h
      31                 : #define CodeLocation_h
      32                 : 
      33                 : #include "assembler/wtf/Platform.h"
      34                 : #include "assembler/assembler/MacroAssemblerCodeRef.h"
      35                 : 
      36                 : #if ENABLE_ASSEMBLER
      37                 : 
      38                 : namespace JSC {
      39                 : 
      40                 : class CodeLocationInstruction;
      41                 : class CodeLocationLabel;
      42                 : class CodeLocationJump;
      43                 : class CodeLocationCall;
      44                 : class CodeLocationNearCall;
      45                 : class CodeLocationDataLabel32;
      46                 : class CodeLocationDataLabelPtr;
      47                 : 
      48                 : // The CodeLocation* types are all pretty much do-nothing wrappers around
      49                 : // CodePtr (or MacroAssemblerCodePtr, to give it its full name).  These
      50                 : // classes only exist to provide type-safety when linking and patching code.
      51                 : //
      52                 : // The one new piece of functionallity introduced by these classes is the
      53                 : // ability to create (or put another way, to re-discover) another CodeLocation
      54                 : // at an offset from one you already know.  When patching code to optimize it
      55                 : // we often want to patch a number of instructions that are short, fixed
      56                 : // offsets apart.  To reduce memory overhead we will only retain a pointer to
      57                 : // one of the instructions, and we will use the *AtOffset methods provided by
      58                 : // CodeLocationCommon to find the other points in the code to modify.
      59                 : class CodeLocationCommon : public MacroAssemblerCodePtr {
      60                 : public:
      61                 :     CodeLocationInstruction instructionAtOffset(int offset);
      62                 :     CodeLocationLabel labelAtOffset(int offset);
      63                 :     CodeLocationJump jumpAtOffset(int offset);
      64                 :     CodeLocationCall callAtOffset(int offset);
      65                 :     CodeLocationNearCall nearCallAtOffset(int offset);
      66                 :     CodeLocationDataLabelPtr dataLabelPtrAtOffset(int offset);
      67                 :     CodeLocationDataLabel32 dataLabel32AtOffset(int offset);
      68                 : 
      69                 : protected:
      70         3618728 :     CodeLocationCommon()
      71         3618728 :     {
      72         3618728 :     }
      73                 : 
      74        21120000 :     CodeLocationCommon(MacroAssemblerCodePtr location)
      75        21120000 :         : MacroAssemblerCodePtr(location)
      76                 :     {
      77        21120000 :     }
      78                 : };
      79                 : 
      80                 : class CodeLocationInstruction : public CodeLocationCommon {
      81                 : public:
      82                 :     CodeLocationInstruction() {}
      83                 :     explicit CodeLocationInstruction(MacroAssemblerCodePtr location)
      84                 :         : CodeLocationCommon(location) {}
      85          101792 :     explicit CodeLocationInstruction(void* location)
      86          101792 :         : CodeLocationCommon(MacroAssemblerCodePtr(location)) {}
      87                 : };
      88                 : 
      89                 : class CodeLocationLabel : public CodeLocationCommon {
      90                 : public:
      91         2551788 :     CodeLocationLabel() {}
      92               0 :     explicit CodeLocationLabel(MacroAssemblerCodePtr location)
      93               0 :         : CodeLocationCommon(location) {}
      94        16630394 :     explicit CodeLocationLabel(void* location)
      95        16630394 :         : CodeLocationCommon(MacroAssemblerCodePtr(location)) {}
      96                 : };
      97                 : 
      98                 : class CodeLocationJump : public CodeLocationCommon {
      99                 : public:
     100          216344 :     CodeLocationJump() {}
     101                 :     explicit CodeLocationJump(MacroAssemblerCodePtr location)
     102                 :         : CodeLocationCommon(location) {}
     103          930587 :     explicit CodeLocationJump(void* location)
     104          930587 :         : CodeLocationCommon(MacroAssemblerCodePtr(location)) {}
     105                 : };
     106                 : 
     107                 : class CodeLocationCall : public CodeLocationCommon {
     108                 : public:
     109          850596 :     CodeLocationCall() {}
     110                 :     explicit CodeLocationCall(MacroAssemblerCodePtr location)
     111                 :         : CodeLocationCommon(location) {}
     112         1419939 :     explicit CodeLocationCall(void* location)
     113         1419939 :         : CodeLocationCommon(MacroAssemblerCodePtr(location)) {}
     114                 : };
     115                 : 
     116                 : class CodeLocationNearCall : public CodeLocationCommon {
     117                 : public:
     118                 :     CodeLocationNearCall() {}
     119                 :     explicit CodeLocationNearCall(MacroAssemblerCodePtr location)
     120                 :         : CodeLocationCommon(location) {}
     121                 :     explicit CodeLocationNearCall(void* location)
     122                 :         : CodeLocationCommon(MacroAssemblerCodePtr(location)) {}
     123                 : };
     124                 : 
     125                 : class CodeLocationDataLabel32 : public CodeLocationCommon {
     126                 : public:
     127                 :     CodeLocationDataLabel32() {}
     128                 :     explicit CodeLocationDataLabel32(MacroAssemblerCodePtr location)
     129                 :         : CodeLocationCommon(location) {}
     130          702963 :     explicit CodeLocationDataLabel32(void* location)
     131          702963 :         : CodeLocationCommon(MacroAssemblerCodePtr(location)) {}
     132                 : };
     133                 : 
     134                 : class CodeLocationDataLabelPtr : public CodeLocationCommon {
     135                 : public:
     136                 :     CodeLocationDataLabelPtr() {}
     137                 :     explicit CodeLocationDataLabelPtr(MacroAssemblerCodePtr location)
     138                 :         : CodeLocationCommon(location) {}
     139         1334325 :     explicit CodeLocationDataLabelPtr(void* location)
     140         1334325 :         : CodeLocationCommon(MacroAssemblerCodePtr(location)) {}
     141                 : };
     142                 : 
     143          101792 : inline CodeLocationInstruction CodeLocationCommon::instructionAtOffset(int offset)
     144                 : {
     145                 :     ASSERT_VALID_CODE_OFFSET(offset);
     146          101792 :     return CodeLocationInstruction(reinterpret_cast<char*>(dataLocation()) + offset);
     147                 : }
     148                 : 
     149          563028 : inline CodeLocationLabel CodeLocationCommon::labelAtOffset(int offset)
     150                 : {
     151                 :     ASSERT_VALID_CODE_OFFSET(offset);
     152          563028 :     return CodeLocationLabel(reinterpret_cast<char*>(dataLocation()) + offset);
     153                 : }
     154                 : 
     155          308411 : inline CodeLocationJump CodeLocationCommon::jumpAtOffset(int offset)
     156                 : {
     157                 :     ASSERT_VALID_CODE_OFFSET(offset);
     158          308411 :     return CodeLocationJump(reinterpret_cast<char*>(dataLocation()) + offset);
     159                 : }
     160                 : 
     161             285 : inline CodeLocationCall CodeLocationCommon::callAtOffset(int offset)
     162                 : {
     163                 :     ASSERT_VALID_CODE_OFFSET(offset);
     164             285 :     return CodeLocationCall(reinterpret_cast<char*>(dataLocation()) + offset);
     165                 : }
     166                 : 
     167                 : inline CodeLocationNearCall CodeLocationCommon::nearCallAtOffset(int offset)
     168                 : {
     169                 :     ASSERT_VALID_CODE_OFFSET(offset);
     170                 :     return CodeLocationNearCall(reinterpret_cast<char*>(dataLocation()) + offset);
     171                 : }
     172                 : 
     173          336101 : inline CodeLocationDataLabelPtr CodeLocationCommon::dataLabelPtrAtOffset(int offset)
     174                 : {
     175                 :     ASSERT_VALID_CODE_OFFSET(offset);
     176          336101 :     return CodeLocationDataLabelPtr(reinterpret_cast<char*>(dataLocation()) + offset);
     177                 : }
     178                 : 
     179          672202 : inline CodeLocationDataLabel32 CodeLocationCommon::dataLabel32AtOffset(int offset)
     180                 : {
     181                 :     ASSERT_VALID_CODE_OFFSET(offset);
     182          672202 :     return CodeLocationDataLabel32(reinterpret_cast<char*>(dataLocation()) + offset);
     183                 : }
     184                 : 
     185                 : } // namespace JSC
     186                 : 
     187                 : #endif // ENABLE(ASSEMBLER)
     188                 : 
     189                 : #endif // CodeLocation_h

Generated by: LCOV version 1.7