recompile.hpp

Go to the documentation of this file.
00001 /* Copyright 1994 - 1996 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 
00025 #ifdef DELTA_COMPILER
00026 
00027 // The recompilation system determines which interpreted methods should be compiled
00028 // by the native-code compiler, or which compiled methods need to be recompiled for
00029 // further optimization. This file contains the interface to the run-time system.   
00030 //
00031 // A Recompilation performs a recompilation from interpreted or compiled code to 
00032 // (hopefully better) compiled code. The global theRecompilation is set only during
00033 // a recompilation.
00034  
00035 class Recompilation;
00036 extern Recompilation* theRecompilation;
00037 extern nmethod* recompilee;             // method currently being recompiled
00038 
00039 class Recompilation : public VM_Operation {
00040  private:
00041   oop           _rcvr;                  // receiver of trigger method/nmethod
00042   methodOop     _method;                // trigger method
00043   nmethod*      _nm;                    // trigger nmethod (if compiled, NULL otherwise)
00044   nmethod*      _newNM;                 // new nmethod replacing trigger (if any)
00045   deltaVFrame*  _triggerVF;             // vframe of trigger method/nmethod (NOT COMPLETELY INITIALIZED)
00046   bool          _isUncommon;            // recompiling because of uncommon branch?
00047   bool          _recompiledTrigger;     // is newNM the new version of _nm?
00048 
00049  public:
00050   Recompilation(oop rcvr, methodOop method) {               // used if interpreted method triggers counter
00051     _method = method; _rcvr = rcvr; _nm = NULL; _isUncommon = false; init();
00052   }
00053   Recompilation(oop rcvr, nmethod* nm, bool unc = false) {  // used if compiled method triggers counter
00054     _method = nm->method(); _rcvr = rcvr; _nm = nm; _isUncommon = unc; init();
00055   }
00056   ~Recompilation()                      { theRecompilation = NULL; }
00057   void doit();
00058   bool isCompiled() const               { return _nm != NULL; }
00059   bool recompiledTrigger() const        { return _recompiledTrigger; }
00060   char* result() const                  { return _newNM ? _newNM->verifiedEntryPoint() : NULL; }
00061   oop  receiverOf(deltaVFrame* vf) const;     // same as vf->receiver() but also works for trigger
00062   char* name()                          { return "recompile"; }
00063 
00064   // entry points dealing with invocation counter overflow
00065   static char* methodOop_invocation_counter_overflow(oop rcvr, methodOop method); // called by interpreter
00066   static char* nmethod_invocation_counter_overflow  (oop rcvr, char*     pc    ); // called by nmethods
00067 
00068  protected:
00069   void init();
00070   void recompile(Recompilee* r);
00071   void recompile_method(Recompilee* r);
00072   void recompile_block(Recompilee* r);
00073   bool handleStaleInlineCache(RFrame* first);
00074 };
00075 
00076 
00077 // A Recompilee represents something to be recompiled (either an interpreted method or
00078 // a compiled method).
00079 
00080 class Recompilee : public ResourceObj {
00081  protected:
00082   RFrame* _rf;
00083   Recompilee(RFrame* rf)                { _rf = rf; }
00084  public:
00085   virtual bool is_interpreted() const   { return false; }
00086   virtual bool is_compiled() const      { return false; }
00087   virtual LookupKey* key() const        = 0;
00088   virtual methodOop  method() const     = 0;
00089   virtual nmethod*   code() const       { ShouldNotCallThis(); return NULL; }   // only for compiled recompileed
00090           RFrame*    rframe() const     { return _rf; }
00091   static Recompilee* new_Recompilee(RFrame* rf);
00092 };
00093 
00094 class InterpretedRecompilee : public Recompilee {
00095   LookupKey* _key;
00096   methodOop _method;
00097  public:
00098   InterpretedRecompilee(RFrame* rf, LookupKey* k, methodOop m) : Recompilee(rf) { _key = k; _method = m; }
00099   bool       is_interpreted() const     { return true; }
00100   LookupKey* key() const                { return _key; }
00101   methodOop  method() const             { return _method; }
00102 };
00103 
00104 class CompiledRecompilee : public Recompilee {
00105   nmethod* _nm;
00106  public:
00107   CompiledRecompilee(RFrame* rf, nmethod* nm) : Recompilee(rf) { _nm = nm; }
00108   bool       is_compiled() const        { return true; }
00109   LookupKey* key() const;
00110   methodOop  method() const;
00111   nmethod*   code() const               { return _nm; }
00112 };
00113 
00114 
00115 #ifdef junk
00116 extern int nstages;                     // # of recompilation stages
00117 extern smi* compileCounts;              // # of compilations indexed by stage
00118 extern int* recompileLimits;            // recompilation limits indexed by stage
00119 #endif
00120 const int MaxRecompilationLevels = 4;   // max. # recompilation levels
00121 const int MaxVersions = 4 - 1;          // desired max. # nmethod recompilations
00122 
00123 
00124 #endif

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