Undo dex2dex compilation before invoking LoadHook

We need to undo any dex_to_dex compilation that might have taken place
before passing a dex file to any registered ClassFileLoadHooks to
ensure that no internal opcodes are present in any methods.

Test: ./test.py --host -j40
Bug: 36653594

Change-Id: Ia42c77312e685d69f6b3ea764fad01710b10ab45
diff --git a/runtime/openjdkjvmti/ti_class_definition.h b/runtime/openjdkjvmti/ti_class_definition.h
index 9ca1c07..7a2e922 100644
--- a/runtime/openjdkjvmti/ti_class_definition.h
+++ b/runtime/openjdkjvmti/ti_class_definition.h
@@ -47,6 +47,7 @@
   jobject protection_domain;
   jint dex_len;
   JvmtiUniquePtr<unsigned char> dex_data;
+  JvmtiUniquePtr<unsigned char> original_dex_file_memory;
   art::ArraySlice<const unsigned char> original_dex_file;
 
   ArtClassDefinition()
@@ -56,8 +57,9 @@
         protection_domain(nullptr),
         dex_len(0),
         dex_data(nullptr),
+        original_dex_file_memory(nullptr),
         original_dex_file(),
-        modified(false) {}
+        redefined(false) {}
 
   ArtClassDefinition(ArtClassDefinition&& o) = default;
 
@@ -65,20 +67,27 @@
     if (new_dex_data == nullptr) {
       return;
     } else if (new_dex_data != dex_data.get() || new_dex_len != dex_len) {
-      SetModified();
       dex_len = new_dex_len;
       dex_data = MakeJvmtiUniquePtr(env, new_dex_data);
     }
   }
 
-  void SetModified() {
-    modified = true;
+  void SetRedefined() {
+    redefined = true;
   }
 
-  bool IsModified(art::Thread* self) const REQUIRES_SHARED(art::Locks::mutator_lock_);
+  art::ArraySlice<const unsigned char> GetNewOriginalDexFile() const {
+    if (redefined) {
+      return original_dex_file;
+    } else {
+      return art::ArraySlice<const unsigned char>();
+    }
+  }
+
+  bool IsModified() const;
 
  private:
-  bool modified;
+  bool redefined;
 };
 
 }  // namespace openjdkjvmti