Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8254024: Enhance native libs for AWT and Swing to work with GraalVM Native Image #562

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -39,7 +39,7 @@ typedef struct {
typedef mlib_image *(*MlibCreateFP_t)(mlib_type, mlib_s32, mlib_s32,
mlib_s32);
typedef mlib_image *(*MlibCreateStructFP_t)(mlib_type, mlib_s32, mlib_s32,
mlib_s32, mlib_s32, void *);
mlib_s32, mlib_s32, const void *);
typedef void (*MlibDeleteFP_t)(mlib_image *);

typedef struct {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -43,6 +43,13 @@
#define VERBOSE_AWT_DEBUG
#endif

#ifdef STATIC_BUILD
extern void Java_sun_xawt_motif_XsessionWMcommand(JNIEnv *env, jobject this,
jobject frame, jstring jcommand);

extern void Java_sun_xawt_motif_XsessionWMcommand_New(JNIEnv *env, jobjectArray jarray);
#endif

static void *awtHandle = NULL;

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

jvm = vm;

#ifndef STATIC_BUILD
/* Get address of this library and the directory containing it. */
dladdr((void *)AWT_OnLoad, &dlinfo);
realpath((char *)dlinfo.dli_fname, buf);
len = strlen(buf);
p = strrchr(buf, '/');

#endif
/*
* The code below is responsible for:
* 1. Loading appropriate awt library, i.e. libawt_xawt or libawt_headless
@@ -156,8 +163,10 @@ AWT_OnLoad(JavaVM *vm, void *reserved)
}
#endif

#ifndef STATIC_BUILD
/* Calculate library name to load */
strncpy(p, tk, MAXPATHLEN-len-1);
#endif

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


#ifndef STATIC_BUILD
jstring jbuf = JNU_NewStringPlatform(env, buf);
CHECK_EXCEPTION_FATAL(env, "Could not allocate library name");
JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "load",
"(Ljava/lang/String;)V",
jbuf);

awtHandle = dlopen(buf, RTLD_LAZY | RTLD_GLOBAL);

#endif
return JNI_VERSION_1_2;
}

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

static XsessionWMcommand_type *XsessionWMcommand = NULL;

#ifndef STATIC_BUILD
if (XsessionWMcommand == NULL && awtHandle == NULL) {
return;
}

XsessionWMcommand = (XsessionWMcommand_type *)
dlsym(awtHandle, "Java_sun_awt_motif_XsessionWMcommand");

#else
XsessionWMcommand = (XsessionWMcommand_type *)Java_sun_xawt_motif_XsessionWMcommand;
#endif
if (XsessionWMcommand == NULL)
return;

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

static XsessionWMcommand_New_type *XsessionWMcommand = NULL;

#ifndef STATIC_BUILD
if (XsessionWMcommand == NULL && awtHandle == NULL) {
return;
}

XsessionWMcommand = (XsessionWMcommand_New_type *)
dlsym(awtHandle, "Java_sun_awt_motif_XsessionWMcommand_New");
#else
XsessionWMcommand = (XsessionWMcommand_New_type *)Java_sun_xawt_motif_XsessionWMcommand_New;
#endif

if (XsessionWMcommand == NULL)
return;

(*XsessionWMcommand)(env, jargv);
}

#ifdef STATIC_BUILD
__attribute__((weak)) void Java_sun_xawt_motif_XsessionWMcommand_New(JNIEnv *env, jobjectArray jarray)
{
}

__attribute__((weak)) void Java_sun_xawt_motif_XsessionWMcommand(JNIEnv *env, jobject this,
jobject frame, jstring jcommand)
{
}
#endif
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -36,9 +36,50 @@
#include "awt_Mlib.h"
#include "java_awt_image_BufferedImage.h"

#ifdef STATIC_BUILD
#include "mlib_image.h"
#endif

static void start_timer(int numsec);
static void stop_timer(int numsec, int ntimes);

#ifdef STATIC_BUILD
// Mapping functions to their names for runtime check
static mlibFnS_t sMlibFnsStatic[] = {
{j2d_mlib_ImageConvMxN, "j2d_mlib_ImageConvMxN"},
{j2d_mlib_ImageAffine, "j2d_mlib_ImageAffine"},
{j2d_mlib_ImageLookUp, "j2d_mlib_ImageLookUp"},
{j2d_mlib_ImageConvKernelConvert, "j2d_mlib_ImageConvKernelConvert"},
};

mlib_status awt_getImagingLib(JNIEnv *env, mlibFnS_t *sMlibFns,
mlibSysFnS_t *sMlibSysFns) {
mlibFnS_t *mptr;
int i;
char *fName;
mlibSysFnS_t tempSysFns;
mlib_status ret = MLIB_SUCCESS;

tempSysFns.createFP = j2d_mlib_ImageCreate;
tempSysFns.createStructFP = j2d_mlib_ImageCreateStruct;
tempSysFns.deleteImageFP = j2d_mlib_ImageDelete;
*sMlibSysFns = tempSysFns;

mptr = sMlibFns;
i = 0;
while (mptr[i].fname != NULL) {
fName = mptr[i].fname;
if(strcmp(fName, sMlibFnsStatic[i].fname) == 0) {
mptr[i].fptr = sMlibFnsStatic[i].fptr;
} else {
ret = MLIB_FAILURE;
}
i++;
}

return ret;
}
#else
/*
* This is called by awt_ImagingLib.initLib()
*/
@@ -121,6 +162,7 @@ mlib_status awt_getImagingLib(JNIEnv *env, mlibFnS_t *sMlibFns,
}
return ret;
}
#endif

mlib_start_timer awt_setMlibStartTimer() {
return start_timer;
@@ -300,9 +300,12 @@ Java_java_awt_TextField_initIDs
{
}

#ifndef STATIC_BUILD
// The same function exists in libawt.a::awt_LoadLibrary.c
JNIEXPORT jboolean JNICALL AWTIsHeadless() {
return JNI_FALSE;
}
#endif

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

JNIEXPORT void JNICALL
Java_sun_awt_motif_XsessionWMcommand(JNIEnv *env, jobject this,
#ifdef STATIC_BUILD
Java_sun_xawt_motif_XsessionWMcommand(JNIEnv *env, jobject this,
This conversation was marked as resolved by arodionov

This comment has been minimized.

@bobvandette

bobvandette Oct 14, 2020
Contributor

I'm not sure if this entrypoint is ever accessed externally in a normal JDK. To be safe, can you make both name changes conditional on STATIC_BUILD?

This comment has been minimized.

@arodionov

arodionov Oct 15, 2020
Author

Have made both names conditional.

jobject frame, jstring jcommand)
#else
Java_sun_awt_motif_XsessionWMcommand(JNIEnv *env, jobject this,
jobject frame, jstring jcommand)
#endif
{
const char *command;
XTextProperty text_prop;
@@ -856,7 +864,11 @@ Java_sun_awt_motif_XsessionWMcommand(JNIEnv *env, jobject this,
* name. It's not! It's just a plain function.
*/
JNIEXPORT void JNICALL
#ifdef STATIC_BUILD
Java_sun_xawt_motif_XsessionWMcommand_New(JNIEnv *env, jobjectArray jarray)
#else
Java_sun_awt_motif_XsessionWMcommand_New(JNIEnv *env, jobjectArray jarray)
#endif
{
jsize length;
char ** array;