1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef jit_CacheIRSpewer_h
8 #define jit_CacheIRSpewer_h
10 #ifdef JS_CACHEIR_SPEW
12 # include "mozilla/Maybe.h"
14 # include "jit/CacheIR.h"
15 # include "jit/CacheIRGenerator.h"
16 # include "jit/CacheIRReader.h"
17 # include "jit/CacheIRWriter.h"
18 # include "js/TypeDecls.h"
19 # include "threading/LockGuard.h"
20 # include "vm/JSONPrinter.h"
21 # include "vm/MutexIDs.h"
27 Mutex outputLock_ MOZ_UNANNOTATED
;
29 mozilla::Maybe
<JSONPrinter
> json_
;
30 static CacheIRSpewer cacheIRspewer
;
32 // Counter to record how many times Guard class is called. This is used to
33 // determine when to flush outputs based on the given interval value.
34 // For example, if |spewInterval_ = 2|, outputs will be flushed on
35 // guardCount_ values 0,2,4,6,...
38 // Interval at which to flush output files. This value can be set with the
39 // environment variable |CACHEIR_LOG_FLUSH|.
40 uint32_t spewInterval_
;
45 bool enabled() { return json_
.isSome(); }
47 // These methods can only be called when enabled() is true.
49 MOZ_ASSERT(enabled());
53 void beginCache(const IRGenerator
& generator
);
54 void valueProperty(const char* name
, const Value
& v
);
55 void opcodeProperty(const char* name
, const JSOp op
);
56 void cacheIRSequence(CacheIRReader
& reader
);
57 void attached(const char* name
);
61 static CacheIRSpewer
& singleton() { return cacheIRspewer
; }
62 bool init(const char* name
);
64 class MOZ_RAII Guard
{
66 const IRGenerator
& gen_
;
70 Guard(const IRGenerator
& gen
, const char* name
)
71 : sp_(CacheIRSpewer::singleton()), gen_(gen
), name_(name
) {
80 const CacheIRWriter
& writer
= gen_
.writerRef();
81 if (!writer
.failed() && writer
.codeLength() > 0) {
82 CacheIRReader
reader(writer
);
83 sp_
.cacheIRSequence(reader
);
85 if (name_
!= nullptr) {
89 if (sp_
.guardCount_
++ % sp_
.spewInterval_
== 0) {
96 void valueProperty(const char* name
, const Value
& v
) const {
97 sp_
.valueProperty(name
, v
);
100 void opcodeProperty(const char* name
, const JSOp op
) const {
101 sp_
.opcodeProperty(name
, op
);
104 explicit operator bool() const { return sp_
.enabled(); }
108 extern void SpewCacheIROps(GenericPrinter
& out
, const char* prefix
,
109 const CacheIRStubInfo
* info
);
114 #endif /* JS_CACHEIR_SPEW */
116 #endif /* jit_CacheIRSpewer_h */