From c1c9d2111bc0cf7c8287e3785c9ea042d0ed60f9 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 27 Sep 2010 15:58:02 -0600 Subject: [PATCH] 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. --- classpath/java/lang/Class.java | 30 +----------- classpath/java/lang/String.java | 38 +-------------- classpath/java/lang/Thread.java | 23 +-------- classpath/java/lang/ThreadGroup.java | 2 +- classpath/java/lang/reflect/Constructor.java | 20 +------- classpath/java/lang/reflect/Field.java | 4 -- .../java/lang/reflect/GenericDeclaration.java | 15 ------ classpath/java/lang/reflect/Member.java | 2 - classpath/java/lang/reflect/Method.java | 28 +---------- classpath/java/lang/reflect/TypeVariable.java | 19 -------- classpath/java/util/Formatter.java | 23 --------- classpath/java/util/regex/Matcher.java | 48 ------------------- classpath/java/util/regex/Pattern.java | 4 -- readme.txt | 30 ------------ src/jnienv.cpp | 19 -------- 15 files changed, 7 insertions(+), 298 deletions(-) delete mode 100644 classpath/java/lang/reflect/GenericDeclaration.java delete mode 100644 classpath/java/lang/reflect/TypeVariable.java delete mode 100644 classpath/java/util/Formatter.java diff --git a/classpath/java/lang/Class.java b/classpath/java/lang/Class.java index 65021739fb..15e4053175 100644 --- a/classpath/java/lang/Class.java +++ b/classpath/java/lang/Class.java @@ -21,11 +21,9 @@ import java.lang.reflect.Method; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.lang.reflect.Type; -import java.lang.reflect.TypeVariable; import java.lang.reflect.Proxy; import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.GenericDeclaration; import java.lang.reflect.AnnotatedElement; import java.lang.annotation.Annotation; import java.io.InputStream; @@ -37,9 +35,7 @@ import java.security.ProtectionDomain; import java.security.Permissions; import java.security.AllPermission; -public final class Class - implements Type, GenericDeclaration, AnnotatedElement -{ +public final class Class implements Type, AnnotatedElement { private static final int PrimitiveFlag = 1 << 5; public final VMClass vmClass; @@ -667,30 +663,6 @@ public final class Class return array; } - public boolean isEnum() { - throw new UnsupportedOperationException(); - } - - public TypeVariable>[] 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() { Permissions p = new Permissions(); p.add(new AllPermission()); diff --git a/classpath/java/lang/String.java b/classpath/java/lang/String.java index 143c60fd72..0dd019d09f 100644 --- a/classpath/java/lang/String.java +++ b/classpath/java/lang/String.java @@ -13,7 +13,6 @@ package java.lang; import java.io.UnsupportedEncodingException; import java.util.regex.Pattern; import java.util.Comparator; -import java.util.Formatter; import java.util.Locale; import java.io.Serializable; import avian.Utf8; @@ -507,9 +506,7 @@ public final class String } public static String valueOf(int v) { - // use Integer.toString(int, int), because GNU Classpath's - // Integer.toString(int) just calls String.valueOf(int): - return Integer.toString(v, 10); + return Integer.toString(v); } public static String valueOf(long v) { @@ -575,37 +572,4 @@ public final class String public int codePointCount(int start, int 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(); - } } diff --git a/classpath/java/lang/Thread.java b/classpath/java/lang/Thread.java index 64d0eab00a..3633921866 100644 --- a/classpath/java/lang/Thread.java +++ b/classpath/java/lang/Thread.java @@ -24,11 +24,8 @@ public class Thread implements Runnable { private Object sleepLock; private ClassLoader classLoader; private UncaughtExceptionHandler exceptionHandler; - - // package private for GNU Classpath, which inexplicably bypasses - // the accessor methods: - String name; - ThreadGroup group; + private String name; + private ThreadGroup group; private static UncaughtExceptionHandler defaultExceptionHandler; @@ -287,22 +284,6 @@ public class Thread implements Runnable { 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 void uncaughtException(Thread t, Throwable e); } diff --git a/classpath/java/lang/ThreadGroup.java b/classpath/java/lang/ThreadGroup.java index 5145f0e865..95ad3383b1 100644 --- a/classpath/java/lang/ThreadGroup.java +++ b/classpath/java/lang/ThreadGroup.java @@ -13,7 +13,7 @@ package java.lang; import avian.Cell; public class ThreadGroup implements Thread.UncaughtExceptionHandler { - final ThreadGroup parent; // package private for GNU Classpath compatibility + private final ThreadGroup parent; private final String name; private Cell subgroups; diff --git a/classpath/java/lang/reflect/Constructor.java b/classpath/java/lang/reflect/Constructor.java index 324797fe9a..7c52df5955 100644 --- a/classpath/java/lang/reflect/Constructor.java +++ b/classpath/java/lang/reflect/Constructor.java @@ -12,9 +12,7 @@ package java.lang.reflect; import java.lang.annotation.Annotation; -public class Constructor extends AccessibleObject - implements Member, GenericDeclaration -{ +public class Constructor extends AccessibleObject implements Member { private Method method; public Constructor(Method method) { @@ -42,10 +40,6 @@ public class Constructor extends AccessibleObject return method.getParameterTypes(); } - public Class[] getExceptionTypes() { - return method.getExceptionTypes(); - } - public int getModifiers() { return method.getModifiers(); } @@ -54,10 +48,6 @@ public class Constructor extends AccessibleObject return method.getName(); } - public boolean isSynthetic() { - return method.isSynthetic(); - } - public T getAnnotation(Class class_) { return method.getAnnotation(class_); } @@ -70,14 +60,6 @@ public class Constructor extends AccessibleObject return method.getDeclaredAnnotations(); } - public TypeVariable>[] getTypeParameters() { - throw new UnsupportedOperationException(); - } - - public Type[] getGenericParameterTypes() { - return method.getGenericParameterTypes(); - } - private static native Object make(avian.VMClass c); public T newInstance(Object ... arguments) diff --git a/classpath/java/lang/reflect/Field.java b/classpath/java/lang/reflect/Field.java index 23fe3bf40f..038ccea54b 100644 --- a/classpath/java/lang/reflect/Field.java +++ b/classpath/java/lang/reflect/Field.java @@ -254,10 +254,6 @@ public class Field extends AccessibleObject { return getAnnotations(); } - public boolean isEnumConstant() { - throw new UnsupportedOperationException(); - } - private static native long getPrimitive (Object instance, int code, int offset); diff --git a/classpath/java/lang/reflect/GenericDeclaration.java b/classpath/java/lang/reflect/GenericDeclaration.java deleted file mode 100644 index 61914661bb..0000000000 --- a/classpath/java/lang/reflect/GenericDeclaration.java +++ /dev/null @@ -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(); -} diff --git a/classpath/java/lang/reflect/Member.java b/classpath/java/lang/reflect/Member.java index cfe00749bb..e5e74042c6 100644 --- a/classpath/java/lang/reflect/Member.java +++ b/classpath/java/lang/reflect/Member.java @@ -19,6 +19,4 @@ public interface Member { public int getModifiers(); public String getName(); - - public boolean isSynthetic(); } diff --git a/classpath/java/lang/reflect/Method.java b/classpath/java/lang/reflect/Method.java index 2db5698eac..b97b648070 100644 --- a/classpath/java/lang/reflect/Method.java +++ b/classpath/java/lang/reflect/Method.java @@ -16,9 +16,7 @@ import avian.SystemClassLoader; import java.lang.annotation.Annotation; -public class Method extends AccessibleObject - implements Member, GenericDeclaration -{ +public class Method extends AccessibleObject implements Member { private final VMMethod vmMethod; private boolean accessible; @@ -200,28 +198,4 @@ public class Method extends AccessibleObject public Annotation[] getDeclaredAnnotations() { 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>[] getTypeParameters() { - throw new UnsupportedOperationException(); - } } diff --git a/classpath/java/lang/reflect/TypeVariable.java b/classpath/java/lang/reflect/TypeVariable.java deleted file mode 100644 index 65d531d6bf..0000000000 --- a/classpath/java/lang/reflect/TypeVariable.java +++ /dev/null @@ -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 - extends Type -{ - public Type[] getBounds(); - public T getGenericDeclaration(); - public String getName(); -} diff --git a/classpath/java/util/Formatter.java b/classpath/java/util/Formatter.java deleted file mode 100644 index 6acf9b5fba..0000000000 --- a/classpath/java/util/Formatter.java +++ /dev/null @@ -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(); - } -} diff --git a/classpath/java/util/regex/Matcher.java b/classpath/java/util/regex/Matcher.java index 2296b4bf9d..99f9d9daad 100644 --- a/classpath/java/util/regex/Matcher.java +++ b/classpath/java/util/regex/Matcher.java @@ -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() { return reset(input); } @@ -63,26 +51,6 @@ public class Matcher { 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) { return replace(replacement, Integer.MAX_VALUE); } @@ -124,10 +92,6 @@ public class Matcher { return end; } - public int end(int group) { - throw new UnsupportedOperationException(); - } - public boolean find() { return find(end); } @@ -143,16 +107,4 @@ public class Matcher { return false; } } - - public int groupCount() { - throw new UnsupportedOperationException(); - } - - public String group() { - throw new UnsupportedOperationException(); - } - - public String group(int group) { - throw new UnsupportedOperationException(); - } } diff --git a/classpath/java/util/regex/Pattern.java b/classpath/java/util/regex/Pattern.java index 2a48591592..c9827c1f70 100644 --- a/classpath/java/util/regex/Pattern.java +++ b/classpath/java/util/regex/Pattern.java @@ -92,10 +92,6 @@ public class Pattern { return pattern; } - public static String quote(String s) { - throw new UnsupportedOperationException(); - } - public String[] split(CharSequence input) { return split(input, 0); } diff --git a/readme.txt b/readme.txt index 93e658dada..1f04cf69d0 100644 --- a/readme.txt +++ b/readme.txt @@ -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" -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 ---------- diff --git a/src/jnienv.cpp b/src/jnienv.cpp index 0c4a7070da..74bab29f5a 100644 --- a/src/jnienv.cpp +++ b/src/jnienv.cpp @@ -367,7 +367,6 @@ ExceptionCheck(Thread* t) return t->exception != 0; } -#ifndef AVIAN_GNU jobject JNICALL NewDirectByteBuffer(Thread*, void*, jlong) { @@ -385,7 +384,6 @@ GetDirectBufferCapacity(Thread*, jobject) { return -1; } -#endif// not AVIAN_GNU jclass JNICALL GetObjectClass(Thread* t, jobject o) @@ -2038,17 +2036,6 @@ append(char** p, const char* value, unsigned length, char tail) 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 populateJNITables(JavaVMVTable* vmTable, JNIEnvVTable* envTable) { @@ -2081,15 +2068,9 @@ populateJNITables(JavaVMVTable* vmTable, JNIEnvVTable* envTable) envTable->ThrowNew = local::ThrowNew; envTable->Throw = local::Throw; 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->GetDirectBufferAddress = local::GetDirectBufferAddress; envTable->GetDirectBufferCapacity = local::GetDirectBufferCapacity; -#endif envTable->DeleteLocalRef = local::DeleteLocalRef; envTable->GetObjectClass = local::GetObjectClass; envTable->IsInstanceOf = local::IsInstanceOf;