Commit graph

442 commits

Author SHA1 Message Date
Josh Gao
01937ee2b9 libutils: allow multiple ATRACE_NAMEs in a scope.
Bug: http://b/31289465
Test: m
Change-Id: Iabd97439fa55ea285ce0501dbb4fd9d07149ae61
2016-12-12 12:28:04 -08:00
Mark Salyzyn
0eeb06b932 utils: Add FastStrcmp.h
Move existing fast<str*cmp> templates for general use, pulled from
the implementation used in logd that dealt with speed through cache
locality and subroutine call mitigation.  Rename to fastcmp.

Test: logd-benchmarks and based on manual profiling from the past
Bug: 31456426
Change-Id: Ic62f4a437fc3e06ffdeaae73a6f34e197957a6b0
2016-12-09 12:40:17 -08:00
Mark Salyzyn
8a7297a09f Merge "system/core: preparation to pull back interfaces from android/log.h"
am: 27d2d49f48

Change-Id: I604bb1d4cf62636663fa92e3d14a55887dbcae23
2016-10-20 18:03:57 +00:00
Mark Salyzyn
cfd5b080af system/core: preparation to pull back interfaces from android/log.h
Point to log/log.h where necessary, define LOG_TAG where necessary.
Accept that private/android_logger.h is suitable replacement for
log/logger.h and android/log.h.

Correct liblog/README

Effectively a cleanup and controlled select revert of
'system/core: drop or replace log/logger.h' and
'system/core: Replace log/log.h with android/log.h'.

Test: compile
Bug: 30465923
Change-Id: Ic2ad157bad6f5efe2c6af293a73bb753300b17a2
2016-10-20 08:11:39 -07:00
Mark Salyzyn
0abff8fc61 system/core Replace cutils/log.h with android/log.h am: 66ce3e08c5 am: eb189f147b
am: 16f7786032

Change-Id: I26939d55686b6182c9fae5fc74f3e7ed92132cdb
2016-09-30 22:18:03 +00:00
Mark Salyzyn
66ce3e08c5 system/core Replace cutils/log.h with android/log.h
Should use android/log.h instead of cutils/log.h as a good example
to all others.  Adjust header order to comply with Android Coding
standards.

Test: Compile
Bug: 26552300
Bug: 31289077
Change-Id: I2c9cbbbd64d8dccf2d44356361d9742e4a9b9031
2016-09-30 12:47:05 -07:00
Colin Cross
0763c30289 Merge "Fix more system/core/include warnings" am: 18fbd80504 am: 5fe194a9fd
am: b5ca47989c

Change-Id: I8d5a602f94bc57866aa3827cc508c94afb4ac4ba
2016-09-29 17:58:08 +00:00
Colin Cross
1811d156e9 Fix more system/core/include warnings
The warnings in these files were hidden by -isystem
framework/native/include.

Bug: 31752268
Test: m -j
Change-Id: I2a54376aea380ee24e6483fb7d35fdfe8991c490
2016-09-27 16:21:12 -07:00
David Pursell
7bc0052ff1 Merge "Flattenable: switch from assignment to memcpy()." am: b2356a6993 am: bb276d8555
am: 9f106bece8

Change-Id: I43e4e5c6bb0aa1fd23a1d0d9776c9e2c8028527e
2016-09-23 22:56:01 +00:00
David Pursell
b2356a6993 Merge "Flattenable: switch from assignment to memcpy()." 2016-09-23 22:46:03 +00:00
David Pursell
2ebce7384b Flattenable: switch from assignment to memcpy().
FlattenableUtils read() and write() currently use assignment to copy
bytes. However, by casting the void* buffer to type T, the compiler is
allowed to assume that buffer obeys the alignment requirements of T,
which is not necessarily the case during serialization. On some
architectures, we can get SIGBUS when this alignment is violated.

We don't want the users of these routines to have to worry about
alignment when packing structures, so use memcpy() instead which should
always be safe since the compiler won't assume any alignment for the
void* buffer.

On architectures that can handle unaligned direct read/write of type T,
the compiler should be smart enough to optimize this code back to a
direct read/write anyway, but architectures that can't handle it will
fall back to memcpy; this means that this change shouldn't have any
impact on current Android devices. See the linked bug for more details.

Bug: http://b/31671510
Test: libgui Sensor serialization no longer gives SIGBUS.
Test: libgui.so unchanged on Shamu before and after this CL.
Change-Id: I2197127e8cbfb43f4f553bda6464f6ebe087febd
2016-09-23 13:56:40 -07:00
Colin Cross
28cda0bf38 Merge "Fix warnings in libutils headers" am: 65a1633ec3 am: 0f79b62bf6
am: 1446cbac58

Change-Id: I94a39bb24224218ef1c48080ace3455c1fc7233a
2016-09-22 23:04:13 +00:00
Colin Cross
021899fa8a Merge "Remove has_trivial_move trait from Vector<T>" am: 588b3b0c03 am: 85942090f6
am: 749181c10b

Change-Id: Ie339e0ea27463d0c5b093e9a5e262367d1ca57a5
2016-09-22 22:58:13 +00:00
Colin Cross
17b5b82d64 Fix warnings in libutils headers
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
2016-09-22 13:03:15 -07:00
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
Martijn Coenen
111ef54a28 Merge changes from topic 'utf' am: 3a07e5bf94 am: aa7fd8a3ec
am: ade3876260

Change-Id: Ifec806c7553b36a6502a8b5bb3dec559c117f4cc
2016-08-25 20:31:42 +00: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
2d3545fe82 Merge "Make RefBase more robust and debuggable" am: daac359be7 am: 7bf3d21fde
am: 7dddf9433c

Change-Id: Ia8bdef250b29d964a9ab07c450da31a368bb3143
2016-08-24 23:52:14 +00:00
Hans Boehm
7dddf9433c Merge "Make RefBase more robust and debuggable" am: daac359be7
am: 7bf3d21fde

Change-Id: I643c4bd38062b80d382c50ed161f5440f35c1dd9
2016-08-24 23:49:14 +00:00
Hans Boehm
daac359be7 Merge "Make RefBase more robust and debuggable" 2016-08-24 23:36:13 +00:00
Andy Hung
8ec6753d61 Fix Mutex::timedLock to properly handle relative time am: 604ba48220 am: 708b9d118a
am: 47e5ca61e2

Change-Id: I5c351fbdc485acbcb33426b99ea6b900519ee0e3
2016-08-24 22:50:00 +00:00
Andy Hung
604ba48220 Fix Mutex::timedLock to properly handle relative time
Bug: 31008450
Change-Id: Ie6c17e17b7a8c3d8a087c47be535e9d04f285380
2016-08-24 22:29:11 +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
f997434b06 Merge "Improve RefBase documentation, especially for clients." am: 0f39fe22ae
am: df6c464e9a

Change-Id: I8fa12835ff648d78c68265facb5b63ca7b1eab6a
2016-08-10 16:26:59 +00: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
e1fff2572c Merge "Fix google-explicit-constructor warnings in utils." am: 5b7e3b9a2a
am: 4d031d6358

Change-Id: I89352ced43afd415aefe2b8e45dd9fdd76dc0551
2016-08-04 21:51:20 +00: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
d20120ae1f Merge \\"LruCache: avoid copying keys in lookup\\" am: 896c6b14ae
am: 4476929073

Change-Id: I3c49a22c68c8a66c912f08e3b7cdd8340de69532
2016-07-20 19:51:07 +00: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
Sergio Giro
71d9f83fa9 Merge \"libutils/Unicode.cpp: Correct length computation and add checks for utf16->utf8\" into nyc-dev
am: 757f4ef340

Change-Id: I29dfaa3968597fc3b0cdadd140b5790c1e61008d
2016-07-14 18:08:00 +00:00
Sergio Giro
570dbfb8b8 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-07-14 13:40:43 +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
Sergio Giro
c4966a363e 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
2016-07-11 09:46:32 +00:00
Hans Boehm
70a46d674a 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
(cherry picked from commit e263e6c633)
2016-05-19 16:18:26 -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