openjdk-jfx icon indicating copy to clipboard operation
openjdk-jfx copied to clipboard

JDK-8228358: Array Size is getting bigger in VirtualFlow.ArrayLinkedList

Open leehimchan opened this issue 6 years ago • 7 comments
trafficstars

I'd like to open bug, about ArrayLinkedList's array size. When moving focus in Listview automatically, click scroll and moving scroll. Then array size is getting bigger and make OOM

public void initialize(URL location, ResourceBundle resources) {

    try {
        final List<TimeZone> timeZones = Stream.of(TimeZone.getAvailableIDs())
            .map(TimeZone::getTimeZone)
            .collect(toList());
        fxList.getItems().addAll(timeZones.stream().map(x -> x.getID() + " - " + x.getDisplayName()).collect(toList()));

        final Field getVirtualFlow = Parent.class.getDeclaredField("top");
        getVirtualFlow.setAccessible(true);
        final Field getPile = VirtualFlow.class.getDeclaredField("pile");
        getPile.setAccessible(true);
        final Field getArray = VirtualFlow.ArrayLinkedList.class.getDeclaredField("array");
        getArray.setAccessible(true);


        final Random random = new Random();

        final Thread thread = new Thread(() -> {
            try {
                VirtualFlow virtualFlow;
                do {
                    sleep(100);
                    virtualFlow = (VirtualFlow) getVirtualFlow.get(fxList);
                } while (virtualFlow == null);
                final VirtualFlow.ArrayLinkedList pile = (VirtualFlow.ArrayLinkedList) getPile.get(virtualFlow);
                final ArrayList<?> array = (ArrayList<?>) getArray.get(pile);

                while (true) {
                    sleep(50);
                    final int index;
                    index = random.nextInt(fxList.getItems().size());
                    Platform.runLater(() -> {
                        fxList.scrollTo(index);
                        fxList.getSelectionModel().select(index);
                        fxItems.setText("items : " + fxList.getItems().size());
                        fxPile.setText("piles : " + pile.size());
                        fxArray.setText("array : " + array.size());
                    });
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        thread.setDaemon(true);
        thread.start();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

test-javafx-virtualflow-pile-leak.zip

leehimchan avatar Jul 17 '19 02:07 leehimchan

If you have a test case that reproduces this, please file a bug at bugreport.java.com/? We will need a small, self-contained test program, not an executable jar file with a number of dependencies. You can refer to this GitHub issue in your submission.

kevinrushforth avatar Jul 17 '19 12:07 kevinrushforth

test-javafx-virtualflow-pile-leak.zip I attache source file, please check it.

leehimchan avatar Jul 18 '19 06:07 leehimchan

JBS bug: https://bugs.openjdk.java.net/browse/JDK-8228358

kevinrushforth avatar Jul 18 '19 15:07 kevinrushforth

@leehimchan Can you please provide a test program that does not use any internal API (meaning no reference to any com.sun.javafx classes and no calls to setAccessible). The attached program doesn't compile on the latest version of openjfx, since VirtualFlow is public API as of FX 9.

kevinrushforth avatar Jul 18 '19 16:07 kevinrushforth

After commenting out the calls to VirtualFlow (the test program was using internal API from FX 8), which were being used to instrument the code to see the size of pile.array, I was able to get the test program running.

I ran it for several minutes and see no evidence of a leak. What I do see when I instrument the JavaFX runtime itself is that the array grows to fit the maximum needed at any one time, but it doesn't keep growing. In my case, I saw the single array grow from 50 to 75 over time and then stay there. Maybe on a faster system, with more updates prior to clearing it, I could see it grow farther. How high are you seeing it get?

kevinrushforth avatar Jul 18 '19 17:07 kevinrushforth

20190722_095338.zip I attached video file that I reproduced the situation. When moving focus, click scroll bar and move scroll.

leehimchan avatar Jul 22 '19 01:07 leehimchan

I'll give that a try, thanks.

kevinrushforth avatar Jul 27 '19 12:07 kevinrushforth