Merge change I690f0051

* changes:
  Fixing a simple concurrency issue in the jtreg runner.
diff --git a/libcore/NativeCode.mk b/libcore/NativeCode.mk
index 0dfad3b..57c4903 100644
--- a/libcore/NativeCode.mk
+++ b/libcore/NativeCode.mk
@@ -74,7 +74,7 @@
 
 # Extract out the allowed LOCAL_* variables. Note: $(sort) also
 # removes duplicates.
-core_c_includes := $(sort $(LOCAL_C_INCLUDES) $(JNI_H_INCLUDE))
+core_c_includes := $(sort dalvik/libcore/include $(LOCAL_C_INCLUDES) $(JNI_H_INCLUDE))
 core_shared_libraries := $(sort $(LOCAL_SHARED_LIBRARIES))
 core_static_libraries := $(sort $(LOCAL_STATIC_LIBRARIES))
 
@@ -118,4 +118,4 @@
 
     # TODO: Figure out cacerts.bks for the host.
 
-endif
\ No newline at end of file
+endif
diff --git a/libcore/include/LocalArray.h b/libcore/include/LocalArray.h
new file mode 100644
index 0000000..85b5a49
--- /dev/null
+++ b/libcore/include/LocalArray.h
@@ -0,0 +1,55 @@
+#ifndef LOCAL_ARRAY_H_included
+#define LOCAL_ARRAY_H_included
+
+#include <cstddef>
+#include <new>
+
+/**
+ * A fixed-size array with a size hint. That number of bytes will be allocated
+ * on the stack, and used if possible, but if more bytes are requested at
+ * construction time, a buffer will be allocated on the heap (and deallocated
+ * by the destructor).
+ *
+ * The API is intended to be a compatible subset of C++0x's std::array.
+ */
+template <size_t STACK_BYTE_COUNT>
+class LocalArray {
+public:
+    /**
+     * Allocates a new fixed-size array of the given size. If this size is
+     * less than or equal to the template parameter STACK_BYTE_COUNT, an
+     * internal on-stack buffer will be used. Otherwise a heap buffer will
+     * be allocated.
+     */
+    LocalArray(size_t desiredByteCount) : mSize(desiredByteCount) {
+        if (desiredByteCount > STACK_BYTE_COUNT) {
+            mPtr = new char[mSize];
+        } else {
+            mPtr = &mOnStackBuffer[0];
+        }
+    }
+
+    /**
+     * Frees the heap-allocated buffer, if there was one.
+     */
+    ~LocalArray() {
+        if (mPtr != &mOnStackBuffer[0]) {
+            delete[] mPtr;
+        }
+    }
+
+    // Capacity.
+    size_t size() { return mSize; }
+    bool empty() { return mSize == 0; }
+
+    // Element access.
+    char& operator[](size_t n) { return mPtr[n]; }
+    const char& operator[](size_t n) const { return mPtr[n]; }
+
+private:
+    char mOnStackBuffer[STACK_BYTE_COUNT];
+    char* mPtr;
+    size_t mSize;
+};
+
+#endif // LOCAL_ARRAY_H_included
diff --git a/libcore/luni/src/main/java/java/net/DatagramSocket.java b/libcore/luni/src/main/java/java/net/DatagramSocket.java
index ba5e207..0e06788 100644
--- a/libcore/luni/src/main/java/java/net/DatagramSocket.java
+++ b/libcore/luni/src/main/java/java/net/DatagramSocket.java
@@ -51,9 +51,11 @@
     private static class Lock {
     }
 
-    static {
-        Platform.getNetworkSystem().oneTimeInitialization(true);
-    }
+    // BEGIN android-removed: we do this statically, when we start the VM.
+    // static {
+    //     Platform.getNetworkSystem().oneTimeInitialization(true);
+    // }
+    // END android-removed
 
     private Object lock = new Lock();
 
diff --git a/libcore/luni/src/main/java/java/net/ServerSocket.java b/libcore/luni/src/main/java/java/net/ServerSocket.java
index f9d5b22..6942577 100644
--- a/libcore/luni/src/main/java/java/net/ServerSocket.java
+++ b/libcore/luni/src/main/java/java/net/ServerSocket.java
@@ -42,9 +42,11 @@
 
     private boolean isClosed;
 
-    static {
-        Platform.getNetworkSystem().oneTimeInitialization(true);
-    }
+    // BEGIN android-removed: we do this statically, when we start the VM.
+    // static {
+    //    Platform.getNetworkSystem().oneTimeInitialization(true);
+    // }
+    // END android-removed
 
     /**
      * Constructs a new {@code ServerSocket} instance which is not bound to any
diff --git a/libcore/luni/src/main/java/java/net/Socket.java b/libcore/luni/src/main/java/java/net/Socket.java
index 5289566..6ecc548 100644
--- a/libcore/luni/src/main/java/java/net/Socket.java
+++ b/libcore/luni/src/main/java/java/net/Socket.java
@@ -78,9 +78,11 @@
         return logger;
     }
 
-    static {
-        Platform.getNetworkSystem().oneTimeInitialization(true);
-    }
+    // BEGIN android-removed: we do this statically, when we start the VM.
+    // static {
+    //     Platform.getNetworkSystem().oneTimeInitialization(true);
+    // }
+    // END android-removed
 
     /**
      * Creates a new unconnected socket. When a SocketImplFactory is defined it
diff --git a/libcore/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java b/libcore/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java
index 1ba7d8c..a082b47 100644
--- a/libcore/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java
+++ b/libcore/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java
@@ -349,12 +349,13 @@
             if (atEnd) {
                 return;
             }
+            skipOutstandingChunks();
             // END android-added
 
             // BEGIN android-note
             // Removed "!atEnd" below because of the check added above.
             // END android-note
-            if(available() > 0) {
+            if (available() > 0) {
                 disconnect(true);
             } else {
                 disconnect(false);
@@ -366,6 +367,21 @@
             }
         }
 
+        // BEGIN android-added
+        // If we're asked to close a stream with unread chunks, we need to skip them.
+        // Otherwise the next caller on this connection will receive that data.
+        // See: http://code.google.com/p/android/issues/detail?id=2939
+        private void skipOutstandingChunks() throws IOException {
+            while (!atEnd) {
+                while (bytesRemaining > 0) {
+                    long skipped = is.skip(bytesRemaining);
+                    bytesRemaining -= skipped;
+                }
+                readChunkSize();
+            }
+        }
+        // END android-added
+
         @Override
         public int available() throws IOException {
             // BEGIN android-added
@@ -1714,4 +1730,4 @@
             }
         }
     }
-}
\ No newline at end of file
+}
diff --git a/libcore/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java b/libcore/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
index 71a272a..a76618f 100644
--- a/libcore/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
+++ b/libcore/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
@@ -260,5 +260,7 @@
 
     public Channel inheritedChannel();
 
-    public void oneTimeInitialization(boolean jcl_supports_ipv6);
+    // BEGIN android-removed: we do this statically, when we start the VM.
+    // public void oneTimeInitialization(boolean jcl_supports_ipv6);
+    // END android-removed
 }
diff --git a/libcore/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java b/libcore/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
index 9901412..831b492 100644
--- a/libcore/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
+++ b/libcore/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
@@ -46,7 +46,7 @@
 
     private static final int INETADDR_REACHABLE = 0;
 
-    private static boolean isNetworkInited = false;
+    // private static boolean isNetworkInited = false; android-removed
 
     private static OSNetworkSystem singleton = new OSNetworkSystem();
 
@@ -310,14 +310,10 @@
     static native void listenStreamSocketImpl(FileDescriptor aFD, int backlog)
             throws SocketException;
 
-    public void oneTimeInitialization(boolean jcl_supports_ipv6) {
-        if (!isNetworkInited) {
-            oneTimeInitializationImpl(jcl_supports_ipv6);
-            isNetworkInited = true;
-        }
-    }
-
-    native void oneTimeInitializationImpl (boolean jcl_supports_ipv6);
+    // BEGIN android-removed: we do this statically, when we start the VM.
+    // public void oneTimeInitialization(boolean jcl_supports_ipv6);
+    // native void oneTimeInitializationImpl(boolean jcl_supports_ipv6);
+    // END android-removed
 
     /**
      * Peek on the socket, update <code>sender</code> address and answer the
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 af2e08a..b4b6d92 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
@@ -25,6 +25,7 @@
 
 #include "AndroidSystemNatives.h"
 #include "JNIHelp.h"
+#include "LocalArray.h"
 #include "jni.h"
 
 #include <arpa/inet.h>
@@ -485,15 +486,17 @@
         return NULL;
     }
 
-    char ipString[INET6_ADDRSTRLEN];
-    int stringLength = env->GetStringUTFLength(javaString);
-    env->GetStringUTFRegion(javaString, 0, stringLength, ipString);
+    // Convert the String to UTF bytes.
+    size_t byteCount = env->GetStringUTFLength(javaString);
+    LocalArray<INET6_ADDRSTRLEN> bytes(byteCount + 1);
+    char* ipString = &bytes[0];
+    env->GetStringUTFRegion(javaString, 0, env->GetStringLength(javaString), ipString);
 
     // Accept IPv6 addresses (only) in square brackets for compatibility.
-    if (ipString[0] == '[' && ipString[stringLength - 1] == ']' &&
+    if (ipString[0] == '[' && ipString[byteCount - 1] == ']' &&
             index(ipString, ':') != NULL) {
-        memmove(ipString, ipString + 1, stringLength - 2);
-        ipString[stringLength - 2] = '\0';
+        memmove(ipString, ipString + 1, byteCount - 2);
+        ipString[byteCount - 2] = '\0';
     }
 
     jbyteArray result = NULL;
@@ -1345,10 +1348,7 @@
 }
 #endif // def ENABLE_MULTICAST
 
-static void osNetworkSystem_oneTimeInitializationImpl(JNIEnv* env, jobject obj,
-        jboolean jcl_supports_ipv6) {
-    // LOGD("ENTER oneTimeInitializationImpl of OSNetworkSystem");
-
+static bool initCachedFields(JNIEnv* env) {
     memset(&gCachedFields, 0, sizeof(gCachedFields));
     struct CachedFields *c = &gCachedFields;
 
@@ -1368,7 +1368,7 @@
     for (unsigned i = 0; i < sizeof(classes) / sizeof(classes[0]); i++) {
         classInfo c = classes[i];
         jclass tempClass = env->FindClass(c.name);
-        if (tempClass == NULL) return;
+        if (tempClass == NULL) return false;
         *c.clazz = (jclass) env->NewGlobalRef(tempClass);
     }
 
@@ -1393,7 +1393,7 @@
         } else {
             *m.method = env->GetMethodID(m.clazz, m.name, m.signature);
         }
-        if (*m.method == NULL) return;
+        if (*m.method == NULL) return false;
     }
 
     struct fieldInfo {
@@ -1417,8 +1417,9 @@
     for (unsigned i = 0; i < sizeof(fields) / sizeof(fields[0]); i++) {
         fieldInfo f = fields[i];
         *f.field = env->GetFieldID(f.clazz, f.name, f.type);
-        if (*f.field == NULL) return;
+        if (*f.field == NULL) return false;
     }
+    return true;
 }
 
 /**
@@ -2918,7 +2919,6 @@
  */
 static JNINativeMethod gMethods[] = {
     /* name, signature, funcPtr */
-    { "oneTimeInitializationImpl",         "(Z)V",                                                                     (void*) osNetworkSystem_oneTimeInitializationImpl          },
     { "createStreamSocketImpl",            "(Ljava/io/FileDescriptor;Z)V",                                             (void*) osNetworkSystem_createStreamSocketImpl             },
     { "createDatagramSocketImpl",          "(Ljava/io/FileDescriptor;Z)V",                                             (void*) osNetworkSystem_createDatagramSocketImpl           },
     { "readSocketImpl",                    "(Ljava/io/FileDescriptor;[BIII)I",                                         (void*) osNetworkSystem_readSocketImpl                     },
@@ -2963,7 +2963,7 @@
 };
 
 int register_org_apache_harmony_luni_platform_OSNetworkSystem(JNIEnv* env) {
-    return jniRegisterNativeMethods(env,
+    return initCachedFields(env) && jniRegisterNativeMethods(env,
             "org/apache/harmony/luni/platform/OSNetworkSystem",
             gMethods,
             NELEM(gMethods));
diff --git a/libcore/luni/src/test/java/java/net/AllTests.java b/libcore/luni/src/test/java/java/net/AllTests.java
index 6d26f0d..3731af4 100644
--- a/libcore/luni/src/test/java/java/net/AllTests.java
+++ b/libcore/luni/src/test/java/java/net/AllTests.java
@@ -23,6 +23,7 @@
     public static final Test suite() {
         TestSuite suite = tests.TestSuiteFactory.createTestSuite();
         suite.addTestSuite(java.net.SocketTest.class);
+        suite.addTestSuite(java.net.URLConnectionTest.class);
         return suite;
     }
 }
diff --git a/libcore/luni/src/test/java/java/net/URLConnectionTest.java b/libcore/luni/src/test/java/java/net/URLConnectionTest.java
new file mode 100644
index 0000000..c5fd43f
--- /dev/null
+++ b/libcore/luni/src/test/java/java/net/URLConnectionTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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 java.net;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+import tests.support.Support_PortManager;
+import tests.support.Support_TestWebServer;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class URLConnectionTest extends junit.framework.TestCase {
+    private int port;
+    private Support_TestWebServer server;
+    
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        port = Support_PortManager.getNextPort();
+        server = new Support_TestWebServer();
+        server.initServer(port, false);
+    }
+    
+    @Override
+    public void tearDown()throws Exception {
+        super.tearDown();
+        server.close();
+    }
+    
+    private String readFirstLine() throws Exception {
+        URLConnection connection = new URL("http://localhost:" + port + "/test1").openConnection();
+        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+        String result = in.readLine();
+        in.close();
+        return result;
+    }
+    
+    // Check that if we don't read to the end of a response, the next request on the
+    // recycled connection doesn't get the unread tail of the first request's response.
+    // http://code.google.com/p/android/issues/detail?id=2939
+    public void test_2939() throws Exception {
+        server.setChunked(true);
+        server.setMaxChunkSize(8);
+        assertTrue(readFirstLine().equals("<html>"));
+        assertTrue(readFirstLine().equals("<html>"));
+    }
+}
diff --git a/libcore/nio/src/main/java/java/nio/channels/DatagramChannel.java b/libcore/nio/src/main/java/java/nio/channels/DatagramChannel.java
index 31b0825..3281cf4 100644
--- a/libcore/nio/src/main/java/java/nio/channels/DatagramChannel.java
+++ b/libcore/nio/src/main/java/java/nio/channels/DatagramChannel.java
@@ -44,9 +44,11 @@
 public abstract class DatagramChannel extends AbstractSelectableChannel
         implements ByteChannel, ScatteringByteChannel, GatheringByteChannel {
 
-    static {
-        Platform.getNetworkSystem().oneTimeInitialization(true);
-    }
+    // BEGIN android-removed: we do this statically, when we start the VM.
+    // static {
+    //     Platform.getNetworkSystem().oneTimeInitialization(true);
+    // }
+    // END android-removed
 
     /**
      * Constructs a new {@code DatagramChannel}.
diff --git a/libcore/nio/src/main/java/java/nio/channels/SocketChannel.java b/libcore/nio/src/main/java/java/nio/channels/SocketChannel.java
index 40003ea..ba03a2a 100644
--- a/libcore/nio/src/main/java/java/nio/channels/SocketChannel.java
+++ b/libcore/nio/src/main/java/java/nio/channels/SocketChannel.java
@@ -59,9 +59,11 @@
 public abstract class SocketChannel extends AbstractSelectableChannel implements
         ByteChannel, ScatteringByteChannel, GatheringByteChannel {
 
-    static {
-        Platform.getNetworkSystem().oneTimeInitialization(true);
-    }
+    // BEGIN android-removed: we do this statically, when we start the VM.
+    // static {
+    //     Platform.getNetworkSystem().oneTimeInitialization(true);
+    // }
+    // END android-removed
 
     /**
      * Constructs a new {@code SocketChannel}.
diff --git a/libcore/support/src/test/java/tests/support/Support_TestWebData.java b/libcore/support/src/test/java/tests/support/Support_TestWebData.java
index 6f414ea..b72fdfd 100644
--- a/libcore/support/src/test/java/tests/support/Support_TestWebData.java
+++ b/libcore/support/src/test/java/tests/support/Support_TestWebData.java
@@ -21,61 +21,32 @@
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.util.Date;
 
 /**
  * Represents test data used by the Request API tests
  */
 public class Support_TestWebData {
-
-  /*
-   * Simple Html body
-   * <html>
-   * <body>
-   * <h1>Hello World!</h1>
-   * </body>
-   * </html>
-   */
-  public final static byte[] test1 = {
-    (byte)0x3c, (byte)0x68, (byte)0x74, (byte)0x6d,
-    (byte)0x6c, (byte)0x3e, (byte)0x0a, (byte)0x3c,
-    (byte)0x62, (byte)0x6f, (byte)0x64, (byte)0x79,
-    (byte)0x3e, (byte)0x0a, (byte)0x3c, (byte)0x68,
-    (byte)0x31, (byte)0x3e, (byte)0x48, (byte)0x65,
-    (byte)0x6c, (byte)0x6c, (byte)0x6f, (byte)0x20,
-    (byte)0x57, (byte)0x6f, (byte)0x72, (byte)0x6c,
-    (byte)0x64, (byte)0x21, (byte)0x3c, (byte)0x2f,
-    (byte)0x68, (byte)0x31, (byte)0x3e, (byte)0x0a,
-    (byte)0x3c, (byte)0x2f, (byte)0x62, (byte)0x6f,
-    (byte)0x64, (byte)0x79, (byte)0x3e, (byte)0x0a,
-    (byte)0x3c, (byte)0x2f, (byte)0x68, (byte)0x74,
-    (byte)0x6d, (byte)0x6c, (byte)0x3e, (byte)0x0a
-  };
-
-  /*
-   * Simple Html body
-   * <html>
-   * <body>
-   * <h1>Hello World!</h1>
-   * </body>
-   * </html>
-   */
-  public final static byte[] test2 = {
-    (byte)0x3c, (byte)0x68, (byte)0x74, (byte)0x6d,
-    (byte)0x6c, (byte)0x3e, (byte)0x0a, (byte)0x3c,
-    (byte)0x62, (byte)0x6f, (byte)0x64, (byte)0x79,
-    (byte)0x3e, (byte)0x0a, (byte)0x3c, (byte)0x68,
-    (byte)0x31, (byte)0x3e, (byte)0x48, (byte)0x65,
-    (byte)0x6c, (byte)0x6c, (byte)0x6f, (byte)0x20,
-    (byte)0x57, (byte)0x6f, (byte)0x72, (byte)0x6c,
-    (byte)0x64, (byte)0x21, (byte)0x3c, (byte)0x2f,
-    (byte)0x68, (byte)0x31, (byte)0x3e, (byte)0x0a,
-    (byte)0x3c, (byte)0x2f, (byte)0x62, (byte)0x6f,
-    (byte)0x64, (byte)0x79, (byte)0x3e, (byte)0x0a,
-    (byte)0x3c, (byte)0x2f, (byte)0x68, (byte)0x74,
-    (byte)0x6d, (byte)0x6c, (byte)0x3e, (byte)0x0a
-  };
-
+  public final static byte[] test1 = utfBytes();
+  public final static byte[] test2 = newBinaryFile(8192);
+  
+  private static byte[] utfBytes() {
+    try {
+      return "<html>\n<body>\n<h1>Hello World!</h1>\n</body>\n</html>\n".getBytes("UTF-8");
+    } catch (UnsupportedEncodingException ex) {
+      throw new AssertionError();
+    }
+  }
+  
+  private static byte[] newBinaryFile(int byteCount) {
+    byte[] result = new byte[byteCount];
+    for (int i = 0; i < result.length; ++i) {
+      result[i] = (byte) i;
+    }
+    return result;
+  }
+  
   // string for test request post body
   public final static String postContent = "user=111";
   
@@ -89,8 +60,8 @@
    * List of static test cases for use with test server
    */
   public static Support_TestWebData[] testParams = {
-    new Support_TestWebData(52, 14000000, "test1", "text/html", false, 0),
-    new Support_TestWebData(52, 14000002, "test2", "unknown/unknown", false,
+    new Support_TestWebData(test1.length, 14000000, "test1", "text/html", false, 0),
+    new Support_TestWebData(test2.length, 14000002, "test2", "unknown/unknown", false,
             new Date().getTime() + 100000)
   };
 
diff --git a/libcore/support/src/test/java/tests/support/Support_TestWebServer.java b/libcore/support/src/test/java/tests/support/Support_TestWebServer.java
index 8c88cc0..b7e8b38 100644
--- a/libcore/support/src/test/java/tests/support/Support_TestWebServer.java
+++ b/libcore/support/src/test/java/tests/support/Support_TestWebServer.java
@@ -79,6 +79,7 @@
 
     /* If set, this will cause response data to be sent in 'chunked' format */
     boolean chunked = false;
+    int maxChunkSize = 1024;
 
     /* If set, this will indicate a new redirection host */
     String redirectHost = null;
@@ -188,6 +189,14 @@
     }
 
     /**
+     * Sets the maximum byte count of any chunk if the server is using
+     * the "chunked" transfer encoding.
+     */
+    public void setMaxChunkSize(int maxChunkSize) {
+        this.maxChunkSize = maxChunkSize;
+    }
+
+    /**
      * Call this to specify the maximum number of sockets to accept
      * @param limit The number of sockets to accept
      */
@@ -718,9 +727,9 @@
         }
 
         // Print bytes to log and output stream
-        void psWrite(PrintStream ps, byte[] bytes, int len) throws IOException {
+        void psWrite(PrintStream ps, byte[] bytes, int offset, int count) throws IOException {
             log(new String(bytes));
-            ps.write(bytes, 0, len);
+            ps.write(bytes, offset, count);
         }
 
         // Print CRLF to log and output stream
@@ -856,39 +865,33 @@
          * @param ps The PrintStream to write to
          */
         void sendFile(PrintStream ps) throws IOException {
-            // For now just make a chunk with the whole of the test data
-            // It might be worth making this multiple chunks for large
-            // test data to test multiple chunks.
             if (testNum == -1) {
                 if (!Support_TestWebData.test0DataAvailable) {
-                    log("testdata was not initilaized");
+                    log("test data was not initialized");
                     return;
                 }
-                int dataSize = Support_TestWebData.test0Data.length;
-                if (chunked) {
-                    psPrint(ps, Integer.toHexString(dataSize));
-                    psWriteEOL(ps);
-                    psWrite(ps, Support_TestWebData.test0Data, dataSize);
-                    psWriteEOL(ps);
-                    psPrint(ps, "0");
-                    psWriteEOL(ps);
-                    psWriteEOL(ps);
-                } else {
-                    psWrite(ps, Support_TestWebData.test0Data, dataSize);
-                }
+                sendFile(ps, Support_TestWebData.test0Data);
             } else {
-                int dataSize = Support_TestWebData.tests[testNum].length;
-                if (chunked) {
-                    psPrint(ps, Integer.toHexString(dataSize));
+                sendFile(ps, Support_TestWebData.tests[testNum]);
+            }
+        }
+
+        void sendFile(PrintStream ps, byte[] bytes) throws IOException {
+            if (chunked) {
+                int offset = 0;
+                while (offset < bytes.length) {
+                    int chunkSize = Math.min(bytes.length - offset, maxChunkSize);
+                    psPrint(ps, Integer.toHexString(chunkSize));
                     psWriteEOL(ps);
-                    psWrite(ps, Support_TestWebData.tests[testNum], dataSize);
+                    psWrite(ps, bytes, offset, chunkSize);
                     psWriteEOL(ps);
-                    psPrint(ps, "0");
-                    psWriteEOL(ps);
-                    psWriteEOL(ps);
-                } else {
-                    psWrite(ps, Support_TestWebData.tests[testNum], dataSize);
+                    offset += chunkSize;
                 }
+                psPrint(ps, "0");
+                psWriteEOL(ps);
+                psWriteEOL(ps);
+            } else {
+                psWrite(ps, bytes, 0, bytes.length);
             }
         }
     }
diff --git a/libcore/tools/dalvik_jtreg/expectations/java.io.BufferedReader.ReadLine.expected b/libcore/tools/dalvik_jtreg/expectations/java.io.BufferedReader.ReadLine.expected
new file mode 100644
index 0000000..36bf26c
--- /dev/null
+++ b/libcore/tools/dalvik_jtreg/expectations/java.io.BufferedReader.ReadLine.expected
@@ -0,0 +1,5 @@
+# The RI avoids blocking calls when '\r' is the last character. We don't
+# bother since that adds complexity to every other read call, and '\r' as the
+# last character will be diminishingly rare anyway.
+result=EXEC_FAILED
+pattern=.*java.lang.RuntimeException: Read past limit.*
diff --git a/libcore/tools/dalvik_jtreg/expectations/java.io.BufferedReader.Ready.expected b/libcore/tools/dalvik_jtreg/expectations/java.io.BufferedReader.Ready.expected
new file mode 100644
index 0000000..b939046
--- /dev/null
+++ b/libcore/tools/dalvik_jtreg/expectations/java.io.BufferedReader.Ready.expected
@@ -0,0 +1,5 @@
+# The RI avoids blocking calls when '\r' is the last character. We don't
+# bother since that adds complexity to every other read call, and '\r' as the
+# last character will be diminishingly rare anyway.
+result=EXEC_FAILED
+pattern=.*Hit infinite wait condition.*
diff --git a/libcore/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_OpenSSLSocketImpl.cpp b/libcore/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_OpenSSLSocketImpl.cpp
index 538b7f3..1a6c3ae 100644
--- a/libcore/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_OpenSSLSocketImpl.cpp
+++ b/libcore/x-net/src/main/native/org_apache_harmony_xnet_provider_jsse_OpenSSLSocketImpl.cpp
@@ -16,9 +16,10 @@
 
 #define LOG_TAG "OpenSSLSocketImpl"
 
-#include <cutils/log.h>
-#include <jni.h>
-#include <JNIHelp.h>
+#include "JNIHelp.h"
+#include "LocalArray.h"
+#include "cutils/log.h"
+#include "jni.h"
 
 #include <stdio.h>
 #include <string.h>
@@ -53,14 +54,12 @@
  * stored in a freshly-allocated BIO memory buffer.
  */
 static BIO *stringToMemBuf(JNIEnv* env, jstring string) {
-    BIO *result = BIO_new(BIO_s_mem());
-    jsize length = env->GetStringUTFLength(string);
-    char buf[length + 1];
-    
-    env->GetStringUTFRegion(string, 0, env->GetStringLength(string), buf);
-    buf[length] = '\0';
+    jsize byteCount = env->GetStringUTFLength(string);
+    LocalArray<1024> buf(byteCount + 1);
+    env->GetStringUTFRegion(string, 0, env->GetStringLength(string), &buf[0]);
 
-    BIO_puts(result, buf);
+    BIO* result = BIO_new(BIO_s_mem());
+    BIO_puts(result, &buf[0]);
     return result;
 }
 
diff --git a/libcore/xml/src/main/java/org/kxml2/wap/Wbxml.java b/libcore/xml/src/main/java/org/kxml2/wap/Wbxml.java
deleted file mode 100644
index 5b0c2d3..0000000
--- a/libcore/xml/src/main/java/org/kxml2/wap/Wbxml.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/* Copyright (c) 2002,2003, Stefan Haustein, Oberhausen, Rhld., Germany
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The  above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE. */
-
-package org.kxml2.wap;
-
-
-/** contains the WBXML constants  */
-
-
-public interface Wbxml {
-
-    static public final int SWITCH_PAGE = 0;
-    static public final int END = 1;
-    static public final int ENTITY = 2;
-    static public final int STR_I = 3;
-    static public final int LITERAL = 4;
-    static public final int EXT_I_0 = 0x40;
-    static public final int EXT_I_1 = 0x41;
-    static public final int EXT_I_2 = 0x42;
-    static public final int PI = 0x43;
-    static public final int LITERAL_C = 0x44;
-    static public final int EXT_T_0 = 0x80;
-    static public final int EXT_T_1 = 0x81;
-    static public final int EXT_T_2 = 0x82;
-    static public final int STR_T = 0x83;
-    static public final int LITERAL_A = 0x084;
-    static public final int EXT_0 = 0x0c0;
-    static public final int EXT_1 = 0x0c1;
-    static public final int EXT_2 = 0x0c2;
-    static public final int OPAQUE = 0x0c3; 
-    static public final int LITERAL_AC = 0x0c4;
-}
diff --git a/libcore/xml/src/main/java/org/kxml2/wap/WbxmlParser.java b/libcore/xml/src/main/java/org/kxml2/wap/WbxmlParser.java
deleted file mode 100644
index 617e1d4..0000000
--- a/libcore/xml/src/main/java/org/kxml2/wap/WbxmlParser.java
+++ /dev/null
@@ -1,1075 +0,0 @@
-/* Copyright (c) 2002,2003,2004 Stefan Haustein, Oberhausen, Rhld., Germany
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The  above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE. */
-
-// Contributors: Bjorn Aadland, Chris Bartley, Nicola Fankhauser,
-//               Victor Havin,  Christian Kurzke, Bogdan Onoiu,
-//                Elias Ross, Jain Sanjay, David Santoro.
-
-package org.kxml2.wap;
-
-import java.io.*;
-import java.util.Vector;
-import java.util.Hashtable;
-
-import org.xmlpull.v1.*;
-
-
-public class WbxmlParser implements XmlPullParser {
-
-    static final String HEX_DIGITS = "0123456789abcdef";
-    
-    /** Parser event type for Wbxml-specific events. The Wbxml event code can be 
-     * accessed with getWapCode() */
-    
-    public static final int WAP_EXTENSION = 64;
-    
-    static final private String UNEXPECTED_EOF =
-    "Unexpected EOF";
-    static final private String ILLEGAL_TYPE =
-    "Wrong event type";
-    
-    private InputStream in;
-    
-    private int TAG_TABLE = 0;
-    private int ATTR_START_TABLE = 1;
-    private int ATTR_VALUE_TABLE = 2;
-    
-    private String[] attrStartTable;
-    private String[] attrValueTable;
-    private String[] tagTable;
-    private byte[] stringTable;
-    private Hashtable cacheStringTable = null;
-    private boolean processNsp;
-    
-    private int depth;
-    private String[] elementStack = new String[16];
-    private String[] nspStack = new String[8];
-    private int[] nspCounts = new int[4];
-    
-    private int attributeCount;
-    private String[] attributes = new String[16];
-    private int nextId = -2;
-    
-    private Vector tables = new Vector();
-    
-    private int version;
-    private int publicIdentifierId;
-    
-    //    StartTag current;
-    //    ParseEvent next;
-    
-    private String prefix;
-    private String namespace;
-    private String name;
-    private String text;
-
-    private Object wapExtensionData;
-    private int wapCode;
-    
-    private int type;
-    
-    private boolean degenerated;
-    private boolean isWhitespace;
-    private String encoding;
-    
-    public boolean getFeature(String feature) {
-        if (XmlPullParser
-        .FEATURE_PROCESS_NAMESPACES
-        .equals(feature))
-            return processNsp;
-        else
-            return false;
-    }
-    
-    public String getInputEncoding() {
-        return encoding;
-    }
-    
-    public void defineEntityReplacementText(
-    String entity,
-    String value)
-    throws XmlPullParserException {
-        
-        // just ignore, has no effect
-    }
-    
-    public Object getProperty(String property) {
-        return null;
-    }
-    
-    public int getNamespaceCount(int depth) {
-        if (depth > this.depth)
-            throw new IndexOutOfBoundsException();
-        return nspCounts[depth];
-    }
-    
-    public String getNamespacePrefix(int pos) {
-        return nspStack[pos << 1];
-    }
-    
-    public String getNamespaceUri(int pos) {
-        return nspStack[(pos << 1) + 1];
-    }
-    
-    public String getNamespace(String prefix) {
-        
-        if ("xml".equals(prefix))
-            return "http://www.w3.org/XML/1998/namespace";
-        if ("xmlns".equals(prefix))
-            return "http://www.w3.org/2000/xmlns/";
-        
-        for (int i = (getNamespaceCount(depth) << 1) - 2;
-        i >= 0;
-        i -= 2) {
-            if (prefix == null) {
-                if (nspStack[i] == null)
-                    return nspStack[i + 1];
-            }
-            else if (prefix.equals(nspStack[i]))
-                return nspStack[i + 1];
-        }
-        return null;
-    }
-    
-    public int getDepth() {
-        return depth;
-    }
-    
-    public String getPositionDescription() {
-        
-        StringBuffer buf =
-        new StringBuffer(
-        type < TYPES.length ? TYPES[type] : "unknown");
-        buf.append(' ');
-        
-        if (type == START_TAG || type == END_TAG) {
-            if (degenerated)
-                buf.append("(empty) ");
-            buf.append('<');
-            if (type == END_TAG)
-                buf.append('/');
-            
-            if (prefix != null)
-                buf.append("{" + namespace + "}" + prefix + ":");
-            buf.append(name);
-            
-            int cnt = attributeCount << 2;
-            for (int i = 0; i < cnt; i += 4) {
-                buf.append(' ');
-                if (attributes[i + 1] != null)
-                    buf.append(
-                    "{"
-                    + attributes[i]
-                    + "}"
-                    + attributes[i
-                    + 1]
-                    + ":");
-                buf.append(
-                attributes[i
-                + 2]
-                + "='"
-                + attributes[i
-                + 3]
-                + "'");
-            }
-            
-            buf.append('>');
-        }
-        else if (type == IGNORABLE_WHITESPACE);
-        else if (type != TEXT)
-            buf.append(getText());
-        else if (isWhitespace)
-            buf.append("(whitespace)");
-        else {
-            String text = getText();
-            if (text.length() > 16)
-                text = text.substring(0, 16) + "...";
-            buf.append(text);
-        }
-        
-        return buf.toString();
-    }
-    
-    public int getLineNumber() {
-        return -1;
-    }
-    
-    public int getColumnNumber() {
-        return -1;
-    }
-    
-    public boolean isWhitespace()
-    throws XmlPullParserException {
-        if (type != TEXT
-        && type != IGNORABLE_WHITESPACE
-        && type != CDSECT)
-            exception(ILLEGAL_TYPE);
-        return isWhitespace;
-    }
-    
-    public String getText() {
-        return text;
-    }
-    
-    public char[] getTextCharacters(int[] poslen) {
-        if (type >= TEXT) {
-            poslen[0] = 0;
-            poslen[1] = text.length();
-            char[] buf = new char[text.length()];
-            text.getChars(0, text.length(), buf, 0);
-            return buf;
-        }
-        
-        poslen[0] = -1;
-        poslen[1] = -1;
-        return null;
-    }
-    
-    public String getNamespace() {
-        return namespace;
-    }
-    
-    public String getName() {
-        return name;
-    }
-    
-    public String getPrefix() {
-        return prefix;
-    }
-    
-    public boolean isEmptyElementTag()
-    throws XmlPullParserException {
-        if (type != START_TAG)
-            exception(ILLEGAL_TYPE);
-        return degenerated;
-    }
-    
-    public int getAttributeCount() {
-        return attributeCount;
-    }
-    
-    public String getAttributeType(int index) {
-        return "CDATA";
-    }
-    
-    public boolean isAttributeDefault(int index) {
-        return false;
-    }
-    
-    public String getAttributeNamespace(int index) {
-        if (index >= attributeCount)
-            throw new IndexOutOfBoundsException();
-        return attributes[index << 2];
-    }
-    
-    public String getAttributeName(int index) {
-        if (index >= attributeCount)
-            throw new IndexOutOfBoundsException();
-        return attributes[(index << 2) + 2];
-    }
-    
-    public String getAttributePrefix(int index) {
-        if (index >= attributeCount)
-            throw new IndexOutOfBoundsException();
-        return attributes[(index << 2) + 1];
-    }
-    
-    public String getAttributeValue(int index) {
-        if (index >= attributeCount)
-            throw new IndexOutOfBoundsException();
-        return attributes[(index << 2) + 3];
-    }
-    
-    public String getAttributeValue(
-    String namespace,
-    String name) {
-        
-        for (int i = (attributeCount << 2) - 4;
-        i >= 0;
-        i -= 4) {
-            if (attributes[i + 2].equals(name)
-            && (namespace == null
-            || attributes[i].equals(namespace)))
-                return attributes[i + 3];
-        }
-        
-        return null;
-    }
-    
-    public int getEventType() throws XmlPullParserException {
-        return type;
-    }
-    
-    
-    // TODO: Reuse resolveWapExtension here? Raw Wap extensions would still be accessible
-    // via nextToken();  ....?
-    
-    public int next() throws XmlPullParserException, IOException {
-        
-        isWhitespace = true;
-        int minType = 9999;
-        
-        while (true) {
-            
-            String save = text;
-            
-            nextImpl();
-            
-            if (type < minType)
-                minType = type;
-            
-            if (minType > CDSECT) continue; // no "real" event so far
-            
-            if (minType >= TEXT) {  // text, see if accumulate
-                
-                if (save != null) text = text == null ? save : save + text;
-                
-                switch(peekId()) {
-                    case Wbxml.ENTITY:
-                    case Wbxml.STR_I:
-                    case Wbxml.STR_T:
-                    case Wbxml.LITERAL:
-                    case Wbxml.LITERAL_C:
-                    case Wbxml.LITERAL_A:
-                    case Wbxml.LITERAL_AC: continue;
-                }
-            }
-            
-            break;
-        }
-        
-        type = minType;
-        
-        if (type > TEXT)
-            type = TEXT;
-        
-        return type;
-    }
-    
-    
-    public int nextToken() throws XmlPullParserException, IOException {
-        
-        isWhitespace = true;
-        nextImpl();
-        return type;
-    }
-    
-    
-    
-    public int nextTag() throws XmlPullParserException, IOException {
-        
-        next();
-        if (type == TEXT && isWhitespace)
-            next();
-        
-        if (type != END_TAG && type != START_TAG)
-            exception("unexpected type");
-        
-        return type;
-    }
-    
-    
-    public String nextText() throws XmlPullParserException, IOException {
-        if (type != START_TAG)
-            exception("precondition: START_TAG");
-        
-        next();
-        
-        String result;
-        
-        if (type == TEXT) {
-            result = getText();
-            next();
-        }
-        else
-            result = "";
-        
-        if (type != END_TAG)
-            exception("END_TAG expected");
-        
-        return result;
-    }
-    
-    
-    public void require(int type, String namespace, String name)
-    throws XmlPullParserException, IOException {
-        
-        if (type != this.type
-        || (namespace != null && !namespace.equals(getNamespace()))
-        || (name != null && !name.equals(getName())))
-            exception(
-            "expected: " + (type == WAP_EXTENSION ? "WAP Ext." : (TYPES[type] + " {" + namespace + "}" + name)));
-    }
-    
-    
-    public void setInput(Reader reader) throws XmlPullParserException {
-        exception("InputStream required");
-    }
-    
-    public void setInput(InputStream in, String enc)
-    throws XmlPullParserException {
-        
-        this.in = in;
-        
-        try {
-            version = readByte();
-            publicIdentifierId = readInt();
-            
-            if (publicIdentifierId == 0)
-                readInt();
-            
-            int charset = readInt(); // skip charset
-            
-            if (null == enc){
-                switch (charset){
-                    case   4: encoding = "ISO-8859-1"; break;
-                    case 106: encoding = "UTF-8";      break;
-                    // add more if you need them
-                    // http://www.iana.org/assignments/character-sets
-                    // case MIBenum: encoding = Name  break;
-                    default:  throw new UnsupportedEncodingException(""+charset);
-                } 
-            }else{
-                encoding = enc;
-            }
-
-            int strTabSize = readInt();
-            stringTable = new byte[strTabSize];
-            
-            int ok = 0;
-            while(ok < strTabSize){
-                int cnt = in.read(stringTable, ok, strTabSize - ok);
-                if(cnt <= 0) break;
-                ok += cnt;
-            }
-            
-            selectPage(0, true);
-            selectPage(0, false);
-        }
-        catch (IOException e) {
-            exception("Illegal input format");
-        }
-    }
-    
-    public void setFeature(String feature, boolean value)
-    throws XmlPullParserException {
-        if (XmlPullParser.FEATURE_PROCESS_NAMESPACES.equals(feature))
-            processNsp = value;
-        else
-            exception("unsupported feature: " + feature);
-    }
-    
-    public void setProperty(String property, Object value)
-    throws XmlPullParserException {
-        throw new XmlPullParserException("unsupported property: " + property);
-    }
-    
-    // ---------------------- private / internal methods
-    
-    private final boolean adjustNsp()
-    throws XmlPullParserException {
-        
-        boolean any = false;
-        
-        for (int i = 0; i < attributeCount << 2; i += 4) {
-            // * 4 - 4; i >= 0; i -= 4) {
-            
-            String attrName = attributes[i + 2];
-            int cut = attrName.indexOf(':');
-            String prefix;
-            
-            if (cut != -1) {
-                prefix = attrName.substring(0, cut);
-                attrName = attrName.substring(cut + 1);
-            }
-            else if (attrName.equals("xmlns")) {
-                prefix = attrName;
-                attrName = null;
-            }
-            else
-                continue;
-            
-            if (!prefix.equals("xmlns")) {
-                any = true;
-            }
-            else {
-                int j = (nspCounts[depth]++) << 1;
-                
-                nspStack = ensureCapacity(nspStack, j + 2);
-                nspStack[j] = attrName;
-                nspStack[j + 1] = attributes[i + 3];
-                
-                if (attrName != null
-                && attributes[i + 3].equals(""))
-                    exception("illegal empty namespace");
-                
-                //  prefixMap = new PrefixMap (prefixMap, attrName, attr.getValue ());
-                
-                //System.out.println (prefixMap);
-                
-                System.arraycopy(
-                attributes,
-                i + 4,
-                attributes,
-                i,
-                ((--attributeCount) << 2) - i);
-                
-                i -= 4;
-            }
-        }
-        
-        if (any) {
-            for (int i = (attributeCount << 2) - 4;
-            i >= 0;
-            i -= 4) {
-                
-                String attrName = attributes[i + 2];
-                int cut = attrName.indexOf(':');
-                
-                if (cut == 0)
-                    throw new RuntimeException(
-                    "illegal attribute name: "
-                    + attrName
-                    + " at "
-                    + this);
-                
-                else if (cut != -1) {
-                    String attrPrefix =
-                    attrName.substring(0, cut);
-                    
-                    attrName = attrName.substring(cut + 1);
-                    
-                    String attrNs = getNamespace(attrPrefix);
-                    
-                    if (attrNs == null)
-                        throw new RuntimeException(
-                        "Undefined Prefix: "
-                        + attrPrefix
-                        + " in "
-                        + this);
-                    
-                    attributes[i] = attrNs;
-                    attributes[i + 1] = attrPrefix;
-                    attributes[i + 2] = attrName;
-                    
-                    for (int j = (attributeCount << 2) - 4;
-                    j > i;
-                    j -= 4)
-                        if (attrName.equals(attributes[j + 2])
-                        && attrNs.equals(attributes[j]))
-                            exception(
-                            "Duplicate Attribute: {"
-                            + attrNs
-                            + "}"
-                            + attrName);
-                }
-            }
-        }
-        
-        int cut = name.indexOf(':');
-        
-        if (cut == 0)
-            exception("illegal tag name: " + name);
-        else if (cut != -1) {
-            prefix = name.substring(0, cut);
-            name = name.substring(cut + 1);
-        }
-        
-        this.namespace = getNamespace(prefix);
-        
-        if (this.namespace == null) {
-            if (prefix != null)
-                exception("undefined prefix: " + prefix);
-            this.namespace = NO_NAMESPACE;
-        }
-        
-        return any;
-    }
-    
-    private final void setTable(int page, int type, String[] table) {
-        if(stringTable != null){
-            throw new RuntimeException("setXxxTable must be called before setInput!");
-        }
-        while(tables.size() < 3*page +3){
-            tables.addElement(null);
-        }
-        tables.setElementAt(table, page*3+type);
-    }
-    
-    
-    
-    
-    
-    private final void exception(String desc)
-    throws XmlPullParserException {
-        throw new XmlPullParserException(desc, this, null);
-    }
-    
-    
-    private void selectPage(int nr, boolean tags) throws XmlPullParserException{
-        if(tables.size() == 0 && nr == 0) return;
-        
-        if(nr*3 > tables.size())
-            exception("Code Page "+nr+" undefined!");
-        
-        if(tags)
-            tagTable = (String[]) tables.elementAt(nr * 3 + TAG_TABLE);
-        else {
-            attrStartTable = (String[]) tables.elementAt(nr * 3 + ATTR_START_TABLE);
-            attrValueTable = (String[]) tables.elementAt(nr * 3 + ATTR_VALUE_TABLE);
-        }
-    }
-    
-    private final void nextImpl()
-    throws IOException, XmlPullParserException {
-        
-        String s;
-        
-        if (type == END_TAG) {
-            depth--;
-        }
-        
-        if (degenerated) {
-            type = XmlPullParser.END_TAG;
-            degenerated = false;
-            return;
-        }
-        
-        text = null;
-        prefix = null;
-        name = null;
-        
-        int id = peekId ();
-        while(id == Wbxml.SWITCH_PAGE){
-            nextId = -2;
-            selectPage(readByte(), true);
-            id = peekId();
-        }
-        nextId = -2;
-        
-        switch (id) {
-            case -1 :
-                type = XmlPullParser.END_DOCUMENT;
-                break;
-                
-            case Wbxml.END : 
-            {
-                int sp = (depth - 1) << 2;
-                
-                type = END_TAG;
-                namespace = elementStack[sp];
-                prefix = elementStack[sp + 1];
-                name = elementStack[sp + 2];
-            }
-            break;
-            
-            case Wbxml.ENTITY : 
-            {
-                type = ENTITY_REF;
-                char c = (char) readInt();
-                text = "" + c;
-                name = "#" + ((int) c);
-            }
-            
-            break;
-            
-            case Wbxml.STR_I :
-                type = TEXT;
-                text = readStrI();
-                break;
-                
-            case Wbxml.EXT_I_0 :
-            case Wbxml.EXT_I_1 :
-            case Wbxml.EXT_I_2 :
-            case Wbxml.EXT_T_0 :
-            case Wbxml.EXT_T_1 :
-            case Wbxml.EXT_T_2 :
-            case Wbxml.EXT_0 :
-            case Wbxml.EXT_1 :
-            case Wbxml.EXT_2 :
-            case Wbxml.OPAQUE :
-                
-                type = WAP_EXTENSION;
-                wapCode = id;
-                wapExtensionData = parseWapExtension(id);
-                break;
-                
-            case Wbxml.PI :
-                throw new RuntimeException("PI curr. not supp.");
-                // readPI;
-                // break;
-                
-            case Wbxml.STR_T : 
-            {
-                type = TEXT;
-                text = readStrT();
-            }
-            break;
-            
-            default :
-                parseElement(id);
-        }
-        //        }
-        //      while (next == null);
-        
-        //        return next;
-    }
-    
-    /** Overwrite this method to intercept all wap events */
-    
-    public Object parseWapExtension(int id)  throws IOException, XmlPullParserException {
-        
-        switch (id) {
-            case Wbxml.EXT_I_0 :
-            case Wbxml.EXT_I_1 :
-            case Wbxml.EXT_I_2 :
-                return readStrI();
-                
-            case Wbxml.EXT_T_0 :
-            case Wbxml.EXT_T_1 :
-            case Wbxml.EXT_T_2 :
-                return new Integer(readInt());
-                
-            case Wbxml.EXT_0 :
-            case Wbxml.EXT_1 :
-            case Wbxml.EXT_2 :
-                return null;
-                
-            case Wbxml.OPAQUE : 
-            {
-                int count = readInt();
-                byte[] buf = new byte[count];
-                
-                while(count > 0){
-                    count -= in.read(buf, buf.length-count, count);
-                }
-                
-                return buf;
-            } // case OPAQUE
-    
-            
-            default:
-                exception("illegal id: "+id);
-                return null; // dead code
-        } // SWITCH
-    }
-    
-    public void readAttr() throws IOException, XmlPullParserException {
-        
-        int id = readByte();
-        int i = 0;
-        
-        while (id != 1) {
-            
-            while(id == Wbxml.SWITCH_PAGE){
-                selectPage(readByte(), false);
-                id = readByte();
-            }
-            
-            String name = resolveId(attrStartTable, id);
-            StringBuffer value;
-            
-            int cut = name.indexOf('=');
-            
-            if (cut == -1)
-                value = new StringBuffer();
-            else {
-                value =
-                new StringBuffer(name.substring(cut + 1));
-                name = name.substring(0, cut);
-            }
-            
-            id = readByte();
-            while (id > 128
-            || id == Wbxml.SWITCH_PAGE
-            || id == Wbxml.ENTITY
-            || id == Wbxml.STR_I
-            || id == Wbxml.STR_T
-            || (id >= Wbxml.EXT_I_0 && id <= Wbxml.EXT_I_2)
-            || (id >= Wbxml.EXT_T_0 && id <= Wbxml.EXT_T_2)) {
-                
-                switch (id) {
-                    case Wbxml.SWITCH_PAGE :
-                        selectPage(readByte(), false);
-                        break;
-                        
-                    case Wbxml.ENTITY :
-                        value.append((char) readInt());
-                        break;
-                        
-                    case Wbxml.STR_I :
-                        value.append(readStrI());
-                        break;
-                        
-                    case Wbxml.EXT_I_0 :
-                    case Wbxml.EXT_I_1 :
-                    case Wbxml.EXT_I_2 :
-                    case Wbxml.EXT_T_0 :
-                    case Wbxml.EXT_T_1 :
-                    case Wbxml.EXT_T_2 :
-                    case Wbxml.EXT_0 :
-                    case Wbxml.EXT_1 :
-                    case Wbxml.EXT_2 :
-                    case Wbxml.OPAQUE :
-                        value.append(resolveWapExtension(id, parseWapExtension(id)));
-                        break;
-                        
-                    case Wbxml.STR_T :
-                        value.append(readStrT());
-                        break;
-                        
-                    default :
-                        value.append(
-                        resolveId(attrValueTable, id));
-                }
-                
-                id = readByte();
-            }
-            
-            attributes = ensureCapacity(attributes, i + 4);
-            
-            attributes[i++] = "";
-            attributes[i++] = null;
-            attributes[i++] = name;
-            attributes[i++] = value.toString();
-            
-            attributeCount++;
-        }
-    }
-    
-    private int peekId () throws IOException {
-        if (nextId == -2) {
-            nextId = in.read ();
-        }
-        return nextId;
-    }
-    
-    /** overwrite for own WAP extension handling in attributes and high level parsing 
-     * (above nextToken() level) */
-    
-    protected String resolveWapExtension(int id, Object data){
-        
-        if(data instanceof byte[]){
-            StringBuffer sb = new StringBuffer();
-            byte[] b = (byte[]) data;
-            
-            for (int i = 0; i < b.length; i++) {
-                sb.append(HEX_DIGITS.charAt((b[i] >> 4) & 0x0f));
-                sb.append(HEX_DIGITS.charAt(b[i] & 0x0f));
-            }
-            return sb.toString();
-        }
-
-        return "$("+data+")";
-    }
-    
-    String resolveId(String[] tab, int id) throws IOException {
-        int idx = (id & 0x07f) - 5;
-        if (idx == -1){
-            wapCode = -1;
-            return readStrT();
-        }
-        if (idx < 0
-        || tab == null
-        || idx >= tab.length
-        || tab[idx] == null)
-            throw new IOException("id " + id + " undef.");
-        
-        wapCode = idx+5;
-        
-        return tab[idx];
-    }
-    
-    void parseElement(int id)
-    throws IOException, XmlPullParserException {
-        
-        type = START_TAG;
-        name = resolveId(tagTable, id & 0x03f);
-        
-        attributeCount = 0;
-        if ((id & 128) != 0) {
-            readAttr();
-        }
-        
-        degenerated = (id & 64) == 0;
-        
-        int sp = depth++ << 2;
-        
-        // transfer to element stack
-        
-        elementStack = ensureCapacity(elementStack, sp + 4);
-        elementStack[sp + 3] = name;
-        
-        if (depth >= nspCounts.length) {
-            int[] bigger = new int[depth + 4];
-            System.arraycopy(nspCounts, 0, bigger, 0, nspCounts.length);
-            nspCounts = bigger;
-        }
-        
-        nspCounts[depth] = nspCounts[depth - 1];
-        
-        for (int i = attributeCount - 1; i > 0; i--) {
-            for (int j = 0; j < i; j++) {
-                if (getAttributeName(i)
-                .equals(getAttributeName(j)))
-                    exception(
-                    "Duplicate Attribute: "
-                    + getAttributeName(i));
-            }
-        }
-        
-        if (processNsp)
-            adjustNsp();
-        else
-            namespace = "";
-        
-        elementStack[sp] = namespace;
-        elementStack[sp + 1] = prefix;
-        elementStack[sp + 2] = name;
-        
-    }
-    
-    private final String[] ensureCapacity(
-    String[] arr,
-    int required) {
-        if (arr.length >= required)
-            return arr;
-        String[] bigger = new String[required + 16];
-        System.arraycopy(arr, 0, bigger, 0, arr.length);
-        return bigger;
-    }
-    
-    int readByte() throws IOException {
-        int i = in.read();
-        if (i == -1)
-            throw new IOException("Unexpected EOF");
-        return i;
-    }
-    
-    int readInt() throws IOException {
-        int result = 0;
-        int i;
-        
-        do {
-            i = readByte();
-            result = (result << 7) | (i & 0x7f);
-        }
-        while ((i & 0x80) != 0);
-        
-        return result;
-    }
-    
-    String readStrI() throws IOException {
-        ByteArrayOutputStream buf = new ByteArrayOutputStream();
-        boolean wsp = true;
-        while (true){
-            int i = in.read();
-            if (i == 0){
-                break;
-            }
-            if (i == -1){
-                throw new IOException(UNEXPECTED_EOF);
-            }
-            if (i > 32){
-                wsp = false;
-            }
-            buf.write(i);
-        }
-        isWhitespace = wsp;
-        String result = new String(buf.toByteArray(), encoding);
-        buf.close();
-        return result;
-    }
-    
-    String readStrT() throws IOException {
-        int pos = readInt();
-        // As the main reason of stringTable is compression we build a cache of Strings
-        // stringTable is supposed to help create Strings from parts which means some cache hit rate
-        // This will help to minimize the Strings created when invoking readStrT() repeatedly
-        if (cacheStringTable == null){
-            //Lazy init if device is not using StringTable but inline 0x03 strings
-            cacheStringTable = new Hashtable();
-        }
-        String forReturn = (String) cacheStringTable.get(new Integer(pos));
-        if (forReturn == null){
-
-            int end = pos;
-            while(end < stringTable.length && stringTable[end] != '\0'){
-                end++;
-            }
-            forReturn = new String(stringTable, pos, end-pos, encoding);
-            cacheStringTable.put(new Integer(pos), forReturn);
-        }
-        return forReturn;
-    }
-    
-    /**
-     * Sets the tag table for a given page.
-     * The first string in the array defines tag 5, the second tag 6 etc.
-     */
-    
-    public void setTagTable(int page, String[] table) {
-        setTable(page, TAG_TABLE, table);
-        
-        //        this.tagTable = tagTable;
-        //      if (page != 0)
-        //        throw new RuntimeException("code pages curr. not supp.");
-    }
-    
-    /** Sets the attribute start Table for a given page.
-     *  The first string in the array defines attribute
-     *  5, the second attribute 6 etc. Please use the
-     *  character '=' (without quote!) as delimiter
-     *  between the attribute name and the (start of the) value
-     */
-    
-    public void setAttrStartTable(
-    int page,
-    String[] table) {
-        
-        setTable(page, ATTR_START_TABLE, table);
-    }
-    
-    /** Sets the attribute value Table for a given page.
-     *  The first string in the array defines attribute value 0x85,
-     *  the second attribute value 0x86 etc.
-     */
-    
-    public void setAttrValueTable(
-    int page,
-    String[] table) {
-        
-        setTable(page, ATTR_VALUE_TABLE, table);
-    }
-    
-    /** Returns the token ID for start tags or the event type for wap proprietary events
-     * such as OPAQUE.
-     */
-    
-    public int getWapCode(){
-        return wapCode;
-    }
-    
-    public Object getWapExtensionData(){
-        return wapExtensionData;
-    }
-    
-    
-}
diff --git a/libcore/xml/src/main/java/org/kxml2/wap/WbxmlSerializer.java b/libcore/xml/src/main/java/org/kxml2/wap/WbxmlSerializer.java
deleted file mode 100644
index a977386..0000000
--- a/libcore/xml/src/main/java/org/kxml2/wap/WbxmlSerializer.java
+++ /dev/null
@@ -1,559 +0,0 @@
-/* Copyright (c) 2002,2003, Stefan Haustein, Oberhausen, Rhld., Germany
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The  above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE. */
-
-//Contributors: Jonathan Cox, Bogdan Onoiu, Jerry Tian
-
-package org.kxml2.wap;
-
-import java.io.*;
-import java.util.*;
-
-import org.xmlpull.v1.*;
-
-// TODO: make some of the "direct" WBXML token writing methods public??
-
-/**
- * A class for writing WBXML. Does not support namespaces yet.
- */
-public class WbxmlSerializer implements XmlSerializer {
-    
-	
-    Hashtable stringTable = new Hashtable();
-    
-    OutputStream out;
-    
-    ByteArrayOutputStream buf = new ByteArrayOutputStream();
-    ByteArrayOutputStream stringTableBuf = new ByteArrayOutputStream();
-    
-    String pending;
-    int depth;
-    String name;
-    String namespace;
-    Vector attributes = new Vector();
-    
-    Hashtable attrStartTable = new Hashtable();
-    Hashtable attrValueTable = new Hashtable();
-    Hashtable tagTable = new Hashtable();
-    
-    private int attrPage;
-    private int tagPage;
-    
-    private String encoding;
-    
-    private boolean headerSent = false;
-    
-    /**
-     * Write an attribute. 
-     * Calls to attribute() MUST follow a call to startTag() immediately. 
-     * If there is no prefix defined for the given namespace, 
-     * a prefix will be defined automatically.
-     */
-    public XmlSerializer attribute(String namespace, String name, String value) {
-        attributes.addElement(name);
-        attributes.addElement(value);
-        return this;
-    }
-    
-    
-    public void cdsect (String cdsect) throws IOException{
-        text (cdsect);
-    }
-    
-    /**
-     * Add comment. Ignore for WBXML.
-     */
-    public void comment (String comment) {
-        // silently ignore comment
-    }
-    
-    /**
-     * Docdecl isn't supported for WBXML.
-     */
-    public void docdecl (String docdecl) {
-        throw new RuntimeException ("Cannot write docdecl for WBXML");
-    }
-    
-    /**
-     * EntityReference not supported for WBXML.
-     */
-    public void entityRef (String er) {
-        throw new RuntimeException ("EntityReference not supported for WBXML");
-    }
-    
-    /**
-     * Return current tag depth.
-     */
-    public int getDepth() {
-        return depth;
-    }
-    
-    /**
-     * Return the current value of the feature with given name.
-     */ 
-    public boolean getFeature (String name) {
-        return false;
-    }
-    
-    /**
-     * Returns the namespace URI of the current element as set by startTag().
-     * Namespaces is not yet implemented.
-     */
-    public String getNamespace() {
-        // Namespaces is not yet implemented. So only null can be setted
-        return null;
-    }
-    
-    /**
-     * Returns the name of the current element as set by startTag(). 
-     * It can only be null before first call to startTag() or when last endTag() 
-     * is called to close first startTag().
-     */
-    public String getName() {
-        return pending;
-    }
-    
-    /**
-     * Prefix for namespace not supported for WBXML. Not yet implemented.
-     */
-    public String getPrefix(String nsp, boolean create) {
-        throw new RuntimeException ("NYI");
-    }
-    
-    /**
-     * Look up the value of a property. 
-     * @param name The name of property. Name is any fully-qualified URI.
-     * @return The value of named property.
-     */
-    public Object getProperty (String name) {
-        return null;
-    }
-    
-    public void ignorableWhitespace (String sp) {
-    }
-    
-    /**
-     * Finish writing. 
-     * All unclosed start tags will be closed and output will be flushed. 
-     * After calling this method no more output can be serialized until 
-     * next call to setOutput().
-     */
-    public void endDocument() throws IOException {
-        flush();
-    }
-        
-    /**
-     * Write all pending output to the stream. 
-     * After first call string table willn't be used and you can't add tag
-     * which is not in tag table.
-     */
-    public void flush() throws IOException {
-        checkPending(false);
-        
-        if (!headerSent) {
-            writeInt(out, stringTableBuf.size());
-            out.write(stringTableBuf.toByteArray());
-            headerSent = true;
-        }
-        
-        out.write(buf.toByteArray());
-        buf.reset();
-    }
-    
-    public void checkPending(boolean degenerated) throws IOException {
-        if (pending == null)
-            return;
-        
-        int len = attributes.size();
-        
-        int[] idx = (int[]) tagTable.get(pending);
-        
-        // if no entry in known table, then add as literal
-        if (idx == null) {
-            buf.write(len == 0
-                ? (degenerated ? Wbxml.LITERAL : Wbxml.LITERAL_C)
-                    : (degenerated ? Wbxml.LITERAL_A : Wbxml.LITERAL_AC));
-            
-            writeStrT(pending, false);
-        } else {
-            if(idx[0] != tagPage){
-                tagPage=idx[0];
-				buf.write(Wbxml.SWITCH_PAGE);
-                buf.write(tagPage);
-            }
-            buf.write(len == 0
-                ? (degenerated ? idx[1] : idx[1] | 64)
-                    : (degenerated ? idx[1] | 128 : idx[1] | 192));
-        }
-        
-        for (int i = 0; i < len;) {
-            idx = (int[]) attrStartTable.get(attributes.elementAt(i));
-            
-            if (idx == null) {
-                buf.write(Wbxml.LITERAL);
-                writeStrT((String) attributes.elementAt(i), false);
-            }
-            else {
-                if(idx[0] != attrPage){
-                  attrPage = idx[0];
-                    buf.write(0);
-                    buf.write(attrPage);
-                }
-                buf.write(idx[1]);
-            }
-            idx = (int[]) attrValueTable.get(attributes.elementAt(++i));
-            if (idx == null) {
-                writeStr((String) attributes.elementAt(i));
-            }
-            else {
-                if(idx[0] != attrPage){
-                    attrPage = idx[0];
-                    buf.write(0);
-                    buf.write(attrPage);					
-                }
-                buf.write(idx[1]);
-            }
-            ++i;
-        }
-        
-        if (len > 0)
-            buf.write(Wbxml.END);
-        
-        pending = null;
-        attributes.removeAllElements();
-    }
-    
-    /**
-     * Not Yet Implemented.
-     */
-    public void processingInstruction(String pi) {
-        throw new RuntimeException ("PI NYI");
-    }
-    
-    /**
-     * Set feature identified by name. There are no supported functions.
-     */
-    public void setFeature(String name, boolean value) {
-        throw new IllegalArgumentException ("unknown feature "+name);
-    }
-    
-    /**
-     * Set the output to the given writer. Wbxml requires an OutputStream.
-     */
-    public void setOutput (Writer writer) {
-        throw new RuntimeException ("Wbxml requires an OutputStream!");
-    }
-    
-    /**
-     * Set to use binary output stream with given encoding.
-     */
-    public void setOutput (OutputStream out, String encoding) throws IOException {
-        
-    	this.encoding = encoding == null ? "UTF-8" : encoding;
-        this.out = out;
-        
-        buf = new ByteArrayOutputStream();
-        stringTableBuf = new ByteArrayOutputStream();
-        headerSent = false;
-        
-        // ok, write header
-    }
-    
-    /**
-     * Binds the given prefix to the given namespace. Not yet implemented.
-     */
-    public void setPrefix(String prefix, String nsp) {
-        throw new RuntimeException("NYI");
-    }
-    
-    /**
-     * Set the value of a property. There are no supported properties.
-     */
-    public void setProperty(String property, Object value) {
-        throw new IllegalArgumentException ("unknown property "+property);
-    }
-    
-    /**
-     * Write version and encoding information.
-     * This method can only be called just after setOutput.
-     * @param encoding Document encoding. Default is UTF-8.
-     * @param standalone Not used in WBXML.
-     */
-    public void startDocument(String encoding, Boolean standalone) throws IOException {
-        out.write(0x03); // version 1.3
-        // http://www.openmobilealliance.org/tech/omna/omna-wbxml-public-docid.htm
-        out.write(0x01); // unknown or missing public identifier
-
-        // default encoding is UTF-8
-        
-        if(encoding != null){
-            this.encoding = encoding;
-        }
-        
-        if (this.encoding.toUpperCase().equals("UTF-8")){
-            out.write(106);
-        }else if (this.encoding.toUpperCase().equals("ISO-8859-1")){
-            out.write(0x04);
-        }else{
-            throw new UnsupportedEncodingException(encoding);
-        }
-    }
-    
-    
-    public XmlSerializer startTag(String namespace, String name) throws IOException {
-        
-        if (namespace != null && !"".equals(namespace))
-            throw new RuntimeException ("NSP NYI");
-        
-        //current = new State(current, prefixMap, name);
-        
-        checkPending(false);
-        pending = name;
-        depth++;
-        
-        return this;
-    }
-    
-    public XmlSerializer text(char[] chars, int start, int len) throws IOException {
-    	checkPending(false);
-        writeStr(new String(chars, start, len));
-        return this;
-    }
-    
-    public XmlSerializer text(String text) throws IOException {
-        checkPending(false);
-        writeStr(text);
-        return this;
-    }
-    
-    /** 
-     * Used in text() and attribute() to write text.
-     */ 
-    private void writeStr(String text) throws IOException{
-        int p0 = 0;
-    	int lastCut = 0;
-    	int len = text.length();
-    	
-        if (headerSent) {
-          writeStrI(buf, text);
-          return;
-        }
-         
-    	while(p0 < len){
-    	    while(p0 < len && text.charAt(p0) < 'A' ){ // skip interpunctation
-    	        p0++;
-    	    }
-    	    int p1 = p0;
-    	    while (p1 < len && text.charAt(p1) >= 'A'){
-    	        p1++;
-    	    }
-    		
-    	    if (p1 - p0 > 10) {
-    	        if (p0 > lastCut && text.charAt(p0-1) == ' ' 
-    	            && stringTable.get(text.substring(p0, p1)) == null){
-    	            buf.write(Wbxml.STR_T);
-    	            writeStrT(text.substring(lastCut, p1), false);
-    	        }
-    	        else {
-    	            if(p0 > lastCut && text.charAt(p0-1) == ' '){
-    	                p0--;
-    	            }
-
-    	            if(p0 > lastCut){
-    	                buf.write(Wbxml.STR_T);
-    	                writeStrT(text.substring(lastCut, p0), false);
-    	            }
-    	            buf.write(Wbxml.STR_T);
-    	            writeStrT(text.substring(p0, p1), true);
-    	        }
-    	        lastCut = p1;
-    	    }
-    	    p0 = p1;
-    	}
-
-    	if(lastCut < len){
-    	  buf.write(Wbxml.STR_T);
-    	  writeStrT(text.substring(lastCut, len), false);
-    	}
-    }
-    
-    
-
-    public XmlSerializer endTag(String namespace, String name) throws IOException {
-        //        current = current.prev;
-        if (pending != null) {
-            checkPending(true);
-        } else {
-            buf.write(Wbxml.END);
-        }
-        depth--;
-        return this;
-    }
-    
-    /** 
-     * @throws IOException 
-     */
-    public void writeWapExtension(int type, Object data) throws IOException {
-        checkPending(false);
-    	buf.write(type);
-    	switch(type){
-    	case Wbxml.EXT_0:
-    	case Wbxml.EXT_1:
-    	case Wbxml.EXT_2:
-    	    break;
-    	
-    	case Wbxml.OPAQUE:
-    	    byte[] bytes = (byte[]) data;
-    	    writeInt(buf, bytes.length);
-    	    buf.write(bytes);
-    	    break;
-    		
-    	case Wbxml.EXT_I_0:
-    	case Wbxml.EXT_I_1:
-    	case Wbxml.EXT_I_2:
-    	  writeStrI(buf, (String) data);
-    	  break;
-
-    	case Wbxml.EXT_T_0:
-    	case Wbxml.EXT_T_1:
-    	case Wbxml.EXT_T_2:
-    	  writeStrT((String) data, false);
-    	  break;
-    		
-    	default: 
-    	  throw new IllegalArgumentException();
-    	}
-    }
-    
-    // ------------- internal methods --------------------------
-    
-    static void writeInt(OutputStream out, int i) throws IOException {
-        byte[] buf = new byte[5];
-        int idx = 0;
-        
-        do {
-            buf[idx++] = (byte) (i & 0x7f);
-            i = i >> 7;
-        }
-        while (i != 0);
-        
-        while (idx > 1) {
-            out.write(buf[--idx] | 0x80);
-        }
-        out.write(buf[0]);
-    }
-    
-    void writeStrI(OutputStream out, String s) throws IOException {
-    	byte[] data = s.getBytes(encoding);
-    	out.write(data);
-        out.write(0);
-    }
-    
-    private final void writeStrT(String s, boolean mayPrependSpace) throws IOException {
-        
-        Integer idx = (Integer) stringTable.get(s);        
-        writeInt(buf, idx == null 
-            ? addToStringTable(s, mayPrependSpace)
-                : idx.intValue());
-    }
-    
-    
-    /**
-     * Add string to string table. Not permitted after string table has been flushed. 
-     * 
-     * @param s string to be added to the string table
-     * @param mayPrependSpace is set, a space is prepended to the string to archieve better compression results
-     * @return offset of s in the string table
-     */
-    public int addToStringTable(String s, boolean mayPrependSpace) throws IOException {
-        if (headerSent) {
-            throw new IOException("stringtable sent");
-        }
-        
-        int i = stringTableBuf.size();
-        int offset = i;
-        if(s.charAt(0) >= '0' && mayPrependSpace){
-            s = ' ' + s;
-            offset++; 
-        }
-        
-        stringTable.put(s, new Integer(i));
-        if(s.charAt(0) == ' '){
-            stringTable.put(s.substring(1), new Integer(i+1));
-        }
-        int j = s.lastIndexOf(' ');
-        if(j > 1){
-                stringTable.put(s.substring(j), new Integer(i+j));
-                stringTable.put(s.substring(j+1), new Integer(i+j+1));
-        }
-                
-        writeStrI(stringTableBuf, s);
-        stringTableBuf.flush();
-        return offset;
-    }
-    
-    /**
-     * Sets the tag table for a given page.
-     * The first string in the array defines tag 5, the second tag 6 etc.
-     */
-    public void setTagTable(int page, String[] tagTable) {
-        // TODO: clear entries in tagTable?
-        
-        for (int i = 0; i < tagTable.length; i++) {
-            if (tagTable[i] != null) {
-                Object idx = new int[]{page, i+5};
-                this.tagTable.put(tagTable[i], idx);
-            }
-        }
-    }
-    
-    /**
-     * Sets the attribute start Table for a given page.
-     * The first string in the array defines attribute
-     * 5, the second attribute 6 etc.
-     *  Please use the
-     *  character '=' (without quote!) as delimiter
-     *  between the attribute name and the (start of the) value
-     */
-    public void setAttrStartTable(int page, String[] attrStartTable) {
-        
-        for (int i = 0; i < attrStartTable.length; i++) {
-            if (attrStartTable[i] != null) {
-                Object idx = new int[] {page, i + 5};
-                this.attrStartTable.put(attrStartTable[i], idx);
-            }
-        }
-    }
-    
-    /**
-     * Sets the attribute value Table for a given page.
-     * The first string in the array defines attribute value 0x85,
-     * the second attribute value 0x86 etc.
-     * Must be called BEFORE use attribute(), flush() etc.
-     */
-    public void setAttrValueTable(int page, String[] attrValueTable) {
-        // clear entries in this.table!
-        for (int i = 0; i < attrValueTable.length; i++) {
-            if (attrValueTable[i] != null) {
-                Object idx = new int[]{page, i + 0x085};
-                this.attrValueTable.put(attrValueTable[i], idx);
-            }
-        }
-    }
-}
diff --git a/libcore/xml/src/main/java/org/kxml2/wap/syncml/SyncML.java b/libcore/xml/src/main/java/org/kxml2/wap/syncml/SyncML.java
deleted file mode 100644
index 5ea8496..0000000
--- a/libcore/xml/src/main/java/org/kxml2/wap/syncml/SyncML.java
+++ /dev/null
@@ -1,192 +0,0 @@
-package org.kxml2.wap.syncml;
-
-import org.kxml2.wap.*;
-
-public abstract class SyncML {
-    
-    
-    // SyncML-Common (-//SYNCML//DTD SyncML 1.2//EN and -//SYNCML//DTD MetInf 1.2//EN) support
-    
-    public static WbxmlParser createParser() {
-        WbxmlParser p = new WbxmlParser();
-        p.setTagTable(0, TAG_TABLE_0);
-        p.setTagTable(1, TAG_TABLE_1);
-        return p;
-    }
-
-    public static WbxmlSerializer createSerializer() {
-        WbxmlSerializer s = new WbxmlSerializer();
-        s.setTagTable(0, TAG_TABLE_0);
-        s.setTagTable(1, TAG_TABLE_1);
-        return s;
-    }
-    
-    
-    // SyncML-Common + DMDDF (-//OMA//DTD-DM-DDF 1.2//EN) support
-    
-    public static WbxmlParser createDMParser() {
-        WbxmlParser p = createParser();
-        p.setTagTable(2, TAG_TABLE_2_DM);
-        return p;
-    }
-
-    public static WbxmlSerializer createDMSerializer() {
-        WbxmlSerializer s = createSerializer();
-        s.setTagTable(2, TAG_TABLE_2_DM);
-        return s;
-    }
-
-    // Tables
-    
-    public static final String [] TAG_TABLE_0 = {
-        
-         //  -//SYNCML//DTD SyncML 1.2//EN
-        
-         "Add",            // 0x05 
-         "Alert",          // 0x06 
-         "Archive",        // 0x07 
-         "Atomic",         // 0x08 
-         "Chal",           // 0x09 
-         "Cmd",            // 0x0a 
-         "CmdID",          // 0x0b 
-         "CmdRef",         // 0x0c 
-         "Copy",           // 0x0d 
-         "Cred",           // 0x0e 
-         "Data",           // 0x0f 
-         "Delete",         // 0x10 
-         "Exec",           // 0x11 
-         "Final",          // 0x12 
-         "Get",            // 0x13 
-         "Item",           // 0x14 
-         "Lang",           // 0x15 
-         "LocName",        // 0x16 
-         "LocURI",         // 0x17 
-         "Map",            // 0x18 
-         "MapItem",        // 0x19 
-         "Meta",           // 0x1a 
-         "MsgID",          // 0x1b 
-         "MsgRef",         // 0x1c 
-         "NoResp",         // 0x1d 
-         "NoResults",      // 0x1e 
-         "Put",            // 0x1f 
-         "Replace",        // 0x20 
-         "RespURI",        // 0x21 
-         "Results",        // 0x22 
-         "Search",         // 0x23 
-         "Sequence",       // 0x24 
-         "SessionID",      // 0x25 
-         "SftDel",         // 0x26 
-         "Source",         // 0x27 
-         "SourceRef",      // 0x28 
-         "Status",         // 0x29 
-         "Sync",           // 0x2a 
-         "SyncBody",       // 0x2b 
-         "SyncHdr",        // 0x2c 
-         "SyncML",         // 0x2d 
-         "Target",         // 0x2e 
-         "TargetRef",      // 0x2f 
-         "Reserved for future use",    // 0x30 
-         "VerDTD",         // 0x31 
-         "VerProto",       // 0x32 
-         "NumberOfChanged",// 0x33 
-         "MoreData",       // 0x34 
-         "Field",          // 0x35
-         "Filter",         // 0x36
-         "Record",         // 0x37
-         "FilterType",     // 0x38
-         "SourceParent",   // 0x39
-         "TargetParent",   // 0x3a
-         "Move",           // 0x3b
-         "Correlator"      // 0x3c
-    };  
-    
-    public static final String [] TAG_TABLE_1 = {
-       
-         //  -//SYNCML//DTD MetInf 1.2//EN 
-        
-         "Anchor",         // 0x05 
-         "EMI",            // 0x06 
-         "Format",         // 0x07 
-         "FreeID",         // 0x08 
-         "FreeMem",        // 0x09 
-         "Last",           // 0x0a 
-         "Mark",           // 0x0b 
-         "MaxMsgSize",     // 0x0c 
-         "Mem",            // 0x0d 
-         "MetInf",         // 0x0e 
-         "Next",           // 0x0f 
-         "NextNonce",      // 0x10 
-         "SharedMem",      // 0x11 
-         "Size",           // 0x12 
-         "Type",           // 0x13 
-         "Version",        // 0x14 
-         "MaxObjSize",     // 0x15
-         "FieldLevel"      // 0x16
-         
-    };
-
-    public static final String [] TAG_TABLE_2_DM = {
-        
-        //  -//OMA//DTD-DM-DDF 1.2//EN 
-       
-        "AccessType",         // 0x05 
-        "ACL",                // 0x06 
-        "Add",                // 0x07 
-        "b64",                // 0x08 
-        "bin",                // 0x09 
-        "bool",               // 0x0a 
-        "chr",                // 0x0b 
-        "CaseSense",          // 0x0c 
-        "CIS",                // 0x0d 
-        "Copy",               // 0x0e 
-        "CS",                 // 0x0f 
-        "date",               // 0x10 
-        "DDFName",            // 0x11 
-        "DefaultValue",       // 0x12 
-        "Delete",             // 0x13 
-        "Description",        // 0x14 
-        "DDFFormat",          // 0x15 
-        "DFProperties",       // 0x16 
-        "DFTitle",            // 0x17 
-        "DFType",             // 0x18 
-        "Dynamic",            // 0x19 
-        "Exec",               // 0x1a 
-        "float",              // 0x1b 
-        "Format",             // 0x1c 
-        "Get",                // 0x1d 
-        "int",                // 0x1e 
-        "Man",                // 0x1f 
-        "MgmtTree",           // 0x20 
-        "MIME",               // 0x21 
-        "Mod",                // 0x22 
-        "Name",               // 0x23 
-        "Node",               // 0x24 
-        "node",               // 0x25 
-        "NodeName",           // 0x26 
-        "null",               // 0x27 
-        "Occurence",          // 0x28 
-        "One",                // 0x29 
-        "OneOrMore",          // 0x2a 
-        "OneOrN",             // 0x2b 
-        "Path",               // 0x2c 
-        "Permanent",          // 0x2d 
-        "Replace",            // 0x2e 
-        "RTProperties",       // 0x2f 
-        "Scope",              // 0x30 
-        "Size",               // 0x31 
-        "time",               // 0x32 
-        "Title",              // 0x33 
-        "TStamp",             // 0x34 
-        "Type",               // 0x35
-        "Value",              // 0x36
-        "VerDTD",             // 0x37
-        "VerNo",              // 0x38
-        "xml",                // 0x39
-        "ZeroOrMore",         // 0x3a
-        "ZeroOrN",            // 0x3b
-        "ZeroOrOne"           // 0x3c
-        
-   };
-    
-}
-
diff --git a/libcore/xml/src/main/java/org/kxml2/wap/wml/Wml.java b/libcore/xml/src/main/java/org/kxml2/wap/wml/Wml.java
deleted file mode 100644
index 7e925d8..0000000
--- a/libcore/xml/src/main/java/org/kxml2/wap/wml/Wml.java
+++ /dev/null
@@ -1,233 +0,0 @@
-package org.kxml2.wap.wml;
-
-import org.kxml2.wap.*;
-
-
-/** This class contains the wml coding tables for elements 
- *  and attributes needed by the WmlParser. 
- */
-
-
-public abstract class Wml {
-
-    /** Creates a WbxmlParser with the WML code pages set */
-
-    public static WbxmlParser createParser() {
-        WbxmlParser p = new WbxmlParser();
-        p.setTagTable(0, TAG_TABLE);
-        p.setAttrStartTable(0, ATTR_START_TABLE);
-        p.setAttrValueTable(0, ATTR_VALUE_TABLE);
-        return p;
-    }
-
-    public static WbxmlSerializer createSerializer() {
-        WbxmlSerializer s = new WbxmlSerializer();
-        s.setTagTable(0, TAG_TABLE);
-        s.setAttrStartTable(0, ATTR_START_TABLE);
-        s.setAttrValueTable(0, ATTR_VALUE_TABLE);
-        return s;
-    }
-
-
-    public static final String [] TAG_TABLE = {
-
-    null, // 05
-    null, // 06
-    null, // 07
-    null, // 08
-    null, // 09
-    null, // 0A
-    null, // 0B
-    null, // 0C
-    null, // 0D
-    null, // 0E
-    null, // 0F
-
-    null, // 10
-    null, // 11
-    null, // 12
-    null, // 13
-    null, // 14
-    null, // 15
-    null, // 16
-    null, // 17
-    null, // 18
-    null, // 19
-    null, // 1A
-    null, // 1B
-    "a",  // 1C
-    "td", // 1D
-    "tr", // 1E
-    "table", // 1F
-
-    "p", // 20
-    "postfield", // 21
-    "anchor", // 22
-    "access", // 23
-    "b",  // 24
-    "big", // 25
-    "br", // 26
-    "card", // 27
-    "do", // 28
-    "em", // 29
-    "fieldset", // 2A
-    "go", // 2B
-    "head", // 2C
-    "i", // 2D
-    "img", // 2E
-    "input", // 2F
-
-    "meta", // 30
-    "noop", // 31
-    "prev", // 32
-    "onevent", // 33
-    "optgroup", // 34
-    "option", // 35
-    "refresh", // 36
-    "select", // 37
-    "small", // 38
-    "strong", // 39
-    null, // 3A
-    "template", // 3B
-    "timer", // 3C
-    "u", // 3D
-    "setvar", // 3E
-    "wml", // 3F
-    };
-
-    
-    public static final String [] ATTR_START_TABLE = { 
-    "accept-charset", // 05
-    "align=bottom", // 06
-    "align=center", // 07
-    "align=left", // 08
-    "align=middle", // 09
-    "align=right", // 0A
-    "align=top", // 0B
-    "alt", // 0C
-    "content", // 0D
-    null, // 0E
-    "domain", // 0F
-    
-    "emptyok=false", // 10
-    "emptyok=true", // 11
-    "format", // 12
-    "height", // 13
-    "hspace", // 14
-    "ivalue", // 15
-    "iname", // 16
-    null, // 17
-    "label", // 18
-    "localsrc", // 19
-    "maxlength", // 1A
-    "method=get", // 1B
-    "method=post", // 1C
-    "mode=nowrap", // 1D
-    "mode=wrap", // 1E
-    "multiple=false", // 1F
-
-    "multiple=true", // 20
-    "name", // 21
-    "newcontext=false", // 22
-    "newcontext=true", // 23
-    "onpick", // 24
-    "onenterbackward", // 25
-    "onenterforward", // 26
-    "ontimer", // 27
-    "optimal=false", // 28
-    "optimal=true", // 29
-    "path", // 2A
-    null, // 2B
-    null, // 2C
-    null, // 2D
-    "scheme", // 2E
-    "sendreferer=false", // 2F
-    
-    "sendreferer=true", // 30
-    "size", // 31
-    "src", // 32
-    "ordered=true", // 33
-    "ordered=false", // 34
-    "tabindex", // 35
-    "title", // 36
-    "type", // 37
-    "type=accept", // 38
-    "type=delete", // 39
-    "type=help", // 3A
-    "type=password", // 3B
-    "type=onpick", // 3C
-    "type=onenterbackward", // 3D
-    "type=onenterforward", // 3E
-    "type=ontimer", // 3F
-
-    null, // 40
-    null, // 41
-    null, // 42
-    null, // 43
-    null, // 44
-    "type=options", // 45
-    "type=prev", // 46
-    "type=reset", // 47
-    "type=text", // 48
-    "type=vnd.", // 49
-    "href", // 4A
-    "href=http://", // 4B
-    "href=https://", // 4C
-    "value", // 4D
-    "vspace", // 4E
-    "width", // 4F
-
-    "xml:lang", // 50
-    null, // 51
-    "align", // 52
-    "columns", // 53
-    "class", // 54
-    "id", // 55
-    "forua=false", // 56
-    "forua=true", // 57
-    "src=http://", // 58
-    "src=https://", // 59
-    "http-equiv", // 5A
-    "http-equiv=Content-Type", // 5B
-    "content=application/vnd.wap.wmlc;charset=", // 5C
-    "http-equiv=Expires", // 5D
-    null, // 5E
-    null, // 5F
-    };
-
-
-    public static final String [] ATTR_VALUE_TABLE = {
-    ".com/", // 85
-    ".edu/", // 86
-    ".net/", // 87
-    ".org/", // 88
-    "accept", // 89
-    "bottom", // 8A
-    "clear", // 8B
-    "delete", // 8C
-    "help", // 8D
-    "http://", // 8E
-    "http://www.", // 8F
-    
-    "https://", // 90
-    "https://www.", // 91
-    null, // 92
-    "middle", // 93
-    "nowrap", // 94
-    "onpick", // 95
-    "onenterbackward", // 96
-    "onenterforward", // 97
-    "ontimer", // 98
-    "options", // 99
-    "password", // 9A
-    "reset", // 9B
-    null, // 9C
-    "text", // 9D
-    "top", // 9E
-    "unknown", // 9F
-    
-    "wrap", // A0
-    "www.", // A1
-    };
-}    
-
diff --git a/libcore/xml/src/main/java/org/kxml2/wap/wv/WV.java b/libcore/xml/src/main/java/org/kxml2/wap/wv/WV.java
deleted file mode 100644
index e2afbfb..0000000
--- a/libcore/xml/src/main/java/org/kxml2/wap/wv/WV.java
+++ /dev/null
@@ -1,593 +0,0 @@
-package org.kxml2.wap.wv;
-
-import java.io.IOException;
-
-import org.kxml2.wap.*;
-
-/*
-
- * WV.java
-
- *
-
- * Created on 25 September 2003, 10:40
-
- */
-
-
-
-
-
-   /** 
-     *    Wireless Village CSP 1.1 ("OMA-WV-CSP-V1_1-20021001-A.pdf")
-     *    Wireless Village CSP 1.2 ("OMA-IMPS-WV-CSP_WBXML-v1_2-20030221-C.PDF")
-     *    There are some bugs in the 1.2 spec but this is Ok. 1.2 is candidate  
- *
-
- * @author  Bogdan Onoiu
-
- */
-
-public abstract class WV {
-
-    
-
-    
-    
-    public static WbxmlParser createParser () throws IOException {
-        
-        WbxmlParser parser = new WbxmlParser();
-
-        parser.setTagTable (0, WV.tagTablePage0);
-        parser.setTagTable (1, WV.tagTablePage1);
-        parser.setTagTable (2, WV.tagTablePage2);
-        parser.setTagTable (3, WV.tagTablePage3);
-        parser.setTagTable (4, WV.tagTablePage4);
-        parser.setTagTable (5, WV.tagTablePage5);
-        parser.setTagTable (6, WV.tagTablePage6);
-        parser.setTagTable (7, WV.tagTablePage7);
-        parser.setTagTable (8, WV.tagTablePage8);
-        parser.setTagTable (9, WV.tagTablePage9);
-        parser.setTagTable (10, WV.tagTablePageA);
-
-        parser.setAttrStartTable (0, WV.attrStartTable);
-        
-        parser.setAttrValueTable (0, WV.attrValueTable);
-
-        return parser;
-    }
-    
-   
-    
-    public static final String [] tagTablePage0 = {
-        /* Common ... continue on Page 0x09 */
-        "Acceptance",     //0x00, 0x05
-        "AddList",        //0x00, 0x06
-        "AddNickList",    //0x00, 0x07
-        "SName",          //0x00, 0x08
-        "WV-CSP-Message", //0x00, 0x09
-        "ClientID",       //0x00, 0x0A
-        "Code",           //0x00, 0x0B
-        "ContactList",    //0x00, 0x0C
-        "ContentData",    //0x00, 0x0D
-        "ContentEncoding",//0x00, 0x0E
-        "ContentSize",    //0x00, 0x0F
-        "ContentType",    //0x00, 0x10
-        "DateTime",       //0x00, 0x11
-        "Description",    //0x00, 0x12
-        "DetailedResult", //0x00, 0x13
-        "EntityList",     //0x00, 0x14
-        "Group",          //0x00, 0x15
-        "GroupID",        //0x00, 0x16
-        "GroupList",      //0x00, 0x17
-        "InUse",          //0x00, 0x18
-        "Logo",           //0x00, 0x19
-        "MessageCount",   //0x00, 0x1A
-        "MessageID",      //0x00, 0x1B
-        "MessageURI",     //0x00, 0x1C
-        "MSISDN",         //0x00, 0x1D
-        "Name",           //0x00, 0x1E
-        "NickList",       //0x00, 0x1F
-        "NickName",       //0x00, 0x20
-        "Poll",           //0x00, 0x21
-        "Presence",       //0x00, 0x22
-        "PresenceSubList",//0x00, 0x23
-        "PresenceValue",  //0x00, 0x24
-        "Property",       //0x00, 0x25
-        "Qualifier",      //0x00, 0x26
-        "Recipient",      //0x00, 0x27
-        "RemoveList",     //0x00, 0x28
-        "RemoveNickList", //0x00, 0x29
-        "Result",         //0x00, 0x2A
-        "ScreenName",     //0x00, 0x2B
-        "Sender",         //0x00, 0x2C
-        "Session",        //0x00, 0x2D
-        "SessionDescriptor",//0x00, 0x2E
-        "SessionID",      //0x00, 0x2F
-        "SessionType",    //0x00, 0x30
-        "Status",         //0x00, 0x31
-        "Transaction",    //0x00, 0x32
-        "TransactionContent",//0x00, 0x33
-        "TransactionDescriptor",//0x00, 0x34
-        "TransactionID",  //0x00, 0x35
-        "TransactionMode",//0x00, 0x36
-        "URL",            //0x00, 0x37
-        "URLList",        //0x00, 0x38
-        "User",           //0x00, 0x39
-        "UserID",         //0x00, 0x3A
-        "UserList",       //0x00, 0x3B
-        "Validity",       //0x00, 0x3C
-        "Value",          //0x00, 0x3D
-    };
-    
-    public static final String [] tagTablePage1 = {
-        /* Access ... continue on Page 0x0A */
-        "AllFunctions",             //  0x01, 0x05
-        "AllFunctionsRequest",      //  0x01, 0x06
-        "CancelInvite-Request",     //  0x01, 0x07
-        "CancelInviteUser-Request", //  0x01, 0x08
-        "Capability",               //  0x01, 0x09
-        "CapabilityList",           //  0x01, 0x0A
-        "CapabilityRequest",        //  0x01, 0x0B
-        "ClientCapability-Request", //  0x01, 0x0C
-        "ClientCapability-Response",//  0x01, 0x0D
-        "DigestBytes",          //  0x01, 0x0E
-        "DigestSchema",         //  0x01, 0x0F
-        "Disconnect",           //  0x01, 0x10
-        "Functions",            //  0x01, 0x11
-        "GetSPInfo-Request",    //  0x01, 0x12
-        "GetSPInfo-Response",   //  0x01, 0x13
-        "InviteID",             //  0x01, 0x14
-        "InviteNote",           //  0x01, 0x15
-        "Invite-Request",       //  0x01, 0x16
-        "Invite-Response",      //  0x01, 0x17
-        "InviteType",           //  0x01, 0x18
-        "InviteUser-Request",   //  0x01, 0x19
-        "InviteUser-Response",  //  0x01, 0x1A
-        "KeepAlive-Request",    //  0x01, 0x1B
-        "KeepAliveTime",        //  0x01, 0x1C
-        "Login-Request",        //  0x01, 0x1D
-        "Login-Response",       //  0x01, 0x1E
-        "Logout-Request",       //  0x01, 0x1F
-        "Nonce",                //  0x01, 0x20
-        "Password",             //  0x01, 0x21
-        "Polling-Request",      //  0x01, 0x22
-        "ResponseNote",         //  0x01, 0x23
-        "SearchElement",        //  0x01, 0x24
-        "SearchFindings",       //  0x01, 0x25
-        "SearchID",             //  0x01, 0x26
-        "SearchIndex",          //  0x01, 0x27
-        "SearchLimit",          //  0x01, 0x28
-        "KeepAlive-Response",   //  0x01, 0x29
-        "SearchPairList",       //  0x01, 0x2A
-        "Search-Request",       //  0x01, 0x2B
-        "Search-Response",      //  0x01, 0x2C
-        "SearchResult",         //  0x01, 0x2D
-        "Service-Request",      //  0x01, 0x2E
-        "Service-Response",     //  0x01, 0x2F
-        "SessionCookie",        //  0x01, 0x30
-        "StopSearch-Request",   //  0x01, 0x31
-        "TimeToLive",           //  0x01, 0x32
-        "SearchString",         //  0x01, 0x33
-        "CompletionFlag",       //  0x01, 0x34
-        null,                   //  0x01, 0x35
-        "ReceiveList",          //  0x01, 0x36 /* WV 1.2 */
-        "VerifyID-Request",     //  0x01, 0x37 /* WV 1.2 */
-        "Extended-Request",     //  0x01, 0x38 /* WV 1.2 */
-        "Extended-Response",    //  0x01, 0x39 /* WV 1.2 */
-        "AgreedCapabilityList", //  0x01, 0x3A /* WV 1.2 */
-        "Extended-Data",        //  0x01, 0x3B /* WV 1.2 */
-        "OtherServer",          //  0x01, 0x3C /* WV 1.2 */
-        "PresenceAttributeNSName",//0x01, 0x3D /* WV 1.2 */
-        "SessionNSName",        //  0x01, 0x3E /* WV 1.2 */
-        "TransactionNSName",    //  0x01, 0x3F /* WV 1.2 */
-    };
-    
-    public static final String [] tagTablePage2 = {
-        /* Service ... continue on Page 0x08 */
-        "ADDGM",        //  0x02, 0x05
-        "AttListFunc",  //  0x02, 0x06
-        "BLENT",        //  0x02, 0x07
-        "CAAUT",        //  0x02, 0x08
-        "CAINV",        //  0x02, 0x09
-        "CALI",         //  0x02, 0x0A
-        "CCLI",         //  0x02, 0x0B
-        "ContListFunc", //  0x02, 0x0C
-        "CREAG",        //  0x02, 0x0D
-        "DALI",         //  0x02, 0x0E
-        "DCLI",         //  0x02, 0x0F
-        "DELGR",        //  0x02, 0x10
-        "FundamentalFeat",//0x02, 0x11
-        "FWMSG",        //  0x02, 0x12
-        "GALS",         //  0x02, 0x13
-        "GCLI",         //  0x02, 0x14
-        "GETGM",        //  0x02, 0x15
-        "GETGP",        //  0x02, 0x16
-        "GETLM",        //  0x02, 0x17
-        "GETM",         //  0x02, 0x18
-        "GETPR",        //  0x02, 0x19
-        "GETSPI",       //  0x02, 0x1A
-        "GETWL",        //  0x02, 0x1B
-        "GLBLU",        //  0x02, 0x1C
-        "GRCHN",        //  0x02, 0x1D
-        "GroupAuthFunc",//  0x02, 0x1E
-        "GroupFeat",    //  0x02, 0x1F
-        "GroupMgmtFunc",//  0x02, 0x20
-        "GroupUseFunc", //  0x02, 0x21
-        "IMAuthFunc",   //  0x02, 0x22
-        "IMFeat",       //  0x02, 0x23
-        "IMReceiveFunc",//  0x02, 0x24
-        "IMSendFunc",   //  0x02, 0x25
-        "INVIT",        //  0x02, 0x26
-        "InviteFunc",   //  0x02, 0x27
-        "MBRAC",        //  0x02, 0x28
-        "MCLS",         //  0x02, 0x29
-        "MDELIV",       //  0x02, 0x2A
-        "NEWM",         //  0x02, 0x2B
-        "NOTIF",        //  0x02, 0x2C
-        "PresenceAuthFunc",//0x02, 0x2D
-        "PresenceDeliverFunc",//0x02, 0x2E
-        "PresenceFeat", //  0x02, 0x2F
-        "REACT",        //  0x02, 0x30
-        "REJCM",        //  0x02, 0x31
-        "REJEC",        //  0x02, 0x32
-        "RMVGM",        //  0x02, 0x33
-        "SearchFunc",   //  0x02, 0x34
-        "ServiceFunc",  //  0x02, 0x35
-        "SETD",         //  0x02, 0x36
-        "SETGP",        //  0x02, 0x37
-        "SRCH",         //  0x02, 0x38
-        "STSRC",        //  0x02, 0x39
-        "SUBGCN",       //  0x02, 0x3A
-        "UPDPR",        //  0x02, 0x3B
-        "WVCSPFeat",    //  0x02, 0x3C
-        "MF",           //  0x02, 0x3D /* WV 1.2 */
-        "MG",           //  0x02, 0x3E /* WV 1.2 */
-        "MM"            //  0x02, 0x3F /* WV 1.2 */
-    };
-    
-    public static final String [] tagTablePage3 = {
-        /* Client Capability */
-        "AcceptedCharset",          //  0x03, 0x05
-        "AcceptedContentLength",    //  0x03, 0x06
-        "AcceptedContentType",      //  0x03, 0x07
-        "AcceptedTransferEncoding", //  0x03, 0x08
-        "AnyContent",               //  0x03, 0x09
-        "DefaultLanguage",          //  0x03, 0x0A
-        "InitialDeliveryMethod",    //  0x03, 0x0B
-        "MultiTrans",               //  0x03, 0x0C
-        "ParserSize",               //  0x03, 0x0D
-        "ServerPollMin",            //  0x03, 0x0E
-        "SupportedBearer",          //  0x03, 0x0F
-        "SupportedCIRMethod",       //  0x03, 0x10
-        "TCPAddress",               //  0x03, 0x11
-        "TCPPort",                  //  0x03, 0x12
-        "UDPPort"                  //  0x03, 0x13
-    };
-    
-    public static final String [] tagTablePage4 = {
-        /* Presence Primitive */
-        "CancelAuth-Request",           //  0x04, 0x05
-        "ContactListProperties",        //  0x04, 0x06
-        "CreateAttributeList-Request",  //  0x04, 0x07
-        "CreateList-Request",           //  0x04, 0x08
-        "DefaultAttributeList",         //  0x04, 0x09
-        "DefaultContactList",           //  0x04, 0x0A
-        "DefaultList",                  //  0x04, 0x0B
-        "DeleteAttributeList-Request",  //  0x04, 0x0C
-        "DeleteList-Request",           //  0x04, 0x0D
-        "GetAttributeList-Request",     //  0x04, 0x0E
-        "GetAttributeList-Response",    //  0x04, 0x0F
-        "GetList-Request",              //  0x04, 0x10
-        "GetList-Response",             //  0x04, 0x11
-        "GetPresence-Request",          //  0x04, 0x12
-        "GetPresence-Response",         //  0x04, 0x13
-        "GetWatcherList-Request",       //  0x04, 0x14
-        "GetWatcherList-Response",      //  0x04, 0x15
-        "ListManage-Request",           //  0x04, 0x16
-        "ListManage-Response",          //  0x04, 0x17
-        "UnsubscribePresence-Request",  //  0x04, 0x18
-        "PresenceAuth-Request",         //  0x04, 0x19
-        "PresenceAuth-User",            //  0x04, 0x1A
-        "PresenceNotification-Request", //  0x04, 0x1B
-        "UpdatePresence-Request",       //  0x04, 0x1C
-        "SubscribePresence-Request",    //  0x04, 0x1D
-        "Auto-Subscribe",               //  0x04, 0x1E /* WV 1.2 */
-        "GetReactiveAuthStatus-Request",//  0x04, 0x1F /* WV 1.2 */
-        "GetReactiveAuthStatus-Response",// 0x04, 0x20 /* WV 1.2 */
-    };
-    
-    public static final String [] tagTablePage5 = {
-        /* Presence Attribute */
-        "Accuracy",         //  0x05, 0x05
-        "Address",          //  0x05, 0x06
-        "AddrPref",         //  0x05, 0x07
-        "Alias",            //  0x05, 0x08
-        "Altitude",         //  0x05, 0x09
-        "Building",         //  0x05, 0x0A
-        "Caddr",            //  0x05, 0x0B
-        "City",             //  0x05, 0x0C
-        "ClientInfo",       //  0x05, 0x0D
-        "ClientProducer",   //  0x05, 0x0E
-        "ClientType",       //  0x05, 0x0F
-        "ClientVersion",    //  0x05, 0x10
-        "CommC",            //  0x05, 0x11
-        "CommCap",          //  0x05, 0x12
-        "ContactInfo",      //  0x05, 0x13
-        "ContainedvCard",   //  0x05, 0x14
-        "Country",          //  0x05, 0x15
-        "Crossing1",        //  0x05, 0x16
-        "Crossing2",        //  0x05, 0x17
-        "DevManufacturer",  //  0x05, 0x18
-        "DirectContent",    //  0x05, 0x19
-        "FreeTextLocation", //  0x05, 0x1A
-        "GeoLocation",      //  0x05, 0x1B
-        "Language",         //  0x05, 0x1C
-        "Latitude",         //  0x05, 0x1D
-        "Longitude",        //  0x05, 0x1E
-        "Model",            //  0x05, 0x1F
-        "NamedArea",        //  0x05, 0x20
-        "OnlineStatus",     //  0x05, 0x21
-        "PLMN",             //  0x05, 0x22
-        "PrefC",            //  0x05, 0x23
-        "PreferredContacts",//  0x05, 0x24
-        "PreferredLanguage",//  0x05, 0x25
-        "PreferredContent", //  0x05, 0x26
-        "PreferredvCard",   //  0x05, 0x27
-        "Registration",     //  0x05, 0x28
-        "StatusContent",    //  0x05, 0x29
-        "StatusMood",       //  0x05, 0x2A
-        "StatusText",       //  0x05, 0x2B
-        "Street",           //  0x05, 0x2C
-        "TimeZone",         //  0x05, 0x2D
-        "UserAvailability", //  0x05, 0x2E
-        "Cap",              //  0x05, 0x2F
-        "Cname",            //  0x05, 0x30
-        "Contact",          //  0x05, 0x31
-        "Cpriority",        //  0x05, 0x32
-        "Cstatus",          //  0x05, 0x33
-        "Note",             //  0x05, 0x34 /* WV 1.2 */
-        "Zone",             //  0x05, 0x35
-        null,
-        "Inf_link",         //  0x05, 0x37 /* WV 1.2 */
-        "InfoLink",         //  0x05, 0x38 /* WV 1.2 */
-        "Link",             //  0x05, 0x39 /* WV 1.2 */
-        "Text",             //  0x05, 0x3A /* WV 1.2 */
-    };
-    
-    public static final String [] tagTablePage6 = {
-        /* Messaging */
-        "BlockList",                //  0x06, 0x05
-//      "BlockUser-Request",        //  0x06, 0x06  //This is a bug in the spec
-        "BlockEntity-Request",        //  0x06, 0x06  
-        "DeliveryMethod",           //  0x06, 0x07
-        "DeliveryReport",           //  0x06, 0x08
-        "DeliveryReport-Request",   //  0x06, 0x09
-        "ForwardMessage-Request",   //  0x06, 0x0A
-        "GetBlockedList-Request",   //  0x06, 0x0B
-        "GetBlockedList-Response",  //  0x06, 0x0C
-        "GetMessageList-Request",   //  0x06, 0x0D
-        "GetMessageList-Response",  //  0x06, 0x0E
-        "GetMessage-Request",       //  0x06, 0x0F
-        "GetMessage-Response",      //  0x06, 0x10
-        "GrantList",                //  0x06, 0x11
-        "MessageDelivered",         //  0x06, 0x12
-        "MessageInfo",              //  0x06, 0x13
-        "MessageNotification",      //  0x06, 0x14
-        "NewMessage",               //  0x06, 0x15
-        "RejectMessage-Request",    //  0x06, 0x16
-        "SendMessage-Request",      //  0x06, 0x17
-        "SendMessage-Response",     //  0x06, 0x18
-        "SetDeliveryMethod-Request",//  0x06, 0x19
-        "DeliveryTime",             //  0x06, 0x1A
-    };
-    
-    public static final String [] tagTablePage7 = {
-        /* Group */
-        "AddGroupMembers-Request",  //  0x07, 0x05
-        "Admin",                    //  0x07, 0x06
-        "CreateGroup-Request",      //  0x07, 0x07
-        "DeleteGroup-Request",      //  0x07, 0x08
-        "GetGroupMembers-Request",  //  0x07, 0x09
-        "GetGroupMembers-Response", //  0x07, 0x0A
-        "GetGroupProps-Request",    //  0x07, 0x0B
-        "GetGroupProps-Response",   //  0x07, 0x0C
-        "GroupChangeNotice",        //  0x07, 0x0D
-        "GroupProperties",          //  0x07, 0x0E
-        "Joined",                   //  0x07, 0x0F
-        "JoinedRequest",            //  0x07, 0x10
-        "JoinGroup-Request",        //  0x07, 0x11
-        "JoinGroup-Response",       //  0x07, 0x12
-        "LeaveGroup-Request",       //  0x07, 0x13
-        "LeaveGroup-Response",      //  0x07, 0x14
-        "Left",                     //  0x07, 0x15
-        "MemberAccess-Request",     //  0x07, 0x16
-        "Mod",                      //  0x07, 0x17
-        "OwnProperties",            //  0x07, 0x18
-        "RejectList-Request",       //  0x07, 0x19
-        "RejectList-Response",      //  0x07, 0x1A
-        "RemoveGroupMembers-Request",// 0x07, 0x1B
-        "SetGroupProps-Request",    //  0x07, 0x1C
-        "SubscribeGroupNotice-Request", //  0x07, 0x1D
-        "SubscribeGroupNotice-Response",//  0x07, 0x1E
-        "Users",                    //  0x07, 0x1F
-        "WelcomeNote",              //  0x07, 0x20
-        "JoinGroup",                //  0x07, 0x21
-        "SubscribeNotification",    //  0x07, 0x22
-        "SubscribeType",            //  0x07, 0x23
-        "GetJoinedUsers-Request",   //  0x07, 0x24 /* WV 1.2 */
-        "GetJoinedUsers-Response",  //  0x07, 0x25 /* WV 1.2 */
-        "AdminMapList",             //  0x07, 0x26 /* WV 1.2 */
-        "AdminMapping",             //  0x07, 0x27 /* WV 1.2 */
-        "Mapping",                  //  0x07, 0x28 /* WV 1.2 */
-        "ModMapping",               //  0x07, 0x29 /* WV 1.2 */
-        "UserMapList",              //  0x07, 0x2A /* WV 1.2 */
-        "UserMapping",              //  0x07, 0x2B /* WV 1.2 */
-    };
-    
-    public static final String [] tagTablePage8 = {
-        /* Service ... continued */
-        "MP",                       //  0x08, 0x05 /* WV 1.2 */
-        "GETAUT",                   //  0x08, 0x06 /* WV 1.2 */
-        "GETJU",                    //  0x08, 0x07 /* WV 1.2 */
-        "VRID",                     //  0x08, 0x08 /* WV 1.2 */
-        "VerifyIDFunc",             //  0x08, 0x09 /* WV 1.2 */
-    };
-    
-    public static final String [] tagTablePage9 = {
-        /* Common ... continued */
-        "CIR",                      //  0x09, 0x05 /* WV 1.2 */
-        "Domain",                   //  0x09, 0x06 /* WV 1.2 */
-        "ExtBlock",                 //  0x09, 0x07 /* WV 1.2 */
-        "HistoryPeriod",            //  0x09, 0x08 /* WV 1.2 */
-        "IDList",                   //  0x09, 0x09 /* WV 1.2 */
-        "MaxWatcherList",           //  0x09, 0x0A /* WV 1.2 */
-        "ReactiveAuthState",        //  0x09, 0x0B /* WV 1.2 */
-        "ReactiveAuthStatus",       //  0x09, 0x0C /* WV 1.2 */
-        "ReactiveAuthStatusList",   //  0x09, 0x0D /* WV 1.2 */
-        "Watcher",                  //  0x09, 0x0E /* WV 1.2 */
-        "WatcherStatus"             //  0x09, 0x0F /* WV 1.2 */
-    };
-    
-    public static final String [] tagTablePageA = {
-        /* Access ... continued */
-        "WV-CSP-NSDiscovery-Request",  //0x0A, 0x05 /* WV 1.2 */
-        "WV-CSP-NSDiscovery-Response", //0x0A, 0x06 /* WV 1.2 */
-        "VersionList"                  //0x0A, 0x07 /* WV 1.2 */
-    };
-    
-    public static final String [] attrStartTable = {
-        "xmlns=http://www.wireless-village.org/CSP",//  0x00, 0x05
-        "xmlns=http://www.wireless-village.org/PA", //  0x00, 0x06
-        "xmlns=http://www.wireless-village.org/TRC",//  0x00, 0x07
-        "xmlns=http://www.openmobilealliance.org/DTD/WV-CSP",   //  0x00, 0x08
-        "xmlns=http://www.openmobilealliance.org/DTD/WV-PA",    //  0x00, 0x09
-        "xmlns=http://www.openmobilealliance.org/DTD/WV-TRC",   //  0x00, 0x0A
-    };
-    
-    public static final String [] attrValueTable = {
-      
-        "AccessType",                           // 0x00 /* Common value token */
-        "ActiveUsers",                          // 0x01 /* Common value token */
-        "Admin",                                // 0x02 /* Common value token */
-        "application/",                         // 0x03 /* Common value token */
-        "application/vnd.wap.mms-message",      // 0x04 /* Common value token */
-        "application/x-sms",                    // 0x05 /* Common value token */
-        "AutoJoin",                             // 0x06 /* Common value token */
-        "BASE64",                               // 0x07 /* Common value token */
-        "Closed",                               // 0x08 /* Common value token */
-        "Default",                              // 0x09 /* Common value token */
-        "DisplayName",                          // 0x0a /* Common value token */
-        "F",                                    // 0x0b /* Common value token */
-        "G",                                    // 0x0c /* Common value token */
-        "GR",                                   // 0x0d /* Common value token */
-        "http://",                              // 0x0e /* Common value token */
-        "https://",                             // 0x0f /* Common value token */
-        "image/",                               // 0x10 /* Common value token */
-        "Inband",                               // 0x11 /* Common value token */
-        "IM",                                   // 0x12 /* Common value token */
-        "MaxActiveUsers",                       // 0x13 /* Common value token */
-        "Mod",                                  // 0x14 /* Common value token */
-        "Name",                                 // 0x15 /* Common value token */
-        "None",                                 // 0x16 /* Common value token */
-        "N",                                    // 0x17 /* Common value token */
-        "Open",                                 // 0x18 /* Common value token */
-        "Outband",                              // 0x19 /* Common value token */
-        "PR",                                   // 0x1a /* Common value token */
-        "Private",                              // 0x1b /* Common value token */
-        "PrivateMessaging",                     // 0x1c /* Common value token */
-        "PrivilegeLevel",                       // 0x1d /* Common value token */
-        "Public",                               // 0x1e /* Common value token */
-        "P",                                    // 0x1f /* Common value token */
-        "Request",                              // 0x20 /* Common value token */
-        "Response",                             // 0x21 /* Common value token */
-        "Restricted",                           // 0x22 /* Common value token */
-        "ScreenName",                           // 0x23 /* Common value token */
-        "Searchable",                           // 0x24 /* Common value token */
-        "S",                                    // 0x25 /* Common value token */
-        "SC",                                   // 0x26 /* Common value token */
-        "text/",                                // 0x27 /* Common value token */
-        "text/plain",                           // 0x28 /* Common value token */
-        "text/x-vCalendar",                     // 0x29 /* Common value token */
-        "text/x-vCard",                         // 0x2a /* Common value token */
-        "Topic",                                // 0x2b /* Common value token */
-        "T",                                    // 0x2c /* Common value token */
-        "Type",                                 // 0x2d /* Common value token */
-        "U",                                    // 0x2e /* Common value token */
-        "US",                                   // 0x2f /* Common value token */
-        "www.wireless-village.org",             // 0x30 /* Common value token */
-        "AutoDelete",                           // 0x31 /* Common value token */ /* WV 1.2 */
-        "GM",                                   // 0x32 /* Common value token */ /* WV 1.2 */
-        "Validity",                             // 0x33 /* Common value token */ /* WV 1.2 */
-        "ShowID",                               // 0x34 /* Common value token */ /* WV 1.2 */
-        "GRANTED",                              // 0x35 /* Common value token */ /* WV 1.2 */
-        "PENDING",                              // 0x36 /* Common value token */ /* WV 1.2 */
-        null,                                   // 0x37
-        null,                                   // 0x38
-        null,                                   // 0x39
-        null,                                   // 0x3a
-        null,                                   // 0x3b
-        null,                                   // 0x3c
-        "GROUP_ID",                             // 0x3d /* Access value token */
-        "GROUP_NAME",                           // 0x3e /* Access value token */
-        "GROUP_TOPIC",                          // 0x3f /* Access value token */
-        "GROUP_USER_ID_JOINED",                 // 0x40 /* Access value token */
-        "GROUP_USER_ID_OWNER",                  // 0x41 /* Access value token */
-        "HTTP",                                 // 0x42 /* Access value token */
-        "SMS",                                  // 0x43 /* Access value token */
-        "STCP",                                 // 0x44 /* Access value token */
-        "SUDP",                                 // 0x45 /* Access value token */
-        "USER_ALIAS",                           // 0x46 /* Access value token */
-        "USER_EMAIL_ADDRESS",                   // 0x47 /* Access value token */
-        "USER_FIRST_NAME",                      // 0x48 /* Access value token */
-        "USER_ID",                              // 0x49 /* Access value token */
-        "USER_LAST_NAME",                       // 0x4a /* Access value token */
-        "USER_MOBILE_NUMBER",                   // 0x4b /* Access value token */
-        "USER_ONLINE_STATUS",                   // 0x4c /* Access value token */
-        "WAPSMS",                               // 0x4d /* Access value token */
-        "WAPUDP",                               // 0x4e /* Access value token */
-        "WSP",                                  // 0x4f /* Access value token */
-        "GROUP_USER_ID_AUTOJOIN",               // 0x50 /* Access value token */ /* WV 1.2 */
-        null,                                   // 0x51
-        null,                                   // 0x52
-        null,                                   // 0x53
-        null,                                   // 0x54
-        null,                                   // 0x55
-        null,                                   // 0x56
-        null,                                   // 0x57
-        null,                                   // 0x58
-        null,                                   // 0x59
-        null,                                   // 0x5a
-        "ANGRY",                                // 0x5b /* Presence value token */
-        "ANXIOUS",                              // 0x5c /* Presence value token */
-        "ASHAMED",                              // 0x5d /* Presence value token */
-        "AUDIO_CALL",                           // 0x5e /* Presence value token */
-        "AVAILABLE",                            // 0x5f /* Presence value token */
-        "BORED",                                // 0x60 /* Presence value token */
-        "CALL",                                 // 0x61 /* Presence value token */
-        "CLI",                                  // 0x62 /* Presence value token */
-        "COMPUTER",                             // 0x63 /* Presence value token */
-        "DISCREET",                             // 0x64 /* Presence value token */
-        "EMAIL",                                // 0x65 /* Presence value token */
-        "EXCITED",                              // 0x66 /* Presence value token */
-        "HAPPY",                                // 0x67 /* Presence value token */
-        "IM",                                   // 0x68 /* Presence value token */
-        "IM_OFFLINE",                           // 0x69 /* Presence value token */
-        "IM_ONLINE",                            // 0x6a /* Presence value token */
-        "IN_LOVE",                              // 0x6b /* Presence value token */
-        "INVINCIBLE",                           // 0x6c /* Presence value token */
-        "JEALOUS",                              // 0x6d /* Presence value token */
-        "MMS",                                  // 0x6e /* Presence value token */
-        "MOBILE_PHONE",                         // 0x6f /* Presence value token */
-        "NOT_AVAILABLE",                        // 0x70 /* Presence value token */
-        "OTHER",                                // 0x71 /* Presence value token */
-        "PDA",                                  // 0x72 /* Presence value token */
-        "SAD",                                  // 0x73 /* Presence value token */
-        "SLEEPY",                               // 0x74 /* Presence value token */
-        "SMS",                                  // 0x75 /* Presence value token */
-        "VIDEO_CALL",                           // 0x76 /* Presence value token */
-        "VIDEO_STREAM",                         // 0x77 /* Presence value token */
-    };
-    
-    
-}
diff --git a/libcore/xml/src/main/java/org/xmlpull/v1/XmlPullParser.java b/libcore/xml/src/main/java/org/xmlpull/v1/XmlPullParser.java
index 2c2946f..66c8f4d 100644
--- a/libcore/xml/src/main/java/org/xmlpull/v1/XmlPullParser.java
+++ b/libcore/xml/src/main/java/org/xmlpull/v1/XmlPullParser.java
@@ -8,7 +8,7 @@
 import java.io.Reader;
 
 /**
- * XML Pull Parser is an interface that defines parsing functionlity provided
+ * XML Pull Parser is an interface that defines parsing functionality provided
  * in <a href="http://www.xmlpull.org/">XMLPULL V1 API</a> (visit this website to
  * learn more about API and its implementations).
  *
@@ -23,7 +23,7 @@
  *   then parser behaves like XML 1.0 compliant non-validating parser under condition that
  *  <em>no DOCDECL is present</em> in XML documents
  *   (internal entites can still be defined with defineEntityReplacementText()).
- *   This mode of operation is intened <b>for operation in constrained environments</b> such as J2ME.
+ *   This mode of operation is intended <b>for operation in constrained environments</b> such as J2ME.
  * </ul>
  *
  *
@@ -45,8 +45,8 @@
  * <p>Th following event types are seen by next()<dl>
  * <dt><a href="#START_TAG">START_TAG</a><dd> An XML start tag was read.
  * <dt><a href="#TEXT">TEXT</a><dd> Text content was read;
- * the text content can be retreived using the getText() method.
- *  (when in validating mode next() will not report ignorable whitespaces, use nextToken() instead)
+ * the text content can be retrieved using the getText() method.
+ *  (when in validating mode next() will not report ignorable whitespace, use nextToken() instead)
  * <dt><a href="#END_TAG">END_TAG</a><dd> An end tag was read
  * <dt><a href="#END_DOCUMENT">END_DOCUMENT</a><dd> No more events are available
  * </dl>
@@ -62,7 +62,7 @@
  *  getProperty(&quot;<a href="http://xmlpull.org/v1/doc/features.html#xmldecl-standalone">http://xmlpull.org/v1/doc/features.html#xmldecl-standalone</a>&quot;)
  *       returns Boolean: null if there was no standalone declaration
  *  or if property is not supported
- *         otherwise returns Boolean(true) if standalon="yes" and Boolean(false) when standalone="no"
+ *         otherwise returns Boolean(true) if standalone="yes" and Boolean(false) when standalone="no"
  * <li><b>encoding</b>: obtained from getInputEncoding()
  *       null if stream had unknown encoding (not set in setInputStream)
  *           and it was not declared in XMLDecl
@@ -221,9 +221,9 @@
      * Also, when the state was reached by calling next(), the text value will
      * be normalized, whereas getText() will
      * return unnormalized content in the case of nextToken(). This allows
-     * an exact roundtrip without chnanging line ends when examining low
+     * an exact roundtrip without changing line ends when examining low
      * level events, whereas for high level applications the text is
-     * normalized apropriately.
+     * normalized appropriately.
      *
      * @see #next
      * @see #nextToken
@@ -239,7 +239,7 @@
      * this token is available only from calls to <a href="#nextToken()">nextToken()</a>.
      * A call to next() will accumulate various text events into a single event
      * of type TEXT. The text contained in the CDATA section is available
-     * by callling getText().
+     * by calling getText().
      *
      * @see #nextToken
      * @see #getText
@@ -250,8 +250,8 @@
      * An entity reference was just read;
      * this token is available from <a href="#nextToken()">nextToken()</a>
      * only. The entity name is available by calling getName(). If available,
-     * the replacement text can be obtained by calling getTextt(); otherwise,
-     * the user is responsibile for resolving the entity reference.
+     * the replacement text can be obtained by calling getText(); otherwise,
+     * the user is responsible for resolving the entity reference.
      * This event type is never returned from next(); next() will
      * accumulate the replacement text and other text
      * events to a single TEXT event.
@@ -323,7 +323,7 @@
      * the string "START_TAG".
      *
      * This array is intended for diagnostic output only. Relying
-     * on the contents of the array may be dangerous since malicous
+     * on the contents of the array may be dangerous since malicious
      * applications may alter the array, although it is final, due
      * to limitations of the Java language.
      */
@@ -375,7 +375,7 @@
      * the DOCDECL event type is reported by nextToken()
      * and ignored by next().
      *
-     * If this featue is activated, then the document declaration
+     * If this feature is activated, then the document declaration
      * must be processed by the parser.
      *
      * <p><strong>Please note:</strong> If the document type declaration
@@ -392,7 +392,7 @@
 
     /**
      * If this feature is activated, all validation errors as
-     * defined in the XML 1.0 sepcification are reported.
+     * defined in the XML 1.0 specification are reported.
      * This implies that FEATURE_PROCESS_DOCDECL is true and both, the
      * internal and external document type declaration will be processed.
      * <p><strong>Please Note:</strong> This feature can not be changed
@@ -412,7 +412,7 @@
      * <p>Example: call setFeature(FEATURE_PROCESS_NAMESPACES, true) in order
      * to switch on namespace processing. The initial settings correspond
      * to the properties requested from the XML Pull Parser factory.
-     * If none were requested, all feautures are deactivated by default.
+     * If none were requested, all features are deactivated by default.
      *
      * @exception XmlPullParserException If the feature is not supported or can not be set
      * @exception IllegalArgumentException If string with the feature name is null
@@ -494,7 +494,7 @@
      * If setInput(InputStream, inputEncoding) was called with an inputEncoding
      * value other than null, this value must be returned
      * from this method. Otherwise, if inputEncoding is null and
-     * the parser suppports the encoding detection feature
+     * the parser supports the encoding detection feature
      * (http://xmlpull.org/v1/doc/features.html#detect-encoding),
      * it must return the detected encoding.
      * If setInput(Reader) was called, null is returned.
@@ -518,7 +518,7 @@
      *
      * <p><b>Please notes:</b> The given value is used literally as replacement text
      * and it corresponds to declaring entity in DTD that has all special characters
-     * escaped: left angle bracket is replaced with &amp;lt;, ampersnad with &amp;amp;
+     * escaped: left angle bracket is replaced with &amp;lt;, ampersand with &amp;amp;
      * and so on.
      *
      * <p><b>Note:</b> The given value is the literal replacement text and must not
@@ -545,7 +545,7 @@
      * <p><b>NOTE:</b> when parser is on END_TAG then it is allowed to call
      *  this function with getDepth()+1 argument to retrieve position of namespace
      *  prefixes and URIs that were declared on corresponding START_TAG.
-     * <p><b>NOTE:</b> to retrieve lsit of namespaces declared in current element:<pre>
+     * <p><b>NOTE:</b> to retrieve list of namespaces declared in current element:<pre>
      *       XmlPullParser pp = ...
      *       int nsStart = pp.getNamespaceCount(pp.getDepth()-1);
      *       int nsEnd = pp.getNamespaceCount(pp.getDepth());
@@ -564,7 +564,7 @@
     int getNamespaceCount(int depth) throws XmlPullParserException;
 
     /**
-     * Returns the namespace prefixe for the given position
+     * Returns the namespace prefix for the given position
      * in the namespace stack.
      * Default namespace declaration (xmlns='...') will have null as prefix.
      * If the given index is out of range, an exception is thrown.
@@ -605,7 +605,7 @@
      * </pre>
      *
      * <p><strong>Please note:</strong> parser implementations
-     * may provide more efifcient lookup, e.g. using a Hashtable.
+     * may provide more efficient lookup, e.g. using a Hashtable.
      * The 'xml' prefix is bound to "http://www.w3.org/XML/1998/namespace", as
      * defined in the
      * <a href="http://www.w3.org/TR/REC-xml-names/#ns-using">Namespaces in XML</a>
@@ -817,7 +817,7 @@
      *
      * @param index zero-based index of attribute
      * @return attribute namespace,
-     *   empty string ("") is returned  if namesapces processing is not enabled or
+     *   empty string ("") is returned  if namespaces processing is not enabled or
      *   namespaces processing is enabled but attribute has no namespace (it has no prefix).
      */
     String getAttributeNamespace (int index);
@@ -915,8 +915,8 @@
     /**
      * Get next parsing event - element content wil be coalesced and only one
      * TEXT event must be returned for whole element content
-     * (comments and processing instructions will be ignored and emtity references
-     * must be expanded or exception mus be thrown if entity reerence can not be exapnded).
+     * (comments and processing instructions will be ignored and entity references
+     * must be expanded or exception mus be thrown if entity reference can not be expanded).
      * If element content is empty (content is "") then no TEXT event will be reported.
      *
      * <p><b>NOTE:</b> empty element (such as &lt;tag/>) will be reported
@@ -963,8 +963,8 @@
      *  <br>Note: that element content may be delivered in multiple consecutive TEXT events.
      * <dt>IGNORABLE_WHITESPACE<dd>return characters that are determined to be ignorable white
      * space. If the FEATURE_XML_ROUNDTRIP is enabled all whitespace content outside root
-     * element will always reported as IGNORABLE_WHITESPACE otherise rteporting is optional.
-     *  <br>Note: that element content may be delevered in multiple consecutive IGNORABLE_WHITESPACE events.
+     * element will always reported as IGNORABLE_WHITESPACE otherwise reporting is optional.
+     *  <br>Note: that element content may be delivered in multiple consecutive IGNORABLE_WHITESPACE events.
      * <dt>CDSECT<dd>
      * return text <em>inside</em> CDATA
      *  (ex. 'fo&lt;o' from &lt;!CDATA[fo&lt;o]]>)
@@ -1002,7 +1002,7 @@
      * </dd>
      * </dl>
      *
-     * <p><strong>NOTE:</strong> there is no gurantee that there will only one TEXT or
+     * <p><strong>NOTE:</strong> there is no guarantee that there will only one TEXT or
      * IGNORABLE_WHITESPACE event from nextToken() as parser may chose to deliver element content in
      * multiple tokens (dividing element content into chunks)
      *
@@ -1113,4 +1113,3 @@
     int nextTag() throws XmlPullParserException, IOException;
 
 }
-
diff --git a/libcore/xml/src/main/native/org_apache_harmony_xml_ExpatParser.cpp b/libcore/xml/src/main/native/org_apache_harmony_xml_ExpatParser.cpp
index 9192b1a..701dbd9 100644
--- a/libcore/xml/src/main/native/org_apache_harmony_xml_ExpatParser.cpp
+++ b/libcore/xml/src/main/native/org_apache_harmony_xml_ExpatParser.cpp
@@ -16,9 +16,10 @@
 
 #define LOG_TAG "ExpatParser"
 
+#include "JNIHelp.h"
+#include "LocalArray.h"
 #include "jni.h"
 #include "utils/Log.h"
-#include "JNIHelp.h"
 
 #include <string.h>
 #include <utils/misc.h>
@@ -1242,30 +1243,24 @@
 static jint getAttributeIndex(JNIEnv* env, jobject clazz,
         jint attributePointer, jstring uri, jstring localName) {
     const char** attributes = (const char**) attributePointer;
-    int uriLength = env->GetStringUTFLength(uri);
-
-    if (uriLength == 0) {
+    int uriByteCount = env->GetStringUTFLength(uri);
+    if (uriByteCount == 0) {
         // If there's no URI, then a local name works just like a qName.
         return getAttributeIndexForQName(
                 env, clazz, attributePointer, localName);
     }
-    int localNameLength = env->GetStringUTFLength(localName);
 
-    // Create string in the same format used by Expat: "uri|localName"
-    // TODO: do we have a guarantee that uriLength and localNameLength are small?
-    char concatenated[uriLength + localNameLength + 2];
+    // Create string in the same format used by Expat: "uri|localName\0".
+    // Note that we need byte counts to size the array but Unicode char counts
+    // for GetStringUTFRegion indexes and counts.
+    int localNameByteCount = env->GetStringUTFLength(localName);
+    LocalArray<1024> concatenated(uriByteCount + 1 + localNameByteCount + 1);
+    env->GetStringUTFRegion(uri, 0, env->GetStringLength(uri), &concatenated[0]);
+    concatenated[uriByteCount] = '|';
+    env->GetStringUTFRegion(localName, 0, env->GetStringLength(localName),
+            &concatenated[uriByteCount + 1]);
 
-    // Append uri.
-    env->GetStringUTFRegion(uri, 0, uriLength, concatenated);
-
-    // Separator.
-    concatenated[uriLength] = '|';
-
-    // Append local name.
-    env->GetStringUTFRegion(localName, 0, localNameLength,
-                            concatenated + uriLength + 1);
-
-    return findAttributeByName(attributes, concatenated);
+    return findAttributeByName(attributes, &concatenated[0]);
 }
 
 /**
diff --git a/run-core-tests.sh b/run-core-tests.sh
index 0246206..03ba43f 100755
--- a/run-core-tests.sh
+++ b/run-core-tests.sh
@@ -72,6 +72,7 @@
 cd $datadir
 exec $valgrind $exe \
      -Duser.language=en -Duser.region=US -Djava.io.tmpdir=$datadir \
+     -Djavax.net.ssl.trustStore=$base/system/etc/security/cacerts.bks \
      -Xmx512M -Xss32K \
      -Xbootclasspath:$bpath -classpath $cpath $debug_opts \
      com.google.coretests.Main "$@"
diff --git a/tests/082-inline-execute/src/Main.java b/tests/082-inline-execute/src/Main.java
index aed334b..ac2b946 100644
--- a/tests/082-inline-execute/src/Main.java
+++ b/tests/082-inline-execute/src/Main.java
@@ -26,9 +26,12 @@
 
 public class Main {
     public static void main(String args[]) {
+        int i;
         stringLengthTest();
         stringCharAtTest();
         stringIndexOfTest();
+        for (i = 0; i < 1000; i++)
+            stringCompareToTest();
     }
 
     public static void stringLengthTest() {
@@ -127,68 +130,69 @@
 
     }
 
-    public static void stringCompareTo() {
+    public static void stringCompareToTest() {
         String test = "0123456789";
         String test1 = new String("0123456789");    // different object
         String test2 = new String("0123456780");    // different value
         String offset = new String("xxx0123456789yyy");
         String sub = offset.substring(3, 13);
+        String str32 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
+        String str33 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxy";
         Object blah = new Object();
-        int i;
 
-        for (i = 0; i < 1000; i++) {
+        Assert.assertEquals(str32.compareTo(str33), -1);
+        Assert.assertEquals(str33.compareTo(str32), 1);
 
-            Assert.assertTrue(test.equals(test));
-            Assert.assertTrue(test.equals(test1));
-            Assert.assertFalse(test.equals(test2));
+        Assert.assertTrue(test.equals(test));
+        Assert.assertTrue(test.equals(test1));
+        Assert.assertFalse(test.equals(test2));
 
-            Assert.assertEquals(test.compareTo(test1), 0);
-            Assert.assertTrue(test1.compareTo(test2) > 0);
-            Assert.assertTrue(test2.compareTo(test1) < 0);
+        Assert.assertEquals(test.compareTo(test1), 0);
+        Assert.assertTrue(test1.compareTo(test2) > 0);
+        Assert.assertTrue(test2.compareTo(test1) < 0);
 
-            /* compare string with a nonzero offset, in left/right side */
-            Assert.assertEquals(test.compareTo(sub), 0);
-            Assert.assertEquals(sub.compareTo(test), 0);
-            Assert.assertTrue(test.equals(sub));
-            Assert.assertTrue(sub.equals(test));
-            /* same base, one is a substring */
-            Assert.assertFalse(offset.equals(sub));
-            Assert.assertFalse(sub.equals(offset));
-            /* wrong class */
-            Assert.assertFalse(test.equals(blah));
+        /* compare string with a nonzero offset, in left/right side */
+        Assert.assertEquals(test.compareTo(sub), 0);
+        Assert.assertEquals(sub.compareTo(test), 0);
+        Assert.assertTrue(test.equals(sub));
+        Assert.assertTrue(sub.equals(test));
+        /* same base, one is a substring */
+        Assert.assertFalse(offset.equals(sub));
+        Assert.assertFalse(sub.equals(offset));
+        /* wrong class */
+        Assert.assertFalse(test.equals(blah));
 
-            /* null ptr - throw */
-            try {
-                test.compareTo(null);
-                Assert.fail("didn't get expected npe");
-            } catch (NullPointerException npe) {
-                System.out.println("Got expected npe");
-            }
-            /* null ptr - ok */
-            Assert.assertFalse(test.equals(null));
-
-            test = test.substring(1);
-            Assert.assertTrue(test.equals("123456789"));
-            Assert.assertFalse(test.equals(test1));
-
-            test = test.substring(1);
-            Assert.assertTrue(test.equals("23456789"));
-
-            test = test.substring(1);
-            Assert.assertTrue(test.equals("3456789"));
-
-            test = test.substring(1);
-            Assert.assertTrue(test.equals("456789"));
-
-            test = test.substring(3,5);
-            Assert.assertTrue(test.equals("78"));
-
-            test = "this/is/a/path";
-            String[] strings = test.split("/");
-            Assert.assertEquals(4, strings.length);
-
-            Assert.assertEquals("this is a path", test.replaceAll("/", " "));
-            Assert.assertEquals("this is a path", test.replace("/", " "));
+        /* null ptr - throw */
+        try {
+            test.compareTo(null);
+            Assert.fail("didn't get expected npe");
+        } catch (NullPointerException npe) {
         }
+        /* null ptr - ok */
+        Assert.assertFalse(test.equals(null));
+
+        test = test.substring(1);
+        Assert.assertTrue(test.equals("123456789"));
+        Assert.assertFalse(test.equals(test1));
+
+        test = test.substring(1);
+        Assert.assertTrue(test.equals("23456789"));
+
+        test = test.substring(1);
+        Assert.assertTrue(test.equals("3456789"));
+
+        test = test.substring(1);
+        Assert.assertTrue(test.equals("456789"));
+
+        test = test.substring(3,5);
+        Assert.assertTrue(test.equals("78"));
+
+        test = "this/is/a/path";
+        String[] strings = test.split("/");
+        Assert.assertEquals(4, strings.length);
+
+        Assert.assertEquals("this is a path", test.replaceAll("/", " "));
+        Assert.assertEquals("this is a path", test.replace("/", " "));
     }
+
 }
diff --git a/vm/Init.c b/vm/Init.c
index 7f83bc5..f77dba6 100644
--- a/vm/Init.c
+++ b/vm/Init.c
@@ -114,8 +114,8 @@
     dvmFprintf(stderr, "  -Xjitop:hexopvalue[-endvalue]"
                        "[,hexopvalue[-endvalue]]*\n");
     dvmFprintf(stderr, "  -Xincludeselectedmethod\n");
-    dvmFprintf(stderr, "  -Xthreshold:decimalvalue\n");
-    dvmFprintf(stderr, "  -Xblocking\n");
+    dvmFprintf(stderr, "  -Xjitthreshold:decimalvalue\n");
+    dvmFprintf(stderr, "  -Xjitblocking\n");
     dvmFprintf(stderr, "  -Xjitmethod:signture[,signature]* "
                        "(eg Ljava/lang/String\\;replace)\n");
     dvmFprintf(stderr, "  -Xjitverbose\n");
@@ -899,10 +899,10 @@
             processXjitop(argv[i]);
         } else if (strncmp(argv[i], "-Xjitmethod", 11) == 0) {
             processXjitmethod(argv[i]);
-        } else if (strncmp(argv[i], "-Xblocking", 10) == 0) {
+        } else if (strncmp(argv[i], "-Xjitblocking", 13) == 0) {
           gDvmJit.blockingMode = true;
-        } else if (strncmp(argv[i], "-Xthreshold:", 12) == 0) {
-          gDvmJit.threshold = atoi(argv[i] + 12);
+        } else if (strncmp(argv[i], "-Xjitthreshold:", 15) == 0) {
+          gDvmJit.threshold = atoi(argv[i] + 15);
         } else if (strncmp(argv[i], "-Xincludeselectedop", 19) == 0) {
           gDvmJit.includeSelectedOp = true;
         } else if (strncmp(argv[i], "-Xincludeselectedmethod", 23) == 0) {
diff --git a/vm/Thread.c b/vm/Thread.c
index 55e27f6..71f6324 100644
--- a/vm/Thread.c
+++ b/vm/Thread.c
@@ -3322,8 +3322,16 @@
         else
             dvmPrintDebugMessage(target, "  | monitors held: <none>\n");
         while (lod != NULL) {
-            dvmPrintDebugMessage(target, "  >  %p[%d] (%s)\n",
-                lod->obj, lod->recursionCount, lod->obj->clazz->descriptor);
+            Object* obj = lod->obj;
+            if (obj->clazz == gDvm.classJavaLangClass) {
+                ClassObject* clazz = (ClassObject*) obj;
+                dvmPrintDebugMessage(target, "  >  %p[%d] (%s object for class %s)\n",
+                    obj, lod->recursionCount, obj->clazz->descriptor,
+                    clazz->descriptor);
+            } else {
+                dvmPrintDebugMessage(target, "  >  %p[%d] (%s)\n",
+                    obj, lod->recursionCount, obj->clazz->descriptor);
+            }
             lod = lod->next;
         }
     }
diff --git a/vm/compiler/Compiler.c b/vm/compiler/Compiler.c
index a44e1c3..b53ebf8 100644
--- a/vm/compiler/Compiler.c
+++ b/vm/compiler/Compiler.c
@@ -96,11 +96,13 @@
 /* Block until queue length is 0 */
 void dvmCompilerDrainQueue(void)
 {
+    int oldStatus = dvmChangeStatus(NULL, THREAD_VMWAIT);
     dvmLockMutex(&gDvmJit.compilerLock);
     while (workQueueLength() != 0 && !gDvmJit.haltCompilerThread) {
         pthread_cond_wait(&gDvmJit.compilerQueueEmpty, &gDvmJit.compilerLock);
     }
     dvmUnlockMutex(&gDvmJit.compilerLock);
+    dvmChangeStatus(NULL, oldStatus);
 }
 
 static void *compilerThreadStart(void *arg)
@@ -135,11 +137,12 @@
                 if (gDvmJit.haltCompilerThread) {
                     LOGD("Compiler shutdown in progress - discarding request");
                 } else {
-                    /* Compilation is successful */
-                    if (dvmCompilerDoWork(&work)) {
-                        dvmJitSetCodeAddr(work.pc, work.result.codeAddress,
-                                          work.result.instructionSet);
+                    /* If compilation failed, use interpret-template */
+                    if (!dvmCompilerDoWork(&work)) {
+                        work.result.codeAddress = gDvmJit.interpretTemplate;
                     }
+                    dvmJitSetCodeAddr(work.pc, work.result.codeAddress,
+                                      work.result.instructionSet);
                 }
                 free(work.info);
                 dvmLockMutex(&gDvmJit.compilerLock);
diff --git a/vm/compiler/codegen/arm/Codegen.c b/vm/compiler/codegen/arm/Codegen.c
index 1261e7d..5dea431 100644
--- a/vm/compiler/codegen/arm/Codegen.c
+++ b/vm/compiler/codegen/arm/Codegen.c
@@ -2568,6 +2568,19 @@
              */
             ClassObject *classPtr =
               (cUnit->method->clazz->pDvmDex->pResClasses[mir->dalvikInsn.vB]);
+            /*
+             * Note: It is possible that classPtr is NULL at this point,
+             * even though this instruction has been successfully interpreted.
+             * If the previous interpretation had a null source, the
+             * interpreter would not have bothered to resolve the clazz.
+             * Bail out to the interpreter in this case, and log it
+             * so that we can tell if it happens frequently.
+             */
+            if (classPtr == NULL) {
+                 LOGD("null clazz in OP_CHECK_CAST, single-stepping");
+                 genInterpSingleStep(cUnit, mir);
+                 return false;
+            }
             flushAllRegs(cUnit);   /* Send everything to home location */
             loadConstant(cUnit, r1, (int) classPtr );
             rlSrc = getSrcLoc(cUnit, mir, 0);
diff --git a/vm/compiler/codegen/arm/armv7-a/ArchVariant.c b/vm/compiler/codegen/arm/armv7-a/ArchVariant.c
index 02b9b79..a2e4175 100644
--- a/vm/compiler/codegen/arm/armv7-a/ArchVariant.c
+++ b/vm/compiler/codegen/arm/armv7-a/ArchVariant.c
@@ -323,6 +323,7 @@
     if (isDouble) {
         rlSrc1 = loadValueWide(cUnit, rlSrc1, kFPReg);
         rlSrc2 = loadValueWide(cUnit, rlSrc2, kFPReg);
+        clobberSReg(cUnit, rlDest.sRegLow);
         rlResult = evalLoc(cUnit, rlDest, kCoreReg, true);
         loadConstant(cUnit, rlResult.lowReg, defaultResult);
         newLIR2(cUnit, kThumb2Vcmpd, S2D(rlSrc1.lowReg, r1Src2.highReg),
@@ -330,6 +331,7 @@
     } else {
         rlSrc1 = loadValue(cUnit, rlSrc1, kFPReg);
         rlSrc2 = loadValue(cUnit, rlSrc2, kFPReg);
+        clobberSReg(cUnit, rlDest.sRegLow);
         rlResult = evalLoc(cUnit, rlDest, kCoreReg, true);
         loadConstant(cUnit, rlResult.lowReg, defaultResult);
         newLIR2(cUnit, kThumb2Vcmps, rlSrc1.lowReg, rlSrc2.lowReg);
diff --git a/vm/compiler/template/armv5te/TEMPLATE_STRING_COMPARETO.S b/vm/compiler/template/armv5te/TEMPLATE_STRING_COMPARETO.S
index 85b2a9f..8a07f14 100644
--- a/vm/compiler/template/armv5te/TEMPLATE_STRING_COMPARETO.S
+++ b/vm/compiler/template/armv5te/TEMPLATE_STRING_COMPARETO.S
@@ -59,7 +59,7 @@
       *   r3, r4, r7, r8, r9, r12 available for loading string data
       */
 
-    cmp   r10, #3
+    sub   r10, #3
     blt   do_remainder
 loopback_triple:
     ldrh  r3, [r2, #2]!
@@ -73,10 +73,10 @@
     subeqs  r0, r9, r12
     bxne  lr
     subs  r10, #3
-    bgt   loopback_triple
+    bge   loopback_triple
 
 do_remainder:
-    cmp   r10, #0
+    adds  r10, #3
     beq   returnDiff
 
 loopback_single:
diff --git a/vm/compiler/template/out/CompilerTemplateAsm-armv5te-vfp.S b/vm/compiler/template/out/CompilerTemplateAsm-armv5te-vfp.S
index 6604773..e04af58 100644
--- a/vm/compiler/template/out/CompilerTemplateAsm-armv5te-vfp.S
+++ b/vm/compiler/template/out/CompilerTemplateAsm-armv5te-vfp.S
@@ -1147,7 +1147,7 @@
       *   r3, r4, r7, r8, r9, r12 available for loading string data
       */
 
-    cmp   r10, #3
+    sub   r10, #3
     blt   do_remainder
 loopback_triple:
     ldrh  r3, [r2, #2]!
@@ -1161,10 +1161,10 @@
     subeqs  r0, r9, r12
     bxne  lr
     subs  r10, #3
-    bgt   loopback_triple
+    bge   loopback_triple
 
 do_remainder:
-    cmp   r10, #0
+    adds  r10, #3
     beq   returnDiff
 
 loopback_single:
diff --git a/vm/compiler/template/out/CompilerTemplateAsm-armv5te.S b/vm/compiler/template/out/CompilerTemplateAsm-armv5te.S
index cee118b..eff456a 100644
--- a/vm/compiler/template/out/CompilerTemplateAsm-armv5te.S
+++ b/vm/compiler/template/out/CompilerTemplateAsm-armv5te.S
@@ -872,7 +872,7 @@
       *   r3, r4, r7, r8, r9, r12 available for loading string data
       */
 
-    cmp   r10, #3
+    sub   r10, #3
     blt   do_remainder
 loopback_triple:
     ldrh  r3, [r2, #2]!
@@ -886,10 +886,10 @@
     subeqs  r0, r9, r12
     bxne  lr
     subs  r10, #3
-    bgt   loopback_triple
+    bge   loopback_triple
 
 do_remainder:
-    cmp   r10, #0
+    adds  r10, #3
     beq   returnDiff
 
 loopback_single:
diff --git a/vm/compiler/template/out/CompilerTemplateAsm-armv7-a.S b/vm/compiler/template/out/CompilerTemplateAsm-armv7-a.S
index aab5067..5e331ff 100644
--- a/vm/compiler/template/out/CompilerTemplateAsm-armv7-a.S
+++ b/vm/compiler/template/out/CompilerTemplateAsm-armv7-a.S
@@ -1147,7 +1147,7 @@
       *   r3, r4, r7, r8, r9, r12 available for loading string data
       */
 
-    cmp   r10, #3
+    sub   r10, #3
     blt   do_remainder
 loopback_triple:
     ldrh  r3, [r2, #2]!
@@ -1161,10 +1161,10 @@
     subeqs  r0, r9, r12
     bxne  lr
     subs  r10, #3
-    bgt   loopback_triple
+    bge   loopback_triple
 
 do_remainder:
-    cmp   r10, #0
+    adds  r10, #3
     beq   returnDiff
 
 loopback_single:
diff --git a/vm/interp/InterpDefs.h b/vm/interp/InterpDefs.h
index 41a2bb8..744033e 100644
--- a/vm/interp/InterpDefs.h
+++ b/vm/interp/InterpDefs.h
@@ -150,7 +150,7 @@
     JitState           jitState;
     void*              jitResume;
     u2*                jitResumePC;
-    const u2*          jitTraceInProgress;
+    int                jitThreshold;
 #endif
 
 #if defined(WITH_PROFILER) || defined(WITH_DEBUGGER)
diff --git a/vm/interp/Jit.c b/vm/interp/Jit.c
index d9b9caa..4c09979 100644
--- a/vm/interp/Jit.c
+++ b/vm/interp/Jit.c
@@ -348,6 +348,12 @@
     unsigned int i;
     bool res = true;  /* Assume success */
 
+#if defined(WITH_SELF_VERIFICATION)
+    // Force JIT into blocking, translate everything mode
+    gDvmJit.threshold = 1;
+    gDvmJit.blockingMode = true;
+#endif
+
     // Create the compiler thread and setup miscellaneous chores */
     res &= dvmCompilerStartup();
 
@@ -380,7 +386,7 @@
             res = false;
             goto done;
         }
-        memset(pJitProfTable,0,JIT_PROF_SIZE);
+        memset(pJitProfTable,gDvmJit.threshold,JIT_PROF_SIZE);
         for (i=0; i < gDvmJit.jitTableSize; i++) {
            pJitTable[i].u.info.chain = gDvmJit.jitTableSize;
         }
@@ -514,6 +520,32 @@
     }
 }
 
+void setTraceConstruction(JitEntry *slot, bool value)
+{
+
+    JitEntryInfoUnion oldValue;
+    JitEntryInfoUnion newValue;
+    do {
+        oldValue = slot->u;
+        newValue = oldValue;
+        newValue.info.traceConstruction = value;
+    } while (!ATOMIC_CMP_SWAP( &slot->u.infoWord,
+             oldValue.infoWord, newValue.infoWord));
+}
+
+void resetTracehead(InterpState* interpState, JitEntry *slot)
+{
+    slot->codeAddress = gDvmJit.interpretTemplate;
+    setTraceConstruction(slot, false);
+}
+
+/* Clean up any pending trace builds */
+void dvmJitAbortTraceSelect(InterpState* interpState)
+{
+    if (interpState->jitState == kJitTSelect)
+        interpState->jitState = kJitTSelectAbort;
+}
+
 /*
  * Adds to the current trace request one instruction at a time, just
  * before that instruction is interpreted.  This is the primary trace
@@ -539,6 +571,7 @@
                           || gDvm.activeProfilers
 #endif
             );
+
     /* Prepare to handle last PC and stage the current PC */
     const u2 *lastPC = interpState->lastPC;
     interpState->lastPC = pc;
@@ -625,6 +658,8 @@
         case kJitTSelectEnd:
             {
                 if (interpState->totalTraceLen == 0) {
+                    /* Bad trace - mark as untranslatable */
+                    dvmJitAbortTraceSelect(interpState);
                     switchInterp = !debugOrProfile;
                     break;
                 }
@@ -635,6 +670,7 @@
                     LOGE("Out of memory in trace selection");
                     dvmJitStopTranslationRequests();
                     interpState->jitState = kJitTSelectAbort;
+                    dvmJitAbortTraceSelect(interpState);
                     switchInterp = !debugOrProfile;
                     break;
                 }
@@ -650,7 +686,8 @@
 #endif
                 dvmCompilerWorkEnqueue(
                        interpState->currTraceHead,kWorkOrderTrace,desc);
-                interpState->jitTraceInProgress = NULL;
+                setTraceConstruction(
+                     dvmJitLookupAndAdd(interpState->currTraceHead), false);
                 if (gDvmJit.blockingMode) {
                     dvmCompilerDrainQueue();
                 }
@@ -668,6 +705,7 @@
 #if defined(SHOW_TRACE)
             LOGD("TraceGen:  trace abort");
 #endif
+            dvmJitAbortTraceSelect(interpState);
             interpState->jitState = kJitNormal;
             switchInterp = !debugOrProfile;
             break;
@@ -864,7 +902,6 @@
  * otherwise.  NOTE: may be called even when trace selection is not being
  * requested
  */
-
 bool dvmJitCheckTraceRequest(Thread* self, InterpState* interpState)
 {
     bool res = false;         /* Assume success */
@@ -873,11 +910,6 @@
      * If previous trace-building attempt failed, force it's head to be
      * interpret-only.
      */
-    if (interpState->jitTraceInProgress) {
-        JitEntry *slot = dvmJitLookupAndAdd(interpState->jitTraceInProgress);
-        slot->codeAddress = gDvmJit.interpretTemplate;
-        interpState->jitTraceInProgress = NULL;
-    }
     if (gDvmJit.pJitEntryTable != NULL) {
         /* Two-level filtering scheme */
         for (i=0; i< JIT_TRACE_THRESH_FILTER_SIZE; i++) {
@@ -894,6 +926,10 @@
             interpState->threshFilter[i] = interpState->pc;
             res = true;
         }
+
+        /* If stress mode (threshold==1), always translate */
+        res &= (gDvmJit.threshold != 1);
+
         /*
          * If the compiler is backlogged, or if a debugger or profiler is
          * active, cancel any JIT actions
@@ -919,26 +955,38 @@
                 interpState->jitState = kJitTSelectAbort;
                 LOGD("JIT: JitTable full, disabling profiling");
                 dvmJitStopTranslationRequests();
-            } else if (slot->u.info.traceRequested) {
-                /* Trace already requested - revert to interpreter */
+            } else if (slot->u.info.traceConstruction) {
+                /*
+                 * Trace already request in progress, but most likely it
+                 * aborted without cleaning up.  Assume the worst and
+                 * mark trace head as untranslatable.  If we're wrong,
+                 * the compiler thread will correct the entry when the
+                 * translation is completed.  The downside here is that
+                 * some existing translation may chain to the interpret-only
+                 * template instead of the real translation during this
+                 * window.  Performance, but not correctness, issue.
+                 */
+                interpState->jitState = kJitTSelectAbort;
+                resetTracehead(interpState, slot);
+            } else if (slot->codeAddress) {
+                 /* Nothing to do here - just return */
                 interpState->jitState = kJitTSelectAbort;
             } else {
-                /* Mark request */
-                JitEntryInfoUnion oldValue;
-                JitEntryInfoUnion newValue;
-                do {
-                    oldValue = slot->u;
-                    newValue = oldValue;
-                    newValue.info.traceRequested = true;
-                } while (!ATOMIC_CMP_SWAP( &slot->u.infoWord,
-                         oldValue.infoWord, newValue.infoWord));
+                /*
+                 * Mark request.  Note, we are not guaranteed exclusivity
+                 * here.  A window exists for another thread to be
+                 * attempting to build this same trace.  Rather than
+                 * bear the cost of locking, we'll just allow that to
+                 * happen.  The compiler thread, if it chooses, can
+                 * discard redundant requests.
+                 */
+                setTraceConstruction(slot, true);
             }
         }
         switch (interpState->jitState) {
             case kJitTSelectRequest:
                  interpState->jitState = kJitTSelect;
                  interpState->currTraceHead = interpState->pc;
-                 interpState->jitTraceInProgress = interpState->pc;
                  interpState->currTraceRun = 0;
                  interpState->totalTraceLen = 0;
                  interpState->currRunHead = interpState->pc;
diff --git a/vm/interp/Jit.h b/vm/interp/Jit.h
index a69a1f0..b093164 100644
--- a/vm/interp/Jit.h
+++ b/vm/interp/Jit.h
@@ -89,13 +89,13 @@
  */
 
 typedef struct JitEntryInfo {
-    unsigned int           traceRequested:1;   /* already requested a translation */
+    unsigned int           traceConstruction:1;   /* build underway? */
     unsigned int           isMethodEntry:1;
     unsigned int           inlineCandidate:1;
     unsigned int           profileEnabled:1;
     JitInstructionSetType  instructionSet:4;
     unsigned int           unused:8;
-    u2                     chain;              /* Index of next in chain */
+    u2                     chain;                 /* Index of next in chain */
 } JitEntryInfo;
 
 typedef union JitEntryInfoUnion {
@@ -122,6 +122,8 @@
 s8 dvmJitd2l(double d);
 s8 dvmJitf2l(float f);
 void dvmJitSetCodeAddr(const u2* dPC, void *nPC, JitInstructionSetType set);
+void dvmJitAbortTraceSelect(InterpState* interpState);
+JitEntry *dvmJitLookupAndAdd(const u2* dPC);
 
 
 #endif /*_DALVIK_INTERP_JIT*/
diff --git a/vm/mterp/Mterp.c b/vm/mterp/Mterp.c
index 053f544..dbae516 100644
--- a/vm/mterp/Mterp.c
+++ b/vm/mterp/Mterp.c
@@ -83,6 +83,7 @@
     glue->pSelfSuspendCount = &self->suspendCount;
 #if defined(WITH_JIT)
     glue->pJitProfTable = gDvmJit.pProfTable;
+    glue->jitThreshold = gDvmJit.threshold;
 #endif
 #if defined(WITH_DEBUGGER)
     glue->pDebuggerActive = &gDvm.debuggerActive;
diff --git a/vm/mterp/armv5te/footer.S b/vm/mterp/armv5te/footer.S
index e6c6cfc..317f151 100644
--- a/vm/mterp/armv5te/footer.S
+++ b/vm/mterp/armv5te/footer.S
@@ -209,7 +209,7 @@
  * is already a native translation in place (and, if so,
  * jump to it now).
  */
-    mov     r1,#255
+    GET_JIT_THRESHOLD(r1)
     strb    r1,[r0,r3,lsr #23] @ reset counter
     EXPORT_PC()
     mov     r0,rPC
diff --git a/vm/mterp/armv5te/header.S b/vm/mterp/armv5te/header.S
index e129b15..78b2282 100644
--- a/vm/mterp/armv5te/header.S
+++ b/vm/mterp/armv5te/header.S
@@ -180,6 +180,7 @@
 #if defined(WITH_JIT)
 #define GET_JIT_ENABLED(_reg)       ldr     _reg,[rGLUE,#offGlue_jitEnabled]
 #define GET_JIT_PROF_TABLE(_reg)    ldr     _reg,[rGLUE,#offGlue_pJitProfTable]
+#define GET_JIT_THRESHOLD(_reg)     ldr     _reg,[rGLUE,#offGlue_jitThreshold]
 #endif
 
 /*
diff --git a/vm/mterp/c/gotoTargets.c b/vm/mterp/c/gotoTargets.c
index 67b3299..1bf188f 100644
--- a/vm/mterp/c/gotoTargets.c
+++ b/vm/mterp/c/gotoTargets.c
@@ -532,6 +532,10 @@
         if (dvmIsBreakFrame(fp)) {
             /* bail without popping the method frame from stack */
             LOGVV("+++ returned into break frame\n");
+#if defined(WITH_JIT)
+            /* Let the Jit know the return is terminating normally */
+            CHECK_JIT();
+#endif
             GOTO_bail();
         }
 
@@ -578,9 +582,7 @@
 
 #if defined(WITH_JIT)
         // Something threw during trace selection - abort the current trace
-        if (interpState->jitState == kJitTSelect) {
-            interpState->jitState = kJitTSelectEnd;
-        }
+        dvmJitAbortTraceSelect(interpState);
 #endif
         /*
          * We save off the exception and clear the exception status.  While
@@ -892,6 +894,11 @@
             ILOGD("> native <-- %s.%s %s", methodToCall->clazz->descriptor,
                 methodToCall->name, methodToCall->shorty);
 
+#if defined(WITH_JIT)
+            /* Allow the Jit to end any pending trace building */
+            CHECK_JIT();
+#endif
+
             /*
              * Jump through native call bridge.  Because we leave no
              * space for locals on native calls, "newFp" points directly
diff --git a/vm/mterp/common/asm-constants.h b/vm/mterp/common/asm-constants.h
index baf6af7..f982793 100644
--- a/vm/mterp/common/asm-constants.h
+++ b/vm/mterp/common/asm-constants.h
@@ -106,6 +106,7 @@
 MTERP_OFFSET(offGlue_jitState,          MterpGlue, jitState, 60)
 MTERP_OFFSET(offGlue_jitResume,         MterpGlue, jitResume, 64)
 MTERP_OFFSET(offGlue_jitResumePC,       MterpGlue, jitResumePC, 68)
+MTERP_OFFSET(offGlue_jitThreshold,      MterpGlue, jitThreshold, 72)
 #endif
 #elif defined(WITH_DEBUGGER)
 MTERP_OFFSET(offGlue_pDebuggerActive,   MterpGlue, pDebuggerActive, 40)
@@ -115,6 +116,7 @@
 MTERP_OFFSET(offGlue_jitState,          MterpGlue, jitState, 56)
 MTERP_OFFSET(offGlue_jitResume,         MterpGlue, jitResume, 60)
 MTERP_OFFSET(offGlue_jitResumePC,       MterpGlue, jitResumePC, 64)
+MTERP_OFFSET(offGlue_jitThreshold,      MterpGlue, jitThreshold, 68)
 #endif
 #elif defined(WITH_PROFILER)
 MTERP_OFFSET(offGlue_pActiveProfilers,  MterpGlue, pActiveProfilers, 40)
@@ -124,6 +126,7 @@
 MTERP_OFFSET(offGlue_jitState,          MterpGlue, jitState, 56)
 MTERP_OFFSET(offGlue_jitResume,         MterpGlue, jitResume, 60)
 MTERP_OFFSET(offGlue_jitResumePC,       MterpGlue, jitResumePC, 64)
+MTERP_OFFSET(offGlue_jitThreshold,      MterpGlue, jitThreshold, 68)
 #endif
 #else
 MTERP_OFFSET(offGlue_entryPoint,        MterpGlue, entryPoint, 40)
@@ -132,6 +135,7 @@
 MTERP_OFFSET(offGlue_jitState,          MterpGlue, jitState, 52)
 MTERP_OFFSET(offGlue_jitResume,         MterpGlue, jitResume, 56)
 MTERP_OFFSET(offGlue_jitResumePC,       MterpGlue, jitResumePC, 60)
+MTERP_OFFSET(offGlue_jitThreshold,      MterpGlue, jitThreshold, 64)
 #endif
 #endif
 /* make sure all JValue union members are stored at the same offset */
diff --git a/vm/mterp/out/InterpAsm-armv4t.S b/vm/mterp/out/InterpAsm-armv4t.S
index f1729eb..56d0a26 100644
--- a/vm/mterp/out/InterpAsm-armv4t.S
+++ b/vm/mterp/out/InterpAsm-armv4t.S
@@ -187,6 +187,7 @@
 #if defined(WITH_JIT)
 #define GET_JIT_ENABLED(_reg)       ldr     _reg,[rGLUE,#offGlue_jitEnabled]
 #define GET_JIT_PROF_TABLE(_reg)    ldr     _reg,[rGLUE,#offGlue_pJitProfTable]
+#define GET_JIT_THRESHOLD(_reg)     ldr     _reg,[rGLUE,#offGlue_jitThreshold]
 #endif
 
 /*
@@ -9681,7 +9682,7 @@
  * is already a native translation in place (and, if so,
  * jump to it now).
  */
-    mov     r1,#255
+    GET_JIT_THRESHOLD(r1)
     strb    r1,[r0,r3,lsr #23] @ reset counter
     EXPORT_PC()
     mov     r0,rPC
diff --git a/vm/mterp/out/InterpAsm-armv5te-vfp.S b/vm/mterp/out/InterpAsm-armv5te-vfp.S
index 5cf8cca..c7926f6 100644
--- a/vm/mterp/out/InterpAsm-armv5te-vfp.S
+++ b/vm/mterp/out/InterpAsm-armv5te-vfp.S
@@ -187,6 +187,7 @@
 #if defined(WITH_JIT)
 #define GET_JIT_ENABLED(_reg)       ldr     _reg,[rGLUE,#offGlue_jitEnabled]
 #define GET_JIT_PROF_TABLE(_reg)    ldr     _reg,[rGLUE,#offGlue_pJitProfTable]
+#define GET_JIT_THRESHOLD(_reg)     ldr     _reg,[rGLUE,#offGlue_jitThreshold]
 #endif
 
 /*
@@ -9199,7 +9200,7 @@
  * is already a native translation in place (and, if so,
  * jump to it now).
  */
-    mov     r1,#255
+    GET_JIT_THRESHOLD(r1)
     strb    r1,[r0,r3,lsr #23] @ reset counter
     EXPORT_PC()
     mov     r0,rPC
diff --git a/vm/mterp/out/InterpAsm-armv5te.S b/vm/mterp/out/InterpAsm-armv5te.S
index 5e1ed1c..3c5c496 100644
--- a/vm/mterp/out/InterpAsm-armv5te.S
+++ b/vm/mterp/out/InterpAsm-armv5te.S
@@ -187,6 +187,7 @@
 #if defined(WITH_JIT)
 #define GET_JIT_ENABLED(_reg)       ldr     _reg,[rGLUE,#offGlue_jitEnabled]
 #define GET_JIT_PROF_TABLE(_reg)    ldr     _reg,[rGLUE,#offGlue_pJitProfTable]
+#define GET_JIT_THRESHOLD(_reg)     ldr     _reg,[rGLUE,#offGlue_jitThreshold]
 #endif
 
 /*
@@ -9675,7 +9676,7 @@
  * is already a native translation in place (and, if so,
  * jump to it now).
  */
-    mov     r1,#255
+    GET_JIT_THRESHOLD(r1)
     strb    r1,[r0,r3,lsr #23] @ reset counter
     EXPORT_PC()
     mov     r0,rPC
diff --git a/vm/mterp/out/InterpAsm-armv7-a.S b/vm/mterp/out/InterpAsm-armv7-a.S
index 7af0a79..aaf85d9 100644
--- a/vm/mterp/out/InterpAsm-armv7-a.S
+++ b/vm/mterp/out/InterpAsm-armv7-a.S
@@ -187,6 +187,7 @@
 #if defined(WITH_JIT)
 #define GET_JIT_ENABLED(_reg)       ldr     _reg,[rGLUE,#offGlue_jitEnabled]
 #define GET_JIT_PROF_TABLE(_reg)    ldr     _reg,[rGLUE,#offGlue_pJitProfTable]
+#define GET_JIT_THRESHOLD(_reg)     ldr     _reg,[rGLUE,#offGlue_jitThreshold]
 #endif
 
 /*
@@ -9135,7 +9136,7 @@
  * is already a native translation in place (and, if so,
  * jump to it now).
  */
-    mov     r1,#255
+    GET_JIT_THRESHOLD(r1)
     strb    r1,[r0,r3,lsr #23] @ reset counter
     EXPORT_PC()
     mov     r0,rPC
diff --git a/vm/mterp/out/InterpC-allstubs.c b/vm/mterp/out/InterpC-allstubs.c
index 1d31227..04d7c32 100644
--- a/vm/mterp/out/InterpC-allstubs.c
+++ b/vm/mterp/out/InterpC-allstubs.c
@@ -3565,6 +3565,10 @@
         if (dvmIsBreakFrame(fp)) {
             /* bail without popping the method frame from stack */
             LOGVV("+++ returned into break frame\n");
+#if defined(WITH_JIT)
+            /* Let the Jit know the return is terminating normally */
+            CHECK_JIT();
+#endif
             GOTO_bail();
         }
 
@@ -3611,9 +3615,7 @@
 
 #if defined(WITH_JIT)
         // Something threw during trace selection - abort the current trace
-        if (interpState->jitState == kJitTSelect) {
-            interpState->jitState = kJitTSelectEnd;
-        }
+        dvmJitAbortTraceSelect(interpState);
 #endif
         /*
          * We save off the exception and clear the exception status.  While
@@ -3925,6 +3927,11 @@
             ILOGD("> native <-- %s.%s %s", methodToCall->clazz->descriptor,
                 methodToCall->name, methodToCall->shorty);
 
+#if defined(WITH_JIT)
+            /* Allow the Jit to end any pending trace building */
+            CHECK_JIT();
+#endif
+
             /*
              * Jump through native call bridge.  Because we leave no
              * space for locals on native calls, "newFp" points directly
diff --git a/vm/mterp/out/InterpC-portdbg.c b/vm/mterp/out/InterpC-portdbg.c
index 03fe00e..4d15b45 100644
--- a/vm/mterp/out/InterpC-portdbg.c
+++ b/vm/mterp/out/InterpC-portdbg.c
@@ -3863,6 +3863,10 @@
         if (dvmIsBreakFrame(fp)) {
             /* bail without popping the method frame from stack */
             LOGVV("+++ returned into break frame\n");
+#if defined(WITH_JIT)
+            /* Let the Jit know the return is terminating normally */
+            CHECK_JIT();
+#endif
             GOTO_bail();
         }
 
@@ -3909,9 +3913,7 @@
 
 #if defined(WITH_JIT)
         // Something threw during trace selection - abort the current trace
-        if (interpState->jitState == kJitTSelect) {
-            interpState->jitState = kJitTSelectEnd;
-        }
+        dvmJitAbortTraceSelect(interpState);
 #endif
         /*
          * We save off the exception and clear the exception status.  While
@@ -4223,6 +4225,11 @@
             ILOGD("> native <-- %s.%s %s", methodToCall->clazz->descriptor,
                 methodToCall->name, methodToCall->shorty);
 
+#if defined(WITH_JIT)
+            /* Allow the Jit to end any pending trace building */
+            CHECK_JIT();
+#endif
+
             /*
              * Jump through native call bridge.  Because we leave no
              * space for locals on native calls, "newFp" points directly
diff --git a/vm/mterp/out/InterpC-portstd.c b/vm/mterp/out/InterpC-portstd.c
index a092da0..6ea6a56 100644
--- a/vm/mterp/out/InterpC-portstd.c
+++ b/vm/mterp/out/InterpC-portstd.c
@@ -3579,6 +3579,10 @@
         if (dvmIsBreakFrame(fp)) {
             /* bail without popping the method frame from stack */
             LOGVV("+++ returned into break frame\n");
+#if defined(WITH_JIT)
+            /* Let the Jit know the return is terminating normally */
+            CHECK_JIT();
+#endif
             GOTO_bail();
         }
 
@@ -3625,9 +3629,7 @@
 
 #if defined(WITH_JIT)
         // Something threw during trace selection - abort the current trace
-        if (interpState->jitState == kJitTSelect) {
-            interpState->jitState = kJitTSelectEnd;
-        }
+        dvmJitAbortTraceSelect(interpState);
 #endif
         /*
          * We save off the exception and clear the exception status.  While
@@ -3939,6 +3941,11 @@
             ILOGD("> native <-- %s.%s %s", methodToCall->clazz->descriptor,
                 methodToCall->name, methodToCall->shorty);
 
+#if defined(WITH_JIT)
+            /* Allow the Jit to end any pending trace building */
+            CHECK_JIT();
+#endif
+
             /*
              * Jump through native call bridge.  Because we leave no
              * space for locals on native calls, "newFp" points directly
diff --git a/vm/mterp/out/InterpC-x86.c b/vm/mterp/out/InterpC-x86.c
index fa2dfa8..ed42355 100644
--- a/vm/mterp/out/InterpC-x86.c
+++ b/vm/mterp/out/InterpC-x86.c
@@ -1720,6 +1720,10 @@
         if (dvmIsBreakFrame(fp)) {
             /* bail without popping the method frame from stack */
             LOGVV("+++ returned into break frame\n");
+#if defined(WITH_JIT)
+            /* Let the Jit know the return is terminating normally */
+            CHECK_JIT();
+#endif
             GOTO_bail();
         }
 
@@ -1766,9 +1770,7 @@
 
 #if defined(WITH_JIT)
         // Something threw during trace selection - abort the current trace
-        if (interpState->jitState == kJitTSelect) {
-            interpState->jitState = kJitTSelectEnd;
-        }
+        dvmJitAbortTraceSelect(interpState);
 #endif
         /*
          * We save off the exception and clear the exception status.  While
@@ -2080,6 +2082,11 @@
             ILOGD("> native <-- %s.%s %s", methodToCall->clazz->descriptor,
                 methodToCall->name, methodToCall->shorty);
 
+#if defined(WITH_JIT)
+            /* Allow the Jit to end any pending trace building */
+            CHECK_JIT();
+#endif
+
             /*
              * Jump through native call bridge.  Because we leave no
              * space for locals on native calls, "newFp" points directly
diff --git a/vm/oo/Object.h b/vm/oo/Object.h
index e467fe9..788ec13 100644
--- a/vm/oo/Object.h
+++ b/vm/oo/Object.h
@@ -288,7 +288,7 @@
  *
  * We don't currently store the size of each element.  Usually it's implied
  * by the instruction.  If necessary, the width can be derived from
- * the first char of obj->clazz->name.
+ * the first char of obj->clazz->descriptor.
  */
 struct ArrayObject {
     Object          obj;                /* MUST be first item */