mirror of
https://github.com/corda/corda.git
synced 2025-01-19 11:16:54 +00:00
Merge remote-tracking branch 'bfbc/avian-pack'
Conflicts: makefile
This commit is contained in:
commit
998f99af44
@ -28,12 +28,15 @@ import java.lang.reflect.Proxy;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.lang.reflect.SignatureParser;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.security.ProtectionDomain;
|
||||
@ -53,7 +56,11 @@ public final class Class <T>
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getName();
|
||||
String res;
|
||||
if (isInterface()) res = "interface ";
|
||||
else if (isAnnotation()) res = "annotation ";
|
||||
else res = "class ";
|
||||
return res + getName();
|
||||
}
|
||||
|
||||
private static byte[] replace(int a, int b, byte[] s, int offset,
|
||||
@ -505,6 +512,51 @@ public final class Class <T>
|
||||
public Class getSuperclass() {
|
||||
return (vmClass.super_ == null ? null : SystemClassLoader.getClass(vmClass.super_));
|
||||
}
|
||||
|
||||
private enum ClassType { GLOBAL, MEMBER, LOCAL, ANONYMOUS }
|
||||
|
||||
/**
|
||||
* Determines the class type.
|
||||
*
|
||||
* There are four class types: global (no dollar sign), anonymous (only digits after the dollar sign),
|
||||
* local (starts with digits after the dollar, ends in class name) and member (does not start with digits
|
||||
* after the dollar sign).
|
||||
*
|
||||
* @return the class type
|
||||
*/
|
||||
private ClassType getClassType() {
|
||||
final String name = getName();
|
||||
// Find the last dollar, as classes can be nested
|
||||
int dollar = name.lastIndexOf('$');
|
||||
if (dollar < 0) return ClassType.GLOBAL;
|
||||
|
||||
// Find the first non-digit after the dollar, if any
|
||||
final char[] chars = name.toCharArray();
|
||||
int skipDigits;
|
||||
for (skipDigits = dollar + 1; skipDigits < chars.length; skipDigits++) {
|
||||
if (chars[skipDigits] < '0' || chars[skipDigits] > '9') break;
|
||||
}
|
||||
|
||||
if (skipDigits == chars.length) {
|
||||
return ClassType.ANONYMOUS;
|
||||
} else if (skipDigits > dollar + 1) {
|
||||
return ClassType.MEMBER;
|
||||
} else {
|
||||
return ClassType.LOCAL;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAnonymousClass () {
|
||||
return getClassType() == ClassType.ANONYMOUS;
|
||||
}
|
||||
|
||||
public boolean isLocalClass () {
|
||||
return getClassType() == ClassType.LOCAL;
|
||||
}
|
||||
|
||||
public boolean isMemberClass () {
|
||||
return getClassType() == ClassType.MEMBER;
|
||||
}
|
||||
|
||||
public boolean isArray() {
|
||||
return vmClass.arrayDimensions != 0;
|
||||
@ -661,6 +713,53 @@ public final class Class <T>
|
||||
}
|
||||
|
||||
public Type[] getGenericInterfaces() {
|
||||
throw new UnsupportedOperationException("not yet implemented");
|
||||
if (vmClass.addendum == null || vmClass.addendum.signature == null) {
|
||||
return getInterfaces();
|
||||
}
|
||||
String signature = Classes.toString((byte[]) vmClass.addendum.signature);
|
||||
final char[] signChars = signature.toCharArray();
|
||||
|
||||
// Addendum format:
|
||||
// <generic args if present>LBaseClass;LIface1;LIface2;...
|
||||
// We should split it
|
||||
|
||||
int i = -1;
|
||||
|
||||
// Passing the generic args
|
||||
int angles = 0;
|
||||
do {
|
||||
i++;
|
||||
if (signChars[i] == '<') angles ++;
|
||||
else if (signChars[i] == '>') angles --;
|
||||
} while (angles > 0);
|
||||
if (signChars[i] == '>') i++;
|
||||
|
||||
// Splitting types list
|
||||
LinkedList<String> typeSigns = new LinkedList<String>();
|
||||
StringBuilder curTypeSign = new StringBuilder();
|
||||
for (; i < signChars.length; i++) {
|
||||
// Counting braces
|
||||
if (signChars[i] == '<') angles ++;
|
||||
else if (signChars[i] == '>') angles --;
|
||||
|
||||
// Appending character
|
||||
curTypeSign.append(signChars[i]);
|
||||
|
||||
// Splitting
|
||||
if (angles == 0 && signChars[i] == ';') {
|
||||
typeSigns.add(curTypeSign.toString());
|
||||
curTypeSign.setLength(0);
|
||||
}
|
||||
}
|
||||
if (curTypeSign.length() > 0) typeSigns.add(curTypeSign.toString());
|
||||
|
||||
// Parsing types, ignoring the first item in the array
|
||||
// cause it's the base type
|
||||
Type[] res = new Type[typeSigns.size() - 1];
|
||||
for (i = 0; i < typeSigns.size() - 1; i++) {
|
||||
res[i] = SignatureParser.parse(vmClass.loader, typeSigns.get(i + 1), this);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class Field<T> extends AccessibleObject {
|
||||
return getType();
|
||||
}
|
||||
String signature = Classes.toString((byte[]) vmField.addendum.signature);
|
||||
return SignatureParser.parse(vmField.class_.loader, signature);
|
||||
return SignatureParser.parse(vmField.class_.loader, signature, getDeclaringClass());
|
||||
}
|
||||
|
||||
public Object get(Object instance) throws IllegalAccessException {
|
||||
|
@ -10,22 +10,35 @@
|
||||
|
||||
package java.lang.reflect;
|
||||
|
||||
import avian.Classes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
class SignatureParser {
|
||||
public class SignatureParser {
|
||||
private final ClassLoader loader;
|
||||
private final char[] array;
|
||||
private final String signature;
|
||||
private int offset;
|
||||
private final Type type;
|
||||
private final Map<String, TypeVariable> typeVariables;
|
||||
|
||||
static Type parse(ClassLoader loader, String signature) {
|
||||
return new SignatureParser(loader, signature).type;
|
||||
public static Type parse(ClassLoader loader, String signature, Class declaringClass) {
|
||||
return new SignatureParser(loader, signature, collectTypeVariables(declaringClass)).type;
|
||||
}
|
||||
|
||||
private SignatureParser(ClassLoader loader, String signature) {
|
||||
private static Type parse(ClassLoader loader, String signature, Map<String, TypeVariable> typeVariables) {
|
||||
return new SignatureParser(loader, signature, typeVariables).type;
|
||||
}
|
||||
|
||||
private SignatureParser(ClassLoader loader, String signature, Map<String, TypeVariable> typeVariables) {
|
||||
this.loader = loader;
|
||||
this.signature = signature;
|
||||
array = signature.toCharArray();
|
||||
this.typeVariables = typeVariables;
|
||||
type = parseType();
|
||||
if (offset != array.length) {
|
||||
throw new IllegalArgumentException("Extra characters after " + offset
|
||||
@ -51,8 +64,16 @@ class SignatureParser {
|
||||
return Short.TYPE;
|
||||
} else if (c == 'Z') {
|
||||
return Boolean.TYPE;
|
||||
} else if (c == 'T') {
|
||||
int end = signature.indexOf(';', offset);
|
||||
if (end < 0) {
|
||||
throw new RuntimeException("No semicolon found while parsing signature");
|
||||
}
|
||||
Type res = typeVariables.get(new String(array, offset, end - offset));
|
||||
offset = end + 1;
|
||||
return res;
|
||||
} else if (c != 'L') {
|
||||
throw new IllegalArgumentException("Unexpected character: " + c);
|
||||
throw new IllegalArgumentException("Unexpected character: " + c + ", signature: " + new String(array, 0, array.length) + ", i = " + offset);
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
Type ownerType = null;
|
||||
@ -71,6 +92,17 @@ class SignatureParser {
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException("Could not find class " + rawTypeName);
|
||||
}
|
||||
|
||||
int lastDollar = rawTypeName.lastIndexOf('$');
|
||||
if (lastDollar != -1 && ownerType == null) {
|
||||
String ownerName = rawTypeName.substring(0, lastDollar);
|
||||
try {
|
||||
ownerType = loader.loadClass(ownerName);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException("Could not find class " + ownerName);
|
||||
}
|
||||
}
|
||||
|
||||
if (c == ';') {
|
||||
return rawType;
|
||||
}
|
||||
@ -132,4 +164,95 @@ class SignatureParser {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static Map<String, TypeVariable> collectTypeVariables(Class clz) {
|
||||
Map<String, TypeVariable> varsMap = new HashMap<String, TypeVariable>();
|
||||
LinkedList<Class> classList = new LinkedList<Class>();
|
||||
for (Class c = clz; c != null; c = c.getDeclaringClass()) {
|
||||
classList.addFirst(c);
|
||||
}
|
||||
|
||||
for (Class cur : classList) {
|
||||
final LinkedList<TypeVariableImpl> varsList = new LinkedList<TypeVariableImpl>();
|
||||
if (cur.vmClass.addendum != null && cur.vmClass.addendum.signature != null) {
|
||||
String signature = Classes.toString((byte[]) cur.vmClass.addendum.signature);
|
||||
final char[] signChars = signature.toCharArray();
|
||||
try {
|
||||
int i = 0;
|
||||
if (signChars[i] == '<') {
|
||||
i++;
|
||||
do {
|
||||
final int colon = signature.indexOf(':', i);
|
||||
if (colon < 0 || colon + 1 == signChars.length) {
|
||||
throw new RuntimeException("Can't find ':' in the signature " + signature + " starting from " + i);
|
||||
}
|
||||
String typeVarName = new String(signChars, i, colon - i);
|
||||
i = colon + 1;
|
||||
|
||||
int start = i;
|
||||
int angles = 0;
|
||||
while (angles > 0 || signChars[i] != ';') {
|
||||
if (signChars[i] == '<') angles ++;
|
||||
else if (signChars[i] == '>') angles --;
|
||||
i++;
|
||||
}
|
||||
String typeName = new String(signChars, start, i - start + 1);
|
||||
final Type baseType = SignatureParser.parse(cur.vmClass.loader, typeName, varsMap);
|
||||
|
||||
TypeVariableImpl tv = new TypeVariableImpl(typeVarName, baseType);
|
||||
varsList.add(tv);
|
||||
|
||||
i++;
|
||||
} while (signChars[i] != '>');
|
||||
|
||||
}
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new RuntimeException("Signature of " + cur + " is broken (" + signature + ") and can't be parsed", e);
|
||||
}
|
||||
}
|
||||
for (TypeVariableImpl tv : varsList) {
|
||||
tv.setVars(varsList);
|
||||
varsMap.put(tv.getName(), tv);
|
||||
}
|
||||
cur = cur.getDeclaringClass();
|
||||
};
|
||||
return varsMap;
|
||||
}
|
||||
|
||||
private static class TypeVariableImpl implements TypeVariable {
|
||||
private String name;
|
||||
private Type baseType;
|
||||
private TypeVariableImpl[] vars;
|
||||
|
||||
public Type[] getBounds() {
|
||||
return new Type[] { baseType };
|
||||
}
|
||||
|
||||
public GenericDeclaration getGenericDeclaration() {
|
||||
return new GenericDeclaration() {
|
||||
public TypeVariable<?>[] getTypeParameters() {
|
||||
return vars;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
TypeVariableImpl(String name, Type baseType) {
|
||||
this.name = name;
|
||||
this.baseType = baseType;
|
||||
}
|
||||
|
||||
void setVars(List<TypeVariableImpl> vars) {
|
||||
this.vars = new TypeVariableImpl[vars.size()];
|
||||
vars.toArray(this.vars);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package java.lang.reflect;
|
||||
|
||||
public interface TypeVariable<T extends GenericDeclaration> extends Type {
|
||||
|
||||
public interface TypeVariable<D extends GenericDeclaration> extends Type {
|
||||
Type[] getBounds();
|
||||
D getGenericDeclaration();
|
||||
String getName();
|
||||
}
|
||||
|
37
makefile
37
makefile
@ -240,6 +240,15 @@ ifneq ($(android),)
|
||||
-g3 \
|
||||
-Werror \
|
||||
-Wno-shift-count-overflow
|
||||
ifeq ($(platform),macosx)
|
||||
android-cflags += -Doff64_t=off_t -Dlseek64=lseek
|
||||
endif
|
||||
# on Windows (in MinGW-based build) there are neither __BEGIN_DECLS nor __END_DECLS
|
||||
# defines; we don't want to patch every file that uses them, so we stub them in
|
||||
# using CFLAGS mechanism
|
||||
ifeq ($(platform),windows)
|
||||
android-cflags += "-D__BEGIN_DECLS=extern \"C\" {" "-D__END_DECLS=}"
|
||||
endif
|
||||
|
||||
luni-cpps := $(shell find $(luni-native) -name '*.cpp')
|
||||
|
||||
@ -257,12 +266,12 @@ ifneq ($(android),)
|
||||
crypto-cpps := $(crypto-native)/org_conscrypt_NativeCrypto.cpp
|
||||
|
||||
ifeq ($(platform),windows)
|
||||
android-cflags += -D__STDC_CONSTANT_MACROS -DHAVE_WIN32_FILEMAP
|
||||
android-cflags += -D__STDC_CONSTANT_MACROS -DHAVE_WIN32_FILEMAP -D__STDC_FORMAT_MACROS
|
||||
blacklist = $(luni-native)/java_io_Console.cpp \
|
||||
$(luni-native)/java_lang_ProcessManager.cpp
|
||||
|
||||
icu-libs := $(android)/external/icu4c/lib/sicuin.a \
|
||||
$(android)/external/icu4c/lib/sicuuc.a \
|
||||
icu-libs := $(android)/external/icu4c/lib/libsicuin.a \
|
||||
$(android)/external/icu4c/lib/libsicuuc.a \
|
||||
$(android)/external/icu4c/lib/sicudt.a
|
||||
platform-lflags := -lgdi32 -lshlwapi -lwsock32
|
||||
else
|
||||
@ -1667,21 +1676,21 @@ $(build)/android.dep: $(luni-javas) $(dalvik-javas) $(libart-javas) \
|
||||
cp -a $(luni-java)/* $(xml-java)/* $(build)/android-src/
|
||||
rm $(call noop-files,$(luni-blacklist),$(luni-java),$(build)/android-src)
|
||||
(cd $(dalvik-java) && \
|
||||
jar c $(call noop-files,$(dalvik-javas),$(dalvik-java),.)) \
|
||||
| (cd $(build)/android-src && jar x)
|
||||
$(jar) c $(call noop-files,$(dalvik-javas),$(dalvik-java),.)) \
|
||||
| (cd $(build)/android-src && $(jar) x)
|
||||
(cd $(libart-java) && \
|
||||
jar c $(call noop-files,$(libart-javas),$(libart-java),.)) \
|
||||
| (cd $(build)/android-src && jar x)
|
||||
$(jar) c $(call noop-files,$(libart-javas),$(libart-java),.)) \
|
||||
| (cd $(build)/android-src && $(jar) x)
|
||||
(cd $(crypto-java) && \
|
||||
jar c $(call noop-files,$(crypto-javas),$(crypto-java),.)) \
|
||||
| (cd $(build)/android-src && jar x)
|
||||
$(jar) c $(call noop-files,$(crypto-javas),$(crypto-java),.)) \
|
||||
| (cd $(build)/android-src && $(jar) x)
|
||||
(cd $(crypto-platform-java) && \
|
||||
jar c $(call noop-files,$(crypto-platform-javas),$(crypto-platform-java),.)) \
|
||||
| (cd $(build)/android-src && jar x)
|
||||
$(jar) c $(call noop-files,$(crypto-platform-javas),$(crypto-platform-java),.)) \
|
||||
| (cd $(build)/android-src && $(jar) x)
|
||||
(cd $(classpath-src) && \
|
||||
jar c $(call noop-files,$(classpath-sources),$(classpath-src),.)) \
|
||||
| (cd $(build)/android-src && jar x)
|
||||
# (cd android && jar c *) | (cd $(build)/android-src && jar x)
|
||||
$(jar) c $(call noop-files,$(classpath-sources),$(classpath-src),.)) \
|
||||
| (cd $(build)/android-src && $(jar) x)
|
||||
# (cd android && $(jar) c *) | (cd $(build)/android-src && $(jar) x)
|
||||
find $(build)/android-src -name '*.java' > $(build)/android.txt
|
||||
$(javac) -Xmaxerrs 1000 -d $(build)/android @$(build)/android.txt
|
||||
rm $(build)/android/sun/misc/Unsafe* \
|
||||
|
Loading…
Reference in New Issue
Block a user