remove GNU Classpath and Apache Harmony compatibility code

Rather than try to support mixing Avian's core classes with those of
an external class library -- which necessitates adding a lot of stub
methods which throw UnsupportedOperationExceptions, among other
comprimises -- we're looking to support such external class libraries
in their unmodified forms.  The latter strategy has already proven
successful with OpenJDK's class library.  Thus, this commit removes
the stub methods, etc., which not only cleans up the code but avoids
misleading application developers as to what classes and methods
Avian's built-in class library supports.
This commit is contained in:
Joel Dice 2010-09-27 15:58:02 -06:00
parent 8c789fb92c
commit c1c9d2111b
15 changed files with 7 additions and 298 deletions

View File

@ -21,11 +21,9 @@ import java.lang.reflect.Method;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.GenericDeclaration;
import java.lang.reflect.AnnotatedElement; import java.lang.reflect.AnnotatedElement;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.io.InputStream; import java.io.InputStream;
@ -37,9 +35,7 @@ import java.security.ProtectionDomain;
import java.security.Permissions; import java.security.Permissions;
import java.security.AllPermission; import java.security.AllPermission;
public final class Class <T> public final class Class <T> implements Type, AnnotatedElement {
implements Type, GenericDeclaration, AnnotatedElement
{
private static final int PrimitiveFlag = 1 << 5; private static final int PrimitiveFlag = 1 << 5;
public final VMClass vmClass; public final VMClass vmClass;
@ -667,30 +663,6 @@ public final class Class <T>
return array; return array;
} }
public boolean isEnum() {
throw new UnsupportedOperationException();
}
public TypeVariable<Class<T>>[] getTypeParameters() {
throw new UnsupportedOperationException();
}
public Method getEnclosingMethod() {
throw new UnsupportedOperationException();
}
public Constructor getEnclosingConstructor() {
throw new UnsupportedOperationException();
}
public Class getEnclosingClass() {
throw new UnsupportedOperationException();
}
public Class[] getDeclaredClasses() {
throw new UnsupportedOperationException();
}
public ProtectionDomain getProtectionDomain() { public ProtectionDomain getProtectionDomain() {
Permissions p = new Permissions(); Permissions p = new Permissions();
p.add(new AllPermission()); p.add(new AllPermission());

View File

@ -13,7 +13,6 @@ package java.lang;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.Comparator; import java.util.Comparator;
import java.util.Formatter;
import java.util.Locale; import java.util.Locale;
import java.io.Serializable; import java.io.Serializable;
import avian.Utf8; import avian.Utf8;
@ -507,9 +506,7 @@ public final class String
} }
public static String valueOf(int v) { public static String valueOf(int v) {
// use Integer.toString(int, int), because GNU Classpath's return Integer.toString(v);
// Integer.toString(int) just calls String.valueOf(int):
return Integer.toString(v, 10);
} }
public static String valueOf(long v) { public static String valueOf(long v) {
@ -575,37 +572,4 @@ public final class String
public int codePointCount(int start, int end) { public int codePointCount(int start, int end) {
return Character.codePointCount(this, start, end); return Character.codePointCount(this, start, end);
} }
public String replace(CharSequence match, CharSequence replacement) {
throw new UnsupportedOperationException();
}
public String toUpperCase(Locale locale) {
throw new UnsupportedOperationException();
}
public String toLowerCase(Locale locale) {
throw new UnsupportedOperationException();
}
public static String format(Locale locale, String format, Object ... args) {
return new Formatter(locale).format(format, args).toString();
}
public static String format(String format, Object ... args) {
return format(Locale.getDefault(), format, args);
}
// for GNU Classpath compatibility:
static char[] zeroBasedStringValue(String s) {
if (s.offset == 0) {
if (s.data instanceof char[]) {
char[] data = (char[]) s.data;
if (data.length == s.length) {
return data;
}
}
}
return s.toCharArray();
}
} }

View File

@ -24,11 +24,8 @@ public class Thread implements Runnable {
private Object sleepLock; private Object sleepLock;
private ClassLoader classLoader; private ClassLoader classLoader;
private UncaughtExceptionHandler exceptionHandler; private UncaughtExceptionHandler exceptionHandler;
private String name;
// package private for GNU Classpath, which inexplicably bypasses private ThreadGroup group;
// the accessor methods:
String name;
ThreadGroup group;
private static UncaughtExceptionHandler defaultExceptionHandler; private static UncaughtExceptionHandler defaultExceptionHandler;
@ -287,22 +284,6 @@ public class Thread implements Runnable {
return peer; return peer;
} }
public void stop() {
throw new UnsupportedOperationException();
}
public void stop(Throwable t) {
throw new UnsupportedOperationException();
}
public void suspend() {
throw new UnsupportedOperationException();
}
public void resume() {
throw new UnsupportedOperationException();
}
public interface UncaughtExceptionHandler { public interface UncaughtExceptionHandler {
public void uncaughtException(Thread t, Throwable e); public void uncaughtException(Thread t, Throwable e);
} }

View File

@ -13,7 +13,7 @@ package java.lang;
import avian.Cell; import avian.Cell;
public class ThreadGroup implements Thread.UncaughtExceptionHandler { public class ThreadGroup implements Thread.UncaughtExceptionHandler {
final ThreadGroup parent; // package private for GNU Classpath compatibility private final ThreadGroup parent;
private final String name; private final String name;
private Cell<ThreadGroup> subgroups; private Cell<ThreadGroup> subgroups;

View File

@ -12,9 +12,7 @@ package java.lang.reflect;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
public class Constructor<T> extends AccessibleObject public class Constructor<T> extends AccessibleObject implements Member {
implements Member, GenericDeclaration
{
private Method<T> method; private Method<T> method;
public Constructor(Method<T> method) { public Constructor(Method<T> method) {
@ -42,10 +40,6 @@ public class Constructor<T> extends AccessibleObject
return method.getParameterTypes(); return method.getParameterTypes();
} }
public Class[] getExceptionTypes() {
return method.getExceptionTypes();
}
public int getModifiers() { public int getModifiers() {
return method.getModifiers(); return method.getModifiers();
} }
@ -54,10 +48,6 @@ public class Constructor<T> extends AccessibleObject
return method.getName(); return method.getName();
} }
public boolean isSynthetic() {
return method.isSynthetic();
}
public <T extends Annotation> T getAnnotation(Class<T> class_) { public <T extends Annotation> T getAnnotation(Class<T> class_) {
return method.getAnnotation(class_); return method.getAnnotation(class_);
} }
@ -70,14 +60,6 @@ public class Constructor<T> extends AccessibleObject
return method.getDeclaredAnnotations(); return method.getDeclaredAnnotations();
} }
public TypeVariable<Constructor<T>>[] getTypeParameters() {
throw new UnsupportedOperationException();
}
public Type[] getGenericParameterTypes() {
return method.getGenericParameterTypes();
}
private static native Object make(avian.VMClass c); private static native Object make(avian.VMClass c);
public T newInstance(Object ... arguments) public T newInstance(Object ... arguments)

View File

@ -254,10 +254,6 @@ public class Field<T> extends AccessibleObject {
return getAnnotations(); return getAnnotations();
} }
public boolean isEnumConstant() {
throw new UnsupportedOperationException();
}
private static native long getPrimitive private static native long getPrimitive
(Object instance, int code, int offset); (Object instance, int code, int offset);

View File

@ -1,15 +0,0 @@
/* Copyright (c) 2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.lang.reflect;
public interface GenericDeclaration {
public TypeVariable<?>[] getTypeParameters();
}

View File

@ -19,6 +19,4 @@ public interface Member {
public int getModifiers(); public int getModifiers();
public String getName(); public String getName();
public boolean isSynthetic();
} }

View File

@ -16,9 +16,7 @@ import avian.SystemClassLoader;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
public class Method<T> extends AccessibleObject public class Method<T> extends AccessibleObject implements Member {
implements Member, GenericDeclaration
{
private final VMMethod vmMethod; private final VMMethod vmMethod;
private boolean accessible; private boolean accessible;
@ -200,28 +198,4 @@ public class Method<T> extends AccessibleObject
public Annotation[] getDeclaredAnnotations() { public Annotation[] getDeclaredAnnotations() {
return getAnnotations(); return getAnnotations();
} }
public boolean isSynthetic() {
throw new UnsupportedOperationException();
}
public Object getDefaultValue() {
throw new UnsupportedOperationException();
}
public Type[] getGenericParameterTypes() {
throw new UnsupportedOperationException();
}
public Type getGenericReturnType() {
throw new UnsupportedOperationException();
}
public Class[] getExceptionTypes() {
throw new UnsupportedOperationException();
}
public TypeVariable<Method<T>>[] getTypeParameters() {
throw new UnsupportedOperationException();
}
} }

View File

@ -1,19 +0,0 @@
/* Copyright (c) 2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.lang.reflect;
public interface TypeVariable<T extends GenericDeclaration>
extends Type
{
public Type[] getBounds();
public T getGenericDeclaration();
public String getName();
}

View File

@ -1,23 +0,0 @@
/* Copyright (c) 2009, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.util;
public class Formatter {
private final Locale locale;
public Formatter(Locale locale) {
this.locale = locale;
}
public Formatter format(String format, Object ... args) {
throw new UnsupportedOperationException();
}
}

View File

@ -36,18 +36,6 @@ public class Matcher {
} }
} }
public boolean requireEnd() {
throw new UnsupportedOperationException();
}
public boolean hitEnd() {
throw new UnsupportedOperationException();
}
public boolean lookingAt() {
throw new UnsupportedOperationException();
}
public Matcher reset() { public Matcher reset() {
return reset(input); return reset(input);
} }
@ -63,26 +51,6 @@ public class Matcher {
return start; return start;
} }
public int start(int group) {
throw new UnsupportedOperationException();
}
public Pattern pattern() {
throw new UnsupportedOperationException();
}
public Matcher region(int start, int end) {
throw new UnsupportedOperationException();
}
public int regionEnd() {
throw new UnsupportedOperationException();
}
public int regionStart() {
throw new UnsupportedOperationException();
}
public String replaceAll(String replacement) { public String replaceAll(String replacement) {
return replace(replacement, Integer.MAX_VALUE); return replace(replacement, Integer.MAX_VALUE);
} }
@ -124,10 +92,6 @@ public class Matcher {
return end; return end;
} }
public int end(int group) {
throw new UnsupportedOperationException();
}
public boolean find() { public boolean find() {
return find(end); return find(end);
} }
@ -143,16 +107,4 @@ public class Matcher {
return false; return false;
} }
} }
public int groupCount() {
throw new UnsupportedOperationException();
}
public String group() {
throw new UnsupportedOperationException();
}
public String group(int group) {
throw new UnsupportedOperationException();
}
} }

View File

@ -92,10 +92,6 @@ public class Pattern {
return pattern; return pattern;
} }
public static String quote(String s) {
throw new UnsupportedOperationException();
}
public String[] split(CharSequence input) { public String[] split(CharSequence input) {
return split(input, 0); return split(input, 0);
} }

View File

@ -191,36 +191,6 @@ Finally, build with the msvc flag set to the MSVC tool directory:
$ make msvc="/cygdrive/c/Program Files/Microsoft Visual Studio 9.0/VC" $ make msvc="/cygdrive/c/Program Files/Microsoft Visual Studio 9.0/VC"
Building with GNU Classpath
---------------------------
** Please note that this feature is still under development and is
neither complete nor well-tested. **
By default, Avian uses its own lightweight class library. However,
that library only contains a relatively small subset of the classes
and methods included in the JRE. If your application requires
features beyond that subset, you may want to tell Avian to use GNU
Classpath instead. In order for this to work, you must configure
Classpath with "--enable-static" and "--with-pic". For example:
$ cd classpath-0.98
$ ./configure --prefix=/usr/local/classpath-0.98 --disable-plugin \
--enable-static --with-pic
$ make && make install
Then, when building Avian, specify the directory where Classpath is
installed, e.g.:
$ cd ../avian
$ make clean
$ make gnu=/usr/local/classpath-0.98
This build will use the classes and native code from Classpath, except
that certain core classes are replaced with implementations from the
Avian class library for compatibility with the VM.
Installing Installing
---------- ----------

View File

@ -367,7 +367,6 @@ ExceptionCheck(Thread* t)
return t->exception != 0; return t->exception != 0;
} }
#ifndef AVIAN_GNU
jobject JNICALL jobject JNICALL
NewDirectByteBuffer(Thread*, void*, jlong) NewDirectByteBuffer(Thread*, void*, jlong)
{ {
@ -385,7 +384,6 @@ GetDirectBufferCapacity(Thread*, jobject)
{ {
return -1; return -1;
} }
#endif// not AVIAN_GNU
jclass JNICALL jclass JNICALL
GetObjectClass(Thread* t, jobject o) GetObjectClass(Thread* t, jobject o)
@ -2038,17 +2036,6 @@ append(char** p, const char* value, unsigned length, char tail)
namespace vm { namespace vm {
#ifdef AVIAN_GNU
jobject JNICALL
NewDirectByteBuffer(Thread*, void*, jlong);
void* JNICALL
GetDirectBufferAddress(Thread*, jobject);
jlong JNICALL
GetDirectBufferCapacity(Thread*, jobject);
#endif//AVIAN_GNU
void void
populateJNITables(JavaVMVTable* vmTable, JNIEnvVTable* envTable) populateJNITables(JavaVMVTable* vmTable, JNIEnvVTable* envTable)
{ {
@ -2081,15 +2068,9 @@ populateJNITables(JavaVMVTable* vmTable, JNIEnvVTable* envTable)
envTable->ThrowNew = local::ThrowNew; envTable->ThrowNew = local::ThrowNew;
envTable->Throw = local::Throw; envTable->Throw = local::Throw;
envTable->ExceptionCheck = local::ExceptionCheck; envTable->ExceptionCheck = local::ExceptionCheck;
#ifdef AVIAN_GNU
envTable->NewDirectByteBuffer = vm::NewDirectByteBuffer;
envTable->GetDirectBufferAddress = vm::GetDirectBufferAddress;
envTable->GetDirectBufferCapacity = vm::GetDirectBufferCapacity;
#else
envTable->NewDirectByteBuffer = local::NewDirectByteBuffer; envTable->NewDirectByteBuffer = local::NewDirectByteBuffer;
envTable->GetDirectBufferAddress = local::GetDirectBufferAddress; envTable->GetDirectBufferAddress = local::GetDirectBufferAddress;
envTable->GetDirectBufferCapacity = local::GetDirectBufferCapacity; envTable->GetDirectBufferCapacity = local::GetDirectBufferCapacity;
#endif
envTable->DeleteLocalRef = local::DeleteLocalRef; envTable->DeleteLocalRef = local::DeleteLocalRef;
envTable->GetObjectClass = local::GetObjectClass; envTable->GetObjectClass = local::GetObjectClass;
envTable->IsInstanceOf = local::IsInstanceOf; envTable->IsInstanceOf = local::IsInstanceOf;