PatchSet 6725 Date: 2005/07/12 23:50:48 Author: robilad Branch: HEAD Tag: (none) Log: Added jni weak ref tests
2005-07-13 Dalibor Topic <[EMAIL PROTECTED]> * test/jni/Makefile.am: (check_PROGRAMS) Added jniWeakTest. (check_LTLIBRARIES, libjniweaklib_la_SOURCES, libjniweaklib_la_LDFLAGS, JAVA_CLASSES, CPATH, JNIWeakTest.class, jniWeakTest_SOURCES, jniWeakTest_LDADD, jniWeakTest_DEPENDECIES, jniWeakTest.o): New rules. (TESTS_ENVIRONMENT) Set BOOTCLASSPATH and KAFFELIBRARYPATH. (EXTRA_DIST) Added JNIWeakTest.java. * test/jni/Makefile.in: Regenerated. 2005-07-13 Guilhem Lavaux <[EMAIL PROTECTED]> * test/jni/JNIWeakTest.java, test/jni/jniWeakTest.c, test/jni/jniweaklib.c: New test. Members: ChangeLog:1.4249->1.4250 test/jni/JNIWeakTest.java:INITIAL->1.1 test/jni/Makefile.am:1.7->1.8 test/jni/Makefile.in:1.37->1.38 test/jni/jniWeakTest.c:INITIAL->1.1 test/jni/jniweaklib.c:INITIAL->1.1 Index: kaffe/ChangeLog diff -u kaffe/ChangeLog:1.4249 kaffe/ChangeLog:1.4250 --- kaffe/ChangeLog:1.4249 Tue Jul 12 13:35:38 2005 +++ kaffe/ChangeLog Tue Jul 12 23:50:48 2005 @@ -1,3 +1,20 @@ +2005-07-13 Dalibor Topic <[EMAIL PROTECTED]> + + * test/jni/Makefile.am: (check_PROGRAMS) Added jniWeakTest. + (check_LTLIBRARIES, libjniweaklib_la_SOURCES, libjniweaklib_la_LDFLAGS, + JAVA_CLASSES, CPATH, JNIWeakTest.class, jniWeakTest_SOURCES, + jniWeakTest_LDADD, jniWeakTest_DEPENDECIES, jniWeakTest.o): New rules. + (TESTS_ENVIRONMENT) Set BOOTCLASSPATH and KAFFELIBRARYPATH. + (EXTRA_DIST) Added JNIWeakTest.java. + + * test/jni/Makefile.in: Regenerated. + +2005-07-13 Guilhem Lavaux <[EMAIL PROTECTED]> + + * test/jni/JNIWeakTest.java, + test/jni/jniWeakTest.c, + test/jni/jniweaklib.c: New test. + 2005-07-12 Dalibor Topic <[EMAIL PROTECTED]> Resynced with GNU classpath. =================================================================== Checking out kaffe/test/jni/JNIWeakTest.java RCS: /home/cvs/kaffe/kaffe/test/jni/JNIWeakTest.java,v VERS: 1.1 *************** --- /dev/null Sun Aug 4 19:57:58 2002 +++ kaffe/test/jni/JNIWeakTest.java Tue Jul 12 23:55:28 2005 @@ -0,0 +1,23 @@ +public class JNIWeakTest +{ + static { + System.out.println("Loading jniweaklib..."); + System.loadLibrary("jniweaklib"); + } + + native Object testWeak(); + + static public void main(String args[]) + { + JNIWeakTest o = new JNIWeakTest(); + Object o2; + + o2 = o.testWeak(); + + if (o2 == o) + System.out.println("OK !"); + else + System.out.println("FAIL !"); + } +} + Index: kaffe/test/jni/Makefile.am diff -u kaffe/test/jni/Makefile.am:1.7 kaffe/test/jni/Makefile.am:1.8 --- kaffe/test/jni/Makefile.am:1.7 Sun Apr 10 17:26:31 2005 +++ kaffe/test/jni/Makefile.am Tue Jul 12 23:50:52 2005 @@ -6,7 +6,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file. -check_PROGRAMS= jniBase jniExecClass jniReflect +check_PROGRAMS= jniBase jniExecClass jniReflect jniWeakTest AM_CPPFLAGS= \ -I$(top_builddir)/include \ @@ -57,9 +57,64 @@ @LIBLTDL@ jniReflect_DEPENDENCIES= $(LIBKAFFEVM) -EXTRA_DIST = HelloWorldApp.class +# Okay, the following is a bit convulted and hackish, and makes me feel dizzy. +# But as I found no way to do it better, here it goes: +# +# We need to have a JNI library built just for make check purpose, i.e +# a) it may not be installed +# b) it may only build on check +# c) in must be dlopen-able for JNI library loading to work +# d) it must actually load the library and run it +# +# Solution for a and b: Fortunately, automake lets us build libtool libraries for +# make check purpose only using check_LTLIBRARIES. +# Solution for c: Unfortunately, it builds convenience libraries by default, which +# can not be dlopened. Adding -module or -static to LDFLAGS does not help, one +# needs to add -rpath with a fake absolute directory to it to make libtool build +# a dlopenable library. +# Solution for d: Adding . to KAFFELIBRARYPATH allows the resulting test to find the +# so created library. +# +# Amazingly enough, this actually seems to work. + +check_LTLIBRARIES = libjniweaklib.la + +libjniweaklib_la_SOURCES = jniweaklib.c + +libjniweaklib_la_LDFLAGS = \ + $(KLIBFLAGS) \ + -no-undefined \ + -module \ + -rpath $(nativedir) \ + -release $(PACKAGE_VERSION) + +JAVA_CLASSES = \ + JNIWeakTest.class + +CPATH = .:$(top_builddir)/libraries/javalib/rt.jar -TESTS_ENVIRONMENT = env `. $(top_builddir)/BUILD_ENVIRONMENT; sed 's/.*export \(.*\)/echo \1=$$\1/' < $(top_builddir)/BUILD_ENVIRONMENT | sh` +JNIWeakTest.class: $(srcdir)/JNIWeakTest.java + $(JIKES) -g -classpath $(CPATH) -d . $(srcdir)/JNIWeakTest.java + +jniWeakTest_SOURCES = jniWeakTest.c + +jniWeakTest_LDADD= \ + -dlopen $(top_builddir)/test/jni/libjniweaklib.la \ + $(DLOPEN_JAVA_LIBS) \ + $(LIBKAFFEVM) \ + $(LIBREPLACE) \ + $(LTLIBINTL) \ + @LIBLTDL@ + +jniWeakTest_DEPENDECIES = $(LIBKAFFEVM) libjniweaklib.la + +jniWeakTest.o: JNIWeakTest.class + +EXTRA_DIST = \ + JNIWeakTest.java \ + HelloWorldApp.class + +TESTS_ENVIRONMENT = env `BOOTCLASSPATH="."; export BOOTCLASSPATH; KAFFELIBRARYPATH="." ; export KAFFELIBRARYPATH ; . $(top_builddir)/BUILD_ENVIRONMENT; sed 's/.*export \(.*\)/echo \1=$$\1/' < $(top_builddir)/BUILD_ENVIRONMENT | sh` TESTS = $(check_PROGRAMS) CLEANFILES = *.fail *.out core *.core Index: kaffe/test/jni/Makefile.in diff -u kaffe/test/jni/Makefile.in:1.37 kaffe/test/jni/Makefile.in:1.38 --- kaffe/test/jni/Makefile.in:1.37 Sat May 14 21:47:09 2005 +++ kaffe/test/jni/Makefile.in Tue Jul 12 23:50:52 2005 @@ -21,7 +21,7 @@ # # See the file "license.terms" for information on usage and redistribution # of this file. -SOURCES = $(jniBase_SOURCES) $(jniExecClass_SOURCES) $(jniReflect_SOURCES) +SOURCES = $(libjniweaklib_la_SOURCES) $(jniBase_SOURCES) $(jniExecClass_SOURCES) $(jniReflect_SOURCES) $(jniWeakTest_SOURCES) srcdir = @srcdir@ top_srcdir = @top_srcdir@ @@ -46,7 +46,7 @@ build_triplet = @build@ host_triplet = @host@ check_PROGRAMS = jniBase$(EXEEXT) jniExecClass$(EXEEXT) \ - jniReflect$(EXEEXT) + jniReflect$(EXEEXT) jniWeakTest$(EXEEXT) subdir = test/jni DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -76,6 +76,9 @@ mkinstalldirs = $(SHELL) $(top_srcdir)/scripts/mkinstalldirs CONFIG_HEADER = $(top_builddir)/config/config.h CONFIG_CLEAN_FILES = +libjniweaklib_la_LIBADD = +am_libjniweaklib_la_OBJECTS = jniweaklib.lo +libjniweaklib_la_OBJECTS = $(am_libjniweaklib_la_OBJECTS) am_jniBase_OBJECTS = jniBase.$(OBJEXT) jniBase_OBJECTS = $(am_jniBase_OBJECTS) am__DEPENDENCIES_1 = @@ -90,6 +93,11 @@ jniExecClass_OBJECTS = $(am_jniExecClass_OBJECTS) am_jniReflect_OBJECTS = jniReflect.$(OBJEXT) jniReflect_OBJECTS = $(am_jniReflect_OBJECTS) +am_jniWeakTest_OBJECTS = jniWeakTest.$(OBJEXT) +jniWeakTest_OBJECTS = $(am_jniWeakTest_OBJECTS) +jniWeakTest_DEPENDENCIES = $(top_builddir)/test/jni/libjniweaklib.la \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_4) \ + $(am__DEPENDENCIES_5) $(am__DEPENDENCIES_1) DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/config depcomp = $(SHELL) $(top_srcdir)/scripts/depcomp am__depfiles_maybe = depfiles @@ -100,10 +108,12 @@ $(AM_CFLAGS) $(CFLAGS) LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ -SOURCES = $(jniBase_SOURCES) $(jniExecClass_SOURCES) \ - $(jniReflect_SOURCES) -DIST_SOURCES = $(jniBase_SOURCES) $(jniExecClass_SOURCES) \ - $(jniReflect_SOURCES) +SOURCES = $(libjniweaklib_la_SOURCES) $(jniBase_SOURCES) \ + $(jniExecClass_SOURCES) $(jniReflect_SOURCES) \ + $(jniWeakTest_SOURCES) +DIST_SOURCES = $(libjniweaklib_la_SOURCES) $(jniBase_SOURCES) \ + $(jniExecClass_SOURCES) $(jniReflect_SOURCES) \ + $(jniWeakTest_SOURCES) ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -423,8 +433,54 @@ @LIBLTDL@ jniReflect_DEPENDENCIES = $(LIBKAFFEVM) -EXTRA_DIST = HelloWorldApp.class -TESTS_ENVIRONMENT = env `. $(top_builddir)/BUILD_ENVIRONMENT; sed 's/.*export \(.*\)/echo \1=$$\1/' < $(top_builddir)/BUILD_ENVIRONMENT | sh` + +# Okay, the following is a bit convulted and hackish, and makes me feel dizzy. +# But as I found no way to do it better, here it goes: +# +# We need to have a JNI library built just for make check purpose, i.e +# a) it may not be installed +# b) it may only build on check +# c) in must be dlopen-able for JNI library loading to work +# d) it must actually load the library and run it +# +# Solution for a and b: Fortunately, automake lets us build libtool libraries for +# make check purpose only using check_LTLIBRARIES. +# Solution for c: Unfortunately, it builds convenience libraries by default, which +# can not be dlopened. Adding -module or -static to LDFLAGS does not help, one +# needs to add -rpath with a fake absolute directory to it to make libtool build +# a dlopenable library. +# Solution for d: Adding . to KAFFELIBRARYPATH allows the resulting test to find the +# so created library. +# +# Amazingly enough, this actually seems to work. +check_LTLIBRARIES = libjniweaklib.la +libjniweaklib_la_SOURCES = jniweaklib.c +libjniweaklib_la_LDFLAGS = \ + $(KLIBFLAGS) \ + -no-undefined \ + -module \ + -rpath $(nativedir) \ + -release $(PACKAGE_VERSION) + +JAVA_CLASSES = \ + JNIWeakTest.class + +CPATH = .:$(top_builddir)/libraries/javalib/rt.jar +jniWeakTest_SOURCES = jniWeakTest.c +jniWeakTest_LDADD = \ + -dlopen $(top_builddir)/test/jni/libjniweaklib.la \ + $(DLOPEN_JAVA_LIBS) \ + $(LIBKAFFEVM) \ + $(LIBREPLACE) \ + $(LTLIBINTL) \ + @LIBLTDL@ + +jniWeakTest_DEPENDECIES = $(LIBKAFFEVM) libjniweaklib.la +EXTRA_DIST = \ + JNIWeakTest.java \ + HelloWorldApp.class + +TESTS_ENVIRONMENT = env `BOOTCLASSPATH="."; export BOOTCLASSPATH; KAFFELIBRARYPATH="." ; export KAFFELIBRARYPATH ; . $(top_builddir)/BUILD_ENVIRONMENT; sed 's/.*export \(.*\)/echo \1=$$\1/' < $(top_builddir)/BUILD_ENVIRONMENT | sh` TESTS = $(check_PROGRAMS) CLEANFILES = *.fail *.out core *.core all: all-am @@ -461,6 +517,17 @@ $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +clean-checkLTLIBRARIES: + -test -z "$(check_LTLIBRARIES)" || rm -f $(check_LTLIBRARIES) + @list='$(check_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libjniweaklib.la: $(libjniweaklib_la_OBJECTS) $(libjniweaklib_la_DEPENDENCIES) + $(LINK) $(libjniweaklib_la_LDFLAGS) $(libjniweaklib_la_OBJECTS) $(libjniweaklib_la_LIBADD) $(LIBS) + clean-checkPROGRAMS: @list='$(check_PROGRAMS)'; for p in $$list; do \ f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ @@ -476,6 +543,9 @@ jniReflect$(EXEEXT): $(jniReflect_OBJECTS) $(jniReflect_DEPENDENCIES) @rm -f jniReflect$(EXEEXT) $(LINK) $(jniReflect_LDFLAGS) $(jniReflect_OBJECTS) $(jniReflect_LDADD) $(LIBS) +jniWeakTest$(EXEEXT): $(jniWeakTest_OBJECTS) $(jniWeakTest_DEPENDENCIES) + @rm -f jniWeakTest$(EXEEXT) + $(LINK) $(jniWeakTest_LDFLAGS) $(jniWeakTest_OBJECTS) $(jniWeakTest_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -486,6 +556,8 @@ @AMDEP_TRUE@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@ @AMDEP_TRUE@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@ @AMDEP_TRUE@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@ [EMAIL PROTECTED]@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@ [EMAIL PROTECTED]@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@ .c.o: @am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ @@ -667,7 +739,7 @@ fi; \ done check-am: all-am - $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) + $(MAKE) $(AM_MAKEFLAGS) $(check_LTLIBRARIES) $(check_PROGRAMS) $(MAKE) $(AM_MAKEFLAGS) check-TESTS check: check-am all-am: Makefile @@ -699,8 +771,8 @@ @echo "it deletes files that may require special tools to rebuild." clean: clean-am -clean-am: clean-checkPROGRAMS clean-generic clean-libtool \ - mostlyclean-am +clean-am: clean-checkLTLIBRARIES clean-checkPROGRAMS clean-generic \ + clean-libtool mostlyclean-am distclean: distclean-am -rm -rf ./$(DEPDIR) @@ -749,17 +821,22 @@ uninstall-am: uninstall-info-am .PHONY: CTAGS GTAGS all all-am check check-TESTS check-am clean \ - clean-checkPROGRAMS clean-generic clean-libtool ctags \ - distclean distclean-compile distclean-generic \ - distclean-libtool distclean-tags distdir dvi dvi-am html \ - html-am info info-am install install-am install-data \ - install-data-am install-exec install-exec-am install-info \ - install-info-am install-man install-strip installcheck \ - installcheck-am installdirs maintainer-clean \ + clean-checkLTLIBRARIES clean-checkPROGRAMS clean-generic \ + clean-libtool ctags distclean distclean-compile \ + distclean-generic distclean-libtool distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-exec install-exec-am \ + install-info install-info-am install-man install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-compile \ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ tags uninstall uninstall-am uninstall-info-am + +JNIWeakTest.class: $(srcdir)/JNIWeakTest.java + $(JIKES) -g -classpath $(CPATH) -d . $(srcdir)/JNIWeakTest.java + +jniWeakTest.o: JNIWeakTest.class # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: =================================================================== Checking out kaffe/test/jni/jniWeakTest.c RCS: /home/cvs/kaffe/kaffe/test/jni/jniWeakTest.c,v VERS: 1.1 *************** --- /dev/null Sun Aug 4 19:57:58 2002 +++ kaffe/test/jni/jniWeakTest.c Tue Jul 12 23:55:28 2005 @@ -0,0 +1,98 @@ +/* + * jniTestWeak.c + * + * Copyright (c) 2005 + * The Kaffe.org's developers. See ChangeLog for details. + * + * See the file "license.terms" for information on usage and redistribution + * of this file. + */ +#include <jni.h> +#include <string.h> +#include <stdlib.h> +#include <stdio.h> +#include <ltdl.h> + +static char *concatString(const char *s1, const char *s2) +{ + char *s; + + if (s1 == NULL) + s1 = ""; + if (s2 == NULL) + s2 = ""; + s = (char *) malloc(strlen(s1) + strlen(s2) + 1); + return strcat(strcpy(s, s1), s2); +} + +int main(void) +{ + JavaVMInitArgs vmargs; + JavaVM *vm; + JNIEnv *env; + JavaVMOption myoptions[3]; + jclass cls, scls; + jarray args; + jmethodID mainid; + + /* set up libtool/libltdl dlopen emulation */ + myoptions[0].optionString = concatString("-Xbootclasspath:", getenv("BOOTCLASSPATH")); + myoptions[1].optionString = concatString("-Xclasspath:", CLASSPATH_SOURCE_DIR); + myoptions[2].optionString = "-Xvmdebug:NATIVELIB"; + + vmargs.version = JNI_VERSION_1_2; + if (JNI_GetDefaultJavaVMInitArgs (&vmargs) < 0) + { + fprintf(stderr, " Cannot retrieve default arguments\n"); + return 1; + } + + vmargs.nOptions = 2; + vmargs.options = myoptions; + + if (JNI_CreateJavaVM (&vm, (void **)&env, &vmargs) < 0) + { + fprintf(stderr, " Cannot create the Java VM\n"); + return 1; + } + + cls = (*env)->FindClass(env, "JNIWeakTest"); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + fprintf(stderr, "FindClass has failed\n"); + return 1; + } + + mainid = (*env)->GetStaticMethodID(env, cls, "main", "([Ljava/lang/String;)V"); + if ((*env)->ExceptionOccurred(env)) + { + fprintf(stderr, "GetStaticMethodID has failed\n"); + return 1; + } + + scls = (*env)->FindClass(env, "java/lang/String"); + if ((*env)->ExceptionOccurred(env)) + { + fprintf(stderr, "FindClass(java/lang/String) has failed\n"); + return 1; + } + + args = (*env)->NewObjectArray(env, 0, scls, 0); + if ((*env)->ExceptionOccurred(env)) + { + fprintf(stderr, "NewObjectArray has failed\n"); + return 1; + } + + (*env)->CallStaticVoidMethod(env, cls, mainid, args); + if ((*env)->ExceptionOccurred(env)) + { + fprintf(stderr, "CallStaticMethod has failed\n"); + return 1; + } + + (*vm)->DestroyJavaVM(vm); + + return 0; +} =================================================================== Checking out kaffe/test/jni/jniweaklib.c RCS: /home/cvs/kaffe/kaffe/test/jni/jniweaklib.c,v VERS: 1.1 *************** --- /dev/null Sun Aug 4 19:57:58 2002 +++ kaffe/test/jni/jniweaklib.c Tue Jul 12 23:55:28 2005 @@ -0,0 +1,7 @@ +#include <jni.h> + +JNIEXPORT jobject JNICALL +Java_JNIWeakTest_testWeak(JNIEnv *env, jobject obj) +{ + return (*env)->NewWeakGlobalRef(env, obj); +} _______________________________________________ kaffe mailing list kaffe@kaffe.org http://kaffe.org/cgi-bin/mailman/listinfo/kaffe