Skip to content

Commit 145c511

Browse files
committed
8146238: [macosx] Java2D Queue Flusher crash on OSX after switching between user accounts
Reviewed-by: prr, avu
1 parent 672ec6f commit 145c511

File tree

9 files changed

+75
-114
lines changed

9 files changed

+75
-114
lines changed

src/java.desktop/macosx/classes/sun/java2d/opengl/CGLSurfaceData.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -48,8 +48,9 @@ public abstract class CGLSurfaceData extends OGLSurfaceData {
4848

4949
native void validate(int xoff, int yoff, int width, int height, boolean isOpaque);
5050

51-
private native void initOps(long pConfigInfo, long pPeerData, long layerPtr,
52-
int xoff, int yoff, boolean isOpaque);
51+
private native void initOps(OGLGraphicsConfig gc, long pConfigInfo,
52+
long pPeerData, long layerPtr, int xoff,
53+
int yoff, boolean isOpaque);
5354

5455
protected CGLSurfaceData(CGLGraphicsConfig gc, ColorModel cm, int type,
5556
int width, int height) {
@@ -74,7 +75,7 @@ protected CGLSurfaceData(CPlatformView pView, CGLGraphicsConfig gc,
7475
pPeerData = pView.getAWTView();
7576
isOpaque = pView.isOpaque();
7677
}
77-
initOps(pConfigInfo, pPeerData, 0, 0, 0, isOpaque);
78+
initOps(gc, pConfigInfo, pPeerData, 0, 0, 0, isOpaque);
7879
}
7980

8081
protected CGLSurfaceData(CGLLayer layer, CGLGraphicsConfig gc,
@@ -90,7 +91,7 @@ protected CGLSurfaceData(CGLLayer layer, CGLGraphicsConfig gc,
9091
layerPtr = layer.getPointer();
9192
isOpaque = layer.isOpaque();
9293
}
93-
initOps(pConfigInfo, 0, layerPtr, 0, 0, isOpaque);
94+
initOps(gc, pConfigInfo, 0, layerPtr, 0, 0, isOpaque);
9495
}
9596

9697
@Override //SurfaceData

src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLSurfaceData.m

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -130,31 +130,6 @@ extern CGLError CGLTexImageIOSurface2D(
130130
JNF_COCOA_EXIT(env);
131131
}
132132

133-
/**
134-
* Returns a pointer (as a jlong) to the native CGLGraphicsConfigInfo
135-
* associated with the given OGLSDOps. This method can be called from
136-
* shared code to retrieve the native GraphicsConfig data in a platform-
137-
* independent manner.
138-
*/
139-
jlong
140-
OGLSD_GetNativeConfigInfo(OGLSDOps *oglsdo)
141-
{
142-
J2dTraceLn(J2D_TRACE_INFO, "OGLSD_GetNativeConfigInfo");
143-
144-
if (oglsdo == NULL) {
145-
J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLSD_GetNativeConfigInfo: ops are null");
146-
return 0L;
147-
}
148-
149-
CGLSDOps *cglsdo = (CGLSDOps *)oglsdo->privOps;
150-
if (cglsdo == NULL) {
151-
J2dRlsTraceLn(J2D_TRACE_ERROR, "OGLSD_GetNativeConfigInfo: cgl ops are null");
152-
return 0L;
153-
}
154-
155-
return ptr_to_jlong(cglsdo->configInfo);
156-
}
157-
158133
/**
159134
* Makes the given GraphicsConfig's context current to its associated
160135
* "scratch" surface. If there is a problem making the context current,
@@ -359,16 +334,30 @@ extern CGLError CGLTexImageIOSurface2D(
359334

360335
JNIEXPORT void JNICALL
361336
Java_sun_java2d_opengl_CGLSurfaceData_initOps
362-
(JNIEnv *env, jobject cglsd,
337+
(JNIEnv *env, jobject cglsd, jobject gc,
363338
jlong pConfigInfo, jlong pPeerData, jlong layerPtr,
364339
jint xoff, jint yoff, jboolean isOpaque)
365340
{
366341
J2dTraceLn(J2D_TRACE_INFO, "CGLSurfaceData_initOps");
367342
J2dTraceLn1(J2D_TRACE_INFO, " pPeerData=%p", jlong_to_ptr(pPeerData));
368343
J2dTraceLn2(J2D_TRACE_INFO, " xoff=%d, yoff=%d", (int)xoff, (int)yoff);
369344

345+
gc = (*env)->NewGlobalRef(env, gc);
346+
if (gc == NULL) {
347+
JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
348+
return;
349+
}
350+
370351
OGLSDOps *oglsdo = (OGLSDOps *)
371352
SurfaceData_InitOps(env, cglsd, sizeof(OGLSDOps));
353+
if (oglsdo == NULL) {
354+
(*env)->DeleteGlobalRef(env, gc);
355+
JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
356+
return;
357+
}
358+
// later the graphicsConfig will be used for deallocation of oglsdo
359+
oglsdo->graphicsConfig = gc;
360+
372361
CGLSDOps *cglsdo = (CGLSDOps *)malloc(sizeof(CGLSDOps));
373362
if (cglsdo == NULL) {
374363
JNU_ThrowOutOfMemoryError(env, "creating native cgl ops");

src/java.desktop/share/classes/sun/java2d/opengl/OGLSurfaceData.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import java.awt.AlphaComposite;
2929
import java.awt.Composite;
30+
import java.awt.GraphicsConfiguration;
3031
import java.awt.GraphicsEnvironment;
3132
import java.awt.Rectangle;
3233
import java.awt.Transparency;
@@ -578,16 +579,16 @@ public void flush() {
578579
* (referenced by the pData parameter). This method is invoked from
579580
* the native Dispose() method from the Disposer thread when the
580581
* Java-level OGLSurfaceData object is about to go away. Note that we
581-
* also pass a reference to the native GLX/WGLGraphicsConfigInfo
582-
* (pConfigInfo) for the purposes of making a context current.
582+
* also pass a reference to the OGLGraphicsConfig
583+
* for the purposes of making a context current.
583584
*/
584-
static void dispose(long pData, long pConfigInfo) {
585+
static void dispose(long pData, OGLGraphicsConfig gc) {
585586
OGLRenderQueue rq = OGLRenderQueue.getInstance();
586587
rq.lock();
587588
try {
588589
// make sure we have a current context before
589590
// disposing the native resources (e.g. texture object)
590-
OGLContext.setScratchSurface(pConfigInfo);
591+
OGLContext.setScratchSurface(gc);
591592

592593
RenderBuffer buf = rq.getBuffer();
593594
rq.ensureCapacityAndAlignment(12, 4);

src/java.desktop/share/native/common/java2d/opengl/OGLSurfaceData.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -37,7 +37,6 @@
3737
* The following methods are implemented in the windowing system (i.e. GLX
3838
* and WGL) source files.
3939
*/
40-
extern jlong OGLSD_GetNativeConfigInfo(OGLSDOps *oglsdo);
4140
extern jboolean OGLSD_InitOGLWindow(JNIEnv *env, OGLSDOps *oglsdo);
4241
extern void OGLSD_DestroyOGLSurface(JNIEnv *env, OGLSDOps *oglsdo);
4342

@@ -593,11 +592,14 @@ void
593592
OGLSD_Dispose(JNIEnv *env, SurfaceDataOps *ops)
594593
{
595594
OGLSDOps *oglsdo = (OGLSDOps *)ops;
596-
jlong pConfigInfo = OGLSD_GetNativeConfigInfo(oglsdo);
595+
jobject graphicsConfig = oglsdo->graphicsConfig;
597596

598597
JNU_CallStaticMethodByName(env, NULL, "sun/java2d/opengl/OGLSurfaceData",
599-
"dispose", "(JJ)V",
600-
ptr_to_jlong(ops), pConfigInfo);
598+
"dispose",
599+
"(JLsun/java2d/opengl/OGLGraphicsConfig;)V",
600+
ptr_to_jlong(ops), graphicsConfig);
601+
(*env)->DeleteGlobalRef(env, graphicsConfig);
602+
oglsdo->graphicsConfig = NULL;
601603
}
602604

603605
/**

src/java.desktop/share/native/common/java2d/opengl/OGLSurfaceData.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -85,6 +85,9 @@ typedef struct {
8585
* Pointer to native-specific (GLX, WGL, etc.) SurfaceData info, such as the
8686
* native Drawable handle and GraphicsConfig data.
8787
*
88+
* jobject graphicsConfig;;
89+
* Strong reference to the OGLGraphicsConfig used by this OGLSurfaceData.
90+
*
8891
* jint drawableType;
8992
* The surface type; can be any one of the surface type constants defined
9093
* below (OGLSD_WINDOW, OGLSD_TEXTURE, etc).
@@ -162,6 +165,7 @@ typedef struct {
162165
struct _OGLSDOps {
163166
SurfaceDataOps sdOps;
164167
void *privOps;
168+
jobject graphicsConfig;
165169
jint drawableType;
166170
GLenum activeBuffer;
167171
jboolean isOpaque;

src/java.desktop/unix/classes/sun/java2d/opengl/GLXSurfaceData.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,16 @@ public abstract class GLXSurfaceData extends OGLSurfaceData {
4040
protected X11ComponentPeer peer;
4141
private GLXGraphicsConfig graphicsConfig;
4242

43-
private native void initOps(X11ComponentPeer peer, long aData);
43+
private native void initOps(OGLGraphicsConfig gc, X11ComponentPeer peer,
44+
long aData);
4445

4546
protected GLXSurfaceData(X11ComponentPeer peer, GLXGraphicsConfig gc,
4647
ColorModel cm, int type)
4748
{
4849
super(gc, cm, type);
4950
this.peer = peer;
5051
this.graphicsConfig = gc;
51-
initOps(peer, graphicsConfig.getAData());
52+
initOps(gc, peer, graphicsConfig.getAData());
5253
}
5354

5455
public GraphicsConfiguration getDeviceConfiguration() {

src/java.desktop/unix/native/common/java2d/opengl/GLXSurfaceData.c

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -54,23 +54,32 @@ jboolean surfaceCreationFailed = JNI_FALSE;
5454

5555
JNIEXPORT void JNICALL
5656
Java_sun_java2d_opengl_GLXSurfaceData_initOps(JNIEnv *env, jobject glxsd,
57+
jobject gc,
5758
jobject peer, jlong aData)
5859
{
5960
#ifndef HEADLESS
60-
GLXSDOps *glxsdo = (GLXSDOps *)malloc(sizeof(GLXSDOps));
61-
62-
if (glxsdo == NULL) {
63-
JNU_ThrowOutOfMemoryError(env, "creating native GLX ops");
61+
gc = (*env)->NewGlobalRef(env, gc);
62+
if (gc == NULL) {
63+
JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
6464
return;
6565
}
6666

6767
OGLSDOps *oglsdo = (OGLSDOps *)SurfaceData_InitOps(env, glxsd,
6868
sizeof(OGLSDOps));
6969
if (oglsdo == NULL) {
70-
free(glxsdo);
70+
(*env)->DeleteGlobalRef(env, gc);
7171
JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
7272
return;
7373
}
74+
// later the graphicsConfig will be used for deallocation of oglsdo
75+
oglsdo->graphicsConfig = gc;
76+
77+
GLXSDOps *glxsdo = (GLXSDOps *)malloc(sizeof(GLXSDOps));
78+
79+
if (glxsdo == NULL) {
80+
JNU_ThrowOutOfMemoryError(env, "creating native GLX ops");
81+
return;
82+
}
7483

7584
J2dTraceLn(J2D_TRACE_INFO, "GLXSurfaceData_initOps");
7685

@@ -152,39 +161,6 @@ GLXSD_MakeCurrentToScratch(JNIEnv *env, OGLContext *oglc)
152161
return JNI_TRUE;
153162
}
154163

155-
/**
156-
* Returns a pointer (as a jlong) to the native GLXGraphicsConfigInfo
157-
* associated with the given OGLSDOps. This method can be called from
158-
* shared code to retrieve the native GraphicsConfig data in a platform-
159-
* independent manner.
160-
*/
161-
jlong
162-
OGLSD_GetNativeConfigInfo(OGLSDOps *oglsdo)
163-
{
164-
GLXSDOps *glxsdo;
165-
166-
if (oglsdo == NULL) {
167-
J2dRlsTraceLn(J2D_TRACE_ERROR,
168-
"OGLSD_GetNativeConfigInfo: ops are null");
169-
return 0L;
170-
}
171-
172-
glxsdo = (GLXSDOps *)oglsdo->privOps;
173-
if (glxsdo == NULL) {
174-
J2dRlsTraceLn(J2D_TRACE_ERROR,
175-
"OGLSD_GetNativeConfigInfo: glx ops are null");
176-
return 0L;
177-
}
178-
179-
if (glxsdo->configData == NULL) {
180-
J2dRlsTraceLn(J2D_TRACE_ERROR,
181-
"OGLSD_GetNativeConfigInfo: config data is null");
182-
return 0L;
183-
}
184-
185-
return ptr_to_jlong(glxsdo->configData->glxInfo);
186-
}
187-
188164
/**
189165
* Makes the given GraphicsConfig's context current to its associated
190166
* "scratch" surface. If there is a problem making the context current,

src/java.desktop/windows/classes/sun/java2d/opengl/WGLSurfaceData.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ public abstract class WGLSurfaceData extends OGLSurfaceData {
4646
protected double scaleX = 1;
4747
protected double scaleY = 1;
4848

49-
private native void initOps(long pConfigInfo, WComponentPeer peer,
50-
long hwnd);
49+
private native void initOps(OGLGraphicsConfig gc, long pConfigInfo,
50+
WComponentPeer peer, long hwnd);
5151

5252
protected WGLSurfaceData(WComponentPeer peer, WGLGraphicsConfig gc,
5353
ColorModel cm, int type)
@@ -62,7 +62,7 @@ protected WGLSurfaceData(WComponentPeer peer, WGLGraphicsConfig gc,
6262
long pConfigInfo = gc.getNativeConfigInfo();
6363
long hwnd = peer != null ? peer.getHWnd() : 0L;
6464

65-
initOps(pConfigInfo, peer, hwnd);
65+
initOps(gc, pConfigInfo, peer, hwnd);
6666
}
6767

6868
@Override

src/java.desktop/windows/native/libawt/java2d/opengl/WGLSurfaceData.c

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -58,11 +58,25 @@ extern void
5858

5959
JNIEXPORT void JNICALL
6060
Java_sun_java2d_opengl_WGLSurfaceData_initOps(JNIEnv *env, jobject wglsd,
61-
jlong pConfigInfo,
61+
jobject gc, jlong pConfigInfo,
6262
jobject peer, jlong hwnd)
6363
{
64+
gc = (*env)->NewGlobalRef(env, gc);
65+
if (gc == NULL) {
66+
JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
67+
return;
68+
}
69+
6470
OGLSDOps *oglsdo = (OGLSDOps *)SurfaceData_InitOps(env, wglsd,
6571
sizeof(OGLSDOps));
72+
if (oglsdo == NULL) {
73+
(*env)->DeleteGlobalRef(env, gc);
74+
JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
75+
return;
76+
}
77+
// later the graphicsConfig will be used for deallocation of oglsdo
78+
oglsdo->graphicsConfig = gc;
79+
6680
WGLSDOps *wglsdo = (WGLSDOps *)malloc(sizeof(WGLSDOps));
6781

6882
J2dTraceLn(J2D_TRACE_INFO, "WGLSurfaceData_initOps");
@@ -144,33 +158,6 @@ WGLSD_MakeCurrentToScratch(JNIEnv *env, OGLContext *oglc)
144158
return JNI_TRUE;
145159
}
146160

147-
/**
148-
* Returns a pointer (as a jlong) to the native WGLGraphicsConfigInfo
149-
* associated with the given OGLSDOps. This method can be called from
150-
* shared code to retrieve the native GraphicsConfig data in a platform-
151-
* independent manner.
152-
*/
153-
jlong
154-
OGLSD_GetNativeConfigInfo(OGLSDOps *oglsdo)
155-
{
156-
WGLSDOps *wglsdo;
157-
158-
if (oglsdo == NULL) {
159-
J2dRlsTraceLn(J2D_TRACE_ERROR,
160-
"OGLSD_GetNativeConfigInfo: ops are null");
161-
return 0L;
162-
}
163-
164-
wglsdo = (WGLSDOps *)oglsdo->privOps;
165-
if (wglsdo == NULL) {
166-
J2dRlsTraceLn(J2D_TRACE_ERROR,
167-
"OGLSD_GetNativeConfigInfo: wgl ops are null");
168-
return 0L;
169-
}
170-
171-
return ptr_to_jlong(wglsdo->configInfo);
172-
}
173-
174161
/**
175162
* Makes the given GraphicsConfig's context current to its associated
176163
* "scratch" surface. If there is a problem making the context current,

0 commit comments

Comments
 (0)