summaryrefslogtreecommitdiffstats
path: root/libutils/RefBase.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Use -Werror in system/coreChih-Hung Hsieh2017-11-011-2/+1
| | | | | | | | | * Move -Wall -Werror from cppflags to cflags. * Fix/suppress warning on unused variables. Bug: 66996870 Test: build with WITH_TIDY=1 Change-Id: I1e05e96a1d0bcb2ccef1ce456504b3af57167cc5
* Silence a use-after-free warning from the analyzerGeorge Burgess IV2017-10-021-0/+5
| | | | | | | | | | | | | | | | | | | The analyzer is known to be very conservative in the face of atomic operations (e.g. https://bugs.llvm.org/show_bug.cgi?id=34365); this case is no different. It's concerned that `delete this;` might read a different value for `flags`, and proceed to delete `refs`. Since there are many comments explaining why this won't happen (and it all looks sane to me), use a NOLINT to silence this warning. Analyzer warning: system/core/libutils/RefBase.cpp:445:5: warning: Use of memory after it is freed Bug: 27101951 Test: mma. Use-after-free warning is gone. Change-Id: Ic1623971bd1bad546fbb12a79439116c89a6762d
* split LightRefBase out of RefBaseMathias Agopian2017-03-291-2/+0
| | | | | | Bug: 36532900 Test: compiled Change-Id: I3088e1a219e04cf924744d3a0c2d374918bb6395
* clean-up libutils includesMathias Agopian2017-03-031-9/+0
| | | | | | | | | | | | moved Foo.h as first include of Foo.cpp, and removed redundant includes. Made NativeHandle non virtual. Test: run & compile Bug: n/a Change-Id: I37fa746cd42c9ba23aba181f84cb6c619386406a
* RefBase.cpp remove unused include typeinfoSteven Moreland2017-02-151-1/+0
| | | | | Test: pass Change-Id: Iec9b9e1e9b6c974124b2043f550fb110cc22846d
* Fix more system/core/include warningsColin Cross2016-09-271-2/+0
| | | | | | | | | The warnings in these files were hidden by -isystem framework/native/include. Bug: 31752268 Test: m -j Change-Id: I2a54376aea380ee24e6483fb7d35fdfe8991c490
* Fix warnings in libutils headersColin Cross2016-09-221-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | system/core/include is included in the global include path using -isystem, which hides all warnings. Fix warnings in libutils headers in preparation for moving from -isystem to -I. - Fix implicit cast from int64_t to long in Condition.h. Remove the __LP64__ check and always compare against LONG_MAX before casting. - Fix implicit cast from size_t to ssize_t in KeyedVector.h - Fix -Wshadow-field-in-constructor warnings in Looper.h and RefBase.h - Move destructors for MessageHandler and LooperCallback to Looper.cpp and ReferenceRenamer and VirtualLightRefBase to RefBase.cpp to prevent vtables in every compilation unit. - Declare template variables in Singleton.h - Fix old-style casts in StrongPointer.h and TypeHelpers.h - Use template metaprogramming in TypeHelpers.h to avoid warnings on memmove on non-trivial types. - Add an assignment operator to key_value_pair_t to complete rule-of-three - Use memcpy instead of dereferencing a reinterpret_casted pointer to treat the bits of a float or double as int32_t or int64_t - Escape unicode sequences inside doxygen comments between \code and \endcode - Remove WIN32 ZD definition in Compat.h, %zd works fine with mingw - Fix WIN32 printf warnings in Filemap.cpp - Initialize mNullValue with 0 in LruCache.h, some of the tests use a non-pointer type for TValue. Test: m -j native Bug: 31492149 Change-Id: I385a05a3ca01258e44fe3b37ef77e4aaff547b26
* Make RefBase more robust and debuggableHans Boehm2016-08-131-32/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This prevents two different kinds of client errors from causing undetected memory corruption, and helps with the detection of others: 1. We no longer deallocate objects when the weak count goes to zero and there have been no strong references. This otherwise causes us to return a garbage object from a constructor if the constructor allocates and deallocates a weak pointer to this. And we do know that clients allocate such weak pointers in constructors and their lifetime is hard to trace. 2. We abort if a RefBase object is explicitly destroyed while the weak count is nonzero. Otherwise a subsequent decrement would cause a write to potentially reallocated memory. 3. We check counter values returned by atomic decrements for plausibility, and fail immediately if they are not plausible. We unconditionally log any cases in which 1 changes behavior from before. We abort in cases in which 2 changes behavior, since those reflect clear bugs. In case 1, a log message now indicates a possible leak. We have not seen such a message in practice. The third point introduces a small amount of overhead into the reference count decrement path. But this should be negligible compared to the actual decrement cost. Add a test for promote/attemptIncStrong that tries to check for both (1) above and concurrent operation of attemptIncStrong. Add some additional warnings and explanations to the RefBase documentation. Bug: 30503444 Bug: 30292291 Bug: 30292538 Change-Id: Ida92b9a2e247f543a948a75d221fbc0038dea66c
* Improve RefBase documentation, especially for clients.Hans Boehm2016-08-091-10/+17
| | | | | | | | | | | | | | | Add basic interface documentation to RefBase.h. Much, but not all, of this is cut-and-pasted from an email message from Mathias Agopian. The rest is reconstructed from the code. Delete some, now redundant, text from Refbase.cpp, and add a bit more about the implementation strategy. Some minor fixes to internal comments. Bug: 30292291 Change-Id: I56518ae5553bc6de0cc2331778e7fcf2e6c4fd87
* Fix race bug in attemptIncStrongHans Boehm2016-07-291-10/+9
| | | | | | | | | | | | | | | | | The compensating onLastStrongRef call could be made even when there was no onIncStrongAttempted call to compensate for. This happened in the OBJECT_LIFETIME_STRONG case when e.g. curCount was initially zero, but was concurrently incremented by another thread. I believe the old code was also incorrect in the curCount = INITIAL_STRONG_VALUE + 1 case, which seems to be possible under unlikely conditions. In that case, I believe the compensating call IS needed. Thus the condition was also changed. Bug: 30503444 Change-Id: I44bcbcbb1264e4b52b6d3750dc39b041c4140381
* Fix memory order and race bugs in Refbase.h & RefBase.cppHans Boehm2016-05-171-58/+140
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Convert to use std::atomic directly. Consistently use relaxed ordering for increments, release ordering for decrements, and an added acquire fence when the count goes to zero. Fix what looks like another race in attemptIncStrong: It seems entirely possible that the final adjustment for INITIAL_STRONG_VALUE would see e.g. INITIAL_STRONG_VALUE + 1, since we could be running in the middle of another initial increment. Attempt to somewhat document what this actually does, and what's expected from the client. Hide the documentation in the .cpp file for now. Remove a confusing redundant test in decWeak. OBJECT_LIFETIME_STRONG and OBJECT_LIFETIME_WEAK are the only options, in spite of some of the original comments. It's conceivable that either of these issues has resulted in actual crashes, though I would guess the probability is small. It's hard enough to reason about this code without the bugs. Bug: 28705989 Change-Id: I4107a56c3fc0fdb7ee17fc8a8f0dd7fb128af9d8
* Fix google-explicit-constructor warnings.Chih-Hung Hsieh2016-04-291-1/+1
| | | | | Bug: 28341362 Change-Id: I4504e98a8db31e0edcbe63c23f9af43eb13e9d86
* Cleanup uses of sprintf so we can deprecate it.George Burgess IV2016-03-071-5/+10
| | | | | | | | Also cleans up two instances of open() with useless mode params, and changes a few uses of snprintf to use sizeof(buffer) instead of hardcoded buffer sizes. Change-Id: If11591003d910c995e72ad8f75afd072c255a3c5
* libutils: turn on -WerrorMark Salyzyn2014-06-021-11/+17
| | | | | | | | | - Deal with some -Wunused issues - Override PRI macros (windows) - Revert use of PRI macros on off64_t (linux) - Deal with a gnu++11 complaince issue Change-Id: Ie66751293bd84477a5a6dfd8a57e700a16e36964
* Fix stack trace logging in RefBase.Ian McKellar2014-04-011-2/+2
| | | | | | | This was broken about 5 months ago in change I78435ed49aa196a0efb45bf9b2d58b62c41737d3. See: https://goto.google.com/jhtss Change-Id: Icc32993552efed3015bc1b79a7bd872d7510e020
* move libs/utils to libutilsAlex Ray2013-08-021-0/+650
Change-Id: I6cf4268599460791414882f91eeb88a992fbd29d