Android Builds of OpenJDK Mobile project now available
Bob Vandette
bob.vandette at oracle.com
Fri Feb 19 13:30:14 UTC 2016
Your patch below may allow you to build the JDK but it won’t be able to run on Android 4 devices
since the missing functions are not available in android-19 libc.a. This is why we need to conditionally
remove these functions based on the platform version you want to target.
Bob.
> On Feb 18, 2016, at 7:16 PM, Ali Ebrahimi <ali.ebrahimi1781 at gmail.com> wrote:
>
> Hi Bob,
>
> On Thu, Feb 18, 2016 at 9:58 PM, Bob Vandette <bob.vandette at oracle.com <mailto:bob.vandette at oracle.com>> wrote:
> Ali,
>
> I decided to take a slightly different approach to supporting NDK r10e.
>
> My last patch did add support for this version of the NDK but forced the Java runtime
> to only support API level 21 and higher. This means we would only be able to run
> on devices with Android 5 and newer.
>
> If you look at the Android Dashboard, there are still a lot of devices that are supporting
> API level 19.
>
> http://developer.android.com/about/dashboards/index.html <http://developer.android.com/about/dashboards/index.html>
>
> I think it’s best that we set API level 19 as our minimum supported API level for now.
>
> This means that we can still use NDK r10e but you need to specify —platform=android-19
> when generating the standalone toolchain.
>
> Taking this approach also reduces the number of changes required in the mobile/dev
> forest to only 2 files.
>
> Here’s the webrev:
>
> http://cr.openjdk.java.net/~bobv/8150074/webrev.01/ <http://cr.openjdk.java.net/~bobv/8150074/webrev.01/>
> I come back with this patchs that work with —platform=android-19 and —platform=android-21 NDK r10e
>
> jdk.diff
>
> diff -r 91482de10f40 src/java.base/linux/native/libjava/ProcessHandleImpl_linux.c
> --- a/src/java.base/linux/native/libjava/ProcessHandleImpl_linux.c Wed Feb 10 14:17:12 2016 -0500
> +++ b/src/java.base/linux/native/libjava/ProcessHandleImpl_linux.c Fri Feb 19 03:22:47 2016 +0330
> @@ -241,34 +241,6 @@
> }
> }
>
> -#ifdef __ANDROID__
> -static int getline(char **line, size_t *len, FILE *fp) {
> - char *buf;
> - size_t bufLen;
> - if (*line != NULL) {
> - buf = *line;
> - bufLen = *len;
> - } else {
> - buf = malloc(64);
> - if (buf == NULL) {
> - return -1;
> - }
> - bufLen = 64;
> - }
> - if (fgets(buf, bufLen, fp) == NULL) {
> - if (*line == NULL) {
> - free(buf);
> - }
> - return -1;
> - }
> - if (*line == NULL) {
> - *line = buf;
> - *len = bufLen;
> - }
> - return strlen(*line);
> -}
> -#endif
> -
> /**
> * Read the boottime from /proc/stat.
> */
> diff -r 91482de10f40 src/java.base/linux/native/libnet/linux_close.c
> --- a/src/java.base/linux/native/libnet/linux_close.c Wed Feb 10 14:17:12 2016 -0500
> +++ b/src/java.base/linux/native/libnet/linux_close.c Fri Feb 19 03:22:47 2016 +0330
> @@ -57,8 +57,10 @@
> * Signal to unblock thread
> */
> #ifdef __ANDROID__
> +#ifndef __SIGRTMAX
> #define __SIGRTMAX SIGRTMAX
> #endif
> +#endif
> static int sigWakeup = (__SIGRTMAX - 2);
>
> /*
> diff -r 91482de10f40 src/java.base/linux/native/libnio/fs/LinuxNativeDispatcher.c
> --- a/src/java.base/linux/native/libnio/fs/LinuxNativeDispatcher.c Wed Feb 10 14:17:12 2016 -0500
> +++ b/src/java.base/linux/native/libnio/fs/LinuxNativeDispatcher.c Fri Feb 19 03:22:47 2016 +0330
> @@ -36,11 +36,6 @@
>
> #include "sun_nio_fs_LinuxNativeDispatcher.h"
>
> -#ifdef __ANDROID__
> -#define setmntent(f,m) fopen(f,m)
> -#define endmntent(f) fclose(f)
> -#endif
> -
> typedef size_t fgetxattr_func(int fd, const char* name, void* value, size_t size);
> typedef int fsetxattr_func(int fd, const char* name, void* value, size_t size, int flags);
> typedef int fremovexattr_func(int fd, const char* name);
> @@ -173,31 +168,6 @@
> return ptr_to_jlong(fp);
> }
>
> -#ifdef __ANDROID__
> -static struct mntent* getmntent_r(FILE* fp, struct mntent* m, char* buf, int buflen) {
> - if (m) {
> - char *str;
> - char *last;
> -
> - // skip comments
> - do {
> - if (!(str = fgets(buf, buflen, fp)))
> - return NULL;
> - m->mnt_fsname = strtok_r(str, " \t\n", &last);
> - if (m->mnt_fsname == NULL)
> - return NULL;
> - } while (*(m->mnt_fsname) == '#');
> -
> - m->mnt_dir = strtok_r((char *)NULL, " \t\n", &last);
> - m->mnt_type = strtok_r((char *)NULL, " \t\n", &last);
> - m->mnt_opts = strtok_r((char *)NULL, " \t\n", &last);
> - if (m->mnt_opts == NULL)
> - return NULL;
> - }
> - return m;
> -}
> -#endif
> -
> JNIEXPORT jint JNICALL
> Java_sun_nio_fs_LinuxNativeDispatcher_getmntent(JNIEnv* env, jclass this,
> jlong value, jobject entry)
> diff -r 91482de10f40 src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c
> --- a/src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c Wed Feb 10 14:17:12 2016 -0500
> +++ b/src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c Fri Feb 19 03:22:47 2016 +0330
> @@ -108,27 +108,6 @@
> * functionality into corresponding, platform-specific os_ functions.
> */
>
> -#ifdef __ANDROID__
> -/*
> - * TODO: Android lacks support for the methods listed below. In it's place are
> - * alternatives that use existing Android functionality, but lack reentrant
> - * support. Determine if the following are the most suitable alternatives.
> - *
> - */
> -static int getpwuid_r(uid_t uid, struct passwd* pwd, char* buf, size_t buflen, struct passwd** result)
> -{
> - *result = NULL;
> - errno = 0;
> - pwd = getpwuid(uid);
> - if (pwd == NULL) {
> - return errno;
> - }
> - // buf not used by caller (see below)
> - *result = pwd;
> - return 0;
> -}
> -#endif
> -
> #ifndef WIFEXITED
> #define WIFEXITED(status) (((status)&0xFF) == 0)
> #endif
> diff -r 91482de10f40 src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
> --- a/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c Wed Feb 10 14:17:12 2016 -0500
> +++ b/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c Fri Feb 19 03:22:47 2016 +0330
> @@ -153,66 +153,6 @@
> #endif
> static fdopendir_func* my_fdopendir_func = NULL;
>
> -#ifdef __ANDROID__
> -/*
> - * TODO: Android lacks support for the methods listed below. In it's place are
> - * alternatives that use existing Android functionality, but lack reentrant
> - * support. Determine if the following are the most suitable alternatives.
> - *
> - */
> -static int getpwuid_r(uid_t uid, struct passwd* pwd, char* buf, size_t buflen, struct passwd** result)
> -{
> - *result = NULL;
> - errno = 0;
> - pwd = getpwuid(uid);
> - if (pwd == NULL) {
> - return errno;
> - }
> - // buf not used by caller (see below)
> - *result = pwd;
> - return 0;
> -}
> -
> -static int getpwnam_r(const char *name, struct passwd* pwd, char* buf, size_t buflen, struct passwd** result)
> -{
> - *result = NULL;
> - errno = 0;
> - pwd = getpwnam(name);
> - if (pwd == NULL) {
> - return errno;
> - }
> - // buf not used by caller (see below)
> - *result = pwd;
> - return 0;
> -}
> -
> -static int getgrgid_r(gid_t gid, struct group* grp, char* buf, size_t buflen, struct group** result)
> -{
> - *result = NULL;
> - errno = 0;
> - grp = getgrgid(gid);
> - if (grp == NULL) {
> - return errno;
> - }
> - // buf not used by caller (see below)
> - *result = grp;
> - return 0;
> -}
> -
> -static int getgrnam_r(const char *name, struct group* grp, char* buf, size_t buflen, struct group** result)
> -{
> - *result = NULL;
> - errno = 0;
> - grp = getgrnam(name);
> - if (grp == NULL) {
> - return errno;
> - }
> - // buf not used by caller (see below)
> - *result = grp;
> - return 0;
> -}
> -#endif
> -
> /**
> * fstatat missing from glibc on Linux. Temporary workaround
> * for x86/x64.
> diff -r 91482de10f40 src/jdk.security.auth/unix/native/libjaas/Unix.c
> --- a/src/jdk.security.auth/unix/native/libjaas/Unix.c Wed Feb 10 14:17:12 2016 -0500
> +++ b/src/jdk.security.auth/unix/native/libjaas/Unix.c Fri Feb 19 03:22:47 2016 +0330
> @@ -38,21 +38,6 @@
> #include <string.h>
> #include <errno.h>
>
> -#ifdef __ANDROID__
> -static int getpwuid_r(uid_t uid, struct passwd* pwd, char* buf, size_t buflen, struct passwd** result)
> -{
> - *result = NULL;
> - errno = 0;
> - pwd = getpwuid(uid);
> - if (pwd == NULL) {
> - return errno;
> - }
> - // buf not used by caller (see below)
> - *result = pwd;
> - return 0;
> -}
> -#endif
> -
> /*
> * Declare library specific JNI_Onload entry if static build
> */
>
>
> hotspot.diff
>
>
> diff -r de1d92b01bae src/os/linux/vm/perfMemory_linux.cpp
> --- a/src/os/linux/vm/perfMemory_linux.cpp Wed Feb 10 14:15:17 2016 -0500
> +++ b/src/os/linux/vm/perfMemory_linux.cpp Fri Feb 19 03:23:39 2016 +0330
> @@ -44,7 +44,7 @@
> # include <pwd.h>
>
> #ifdef __ANDROID__
> -static int getpwuid_r(uid_t uid, struct passwd* pwd, char* buf, size_t buflen, struct passwd** result)
> +int getpwuid_r(uid_t uid, struct passwd* pwd, char* buf, size_t buflen, struct passwd** result)
> {
> *result = NULL;
> errno = 0;
> diff -r de1d92b01bae src/os_cpu/linux_x86/vm/os_linux_x86.cpp
> --- a/src/os_cpu/linux_x86/vm/os_linux_x86.cpp Wed Feb 10 14:15:17 2016 -0500
> +++ b/src/os_cpu/linux_x86/vm/os_linux_x86.cpp Fri Feb 19 03:23:39 2016 +0330
> @@ -73,11 +73,8 @@
> # include <sys/wait.h>
> # include <pwd.h>
> # include <poll.h>
> -#ifdef __ANDROID__
> -# include <asm/elf.h>
> -# include <asm/sigcontext.h>
> -#else
> # include <ucontext.h>
> +#ifndef __ANDROID__
> # include <fpu_control.h>
> #endif
>
> @@ -88,22 +85,6 @@
> #define _FPU_SETCW(cw) __asm__ ("fldcw %0" : : "m" (*&cw))
> #endif
>
> -#ifdef __ANDROID__
> -typedef elf_greg_t greg_t;
> -#define SPELL_REG_SP "esp"
> -#define SPELL_REG_FP "ebp"
> -#define CTX_REG_AX eax
> -#define CTX_REG_BX ebx
> -#define CTX_REG_CX ecx
> -#define CTX_REG_DX edx
> -#define CTX_REG_DI edi
> -#define CTX_REG_SI esi
> -#define CTX_REG_PC eip
> -#define CTX_REG_SP esp
> -#define CTX_REG_BP ebp
> -#define CTX_REG_TRAPNO trapno
> -#define CTX_REG_FL eflags
> -#else
> #ifdef AMD64
> #define SPELL_REG_SP "rsp"
> #define SPELL_REG_FP "rbp"
> @@ -143,7 +124,6 @@
> #define CTX_REG_TRAPNO gregs[REG_TRAPNO]
> #define CTX_REG_FL gregs[REG_EFL]
> #endif // AMD64
> -#endif // __ANDROID__
>
> address os::current_stack_pointer() {
> #ifdef SPARC_WORKS
> diff -r de1d92b01bae src/share/vm/utilities/globalDefinitions_gcc.hpp
> --- a/src/share/vm/utilities/globalDefinitions_gcc.hpp Wed Feb 10 14:15:17 2016 -0500
> +++ b/src/share/vm/utilities/globalDefinitions_gcc.hpp Fri Feb 19 03:23:39 2016 +0330
> @@ -74,26 +74,10 @@
> #endif // __STDC_LIMIT_MACROS
> #include <inttypes.h>
> #include <signal.h>
> -#ifdef __ANDROID__
> -#include <asm/sigcontext.h>
> -/* avoid conflicting ucontext definitions */
> -#define ucontext asm_ucontext
> -struct ucontext {
> - unsigned long uc_flags;
> - struct ucontext *uc_link;
> - stack_t uc_stack;
> - struct sigcontext uc_mcontext;
> - sigset_t uc_sigmask;
> -};
> -
> -typedef struct ucontext ucontext_t;
> -#endif //__ANDROID__
>
> #ifndef __OpenBSD__
> -#ifndef __ANDROID__
> #include <ucontext.h>
> #endif
> -#endif
> #ifdef __APPLE__
> #include <AvailabilityMacros.h>
> #include <mach/mach.h>
>
> --
>
> Best Regards,
> Ali Ebrahimi
> <hotspot.diff><jdk.diff>
More information about the mobile-dev
mailing list