RFR: 8349241: Fix the concurrent execution JVM crash of StringBuilder::append(int/long) [v5]
Chen Liang
liach at openjdk.org
Tue Feb 4 17:48:13 UTC 2025
On Tue, 4 Feb 2025 14:03:24 GMT, Shaojin Wen <swen at openjdk.org> wrote:
>> The following code can reproduce the problem, writing out of bounds causes JVM Crash
>>
>>
>> StringBuilder buf = new StringBuilder();
>> buf.append('中');
>>
>> Thread[] threads = new Thread[40];
>> final CountDownLatch latch = new CountDownLatch(threads.length);
>> Runnable r = () -> {
>> for (int i = 0; i < 1000000; i++) {
>> buf.setLength(0);
>> buf.trimToSize();
>> buf.append(123456789123456789L);
>> }
>> latch.countDown();
>> };
>>
>> for (int i = 0; i < threads.length; i++) {
>> threads[i] = new Thread(r);
>> }
>> for (Thread t : threads) {
>> t.start();
>> }
>> latch.await();
>>
>>
>> This problem can be avoided by using the value of ensureCapacityInternal directly.
>
> Shaojin Wen has updated the pull request incrementally with one additional commit since the last revision:
>
> improved coder thread safe
On a second examination, I find this is caused by #22023, which is not in 24. And I cannot replicate the oob write on 24. I have updated the affected version to 25 as a result, and updated the caused-by link in the JBS issue.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/23427#issuecomment-2634659498
More information about the core-libs-dev
mailing list