author | ihse |
Sat, 03 Mar 2018 08:21:47 +0100 | |
branch | ihse-warnings-cflags-branch |
changeset 56230 | 489867818774 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
33653
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
32123
diff
changeset
|
2 |
* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
#include <stdio.h> |
|
27 |
#include <dlfcn.h> |
|
28 |
#include <string.h> |
|
29 |
#include <stdlib.h> |
|
30 |
#include <jni.h> |
|
31 |
#include <jni_util.h> |
|
32 |
#include <jvm.h> |
|
33 |
#include "gdefs.h" |
|
34 |
||
35 |
#include <sys/param.h> |
|
36 |
#include <sys/utsname.h> |
|
37 |
||
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20453
diff
changeset
|
38 |
#ifdef AIX |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20453
diff
changeset
|
39 |
#include "porting_aix.h" /* For the 'dladdr' function. */ |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20453
diff
changeset
|
40 |
#endif |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
20453
diff
changeset
|
41 |
|
2 | 42 |
#ifdef DEBUG |
43 |
#define VERBOSE_AWT_DEBUG |
|
44 |
#endif |
|
45 |
||
46 |
static void *awtHandle = NULL; |
|
47 |
||
16862
247af361e9ca
8008509: 6588413 changed JNIEXPORT visibility for GCC on HSX, jdk's jni_md.h needs similar change
martin
parents:
12050
diff
changeset
|
48 |
typedef jint JNICALL JNI_OnLoad_type(JavaVM *vm, void *reserved); |
2 | 49 |
|
50 |
/* Initialize the Java VM instance variable when the library is |
|
51 |
first loaded */ |
|
52 |
JavaVM *jvm; |
|
53 |
||
56230 | 54 |
JNIEXPORT jboolean JNICALL AWTIsHeadless(void) { |
2 | 55 |
static JNIEnv *env = NULL; |
56 |
static jboolean isHeadless; |
|
57 |
jmethodID headlessFn; |
|
58 |
jclass graphicsEnvClass; |
|
59 |
||
60 |
if (env == NULL) { |
|
61 |
env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); |
|
62 |
graphicsEnvClass = (*env)->FindClass(env, |
|
63 |
"java/awt/GraphicsEnvironment"); |
|
64 |
if (graphicsEnvClass == NULL) { |
|
65 |
return JNI_TRUE; |
|
66 |
} |
|
67 |
headlessFn = (*env)->GetStaticMethodID(env, |
|
68 |
graphicsEnvClass, "isHeadless", "()Z"); |
|
69 |
if (headlessFn == NULL) { |
|
70 |
return JNI_TRUE; |
|
71 |
} |
|
72 |
isHeadless = (*env)->CallStaticBooleanMethod(env, graphicsEnvClass, |
|
73 |
headlessFn); |
|
32123
92824eb030c5
8130507: closed/java/awt/font/JNICheck/JNICheck.sh test reports some warnings
psadhukhan
parents:
26751
diff
changeset
|
74 |
if ((*env)->ExceptionCheck(env)) { |
92824eb030c5
8130507: closed/java/awt/font/JNICheck/JNICheck.sh test reports some warnings
psadhukhan
parents:
26751
diff
changeset
|
75 |
(*env)->ExceptionClear(env); |
92824eb030c5
8130507: closed/java/awt/font/JNICheck/JNICheck.sh test reports some warnings
psadhukhan
parents:
26751
diff
changeset
|
76 |
return JNI_TRUE; |
92824eb030c5
8130507: closed/java/awt/font/JNICheck/JNICheck.sh test reports some warnings
psadhukhan
parents:
26751
diff
changeset
|
77 |
} |
2 | 78 |
} |
79 |
return isHeadless; |
|
80 |
} |
|
81 |
||
24130
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23328
diff
changeset
|
82 |
#define CHECK_EXCEPTION_FATAL(env, message) \ |
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23328
diff
changeset
|
83 |
if ((*env)->ExceptionCheck(env)) { \ |
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23328
diff
changeset
|
84 |
(*env)->ExceptionClear(env); \ |
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23328
diff
changeset
|
85 |
(*env)->FatalError(env, message); \ |
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23328
diff
changeset
|
86 |
} |
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23328
diff
changeset
|
87 |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
88 |
/* |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
89 |
* Pathnames to the various awt toolkits |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
90 |
*/ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
91 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
92 |
#ifdef MACOSX |
12050
28109b684ac0
7152186: java.awt.HeadlessException when running AWT apps [macosx]
michaelm
parents:
12047
diff
changeset
|
93 |
#define LWAWT_PATH "/libawt_lwawt.dylib" |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
94 |
#define DEFAULT_PATH LWAWT_PATH |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
95 |
#else |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
96 |
#define XAWT_PATH "/libawt_xawt.so" |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
97 |
#define DEFAULT_PATH XAWT_PATH |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
98 |
#define HEADLESS_PATH "/libawt_headless.so" |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
99 |
#endif |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
100 |
|
2 | 101 |
jint |
102 |
AWT_OnLoad(JavaVM *vm, void *reserved) |
|
103 |
{ |
|
104 |
Dl_info dlinfo; |
|
105 |
char buf[MAXPATHLEN]; |
|
106 |
int32_t len; |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
107 |
char *p, *tk; |
2 | 108 |
JNI_OnLoad_type *JNI_OnLoad_ptr; |
109 |
struct utsname name; |
|
110 |
JNIEnv *env = (JNIEnv *)JNU_GetEnv(vm, JNI_VERSION_1_2); |
|
111 |
void *v; |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
112 |
jstring fmanager = NULL; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
113 |
jstring fmProp = NULL; |
2 | 114 |
|
115 |
if (awtHandle != NULL) { |
|
116 |
/* Avoid several loading attempts */ |
|
117 |
return JNI_VERSION_1_2; |
|
118 |
} |
|
119 |
||
120 |
jvm = vm; |
|
121 |
||
122 |
/* Get address of this library and the directory containing it. */ |
|
23252
4c62cbe8fddf
6571600: JNI use results in UnsatisfiedLinkError looking for libmawt.so
dbuck
parents:
20453
diff
changeset
|
123 |
dladdr((void *)AWT_OnLoad, &dlinfo); |
2 | 124 |
realpath((char *)dlinfo.dli_fname, buf); |
125 |
len = strlen(buf); |
|
126 |
p = strrchr(buf, '/'); |
|
127 |
||
128 |
/* |
|
129 |
* The code below is responsible for: |
|
11665
98dad53a8ba1
7110002: Rename xawt/libmawt.so and headless/libmawt.so so they can be colocated with libawt
chegar
parents:
9203
diff
changeset
|
130 |
* 1. Loading appropriate awt library, i.e. libawt_xawt or libawt_headless |
20453
e480eb64d2c2
7174704: [macosx] New issue in 7u6 b12: HeadlessPrintingTest failure
anthony
parents:
16862
diff
changeset
|
131 |
* 2. Set the "sun.font.fontmanager" system property. |
2 | 132 |
*/ |
133 |
||
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
134 |
fmProp = (*env)->NewStringUTF(env, "sun.font.fontmanager"); |
24130
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23328
diff
changeset
|
135 |
CHECK_EXCEPTION_FATAL(env, "Could not allocate font manager property"); |
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23328
diff
changeset
|
136 |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
137 |
#ifdef MACOSX |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
138 |
fmanager = (*env)->NewStringUTF(env, "sun.font.CFontManager"); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
139 |
tk = LWAWT_PATH; |
20453
e480eb64d2c2
7174704: [macosx] New issue in 7u6 b12: HeadlessPrintingTest failure
anthony
parents:
16862
diff
changeset
|
140 |
#else |
e480eb64d2c2
7174704: [macosx] New issue in 7u6 b12: HeadlessPrintingTest failure
anthony
parents:
16862
diff
changeset
|
141 |
fmanager = (*env)->NewStringUTF(env, "sun.awt.X11FontManager"); |
e480eb64d2c2
7174704: [macosx] New issue in 7u6 b12: HeadlessPrintingTest failure
anthony
parents:
16862
diff
changeset
|
142 |
tk = XAWT_PATH; |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
143 |
#endif |
24130
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23328
diff
changeset
|
144 |
CHECK_EXCEPTION_FATAL(env, "Could not allocate font manager name"); |
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23328
diff
changeset
|
145 |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
146 |
if (fmanager && fmProp) { |
20453
e480eb64d2c2
7174704: [macosx] New issue in 7u6 b12: HeadlessPrintingTest failure
anthony
parents:
16862
diff
changeset
|
147 |
JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "setProperty", |
e480eb64d2c2
7174704: [macosx] New issue in 7u6 b12: HeadlessPrintingTest failure
anthony
parents:
16862
diff
changeset
|
148 |
"(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", |
e480eb64d2c2
7174704: [macosx] New issue in 7u6 b12: HeadlessPrintingTest failure
anthony
parents:
16862
diff
changeset
|
149 |
fmProp, fmanager); |
24130
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23328
diff
changeset
|
150 |
CHECK_EXCEPTION_FATAL(env, "Could not allocate set properties"); |
2 | 151 |
} |
152 |
||
20453
e480eb64d2c2
7174704: [macosx] New issue in 7u6 b12: HeadlessPrintingTest failure
anthony
parents:
16862
diff
changeset
|
153 |
#ifndef MACOSX |
2 | 154 |
if (AWTIsHeadless()) { |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
155 |
tk = HEADLESS_PATH; |
2 | 156 |
} |
20453
e480eb64d2c2
7174704: [macosx] New issue in 7u6 b12: HeadlessPrintingTest failure
anthony
parents:
16862
diff
changeset
|
157 |
#endif |
e480eb64d2c2
7174704: [macosx] New issue in 7u6 b12: HeadlessPrintingTest failure
anthony
parents:
16862
diff
changeset
|
158 |
|
e480eb64d2c2
7174704: [macosx] New issue in 7u6 b12: HeadlessPrintingTest failure
anthony
parents:
16862
diff
changeset
|
159 |
/* Calculate library name to load */ |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
160 |
strncpy(p, tk, MAXPATHLEN-len-1); |
2 | 161 |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
162 |
if (fmProp) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
163 |
(*env)->DeleteLocalRef(env, fmProp); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
164 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
165 |
if (fmanager) { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
166 |
(*env)->DeleteLocalRef(env, fmanager); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
11665
diff
changeset
|
167 |
} |
2 | 168 |
|
24130
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23328
diff
changeset
|
169 |
jstring jbuf = JNU_NewStringPlatform(env, buf); |
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23328
diff
changeset
|
170 |
CHECK_EXCEPTION_FATAL(env, "Could not allocate library name"); |
2 | 171 |
JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "load", |
172 |
"(Ljava/lang/String;)V", |
|
24130
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23328
diff
changeset
|
173 |
jbuf); |
2 | 174 |
|
175 |
awtHandle = dlopen(buf, RTLD_LAZY | RTLD_GLOBAL); |
|
176 |
||
177 |
return JNI_VERSION_1_2; |
|
178 |
} |
|
179 |
||
180 |
JNIEXPORT jint JNICALL |
|
33653
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
32123
diff
changeset
|
181 |
DEF_JNI_OnLoad(JavaVM *vm, void *reserved) |
2 | 182 |
{ |
183 |
return AWT_OnLoad(vm, reserved); |
|
184 |
} |
|
185 |
||
186 |
/* |
|
187 |
* This entry point must remain in libawt.so as part of a contract |
|
188 |
* with the CDE variant of Java Media Framework. (sdtjmplay) |
|
11665
98dad53a8ba1
7110002: Rename xawt/libmawt.so and headless/libmawt.so so they can be colocated with libawt
chegar
parents:
9203
diff
changeset
|
189 |
* Reflect this call over to the correct libawt_<toolkit>.so. |
2 | 190 |
*/ |
191 |
JNIEXPORT void JNICALL |
|
192 |
Java_sun_awt_motif_XsessionWMcommand(JNIEnv *env, jobject this, |
|
193 |
jobject frame, jstring jcommand) |
|
194 |
{ |
|
195 |
/* type of the old backdoor function */ |
|
16862
247af361e9ca
8008509: 6588413 changed JNIEXPORT visibility for GCC on HSX, jdk's jni_md.h needs similar change
martin
parents:
12050
diff
changeset
|
196 |
typedef void JNICALL |
2 | 197 |
XsessionWMcommand_type(JNIEnv *env, jobject this, |
198 |
jobject frame, jstring jcommand); |
|
199 |
||
200 |
static XsessionWMcommand_type *XsessionWMcommand = NULL; |
|
201 |
||
202 |
if (XsessionWMcommand == NULL && awtHandle == NULL) { |
|
203 |
return; |
|
204 |
} |
|
205 |
||
206 |
XsessionWMcommand = (XsessionWMcommand_type *) |
|
207 |
dlsym(awtHandle, "Java_sun_awt_motif_XsessionWMcommand"); |
|
208 |
||
209 |
if (XsessionWMcommand == NULL) |
|
210 |
return; |
|
211 |
||
212 |
(*XsessionWMcommand)(env, this, frame, jcommand); |
|
213 |
} |
|
214 |
||
215 |
||
216 |
/* |
|
217 |
* This entry point must remain in libawt.so as part of a contract |
|
218 |
* with the CDE variant of Java Media Framework. (sdtjmplay) |
|
11665
98dad53a8ba1
7110002: Rename xawt/libmawt.so and headless/libmawt.so so they can be colocated with libawt
chegar
parents:
9203
diff
changeset
|
219 |
* Reflect this call over to the correct libawt_<toolkit>.so. |
2 | 220 |
*/ |
221 |
JNIEXPORT void JNICALL |
|
222 |
Java_sun_awt_motif_XsessionWMcommand_New(JNIEnv *env, jobjectArray jargv) |
|
223 |
{ |
|
16862
247af361e9ca
8008509: 6588413 changed JNIEXPORT visibility for GCC on HSX, jdk's jni_md.h needs similar change
martin
parents:
12050
diff
changeset
|
224 |
typedef void JNICALL |
2 | 225 |
XsessionWMcommand_New_type(JNIEnv *env, jobjectArray jargv); |
226 |
||
227 |
static XsessionWMcommand_New_type *XsessionWMcommand = NULL; |
|
228 |
||
229 |
if (XsessionWMcommand == NULL && awtHandle == NULL) { |
|
230 |
return; |
|
231 |
} |
|
232 |
||
233 |
XsessionWMcommand = (XsessionWMcommand_New_type *) |
|
234 |
dlsym(awtHandle, "Java_sun_awt_motif_XsessionWMcommand_New"); |
|
235 |
||
236 |
if (XsessionWMcommand == NULL) |
|
237 |
return; |
|
238 |
||
239 |
(*XsessionWMcommand)(env, jargv); |
|
240 |
} |