Remove DVM_LOCK_INIT and DVM_LOCK_INITIAL_THIN_VALUE.

The original implementation for thin locks used a magic non-zero value
to encode the initial thin lock state.  This magic value was kept
around in DVM_LOCK_INITIAL_THIN_VALUE and stored into the lock word of
newly allocated objects.  A later revision to the thin locking code
made the initial thin lock value be 0.  That change eliminated the
requirement that lock words be explicitly initialized as the allocator
always returns zero-filled memory.

Change-Id: I34e0b43b4c4db0f45cf7cf524e15d4a6096c1365
diff --git a/vm/Sync.cpp b/vm/Sync.cpp
index 6f0a50f..ef3524a 100644
--- a/vm/Sync.cpp
+++ b/vm/Sync.cpp
@@ -1281,10 +1281,9 @@
              * If the lock is thin assume it is unowned.  We simulate
              * an acquire, update, and release with a single CAS.
              */
-            lock = DVM_LOCK_INITIAL_THIN_VALUE;
-            lock |= (LW_HASH_STATE_HASHED << LW_HASH_STATE_SHIFT);
+            lock = (LW_HASH_STATE_HASHED << LW_HASH_STATE_SHIFT);
             if (android_atomic_acquire_cas(
-                                (int32_t)DVM_LOCK_INITIAL_THIN_VALUE,
+                                0,
                                 (int32_t)lock,
                                 (int32_t *)lw) == 0) {
                 /*
diff --git a/vm/Sync.h b/vm/Sync.h
index a039483..9f4592d 100644
--- a/vm/Sync.h
+++ b/vm/Sync.h
@@ -73,15 +73,6 @@
 typedef struct Monitor Monitor;
 
 /*
- * Initialize a Lock to the proper starting value.
- * This is necessary for thin locking.
- */
-#define DVM_LOCK_INITIAL_THIN_VALUE (0)
-
-#define DVM_LOCK_INIT(lock) \
-    do { *(lock) = DVM_LOCK_INITIAL_THIN_VALUE; } while (0)
-
-/*
  * Returns true if the lock has been fattened.
  */
 #define IS_LOCK_FAT(lock)   (LW_SHAPE(*(lock)) == LW_SHAPE_FAT)
diff --git a/vm/Thread.cpp b/vm/Thread.cpp
index 7b8f0a3..9f8896b 100644
--- a/vm/Thread.cpp
+++ b/vm/Thread.cpp
@@ -1110,7 +1110,6 @@
     thread->threadId = num + 1;
 
     assert(thread->threadId != 0);
-    assert(thread->threadId != DVM_LOCK_INITIAL_THIN_VALUE);
 }
 
 /*
diff --git a/vm/alloc/Alloc.cpp b/vm/alloc/Alloc.cpp
index 1529510..31df25d 100644
--- a/vm/alloc/Alloc.cpp
+++ b/vm/alloc/Alloc.cpp
@@ -224,12 +224,8 @@
  */
 Object* dvmCloneObject(Object* obj, int flags)
 {
-    ClassObject* clazz;
-    Object* copy;
-    size_t size;
-
     assert(dvmIsValidObject(obj));
-    clazz = obj->clazz;
+    ClassObject* clazz = obj->clazz;
 
     /* Class.java shouldn't let us get here (java.lang.Class is final
      * and does not implement Clonable), but make extra sure.
@@ -237,20 +233,21 @@
      */
     assert(!dvmIsTheClassClass(clazz));
 
+    size_t size;
     if (IS_CLASS_FLAG_SET(clazz, CLASS_ISARRAY)) {
         size = dvmArrayObjectSize((ArrayObject *)obj);
     } else {
         size = clazz->objectSize;
     }
 
-    copy = (Object*)dvmMalloc(size, flags);
+    Object* copy = (Object*)dvmMalloc(size, flags);
     if (copy == NULL)
         return NULL;
 
-    /* We assume that memcpy will copy obj by words. */
-    memcpy(copy, obj, size);
-    DVM_LOCK_INIT(&copy->lock);
-    dvmWriteBarrierObject(copy);
+    DVM_OBJECT_INIT(copy, clazz);
+    size_t offset = sizeof(Object);
+    /* Copy instance data.  We assume memcpy copies by words. */
+    memcpy((char*)copy + offset, (char*)obj + offset, size - offset);
 
     /* Mark the clone as finalizable if appropriate. */
     if (IS_CLASS_FLAG_SET(clazz, CLASS_ISFINALIZABLE)) {
diff --git a/vm/oo/Object.h b/vm/oo/Object.h
index ac7eb74..eed642a 100644
--- a/vm/oo/Object.h
+++ b/vm/oo/Object.h
@@ -236,12 +236,8 @@
  * Properly initialize an Object.
  * void DVM_OBJECT_INIT(Object *obj, ClassObject *clazz_)
  */
-#define DVM_OBJECT_INIT(obj, clazz_)                                    \
-    do {                                                                \
-        dvmSetFieldObject((Object *)obj, offsetof(Object, clazz),       \
-                          (Object *)clazz_);                            \
-        DVM_LOCK_INIT(&(obj)->lock);                                    \
-    } while (0)
+#define DVM_OBJECT_INIT(obj, clazz_) \
+    dvmSetFieldObject((Object *)obj, offsetof(Object, clazz), (Object *)clazz_)
 
 /*
  * Data objects have an Object header followed by their instance data.