diff --git a/classpath/java-net.cpp b/classpath/java-net.cpp index b92ed16935..88d03ab346 100644 --- a/classpath/java-net.cpp +++ b/classpath/java-net.cpp @@ -10,8 +10,8 @@ #include "jni.h" #include "avian/machine.h" - #include "sockets.h" +#include "jni-util.h" using namespace avian::classpath::sockets; @@ -88,7 +88,8 @@ Java_java_net_InetAddress_ipv4AddressForName(JNIEnv* e, if (host) { return ntohl(reinterpret_cast(host->h_addr_list[0])->s_addr); } else { - fprintf(stderr, "trouble %d\n", WSAGetLastError()); + throwNew(e, "java/net/UnknownHostException", 0); + return 0; } #else addrinfo hints; @@ -100,19 +101,20 @@ Java_java_net_InetAddress_ipv4AddressForName(JNIEnv* e, int r = getaddrinfo(chars, 0, &hints, &result); e->ReleaseStringUTFChars(name, chars); - jint address; if (r != 0) { - address = 0; + throwNew(e, "java/net/UnknownHostException", 0); + return 0; } else { - address = ntohl + int address = ntohl (reinterpret_cast(result->ai_addr)->sin_addr.s_addr); freeaddrinfo(result); + return address; } - - return address; #endif + } else { + throwNew(e, "java/lang/OutOfMemoryError", 0); + return 0; } - return 0; } diff --git a/classpath/java/net/InetAddress.java b/classpath/java/net/InetAddress.java index d0030d0469..39a4aa3dc5 100644 --- a/classpath/java/net/InetAddress.java +++ b/classpath/java/net/InetAddress.java @@ -19,9 +19,6 @@ public class InetAddress { private InetAddress(String name) throws UnknownHostException { this.name = name; this.ip = ipv4AddressForName(name); - if (ip == 0) { - throw new UnknownHostException(name); - } } public String getHostName() { diff --git a/classpath/java/util/Arrays.java b/classpath/java/util/Arrays.java index 9f2ef702c5..b978b5c5ff 100644 --- a/classpath/java/util/Arrays.java +++ b/classpath/java/util/Arrays.java @@ -286,6 +286,24 @@ public class Arrays { return true; } + public static boolean equals(byte[] a, byte[] b) { + if(a == b) { + return true; + } + if(a == null || b == null) { + return false; + } + if(a.length != b.length) { + return false; + } + for(int i = 0; i < a.length; i++) { + if(a[i] != b[i]) { + return false; + } + } + return true; + } + public static List asList(final T ... array) { return new AbstractList() { public int size() { diff --git a/classpath/sun/misc/Unsafe.java b/classpath/sun/misc/Unsafe.java index e5fd094c45..5cb571ee9c 100644 --- a/classpath/sun/misc/Unsafe.java +++ b/classpath/sun/misc/Unsafe.java @@ -48,6 +48,8 @@ public final class Unsafe { public native void putIntVolatile(Object o, long offset, int x); + public native long getLongVolatile(Object o, long offset); + public native void putOrderedInt(Object o, long offset, int x); public native Object getObject(Object o, long offset); diff --git a/makefile b/makefile index 8e916fb336..fc3495cef9 100755 --- a/makefile +++ b/makefile @@ -652,7 +652,8 @@ ifeq ($(platform),darwin) sdk-dir = $(platform-dir)/Developer/SDKs ios-version := $(shell \ - if test -d $(sdk-dir)/$(target)6.1.sdk; then echo 6.1; \ + if test -d $(sdk-dir)/$(target)7.0.sdk; then echo 7.0; \ + elif test -d $(sdk-dir)/$(target)6.1.sdk; then echo 6.1; \ elif test -d $(sdk-dir)/$(target)6.0.sdk; then echo 6.0; \ elif test -d $(sdk-dir)/$(target)5.1.sdk; then echo 5.1; \ elif test -d $(sdk-dir)/$(target)5.0.sdk; then echo 5.0; \ @@ -666,6 +667,12 @@ ifeq ($(platform),darwin) ios-bin = $(platform-dir)/Developer/usr/bin + found-gcc = $(shell if test -f $(ios-bin)/gcc; then echo true; else echo false; fi) + + ifeq ($(found-gcc),false) + use-clang = true + endif + ifeq ($(use-clang),true) cxx = clang -std=c++11 cc = clang diff --git a/src/avian/arm.h b/src/avian/arm.h index 5637aeef4b..c2a88b608c 100644 --- a/src/avian/arm.h +++ b/src/avian/arm.h @@ -19,8 +19,8 @@ # include "libkern/OSAtomic.h" # include "libkern/OSCacheControl.h" # include "mach/mach_types.h" -# include "mach/arm/thread_act.h" -# include "mach/arm/thread_status.h" +# include "mach/thread_act.h" +# include "mach/thread_status.h" # define THREAD_STATE ARM_THREAD_STATE # define THREAD_STATE_TYPE arm_thread_state_t diff --git a/src/builtin.cpp b/src/builtin.cpp index ff29d6e3ce..1a7d283231 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -48,6 +48,60 @@ resolveSystemClassThrow(Thread* t, object loader, object spec) (t, loader, spec, true, Machine::ClassNotFoundExceptionType); } +object +fieldForOffsetInClass(Thread* t, object c, unsigned offset) +{ + object super = classSuper(t, c); + if (super) { + object field = fieldForOffsetInClass(t, super, offset); + if (field) { + return field; + } + } + + object table = classFieldTable(t, c); + if (table) { + for (unsigned i = 0; i < objectArrayLength(t, table); ++i) { + object field = objectArrayBody(t, table, i); + if ((fieldFlags(t, field) & ACC_STATIC) == 0 + and fieldOffset(t, field) == offset) + { + return field; + } + } + } + + return 0; +} + +object +fieldForOffset(Thread* t, object o, unsigned offset) +{ + object c = objectClass(t, o); + if (classVmFlags(t, c) & SingletonFlag) { + c = singletonObject(t, o, 0); + object table = classFieldTable(t, c); + if (table) { + for (unsigned i = 0; i < objectArrayLength(t, table); ++i) { + object field = objectArrayBody(t, table, i); + if ((fieldFlags(t, field) & ACC_STATIC) + and fieldOffset(t, field) == offset) + { + return field; + } + } + } + abort(t); + } else { + object field = fieldForOffsetInClass(t, c, offset); + if (field) { + return field; + } else { + abort(t); + } + } +} + } // namespace extern "C" AVIAN_EXPORT void JNICALL @@ -694,7 +748,7 @@ Avian_sun_misc_Unsafe_compareAndSwapLong return atomicCompareAndSwap64 (&fieldAtOffset(target, offset), expect, update); #else - ACQUIRE_FIELD_FOR_WRITE(t, local::fieldForOffset(t, target, offset)); + ACQUIRE_FIELD_FOR_WRITE(t, fieldForOffset(t, target, offset)); if (fieldAtOffset(target, offset) == expect) { fieldAtOffset(target, offset) = update; return true; @@ -704,6 +758,36 @@ Avian_sun_misc_Unsafe_compareAndSwapLong #endif } +extern "C" AVIAN_EXPORT int64_t JNICALL +Avian_sun_misc_Unsafe_getLongVolatile +(Thread* t, object, uintptr_t* arguments) +{ + object o = reinterpret_cast(arguments[1]); + int64_t offset; memcpy(&offset, arguments + 2, 8); + + // avoid blocking the VM if this is being called in a busy loop + PROTECT(t, o); + { ENTER(t, Thread::IdleState); } + + object field; + if (BytesPerWord < 8) { + field = fieldForOffset(t, o, offset); + + PROTECT(t, field); + acquire(t, field); + } + + int64_t result = fieldAtOffset(o, offset); + + if (BytesPerWord < 8) { + release(t, field); + } else { + loadMemoryBarrier(); + } + + return result; +} + extern "C" AVIAN_EXPORT void JNICALL Avian_sun_misc_Unsafe_unpark (Thread* t, object, uintptr_t* arguments) diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index a49bd43db2..ac406b3adb 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -2460,60 +2460,6 @@ pipeAvailable(int fd, int* available) #endif } -object -fieldForOffsetInClass(Thread* t, object c, unsigned offset) -{ - object super = classSuper(t, c); - if (super) { - object field = fieldForOffsetInClass(t, super, offset); - if (field) { - return field; - } - } - - object table = classFieldTable(t, c); - if (table) { - for (unsigned i = 0; i < objectArrayLength(t, table); ++i) { - object field = objectArrayBody(t, table, i); - if ((fieldFlags(t, field) & ACC_STATIC) == 0 - and fieldOffset(t, field) == offset) - { - return field; - } - } - } - - return 0; -} - -object -fieldForOffset(Thread* t, object o, unsigned offset) -{ - object c = objectClass(t, o); - if (classVmFlags(t, c) & SingletonFlag) { - c = singletonObject(t, o, 0); - object table = classFieldTable(t, c); - if (table) { - for (unsigned i = 0; i < objectArrayLength(t, table); ++i) { - object field = objectArrayBody(t, table, i); - if ((fieldFlags(t, field) & ACC_STATIC) - and fieldOffset(t, field) == offset) - { - return field; - } - } - } - abort(t); - } else { - object field = fieldForOffsetInClass(t, c, offset); - if (field) { - return field; - } else { - abort(t); - } - } -} - } // namespace local } // namespace @@ -2737,36 +2683,6 @@ Avian_sun_misc_Unsafe_getDouble__Ljava_lang_Object_2J (t, method, arguments); } -extern "C" AVIAN_EXPORT int64_t JNICALL -Avian_sun_misc_Unsafe_getLongVolatile -(Thread* t, object, uintptr_t* arguments) -{ - object o = reinterpret_cast(arguments[1]); - int64_t offset; memcpy(&offset, arguments + 2, 8); - - // avoid blocking the VM if this is being called in a busy loop - PROTECT(t, o); - { ENTER(t, Thread::IdleState); } - - object field; - if (BytesPerWord < 8) { - field = local::fieldForOffset(t, o, offset); - - PROTECT(t, field); - acquire(t, field); - } - - int64_t result = fieldAtOffset(o, offset); - - if (BytesPerWord < 8) { - release(t, field); - } else { - loadMemoryBarrier(); - } - - return result; -} - extern "C" AVIAN_EXPORT void JNICALL Avian_sun_misc_Unsafe_putByte__Ljava_lang_Object_2JB (Thread*, object, uintptr_t* arguments) diff --git a/test/Misc.java b/test/Misc.java index b0fde2d44b..276fb56c21 100644 --- a/test/Misc.java +++ b/test/Misc.java @@ -135,7 +135,7 @@ public class Misc { } } - public static void main(String[] args) { + public static void main(String[] args) throws Exception { zam(); Bim bim = new Baz(); @@ -287,6 +287,18 @@ public class Misc { } catch (IOException e) { throw new RuntimeException(e); } + + expect(java.util.Arrays.equals + (new byte[] { 0, 0, 0, 0 }, + java.net.InetAddress.getByName("0.0.0.0").getAddress())); + + try { + java.net.InetAddress.getByName + ("bs.thisdomaindoesntexistseriouslynoway"); + throw new AssertionError(); + } catch (java.net.UnknownHostException e) { + // cool + } } protected class Protected { }