From 8cda2446d5782d012eb9e7a6912c3f53fed7dc5a Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 5 Dec 2013 20:28:08 -0700 Subject: [PATCH] implement sun.misc.Unsafe.throwException --- classpath/sun/misc/Unsafe.java | 2 ++ src/builtin.cpp | 7 +++++++ test/UnsafeTest.java | 24 ++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/classpath/sun/misc/Unsafe.java b/classpath/sun/misc/Unsafe.java index 57309949e6..d894e76db8 100644 --- a/classpath/sun/misc/Unsafe.java +++ b/classpath/sun/misc/Unsafe.java @@ -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); } diff --git a/src/builtin.cpp b/src/builtin.cpp index 984e1e5f32..63b8a42591 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -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(arguments[1])); +} + extern "C" AVIAN_EXPORT int64_t JNICALL Avian_avian_Classes_primitiveClass (Thread* t, object, uintptr_t* arguments) diff --git a/test/UnsafeTest.java b/test/UnsafeTest.java index 5167526c3b..3cbc6733e7 100644 --- a/test/UnsafeTest.java +++ b/test/UnsafeTest.java @@ -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); + } }