CharsetUtils alternatives that avoid allocations.

Internally String.getBytes() calls libcore.util.CharsetUtils methods
for a handful of common charsets, but that path requires new memory
allocations for every call.

This change introduces alternative versions of those methods which
attempt to encode data directly into an already-allocated memory
region.  If the destination is to small, callers can detect and pivot
back to calling String.getBytes().

The included benchmarks reveal these raw performance improvements,
in addition to the reduced GC load which is harder to measure:

    timeLocal_LargeBuffer[simple]_mean: 424
    timeLocal_SmallBuffer[simple]_mean: 511
    timeUpstream[simple]_mean: 800

    timeLocal_LargeBuffer[complex]_mean: 977
    timeLocal_SmallBuffer[complex]_mean: 1266
    timeUpstream[complex]_mean: 1468

Bug: 171832118
Test: atest CorePerfTests:android.util.CharsetUtilsPerfTest
Test: atest FrameworksCoreTests:android.util.CharsetUtilsTest
Change-Id: Iac1151e7cb8e88bf82339cada64b0936e1a7578b
6 files changed