Skip to content

Commit a6823ab

Browse files
committed
simplify executable debug options
1 parent fdaf9dc commit a6823ab

8 files changed

Lines changed: 79 additions & 40 deletions

File tree

native/linux/build.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323

2424
<!-- build cli version -->
2525
<exec command="gcc ${opt} -I ${java.home}/include -I ${java.home}/include/@{linux} -I ../headers -I ../opencl -Wno-write-strings -D_JF_CLI loader.cpp native.a @{libs} -o ${user.home}/bin/jfexec"/>
26-
<exec command="gcc ${opt} -I ${java.home}/include -I ${java.home}/include/@{linux} -I ../headers -I ../opencl -Wno-write-strings -D_JF_CLI -D_JF_DEBUG loader.cpp native.a @{libs} -o ${user.home}/bin/jfexecd"/>
27-
<exec command="gcc ${opt} -I ${java.home}/include -I ${java.home}/include/@{linux} -I ../headers -I ../opencl -Wno-write-strings -D_JF_CLI -D_JF_DEBUG -D_JF_SERVICE loader.cpp native.a @{libs} -o ${user.home}/bin/jfexecsd"/>
26+
<exec command="gcc ${opt} -I ${java.home}/include -I ${java.home}/include/@{linux} -I ../headers -I ../opencl -Wno-write-strings -D_JF_CLI -D_JF_SERVICE loader.cpp native.a @{libs} -o ${user.home}/bin/jfexecs"/>
2827

2928
<!-- build shared library -->
3029
<exec command="gcc ${opt} -shared native.o glfw.o glfw-null.o @{libs} -o ${user.home}/bin/jfnative64.so"/>

native/linux/loader.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ char xoptions[MAX_PATH];
6161
char cfgargs[1024];
6262
bool graal = false;
6363
bool debug = false;
64+
int debug_port = 9010;
65+
char debug_opt[64];
6466
char errmsg[1024];
6567

6668
/* Prototypes */
@@ -243,19 +245,24 @@ JavaVMInitArgs *BuildArgs() {
243245
int nOpts = 0;
244246
char *opts[64];
245247
int idx;
248+
char *jf_debug;
246249

247-
#ifdef _JF_DEBUG
248-
debug = true;
249-
#else
250-
if (getenv("JF_DEBUG") != NULL) {
251-
debug = true;
250+
jf_debug = getenv("JF_DEBUG");
251+
if (jf_debug != NULL) {
252+
if (strcmp(jf_debug, "true") == 0) {
253+
debug = true;
254+
}
255+
}
256+
jf_debug = getenv("JF_DEBUG_PORT");
257+
if (jf_debug != NULL) {
258+
debug_port = atoi(jf_debug);
252259
}
253-
#endif
254260

255261
if (debug) {
256262
opts[nOpts++] = "-Djava.debug=true";
257263
opts[nOpts++] = "-Dcom.sun.management.jmxremote";
258-
opts[nOpts++] = "-Dcom.sun.management.jmxremote.port=9010";
264+
sprintf(debug_opt, "-Dcom.sun.management.jmxremote.port=%d", debug_port);
265+
opts[nOpts++] = debug_opt;
259266
opts[nOpts++] = "-Dcom.sun.management.jmxremote.local.only=false";
260267
opts[nOpts++] = "-Dcom.sun.management.jmxremote.authenticate=false";
261268
opts[nOpts++] = "-Dcom.sun.management.jmxremote.ssl=false";
@@ -521,6 +528,9 @@ bool loadProperties() {
521528
else if (strncmp(ln1, "DEBUG=", 6) == 0) {
522529
debug = true;
523530
}
531+
else if (strncmp(ln1, "DEBUG_PORT=", 11) == 0) {
532+
debug_port = atoi(ln1 + 11);
533+
}
524534
ln1 = ln2;
525535
}
526536
free(data);

native/mac/build.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
<!-- build native cli executable -->
2121
<exec command="gcc -framework CoreFoundation -I ${java.home}/include -I ${java.home}/include/darwin -I ../headers -D_JF_CLI loader.mm ${libs} -o ${user.home}/bin/jfexec"/>
22-
<exec command="gcc -framework CoreFoundation -I ${java.home}/include -I ${java.home}/include/darwin -I ../headers -D_JF_CLI -D_JF_DEBUG loader.mm ${libs} -o ${user.home}/bin/jfexecd"/>
2322

2423
<delete>
2524
<fileset dir=".">

native/mac/loader.mm

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
char cfgargs[1024];
6464
char app_path[MAX_PATH];
6565
char app_name[MAX_PATH];
66+
bool debug = false;
67+
int debug_port = 9010;
68+
char debug_opt[64];
6669

6770
/* Prototypes */
6871
void error(char *msg);
@@ -153,17 +156,30 @@ void printException(JNIEnv *env) {
153156
int nOpts = 0;
154157
char *opts[64];
155158
int idx;
159+
char *jf_debug;
156160

157-
#ifdef _JF_DEBUG
158-
opts[nOpts++] = "-Djava.debug=true";
159-
opts[nOpts++] = "-Dcom.sun.management.jmxremote";
160-
opts[nOpts++] = "-Dcom.sun.management.jmxremote.port=9010";
161-
opts[nOpts++] = "-Dcom.sun.management.jmxremote.local.only=false";
162-
opts[nOpts++] = "-Dcom.sun.management.jmxremote.authenticate=false";
163-
opts[nOpts++] = "-Dcom.sun.management.jmxremote.ssl=false";
164-
#else
165-
opts[nOpts++] = "-XX:-UsePerfData";
166-
#endif
161+
jf_debug = getenv("JF_DEBUG");
162+
if (jf_debug != NULL) {
163+
if (strcmp(jf_debug, "true") == 0) {
164+
debug = true;
165+
}
166+
}
167+
jf_debug = getenv("JF_DEBUG_PORT");
168+
if (jf_debug != NULL) {
169+
debug_port = atoi(jf_debug);
170+
}
171+
172+
if (debug) {
173+
opts[nOpts++] = "-Djava.debug=true";
174+
opts[nOpts++] = "-Dcom.sun.management.jmxremote";
175+
sprintf(debug_opt, "-Dcom.sun.management.jmxremote.port=%d", debug_port);
176+
opts[nOpts++] = debug_opt;
177+
opts[nOpts++] = "-Dcom.sun.management.jmxremote.local.only=false";
178+
opts[nOpts++] = "-Dcom.sun.management.jmxremote.authenticate=false";
179+
opts[nOpts++] = "-Dcom.sun.management.jmxremote.ssl=false";
180+
} else {
181+
opts[nOpts++] = "-XX:-UsePerfData";
182+
}
167183
opts[nOpts++] = (char*)"-Djava.app.home=.";
168184
if (graal) {
169185
opts[nOpts++] = (char*)"-Djava.graal=true";
@@ -313,6 +329,12 @@ int loadProperties() {
313329
else if (strncmp(ln1, "ARGS=", 5) == 0) {
314330
strcpy(cfgargs, ln1 + 5);
315331
}
332+
else if (strncmp(ln1, "DEBUG=", 6) == 0) {
333+
debug = true;
334+
}
335+
else if (strncmp(ln1, "DEBUG_PORT=", 11) == 0) {
336+
debug_port = atoi(ln1 + 11);
337+
}
316338
ln1 = ln2;
317339
}
318340
free(data);

native/windows/build.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
<!-- native cli loaders -->
2323
<exec command="cl /I '${java.home}/include' /I '${java.home}/include/win32' /I '../headers' /D_JF_CLI loader.cpp native.lib ${winlibs} /Fe: ${user.home}/bin/jfexecw.exe /link /subsystem:windows /entry:mainCRTStartup"/>
2424
<exec command="cl /I '${java.home}/include' /I '${java.home}/include/win32' /I '../headers' /D_JF_CLI loader.cpp native.lib ${winlibs} /Fe: ${user.home}/bin/jfexec.exe /link /subsystem:console"/>
25-
<exec command="cl /I '${java.home}/include' /I '${java.home}/include/win32' /I '../headers' /D_JF_CLI /D_JF_DEBUG loader.cpp native.lib ${winlibs} /Fe: ${user.home}/bin/jfexecwd.exe /link /subsystem:windows /entry:mainCRTStartup"/>
26-
<exec command="cl /I '${java.home}/include' /I '${java.home}/include/win32' /I '../headers' /D_JF_CLI /D_JF_DEBUG loader.cpp native.lib ${winlibs} /Fe: ${user.home}/bin/jfexecd.exe /link /subsystem:console"/>
27-
<exec command="cl /I '${java.home}/include' /I '${java.home}/include/win32' /I '../headers' /D_JF_CLI /D_JF_DEBUG /D_JF_CLI_SERVICE loader.cpp native.lib ${winlibs} /Fe: ${user.home}/bin/jfexecsd.exe /link /subsystem:console"/>
25+
<exec command="cl /I '${java.home}/include' /I '${java.home}/include/win32' /I '../headers' /D_JF_CLI /D_JF_CLI_SERVICE loader.cpp native.lib ${winlibs} /Fe: ${user.home}/bin/jfexecs.exe /link /subsystem:console"/>
2826

2927
<!-- native shared library -->
3028
<exec command="cl /LD /MT ${objs} ${winlibs} libcmt.lib /Fe: ${user.home}/bin/jfnative64.dll /link /MACHINE:X64"/>

native/windows/loader.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ JavaVM *g_jvm = NULL;
6565
JNIEnv *g_env = NULL;
6666
bool graal = false;
6767
bool debug = false;
68+
int debug_port = 9010;
69+
char debug_opt[64];
6870
char errmsg[1024];
6971

7072
/* Prototypes */
@@ -254,22 +256,24 @@ JavaVMInitArgs *BuildArgs() {
254256
int idx;
255257
char *opts[64];
256258

257-
#ifdef _JF_DEBUG
258-
debug = true;
259-
#else
260259
char jf_debug[64];
261260
jf_debug[0] = 0;
262261
GetEnvironmentVariable("JF_DEBUG", jf_debug, 64);
263262
if (strcmp(jf_debug, "true") == 0) {
264263
debug = true;
265264
}
266-
#endif
265+
jf_debug[0] = 0;
266+
GetEnvironmentVariable("JF_DEBUG_PORT", jf_debug, 64);
267+
if (jf_debug[0] != 0) {
268+
debug_port = atoi(jf_debug);
269+
}
267270

268271
if (debug) {
269272
// Warning : this will cause the app not to load if MSVCRT is not installed at the system level - the one included in the MSI is not found by jmx
270273
opts[nOpts++] = "-Djava.debug=true";
271274
opts[nOpts++] = "-Dcom.sun.management.jmxremote";
272-
opts[nOpts++] = "-Dcom.sun.management.jmxremote.port=9010";
275+
sprintf(debug_opt, "-Dcom.sun.management.jmxremote.port=%d", debug_port);
276+
opts[nOpts++] = debug_opt;
273277
opts[nOpts++] = "-Dcom.sun.management.jmxremote.local.only=false";
274278
opts[nOpts++] = "-Dcom.sun.management.jmxremote.authenticate=false";
275279
opts[nOpts++] = "-Dcom.sun.management.jmxremote.ssl=false";
@@ -494,6 +498,9 @@ bool loadProperties() {
494498
else if (strncmp(ln1, "DEBUG=", 6) == 0) {
495499
debug = true;
496500
}
501+
else if (strncmp(ln1, "DEBUG_PORT=", 11) == 0) {
502+
debug_port = atoi(ln1 + 11);
503+
}
497504
#ifdef _JF_SERVICE
498505
else if (strncmp(ln1, "SERVICE=", 8) == 0) {
499506
strcpy(service, ln1 + 8);

readme.txt

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,21 @@ deploy : build maven deployment artifacts (requires pom.xml) and publish to sona
8585
- must define 'maven' property which is groupId
8686
- auth token must be defined in ~/.m2/settings.xml
8787
executable : build native loader
88-
- a stub loader for the platform is copied into the project folder and configured to load classpath and start main method
89-
- a project property "apptype" can be defined as:
88+
- creates executable for the app and configures it to load classpath and start main method
89+
- project property "apptype" can be defined as:
9090
"window" for Window GUI apps (default)
9191
"console" for console apps (alias "c")
9292
"service" for service apps (alias "s")
9393
"server" for service config GUI apps (same as "window" type plus adds "-server" to executable and package names)
9494
"client" for client config GUI apps (same as "window" type plus adds "-client" to executable and package names)
95+
- {app}.cfg file contains executable properties:
96+
- CLASSPATH={list of jar files seperated by ;} //CLASSPATH will be adjusted to OS requirements
97+
- MAINCLASS={main class to find main()} //startup class to find main() or serviceStart() if apptype=service
98+
- DEBUG=true //enable JMX debugging (see JMX Debugging)
99+
- DEBUG_PORT={port} //JMX port binding (default = 9010)
100+
- OPTION={options} //JVM options such as heap size, GC options, etc.
101+
- JAVA_HOME={path} //alternative JVM home (default = search various locations which depends on OS)
102+
- METHOD={start method} //alternative main method (default = main or serviceStart)
95103
ffmpeg : copy ffmpeg libraries to project folder (Windows only)
96104
installapp : install files before package creation (Linux only)
97105
deb : build Debian deb file (after installapp)
@@ -150,15 +158,13 @@ To build a project using Graal use the following Ant Tasks.
150158
- library name should be the full class name where main() is defined (ie: javaforce.utils.CopyPath.dll)
151159
GraalVM support for AWT is still a work in progress.
152160

153-
Debugging
154-
---------
155-
The CLI native loaders ~/bin/jfexec* enable JMX debugging support on port 9010.
156-
These loaders are used when you run an app with "ant run".
157-
From VisualVM you can connect to the JMX as localhost:9010
158-
You can also enable debug support by adding DEBUG=true to the project .cfg file to have it enabled in the generated executable.
159-
Debug support can also be enabled with environment variable JF_DEBUG=true
161+
JMX Debugging
162+
-------------
163+
JMX debugging support can be enabled with environment variable JF_DEBUG=true
164+
The JMX port by default is 9010 but can be overridden with environment variable JF_DEBUG_PORT
165+
You can enable debug support by adding DEBUG=true and DEBUG_PORT=9010 to the project .cfg file to have it enabled in the generated executable.
166+
From VisualVM you can connect to the JMX as localhost:9010 if it does not appear automatically.
160167
Also try adding -Xlog:gc*:gc.log to the OPTIONS= in the project .cfg file. Then while the app is running use 'tail -f gc.log' from a terminal to watch memory usage.
161-
This should be removed for any public release.
162168

163169
Requirements
164170
------------

src/javaforce/utils/ExecProject.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ public void run(String buildfile) throws Exception {
6060
exec += "s";
6161
}
6262

63-
exec += "d"; //use debug version
64-
6563
if (JF.isWindows()) {
6664
exec += ".exe";
6765
}

0 commit comments

Comments
 (0)