location.hpp

Go to the documentation of this file.
00001 /* Copyright 1994 - 1996 LongView Technologies L.L.C. $Revision: 1.18 $ */
00002 /* Copyright (c) 2006, Sun Microsystems, Inc.
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 
00006 following conditions are met:
00007 
00008     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 
00010           disclaimer in the documentation and/or other materials provided with the distribution.
00011     * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived 
00012           from this software without specific prior written permission.
00013 
00014 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 
00015 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
00016 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
00017 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00018 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
00019 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
00020 
00021 
00022 */
00023 
00024 # ifdef DELTA_COMPILER
00025 
00026 // Locations serve as abstractions for physical addresses. For each
00027 // physical location (register, stack position or context temporary),
00028 // there is a corresponding location and vice versa.
00029 
00030 enum Mode {
00031 // mode\bits            3...................31  describes
00032 //                      3..9    10..16  17..31
00033    specialLoc,  //      --------id------------  sentinel values/global locations
00034    registerLoc, //      --------regLoc--------  register locations
00035    stackLoc,    //      --------offset--------  stack locations
00036    contextLoc1, //      ctxtNo  offset  scID    context locations during compilation (scope ID identifies InlinedScope)
00037    contextLoc2, //      ctxtNo  offset  scOffs  context locations (scOffs is scope offset within encoded scopes)
00038    floatLoc,    //      0       floatNo scopeN  float locations
00039 };
00040 
00041 
00042 class Location: public ResourceObj /* but usually used as ValueObj */ {
00043  private:
00044   int _loc;     // location encoding
00045 
00046   // field layout of _loc (no local const definitions allowed in C++)
00047   enum {
00048     _f1Pos      = 3,                    _f1Len  = 7,    _f1Mask = (1<<_f1Len) - 1,
00049     _f2Pos      = _f1Pos + _f1Len,      _f2Len  = 7,    _f2Mask = (1<<_f2Len) - 1,
00050     _f3Pos      = _f2Pos + _f2Len,      _f3Len  = 15,   _f3Mask = (1<<_f3Len) - 1,
00051     _fPos       = _f1Pos,               _fLen   = 29,   _fMask  = (1<<_fLen ) - 1,
00052   };
00053 
00054   void overflow(Mode mode, int f1, int f2, int f3);                             // handle field overflow if possible
00055 
00056  public:
00057   // default constructor - for better debugging
00058   Location()                                                                    { specialLocation(0); }
00059   Location(int l)                                                               { _loc = l; }
00060   Location(Mode mode, int f);
00061   Location(Mode mode, int f1, int f2, int f3);
00062 
00063   // factory
00064   static Location specialLocation(int id)                                       { return Location(specialLoc, id); }
00065   static Location registerLocation(int number)                                  { return Location(registerLoc, number); }
00066   static Location stackLocation(int offset)                                     { return Location(stackLoc, offset); }
00067   static Location compiledContextLocation(int contextNo, int tempNo, int id)    { return Location(contextLoc1, contextNo, tempNo, id); }
00068   static Location runtimeContextLocation(int contextNo, int tempNo, int offs)   { return Location(contextLoc2, contextNo, tempNo, offs); }
00069   static Location floatLocation(int scopeNo, int tempNo)                        { return Location(floatLoc, 0, tempNo, scopeNo); }
00070 
00071   // attributes
00072   Mode mode() const { return (Mode)(_loc & ((1<<_f1Pos) - 1)); }
00073 
00074   int id() const {
00075     assert(mode() == specialLoc, "not a special location");
00076     return (_loc>>_fPos) & _fMask;
00077   }
00078 
00079   int number() const {
00080     assert(mode() == registerLoc, "not a register location");
00081     return (_loc>>_fPos) & _fMask;
00082   }
00083 
00084   int offset() const {
00085     assert(mode() == stackLoc, "not a stack location");
00086     int t = _loc>>_fPos;
00087     return _loc < 0 ? (t | ~_fMask) : t;
00088   }
00089 
00090   int contextNo() const {
00091     assert(mode() == contextLoc1 || mode() == contextLoc2, "not a context location");
00092     return (_loc>>_f1Pos) & _f1Mask;
00093   }
00094 
00095   int tempNo() const {
00096     assert(mode() == contextLoc1 || mode() == contextLoc2, "not a context location");
00097     return (_loc>>_f2Pos) & _f2Mask;
00098   }
00099 
00100   int scopeID() const {
00101     assert(mode() == contextLoc1, "not a compiled context location");
00102     return (_loc>>_f3Pos) & _f3Mask;
00103   }
00104 
00105   int scopeOffs() const {
00106     assert(mode() == contextLoc2, "not a runtime context location");
00107     return (_loc>>_f3Pos) & _f3Mask;
00108   }
00109 
00110   int floatNo() const {
00111     assert(mode() == floatLoc, "not a float location");
00112     return (_loc>>_f2Pos) & _f2Mask;
00113   }
00114 
00115   int scopeNo() const {
00116     assert(mode() == floatLoc, "not a float location");
00117     return (_loc>>_f3Pos) & _f3Mask;
00118   }
00119 
00120   // helper functions
00121   char* name() const;
00122 
00123   // predicates
00124   bool isSpecialLocation() const        { return mode() == specialLoc; }
00125   bool isRegisterLocation() const       { return mode() == registerLoc; }
00126   bool isStackLocation() const          { return mode() == stackLoc; }
00127   bool isContextLocation() const        { return mode() == contextLoc1 || mode() == contextLoc2; }
00128   bool isFloatLocation() const          { return mode() == floatLoc; }
00129   bool isTopOfStack() const;
00130   bool equals(Location y) const         { return _loc == y._loc; }
00131 
00132   friend bool operator == (Location x, Location y) {return x._loc == y._loc; }
00133   friend bool operator != (Location x, Location y) {return x._loc != y._loc; }
00134   
00135   bool isTemporaryRegister() const;
00136   bool isTrashedRegister() const;
00137   bool isLocalRegister() const;
00138 
00139   // For packing and unpacking scope information
00140   friend class LocationName;
00141   friend class MemoizedName;
00142   friend class nmethodScopes;
00143   friend class DebugInfoWriter;
00144 };
00145 
00146 
00147 // special locations
00148 const int nofSpecialLocations   = 6;
00149 const Location illegalLocation  = Location::specialLocation(0);
00150 const Location unAllocated      = Location::specialLocation(1);
00151 const Location noRegister       = Location::specialLocation(2);
00152 const Location topOfStack       = Location::specialLocation(3);
00153 const Location resultOfNLR      = Location::specialLocation(4);
00154 const Location topOfFloatStack  = Location::specialLocation(5); // only used if UseFPUStack is true
00155 
00156 
00157 // An IntFreeList maintains a list of 'available' integers in the range [0, n[
00158 // where n is the maximum number of integers ever allocated. An IntFreeList may
00159 // be used to allocate/release stack locations.
00160 
00161 class IntFreeList : public PrintableResourceObj {
00162  protected:
00163   int                   _first; // the first available integer
00164   GrowableArray<int>*   _list;  // the list
00165 
00166   void grow();
00167 
00168  public:
00169   IntFreeList(int size);
00170 
00171   int   allocate();             // returns a new integer, grows the list if necessary
00172   int   allocated();            // returns the number of allocated integers
00173   void  release(int i);         // marks the integer i as 'available' again
00174   int   length();               // the maximum number of integers ever allocated
00175   void  print();
00176 };
00177 
00178 
00179 # endif

Generated on Mon Oct 9 13:37:13 2006 for Strongtalk VM by  doxygen 1.4.7