diff --git a/classpath/avian/SystemClassLoader.java b/classpath/avian/SystemClassLoader.java index 3054afe15a..d9e53604b0 100644 --- a/classpath/avian/SystemClassLoader.java +++ b/classpath/avian/SystemClassLoader.java @@ -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 findResources(String name) { + Collection urls = new ArrayList(1); + URL url = findResource(name); + if (url != null) { + urls.add(url); + } + return Collections.enumeration(urls); + } } diff --git a/classpath/java/lang/ClassLoader.java b/classpath/java/lang/ClassLoader.java index dbd376b62f..54b7a723b7 100644 --- a/classpath/java/lang/ClassLoader.java +++ b/classpath/java/lang/ClassLoader.java @@ -99,6 +99,10 @@ public abstract class ClassLoader { return null; } + protected Enumeration findResources(String name) throws IOException { + return Collections.enumeration(new ArrayList(0)); + } + public URL getResource(String path) { URL url = null; if (parent != null) { diff --git a/makefile b/makefile index 200d132d71..8b8a1593d3 100644 --- a/makefile +++ b/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 \ diff --git a/src/boot.cpp b/src/boot.cpp index f6a1cd8d20..e677b81bde 100644 --- a/src/boot.cpp +++ b/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 diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index 177dd077ef..d1986e6125 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -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), "", "(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(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(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 + (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(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 + (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