Merge change 22183 into eclair

* changes:
  Progress toward indirect JNI references.
diff --git a/libcore/luni/src/test/java/tests/AllTests.java b/libcore/luni/src/test/java/tests/AllTests.java
index 9ef1aa8..26e58c1 100644
--- a/libcore/luni/src/test/java/tests/AllTests.java
+++ b/libcore/luni/src/test/java/tests/AllTests.java
@@ -49,6 +49,7 @@
         suite.addTest(tests.regex.AllTests.suite());
         suite.addTest(tests.security.AllTests.suite());
         suite.addTest(tests.sql.AllTests.suite());
+        suite.addTest(tests.suncompat.AllTests.suite());
         suite.addTest(tests.text.AllTests.suite());
         suite.addTest(tests.xml.AllTests.suite());
         suite.addTest(tests.xnet.AllTests.suite());
diff --git a/libcore/suncompat/src/main/java/sun/misc/Unsafe.java b/libcore/suncompat/src/main/java/sun/misc/Unsafe.java
index e880af2..6ae572f 100644
--- a/libcore/suncompat/src/main/java/sun/misc/Unsafe.java
+++ b/libcore/suncompat/src/main/java/sun/misc/Unsafe.java
@@ -52,9 +52,7 @@
          * Only code on the bootclasspath is allowed to get at the
          * Unsafe instance.
          */
-        ClassLoader calling = VMStack.getCallingClassLoader2();
-        ClassLoader current = Unsafe.class.getClassLoader();
-
+        ClassLoader calling = VMStack.getCallingClassLoader();
         if ((calling != null) && (calling != Unsafe.class.getClassLoader())) {
             throw new SecurityException("Unsafe access denied");
         }
diff --git a/libcore/suncompat/src/test/java/sun/misc/AllTests.java b/libcore/suncompat/src/test/java/sun/misc/AllTests.java
new file mode 100644
index 0000000..8ea3bcf
--- /dev/null
+++ b/libcore/suncompat/src/test/java/sun/misc/AllTests.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package sun.misc;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(AllTests.suite());
+    }
+
+    public static Test suite() {
+        TestSuite suite = tests.TestSuiteFactory.createTestSuite("Test for sun.misc");
+
+        // $JUnit-BEGIN$
+
+        suite.addTestSuite(UnsafeTest.class);
+
+        // $JUnit-END$
+
+        return suite;
+    }
+}
diff --git a/libcore/suncompat/src/test/java/sun/misc/UnsafeTest.java b/libcore/suncompat/src/test/java/sun/misc/UnsafeTest.java
new file mode 100644
index 0000000..338055b
--- /dev/null
+++ b/libcore/suncompat/src/test/java/sun/misc/UnsafeTest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package sun.misc;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import junit.framework.TestCase;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.Executors;
+
+@TestTargetClass(Unsafe.class)
+public class UnsafeTest extends TestCase {
+
+    @TestTargetNew(
+            level = TestLevel.PARTIAL,
+            notes = "",
+            method = "getUnsafe",
+            args = {}
+    )
+    public void test_getUnsafeForbidden() {
+        try {
+            Unsafe.getUnsafe();
+            fail();
+        } catch (SecurityException expected) {
+        }
+    }
+
+    /**
+     * Regression for 2053217. We used to look one level higher than necessary
+     * on the stack.
+     */
+    @TestTargetNew(
+            level = TestLevel.PARTIAL,
+            notes = "",
+            method = "getUnsafe",
+            args = {}
+    )
+    public void test_getUnsafeForbiddenWithSystemCaller() throws Exception {
+        Callable<Object> callable = Executors.callable(new Runnable() {
+            public void run() {
+                Unsafe.getUnsafe();
+            }
+        });
+
+        try {
+            callable.call();
+            fail();
+        } catch (SecurityException expected) {
+        }
+    }
+}
diff --git a/libcore/suncompat/src/test/java/tests/suncompat/AllTests.java b/libcore/suncompat/src/test/java/tests/suncompat/AllTests.java
new file mode 100644
index 0000000..0884517
--- /dev/null
+++ b/libcore/suncompat/src/test/java/tests/suncompat/AllTests.java
@@ -0,0 +1,38 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.suncompat;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite that includes all tests for the suncompat project.
+ */
+public class AllTests {
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(AllTests.suite());
+    }
+
+    public static Test suite() {
+        TestSuite suite = tests.TestSuiteFactory.createTestSuite("All suncompat test suites");
+        // $JUnit-BEGIN$
+        suite.addTest(sun.misc.AllTests.suite());
+        // $JUnit-END$
+        return suite;
+    }
+}
diff --git a/libcore/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLParameters.java b/libcore/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLParameters.java
index 60a5535..fb05722 100644
--- a/libcore/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLParameters.java
+++ b/libcore/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLParameters.java
@@ -431,5 +431,13 @@
         }
 // END android-changed
     }
-}
 
+    /**
+     * Gets the default trust manager.
+     *
+     * TODO: Move this to a published API under dalvik.system.
+     */
+    public static X509TrustManager getDefaultTrustManager() {
+        return defaultTrustManager;
+    }
+}
diff --git a/vm/Misc.c b/vm/Misc.c
index 6b1372c..f8f7256 100644
--- a/vm/Misc.c
+++ b/vm/Misc.c
@@ -280,6 +280,7 @@
         pBits->storage = realloc(pBits->storage, newSize * sizeof(u4));
         memset(&pBits->storage[pBits->storageSize], 0x00,
             (newSize - pBits->storageSize) * sizeof(u4));
+        pBits->storageSize = newSize;
     }
 
     pBits->storage[num >> 5] |= 1 << (num & 0x1f);
diff --git a/vm/native/dalvik_system_SamplingProfiler.c b/vm/native/dalvik_system_SamplingProfiler.c
index 13f4f46..2381ade 100644
--- a/vm/native/dalvik_system_SamplingProfiler.c
+++ b/vm/native/dalvik_system_SamplingProfiler.c
@@ -316,7 +316,7 @@
  * Heurtistically guesses whether or not 'method' actually points to a Method
  * struct.
  */
-static bool isValidMethod(Method* method) {
+static bool isValidMethod(const Method* method) {
     if (!dvmLinearAllocContains(method, sizeof(Method))) {
         LOGW("Method* is not in linear allocation table.");
         return false;
@@ -526,7 +526,7 @@
             setIndex >= 0 && wrapperIndex < set->size;
             setIndex--) {
         MethodCount* mc = &set->entries[setIndex];
-        Method* method = mc->method;
+        const Method* method = mc->method;
         if (method != NULL && isValidMethod(method)) {
             MethodCountWrapper* wrapper = &wrappers[wrapperIndex];
             wrapper->methodCount = mc;
@@ -612,4 +612,4 @@
     { "setEventThread", "(ILjava/lang/Thread;)V",
             Dalvik_dalvik_system_SamplingProfiler_setEventThread },
     { NULL, NULL, NULL },
-};
\ No newline at end of file
+};
diff --git a/vm/oo/Class.c b/vm/oo/Class.c
index 50ef961..1bde718 100644
--- a/vm/oo/Class.c
+++ b/vm/oo/Class.c
@@ -4446,7 +4446,7 @@
              * f->byteOffset is the offset from the beginning of
              * obj, not the offset into obj->instanceData.
              */
-            assert(f->byteOffset >= CLASS_SMALLEST_OFFSET);
+            assert(f->byteOffset >= (int) CLASS_SMALLEST_OFFSET);
             assert((f->byteOffset & (CLASS_OFFSET_ALIGNMENT - 1)) == 0);
             u4 newBit = CLASS_BIT_FROM_OFFSET(f->byteOffset);
             if (newBit != 0) {