Skip to content

Revert "Metadata cache optimizations" #4549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 8 additions & 37 deletions include/swift/Runtime/Concurrent.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#include <stdio.h>
#endif

namespace swift {

/// This is a node in a concurrent linked list.
template <class ElemTy> struct ConcurrentListNode {
ConcurrentListNode(ElemTy Elem) : Payload(Elem), Next(nullptr) {}
Expand Down Expand Up @@ -125,29 +123,6 @@ template <class ElemTy> struct ConcurrentList {
std::atomic<ConcurrentListNode<ElemTy> *> First;
};

template <class T, bool Delete> class AtomicMaybeOwningPointer;

template <class T>
class AtomicMaybeOwningPointer<T, false> {
public:
std::atomic<T*> Value;
constexpr AtomicMaybeOwningPointer(T *value) : Value(value) {}
};

template <class T>
class AtomicMaybeOwningPointer<T, true> {
public:
std::atomic<T*> Value;
constexpr AtomicMaybeOwningPointer(T *value) : Value(value) {}

~AtomicMaybeOwningPointer() {
// This can use relaxed memory order because the client has to ensure
// that all accesses are safely completed and their effects fully
// visible before destruction occurs anyway.
::delete Value.load(std::memory_order_relaxed);
}
};

/// A concurrent map that is implemented using a binary tree. It supports
/// concurrent insertions but does not support removals or rebalancing of
/// the tree.
Expand All @@ -165,8 +140,7 @@ class AtomicMaybeOwningPointer<T, true> {
/// /// where KeyTy is the type of the first argument to getOrInsert and
/// /// ArgTys is the type of the remaining arguments.
/// static size_t getExtraAllocationSize(KeyTy key, ArgTys...)
template <class EntryTy, bool ProvideDestructor = true>
class ConcurrentMap {
template <class EntryTy> class ConcurrentMap {
struct Node {
std::atomic<Node*> Left;
std::atomic<Node*> Right;
Expand Down Expand Up @@ -208,7 +182,7 @@ class ConcurrentMap {
};

/// The root of the tree.
AtomicMaybeOwningPointer<Node, ProvideDestructor> Root;
std::atomic<Node*> Root;

/// This member stores the address of the last node that was found by the
/// search procedure. We cache the last search to accelerate code that
Expand All @@ -221,14 +195,13 @@ class ConcurrentMap {
ConcurrentMap(const ConcurrentMap &) = delete;
ConcurrentMap &operator=(const ConcurrentMap &) = delete;

// ConcurrentMap<T, false> must have a trivial destructor.
~ConcurrentMap() = default;

public:
~ConcurrentMap() {
::delete Root.load(std::memory_order_relaxed);
}

#ifndef NDEBUG
void dump() const {
auto R = Root.Value.load(std::memory_order_acquire);
auto R = Root.load(std::memory_order_acquire);
printf("digraph g {\n"
"graph [ rankdir = \"TB\"];\n"
"node [ fontsize = \"16\" ];\n"
Expand All @@ -252,7 +225,7 @@ class ConcurrentMap {
}

// Search the tree, starting from the root.
Node *node = Root.Value.load(std::memory_order_acquire);
Node *node = Root.load(std::memory_order_acquire);
while (node) {
int comparisonResult = node->Payload.compareWithKey(key);
if (comparisonResult == 0) {
Expand Down Expand Up @@ -285,7 +258,7 @@ class ConcurrentMap {
Node *newNode = nullptr;

// Start from the root.
auto edge = &Root.Value;
auto edge = &Root;

while (true) {
// Load the edge.
Expand Down Expand Up @@ -340,6 +313,4 @@ class ConcurrentMap {
}
};

} // end namespace swift

#endif // SWIFT_RUNTIME_CONCURRENTUTILS_H
29 changes: 2 additions & 27 deletions stdlib/public/runtime/Demangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,35 +209,10 @@ Demangle::NodePointer swift::_swift_buildDemanglingForMetadata(const Metadata *t
}
case MetadataKind::Tuple: {
auto tuple = static_cast<const TupleTypeMetadata *>(type);
const char *labels = tuple->Labels;
auto tupleNode = NodeFactory::create(Node::Kind::NonVariadicTuple);
for (unsigned i = 0, e = tuple->NumElements; i < e; ++i) {
auto elt = NodeFactory::create(Node::Kind::TupleElement);

// Add a label child if applicable:
if (labels) {
// Look for the next space in the labels string.
if (const char *space = strchr(labels, ' ')) {
// If there is one, and the label isn't empty, add a label child.
if (labels != space) {
auto eltName =
NodeFactory::create(Node::Kind::TupleElementName,
std::string(labels, space));
elt->addChild(std::move(eltName));
}

// Skip past the space.
labels = space + 1;
}
}

// Add the element type child.
auto eltType =
_swift_buildDemanglingForMetadata(tuple->getElement(i).Type);
elt->addChild(std::move(eltType));

// Add the completed element to the tuple.
tupleNode->addChild(std::move(elt));
auto elt = _swift_buildDemanglingForMetadata(tuple->getElement(i).Type);
tupleNode->addChild(elt);
}
return tupleNode;
}
Expand Down
Loading