1 /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
2 /* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is [Open Source Virtual Machine].
18 * The Initial Developer of the Original Code is
19 * Adobe System Incorporated.
20 * Portions created by the Initial Developer are Copyright (C) 2004-2007
21 * the Initial Developer. All Rights Reserved.
25 * Mozilla TraceMonkey Team
26 * Asko Tontti <atontti@cc.hut.fi>
28 * Alternatively, the contents of this file may be used under the terms of
29 * either the GNU General Public License Version 2 or later (the "GPL"), or
30 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
43 #ifndef __nanojit_Fragmento__
44 #define __nanojit_Fragmento__
51 * Fragments are linear sequences of native code that have a single entry
52 * point at the start of the fragment and may have one or more exit points
54 * It may turn out that that this arrangement causes too much traffic
55 * between d and i-caches and that we need to carve up the structure differently.
61 verbose_only(, uint32_t profFragID));
63 NIns* code() { return _code; }
64 void setCode(NIns* codee) { _code = codee; }
65 int32_t& hits() { return _hits; }
71 uint32_t recordAttempts;
74 // for fragment entry and exit profiling. See detailed
75 // how-to-use comment below.
76 verbose_only( LIns* loopLabel; ) // where's the loop top?
77 verbose_only( uint32_t profFragID; )
78 verbose_only( uint32_t profCount; )
79 verbose_only( uint32_t nStaticExits; )
80 verbose_only( size_t nCodeBytes; )
81 verbose_only( size_t nExitBytes; )
82 verbose_only( uint32_t guardNumberer; )
83 verbose_only( GuardRecord* guardsForFrag; )
86 NIns* _code; // ptr to start of code
92 * How to use fragment profiling
94 * Fragprofiling adds code to count how many times each fragment is
95 * entered, and how many times each guard (exit) is taken. Using this
96 * it's possible to easily find which fragments are hot, which ones
97 * typically exit early, etc. The fragprofiler also gathers some
98 * simple static info: for each fragment, the number of code bytes,
99 * number of exit-block bytes, and number of guards (exits).
101 * Fragments and guards are given unique IDs (FragID, GuardID) which
102 * are shown in debug printouts, so as to facilitate navigating from
103 * the accumulated statistics to the associated bits of code.
104 * GuardIDs are issued automatically, but FragIDs you must supply when
105 * calling Fragment::Fragment. Supply values >= 1, and supply a
106 * different value for each new fragment (doesn't matter what, they
107 * just have to be unique and >= 1); else
108 * js_FragProfiling_FragFinalizer will assert.
112 * - use a debug build (one with NJ_VERBOSE). Without it, none of
113 * this code is compiled in.
115 * - set LC_FragProfile in the lcbits of the LogControl* object handed
118 * When enabled, Fragment::profCount is incremented every time the
119 * fragment is entered, and GuardRecord::profCount is incremented
120 * every time that guard exits. However, NJ has no way to know where
121 * the fragment entry/loopback point is. So you must set
122 * Fragment::loopLabel before running the assembler, so as to indicate
123 * where the fragment-entry counter increment should be placed. If
124 * the fragment does not naturally have a loop label then you will
125 * need to artificially add one.
127 * It is the embedder's problem to fish out, collate and present the
128 * accumulated stats at the end of the Fragment's lifetime. A
129 * Fragment contains stats indicating its entry count and static code
130 * sizes. It also has a ::guardsForFrag field, which is a linked list
131 * of GuardRecords, and by traversing them you can get hold of the
135 #endif // __nanojit_Fragmento__