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

Commit

Permalink
Review feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolay Igotti committed Apr 9, 2019
1 parent 87cc869 commit 932d1f4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 31 deletions.
25 changes: 0 additions & 25 deletions runtime/src/main/cpp/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1982,35 +1982,10 @@ 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::hold() {
if (obj_ != nullptr) {
MEMORY_LOG("Holding %p, rc=%d\n", obj_, obj_->container() ? obj_->container()->refCount() : -1)
AddHeapRef(obj_);
}
}

void* ObjHolder::transferHeld() {
auto* result = obj_;
if (result != nullptr) {
auto* container = result->container();
MEMORY_LOG("Transferring %p, rc=%d\n", result, container ? container->refCount() : -1)
clear();
}
return result;
}

#if USE_GC
bool hasExternalRefs(ContainerHeader* start, ContainerHeaderSet* visited) {
ContainerHeaderDeque toVisit;
Expand Down
4 changes: 0 additions & 4 deletions runtime/src/main/cpp/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -544,10 +544,6 @@ class ObjHolder {

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


void hold();
void* transferHeld();

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

Expand Down
6 changes: 4 additions & 2 deletions runtime/src/main/cpp/Worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ enum {
THREAD_LOCAL_VARIABLE KInt g_currentWorkerId = 0;

KNativePtr transfer(ObjHolder* holder, KInt mode) {
holder->hold();
void* result = CreateStablePointer(holder->obj());
if (!ClearSubgraphReferences(holder->obj(), mode == CHECKED)) {
DisposeStablePointer(result);
ThrowWorkerInvalidState();
}
return holder->transferHeld();
holder->clear();
return result;
}

class Locker {
Expand Down

0 comments on commit 932d1f4

Please sign in to comment.