fix Avian classpath build

This commit is contained in:
Joel Dice 2013-02-22 11:55:01 -07:00
parent 201473cf87
commit 8546ca5670
15 changed files with 106 additions and 20 deletions

View File

@ -317,7 +317,7 @@ public class Classes {
int index = 0;
String spec = new String
(vmMethod.spec, 1, vmMethod.spec.length - 1);
(vmMethod.spec, 1, vmMethod.spec.length - 2);
try {
for (int i = 0; i < spec.length(); ++i) {
@ -353,6 +353,7 @@ public class Classes {
return types;
}
public static int findField(VMClass vmClass, String name) {
if (vmClass.fieldTable != null) {
Classes.link(vmClass);
@ -370,7 +371,7 @@ public class Classes {
return new String(array, 0, array.length - 1);
}
private static boolean match(Class[] a, Class[] b) {
public static boolean match(Class[] a, Class[] b) {
if (a.length == b.length) {
for (int i = 0; i < a.length; ++i) {
if (! a[i].isAssignableFrom(b[i])) {
@ -383,7 +384,7 @@ public class Classes {
}
}
private static int findMethod(VMClass vmClass, String name,
public static int findMethod(VMClass vmClass, String name,
Class[] parameterTypes)
{
if (vmClass.methodTable != null) {

View File

@ -11,7 +11,7 @@
package java.lang;
public final class Boolean implements Comparable<Boolean> {
public static final Class TYPE = Class.forCanonicalName("Z");
public static final Class TYPE = avian.Classes.forCanonicalName("Z");
public static final Boolean FALSE = new Boolean(false);
public static final Boolean TRUE = new Boolean(true);

View File

@ -11,7 +11,7 @@
package java.lang;
public final class Byte extends Number implements Comparable<Byte> {
public static final Class TYPE = Class.forCanonicalName("B");
public static final Class TYPE = avian.Classes.forCanonicalName("B");
private final byte value;

View File

@ -14,7 +14,7 @@ public final class Character implements Comparable<Character> {
public static final int MIN_RADIX = 2;
public static final int MAX_RADIX = 36;
public static final Class TYPE = Class.forCanonicalName("C");
public static final Class TYPE = avian.Classes.forCanonicalName("C");
private final char value;

View File

@ -191,7 +191,7 @@ public final class Class <T> implements Type, AnnotatedElement {
public Field getField(String name) throws NoSuchFieldException {
for (VMClass c = vmClass; c != null; c = c.super_) {
int index = findField(c, name);
int index = Classes.findField(c, name);
if (index >= 0) {
return new Field(vmClass.fieldTable[index]);
}
@ -220,7 +220,7 @@ public final class Class <T> implements Type, AnnotatedElement {
throw new NoSuchMethodException(name);
}
for (VMClass c = vmClass; c != null; c = c.super_) {
int index = findMethod(c, name, parameterTypes);
int index = Classes.findMethod(c, name, parameterTypes);
if (index >= 0) {
return new Method(vmClass.methodTable[index]);
}
@ -231,11 +231,11 @@ public final class Class <T> implements Type, AnnotatedElement {
public Constructor getConstructor(Class ... parameterTypes)
throws NoSuchMethodException
{
Method m = findMethod(vmClass, "<init>", parameterTypes);
if (m == null) {
int index = Classes.findMethod(vmClass, "<init>", parameterTypes);
if (index < 0) {
throw new NoSuchMethodException();
} else {
return new Constructor(m);
return new Constructor(new Method(vmClass.methodTable[index]));
}
}
@ -246,7 +246,7 @@ public final class Class <T> implements Type, AnnotatedElement {
Constructor[] constructors = getDeclaredConstructors();
for (int i = 0; i < constructors.length; ++i) {
if (match(parameterTypes, constructors[i].getParameterTypes())) {
if (Classes.match(parameterTypes, constructors[i].getParameterTypes())) {
c = constructors[i];
}
}

View File

@ -11,7 +11,7 @@
package java.lang;
public final class Double extends Number {
public static final Class TYPE = Class.forCanonicalName("D");
public static final Class TYPE = avian.Classes.forCanonicalName("D");
public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
public static final double POSITIVE_INFINITY = 1.0 / 0.0;

View File

@ -11,7 +11,7 @@
package java.lang;
public final class Float extends Number {
public static final Class TYPE = Class.forCanonicalName("F");
public static final Class TYPE = avian.Classes.forCanonicalName("F");
private static final int EXP_BIT_MASK = 0x7F800000;
private static final int SIGNIF_BIT_MASK = 0x007FFFFF;

View File

@ -11,7 +11,7 @@
package java.lang;
public final class Integer extends Number implements Comparable<Integer> {
public static final Class TYPE = Class.forCanonicalName("I");
public static final Class TYPE = avian.Classes.forCanonicalName("I");
public static final int MIN_VALUE = 0x80000000;
public static final int MAX_VALUE = 0x7FFFFFFF;

View File

@ -14,7 +14,7 @@ public final class Long extends Number implements Comparable<Long> {
public static final long MIN_VALUE = -9223372036854775808l;
public static final long MAX_VALUE = 9223372036854775807l;
public static final Class TYPE = Class.forCanonicalName("J");
public static final Class TYPE = avian.Classes.forCanonicalName("J");
private final long value;

View File

@ -11,7 +11,7 @@
package java.lang;
public final class Short extends Number implements Comparable<Short> {
public static final Class TYPE = Class.forCanonicalName("S");
public static final Class TYPE = avian.Classes.forCanonicalName("S");
public static final short MAX_VALUE = 32767;
private final short value;

View File

@ -127,6 +127,11 @@ public final class String
} else {
c = Utf8.decode((byte[])data, offset, length);
if(c instanceof char[]) length = ((char[])c).length;
if (c == null) {
throw new RuntimeException
("unable to parse \"" + new String(data, offset, length, false)
+ "\"");
}
}
this.data = c;

View File

@ -11,7 +11,7 @@
package java.lang;
public final class Void {
public static final Class TYPE = Class.forCanonicalName("V");
public static final Class TYPE = avian.Classes.forCanonicalName("V");
private Void() { }
}

View File

@ -61,7 +61,7 @@ public class Field<T> extends AccessibleObject {
}
public Class getType() {
return Class.forCanonicalName
return Classes.forCanonicalName
(vmField.class_.loader,
new String(vmField.spec, 0, vmField.spec.length - 1, false));
}

View File

@ -13,6 +13,7 @@ package java.lang.reflect;
import avian.VMMethod;
import avian.AnnotationInvocationHandler;
import avian.SystemClassLoader;
import avian.Classes;
import java.lang.annotation.Annotation;
@ -98,7 +99,7 @@ public class Method<T> extends AccessibleObject implements Member {
public Class getReturnType() {
for (int i = 0; i < vmMethod.spec.length - 1; ++i) {
if (vmMethod.spec[i] == ')') {
return Class.forCanonicalName
return Classes.forCanonicalName
(vmMethod.class_.loader,
new String
(vmMethod.spec, i + 1, vmMethod.spec.length - i - 2, false));

View File

@ -127,6 +127,47 @@ class MyClasspath : public Classpath {
// ignore
}
virtual object
makeDirectByteBuffer(Thread* t, void* p, jlong capacity)
{
object c = resolveClass
(t, root(t, Machine::BootLoader), "java/nio/DirectByteBuffer");
PROTECT(t, c);
object instance = makeNew(t, c);
PROTECT(t, instance);
object constructor = resolveMethod(t, c, "<init>", "(JI)V");
t->m->processor->invoke
(t, constructor, instance, reinterpret_cast<int64_t>(p),
static_cast<int32_t>(capacity));
return instance;
}
virtual void*
getDirectBufferAddress(Thread* t, object b)
{
PROTECT(t, b);
object field = resolveField(t, objectClass(t, b), "address", "J");
return reinterpret_cast<void*>
(fieldAtOffset<int64_t>(b, fieldOffset(t, field)));
}
virtual int64_t
getDirectBufferCapacity(Thread* t, object b)
{
PROTECT(t, b);
object field = resolveField
(t, objectClass(t, b), "capacity", "I");
return fieldAtOffset<int32_t>(b, fieldOffset(t, field));
}
virtual void
dispose()
{
@ -698,3 +739,41 @@ Avian_avian_Classes_getVMClass
return reinterpret_cast<int64_t>
(objectClass(t, reinterpret_cast<object>(arguments[0])));
}
extern "C" JNIEXPORT int64_t JNICALL
Avian_avian_Classes_makeMethod
(Thread* t, object, uintptr_t* arguments)
{
object method = arrayBody
(t, classMethodTable
(t, jclassVmClass(t, reinterpret_cast<object>(arguments[0]))),
arguments[1]);
PROTECT(t, method);
object c = resolveClass
(t, root(t, Machine::BootLoader), "java/lang/reflect/Method");
PROTECT(t, c);
object instance = makeNew(t, c);
PROTECT(t, instance);
object constructor = resolveMethod(t, c, "<init>", "(Lavian/VMMethod;)V");
t->m->processor->invoke(t, constructor, instance, method);
if (byteArrayBody(t, methodName(t, method), 0) == '<') {
method = instance;
c = resolveClass
(t, root(t, Machine::BootLoader), "java/lang/reflect/Constructor");
object instance = makeNew(t, c);
object constructor = resolveMethod
(t, c, "<init>", "(Ljava/lang/Method;)V");
t->m->processor->invoke(t, constructor, instance, method);
}
return reinterpret_cast<uintptr_t>(instance);
}