java.lang.OutOfMemoryError: Java heap space

JDK Bug System | Webbug Group | 4 months ago
  1. 0

    FULL PRODUCT VERSION : java version "1.8.0_112-ea" Java(TM) SE Runtime Environment (build 1.8.0_112-ea-b02) Java HotSpot(TM) 64-Bit Server VM (build 25.112-b02, mixed mode) (Happens on 1.8.0_91 and Java 9-ea too) ADDITIONAL OS VERSION INFORMATION : Linux 64-bit (Debian) A DESCRIPTION OF THE PROBLEM : Calls to Accessor.getPageFor(WebEngine).getOwnerElement(long) and Accessor.getPageFor(WebEngine).getDocument(long) leak memory (heap space) when a webpage has an image resource. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Let the attached code run for ~30-60 seconds. EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - The attached code should run indefinitely. ACTUAL - Out of memory errors occur (heap space). ERROR MESSAGES/STACK TRACES THAT OCCUR : Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space at java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:57) at java.nio.ByteBuffer.allocate(ByteBuffer.java:335) at com.sun.javafx.iio.png.PNGImageLoader2.load(PNGImageLoader2.java:652) at com.sun.javafx.iio.ImageStorage.loadAll(ImageStorage.java:364) at com.sun.javafx.iio.ImageStorage.loadAll(ImageStorage.java:274) at com.sun.javafx.webkit.prism.WCImageDecoderImpl.loadFrames(WCImageDecoderImpl.java:179) at com.sun.javafx.webkit.prism.WCImageDecoderImpl.loadFrames(WCImageDecoderImpl.java:192) at com.sun.javafx.webkit.prism.WCImageDecoderImpl.getImageFrame(WCImageDecoderImpl.java:292) at com.sun.javafx.webkit.prism.WCImageDecoderImpl.getFrame(WCImageDecoderImpl.java:251) at com.sun.webkit.WebPage.twkUpdateContent(Native Method) at com.sun.webkit.WebPage.updateDirty(WebPage.java:296) at com.sun.webkit.WebPage.updateContent(WebPage.java:615) at com.sun.javafx.sg.prism.web.NGWebView.update(NGWebView.java:74) at javafx.scene.web.WebView.handleStagePulse(WebView.java:999) at javafx.scene.web.WebView.lambda$new$29(WebView.java:280) at javafx.scene.web.WebView$$Lambda$96/451391812.pulse(Unknown Source) at com.sun.javafx.tk.Toolkit.lambda$runPulse$30(Toolkit.java:355) at com.sun.javafx.tk.Toolkit$$Lambda$154/1357067674.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.tk.Toolkit.runPulse(Toolkit.java:354) at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:378) at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:510) at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:490) at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$404(QuantumToolkit.java:319) at com.sun.javafx.tk.quantum.QuantumToolkit$$Lambda$45/183263726.run(Unknown Source) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method) at com.sun.glass.ui.gtk.GtkApplication.lambda$null$49(GtkApplication.java:139) at com.sun.glass.ui.gtk.GtkApplication$$Lambda$41/1535128843.run(Unknown Source) at java.lang.Thread.run(Thread.java:745) Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: Java heap space Exception in thread "JavaFX Application Thread" java.lang.OutOfMemoryError: GC overhead limit exceeded REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- package com.machinepublishers.jbrowserdriver.diagnostics; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.net.InetAddress; import java.net.ServerSocket; import java.net.Socket; import java.util.Base64; import com.sun.javafx.webkit.Accessor; import com.sun.webkit.LoadListenerClient; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.StackPane; import javafx.scene.web.WebEngine; import javafx.scene.web.WebView; import javafx.stage.Stage; public class SimpleWebView extends Application { private static final int PORT = 9000; @Override public void start(Stage stage) throws Exception { StackPane root = new StackPane(); WebView view = new WebView(); WebEngine engine = view.getEngine(); engine.load("http://127.0.0.1:" + PORT); root.getChildren().add(view); Accessor.getPageFor(engine).addLoadListenerClient(new LoadListenerClient() { @Override public void dispatchResourceLoadEvent(long frame, int state, String url, String contentType, double progress, int errorCode) {} @Override public void dispatchLoadEvent(long frame, int state, String url, String contentType, double progress, int errorCode) { Accessor.getPageFor(engine).getOwnerElement(frame); //leaks memory Accessor.getPageFor(engine).getDocument(frame); //also leaks memory if (state == LoadListenerClient.PAGE_FINISHED) { engine.load("http://127.0.0.1:" + PORT); } } }); Scene scene = new Scene(root, 100, 100); stage.setScene(scene); stage.show(); } public static void main(String[] args) throws IOException, InterruptedException { launchServer(PORT); Application.launch(args); } private static final byte[] indexBody; private static final byte[] indexHeaders; private static final byte[] imageBody; private static final byte[] imageHeaders; static { indexBody = "<html><head></head><body><img src=\"/image.png\"></body></html>".getBytes(); indexHeaders = headers(indexBody, "text/html"); imageBody = Base64.getDecoder().decode( "iVBORw0KGgoAAAANSUhEUgAAAyAAAAMgCAIAAABUEpE/AAAHW0lEQVR42u3BAQEAAACCIP+vbkhAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHwaUNMAAWZG6bQAAAAASUVORK5CYII="); imageHeaders = headers(imageBody, "image/png"); } private static byte[] headers(byte[] body, String contentType) { byte[] headersTmp = null; headersTmp = new String("HTTP/1.1 200 OK\n" + "Content-Type: " + contentType + "\n" + "Content-Length: " + body.length + "\n" + "Cache-Control: no-cache, no-store\n" + "Connection: close\n\n").getBytes(); return headersTmp; } public static void launchServer(int port) { new Thread(new Runnable() { @Override public void run() { try (ServerSocket serverSocket = new ServerSocket(port, Integer.MAX_VALUE, InetAddress.getByName("127.0.0.1"))) { while (true) { try (Socket socket = serverSocket.accept(); DataOutputStream output = new DataOutputStream(socket.getOutputStream()); BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()))) { for (String line; (line = reader.readLine()) != null;) { if (line.startsWith("GET / ")) { output.write(indexHeaders, 0, indexHeaders.length); output.write(indexBody, 0, indexBody.length); } else if (line.startsWith("GET /image.png")) { output.write(imageHeaders, 0, imageHeaders.length); output.write(imageBody, 0, imageBody.length); } } } } } catch (Throwable t) {} } }).start(); } } ---------- END SOURCE ----------

    JDK Bug System | 4 months ago | Webbug Group
    java.lang.OutOfMemoryError: Java heap space
  2. 0

    GitHub comment 1298#120359671

    GitHub | 1 year ago | tomikiss
    java.lang.OutOfMemoryError: Java heap space
  3. 0

    GitHub comment 1298#120398501

    GitHub | 1 year ago | tomikiss
    java.lang.OutOfMemoryError: Java heap space
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    JRakLibPlus Integration

    GitHub | 1 year ago | DefinitlyEvil
    java.lang.OutOfMemoryError: Java heap space
  6. 0

    GitHub comment 1646#78652871

    GitHub | 2 years ago | ctrueden
    java.lang.OutOfMemoryError: Java heap space

  1. rexgreenza 1 times, last 3 months ago
12 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.lang.OutOfMemoryError

    Java heap space

    at java.nio.HeapByteBuffer.<init>()
  2. Java RT
    ByteBuffer.allocate
    1. java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:57)
    2. java.nio.ByteBuffer.allocate(ByteBuffer.java:335)
    2 frames
  3. com.sun.javafx
    WCImageDecoderImpl.getFrame
    1. com.sun.javafx.iio.png.PNGImageLoader2.load(PNGImageLoader2.java:652)
    2. com.sun.javafx.iio.ImageStorage.loadAll(ImageStorage.java:364)
    3. com.sun.javafx.iio.ImageStorage.loadAll(ImageStorage.java:274)
    4. com.sun.javafx.webkit.prism.WCImageDecoderImpl.loadFrames(WCImageDecoderImpl.java:179)
    5. com.sun.javafx.webkit.prism.WCImageDecoderImpl.loadFrames(WCImageDecoderImpl.java:192)
    6. com.sun.javafx.webkit.prism.WCImageDecoderImpl.getImageFrame(WCImageDecoderImpl.java:292)
    7. com.sun.javafx.webkit.prism.WCImageDecoderImpl.getFrame(WCImageDecoderImpl.java:251)
    7 frames
  4. com.sun.webkit
    WebPage.updateContent
    1. com.sun.webkit.WebPage.twkUpdateContent(Native Method)
    2. com.sun.webkit.WebPage.updateDirty(WebPage.java:296)
    3. com.sun.webkit.WebPage.updateContent(WebPage.java:615)
    3 frames
  5. com.sun.javafx
    NGWebView.update
    1. com.sun.javafx.sg.prism.web.NGWebView.update(NGWebView.java:74)
    1 frame
  6. javafx.scene.web
    WebView.lambda$new$29
    1. javafx.scene.web.WebView.handleStagePulse(WebView.java:999)
    2. javafx.scene.web.WebView.lambda$new$29(WebView.java:280)
    2 frames