Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2016-03-31 Thread Paul Sandoz
> On 31 Mar 2016, at 07:59, Ivan Gerasimov wrote: > >> I think they are important, more so the test update. >> >> If we can roll ‘em to Ivan’s patch that would be the most efficient. Ivan >> are you ok with that? >> > > Sure! > Thanks. > Here's the webrev, updated with those changes: >

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2016-03-30 Thread Tagir F. Valeev
Looks good for me, thank you! With best regards, Tagir Valeev. >> I think they are important, more so the test update. >> >> If we can roll ‘em to Ivan’s patch that would be the most efficient. Ivan >> are you ok with that? >> IG> Sure! IG> Here's the webrev, updated with those changes: IG> h

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2016-03-30 Thread Ivan Gerasimov
I think they are important, more so the test update. If we can roll ‘em to Ivan’s patch that would be the most efficient. Ivan are you ok with that? Sure! Here's the webrev, updated with those changes: http://cr.openjdk.java.net/~igerasim/8079136/10/webrev/ With kind regards, Ivan

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2016-03-30 Thread Paul Sandoz
> On 30 Mar 2016, at 11:03, Tagir F. Valeev wrote: > > Hello! > > IG> After the fix for JDK-8148748 went in, I needed to rebase the fix. > IG> Comparing to the previous webrev, the changes are local to > IG> ArrayList.spliterator(). > > IG> http://cr.openjdk.java.net/~igerasim/8079136/09/webre

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2016-03-30 Thread Tagir F. Valeev
Hello! IG> After the fix for JDK-8148748 went in, I needed to rebase the fix. IG> Comparing to the previous webrev, the changes are local to IG> ArrayList.spliterator(). IG> http://cr.openjdk.java.net/~igerasim/8079136/09/webrev/ IG> The builds/tests are green. Looks good to me, thanks. By th

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2016-03-29 Thread Ivan Gerasimov
Hello! After the fix for JDK-8148748 went in, I needed to rebase the fix. Comparing to the previous webrev, the changes are local to ArrayList.spliterator(). http://cr.openjdk.java.net/~igerasim/8079136/09/webrev/ The builds/tests are green. With kind regards, Ivan On 03.02.2016 22:16, Iv

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2016-03-21 Thread Ivan Gerasimov
Hello everyone! As the CCC request has been approved, the change is ready to be integrated. Here's the latest variant of the webrev: http://cr.openjdk.java.net/~igerasim/8079136/08/webrev/ It differs from the previous revision only in the javadoc section of AbstractList. All the code changes a

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2016-02-03 Thread Ivan Gerasimov
Hello! Here's the updated webrev with rangeCheckForAdd() restored in both AbstractList and ArrayList. http://cr.openjdk.java.net/~igerasim/8079136/07/webrev/ The fix was built/tested successfully on all supported platforms. Sincerely yours, Ivan On 02.02.2016 9:55, Martin Buchholz wrote: On

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2016-02-01 Thread Martin Buchholz
On Mon, Feb 1, 2016 at 10:19 PM, Tagir F. Valeev wrote: > I have a doubt about replacing rangeCheckForAdd. What if size() == > Integer.MAX_VALUE? This is not an issue for ArrayList as it's limited > by MAX_ARRAY_SIZE which is Integer.MAX_VALUE - 8. Actually, the limit is Integer.MAX_VALUE. But

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2016-02-01 Thread Ivan Gerasimov
Thanks Tagir for the comments! On 02.02.2016 9:19, Tagir F. Valeev wrote: Hello! IG> It's misfortune that the spec of subList() doesn't match the spec of IG> similar methods, like CharSequence.subSequence() or String.substring(). IG> It even contradicts the spec of List.subList(), which declar

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2016-02-01 Thread Tagir F. Valeev
Hello! IG> It's misfortune that the spec of subList() doesn't match the spec of IG> similar methods, like CharSequence.subSequence() or String.substring(). IG> It even contradicts the spec of List.subList(), which declares only IOOB IG> to be thrown! Yes, it's a pity. Isn't it the reason to chang

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2016-01-29 Thread Ivan Gerasimov
Thank you Tagir for the review! On 29.01.2016 7:16, Tagir F. Valeev wrote: Hello! AbstractList::subListRangeCheck could be replaced with new Objects::checkFromToIndex for consistency with other methods. Also Yes, that would be good. However, for AbstractList.subList() we have this in spec:

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2016-01-28 Thread Tagir F. Valeev
Hello! AbstractList::subListRangeCheck could be replaced with new Objects::checkFromToIndex for consistency with other methods. Also AbstractList::rangeCheck could be replaced with Obejcts::checkIndex. The same for ArrayList class. Otherwise looks good to me. With best regards, Tagir Valeev. IG

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2016-01-28 Thread Ivan Gerasimov
Hello everyone! I'd like to respin the discussion. The previous attempt can be found here: http://mail.openjdk.java.net/pipermail/core-libs-dev/2015-May/033159.html BUGURL: https://bugs.openjdk.java.net/browse/JDK-8079136 WEBREV: http://cr.openjdk.java.net/~igerasim/8079136/05/webrev/ Here's th

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-09 Thread Peter Levart
Hi, On 05/09/2015 04:36 PM, Ivan Gerasimov wrote: On 09.05.2015 14:15, Doug Lea wrote: On 05/08/2015 02:17 PM, Ivan Gerasimov wrote: The spec says "The returned list is backed by this list" and "The subclass's set(int, E), get(int), add(int, E), remove(int), addAll(int, Collection) and remo

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-09 Thread Ivan Gerasimov
On 09.05.2015 14:15, Doug Lea wrote: On 05/08/2015 02:17 PM, Ivan Gerasimov wrote: The spec says "The returned list is backed by this list" and "The subclass's set(int, E), get(int), add(int, E), remove(int), addAll(int, Collection) and removeRange(int, int) methods all delegate to the corr

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-09 Thread Doug Lea
On 05/08/2015 02:17 PM, Ivan Gerasimov wrote: The spec says "The returned list is backed by this list" and "The subclass's set(int, E), get(int), add(int, E), remove(int), addAll(int, Collection) and removeRange(int, int) methods all delegate to the corresponding methods on the backing abstract

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-08 Thread Ivan Gerasimov
Thank you Doug for your comments! On 08.05.2015 20:10, Doug Lea wrote: On 05/08/2015 10:49 AM, Ivan Gerasimov wrote: I believe that they also break the AbstractList.subList spec. http://docs.oracle.com/javase/8/docs/api/java/util/AbstractList.html#subList-int-int- I think that the propos

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-08 Thread Doug Lea
On 05/08/2015 10:49 AM, Ivan Gerasimov wrote: I believe that they also break the AbstractList.subList spec. http://docs.oracle.com/javase/8/docs/api/java/util/AbstractList.html#subList-int-int- I think that the proposed fix formally conforms to the spec. That would surprise me. The spec say

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-08 Thread Ivan Gerasimov
On 08.05.2015 1:26, Martin Buchholz wrote: On Thu, May 7, 2015 at 12:23 PM, Doug Lea wrote: It would be possible (and easy) to create a specialization for the java.util.Arrays.ArrayList class (i.e., the kind returned by Arrays.asList(a).subList), which would also fix the SOE problem in this p

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-08 Thread Ivan Gerasimov
Hi Doug! On 07.05.2015 22:23, Doug Lea wrote: On 05/06/2015 07:23 PM, Martin Buchholz wrote: Hi Ivan, I'm afraid of these changes - they are hard to review. I believe that they also break the AbstractList.subList spec. http://docs.oracle.com/javase/8/docs/api/java/util/AbstractList.html#sub

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-07 Thread Martin Buchholz
On Thu, May 7, 2015 at 3:07 PM, Martin Buchholz wrote: > >>> if ((fromIndex < 0) | (toIndex > size) | (fromIndex > toIndex)) >>> slowpath(); >>> >>> Yeah, the refined proposal would be if ((fromIndex | (size - toIndex) | (toIndex - fromIndex)) < 0) slowpath(); considering that here performance

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-07 Thread Martin Buchholz
On Thu, May 7, 2015 at 12:23 PM, Doug Lea wrote: > > It would be possible (and easy) to create a specialization for the > java.util.Arrays.ArrayList class (i.e., the kind returned by > Arrays.asList(a).subList), which would also fix the SOE problem > in this particular case. It seems it would be

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-07 Thread Martin Buchholz
On Thu, May 7, 2015 at 9:18 AM, Ivan Gerasimov wrote: > > --- >> >> I would make modCount an argument to updateSizeAndModCount. >> >> I did that initially, but later realized that this argument should never > be different from root.modCount. > > Sure, but you'd keep it in a local variable in th

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-07 Thread Pavel Rappo
Hi Doug, > The reason that flattened forms were not used is that each > layer does not in general know the class of its parent. Could you please explain this a bit more? I'm afraid I don't quite understand how this is possible. Thanks. -Pavel

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-07 Thread Doug Lea
On 05/06/2015 07:23 PM, Martin Buchholz wrote: Hi Ivan, I'm afraid of these changes - they are hard to review. I believe that they also break the AbstractList.subList spec. http://docs.oracle.com/javase/8/docs/api/java/util/AbstractList.html#subList-int-int- The reason that flattened forms w

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-07 Thread Ivan Gerasimov
Hi Martin! I'm afraid of these changes - they are hard to review. Can't we fix the SOE with a relatively small change to ArrayList.SubList methods that recursively invoke parent methods to use iteration instead, i.e. can't you implement updateSizeAndModCount in the existing SubList class?

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-07 Thread Paul Sandoz
On May 7, 2015, at 1:23 AM, Martin Buchholz wrote: > Hi Ivan, > > I'm afraid of these changes - they are hard to review. > > Can't we fix the SOE with a relatively small change to ArrayList.SubList > methods that recursively invoke parent methods to use iteration instead, Since all that woul

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-06 Thread Martin Buchholz
Hi Ivan, I'm afraid of these changes - they are hard to review. Can't we fix the SOE with a relatively small change to ArrayList.SubList methods that recursively invoke parent methods to use iteration instead, i.e. can't you implement updateSizeAndModCount in the existing SubList class? --- I w

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-06 Thread Ivan Gerasimov
And here's another update: WEBREV: http://cr.openjdk.java.net/~igerasim/8079136/2/webrev/ This is cleaner. For extra bonus test points you could add singleton-list, checked wrappers, and synchronized list wrappers to the test set. Done. I also added a simple implementation of AbstractList,

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-06 Thread Daniel Fuchs
On 06/05/15 16:47, Paul Sandoz wrote: n May 6, 2015, at 4:08 PM, Ivan Gerasimov wrote: >Hello everyone! > >Here's the second iteration of the fix. > >BUGURL:https://bugs.openjdk.java.net/browse/JDK-8079136 >WEBREV:http://cr.openjdk.java.net/~igerasim/8079136/1/webrev/ > This is cleaner. For

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-06 Thread Paul Sandoz
On May 6, 2015, at 4:08 PM, Ivan Gerasimov wrote: > Hello everyone! > > Here's the second iteration of the fix. > > BUGURL: https://bugs.openjdk.java.net/browse/JDK-8079136 > WEBREV: http://cr.openjdk.java.net/~igerasim/8079136/1/webrev/ > This is cleaner. For extra bonus test points you co

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-06 Thread Ivan Gerasimov
Hi Pavel! It was intentional to avoid checking for co-modification for every pair of list-sublist in the chain. It's surely enough to only compare modCount of the root and the sublist we're dealing with. However, I didn't notice that SubList.size() had not checked for comodifications recursi

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-06 Thread Ivan Gerasimov
Hello everyone! Here's the second iteration of the fix. BUGURL: https://bugs.openjdk.java.net/browse/JDK-8079136 WEBREV: http://cr.openjdk.java.net/~igerasim/8079136/1/webrev/ I changed all the sub-list classes to be non internal, but standalone. I think the logic become more obvious now. Arra

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-06 Thread Pavel Rappo
Ivan, It looks like your change (I don't know whether it was intentional or not) brings some more "fail-fast"-ness which is good! For instance, before the change, this snippet: List integers = new LinkedList<>(); integers.addAll(Arrays.asList(0, 1)); List sublist = integers.subList(0

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-05 Thread Martin Buchholz
The problem of deep nesting of sublists was known to previous generations of ArrayList maintainers. We got discouraged because there is no known way to make operations that are O(1) on the full list also O(1) on subsub...sublists. It's especially a performance problem when you use ArrayLists with

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-05 Thread Ivan Gerasimov
Thanks Louis for looking at this! Removing an element from a sub-sublist is done as: 549 public E remove(int index) { 550 rangeCheck(index); 551 checkForComodification(); 552 E result = AbstractList.this.remove(index + offset); 553 upda

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-05 Thread Louis Wasserman
Just checking -- IIRC, this will change the semantics of how structural modifications to a subList of a subList will affect the first subList. For example, I believe in the past, removing an element from a subList of a subList would decrease the size of the first subList by 1, but now the first su

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-05 Thread Ivan Gerasimov
Hi Paul On 05.05.2015 19:56, Paul Sandoz wrote: Hi Ivan, ArrayList -- You can simplify SubList with: private final class SubList extends AbstractList implements RandomAccess { private final SubList parent; private final int offset; int size; // Top level sub-list Sub

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-05 Thread Paul Sandoz
Hi Ivan, ArrayList -- You can simplify SubList with: private final class SubList extends AbstractList implements RandomAccess { private final SubList parent; private final int offset; int size; // Top level sub-list SubList(int offset, int fromIndex, int toIndex) { t

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-05 Thread Daniel Fuchs
Hi Ivan, On 05/05/15 14:55, Ivan Gerasimov wrote: I converted the SubList into an inner class to make the implementations for AbstractList.SubList and ArrayList.SubList similar. It might be not worth doing so, but I thought it would be easier to maintain those classes, if they have similar struc

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-05 Thread Ivan Gerasimov
On 05.05.2015 13:23, Daniel Fuchs wrote: On 05/05/15 10:58, Ivan Gerasimov wrote: Thank you Daniel for taking look at it! On 05.05.2015 11:14, Daniel Fuchs wrote: Hi Ivan, Have you considered to simply override/change subList(int fromIndex, int toIndex) in SubList and RandomAccessSubList -

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-05 Thread Daniel Fuchs
On 05/05/15 10:58, Ivan Gerasimov wrote: Thank you Daniel for taking look at it! On 05.05.2015 11:14, Daniel Fuchs wrote: Hi Ivan, Have you considered to simply override/change subList(int fromIndex, int toIndex) in SubList and RandomAccessSubList - so that 'l'/'parent' points always to the or

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-05 Thread Ivan Gerasimov
Thank you Daniel for taking look at it! On 05.05.2015 11:14, Daniel Fuchs wrote: Hi Ivan, Have you considered to simply override/change subList(int fromIndex, int toIndex) in SubList and RandomAccessSubList - so that 'l'/'parent' points always to the original root list (instead of being a su

Re: RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-05 Thread Daniel Fuchs
Hi Ivan, Have you considered to simply override/change subList(int fromIndex, int toIndex) in SubList and RandomAccessSubList - so that 'l'/'parent' points always to the original root list (instead of being a sublist of sublist of sublist)? It seems to me that overriding sublist to create a s

RFR: 8079136: Accessing a nested sublist leads to StackOverflowError

2015-05-05 Thread Ivan Gerasimov
Hello! When creating a sublist with List.subList(), it keeps a reference to its parent. Then, when accessing (get(), set(), add(), remove(), etc.) the sublist, it recursively calls the corresponding methods of its parent. This recursion, when deep enough, can cause StackOverflowError. The onl