Skip to content

Commit 7977e38

Browse files
Andrii RodionovBob Vandette
Andrii Rodionov
authored and
Bob Vandette
committed
8254024: Enhance native libs for AWT and Swing to work with GraalVM Native Image
Reviewed-by: serb, ihse, bobv
1 parent c37eabe commit 7977e38

File tree

4 files changed

+92
-11
lines changed

4 files changed

+92
-11
lines changed

src/java.desktop/share/native/libawt/awt/medialib/awt_ImagingLib.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2020, 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
@@ -39,7 +39,7 @@ typedef struct {
3939
typedef mlib_image *(*MlibCreateFP_t)(mlib_type, mlib_s32, mlib_s32,
4040
mlib_s32);
4141
typedef mlib_image *(*MlibCreateStructFP_t)(mlib_type, mlib_s32, mlib_s32,
42-
mlib_s32, mlib_s32, void *);
42+
mlib_s32, mlib_s32, const void *);
4343
typedef void (*MlibDeleteFP_t)(mlib_image *);
4444

4545
typedef struct {

src/java.desktop/unix/native/libawt/awt/awt_LoadLibrary.c

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2020, 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
@@ -43,6 +43,13 @@
4343
#define VERBOSE_AWT_DEBUG
4444
#endif
4545

46+
#ifdef STATIC_BUILD
47+
extern void Java_sun_xawt_motif_XsessionWMcommand(JNIEnv *env, jobject this,
48+
jobject frame, jstring jcommand);
49+
50+
extern void Java_sun_xawt_motif_XsessionWMcommand_New(JNIEnv *env, jobjectArray jarray);
51+
#endif
52+
4653
static void *awtHandle = NULL;
4754

4855
typedef jint JNICALL JNI_OnLoad_type(JavaVM *vm, void *reserved);
@@ -118,13 +125,13 @@ AWT_OnLoad(JavaVM *vm, void *reserved)
118125
}
119126

120127
jvm = vm;
121-
128+
#ifndef STATIC_BUILD
122129
/* Get address of this library and the directory containing it. */
123130
dladdr((void *)AWT_OnLoad, &dlinfo);
124131
realpath((char *)dlinfo.dli_fname, buf);
125132
len = strlen(buf);
126133
p = strrchr(buf, '/');
127-
134+
#endif
128135
/*
129136
* The code below is responsible for:
130137
* 1. Loading appropriate awt library, i.e. libawt_xawt or libawt_headless
@@ -156,8 +163,10 @@ AWT_OnLoad(JavaVM *vm, void *reserved)
156163
}
157164
#endif
158165

166+
#ifndef STATIC_BUILD
159167
/* Calculate library name to load */
160168
strncpy(p, tk, MAXPATHLEN-len-1);
169+
#endif
161170

162171
if (fmProp) {
163172
(*env)->DeleteLocalRef(env, fmProp);
@@ -166,14 +175,16 @@ AWT_OnLoad(JavaVM *vm, void *reserved)
166175
(*env)->DeleteLocalRef(env, fmanager);
167176
}
168177

178+
179+
#ifndef STATIC_BUILD
169180
jstring jbuf = JNU_NewStringPlatform(env, buf);
170181
CHECK_EXCEPTION_FATAL(env, "Could not allocate library name");
171182
JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "load",
172183
"(Ljava/lang/String;)V",
173184
jbuf);
174185

175186
awtHandle = dlopen(buf, RTLD_LAZY | RTLD_GLOBAL);
176-
187+
#endif
177188
return JNI_VERSION_1_2;
178189
}
179190

@@ -198,14 +209,16 @@ Java_sun_awt_motif_XsessionWMcommand(JNIEnv *env, jobject this,
198209
jobject frame, jstring jcommand);
199210

200211
static XsessionWMcommand_type *XsessionWMcommand = NULL;
201-
212+
#ifndef STATIC_BUILD
202213
if (XsessionWMcommand == NULL && awtHandle == NULL) {
203214
return;
204215
}
205216

206217
XsessionWMcommand = (XsessionWMcommand_type *)
207218
dlsym(awtHandle, "Java_sun_awt_motif_XsessionWMcommand");
208-
219+
#else
220+
XsessionWMcommand = (XsessionWMcommand_type *)Java_sun_xawt_motif_XsessionWMcommand;
221+
#endif
209222
if (XsessionWMcommand == NULL)
210223
return;
211224

@@ -225,16 +238,30 @@ Java_sun_awt_motif_XsessionWMcommand_New(JNIEnv *env, jobjectArray jargv)
225238
XsessionWMcommand_New_type(JNIEnv *env, jobjectArray jargv);
226239

227240
static XsessionWMcommand_New_type *XsessionWMcommand = NULL;
228-
241+
#ifndef STATIC_BUILD
229242
if (XsessionWMcommand == NULL && awtHandle == NULL) {
230243
return;
231244
}
232245

233246
XsessionWMcommand = (XsessionWMcommand_New_type *)
234247
dlsym(awtHandle, "Java_sun_awt_motif_XsessionWMcommand_New");
248+
#else
249+
XsessionWMcommand = (XsessionWMcommand_New_type *)Java_sun_xawt_motif_XsessionWMcommand_New;
250+
#endif
235251

236252
if (XsessionWMcommand == NULL)
237253
return;
238254

239255
(*XsessionWMcommand)(env, jargv);
240256
}
257+
258+
#ifdef STATIC_BUILD
259+
__attribute__((weak)) void Java_sun_xawt_motif_XsessionWMcommand_New(JNIEnv *env, jobjectArray jarray)
260+
{
261+
}
262+
263+
__attribute__((weak)) void Java_sun_xawt_motif_XsessionWMcommand(JNIEnv *env, jobject this,
264+
jobject frame, jstring jcommand)
265+
{
266+
}
267+
#endif

src/java.desktop/unix/native/libawt/awt/awt_Mlib.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2020, 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
@@ -36,9 +36,50 @@
3636
#include "awt_Mlib.h"
3737
#include "java_awt_image_BufferedImage.h"
3838

39+
#ifdef STATIC_BUILD
40+
#include "mlib_image.h"
41+
#endif
42+
3943
static void start_timer(int numsec);
4044
static void stop_timer(int numsec, int ntimes);
4145

46+
#ifdef STATIC_BUILD
47+
// Mapping functions to their names for runtime check
48+
static mlibFnS_t sMlibFnsStatic[] = {
49+
{j2d_mlib_ImageConvMxN, "j2d_mlib_ImageConvMxN"},
50+
{j2d_mlib_ImageAffine, "j2d_mlib_ImageAffine"},
51+
{j2d_mlib_ImageLookUp, "j2d_mlib_ImageLookUp"},
52+
{j2d_mlib_ImageConvKernelConvert, "j2d_mlib_ImageConvKernelConvert"},
53+
};
54+
55+
mlib_status awt_getImagingLib(JNIEnv *env, mlibFnS_t *sMlibFns,
56+
mlibSysFnS_t *sMlibSysFns) {
57+
mlibFnS_t *mptr;
58+
int i;
59+
char *fName;
60+
mlibSysFnS_t tempSysFns;
61+
mlib_status ret = MLIB_SUCCESS;
62+
63+
tempSysFns.createFP = j2d_mlib_ImageCreate;
64+
tempSysFns.createStructFP = j2d_mlib_ImageCreateStruct;
65+
tempSysFns.deleteImageFP = j2d_mlib_ImageDelete;
66+
*sMlibSysFns = tempSysFns;
67+
68+
mptr = sMlibFns;
69+
i = 0;
70+
while (mptr[i].fname != NULL) {
71+
fName = mptr[i].fname;
72+
if(strcmp(fName, sMlibFnsStatic[i].fname) == 0) {
73+
mptr[i].fptr = sMlibFnsStatic[i].fptr;
74+
} else {
75+
ret = MLIB_FAILURE;
76+
}
77+
i++;
78+
}
79+
80+
return ret;
81+
}
82+
#else
4283
/*
4384
* This is called by awt_ImagingLib.initLib()
4485
*/
@@ -121,6 +162,7 @@ mlib_status awt_getImagingLib(JNIEnv *env, mlibFnS_t *sMlibFns,
121162
}
122163
return ret;
123164
}
165+
#endif
124166

125167
mlib_start_timer awt_setMlibStartTimer() {
126168
return start_timer;

src/java.desktop/unix/native/libawt_xawt/xawt/XToolkit.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,12 @@ Java_java_awt_TextField_initIDs
300300
{
301301
}
302302

303+
#ifndef STATIC_BUILD
304+
// The same function exists in libawt.a::awt_LoadLibrary.c
303305
JNIEXPORT jboolean JNICALL AWTIsHeadless() {
304306
return JNI_FALSE;
305307
}
308+
#endif
306309

307310
JNIEXPORT void JNICALL Java_java_awt_Dialog_initIDs (JNIEnv *env, jclass cls)
308311
{
@@ -811,8 +814,13 @@ Window get_xawt_root_shell(JNIEnv *env) {
811814
*/
812815

813816
JNIEXPORT void JNICALL
814-
Java_sun_awt_motif_XsessionWMcommand(JNIEnv *env, jobject this,
817+
#ifdef STATIC_BUILD
818+
Java_sun_xawt_motif_XsessionWMcommand(JNIEnv *env, jobject this,
815819
jobject frame, jstring jcommand)
820+
#else
821+
Java_sun_awt_motif_XsessionWMcommand(JNIEnv *env, jobject this,
822+
jobject frame, jstring jcommand)
823+
#endif
816824
{
817825
const char *command;
818826
XTextProperty text_prop;
@@ -856,7 +864,11 @@ Java_sun_awt_motif_XsessionWMcommand(JNIEnv *env, jobject this,
856864
* name. It's not! It's just a plain function.
857865
*/
858866
JNIEXPORT void JNICALL
867+
#ifdef STATIC_BUILD
868+
Java_sun_xawt_motif_XsessionWMcommand_New(JNIEnv *env, jobjectArray jarray)
869+
#else
859870
Java_sun_awt_motif_XsessionWMcommand_New(JNIEnv *env, jobjectArray jarray)
871+
#endif
860872
{
861873
jsize length;
862874
char ** array;

0 commit comments

Comments
 (0)