Bug 469739 - Add support for displaying Vista UAC shield icon; r=joe sr=vladimir
[wine-gecko.git] / js / src / nanojit / Fragmento.h
bloba01f6ad591d2ab9b88cccca43f0f771a8a740d14
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 clearFrag(const void* ip);
111 void clearFrags(); // clear all fragments from the cache
112 Fragment* getMerge(GuardRecord *lr, const void* ip);
113 Fragment* createBranch(SideExit *exit, const void* ip);
114 Fragment* newFrag(const void* ip);
115 Fragment* newBranch(Fragment *from, const void* ip);
117 verbose_only ( uint32_t pageCount(); )
118 verbose_only ( void dumpStats(); )
119 verbose_only ( void dumpRatio(const char*, BlockHist*);)
120 verbose_only ( void dumpFragStats(Fragment*, int level, fragstats&); )
121 verbose_only ( void countBlock(BlockHist*, const void* pc); )
122 verbose_only ( void countIL(uint32_t il, uint32_t abc); )
123 verbose_only( void addLabel(Fragment* f, const char *prefix, int id); )
125 // stats
126 struct
128 uint32_t pages; // pages consumed
129 uint32_t maxPageUse; // highwater mark of (pages-freePages)
130 uint32_t flushes, ilsize, abcsize, compiles, totalCompiles;
132 _stats;
134 verbose_only( DWB(BlockHist*) enterCounts; )
135 verbose_only( DWB(BlockHist*) mergeCounts; )
136 verbose_only( DWB(LabelMap*) labels; )
138 #ifdef AVMPLUS_VERBOSE
139 void drawTrees(char *fileName);
140 #endif
142 uint32_t cacheUsed() const { return (_stats.pages-_freePages.size())<<NJ_LOG2_PAGE_SIZE; }
143 uint32_t cacheUsedMax() const { return (_stats.maxPageUse)<<NJ_LOG2_PAGE_SIZE; }
144 private:
145 void clearFragment(Fragment *f);
146 void pagesGrow(int32_t count);
147 void trackPages();
149 AvmCore* _core;
150 DWB(Assembler*) _assm;
151 FragmentMap _frags; /* map from ip -> Fragment ptr */
152 PageList _freePages;
154 /* unmanaged mem */
155 AllocList _allocList;
156 avmplus::GCHeap* _gcHeap;
158 const uint32_t _max_pages;
159 uint32_t _pagesGrowth;
162 enum TraceKind {
163 LoopTrace,
164 BranchTrace,
165 MergeTrace
169 * Fragments are linear sequences of native code that have a single entry
170 * point at the start of the fragment and may have one or more exit points
172 * It may turn out that that this arrangement causes too much traffic
173 * between d and i-caches and that we need to carve up the structure differently.
175 class Fragment : public avmplus::GCFinalizedObject
177 public:
178 Fragment(const void*);
179 ~Fragment();
181 NIns* code() { return _code; }
182 void setCode(NIns* codee, Page* pages) { _code = codee; _pages = pages; }
183 GuardRecord* links() { return _links; }
184 int32_t& hits() { return _hits; }
185 void resetHits();
186 void blacklist();
187 bool isBlacklisted() { return _hits < 0; }
188 debug_only( bool hasOnlyTreeLinks(); )
189 void releaseLirBuffer();
190 void releaseCode(Fragmento* frago);
191 void releaseTreeMem(Fragmento* frago);
192 bool isAnchor() { return anchor == this; }
193 bool isRoot() { return root == this; }
194 void onDestroy();
196 verbose_only( uint32_t _called; )
197 verbose_only( uint32_t _native; )
198 verbose_only( uint32_t _exitNative; )
199 verbose_only( uint32_t _lir; )
200 verbose_only( uint32_t _lirbytes; )
201 verbose_only( const char* _token; )
202 verbose_only( uint64_t traceTicks; )
203 verbose_only( uint64_t interpTicks; )
204 verbose_only( DWB(Fragment*) eot_target; )
205 verbose_only( uint32_t sid;)
206 verbose_only( uint32_t compileNbr;)
208 DWB(Fragment*) treeBranches;
209 DWB(Fragment*) branches;
210 DWB(Fragment*) nextbranch;
211 DWB(Fragment*) anchor;
212 DWB(Fragment*) root;
213 DWB(Fragment*) parent;
214 DWB(Fragment*) first;
215 DWB(Fragment*) peer;
216 DWB(LirBuffer*) lirbuf;
217 LIns* lastIns;
218 SideExit* spawnedFrom;
220 TraceKind kind;
221 const void* ip;
222 uint32_t guardCount;
223 uint32_t xjumpCount;
224 uint32_t recordAttempts;
225 int32_t blacklistLevel;
226 NIns* fragEntry;
227 NIns* loopEntry;
228 void* vmprivate;
230 private:
231 NIns* _code; // ptr to start of code
232 GuardRecord* _links; // code which is linked (or pending to be) to this fragment
233 int32_t _hits;
234 Page* _pages; // native code pages
237 #endif // __nanojit_Fragmento__