Skip to content

Commit

Permalink
8261254: Initialize charset mapping data lazily
Browse files Browse the repository at this point in the history
Reviewed-by: alanb, jkuhn, naoto
  • Loading branch information
cl4es committed Feb 8, 2021
1 parent 351d788 commit 92c6e6d
Show file tree
Hide file tree
Showing 21 changed files with 215 additions and 250 deletions.
41 changes: 14 additions & 27 deletions make/data/charsetmapping/DoubleByte-X.java.template
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
}
}
}
28 changes: 15 additions & 13 deletions make/data/charsetmapping/SingleByte-X.java.template
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
}
}
}
6 changes: 4 additions & 2 deletions src/java.base/share/classes/java/lang/ModuleLayer.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -68,11 +68,11 @@ public class AbstractCharsetProvider
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
Expand Down Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -56,8 +56,8 @@ private static class Decoder extends HKSCS.Decoder {
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);
Expand All @@ -72,8 +72,8 @@ private static class Encoder extends HKSCS.Encoder {
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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

1 comment on commit 92c6e6d

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.