javafxports / openjdk-jfx

The openjfx repo has moved to:
https://github.com/openjdk/jfx
GNU General Public License v2.0
1.01k stars 145 forks source link

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

Open leehimchan opened 5 years ago

leehimchan commented 5 years ago

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

kevinrushforth commented 5 years ago

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.

leehimchan commented 5 years ago

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

kevinrushforth commented 5 years ago

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

kevinrushforth commented 5 years ago

@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 commented 5 years ago

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?

leehimchan commented 5 years ago

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

kevinrushforth commented 5 years ago

I'll give that a try, thanks.