mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1491909 - Add an AllocPolicy to mozilla::JSONWriter r=jwalden,mstange
JSONWriter currently calls new and delete indirectly through mozilla::MakeUnique to allocate a buffer. Becuase of this, the methods of this class cannot be invoked within Spidermonkey due to https://searchfox.org/mozilla-central/source/config/check_vanilla_allocations.py#6-14. Therefore, JSONWriter needs an AllocPolicy template parameter so that the allocation and deallocation routines can be changed to match the JS AllocPolicy when invoked within SpiderMonkey. Differential Revision: https://phabricator.services.mozilla.com/D7279 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
19c8368ea5
commit
fc930ad16f
@ -85,7 +85,7 @@ public:
|
||||
{
|
||||
nsAutoString buffer;
|
||||
|
||||
JSONWriter w(MakeUnique<StringWriteFunc>(buffer));
|
||||
JSONWriter<> w(MakeUnique<StringWriteFunc>(buffer));
|
||||
w.Start();
|
||||
|
||||
for (auto iter = mLog.Iter(); !iter.Done(); iter.Next()) {
|
||||
|
@ -85,7 +85,7 @@ AppendToString(const DDLogValue& aValue, nsCString& aString)
|
||||
|
||||
struct LogValueMatcherJson
|
||||
{
|
||||
JSONWriter& mJW;
|
||||
JSONWriter<>& mJW;
|
||||
const char* mPropertyName;
|
||||
|
||||
void match(const DDNoValue&) const { mJW.NullProperty(mPropertyName); }
|
||||
@ -137,7 +137,7 @@ struct LogValueMatcherJson
|
||||
|
||||
void
|
||||
ToJSON(const DDLogValue& aValue,
|
||||
JSONWriter& aJSONWriter,
|
||||
JSONWriter<>& aJSONWriter,
|
||||
const char* aPropertyName)
|
||||
{
|
||||
aValue.match(LogValueMatcherJson{ aJSONWriter, aPropertyName });
|
||||
|
@ -54,10 +54,12 @@ using DDLogValue = Variant<DDNoValue,
|
||||
void
|
||||
AppendToString(const DDLogValue& aValue, nsCString& aString);
|
||||
|
||||
template <class AllocPolicy>
|
||||
class JSONWriter;
|
||||
class MallocAllocPolicy;
|
||||
void
|
||||
ToJSON(const DDLogValue& aValue,
|
||||
JSONWriter& aJSONWriter,
|
||||
JSONWriter<MallocAllocPolicy>& aJSONWriter,
|
||||
const char* aPropertyName);
|
||||
|
||||
} // namespace mozilla
|
||||
|
@ -462,11 +462,11 @@ DDMediaLogs::FulfillPromises()
|
||||
}
|
||||
|
||||
nsCString json;
|
||||
JSONWriter jw{ MakeUnique<StringWriteFunc>(json) };
|
||||
JSONWriter<> jw{ MakeUnique<StringWriteFunc>(json) };
|
||||
jw.Start();
|
||||
jw.StartArrayProperty("messages");
|
||||
for (const DDLogMessage& message : log->mMessages) {
|
||||
jw.StartObjectElement(JSONWriter::SingleLineStyle);
|
||||
jw.StartObjectElement(JSONWriter<>::SingleLineStyle);
|
||||
jw.IntProperty("i", message.mIndex.Value());
|
||||
jw.DoubleProperty("ts", ToSeconds(message.mTimeStamp));
|
||||
DDLifetime* lifetime =
|
||||
@ -505,7 +505,7 @@ DDMediaLogs::FulfillPromises()
|
||||
mediaElement,
|
||||
[&](const DDLifetime& lifetime) {
|
||||
jw.StartObjectProperty(nsPrintfCString("%" PRIi32, lifetime.mTag).get(),
|
||||
JSONWriter::SingleLineStyle);
|
||||
JSONWriter<>::SingleLineStyle);
|
||||
jw.IntProperty("tag", lifetime.mTag);
|
||||
jw.StringProperty("cls", lifetime.mObject.TypeName());
|
||||
jw.StringProperty(
|
||||
|
@ -1742,7 +1742,7 @@ Notification::ShowInternal()
|
||||
if (isPersistent) {
|
||||
nsAutoString persistentData;
|
||||
|
||||
JSONWriter w(MakeUnique<StringWriteFunc>(persistentData));
|
||||
JSONWriter<> w(MakeUnique<StringWriteFunc>(persistentData));
|
||||
w.Start();
|
||||
|
||||
nsAutoString origin;
|
||||
|
@ -141,9 +141,9 @@ GetLoadedPath(nsAString& aPath)
|
||||
}
|
||||
|
||||
static void
|
||||
AnnotateClsidRegistrationForHive(JSONWriter& aJson, HKEY aHive,
|
||||
AnnotateClsidRegistrationForHive(JSONWriter<>& aJson, HKEY aHive,
|
||||
const nsAString& aClsid,
|
||||
const JSONWriter::CollectionStyle aStyle)
|
||||
const JSONWriter<>::CollectionStyle aStyle)
|
||||
{
|
||||
nsAutoString clsidSubkey;
|
||||
clsidSubkey.AppendLiteral(kSoftwareClasses);
|
||||
@ -193,7 +193,7 @@ AnnotateClsidRegistrationForHive(JSONWriter& aJson, HKEY aHive,
|
||||
}
|
||||
|
||||
static void
|
||||
CheckTlbPath(JSONWriter& aJson, const nsAString& aTypelibPath)
|
||||
CheckTlbPath(JSONWriter<>& aJson, const nsAString& aTypelibPath)
|
||||
{
|
||||
const nsString& flatPath = PromiseFlatString(aTypelibPath);
|
||||
DWORD bufCharLen = ExpandEnvironmentStrings(flatPath.get(), nullptr, 0);
|
||||
@ -214,10 +214,10 @@ CheckTlbPath(JSONWriter& aJson, const nsAString& aTypelibPath)
|
||||
|
||||
template <size_t N>
|
||||
static void
|
||||
AnnotateTypelibPlatform(JSONWriter& aJson, HKEY aBaseKey,
|
||||
AnnotateTypelibPlatform(JSONWriter<>& aJson, HKEY aBaseKey,
|
||||
const nsAString& aLcidSubkey,
|
||||
const char16_t (&aPlatform)[N],
|
||||
const JSONWriter::CollectionStyle aStyle)
|
||||
const JSONWriter<>::CollectionStyle aStyle)
|
||||
{
|
||||
nsLiteralString platform(aPlatform);
|
||||
|
||||
@ -235,10 +235,10 @@ AnnotateTypelibPlatform(JSONWriter& aJson, HKEY aBaseKey,
|
||||
}
|
||||
|
||||
static void
|
||||
AnnotateTypelibRegistrationForHive(JSONWriter& aJson, HKEY aHive,
|
||||
AnnotateTypelibRegistrationForHive(JSONWriter<>& aJson, HKEY aHive,
|
||||
const nsAString& aTypelibId,
|
||||
const nsAString& aTypelibVersion,
|
||||
const JSONWriter::CollectionStyle aStyle)
|
||||
const JSONWriter<>::CollectionStyle aStyle)
|
||||
{
|
||||
nsAutoString typelibSubKey;
|
||||
typelibSubKey.AppendLiteral(kSoftwareClasses);
|
||||
@ -293,8 +293,8 @@ AnnotateTypelibRegistrationForHive(JSONWriter& aJson, HKEY aHive,
|
||||
}
|
||||
|
||||
static void
|
||||
AnnotateInterfaceRegistrationForHive(JSONWriter& aJson, HKEY aHive, REFIID aIid,
|
||||
const JSONWriter::CollectionStyle aStyle)
|
||||
AnnotateInterfaceRegistrationForHive(JSONWriter<>& aJson, HKEY aHive, REFIID aIid,
|
||||
const JSONWriter<>::CollectionStyle aStyle)
|
||||
{
|
||||
nsAutoString interfaceSubKey;
|
||||
interfaceSubKey.AppendLiteral(kSoftwareClasses);
|
||||
@ -357,12 +357,12 @@ void
|
||||
AnnotateInterfaceRegistration(REFIID aIid)
|
||||
{
|
||||
#if defined(DEBUG)
|
||||
const JSONWriter::CollectionStyle style = JSONWriter::MultiLineStyle;
|
||||
const JSONWriter<>::CollectionStyle style = JSONWriter<>::MultiLineStyle;
|
||||
#else
|
||||
const JSONWriter::CollectionStyle style = JSONWriter::SingleLineStyle;
|
||||
const JSONWriter<>::CollectionStyle style = JSONWriter<>::SingleLineStyle;
|
||||
#endif
|
||||
|
||||
JSONWriter json(MakeUnique<CStringWriter>());
|
||||
JSONWriter<> json(MakeUnique<CStringWriter>());
|
||||
|
||||
json.Start(style);
|
||||
|
||||
@ -391,15 +391,15 @@ void
|
||||
AnnotateClassRegistration(REFCLSID aClsid)
|
||||
{
|
||||
#if defined(DEBUG)
|
||||
const JSONWriter::CollectionStyle style = JSONWriter::MultiLineStyle;
|
||||
const JSONWriter<>::CollectionStyle style = JSONWriter<>::MultiLineStyle;
|
||||
#else
|
||||
const JSONWriter::CollectionStyle style = JSONWriter::SingleLineStyle;
|
||||
const JSONWriter<>::CollectionStyle style = JSONWriter<>::SingleLineStyle;
|
||||
#endif
|
||||
|
||||
nsAutoString strClsid;
|
||||
GUIDToString(aClsid, strClsid);
|
||||
|
||||
JSONWriter json(MakeUnique<CStringWriter>());
|
||||
JSONWriter<> json(MakeUnique<CStringWriter>());
|
||||
|
||||
json.Start(style);
|
||||
|
||||
|
@ -134,4 +134,8 @@ class TempAllocPolicy : public AllocPolicyBase
|
||||
|
||||
} /* namespace js */
|
||||
|
||||
namespace JS {
|
||||
using SystemAllocPolicy = js::SystemAllocPolicy;
|
||||
} /* namespace JS */
|
||||
|
||||
#endif /* js_AllocPolicy_h */
|
||||
|
@ -1789,7 +1789,7 @@ private:
|
||||
};
|
||||
|
||||
static void
|
||||
WriteBlockContents(JSONWriter& aWriter, const LiveBlock& aBlock)
|
||||
WriteBlockContents(JSONWriter<>& aWriter, const LiveBlock& aBlock)
|
||||
{
|
||||
size_t numWords = aBlock.ReqSize() / sizeof(uintptr_t*);
|
||||
if (numWords == 0) {
|
||||
@ -1817,7 +1817,7 @@ AnalyzeImpl(UniquePtr<JSONWriteFunc> aWriter)
|
||||
// Therefore, this declaration must precede the AutoBlockIntercepts
|
||||
// declaration, to ensure that |write| is destroyed *after* intercepts are
|
||||
// unblocked.
|
||||
JSONWriter writer(std::move(aWriter));
|
||||
JSONWriter<> writer(std::move(aWriter));
|
||||
|
||||
AutoBlockIntercepts block(Thread::Fetch());
|
||||
AutoLockState lock;
|
||||
|
@ -120,6 +120,7 @@ namespace detail {
|
||||
extern MFBT_DATA const char gTwoCharEscapes[256];
|
||||
} // namespace detail
|
||||
|
||||
template <class AllocPolicy = MallocAllocPolicy>
|
||||
class JSONWriter
|
||||
{
|
||||
// From http://www.ietf.org/rfc/rfc4627.txt:
|
||||
@ -142,7 +143,15 @@ class JSONWriter
|
||||
// wouldn't work with UniquePtr.
|
||||
bool mIsOwned;
|
||||
const char* mUnownedStr;
|
||||
UniquePtr<char[]> mOwnedStr;
|
||||
|
||||
struct FreePolicy {
|
||||
AllocPolicy mAllocPolicy;
|
||||
void operator() (void* p) {
|
||||
mAllocPolicy.free_(p);
|
||||
}
|
||||
};
|
||||
|
||||
UniquePtr<char[], FreePolicy> mOwnedStr;
|
||||
|
||||
void SanityCheck() const
|
||||
{
|
||||
@ -156,6 +165,10 @@ class JSONWriter
|
||||
return u < 10 ? '0' + u : 'a' + (u - 10);
|
||||
}
|
||||
|
||||
AllocPolicy& allocPolicy() {
|
||||
return mOwnedStr.get_deleter().mAllocPolicy;
|
||||
}
|
||||
|
||||
public:
|
||||
explicit EscapedString(const char* aStr)
|
||||
: mUnownedStr(nullptr)
|
||||
@ -189,7 +202,8 @@ class JSONWriter
|
||||
// Escapes are needed. We'll create a new string.
|
||||
mIsOwned = true;
|
||||
size_t len = (p - aStr) + nExtra;
|
||||
mOwnedStr = MakeUnique<char[]>(len + 1);
|
||||
UniquePtr<char[], FreePolicy> buffer(allocPolicy().template pod_malloc<char>(len + 1));
|
||||
mOwnedStr = std::move(buffer);
|
||||
|
||||
p = aStr;
|
||||
size_t i = 0;
|
||||
|
@ -101,7 +101,7 @@ void TestBasicProperties()
|
||||
}\n\
|
||||
";
|
||||
|
||||
JSONWriter w(MakeUnique<StringWriteFunc>());
|
||||
JSONWriter<> w(MakeUnique<StringWriteFunc>());
|
||||
|
||||
w.Start();
|
||||
{
|
||||
@ -260,7 +260,7 @@ void TestBasicElements()
|
||||
}\n\
|
||||
";
|
||||
|
||||
JSONWriter w(MakeUnique<StringWriteFunc>());
|
||||
JSONWriter<> w(MakeUnique<StringWriteFunc>());
|
||||
|
||||
w.Start();
|
||||
w.StartArrayProperty("array");
|
||||
@ -376,7 +376,7 @@ void TestOneLineObject()
|
||||
{\"i\": 1, \"array\": [null, [{}], {\"o\": {}}, \"s\"], \"d\": 3.33}\n\
|
||||
";
|
||||
|
||||
JSONWriter w(MakeUnique<StringWriteFunc>());
|
||||
JSONWriter<> w(MakeUnique<StringWriteFunc>());
|
||||
|
||||
w.Start(w.SingleLineStyle);
|
||||
|
||||
@ -430,7 +430,7 @@ void TestStringEscaping()
|
||||
}\n\
|
||||
";
|
||||
|
||||
JSONWriter w(MakeUnique<StringWriteFunc>());
|
||||
JSONWriter<> w(MakeUnique<StringWriteFunc>());
|
||||
|
||||
// Test the string escaping behaviour.
|
||||
w.Start();
|
||||
@ -508,7 +508,7 @@ void TestDeepNesting()
|
||||
}\n\
|
||||
";
|
||||
|
||||
JSONWriter w(MakeUnique<StringWriteFunc>());
|
||||
JSONWriter<> w(MakeUnique<StringWriteFunc>());
|
||||
|
||||
w.Start();
|
||||
{
|
||||
@ -533,7 +533,7 @@ void TestEscapedPropertyNames()
|
||||
{\"i\\t\": 1, \"array\\t\": [null, [{}], {\"o\\t\": {}}, \"s\"], \"d\\t\": 3.33}\n\
|
||||
";
|
||||
|
||||
JSONWriter w(MakeUnique<StringWriteFunc>());
|
||||
JSONWriter<> w(MakeUnique<StringWriteFunc>());
|
||||
|
||||
w.Start(w.SingleLineStyle);
|
||||
|
||||
|
@ -2584,8 +2584,8 @@ Database::MigrateV51Up()
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsAutoCString json;
|
||||
JSONWriter jw{ MakeUnique<StringWriteFunc>(json) };
|
||||
jw.StartArrayProperty(nullptr, JSONWriter::SingleLineStyle);
|
||||
JSONWriter<> jw{ MakeUnique<StringWriteFunc>(json) };
|
||||
jw.StartArrayProperty(nullptr, JSONWriter<>::SingleLineStyle);
|
||||
|
||||
bool hasAtLeastOne = false;
|
||||
bool hasMore = false;
|
||||
|
@ -2638,7 +2638,7 @@ namespace {
|
||||
*/
|
||||
void
|
||||
internal_ReflectHistogramToJSON(const HistogramSnapshotData& aSnapshot,
|
||||
mozilla::JSONWriter& aWriter)
|
||||
mozilla::JSONWriter<>& aWriter)
|
||||
{
|
||||
aWriter.IntProperty("sum", aSnapshot.mSampleSum);
|
||||
|
||||
@ -2765,7 +2765,7 @@ internal_ParseHistogramData(JSContext* aCx, JS::HandleId aEntryId,
|
||||
// PUBLIC: GeckoView serialization/deserialization functions.
|
||||
|
||||
nsresult
|
||||
TelemetryHistogram::SerializeHistograms(mozilla::JSONWriter& aWriter)
|
||||
TelemetryHistogram::SerializeHistograms(mozilla::JSONWriter<>& aWriter)
|
||||
{
|
||||
MOZ_ASSERT(XRE_IsParentProcess(), "Only save histograms in the parent process");
|
||||
if (!XRE_IsParentProcess()) {
|
||||
@ -2812,7 +2812,7 @@ TelemetryHistogram::SerializeHistograms(mozilla::JSONWriter& aWriter)
|
||||
}
|
||||
|
||||
nsresult
|
||||
TelemetryHistogram::SerializeKeyedHistograms(mozilla::JSONWriter& aWriter)
|
||||
TelemetryHistogram::SerializeKeyedHistograms(mozilla::JSONWriter<>& aWriter)
|
||||
{
|
||||
MOZ_ASSERT(XRE_IsParentProcess(), "Only save keyed histograms in the parent process");
|
||||
if (!XRE_IsParentProcess()) {
|
||||
|
@ -13,9 +13,10 @@
|
||||
|
||||
namespace mozilla{
|
||||
// This is only used for the GeckoView persistence.
|
||||
template <class AllocPolicy>
|
||||
class JSONWriter;
|
||||
class MallocAllocPolicy;
|
||||
}
|
||||
|
||||
// This module is internal to Telemetry. It encapsulates Telemetry's
|
||||
// histogram accumulation and storage logic. It should only be used by
|
||||
// Telemetry.cpp. These functions should not be used anywhere else.
|
||||
@ -81,8 +82,8 @@ GetHistogramSizesOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
|
||||
// These functions are only meant to be used for GeckoView persistence.
|
||||
// They are responsible for updating in-memory probes with the data persisted
|
||||
// on the disk and vice-versa.
|
||||
nsresult SerializeHistograms(mozilla::JSONWriter &aWriter);
|
||||
nsresult SerializeKeyedHistograms(mozilla::JSONWriter &aWriter);
|
||||
nsresult SerializeHistograms(mozilla::JSONWriter<mozilla::MallocAllocPolicy>& aWriter);
|
||||
nsresult SerializeKeyedHistograms(mozilla::JSONWriter<mozilla::MallocAllocPolicy>& aWriter);
|
||||
nsresult DeserializeHistograms(JSContext* aCx, JS::HandleValue aData);
|
||||
nsresult DeserializeKeyedHistograms(JSContext* aCx, JS::HandleValue aData);
|
||||
|
||||
|
@ -272,7 +272,7 @@ GetVariantFromIVariant(nsIVariant* aInput, uint32_t aScalarKind,
|
||||
*/
|
||||
nsresult
|
||||
WriteVariantToJSONWriter(uint32_t aScalarType, nsIVariant* aInputValue,
|
||||
const char* aPropertyName, mozilla::JSONWriter& aWriter)
|
||||
const char* aPropertyName, mozilla::JSONWriter<>& aWriter)
|
||||
{
|
||||
MOZ_ASSERT(aInputValue);
|
||||
|
||||
@ -3480,7 +3480,7 @@ TelemetryScalar::AddDynamicScalarDefinitions(
|
||||
* @returns NS_OK or a failure value explaining why persistence failed.
|
||||
*/
|
||||
nsresult
|
||||
TelemetryScalar::SerializeScalars(mozilla::JSONWriter& aWriter)
|
||||
TelemetryScalar::SerializeScalars(mozilla::JSONWriter<>& aWriter)
|
||||
{
|
||||
// Get a copy of the data, without clearing.
|
||||
ScalarSnapshotTable scalarsToReflect;
|
||||
@ -3531,7 +3531,7 @@ TelemetryScalar::SerializeScalars(mozilla::JSONWriter& aWriter)
|
||||
* @returns NS_OK or a failure value explaining why persistence failed.
|
||||
*/
|
||||
nsresult
|
||||
TelemetryScalar::SerializeKeyedScalars(mozilla::JSONWriter& aWriter)
|
||||
TelemetryScalar::SerializeKeyedScalars(mozilla::JSONWriter<>& aWriter)
|
||||
{
|
||||
// Get a copy of the data, without clearing.
|
||||
KeyedScalarSnapshotTable keyedScalarsToReflect;
|
||||
|
@ -18,7 +18,9 @@
|
||||
|
||||
namespace mozilla {
|
||||
// This is only used for the GeckoView persistence.
|
||||
template <class AllocPolicy>
|
||||
class JSONWriter;
|
||||
class MallocAllocPolicy;
|
||||
namespace Telemetry {
|
||||
struct ScalarAction;
|
||||
struct KeyedScalarAction;
|
||||
@ -94,8 +96,8 @@ void AddDynamicScalarDefinitions(const nsTArray<mozilla::Telemetry::DynamicScala
|
||||
|
||||
// They are responsible for updating in-memory probes with the data persisted
|
||||
// on the disk and vice-versa.
|
||||
nsresult SerializeScalars(mozilla::JSONWriter &aWriter);
|
||||
nsresult SerializeKeyedScalars(mozilla::JSONWriter &aWriter);
|
||||
nsresult SerializeScalars(mozilla::JSONWriter<mozilla::MallocAllocPolicy>& aWriter);
|
||||
nsresult SerializeKeyedScalars(mozilla::JSONWriter<mozilla::MallocAllocPolicy>& aWriter);
|
||||
nsresult DeserializePersistedScalars(JSContext* aCx, JS::HandleValue aData);
|
||||
nsresult DeserializePersistedKeyedScalars(JSContext* aCx, JS::HandleValue aData);
|
||||
// Mark deserialization as in progress.
|
||||
|
@ -382,7 +382,7 @@ PersistenceThreadPersist()
|
||||
}
|
||||
|
||||
// Build the JSON structure: give up the ownership of jsonWriter.
|
||||
mozilla::JSONWriter w(std::move(jsonWriter));
|
||||
mozilla::JSONWriter<> w(std::move(jsonWriter));
|
||||
w.Start();
|
||||
|
||||
w.StartObjectProperty("scalars");
|
||||
|
@ -85,11 +85,11 @@ ProfileBufferEntry::ProfileBufferEntry(Kind aKind, uint64_t aUint64)
|
||||
|
||||
class JSONSchemaWriter
|
||||
{
|
||||
JSONWriter& mWriter;
|
||||
ProfilerJSONWriter& mWriter;
|
||||
uint32_t mIndex;
|
||||
|
||||
public:
|
||||
explicit JSONSchemaWriter(JSONWriter& aWriter)
|
||||
explicit JSONSchemaWriter(ProfilerJSONWriter& aWriter)
|
||||
: mWriter(aWriter)
|
||||
, mIndex(0)
|
||||
{
|
||||
|
@ -140,11 +140,11 @@ public:
|
||||
aWriter.TakeAndSplice(mStringTableWriter.WriteFunc());
|
||||
}
|
||||
|
||||
void WriteProperty(mozilla::JSONWriter& aWriter, const char* aName, const char* aStr) {
|
||||
void WriteProperty(ProfilerJSONWriter& aWriter, const char* aName, const char* aStr) {
|
||||
aWriter.IntProperty(aName, GetOrAddIndex(aStr));
|
||||
}
|
||||
|
||||
void WriteElement(mozilla::JSONWriter& aWriter, const char* aStr) {
|
||||
void WriteElement(ProfilerJSONWriter& aWriter, const char* aStr) {
|
||||
aWriter.IntElement(GetOrAddIndex(aStr));
|
||||
}
|
||||
|
||||
|
@ -1567,7 +1567,7 @@ SafeJSInteger(uint64_t aValue) {
|
||||
}
|
||||
|
||||
static void
|
||||
AddSharedLibraryInfoToStream(JSONWriter& aWriter, const SharedLibrary& aLib)
|
||||
AddSharedLibraryInfoToStream(ProfilerJSONWriter& aWriter, const SharedLibrary& aLib)
|
||||
{
|
||||
aWriter.StartObjectElement();
|
||||
aWriter.IntProperty("start", SafeJSInteger(aLib.GetStart()));
|
||||
@ -1583,7 +1583,7 @@ AddSharedLibraryInfoToStream(JSONWriter& aWriter, const SharedLibrary& aLib)
|
||||
}
|
||||
|
||||
void
|
||||
AppendSharedLibraries(JSONWriter& aWriter)
|
||||
AppendSharedLibraries(ProfilerJSONWriter& aWriter)
|
||||
{
|
||||
SharedLibraryInfo info = SharedLibraryInfo::GetInfoForSelf();
|
||||
info.SortByAddress();
|
||||
@ -1594,7 +1594,7 @@ AppendSharedLibraries(JSONWriter& aWriter)
|
||||
|
||||
#ifdef MOZ_TASK_TRACER
|
||||
static void
|
||||
StreamNameAndThreadId(JSONWriter& aWriter, const char* aName, int aThreadId)
|
||||
StreamNameAndThreadId(ProfilerJSONWriter& aWriter, const char* aName, int aThreadId)
|
||||
{
|
||||
aWriter.StartObjectElement();
|
||||
{
|
||||
@ -1823,7 +1823,7 @@ StreamMetaJSCustomObject(PSLockRef aLock, SpliceableJSONWriter& aWriter,
|
||||
ExtensionPolicyService::GetSingleton().GetAll(exts);
|
||||
|
||||
for (auto& ext : exts) {
|
||||
aWriter.StartArrayElement(JSONWriter::SingleLineStyle);
|
||||
aWriter.StartArrayElement(ProfilerJSONWriter::SingleLineStyle);
|
||||
|
||||
nsAutoString id;
|
||||
ext->GetId(id);
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "PlatformMacros.h"
|
||||
#include "ProfileJSONWriter.h"
|
||||
#include <vector>
|
||||
|
||||
// We need a definition of gettid(), but glibc doesn't provide a
|
||||
@ -116,9 +117,11 @@ typedef mozilla::UniquePtr<PlatformData, PlatformDataDestructor>
|
||||
UniquePlatformData AllocPlatformData(int aThreadId);
|
||||
|
||||
namespace mozilla {
|
||||
template <class AllocPolicy>
|
||||
class JSONWriter;
|
||||
class MallocAllocPolicy;
|
||||
}
|
||||
void AppendSharedLibraries(mozilla::JSONWriter& aWriter);
|
||||
void AppendSharedLibraries(ProfilerJSONWriter& aWriter);
|
||||
|
||||
// Convert the array of strings to a bitfield.
|
||||
uint32_t ParseFeaturesFromStringArray(const char** aFeatures,
|
||||
|
@ -193,7 +193,7 @@ nsProfiler::GetSharedLibraries(JSContext* aCx,
|
||||
JS::RootedValue val(aCx);
|
||||
{
|
||||
nsString buffer;
|
||||
JSONWriter w(MakeUnique<StringWriteFunc>(buffer));
|
||||
ProfilerJSONWriter w(MakeUnique<StringWriteFunc>(buffer));
|
||||
w.StartArrayElement();
|
||||
AppendSharedLibraries(w);
|
||||
w.EndArray();
|
||||
|
@ -10,9 +10,14 @@
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
|
||||
#include "js/AllocPolicy.h"
|
||||
#include "mozilla/JSONWriter.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
|
||||
// JS::SystemAllocPolicy is used here instead of the default so that the JSONWriter
|
||||
// object can also be passed into SpiderMonkey and used there.
|
||||
using ProfilerJSONWriter = mozilla::JSONWriter<JS::SystemAllocPolicy>;
|
||||
|
||||
class SpliceableChunkedJSONWriter;
|
||||
|
||||
// On average, profile JSONs are large enough such that we want to avoid
|
||||
@ -83,11 +88,11 @@ struct OStreamJSONWriteFunc : public mozilla::JSONWriteFunc
|
||||
std::ostream& mStream;
|
||||
};
|
||||
|
||||
class SpliceableJSONWriter : public mozilla::JSONWriter
|
||||
class SpliceableJSONWriter : public ProfilerJSONWriter
|
||||
{
|
||||
public:
|
||||
explicit SpliceableJSONWriter(mozilla::UniquePtr<mozilla::JSONWriteFunc> aWriter)
|
||||
: JSONWriter(std::move(aWriter))
|
||||
: ProfilerJSONWriter(std::move(aWriter))
|
||||
{ }
|
||||
|
||||
void StartBareList(CollectionStyle aStyle = MultiLineStyle) {
|
||||
|
@ -25,10 +25,10 @@ struct StringWriteFunc : public JSONWriteFunc
|
||||
};
|
||||
|
||||
static void
|
||||
EvaluateDict(JSONWriter* aWriter, NSDictionary<NSString*, id>* aDict);
|
||||
EvaluateDict(JSONWriter<>* aWriter, NSDictionary<NSString*, id>* aDict);
|
||||
|
||||
static void
|
||||
EvaluateArray(JSONWriter* aWriter, NSArray* aArray)
|
||||
EvaluateArray(JSONWriter<>* aWriter, NSArray* aArray)
|
||||
{
|
||||
for (id elem in aArray) {
|
||||
if ([elem isKindOfClass:[NSString class]]) {
|
||||
@ -48,7 +48,7 @@ EvaluateArray(JSONWriter* aWriter, NSArray* aArray)
|
||||
}
|
||||
|
||||
static void
|
||||
EvaluateDict(JSONWriter* aWriter, NSDictionary<NSString*, id>* aDict)
|
||||
EvaluateDict(JSONWriter<>* aWriter, NSDictionary<NSString*, id>* aDict)
|
||||
{
|
||||
for (NSString* key in aDict) {
|
||||
id value = aDict[key];
|
||||
@ -83,7 +83,7 @@ nsMacPreferencesReader::ReadPreferences(JSContext* aCx,
|
||||
JS::MutableHandle<JS::Value> aResult)
|
||||
{
|
||||
nsAutoString jsonStr;
|
||||
JSONWriter w(MakeUnique<StringWriteFunc>(jsonStr));
|
||||
JSONWriter<> w(MakeUnique<StringWriteFunc>(jsonStr));
|
||||
w.Start();
|
||||
EvaluateDict(&w, [[NSUserDefaults standardUserDefaults]
|
||||
dictionaryRepresentation]);
|
||||
|
@ -469,7 +469,7 @@ class HandleReportAndFinishReportingCallbacks final
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
HandleReportAndFinishReportingCallbacks(UniquePtr<JSONWriter> aWriter,
|
||||
HandleReportAndFinishReportingCallbacks(UniquePtr<JSONWriter<>> aWriter,
|
||||
nsIFinishDumpingCallback* aFinishDumping,
|
||||
nsISupports* aFinishDumpingData)
|
||||
: mWriter(std::move(aWriter))
|
||||
@ -545,7 +545,7 @@ public:
|
||||
private:
|
||||
~HandleReportAndFinishReportingCallbacks() {}
|
||||
|
||||
UniquePtr<JSONWriter> mWriter;
|
||||
UniquePtr<JSONWriter<>> mWriter;
|
||||
nsCOMPtr<nsIFinishDumpingCallback> mFinishDumping;
|
||||
nsCOMPtr<nsISupports> mFinishDumpingData;
|
||||
};
|
||||
@ -649,7 +649,7 @@ DumpMemoryInfoToFile(
|
||||
return rv;
|
||||
}
|
||||
auto jsonWriter =
|
||||
MakeUnique<JSONWriter>(MakeUnique<GZWriterWrapper>(gzWriter));
|
||||
MakeUnique<JSONWriter<>>(MakeUnique<GZWriterWrapper>(gzWriter));
|
||||
|
||||
nsCOMPtr<nsIMemoryReporterManager> mgr =
|
||||
do_GetService("@mozilla.org/memory-reporter-manager;1");
|
||||
|
Loading…
Reference in New Issue
Block a user