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

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

Filter by extension

Filter by extension

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) {
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;

@Warmup(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
public class StringBuilders {

private String[] strings;
@@ -330,6 +337,20 @@ public String appendBoundsMix(Data data) {

public int charAt_index = 3;

public char charAtLatin1() {
return sbLatin1.charAt(charAt_index);

public char charAtUtf16() {
return sbUtf16.charAt(charAt_index);

public static class Data {
int i = 0;