提交 12965ab5 编写于 作者: A alitvinov

8025775: JNI warnings in TryXShmAttach

Reviewed-by: art, anthony
上级 e5a0d5a6
...@@ -674,9 +674,4 @@ final public class XConstants { ...@@ -674,9 +674,4 @@ final public class XConstants {
public static final long XkbModifierMapMask = (1L<<2); public static final long XkbModifierMapMask = (1L<<2);
public static final long XkbVirtualModsMask = (1L<<6); //server map public static final long XkbVirtualModsMask = (1L<<6); //server map
/*****************************************************************
* X SHARED MEMORY EXTENSION FUNCTIONS
*****************************************************************/
public static final int X_ShmAttach = 1;
} }
...@@ -42,29 +42,6 @@ public abstract class XErrorHandler { ...@@ -42,29 +42,6 @@ public abstract class XErrorHandler {
} }
} }
/**
* This is a base synthetic error handler containing a boolean flag which allows
* to show that an error is handled or not.
*/
public static class XErrorHandlerWithFlag extends XBaseErrorHandler {
private volatile boolean errorOccurred = false;
public boolean getErrorOccurredFlag() {
return errorOccurred;
}
/**
* Sets an internal boolean flag to a particular value. Should be always called with
* <code>false</code> value of the parameter <code>errorOccurred</code> before this
* error handler is set as current.
* @param errorOccurred <code>true</code> to indicate that an error was handled,
* <code>false</code> to reset the internal boolean flag
*/
public void setErrorOccurredFlag(boolean errorOccurred) {
this.errorOccurred = errorOccurred;
}
}
/* /*
* Instead of validating window id, we simply call XGetWindowProperty, * Instead of validating window id, we simply call XGetWindowProperty,
* but temporary install this function as the error handler to ignore * but temporary install this function as the error handler to ignore
...@@ -99,51 +76,4 @@ public abstract class XErrorHandler { ...@@ -99,51 +76,4 @@ public abstract class XErrorHandler {
return theInstance; return theInstance;
} }
} }
/**
* This is a synthetic error handler for errors generated by the native function
* <code>XShmAttach</code>. If an error is handled, an internal boolean flag of the
* handler is set to <code>true</code>.
*/
public static final class XShmAttachHandler extends XErrorHandlerWithFlag {
private XShmAttachHandler() {}
@Override
public int handleError(long display, XErrorEvent err) {
if (err.get_minor_code() == XConstants.X_ShmAttach) {
setErrorOccurredFlag(true);
return 0;
}
return super.handleError(display, err);
}
// Shared instance
private static XShmAttachHandler theInstance = new XShmAttachHandler();
public static XShmAttachHandler getInstance() {
return theInstance;
}
}
/**
* This is a synthetic error handler for <code>BadAlloc</code> errors generated by the
* native <code>glX*</code> functions. Its internal boolean flag is set to <code>true</code>,
* if an error is handled.
*/
public static final class GLXBadAllocHandler extends XErrorHandlerWithFlag {
private GLXBadAllocHandler() {}
@Override
public int handleError(long display, XErrorEvent err) {
if (err.get_error_code() == XConstants.BadAlloc) {
setErrorOccurredFlag(true);
return 0;
}
return super.handleError(display, err);
}
private static GLXBadAllocHandler theInstance = new GLXBadAllocHandler();
public static GLXBadAllocHandler getInstance() {
return theInstance;
}
}
} }
...@@ -42,7 +42,7 @@ public final class XErrorHandlerUtil { ...@@ -42,7 +42,7 @@ public final class XErrorHandlerUtil {
private static long display; private static long display;
/** /**
* Error handler at the moment of <code>XErrorHandlerUtil</code> initialization. * Error handler at the moment of {@code XErrorHandlerUtil} initialization.
*/ */
private static long saved_error_handler; private static long saved_error_handler;
...@@ -63,7 +63,7 @@ public final class XErrorHandlerUtil { ...@@ -63,7 +63,7 @@ public final class XErrorHandlerUtil {
new GetBooleanAction("sun.awt.noisyerrorhandler")); new GetBooleanAction("sun.awt.noisyerrorhandler"));
/** /**
* The flag indicating that <code>init</code> was called already. * The flag indicating that {@code init} was called already.
*/ */
private static boolean initPassed; private static boolean initPassed;
...@@ -73,9 +73,9 @@ public final class XErrorHandlerUtil { ...@@ -73,9 +73,9 @@ public final class XErrorHandlerUtil {
private XErrorHandlerUtil() {} private XErrorHandlerUtil() {}
/** /**
* Sets the toolkit global error handler, stores the connection to X11 server, which * Sets the toolkit global error handler, stores the connection to X11 server,
* will be used during an error handling process. This method is called once from * which will be used during an error handling process. This method is called
* <code>awt_init_Display</code> function defined in <code>awt_GraphicsEnv.c</code> * once from {@code awt_init_Display} function defined in {@code awt_GraphicsEnv.c}
* file immediately after the connection to X11 window server is opened. * file immediately after the connection to X11 window server is opened.
* @param display the connection to X11 server which should be stored * @param display the connection to X11 server which should be stored
*/ */
...@@ -109,9 +109,9 @@ public final class XErrorHandlerUtil { ...@@ -109,9 +109,9 @@ public final class XErrorHandlerUtil {
} }
private static void RESTORE_XERROR_HANDLER(boolean doXSync) { private static void RESTORE_XERROR_HANDLER(boolean doXSync) {
if (doXSync) {
// Wait until all requests are processed by the X server // Wait until all requests are processed by the X server
// and only then uninstall the error handler. // and only then uninstall the error handler.
if (doXSync) {
XSync(); XSync();
} }
current_error_handler = null; current_error_handler = null;
......
...@@ -906,6 +906,20 @@ Java_sun_awt_X11GraphicsDevice_getDisplay(JNIEnv *env, jobject this) ...@@ -906,6 +906,20 @@ Java_sun_awt_X11GraphicsDevice_getDisplay(JNIEnv *env, jobject this)
static jint canUseShmExt = UNSET_MITSHM; static jint canUseShmExt = UNSET_MITSHM;
static jint canUseShmExtPixmaps = UNSET_MITSHM; static jint canUseShmExtPixmaps = UNSET_MITSHM;
static jboolean xshmAttachFailed = JNI_FALSE;
int XShmAttachXErrHandler(Display *display, XErrorEvent *xerr) {
if (xerr->minor_code == X_ShmAttach) {
xshmAttachFailed = JNI_TRUE;
}
return 0;
}
jboolean isXShmAttachFailed() {
return xshmAttachFailed;
}
void resetXShmAttachFailed() {
xshmAttachFailed = JNI_FALSE;
}
extern int mitShmPermissionMask; extern int mitShmPermissionMask;
...@@ -913,7 +927,6 @@ void TryInitMITShm(JNIEnv *env, jint *shmExt, jint *shmPixmaps) { ...@@ -913,7 +927,6 @@ void TryInitMITShm(JNIEnv *env, jint *shmExt, jint *shmPixmaps) {
XShmSegmentInfo shminfo; XShmSegmentInfo shminfo;
int XShmMajor, XShmMinor; int XShmMajor, XShmMinor;
int a, b, c; int a, b, c;
jboolean xShmAttachResult;
AWT_LOCK(); AWT_LOCK();
if (canUseShmExt != UNSET_MITSHM) { if (canUseShmExt != UNSET_MITSHM) {
...@@ -957,14 +970,21 @@ void TryInitMITShm(JNIEnv *env, jint *shmExt, jint *shmPixmaps) { ...@@ -957,14 +970,21 @@ void TryInitMITShm(JNIEnv *env, jint *shmExt, jint *shmPixmaps) {
} }
shminfo.readOnly = True; shminfo.readOnly = True;
xShmAttachResult = TryXShmAttach(env, awt_display, &shminfo); resetXShmAttachFailed();
/**
* The J2DXErrHandler handler will set xshmAttachFailed
* to JNI_TRUE if any Shm error has occured.
*/
EXEC_WITH_XERROR_HANDLER(XShmAttachXErrHandler,
XShmAttach(awt_display, &shminfo));
/** /**
* Get rid of the id now to reduce chances of leaking * Get rid of the id now to reduce chances of leaking
* system resources. * system resources.
*/ */
shmctl(shminfo.shmid, IPC_RMID, 0); shmctl(shminfo.shmid, IPC_RMID, 0);
if (xShmAttachResult == JNI_TRUE) { if (isXShmAttachFailed() == JNI_FALSE) {
canUseShmExt = CAN_USE_MITSHM; canUseShmExt = CAN_USE_MITSHM;
/* check if we can use shared pixmaps */ /* check if we can use shared pixmaps */
XShmQueryVersion(awt_display, &XShmMajor, &XShmMinor, XShmQueryVersion(awt_display, &XShmMajor, &XShmMinor,
...@@ -979,23 +999,6 @@ void TryInitMITShm(JNIEnv *env, jint *shmExt, jint *shmPixmaps) { ...@@ -979,23 +999,6 @@ void TryInitMITShm(JNIEnv *env, jint *shmExt, jint *shmPixmaps) {
} }
AWT_UNLOCK(); AWT_UNLOCK();
} }
/*
* Must be called with the acquired AWT lock.
*/
jboolean TryXShmAttach(JNIEnv *env, Display *display, XShmSegmentInfo *shminfo) {
jboolean errorOccurredFlag = JNI_FALSE;
jobject errorHandlerRef;
/*
* XShmAttachHandler will set its internal flag to JNI_TRUE, if any Shm error occurs.
*/
EXEC_WITH_XERROR_HANDLER(env, "sun/awt/X11/XErrorHandler$XShmAttachHandler",
"()Lsun/awt/X11/XErrorHandler$XShmAttachHandler;", JNI_TRUE,
errorHandlerRef, errorOccurredFlag,
XShmAttach(display, shminfo));
return errorOccurredFlag == JNI_FALSE ? JNI_TRUE : JNI_FALSE;
}
#endif /* MITSHM */ #endif /* MITSHM */
/* /*
......
...@@ -53,7 +53,8 @@ ...@@ -53,7 +53,8 @@
extern int XShmQueryExtension(); extern int XShmQueryExtension();
void TryInitMITShm(JNIEnv *env, jint *shmExt, jint *shmPixmaps); void TryInitMITShm(JNIEnv *env, jint *shmExt, jint *shmPixmaps);
jboolean TryXShmAttach(JNIEnv *env, Display *display, XShmSegmentInfo *shminfo); void resetXShmAttachFailed();
jboolean isXShmAttachFailed();
#endif /* MITSHM */ #endif /* MITSHM */
......
...@@ -41,6 +41,11 @@ ...@@ -41,6 +41,11 @@
#include "java_awt_event_MouseWheelEvent.h" #include "java_awt_event_MouseWheelEvent.h"
/*
* Called by "ToolkitErrorHandler" function in "XlibWrapper.c" file.
*/
XErrorHandler current_native_xerror_handler = NULL;
extern jint getModifiers(uint32_t state, jint button, jint keyCode); extern jint getModifiers(uint32_t state, jint button, jint keyCode);
extern jint getButton(uint32_t button); extern jint getButton(uint32_t button);
......
...@@ -29,57 +29,29 @@ ...@@ -29,57 +29,29 @@
#ifndef HEADLESS #ifndef HEADLESS
#include "gdefs.h" #include "gdefs.h"
/* #define WITH_XERROR_HANDLER(f) do { \
* Expected types of arguments of the macro. XSync(awt_display, False); \
* (JNIEnv*, const char*, const char*, jboolean, jobject) current_native_xerror_handler = (f); \
*/
#define WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature, \
handlerHasFlag, handlerRef) do { \
handlerRef = JNU_CallStaticMethodByName(env, NULL, handlerClassName, "getInstance", \
getInstanceSignature).l; \
if (handlerHasFlag == JNI_TRUE) { \
JNU_CallMethodByName(env, NULL, handlerRef, "setErrorOccurredFlag", "(Z)V", JNI_FALSE); \
} \
JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil", "WITH_XERROR_HANDLER", \
"(Lsun/awt/X11/XErrorHandler;)V", handlerRef); \
} while (0) } while (0)
/* #define RESTORE_XERROR_HANDLER do { \
* Expected types of arguments of the macro. XSync(awt_display, False); \
* (JNIEnv*, jboolean) current_native_xerror_handler = NULL; \
*/
#define RESTORE_XERROR_HANDLER(env, doXSync) do { \
JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil", \
"RESTORE_XERROR_HANDLER", "(Z)V", doXSync); \
} while (0) } while (0)
/* #define EXEC_WITH_XERROR_HANDLER(f, code) do { \
* Expected types of arguments of the macro. WITH_XERROR_HANDLER(f); \
* (JNIEnv*, const char*, const char*, jboolean, jobject, jboolean, No type - C expression)
*/
#define EXEC_WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature, handlerHasFlag, \
handlerRef, errorOccurredFlag, code) do { \
handlerRef = NULL; \
WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature, handlerHasFlag, handlerRef); \
do { \ do { \
code; \ code; \
} while (0); \ } while (0); \
RESTORE_XERROR_HANDLER(env, JNI_TRUE); \ RESTORE_XERROR_HANDLER; \
if (handlerHasFlag == JNI_TRUE) { \
GET_HANDLER_ERROR_OCCURRED_FLAG(env, handlerRef, errorOccurredFlag); \
} \
} while (0) } while (0)
/* /*
* Expected types of arguments of the macro. * Called by "ToolkitErrorHandler" function in "XlibWrapper.c" file.
* (JNIEnv*, jobject, jboolean)
*/ */
#define GET_HANDLER_ERROR_OCCURRED_FLAG(env, handlerRef, errorOccurredFlag) do { \ extern XErrorHandler current_native_xerror_handler;
if (handlerRef != NULL) { \
errorOccurredFlag = JNU_CallMethodByName(env, NULL, handlerRef, "getErrorOccurredFlag", \
"()Z").z; \
} \
} while (0)
#endif /* !HEADLESS */ #endif /* !HEADLESS */
#ifndef INTERSECTS #ifndef INTERSECTS
......
...@@ -48,6 +48,8 @@ extern DisposeFunc OGLSD_Dispose; ...@@ -48,6 +48,8 @@ extern DisposeFunc OGLSD_Dispose;
extern void extern void
OGLSD_SetNativeDimensions(JNIEnv *env, OGLSDOps *oglsdo, jint w, jint h); OGLSD_SetNativeDimensions(JNIEnv *env, OGLSDOps *oglsdo, jint w, jint h);
jboolean surfaceCreationFailed = JNI_FALSE;
#endif /* !HEADLESS */ #endif /* !HEADLESS */
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
...@@ -347,6 +349,15 @@ OGLSD_InitOGLWindow(JNIEnv *env, OGLSDOps *oglsdo) ...@@ -347,6 +349,15 @@ OGLSD_InitOGLWindow(JNIEnv *env, OGLSDOps *oglsdo)
return JNI_TRUE; return JNI_TRUE;
} }
static int
GLXSD_BadAllocXErrHandler(Display *display, XErrorEvent *xerr)
{
if (xerr->error_code == BadAlloc) {
surfaceCreationFailed = JNI_TRUE;
}
return 0;
}
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_sun_java2d_opengl_GLXSurfaceData_initPbuffer Java_sun_java2d_opengl_GLXSurfaceData_initPbuffer
(JNIEnv *env, jobject glxsd, (JNIEnv *env, jobject glxsd,
...@@ -362,8 +373,6 @@ Java_sun_java2d_opengl_GLXSurfaceData_initPbuffer ...@@ -362,8 +373,6 @@ Java_sun_java2d_opengl_GLXSurfaceData_initPbuffer
int attrlist[] = {GLX_PBUFFER_WIDTH, 0, int attrlist[] = {GLX_PBUFFER_WIDTH, 0,
GLX_PBUFFER_HEIGHT, 0, GLX_PBUFFER_HEIGHT, 0,
GLX_PRESERVED_CONTENTS, GL_FALSE, 0}; GLX_PRESERVED_CONTENTS, GL_FALSE, 0};
jboolean errorOccurredFlag;
jobject errorHandlerRef;
J2dTraceLn3(J2D_TRACE_INFO, J2dTraceLn3(J2D_TRACE_INFO,
"GLXSurfaceData_initPbuffer: w=%d h=%d opq=%d", "GLXSurfaceData_initPbuffer: w=%d h=%d opq=%d",
...@@ -391,15 +400,12 @@ Java_sun_java2d_opengl_GLXSurfaceData_initPbuffer ...@@ -391,15 +400,12 @@ Java_sun_java2d_opengl_GLXSurfaceData_initPbuffer
attrlist[1] = width; attrlist[1] = width;
attrlist[3] = height; attrlist[3] = height;
errorOccurredFlag = JNI_FALSE; surfaceCreationFailed = JNI_FALSE;
WITH_XERROR_HANDLER(env, "sun/awt/X11/XErrorHandler$GLXBadAllocHandler", EXEC_WITH_XERROR_HANDLER(
"()Lsun/awt/X11/XErrorHandler$GLXBadAllocHandler;", JNI_TRUE, errorHandlerRef); GLXSD_BadAllocXErrHandler,
pbuffer = j2d_glXCreatePbuffer(awt_display, glxinfo->fbconfig, attrlist); pbuffer = j2d_glXCreatePbuffer(awt_display,
XSync(awt_display, False); glxinfo->fbconfig, attrlist));
RESTORE_XERROR_HANDLER(env, JNI_FALSE); if ((pbuffer == 0) || surfaceCreationFailed) {
GET_HANDLER_ERROR_OCCURRED_FLAG(env, errorHandlerRef, errorOccurredFlag);
if ((pbuffer == 0) || errorOccurredFlag) {
J2dRlsTraceLn(J2D_TRACE_ERROR, J2dRlsTraceLn(J2D_TRACE_ERROR,
"GLXSurfaceData_initPbuffer: could not create glx pbuffer"); "GLXSurfaceData_initPbuffer: could not create glx pbuffer");
return JNI_FALSE; return JNI_FALSE;
......
...@@ -65,6 +65,7 @@ static UnlockFunc X11SD_Unlock; ...@@ -65,6 +65,7 @@ static UnlockFunc X11SD_Unlock;
static DisposeFunc X11SD_Dispose; static DisposeFunc X11SD_Dispose;
static GetPixmapBgFunc X11SD_GetPixmapWithBg; static GetPixmapBgFunc X11SD_GetPixmapWithBg;
static ReleasePixmapBgFunc X11SD_ReleasePixmapWithBg; static ReleasePixmapBgFunc X11SD_ReleasePixmapWithBg;
extern int XShmAttachXErrHandler(Display *display, XErrorEvent *xerr);
extern AwtGraphicsConfigDataPtr extern AwtGraphicsConfigDataPtr
getGraphicsConfigFromComponentPeer(JNIEnv *env, jobject this); getGraphicsConfigFromComponentPeer(JNIEnv *env, jobject this);
extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs; extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
...@@ -532,8 +533,6 @@ XImage* X11SD_CreateSharedImage(X11SDOps *xsdo, ...@@ -532,8 +533,6 @@ XImage* X11SD_CreateSharedImage(X11SDOps *xsdo,
{ {
XImage *img = NULL; XImage *img = NULL;
XShmSegmentInfo *shminfo; XShmSegmentInfo *shminfo;
JNIEnv* env;
jboolean xShmAttachResult;
shminfo = malloc(sizeof(XShmSegmentInfo)); shminfo = malloc(sizeof(XShmSegmentInfo));
if (shminfo == NULL) { if (shminfo == NULL) {
...@@ -573,8 +572,9 @@ XImage* X11SD_CreateSharedImage(X11SDOps *xsdo, ...@@ -573,8 +572,9 @@ XImage* X11SD_CreateSharedImage(X11SDOps *xsdo,
shminfo->readOnly = False; shminfo->readOnly = False;
env = (JNIEnv*)JNU_GetEnv(jvm, JNI_VERSION_1_2); resetXShmAttachFailed();
xShmAttachResult = TryXShmAttach(env, awt_display, shminfo); EXEC_WITH_XERROR_HANDLER(XShmAttachXErrHandler,
XShmAttach(awt_display, shminfo));
/* /*
* Once the XSync round trip has finished then we * Once the XSync round trip has finished then we
...@@ -583,7 +583,7 @@ XImage* X11SD_CreateSharedImage(X11SDOps *xsdo, ...@@ -583,7 +583,7 @@ XImage* X11SD_CreateSharedImage(X11SDOps *xsdo,
*/ */
shmctl(shminfo->shmid, IPC_RMID, 0); shmctl(shminfo->shmid, IPC_RMID, 0);
if (xShmAttachResult == JNI_FALSE) { if (isXShmAttachFailed() == JNI_TRUE) {
J2dRlsTraceLn1(J2D_TRACE_ERROR, J2dRlsTraceLn1(J2D_TRACE_ERROR,
"X11SD_SetupSharedSegment XShmAttach has failed: %s", "X11SD_SetupSharedSegment XShmAttach has failed: %s",
strerror(errno)); strerror(errno));
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include <sizecalc.h> #include <sizecalc.h>
#include <awt.h> #include <awt.h>
#include <awt_util.h>
#include <jvm.h> #include <jvm.h>
#include <Region.h> #include <Region.h>
...@@ -1266,6 +1267,10 @@ JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_IsKanaKeyboard ...@@ -1266,6 +1267,10 @@ JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XlibWrapper_IsKanaKeyboard
JavaVM* jvm = NULL; JavaVM* jvm = NULL;
static int ToolkitErrorHandler(Display * dpy, XErrorEvent * event) { static int ToolkitErrorHandler(Display * dpy, XErrorEvent * event) {
JNIEnv * env; JNIEnv * env;
// First call the native synthetic error handler declared in "awt_util.h" file.
if (current_native_xerror_handler != NULL) {
current_native_xerror_handler(dpy, event);
}
if (jvm != NULL) { if (jvm != NULL) {
env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
if (env) { if (env) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册