8244936: Reduce JNI overhead of accessing FileDescriptor

Reviewed-by: rriggs, alanb
This commit is contained in:
Claes Redestad 2020-05-13 22:25:14 +02:00
parent ad2afe0bf4
commit 168cdcf65d
8 changed files with 66 additions and 45 deletions

View file

@ -43,20 +43,12 @@ jlong handleGetLength(FD fd);
FD handleOpen(const char *path, int oflag, int mode);
/*
* Macros to set/get fd from the java.io.FileDescriptor. These
* macros rely on having an appropriately defined 'this' object
* within the scope in which they're used.
* If GetObjectField returns null, SET_FD will stop and GET_FD
* will simply return -1 to avoid crashing VM.
* Functions to get fd from the java.io.FileDescriptor field
* of an object. These functions rely on having an appropriately
* defined object with a FileDescriptor object at the fid offset.
* If the FD object is null, return -1 to avoid crashing VM.
*/
#define SET_FD(this, fd, fid) \
if ((*env)->GetObjectField(env, (this), (fid)) != NULL) \
(*env)->SetIntField(env, (*env)->GetObjectField(env, (this), (fid)),IO_fd_fdID, (fd))
#define GET_FD(this, fid) \
(*env)->GetObjectField(env, (this), (fid)) == NULL ? \
-1 : (*env)->GetIntField(env, (*env)->GetObjectField(env, (this), (fid)), IO_fd_fdID)
FD getFD(JNIEnv *env, jobject cur, jfieldID fid);
/*
* Macros to set/get fd when inside java.io.FileDescriptor