src/java.base/share/classes/sun/nio/cs/ISO_8859_1.java
author martin
Wed, 28 Mar 2018 21:14:06 -0700
changeset 49443 e5679a6661d6
parent 48262 daf3b49f4839
child 49556 809b178407cc
permissions -rw-r--r--
8200310: Avoid charset lookup machinery in java.nio.charset.StandardCharsets Reviewed-by: sherman, ulfzibis
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
45894
995421c69f66 8184665: Skip name and alias checks for standard Charsets
redestad
parents: 42679
diff changeset
     2
 * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3714
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3714
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3714
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3714
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3714
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.nio.cs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.nio.ByteBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.nio.CharBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.nio.charset.Charset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.nio.charset.CharsetDecoder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.nio.charset.CharsetEncoder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.nio.charset.CoderResult;
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
    34
import java.util.Objects;
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
    35
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
    36
import jdk.internal.HotSpotIntrinsicCandidate;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
47026
94c45ad89b9c 8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents: 45894
diff changeset
    38
public class ISO_8859_1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    extends Charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    implements HistoricallyNamedCharset
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    public ISO_8859_1() {
47026
94c45ad89b9c 8186517: sun.nio.cs.StandardCharsets$Aliases and Classes can be lazily loaded
redestad
parents: 45894
diff changeset
    43
        super("ISO-8859-1", StandardCharsets.aliases_ISO_8859_1());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    public String historicalName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        return "ISO8859_1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public boolean contains(Charset cs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        return ((cs instanceof US_ASCII)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
                || (cs instanceof ISO_8859_1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public CharsetDecoder newDecoder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        return new Decoder(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public CharsetEncoder newEncoder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        return new Encoder(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
48262
daf3b49f4839 8184947: ZipCoder performance improvements
sherman
parents: 47216
diff changeset
    63
    private static class Decoder extends CharsetDecoder {
daf3b49f4839 8184947: ZipCoder performance improvements
sherman
parents: 47216
diff changeset
    64
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        private Decoder(Charset cs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            super(cs, 1.0f, 1.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        private CoderResult decodeArrayLoop(ByteBuffer src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                                            CharBuffer dst)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            byte[] sa = src.array();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            int sp = src.arrayOffset() + src.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            int sl = src.arrayOffset() + src.limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            assert (sp <= sl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            sp = (sp <= sl ? sp : sl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            char[] da = dst.array();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            int dp = dst.arrayOffset() + dst.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            int dl = dst.arrayOffset() + dst.limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            assert (dp <= dl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            dp = (dp <= dl ? dp : dl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                while (sp < sl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                    byte b = sa[sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                    if (dp >= dl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                        return CoderResult.OVERFLOW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                    da[dp++] = (char)(b & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                    sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                return CoderResult.UNDERFLOW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                src.position(sp - src.arrayOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                dst.position(dp - dst.arrayOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        private CoderResult decodeBufferLoop(ByteBuffer src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                                             CharBuffer dst)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            int mark = src.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                while (src.hasRemaining()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                    byte b = src.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                    if (!dst.hasRemaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                        return CoderResult.OVERFLOW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                    dst.put((char)(b & 0xff));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                    mark++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                return CoderResult.UNDERFLOW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                src.position(mark);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        protected CoderResult decodeLoop(ByteBuffer src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                         CharBuffer dst)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            if (src.hasArray() && dst.hasArray())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                return decodeArrayLoop(src, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                return decodeBufferLoop(src, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
48262
daf3b49f4839 8184947: ZipCoder performance improvements
sherman
parents: 47216
diff changeset
   126
    private static class Encoder extends CharsetEncoder {
daf3b49f4839 8184947: ZipCoder performance improvements
sherman
parents: 47216
diff changeset
   127
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        private Encoder(Charset cs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            super(cs, 1.0f, 1.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        public boolean canEncode(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            return c <= '\u00FF';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
2294
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 2
diff changeset
   136
        public boolean isLegalReplacement(byte[] repl) {
3055
54b677070c61 6847092: (cs) CharsetEncoder.isLegalReplacement of US_ASCII behaves differently since
sherman
parents: 2294
diff changeset
   137
            return true;  // we accept any byte value
2294
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 2
diff changeset
   138
        }
4259115772f7 6636323: Optimize handling of builtin charsets
sherman
parents: 2
diff changeset
   139
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        private final Surrogate.Parser sgp = new Surrogate.Parser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   142
        // Method possible replaced with a compiler intrinsic.
15337
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   143
        private static int encodeISOArray(char[] sa, int sp,
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   144
                                          byte[] da, int dp, int len) {
42679
25fec8839946 8159035: com/sun/crypto/provider/Cipher/CTS/CTSMode.java test crashed due to unhandled case of cipher length value as 0
rraghavan
parents: 33663
diff changeset
   145
            if (len <= 0) {
25fec8839946 8159035: com/sun/crypto/provider/Cipher/CTS/CTSMode.java test crashed due to unhandled case of cipher length value as 0
rraghavan
parents: 33663
diff changeset
   146
                return 0;
25fec8839946 8159035: com/sun/crypto/provider/Cipher/CTS/CTSMode.java test crashed due to unhandled case of cipher length value as 0
rraghavan
parents: 33663
diff changeset
   147
            }
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   148
            encodeISOArrayCheck(sa, sp, da, dp, len);
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   149
            return implEncodeISOArray(sa, sp, da, dp, len);
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   150
        }
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   151
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   152
        @HotSpotIntrinsicCandidate
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   153
        private static int implEncodeISOArray(char[] sa, int sp,
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   154
                                              byte[] da, int dp, int len)
15337
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   155
        {
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   156
            int i = 0;
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   157
            for (; i < len; i++) {
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   158
                char c = sa[sp++];
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   159
                if (c > '\u00FF')
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   160
                    break;
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   161
                da[dp++] = (byte)c;
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   162
            }
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   163
            return i;
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   164
        }
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   165
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   166
        private static void encodeISOArrayCheck(char[] sa, int sp,
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   167
                                                byte[] da, int dp, int len) {
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   168
            Objects.requireNonNull(sa);
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   169
            Objects.requireNonNull(da);
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   170
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   171
            if (sp < 0 || sp >= sa.length) {
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   172
                throw new ArrayIndexOutOfBoundsException(sp);
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   173
            }
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   174
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   175
            if (dp < 0 || dp >= da.length) {
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   176
                throw new ArrayIndexOutOfBoundsException(dp);
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   177
            }
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   178
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   179
            int endIndexSP = sp + len - 1;
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   180
            if (endIndexSP < 0 || endIndexSP >= sa.length) {
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   181
                throw new ArrayIndexOutOfBoundsException(endIndexSP);
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   182
            }
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   183
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   184
            int endIndexDP = dp + len - 1;
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   185
            if (endIndexDP < 0 || endIndexDP >= da.length) {
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   186
                throw new ArrayIndexOutOfBoundsException(endIndexDP);
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   187
            }
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   188
        }
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   189
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        private CoderResult encodeArrayLoop(CharBuffer src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                                            ByteBuffer dst)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            char[] sa = src.array();
15337
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   194
            int soff = src.arrayOffset();
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   195
            int sp = soff + src.position();
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   196
            int sl = soff + src.limit();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            assert (sp <= sl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            sp = (sp <= sl ? sp : sl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            byte[] da = dst.array();
15337
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   200
            int doff = dst.arrayOffset();
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   201
            int dp = doff + dst.position();
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   202
            int dl = doff + dst.limit();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            assert (dp <= dl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            dp = (dp <= dl ? dp : dl);
15337
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   205
            int dlen = dl - dp;
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   206
            int slen = sl - sp;
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   207
            int len  = (dlen < slen) ? dlen : slen;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            try {
15337
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   209
                int ret = encodeISOArray(sa, sp, da, dp, len);
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   210
                sp = sp + ret;
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   211
                dp = dp + ret;
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   212
                if (ret != len) {
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   213
                    if (sgp.parse(sa[sp], sa, sp, sl) < 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                        return sgp.error();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    return sgp.unmappableResult();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                }
15337
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   217
                if (len < slen)
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   218
                    return CoderResult.OVERFLOW;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                return CoderResult.UNDERFLOW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            } finally {
15337
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   221
                src.position(sp - soff);
3fc0afb7ff5b 8006799: Optimize sun.nio.cs.ISO_8859_1$Encode.encodeArrayLoop() (jdk part of 6896617)
kvn
parents: 5506
diff changeset
   222
                dst.position(dp - doff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        private CoderResult encodeBufferLoop(CharBuffer src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                                             ByteBuffer dst)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            int mark = src.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                while (src.hasRemaining()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    char c = src.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                    if (c <= '\u00FF') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                        if (!dst.hasRemaining())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                            return CoderResult.OVERFLOW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                        dst.put((byte)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                        mark++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    if (sgp.parse(c, src) < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                        return sgp.error();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    return sgp.unmappableResult();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                return CoderResult.UNDERFLOW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                src.position(mark);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        protected CoderResult encodeLoop(CharBuffer src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                                         ByteBuffer dst)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            if (src.hasArray() && dst.hasArray())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                return encodeArrayLoop(src, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                return encodeBufferLoop(src, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
}