< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/ConstantStringIndexOfSnippets.java

Print this page

        

*** 23,32 **** --- 23,33 ---- package org.graalvm.compiler.replacements; import static org.graalvm.compiler.replacements.SnippetTemplate.DEFAULT_REPLACER; + import static org.graalvm.compiler.serviceprovider.GraalUnsafeAccess.getUnsafe; import org.graalvm.compiler.api.replacements.Fold; import org.graalvm.compiler.api.replacements.Fold.InjectedParameter; import org.graalvm.compiler.api.replacements.Snippet; import org.graalvm.compiler.api.replacements.Snippet.ConstantParameter;
*** 42,53 **** --- 43,57 ---- import org.graalvm.compiler.replacements.nodes.ExplodeLoopNode; import jdk.vm.ci.code.TargetDescription; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.MetaAccessProvider; + import sun.misc.Unsafe; public class ConstantStringIndexOfSnippets implements Snippets { + private static final Unsafe UNSAFE = getUnsafe(); + public static class Templates extends AbstractTemplates { private final SnippetInfo indexOfConstant = snippet(ConstantStringIndexOfSnippets.class, "indexOfConstant"); private final SnippetInfo latin1IndexOfConstant = snippet(ConstantStringIndexOfSnippets.class, "latin1IndexOfConstant"); private final SnippetInfo utf16IndexOfConstant = snippet(ConstantStringIndexOfSnippets.class, "utf16IndexOfConstant");
*** 155,168 **** int c = target.length / 2; if (c == 0) { return 0; } long base = metaAccess.getArrayBaseOffset(JavaKind.Byte); ! char lastChar = UnsafeAccess.UNSAFE.getChar(target, base + (c - 1) * 2); int md2 = c; for (int i = 0; i < c - 1; i++) { ! char currChar = UnsafeAccess.UNSAFE.getChar(target, base + i * 2); if (currChar == lastChar) { md2 = (c - 1) - i; } } return md2; --- 159,172 ---- int c = target.length / 2; if (c == 0) { return 0; } long base = metaAccess.getArrayBaseOffset(JavaKind.Byte); ! char lastChar = UNSAFE.getChar(target, base + (c - 1) * 2); int md2 = c; for (int i = 0; i < c - 1; i++) { ! char currChar = UNSAFE.getChar(target, base + i * 2); if (currChar == lastChar) { md2 = (c - 1) - i; } } return md2;
*** 172,182 **** int c = s.length / 2; int cache = 0; int i; long base = metaAccess.getArrayBaseOffset(JavaKind.Byte); for (i = 0; i < c - 1; i++) { ! char currChar = UnsafeAccess.UNSAFE.getChar(s, base + i * 2); cache |= (1 << (currChar & 63)); } return cache; } --- 176,186 ---- int c = s.length / 2; int cache = 0; int i; long base = metaAccess.getArrayBaseOffset(JavaKind.Byte); for (i = 0; i < c - 1; i++) { ! char currChar = UNSAFE.getChar(s, base + i * 2); cache |= (1 << (currChar & 63)); } return cache; }
*** 210,223 **** int targetCountLess1 = targetCount - 1; int sourceEnd = sourceCount - targetCountLess1; long base = charArrayBaseOffset(INJECTED); ! int lastChar = UnsafeAccess.UNSAFE.getChar(target, base + targetCountLess1 * 2); outer_loop: for (long i = sourceOffset + fromIndex; i < sourceEnd;) { ! int src = UnsafeAccess.UNSAFE.getChar(source, base + (i + targetCountLess1) * 2); if (src == lastChar) { // With random strings and a 4-character alphabet, // reverse matching at this point sets up 0.8% fewer // frames, but (paradoxically) makes 0.3% more probes. // Since those probes are nearer the lastChar probe, --- 214,227 ---- int targetCountLess1 = targetCount - 1; int sourceEnd = sourceCount - targetCountLess1; long base = charArrayBaseOffset(INJECTED); ! int lastChar = UNSAFE.getChar(target, base + targetCountLess1 * 2); outer_loop: for (long i = sourceOffset + fromIndex; i < sourceEnd;) { ! int src = UNSAFE.getChar(source, base + (i + targetCountLess1) * 2); if (src == lastChar) { // With random strings and a 4-character alphabet, // reverse matching at this point sets up 0.8% fewer // frames, but (paradoxically) makes 0.3% more probes. // Since those probes are nearer the lastChar probe,
*** 227,238 **** // (sourceOffset - targetCountLess1) to (sourceOffset + sourceCount) if (targetCount <= 8) { ExplodeLoopNode.explodeLoop(); } for (long j = 0; j < targetCountLess1; j++) { ! char sourceChar = UnsafeAccess.UNSAFE.getChar(source, base + (i + j) * 2); ! if (UnsafeAccess.UNSAFE.getChar(target, base + (targetOffset + j) * 2) != sourceChar) { if ((cache & (1 << sourceChar)) == 0) { if (md2 < j + 1) { i += j + 1; continue outer_loop; } --- 231,242 ---- // (sourceOffset - targetCountLess1) to (sourceOffset + sourceCount) if (targetCount <= 8) { ExplodeLoopNode.explodeLoop(); } for (long j = 0; j < targetCountLess1; j++) { ! char sourceChar = UNSAFE.getChar(source, base + (i + j) * 2); ! if (UNSAFE.getChar(target, base + (targetOffset + j) * 2) != sourceChar) { if ((cache & (1 << sourceChar)) == 0) { if (md2 < j + 1) { i += j + 1; continue outer_loop; }
*** 268,281 **** int targetCountLess1 = targetCount - 1; int sourceEnd = sourceCount - targetCountLess1; long base = byteArrayBaseOffset(INJECTED); ! int lastChar = UnsafeAccess.UNSAFE.getChar(target, base + targetCountLess1 * 2); outer_loop: for (long i = fromIndex; i < sourceEnd;) { ! int src = UnsafeAccess.UNSAFE.getChar(source, base + (i + targetCountLess1) * 2); if (src == lastChar) { // With random strings and a 4-character alphabet, // reverse matching at this point sets up 0.8% fewer // frames, but (paradoxically) makes 0.3% more probes. // Since those probes are nearer the lastChar probe, --- 272,285 ---- int targetCountLess1 = targetCount - 1; int sourceEnd = sourceCount - targetCountLess1; long base = byteArrayBaseOffset(INJECTED); ! int lastChar = UNSAFE.getChar(target, base + targetCountLess1 * 2); outer_loop: for (long i = fromIndex; i < sourceEnd;) { ! int src = UNSAFE.getChar(source, base + (i + targetCountLess1) * 2); if (src == lastChar) { // With random strings and a 4-character alphabet, // reverse matching at this point sets up 0.8% fewer // frames, but (paradoxically) makes 0.3% more probes. // Since those probes are nearer the lastChar probe,
*** 285,296 **** // (sourceOffset - targetCountLess1) to (sourceOffset + sourceCount) if (targetCount <= 8) { ExplodeLoopNode.explodeLoop(); } for (long j = 0; j < targetCountLess1; j++) { ! char sourceChar = UnsafeAccess.UNSAFE.getChar(source, base + (i + j) * 2); ! if (UnsafeAccess.UNSAFE.getChar(target, base + j * 2) != sourceChar) { if ((cache & (1 << sourceChar)) == 0) { if (md2 < j + 1) { i += j + 1; continue outer_loop; } --- 289,300 ---- // (sourceOffset - targetCountLess1) to (sourceOffset + sourceCount) if (targetCount <= 8) { ExplodeLoopNode.explodeLoop(); } for (long j = 0; j < targetCountLess1; j++) { ! char sourceChar = UNSAFE.getChar(source, base + (i + j) * 2); ! if (UNSAFE.getChar(target, base + j * 2) != sourceChar) { if ((cache & (1 << sourceChar)) == 0) { if (md2 < j + 1) { i += j + 1; continue outer_loop; }
*** 326,339 **** int targetCountLess1 = targetCount - 1; int sourceEnd = sourceCount - targetCountLess1; long base = byteArrayBaseOffset(INJECTED); ! int lastByte = UnsafeAccess.UNSAFE.getByte(target, base + targetCountLess1); outer_loop: for (long i = fromIndex; i < sourceEnd;) { ! int src = UnsafeAccess.UNSAFE.getByte(source, base + i + targetCountLess1); if (src == lastByte) { // With random strings and a 4-character alphabet, // reverse matching at this point sets up 0.8% fewer // frames, but (paradoxically) makes 0.3% more probes. // Since those probes are nearer the lastByte probe, --- 330,343 ---- int targetCountLess1 = targetCount - 1; int sourceEnd = sourceCount - targetCountLess1; long base = byteArrayBaseOffset(INJECTED); ! int lastByte = UNSAFE.getByte(target, base + targetCountLess1); outer_loop: for (long i = fromIndex; i < sourceEnd;) { ! int src = UNSAFE.getByte(source, base + i + targetCountLess1); if (src == lastByte) { // With random strings and a 4-character alphabet, // reverse matching at this point sets up 0.8% fewer // frames, but (paradoxically) makes 0.3% more probes. // Since those probes are nearer the lastByte probe,
*** 343,354 **** // (sourceOffset - targetCountLess1) to (sourceOffset + sourceCount) if (targetCount <= 8) { ExplodeLoopNode.explodeLoop(); } for (long j = 0; j < targetCountLess1; j++) { ! byte sourceByte = UnsafeAccess.UNSAFE.getByte(source, base + i + j); ! if (UnsafeAccess.UNSAFE.getByte(target, base + j) != sourceByte) { if ((cache & (1 << sourceByte)) == 0) { if (md2 < j + 1) { i += j + 1; continue outer_loop; } --- 347,358 ---- // (sourceOffset - targetCountLess1) to (sourceOffset + sourceCount) if (targetCount <= 8) { ExplodeLoopNode.explodeLoop(); } for (long j = 0; j < targetCountLess1; j++) { ! byte sourceByte = UNSAFE.getByte(source, base + i + j); ! if (UNSAFE.getByte(target, base + j) != sourceByte) { if ((cache & (1 << sourceByte)) == 0) { if (md2 < j + 1) { i += j + 1; continue outer_loop; }
< prev index next >