Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8271732: Regression in StringBuilder.charAt bounds checking #5086

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -349,10 +349,11 @@ public void setLength(int newLength) {
*/
@Override
public char charAt(int index) {
checkIndex(index, count);
if (isLatin1()) {
return StringLatin1.charAt(value, index);
return (char)(value[index] & 0xff);
}
return StringUTF16.charAt(value, index);
return StringUTF16.getChar(value, index);
}

/**
@@ -24,18 +24,25 @@

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.CompilerControl;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;

import java.util.concurrent.TimeUnit;

@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Thread)
@Warmup(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
@Fork(3)
public class StringBuilders {

private String[] strings;
@@ -330,6 +337,20 @@ public String appendBoundsMix(Data data) {
endIndex).append(';').toString();
}

public int charAt_index = 3;

@Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public char charAtLatin1() {
return sbLatin1.charAt(charAt_index);
}

@Benchmark
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
public char charAtUtf16() {
return sbUtf16.charAt(charAt_index);
}

@State(Scope.Thread)
public static class Data {
int i = 0;