Bug 492301 - nanojit: remove some dead code. r=edwsmith
[mozilla-central.git] / js / src / nanojit / Fragmento.h
blobaab9d063e9f0414dc72f27ebe3eb7109b9557e36
1 /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is [Open Source Virtual Machine].
17 * The Initial Developer of the Original Code is
18 * Adobe System Incorporated.
19 * Portions created by the Initial Developer are Copyright (C) 2004-2007
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Adobe AS3 Team
24 * Mozilla TraceMonkey Team
25 * Asko Tontti <atontti@cc.hut.fi>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
42 #ifndef __nanojit_Fragmento__
43 #define __nanojit_Fragmento__
45 #ifdef AVMPLUS_VERBOSE
46 extern void drawTraceTrees(Fragmento *frago, FragmentMap * _frags, avmplus::AvmCore *core, char *fileName);
47 #endif
49 namespace nanojit
51 struct GuardRecord;
52 class Assembler;
54 struct PageHeader
56 struct Page *next;
58 struct Page: public PageHeader
60 union {
61 LIns lir[(NJ_PAGE_SIZE-sizeof(PageHeader))/sizeof(LIns)];
62 NIns code[(NJ_PAGE_SIZE-sizeof(PageHeader))/sizeof(NIns)];
65 struct AllocEntry : public avmplus::GCObject
67 Page *page;
68 uint32_t allocSize;
70 typedef avmplus::List<AllocEntry*,avmplus::LIST_NonGCObjects> AllocList;
72 typedef avmplus::GCSortedMap<const void*, uint32_t, avmplus::LIST_NonGCObjects> BlockSortedMap;
73 class BlockHist: public BlockSortedMap
75 public:
76 BlockHist(avmplus::GC*gc) : BlockSortedMap(gc)
79 uint32_t count(const void *p) {
80 uint32_t c = 1+get(p);
81 put(p, c);
82 return c;
86 struct fragstats;
89 * This is the main control center for creating and managing fragments.
91 class Fragmento : public avmplus::GCFinalizedObject
93 public:
94 Fragmento(AvmCore* core, uint32_t cacheSizeLog2);
95 ~Fragmento();
97 void addMemory(void* firstPage, uint32_t pageCount); // gives memory to the Assembler
98 Assembler* assm();
99 AvmCore* core();
100 Page* pageAlloc();
101 void pageFree(Page* page);
102 void pagesRelease(PageList& list);
104 Fragment* getLoop(const void* ip);
105 Fragment* getAnchor(const void* ip);
106 // Remove one fragment. The caller is responsible for making sure
107 // that this does not destroy any resources shared with other
108 // fragments (such as a LirBuffer or this fragment itself as a
109 // jump target).
110 void clearFrags(); // clear all fragments from the cache
111 Fragment* createBranch(SideExit *exit, const void* ip);
112 Fragment* newFrag(const void* ip);
113 Fragment* newBranch(Fragment *from, const void* ip);
115 verbose_only ( uint32_t pageCount(); )
116 verbose_only ( void dumpStats(); )
117 verbose_only ( void dumpRatio(const char*, BlockHist*);)
118 verbose_only ( void dumpFragStats(Fragment*, int level, fragstats&); )
119 verbose_only ( void countBlock(BlockHist*, const void* pc); )
120 verbose_only ( void countIL(uint32_t il, uint32_t abc); )
121 verbose_only( void addLabel(Fragment* f, const char *prefix, int id); )
123 // stats
124 struct
126 uint32_t pages; // pages consumed
127 uint32_t maxPageUse; // highwater mark of (pages-freePages)
128 uint32_t flushes, ilsize, abcsize, compiles, totalCompiles;
130 _stats;
132 verbose_only( DWB(BlockHist*) enterCounts; )
133 verbose_only( DWB(BlockHist*) mergeCounts; )
134 verbose_only( DWB(LabelMap*) labels; )
136 #ifdef AVMPLUS_VERBOSE
137 void drawTrees(char *fileName);
138 #endif
140 uint32_t cacheUsed() const { return (_stats.pages-_freePages.size())<<NJ_LOG2_PAGE_SIZE; }
141 uint32_t cacheUsedMax() const { return (_stats.maxPageUse)<<NJ_LOG2_PAGE_SIZE; }
142 void clearFragment(Fragment *f);
143 private:
144 void pagesGrow(int32_t count);
145 void trackPages();
147 AvmCore* _core;
148 DWB(Assembler*) _assm;
149 FragmentMap _frags; /* map from ip -> Fragment ptr */
150 PageList _freePages;
152 /* unmanaged mem */
153 AllocList _allocList;
154 avmplus::GCHeap* _gcHeap;
156 const uint32_t _max_pages;
157 uint32_t _pagesGrowth;
160 enum TraceKind {
161 LoopTrace,
162 BranchTrace,
163 MergeTrace
167 * Fragments are linear sequences of native code that have a single entry
168 * point at the start of the fragment and may have one or more exit points
170 * It may turn out that that this arrangement causes too much traffic
171 * between d and i-caches and that we need to carve up the structure differently.
173 class Fragment : public avmplus::GCFinalizedObject
175 public:
176 Fragment(const void*);
177 ~Fragment();
179 NIns* code() { return _code; }
180 void setCode(NIns* codee, Page* pages) { _code = codee; _pages = pages; }
181 int32_t& hits() { return _hits; }
182 void blacklist();
183 bool isBlacklisted() { return _hits < 0; }
184 void releaseLirBuffer();
185 void releaseCode(Fragmento* frago);
186 void releaseTreeMem(Fragmento* frago);
187 bool isAnchor() { return anchor == this; }
188 bool isRoot() { return root == this; }
189 void onDestroy();
191 verbose_only( uint32_t _called; )
192 verbose_only( uint32_t _native; )
193 verbose_only( uint32_t _exitNative; )
194 verbose_only( uint32_t _lir; )
195 verbose_only( uint32_t _lirbytes; )
196 verbose_only( const char* _token; )
197 verbose_only( uint64_t traceTicks; )
198 verbose_only( uint64_t interpTicks; )
199 verbose_only( DWB(Fragment*) eot_target; )
200 verbose_only( uint32_t sid;)
201 verbose_only( uint32_t compileNbr;)
203 DWB(Fragment*) treeBranches;
204 DWB(Fragment*) branches;
205 DWB(Fragment*) nextbranch;
206 DWB(Fragment*) anchor;
207 DWB(Fragment*) root;
208 DWB(Fragment*) parent;
209 DWB(Fragment*) first;
210 DWB(Fragment*) peer;
211 DWB(LirBuffer*) lirbuf;
212 LIns* lastIns;
213 SideExit* spawnedFrom;
215 TraceKind kind;
216 const void* ip;
217 uint32_t guardCount;
218 uint32_t xjumpCount;
219 uint32_t recordAttempts;
220 int32_t blacklistLevel;
221 NIns* fragEntry;
222 NIns* loopEntry;
223 void* vmprivate;
225 private:
226 NIns* _code; // ptr to start of code
227 GuardRecord* _links; // code which is linked (or pending to be) to this fragment
228 int32_t _hits;
229 Page* _pages; // native code pages
232 #endif // __nanojit_Fragmento__