Bug 625718: Correct SETPROP label offsets. (r=jbramley)
[mozilla-central.git] / js / src / methodjit / Retcon.h
blobd07409beb0e502f16607b80a28152ffc77dd0643
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=4 sw=4 et tw=99:
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
15 * License.
17 * The Original Code is Mozilla Jaegermonkey.
19 * The Initial Developer of the Original Code is the Mozilla Foundation.
21 * Portions created by the Initial Developer are Copyright (C) 2010
22 * the Initial Developer. All Rights Reserved.
24 * Contributor(s):
25 * Andrew Drake <drakedevel@gmail.com>
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 * Retroactive continuity ("retcon") refers to the retroactive modification
43 * or reinterpretation of established facts.
46 #if !defined jsjaeger_retcon_h__ && defined JS_METHODJIT
47 #define jsjaeger_retcon_h__
49 #include "jscntxt.h"
50 #include "jsscript.h"
51 #include "MethodJIT.h"
52 #include "Compiler.h"
54 namespace js {
55 namespace mjit {
58 * A problem often arises where, for one reason or another, a piece of code
59 * wants to touch the script->code, but isn't expecting JSOP_TRAP. This allows
60 * one to temporarily remove JSOP_TRAPs from the instruction stream (without
61 * copying) and automatically re-add them on scope exit.
63 class AutoScriptRetrapper
65 public:
66 AutoScriptRetrapper(JSContext *cx1, JSScript *script1) :
67 cx(cx1), script(script1), traps(cx) {};
68 ~AutoScriptRetrapper();
70 bool untrap(jsbytecode *pc);
72 private:
73 JSContext *cx;
74 JSScript *script;
75 Vector<jsbytecode*> traps;
79 * This class is responsible for sanely re-JITing a script and fixing up
80 * the world. If you ever change the code associated with a JSScript, or
81 * otherwise would cause existing JITed code to be incorrect, you /must/ use
82 * this to invalidate and potentially re-compile the existing JITed code,
83 * fixing up the stack in the process.
85 class Recompiler {
86 struct PatchableAddress {
87 void **location;
88 CallSite callSite;
91 public:
92 Recompiler(JSContext *cx, JSScript *script);
94 bool recompile();
96 private:
97 JSContext *cx;
98 JSScript *script;
100 PatchableAddress findPatch(JITScript *jit, void **location);
101 void applyPatch(Compiler& c, PatchableAddress& toPatch);
102 bool recompile(JSStackFrame *fp, Vector<PatchableAddress> &patches,
103 Vector<CallSite> &sites);
104 bool saveTraps(JITScript *jit, Vector<CallSite> *sites);
107 } /* namespace mjit */
108 } /* namespace js */
110 #endif