Re: RFR: 8329623: NegativeArraySizeException encoding large String to UTF-8

2024-04-08 Thread Raffaello Giulietti
On Fri, 5 Apr 2024 17:44:38 GMT, Roger Riggs wrote: > When encoding a vary large string in String.getBytes(StandardCharset.UTF_8) > computation of the buffer size may exceed the range of a positive 32-bit > Integer. > If the estimated size for the result byte array is too large, pre-compute

Re: RFR: 8329623: NegativeArraySizeException encoding large String to UTF-8

2024-04-08 Thread Raffaello Giulietti
On Mon, 8 Apr 2024 13:46:03 GMT, Roger Riggs wrote: >> Indeed, different OOMEs are thrown in the two cases triggered by different >> limits, min +2 is due to integer overflow, while min +1 is due a VM limit >> on the size of byte[Integer.MAX_VALUE]. Different VM implementations may >> have

Re: RFR: 8329623: NegativeArraySizeException encoding large String to UTF-8

2024-04-08 Thread Roger Riggs
On Mon, 8 Apr 2024 13:39:34 GMT, Roger Riggs wrote: >> test/jdk/java/lang/String/CompactString/MaxSizeUTF16String.java line 143: >> >>> 141: // Strings of size min+1...min+2, throw OOME >>> 142: // The resulting byte array would exceed implementation limits >>> 143: for

Re: RFR: 8329623: NegativeArraySizeException encoding large String to UTF-8

2024-04-08 Thread Roger Riggs
On Mon, 8 Apr 2024 08:54:21 GMT, Raffaello Giulietti wrote: >> When encoding a vary large string in String.getBytes(StandardCharset.UTF_8) >> computation of the buffer size may exceed the range of a positive 32-bit >> Integer. >> If the estimated size for the result byte array is too large,

Re: RFR: 8329623: NegativeArraySizeException encoding large String to UTF-8

2024-04-08 Thread Raffaello Giulietti
On Fri, 5 Apr 2024 17:44:38 GMT, Roger Riggs wrote: > When encoding a vary large string in String.getBytes(StandardCharset.UTF_8) > computation of the buffer size may exceed the range of a positive 32-bit > Integer. > If the estimated size for the result byte array is too large, pre-compute

Re: RFR: 8329623: NegativeArraySizeException encoding large String to UTF-8

2024-04-05 Thread Naoto Sato
On Fri, 5 Apr 2024 21:57:15 GMT, Roger Riggs wrote: > The test doesn't run quickly already due to the large chunks of memory used. OK, never mind then, if it would take considerable time. - PR Comment: https://git.openjdk.org/jdk/pull/18663#issuecomment-2040706486

Re: RFR: 8329623: NegativeArraySizeException encoding large String to UTF-8

2024-04-05 Thread Roger Riggs
On Fri, 5 Apr 2024 20:17:39 GMT, Naoto Sato wrote: > LGTM. The test case could be more thorough if it tests strings with > supplementary codepoints, as the new method computes them exclusively. I considered that, but the worst case is the x3 expansion. A 2 character high/low surrogate pair

Re: RFR: 8329623: NegativeArraySizeException encoding large String to UTF-8

2024-04-05 Thread Naoto Sato
On Fri, 5 Apr 2024 17:44:38 GMT, Roger Riggs wrote: > When encoding a vary large string in String.getBytes(StandardCharset.UTF_8) > computation of the buffer size may exceed the range of a positive 32-bit > Integer. > If the estimated size for the result byte array is too large, pre-compute

RFR: 8329623: NegativeArraySizeException encoding large String to UTF-8

2024-04-05 Thread Roger Riggs
When encoding a vary large string in String.getBytes(StandardCharset.UTF_8) computation of the buffer size may exceed the range of a positive 32-bit Integer. If the estimated size for the result byte array is too large, pre-compute the exact buffer size. If that exceeds the range, then throw