Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Commit

Permalink
Final touches.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolay Igotti committed Apr 9, 2019
1 parent d7dd6d2 commit 87521e9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
25 changes: 20 additions & 5 deletions runtime/src/main/cpp/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,10 @@ void dumpObject(ObjHeader* ref, int indent) {
}

void dumpContainerContent(ContainerHeader* container) {
if (container->refCount() <= 0) {
MEMORY_LOG("%p has non-positive RC, likely a memory bug\n", container)
return;
}
if (isAggregatingFrozenContainer(container)) {
MEMORY_LOG("%s aggregating container %p with %d objects rc=%d\n",
colorNames[container->color()], container, container->objectCount(), container->refCount());
Expand Down Expand Up @@ -1630,7 +1634,7 @@ OBJ_GETTER(AllocInstance, const TypeInfo* type_info) {
ContainerHeader* header = container.header();
// We cannot collect until reference will be stored into the stack slot.
if (header->tag() == CONTAINER_TAG_NORMAL) {
IncrementRC<false>(header);
IncrementRC</* Atomic = */ false>(header);
EnqueueDecrementRC</* CanCollect = */ true>(header);
}
RETURN_OBJ(container.GetPlace());
Expand All @@ -1643,7 +1647,7 @@ OBJ_GETTER(AllocArrayInstance, const TypeInfo* type_info, int32_t elements) {
ContainerHeader* header = container.header();
// We cannot collect until reference will be stored into the stack slot.
if (header->tag() == CONTAINER_TAG_NORMAL) {
IncrementRC<false>(header);
IncrementRC</* Atomic = */ false>(header);
EnqueueDecrementRC</* CanCollect = */ true>(header);
}
RETURN_OBJ(container.GetPlace()->obj());
Expand Down Expand Up @@ -1978,10 +1982,24 @@ OBJ_GETTER(AdoptStablePointer, KNativePtr pointer) {
MEMORY_LOG("adopting stable pointer %p, rc=%d\n", \
ref, (ref && ref->container()) ? ref->container()->refCount() : -1)
UpdateReturnRef(OBJ_RESULT, ref);
if (ref != nullptr) {
auto* container = ref->container();
// Effectively adoption is like allocation, so for the normal objects - do the same thing.
if (container != nullptr && container->tag() == CONTAINER_TAG_NORMAL) {
IncrementRC</* Atomic = */ false>(container);
EnqueueDecrementRC</* CanCollect = */ true>(container);
}
}
DisposeStablePointer(pointer);
return ref;
}

void* ObjHolder::transfer() {
auto* result = obj_;
obj_ = nullptr;
return CreateStablePointer(result);
}

#if USE_GC
bool hasExternalRefs(ContainerHeader* start, ContainerHeaderSet* visited) {
ContainerHeaderDeque toVisit;
Expand Down Expand Up @@ -2029,12 +2047,9 @@ bool ClearSubgraphReferences(ObjHeader* root, bool checked) {
released->decRefCount<false>();
}
}
container->decRefCount<false>();
MarkGray<false>(container);
auto bad = hasExternalRefs(container, &visited);
ScanBlack<false>(container);
// Restore original RC.
container->incRefCount<false>();
for (auto it = state->toRelease->begin(); it != state->toRelease->end(); ++it) {
auto released = *it;
if (!isMarkedAsRemoved(released) && released->tag() == CONTAINER_TAG_NORMAL) {
Expand Down
6 changes: 1 addition & 5 deletions runtime/src/main/cpp/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,7 @@ class ObjHolder {

void clear() { ::ZeroStackRef(&obj_); }

void* transfer() {
auto* result = obj_;
obj_ = nullptr;
return result;
}
void* transfer();

private:
ObjHeader** frame() { return reinterpret_cast<ObjHeader**>(&frame_); }
Expand Down

0 comments on commit 87521e9

Please sign in to comment.