JDK-6631559 : Registration of ImageIO plugins should not cause loading of jpeg.dlli and cmm.dll
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 6u10
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2007-11-19
  • Updated: 2011-01-19
  • Resolved: 2007-12-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
6u10 b09Fixed 7Fixed
Initialization of ImageIO always loads of jpeg.dll (even if JPEGs are not processed).
This is because JPEGImageReader/WriterSPI performs explicit library loading.

It seems that the only reason to do this is to avoid throwing exceptions later on if 
library will not load sucessfully. 

On other hand if JPEG plugin will not be used then library was loaded without 
real need (and with negative impact on footprint and startup).
Please note that JPEGImageReader/Writer, i.e. classes which actually have native methods, will call LoadLibrary anyway.

Sample test:

import javax.imageio.*;
import java.awt.image.*;
import java.io.*;

public class ImageIOTest {
   public static void main(String a[]) throws Exception {
      BufferedImage bi = ImageIO.read(new File("new.png"));

To run it use any non JPEG image and procmon tool to monitor disk file access.
Note that jpeg.dll was read.
Further analysis shows that com.sun.imageio.plugins.jpeg.JPEG has explicit dependency on 
ColorSpace that causes loading of several color profiles and initialization of CMM.

Note that some of public constants from this class are required for registration of JPEGImageReader/Writer. This means that CMM is initialized and loaded if ImageIO is initialized.

Clearly this extra work can be avoided.

SUGGESTED FIX http://sa.sfbay.sun.com/projects/java2d_data/6u10/6631559.0

EVALUATION For CMM initialization part we can consider creation of inner public static class in the JPEG. ColorSpace logic constants and static initialization logic can be moved to this inner class. Alternatively, public constants needed for registration can be moved to this inner class. Either way, we need to separate initialization of these public string constants and initialization of fields related to CMM.

EVALUATION It seems the simplest fix is to remove static blocks from both JPEGImageReaderSpi and JPEGImageWriterSpi.