Files
palemoon27/toolkit/devtools/server/DeserializedNode.cpp
T
roytam1 6629d22907 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1170717 - Move heapState check up to readBarrier; r=jonco (b9c4df5ea)
- Bug 1163908 - Export GL draw data to layerscope for drawing heat-map view. r=:djg (cf078d4fd)
- Bug 1161372 - Add EventRegions on LayerScope. r=dglastonbury (49fc29e8a)
- Files as of Bug 1138721 - Application reputation should check mac file extensions. r=mmc (4b76de8d8)
- Bug 1024774 - Part 0: Upgrade the protobuf library. r=mmc,glandium (c98c08fbd)
- Bug 1149397 - JS::ubi::Node::edges should return a mozilla::UniquePtr; r=jimb (32f755867)
- Bug 1110039 - Part 1 - Add nsLayoutUtils::ClampRectToScrollFrames. r=roc (a8812c287)
- Bug 1110039 - Part 2.1 - Add logger facility. r=roc (1a400bb1f)
- Bug 1110039 - Part 2.2 - Add AccessibleCaret. r=roc (d8c2c759f)
- Bug 1110039 - Part 2.3 - Add AccessibleCaretManager. r=roc (ba8ad6424)
- Bug 1110039 - Part 2.4 - Add AccessibleCaretEventHub. r=roc (db4ef1fe6)
- Bug 1110039 - Part 2.5 - Add all files to build system. r=roc (bee54dc43)
- fix nsRefPtr includes - but build still broken (423d9f32d)
- Bug 1110039 - Part 3 - Add gtest for AccessibleCaretEventHub. r=roc (cdf0df240)
- Bug 1110039 - Part 4 - Hook new classes into the system. r=roc (438a4df68)
- Bug 1109183 - Fix imports of the marionette client and remove spurious entry from sys.path provided by mach. r=ahal (86b814562)
- Bug 1110039 - Part 5 - Reuse marionette tests for AccessibleCaret. r=roc (d5cd35016)
- Bug 1110039 followup: Add 'override' keyword to Name() decl in Access# (cd0d9b0f6)
- Bug 1140994 - Notify gaia to hide selection bubble when scrolling without APZ. r=roc (ca15626fa)
- Bug 1143665 - Remove the ambiguous scroll position being passed around in scroll started/stop notifications. r=roc,ehsan (ce8f1d2a9)
- Bug 1140238 - Part 1: Add a test to drag first caret over non-selectable. r=automatedtester (4080723fe)
- Bug 1140238 - Part 2: Adjust ranges after changing selection direction. r=mats (add1f155d)
- Bug 1140238 - Part 3: Clear maintain selection when dragging caret. r=mats (0aba36f24)
- Bug 1024774 - Part 2: Implement a google::protobuf::ZeroCopyOutputStream wrapper around nsIOutputStream; r=jimb (30c6272d2)
- Bug 1024774 - Part 3: Serialize heap snapshots. r=jimb (9d0c8f6ec)
- Bug 1024774 - Part 1: Add the ChromeUtils WebIDL interface. r=bholley (8e81e8344)
- Bug 1024774 - Part 4: Add an xpcshell test for saving heap snapshots. r=jimb (6e0a07069)
- Bug 1024774 - Part 5: Add GTests for core dump serialization. r=jimb (79315c540)
- clean up spurious char (9a1f9bc18)
- Bug 1121528 - Avoid the inspector going blank when quickly navigating; r=bgrins (f4cff269f)
- Bug 1155168 - Always use the same actor pool. r=ochameau (3e6cc5504)
- Bug 1137527 - Part 1: Make the memory actor emit events for garbage collection. r=jryans (6dcdb18f8)
- Bug 1137527 - Part 2: Add a test for GC MemoryActor events. r=jryans (df2bcf120)
- Bug 1024774 - Part 6: Add a mochitest-chrome sanity check test. r=bholley (4b5bffe79)
- Bug 1024774 - Part 7: Add HeapSnapshot WebIDL interface; r=bholley (7b5ae703a)
- Bug 1024774 - Part 8: Add JS::ubi::Node::isLive; r=jimb (42a965f56)
- Bug 1024774 - Part 9: Deserialize heap snapshots; r=jimb (fb3edfbc0)
- Bug 1024774 - Part 10: Add an xpcshell test for reading heap snapshots. r=jimb (09c3390a1)
- Bug 1024774 - Part 11: Implement a JS::ubi::Node specialization for DeserializedNode; r=jimb (d73362efe)
- Bug 1024774 - Part 12: Add a GTest for the JS::ubi::Node specialization for DeserializedNode; r=jimb (4415acb73)
- Bug 1024774 - Part 13: Change to new SpiderMonkey style from bug 1144366; r=me (15c4bcf87)
- Bug 1024774 - Part 14: Ignore protobuf indirect calls in the GC hazard analysis; r=sfink (c5b141c59)
- Bug 1024774 - Followup: Don't redefine the Debugger property in xpcshell tests; r=jorendorff (dc4f1f109)
- Bug 1169791 - Strongly type NoteJSRoot; r=mccr8 (ba722a44f)
- Bug 1169791 - Strongly type MergeZone; r=mccr8 (a118cf612)
- Bug 1169791 - Strongly type GetTenuredGCThingZone; r=jonco, r=mccr8 (a4da82aea)
- Bug 1171780 - We no longer need to cast out of barrieried types in GC; r=jonco (be83218fa)
- Bug 1144361: Re-enable JIT code randomization on Win64. r=jandem (6c88b4312)
- pointer style (458344bcd)
- Bug 1156914 - Fix the MacroAssembler::pushValue(const Address&) footgun on 32 bit platforms. (r=jandem) (52d5c351d)
- Bug 1156030 - Remove some obsolete static assertion macros from the tree; r=Waldo (84d8f3fea)
- pointer style (ac3c92ce1)
- Bug 1151323 - Handle loading unboxed int32 properties into floating point registers, r=jandem. (790920f3d)
- Bug 1023297 - Use explicit constructors for ARM-specific classes. r=jandem (f7f12cd76)
- Bug 1164229 - Rename ARM SetCond_ to SBit. r=efaust (c55e1d535)
- Bug 977805 - Add an option to mark JIT pages as non-writable. r=luke bug 977805 - add missing #include. r=jandem (384abd6ad)
- Bug 1173992 - Add ARM64 build support. r=glandium (540a7c784)
- Bug 1170750 - Replace %f by %.16g in js/src. r=jandem (48f808c73)
- Bug 1170750 - Use mfbt snprintf_literal instead of sprintf. r=jandem (3b2016484)
- Bug 1170750 - jsprf.cpp: Sort headers properly. r=me (0956cd3a5)
- Bug 923717 - Use structured control flow when testing for the forceInlineCaches option, r=nbp. (fc1dcef6e)
- Bug 1158044 - Remove unused TypeWrapper class and untemplatize/cleanup some code. r=bhackett (a4d5de646)
- Bug 1169355 - Remove unnecessary assertion, r=jandem. (f55c99552)
- Bug 1162986 - Allow objects to be turned into singletons dynamically, r=jandem. (9c683e420)
- Bug 1169731 - [[Call]] on a class constructor should throw. (r=jandem) (470895e3f)
and fix for shared-js in UbiNode.h
2020-11-09 23:37:50 +08:00

203 lines
4.9 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/devtools/DeserializedNode.h"
#include "mozilla/devtools/HeapSnapshot.h"
#include "nsCRTGlue.h"
namespace mozilla {
namespace devtools {
DeserializedEdge::DeserializedEdge()
: referent(0)
, name(nullptr)
{ }
DeserializedEdge::DeserializedEdge(DeserializedEdge&& rhs)
{
referent = rhs.referent;
name = rhs.name;
}
DeserializedEdge& DeserializedEdge::operator=(DeserializedEdge&& rhs)
{
MOZ_ASSERT(&rhs != this);
this->~DeserializedEdge();
new(this) DeserializedEdge(Move(rhs));
return *this;
}
bool
DeserializedEdge::init(const protobuf::Edge& edge, HeapSnapshot& owner)
{
// Although the referent property is optional in the protobuf format for
// future compatibility, we can't semantically have an edge to nowhere and
// require a referent here.
if (!edge.has_referent())
return false;
referent = edge.referent();
if (edge.has_name()) {
const char16_t* duplicateEdgeName = reinterpret_cast<const char16_t*>(edge.name().c_str());
name = owner.borrowUniqueString(duplicateEdgeName, edge.name().length() / sizeof(char16_t));
if (!name)
return false;
}
return true;
}
/* static */ UniquePtr<DeserializedNode>
DeserializedNode::Create(const protobuf::Node& node, HeapSnapshot& owner)
{
if (!node.has_id())
return nullptr;
NodeId id = node.id();
if (!node.has_typename_())
return nullptr;
const char16_t* duplicatedTypeName = reinterpret_cast<const char16_t*>(node.typename_().c_str());
const char16_t* uniqueTypeName = owner.borrowUniqueString(duplicatedTypeName,
node.typename_().length() / sizeof(char16_t));
if (!uniqueTypeName)
return nullptr;
auto edgesLength = node.edges_size();
EdgeVector edges;
if (!edges.reserve(edgesLength))
return nullptr;
for (decltype(edgesLength) i = 0; i < edgesLength; i++) {
DeserializedEdge edge;
if (!edge.init(node.edges(i), owner))
return nullptr;
edges.infallibleAppend(Move(edge));
}
if (!node.has_size())
return nullptr;
uint64_t size = node.size();
return MakeUnique<DeserializedNode>(id,
uniqueTypeName,
size,
Move(edges),
owner);
}
DeserializedNode::DeserializedNode(NodeId id,
const char16_t* typeName,
uint64_t size,
EdgeVector&& edges,
HeapSnapshot& owner)
: id(id)
, typeName(typeName)
, size(size)
, edges(Move(edges))
, owner(&owner)
{ }
DeserializedNode::DeserializedNode(NodeId id, const char16_t* typeName, uint64_t size)
: id(id)
, typeName(typeName)
, size(size)
, edges()
, owner(nullptr)
{ }
DeserializedNode&
DeserializedNode::getEdgeReferent(const DeserializedEdge& edge)
{
auto ptr = owner->nodes.lookup(edge.referent);
MOZ_ASSERT(ptr);
return *ptr->value();
}
} // namespace devtools
} // namespace mozilla
namespace JS {
namespace ubi {
using mozilla::devtools::DeserializedEdge;
const char16_t Concrete<DeserializedNode>::concreteTypeName[] =
MOZ_UTF16("mozilla::devtools::DeserializedNode");
const char16_t*
Concrete<DeserializedNode>::typeName() const
{
return get().typeName;
}
size_t
Concrete<DeserializedNode>::size(mozilla::MallocSizeOf mallocSizeof) const
{
return get().size;
}
class DeserializedEdgeRange : public EdgeRange
{
SimpleEdgeVector edges;
size_t i;
void settle() {
front_ = i < edges.length() ? &edges[i] : nullptr;
}
public:
explicit DeserializedEdgeRange(JSContext* cx)
: edges(cx)
, i(0)
{
settle();
}
bool init(DeserializedNode& node)
{
if (!edges.reserve(node.edges.length()))
return false;
for (DeserializedEdge* edgep = node.edges.begin();
edgep != node.edges.end();
edgep++)
{
char16_t* name = nullptr;
if (edgep->name) {
name = NS_strdup(edgep->name);
if (!name)
return false;
}
DeserializedNode& referent = node.getEdgeReferent(*edgep);
edges.infallibleAppend(mozilla::Move(SimpleEdge(name, Node(&referent))));
}
settle();
return true;
}
void popFront() override
{
i++;
settle();
}
};
UniquePtr<EdgeRange>
Concrete<DeserializedNode>::edges(JSContext* cx, bool) const
{
UniquePtr<DeserializedEdgeRange, JS::DeletePolicy<DeserializedEdgeRange>> range(
js_new<DeserializedEdgeRange>(cx));
if (!range || !range->init(get()))
return nullptr;
return UniquePtr<EdgeRange>(range.release());
}
} // namespace JS
} // namespace ubi