Skip to content
Permalink
Browse files
8261254: Initialize charset mapping data lazily
Reviewed-by: alanb, jkuhn, naoto
  • Loading branch information
cl4es committed Feb 8, 2021
1 parent 351d788 commit 92c6e6dffa0e3073205b833a91a66e53ec13c213
Showing with 215 additions and 250 deletions.
  1. +14 −27 make/data/charsetmapping/DoubleByte-X.java.template
  2. +15 −13 make/data/charsetmapping/SingleByte-X.java.template
  3. +4 −2 src/java.base/share/classes/java/lang/ModuleLayer.java
  4. +4 −4 src/jdk.charsets/share/classes/sun/nio/cs/ext/AbstractCharsetProvider.java
  5. +7 −7 src/jdk.charsets/share/classes/sun/nio/cs/ext/Big5_HKSCS.java.template
  6. +5 −5 src/jdk.charsets/share/classes/sun/nio/cs/ext/Big5_HKSCS_2001.java
  7. +14 −35 src/jdk.charsets/share/classes/sun/nio/cs/ext/Big5_Solaris.java.template
  8. +19 −19 src/jdk.charsets/share/classes/sun/nio/cs/ext/IBM29626C.java.template
  9. +3 −6 src/jdk.charsets/share/classes/sun/nio/cs/ext/IBM834.java.template
  10. +29 −30 src/jdk.charsets/share/classes/sun/nio/cs/ext/IBM942C.java.template
  11. +22 −23 src/jdk.charsets/share/classes/sun/nio/cs/ext/IBM943C.java.template
  12. +22 −22 src/jdk.charsets/share/classes/sun/nio/cs/ext/IBM949C.java.template
  13. +4 −6 src/jdk.charsets/share/classes/sun/nio/cs/ext/ISO2022_CN_CNS.java
  14. +3 −6 src/jdk.charsets/share/classes/sun/nio/cs/ext/ISO2022_CN_GB.java
  15. +6 −5 src/jdk.charsets/share/classes/sun/nio/cs/ext/ISO2022_KR.java
  16. +13 −11 src/jdk.charsets/share/classes/sun/nio/cs/ext/MS50220.java
  17. +3 −3 src/jdk.charsets/share/classes/sun/nio/cs/ext/MS932_0213.java
  18. +5 −5 src/jdk.charsets/share/classes/sun/nio/cs/ext/MS950_HKSCS.java.template
  19. +3 −3 src/jdk.charsets/share/classes/sun/nio/cs/ext/MS950_HKSCS_XP.java.template
  20. +3 −3 src/jdk.charsets/share/classes/sun/nio/cs/ext/MSISO2022JP.java
  21. +17 −15 src/jdk.charsets/share/classes/sun/nio/cs/ext/SJIS_0213.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -49,53 +49,40 @@ public class $NAME_CLZ$ extends Charset
}

public CharsetDecoder newDecoder() {
initb2c();
return new DoubleByte.Decoder$DECTYPE$(this, b2c, b2cSB, $B2MIN$, $B2MAX$, $ASCIICOMPATIBLE$);
return new DoubleByte.Decoder$DECTYPE$(this, DecodeHolder.b2c, DecodeHolder.b2cSB, $B2MIN$, $B2MAX$, $ASCIICOMPATIBLE$);
}

public CharsetEncoder newEncoder() {
initc2b();
return new DoubleByte.Encoder$ENCTYPE$(this, $ENC_REPLACEMENT$ c2b, c2bIndex, $ASCIICOMPATIBLE$);
return new DoubleByte.Encoder$ENCTYPE$(this, $ENC_REPLACEMENT$ EncodeHolder.c2b, EncodeHolder.c2bIndex, $ASCIICOMPATIBLE$);
}

$B2C$
static char[][] b2c = new char[b2cStr.length][];
static char[] b2cSB;
private static volatile boolean b2cInitialized = false;
static class DecodeHolder {
$B2C$
static final char[][] b2c = new char[b2cStr.length][];
static final char[] b2cSB;

static void initb2c() {
if (b2cInitialized)
return;
synchronized (b2c) {
if (b2cInitialized)
return;
static {
for (int i = 0; i < b2cStr.length; i++) {
if (b2cStr[i] == null)
b2c[i] = DoubleByte.B2C_UNMAPPABLE;
else
b2c[i] = b2cStr[i].toCharArray();
}
b2cSB = b2cSBStr.toCharArray();
b2cInitialized = true;
}
}

static char[] c2b = new char[$C2BLENGTH$];
static char[] c2bIndex = new char[0x100];
private static volatile boolean c2bInitialized = false;
static class EncodeHolder {
static final char[] c2b = new char[$C2BLENGTH$];
static final char[] c2bIndex = new char[0x100];

static void initc2b() {
if (c2bInitialized)
return;
synchronized (c2b) {
if (c2bInitialized)
return;
static {
$NONROUNDTRIP_B2C$
$NONROUNDTRIP_C2B$
DoubleByte.Encoder.initC2B(b2cStr, b2cSBStr, b2cNR, c2bNR,
DoubleByte.Encoder.initC2B(DecodeHolder.b2cStr, DecodeHolder.b2cSBStr,
b2cNR, c2bNR,
$B2MIN$, $B2MAX$,
c2b, c2bIndex);
c2bInitialized = true;
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -48,24 +48,26 @@ public class $NAME_CLZ$ extends Charset implements HistoricallyNamedCharset
}

public CharsetDecoder newDecoder() {
return new SingleByte.Decoder(this, b2c, $ASCIICOMPATIBLE$, $LATIN1DECODABLE$);
return new SingleByte.Decoder(this, Holder.b2c, $ASCIICOMPATIBLE$, $LATIN1DECODABLE$);
}

public CharsetEncoder newEncoder() {
return new SingleByte.Encoder(this, c2b, c2bIndex, $ASCIICOMPATIBLE$);
return new SingleByte.Encoder(this, Holder.c2b, Holder.c2bIndex, $ASCIICOMPATIBLE$);
}

private final static String b2cTable = $B2CTABLE$
private static class Holder {
private static final String b2cTable = $B2CTABLE$

private final static char[] b2c = b2cTable.toCharArray();
private final static char[] c2b = new char[$C2BLENGTH$];
private final static char[] c2bIndex = new char[0x100];
private static final char[] b2c = b2cTable.toCharArray();
private static final char[] c2b = new char[$C2BLENGTH$];
private static final char[] c2bIndex = new char[0x100];

static {
char[] b2cMap = b2c;
char[] c2bNR = null;
$NONROUNDTRIP_B2C$
$NONROUNDTRIP_C2B$
SingleByte.initC2B(b2cMap, c2bNR, c2b, c2bIndex);
static {
char[] b2cMap = b2c;
char[] c2bNR = null;
$NONROUNDTRIP_B2C$
$NONROUNDTRIP_C2B$
SingleByte.initC2B(b2cMap, c2bNR, c2b, c2bIndex);
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -931,7 +931,9 @@ ServicesCatalog getServicesCatalog() {
servicesCatalog = this.servicesCatalog;
if (servicesCatalog == null) {
servicesCatalog = ServicesCatalog.create();
nameToModule.values().forEach(servicesCatalog::register);
for (Module m : nameToModule.values()) {
servicesCatalog.register(m);
}
this.servicesCatalog = servicesCatalog;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -68,11 +68,11 @@
private String packagePrefix;

protected AbstractCharsetProvider() {
packagePrefix = "sun.nio.cs";
packagePrefix = "sun.nio.cs.";
}

protected AbstractCharsetProvider(String pkgPrefixName) {
packagePrefix = pkgPrefixName;
packagePrefix = pkgPrefixName.concat(".");
}

/* Add an entry to the given map, but only if no mapping yet exists
@@ -144,7 +144,7 @@ private Charset lookup(String csn) {
// Instantiate the charset and cache it
try {

Class<?> c = Class.forName(packagePrefix + "." + cln,
Class<?> c = Class.forName(packagePrefix.concat(cln),
true,
this.getClass().getClassLoader());

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -59,11 +59,11 @@ public class Big5_HKSCS extends Charset implements HistoricallyNamedCharset
}

static class Decoder extends HKSCS.Decoder {
private static DoubleByte.Decoder big5 =
private static final DoubleByte.Decoder big5 =
(DoubleByte.Decoder)new Big5().newDecoder();

private static char[][] b2cBmp = new char[0x100][];
private static char[][] b2cSupp = new char[0x100][];
private static final char[][] b2cBmp = new char[0x100][];
private static final char[][] b2cSupp = new char[0x100][];
static {
initb2c(b2cBmp, HKSCSMapping.b2cBmpStr);
initb2c(b2cSupp, HKSCSMapping.b2cSuppStr);
@@ -75,11 +75,11 @@ public class Big5_HKSCS extends Charset implements HistoricallyNamedCharset
}

static class Encoder extends HKSCS.Encoder {
private static DoubleByte.Encoder big5 =
private static final DoubleByte.Encoder big5 =
(DoubleByte.Encoder)new Big5().newEncoder();

static char[][] c2bBmp = new char[0x100][];
static char[][] c2bSupp = new char[0x100][];
static final char[][] c2bBmp = new char[0x100][];
static final char[][] c2bSupp = new char[0x100][];
static {
initc2b(c2bBmp, HKSCSMapping.b2cBmpStr, HKSCSMapping.pua);
initc2b(c2bSupp, HKSCSMapping.b2cSuppStr, null);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -56,8 +56,8 @@ public CharsetEncoder newEncoder() {
private static DoubleByte.Decoder big5 =
(DoubleByte.Decoder)new Big5().newDecoder();

private static char[][] b2cBmp = new char[0x100][];
private static char[][] b2cSupp = new char[0x100][];
private static final char[][] b2cBmp = new char[0x100][];
private static final char[][] b2cSupp = new char[0x100][];
static {
initb2c(b2cBmp, HKSCS2001Mapping.b2cBmpStr);
initb2c(b2cSupp, HKSCS2001Mapping.b2cSuppStr);
@@ -72,8 +72,8 @@ private Decoder(Charset cs) {
private static DoubleByte.Encoder big5 =
(DoubleByte.Encoder)new Big5().newEncoder();

static char[][] c2bBmp = new char[0x100][];
static char[][] c2bSupp = new char[0x100][];
static final char[][] c2bBmp = new char[0x100][];
static final char[][] c2bSupp = new char[0x100][];
static {
initc2b(c2bBmp, HKSCS2001Mapping.b2cBmpStr,
HKSCS2001Mapping.pua);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -50,27 +50,21 @@ public class Big5_Solaris extends Charset implements HistoricallyNamedCharset
}

public CharsetDecoder newDecoder() {
initb2c();
return new DoubleByte.Decoder(this, b2c, b2cSB, 0x40, 0xfe, true);
return new DoubleByte.Decoder(this, Holder.b2c, Holder.b2cSB, 0x40, 0xfe, true);
}

public CharsetEncoder newEncoder() {
initc2b();
return new DoubleByte.Encoder(this, c2b, c2bIndex, true);
return new DoubleByte.Encoder(this, Holder.c2b, Holder.c2bIndex, true);
}

static char[][] b2c;
static char[] b2cSB;
private static volatile boolean b2cInitialized = false;
private static class Holder {
static final char[][] b2c;
static final char[] b2cSB;
static final char[] c2b;
static final char[] c2bIndex;

static void initb2c() {
if (b2cInitialized)
return;
synchronized (Big5_Solaris.class) {
if (b2cInitialized)
return;
Big5.initb2c();
b2c = Big5.b2c.clone();
static {
b2c = Big5.DecodeHolder.b2c.clone();
// Big5 Solaris implementation has 7 additional mappings
int[] sol = new int[] {
0xF9D6, 0x7881,
@@ -88,25 +82,11 @@ public class Big5_Solaris extends Charset implements HistoricallyNamedCharset
for (int i = 0; i < sol.length;) {
b2c[0xf9][sol[i++] & 0xff - 0x40] = (char)sol[i++];
}
b2cSB = Big5.b2cSB;
b2cInitialized = true;
}
}
b2cSB = Big5.DecodeHolder.b2cSB;

static char[] c2b;
static char[] c2bIndex;
private static volatile boolean c2bInitialized = false;

static void initc2b() {
if (c2bInitialized)
return;
synchronized (Big5_Solaris.class) {
if (c2bInitialized)
return;
Big5.initc2b();
c2b = Big5.c2b.clone();
c2bIndex = Big5.c2bIndex.clone();
int[] sol = new int[] {
c2b = Big5.EncodeHolder.c2b.clone();
c2bIndex = Big5.EncodeHolder.c2bIndex.clone();
sol = new int[] {
0x7881, 0xF9D6,
0x92B9, 0xF9D7,
0x88CF, 0xF9D8,
@@ -121,7 +101,6 @@ public class Big5_Solaris extends Charset implements HistoricallyNamedCharset
// to the appropriate place.
c2b[c2bIndex[c >> 8] + (c & 0xff)] = (char)sol[i++];
}
c2bInitialized = true;
}
}
}
Loading

0 comments on commit 92c6e6d

Please sign in to comment.