Merge branch 'master' of dice:git/vm

Conflicts:

	src/cdecl.S
This commit is contained in:
Joel Dice 2007-10-04 17:17:57 -06:00
commit e32a335079
6 changed files with 65 additions and 14 deletions

View File

@ -198,7 +198,7 @@ Java_java_io_FileInputStream_read__I(JNIEnv* e, jclass, jint fd)
if (r <= 0) {
return -1;
} else {
return data;
return data & 0xff;
}
}

View File

@ -69,3 +69,13 @@ Java_java_lang_System_doMapLibraryName(JNIEnv* e, jclass, jstring name)
}
return r;
}
extern "C" JNIEXPORT jint JNICALL
Java_java_lang_Double_fillBufferWithDouble(JNIEnv *e, jclass, jdouble val,
jbyteArray buffer, jint bufferSize) {
jboolean isCopy;
jbyte* buf = e->GetByteArrayElements(buffer, &isCopy);
jint count = snprintf(reinterpret_cast<char*>(buf), bufferSize, "%g", val);
e->ReleaseByteArrayElements(buffer, buf, 0);
return count;
}

View File

@ -35,7 +35,9 @@ public final class Double extends Number {
}
public static String toString(double v) {
return "Double.toString: todo";
byte[] buffer = new byte[20];
int numChars = fillBufferWithDouble(v, buffer, 20);
return new String(buffer, 0, numChars, false);
}
public byte byteValue() {
@ -67,6 +69,9 @@ public final class Double extends Number {
throw new NumberFormatException(s);
}
public static native int fillBufferWithDouble(double value, byte[] buffer,
int charCount);
public static native long doubleToRawLongBits(double value);
public static native double longBitsToDouble(long bits);

View File

@ -26,7 +26,7 @@ public final class Float extends Number {
}
public static String toString(float v) {
return "Float.toString: todo";
return Double.toString(v);
}
public byte byteValue() {

View File

@ -81,6 +81,15 @@ public class StringBuilder {
return append(String.valueOf(v));
}
public StringBuilder append(float v) {
return append(String.valueOf(v));
}
public StringBuilder append(double v) {
return append(String.valueOf(v));
}
public char charAt(int i) {
if (i < 0 || i >= length) {
throw new IndexOutOfBoundsException();

View File

@ -683,8 +683,9 @@ populateMultiArray(Thread* t, object array, int32_t* counts,
}
ExceptionHandler*
findExceptionHandler(Thread* t, object method)
findExceptionHandler(Thread* t, int frame)
{
object method = frameMethod(t, frame);
object eht = codeExceptionHandlerTable(t, methodCode(t, method));
if (eht) {
@ -697,16 +698,16 @@ findExceptionHandler(Thread* t, object method)
object catchType = 0;
if (exceptionHandlerCatchType(eh)) {
object e = t->exception;
exception = 0;
t->exception = 0;
PROTECT(t, e);
PROTECT(t, eht);
catchType = resolveClass
(t, codePool(t, code), exceptionHandlerCatchType(eh) - 1);
(t, codePool(t, t->code), exceptionHandlerCatchType(eh) - 1);
if (catchType) {
eh = exceptionHandlerTableBody(t, eht, i);
exception = e;
t->exception = e;
} else {
// can't find what we're supposed to catch - move on.
continue;
@ -756,7 +757,7 @@ interpret(Thread* t)
&byteArrayBody
(t, methodName(t, frameMethod(t, frame)), 0));
int line = lineNumber(t, frameMethod(t, frame), ip);
int line = t->m->processor->lineNumber(t, frameMethod(t, frame), ip);
switch (line) {
case NativeLine:
fprintf(stderr, "(native)\n");
@ -1297,14 +1298,30 @@ interpret(Thread* t)
float b = popFloat(t);
float a = popFloat(t);
pushInt(t, (a > b ? 1 : 0));
if (a < b) {
pushInt(t, static_cast<unsigned>(-1));
} else if (a > b) {
pushInt(t, 1);
} else if (a == b) {
pushInt(t, 0);
} else {
pushInt(t, 1);
}
} goto loop;
case fcmpl: {
float b = popFloat(t);
float a = popFloat(t);
pushInt(t, (a < b ? 1 : 0));
if (a < b) {
pushInt(t, static_cast<unsigned>(-1));
} else if (a > b) {
pushInt(t, 1);
} else if (a == b) {
pushInt(t, 0);
} else {
pushInt(t, static_cast<unsigned>(-1));
}
} goto loop;
case fconst_0: {
@ -2606,7 +2623,7 @@ interpret(Thread* t)
pokeInt(t, t->frame + FrameIpOffset, t->ip);
for (; frame >= base; popFrame(t)) {
ExceptionHandler* eh = findExceptionHandler(t, frameMethod(t, frame));
ExceptionHandler* eh = findExceptionHandler(t, frame);
if (eh) {
sp = frame + FrameFootprint;
ip = exceptionHandlerIp(eh);
@ -2669,6 +2686,14 @@ pushArguments(Thread* t, object this_, const char* spec, bool indirectObjects,
++ s;
pushLong(t, va_arg(a, uint64_t));
break;
case 'F': {
++ s;
float f = va_arg(a, double);
uint32_t i;
memcpy(&i, &f, 4);
pushInt(t, i);
} break;
default:
++ s;
@ -2847,13 +2872,13 @@ class MyProcessor: public Processor {
return new (s->allocate(sizeof(Thread))) Thread(m, javaThread, parent);
}
virtual Compiled*
virtual void*
methodStub(vm::Thread*)
{
return 0;
}
virtual Compiled*
virtual void*
nativeInvoker(vm::Thread*)
{
return 0;
@ -2980,8 +3005,10 @@ class MyProcessor: public Processor {
}
virtual int
lineNumber(Thread* t, object method, unsigned ip)
lineNumber(vm::Thread* vmt, object method, unsigned ip)
{
Thread* t = static_cast<Thread*>(vmt);
if (methodFlags(t, method) & ACC_NATIVE) {
return NativeLine;
}