Re: Avoid stepping on page faults while writing to MappedByteBuffer

2019-03-30 Thread Gil Tene


On Saturday, March 30, 2019 at 10:17:15 AM UTC-7, Steven Stewart-Gallus 
wrote:
>
> I feel like this is just a bug in the JDK that should be patched.
>

And how would you "patch" it? Without the result being sucky performance, 
that is?

The tension is between the performance of mapped byte buffer access, and 
the wish to avoid being caught in a page fault while not at a safepoint. 
You can do one or the other "easily": either be at a safepoint on all 
buffer accesses, or don't. Being at a safepoint in e.g. every call to 
ByteBuffer.get() [in the actual memory accessing code that is susceptible 
to page faults] would certainly prevent the TTSP-due-to-page-fault 
problems. But it would also dramatically reduce the performance of loops 
with such access in them. Not only because of the need to poll for 
safepoint conditions on every access but [mostly] because many compiler 
optimizations are "hard" to do across safepoint opportunities. 
 

> Couldn't this all be solved by replacing UNSAFE.copyMemory with a call to 
> a different method that isn't a HotSpot intrinsic?
>
>
> https://hg.openjdk.java.net/jdk/jdk/file/235883996bc7/src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template#l313
>  
> 
>
> Interestingly I don't believe that copySwapMemory is an intrinsic so an 
> ugly kludge might be to use a nonnative byte order deliberately.
>

Counting on things not being intrinsified (or treated as leaf functions 
that don't need safepoints) is a dangerous practice, since anything in the 
jdk may become intrinsifed or otherwise optimized tomorrow.

But specifcially to the above, copySwapMemory (via copySwapMemory0) is 
already treated as a known leaf method 
(http://hg.openjdk.java.net/jdk/jdk/file/235883996bc7/src/hotspot/share/prims/unsafe.cpp#l1095),
 
which (among other things) means that [unlike generic JNI calls] no 
safepoints will be taken on calling it.


-- 
You received this message because you are subscribed to the Google Groups 
"mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mechanical-sympathy+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Avoid stepping on page faults while writing to MappedByteBuffer

2019-03-30 Thread Steven Stewart-Gallus
I feel like this is just a bug in the JDK that should be patched.

Couldn't this all be solved by replacing UNSAFE.copyMemory with a call to a 
different method that isn't a HotSpot intrinsic?

https://hg.openjdk.java.net/jdk/jdk/file/235883996bc7/src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template#l313

-- 
You received this message because you are subscribed to the Google Groups 
"mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mechanical-sympathy+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.