[OpenJDK 2D-Dev] Review Reqeust for Bug 100068 - SunGraphics2D exposes a reference to itself while non fully initialised

Jim Graham Jim.A.Graham at Sun.COM
Tue Jul 14 19:07:31 UTC 2009

Hi Mario,


Mario Torre wrote:
> I tried to figure out some "common" use case, so i did this (based on 
> your suggestion too), I found this combination to force the pipe to be 
> invalidated:
> BufferedImage bimg =
>     new BufferedImage(100, 100, BufferedImage.TRANSLUCENT);
> Graphics2D g = bimg.createGraphics();
> for (int i = 0; i < 100000; i++) {
>   g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
>                      RenderingHints.VALUE_ANTIALIAS_ON);
>   g.setComposite(AlphaComposite.getInstance(
>                  AlphaComposite.SRC_OVER, 0.5f));
>   g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
>                      RenderingHints.VALUE_ANTIALIAS_OFF);
>   g.setComposite(AlphaComposite.getInstance(
>                  AlphaComposite.SRC_OVER, 1.0f));
>   g.fillRect(0,0,1,1);
> }

I would set the AA hint or set the composite - one or the other - but 
not both.  Basically you are looking for the minimum action that causes 
an invalidation/revalidation cycle in order to measure the impact.  The 
more extraneous work in the inner loop, the less impact you will notice 
from any overhead the new code might have added.

> In both cases I was using debug build (as make debug_build) on an Intel 
> Core2 Duo T8300 running at full speed (2.40GHz).

I would also compare optimized to optimized as the debug build probably 
adds a bit of overhead on its own - again, which could mask any overhead 
your changes might have added.

> Maybe I should run a more scientific test, but this doesn't look too bad 
> to me :)

True - it's a nice quick check result, but to be sure it should be done 
with minimal test overhead on an optimized build...


More information about the 2d-dev mailing list