Commit graph

416 commits

Author SHA1 Message Date
Colin Cross
097395532b Remove has_trivial_move trait from Vector<T>
Vector<T> objects are a dynamic type with a vtable, which is not
trivially moveable.

Impact on aapt for frameworks-res is negligible, ~3%.

Bug: 31595853
Test: m -j framework-res
Change-Id: I8a3269c35d95affb6e86d60588bcfca46db7f445
2016-09-22 10:14:05 -07:00
Sergio Giro
1cfa56d46c libutils/Unicode.cpp: Correct length computation and add checks for utf16->utf8
Inconsistent behaviour between utf16_to_utf8 and utf16_to_utf8_length
is causing a heap overflow.

Correcting the length computation and adding bound checks to the
conversion functions.

Test: ran libutils_tests
Bug: 29250543
Change-Id: I6115e3357141ed245c63c6eb25fc0fd0a9a7a2bb
(cherry picked from commit c4966a363e)
2016-08-25 20:07:51 +00:00
Sergio Giro
9de6776321 Unicode: specify destination length in utf8_to_utf16 methods
String16(const char *utf8) now returns the empty string in case
a string ends halfway throw a utf8 character.

Bug: 29267949
Clean cherry-pick from 1dcc0c8239

Change-Id: I5223caa7d42f4582a982609a898a02043265c6d3
2016-08-25 19:57:06 +00:00
Hans Boehm
daac359be7 Merge "Make RefBase more robust and debuggable" 2016-08-24 23:36:13 +00:00
Hans Boehm
23c857ebd6 Make RefBase more robust and debuggable
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
2016-08-13 11:17:51 -07:00
Hans Boehm
df6c464e9a Merge "Improve RefBase documentation, especially for clients."
am: 0f39fe22ae

Change-Id: I804989b192142dc9d69ca36f0122079822625e7e
2016-08-10 16:24:01 +00:00
Hans Boehm
0f39fe22ae Merge "Improve RefBase documentation, especially for clients." 2016-08-10 16:16:22 +00:00
Hans Boehm
9ba7192c1f Improve RefBase documentation, especially for clients.
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
2016-08-09 15:12:19 -07:00
Chih-Hung Hsieh
4d031d6358 Merge "Fix google-explicit-constructor warnings in utils."
am: 5b7e3b9a2a

Change-Id: I88b7d5f20f26a028c90efdb837730e5b8631ce80
2016-08-04 21:48:20 +00:00
Chih-Hung Hsieh
2a929968e1 Fix google-explicit-constructor warnings in utils.
* Declare explicit conversion constructors.
* Use NOLINT(implicit) for implicit conversion constructors.

Bug: 28341362
Change-Id: I4fb58fa32aafc520b2ed862a05a8bdbfabbc6c35
Test: build with WITH_TIDY=1
2016-08-02 12:20:06 -07:00
Sergio Giro
4476929073 Merge \"LruCache: avoid copying keys in lookup\"
am: 896c6b14ae

Change-Id: If8223e90988510385378506cd3a05d382ab73fc9
2016-07-20 19:48:44 +00:00
Sergio Giro
4c56e0a222 LruCache: avoid copying keys in lookup
Create objects of type KeyedEntry for lookups that only have
a key reference

Bug: 27567036
Change-Id: I5e609a3db63d3b9277ff1547a3cca37dce70251c
2016-07-20 18:38:44 +00:00
Greg Kaiser
3b43562535 Merge \"RefBase: Silence compiler warnings\"
am: f76ca2a43b

Change-Id: I4a146e36db49fc336baa7a59f8fbea0ca1dbb084
2016-07-12 00:15:19 +00:00
Greg Kaiser
d9885e7edb RefBase: Silence compiler warnings
We comment out the names of the parameters we're intentionally
not using.

(cherrypick of 44a0eb4d8cdf4ab881f5d5a1acc1155266a46f6a.)

Change-Id: I0a92d9200ca26cdc4700d2ff9e3ab33c102520d5
2016-07-11 16:11:30 -07:00
Hans Boehm
fdad5af164 Merge "Fix memory order and race bugs in Refbase.h & RefBase.cpp" am: 62212954ef
am: d657e639cf

* commit 'd657e639cf74e0ee5a32d0f67efe0097c3df17a1':
  Fix memory order and race bugs in Refbase.h & RefBase.cpp

Change-Id: I79106bb0399e7699d51d526235843504ab52708b
2016-05-19 22:12:01 +00:00
Hans Boehm
e263e6c633 Fix memory order and race bugs in Refbase.h & RefBase.cpp
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
2016-05-17 16:11:11 -07:00
Michael Wright
2a9a993af9 Merge commit '8b452b876b90dcfff1dab9012b65b5e67c4531a4' into manual_merge_8b452b8
Change-Id: Iacdc2d521f669661b4979c03b0476512abdb37c7
2016-05-16 15:06:22 +01:00
Michael Wright
5bacef33c9 Add String16#contains and strstr16 methods.
These are needed for aapt to find javadoc comments that contain
"@removed" in order to skip them when printing styleable docs.

Bug: 28663748
Change-Id: I8866d2167c41e11d6c2586da369560d5815fd13e
2016-05-09 19:45:07 +01:00
Elliott Hughes
46ae7d36a4 Merge "Remove <utils/ashmem.h>." am: f9f76146a1
am: ee3202563b

* commit 'ee3202563be401328ad318d77d7c6c0622ab0960':
  Remove <utils/ashmem.h>.

Change-Id: I6d076a9097df4969b703fc2833d464a15692835b
2016-05-04 22:04:29 +00:00
Elliott Hughes
6d7823a54e Remove <utils/ashmem.h>.
Not to be confused with <cutils/ashmem.h> or <linux/ashmem.h>, one or other
of which is what you should be using instead.

Change-Id: Ie158530591b28b94c2cda9e2686cae56b7aeb1a3
2016-05-04 13:33:20 -07:00
Greg Kaiser
e60b407d43 Merge "Mutex: Note that STL is generally prefered" into nyc-dev
am: a30a626

* commit 'a30a6263d632a7d2dedc4f09c6707ab20df3fb1a':
  Mutex: Note that STL is generally prefered

Change-Id: I69eec173bf9679dc592987bd78cc8edcc81a1fbb
2016-04-06 13:06:00 +00:00
Greg Kaiser
d62698d4a3 Mutex: Note that STL is generally prefered
This class was designed prior to Android having usable C++11
support.  With that support now in place, we prefer people to
start using the STL threading classes, unless the code needs
to build on Win32.

Change-Id: If1b4d9bdfcb1e65824909376f022842bab9653d6
2016-04-05 12:38:47 -07:00
Elliott Hughes
8ea300663e Merge "Fix Condition::waitRelative." am: 0d6bb55
am: 9bf8f9e

* commit '9bf8f9efd4945513f2713159c1d72a7a7bd9cfb5':
  Fix Condition::waitRelative.

Change-Id: I378c8cbdd1b8f2563b6f2e0f7fb3799f0127eff7
2016-04-05 16:54:44 +00:00
Elliott Hughes
fd376b97f7 Fix Condition::waitRelative.
HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE has never been defined for LP64,
so let's have everyone use the same code path.

Also fix the possible overflow.

Bug: http://b/26944282
Bug: http://b/27918161
Change-Id: I51fc0ebb1f6b860dc62d721f8ebfbcf724ce66e7
2016-04-04 14:51:21 -07:00
Brian Carlstrom
de6d6041c1 system/core: Make Thread::run threadName argument required
am: e71b914775

* commit 'e71b9147756ab4da306e4c16461ad23936769603':
  system/core: Make Thread::run threadName argument required
2016-03-14 15:24:54 +00:00
Brian Carlstrom
e71b914775 system/core: Make Thread::run threadName argument required
Bug: 27557176
Change-Id: Iae83a1e5489c86c2858fc8481f246b8480f0eec4
2016-03-12 21:32:52 -08:00
Dan Willemsen
9dddd137c7 Fix windows 64-bit builds
pid_t is 64-bit in 64-bit mingw, but the windows process/thread
functions return a DWORD(uint32_t). Instead of promoting to a pid_t and
fixing the format strings, just use a uint32_t to store the values.

android_thread_id also cannot be a 64-bit pointer, so for windows just
force it to be a uint32_t.

libutils/ProcessCallStack only works under Linux, since it makes heavy
use of /proc. Don't compile it under Windows or Darwin.

Bug: 26957718

(cherry picked from commit 86cf941c48)

Change-Id: I8d39d1951fea1b3011caf585c983e1da7959f7c0
2016-02-25 18:43:55 -08:00
Samuel Tan
9ac4e005b4 libutils: add String8 and String16 std_string utility methods
Add utility methods that convert String16 and String8 into
std::string.

Also, remove a repeated include of <utils/Unicode.h> in
String16.h, since it is not used in that header file,
and is already included in String16.cpp.

BUG: 27200800
Change-Id: I5238aeb70689499763060a99dff9950fbb7adb3e
TEST: libutils builds successfully.
2016-02-18 17:04:23 -08:00
Samuel Tan
95fd527065 libutils: remove whitespace from String8 files
Remove trailing whitespace from String8 header and
cpp files.

BUG: None
Change-Id: Ie77da3f0fbce9cdce20225ce1310cf62295179a4
2016-02-18 17:04:20 -08:00
Samuel Tan
f9d16ef106 libutils: remove whitespaces in String16.cpp and String16.h
Remove trailing whitespaces in both these files.

BUG: None
Change-Id: I18eca5162871b5b2bf7757a7ef36a4e80073798c
2016-02-16 15:21:34 -08:00
Dan Willemsen
86cf941c48 Fix windows 64-bit builds
pid_t is 64-bit in 64-bit mingw, but the windows process/thread
functions return a DWORD(uint32_t). Instead of promoting to a pid_t and
fixing the format strings, just use a uint32_t to store the values.

android_thread_id also cannot be a 64-bit pointer, so for windows just
force it to be a uint32_t.

libutils/ProcessCallStack only works under Linux, since it makes heavy
use of /proc. Don't compile it under Windows or Darwin.

Bug: 26957718
Change-Id: I4e43e7cf18a96f22b3a9a08dbab8c3e960c12930
2016-02-05 16:10:10 -08:00
Sergio Giro
b7170fe3fe libutils: fix cache removal when callback invalidates the key
Bug: 24785286
Change-Id: I9d17d2247258a56ef7776b3a701389e825a9c533
2015-11-20 14:54:51 +00:00
Christopher Wiley
c3441e69c0 libutils: Add UNEXPECTED_NULL status_t
We use this specifically in situations where we expect to read
an object from a Parcel, but fail because the object is null.

Bug: 25617251

Change-Id: Id0b6118b19a932998b5028e30dc15d70e4d7f9c3
2015-11-10 11:12:43 -08:00
Dan Albert
f2d2509690 Use std::unique_ptr instead of UniquePtr.
Bug: http://b/22403888
Change-Id: I398fa43b8f33c9281d7ff238521d75f1dcb8a5e7
2015-11-05 01:09:22 -08:00
John Reck
d69089a742 Teach sp<> how to std::move
Arguably we should migrate to std::shared_ptr
but for now make std::vector<sp<>> a bit less
horrible

Change-Id: Ia458a2daff0b656b2f3310b3ea100565ec844c69
2015-10-29 07:17:40 -07:00
Sergio Giro
0cb59c0dce system/core: fix iterator for LruCache
Was failing to return the first element

Change-Id: Ic803f5d463a56519212014d0d190407cf4b859cf
2015-10-12 16:13:44 +01:00
Adam Lesinski
bda375fa41 am c6c6ab50: Merge "Implement C++11 move semantics for android::FileMap"
* commit 'c6c6ab50bc11d55f3135312ceccbcf0c400b437e':
  Implement C++11 move semantics for android::FileMap
2015-10-02 01:19:25 +00:00
Adam Lesinski
6f8885bc14 Implement C++11 move semantics for android::FileMap
FileMaps should be movable, thereby not requiring them to be only used
with a unique_ptr as they currently are.

Change-Id: I0fb8013bf398a2ced5420d85ba888c2a7fc5a496
2015-10-01 12:47:49 -07:00
Sergio Giro
bdae9bf2ec resolved conflicts for 70808827 to stage-aosp-master
Change-Id: I2de8a63fa5be5423846df4c2e8ccc5f12e843f09
2015-10-01 19:49:22 +01:00
Sergio Giro
f84a4906fa system/core: remove BasicHashtable
Towards deprecation of SharedBuffer

Change-Id: Id6d1c8637583df38b6f28398b6804d9c1e96472a
2015-10-01 11:44:47 +01:00
Sergio Giro
b5a00d6b2e am e0453334: Merge "system/core: remove methods returning SharedBuffer in String8, String16"
* commit 'e045333445ab3ebb8d602d25ed750169f135baa6':
  system/core: remove methods returning SharedBuffer in String8, String16
2015-09-30 20:04:50 +00:00
Sergio Giro
e045333445 Merge "system/core: remove methods returning SharedBuffer in String8, String16" 2015-09-30 15:21:48 +00:00
Sergio Giro
282efae9c3 system/core: remove methods returning SharedBuffer in String8, String16
Towards deprecation of SharedBuffer

Change-Id: I3069837db32837bcc0f5d8f1118ccd502c9070dc
2015-09-30 15:42:02 +01:00
Sergio Giro
8e2c820819 am 730fdbb1: Merge "system/core: change LruCache to use unordered_set instead of BasicHashTable"
* commit '730fdbb1ca4c39a4d69868f7a261b023f2bea296':
  system/core: change LruCache to use unordered_set instead of BasicHashTable
2015-09-30 13:20:02 +00:00
Sergio Giro
730fdbb1ca Merge "system/core: change LruCache to use unordered_set instead of BasicHashTable" 2015-09-30 13:15:21 +00:00
Sergio Giro
bb58cde899 system/core: change LruCache to use unordered_set instead of BasicHashTable
Towards deprecation of BasicHashTable

Change-Id: I3f3d904636a85a794cccf972f6e4a94e7f3808f5
2015-09-30 13:48:30 +01:00
Sami Tolvanen
c6ca7a5a31 am eccf0a45: Merge "utils: add pwrite64 to Compat.h for Mac"
* commit 'eccf0a4502293d628152888be85d1cd6fa0b4751':
  utils: add pwrite64 to Compat.h for Mac
2015-09-28 16:02:35 +00:00
Sami Tolvanen
8731d30085 utils: add pwrite64 to Compat.h for Mac
Compat.h has lseek64 and pread64, but it's missing pwrite64.

Change-Id: I02b4adf5a5e15e55e008ff1ba8113a75faf1c4e9
2015-09-28 16:52:38 +01:00
Sergio Giro
f777655d85 resolved conflicts for 6ee734cf to stage-aosp-master
Change-Id: Ia06c4d941d9b8828707299bb363f51fab5549897
2015-09-23 17:58:25 +01:00
Sergio Giro
d2529f2830 libutils: hide SharedBuffer by moving SharedBuffer.h to the implementation directory
Some methods in header files of classes using SharedBuffer need
to be moved to the implementation files accordingly

Change-Id: I891f3ace2b940ab219e4e449040bfed71c0547db
2015-09-23 16:22:59 +01:00