Skip to content

HprofPrimitiveArrayStripper: sync with android-register, fix bugs, clean up#2736

Open
pyricau wants to merge 4 commits intomainfrom
py/strip_more
Open

HprofPrimitiveArrayStripper: sync with android-register, fix bugs, clean up#2736
pyricau wants to merge 4 commits intomainfrom
py/strip_more

Conversation

@pyricau
Copy link
Member

@pyricau pyricau commented Jan 8, 2025

Sync HprofPrimitiveArrayStripper with the battle-tested android-register implementation, fixing two correctness bugs in the process, and clean up the tests.

Changes

Bug fixes

  • Fix INSTANCE_DUMP parsing: stackTraceSerialNumber is always a u4 (4 bytes), not identifier-sized. This was silently corrupting output for heap dumps with 8-byte identifiers (most Android heap dumps).
  • Fix PRIMITIVE_ARRAY_DUMP double-write: CopyingSource.transferUnsignedByte() already copies the byte to the sink — the extra sink.writeByte(type) call was writing the type byte twice, corrupting all primitive array records.

API / structure

  • Add StreamingSinkProvider (mirrors StreamingSourceProvider) so the sink lifecycle is managed inside the function via .use {}, consistent with how source opening works
  • Replace BufferedSink parameter with StreamingSinkProvider in the streaming overload
  • Refactor parsing into a private stripPrimitiveArrays(CopyingSource) method
  • Add CopyingSource.indexOf delegate (needed by the refactored private method)
  • Use repeat() instead of for (i in 0 until ...) loops

Tests

  • Remove the @Test fun foo() debugging test (broken assertions, println noise)
  • Replace raw-byte HPROF building helpers with a clean writeRawTestHprof fixture using HprofWriter, testing LongArray zeroing, CharArray '?' replacement, and instance dump wrapper value zeroing
  • Remove duplicate ByteArraySourceProvider inner class (it's already in main source)

pyricau and others added 4 commits February 27, 2026 21:22
- Add StreamingSinkProvider (mirrors StreamingSourceProvider pattern)
- Replace BufferedSink parameter with StreamingSinkProvider so the sink
  is opened and closed inside the function
- Refactor parsing logic into a private stripPrimitiveArrays(CopyingSource)
  method (cleaner separation, matches android-register structure)
- Fix INSTANCE_DUMP: stackTraceSerialNumber is u4 (intByteSize), not
  identifier-sized — this was wrong for 8-byte identifier heaps
- Fix PRIMITIVE_ARRAY_DUMP: remove extra sink.writeByte(type) that was
  writing the type byte twice (CopyingSource.transferUnsignedByte already
  copies it)
- Add CopyingSource.indexOf delegate
- Use repeat() instead of for (i in 0 until ...) loops
- Remove TODO comment from CHAR array handling
- Add deleteInputHprofFile parameter to SharkLog logging path
- Clean up test: remove debugging @test fun foo() and raw-byte helpers,
  replace with proper writeRawTestHprof fixture using HprofWriter that
  tests LongArray zeroing, CharArray '?' replacement, and instance dump
  wrapper value zeroing; remove duplicate ByteArraySourceProvider class

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@pyricau pyricau changed the title HprofPrimitiveArrayStripper clears out primitive wrapper value fields HprofPrimitiveArrayStripper: sync with android-register, fix bugs, clean up Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant