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
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.
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
);
58 struct Page
: public PageHeader
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
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
76 BlockHist(avmplus::GC
*gc
) : BlockSortedMap(gc
)
79 uint32_t count(const void *p
) {
80 uint32_t c
= 1+get(p
);
89 * This is the main control center for creating and managing fragments.
91 class Fragmento
: public avmplus::GCFinalizedObject
94 Fragmento(AvmCore
* core
, uint32_t cacheSizeLog2
);
97 void addMemory(void* firstPage
, uint32_t pageCount
); // gives memory to the Assembler
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
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
); )
126 uint32_t pages
; // pages consumed
127 uint32_t maxPageUse
; // highwater mark of (pages-freePages)
128 uint32_t flushes
, ilsize
, abcsize
, compiles
, totalCompiles
;
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
);
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
);
144 void pagesGrow(int32_t count
);
148 DWB(Assembler
*) _assm
;
149 FragmentMap _frags
; /* map from ip -> Fragment ptr */
153 AllocList _allocList
;
154 avmplus::GCHeap
* _gcHeap
;
156 const uint32_t _max_pages
;
157 uint32_t _pagesGrowth
;
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
176 Fragment(const void*);
179 NIns
* code() { return _code
; }
180 void setCode(NIns
* codee
, Page
* pages
) { _code
= codee
; _pages
= pages
; }
181 int32_t& hits() { return _hits
; }
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; }
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
;
208 DWB(Fragment
*) parent
;
209 DWB(Fragment
*) first
;
211 DWB(LirBuffer
*) lirbuf
;
213 SideExit
* spawnedFrom
;
219 uint32_t recordAttempts
;
220 int32_t blacklistLevel
;
226 NIns
* _code
; // ptr to start of code
227 GuardRecord
* _links
; // code which is linked (or pending to be) to this fragment
229 Page
* _pages
; // native code pages
232 #endif // __nanojit_Fragmento__