From 5be0edd628cf49f4a16c0a5139ef4bc61e34fb3d Mon Sep 17 00:00:00 2001 From: Vaughn Dice Date: Mon, 26 Mar 2012 11:12:07 -0600 Subject: [PATCH 01/10] Use latest iOS SDK found on local machine --- makefile | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/makefile b/makefile index 9408df6d9c..5bfcd04ca9 100755 --- a/makefile +++ b/makefile @@ -320,12 +320,24 @@ ifeq ($(platform),darwin) so-suffix = .dylib shared = -dynamiclib + sdk-dir = $(developer-dir)/Platforms/iPhoneOS.platform/Developer/SDKs + + ios-version := $(shell if test -d $(sdk-dir)/iPhoneOS5.1.sdk; then echo 5.1; \ + elif test -d $(sdk-dir)/iPhoneOS5.0.sdk; then echo 5.0; \ + elif test -d $(sdk-dir)/iPhoneOS4.3.sdk; then echo 4.3; \ + elif test -d $(sdk-dir)/iPhoneOS4.2.sdk; then echo 4.2; \ + else echo; fi) + + ifeq ($(ios-version),) + x := $(error "couldn't find SDK for iOS version") + endif + ifeq ($(arch),arm) ifeq ($(build-arch),powerpc) converter-cflags += -DOPPOSITE_ENDIAN endif flags = -arch armv7 -isysroot \ - $(developer-dir)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/ + $(sdk-dir)/iPhoneOS$(ios-version).sdk/ openjdk-extra-cflags += $(flags) cflags += $(flags) asmflags += $(flags) From 1be6fe6f152e22e569610ec261892efbb3167ab0 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 26 Mar 2012 18:02:43 -0600 Subject: [PATCH 02/10] add -march=i586 to lflags as well as cflags where appropriate When link time optimization is enabled, we need to remind the compiler that we're targeting i586 when linking so it can resolve atomic operations like __sync_bool_compare_and_swap. --- makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/makefile b/makefile index 5bfcd04ca9..49a2bf0ff6 100755 --- a/makefile +++ b/makefile @@ -476,6 +476,7 @@ ifneq ($(platform),darwin) ifeq ($(arch),i386) # this is necessary to support __sync_bool_compare_and_swap: cflags += -march=i586 + lflags += -march=i586 endif endif From 994098baf13347f801e03166deeb908541869094 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 26 Mar 2012 18:06:16 -0600 Subject: [PATCH 03/10] make find[Field|Method]InClass non-inline functions It seems that GCC 4.6.1 gets confused at LTO time when we take the address of inline functions, so I'm switching them to non-inline linkage to make it happy. --- src/machine.cpp | 68 +++++++++++++++++++++++++++++-------------------- src/machine.h | 19 +++----------- 2 files changed, 44 insertions(+), 43 deletions(-) diff --git a/src/machine.cpp b/src/machine.cpp index 47b53dccbf..ac2c5bdd51 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -2418,6 +2418,38 @@ isInitializing(Thread* t, object c) return false; } +object +findInTable(Thread* t, object table, object name, object spec, + object& (*getName)(Thread*, object), + object& (*getSpec)(Thread*, object)) +{ + if (table) { + for (unsigned i = 0; i < arrayLength(t, table); ++i) { + object o = arrayBody(t, table, i); + if (vm::strcmp(&byteArrayBody(t, getName(t, o), 0), + &byteArrayBody(t, name, 0)) == 0 and + vm::strcmp(&byteArrayBody(t, getSpec(t, o), 0), + &byteArrayBody(t, spec, 0)) == 0) + { + return o; + } + } + +// fprintf(stderr, "%s %s not in\n", +// &byteArrayBody(t, name, 0), +// &byteArrayBody(t, spec, 0)); + +// for (unsigned i = 0; i < arrayLength(t, table); ++i) { +// object o = arrayBody(t, table, i); +// fprintf(stderr, "\t%s %s\n", +// &byteArrayBody(t, getName(t, o), 0), +// &byteArrayBody(t, getSpec(t, o), 0)); +// } + } + + return 0; +} + } // namespace namespace vm { @@ -3884,35 +3916,17 @@ makeObjectArray(Thread* t, object elementClass, unsigned count) } object -findInTable(Thread* t, object table, object name, object spec, - object& (*getName)(Thread*, object), - object& (*getSpec)(Thread*, object)) +findFieldInClass(Thread* t, object class_, object name, object spec) { - if (table) { - for (unsigned i = 0; i < arrayLength(t, table); ++i) { - object o = arrayBody(t, table, i); - if (vm::strcmp(&byteArrayBody(t, getName(t, o), 0), - &byteArrayBody(t, name, 0)) == 0 and - vm::strcmp(&byteArrayBody(t, getSpec(t, o), 0), - &byteArrayBody(t, spec, 0)) == 0) - { - return o; - } - } + return findInTable + (t, classFieldTable(t, class_), name, spec, fieldName, fieldSpec); +} -// fprintf(stderr, "%s %s not in\n", -// &byteArrayBody(t, name, 0), -// &byteArrayBody(t, spec, 0)); - -// for (unsigned i = 0; i < arrayLength(t, table); ++i) { -// object o = arrayBody(t, table, i); -// fprintf(stderr, "\t%s %s\n", -// &byteArrayBody(t, getName(t, o), 0), -// &byteArrayBody(t, getSpec(t, o), 0)); -// } - } - - return 0; +object +findMethodInClass(Thread* t, object class_, object name, object spec) +{ + return findInTable + (t, classMethodTable(t, class_), name, spec, methodName, methodSpec); } object diff --git a/src/machine.h b/src/machine.h index a52cf30a73..f163214917 100644 --- a/src/machine.h +++ b/src/machine.h @@ -2591,16 +2591,7 @@ makeObjectArray(Thread* t, unsigned count) } object -findInTable(Thread* t, object table, object name, object spec, - object& (*getName)(Thread*, object), - object& (*getSpec)(Thread*, object)); - -inline object -findFieldInClass(Thread* t, object class_, object name, object spec) -{ - return findInTable - (t, classFieldTable(t, class_), name, spec, fieldName, fieldSpec); -} +findFieldInClass(Thread* t, object class_, object name, object spec); inline object findFieldInClass2(Thread* t, object class_, const char* name, const char* spec) @@ -2612,12 +2603,8 @@ findFieldInClass2(Thread* t, object class_, const char* name, const char* spec) return findFieldInClass(t, class_, n, s); } -inline object -findMethodInClass(Thread* t, object class_, object name, object spec) -{ - return findInTable - (t, classMethodTable(t, class_), name, spec, methodName, methodSpec); -} +object +findMethodInClass(Thread* t, object class_, object name, object spec); inline object makeThrowable From 382f01641506700d7757af22324a070ce6be959d Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 26 Mar 2012 18:12:58 -0600 Subject: [PATCH 04/10] remove debug logging --- classpath/java-io.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index c1373a3c58..9b7f83286f 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -405,7 +405,6 @@ Java_java_io_File_createNewFile(JNIEnv* e, jclass, jstring path) bool result = false; string_t chars = getChars(e, path); if (chars) { - fprintf(stderr, "create file \"%s\"\n", chars); if (not exists(chars)) { int fd = OPEN(chars, O_CREAT | O_WRONLY | O_EXCL, 0600); if (fd == -1) { From 2f225795fc1e4a28a1bc5bf7d7fd7159320df1cf Mon Sep 17 00:00:00 2001 From: JET Date: Mon, 2 Apr 2012 22:15:02 -0600 Subject: [PATCH 05/10] added RuntimePermission and System.getenv() --- classpath/java-lang.cpp | 29 +++++++++++++++++ classpath/java/lang/RuntimePermission.java | 21 +++++++++++++ classpath/java/lang/System.java | 36 ++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 classpath/java/lang/RuntimePermission.java diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index bb087560fe..9e99dda6cf 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -631,6 +631,35 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, return r; } +// System.getEnvironment() implementation +// TODO: For Win32, replace usage of deprecated _wenviron +#ifndef PLATFORM_WINDOWS +extern char** environ; +# else +extern wchar_t** _wenviron; +const wchar_t** environ = _wenviron; +#endif +extern "C" JNIEXPORT jobjectArray JNICALL +Java_java_lang_System_getEnvironment(JNIEnv* env, jclass) { + int length; + for (length = 0; environ[length] != 0; ++length); + + jobjectArray stringArray = + env->NewObjectArray(length, env->FindClass("java/lang/String"), + env->NewStringUTF("")); + + for (int i = 0; i < length; i++) { +#ifndef PLATFORM_WINDOWS + jobject varString = env->NewStringUTF(environ[i]); // UTF-8 +#else + jobject varString = env->NewString(environ[i]); // UTF-16 +#endif + env->SetObjectArrayElement(stringArray, i, varString); + } + + return stringArray; +} + extern "C" JNIEXPORT jlong JNICALL Java_java_lang_System_currentTimeMillis(JNIEnv*, jclass) { diff --git a/classpath/java/lang/RuntimePermission.java b/classpath/java/lang/RuntimePermission.java new file mode 100644 index 0000000000..a737444a6f --- /dev/null +++ b/classpath/java/lang/RuntimePermission.java @@ -0,0 +1,21 @@ +/* Copyright (c) 2012, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +package java.lang; + +import java.security.BasicPermission; + +public class RuntimePermission extends BasicPermission { + + public RuntimePermission(String name) { + super(name); + } + +} diff --git a/classpath/java/lang/System.java b/classpath/java/lang/System.java index 9506fb3457..827f357e8b 100644 --- a/classpath/java/lang/System.java +++ b/classpath/java/lang/System.java @@ -17,12 +17,15 @@ import java.io.BufferedOutputStream; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileDescriptor; +import java.util.Map; +import java.util.Hashtable; import java.util.Properties; public abstract class System { private static final long NanoTimeBaseInMillis = currentTimeMillis(); private static Property properties; + private static Map environment; private static SecurityManager securityManager; // static { @@ -145,4 +148,37 @@ public abstract class System { this.next = next; } } + + public static String getenv(String name) throws NullPointerException, + SecurityException { + if (getSecurityManager() != null) { // is this allowed? + getSecurityManager(). + checkPermission(new RuntimePermission("getenv." + name)); + } + return getenv().get(name); + } + + public static Map getenv() throws SecurityException { + if (getSecurityManager() != null) { // is this allowed? + getSecurityManager().checkPermission(new RuntimePermission("getenv.*")); + } + + if (environment == null) { // build environment table + String[] vars = getEnvironment(); + environment = new Hashtable(vars.length); + for (String var : vars) { // parse name-value pairs + int equalsIndex = var.indexOf('='); + // null names and values are forbidden + if (equalsIndex != -1 && equalsIndex < var.length() - 1) { + environment.put(var.substring(0, equalsIndex), + var.substring(equalsIndex + 1)); + } + } + } + + return environment; + } + + /** Returns the native process environment. */ + private static native String[] getEnvironment(); } From 57092ece0d0e23e4aaccecaee7da80f3e957b05c Mon Sep 17 00:00:00 2001 From: JET Date: Tue, 3 Apr 2012 10:38:48 -0600 Subject: [PATCH 06/10] fixed Win32 getenv implementation --- classpath/java-lang.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index 9e99dda6cf..ed422d901b 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -632,13 +632,9 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, } // System.getEnvironment() implementation -// TODO: For Win32, replace usage of deprecated _wenviron -#ifndef PLATFORM_WINDOWS +// TODO: For Win32, replace usage of deprecated _environ and add Unicode +// support (neither of which is likely to be of great importance). extern char** environ; -# else -extern wchar_t** _wenviron; -const wchar_t** environ = _wenviron; -#endif extern "C" JNIEXPORT jobjectArray JNICALL Java_java_lang_System_getEnvironment(JNIEnv* env, jclass) { int length; @@ -649,11 +645,7 @@ Java_java_lang_System_getEnvironment(JNIEnv* env, jclass) { env->NewStringUTF("")); for (int i = 0; i < length; i++) { -#ifndef PLATFORM_WINDOWS - jobject varString = env->NewStringUTF(environ[i]); // UTF-8 -#else - jobject varString = env->NewString(environ[i]); // UTF-16 -#endif + jobject varString = env->NewStringUTF(environ[i]); env->SetObjectArrayElement(stringArray, i, varString); } From 6323c76540f9256bc45cc065634757ddea7015d2 Mon Sep 17 00:00:00 2001 From: JET Date: Wed, 4 Apr 2012 13:13:06 -0600 Subject: [PATCH 07/10] added space before ';' in empty for loop to make Apple happy --- classpath/java-lang.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index ed422d901b..973bd8f89c 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -638,7 +638,7 @@ extern char** environ; extern "C" JNIEXPORT jobjectArray JNICALL Java_java_lang_System_getEnvironment(JNIEnv* env, jclass) { int length; - for (length = 0; environ[length] != 0; ++length); + for (length = 0; environ[length] != 0; ++length) ; jobjectArray stringArray = env->NewObjectArray(length, env->FindClass("java/lang/String"), From 2b4407a962bd6584759f33f4feb25652890c0fdc Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 5 Apr 2012 10:04:53 -0600 Subject: [PATCH 08/10] fix iOS build regression --- classpath/java-lang.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index 973bd8f89c..bc09cd89fe 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -634,7 +634,13 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, // System.getEnvironment() implementation // TODO: For Win32, replace usage of deprecated _environ and add Unicode // support (neither of which is likely to be of great importance). +#ifdef AVIAN_IOS +namespace { + const char* environ[] = { 0 }; +} +#else extern char** environ; +#endif extern "C" JNIEXPORT jobjectArray JNICALL Java_java_lang_System_getEnvironment(JNIEnv* env, jclass) { int length; From 2fedfdea5be13dfeebf0c615e41b2f15c90834ce Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 6 Apr 2012 16:52:24 -0600 Subject: [PATCH 09/10] fix OS X build regression --- classpath/java-lang.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index bc09cd89fe..855e6b5c60 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -638,6 +638,9 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name, namespace { const char* environ[] = { 0 }; } +#elif defined __APPLE__ +# include +# define environ (*_NSGetEnviron()) #else extern char** environ; #endif From ba1f8aa68ec552a7b07d3aa90541b61ff7233f9c Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sat, 7 Apr 2012 17:15:59 -0600 Subject: [PATCH 10/10] don't fail build on missing iOS SDK unless actually building for iOS --- makefile | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/makefile b/makefile index 49a2bf0ff6..4a481f9c7b 100755 --- a/makefile +++ b/makefile @@ -322,17 +322,18 @@ ifeq ($(platform),darwin) sdk-dir = $(developer-dir)/Platforms/iPhoneOS.platform/Developer/SDKs - ios-version := $(shell if test -d $(sdk-dir)/iPhoneOS5.1.sdk; then echo 5.1; \ - elif test -d $(sdk-dir)/iPhoneOS5.0.sdk; then echo 5.0; \ - elif test -d $(sdk-dir)/iPhoneOS4.3.sdk; then echo 4.3; \ - elif test -d $(sdk-dir)/iPhoneOS4.2.sdk; then echo 4.2; \ - else echo; fi) - - ifeq ($(ios-version),) - x := $(error "couldn't find SDK for iOS version") - endif - ifeq ($(arch),arm) + ios-version := \ + $(shell if test -d $(sdk-dir)/iPhoneOS5.1.sdk; then echo 5.1; \ + elif test -d $(sdk-dir)/iPhoneOS5.0.sdk; then echo 5.0; \ + elif test -d $(sdk-dir)/iPhoneOS4.3.sdk; then echo 4.3; \ + elif test -d $(sdk-dir)/iPhoneOS4.2.sdk; then echo 4.2; \ + else echo; fi) + + ifeq ($(ios-version),) + x := $(error "couldn't find SDK for iOS version") + endif + ifeq ($(build-arch),powerpc) converter-cflags += -DOPPOSITE_ENDIAN endif