Skip to content

Commit

Permalink
Pass version as integer instead of string
Browse files Browse the repository at this point in the history
  • Loading branch information
chadrako committed Mar 11, 2024
1 parent 85dc080 commit 4dcd472
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 20 deletions.
6 changes: 5 additions & 1 deletion make/modules/java.base/Launcher.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ ifeq ($(call isTargetOsType, unix), true)
NAME := jspawnhelper, \
SRC := $(TOPDIR)/src/$(MODULE)/unix/native/jspawnhelper, \
OPTIMIZATION := LOW, \
CFLAGS := $(CFLAGS_JDKEXE) -I$(TOPDIR)/src/$(MODULE)/unix/native/libjava -DVERSION_NUMBER='"$(VERSION_NUMBER_FOUR_POSITIONS)"', \
CFLAGS := $(CFLAGS_JDKEXE) -I$(TOPDIR)/src/$(MODULE)/unix/native/libjava \
-DVERSION_FEATURE=$(VERSION_FEATURE) \
-DVERSION_INTERIM=$(VERSION_INTERIM) \
-DVERSION_UPDATE=$(VERSION_UPDATE) \
-DVERSION_PATCH=$(VERSION_PATCH), \
EXTRA_OBJECT_FILES := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libjava/childproc$(OBJ_SUFFIX), \
LDFLAGS := $(LDFLAGS_JDKEXE), \
OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/modules_libs/$(MODULE), \
Expand Down
6 changes: 5 additions & 1 deletion make/modules/java.base/lib/CoreLibraries.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ TARGETS += $(BUILD_LIBVERIFY)

##########################################################################################

LIBJAVA_CFLAGS := -DARCHPROPNAME='"$(OPENJDK_TARGET_CPU_OSARCH)"' -DVERSION_NUMBER='"$(VERSION_NUMBER_FOUR_POSITIONS)"'
LIBJAVA_CFLAGS := -DARCHPROPNAME='"$(OPENJDK_TARGET_CPU_OSARCH)"' \
-DVERSION_FEATURE=$(VERSION_FEATURE) \
-DVERSION_INTERIM=$(VERSION_INTERIM) \
-DVERSION_UPDATE=$(VERSION_UPDATE) \
-DVERSION_PATCH=$(VERSION_PATCH)

ifeq ($(call isTargetOs, macosx), true)
BUILD_LIBJAVA_java_props_md.c_CFLAGS := -x objective-c
Expand Down
30 changes: 17 additions & 13 deletions src/java.base/unix/native/jspawnhelper/jspawnhelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,20 @@ extern int errno;
#define ERR_PIPE 2
#define ERR_ARGS 3

#ifndef VERSION_NUMBER
#error VERSION_NUMBER must be defined
#ifndef VERSION_FEATURE
#error VERSION_FEATURE must be defined
#endif

#ifndef VERSION_INTERIM
#error VERSION_INTERIM must be defined
#endif

#ifndef VERSION_UPDATE
#error VERSION_UPDATE must be defined
#endif

#ifndef VERSION_PATCH
#error VERSION_PATCH must be defined
#endif

void error (int fd, int err) {
Expand Down Expand Up @@ -145,7 +157,6 @@ int main(int argc, char *argv[]) {
/* argv[1] contains the fd number to read all the child info */
int r, fdinr, fdinw, fdout;
int jdk_feature, jdk_interim, jdk_update, jdk_patch;
int jspawn_feature, jspawn_interim, jspawn_update, jspawn_patch;
sigset_t unblock_signals;

if (argc != 2) {
Expand All @@ -165,16 +176,9 @@ int main(int argc, char *argv[]) {
}

// Check that JDK version and jspawnhelper version are the same
r = sscanf (VERSION_NUMBER, "%d.%d.%d.%d", &jspawn_feature, &jspawn_interim, &jspawn_update, &jspawn_patch);
if (r == 4) {
if (jdk_feature != jspawn_feature || jdk_interim != jspawn_interim ||
jdk_update != jspawn_update || jdk_patch != jspawn_patch) {

fprintf(stderr, "Expected jspawnhelper for Java %d.%d.%d+%d,", jspawn_feature, jspawn_interim, jspawn_update, jspawn_patch);
fprintf(stderr, "but jspawnhelper for Java %d.%d.%d+%d was found.\n", jdk_feature, jdk_interim, jdk_update, jdk_patch);
shutItDown();
}
} else {
if (jdk_feature != VERSION_FEATURE || jdk_interim != VERSION_INTERIM || jdk_update != VERSION_UPDATE || jdk_patch != VERSION_PATCH) {
fprintf(stderr, "Expected jspawnhelper for Java %d.%d.%d+%d,", VERSION_FEATURE, VERSION_INTERIM, VERSION_UPDATE, VERSION_PATCH);
fprintf(stderr, "but jspawnhelper for Java %d.%d.%d+%d was found.\n", jdk_feature, jdk_interim, jdk_update, jdk_patch);
shutItDown();
}

Expand Down
25 changes: 21 additions & 4 deletions src/java.base/unix/native/libjava/ProcessImpl_md.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,9 @@ spawnChild(JNIEnv *env, jobject process, ChildStuff *c, const char *helperpath)
/* need to tell helper which fd is for receiving the childstuff
* and which fd to send response back on
*/
snprintf(buf1, sizeof(buf1), "%d:%d:%d:%s", c->childenv[0], c->childenv[1], c->fail[1], c->version);
snprintf(buf1, sizeof(buf1), "%d:%d:%d:%d.%d.%d.%d", c->childenv[0], c->childenv[1], c->fail[1],
c->version_feature, c->version_interim, c->version_update, c->version_patch);

/* NULL-terminated argv array.
* argv[0] contains path to jspawnhelper, to follow conventions.
* argv[1] contains the fd string as argument to jspawnhelper
Expand Down Expand Up @@ -609,8 +611,20 @@ startChild(JNIEnv *env, jobject process, ChildStuff *c, const char *helperpath)
}
}

#ifndef VERSION_NUMBER
#error VERSION_NUMBER must be defined
#ifndef VERSION_FEATURE
#error VERSION_FEATURE must be defined
#endif

#ifndef VERSION_INTERIM
#error VERSION_INTERIM must be defined
#endif

#ifndef VERSION_UPDATE
#error VERSION_UPDATE must be defined
#endif

#ifndef VERSION_PATCH
#error VERSION_PATCH must be defined
#endif

JNIEXPORT jint JNICALL
Expand Down Expand Up @@ -644,7 +658,10 @@ Java_java_lang_ProcessImpl_forkAndExec(JNIEnv *env,
c->argv = NULL;
c->envv = NULL;
c->pdir = NULL;
c->version = VERSION_NUMBER;
c->version_feature = VERSION_FEATURE;
c->version_interim = VERSION_INTERIM;
c->version_update = VERSION_UPDATE;
c->version_patch = VERSION_PATCH;

/* Convert prog + argBlock into a char ** argv.
* Add one word room for expansion of argv for use by
Expand Down
5 changes: 4 additions & 1 deletion src/java.base/unix/native/libjava/childproc.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ typedef struct _ChildStuff
const char *pdir;
int redirectErrorStream;
int sendAlivePing;
const char *version;
int version_feature;
int version_interim;
int version_update;
int version_patch;
} ChildStuff;

/* following used in addition when mode is SPAWN */
Expand Down

0 comments on commit 4dcd472

Please sign in to comment.