[PATH] Quick backport Eclair's Dalvik to Donut based environment

Hacked by Jim Huang <jserv@0xlab.org>

Repository: dalvik
diff --git a/Android.mk b/Android.mk
index 32d5e34..c364574 100644
--- a/Android.mk
+++ b/Android.mk
@@ -14,6 +14,8 @@
 
 LOCAL_PATH := $(call my-dir)
 
+WITH_JIT := true
+
 subdirs := $(addprefix $(LOCAL_PATH)/,$(addsuffix /Android.mk, \
 		libdex \
 		vm \
diff --git a/libcore/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp b/libcore/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp
index 7b6023a..9caef10 100644
--- a/libcore/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp
+++ b/libcore/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp
@@ -1566,7 +1566,7 @@ static void mcastAddDropMembership (JNIEnv * env, int handle, jobject optVal,
                 memset(&ipv6Request, 0, requestLength);
                 ipv6Request.ipv6mr_multiaddr =
                         ((struct sockaddr_in6 *) &sockaddrP)->sin6_addr;
-                ipv6Request.ipv6mr_interface = interfaceIndex;
+                ipv6Request.ipv6mr_ifindex = interfaceIndex;
                 multicastRequest = &ipv6Request;
                 level = SOL_IPV6;
                 break;
diff --git a/vm/Dvm.mk b/vm/Dvm.mk
index 96f6dac..8ecf690 100644
--- a/vm/Dvm.mk
+++ b/vm/Dvm.mk
@@ -263,7 +263,7 @@ endif
 MTERP_ARCH_KNOWN := false
 
 ifeq ($(dvm_arch),arm)
-  #dvm_arch_variant := armv7-a
+  dvm_arch_variant := armv7-a
   #LOCAL_CFLAGS += -march=armv7-a -mfloat-abi=softfp -mfpu=vfp
   MTERP_ARCH_KNOWN := true
   # Select architecture-specific sources (armv4t, armv5te etc.)
diff --git a/vm/Thread.c b/vm/Thread.c
index be3e952..2d40ab6 100644
--- a/vm/Thread.c
+++ b/vm/Thread.c
@@ -30,8 +30,6 @@
 #include <errno.h>
 #include <fcntl.h>
 
-#include <cutils/sched_policy.h>
-
 #if defined(HAVE_PRCTL)
 #include <sys/prctl.h>
 #endif
@@ -3063,6 +3061,38 @@ static const int kNiceValues[10] = {
     ANDROID_PRIORITY_URGENT_DISPLAY         /* 10 (MAX_PRIORITY) */
 };
 
+int dvmChangeThreadSchedulerGroup(const char *cgroup)
+{
+#ifdef HAVE_ANDROID_OS
+    FILE *fp;
+    char path[255];
+    int rc;
+
+    sprintf(path, "/dev/cpuctl/%s/tasks", (cgroup ? cgroup : ""));
+
+    if (!(fp = fopen(path, "w"))) {
+#if ENABLE_CGROUP_ERR_LOGGING
+        LOGW("Unable to open %s (%s)\n", path, strerror(errno));
+#endif
+        return -errno;
+    }
+
+    rc = fprintf(fp, "0");
+    fclose(fp);
+
+    if (rc < 0) {
+#if ENABLE_CGROUP_ERR_LOGGING
+        LOGW("Unable to move pid %d to cgroup %s (%s)\n", getpid(),
+             (cgroup ? cgroup : "<default>"), strerror(errno));
+#endif
+    }
+
+    return (rc < 0) ? errno : 0;
+#else // HAVE_ANDROID_OS
+    return 0;
+#endif
+}
+
 /*
  * Change the priority of a system thread to match that of the Thread object.
  *
@@ -3080,10 +3110,10 @@ void dvmChangeThreadPriority(Thread* thread, int newPriority)
     }
     newNice = kNiceValues[newPriority-1];
 
-    if (newNice >= ANDROID_PRIORITY_BACKGROUND) {
-        set_sched_policy(dvmGetSysThreadId(), SP_BACKGROUND);
+    if (newPriority >= ANDROID_PRIORITY_BACKGROUND) {
+        dvmChangeThreadSchedulerGroup("bg_non_interactive");
     } else if (getpriority(PRIO_PROCESS, pid) >= ANDROID_PRIORITY_BACKGROUND) {
-        set_sched_policy(dvmGetSysThreadId(), SP_FOREGROUND);
+        dvmChangeThreadSchedulerGroup(NULL);
     }
 
     if (setpriority(PRIO_PROCESS, pid, newNice) != 0) {
diff --git a/vm/alloc/Heap.c b/vm/alloc/Heap.c
index 17d6a5c..c548190 100644
--- a/vm/alloc/Heap.c
+++ b/vm/alloc/Heap.c
@@ -27,8 +27,6 @@
 #include "utils/threads.h"      // need Android thread priorities
 #define kInvalidPriority        10000
 
-#include <cutils/sched_policy.h>
-
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <limits.h>
@@ -785,7 +783,7 @@ void dvmCollectGarbageInternal(bool collectSoftReferences)
          */
 
         if (priorityResult >= ANDROID_PRIORITY_BACKGROUND) {
-            set_sched_policy(dvmGetSysThreadId(), SP_FOREGROUND);
+            dvmChangeThreadSchedulerGroup(NULL);
         }
 
         if (setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_NORMAL) != 0) {
@@ -1038,7 +1036,7 @@ void dvmCollectGarbageInternal(bool collectSoftReferences)
         }
 
         if (oldThreadPriority >= ANDROID_PRIORITY_BACKGROUND) {
-            set_sched_policy(dvmGetSysThreadId(), SP_BACKGROUND);
+            dvmChangeThreadSchedulerGroup("bg_non_interactive");
         }
     }
     gcElapsedTime = (dvmGetRelativeTimeUsec() - gcHeap->gcStartTime) / 1000;
