diff --git a/makefile b/makefile index 7e1ed6de37..fa197dc8c6 100755 --- a/makefile +++ b/makefile @@ -86,6 +86,8 @@ ifeq ($(build-platform),darwin) library-path-variable = DYLD_LIBRARY_PATH endif +library-path = $(library-path-variable)=$(test-build) + ifneq ($(openjdk),) openjdk-arch = $(arch) ifeq ($(arch),x86_64) @@ -123,10 +125,10 @@ ifneq ($(openjdk),) test-executable = $(shell pwd)/$(executable-dynamic) ifeq ($(build-platform),darwin) library-path = \ - $(library-path-variable)=$(build):$(openjdk)/jre/lib + $(library-path-variable)=$(test-build):$(build):$(openjdk)/jre/lib else library-path = \ - $(library-path-variable)=$(build):$(openjdk)/jre/lib/$(openjdk-arch) + $(library-path-variable)=$(test-build):$(build):$(openjdk)/jre/lib/$(openjdk-arch) endif javahome = "$$($(native-path) "$(openjdk)/jre")" endif @@ -148,8 +150,8 @@ ifeq ($(use-clang),true) build-cxx = clang -std=c++11 build-cc = clang else - build-cxx = g++ - build-cc = gcc + build-cxx = g++-4.7 + build-cc = gcc-4.7 endif mflag = @@ -187,7 +189,7 @@ warnings = -Wall -Wextra -Werror -Wunused-parameter -Winit-self \ target-cflags = -DTARGET_BYTES_PER_WORD=$(pointer-size) -common-cflags = $(warnings) -fno-rtti -fno-exceptions \ +common-cflags = $(warnings) -fno-rtti -fno-exceptions -I$(classpath-src) \ "-I$(JAVA_HOME)/include" -idirafter $(src) -I$(build) $(classpath-cflags) \ -D__STDC_LIMIT_MACROS -D_JNI_IMPLEMENTATION_ -DAVIAN_VERSION=\"$(version)\" \ -DUSE_ATOMIC_OPERATIONS -DAVIAN_JAVA_HOME=\"$(javahome)\" \ @@ -800,9 +802,12 @@ vm-classes = \ test-support-sources = $(shell find $(test)/avian/ -name '*.java') test-sources = $(wildcard $(test)/*.java) +test-cpp-sources = $(wildcard $(test)/*.cpp) test-sources += $(test-support-sources) test-support-classes = $(call java-classes, $(test-support-sources),$(test),$(test-build)) test-classes = $(call java-classes,$(test-sources),$(test),$(test-build)) +test-cpp-objects = $(call cpp-objects,$(test-cpp-sources),$(test),$(test-build)) +test-library = $(test-build)/libtest.so test-dep = $(test-build).dep test-extra-sources = $(wildcard $(test)/extra/*.java) @@ -927,7 +932,7 @@ $(classpath-dep): $(classpath-sources) $(test-build)/%.class: $(test)/%.java @echo $(<) -$(test-dep): $(test-sources) +$(test-dep): $(test-sources) $(test-library) @echo "compiling test classes" @mkdir -p $(test-build) files="$(shell $(MAKE) -s --no-print-directory build=$(build) $(test-classes))"; \ @@ -962,6 +967,19 @@ endef $(vm-cpp-objects): $(build)/%.o: $(src)/%.cpp $(vm-depends) $(compile-object) +$(test-cpp-objects): $(test-build)/%.o: $(test)/%.cpp $(vm-depends) + $(compile-object) + +$(test-library): $(test-cpp-objects) + @echo "linking $(@)" +ifdef msvc + $(ld) $(shared) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \ + -IMPLIB:$(test-build)/$(name).lib -MANIFESTFILE:$(@).manifest + $(mt) -manifest $(@).manifest -outputresource:"$(@);2" +else + $(ld) $(^) $(shared) $(lflags) -o $(@) +endif + $(build)/%.o: $(lzma)/C/%.c @echo "compiling $(@)" @mkdir -p $(dir $(@)) diff --git a/test/JNI.java b/test/JNI.java new file mode 100644 index 0000000000..edd52364b5 --- /dev/null +++ b/test/JNI.java @@ -0,0 +1,33 @@ +public class JNI { + static { + System.loadLibrary("test"); + } + + private static void expect(boolean v) { + if (! v) throw new RuntimeException(); + } + + private static native double addDoubles + (double a1, double a2, double a3, double a4, double a5, double a6, + double a7, double a8, double a9, double a10, double a11, double a12, + double a13, double a14, double a15, double a16, double a17, double a18, + double a19, double a20); + + private static native float addFloats + (float a1, float a2, float a3, float a4, float a5, float a6, + float a7, float a8, float a9, float a10, float a11, float a12, + float a13, float a14, float a15, float a16, float a17, float a18, + float a19, float a20); + + public static void main(String[] args) { + expect(addDoubles + (1.0d, 2.0d, 3.0d, 4.0d, 5.0d, 6.0d, 7.0d, 8.0d, 9.0d, 10.0d, 11.0d, + 12.0d, 13.0d, 14.0d, 15.0d, 16.0d, 17.0d, 18.0d, 19.0d, 20.0d) + == 210.0d); + + expect(addFloats + (1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, + 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, 20.0f) + == 210.0f); + } +} diff --git a/test/jni.cpp b/test/jni.cpp new file mode 100644 index 0000000000..a4bfbf8093 --- /dev/null +++ b/test/jni.cpp @@ -0,0 +1,26 @@ +#include +#include "jni-util.h" + +extern "C" JNIEXPORT jdouble JNICALL +Java_JNI_addDoubles +(JNIEnv*, jclass, + jdouble a1, jdouble a2, jdouble a3, jdouble a4, jdouble a5, jdouble a6, + jdouble a7, jdouble a8, jdouble a9, jdouble a10, jdouble a11, jdouble a12, + jdouble a13, jdouble a14, jdouble a15, jdouble a16, jdouble a17, jdouble a18, + jdouble a19, jdouble a20) +{ + return a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12 + a13 + + a14 + a15 + a16 + a17 + a18 + a19 + a20; +} + +extern "C" JNIEXPORT jfloat JNICALL +Java_JNI_addFloats +(JNIEnv*, jclass, + jfloat a1, jfloat a2, jfloat a3, jfloat a4, jfloat a5, jfloat a6, + jfloat a7, jfloat a8, jfloat a9, jfloat a10, jfloat a11, jfloat a12, + jfloat a13, jfloat a14, jfloat a15, jfloat a16, jfloat a17, jfloat a18, + jfloat a19, jfloat a20) +{ + return a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12 + a13 + + a14 + a15 + a16 + a17 + a18 + a19 + a20; +}