Skip to main content

Compact Strings -  Java 9 Feature

Motivation

The current implementation of the String class stores characters in a char array, using two bytes (sixteen bits) for each character. Data gathered from many different applications indicates that strings are a major component of heap usage and, moreover, that most String objects contain only Latin-1 characters. Such characters require only one byte of storage, hence half of the space in the internal char arrays of such String objects is going unused

Description

We propose to change the internal representation of the String class from a UTF-16 char array to a byte array plus an encoding-flag field. The new String class will store characters encoded either as ISO-8859-1/Latin-1 (one byte per character), or as UTF-16 (two bytes per character), based upon the contents of the string. The encoding flag will indicate which encoding is used.

String-related classes such as AbstractStringBuilder, StringBuilder, and StringBuffer will be updated to use the same representation, as will the HotSpot VM's intrinsic string operations.

This is purely an implementation change, with no changes to existing public interfaces. There are no plans to add any new public APIs or other interfaces.

The prototyping work done to date confirms the expected reduction in memory footprint, substantial reductions of GC activity, and minor performance regressions in some corner cases.

Comments

Popular posts from this blog

What is Servet ?

A servlet is a java class that extends an application hosted on a web server. Handles the HTTP request-response process (for our purposes) Often thought of as an applet that runs on a server. Provides a component base architecture for web development, using the Java Platform The foundation for Java Server Pages (JSP). Alternative to CGI scripting and platform specific server side applications.

Panels in AWT

Panels: import java.applet.*; import java.awt.*; /*<applet code="PanelDemo" width=300 height=300></applet>*/ public class PanelDemo extends Applet { public void  init() { setLayout(new BorderLayout()); Panel pn=new Panel(); Button b1=new Button("Button 1"); pn.add(b1); Button b2=new Button("Button 2"); pn.add(b2); add(pn,"North"); Panel pe=new Panel(); Button b3=new Button("Button 3"); pe.add(b3); add(pe,"East"); Panel pw=new Panel(); Button b4=new Button("Button 4"); pw.add(b4); add(pw,"West"); Panel ps=new Panel(); Button b5=new Button("Button 5"); ps.add(b5); Button b6=new Button("Button 6"); ps.add(b6); add(ps,"South"); } }