<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
+1<br>
<br>
Code changes look good.<br>
<br>
I verified that the bug happens on my Windows 10 laptop with
SwingSet2 and with the LargeWindowPaintTest without the patch, and
everything looks good with the patch.<br>
<br>
-- Kevin<br>
<br>
<br>
<div class="moz-cite-prefix">On 6/10/2020 1:48 PM, Philip Race
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:ef45e6f4-5ce4-a8b5-dd2c-38a79ff0c327@oracle.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
Bug: <a class="moz-txt-link-freetext"
href="https://bugs.openjdk.java.net/browse/JDK-8240654"
moz-do-not-send="true">https://bugs.openjdk.java.net/browse/JDK-8240654</a><br>
Webrev: <a class="moz-txt-link-freetext"
href="http://cr.openjdk.java.net/~prr/8240654/index.html"
moz-do-not-send="true">http://cr.openjdk.java.net/~prr/8240654/index.html</a><br>
<br>
This is for JDK 15 so review ASAP please since RDP 1 and the test
cycle are looming.<br>
<br>
This is not a fix for a JDK bug. It is a bunch of workarounds for
a Microsoft Windows bug affecting<br>
GDI in the context of ZGC (<a class="moz-txt-link-freetext"
href="http://openjdk.java.net/jeps/333" moz-do-not-send="true">http://openjdk.java.net/jeps/333</a>).<br>
Some extra details about the Windows bug at the end, but first the
technical details of the fix.<br>
<br>
With ZGC's memory allocation requirement of reserving memory in
2Mb chunks some Windows GDI<br>
functions, mostly involving some bitmaps APIs may return a failure
code (ie fail!)<br>
This typically occurs when Java heap memory is used for a Java
image and then in a JNI<br>
call we use GetPrimitiveArrayCritical so that Java heap allocated
memory is passed to a GDI<br>
function AND the Java heap memory spans one of the 2Mb boundaries.
<br>
This is very easy to trigger in almost any Java UI app if the
window is of a large enough (ie typical) size.<br>
NB: if you have an Nvidia or ATI card, then you won't see it,
because the D3D pipeline doesn't<br>
call the affected method but if you have an Intel chip as do 90%
(?) of laptops you will see it.<br>
There are also several other places we found that are affected.
Printing is the other one<br>
somewhat easy to trigger. The others : custom cursors and tray
icons are less common.<br>
The painful thing here is that there is no definitive list (a list
of the known ones is below) of<br>
affected Windows GDI APIs and we are just hunting around our code
trying to see where it<br>
might be side-swiped by this bug.<br>
<br>
The basic approach in these workarounds is that for cases where
performance does not matter we now copy <br>
and for cases where performance does matter or larger amounts of
memory is involved we check if<br>
the return value of the GDI function indicates failure and then
re-try with a copy of the heap memory. <br>
Unless GDI was randomly failing already (unlikely) this should be
a no-risk solution in the high profile cases. <br>
We have done performance measurements on the important screen case
and the failures<br>
happen fast so the penalty is then in the re-try which is only if
ZGC is enabled.<br>
Always copying the memory is slower (and memcpy is the slow
operation) than an alternative approach<br>
that "knows" about the memory allocation of ZGC but this coupling
and the complexity seem like they aren't<br>
worth it since I haven't seen any visible performance consequence.
That can be revisited<br>
some day if need be, but for now we have correctness which is the
key as well as sufficient performance.<br>
<br>
I've created an automated test for the most important on-screen
case. <br>
Also a manual printing test case which invokes ZGC is provided
since there we also only<br>
conditionally copy. In the other cases we now always copy so
existing test cases should over those.<br>
<br>
There is some clean up in this fix - one completely unusedÂ
(provably so because it was #if'd out)<br>
JNI method in awt_PrintJob.cpp is removed since it had code that
looked like it needed a workaround,<br>
which would be somewhat of a waste of effort.<br>
<br>
the doPrintBand code and its callee bitsToDevice has code I think
we can remove too since<br>
I don't see how it ever gets executed (the top down case for
browserPrint == true) but<br>
I think I'll save that for a P4 follow-on since it does nothing
that would be affected by this<br>
Windows bug.<br>
<br>
One oddity is the in the printing case I observed that some times
the rendering is performed<br>
even if an error code is returned. I don't know why, but in code
we can't tell that it was actually<br>
rendered and in any case there is no harm in repeating the call
with copied memory.<br>
<br>
We are right before the JDK15 stabilisation fork and this fix
needs to go there and will<br>
but the webrev is against jdk/client simply because jdk15 does not
exist yet !<br>
<br>
Please test and review ASAP.<br>
<br>
About the bug:<br>
Microsoft has acknowleged the bug and will publish a knowledge
base article about it<br>
but a fix may show up only in a future version of Windows. Not, it
seems, any time soon.<br>
Below is a list of potentially affected GDI APIs. Per microsoft
whether it actually manifests in<br>
any specific case depends on "branching"<br>
<span style="font-family:"Courier
New",serif;color:#1F4E79"></span>
<p class="MsoNormal"><span style="font-family:"Courier
New",serif"><a
href="https://docs.microsoft.com/en-us/previous-versions/windows/desktop/wcs/checkbitmapbits"
moz-do-not-send="true">https://docs.microsoft.com/en-us/previous-versions/windows/desktop/wcs/checkbitmapbits</a></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New",serif"><a
href="https://docs.microsoft.com/en-us/previous-versions/windows/desktop/wcs/createcolortransform"
moz-do-not-send="true">https://docs.microsoft.com/en-us/previous-versions/windows/desktop/wcs/createcolortransform</a></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New",serif"><a
href="https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setdibitstodevice"
moz-do-not-send="true">https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setdibitstodevice</a></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New",serif"><a
href="https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-stretchdibits"
moz-do-not-send="true">https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-stretchdibits</a></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New",serif"><a
href="https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getbitmapbits"
moz-do-not-send="true">https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getbitmapbits</a></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New",serif"><a
href="https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createdibitmap"
moz-do-not-send="true">https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createdibitmap</a></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New",serif"><a
href="https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createdibsection"
moz-do-not-send="true">https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createdibsection</a></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New",serif"><a
href="https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-polydraw"
moz-do-not-send="true">https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-polydraw</a></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New",serif"><a
href="https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-drawescape"
moz-do-not-send="true">https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-drawescape</a></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New",serif"><a
href="https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createbitmap"
moz-do-not-send="true">https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createbitmap</a></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New",serif"><a
href="https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setbitmapbits"
moz-do-not-send="true">https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setbitmapbits</a></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New",serif"><a
href="https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getdibits"
moz-do-not-send="true">https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getdibits</a></span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New",serif"><br>
</span></p>
<p class="MsoNormal"><span style="font-family:"Courier
New",serif">-phil.<br>
</span></p>
</blockquote>
<br>
</body>
</html>