mirror of
https://github.com/corda/corda.git
synced 2025-01-21 03:55:00 +00:00
include native Classpath code in libavian.a and the avian executable
This commit is contained in:
parent
16537a32bc
commit
6efeee49f8
34
makefile
34
makefile
@ -46,6 +46,18 @@ endif
|
|||||||
ifdef gnu
|
ifdef gnu
|
||||||
options := $(options)-gnu
|
options := $(options)-gnu
|
||||||
gnu-sources = $(src)/gnu.cpp
|
gnu-sources = $(src)/gnu.cpp
|
||||||
|
gnu-libraries = \
|
||||||
|
$(gnu)/lib/classpath/libjavaio.a \
|
||||||
|
$(gnu)/lib/classpath/libjavalang.a \
|
||||||
|
$(gnu)/lib/classpath/libjavalangreflect.a \
|
||||||
|
$(gnu)/lib/classpath/libjavamath.a \
|
||||||
|
$(gnu)/lib/classpath/libjavanet.a \
|
||||||
|
$(gnu)/lib/classpath/libjavanio.a \
|
||||||
|
$(gnu)/lib/classpath/libjavautil.a
|
||||||
|
gnu-object-dep = $(build)/gnu-object.dep
|
||||||
|
gnu-cflags = -DBOOT_BUILTINS=\"javaio,javalang,javalangreflect,javamath,javanet,javanio,javautil\"
|
||||||
|
gnu-lflags = -lgmp
|
||||||
|
gnu-objects = $(shell find $(build)/gnu-objects -name "*.o")
|
||||||
endif
|
endif
|
||||||
|
|
||||||
root = $(shell (cd .. && pwd))
|
root = $(shell (cd .. && pwd))
|
||||||
@ -93,13 +105,14 @@ warnings = -Wall -Wextra -Werror -Wunused-parameter -Winit-self \
|
|||||||
common-cflags = $(warnings) -fno-rtti -fno-exceptions -fno-omit-frame-pointer \
|
common-cflags = $(warnings) -fno-rtti -fno-exceptions -fno-omit-frame-pointer \
|
||||||
"-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)\" \
|
||||||
|
$(gnu-cflags)
|
||||||
|
|
||||||
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
|
common-lflags = -lm -lz $(gnu-lflags)
|
||||||
|
|
||||||
build-lflags =
|
build-lflags =
|
||||||
|
|
||||||
@ -534,10 +547,11 @@ $(generator-objects): $(native-build)/%.o: $(src)/%.cpp
|
|||||||
$(jni-objects): $(native-build)/%.o: $(classpath)/%.cpp
|
$(jni-objects): $(native-build)/%.o: $(classpath)/%.cpp
|
||||||
$(compile-object)
|
$(compile-object)
|
||||||
|
|
||||||
|
$(static-library): $(gnu-object-dep)
|
||||||
$(static-library): $(vm-objects) $(jni-objects) $(vm-heapwalk-objects)
|
$(static-library): $(vm-objects) $(jni-objects) $(vm-heapwalk-objects)
|
||||||
@echo "creating $(@)"
|
@echo "creating $(@)"
|
||||||
rm -rf $(@)
|
rm -rf $(@)
|
||||||
$(ar) cru $(@) $(^)
|
$(ar) cru $(@) $(^) $(call gnu-objects)
|
||||||
$(ranlib) $(@)
|
$(ranlib) $(@)
|
||||||
|
|
||||||
$(bootimage-bin): $(bootimage-generator)
|
$(bootimage-bin): $(bootimage-generator)
|
||||||
@ -557,16 +571,24 @@ else
|
|||||||
"$${wd}/$(@)")
|
"$${wd}/$(@)")
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
$(gnu-object-dep): $(gnu-libraries)
|
||||||
|
@mkdir -p $(build)/gnu-objects
|
||||||
|
(cd $(build)/gnu-objects && \
|
||||||
|
for x in $(gnu-libraries); do ar x $${x}; done)
|
||||||
|
@touch $(@)
|
||||||
|
|
||||||
|
$(executable): $(gnu-object-dep)
|
||||||
$(executable): \
|
$(executable): \
|
||||||
$(vm-objects) $(jni-objects) $(driver-object) $(vm-heapwalk-objects) \
|
$(vm-objects) $(jni-objects) $(driver-object) $(vm-heapwalk-objects) \
|
||||||
$(boot-object) $(vm-classpath-object)
|
$(boot-object) $(vm-classpath-object)
|
||||||
@echo "linking $(@)"
|
@echo "linking $(@)"
|
||||||
ifeq ($(platform),windows)
|
ifeq ($(platform),windows)
|
||||||
$(dlltool) -z $(@).def $(^)
|
$(dlltool) -z $(@).def $(^) $(call gnu-objects)
|
||||||
$(dlltool) -d $(@).def -e $(@).exp
|
$(dlltool) -d $(@).def -e $(@).exp
|
||||||
$(cc) $(@).exp $(^) $(lflags) -o $(@)
|
$(cc) $(@).exp $(^) $(call gnu-objects) $(lflags) -o $(@)
|
||||||
else
|
else
|
||||||
$(cc) $(^) $(rdynamic) $(lflags) $(bootimage-lflags) -o $(@)
|
$(cc) $(^) $(call gnu-objects) $(rdynamic) $(lflags) $(bootimage-lflags) \
|
||||||
|
-o $(@)
|
||||||
endif
|
endif
|
||||||
$(strip) $(strip-all) $(@)
|
$(strip) $(strip-all) $(@)
|
||||||
|
|
||||||
@ -597,7 +619,7 @@ endif
|
|||||||
|
|
||||||
$(dynamic-library): \
|
$(dynamic-library): \
|
||||||
$(vm-objects) $(dynamic-object) $(jni-objects) $(vm-heapwalk-objects) \
|
$(vm-objects) $(dynamic-object) $(jni-objects) $(vm-heapwalk-objects) \
|
||||||
$(boot-object) $(vm-classpath-object)
|
$(boot-object) $(vm-classpath-object) $(gnu-libraries)
|
||||||
@echo "linking $(@)"
|
@echo "linking $(@)"
|
||||||
$(cc) $(^) $(shared) $(lflags) $(bootimage-lflags) -o $(@)
|
$(cc) $(^) $(shared) $(lflags) $(bootimage-lflags) -o $(@)
|
||||||
$(strip) $(strip-all) $(@)
|
$(strip) $(strip-all) $(@)
|
||||||
|
68
src/gnu.cpp
68
src/gnu.cpp
@ -57,9 +57,17 @@ Avian_gnu_classpath_VMSystemProperties_preInit
|
|||||||
|
|
||||||
setProperty(t, method, properties, "file.encoding", "ASCII");
|
setProperty(t, method, properties, "file.encoding", "ASCII");
|
||||||
|
|
||||||
#ifdef WIN32
|
// specify a bogus library path so we can do our own search in
|
||||||
|
// VMRuntime.nativeLoad:
|
||||||
|
#define LIBRARY_PATH_SENTINAL "*"
|
||||||
|
setProperty(t, method, properties, "java.library.path",
|
||||||
|
LIBRARY_PATH_SENTINAL);
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
# define FILE_SEPARATOR "\\"
|
||||||
|
|
||||||
setProperty(t, method, properties, "line.separator", "\r\n");
|
setProperty(t, method, properties, "line.separator", "\r\n");
|
||||||
setProperty(t, method, properties, "file.separator", "\\");
|
setProperty(t, method, properties, "file.separator", FILE_SEPARATOR);
|
||||||
setProperty(t, method, properties, "path.separator", ";");
|
setProperty(t, method, properties, "path.separator", ";");
|
||||||
setProperty(t, method, properties, "os.name", "Windows");
|
setProperty(t, method, properties, "os.name", "Windows");
|
||||||
|
|
||||||
@ -69,21 +77,16 @@ Avian_gnu_classpath_VMSystemProperties_preInit
|
|||||||
|
|
||||||
setProperty(t, method, properties, "user.home",
|
setProperty(t, method, properties, "user.home",
|
||||||
_wgetenv(L"USERPROFILE"), "%ls");
|
_wgetenv(L"USERPROFILE"), "%ls");
|
||||||
|
|
||||||
setProperty(t, method, properties, "java.library.path",
|
|
||||||
_wgetenv(L"PATH"), "%ls");
|
|
||||||
#else
|
#else
|
||||||
|
# define FILE_SEPARATOR "/"
|
||||||
|
|
||||||
setProperty(t, method, properties, "line.separator", "\n");
|
setProperty(t, method, properties, "line.separator", "\n");
|
||||||
setProperty(t, method, properties, "file.separator", "/");
|
setProperty(t, method, properties, "file.separator", FILE_SEPARATOR);
|
||||||
setProperty(t, method, properties, "path.separator", ":");
|
setProperty(t, method, properties, "path.separator", ":");
|
||||||
# ifdef __APPLE__
|
# ifdef __APPLE__
|
||||||
setProperty(t, method, properties, "os.name", "Mac OS X");
|
setProperty(t, method, properties, "os.name", "Mac OS X");
|
||||||
setProperty(t, method, properties, "java.library.path",
|
|
||||||
getenv("DYLD_LIBRARY_PATH"));
|
|
||||||
# else
|
# else
|
||||||
setProperty(t, method, properties, "os.name", "Linux");
|
setProperty(t, method, properties, "os.name", "Linux");
|
||||||
setProperty(t, method, properties, "java.library.path",
|
|
||||||
getenv("LD_LIBRARY_PATH"));
|
|
||||||
# endif
|
# endif
|
||||||
setProperty(t, method, properties, "java.io.tmpdir", "/tmp");
|
setProperty(t, method, properties, "java.io.tmpdir", "/tmp");
|
||||||
setProperty(t, method, properties, "user.home", getenv("HOME"));
|
setProperty(t, method, properties, "user.home", getenv("HOME"));
|
||||||
@ -153,17 +156,17 @@ Avian_java_lang_VMRuntime_mapLibraryName
|
|||||||
object name = reinterpret_cast<object>(arguments[0]);
|
object name = reinterpret_cast<object>(arguments[0]);
|
||||||
PROTECT(t, name);
|
PROTECT(t, name);
|
||||||
|
|
||||||
const unsigned prefixLength = sizeof(SO_PREFIX) - 1;
|
const unsigned soPrefixLength = sizeof(SO_PREFIX) - 1;
|
||||||
const unsigned nameLength = stringLength(t, name);
|
const unsigned nameLength = stringLength(t, name);
|
||||||
const unsigned suffixLength = sizeof(SO_SUFFIX) - 1;
|
const unsigned soSuffixLength = sizeof(SO_SUFFIX) - 1;
|
||||||
const unsigned total = prefixLength + nameLength + suffixLength;
|
const unsigned total = soPrefixLength + nameLength + soSuffixLength;
|
||||||
|
|
||||||
object s = makeByteArray(t, total + 1);
|
object s = makeByteArray(t, total + 1);
|
||||||
char* p = reinterpret_cast<char*>(&byteArrayBody(t, s, 0));
|
char* p = reinterpret_cast<char*>(&byteArrayBody(t, s, 0));
|
||||||
|
|
||||||
memcpy(p, SO_PREFIX, prefixLength);
|
memcpy(p, SO_PREFIX, soPrefixLength);
|
||||||
stringChars(t, name, p + prefixLength);
|
stringChars(t, name, p + soPrefixLength);
|
||||||
memcpy(p + prefixLength + nameLength, SO_SUFFIX, suffixLength);
|
memcpy(p + soPrefixLength + nameLength, SO_SUFFIX, soSuffixLength);
|
||||||
p[total] = 0;
|
p[total] = 0;
|
||||||
|
|
||||||
return reinterpret_cast<int64_t>(makeString(t, s, 0, total, 0));
|
return reinterpret_cast<int64_t>(makeString(t, s, 0, total, 0));
|
||||||
@ -188,7 +191,38 @@ extern "C" JNIEXPORT int64_t JNICALL
|
|||||||
Avian_java_lang_VMRuntime_nativeLoad
|
Avian_java_lang_VMRuntime_nativeLoad
|
||||||
(Thread* t, object, uintptr_t* arguments)
|
(Thread* t, object, uintptr_t* arguments)
|
||||||
{
|
{
|
||||||
uintptr_t args[] = { arguments[0], 0 };
|
object name = reinterpret_cast<object>(arguments[0]);
|
||||||
|
|
||||||
|
// given that we set java.library.path to LIBRARY_PATH_SENTINAL, we
|
||||||
|
// can determine which names are filenames and which are library
|
||||||
|
// names by looking for the prefix LIBRARY_PATH_SENTINAL
|
||||||
|
// FILE_SEPARATOR
|
||||||
|
|
||||||
|
unsigned length = stringLength(t, name);
|
||||||
|
char n[length + 1];
|
||||||
|
stringChars(t, name, n);
|
||||||
|
|
||||||
|
const unsigned pathPrefixLength
|
||||||
|
= sizeof(LIBRARY_PATH_SENTINAL) - 1
|
||||||
|
+ sizeof(FILE_SEPARATOR) - 1;
|
||||||
|
|
||||||
|
bool mapName = (strncmp(n, LIBRARY_PATH_SENTINAL FILE_SEPARATOR,
|
||||||
|
pathPrefixLength) == 0);
|
||||||
|
if (mapName) {
|
||||||
|
// strip the path prefix, SO prefix, and SO suffix before passing
|
||||||
|
// the name to Runtime.load
|
||||||
|
|
||||||
|
const unsigned soPrefixLength = sizeof(SO_PREFIX) - 1;
|
||||||
|
const unsigned soSuffixLength = sizeof(SO_SUFFIX) - 1;
|
||||||
|
const unsigned newOffset
|
||||||
|
= stringOffset(t, name) + pathPrefixLength + soPrefixLength;
|
||||||
|
const unsigned newLength
|
||||||
|
= length - pathPrefixLength - soPrefixLength - soSuffixLength;
|
||||||
|
|
||||||
|
name = makeString(t, stringData(t, name), newOffset, newLength, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
uintptr_t args[] = { reinterpret_cast<uintptr_t>(name), mapName };
|
||||||
|
|
||||||
Avian_java_lang_Runtime_load(t, 0, args);
|
Avian_java_lang_Runtime_load(t, 0, args);
|
||||||
|
|
||||||
|
@ -83,6 +83,10 @@ main(int ac, const char** av)
|
|||||||
++ vmArgs.nOptions;
|
++ vmArgs.nOptions;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef BOOT_BUILTINS
|
||||||
|
++ vmArgs.nOptions;
|
||||||
|
#endif
|
||||||
|
|
||||||
JavaVMOption options[vmArgs.nOptions];
|
JavaVMOption options[vmArgs.nOptions];
|
||||||
vmArgs.options = options;
|
vmArgs.options = options;
|
||||||
|
|
||||||
@ -103,6 +107,11 @@ main(int ac, const char** av)
|
|||||||
= const_cast<char*>("-Davian.bootstrap=" BOOT_LIBRARY);
|
= const_cast<char*>("-Davian.bootstrap=" BOOT_LIBRARY);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef BOOT_BUILTINS
|
||||||
|
options[optionIndex++].optionString
|
||||||
|
= const_cast<char*>("-Davian.builtins=" BOOT_BUILTINS);
|
||||||
|
#endif
|
||||||
|
|
||||||
#define CLASSPATH_PROPERTY "-Djava.class.path="
|
#define CLASSPATH_PROPERTY "-Djava.class.path="
|
||||||
|
|
||||||
unsigned classpathSize = strlen(classpath);
|
unsigned classpathSize = strlen(classpath);
|
||||||
|
Loading…
Reference in New Issue
Block a user