提交 4eae7ef8 编写于 作者: S serb

8028486: java/awt/Window/WindowsLeak/WindowsLeak.java fails

Reviewed-by: ant, prr
上级 3b71736c
/* /*
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -38,6 +38,8 @@ import static sun.java2d.pipe.BufferedOpCodes.*; ...@@ -38,6 +38,8 @@ import static sun.java2d.pipe.BufferedOpCodes.*;
import static sun.java2d.pipe.BufferedRenderPipe.BYTES_PER_SPAN; import static sun.java2d.pipe.BufferedRenderPipe.BYTES_PER_SPAN;
import java.lang.annotation.Native; import java.lang.annotation.Native;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
/** /**
* Base context class for managing state in a single-threaded rendering * Base context class for managing state in a single-threaded rendering
...@@ -87,11 +89,11 @@ public abstract class BufferedContext { ...@@ -87,11 +89,11 @@ public abstract class BufferedContext {
*/ */
protected static BufferedContext currentContext; protected static BufferedContext currentContext;
private AccelSurface validatedSrcData; private Reference<AccelSurface> validSrcDataRef = new WeakReference<>(null);
private AccelSurface validatedDstData; private Reference<AccelSurface> validDstDataRef = new WeakReference<>(null);
private Region validatedClip; private Reference<Region> validClipRef = new WeakReference<>(null);
private Composite validatedComp; private Reference<Composite> validCompRef = new WeakReference<>(null);
private Paint validatedPaint; private Reference<Paint> validPaintRef = new WeakReference<>(null);
// renamed from isValidatedPaintAColor as part of a work around for 6764257 // renamed from isValidatedPaintAColor as part of a work around for 6764257
private boolean isValidatedPaintJustAColor; private boolean isValidatedPaintJustAColor;
private int validatedRGB; private int validatedRGB;
...@@ -127,9 +129,9 @@ public abstract class BufferedContext { ...@@ -127,9 +129,9 @@ public abstract class BufferedContext {
int flags) int flags)
{ {
// assert rq.lock.isHeldByCurrentThread(); // assert rq.lock.isHeldByCurrentThread();
BufferedContext d3dc = dstData.getContext(); BufferedContext context = dstData.getContext();
d3dc.validate(srcData, dstData, context.validate(srcData, dstData,
clip, comp, xform, paint, sg2d, flags); clip, comp, xform, paint, sg2d, flags);
} }
/** /**
...@@ -200,13 +202,15 @@ public abstract class BufferedContext { ...@@ -200,13 +202,15 @@ public abstract class BufferedContext {
updatePaint = true; updatePaint = true;
isValidatedPaintJustAColor = true; isValidatedPaintJustAColor = true;
} }
} else if (validatedPaint != paint) { } else if (validPaintRef.get() != paint) {
updatePaint = true; updatePaint = true;
// this should be set when we are switching from paint to color // this should be set when we are switching from paint to color
// in which case this condition will be true // in which case this condition will be true
isValidatedPaintJustAColor = false; isValidatedPaintJustAColor = false;
} }
final AccelSurface validatedSrcData = validSrcDataRef.get();
final AccelSurface validatedDstData = validDstDataRef.get();
if ((currentContext != this) || if ((currentContext != this) ||
(srcData != validatedSrcData) || (srcData != validatedSrcData) ||
(dstData != validatedDstData)) (dstData != validatedDstData))
...@@ -228,11 +232,12 @@ public abstract class BufferedContext { ...@@ -228,11 +232,12 @@ public abstract class BufferedContext {
setSurfaces(srcData, dstData); setSurfaces(srcData, dstData);
currentContext = this; currentContext = this;
validatedSrcData = srcData; validSrcDataRef = new WeakReference<>(srcData);
validatedDstData = dstData; validDstDataRef = new WeakReference<>(dstData);
} }
// validate clip // validate clip
final Region validatedClip = validClipRef.get();
if ((clip != validatedClip) || updateClip) { if ((clip != validatedClip) || updateClip) {
if (clip != null) { if (clip != null) {
if (updateClip || if (updateClip ||
...@@ -248,13 +253,13 @@ public abstract class BufferedContext { ...@@ -248,13 +253,13 @@ public abstract class BufferedContext {
} else { } else {
resetClip(); resetClip();
} }
validatedClip = clip; validClipRef = new WeakReference<>(clip);
} }
// validate composite (note that a change in the context flags // validate composite (note that a change in the context flags
// may require us to update the composite state, even if the // may require us to update the composite state, even if the
// composite has not changed) // composite has not changed)
if ((comp != validatedComp) || (flags != validatedFlags)) { if ((comp != validCompRef.get()) || (flags != validatedFlags)) {
if (comp != null) { if (comp != null) {
setComposite(comp, flags); setComposite(comp, flags);
} else { } else {
...@@ -263,7 +268,7 @@ public abstract class BufferedContext { ...@@ -263,7 +268,7 @@ public abstract class BufferedContext {
// the paint state is dependent on the composite state, so make // the paint state is dependent on the composite state, so make
// sure we update the color below // sure we update the color below
updatePaint = true; updatePaint = true;
validatedComp = comp; validCompRef = new WeakReference<>(comp);
validatedFlags = flags; validatedFlags = flags;
} }
...@@ -297,7 +302,7 @@ public abstract class BufferedContext { ...@@ -297,7 +302,7 @@ public abstract class BufferedContext {
} else { } else {
BufferedPaints.resetPaint(rq); BufferedPaints.resetPaint(rq);
} }
validatedPaint = paint; validPaintRef = new WeakReference<>(paint);
} }
// mark dstData dirty // mark dstData dirty
...@@ -315,9 +320,9 @@ public abstract class BufferedContext { ...@@ -315,9 +320,9 @@ public abstract class BufferedContext {
* @see RenderQueue#lock * @see RenderQueue#lock
* @see RenderQueue#unlock * @see RenderQueue#unlock
*/ */
public void invalidateSurfaces() { private void invalidateSurfaces() {
validatedSrcData = null; validSrcDataRef.clear();
validatedDstData = null; validDstDataRef.clear();
} }
private void setSurfaces(AccelSurface srcData, private void setSurfaces(AccelSurface srcData,
...@@ -434,9 +439,9 @@ public abstract class BufferedContext { ...@@ -434,9 +439,9 @@ public abstract class BufferedContext {
resetClip(); resetClip();
BufferedPaints.resetPaint(rq); BufferedPaints.resetPaint(rq);
invalidateSurfaces(); invalidateSurfaces();
validatedComp = null; validCompRef.clear();
validatedClip = null; validClipRef.clear();
validatedPaint = null; validPaintRef.clear();
isValidatedPaintJustAColor = false; isValidatedPaintJustAColor = false;
xformInUse = false; xformInUse = false;
} }
......
/* /*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -23,41 +23,40 @@ ...@@ -23,41 +23,40 @@
/* /*
* @test * @test
* @bug 8013563 * @bug 8013563 8028486
* @summary Tests that windows are removed from windows list * @summary Tests that windows are removed from windows list
* @library /javax/swing/regtesthelpers
* @build Util
* @run main/othervm -Xms32M -Xmx32M WindowsLeak * @run main/othervm -Xms32M -Xmx32M WindowsLeak
*/ */
import java.awt.*; import java.awt.Frame;
import sun.awt.AppContext; import java.awt.Robot;
import java.awt.Window;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.Vector; import java.util.Vector;
import sun.awt.AppContext;
import sun.java2d.Disposer;
public class WindowsLeak { public class WindowsLeak {
public static void main(String[] args) { private static volatile boolean disposerPhantomComplete;
for (int i = 0; i < 100; i++)
{ public static void main(String[] args) throws Exception {
Robot r = new Robot();
for (int i = 0; i < 100; i++) {
Frame f = new Frame(); Frame f = new Frame();
f.pack(); f.pack();
f.dispose(); f.dispose();
} }
r.waitForIdle();
Disposer.addRecord(new Object(), () -> disposerPhantomComplete = true);
Vector garbage = new Vector(); while (!disposerPhantomComplete) {
while (true) Util.generateOOME();
{
try
{
garbage.add(new byte[1000]);
}
catch (OutOfMemoryError e)
{
break;
}
} }
garbage = null;
Vector<WeakReference<Window>> windowList = Vector<WeakReference<Window>> windowList =
(Vector<WeakReference<Window>>) AppContext.getAppContext().get(Window.class); (Vector<WeakReference<Window>>) AppContext.getAppContext().get(Window.class);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册