js/src/jit/Ion.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit/Ion.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,200 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99:
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef jit_Ion_h
    1.11 +#define jit_Ion_h
    1.12 +
    1.13 +#ifdef JS_ION
    1.14 +
    1.15 +#include "mozilla/MemoryReporting.h"
    1.16 +
    1.17 +#include "jscntxt.h"
    1.18 +#include "jscompartment.h"
    1.19 +
    1.20 +#include "jit/CompileInfo.h"
    1.21 +#include "jit/CompileWrappers.h"
    1.22 +#include "jit/JitOptions.h"
    1.23 +
    1.24 +namespace js {
    1.25 +namespace jit {
    1.26 +
    1.27 +class TempAllocator;
    1.28 +
    1.29 +enum MethodStatus
    1.30 +{
    1.31 +    Method_Error,
    1.32 +    Method_CantCompile,
    1.33 +    Method_Skipped,
    1.34 +    Method_Compiled
    1.35 +};
    1.36 +
    1.37 +enum AbortReason {
    1.38 +    AbortReason_Alloc,
    1.39 +    AbortReason_Inlining,
    1.40 +    AbortReason_Disable,
    1.41 +    AbortReason_Error,
    1.42 +    AbortReason_NoAbort
    1.43 +};
    1.44 +
    1.45 +// An Ion context is needed to enter into either an Ion method or an instance
    1.46 +// of the Ion compiler. It points to a temporary allocator and the active
    1.47 +// JSContext, either of which may be nullptr, and the active compartment, which
    1.48 +// will not be nullptr.
    1.49 +
    1.50 +class IonContext
    1.51 +{
    1.52 +  public:
    1.53 +    IonContext(JSContext *cx, TempAllocator *temp);
    1.54 +    IonContext(ExclusiveContext *cx, TempAllocator *temp);
    1.55 +    IonContext(CompileRuntime *rt, CompileCompartment *comp, TempAllocator *temp);
    1.56 +    IonContext(CompileRuntime *rt);
    1.57 +    ~IonContext();
    1.58 +
    1.59 +    // Running context when executing on the main thread. Not available during
    1.60 +    // compilation.
    1.61 +    JSContext *cx;
    1.62 +
    1.63 +    // Allocator for temporary memory during compilation.
    1.64 +    TempAllocator *temp;
    1.65 +
    1.66 +    // Wrappers with information about the current runtime/compartment for use
    1.67 +    // during compilation.
    1.68 +    CompileRuntime *runtime;
    1.69 +    CompileCompartment *compartment;
    1.70 +
    1.71 +    int getNextAssemblerId() {
    1.72 +        return assemblerCount_++;
    1.73 +    }
    1.74 +  private:
    1.75 +    IonContext *prev_;
    1.76 +    int assemblerCount_;
    1.77 +};
    1.78 +
    1.79 +// Initialize Ion statically for all JSRuntimes.
    1.80 +bool InitializeIon();
    1.81 +
    1.82 +// Get and set the current Ion context.
    1.83 +IonContext *GetIonContext();
    1.84 +IonContext *MaybeGetIonContext();
    1.85 +
    1.86 +void SetIonContext(IonContext *ctx);
    1.87 +
    1.88 +bool CanIonCompileScript(JSContext *cx, JSScript *script, bool osr);
    1.89 +
    1.90 +MethodStatus CanEnterAtBranch(JSContext *cx, JSScript *script,
    1.91 +                              BaselineFrame *frame, jsbytecode *pc, bool isConstructing);
    1.92 +MethodStatus CanEnter(JSContext *cx, RunState &state);
    1.93 +MethodStatus CompileFunctionForBaseline(JSContext *cx, HandleScript script, BaselineFrame *frame,
    1.94 +                                        bool isConstructing);
    1.95 +MethodStatus CanEnterUsingFastInvoke(JSContext *cx, HandleScript script, uint32_t numActualArgs);
    1.96 +
    1.97 +MethodStatus CanEnterInParallel(JSContext *cx, HandleScript script);
    1.98 +
    1.99 +MethodStatus
   1.100 +Recompile(JSContext *cx, HandleScript script, BaselineFrame *osrFrame, jsbytecode *osrPc,
   1.101 +          bool constructing);
   1.102 +
   1.103 +enum IonExecStatus
   1.104 +{
   1.105 +    // The method call had to be aborted due to a stack limit check. This
   1.106 +    // error indicates that Ion never attempted to clean up frames.
   1.107 +    IonExec_Aborted,
   1.108 +
   1.109 +    // The method call resulted in an error, and IonMonkey has cleaned up
   1.110 +    // frames.
   1.111 +    IonExec_Error,
   1.112 +
   1.113 +    // The method call succeeed and returned a value.
   1.114 +    IonExec_Ok
   1.115 +};
   1.116 +
   1.117 +static inline bool
   1.118 +IsErrorStatus(IonExecStatus status)
   1.119 +{
   1.120 +    return status == IonExec_Error || status == IonExec_Aborted;
   1.121 +}
   1.122 +
   1.123 +struct EnterJitData;
   1.124 +
   1.125 +bool SetEnterJitData(JSContext *cx, EnterJitData &data, RunState &state, AutoValueVector &vals);
   1.126 +
   1.127 +IonExecStatus IonCannon(JSContext *cx, RunState &state);
   1.128 +
   1.129 +// Used to enter Ion from C++ natives like Array.map. Called from FastInvokeGuard.
   1.130 +IonExecStatus FastInvoke(JSContext *cx, HandleFunction fun, CallArgs &args);
   1.131 +
   1.132 +// Walk the stack and invalidate active Ion frames for the invalid scripts.
   1.133 +void Invalidate(types::TypeZone &types, FreeOp *fop,
   1.134 +                const Vector<types::RecompileInfo> &invalid, bool resetUses = true,
   1.135 +                bool cancelOffThread = true);
   1.136 +void Invalidate(JSContext *cx, const Vector<types::RecompileInfo> &invalid, bool resetUses = true,
   1.137 +                bool cancelOffThread = true);
   1.138 +bool Invalidate(JSContext *cx, JSScript *script, ExecutionMode mode, bool resetUses = true,
   1.139 +                bool cancelOffThread = true);
   1.140 +bool Invalidate(JSContext *cx, JSScript *script, bool resetUses = true,
   1.141 +                bool cancelOffThread = true);
   1.142 +
   1.143 +void MarkValueFromIon(JSRuntime *rt, Value *vp);
   1.144 +void MarkShapeFromIon(JSRuntime *rt, Shape **shapep);
   1.145 +
   1.146 +void ToggleBarriers(JS::Zone *zone, bool needs);
   1.147 +
   1.148 +class IonBuilder;
   1.149 +class MIRGenerator;
   1.150 +class LIRGraph;
   1.151 +class CodeGenerator;
   1.152 +
   1.153 +bool OptimizeMIR(MIRGenerator *mir);
   1.154 +LIRGraph *GenerateLIR(MIRGenerator *mir);
   1.155 +CodeGenerator *GenerateCode(MIRGenerator *mir, LIRGraph *lir);
   1.156 +CodeGenerator *CompileBackEnd(MIRGenerator *mir);
   1.157 +
   1.158 +void AttachFinishedCompilations(JSContext *cx);
   1.159 +void FinishOffThreadBuilder(IonBuilder *builder);
   1.160 +void StopAllOffThreadCompilations(JSCompartment *comp);
   1.161 +
   1.162 +static inline bool
   1.163 +IsIonEnabled(JSContext *cx)
   1.164 +{
   1.165 +    return cx->runtime()->options().ion() &&
   1.166 +           cx->runtime()->options().baseline() &&
   1.167 +           cx->runtime()->jitSupportsFloatingPoint;
   1.168 +}
   1.169 +
   1.170 +inline bool
   1.171 +IsIonInlinablePC(jsbytecode *pc) {
   1.172 +    // CALL, FUNCALL, FUNAPPLY, EVAL, NEW (Normal Callsites)
   1.173 +    // GETPROP, CALLPROP, and LENGTH. (Inlined Getters)
   1.174 +    // SETPROP, SETNAME, SETGNAME (Inlined Setters)
   1.175 +    return IsCallPC(pc) || IsGetPropPC(pc) || IsSetPropPC(pc);
   1.176 +}
   1.177 +
   1.178 +inline bool
   1.179 +TooManyArguments(unsigned nargs)
   1.180 +{
   1.181 +    return nargs >= SNAPSHOT_MAX_NARGS || nargs > js_JitOptions.maxStackArgs;
   1.182 +}
   1.183 +
   1.184 +void ForbidCompilation(JSContext *cx, JSScript *script);
   1.185 +void ForbidCompilation(JSContext *cx, JSScript *script, ExecutionMode mode);
   1.186 +
   1.187 +void PurgeCaches(JSScript *script);
   1.188 +size_t SizeOfIonData(JSScript *script, mozilla::MallocSizeOf mallocSizeOf);
   1.189 +void DestroyIonScripts(FreeOp *fop, JSScript *script);
   1.190 +void TraceIonScripts(JSTracer* trc, JSScript *script);
   1.191 +
   1.192 +void RequestInterruptForIonCode(JSRuntime *rt, JSRuntime::InterruptMode mode);
   1.193 +
   1.194 +bool RematerializeAllFrames(JSContext *cx, JSCompartment *comp);
   1.195 +bool UpdateForDebugMode(JSContext *maybecx, JSCompartment *comp,
   1.196 +                        AutoDebugModeInvalidation &invalidate);
   1.197 +
   1.198 +} // namespace jit
   1.199 +} // namespace js
   1.200 +
   1.201 +#endif // JS_ION
   1.202 +
   1.203 +#endif /* jit_Ion_h */

mercurial