author | martin |
Wed, 28 Mar 2018 21:14:06 -0700 | |
changeset 49443 | e5679a6661d6 |
parent 47216 | 71c04702a3d5 |
child 49556 | 809b178407cc |
permissions | -rw-r--r-- |
22639
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
1 |
/* |
45894
995421c69f66
8184665: Skip name and alias checks for standard Charsets
redestad
parents:
43790
diff
changeset
|
2 |
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. |
22639
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
3 |
* |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
4 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
5 |
* |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
6 |
* This code is free software; you can redistribute it and/or modify it |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
7 |
* under the terms of the GNU General Public License version 2 only, as |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
8 |
* published by the Free Software Foundation. Oracle designates this |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
9 |
* particular file as subject to the "Classpath" exception as provided |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
10 |
* by Oracle in the LICENSE file that accompanied this code. |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
11 |
* |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
12 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
13 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
14 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
15 |
* version 2 for more details (a copy is included in the LICENSE file that |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
16 |
* accompanied this code). |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
17 |
* |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
18 |
* You should have received a copy of the GNU General Public License version |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
19 |
* 2 along with this work; if not, write to the Free Software Foundation, |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
20 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
21 |
* |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
22 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
23 |
* or visit www.oracle.com if you need additional information or have any |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
24 |
* questions. |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
25 |
* |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
26 |
*/ |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
27 |
|
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
28 |
// -- This file was mechanically generated: Do not edit! -- // |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
29 |
|
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
30 |
package sun.nio.cs; |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
31 |
|
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
32 |
import java.nio.charset.Charset; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
33 |
import java.nio.charset.spi.CharsetProvider; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
34 |
import java.util.Iterator; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
35 |
import java.util.Map; |
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
36 |
import java.util.Set; |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
37 |
import jdk.internal.vm.annotation.Stable; |
37593
824750ada3d6
8154231: Simplify access to System properties from JDK code
redestad
parents:
34882
diff
changeset
|
38 |
import sun.security.action.GetPropertyAction; |
22639
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
39 |
|
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
40 |
public class StandardCharsets extends CharsetProvider { |
22639
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
41 |
|
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
42 |
_INCLUDE_ALIASES_TABLES_ |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
43 |
_INCLUDE_ALIASES_MAP_ |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
44 |
_INCLUDE_CLASSES_MAP_ |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
45 |
_INCLUDE_CACHE_MAP_ |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
46 |
|
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
47 |
// Maps canonical names to class names |
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
48 |
private @Stable Map<String,String> classMap; |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
49 |
|
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
50 |
// Maps alias names to canonical names |
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
51 |
private @Stable Map<String,String> aliasMap; |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
52 |
|
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
53 |
// Maps canonical names to cached instances |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
54 |
private @Stable Map<String,Charset> cache; |
45894
995421c69f66
8184665: Skip name and alias checks for standard Charsets
redestad
parents:
43790
diff
changeset
|
55 |
|
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
56 |
private static final String packagePrefix = "sun.nio.cs."; |
45894
995421c69f66
8184665: Skip name and alias checks for standard Charsets
redestad
parents:
43790
diff
changeset
|
57 |
|
22639
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
58 |
public StandardCharsets() { |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
59 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
60 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
61 |
private String canonicalize(String csn) { |
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
62 |
String acn = aliasMap().get(csn); |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
63 |
return (acn != null) ? acn : csn; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
64 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
65 |
|
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
66 |
private Map<String,String> aliasMap() { |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
67 |
Map<String,String> map = aliasMap; |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
68 |
if (map == null) { |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
69 |
aliasMap = map = new Aliases(); |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
70 |
} |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
71 |
return map; |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
72 |
} |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
73 |
|
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
74 |
private Map<String,String> classMap() { |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
75 |
Map<String,String> map = classMap; |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
76 |
if (map == null) { |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
77 |
classMap = map = new Classes(); |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
78 |
} |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
79 |
return map; |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
80 |
} |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
81 |
|
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
82 |
private Map<String,Charset> cache() { |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
83 |
Map<String,Charset> map = cache; |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
84 |
if (map == null) { |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
85 |
map = new Cache(); |
49443
e5679a6661d6
8200310: Avoid charset lookup machinery in java.nio.charset.StandardCharsets
martin
parents:
47216
diff
changeset
|
86 |
map.put("utf-8", java.nio.charset.StandardCharsets.UTF_8); |
e5679a6661d6
8200310: Avoid charset lookup machinery in java.nio.charset.StandardCharsets
martin
parents:
47216
diff
changeset
|
87 |
map.put("iso-8859-1", java.nio.charset.StandardCharsets.ISO_8859_1); |
e5679a6661d6
8200310: Avoid charset lookup machinery in java.nio.charset.StandardCharsets
martin
parents:
47216
diff
changeset
|
88 |
map.put("us-ascii", java.nio.charset.StandardCharsets.US_ASCII); |
e5679a6661d6
8200310: Avoid charset lookup machinery in java.nio.charset.StandardCharsets
martin
parents:
47216
diff
changeset
|
89 |
map.put("utf-16", java.nio.charset.StandardCharsets.UTF_16); |
e5679a6661d6
8200310: Avoid charset lookup machinery in java.nio.charset.StandardCharsets
martin
parents:
47216
diff
changeset
|
90 |
map.put("utf-16be", java.nio.charset.StandardCharsets.UTF_16BE); |
e5679a6661d6
8200310: Avoid charset lookup machinery in java.nio.charset.StandardCharsets
martin
parents:
47216
diff
changeset
|
91 |
map.put("utf-16le", java.nio.charset.StandardCharsets.UTF_16LE); |
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
92 |
cache = map; |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
93 |
} |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
94 |
return map; |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
95 |
} |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
96 |
|
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
97 |
// Private ASCII-only version, optimized for interpretation during startup |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
98 |
// |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
99 |
private static String toLower(String s) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
100 |
int n = s.length(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
101 |
boolean allLower = true; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
102 |
for (int i = 0; i < n; i++) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
103 |
int c = s.charAt(i); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
104 |
if (((c - 'A') | ('Z' - c)) >= 0) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
105 |
allLower = false; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
106 |
break; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
107 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
108 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
109 |
if (allLower) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
110 |
return s; |
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
111 |
StringBuilder sb = new StringBuilder(n); |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
112 |
for (int i = 0; i < n; i++) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
113 |
int c = s.charAt(i); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
114 |
if (((c - 'A') | ('Z' - c)) >= 0) |
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
115 |
sb.append((char)(c + 0x20)); |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
116 |
else |
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
117 |
sb.append((char)c); |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
118 |
} |
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
119 |
return sb.toString(); |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
120 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
121 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
122 |
private Charset lookup(String charsetName) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
123 |
init(); |
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
124 |
|
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
125 |
// By checking these built-ins we can avoid initializing Aliases and |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
126 |
// Classes eagerly during bootstrap |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
127 |
String csn; |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
128 |
if (charsetName.equals("UTF-8")) { |
49443
e5679a6661d6
8200310: Avoid charset lookup machinery in java.nio.charset.StandardCharsets
martin
parents:
47216
diff
changeset
|
129 |
return java.nio.charset.StandardCharsets.UTF_8; |
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
130 |
} else if (charsetName.equals("US-ASCII")) { |
49443
e5679a6661d6
8200310: Avoid charset lookup machinery in java.nio.charset.StandardCharsets
martin
parents:
47216
diff
changeset
|
131 |
return java.nio.charset.StandardCharsets.US_ASCII; |
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
132 |
} else if (charsetName.equals("ISO-8859-1")) { |
49443
e5679a6661d6
8200310: Avoid charset lookup machinery in java.nio.charset.StandardCharsets
martin
parents:
47216
diff
changeset
|
133 |
return java.nio.charset.StandardCharsets.ISO_8859_1; |
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
134 |
} else { |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
135 |
csn = canonicalize(toLower(charsetName)); |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
136 |
} |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
137 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
138 |
// Check cache first |
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
139 |
Charset cs = cache().get(csn); |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
140 |
if (cs != null) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
141 |
return cs; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
142 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
143 |
// Do we even support this charset? |
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
144 |
String cln = classMap().get(csn); |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
145 |
if (cln == null) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
146 |
return null; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
147 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
148 |
// Instantiate the charset and cache it |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
149 |
try { |
37782
ad8fe7507ecc
6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents:
37781
diff
changeset
|
150 |
@SuppressWarnings("deprecation") |
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
151 |
Object o = Class.forName(packagePrefix + cln, |
37782
ad8fe7507ecc
6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents:
37781
diff
changeset
|
152 |
true, |
ad8fe7507ecc
6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents:
37781
diff
changeset
|
153 |
this.getClass().getClassLoader()).newInstance(); |
43790
b9e56c7fba7e
8174831: Reduce number of Charset classes loaded on bootstrap
redestad
parents:
37782
diff
changeset
|
154 |
return cache(csn, (Charset)o); |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
155 |
} catch (ClassNotFoundException | |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
156 |
IllegalAccessException | |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
157 |
InstantiationException x) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
158 |
return null; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
159 |
} |
22639
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
160 |
} |
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
161 |
|
43790
b9e56c7fba7e
8174831: Reduce number of Charset classes loaded on bootstrap
redestad
parents:
37782
diff
changeset
|
162 |
private Charset cache(String csn, Charset cs) { |
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
163 |
cache().put(csn, cs); |
43790
b9e56c7fba7e
8174831: Reduce number of Charset classes loaded on bootstrap
redestad
parents:
37782
diff
changeset
|
164 |
return cs; |
b9e56c7fba7e
8174831: Reduce number of Charset classes loaded on bootstrap
redestad
parents:
37782
diff
changeset
|
165 |
} |
b9e56c7fba7e
8174831: Reduce number of Charset classes loaded on bootstrap
redestad
parents:
37782
diff
changeset
|
166 |
|
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
167 |
public final Charset charsetForName(String charsetName) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
168 |
synchronized (this) { |
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
169 |
return lookup(charsetName); |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
170 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
171 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
172 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
173 |
public final Iterator<Charset> charsets() { |
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
174 |
Set<String> charsetNames; |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
175 |
synchronized (this) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
176 |
init(); |
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
177 |
// Ensure initialized in synchronized block |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
178 |
charsetNames = classMap().keySet(); |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
179 |
aliasMap(); |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
180 |
cache(); |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
181 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
182 |
return new Iterator<Charset>() { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
183 |
|
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
184 |
Iterator<String> i = charsetNames.iterator(); |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
185 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
186 |
public boolean hasNext() { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
187 |
return i.hasNext(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
188 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
189 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
190 |
public Charset next() { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
191 |
String csn = i.next(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
192 |
return lookup(csn); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
193 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
194 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
195 |
public void remove() { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
196 |
throw new UnsupportedOperationException(); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
197 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
198 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
199 |
}; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
200 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
201 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
202 |
private boolean initialized = false; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
203 |
|
34882 | 204 |
/* provider the sun.nio.cs.map property fir sjis/ms932 mapping hack |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
205 |
*/ |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
206 |
private void init() { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
207 |
if (initialized) |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
208 |
return; |
34882 | 209 |
if (!jdk.internal.misc.VM.isBooted()) |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
210 |
return; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
211 |
initialized = true; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
212 |
|
37781
71ed5645f17c
8155775: Re-examine naming of privileged methods to access System properties
redestad
parents:
37593
diff
changeset
|
213 |
String map = GetPropertyAction.privilegedGetProperty("sun.nio.cs.map"); |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
214 |
if (map != null) { |
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
215 |
Map<String,String> aliasMap = aliasMap(); |
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
216 |
Map<String,String> classMap = classMap(); |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
217 |
String[] maps = map.split(","); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
218 |
for (int i = 0; i < maps.length; i++) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
219 |
if (maps[i].equalsIgnoreCase("Windows-31J/Shift_JIS")) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
220 |
// if we dont have both sjis and ms932, do nothing |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
221 |
if (classMap.get("shift_jis") == null || |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
222 |
classMap.get("windows-31j") == null) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
223 |
break; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
224 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
225 |
aliases_MS932 = new String[] { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
226 |
"MS932", // JDK historical |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
227 |
"windows-932", |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
228 |
"csWindows31J", |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
229 |
"shift-jis", |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
230 |
"ms_kanji", |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
231 |
"x-sjis", |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
232 |
"csShiftJIS", |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
233 |
// This alias takes precedence over the actual |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
234 |
// Shift_JIS charset itself since aliases are always |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
235 |
// resolved first, before looking up canonical names. |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
236 |
"shift_jis" |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
237 |
}; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
238 |
aliases_SJIS = new String[] { "sjis" }; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
239 |
|
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
240 |
for (String alias : aliases_MS932) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
241 |
aliasMap.put(toLower(alias), "windows-31j"); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
242 |
} |
47026
94c45ad89b9c
8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents:
45894
diff
changeset
|
243 |
cache().put("shift_jis", null); |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
244 |
break; |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
245 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
246 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
247 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
248 |
} |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
25859
diff
changeset
|
249 |
|
22639
37f4508257fe
8033236: Update GensrcCharsetMapping.gmk to build-infra standards
ihse
parents:
diff
changeset
|
250 |
} |