Specify `-Dsun.zip.disableMemoryMapping=true` for Buck's own tests.

Summary:
This adds `-Dsun.zip.disableMemoryMapping=true` when Buck runs its
own tests, both via Ant and via Buck.
See the detailed comment in `DEFS` for details about why this is
necessary.
diff --git a/DEFS b/DEFS
index 1d1c357..792f4a8 100644
--- a/DEFS
+++ b/DEFS
@@ -46,11 +46,39 @@
     resources=resources,
     source=source,
     target=target,
-    # Add -XX:-UseSplitVerifier by default to work around:
-    # http://arihantwin.blogspot.com/2012/08/getting-error-illegal-local-variable.html
-    vm_args=['-XX:-UseSplitVerifier'] + vm_args,
+    vm_args=[
+      # Add -XX:-UseSplitVerifier by default to work around:
+      # http://arihantwin.blogspot.com/2012/08/getting-error-illegal-local-variable.html
+      '-XX:-UseSplitVerifier',
+
+      # Add -Dsun.zip.disableMemoryMapping=true to work around a JDK issue
+      # related to modifying JAR/ZIP files that have been loaded into memory:
+      #
+      # http://bugs.sun.com/view_bug.do?bug_id=7129299
+      #
+      # This has been observed to cause a problem in integration tests such as
+      # CachedTestIntegrationTest where `buck build //:test` is run repeatedly
+      # such that a corresponding `test.jar` file is overwritten several times.
+      # The CompiledClassFileFinder in JavaTestRule creates a java.util.zip.ZipFile
+      # to enumerate the zip entries in order to find the set of .class files
+      # in `test.jar`. This interleaving of reads and writes appears to match
+      # the conditions to trigger the issue reported on bugs.sun.com.
+      #
+      # Currently, we do not set this flag in bin/buck_common, as Buck does not
+      # normally modify the contents of buck-out after they are loaded into
+      # memory. However, we may need to use this flag when running buckd where
+      # references to zip files may be long-lived.
+      #
+      # Finally, note that when you specify this flag,
+      # `System.getProperty("sun.zip.disableMemoryMapping")` will return `null`
+      # even though you have specified the flag correctly. Apparently sun.misc.VM
+      # (http://www.docjar.com/html/api/sun/misc/VM.java.html) saves the property
+      # internally, but removes it from the set of system properties that are
+      # publicly accessible.
+      '-Dsun.zip.disableMemoryMapping=true',
+    ] + vm_args,
     source_under_test=source_under_test,
     contacts=contacts,
     deps=deps,
     visibility=visibility,
-    )
+  )
diff --git a/build.xml b/build.xml
index a8748ff..4481f50 100644
--- a/build.xml
+++ b/build.xml
@@ -188,6 +188,9 @@
       <sysproperty key="buck.path_to_emma_jar" value="${buck.path_to_emma_jar}" />
       <sysproperty key="buck.path_to_buck_py" value="${buck.path_to_buck_py}" />
 
+      <!-- See DEFS for details on why this property is needed. -->
+      <sysproperty key="sun.zip.disableMemoryMapping" value="true" />
+
       <formatter type="plain" usefile="false" />
 
       <batchtest fork="yes">