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

requested changes to java.c, configure.ac, and internal state to cobl… #150

Closed
wants to merge 9 commits into from
73 changes: 47 additions & 26 deletions cobc/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ static struct literal_list *literal_cache = NULL;
static struct field_list *field_cache = NULL;
static struct field_list *local_field_cache = NULL;
static struct call_list *call_cache = NULL;
extern JavaVM *jvm;
extern JNIEnv *env;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure these are needed in the compiler (cobc) itself.

static struct call_list *func_call_cache = NULL;
static struct static_call_list *static_call_cache = NULL;
static struct base_list *base_cache = NULL;
Expand Down Expand Up @@ -387,6 +389,21 @@ lookup_source (const char *p)
return source_id++;
}

static void lookup_java_call(const char *p) {
struct call_list *clp;

for (clp = call_cache; clp; clp = clp->next) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's another list you need to manipulate in this function. Something like call_java_cache.

if (strcmp(p, clp->call_name) == 0) {
return;
}
}

clp = (struct call_list *)cob_malloc(sizeof(struct call_list));
clp->call_name = p;
clp->next = call_cache;
call_cache = clp;
}

static void
lookup_call (const char *p)
{
Expand Down Expand Up @@ -7529,38 +7546,42 @@ output_call (struct cb_call *p)
}
} else {
/* Dynamic link */
if(module_type == COB_MODULE_TYPE_FUNCTION && strmcmp ("Java.", s, 6) == 0) {
(void*)func = cob_lookup_static_java_method(s + 6); /* <- java.c, declared in coblocal.h */
if(func != NULL) {
insert(name, func, NULL, NULL, NULL, 1);
resolve_error = NULL;
return func;
}
}
if (name_is_literal_or_prototype) {
s = get_program_id_str (p->name);
name_str = cb_encode_program_id (s, 1, cb_fold_call);
lookup_call (name_str);
callname = s;
#ifdef HAVE_JNI
/* Distinguishing lookup from call*/
if(strncmp("Java.", name, 6) == 0) {
void static_java_method = lookup_static_call(s + 6, p->argv[0], COB_RETURN_NULL);
cob_call_java(static_java_method);
} else {
// rest
#endif
// we need to use lookup_java_call instead (implement)
lookup_java_call (name_str);
callname = s;

output_line ("if (call_%s.funcvoid == NULL || cob_glob_ptr->cob_physical_cancel)", name_str);
output_block_open ();
output_prefix ();
output_line ("if (call_%s.funcvoid == NULL || cob_glob_ptr->cob_physical_cancel)", name_str);
output_block_open ();
output_prefix ();

nlp = find_nested_prog_with_id (name_str);
if (nlp) {
output ("call_%s.funcint = %s_%d__;",
name_str, name_str,
nlp->nested_prog->toplev_count);
} else {
output ("call_%s.funcvoid = ", name_str);
output ("cob_resolve_cobol (");
output_string ((const unsigned char *)s,
(int)strlen (s), 0);
output (", %d, %d);", cb_fold_call, !p->stmt1);
nlp = find_nested_prog_with_id (name_str);
if (nlp) {
output ("call_%s.funcint = %s_%d__;",
name_str, name_str,
nlp->nested_prog->toplev_count);
} else {
output ("call_%s.funcvoid = ", name_str);
output ("cob_resolve_cobol (");
output_string ((const unsigned char *)s,
(int)strlen (s), 0);
output (", %d, %d);", cb_fold_call, !p->stmt1);
}
output_newline ();
output_block_close ();
#ifdef HAVE_JNI
}
output_newline ();
output_block_close ();
#endif
} else {
name_str = NULL;
needs_unifunc = 1;
Expand Down
25 changes: 13 additions & 12 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -503,25 +503,26 @@ AC_CHECK_HEADERS([jni_md.h], [],
# optional:
AC_CHECK_HEADERS([sys/time.h locale.h fcntl.h dlfcn.h sys/wait.h sys/sysmacros.h])
AC_ARG_VAR([JAVA_HOME], [Java Runtime Environment (JRE) location])
AC_ARG_ENABLE([java-feature],
[AC_HELP_STRING([--disable-java-feature],
[disable Java feature])])
AC_ARG_ENABLE([java],
[AC_HELP_STRING([--disable-java],
[disable Java Interoperatibility])])
case $target_cpu in
x86_64) JVM_ARCH=amd64 ;;
i?86) JVM_ARCH=i386 ;;
*) JVM_ARCH=$target_cpu ;;
esac
AC_SUBST([JVM_ARCH])
AS_IF([test X$enable_java_feature != Xno],
[AS_IF([test X$have_jni != Xyes],
[AC_MSG_FAILURE([The Java Native Interface is required for Java feature.])])
AS_IF([test -z "$JAVA_HOME"],
[AC_MSG_WARN([JAVA_HOME has not been set. JAVA_HOME must be set at run time to locate libjvm.])],
[save_LDFLAGS=$LDFLAGS
LDFLAGS="-L$JAVA_HOME/lib/$JVM_ARCH/client -L$JAVA_HOME/lib/$JVM_ARCH/server $LDFLAGS"
AC_CHECK_LIB([jvm], [JNI_CreateJavaVM], [LIBS=$LIBS],
[AC_MSG_WARN([no libjvm found at JAVA_HOME])])
LDFLAGS=$save_LDFLAGS
[AS_IF([test X$have_jni != Xyes],
[AC_MSG_FAILURE([The Java Native Interface is required for Java feature.])])
AS_IF([test -z "$JAVA_HOME"],
[AC_MSG_WARN([JAVA_HOME has not been set. JAVA_HOME must be set at run time to locate libjvm.])],
[save_LDFLAGS=$LDFLAGS
LDFLAGS="-L$JAVA_HOME/lib/$JVM_ARCH/client -L$JAVA_HOME/lib/$JVM_ARCH/server $LDFLAGS"
AC_CHECK_LIB([jvm], [JNI_CreateJavaVM], [LIBS=$LIBS],
[AC_MSG_WARN([no libjvm found at JAVA_HOME])])
AC_DEFINE([WITH_JNI], [1])
LDFLAGS=$save_LDFLAGS
])])

# Checks for typedefs, structures, and compiler characteristics.
Expand Down
8 changes: 0 additions & 8 deletions libcob/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -1383,14 +1383,6 @@ cob_call (const char *name, const int argc, void **argv)
/* LCOV_EXCL_STOP */
unifunc.funcvoid = cob_resolve_cobol (name, 0, 1);
pargv = cob_malloc (MAX_CALL_FIELD_PARAMS * sizeof(void *));

#ifndef HAVE_JNI
/* Distinguishing lookup from call*/
if(strncmp("Java.", name, 6) == 0) {
static_java_method = cob_lookup_static_method(s + 6, argv);
cob_call_java_static_method(method);
}
/*HAVE_JNI*/
/* Set number of parameters */
cobglobptr->cob_call_params = argc;
cobglobptr->cob_call_from_c = 1;
Expand Down
23 changes: 0 additions & 23 deletions libcob/coblocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,29 +451,6 @@ COB_EXPIMP void cob_field_to_string (const cob_field *, void *,
COB_HIDDEN void cob_parameter_check (const char *, const int);
COB_HIDDEN char* cob_get_strerror (void);

// COB_HIDDEN JNIEnv* cob_create_vm ();
// COB_HIDDEN void cob_handle_error (JavaVM* jvm, char* methodSig);
// COB_HIDDEN char* cob_gen_method_sig (const char** paramType, int paramCount, const char** returnType);

#ifdef COB_WITH_JNI
COB_EXPIMP cob_call_java_static_method(const char *className, const char* methodName, const char *returnType, const char** paramTypes, int paramCount, jvalue *args)
#endif

// COB_HIDDEN void cob_lookup_static_method (JNIEnv* env, JavaVM* jvm, const char *className, const char *methodName,
// const char *methodSig, const char *returnType, const char** paramTypes, int paramCount);
// COB_HIDDEN static char* cob_gen_method_sig(JNIEnv *env, jobjectArray paramTypes, const char *className, const char *returnType);

// COB_HIDDEN jobjectArray cob_get_method_parameter_types(JNIEnv* env, jclass clazz, const char* methodName);

// COB_HIDDEN void cob_static_method (JNIEnv* env, JavaVM* jvm, jclass cls, jmethodID mid);
COB_HIDDEN void cob_call_java_static_method (JNIEnv *env, JavaVM *jvm, const char *className, const char *methodName, jobject obj, jstring input);

COB_HIDDEN jobject cob_create_java_object(JNIEnv* env, const char* className, const char* constructorSig, jvalue* args);
COB_HIDDEN void cob_set_java_field(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig, jvalue value);

COB_HIDDEN jvalue cob_get_java_field(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig);
COB_HIDDEN jvalue cob_call_java_method(JNIEnv* env, jobject obj, const char* methodName, const char* methodSig, jvalue* args);

enum cob_case_modifier {
CCM_NONE,
CCM_LOWER,
Expand Down
9 changes: 6 additions & 3 deletions libcob/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1294,12 +1294,15 @@ struct cob_call_struct {
cob_call_union cob_cstr_cancel; /* Cancel entry */
};

#ifdef COB_HAVE_JNI
COB_EXPIMP cob_call_java_static_method(const char *className, const char* methodName, const char *returnType, const char** paramTypes, int paramCount, jvalue *args)
#ifdef HAVE_JNI
typedef struct __cob_java_static_method {
jclass cls;
jmethodID mid;
} cob_java_static_method_handle;
} cob_java_handle;

COB_EXPIMP cob_java_handle* cob_resolve_java (const char* class_name, const char* method_name,
const char *type_signature);
COB_EXPIMP int cob_call_java (const cob_java_handle* nargs);
#endif

/* Screen structure */
Expand Down
Loading