1 /*
2 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
117
118 @MethodSubstitution
119 public static int indexOf(byte[] source, int sourceCount, byte[] target, int targetCount, int origFromIndex) {
120 int fromIndex = origFromIndex;
121 if (fromIndex >= sourceCount) {
122 return (targetCount == 0 ? sourceCount : -1);
123 }
124 if (fromIndex < 0) {
125 fromIndex = 0;
126 }
127 if (targetCount == 0) {
128 // The empty string is in every string.
129 return fromIndex;
130 }
131 if (sourceCount - fromIndex < targetCount) {
132 // The empty string contains nothing except the empty string.
133 return -1;
134 }
135 if (targetCount == 1) {
136 return AMD64ArrayIndexOf.indexOf1Byte(source, sourceCount, fromIndex, target[0]);
137 } else if (targetCount == 2) {
138 return AMD64ArrayIndexOf.indexOfTwoConsecutiveBytes(source, sourceCount, fromIndex, target[0], target[1]);
139 } else {
140 int haystackLength = sourceCount - (targetCount - 2);
141 int offset = fromIndex;
142 while (offset < haystackLength) {
143 int indexOfResult = AMD64ArrayIndexOf.indexOfTwoConsecutiveBytes(source, haystackLength, offset, target[0], target[1]);
144 if (indexOfResult < 0) {
145 return -1;
146 }
147 offset = indexOfResult;
148 Pointer cmpSourcePointer = byteOffsetPointer(source, offset);
149 Pointer targetPointer = pointer(target);
150 if (ArrayRegionEqualsNode.regionEquals(cmpSourcePointer, targetPointer, targetCount, JavaKind.Byte)) {
151 return offset;
152 }
153 offset++;
154 }
155 return -1;
156 }
157 }
158
159 /**
160 * Intrinsic for {@code java.lang.StringLatin1.inflate([BI[CII)V}.
161 *
162 * <pre>
163 * @HotSpotIntrinsicCandidate
164 * public static void inflate(byte[] src, int src_indx, char[] dst, int dst_indx, int len)
165 * </pre>
166 */
167 @MethodSubstitution
168 public static void inflate(byte[] src, int srcIndex, char[] dest, int destIndex, int len) {
169 if (len < 0 || srcIndex < 0 || (srcIndex + len > src.length) || destIndex < 0 || (destIndex + len > dest.length)) {
170 DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.BoundsCheckException);
|
1 /*
2 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
117
118 @MethodSubstitution
119 public static int indexOf(byte[] source, int sourceCount, byte[] target, int targetCount, int origFromIndex) {
120 int fromIndex = origFromIndex;
121 if (fromIndex >= sourceCount) {
122 return (targetCount == 0 ? sourceCount : -1);
123 }
124 if (fromIndex < 0) {
125 fromIndex = 0;
126 }
127 if (targetCount == 0) {
128 // The empty string is in every string.
129 return fromIndex;
130 }
131 if (sourceCount - fromIndex < targetCount) {
132 // The empty string contains nothing except the empty string.
133 return -1;
134 }
135 if (targetCount == 1) {
136 return AMD64ArrayIndexOf.indexOf1Byte(source, sourceCount, fromIndex, target[0]);
137 } else {
138 int haystackLength = sourceCount - (targetCount - 2);
139 int offset = fromIndex;
140 while (offset < haystackLength) {
141 int indexOfResult = AMD64ArrayIndexOf.indexOfTwoConsecutiveBytes(source, haystackLength, offset, target[0], target[1]);
142 if (indexOfResult < 0) {
143 return -1;
144 }
145 offset = indexOfResult;
146 Pointer cmpSourcePointer = byteOffsetPointer(source, offset);
147 Pointer targetPointer = pointer(target);
148 if (targetCount == 2 || ArrayRegionEqualsNode.regionEquals(cmpSourcePointer, targetPointer, targetCount, JavaKind.Byte)) {
149 return offset;
150 }
151 offset++;
152 }
153 return -1;
154 }
155 }
156
157 /**
158 * Intrinsic for {@code java.lang.StringLatin1.inflate([BI[CII)V}.
159 *
160 * <pre>
161 * @HotSpotIntrinsicCandidate
162 * public static void inflate(byte[] src, int src_indx, char[] dst, int dst_indx, int len)
163 * </pre>
164 */
165 @MethodSubstitution
166 public static void inflate(byte[] src, int srcIndex, char[] dest, int destIndex, int len) {
167 if (len < 0 || srcIndex < 0 || (srcIndex + len > src.length) || destIndex < 0 || (destIndex + len > dest.length)) {
168 DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.BoundsCheckException);
|