harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From var...@apache.org
Subject svn commit: r536140 [3/3] - in /harmony/enhanced/drlvm/trunk/vm/jitrino: config/em64t/opt.emconf config/ia32/opt.emconf src/optimizer/escanalyzer.cpp src/optimizer/escanalyzer.h
Date Tue, 08 May 2007 09:44:53 GMT
Modified: harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/escanalyzer.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/escanalyzer.h?view=diff&rev=536140&r1=536139&r2=536140
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/escanalyzer.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/jitrino/src/optimizer/escanalyzer.h Tue May  8 02:44:50
2007
@@ -32,16 +32,46 @@
 
 namespace Jitrino {
 
-//
-// Escape analyzer (synchronization removing)
-//
+/**
+ * Performs escape analysis for the compiled method. 
+ * Creates data connection graph, sets states (local, argument escaped, global escaped)
+ * for objects created in compiled method, runs escape analysis related optimizations:
+ *  - monitor elimination optimization;
+ *  - scalar replacement optimization.
+ * Saves information about method arguments and return value states for future usage. 
+ */
+
 class EscAnalyzer {
 
 public:
+/**
+ * Creates EscAnalyzer class for compiled method. 
+ * @param mm - memory manager,
+ * @param argSource - session action,
+ * @param irm - compiled method IR manager.
+ */
     EscAnalyzer(MemoryManager& mm, SessionAction* argSource, IRManager& irm);
     
+/**
+ * Performs escape analysis and runs escape analysis related optimizations. 
+ */
     void doAnalysis();
 
+    // read from command line to output debug information
+    uint32 allProps;
+
+private:
+/**
+ * Creates EscAnalyzer class for callee method escape analysis. 
+ * @param parent - parent (caller method) EscAnalyzer class
+ * @param irm - compiled method IR manager.
+ */
+    EscAnalyzer(EscAnalyzer* parent, IRManager& irm);
+
+    // initial level to start callee method escape analysis
+    static const int maxMethodExamLevel_default = 0;
+
+    // Connection Graph Structure
 // CnG node types
     static const uint32 NT_OBJECT   = 8;  // Op_LdRef,Op_NewObj,Op_NewArray,Op_NewMultiArray
   
     static const uint32 NT_DEFARG   = NT_OBJECT+1;  // formal parameter - Op_DefArg
@@ -53,7 +83,7 @@
     static const uint32 NT_VARVAL   = NT_LDOBJ+2;   // Op_StVar,Op_Phi
     static const uint32 NT_ARRELEM  = NT_LDOBJ+3;   // Op_LdArrayBaseAddr,Op_AddScaledIndex
     static const uint32 NT_REF      = NT_LDOBJ+4;   // reference value - Op_LdFieldAddr,
-                                                    // Op_LdStaticAddr
+                                                    // Op_LdStaticAddr, Op_TauCast, Op_TauStaticCast
     static const uint32 NT_STFLD    = 64;           // Op_LdStaticAddr
     static const uint32 NT_INSTFLD  = NT_STFLD+1;   // Op_LdFieldAddr
     static const uint32 NT_ACTARG   = 128;          // Op_DirectCall,Op_IndirectMemoryCall
@@ -80,7 +110,6 @@
     static const uint32 CALLEE_ESCAPED = 16;
     static const uint32 VIRTUAL_CALL = 32;
 
-    typedef StlList<uint32> NodeMDs;    
 
     struct CnGNode;
     struct CnGRef {
@@ -91,7 +120,9 @@
 
     typedef StlList<CnGRef*> CnGRefs;   
     typedef StlList<Inst*> Insts;
+    typedef StlList<uint32> NodeMDs;    
 
+    // connection graph node structure
     struct CnGNode {
         uint32 cngNodeId;   // CnG node id
         uint32 opndId;      // opnd id  (0 for NT_ACTARG) 
@@ -99,8 +130,7 @@
         uint32 nodeType;    // CnG node types
         uint32 nodeRefType; // CnG node reference types
         uint32 instrId;
-        CnGNode* lNode;     // ldind from lNode 
-        Node* fgNode;
+        CnGNode* lNode;     // ldind from lNode for ldflda & ldsflda
         uint32 state;       // escape state
         NodeMDs* nodeMDs;   // list of NT_ACTARG nodes
         Inst* nInst;        // ref to inst 
@@ -131,7 +161,8 @@
 
     typedef StlList<ParamInfo*> ParamInfos; 
 
-    struct CalledMethodInfo {
+    // structure of saved by EA information about compiled method
+    struct CalleeMethodInfo {
         MemberIdent* methodIdent;
         uint32 numberOfArgs;
         uint32 properties;     // native, final, virtual ...
@@ -140,169 +171,424 @@
         bool mon_on_this;
     };
 
-    typedef StlList<CalledMethodInfo*> CalledMethodInfos;
+    // list of saved by EA information about compiled methods
+    typedef StlList<CalleeMethodInfo*> CalleeMethodInfos;
 
-    struct MonUnit {
-        uint32 opndId;
-        Insts* monInsts;
-        Insts* icallInsts;
+    // connection graph edge structure
+    struct CnGEdge {
+        CnGNode* cngNodeFrom;
+        CnGRefs* refList;
     };
 
-    MemoryManager& eaMemManager;
+    // list of connection graph nodes definition
+    typedef StlList<CnGNode*> CnGNodes; 
+    // list of connection graph edges definition
+    typedef StlList<CnGEdge*> CnGEdges; 
+    // list of object Ids definition
+    typedef StlList<uint32> ObjIds; 
+
 
-    static CalledMethodInfos* calledMethodInfos;
-    static Mutex calledMethodInfosLock;
+    static CalleeMethodInfos* calleeMethodInfos;
+    static Mutex calleeMethodInfosLock;
     
-    uint32 allProps;
+    // variables to read command line options
     const char* debug_method;
     bool do_sync_removal;
+    bool do_sync_removal_vc;
+    bool do_sync_removal_sm;
     bool do_scalar_repl;
     bool do_esc_scalar_repl;
     bool do_scalar_repl_only_final_fields;
     bool scalarize_final_fields;
     const char* execCountMultiplier_string;
     double ec_mult;
+    bool print_scinfo;
     bool compressedReferencesArg; // for makeTauLdInd 
 
-private:
-    static const int maxMethodExamLevel_default = 0;
-
-    struct CnGEdge {
-        CnGNode* cngNodeFrom;
-        CnGRefs* refList;
-    };
-
-    typedef StlList<CnGNode*> CnGNodes; 
-    typedef StlList<CnGEdge*> CnGEdges; 
-    
-    struct cfgNode {
-        uint32 nodeId;
-        Node* fgNode;
-        Insts* instructions;
-    };
-
-    typedef StlList<uint32> ObjIds; 
-
-    typedef StlList<MonUnit*> MonInstUnits; 
+    TranslatorAction* translatorAction;
 
-    EscAnalyzer(EscAnalyzer* parent, IRManager& irm);
-    
-    uint32 maxMethodExamLevel;
+    MemoryManager& eaMemManager;
     IRManager& irManager;
     MethodDesc& mh;            // analyzed method header
+    CompilationInterface &compInterface;
+
+    // list of connection graph nodes
     CnGNodes* cngNodes;
+    // list of connection graph edges
     CnGEdges* cngEdges;
+    // list of instructions for edge creation
+    Insts* exam2Insts;
+
+    // maximum level to analyze callee methods (from command line or default set)
+    uint32 maxMethodExamLevel;
+    // set level for escape analysis
+    uint32 method_ea_level;
+
     uint32 lastCnGNodeId;
     uint32 curMDNode;
     int defArgNumber;
-    uint32 method_ea_level;
+    uint32 initNodeType;  // type of initial scanned node
+
+    // lists to help do CFG scan
     ObjIds *scannedObjs;
     ObjIds *scannedObjsRev;
     ObjIds *scannedInsts;
     ObjIds *scannedSucNodes;
-    uint32 initNodeType;  // type of initial scanned node
-    MonInstUnits* monitorInstUnits ;
+
+    // format 32 0 operand used by the optimizations
     SsaTmpOpnd* i32_0;
+    // format 32 1 operand used by the optimizations
     SsaTmpOpnd* i32_1;
-    TranslatorAction* translatorAction;
+
+    // list of Op_MethodEnd instructions (for scalar replacement optimization)
     Insts* methodEndInsts;
+    // list of Op_Branch and Op_TauCheckNull instructions (for scalar replacement optimization)
     Insts* checkInsts;
 
-    std::ostream& os_sc;
-    bool print_scinfo;
-
-    struct ScObjFld {
-        VarOpnd* fldVarOpnd;
-        Insts* ls_insts;
-        FieldDesc* fd;
-        bool isFinalFld;
-    };
+    // variable used to output debug information
+    int _cfgirun;
+    int _instrInfo;
+    int _instrInfo2;
+    int _cngnodes;
+    int _cngedges;
+    int _scanMtds;
+    int _setState;
+    int _printstat;
+    int _eainfo;
+    int _seinfo;
+    int _scinfo;
+#define  prsNum  10
+    int prsArr[prsNum];
 
-    typedef StlList<ScObjFld*> ScObjFlds; 
 
-#ifdef _DEBUG
-    void prPrN(cfgNode pr_n[],int maxInd) {
-        Log::out()<<"--------------------"<<std::endl;
-        Log::out() <<"    pr_n contains"<<std::endl;
-        for (int i=0; i<maxInd; i++) {
-            Log::out() <<i<<"  nId "<<(pr_n[i]).nodeId;
-            Log::out() <<"  Node "<<(pr_n[i]).fgNode->getId();
-            Log::out() <<std::endl;
-        }
-        Log::out() <<"--------------------"<<std::endl;
-    }
-#endif
-    //common method for both EscAnalyzer constructors
+    // common method for both EscAnalyzer constructors
     void init();
+    // output escape analysis flags
     void showFlags(std::ostream& os);
-    void eaFixupVars(IRManager& irm);
-    void instrExam(cfgNode* node);
-    void instrExam2(cfgNode* node);
-    void addEdge(CnGNode* cgnfrom, CnGNode* cgnto, uint32 etype, Inst* inst);
-    void printCnGEdges(char* text,::std::ostream& os); 
-    void what_inst(Inst* inst,::std::ostream& os); 
-    void debug_inst_info(Inst* inst,::std::ostream& os);
-    void debug_opnd_info(Opnd* opnd,::std::ostream& os);
-    void ref_type_info(Type* type,::std::ostream& os);
+
+/**
+ * Scans specified CFG node instructions to create CnG nodes.
+ * Adds some instructions to exam2Instrs list to create CnG edges later.
+ * @param node - control flow graph node.
+ */
+    void instrExam(Node* node);
+
+/**
+ * Scans instructions from exam2Instrs list to create CnG edges. 
+ */
+    void instrExam2();
+
+/**
+ * Creates new CnG node for specified instruction and adds it to cngNodes list. 
+ * @param inst - instruction,
+ * @param type - operand type,
+ * @param ntype - CnG node type.
+ * @return created CnGnode. 
+ */
     CnGNode* addCnGNode(Inst* inst, Type* type, uint32 ntype);
+
+/**
+ * Creates new CnG node for specified instruction dst operand. 
+ * @param inst - instruction,
+ * @param type - operand type,
+ * @param ntype - CnG node type.
+ * @return created CnGnode. 
+ */
     CnGNode* addCnGNode_op(Inst* inst, Type* type, uint32 ntype);
+
+/**
+ * Creates new CnG node for specified call instruction argument. 
+ * @param inst - instruction,
+ * @param md - callee method description,
+ * @param ntype - CnG node type,
+ * @param narg - method argument.
+ * @return created CnGnode. 
+ */
     CnGNode* addCnGNode_mp(Inst* inst, MethodDesc* md, uint32 ntype, uint32 narg);
+
+/**
+ * Creates new CnG node for specified return or throw instruction. 
+ * @param inst - instruction,
+ * @param ntype - CnG node type.
+ * @return created CnGnode. 
+ */
     CnGNode* addCnGNode_ex(Inst* inst, uint32 ntype);
+
+/**
+ * Creates new field CnG node for specified instruction. 
+ * @param inst - instruction,
+ * @param ntype - CnG node type.
+ * @return created CnGnode. 
+ */
     CnGNode* addCnGNode_fl(Inst* inst, uint32 ntype);
-    void printCnGNodes(char* text,::std::ostream& os);
-    void printCnGNode(CnGNode* cgn,::std::ostream& os);
-    std::string nodeTypeToString(CnGNode* cgn);
-    std::string edgeTypeToString(CnGRef* edr);
-    CnGNode* findCnGNode_id(uint32 nId);
+
+/**
+ * Finds CnG node for specified operand Id. 
+ * @param nId - operand Id.
+ * @return found CnGnode, or <code>NULL</code>. 
+ */
     CnGNode* findCnGNode_op(uint32 nId);
+
+/**
+ * Finds CnG node for specified CnG node Id. 
+ * @param nId - CnG node Id.
+ * @return found CnGnode, or <code>NULL</code>. 
+ */
+    CnGNode* findCnGNode_id(uint32 nId);
+
+/**
+ * Finds CnG node for specified instruction Id. 
+ * @param nId - instruction Id.
+ * @return found CnGnode, or <code>NULL</code>. 
+ */
     CnGNode* findCnGNode_in(uint32 nId);
+
+/**
+ * Finds NT_ACTARG CnG node for specified instruction Id and argument number. 
+ * @param iId - instruction Id,
+ * @param aId - argument number.
+ * @return found CnGnode, or <code>NULL</code>. 
+ */
     CnGNode* findCnGNode_mp(uint32 iId, uint32 aId);
+
+/**
+ * Finds field CnG node for specified instruction and CnG node type. 
+ * @param inst - instruction,
+ * @param ntype - CnG node type.
+ * @return found CnGnode, or <code>NULL</code>. 
+ */
     CnGNode* findCnGNode_fl(Inst* inst, uint32 ntype);
-    void printCnGNodeRefs(CnGNode* cgn, std::string text,::std::ostream& os);
-    void printRefInfo(::std::ostream& os); 
-    void addInst(cfgNode* cfgn, Inst* inst);
-    void scanCnGNodeRefsGE(CnGNode* cgn, bool check_var_src, bool check_field_elem=true);
-//    void scanCnGNodeRefsEV(CnGNode* cgn);
-//    void scanCnGNodeRefsDA(CnGNode* cgn);
-    void scanCnGNodeRefsAE(CnGNode* cgn, bool check_var_src, bool check_field_elem=true);
+
+/**
+ * Creates new CnG edge for specified instruction, adds it to cngEdges and
+ * cgnfrom->outEdges lists.
+ * @param cgnfrom - CnG node from,
+ * @param cgnto - CnG node to,
+ * @param etype - edge type,
+ * @param inst - instruction.
+ * @return created CnGnode. 
+ */
+    void addEdge(CnGNode* cgnfrom, CnGNode* cgnto, uint32 etype, Inst* inst);
+
+/**
+ * Sets escape state for method created objects.
+ */
+    void setCreatedObjectStates();
+
+/**
+ * Scans CnG nodes beginning with specified node to set 
+ * GLOBAL_ESCAPE or VIRTUAL_CALL states.
+ * @param cgnfrom - CnG node to begin scan,
+ * @param check_var_src - sign to check variable operands.
+ */
+    void scanCnGNodeRefsGE(CnGNode* cgn, bool check_var_src);
+
+/**
+ * Scans CnG nodes beginning with specified node to set 
+ * ARG_ESCAPE states.
+ * @param cgnfrom - CnG node to begin scan,
+ * @param check_var_src - sign to check variable operands.
+ */
+    void scanCnGNodeRefsAE(CnGNode* cgn, bool check_var_src);
+
+/**
+ * Scans connection graph nodes beginning with specified not global escaped node to set 
+ * corresponding state to array elements and fields values.
+ * @param node - connection graph node to begin scan.
+ */
+    void checkSubobjectStates(CnGNode* node);
+
+/**
+ * Scans connection graph nodes specified NT_EXITVAL node refers to. 
+ * @param node - NT_EXITVAL connection graph node.
+ * @return GLOBAL_ESCAPE, if any of nodes node reference to is GLOBAL_ESCAPE, otherwise 
+ *         ARG_ESCAPE, if any of nodes node reference to is ARG_ESCAPE, otherwise
+ *         NO_ESCAPE.
+ */
+    uint32 getSubobjectStates(CnGNode* node);
+
+/**
+ * Finds specified method escape analysis information in the common repository and compiles

+ * the method if it is required and possible. 
+ * @param md - method description,
+ * @param inst - method call instruction.
+ * @return method info, if it was found, NULL - otherwise.
+ */
+    CalleeMethodInfo* findMethodInfo(MethodDesc* md,Inst* inst);
+
+/**
+ * Finds specified method escape analysis information in the common repository. 
+ * @param ch1 - method package name,
+ * @param ch2 - method name,
+ * @param ch3 - method signature.
+ * @return method info, if it was found, NULL - otherwise.
+ */
+    CalleeMethodInfo* getMethodInfo(const char* ch1,const char* ch2,const char* ch3);
+
+/**
+ * Runs escape analysis for direct call method. 
+ * @param call - direct call instruction.
+ */
     void scanCalleeMethod(Inst* call);
+
+/**
+ * Runs translator session for callee method. 
+ * @param inlineCC - compilation interface.
+ */
+    void runTranslatorSession(CompilationContext& inlineCC);
+
+/**
+ * Runs optimizations for callee method. 
+ * @param irManager - IR manager.
+ */
     void optimizeTranslatedCode(IRManager& irManager);
-    void setCreatedObjectStates();
-    void printCreatedObjectsInfo(::std::ostream& os);
-//    void printLocalObjectsInfo(::std::ostream& os);  //nvg
-    void printMethodInfos();        //?
-    void printMethodInfo(CalledMethodInfo* mi);
-    CalledMethodInfo* getMethodInfo(const char* ch1,const char* ch2,const char* ch3);
-    CalledMethodInfo* findMethodInfo(MethodDesc* md,Inst* inst);
+
+/**
+ * Saves escape analysis method information into common repository.
+ */
     void saveScannedMethodInfo();
-    uint32 getMethodParamState(CalledMethodInfo* mi, uint32 np);
+
+/**
+ * Returns specified method parameter state. 
+ * @param mi - escape analysis method information,
+ * @param np - parameter number.
+ * @return specified parameter state.
+ */
+    uint32 getMethodParamState(CalleeMethodInfo* mi, uint32 np);
+
+/**
+ * Collects instructions creating objects that are not GLOBAL_ESCAPE. 
+ */
     void markNotEscInsts();
 
-    void createdObjectInfo();
-    void addMonInst(Inst* inst);
-    void addMonUnitVCall(MonUnit* mu, Inst* inst); 
-    MonUnit* findMonUnit(uint32 opndId);
-    void scanSyncInsts();
-    void fixSyncMethodMonitorInsts(Insts* syncInsts);
-    void checkCallSyncMethod();
-    void insertSaveJitHelperCall(CnGNode* node);
-    Opnd* insertReadJitHelperCall();
-    bool checkMonitorsOnThis();
-    void setSencEscState(CnGNode* node,Insts* syncInsts);
-    void collectSuccessors(Node* node);
-    void collectGlobalNodeSuccessors(CnGNode* node);
-    uint32 getContainingObjState(Inst* linst);
-    void removeMonitorInsts(Insts* syncInsts);
-    void removeNode(Node* node);
-    SsaTmpOpnd* insertLdConst(uint32 value);
-    void fixMonitorInstsVCalls(MonUnit* mu);
-    void insertFlagCheck(Insts* syncInsts, Opnd* muflag);
-    void printNode(Node* n,::std::ostream& os);
-    uint32 checkState(Inst* inst,uint32 st);
-    void findObject(Inst* inst,std::string text="  ");
-    void findObject1(Inst* inst,std::string text="  ");
+/**
+ * Performs variable operands fixup after done optimizations. 
+ * @param irManager - IR manager.
+ */
+    void eaFixupVars(IRManager& irm);
+
+/**
+ * Outputs connection graph nodes information into the specified log. 
+ * @param text - output information naming,
+ * @param os - log.
+ */
+    void printCnGNodes(char* text,::std::ostream& os);
+
+/**
+ * Outputs connection graph node information into the specified log. 
+ * @param cgn - connection graph node,
+ * @param os - log.
+ */
+    void printCnGNode(CnGNode* cgn,::std::ostream& os);
+
+/**
+ * Creates string representing CnG node type. 
+ * @param cgn - connection graph node.
+ * @return srting representing CnG node type.
+ */
+    std::string nodeTypeToString(CnGNode* cgn);
+
+/**
+ * Outputs connection graph edges information into the specified log. 
+ * @param text - output information naming,
+ * @param os - log.
+ */
+    void printCnGEdges(char* text,::std::ostream& os); 
+
+/**
+ * Creates string representing CnG edge type. 
+ * @param cgn - connection graph node.
+ * @return srting representing CnG edge type.
+ */
+    std::string edgeTypeToString(CnGRef* edr);
+
+/**
+ * Outputs information about reference objects created in analyzed method into the specified
log. 
+ * @param os - log.
+ */
+    void printRefInfo(::std::ostream& os); 
+
+/**
+ * Outputs information about CnG node with all nodes it refers to. 
+ * @param cgn - connection graph node,
+ * @param text - text printed before CnG node information,
+ * @param os - log.
+ */
+    void printCnGNodeRefs(CnGNode* cgn, std::string text,::std::ostream& os);
+
+/**
+ * Outputs origin operands of specified instruction operands that aren't tau operand
+ * into the specified log.
+ * @param inst - instruction,
+ * @param text - text to print before the instruction,
+ * @param os - log.
+ */
     void lObjectHistory(Inst* inst,std::string text,::std::ostream& os);
-    uint32 getSubobjectStates(CnGNode* node);
+
+/**
+ * Outputs information about objects created in analyzed method into the specified log. 
+ * @param os - log.
+ */
+    void printCreatedObjectsInfo(::std::ostream& os);
+
+/**
+ * Outputs common information about created objects into log file. 
+ */
+    void createdObjectInfo();
+
+/**
+ * Prints origin operands of specified instruction operands.
+ * @param inst - instruction,
+ * @param text - text to print before the instruction.
+ */
+    void printOriginObject(Inst* inst,std::string text="  ");
+
+/**
+ * Prints origin operands of specified instruction main operand.
+ * @param inst - instruction,
+ * @param text - text to print before the instruction.
+ */
+    void printOriginObject1(Inst* inst,std::string text="  ");
+
+/**
+ * Prints escape analysis method information stored in common repository.
+ */
+    void printMethodInfos();
+
+/**
+ * Prints escape analysis method information for specified parameter.
+ * @param mi - method info from common repository.
+ */
+    void printMethodInfo(CalleeMethodInfo* mi);
+
+/**
+ * Outputs information about instruction kind into the specified log.
+ * @param inst - instruction,
+ * @param os - log.
+ */
+    void what_inst(Inst* inst,::std::ostream& os); 
+
+/**
+ * Outputs debug information about the specified type into the specified log.
+ * @param type - reference type,
+ * @param os - log.
+ */
+    void ref_type_info(Type* type,::std::ostream& os);
+
+/**
+ * Outputs debug information about the specified instruction into the specified log.
+ * @param inst - instruction,
+ * @param os - log.
+ */
+    void debug_inst_info(Inst* inst,::std::ostream& os);
+
+/**
+ * Outputs debug information about the specified operand into the specified log.
+ * @param opnd - operand,
+ * @param os - log.
+ */
+    void debug_opnd_info(Opnd* opnd,::std::ostream& os);
+
 
     bool checkScanned(ObjIds* ids, uint32 id) {
         ObjIds::iterator it;
@@ -371,10 +657,196 @@
             return true;
         return false;
     }
-    void runTranslatorSession(CompilationContext& inlineCC);
 
 
-    // Scalar replacement optimization
+// Monitors elimination optimization
+
+    struct MonUnit {
+        uint32 opndId;
+        Insts* monInsts;
+        Insts* icallInsts;
+    };
+    typedef StlList<MonUnit*> MonInstUnits; 
+    // list to collect info about monitor instruction operands
+    MonInstUnits* monitorInstUnits ;
+
+/**
+ * Adds monitor instruction to monitorInstUnits. 
+ * @param inst - monitor instruction.
+ */
+    void addMonInst(Inst* inst);
+
+/**
+ * Finds opndId specified monitor unit in monitorInstUnits. 
+ * @param opndId - monitor instruction operand Id.
+ * @return <code>MonUnit</code>, if found, or <code>NULL</code> otherwise.

+ */
+    MonUnit* findMonUnit(uint32 opndId);
+
+/**
+ * Adds call instruction to the specified monitor unit. 
+ * @param mu - monitor unit,
+ * @param inst - call instruction.
+ */
+    void addMonUnitVCall(MonUnit* mu, Inst* inst); 
+
+/**
+ * Checks, that method contains monitor instructions with parameter 
+ * which is <code>this</code> or subobject of this.
+ * @return <code>true</code>, if such monitors exist, or <code>false</code>
otherwise. 
+ */
+    bool checkMonitorsOnThis();
+
+/**
+ * Performs monitors elimination optimization. 
+ */
+    void scanSyncInsts();
+
+/**
+ * Marks (in CFG nodes bitset) nodes that are 'locked' by monitor instructions. 
+ * @param bs - CFG nodes bitset,
+ * @param syncInsts - list of monitor instruction for the same operand.
+ */
+    void markLockedNodes(BitSet* bs, Insts* syncInsts);
+
+ /**
+ * Marks (in CFG nodes bitset) nodes that are 'locked' by monitor instructions. 
+ * @param node - next CFG node to search monexit instruction,
+ * @param bs - CFG nodes bitset,
+ * @param moninstop - monitor instruction operand,
+ * @return <code>true</code>, if such monexit was found, or <code>false</code>
otherwise. 
+ */
+    bool markLockedNodes2(Node* node, BitSet* bs, Opnd* moninstop);
+
+/**
+ * Checks instruction source operand states for specified instruction. 
+ * @param inst - specified instruction,
+ * @param st - instruction target operand state.
+ * @return <code>GLOBAL_ESCAPE</code>, if any of source operand state is <code>GLOBAL_ESCAPE</code>,
+ *         <code>ARG_ESCAPE</code>, if any of source operand state or st is <code>ARG_ESCAPE</code>,
+ *         <code>NO_ESCAPE</code> otherwise.
+ */
+    uint32 checkState(Inst* inst,uint32 st);
+
+/**
+ * Checks if CnGNode operand is GLOBAL_ESCAPED while monitor instructions are executed. 
+ * @param node - specified operand CnGNode,
+ * @param syncInsts - list of monitor instructions for specified operand.
+ * @return <code>true</code>, specified operand is global, when monitor instruction
are executed,
+ *         <code>false</code>, otherwise.
+ */
+    bool checkSencEscState(CnGNode* node,Insts* syncInsts);
+
+/**
+ * Collects all reachable in FlowGraph nodes from the specified node to scannedSucNodes list.
+ * @param node - FlowGraph node,
+ * @param syncInsts - instruction target operand state.
+ */
+    void collectSuccessors(Node* node);
+
+/**
+ * Collects global node successors to scannedSucNodes list. 
+ * @param node - CnG node.
+ */
+    void collectGlobalNodeSuccessors(CnGNode* node);
+
+/**
+ * Returns state of object containing address for Op_TauStInd instruction.
+ * @param linst - Op_TauStInd instruction.
+ * @return object state.
+ */
+    uint32 getContainingObjState(Inst* linst);
+
+/**
+ * Inserts flag for specified monitor unit. Flag is set to 0 after operand creation instruction.
+ * Flag is set to 1 before call instruction from vcInsts list.
+ * Inserts flag check before monitor instruction from monInsts list.
+ * If flag is equal to 0, monitor instruction isn't executed.
+ * @param mu - monitor unit,
+ * @param bs - CFG nodes bitset (with marked nodes for specified monitor unit).
+ */
+    void fixMonitorInstsVCalls(MonUnit* mu, BitSet* bs);
+
+/**
+ * Inserts flag check before monitor instruction.
+ * If flag = 0 monitor instruction isn't executed.
+ * @param syncInsts - monitor instruction list,
+ * @param chk - value to check with (0 or 1),
+ * @param muflag - monitor flag operand (VarOpnd* or SsaTmpOpnd*).
+ */
+    void insertFlagCheck(Insts* syncInsts, Opnd* muflag, uint32 chk);
+
+/**
+ * Removes monitor instructions from the specified monitor instruction list.
+ * @param syncInsts - monitor instruction list.
+ */
+    void removeMonitorInsts(Insts* syncInsts);
+
+/**
+ * Removes flow graph node.
+ * @param node - flow graph node.
+ */
+    void removeNode(Node* node);
+
+/**
+ * Performs monitors elimination optimization for specified monitor instructions with 
+ * method <code>this</code> argument.
+ * @param syncInsts - monitor instruction list.
+ */
+    void fixSyncMethodMonitorInsts(Insts* syncInsts);
+
+/**
+ * Inserts ReadJitHelperCall instruction to read state of method <code>this</code>
argument
+ * after first instruction in entry block.
+ * @return <code>this</code> argument state 
+ *              0 - <code>this</code> argument is thread local, 
+ *              1 - <code>this</code> argument is thread global.
+ */
+    Opnd* insertReadJitHelperCall();
+
+/**
+ * Checks <code>this</code> argument of direct call synchronized methods.
+ * If the argument doesn't escape callee method, and actual argument isn't global,
+ * calls 'insertSaveJitHelperCall' to transfer <code>this</code> argument state

+ * to callee method.
+ */
+    void checkCallSyncMethod();
+
+/**
+ * Inserts SaveJitHelperCall instruction to store state of method <code>this</code>
argument
+ * before the specified instruction.
+ * @param inst_before - instruction to insert SaveJitHelperCall before,
+ * @param stVal - stored value.
+ */
+    void insertSaveJitHelperCall(Inst* inst_before, SsaTmpOpnd* stVal);
+
+/**
+ * Creates i32_0 or i32_1 SsaTmpOpnd (in accordance with value: 0 or 1)
+ * if it wasn't created before.
+ * Inserts ldc0 or ldc1 instruction after first instruction in entry Node, 
+ * if SsaTmpOpnd was created.
+ * @param value - 0 or 1.
+ * @return  i32_0, if value = 0
+ *          i32_1, if value = 1
+ */
+    SsaTmpOpnd* insertLdConst(uint32 value);
+
+
+
+// Scalar replacement optimization
+
+    struct ScObjFld {
+        VarOpnd* fldVarOpnd;
+        Insts* ls_insts;
+        FieldDesc* fd;
+        bool isFinalFld;
+    };
+    // list to collect scalarized object candidates
+    typedef StlList<ScObjFld*> ScObjFlds; 
+
+    // output stream for scalar replacement optimization
+    std::ostream& os_sc;
+
 /**
  * Performs scalar replacement optimization for local objects 
  * (class instances and arrays).
@@ -388,51 +860,59 @@
 
 /**
  * Performs scalar replacement optimization for local objects from the specified list.
- * @param loids - list of local objects CnG nodes Ids
- * @param os - output stream
+ * @param loids - list of local objects CnG nodes Ids,
  */
     void doLOScalarReplacement(ObjIds* loids);
 
 /**
  * Performs scalar replacement optimization for method escaped objects from the specified
list.
- * @param loids - list of local objects CnG nodes Ids
+ * @param loids - list of optimized objects CnG nodes Ids.
  */
     void doEOScalarReplacement(ObjIds* loids);
 
 /**
  * Collects (using connection graph) information of onode object fields usage.
  * @param onode - connection graph node fields usage of which is collected
- * @param scObjFlds - list to collect onode fields usage
+ * @param scObjFlds - list to collect onode field's usage.
  */
     void collectStLdInsts(CnGNode* onode, ScObjFlds* scObjFlds);
 
 /**
  * Collects (using connection graph) call instructions which use optimized object 
  * as a parameter.
- * @param n - optimized obgect connection graph node Id;
- * @param vc_insts - list of call instructions;
+ * @param n - optimized object connection graph node Id,
+ * @param vc_insts - list of call instructions,
  * @param vcids - list of call instructions ids.
  */
     void collectCallInsts(uint32 n, Insts* vc_insts, ObjIds* vcids);
 
 /**
  * Performs scalar replacement optimization for optimized object field usage.
- * @param scfld       - optimized object scalarizable field
+ * @param scfld - optimized object scalarizable field.
  */
     void scalarizeOFldUsage(ScObjFld* scfld);
 
 /**
  * Checks if an object from the specified list can be removed and its fields/elements scalarized.
  * If an object cannot be optimized it is removed from the list.
- * @param loids - list of local object CnG nodes Ids
+ * @param lnoids - list of new object CnG nodes Ids,
+ * @param lloids - list of load object CnG nodes Ids,
  * @param check_loc - if <code>true</code> checks for local objects,
  *                    if <code>false</code> checks for virtual call escaped objects.
  */
     void checkOpndUsage(ObjIds* lnoids, ObjIds* lloids, bool check_loc);
 
 /**
+ * Checks if a tau operand may be removed/replaced.
+ * @param tau_inst - object CnG nodes Ids.
+ * @return <code>true</code> if tau operand may be removed; 
+ *         <code>false<code> otherwise.
+ */
+    bool checkTauOpnd(Inst* tau_inst);
+
+/**
  * Checks if an object can be removed and its fields/elements scalarized.
- * @param lobjid - object CnG nodes Ids
+ * @param lobjid - object CnG nodes Ids.
  * @return <code>true</code> if an object is used only in ldflda or ldbase instructions;

  *         <code>false<code> otherwise.
  */
@@ -441,16 +921,16 @@
 /**
  * Performs checks for CnGNode operand using connection graph.
  * @param scnode - CnG node of optimized operand
- * @param check_loc - <true> * @param check_loc - if <code>true</code>
checks for local objects,
+ * @param check_loc - if <code>true</code> checks for local objects,
  *                    if <code>false</code> checks for virtual call escaped objects.
  * @return CnGNode* for operand that may be optimized; 
  *         <code>NULL<code> otherwise.
  */
-    CnGNode* checkCnG(CnGNode* scnode, bool check_loc);
+    CnGNode* checkCnGtoScalarize(CnGNode* scnode, bool check_loc);
 
 /**
- * Checks if there is a path in CFG from node where object created by a nob_inst instruction
- * to EXIT node and this object is not escaped to any method call.
+ * Checks if there is a path in CFG from node where object is created by a nob_inst instruction
+ * to EXIT node and this object is not escaped to any method call on this path.
  * @param nob_inst - object creation instruction.
  * @return <code>execCount</code> of this path execution; 
  *         <code>0<code> otherwise.
@@ -460,22 +940,22 @@
 /**
  * Checks if there is a path in CFG from node where object created by a nob_inst instruction
  * to EXIT node and this object is not escaped to any method call.
- * @param n - CFG node to scan
- * @param obId - escaped optimized object Id
- * @param cExecCount - current execCount
+ * @param n - CFG node to scan,
+ * @param obId - escaped optimized object Id,
+ * @param cExecCount - current execCount.
  * @return <code>execCount</code> the most value of <code>execCount</code>
and 
- *                                checkNextNodes execution for next after n node; 
+ *                                checkNextNodes execution for next after n node.
  */
-    double checkNextNodes(Node* n, uint32 obId, double cExecCount, std::string text="");
+    double checkNextNodes(Node* n, uint32 obId, double cExecCount);
 
 /**
  * Checks flag and creates object before call instruction (if it was not created yet).
- * @param vc_insts    - list of call instructions optimized object is escaped to
- * @param objs        - list of optimized object fields
- * @param ob_var_opnd -  varOpnd replacing optimized object
- * @param ob_flag_var_opnd - sign if optimized object was created
- * @param tnode       - target CFG node for newobj instruction exception edge
- * @param oid         - escaped optimized object Id 
+ * @param vc_insts    - list of call instructions optimized object is escaped to,
+ * @param objs        - list of optimized object fields,
+ * @param ob_var_opnd -  varOpnd replacing optimized object,
+ * @param ob_flag_var_opnd - sign if optimized object was created,
+ * @param tnode       - target CFG node for newobj instruction exception edge,
+ * @param oid         - escaped optimized object Id.
  */
     void restoreEOCreation(Insts* vc_insts, ScObjFlds* objs, VarOpnd* ob_var_opnd, 
         VarOpnd* ob_flag_var_opnd, Node* tnode, uint32 oid);
@@ -483,7 +963,7 @@
 /**
  * Removes specified instruction from ControlFlowGraph.
  * If instruction can throw exception removes corresponding CFGEdge.
- * @param reminst - removed instruction
+ * @param reminst - removed instruction.
  */
     void removeInst(Inst* reminst);
 
@@ -498,14 +978,14 @@
 /**
  * Replaces first source operand of Op_MethodEnd instruction by NULL
  * for scalar replacement optimized object.
- * @param ob_id - optimized object Id
+ * @param ob_id - optimized object Id.
  */
     void fixMethodEndInsts(uint32 ob_id);
 
 /**
  * Finds (using connection graph) load varOpnd that should be optimized with 
  * new object operand.
- * @param vval - CnG node of target stvar instruction varOpnd 
+ * @param vval - CnG node of target stvar instruction varOpnd.
  * @return CnGNode* - found optimized load varOpnd CnG node
  *         <code>NULL</code> otherwise.
  */
@@ -530,8 +1010,8 @@
 
 /**
  * Checks that all load varOpnd fields are in new object field usage list.
- * @param nscObjFlds - list of used fields of optimized new object
- * @param lscObjFlds - list of used fields of optimized load varOpnd
+ * @param nscObjFlds - list of used fields of optimized new object,
+ * @param lscObjFlds - list of used fields of optimized load varOpnd.
  * @return <code>true</code> if list of new object used field contains all 
  *                           load varOpnd used field; 
  *         <code>false<code> otherwise.
@@ -540,52 +1020,37 @@
 
 /**
  * Removes check instructions for optimized load varOpnd.
- * @param ob_id - optimized load variable operand Id
+ * @param ob_id - optimized load variable operand Id.
  */
     void fixCheckInsts(uint32 opId);
 
 /**
  * Checks (using connection graph) if CnGNode operand has final fields and adds it to
- * the list of posible optimized final fields operands.
- * @param onode - CnG node of optimized operand
- * @param scObjFlds - list to collect onode operand field usage
+ * the list of possible optimized final fields operands.
+ * @param onode - CnG node of optimized operand,
+ * @param scObjFlds - list to collect onode operand field usage.
  */
     void checkToScalarizeFinalFiels(CnGNode* onode, ScObjFlds* scObjFlds);
 
 
-    // BCMap support
+// BCMap support
+    // Byte code map info
+    bool isBCmapRequired;
+    VectorHandler* bc2HIRMapHandler;
 /**
  * Sets bcmap offset in bc2HIRMapHandler.
- * @param new_i - instruction to set offset
- * @param old_i - offset of old_i instruction is set to new_i instruction
+ * @param new_i - instruction to set offset,
+ * @param old_i - offset of old_i instruction is set to new_i instruction.
  */
     void setNewBCMap(Inst* new_i, Inst* old_i);
 
 /**
  * Removes bcmap offset in bc2HIRMapHandler.
- * @param inst - instruction to remove offset
+ * @param inst - instruction to remove offset.
  */
     void remBCMap(Inst* inst);
 
 
-    int _cfgirun;
-    int _instrInfo;
-    int _instrInfo2;
-    int _cngnodes;
-    int _cngedges;
-    int _scanMtds;
-    int _setState;
-    int _printstat;
-    int _eainfo;
-    int _seinfo;
-    int _scinfo;
-#define  prsNum  10
-    int prsArr[prsNum];
-
-    CompilationInterface &compInterface;
-    // Byte code map info
-    bool isBCmapRequired;
-    VectorHandler* bc2HIRMapHandler;
 };
 
 } //namespace Jitrino 



Mime
View raw message