00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 # ifdef DELTA_COMPILER
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 class Scope;
00040 class InlinedScope;
00041 class MethodScope;
00042 class BlockScope;
00043 class OutlinedScope;
00044 class OutlinedMethodScope;
00045 class OutlinedBlockScope;
00046
00047
00048
00049
00050
00051 class SendInfo: public PrintableResourceObj {
00052 public:
00053 InlinedScope* senderScope;
00054 Expr* rcvr;
00055 LookupKey* key;
00056 symbolOop sel;
00057 PReg* resReg;
00058 bool needRealSend;
00059 bool counting;
00060 int nsends;
00061 bool predicted;
00062 bool uninlinable;
00063 bool receiverStatic;
00064 bool inPrimFailure;
00065
00066 protected:
00067 void init();
00068
00069 public:
00070 SendInfo(InlinedScope* sen, Expr* r, symbolOop s) {
00071 senderScope = sen; rcvr = r; sel = s; key = NULL;
00072 init();
00073 }
00074
00075 SendInfo(InlinedScope* sen, LookupKey* lkup, Expr* r);
00076 void computeNSends(RScope* rscope, int bci);
00077
00078 void print();
00079 };
00080
00081
00082
00083
00084 class Scope : public PrintableResourceObj {
00085 private:
00086 static smi _currentScopeID;
00087
00088 public:
00089
00090 static void initialize() { _currentScopeID = 0; }
00091 smi currentScopeID() { return _currentScopeID++; }
00092 virtual smi scopeID() const = 0;
00093
00094
00095 virtual bool isInlinedScope() const { return false; }
00096 virtual bool isMethodScope() const { return false; }
00097 virtual bool isBlockScope() const { return false; }
00098 virtual bool isOutlinedScope() const { return false; }
00099 virtual bool isOutlinedMethodScope() const { return false; }
00100 virtual bool isOutlinedBlockScope() const { return false; }
00101
00102 virtual klassOop selfKlass() const = 0;
00103 virtual symbolOop selector() const = 0;
00104 virtual methodOop method() const = 0;
00105 virtual Scope* parent() const = 0;
00106 virtual InlinedScope* sender() const = 0;
00107 virtual klassOop methodHolder() const = 0;
00108
00109 virtual bool allocatesInterpretedContext() const = 0;
00110 virtual bool allocatesCompiledContext() const = 0;
00111 virtual bool expectsContext() const = 0;
00112 bool needsContextZapping() const { return (parent() == NULL) && allocatesCompiledContext(); }
00113
00114 virtual Scope* home() const = 0;
00115 bool isTop() const { return sender() == NULL; }
00116 bool isInlined() const { return sender() != NULL; }
00117 virtual bool isSenderOf(InlinedScope* s) const { return false; }
00118 bool isSenderOrSame(InlinedScope* s) { return (Scope*)s == this || isSenderOf(s); }
00119
00120 virtual bool isRecursiveCall(methodOop method, klassOop rcvrKlass, int n) = 0;
00121 virtual void genCode() { ShouldNotCallThis(); }
00122 };
00123
00124
00125 class InlinedScope: public Scope {
00126 protected:
00127 int _scopeID;
00128 InlinedScope* _sender;
00129 int _senderBCI;
00130 ScopeInfo _scopeInfo;
00131 LookupKey* _key;
00132 klassOop _methodHolder;
00133 methodOop _method;
00134 int _nofSends;
00135 int _nofInterruptPoints;
00136
00137 bool _primFailure;
00138 bool _endsDead;
00139 Expr* _self;
00140 NodeBuilder _gen;
00141
00142 PReg* _context;
00143 GrowableArray<Expr*>* _arguments;
00144 GrowableArray<Expr*>* _temporaries;
00145 GrowableArray<Expr*>* _floatTemporaries;
00146 GrowableArray<Expr*>* _contextTemporaries;
00147 GrowableArray<Expr*>* _exprStackElems;
00148 GrowableArray<InlinedScope*>* _subScopes;
00149 GrowableArray<CompiledLoop*>* _loops;
00150 GrowableArray<NonTrivialNode*>* _typeTests;
00151
00152 GrowableArray<PReg*>* _pregsBegSorted;
00153 GrowableArray<PReg*>* _pregsEndSorted;
00154
00155
00156 int _firstFloatIndex;
00157
00158
00159 MergeNode* _returnPoint;
00160 MergeNode* _NLReturnPoint;
00161 MergeNode* _nlrTestPoint;
00162 ContextInitNode* _contextInitializer;
00163 bool _hasBeenGenerated;
00164
00165 public:
00166
00167 MergeNode* returnPoint() { return _returnPoint; }
00168 MergeNode* nlrPoint() { return _NLReturnPoint; }
00169 MergeNode* nlrTestPoint();
00170 ContextInitNode* contextInitializer() { return _contextInitializer; }
00171 bool has_nlrTestPoint() { return _nlrTestPoint != NULL; }
00172 void set_contextInitializer(ContextInitNode* n) { _contextInitializer = n; }
00173
00174 public:
00175 RScope* rscope;
00176 bool predicted;
00177 int depth;
00178 int loopDepth;
00179 Expr* result;
00180 Expr* nlrResult;
00181 PReg* resultPR;
00182
00183 protected:
00184 InlinedScope();
00185 void initialize(methodOop method, klassOop methodHolder, InlinedScope* sender, RScope* rs, SendInfo* info);
00186
00187 public:
00188 int scopeID() const { return _scopeID; }
00189 InlinedScope* sender() const { return _sender; }
00190 int senderBCI() const { return _senderBCI; }
00191 ScopeInfo scopeInfo() const { return _scopeInfo; }
00192 virtual int bci() const { return gen()->bci(); }
00193 bool isInlinedScope() const { return true; }
00194 int nofArguments() const { return _arguments->length(); }
00195 bool hasTemporaries() const { return _temporaries != NULL; }
00196 int nofTemporaries() const { return _temporaries->length(); }
00197 bool hasFloatTemporaries() const { return _floatTemporaries != NULL; }
00198 int nofFloatTemporaries() const { return _floatTemporaries->length(); }
00199 int firstFloatIndex() const { assert(_firstFloatIndex >= 0, "not yet computed"); return _firstFloatIndex; }
00200 bool allocatesInterpretedContext() const { return _method->allocatesInterpretedContext(); }
00201 bool allocatesCompiledContext() const;
00202 bool expectsContext() const { return _method->expectsContext(); }
00203 bool isSenderOf(InlinedScope* s) const;
00204
00205 GrowableArray<Expr*>* contextTemporaries() const { return _contextTemporaries; }
00206 int nofBytes() const { return _method->end_bci() - 1; }
00207 int nofSends() const { return _nofSends; }
00208 bool containsNLR() const { return _method->containsNLR(); }
00209 bool primFailure() const { return _primFailure; }
00210 Expr* self() const { return _self; }
00211 void set_self(Expr* e);
00212 NodeBuilder* gen() const { return (NodeBuilder*const)&_gen; }
00213
00214 GrowableArray<Expr*>* exprStackElems() const { return _exprStackElems; }
00215 void addSubScope(InlinedScope* s);
00216
00217 klassOop selfKlass() const { return _key->klass(); }
00218 LookupKey* key() const { return _key; }
00219 klassOop methodHolder() const { return _methodHolder; }
00220 methodOop method() const { return _method; }
00221 symbolOop selector() const { return _key->selector(); }
00222 bool isLite() const;
00223 Expr* argument(int no) const { return _arguments->at(no); }
00224 Expr* temporary(int no) const { return _temporaries->at(no); }
00225 Expr* floatTemporary(int no) const { return _floatTemporaries->at(no); }
00226 void set_temporary(int no, Expr* t) { _temporaries->at_put(no, t); }
00227 Expr* contextTemporary(int no) const { return _contextTemporaries->at(no); }
00228 PReg* context() const { return _context; }
00229 void setContext(PReg* ctx) { _context = ctx; }
00230 ExprStack* exprStack() const { return gen()->exprStack(); }
00231 Node* current() const { return gen()->current(); }
00232 virtual bool is_self_initialized() const { return true; }
00233 virtual void set_self_initialized() { ShouldNotCallThis(); }
00234 bool hasBeenGenerated() const { return _hasBeenGenerated; }
00235
00236 void createTemporaries(int nofTemps);
00237 void createFloatTemporaries(int nofFloats);
00238 void createContextTemporaries(int nofTemps);
00239 void contextTemporariesAtPut(int no, Expr* e);
00240 int homeContext() const;
00241 InlinedScope* find_scope(int context, int& nofIndirections, OutlinedScope*& out);
00242 void addResult(Expr* e);
00243
00244 void genCode();
00245 void addSend(GrowableArray<PReg*>* exprStack, bool isSend);
00246 GrowableArray<NonTrivialNode*>* typeTests() const { return _typeTests; }
00247 GrowableArray<CompiledLoop*>* loops() const { return _loops; }
00248 void addTypeTest(NonTrivialNode* t);
00249 CompiledLoop* addLoop();
00250
00251 void setExprForBCI(int bci, Expr* expr);
00252 void set2ndExprForBCI(int bci, Expr* expr);
00253
00254 virtual void collectContextInfo(GrowableArray<InlinedScope*>* scopeList);
00255 virtual void generateDebugInfo();
00256 void generateDebugInfoForNonInlinedBlocks();
00257 void optimizeLoops();
00258 void subScopesDo(Closure<InlinedScope*>* c);
00259
00260 protected:
00261 void initializeArguments();
00262 virtual void initializeSelf() {}
00263 virtual void prologue();
00264 virtual void epilogue();
00265
00266 public:
00267 int descOffset();
00268
00269 protected:
00270
00271 void markLocalsDebugVisible(GrowableArray<PReg*>* exprStack);
00272
00273 public:
00274
00275 void addToPRegsBegSorted(PReg* r);
00276 void addToPRegsEndSorted(PReg* r);
00277 void allocatePRegs(IntFreeList* f);
00278 int allocateFloatTemporaries(int firstFloatIndex);
00279
00280 public:
00281 void print();
00282 void printTree();
00283
00284
00285 int number_of_noninlined_blocks();
00286
00287 void copy_noninlined_block_info(nmethod* nm);
00288
00289 friend class OutlinedScope;
00290 };
00291
00292
00293 class MethodScope: public InlinedScope {
00294 protected:
00295 MethodScope();
00296 void initialize(methodOop method, klassOop methodHolder, InlinedScope* sen, RScope* rs, SendInfo* info);
00297 public:
00298 static MethodScope* new_MethodScope(methodOop method, klassOop methodHolder, InlinedScope* sen, RScope* rs, SendInfo* info);
00299
00300 bool isMethodScope() const { return true; }
00301 Scope* parent() const { return NULL; }
00302 Scope* home() const { return (Scope*)this; }
00303
00304 bool isRecursiveCall(methodOop method, klassOop rcvrKlass, int n);
00305
00306 void generateDebugInfo();
00307
00308
00309 void print_short();
00310 void print();
00311 };
00312
00313
00314 class BlockScope: public InlinedScope {
00315 protected:
00316 Scope* _parent;
00317 bool _self_is_initialized;
00318 void initialize(methodOop method, klassOop methodHolder, Scope* p, InlinedScope* s, RScope* rs, SendInfo* info);
00319 void initializeSelf();
00320 BlockScope();
00321
00322 public:
00323 static BlockScope* new_BlockScope(methodOop method, klassOop methodHolder, Scope* p, InlinedScope* s, RScope* rs,
00324 SendInfo* info);
00325
00326 bool isBlockScope() const { return true; }
00327 bool is_self_initialized() const { return _self_is_initialized; }
00328 void set_self_initialized() { _self_is_initialized = true; }
00329
00330 Scope* parent() const { return _parent; }
00331 Scope* home() const { return _parent->home(); }
00332 klassOop selfKlass() const { return _parent->selfKlass(); }
00333 bool isRecursiveCall(methodOop method, klassOop rcvrKlass, int n);
00334
00335 void generateDebugInfo();
00336
00337
00338 void print_short();
00339 void print();
00340 };
00341
00342
00343 class OutlinedScope: public Scope {
00344 protected:
00345 nmethod* _nm;
00346 ScopeDesc* _scope;
00347
00348 public:
00349 OutlinedScope(nmethod* nm, ScopeDesc* scope);
00350 bool isOutlinedScope() const { return true; }
00351 symbolOop selector() const { return _scope->selector(); }
00352 Expr* receiverExpr(PReg* p) const;
00353 methodOop method() const;
00354 nmethod* nm() const { return _nm; }
00355 InlinedScope* sender() const { return NULL; }
00356 ScopeDesc* scope() const { return _scope; }
00357 bool allocatesInterpretedContext() const { return method()->allocatesInterpretedContext(); }
00358 bool allocatesCompiledContext() const { return _scope->allocates_compiled_context(); }
00359 bool expectsContext() const { return method()->expectsContext(); }
00360
00361
00362 void print_short(char* name);
00363 void print(char* name);
00364 };
00365
00366 OutlinedScope* new_OutlinedScope(nmethod* nm, ScopeDesc* sc);
00367
00368
00369 class OutlinedMethodScope: public OutlinedScope {
00370 public:
00371 OutlinedMethodScope(nmethod* nm, ScopeDesc* s) : OutlinedScope(nm, s) {}
00372
00373 bool isOutlinedMethodScope() const { return true; }
00374 bool isRecursiveCall(methodOop method, klassOop rcvrKlass, int n) { ShouldNotCallThis(); return false; }
00375 klassOop selfKlass() const { return _scope->selfKlass(); }
00376 smi scopeID() const { return _scope->scopeID(); }
00377 Scope* parent() const { return NULL; }
00378 Scope* home() const { return (Scope*)this; }
00379 klassOop methodHolder() const;
00380
00381
00382 void print_short();
00383 void print();
00384 };
00385
00386
00387 class OutlinedBlockScope: public OutlinedScope {
00388 protected:
00389 OutlinedScope* _parent;
00390
00391 public:
00392 OutlinedBlockScope(nmethod* nm, ScopeDesc* sen);
00393
00394 bool isOutlinedBlockScope() const { return true; }
00395 bool isRecursiveCall(methodOop method, klassOop rcvrKlass, int n) { ShouldNotCallThis(); return false; }
00396 Scope* parent() const { return _parent; }
00397 Scope* home() const { return _parent ? _parent->home() : NULL; }
00398 klassOop selfKlass() const { return _parent->selfKlass(); }
00399 smi scopeID() const { return _scope->scopeID(); }
00400 klassOop methodHolder() const { return _parent->methodHolder(); }
00401
00402
00403 void print_short();
00404 void print();
00405 };
00406
00407
00408 # endif