Merge changes from topic \'parcel-v2\' into mnc-dr-dev am: cf33d50d25

am: 0c11f9918c

* commit '0c11f9918c6f834f12d97315ef0247c08f8fef63':
  Maintain Parcel ABI
  Revert "Revert "Track ashmem memory usage in Parcel""
This commit is contained in:
Adrian Roos 2015-10-23 17:32:40 +00:00 committed by android-build-merger
commit bcc709b94d
2 changed files with 51 additions and 15 deletions

View File

@ -341,10 +341,12 @@ public:
}; };
private: private:
size_t mBlobAshmemSize; size_t mOpenAshmemSize;
public: public:
// TODO: Remove once ABI can be changed.
size_t getBlobAshmemSize() const; size_t getBlobAshmemSize() const;
size_t getOpenAshmemSize() const;
}; };
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@ -96,7 +96,7 @@ enum {
}; };
void acquire_object(const sp<ProcessState>& proc, void acquire_object(const sp<ProcessState>& proc,
const flat_binder_object& obj, const void* who) const flat_binder_object& obj, const void* who, size_t* outAshmemSize)
{ {
switch (obj.type) { switch (obj.type) {
case BINDER_TYPE_BINDER: case BINDER_TYPE_BINDER:
@ -123,8 +123,15 @@ void acquire_object(const sp<ProcessState>& proc,
return; return;
} }
case BINDER_TYPE_FD: { case BINDER_TYPE_FD: {
// intentionally blank -- nothing to do to acquire this, but we do if (obj.cookie != 0) {
// recognize it as a legitimate object type. if (outAshmemSize != NULL) {
// If we own an ashmem fd, keep track of how much memory it refers to.
int size = ashmem_get_size_region(obj.handle);
if (size > 0) {
*outAshmemSize += size;
}
}
}
return; return;
} }
} }
@ -132,8 +139,14 @@ void acquire_object(const sp<ProcessState>& proc,
ALOGD("Invalid object type 0x%08x", obj.type); ALOGD("Invalid object type 0x%08x", obj.type);
} }
void release_object(const sp<ProcessState>& proc, void acquire_object(const sp<ProcessState>& proc,
const flat_binder_object& obj, const void* who) const flat_binder_object& obj, const void* who)
{
acquire_object(proc, obj, who, NULL);
}
static void release_object(const sp<ProcessState>& proc,
const flat_binder_object& obj, const void* who, size_t* outAshmemSize)
{ {
switch (obj.type) { switch (obj.type) {
case BINDER_TYPE_BINDER: case BINDER_TYPE_BINDER:
@ -160,7 +173,16 @@ void release_object(const sp<ProcessState>& proc,
return; return;
} }
case BINDER_TYPE_FD: { case BINDER_TYPE_FD: {
if (obj.cookie != 0) close(obj.handle); if (outAshmemSize != NULL) {
if (obj.cookie != 0) {
int size = ashmem_get_size_region(obj.handle);
if (size > 0) {
*outAshmemSize -= size;
}
close(obj.handle);
}
}
return; return;
} }
} }
@ -168,6 +190,12 @@ void release_object(const sp<ProcessState>& proc,
ALOGE("Invalid object type 0x%08x", obj.type); ALOGE("Invalid object type 0x%08x", obj.type);
} }
void release_object(const sp<ProcessState>& proc,
const flat_binder_object& obj, const void* who)
{
release_object(proc, obj, who, NULL);
}
inline static status_t finish_flatten_binder( inline static status_t finish_flatten_binder(
const sp<IBinder>& /*binder*/, const flat_binder_object& flat, Parcel* out) const sp<IBinder>& /*binder*/, const flat_binder_object& flat, Parcel* out)
{ {
@ -504,7 +532,7 @@ status_t Parcel::appendFrom(const Parcel *parcel, size_t offset, size_t len)
flat_binder_object* flat flat_binder_object* flat
= reinterpret_cast<flat_binder_object*>(mData + off); = reinterpret_cast<flat_binder_object*>(mData + off);
acquire_object(proc, *flat, this); acquire_object(proc, *flat, this, &mOpenAshmemSize);
if (flat->type == BINDER_TYPE_FD) { if (flat->type == BINDER_TYPE_FD) {
// If this is a file descriptor, we need to dup it so the // If this is a file descriptor, we need to dup it so the
@ -923,8 +951,6 @@ status_t Parcel::writeBlob(size_t len, bool mutableCopy, WritableBlob* outBlob)
int fd = ashmem_create_region("Parcel Blob", len); int fd = ashmem_create_region("Parcel Blob", len);
if (fd < 0) return NO_MEMORY; if (fd < 0) return NO_MEMORY;
mBlobAshmemSize += len;
int result = ashmem_set_prot_region(fd, PROT_READ | PROT_WRITE); int result = ashmem_set_prot_region(fd, PROT_READ | PROT_WRITE);
if (result < 0) { if (result < 0) {
status = result; status = result;
@ -1026,7 +1052,7 @@ restart_write:
// Need to write meta-data? // Need to write meta-data?
if (nullMetaData || val.binder != 0) { if (nullMetaData || val.binder != 0) {
mObjects[mObjectsSize] = mDataPos; mObjects[mObjectsSize] = mDataPos;
acquire_object(ProcessState::self(), val, this); acquire_object(ProcessState::self(), val, this, &mOpenAshmemSize);
mObjectsSize++; mObjectsSize++;
} }
@ -1609,7 +1635,7 @@ void Parcel::releaseObjects()
i--; i--;
const flat_binder_object* flat const flat_binder_object* flat
= reinterpret_cast<flat_binder_object*>(data+objects[i]); = reinterpret_cast<flat_binder_object*>(data+objects[i]);
release_object(proc, *flat, this); release_object(proc, *flat, this, &mOpenAshmemSize);
} }
} }
@ -1623,7 +1649,7 @@ void Parcel::acquireObjects()
i--; i--;
const flat_binder_object* flat const flat_binder_object* flat
= reinterpret_cast<flat_binder_object*>(data+objects[i]); = reinterpret_cast<flat_binder_object*>(data+objects[i]);
acquire_object(proc, *flat, this); acquire_object(proc, *flat, this, &mOpenAshmemSize);
} }
} }
@ -1805,7 +1831,7 @@ status_t Parcel::continueWrite(size_t desired)
// will need to rescan because we may have lopped off the only FDs // will need to rescan because we may have lopped off the only FDs
mFdsKnown = false; mFdsKnown = false;
} }
release_object(proc, *flat, this); release_object(proc, *flat, this, &mOpenAshmemSize);
} }
binder_size_t* objects = binder_size_t* objects =
(binder_size_t*)realloc(mObjects, objectsSize*sizeof(binder_size_t)); (binder_size_t*)realloc(mObjects, objectsSize*sizeof(binder_size_t));
@ -1890,7 +1916,7 @@ void Parcel::initState()
mFdsKnown = true; mFdsKnown = true;
mAllowFds = true; mAllowFds = true;
mOwner = NULL; mOwner = NULL;
mBlobAshmemSize = 0; mOpenAshmemSize = 0;
} }
void Parcel::scanForFds() const void Parcel::scanForFds() const
@ -1910,7 +1936,15 @@ void Parcel::scanForFds() const
size_t Parcel::getBlobAshmemSize() const size_t Parcel::getBlobAshmemSize() const
{ {
return mBlobAshmemSize; // This used to return the size of all blobs that were written to ashmem, now we're returning
// the ashmem currently referenced by this Parcel, which should be equivalent.
// TODO: Remove method once ABI can be changed.
return mOpenAshmemSize;
}
size_t Parcel::getOpenAshmemSize() const
{
return mOpenAshmemSize;
} }
// --- Parcel::Blob --- // --- Parcel::Blob ---