implement sun.misc.Unsafe.throwException

This commit is contained in:
Joshua Warner 2013-12-05 20:28:08 -07:00
parent f7ce0c4207
commit 8cda2446d5
3 changed files with 31 additions and 2 deletions

View File

@ -79,4 +79,6 @@ public final class Unsafe {
public void copyMemory(long src, long dst, long count) {
copyMemory(null, src, null, dst, count);
}
public native void throwException(Throwable t);
}

View File

@ -757,6 +757,13 @@ Avian_sun_misc_Unsafe_putOrderedInt
Avian_sun_misc_Unsafe_putIntVolatile(t, method, arguments);
}
extern "C" AVIAN_EXPORT void JNICALL
Avian_sun_misc_Unsafe_throwException
(Thread* t, object, uintptr_t* arguments)
{
vm::throw_(t, reinterpret_cast<object>(arguments[1]));
}
extern "C" AVIAN_EXPORT int64_t JNICALL
Avian_avian_Classes_primitiveClass
(Thread* t, object, uintptr_t* arguments)

View File

@ -5,9 +5,22 @@ public class UnsafeTest {
if (! v) throw new RuntimeException();
}
public static void main(String[] args) {
Unsafe u = avian.Machine.getUnsafe();
private static void unsafeThrow(Unsafe u) {
u.throwException(new Exception());
}
private static void unsafeCatch(Unsafe u) {
boolean success = false;
try {
unsafeThrow(u);
} catch(Exception e) {
expect(e.getClass() == Exception.class);
success = true;
}
expect(success);
}
private static void unsafeMemory(Unsafe u) {
final long size = 64;
long memory = u.allocateMemory(size);
try {
@ -62,4 +75,11 @@ public class UnsafeTest {
u.freeMemory(memory);
}
}
public static void main(String[] args) {
Unsafe u = avian.Machine.getUnsafe();
unsafeCatch(u);
unsafeMemory(u);
}
}