Class Utf8LdcChunker
String so it can be emitted as one-or-more JVM LDC constants
without breaching the class-file CONSTANT_Utf8 ceiling.
A CONSTANT_Utf8 entry stores its length in a u2, so a single LDC string
cannot exceed 65535 modified-UTF8 bytes (JVMS 4.4.7). The coverage/profiling per-module
metadata JSON blows past this on large, cohesive modules (a real web service with inline dynamic
response classes carries hundreds of probes) — see
docs/ir-and-codegen/EK9_BUG_COVERAGE_METADATA_UTF8_OVERFLOW.md. The caller emits the string
as chunks re-joined by a StringBuilder at runtime, so no single constant breaches the limit
and the registration call still receives the whole string (no runtime-format change, and the
self-contained per-class embedding is preserved).
Pure logic, unit-tested independently of the bytecode emission it feeds. "modified UTF-8" is the class-file encoding: each UTF-16 code unit encodes on its own (1 byte for U+0001..U+007F, 3 bytes for U+0800..U+FFFF, otherwise 2), so an unpaired surrogate at a chunk boundary round-trips verbatim and the re-joined string equals the original.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final intHard JVM limit: aCONSTANT_Utf8entry's length field is au2.(package private) static final intPer-chunk target, with headroom below the hard limit so every emittedLDCstays safe. -
Method Summary
Modifier and TypeMethodDescriptionSplit into pieces whose modified-UTF8 length each stays<= maxBytesPerChunk, cutting only on char boundaries.(package private) static booleanTrue when the whole string fits in oneLDC— the common fast path, no reassembly.(package private) static intModified-UTF8 encoded length (the class-fileCONSTANT_Utf8encoding), per JVMS 4.4.7.
-
Field Details
-
MAX_UTF8_BYTES
static final int MAX_UTF8_BYTESHard JVM limit: aCONSTANT_Utf8entry's length field is au2.- See Also:
-
SAFE_CHUNK_BYTES
static final int SAFE_CHUNK_BYTESPer-chunk target, with headroom below the hard limit so every emittedLDCstays safe.- See Also:
-
-
Method Details
-
modifiedUtf8Length
Modified-UTF8 encoded length (the class-fileCONSTANT_Utf8encoding), per JVMS 4.4.7. -
fitsInSingleLdc
True when the whole string fits in oneLDC— the common fast path, no reassembly. -
chunk
Split into pieces whose modified-UTF8 length each stays<= maxBytesPerChunk, cutting only on char boundaries. Concatenating the pieces reproduces the input exactly.- Parameters:
s- the string to split (may be any length)maxBytesPerChunk- per-chunk byte ceiling; must be>= 3(a single char costs ≤ 3 bytes)- Returns:
- the ordered chunks; joining them equals
s
-