various tweaks for Classpath compatibility

This commit is contained in:
Joel Dice 2009-06-06 20:32:44 -06:00
parent 4fca1d64ba
commit 20ea82ec2e
4 changed files with 29 additions and 95 deletions

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2008, Avian Contributors
/* Copyright (c) 2008-2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
@ -11,7 +11,6 @@
package java.net;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.InputStream;
public final class URL {
@ -73,7 +72,7 @@ public final class URL {
throws MalformedURLException
{
if ("resource".equals(protocol)) {
return new ResourceHandler();
return new avian.resource.Handler();
} else {
throw new MalformedURLException("unknown protocol: " + protocol);
}
@ -88,87 +87,4 @@ public final class URL {
this.file = file;
this.ref = ref;
}
private static class ResourceHandler extends URLStreamHandler {
protected URLConnection openConnection(URL url) {
return new ResourceConnection(url);
}
}
private static class ResourceConnection extends URLConnection {
public ResourceConnection(URL url) {
super(url);
}
public int getContentLength() {
return ResourceInputStream.getContentLength(url.getFile());
}
public InputStream getInputStream() throws IOException {
return new ResourceInputStream(url.getFile());
}
}
private static class ResourceInputStream extends InputStream {
private long peer;
private int position;
public ResourceInputStream(String path) throws IOException {
peer = open(path);
if (peer == 0) {
throw new FileNotFoundException(path);
}
}
private static native int getContentLength(String path);
private static native long open(String path) throws IOException;
private static native int read(long peer, int position) throws IOException;
private static native int read(long peer, int position,
byte[] b, int offset, int length)
throws IOException;
public static native void close(long peer) throws IOException;
public int read() throws IOException {
if (peer != 0) {
int c = read(peer, position);
if (c >= 0) {
++ position;
}
return c;
} else {
throw new IOException();
}
}
public int read(byte[] b, int offset, int length) throws IOException {
if (peer != 0) {
if (b == null) {
throw new NullPointerException();
}
if (offset < 0 || offset + length > b.length) {
throw new ArrayIndexOutOfBoundsException();
}
int c = read(peer, position, b, offset, length);
if (c >= 0) {
position += c;
}
return c;
} else {
throw new IOException();
}
}
public void close() throws IOException {
if (peer != 0) {
close(peer);
peer = 0;
}
}
}
}

View File

@ -46,6 +46,7 @@ endif
ifdef gnu
options := $(options)-gnu
gnu-sources = $(src)/gnu.cpp
gnu-jar = $(gnu)/share/classpath/glibj.zip
gnu-libraries = \
$(gnu)/lib/classpath/libjavaio.a \
$(gnu)/lib/classpath/libjavalang.a \
@ -346,6 +347,7 @@ gnu-blacklist = \
gnu-overrides = \
avian/*.class \
avian/resource/*.class \
java/lang/Class.class \
java/lang/Enum.class \
java/lang/InheritableThreadLocal.class \
@ -443,7 +445,7 @@ $(native-build)/type-generator.o: \
$(classpath-build)/%.class: $(classpath)/%.java
@echo $(<)
$(classpath-dep): $(classpath-sources)
$(classpath-dep): $(classpath-sources) $(gnu-jar)
@echo "compiling classpath classes"
@mkdir -p $(avian-classpath-build)
$(javac) -d $(avian-classpath-build) \
@ -457,7 +459,7 @@ ifdef gnu
@mkdir -p $(classpath-build)
(wd=$$(pwd) && \
cd $(classpath-build) && \
$(jar) xf $(gnu)/share/classpath/glibj.zip && \
$(jar) xf $(gnu-jar) && \
rm $(gnu-blacklist) && \
jar xf "$$($(native-path) "$${wd}/$(build)/overrides.jar")")
endif

View File

@ -846,7 +846,7 @@ Avian_java_lang_Thread_enumerate
}
extern "C" JNIEXPORT int64_t JNICALL
Avian_java_net_URL_00024ResourceInputStream_getContentLength
Avian_avian_resource_Handler_00024ResourceInputStream_getContentLength
(Thread* t, object, uintptr_t* arguments)
{
object path = reinterpret_cast<object>(*arguments);
@ -866,7 +866,7 @@ Avian_java_net_URL_00024ResourceInputStream_getContentLength
}
extern "C" JNIEXPORT int64_t JNICALL
Avian_java_net_URL_00024ResourceInputStream_open
Avian_avian_resource_Handler_00024ResourceInputStream_open
(Thread* t, object, uintptr_t* arguments)
{
object path = reinterpret_cast<object>(*arguments);
@ -883,7 +883,7 @@ Avian_java_net_URL_00024ResourceInputStream_open
}
extern "C" JNIEXPORT int64_t JNICALL
Avian_java_net_URL_00024ResourceInputStream_read__JI
Avian_avian_resource_Handler_00024ResourceInputStream_read__JI
(Thread*, object, uintptr_t* arguments)
{
int64_t peer; memcpy(&peer, arguments, 8);
@ -898,7 +898,7 @@ Avian_java_net_URL_00024ResourceInputStream_read__JI
}
extern "C" JNIEXPORT int64_t JNICALL
Avian_java_net_URL_00024ResourceInputStream_read__JI_3BII
Avian_avian_resource_Handler_00024ResourceInputStream_read__JI_3BII
(Thread* t, object, uintptr_t* arguments)
{
int64_t peer; memcpy(&peer, arguments, 8);
@ -923,7 +923,7 @@ Avian_java_net_URL_00024ResourceInputStream_read__JI_3BII
}
extern "C" JNIEXPORT void JNICALL
Avian_java_net_URL_00024ResourceInputStream_close
Avian_avian_resource_Handler_00024ResourceInputStream_close
(Thread*, object, uintptr_t* arguments)
{
int64_t peer; memcpy(&peer, arguments, 8);

View File

@ -52,8 +52,7 @@ Avian_gnu_classpath_VMSystemProperties_preInit
setProperty(t, method, properties, "java.vm.name", "Avian");
setProperty(t, method, properties, "java.lang.classpath",
t->m->finder->path());
setProperty(t, method, properties, "java.protocol.handler.pkgs", "avian");
setProperty(t, method, properties, "file.encoding", "ASCII");
@ -77,6 +76,9 @@ Avian_gnu_classpath_VMSystemProperties_preInit
setProperty(t, method, properties, "user.home",
_wgetenv(L"USERPROFILE"), "%ls");
GetCurrentDirectory(MAX_PATH, buffer);
setProperty(t, method, properties, "user.dir", buffer);
#else
# define FILE_SEPARATOR "/"
@ -90,6 +92,7 @@ Avian_gnu_classpath_VMSystemProperties_preInit
# endif
setProperty(t, method, properties, "java.io.tmpdir", "/tmp");
setProperty(t, method, properties, "user.home", getenv("HOME"));
setProperty(t, method, properties, "user.dir", getenv("PWD"));
#endif
}
@ -279,3 +282,16 @@ Avian_java_lang_VMClassLoader_loadClass
return Avian_avian_SystemClassLoader_findClass(t, 0, args);
}
extern "C" JNIEXPORT int64_t JNICALL
Avian_avian_SystemClassLoader_findLoadedClass
(Thread*, object, uintptr_t*);
extern "C" JNIEXPORT int64_t JNICALL
Avian_java_lang_VMClassLoader_findLoadedClass
(Thread* t, object, uintptr_t* arguments)
{
uintptr_t args[] = { 0, arguments[1] };
return Avian_avian_SystemClassLoader_findLoadedClass(t, 0, args);
}