Compressed Java String Storage for UTF-16 Memory Waste

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Current Java virtual machine implementations using a char array for String objects in Java are inefficient, as they waste memory for languages encoded in UTF-16, where high-order bytes are always zero for single-byte encodings like ISO8859-1, and for complex encodings like UTF-16, they allocate more space than needed.

Innovation Solution

A computer-implemented method for multi-byte compressed string representation is introduced, using a package protected final static boolean control field to enable or disable compression, with a static control field to track decompressed strings, and compiler-recognized helper methods for endian-aware operations, widening, truncation, and masking, allowing for efficient storage and processing of strings.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Adaptability or versatility

If a char array is used as backing storage for String objects in Java, then the representation is compatible with UTF-16 character encoding, but memory is wasted for single-byte encodings where high-order bytes are always zero

Engineering Contradiction:
ImproveUTF-16 compatibilityVSAvoidmemory consumption
Core Design Contradiction:
Adaptability or versatilityVSQuantity of substance

Solution Approach 1:

The patent implements dynamic string representation that automatically adapts between compressed and decompressed formats based on the actual character encoding requirements. When strings contain only single-byte characters, they are stored in compressed format using byte arrays; when multi-byte characters are detected, the representation switches to decompressed char arrays, eliminating memory waste while maintaining UTF-16 compatibility

Inventive Principle:
Principle #15Dynamics

Solution Approach 2:

The patent changes the storage parameter from fixed 2-byte char representation to variable-length representation. By detecting whether characters require single-byte or multi-byte encoding, the system dynamically adjusts the storage size, using 1 byte per character for single-byte encodings and 2 bytes per character for multi-byte encodings, thereby optimizing memory consumption

Inventive Principle:
Principle #35Parameter changes

2Reliability

If a char array is used for all String objects, then UTF-16 characters are properly represented, but allocated space is wasted when characters requiring more than 8 bits are never instantiated

Engineering Contradiction:
Improvecharacter encoding accuracyVSAvoidallocated memory space
Core Design Contradiction:
ReliabilityVSQuantity of substance

Solution Approach 1:

The system dynamically determines the appropriate representation format based on the actual character content. By analyzing whether the string contains characters that require more than 8 bits, the system switches between compressed byte array representation for single-byte characters and decompressed char array representation for multi-byte characters, ensuring encoding accuracy while minimizing memory allocation

Inventive Principle:
Principle #15Dynamics

Solution Approach 2:

The patent performs preliminary analysis during string creation to determine whether compressed or decompressed representation should be used. By checking the character encoding requirements before allocation, the system pre-determines the optimal storage format, preventing wasted memory allocation while ensuring proper character representation

Inventive Principle:
Principle #10Preliminary action

Data Source

PatentUS10002010B2Multi-byte compressed string representation
Publication Date: 2018.06.19 INTERNATIONAL BUSINESS MACHINE CORPORATION
  • US10002010B2 patent drawing
  • US10002010B2 patent drawing
  • US10002010B2 patent drawing

AI summary

Multi-byte compressed string representation embodiments define a String class control field identifying compression as enabled/disabled, and another control field, identifying a decompressed string created when compression enabled. Tests are noped based on null setting of the compression flag. When arguments to a String class constructor are not compressible, a decompressed String is created and stringCompressionFlag initialized. Endian-aware helper methods for reading/writing byte and character values are defined. Enhanced String class constructors, when characters are not compressible, create a decompressed String, and initialize stringCompressionFlag triggering class load assumptions, overwriting all nopable patch points. A String object sign bit is set to one for decompressed strings when compression enabled, and masking/testing this flag bit is noped. Alternative package protected string constructors and operations are provided. A predetermined location is checked to determine whether supplied arguments to a String class constructor are compressible is performed.