various fixes for embedded resource loading in OpenJDK build

This commit is contained in:
Joel Dice 2010-12-05 17:40:50 -07:00
parent b5ae66b10f
commit 1271678d41
5 changed files with 76 additions and 36 deletions

View File

@ -12,6 +12,10 @@ package avian;
import java.net.URL; import java.net.URL;
import java.net.MalformedURLException; 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 { public class SystemClassLoader extends ClassLoader {
private native VMClass findVMClass(String name) private native VMClass findVMClass(String name)
@ -40,4 +44,13 @@ public class SystemClassLoader extends ClassLoader {
} }
return null; 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);
}
} }

View File

@ -99,6 +99,10 @@ public abstract class ClassLoader {
return null; return null;
} }
protected Enumeration<URL> findResources(String name) throws IOException {
return Collections.enumeration(new ArrayList<URL>(0));
}
public URL getResource(String path) { public URL getResource(String path) {
URL url = null; URL url = null;
if (parent != null) { if (parent != null) {

View File

@ -93,6 +93,7 @@ ifneq ($(openjdk),)
javahome-files += lib/currency.data javahome-files += lib/currency.data
endif endif
javahome-object = $(build)/javahome-jar.o javahome-object = $(build)/javahome-jar.o
boot-javahome-object = $(build)/boot-javahome.o
else else
options := $(options)-openjdk options := $(options)-openjdk
test-executable = $(executable-dynamic) test-executable = $(executable-dynamic)
@ -673,6 +674,9 @@ $(build)/main-dynamic.o: $(driver-source)
$(boot-object): $(boot-source) $(boot-object): $(boot-source)
$(compile-object) $(compile-object)
$(boot-javahome-object): $(src)/boot-javahome.cpp
$(compile-object)
$(build)/binaryToObject-main.o: $(src)/binaryToObject/main.cpp $(build)/binaryToObject-main.o: $(src)/binaryToObject/main.cpp
$(build-cxx) -c $(^) -o $(@) $(build-cxx) -c $(^) -o $(@)
@ -726,7 +730,8 @@ $(generator-objects): $(build)/%-build.o: $(src)/%.cpp
$(jni-objects): $(build)/%.o: $(classpath-src)/%.cpp $(jni-objects): $(build)/%.o: $(classpath-src)/%.cpp
$(compile-object) $(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 $(@)" @echo "creating $(@)"
rm -rf $(@) rm -rf $(@)
$(ar) cru $(@) $(^) $(ar) cru $(@) $(^)
@ -743,7 +748,7 @@ $(bootimage-object): $(bootimage-bin) $(converter)
executable-objects = $(vm-objects) $(classpath-objects) $(driver-object) \ executable-objects = $(vm-objects) $(classpath-objects) $(driver-object) \
$(vm-heapwalk-objects) $(boot-object) $(vm-classpath-object) \ $(vm-heapwalk-objects) $(boot-object) $(vm-classpath-object) \
$(javahome-object) $(javahome-object) $(boot-javahome-object)
$(executable): $(executable-objects) $(executable): $(executable-objects)
@echo "linking $(@)" @echo "linking $(@)"
@ -792,7 +797,7 @@ endif
$(dynamic-library): $(vm-objects) $(dynamic-object) $(classpath-objects) \ $(dynamic-library): $(vm-objects) $(dynamic-object) $(classpath-objects) \
$(vm-heapwalk-objects) $(boot-object) $(vm-classpath-object) \ $(vm-heapwalk-objects) $(boot-object) $(vm-classpath-object) \
$(classpath-libraries) $(javahome-object) $(classpath-libraries) $(javahome-object) $(boot-javahome-object)
@echo "linking $(@)" @echo "linking $(@)"
ifdef msvc ifdef msvc
$(ld) $(shared) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \ $(ld) $(shared) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \

View File

@ -81,29 +81,3 @@ extern "C" {
#undef SYMBOL #undef SYMBOL
#endif//BOOT_CLASSPATH #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

View File

@ -380,6 +380,10 @@ class MyClasspath : public Classpath {
{ {
globalMachine = t->m; globalMachine = t->m;
resolveSystemClass(t, root(t, Machine::BootLoader),
className(t, type(t, Machine::ClassLoaderType)));
if (UNLIKELY(t->exception)) return;
#ifdef AVIAN_OPENJDK_SRC #ifdef AVIAN_OPENJDK_SRC
interceptFileOperations(t); interceptFileOperations(t);
if (UNLIKELY(t->exception)) return; if (UNLIKELY(t->exception)) return;
@ -391,10 +395,6 @@ class MyClasspath : public Classpath {
} }
#endif // not AVIAN_OPENJDK_SRC #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 object constructor = resolveMethod
(t, type(t, Machine::ClassLoaderType), "<init>", (t, type(t, Machine::ClassLoaderType), "<init>",
"(Ljava/lang/ClassLoader;)V"); "(Ljava/lang/ClassLoader;)V");
@ -694,7 +694,7 @@ checkFileAccess
} }
int64_t JNICALL int64_t JNICALL
getLength getFileLength
(Thread* t, object method, uintptr_t* arguments) (Thread* t, object method, uintptr_t* arguments)
{ {
MyClasspath* cp = static_cast<MyClasspath*>(t->m->classpath); MyClasspath* cp = static_cast<MyClasspath*>(t->m->classpath);
@ -1012,6 +1012,42 @@ 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 // only safe to call during bootstrap when there's only one thread
// running: // running:
void void
@ -1121,8 +1157,16 @@ interceptFileOperations(Thread* t)
voidPointer(checkFileAccess)); voidPointer(checkFileAccess));
intercept(t, fsClass, "getLength", "(Ljava/io/File;)J", 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 unsigned