Merge branch 'master' of ssh://oss.readytalk.com/var/local/git/avian

This commit is contained in:
dain 2008-10-13 09:48:04 -06:00
commit 8549ab856e
7 changed files with 133 additions and 51 deletions

View File

@ -12,6 +12,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
#include <unistd.h> #include <unistd.h>
#include "jni.h" #include "jni.h"

View File

@ -93,6 +93,11 @@ public class StringBuffer implements CharSequence {
return this; return this;
} }
public synchronized StringBuffer insert(int i, int v) {
sb.insert(i, v);
return this;
}
public synchronized StringBuffer delete(int start, int end) { public synchronized StringBuffer delete(int start, int end) {
sb.delete(start, end); sb.delete(start, end);
return this; return this;

View File

@ -154,6 +154,10 @@ public class StringBuilder implements CharSequence {
return insert(i, new String(new char[] { c }, 0, 1, false)); return insert(i, new String(new char[] { c }, 0, 1, false));
} }
public StringBuilder insert(int i, int v) {
return insert(i, String.valueOf(v));
}
public StringBuilder delete(int start, int end) { public StringBuilder delete(int start, int end) {
if (start >= end) { if (start >= end) {
return this; return this;

View File

@ -45,6 +45,12 @@ public abstract class Calendar {
fields[field] = value; fields[field] = value;
} }
public void set(int year, int month, int date) {
set(YEAR, year);
set(MONTH, month);
set(DAY_OF_MONTH, date);
}
public void setTime(Date date) { public void setTime(Date date) {
time = date.getTime(); time = date.getTime();
} }

View File

@ -3,18 +3,15 @@ MAKEFLAGS = -s
name = avian name = avian
version = 0.1.1 version = 0.1.1
build-arch = $(shell uname -m) build-arch = $(shell uname -m | sed 's/^i.86$$/i386/')
ifeq ($(build-arch),i586)
build-arch = i386
endif
ifeq ($(build-arch),i686)
build-arch = i386
endif
build-platform = $(shell uname -s | tr [:upper:] [:lower:]) build-platform = \
$(shell uname -s | tr [:upper:] [:lower:] \
| sed 's/^mingw32.*$$/mingw32/' \
| sed 's/^cygwin.*$$/cygwin/')
arch = $(build-arch) arch = $(build-arch)
platform = $(build-platform) platform = $(subst cygwin,windows,$(subst mingw32,windows,$(build-platform)))
ifeq ($(platform),windows) ifeq ($(platform),windows)
arch = i386 arch = i386
@ -41,12 +38,13 @@ cxx = $(build-cxx)
cc = $(build-cc) cc = $(build-cc)
ar = ar ar = ar
ranlib = ranlib ranlib = ranlib
dlltool = dlltool
objcopy = objcopy objcopy = objcopy
vg = nice valgrind --num-callers=32 --db-attach=yes --freelist-vol=100000000 vg = nice valgrind --num-callers=32 --db-attach=yes --freelist-vol=100000000
vg += --leak-check=full --suppressions=valgrind.supp vg += --leak-check=full --suppressions=valgrind.supp
db = gdb --args db = gdb --args
javac = javac javac = "$(JAVA_HOME)/bin/javac"
jar = jar jar = "$(JAVA_HOME)/bin/jar"
strip = : strip = :
strip-all = --strip-all strip-all = --strip-all
@ -55,17 +53,19 @@ rdynamic = -rdynamic
warnings = -Wall -Wextra -Werror -Wunused-parameter -Winit-self warnings = -Wall -Wextra -Werror -Wunused-parameter -Winit-self
common-cflags = $(warnings) -fno-rtti -fno-exceptions \ common-cflags = $(warnings) -fno-rtti -fno-exceptions \
-I$(JAVA_HOME)/include -idirafter $(src) -I$(native-build) \ "-I$(JAVA_HOME)/include" -idirafter $(src) -I$(native-build) \
-D__STDC_LIMIT_MACROS -D_JNI_IMPLEMENTATION_ -DAVIAN_VERSION=\"$(version)\" \ -D__STDC_LIMIT_MACROS -D_JNI_IMPLEMENTATION_ -DAVIAN_VERSION=\"$(version)\" \
-DBOOT_CLASSPATH=\"[classpathJar]\" -DBOOT_CLASSPATH=\"[classpathJar]\"
build-cflags = $(common-cflags) -fPIC -fvisibility=hidden \ build-cflags = $(common-cflags) -fPIC -fvisibility=hidden \
-I$(JAVA_HOME)/include/linux -I$(src) -pthread "-I$(JAVA_HOME)/include/linux" -I$(src) -pthread
cflags = $(build-cflags) cflags = $(build-cflags)
common-lflags = -lm -lz -lstdc++ common-lflags = -lm -lz -lstdc++
build-lflags =
lflags = $(common-lflags) -lpthread -ldl lflags = $(common-lflags) -lpthread -ldl
system = posix system = posix
@ -80,6 +80,8 @@ so-suffix = .so
shared = -shared shared = -shared
native-path = echo
ifeq ($(arch),i386) ifeq ($(arch),i386)
object-arch = i386 object-arch = i386
object-format = elf32-i386 object-format = elf32-i386
@ -87,8 +89,7 @@ ifeq ($(arch),i386)
endif endif
ifeq ($(platform),darwin) ifeq ($(platform),darwin)
build-cflags = $(common-cflags) -fPIC -fvisibility=hidden \ build-cflags = $(common-cflags) -fPIC -fvisibility=hidden -I$(src)
-I$(JAVA_HOME)/include/linux -I$(src)
lflags = $(common-lflags) -ldl -framework CoreFoundation lflags = $(common-lflags) -ldl -framework CoreFoundation
rdynamic = rdynamic =
strip-all = -S -x strip-all = -S -x
@ -98,25 +99,37 @@ ifeq ($(platform),darwin)
endif endif
ifeq ($(platform),windows) ifeq ($(platform),windows)
inc = $(root)/win32/include inc = "$(root)/win32/include"
lib = $(root)/win32/lib lib = "$(root)/win32/lib"
system = windows system = windows
object-format = pe-i386 object-format = pe-i386
so-prefix = so-prefix =
so-suffix = .dll so-suffix = .dll
exe-suffix = .exe
lflags = -L$(lib) $(common-lflags) -lws2_32 -mwindows -mconsole
cflags = $(common-cflags) -I$(inc)
ifeq (,$(filter mingw32 cygwin,$(build-platform)))
cxx = i586-mingw32msvc-g++ cxx = i586-mingw32msvc-g++
cc = i586-mingw32msvc-gcc cc = i586-mingw32msvc-gcc
dlltool = i586-mingw32msvc-dlltool dlltool = i586-mingw32msvc-dlltool
ar = i586-mingw32msvc-ar ar = i586-mingw32msvc-ar
ranlib = i586-mingw32msvc-ranlib ranlib = i586-mingw32msvc-ranlib
objcopy = i586-mingw32msvc-objcopy objcopy = i586-mingw32msvc-objcopy
else
rdynamic = -Wl,--export-dynamic build-cflags = $(common-cflags) \
lflags = -L$(lib) $(common-lflags) -lws2_32 -mwindows -mconsole "-I$(JAVA_HOME)/include/win32" -I$(src) -mthreads
cflags = $(common-cflags) -I$(inc) ifeq ($(build-platform),cygwin)
build-lflags += -mno-cygwin
build-cflags += -mno-cygwin
lflags += -mno-cygwin
cflags += -mno-cygwin
native-path = cygpath -m
endif
endif
endif endif
ifeq ($(mode),debug) ifeq ($(mode),debug)
@ -214,9 +227,9 @@ generator-objects = \
generator = $(native-build)/generator generator = $(native-build)/generator
static-library = $(native-build)/lib$(name).a static-library = $(native-build)/lib$(name).a
executable = $(native-build)/$(name) executable = $(native-build)/$(name)${exe-suffix}
dynamic-library = $(native-build)/$(so-prefix)$(name)$(so-suffix) dynamic-library = $(native-build)/$(so-prefix)$(name)$(so-suffix)
executable-dynamic = $(native-build)/$(name)-dynamic executable-dynamic = $(native-build)/$(name)-dynamic${exe-suffix}
classpath-sources = $(shell find $(classpath) -name '*.java') classpath-sources = $(shell find $(classpath) -name '*.java')
classpath-classes = \ classpath-classes = \
@ -255,7 +268,7 @@ vg: build
.PHONY: test .PHONY: test
test: build test: build
/bin/bash $(test)/test.sh 2>/dev/null \ /bin/sh $(test)/test.sh 2>/dev/null \
$(executable) $(mode) "$(flags)" \ $(executable) $(mode) "$(flags)" \
$(call class-names,$(test-build),$(test-classes)) $(call class-names,$(test-build),$(test-classes))
@ -293,7 +306,7 @@ $(classpath-dep): $(classpath-sources)
@echo "compiling classpath classes" @echo "compiling classpath classes"
@mkdir -p $(dir $(@)) @mkdir -p $(dir $(@))
$(javac) -d $(dir $(@)) -bootclasspath $(classpath-build) \ $(javac) -d $(dir $(@)) -bootclasspath $(classpath-build) \
$(shell make -s --no-print-directory $(classpath-classes)) $(shell $(MAKE) -s --no-print-directory $(classpath-classes))
@touch $(@) @touch $(@)
$(test-build)/%.class: $(test)/%.java $(test-build)/%.class: $(test)/%.java
@ -303,7 +316,7 @@ $(test-dep): $(test-sources)
@echo "compiling test classes" @echo "compiling test classes"
@mkdir -p $(dir $(@)) @mkdir -p $(dir $(@))
$(javac) -d $(dir $(@)) -bootclasspath $(classpath-build) \ $(javac) -d $(dir $(@)) -bootclasspath $(classpath-build) \
$(shell make -s --no-print-directory $(test-classes)) $(shell $(MAKE) -s --no-print-directory $(test-classes))
@touch $(@) @touch $(@)
define compile-object define compile-object
@ -333,7 +346,7 @@ $(boot-object): $(boot-source)
$(build)/classpath.jar: $(classpath-dep) $(build)/classpath.jar: $(classpath-dep)
(wd=$$(pwd); \ (wd=$$(pwd); \
cd $(classpath-build); \ cd $(classpath-build); \
$(jar) c0f $${wd}/$(@) $$(find . -name '*.class')) $(jar) c0f "$$($(native-path) "$${wd}/$(@)")" $$(find . -name '*.class'))
$(binaryToMacho): $(src)/binaryToMacho.cpp $(binaryToMacho): $(src)/binaryToMacho.cpp
$(cxx) $(^) -o $(@) $(cxx) $(^) -o $(@)
@ -347,7 +360,7 @@ else
(wd=$$(pwd); \ (wd=$$(pwd); \
cd $(build); \ cd $(build); \
$(objcopy) -I binary classpath.jar \ $(objcopy) -I binary classpath.jar \
-O $(object-format) -B $(object-arch) $${wd}/$(@)) -O $(object-format) -B $(object-arch) "$${wd}/$(@)")
endif endif
$(generator-objects): $(native-build)/%.o: $(src)/%.cpp $(generator-objects): $(native-build)/%.o: $(src)/%.cpp
@ -371,7 +384,7 @@ $(executable): \
@echo "linking $(@)" @echo "linking $(@)"
ifeq ($(platform),windows) ifeq ($(platform),windows)
$(dlltool) -z $(@).def $(^) $(dlltool) -z $(@).def $(^)
$(dlltool) -k -d $(@).def -e $(@).exp $(dlltool) -d $(@).def -e $(@).exp
$(cc) $(@).exp $(^) $(lflags) -o $(@) $(cc) $(@).exp $(^) $(lflags) -o $(@)
else else
$(cc) $(^) $(rdynamic) $(lflags) -o $(@) $(cc) $(^) $(rdynamic) $(lflags) -o $(@)
@ -392,5 +405,5 @@ $(executable-dynamic): $(driver-dynamic-object) $(dynamic-library)
$(generator): $(generator-objects) $(generator): $(generator-objects)
@echo "linking $(@)" @echo "linking $(@)"
$(build-cc) $(^) -o $(@) $(build-cc) $(^) $(build-lflags) -o $(@)

View File

@ -11,6 +11,21 @@ on Mac OS X:
$ make $ make
$ build/darwin-i386-compile-fast/avian -cp build/test Hello $ build/darwin-i386-compile-fast/avian -cp build/test Hello
on Windows (MSYS):
$ export JAVA_HOME="C:/Program Files/Java/jdk1.6.0_07"
$ make
$ build/windows-i386-compile-fast/avian -cp build/test Hello
on Windows (Cygwin):
$ export JAVA_HOME="/cygdrive/c/Program Files/Java/jdk1.6.0_07"
$ make
$ build/windows-i386-compile-fast/avian -cp build/test Hello
Adjust JAVA_HOME according to your system, but be sure to use forward
slashes in the path.
Introduction Introduction
------------ ------------
@ -40,10 +55,6 @@ Avian can currently target the following platforms:
Win32 (i386) Win32 (i386)
Mac OS X (i386) Mac OS X (i386)
The Win32 port may be built on Linux using a MinGW cross compiler and
build environment. Builds on MSYS or Cygwin are not yet supported,
but patches to enable them are welcome.
Building Building
-------- --------
@ -60,20 +71,11 @@ Build requirements include:
Earlier versions of some of these packages may also work but have not Earlier versions of some of these packages may also work but have not
been tested. been tested.
If you are cross-compiling for Windows, you may find it useful to use
our win32 repository: (run this from the directory containing the
avian directory)
$ git clone git://oss.readytalk.com/win32.git
This gives you the Windows JNI headers, zlib headers and library, and
a few other useful libraries like OpenSSL and libjpeg.
The build is directed by a single makefile and may be influenced via The build is directed by a single makefile and may be influenced via
certain flags described below. certain flags described below.
$ make platform={linux,windows,darwin} arch={i386,x86_64} \ $ make platform={linux,windows,darwin} arch={i386,x86_64} \
process={compile,interpret} mode={debug,debug-fast,fast} process={compile,interpret} mode={debug,debug-fast,fast,small}
* platform - the target platform * platform - the target platform
default: output of $(uname -s | tr [:upper:] [:lower:]) default: output of $(uname -s | tr [:upper:] [:lower:])
@ -89,6 +91,33 @@ certain flags described below.
* process - choice between pure interpreter or JIT compiler * process - choice between pure interpreter or JIT compiler
default: compile default: compile
If you are compiling for Windows, you may either cross-compile using
MinGW or build natively on Windows under MSYS or Cygwin.
Installing MSYS:
1. Download and install the current MinGW and MSYS packages from
mingw.org, selecting the C and C++ compilers when prompted. Use the
post-install script to create the filesystem link to the compiler.
2. Download GNU Make 3.81 from the MSYS download page
(make-3.81-MSYS-1.0.11-2.tar.bz2) and extract the tar file into
e.g. c:/msys/1.0.
Installing Cygwin:
1. Download and run setup.exe from cygwin.com, installing the base
system and these packages: make, gcc-mingw-g++, and (optionally)
git.
You may also find our win32 repository useful: (run this from the
directory containing the avian directory)
$ git clone git://oss.readytalk.com/win32.git
This gives you the Windows JNI headers, zlib headers and library, and
a few other useful libraries like OpenSSL and libjpeg.
Installing Installing
---------- ----------
@ -102,6 +131,9 @@ Embedding
The following series of commands illustrates how to produce a The following series of commands illustrates how to produce a
stand-alone executable out of a Java application using Avian. stand-alone executable out of a Java application using Avian.
Note: if you are building on Cygwin, add -mno-cygwin to each of the
compile and link commands below.
Step 1: Build Avian, create a new directory, and populate it with the Step 1: Build Avian, create a new directory, and populate it with the
VM object files and bootstrap classpath jar. VM object files and bootstrap classpath jar.
@ -223,7 +255,17 @@ main(int ac, const char** av)
return exitCode; return exitCode;
} }
EOF EOF
$ g++ -I$JAVA_HOME/include -c main.cpp -o main.o
on Linux:
$ g++ -I$JAVA_HOME/include -I$JAVA_HOME/include/linux \
-D_JNI_IMPLEMENTATION_ -c main.cpp -o main.o
on Mac OS X:
$ g++ -I$JAVA_HOME/include -D_JNI_IMPLEMENTATION_ -c main.cpp -o main.o
on Windows:
$ g++ -I$JAVA_HOME/include -I$JAVA_HOME/include/win32 \
-D_JNI_IMPLEMENTATION_ -c main.cpp -o main.o
Step 5: Link the objects produced above to produce the final Step 5: Link the objects produced above to produce the final
@ -237,3 +279,9 @@ on Mac OS X:
$ g++ -rdynamic *.o -ldl -lpthread -lz -o hello -framework CoreFoundation $ g++ -rdynamic *.o -ldl -lpthread -lz -o hello -framework CoreFoundation
$ strip -S -x hello $ strip -S -x hello
on Windows:
$ dlltool -z hello.def *.o
$ dlltool -d hello.def -e hello.exp
$ g++ hello.exp *.o -L../../win32/lib -lmingwthrd -lm -lz -lws2_32 \
-mwindows -mconsole -o hello.exe
$ strip --strip-all hello.exe

View File

@ -167,8 +167,7 @@ resolveNativeMethod2(Thread* t, object method)
} }
#ifdef __MINGW32__ #ifdef __MINGW32__
// on windows, we also try the _%s@%d variant, since the SWT // on windows, we also try the _%s@%d and %s@%d variants
// libraries use it.
unsigned footprint = methodParameterFootprint(t, method) + 1; unsigned footprint = methodParameterFootprint(t, method) + 1;
if (methodFlags(t, method) & ACC_STATIC) { if (methodFlags(t, method) & ACC_STATIC) {
++ footprint; ++ footprint;
@ -186,6 +185,12 @@ resolveNativeMethod2(Thread* t, object method)
if (p) { if (p) {
return p; return p;
} }
// one more try without the leading underscore
p = ::resolveNativeMethod(t, undecorated + 1, decorated + 1);
if (p) {
return p;
}
#endif #endif
return 0; return 0;