Do not use GetPrimitiveArrayCritical(...) due multiple not-fixed bugs…#8921
Do not use GetPrimitiveArrayCritical(...) due multiple not-fixed bugs…#8921normanmaurer merged 2 commits into4.1from
Conversation
| int netty_unix_socket_initSockaddr(JNIEnv* env, jbyteArray address, jint scopeId, jint jport, | ||
| const struct sockaddr_storage* addr, socklen_t* addrSize) { | ||
| uint16_t port = htons((uint16_t) jport); | ||
| // 24 is the maximum possible |
There was a problem hiding this comment.
128 bit (16 byte) for IPv6 address plus long port 64 bit (8 byte)?
There was a problem hiding this comment.
actually we only need 16 here, so I changed it and added a comment. Good catch!
… related to GCLocker Motivation: GetPrimitiveArrayCritical(...) may cause multiple not-fixed bugs related to the GCLocker while there is little gain for our use-case. We should just use GetByteArrayRegion(...) and copy into a small on-stack buffer. See also: - https://shipilev.net/jvm/anatomy-quarks/9-jni-critical-gclocker/#_g1 - https://bugs.openjdk.java.net/browse/JDK-8048556 - https://bugs.openjdk.java.net/browse/JDK-8057573 - https://bugs.openjdk.java.net/browse/JDK-8057586 Special thanks to @jayv @shipilev @apangin for the pointers. Modifications: Replace GetPrimitiveArrayCritical(...) with GetByteArrayRegion(...) Result: Less risks hitting GCLocker related bugs.
|
@netty-bot test this please |
| // https://bugs.openjdk.java.net/browse/JDK-8048556 | ||
| // https://bugs.openjdk.java.net/browse/JDK-8057573 | ||
| // https://bugs.openjdk.java.net/browse/JDK-8057586 | ||
| (*env)->GetByteArrayRegion(env, address, 0, len, addressBytes); |
There was a problem hiding this comment.
Seems we should do min(len, 16) or have an assert. Yes, we know it should be 16 or less, but I don't like playing with fire.
There was a problem hiding this comment.
Or just 16? The code which reads the array below assumes that's always the case.
There was a problem hiding this comment.
let me just add a guard for now... can't hurt.
| netty_unix_errors_throwOutOfMemoryError(env); | ||
| int len = (*env)->GetArrayLength(env, address); | ||
|
|
||
| if (len > 16) { |
There was a problem hiding this comment.
I think it should be != 16 or it's potentially going to segfault..
#8921) * Do not use GetPrimitiveArrayCritical(...) due multiple not-fixed bugs related to GCLocker Motivation: GetPrimitiveArrayCritical(...) may cause multiple not-fixed bugs related to the GCLocker while there is little gain for our use-case. We should just use GetByteArrayRegion(...) and copy into a small on-stack buffer. See also: - https://shipilev.net/jvm/anatomy-quarks/9-jni-critical-gclocker/#_g1 - https://bugs.openjdk.java.net/browse/JDK-8048556 - https://bugs.openjdk.java.net/browse/JDK-8057573 - https://bugs.openjdk.java.net/browse/JDK-8057586 Special thanks to @jayv @shipilev @apangin for the pointers. Modifications: Replace GetPrimitiveArrayCritical(...) with GetByteArrayRegion(...) Result: Less risks hitting GCLocker related bugs.
|
I hope G1 Region Pinning in JDK may help eliminate or alleviate this problem in the future. |
… related to GCLocker
Motivation:
GetPrimitiveArrayCritical(...) may cause multiple not-fixed bugs related to the GCLocker while there is little gain for our use-case. We should just use GetByteArrayRegion(...) and copy into a small on-stack buffer.
See also:
Special thanks to @jayv @shipilev @apangin for the pointers.
Modifications:
Replace GetPrimitiveArrayCritical(...) with GetByteArrayRegion(...)