This commit is contained in:
Abhijit Saha 2009-08-05 14:16:34 -07:00
commit afe5efd931
11 changed files with 756 additions and 448 deletions

View File

@ -1 +1,187 @@
0x15 U+0085
#
# The diff of 01A434B0.TXMAP110 and 34B001A4.RXMAP110
#
# Added: 0x15 U+0085
#
0x15 U+0085
0x42 U+FE7C
0x46 U+FE80
0x47 U+FE81
0x49 U+FE83
0x4B U+066C
0x4B U+FF0E
0x4C U+FF1C
0x4D U+FF08
0x4E U+FF0B
0x4F U+FF5C
0x50 U+FF06
0x52 U+FE85
0x52 U+FE86
0x55 U+FE89
0x55 U+FE8A
0x55 U+FE8B
0x55 U+FE8C
0x56 U+0625
0x56 U+FE87
0x56 U+FE8D
0x57 U+FE88
0x58 U+FE8F
0x58 U+FE90
0x59 U+FE92
0x5A U+FF01
0x5B U+FF04
0x5C U+066D
0x5C U+FF0A
0x5D U+FF09
0x5E U+FF1B
0x60 U+FF0D
0x61 U+FF0F
0x62 U+FE93
0x62 U+FE94
0x63 U+FE95
0x63 U+FE96
0x64 U+FE98
0x65 U+FE99
0x65 U+FE9A
0x66 U+FE9C
0x67 U+FE9D
0x67 U+FE9E
0x68 U+FEA0
0x69 U+FEA1
0x69 U+FEA2
0x6B U+066B
0x6B U+FF0C
0x6C U+066A
0x6C U+FF05
0x6D U+FF3F
0x6E U+FF1E
0x6F U+FF1F
0x70 U+FEA4
0x71 U+FEA5
0x71 U+FEA6
0x72 U+FEA8
0x73 U+FEA9
0x73 U+FEAA
0x74 U+FEAB
0x74 U+FEAC
0x75 U+FEAD
0x75 U+FEAE
0x76 U+FEAF
0x76 U+FEB0
0x77 U+FEB1
0x77 U+FEB2
0x78 U+FEB4
0x7A U+FF1A
0x7B U+FF03
0x7C U+FF20
0x7D U+FF07
0x7E U+FF1D
0x7F U+FF02
0x80 U+FEB5
0x80 U+FEB6
0x81 U+FF41
0x82 U+FF42
0x83 U+FF43
0x84 U+FF44
0x85 U+FF45
0x86 U+FF46
0x87 U+FF47
0x88 U+FF48
0x89 U+FF49
0x8A U+FEB8
0x8B U+FEB9
0x8B U+FEBA
0x8C U+FEBC
0x8D U+FEBD
0x8D U+FEBE
0x8E U+FEC0
0x8F U+FEC1
0x8F U+FEC2
0x8F U+FEC3
0x8F U+FEC4
0x90 U+FEC5
0x90 U+FEC6
0x90 U+FEC7
0x90 U+FEC8
0x91 U+FF4A
0x92 U+FF4B
0x93 U+FF4C
0x94 U+FF4D
0x95 U+FF4E
0x96 U+FF4F
0x97 U+FF50
0x98 U+FF51
0x99 U+FF52
0x9A U+FEC9
0x9E U+FECD
0xA2 U+FF53
0xA3 U+FF54
0xA4 U+FF55
0xA5 U+FF56
0xA6 U+FF57
0xA7 U+FF58
0xA8 U+FF59
0xA9 U+FF5A
0xAB U+FED1
0xAB U+FED2
0xAC U+FED4
0xAD U+FED5
0xAD U+FED6
0xAE U+FED8
0xAF U+FED9
0xAF U+FEDA
0xB0 U+FEDC
0xB1 U+FEDD
0xB1 U+FEDE
0xB8 U+FEF9
0xB9 U+FEFA
0xBA U+FEE0
0xBB U+FEE1
0xBB U+FEE2
0xBC U+FEE4
0xBD U+FEE5
0xBD U+FEE6
0xBE U+FEE8
0xBF U+FEE9
0xBF U+FEEA
0xC1 U+FF21
0xC2 U+FF22
0xC3 U+FF23
0xC4 U+FF24
0xC5 U+FF25
0xC6 U+FF26
0xC7 U+FF27
0xC8 U+FF28
0xC9 U+FF29
0xCF U+FEED
0xCF U+FEEE
0xD1 U+FF2A
0xD2 U+FF2B
0xD3 U+FF2C
0xD4 U+FF2D
0xD5 U+FF2E
0xD6 U+FF2F
0xD7 U+FF30
0xD8 U+FF31
0xD9 U+FF32
0xDA U+FEEF
0xDC U+FEF1
0xDE U+FEF4
0xE2 U+FF33
0xE3 U+FF34
0xE4 U+FF35
0xE5 U+FF36
0xE6 U+FF37
0xE7 U+FF38
0xE8 U+FF39
0xE9 U+FF3A
0xF0 U+FF10
0xF1 U+FF11
0xF2 U+FF12
0xF3 U+FF13
0xF4 U+FF14
0xF5 U+FF15
0xF6 U+FF16
0xF7 U+FF17
0xF8 U+FF18
0xF9 U+FF19

View File

@ -1,257 +1,253 @@
#Generated from IBM420.java
0x00 U+0000
0x01 U+0001
0x02 U+0002
0x03 U+0003
0x04 U+009c
0x05 U+0009
0x06 U+0086
0x07 U+007f
0x08 U+0097
0x09 U+008d
0x0a U+008e
0x0b U+000b
0x0c U+000c
0x0d U+000d
0x0e U+000e
0x0f U+000f
0x10 U+0010
0x11 U+0011
0x12 U+0012
0x13 U+0013
0x14 U+009d
0x15 U+000a
0x16 U+0008
0x17 U+0087
0x18 U+0018
0x19 U+0019
0x1a U+0092
0x1b U+008f
0x1c U+001c
0x1d U+001d
0x1e U+001e
0x1f U+001f
0x20 U+0080
0x21 U+0081
0x22 U+0082
0x23 U+0083
0x24 U+0084
0x25 U+000a
0x26 U+0017
0x27 U+001b
0x28 U+0088
0x29 U+0089
0x2a U+008a
0x2b U+008b
0x2c U+008c
0x2d U+0005
0x2e U+0006
0x2f U+0007
0x30 U+0090
0x31 U+0091
0x32 U+0016
0x33 U+0093
0x34 U+0094
0x35 U+0095
0x36 U+0096
0x37 U+0004
0x38 U+0098
0x39 U+0099
0x3a U+009a
0x3b U+009b
0x3c U+0014
0x3d U+0015
0x3e U+009e
0x3f U+001a
0x40 U+0020
0x41 U+00a0
0x42 U+fe7c
0x43 U+fe7d
0x44 U+0640
0x45 U+f8fc
0x46 U+fe80
0x47 U+fe81
0x48 U+fe82
0x49 U+fe83
0x4a U+00a2
0x4b U+002e
0x4c U+003c
0x4d U+0028
0x4e U+002b
0x4f U+007c
0x50 U+0026
0x51 U+fe84
0x52 U+fe85
0x53 U+fffd
0x54 U+fffd
0x55 U+fe8b
0x56 U+fe8d
0x57 U+fe8e
0x58 U+fe8f
0x59 U+fe91
0x5a U+0021
0x5b U+0024
0x5c U+002a
0x5d U+0029
0x5e U+003b
0x5f U+00ac
0x60 U+002d
0x61 U+002f
0x62 U+fe93
0x63 U+fe95
0x64 U+fe97
0x65 U+fe99
0x66 U+fe9b
0x67 U+fe9d
0x68 U+fe9f
0x69 U+fea1
0x6a U+00a6
0x6b U+002c
0x6c U+0025
0x6d U+005f
0x6e U+003e
0x6f U+003f
0x70 U+fea3
0x71 U+fea5
0x72 U+fea7
0x73 U+fea9
0x74 U+feab
0x75 U+fead
0x76 U+feaf
0x77 U+f8f6
0x78 U+feb3
0x79 U+060c
0x7a U+003a
0x7b U+0023
0x7c U+0040
0x7d U+0027
0x7e U+003d
0x7f U+0022
0x80 U+f8f5
0x81 U+0061
0x82 U+0062
0x83 U+0063
0x84 U+0064
0x85 U+0065
0x86 U+0066
0x87 U+0067
0x88 U+0068
0x89 U+0069
0x8a U+feb7
0x8b U+f8f4
0x8c U+febb
0x8d U+f8f7
0x8e U+febf
0x8f U+fec3
0x90 U+fec7
0x91 U+006a
0x92 U+006b
0x93 U+006c
0x94 U+006d
0x95 U+006e
0x96 U+006f
0x97 U+0070
0x98 U+0071
0x99 U+0072
0x9a U+fec9
0x9b U+feca
0x9c U+fecb
0x9d U+fecc
0x9e U+fecd
0x9f U+fece
0xa0 U+fecf
0xa1 U+00f7
0xa2 U+0073
0xa3 U+0074
0xa4 U+0075
0xa5 U+0076
0xa6 U+0077
0xa7 U+0078
0xa8 U+0079
0xa9 U+007a
0xaa U+fed0
0xab U+fed1
0xac U+fed3
0xad U+fed5
0xae U+fed7
0xaf U+fed9
0xb0 U+fedb
0xb1 U+fedd
0xb2 U+fef5
0xb3 U+fef6
0xb4 U+fef7
0xb5 U+fef8
0xb6 U+fffd
0xb7 U+fffd
0xb8 U+fefb
0xb9 U+fefc
0xba U+fedf
0xbb U+fee1
0xbc U+fee3
0xbd U+fee5
0xbe U+fee7
0xbf U+fee9
0xc0 U+061b
0xc1 U+0041
0xc2 U+0042
0xc3 U+0043
0xc4 U+0044
0xc5 U+0045
0xc6 U+0046
0xc7 U+0047
0xc8 U+0048
0xc9 U+0049
0xca U+00ad
0xcb U+feeb
0xcc U+fffd
0xcd U+feec
0xce U+fffd
0xcf U+feed
0xd0 U+061f
0xd1 U+004a
0xd2 U+004b
0xd3 U+004c
0xd4 U+004d
0xd5 U+004e
0xd6 U+004f
0xd7 U+0050
0xd8 U+0051
0xd9 U+0052
0xda U+feef
0xdb U+fef0
0xdc U+fef1
0xdd U+fef2
0xde U+fef3
0xdf U+0660
0xe0 U+00d7
0xe1 U+2007
0xe2 U+0053
0xe3 U+0054
0xe4 U+0055
0xe5 U+0056
0xe6 U+0057
0xe7 U+0058
0xe8 U+0059
0xe9 U+005a
0xea U+0661
0xeb U+0662
0xec U+fffd
0xed U+0663
0xee U+0664
0xef U+0665
0xf0 U+0030
0xf1 U+0031
0xf2 U+0032
0xf3 U+0033
0xf4 U+0034
0xf5 U+0035
0xf6 U+0036
0xf7 U+0037
0xf8 U+0038
0xf9 U+0039
0xfa U+fffd
0xfb U+0666
0xfc U+0667
0xfd U+0668
0xfe U+0669
0xff U+009f
#
# Frm IBMCDC datatable 01A434B0.TXMAP110
#
# Changed
# 0x15 U+0085 -> 0x15 U+000a
#
0x00 U+0000
0x01 U+0001
0x02 U+0002
0x03 U+0003
0x04 U+009C
0x05 U+0009
0x06 U+0086
0x07 U+007F
0x08 U+0097
0x09 U+008D
0x0A U+008E
0x0B U+000B
0x0C U+000C
0x0D U+000D
0x0E U+000E
0x0F U+000F
0x10 U+0010
0x11 U+0011
0x12 U+0012
0x13 U+0013
0x14 U+009D
0x15 U+000A
0x16 U+0008
0x17 U+0087
0x18 U+0018
0x19 U+0019
0x1A U+0092
0x1B U+008F
0x1C U+001C
0x1D U+001D
0x1E U+001E
0x1F U+001F
0x20 U+0080
0x21 U+0081
0x22 U+0082
0x23 U+0083
0x24 U+0084
0x25 U+000A
0x26 U+0017
0x27 U+001B
0x28 U+0088
0x29 U+0089
0x2A U+008A
0x2B U+008B
0x2C U+008C
0x2D U+0005
0x2E U+0006
0x2F U+0007
0x30 U+0090
0x31 U+0091
0x32 U+0016
0x33 U+0093
0x34 U+0094
0x35 U+0095
0x36 U+0096
0x37 U+0004
0x38 U+0098
0x39 U+0099
0x3A U+009A
0x3B U+009B
0x3C U+0014
0x3D U+0015
0x3E U+009E
0x3F U+001A
0x40 U+0020
0x41 U+00A0
0x42 U+0651
0x43 U+FE7D
0x44 U+0640
0x45 U+200B
0x46 U+0621
0x47 U+0622
0x48 U+FE82
0x49 U+0623
0x4A U+00A2
0x4B U+002E
0x4C U+003C
0x4D U+0028
0x4E U+002B
0x4F U+007C
0x50 U+0026
0x51 U+FE84
0x52 U+0624
0x55 U+0626
0x56 U+0627
0x57 U+FE8E
0x58 U+0628
0x59 U+FE91
0x5A U+0021
0x5B U+0024
0x5C U+002A
0x5D U+0029
0x5E U+003B
0x5F U+00AC
0x60 U+002D
0x61 U+002F
0x62 U+0629
0x63 U+062A
0x64 U+FE97
0x65 U+062B
0x66 U+FE9B
0x67 U+062C
0x68 U+FE9F
0x69 U+062D
0x6A U+00A6
0x6B U+002C
0x6C U+0025
0x6D U+005F
0x6E U+003E
0x6F U+003F
0x70 U+FEA3
0x71 U+062E
0x72 U+FEA7
0x73 U+062F
0x74 U+0630
0x75 U+0631
0x76 U+0632
0x77 U+0633
0x78 U+FEB3
0x79 U+060C
0x7A U+003A
0x7B U+0023
0x7C U+0040
0x7D U+0027
0x7E U+003D
0x7F U+0022
0x80 U+0634
0x81 U+0061
0x82 U+0062
0x83 U+0063
0x84 U+0064
0x85 U+0065
0x86 U+0066
0x87 U+0067
0x88 U+0068
0x89 U+0069
0x8A U+FEB7
0x8B U+0635
0x8C U+FEBB
0x8D U+0636
0x8E U+FEBF
0x8F U+0637
0x90 U+0638
0x91 U+006A
0x92 U+006B
0x93 U+006C
0x94 U+006D
0x95 U+006E
0x96 U+006F
0x97 U+0070
0x98 U+0071
0x99 U+0072
0x9A U+0639
0x9B U+FECA
0x9C U+FECB
0x9D U+FECC
0x9E U+063A
0x9F U+FECE
0xA0 U+FECF
0xA1 U+00F7
0xA2 U+0073
0xA3 U+0074
0xA4 U+0075
0xA5 U+0076
0xA6 U+0077
0xA7 U+0078
0xA8 U+0079
0xA9 U+007A
0xAA U+FED0
0xAB U+0641
0xAC U+FED3
0xAD U+0642
0xAE U+FED7
0xAF U+0643
0xB0 U+FEDB
0xB1 U+0644
0xB2 U+FEF5
0xB3 U+FEF6
0xB4 U+FEF7
0xB5 U+FEF8
0xB8 U+FEFB
0xB9 U+FEFC
0xBA U+FEDF
0xBB U+0645
0xBC U+FEE3
0xBD U+0646
0xBE U+FEE7
0xBF U+0647
0xC0 U+061B
0xC1 U+0041
0xC2 U+0042
0xC3 U+0043
0xC4 U+0044
0xC5 U+0045
0xC6 U+0046
0xC7 U+0047
0xC8 U+0048
0xC9 U+0049
0xCA U+00AD
0xCB U+FEEB
0xCD U+FEEC
0xCF U+0648
0xD0 U+061F
0xD1 U+004A
0xD2 U+004B
0xD3 U+004C
0xD4 U+004D
0xD5 U+004E
0xD6 U+004F
0xD7 U+0050
0xD8 U+0051
0xD9 U+0052
0xDA U+0649
0xDB U+FEF0
0xDC U+064A
0xDD U+FEF2
0xDE U+FEF3
0xDF U+0660
0xE0 U+00D7
0xE2 U+0053
0xE3 U+0054
0xE4 U+0055
0xE5 U+0056
0xE6 U+0057
0xE7 U+0058
0xE8 U+0059
0xE9 U+005A
0xEA U+0661
0xEB U+0662
0xED U+0663
0xEE U+0664
0xEF U+0665
0xF0 U+0030
0xF1 U+0031
0xF2 U+0032
0xF3 U+0033
0xF4 U+0034
0xF5 U+0035
0xF6 U+0036
0xF7 U+0037
0xF8 U+0038
0xF9 U+0039
0xFB U+0666
0xFC U+0667
0xFD U+0668
0xFE U+0669
0xFF U+009F

View File

@ -1 +1 @@
0x25 U+000a
0x25 U+000a

View File

@ -26,6 +26,7 @@
package build.tools.charsetmapping;
import java.io.*;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Formatter;
@ -54,33 +55,19 @@ public class GenerateSBCS {
String pkgName = fields[4];
System.out.printf("%s,%s,%s,%b,%s%n", clzName, csName, hisName, isASCII, pkgName);
StringBuilder b2c = new StringBuilder();
int c2bLen = genB2C(
new FileInputStream(new File(args[0], clzName+".map")), b2c);
String b2cNR = null;
File nrF = new File(args[0], clzName+".nr");
if (nrF.exists()) {
b2cNR = genNR(new FileInputStream(nrF));
}
String c2bNR = null;
File c2bF = new File(args[0], clzName+".c2b");
if (c2bF.exists()) {
c2bNR = genC2BNR(new FileInputStream(c2bF));
}
genSBCSClass(args[0], args[1], "SingleByte-X.java",
clzName, csName, hisName, pkgName, isASCII,
b2c.toString(), b2cNR, c2bNR, c2bLen);
genClass(args[0], args[1], "SingleByte-X.java",
clzName, csName, hisName, pkgName, isASCII);
}
}
private static void toString(char[] sb, int off, int end,
Formatter out, String closure) {
Formatter out, String closure,
boolean comment) {
while (off < end) {
out.format(" \"");
for (int j = 0; j < 8; j++) {
if (off == end)
break;
char c = sb[off++];
switch (c) {
case '\b':
@ -103,101 +90,124 @@ public class GenerateSBCS {
out.format("\\u%04X", c & 0xffff);
}
}
if (off == end)
out.format("\" %s // 0x%02x - 0x%02x%n", closure, off-8, off-1);
else
out.format("\" + // 0x%02x - 0x%02x%n", off-8, off-1);
if (comment) {
if (off == end)
out.format("\" %s // 0x%02x - 0x%02x%n",
closure, off-8, off-1);
else
out.format("\" + // 0x%02x - 0x%02x%n",
off-8, off-1);
} else {
if (off == end)
out.format("\"%s%n", closure);
else
out.format("\" +%n");
}
}
}
static Pattern sbmap = Pattern.compile("0x(\\p{XDigit}++)\\s++U\\+(\\p{XDigit}++)(\\s++#.*)?");
private static int genB2C(InputStream in, StringBuilder out)
private static void genClass(String srcDir, String dstDir,
String template,
String clzName,
String csName,
String hisName,
String pkgName,
boolean isASCII)
throws Exception
{
StringBuilder b2cSB = new StringBuilder();
StringBuilder b2cNRSB = new StringBuilder();
StringBuilder c2bNRSB = new StringBuilder();
char[] sb = new char[0x100];
int[] indexC2B = new int[0x100];
char[] c2bIndex = new char[0x100];
int c2bOff = 0;
Arrays.fill(sb, UNMAPPABLE_DECODING);
Arrays.fill(c2bIndex, UNMAPPABLE_DECODING);
for (int i = 0; i < sb.length; i++)
sb[i] = UNMAPPABLE_DECODING;
// parse the b2c mapping table
// (1)read in .map to parse all b->c entries
FileInputStream in = new FileInputStream(
new File(srcDir, clzName + ".map"));
Parser p = new Parser(in, sbmap);
Entry e = null;
int off = 0;
while ((e = p.next()) != null) {
sb[e.bs] = (char)e.cp;
if (indexC2B[e.cp>>8] == 0) {
off += 0x100;
indexC2B[e.cp>>8] = 1;
if (c2bIndex[e.cp>>8] == UNMAPPABLE_DECODING) {
c2bOff += 0x100;
c2bIndex[e.cp>>8] = 1;
}
}
Formatter fm = new Formatter(out);
Formatter fm = new Formatter(b2cSB);
fm.format("%n");
// vm -server shows cc[byte + 128] access is much faster than
// cc[byte&0xff] so we output the upper segment first
toString(sb, 0x80, 0x100, fm, "+");
toString(sb, 0x00, 0x80, fm, ";");
toString(sb, 0x80, 0x100, fm, "+", true);
toString(sb, 0x00, 0x80, fm, ";", true);
fm.close();
return off;
}
// generate non-roundtrip entries from xxx.nr file
private static String genNR(InputStream in) throws Exception
{
StringBuilder sb = new StringBuilder();
Formatter fm = new Formatter(sb);
Parser p = new Parser(in, sbmap);
Entry e = null;
fm.format("// remove non-roundtrip entries%n");
fm.format(" b2cMap = b2cTable.toCharArray();%n");
while ((e = p.next()) != null) {
fm.format(" b2cMap[%d] = UNMAPPABLE_DECODING;%n",
(e.bs>=0x80)?(e.bs-0x80):(e.bs+0x80));
}
fm.close();
return sb.toString();
}
// (2)now the .nr file which includes "b->c" non-roundtrip entries
File f = new File(srcDir, clzName + ".nr");
if (f.exists()) {
in = new FileInputStream(f);
fm = new Formatter(b2cNRSB);
p = new Parser(in, sbmap);
e = null;
// generate c2b only entries from xxx.c2b file
private static String genC2BNR(InputStream in) throws Exception
{
StringBuilder sb = new StringBuilder();
Formatter fm = new Formatter(sb);
Parser p = new Parser(in, sbmap);
ArrayList<Entry> es = new ArrayList<Entry>();
Entry e = null;
while ((e = p.next()) != null) {
es.add(e);
fm.format("// remove non-roundtrip entries%n");
fm.format(" b2cMap = b2cTable.toCharArray();%n");
while ((e = p.next()) != null) {
fm.format(" b2cMap[%d] = UNMAPPABLE_DECODING;%n",
(e.bs>=0x80)?(e.bs-0x80):(e.bs+0x80));
}
fm.close();
}
fm.format("// non-roundtrip c2b only entries%n");
fm.format(" c2bNR = new char[%d];%n", es.size() * 2);
int i = 0;
for (Entry entry: es) {
fm.format(" c2bNR[%d] = 0x%x; c2bNR[%d] = 0x%x;%n",
i++, entry.bs, i++, entry.cp);
// (3)finally the .c2b file which includes c->b non-roundtrip entries
f = new File(srcDir, clzName + ".c2b");
if (f.exists()) {
in = new FileInputStream(f);
fm = new Formatter(c2bNRSB);
p = new Parser(in, sbmap);
e = null;
ArrayList<Entry> es = new ArrayList<Entry>();
while ((e = p.next()) != null) {
if (c2bIndex[e.cp>>8] == UNMAPPABLE_DECODING) {
c2bOff += 0x100;
c2bIndex[e.cp>>8] = 1;
}
es.add(e);
}
fm.format("// non-roundtrip c2b only entries%n");
if (es.size() < 100) {
fm.format(" c2bNR = new char[%d];%n", es.size() * 2);
int i = 0;
for (Entry entry: es) {
fm.format(" c2bNR[%d] = 0x%x; c2bNR[%d] = 0x%x;%n",
i++, entry.bs, i++, entry.cp);
}
} else {
char[] cc = new char[es.size() * 2];
int i = 0;
for (Entry entry: es) {
cc[i++] = (char)entry.bs;
cc[i++] = (char)entry.cp;
}
fm.format(" c2bNR = (%n");
toString(cc, 0, i, fm, ").toCharArray();", false);
}
fm.close();
}
fm.close();
return sb.toString();
}
private static void genSBCSClass(String srcDir,
String dstDir,
String template,
String clzName,
String csName,
String hisName,
String pkgName,
boolean isASCII,
String b2c,
String b2cNR,
String c2bNR,
int c2blen)
throws Exception
{
// (4)it's time to generate the source file
String b2c = b2cSB.toString();
String b2cNR = b2cNRSB.toString();
String c2bNR = c2bNRSB.toString();
Scanner s = new Scanner(new File(srcDir, template));
PrintStream out = new PrintStream(new FileOutputStream(
new File(dstDir, clzName + ".java")));
@ -239,16 +249,16 @@ public class GenerateSBCS {
line = line.replace("$B2CTABLE$", b2c);
}
if (line.indexOf("$C2BLENGTH$") != -1) {
line = line.replace("$C2BLENGTH$", "0x" + Integer.toString(c2blen, 16));
line = line.replace("$C2BLENGTH$", "0x" + Integer.toString(c2bOff, 16));
}
if (line.indexOf("$NONROUNDTRIP_B2C$") != -1) {
if (b2cNR == null)
if (b2cNR.length() == 0)
continue;
line = line.replace("$NONROUNDTRIP_B2C$", b2cNR);
}
if (line.indexOf("$NONROUNDTRIP_C2B$") != -1) {
if (c2bNR == null)
if (c2bNR.length() == 0)
continue;
line = line.replace("$NONROUNDTRIP_C2B$", c2bNR);
}

View File

@ -50,27 +50,72 @@
#include <limits.h>
/*
* (Hopefully temporarily) disable the clone-exec feature pending
* further investigation and bug-fixing.
* 32-bit (but not 64-bit) Linux fails on the program
* Runtime.getRuntime().exec("/bin/true").waitFor();
* with:
* # Internal Error (os_linux_x86.cpp:683), pid=19940, tid=2934639536
* # Error: pthread_getattr_np failed with errno = 3 (ESRCH)
* Linux kernel/pthread gurus are invited to figure this out.
* There are 3 possible strategies we might use to "fork":
*
* - fork(2). Very portable and reliable but subject to
* failure due to overcommit (see the documentation on
* /proc/sys/vm/overcommit_memory in Linux proc(5)).
* This is the ancient problem of spurious failure whenever a large
* process starts a small subprocess.
*
* - vfork(). Using this is scary because all relevant man pages
* contain dire warnings, e.g. Linux vfork(2). But at least it's
* documented in the glibc docs and is standardized by XPG4.
* http://www.opengroup.org/onlinepubs/000095399/functions/vfork.html
* On Linux, one might think that vfork() would be implemented using
* the clone system call with flag CLONE_VFORK, but in fact vfork is
* a separate system call (which is a good sign, suggesting that
* vfork will continue to be supported at least on Linux).
* Another good sign is that glibc implements posix_spawn using
* vfork whenever possible. Note that we cannot use posix_spawn
* ourselves because there's no reliable way to close all inherited
* file descriptors.
*
* - clone() with flags CLONE_VM but not CLONE_THREAD. clone() is
* Linux-specific, but this ought to work - at least the glibc
* sources contain code to handle different combinations of CLONE_VM
* and CLONE_THREAD. However, when this was implemented, it
* appeared to fail on 32-bit i386 (but not 64-bit x86_64) Linux with
* the simple program
* Runtime.getRuntime().exec("/bin/true").waitFor();
* with:
* # Internal Error (os_linux_x86.cpp:683), pid=19940, tid=2934639536
* # Error: pthread_getattr_np failed with errno = 3 (ESRCH)
* We believe this is a glibc bug, reported here:
* http://sources.redhat.com/bugzilla/show_bug.cgi?id=10311
* but the glibc maintainers closed it as WONTFIX.
*
* Based on the above analysis, we are currently using vfork() on
* Linux and fork() on other Unix systems, but the code to use clone()
* remains.
*/
#define USE_CLONE 0
#ifndef USE_CLONE
#ifdef __linux__
#define USE_CLONE 1
#else
#define USE_CLONE 0
#endif
#define START_CHILD_USE_CLONE 0 /* clone() currently disabled; see above. */
#ifndef START_CHILD_USE_CLONE
#ifdef __linux__
#define START_CHILD_USE_CLONE 1
#else
#define START_CHILD_USE_CLONE 0
#endif
#endif
#if USE_CLONE
/* By default, use vfork() on Linux. */
#ifndef START_CHILD_USE_VFORK
#ifdef __linux__
#define START_CHILD_USE_VFORK 1
#else
#define START_CHILD_USE_VFORK 0
#endif
#endif
#if START_CHILD_USE_CLONE
#include <sched.h>
#define START_CHILD_SYSTEM_CALL "clone"
#elif START_CHILD_USE_VFORK
#define START_CHILD_SYSTEM_CALL "vfork"
#else
#define START_CHILD_SYSTEM_CALL "fork"
#endif
#ifndef STDIN_FILENO
@ -95,6 +140,27 @@
#define FAIL_FILENO (STDERR_FILENO + 1)
/* TODO: Refactor. */
#define RESTARTABLE(_cmd, _result) do { \
do { \
_result = _cmd; \
} while((_result == -1) && (errno == EINTR)); \
} while(0)
/* This is one of the rare times it's more portable to declare an
* external symbol explicitly, rather than via a system header.
* The declaration is standardized as part of UNIX98, but there is
* no standard (not even de-facto) header file where the
* declaration is to be found. See:
* http://www.opengroup.org/onlinepubs/009695399/functions/environ.html
* http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_02.html
*
* "All identifiers in this volume of IEEE Std 1003.1-2001, except
* environ, are defined in at least one of the headers" (!)
*/
extern char **environ;
static void
setSIGCHLDHandler(JNIEnv *env)
{
@ -283,6 +349,36 @@ Java_java_lang_UNIXProcess_waitForProcessExit(JNIEnv* env,
}
}
static ssize_t
restartableWrite(int fd, const void *buf, size_t count)
{
ssize_t result;
RESTARTABLE(write(fd, buf, count), result);
return result;
}
static int
restartableDup2(int fd_from, int fd_to)
{
int err;
RESTARTABLE(dup2(fd_from, fd_to), err);
return err;
}
static int
restartableClose(int fd)
{
int err;
RESTARTABLE(close(fd), err);
return err;
}
static int
closeSafely(int fd)
{
return (fd == -1) ? 0 : restartableClose(fd);
}
static int
isAsciiDigit(char c)
{
@ -303,8 +399,8 @@ closeDescriptors(void)
* the lowest numbered file descriptor, just like open(). So we
* close a couple explicitly. */
close(from_fd); /* for possible use by opendir() */
close(from_fd + 1); /* another one for good luck */
restartableClose(from_fd); /* for possible use by opendir() */
restartableClose(from_fd + 1); /* another one for good luck */
if ((dp = opendir("/proc/self/fd")) == NULL)
return 0;
@ -316,7 +412,7 @@ closeDescriptors(void)
int fd;
if (isAsciiDigit(dirp->d_name[0]) &&
(fd = strtol(dirp->d_name, NULL, 10)) >= from_fd + 2)
close(fd);
restartableClose(fd);
}
closedir(dp);
@ -324,13 +420,15 @@ closeDescriptors(void)
return 1;
}
static void
static int
moveDescriptor(int fd_from, int fd_to)
{
if (fd_from != fd_to) {
dup2(fd_from, fd_to);
close(fd_from);
if ((restartableDup2(fd_from, fd_to) == -1) ||
(restartableClose(fd_from) == -1))
return -1;
}
return 0;
}
static const char *
@ -434,13 +532,13 @@ execve_with_shell_fallback(const char *file,
const char *argv[],
const char *const envp[])
{
#if USE_CLONE
#if START_CHILD_USE_CLONE || START_CHILD_USE_VFORK
/* shared address space; be very careful. */
execve(file, (char **) argv, (char **) envp);
if (errno == ENOEXEC)
execve_as_traditional_shell_script(file, argv, envp);
#else
/* Our address space is unshared, so can mutate environ. */
extern char **environ;
/* unshared address space; we can mutate environ. */
environ = (char **) envp;
execvp(file, (char **) argv);
#endif
@ -458,19 +556,6 @@ JDK_execvpe(const char *file,
const char *argv[],
const char *const envp[])
{
/* This is one of the rare times it's more portable to declare an
* external symbol explicitly, rather than via a system header.
* The declaration is standardized as part of UNIX98, but there is
* no standard (not even de-facto) header file where the
* declaration is to be found. See:
* http://www.opengroup.org/onlinepubs/009695399/functions/environ.html
* http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_02.html
*
* "All identifiers in this volume of IEEE Std 1003.1-2001, except
* environ, are defined in at least one of the headers" (!)
*/
extern char **environ;
if (envp == NULL || (char **) envp == environ) {
execvp(file, (char **) argv);
return;
@ -540,13 +625,6 @@ JDK_execvpe(const char *file,
}
}
static void
closeSafely(int fd)
{
if (fd != -1)
close(fd);
}
/*
* Reads nbyte bytes from file descriptor fd into buf,
* The read operation is retried in case of EINTR or partial reads.
@ -589,6 +667,9 @@ typedef struct _ChildStuff
const char **envv;
const char *pdir;
jboolean redirectErrorStream;
#if START_CHILD_USE_CLONE
void *clone_stack;
#endif
} ChildStuff;
static void
@ -612,31 +693,40 @@ childProcess(void *arg)
/* Close the parent sides of the pipes.
Closing pipe fds here is redundant, since closeDescriptors()
would do it anyways, but a little paranoia is a good thing. */
closeSafely(p->in[1]);
closeSafely(p->out[0]);
closeSafely(p->err[0]);
closeSafely(p->fail[0]);
if ((closeSafely(p->in[1]) == -1) ||
(closeSafely(p->out[0]) == -1) ||
(closeSafely(p->err[0]) == -1) ||
(closeSafely(p->fail[0]) == -1))
goto WhyCantJohnnyExec;
/* Give the child sides of the pipes the right fileno's. */
/* Note: it is possible for in[0] == 0 */
moveDescriptor(p->in[0] != -1 ? p->in[0] : p->fds[0], STDIN_FILENO);
moveDescriptor(p->out[1]!= -1 ? p->out[1] : p->fds[1], STDOUT_FILENO);
if ((moveDescriptor(p->in[0] != -1 ? p->in[0] : p->fds[0],
STDIN_FILENO) == -1) ||
(moveDescriptor(p->out[1]!= -1 ? p->out[1] : p->fds[1],
STDOUT_FILENO) == -1))
goto WhyCantJohnnyExec;
if (p->redirectErrorStream) {
closeSafely(p->err[1]);
dup2(STDOUT_FILENO, STDERR_FILENO);
if ((closeSafely(p->err[1]) == -1) ||
(restartableDup2(STDOUT_FILENO, STDERR_FILENO) == -1))
goto WhyCantJohnnyExec;
} else {
moveDescriptor(p->err[1] != -1 ? p->err[1] : p->fds[2], STDERR_FILENO);
if (moveDescriptor(p->err[1] != -1 ? p->err[1] : p->fds[2],
STDERR_FILENO) == -1)
goto WhyCantJohnnyExec;
}
moveDescriptor(p->fail[1], FAIL_FILENO);
if (moveDescriptor(p->fail[1], FAIL_FILENO) == -1)
goto WhyCantJohnnyExec;
/* close everything */
if (closeDescriptors() == 0) { /* failed, close the old way */
int max_fd = (int)sysconf(_SC_OPEN_MAX);
int i;
for (i = FAIL_FILENO + 1; i < max_fd; i++)
close(i);
int fd;
for (fd = FAIL_FILENO + 1; fd < max_fd; fd++)
if (restartableClose(fd) == -1 && errno != EBADF)
goto WhyCantJohnnyExec;
}
/* change to the new working directory */
@ -661,13 +751,62 @@ childProcess(void *arg)
*/
{
int errnum = errno;
write(FAIL_FILENO, &errnum, sizeof(errnum));
restartableWrite(FAIL_FILENO, &errnum, sizeof(errnum));
}
close(FAIL_FILENO);
restartableClose(FAIL_FILENO);
_exit(-1);
return 0; /* Suppress warning "no return value from function" */
}
/**
* Start a child process running function childProcess.
* This function only returns in the parent.
* We are unusually paranoid; use of clone/vfork is
* especially likely to tickle gcc/glibc bugs.
*/
#ifdef __attribute_noinline__ /* See: sys/cdefs.h */
__attribute_noinline__
#endif
static pid_t
startChild(ChildStuff *c) {
#if START_CHILD_USE_CLONE
#define START_CHILD_CLONE_STACK_SIZE (64 * 1024)
/*
* See clone(2).
* Instead of worrying about which direction the stack grows, just
* allocate twice as much and start the stack in the middle.
*/
if ((c->clone_stack = malloc(2 * START_CHILD_CLONE_STACK_SIZE)) == NULL)
/* errno will be set to ENOMEM */
return -1;
return clone(childProcess,
c->clone_stack + START_CHILD_CLONE_STACK_SIZE,
CLONE_VFORK | CLONE_VM | SIGCHLD, c);
#else
#if START_CHILD_USE_VFORK
/*
* We separate the call to vfork into a separate function to make
* very sure to keep stack of child from corrupting stack of parent,
* as suggested by the scary gcc warning:
* warning: variable 'foo' might be clobbered by 'longjmp' or 'vfork'
*/
volatile pid_t resultPid = vfork();
#else
/*
* From Solaris fork(2): In Solaris 10, a call to fork() is
* identical to a call to fork1(); only the calling thread is
* replicated in the child process. This is the POSIX-specified
* behavior for fork().
*/
pid_t resultPid = fork();
#endif
if (resultPid == 0)
childProcess(c);
assert(resultPid != 0); /* childProcess never returns */
return resultPid;
#endif /* ! START_CHILD_USE_CLONE */
}
JNIEXPORT jint JNICALL
Java_java_lang_UNIXProcess_forkAndExec(JNIEnv *env,
jobject process,
@ -680,9 +819,6 @@ Java_java_lang_UNIXProcess_forkAndExec(JNIEnv *env,
{
int errnum;
int resultPid = -1;
#if USE_CLONE
void *clone_stack = NULL;
#endif
int in[2], out[2], err[2], fail[2];
jint *fds = NULL;
const char *pprog = NULL;
@ -696,6 +832,9 @@ Java_java_lang_UNIXProcess_forkAndExec(JNIEnv *env,
c->argv = NULL;
c->envv = NULL;
c->pdir = NULL;
#if START_CHILD_USE_CLONE
c->clone_stack = NULL;
#endif
/* Convert prog + argBlock into a char ** argv.
* Add one word room for expansion of argv for use by
@ -741,37 +880,15 @@ Java_java_lang_UNIXProcess_forkAndExec(JNIEnv *env,
c->redirectErrorStream = redirectErrorStream;
{
#if USE_CLONE
/* See clone(2).
* Instead of worrying about which direction the stack grows, just
* allocate twice as much and start the stack in the middle. */
const int stack_size = 64 * 1024;
if ((clone_stack = NEW(char, 2 * stack_size)) == NULL) goto Catch;
resultPid = clone(childProcess, clone_stack + stack_size,
/* CLONE_VFORK | // works, but unnecessary */
CLONE_VM | SIGCHLD, c);
#else
/* From fork(2): In Solaris 10, a call to fork() is identical
* to a call to fork1(); only the calling thread is replicated
* in the child process. This is the POSIX-specified behavior
* for fork(). */
resultPid = fork();
if (resultPid == 0) {
childProcess(c);
assert(0); /* childProcess must not return */
}
#endif
}
resultPid = startChild(c);
assert(resultPid != 0);
if (resultPid < 0) {
throwIOException(env, errno, "Fork failed");
throwIOException(env, errno, START_CHILD_SYSTEM_CALL " failed");
goto Catch;
}
/* parent process */
close(fail[1]); fail[1] = -1; /* See: WhyCantJohnnyExec */
restartableClose(fail[1]); fail[1] = -1; /* See: WhyCantJohnnyExec */
switch (readFully(fail[0], &errnum, sizeof(errnum))) {
case 0: break; /* Exec succeeded */
@ -789,8 +906,8 @@ Java_java_lang_UNIXProcess_forkAndExec(JNIEnv *env,
fds[2] = (err[0] != -1) ? err[0] : -1;
Finally:
#if USE_CLONE
free(clone_stack);
#if START_CHILD_USE_CLONE
free(c->clone_stack);
#endif
/* Always clean up the child's side of the pipes */

View File

@ -29,7 +29,7 @@
* @author jjh
*
* @run build TestScaffold VMConnection TargetListener TargetAdapter
* @run compile -source 1.5 -target 1.5 -g EnumTest.java
* @run compile -g EnumTest.java
* @run main EnumTest
*/
import com.sun.jdi.*;

View File

@ -29,7 +29,7 @@
* @author jjh
*
* @run build TestScaffold VMConnection TargetListener TargetAdapter
* @run compile -source 1.5 -target 1.5 -g GenericsTest.java
* @run compile -g GenericsTest.java
* @run main GenericsTest
*/
import com.sun.jdi.*;

View File

@ -32,7 +32,6 @@
# @run shell JdbVarargsTest.sh
classname=JdbVarargsTest
compileOptions="-source 1.5 -target 1.5"
createJavaFile()
{
cat <<EOF > $classname.java.1

View File

@ -27,7 +27,7 @@
* @author Gordon Hirsch
*
* @run build TestScaffold VMConnection TargetAdapter TargetListener
* @run compile -g -target 1.5 MethodCalls.java
* @run compile -g MethodCalls.java
* @run compile -g MethodCallsReflection.java
* @run compile -g ControlFlow.java
* @run build StepTest

View File

@ -29,7 +29,7 @@
* @author jjh
*
* @run build TestScaffold VMConnection TargetListener TargetAdapter
* @run compile -g -source 1.5 UTF8Test.java
* @run compile -g UTF8Test.java
* @run main UTF8Test
*/

View File

@ -29,7 +29,7 @@
* @author jjh
*
* @run build TestScaffold VMConnection TargetListener TargetAdapter
* @run compile -g -source 1.5 -target 1.5 VarargsTest.java
* @run compile -g VarargsTest.java
* @run main VarargsTest
*/
import com.sun.jdi.*;