diff options
author | 2017-03-24 08:55:08 +0000 | |
---|---|---|
committer | 2017-03-24 08:55:08 +0000 | |
commit | a7c04c4fe6623985ba2d0cca942d5e1e584f4358 (patch) | |
tree | ede1a98db77cfb0a05e3d445b7e1f7aed3d242d3 | |
parent | 9556cb2bfc6788656d53a9ddb2159ca2040f6e38 (diff) |
Revert "Make original dex file be more deduplicated"
Bug: 31455788
This reverts commit 9556cb2bfc6788656d53a9ddb2159ca2040f6e38.
Change-Id: If22f2bd9d1b788c2a784dbe0e7f0c2304d8e4a59
-rw-r--r-- | runtime/class_linker_test.cc | 2 | ||||
-rw-r--r-- | runtime/mirror/class_ext.cc | 4 | ||||
-rw-r--r-- | runtime/mirror/class_ext.h | 8 | ||||
-rw-r--r-- | runtime/openjdkjvmti/ti_class.cc | 2 | ||||
-rw-r--r-- | runtime/openjdkjvmti/ti_redefine.cc | 43 | ||||
-rw-r--r-- | runtime/openjdkjvmti/ti_redefine.h | 4 | ||||
-rw-r--r-- | runtime/openjdkjvmti/transform.cc | 25 | ||||
-rw-r--r-- | test/981-dedup-original-dex/expected.txt | 0 | ||||
-rw-r--r-- | test/981-dedup-original-dex/info.txt | 4 | ||||
-rwxr-xr-x | test/981-dedup-original-dex/run | 17 | ||||
-rw-r--r-- | test/981-dedup-original-dex/src/Main.java | 139 | ||||
-rw-r--r-- | test/981-dedup-original-dex/src/Transform.java | 21 | ||||
-rw-r--r-- | test/981-dedup-original-dex/src/Transform2.java | 21 | ||||
-rw-r--r-- | test/ti-agent/common_load.cc | 1 |
14 files changed, 40 insertions, 251 deletions
diff --git a/runtime/class_linker_test.cc b/runtime/class_linker_test.cc index b421810113..9f04e598eb 100644 --- a/runtime/class_linker_test.cc +++ b/runtime/class_linker_test.cc @@ -618,7 +618,7 @@ struct ClassExtOffsets : public CheckOffsets<mirror::ClassExt> { ClassExtOffsets() : CheckOffsets<mirror::ClassExt>(false, "Ldalvik/system/ClassExt;") { addOffset(OFFSETOF_MEMBER(mirror::ClassExt, obsolete_dex_caches_), "obsoleteDexCaches"); addOffset(OFFSETOF_MEMBER(mirror::ClassExt, obsolete_methods_), "obsoleteMethods"); - addOffset(OFFSETOF_MEMBER(mirror::ClassExt, original_dex_file_), "originalDexFile"); + addOffset(OFFSETOF_MEMBER(mirror::ClassExt, original_dex_file_bytes_), "originalDexFile"); addOffset(OFFSETOF_MEMBER(mirror::ClassExt, verify_error_), "verifyError"); } }; diff --git a/runtime/mirror/class_ext.cc b/runtime/mirror/class_ext.cc index 94e4b88f6c..5dc3aca094 100644 --- a/runtime/mirror/class_ext.cc +++ b/runtime/mirror/class_ext.cc @@ -117,9 +117,9 @@ void ClassExt::SetVerifyError(ObjPtr<Object> err) { } } -void ClassExt::SetOriginalDexFile(ObjPtr<Object> bytes) { +void ClassExt::SetOriginalDexFileBytes(ObjPtr<ByteArray> bytes) { DCHECK(!Runtime::Current()->IsActiveTransaction()); - SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ClassExt, original_dex_file_), bytes); + SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ClassExt, original_dex_file_bytes_), bytes); } void ClassExt::SetClass(ObjPtr<Class> dalvik_system_ClassExt) { diff --git a/runtime/mirror/class_ext.h b/runtime/mirror/class_ext.h index 708665d46b..fac955a45e 100644 --- a/runtime/mirror/class_ext.h +++ b/runtime/mirror/class_ext.h @@ -60,11 +60,11 @@ class MANAGED ClassExt : public Object { OFFSET_OF_OBJECT_MEMBER(ClassExt, obsolete_methods_)); } - Object* GetOriginalDexFile() REQUIRES_SHARED(Locks::mutator_lock_) { - return GetFieldObject<Object>(OFFSET_OF_OBJECT_MEMBER(ClassExt, original_dex_file_)); + ByteArray* GetOriginalDexFileBytes() REQUIRES_SHARED(Locks::mutator_lock_) { + return GetFieldObject<ByteArray>(OFFSET_OF_OBJECT_MEMBER(ClassExt, original_dex_file_bytes_)); } - void SetOriginalDexFile(ObjPtr<Object> bytes) REQUIRES_SHARED(Locks::mutator_lock_); + void SetOriginalDexFileBytes(ObjPtr<ByteArray> bytes) REQUIRES_SHARED(Locks::mutator_lock_); void SetObsoleteArrays(ObjPtr<PointerArray> methods, ObjPtr<ObjectArray<DexCache>> dex_caches) REQUIRES_SHARED(Locks::mutator_lock_); @@ -89,7 +89,7 @@ class MANAGED ClassExt : public Object { HeapReference<PointerArray> obsolete_methods_; - HeapReference<Object> original_dex_file_; + HeapReference<ByteArray> original_dex_file_bytes_; // The saved verification error of this class. HeapReference<Object> verify_error_; diff --git a/runtime/openjdkjvmti/ti_class.cc b/runtime/openjdkjvmti/ti_class.cc index 38fd1d4af3..2d1b25ed26 100644 --- a/runtime/openjdkjvmti/ti_class.cc +++ b/runtime/openjdkjvmti/ti_class.cc @@ -259,7 +259,7 @@ struct ClassCallback : public art::ClassLoadCallback { } // Actually set the ClassExt's original bytes once we have actually succeeded. - ext->SetOriginalDexFile(arr.Get()); + ext->SetOriginalDexFileBytes(arr.Get()); // Set the return values *final_class_def = &dex_file->GetClassDef(0); *final_dex_file = dex_file.release(); diff --git a/runtime/openjdkjvmti/ti_redefine.cc b/runtime/openjdkjvmti/ti_redefine.cc index 7faddfb0f9..9c1d6ef0a5 100644 --- a/runtime/openjdkjvmti/ti_redefine.cc +++ b/runtime/openjdkjvmti/ti_redefine.cc @@ -469,7 +469,7 @@ void Redefiner::RecordFailure(jvmtiError result, result_ = result; } -art::mirror::Object* Redefiner::ClassRedefinition::AllocateOrGetOriginalDexFile() { +art::mirror::ByteArray* Redefiner::ClassRedefinition::AllocateOrGetOriginalDexFileBytes() { // If we have been specifically given a new set of bytes use that if (original_dex_file_.size() != 0) { return art::mirror::ByteArray::AllocateAndFill( @@ -481,21 +481,24 @@ art::mirror::Object* Redefiner::ClassRedefinition::AllocateOrGetOriginalDexFile( // See if we already have one set. art::ObjPtr<art::mirror::ClassExt> ext(GetMirrorClass()->GetExtData()); if (!ext.IsNull()) { - art::ObjPtr<art::mirror::Object> old_original_dex_file(ext->GetOriginalDexFile()); - if (!old_original_dex_file.IsNull()) { + art::ObjPtr<art::mirror::ByteArray> old_original_bytes(ext->GetOriginalDexFileBytes()); + if (!old_original_bytes.IsNull()) { // We do. Use it. - return old_original_dex_file.Ptr(); + return old_original_bytes.Ptr(); } } - // return the current dex_cache which has the dex file in it. - art::ObjPtr<art::mirror::DexCache> current_dex_cache(GetMirrorClass()->GetDexCache()); + // Copy the current dex_file + const art::DexFile& current_dex_file = GetMirrorClass()->GetDexFile(); // TODO Handle this or make it so it cannot happen. - if (current_dex_cache->GetDexFile()->NumClassDefs() != 1) { + if (current_dex_file.NumClassDefs() != 1) { LOG(WARNING) << "Current dex file has more than one class in it. Calling RetransformClasses " << "on this class might fail if no transformations are applied to it!"; } - return current_dex_cache.Ptr(); + return art::mirror::ByteArray::AllocateAndFill( + driver_->self_, + reinterpret_cast<const signed char*>(current_dex_file.Begin()), + current_dex_file.Size()); } struct CallbackCtx { @@ -844,9 +847,9 @@ class RedefinitionDataHolder { return art::down_cast<art::mirror::Class*>(GetSlot(klass_index, kSlotMirrorClass)); } - art::mirror::Object* GetOriginalDexFile(jint klass_index) const + art::mirror::ByteArray* GetOriginalDexFileBytes(jint klass_index) const REQUIRES_SHARED(art::Locks::mutator_lock_) { - return art::down_cast<art::mirror::Object*>(GetSlot(klass_index, kSlotOrigDexFile)); + return art::down_cast<art::mirror::ByteArray*>(GetSlot(klass_index, kSlotOrigDexFile)); } void SetSourceClassLoader(jint klass_index, art::mirror::ClassLoader* loader) @@ -869,7 +872,7 @@ class RedefinitionDataHolder { REQUIRES_SHARED(art::Locks::mutator_lock_) { SetSlot(klass_index, kSlotMirrorClass, klass); } - void SetOriginalDexFile(jint klass_index, art::mirror::Object* bytes) + void SetOriginalDexFileBytes(jint klass_index, art::mirror::ByteArray* bytes) REQUIRES_SHARED(art::Locks::mutator_lock_) { SetSlot(klass_index, kSlotOrigDexFile, bytes); } @@ -982,9 +985,9 @@ class RedefinitionDataIter { art::mirror::Class* GetMirrorClass() const REQUIRES_SHARED(art::Locks::mutator_lock_) { return holder_.GetMirrorClass(idx_); } - art::mirror::Object* GetOriginalDexFile() const + art::mirror::ByteArray* GetOriginalDexFileBytes() const REQUIRES_SHARED(art::Locks::mutator_lock_) { - return holder_.GetOriginalDexFile(idx_); + return holder_.GetOriginalDexFileBytes(idx_); } int32_t GetIndex() const { return idx_; @@ -1007,9 +1010,9 @@ class RedefinitionDataIter { void SetMirrorClass(art::mirror::Class* klass) REQUIRES_SHARED(art::Locks::mutator_lock_) { holder_.SetMirrorClass(idx_, klass); } - void SetOriginalDexFile(art::mirror::Object* bytes) + void SetOriginalDexFileBytes(art::mirror::ByteArray* bytes) REQUIRES_SHARED(art::Locks::mutator_lock_) { - holder_.SetOriginalDexFile(idx_, bytes); + holder_.SetOriginalDexFileBytes(idx_, bytes); } private: @@ -1135,8 +1138,8 @@ bool Redefiner::ClassRedefinition::FinishRemainingAllocations( } // We won't always need to set this field. - cur_data->SetOriginalDexFile(AllocateOrGetOriginalDexFile()); - if (cur_data->GetOriginalDexFile() == nullptr) { + cur_data->SetOriginalDexFileBytes(AllocateOrGetOriginalDexFileBytes()); + if (cur_data->GetOriginalDexFileBytes() == nullptr) { driver_->self_->AssertPendingOOMException(); driver_->self_->ClearException(); RecordFailure(ERR(OUT_OF_MEMORY), "Unable to allocate array for original dex file"); @@ -1282,7 +1285,7 @@ jvmtiError Redefiner::Run() { art::mirror::Class* klass = data.GetMirrorClass(); // TODO Rewrite so we don't do a stack walk for each and every class. redef.FindAndAllocateObsoleteMethods(klass); - redef.UpdateClass(klass, data.GetNewDexCache(), data.GetOriginalDexFile()); + redef.UpdateClass(klass, data.GetNewDexCache(), data.GetOriginalDexFileBytes()); } // TODO We should check for if any of the redefined methods are intrinsic methods here and, if any // are, force a full-world deoptimization before finishing redefinition. If we don't do this then @@ -1362,7 +1365,7 @@ void Redefiner::ClassRedefinition::UpdateFields(art::ObjPtr<art::mirror::Class> void Redefiner::ClassRedefinition::UpdateClass( art::ObjPtr<art::mirror::Class> mclass, art::ObjPtr<art::mirror::DexCache> new_dex_cache, - art::ObjPtr<art::mirror::Object> original_dex_file) { + art::ObjPtr<art::mirror::ByteArray> original_dex_file) { DCHECK_EQ(dex_file_->NumClassDefs(), 1u); const art::DexFile::ClassDef& class_def = dex_file_->GetClassDef(0); UpdateMethods(mclass, new_dex_cache, class_def); @@ -1376,7 +1379,7 @@ void Redefiner::ClassRedefinition::UpdateClass( mclass->SetDexTypeIndex(dex_file_->GetIndexForTypeId(*dex_file_->FindTypeId(class_sig_.c_str()))); art::ObjPtr<art::mirror::ClassExt> ext(mclass->GetExtData()); CHECK(!ext.IsNull()); - ext->SetOriginalDexFile(original_dex_file); + ext->SetOriginalDexFileBytes(original_dex_file); } // This function does all (java) allocations we need to do for the Class being redefined. diff --git a/runtime/openjdkjvmti/ti_redefine.h b/runtime/openjdkjvmti/ti_redefine.h index 6c09d46e89..4313a9476e 100644 --- a/runtime/openjdkjvmti/ti_redefine.h +++ b/runtime/openjdkjvmti/ti_redefine.h @@ -137,7 +137,7 @@ class Redefiner { REQUIRES_SHARED(art::Locks::mutator_lock_); // This may return nullptr with a OOME pending if allocation fails. - art::mirror::Object* AllocateOrGetOriginalDexFile() + art::mirror::ByteArray* AllocateOrGetOriginalDexFileBytes() REQUIRES_SHARED(art::Locks::mutator_lock_); void RecordFailure(jvmtiError e, const std::string& err) { @@ -196,7 +196,7 @@ class Redefiner { void UpdateClass(art::ObjPtr<art::mirror::Class> mclass, art::ObjPtr<art::mirror::DexCache> new_dex_cache, - art::ObjPtr<art::mirror::Object> original_dex_file) + art::ObjPtr<art::mirror::ByteArray> original_dex_file) REQUIRES(art::Locks::mutator_lock_); void ReleaseDexFile() REQUIRES_SHARED(art::Locks::mutator_lock_); diff --git a/runtime/openjdkjvmti/transform.cc b/runtime/openjdkjvmti/transform.cc index 06aecbaee3..bd52cbb7f9 100644 --- a/runtime/openjdkjvmti/transform.cc +++ b/runtime/openjdkjvmti/transform.cc @@ -150,27 +150,16 @@ jvmtiError Transformer::GetDexDataForRetransformation(ArtJvmTiEnv* env, art::Handle<art::mirror::Class> klass, /*out*/jint* dex_data_len, /*out*/unsigned char** dex_data) { - art::StackHandleScope<3> hs(art::Thread::Current()); + art::StackHandleScope<2> hs(art::Thread::Current()); art::Handle<art::mirror::ClassExt> ext(hs.NewHandle(klass->GetExtData())); if (!ext.IsNull()) { - art::Handle<art::mirror::Object> orig_dex(hs.NewHandle(ext->GetOriginalDexFile())); + art::Handle<art::mirror::ByteArray> orig_dex(hs.NewHandle(ext->GetOriginalDexFileBytes())); if (!orig_dex.IsNull()) { - if (orig_dex->IsArrayInstance()) { - DCHECK(orig_dex->GetClass()->GetComponentType()->IsPrimitiveByte()); - art::Handle<art::mirror::ByteArray> orig_dex_bytes( - hs.NewHandle(art::down_cast<art::mirror::ByteArray*>(orig_dex->AsArray()))); - *dex_data_len = static_cast<jint>(orig_dex_bytes->GetLength()); - return CopyDataIntoJvmtiBuffer( - env, - reinterpret_cast<const unsigned char*>(orig_dex_bytes->GetData()), - *dex_data_len, - /*out*/dex_data); - } else { - DCHECK(orig_dex->IsDexCache()); - const art::DexFile* dex_file = orig_dex->AsDexCache()->GetDexFile(); - *dex_data_len = static_cast<jint>(dex_file->Size()); - return CopyDataIntoJvmtiBuffer(env, dex_file->Begin(), dex_file->Size(), /*out*/dex_data); - } + *dex_data_len = static_cast<jint>(orig_dex->GetLength()); + return CopyDataIntoJvmtiBuffer(env, + reinterpret_cast<const unsigned char*>(orig_dex->GetData()), + *dex_data_len, + /*out*/dex_data); } } // TODO De-quicken the dex file before passing it to the agents. diff --git a/test/981-dedup-original-dex/expected.txt b/test/981-dedup-original-dex/expected.txt deleted file mode 100644 index e69de29bb2..0000000000 --- a/test/981-dedup-original-dex/expected.txt +++ /dev/null diff --git a/test/981-dedup-original-dex/info.txt b/test/981-dedup-original-dex/info.txt deleted file mode 100644 index 62696e00d7..0000000000 --- a/test/981-dedup-original-dex/info.txt +++ /dev/null @@ -1,4 +0,0 @@ -Tests basic functions in the jvmti plugin. - -This checks that we do not needlessly duplicate the contents of retransformed -classes original dex files. diff --git a/test/981-dedup-original-dex/run b/test/981-dedup-original-dex/run deleted file mode 100755 index e92b873956..0000000000 --- a/test/981-dedup-original-dex/run +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# -# Copyright 2017 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. - -./default-run "$@" --jvmti diff --git a/test/981-dedup-original-dex/src/Main.java b/test/981-dedup-original-dex/src/Main.java deleted file mode 100644 index cd3f007532..0000000000 --- a/test/981-dedup-original-dex/src/Main.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -import java.lang.reflect.Field; -import java.util.Base64; - -import dalvik.system.ClassExt; - -public class Main { - - /** - * base64 encoded class/dex file for - * class Transform { - * public void sayHi() { - * System.out.println("Goodbye"); - * } - * } - */ - private static final byte[] DEX_BYTES_1 = Base64.getDecoder().decode( - "ZGV4CjAzNQCLXSBQ5FiS3f16krSYZFF8xYZtFVp0GRXMAgAAcAAAAHhWNBIAAAAAAAAAACwCAAAO" + - "AAAAcAAAAAYAAACoAAAAAgAAAMAAAAABAAAA2AAAAAQAAADgAAAAAQAAAAABAACsAQAAIAEAAGIB" + - "AABqAQAAcwEAAIABAACXAQAAqwEAAL8BAADTAQAA4wEAAOYBAADqAQAA/gEAAAMCAAAMAgAAAgAA" + - "AAMAAAAEAAAABQAAAAYAAAAIAAAACAAAAAUAAAAAAAAACQAAAAUAAABcAQAABAABAAsAAAAAAAAA" + - "AAAAAAAAAAANAAAAAQABAAwAAAACAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAHAAAAAAAAAB4CAAAA" + - "AAAAAQABAAEAAAATAgAABAAAAHAQAwAAAA4AAwABAAIAAAAYAgAACQAAAGIAAAAbAQEAAABuIAIA" + - "EAAOAAAAAQAAAAMABjxpbml0PgAHR29vZGJ5ZQALTFRyYW5zZm9ybTsAFUxqYXZhL2lvL1ByaW50" + - "U3RyZWFtOwASTGphdmEvbGFuZy9PYmplY3Q7ABJMamF2YS9sYW5nL1N0cmluZzsAEkxqYXZhL2xh" + - "bmcvU3lzdGVtOwAOVHJhbnNmb3JtLmphdmEAAVYAAlZMABJlbWl0dGVyOiBqYWNrLTMuMzYAA291" + - "dAAHcHJpbnRsbgAFc2F5SGkAEQAHDgATAAcOhQAAAAEBAICABKACAQG4Ag0AAAAAAAAAAQAAAAAA" + - "AAABAAAADgAAAHAAAAACAAAABgAAAKgAAAADAAAAAgAAAMAAAAAEAAAAAQAAANgAAAAFAAAABAAA" + - "AOAAAAAGAAAAAQAAAAABAAABIAAAAgAAACABAAABEAAAAQAAAFwBAAACIAAADgAAAGIBAAADIAAA" + - "AgAAABMCAAAAIAAAAQAAAB4CAAAAEAAAAQAAACwCAAA="); - - /** - * base64 encoded class/dex file for - * class Transform2 { - * public void sayHi() { - * System.out.println("Goodbye2"); - * } - * } - */ - private static final byte[] DEX_BYTES_2 = Base64.getDecoder().decode( - "ZGV4CjAzNQAjXDED2iflQ3NXbPtBRVjQVMqoDU9nDz/QAgAAcAAAAHhWNBIAAAAAAAAAADACAAAO" + - "AAAAcAAAAAYAAACoAAAAAgAAAMAAAAABAAAA2AAAAAQAAADgAAAAAQAAAAABAACwAQAAIAEAAGIB" + - "AABqAQAAdAEAAIIBAACZAQAArQEAAMEBAADVAQAA5gEAAOkBAADtAQAAAQIAAAYCAAAPAgAAAgAA" + - "AAMAAAAEAAAABQAAAAYAAAAIAAAACAAAAAUAAAAAAAAACQAAAAUAAABcAQAABAABAAsAAAAAAAAA" + - "AAAAAAAAAAANAAAAAQABAAwAAAACAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAHAAAAAAAAACECAAAA" + - "AAAAAQABAAEAAAAWAgAABAAAAHAQAwAAAA4AAwABAAIAAAAbAgAACQAAAGIAAAAbAQEAAABuIAIA" + - "EAAOAAAAAQAAAAMABjxpbml0PgAIR29vZGJ5ZTIADExUcmFuc2Zvcm0yOwAVTGphdmEvaW8vUHJp" + - "bnRTdHJlYW07ABJMamF2YS9sYW5nL09iamVjdDsAEkxqYXZhL2xhbmcvU3RyaW5nOwASTGphdmEv" + - "bGFuZy9TeXN0ZW07AA9UcmFuc2Zvcm0yLmphdmEAAVYAAlZMABJlbWl0dGVyOiBqYWNrLTQuMzAA" + - "A291dAAHcHJpbnRsbgAFc2F5SGkAAQAHDgADAAcOhwAAAAEBAICABKACAQG4AgANAAAAAAAAAAEA" + - "AAAAAAAAAQAAAA4AAABwAAAAAgAAAAYAAACoAAAAAwAAAAIAAADAAAAABAAAAAEAAADYAAAABQAA" + - "AAQAAADgAAAABgAAAAEAAAAAAQAAASAAAAIAAAAgAQAAARAAAAEAAABcAQAAAiAAAA4AAABiAQAA" + - "AyAAAAIAAAAWAgAAACAAAAEAAAAhAgAAABAAAAEAAAAwAgAA"); - - public static void main(String[] args) { - try { - doTest(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - private static void assertSame(Object a, Object b) throws Exception { - if (a != b) { - throw new AssertionError("'" + (a != null ? a.toString() : "null") + "' is not the same as " + - "'" + (b != null ? b.toString() : "null") + "'"); - } - } - - private static Object getObjectField(Object o, String name) throws Exception { - return getObjectField(o, o.getClass(), name); - } - - private static Object getObjectField(Object o, Class<?> type, String name) throws Exception { - Field f = type.getDeclaredField(name); - f.setAccessible(true); - return f.get(o); - } - - private static Object getOriginalDexFile(Class<?> k) throws Exception { - ClassExt ext_data_object = (ClassExt) getObjectField(k, "extData"); - if (ext_data_object == null) { - return null; - } - - return getObjectField(ext_data_object, "originalDexFile"); - } - - public static void doTest() throws Exception { - // Make sure both of these are loaded prior to transformations being added so they have the same - // original dex files. - Transform t1 = new Transform(); - Transform2 t2 = new Transform2(); - - assertSame(null, getOriginalDexFile(t1.getClass())); - assertSame(null, getOriginalDexFile(t2.getClass())); - assertSame(null, getOriginalDexFile(Main.class)); - - addCommonTransformationResult("Transform", new byte[0], DEX_BYTES_1); - addCommonTransformationResult("Transform2", new byte[0], DEX_BYTES_2); - enableCommonRetransformation(true); - doCommonClassRetransformation(Transform.class, Transform2.class); - - assertSame(getOriginalDexFile(t1.getClass()), getOriginalDexFile(t2.getClass())); - assertSame(null, getOriginalDexFile(Main.class)); - // Make sure that the original dex file is a DexCache object. - assertSame(getOriginalDexFile(t1.getClass()).getClass(), Class.forName("java.lang.DexCache")); - - // Check that we end up with a byte[] if we do a direct RedefineClasses - enableCommonRetransformation(false); - doCommonClassRedefinition(Transform.class, new byte[0], DEX_BYTES_1); - assertSame((new byte[0]).getClass(), getOriginalDexFile(t1.getClass()).getClass()); - } - - // Transforms the class - private static native void doCommonClassRetransformation(Class<?>... target); - private static native void doCommonClassRedefinition(Class<?> target, - byte[] class_file, - byte[] dex_file); - private static native void enableCommonRetransformation(boolean enable); - private static native void addCommonTransformationResult(String target_name, - byte[] class_bytes, - byte[] dex_bytes); -} diff --git a/test/981-dedup-original-dex/src/Transform.java b/test/981-dedup-original-dex/src/Transform.java deleted file mode 100644 index 3c97907ddc..0000000000 --- a/test/981-dedup-original-dex/src/Transform.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -class Transform { - public void sayHi() { - System.out.println("hello"); - } -} diff --git a/test/981-dedup-original-dex/src/Transform2.java b/test/981-dedup-original-dex/src/Transform2.java deleted file mode 100644 index eb22842184..0000000000 --- a/test/981-dedup-original-dex/src/Transform2.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ - -class Transform2 { - public void sayHi() { - System.out.println("hello2"); - } -} diff --git a/test/ti-agent/common_load.cc b/test/ti-agent/common_load.cc index 8cb14bdfc5..fddae3af02 100644 --- a/test/ti-agent/common_load.cc +++ b/test/ti-agent/common_load.cc @@ -121,7 +121,6 @@ static AgentLib agents[] = { { "943-private-recursive-jit", common_redefine::OnLoad, nullptr }, { "944-transform-classloaders", common_redefine::OnLoad, nullptr }, { "945-obsolete-native", common_redefine::OnLoad, nullptr }, - { "981-dedup-original-dex", common_retransform::OnLoad, nullptr }, }; static AgentLib* FindAgent(char* name) { |