zone.hpp

Go to the documentation of this file.
00001 /* Copyright 1994, LongView Technologies L.L.C. $Revision: 1.20 $ */
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 // The zone implements the code cache for optimized methods and contains:
00027 //   1) a lookup table:      "Lookup key -> nmethod"
00028 //   2) the optimized methods (nmethods).
00029 
00030 // Implementation:
00031 //   - Each compiled method occupies one chunk of memory.
00032 //   - Like the offset table in oldspace the zone has at table for
00033 //     locating a method given a addess of an instruction.
00034 
00035 class ScopeDesc;
00036 class PcDesc;
00037 class relocInfo;
00038 
00039 class ZombieLink;
00040 
00041 class zone: public CHeapObj {
00042  public:
00043   Heap*       methodHeap;     // Contains all nmethods
00044   Heap*       picHeap;        // Contains all compiled CompiledPICs
00045   codeTable*  methodTable;    // Hash table: LookupKey --> nmethod
00046   jumpTable   _jump_table;    // Contains all jump entries
00047 
00048  public: 
00049   // returns the optimized method matching the lookup key, otherwise NULL
00050   nmethod* lookup(LookupKey* key) { return methodTable->lookup(key); }
00051 
00052  protected:
00053   nmethod* LRUhand;     // for LRU algorithm; sweeps through iZone
00054 
00055   bool _needsCompaction;
00056   bool _needsLRUSweep;
00057   bool _needsSweep;
00058 
00059   int compactTime;      // time of last compaction
00060   int compactDuration;  // duration of last compaction
00061 
00062   double minFreeFrac;   // fraction of free space needed at compaction time
00063 
00064  public:  
00065   zone(int& size);
00066 
00067   void* operator new(size_t size)       { return AllocateHeap(size, "nmethod zone header"); }
00068 
00069   void clear();
00070   
00071   int capacity() const                  { return methodHeap->capacity(); }
00072 
00073   jumpTable* jump_table() const         { return (jumpTable*)&_jump_table; }
00074 
00075   void verify_if_often();
00076 
00077   int used();
00078   int numberOfNMethods() const          { return jump_table()->usedIDs; }
00079   
00080   nmethod* allocate(int size);
00081 
00082   void free(nmethod* m);
00083   void addToCodeTable(nmethod* nm);
00084 
00085   void compact(bool forced = false);
00086   bool needsCompaction() const          { return _needsCompaction; }
00087   bool needsWork() const                { return needsCompaction() || _needsSweep; }
00088   bool needsSweep() const               { return _needsSweep; }
00089   void doWork();
00090   void doSweep();
00091   void flush();
00092   void flushZombies();
00093   void flushUnused();
00094 
00095   // Clear all inline caches of all nmethods
00096   void clear_inline_caches();
00097 
00098   void cleanup_inline_caches();
00099 
00100   int findReplCandidates(int needed);
00101   
00102   bool isDeltaPC(void* p) const;
00103   bool contains(void *p) const          { return methodHeap->contains(p); }
00104 
00105   nmethod* findNMethod(void* start) const;
00106   nmethod* findNMethod_maybe(void* start) const;        // slow!
00107   
00108   void nmethods_do(void f(nmethod* nm));
00109   void PICs_do(void f(PIC* pic));
00110 
00111   // Iterates over all oops is the zone
00112   void oops_do(void f(oop*));
00113 
00114   void switch_pointers(oop from, oop to);
00115   void verify();
00116 
00117   void print();
00118   
00119   void print_nmethod_histogram(int size);
00120 
00121   nmethod* first_nm() const             { return (nmethod*)(methodHeap->firstUsed()); }
00122   nmethod* next_nm(nmethod* p) const    { return (nmethod*)(methodHeap->nextUsed(p)); }
00123 
00124   PIC* first_pic() const        { return (PIC*)(picHeap->firstUsed()); }
00125   PIC* next_pic(PIC* p) const   { return (PIC*)(picHeap->nextUsed(p)); }
00126 
00127   char*    instsStart();
00128   int      instsSize();
00129   int    LRU_time();
00130   int      sweeper(int maxVisit, int maxReclaim,
00131                    int* nvisited = NULL, int* nbytesReclaimed = NULL);
00132   int    nextNMethodID();
00133 
00134  public:
00135    void mark_dependents_for_deoptimization();
00136    void mark_all_for_deoptimization();
00137    void unmark_all_for_deoptimization();
00138    void make_marked_nmethods_zombies();
00139 
00140  protected:
00141   void     print_helper(bool stats);
00142   void     adjustPolicy();
00143   int    flushNextMethod(int needed);
00144   inline nmethod* next_circular_nm(nmethod* nm);
00145  
00146   friend void moveInsts(char* from, char* to, int size);
00147   friend void printAllNMethods();
00148   friend void sweepTrigger();
00149 };
00150 
00151 // holds usage information for nmethods (or index of next free nmethod ID
00152 // if not assigned to any nmethod)
00153 class LRUcount : ValueObj {
00154  public:
00155   uint16 unused;        // nmethod prologue clears BOTH fields to 0
00156   uint16 lastUsed;      // time of last use
00157   
00158   LRUcount()            { ShouldNotCallThis(); } // shouldn't create
00159   void  set(int i)      { *(int*)this = i; }
00160 };
00161 
00162 extern LRUcount* LRUtable;      // for optimized methods
00163 extern int* LRUflag;    // == LRUtable, just different type for convenience
00164 #endif

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