compiler.hpp

Go to the documentation of this file.
00001 /* Copyright 1994 - 1996 LongView Technologies L.L.C. $Revision: 1.56 $ */
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 extern int nofCompilations;
00027 extern Compiler* theCompiler;
00028 
00029 class CodeGenerator;
00030 class NLRTestNode;
00031 
00032 class Compiler : public PrintableResourceObj {
00033   // A Compiler holds all the global state required for a single compilation.
00034  private:
00035   GrowableArray<InlinedScope*>  _scopeStack;                    // to keep track of current scope
00036   int                           _totalNofBytes;                 // total no. of bytes compiled (for statistics)
00037   int                           _special_handler_call_offset;   // call to recompilation stub or zombie handler (offset in bytes)
00038   int                           _entry_point_offset;            // nmethod entry point if receiver is unknown (offset in bytes)
00039   int                           _verified_entry_point_offset;   // nmethod entry point if receiver is known (offset in bytes)
00040   int                           _totalNofFloatTemporaries;      // the number of floatTemporaries for this nmethod
00041   int                           _float_section_size;            // the size of the float section on the stack in oops
00042   int                           _float_section_start_offset;    // the offset of the float section on the stack relative to ebp in oops
00043   CodeBuffer*                   _code;                          // the buffer used for code generation
00044 
00045   int   _nextLevel;                                     // optimization level for nmethod being created
00046   bool  _noInlinableSends;                              // no inlinable sends remaining?
00047   bool  _uses_inlining_database;                        // tells whether the compilation is base on inlinine database information.
00048 
00049 public:
00050   LookupKey*                    key;
00051   CompiledIC*                   ic;                     // sending inline cache
00052   nmethod*                      parentNMethod;          // nmethod of lexical parent (or NULL if not compiling a block method)
00053   methodOop                     method;                 // top-level method being compiled
00054   NonInlinedBlockScopeDesc*     blockScope;             // or NULL if not compiling a block method
00055 
00056   RScope*                       recompileeRScope;       // recompilee's rscope (or NULL)
00057   int                           countID;                // recompile counter ID
00058 
00059   jumpTableID                   main_jumpTable_id;      // jump table id
00060   jumpTableID                   promoted_jumpTable_id;  // promoted jump table entry for block method only
00061 
00062   bool                          useUncommonTraps;       // ok to use uncommon traps?
00063 
00064   ScopeDescRecorder*            rec;
00065   InlinedScope*                 topScope;               // top scope 
00066   BB*                           firstBB;                // first basic block
00067   GrowableArray<NLRTestNode*>*  nlrTestPoints;          // needed to fix up NLR points after node generation
00068   GrowableArray<InlinedScope*>* scopes;                 // list of all scopes (indexed by scope ID)
00069   GrowableArray<InlinedScope*>* contextList;            // list of all scopes with run-time contexts
00070   GrowableArray<BlockPReg*>*    blockClosures;          // list of all block literals created so far
00071   Node*                         firstNode;              // the very first node of the intermediate representation
00072   PerformanceDebugger*          reporter;               // for reporting performance info
00073   
00074 #ifdef DEBUG
00075   stringStream* messages;                               // debug messages    
00076 #endif 
00077 
00078 #ifdef LATER
00079   int   inlineLimit[LastLimit];                         // limits for current compilation
00080 #endif
00081 
00082 
00083  private:
00084   void initialize(RScope* remote_scope = NULL);
00085   void initTopScope();
00086   void initLimits();
00087   void buildBBs();
00088   void fixupNLRTestPoints();
00089   void computeBlockInfo();
00090 
00091 public:
00092   Compiler(LookupKey* k, methodOop m, CompiledIC* ic = NULL);           // normal entry point (method lookups)
00093   Compiler(blockClosureOop blk, NonInlinedBlockScopeDesc* scope);       // for block methods
00094   Compiler(RScope* scope);                                              // for inlining database
00095   ~Compiler() { finalize(); }
00096 
00097   CodeBuffer*           code() const;
00098   ScopeDescRecorder*    scopeDescRecorder();
00099   nmethod*              compile();
00100   void                  finalize();
00101 
00102   int   level() const;                                  // optimization level of new nmethod
00103   int   version() const;                                // version ("nth recompilation") of new nmethod
00104   int   special_handler_call_offset() const             { return _special_handler_call_offset ; }
00105   int   entry_point_offset() const                      { return _entry_point_offset; }
00106   int   verified_entry_point_offset() const             { return _verified_entry_point_offset; }
00107   int   get_invocation_counter_limit() const;           // invocation limit for nmethod being created
00108 
00109   void  set_special_handler_call_offset(int offset);
00110   void  set_entry_point_offset(int offset);
00111   void  set_verified_entry_point_offset(int offset);
00112 
00113   int   totalNofFloatTemporaries() const                { assert(_totalNofFloatTemporaries >= 0, "not yet determined"); return _totalNofFloatTemporaries; }
00114   bool  has_float_temporaries() const                   { return totalNofFloatTemporaries() > 0; }
00115   int   float_section_size() const                      { return has_float_temporaries() ? _float_section_size : 0; }
00116   int   float_section_start_offset() const              { return has_float_temporaries() ? _float_section_start_offset : 0; }
00117 
00118   void  set_float_section_size(int size);
00119   void  set_float_section_start_offset(int offset);
00120 
00121   bool  is_block_compile() const                        { return parentNMethod != NULL; }
00122   bool  is_method_compile() const                       { return !is_block_compile(); }
00123   bool  is_uncommon_compile() const;                    // recompiling because of uncommon trap?
00124   bool  is_database_compile() const                     { return _uses_inlining_database; }
00125 
00126   int   number_of_noninlined_blocks() const;            // no. of noninlined blocks in nmethod (used for jump entry alloc.)
00127   void  copy_noninlined_block_info(nmethod* nm);        // copy the noninlined block info to the nmethod.
00128   void  nofBytesCompiled(int n)                         { _totalNofBytes += n; }
00129   int   totalNofBytes() const                           { return _totalNofBytes; }
00130 
00131   int           estimatedSize() const;
00132   InlinedScope* currentScope() const;                   // scope currently being compiled
00133   void          enterScope(InlinedScope* s);
00134   void          exitScope (InlinedScope* s);
00135 
00136   void          allocateArgs(int nargs, bool isPrimCall);
00137   bool          registerUninlinable(Inliner* inliner);
00138   
00139   void print();
00140   void print_short();
00141   void print_key(outputStream* s);
00142   void print_code(bool suppressTrivial);
00143 };
00144 
00145 #ifdef DEBUG
00146 // cout: output stream for compiler messages
00147 // Intended usage pattern: if (CompilerDebug) cout(PrintXXX)->print("....").
00148 // This will print the message to std if the PrintXXX flag is set or to the compiler's string buffer otherwise.
00149 outputStream* cout(bool flag);  // for compiler debugging; returns stdout or compiler-internal string stream depending on flag
00150 void print_cout();              // prints hidden messages of current compilation
00151 #else
00152 #define cout(flag)  if (flag) std
00153 #endif
00154 
00155 #endif

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