mirror of
https://github.com/corda/corda.git
synced 2025-01-17 02:09:50 +00:00
various fixes for embedded resource loading in OpenJDK build
This commit is contained in:
parent
b5ae66b10f
commit
1271678d41
@ -12,6 +12,10 @@ package avian;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
|
||||
public class SystemClassLoader extends ClassLoader {
|
||||
private native VMClass findVMClass(String name)
|
||||
@ -40,4 +44,13 @@ public class SystemClassLoader extends ClassLoader {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Enumeration<URL> findResources(String name) {
|
||||
Collection<URL> urls = new ArrayList(1);
|
||||
URL url = findResource(name);
|
||||
if (url != null) {
|
||||
urls.add(url);
|
||||
}
|
||||
return Collections.enumeration(urls);
|
||||
}
|
||||
}
|
||||
|
@ -99,6 +99,10 @@ public abstract class ClassLoader {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Enumeration<URL> findResources(String name) throws IOException {
|
||||
return Collections.enumeration(new ArrayList<URL>(0));
|
||||
}
|
||||
|
||||
public URL getResource(String path) {
|
||||
URL url = null;
|
||||
if (parent != null) {
|
||||
|
11
makefile
11
makefile
@ -93,6 +93,7 @@ ifneq ($(openjdk),)
|
||||
javahome-files += lib/currency.data
|
||||
endif
|
||||
javahome-object = $(build)/javahome-jar.o
|
||||
boot-javahome-object = $(build)/boot-javahome.o
|
||||
else
|
||||
options := $(options)-openjdk
|
||||
test-executable = $(executable-dynamic)
|
||||
@ -673,6 +674,9 @@ $(build)/main-dynamic.o: $(driver-source)
|
||||
$(boot-object): $(boot-source)
|
||||
$(compile-object)
|
||||
|
||||
$(boot-javahome-object): $(src)/boot-javahome.cpp
|
||||
$(compile-object)
|
||||
|
||||
$(build)/binaryToObject-main.o: $(src)/binaryToObject/main.cpp
|
||||
$(build-cxx) -c $(^) -o $(@)
|
||||
|
||||
@ -726,7 +730,8 @@ $(generator-objects): $(build)/%-build.o: $(src)/%.cpp
|
||||
$(jni-objects): $(build)/%.o: $(classpath-src)/%.cpp
|
||||
$(compile-object)
|
||||
|
||||
$(static-library): $(vm-objects) $(classpath-objects) $(vm-heapwalk-objects)
|
||||
$(static-library): $(vm-objects) $(classpath-objects) $(vm-heapwalk-objects) \
|
||||
$(javahome-object) $(boot-javahome-object)
|
||||
@echo "creating $(@)"
|
||||
rm -rf $(@)
|
||||
$(ar) cru $(@) $(^)
|
||||
@ -743,7 +748,7 @@ $(bootimage-object): $(bootimage-bin) $(converter)
|
||||
|
||||
executable-objects = $(vm-objects) $(classpath-objects) $(driver-object) \
|
||||
$(vm-heapwalk-objects) $(boot-object) $(vm-classpath-object) \
|
||||
$(javahome-object)
|
||||
$(javahome-object) $(boot-javahome-object)
|
||||
|
||||
$(executable): $(executable-objects)
|
||||
@echo "linking $(@)"
|
||||
@ -792,7 +797,7 @@ endif
|
||||
|
||||
$(dynamic-library): $(vm-objects) $(dynamic-object) $(classpath-objects) \
|
||||
$(vm-heapwalk-objects) $(boot-object) $(vm-classpath-object) \
|
||||
$(classpath-libraries) $(javahome-object)
|
||||
$(classpath-libraries) $(javahome-object) $(boot-javahome-object)
|
||||
@echo "linking $(@)"
|
||||
ifdef msvc
|
||||
$(ld) $(shared) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \
|
||||
|
26
src/boot.cpp
26
src/boot.cpp
@ -81,29 +81,3 @@ extern "C" {
|
||||
#undef SYMBOL
|
||||
|
||||
#endif//BOOT_CLASSPATH
|
||||
|
||||
#ifdef BOOT_JAVAHOME
|
||||
|
||||
#if (defined __MINGW32__) || (defined _MSC_VER)
|
||||
# define SYMBOL(x) binary_javahome_jar_##x
|
||||
#else
|
||||
# define SYMBOL(x) _binary_javahome_jar_##x
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
|
||||
extern const uint8_t SYMBOL(start)[];
|
||||
extern const uint8_t SYMBOL(end)[];
|
||||
|
||||
EXPORT const uint8_t*
|
||||
javahomeJar(unsigned* size)
|
||||
{
|
||||
*size = SYMBOL(end) - SYMBOL(start);
|
||||
return SYMBOL(start);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#undef SYMBOL
|
||||
|
||||
#endif//BOOT_JAVAHOME
|
||||
|
@ -380,6 +380,10 @@ class MyClasspath : public Classpath {
|
||||
{
|
||||
globalMachine = t->m;
|
||||
|
||||
resolveSystemClass(t, root(t, Machine::BootLoader),
|
||||
className(t, type(t, Machine::ClassLoaderType)));
|
||||
if (UNLIKELY(t->exception)) return;
|
||||
|
||||
#ifdef AVIAN_OPENJDK_SRC
|
||||
interceptFileOperations(t);
|
||||
if (UNLIKELY(t->exception)) return;
|
||||
@ -391,10 +395,6 @@ class MyClasspath : public Classpath {
|
||||
}
|
||||
#endif // not AVIAN_OPENJDK_SRC
|
||||
|
||||
resolveSystemClass(t, root(t, Machine::BootLoader),
|
||||
className(t, type(t, Machine::ClassLoaderType)));
|
||||
if (UNLIKELY(t->exception)) return;
|
||||
|
||||
object constructor = resolveMethod
|
||||
(t, type(t, Machine::ClassLoaderType), "<init>",
|
||||
"(Ljava/lang/ClassLoader;)V");
|
||||
@ -694,7 +694,7 @@ checkFileAccess
|
||||
}
|
||||
|
||||
int64_t JNICALL
|
||||
getLength
|
||||
getFileLength
|
||||
(Thread* t, object method, uintptr_t* arguments)
|
||||
{
|
||||
MyClasspath* cp = static_cast<MyClasspath*>(t->m->classpath);
|
||||
@ -1012,13 +1012,49 @@ closeFile(Thread* t, object method, uintptr_t* arguments)
|
||||
}
|
||||
}
|
||||
|
||||
int64_t JNICALL
|
||||
getBootstrapResource(Thread* t, object, uintptr_t* arguments)
|
||||
{
|
||||
object name = reinterpret_cast<object>(arguments[0]);
|
||||
PROTECT(t, name);
|
||||
|
||||
object m = findMethodOrNull
|
||||
(t, type(t, Machine::SystemClassLoaderType),
|
||||
"findResource", "(Ljava/lang/String;)Ljava/net/URL;");
|
||||
|
||||
if (m) {
|
||||
return reinterpret_cast<int64_t>
|
||||
(t->m->processor->invoke(t, m, root(t, Machine::BootLoader), name));
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t JNICALL
|
||||
getBootstrapResources(Thread* t, object, uintptr_t* arguments)
|
||||
{
|
||||
object name = reinterpret_cast<object>(arguments[0]);
|
||||
PROTECT(t, name);
|
||||
|
||||
object m = findMethodOrNull
|
||||
(t, type(t, Machine::SystemClassLoaderType),
|
||||
"findResources", "(Ljava/lang/String;)Ljava/util/Enumeration;");
|
||||
|
||||
if (m) {
|
||||
return reinterpret_cast<int64_t>
|
||||
(t->m->processor->invoke(t, m, root(t, Machine::BootLoader), name));
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// only safe to call during bootstrap when there's only one thread
|
||||
// running:
|
||||
void
|
||||
intercept(Thread* t, object c, const char* name, const char* spec,
|
||||
void* function)
|
||||
{
|
||||
object m = findMethodOrNull(t, c, name, spec);
|
||||
object m = findMethodOrNull(t, c, name, spec);
|
||||
if (m) {
|
||||
PROTECT(t, m);
|
||||
|
||||
@ -1121,8 +1157,16 @@ interceptFileOperations(Thread* t)
|
||||
voidPointer(checkFileAccess));
|
||||
|
||||
intercept(t, fsClass, "getLength", "(Ljava/io/File;)J",
|
||||
voidPointer(getLength));
|
||||
voidPointer(getFileLength));
|
||||
}
|
||||
|
||||
intercept(t, type(t, Machine::ClassLoaderType), "getBootstrapResource",
|
||||
"(Ljava/lang/String;)Ljava/net/URL;",
|
||||
voidPointer(getBootstrapResource));
|
||||
|
||||
intercept(t, type(t, Machine::ClassLoaderType), "getBootstrapResources",
|
||||
"(Ljava/lang/String;)Ljava/util/Enumeration;",
|
||||
voidPointer(getBootstrapResources));
|
||||
}
|
||||
|
||||
unsigned
|
||||
|
Loading…
Reference in New Issue
Block a user