summaryrefslogtreecommitdiff
path: root/test/jvmti-common/Redefinition.java
diff options
context:
space:
mode:
author Alex Light <allight@google.com> 2019-10-15 15:46:07 -0700
committer Alex Light <allight@google.com> 2019-10-30 16:53:25 -0700
commitd55b844e39c4d5eb1a56de6cb95c891659f8a27f (patch)
treeed2f7809528e8b44985edc12d75fb0965806045f /test/jvmti-common/Redefinition.java
parent436c6f5fae95aae332361060778599d0ef24a167 (diff)
Add more standard structural redefinition entrypoints
Add structural redefinition extension function and event that mirror the 'RedefineClasses' function and 'ClassFileLoadHook' event. The new extension function is called 'com.android.art.class.structurally_redefine_classes' and the new extension event is called 'com.android.art.class.structural_dex_file_load_hook'. These extensions are the preferred way to use structural redefinition. Like the standard 'RedefineClasses' multiple classes may be redefined at a time. The structural_dex_file_load_hook is triggered prior to the can_retransform_classes ClassFileLoadHook. It is triggered on all classes, even ones that cannot be structurally changed by class-loading, class redefinition or by calling the RetransformClasses function. Calling 'structurally_redefine_classes' with new definitions that do not require structural changes will fall back to non-structural redefinition. Test: ./test.py --host Bug: 134162467 Change-Id: If4810930470c5c6509cf6db779910006e114b39f
Diffstat (limited to 'test/jvmti-common/Redefinition.java')
-rw-r--r--test/jvmti-common/Redefinition.java24
1 files changed, 22 insertions, 2 deletions
diff --git a/test/jvmti-common/Redefinition.java b/test/jvmti-common/Redefinition.java
index 2ebce17686..3402fa12b5 100644
--- a/test/jvmti-common/Redefinition.java
+++ b/test/jvmti-common/Redefinition.java
@@ -19,7 +19,7 @@ package art;
import java.util.ArrayList;
// Common Redefinition functions. Placed here for use by CTS
public class Redefinition {
- public static final class CommonClassDefinition {
+ public static class CommonClassDefinition {
public final Class<?> target;
public final byte[] class_file_bytes;
public final byte[] dex_file_bytes;
@@ -31,12 +31,19 @@ public class Redefinition {
}
}
+ public static class DexOnlyClassDefinition extends CommonClassDefinition {
+ public DexOnlyClassDefinition(Class<?> target, byte[] dex_file_bytes) {
+ super(target, new byte[0], dex_file_bytes);
+ }
+ }
+
// A set of possible test configurations. Test should set this if they need to.
// This must be kept in sync with the defines in ti-agent/common_helper.cc
public static enum Config {
COMMON_REDEFINE(0),
COMMON_RETRANSFORM(1),
- COMMON_TRANSFORM(2);
+ COMMON_TRANSFORM(2),
+ STRUCTURAL_TRANSFORM(3);
private final int val;
private Config(int val) {
@@ -90,5 +97,18 @@ public class Redefinition {
byte[] dex_bytes);
public static native void doCommonStructuralClassRedefinition(Class<?> target, byte[] dex_file);
+ public static void doMultiStructuralClassRedefinition(CommonClassDefinition... defs) {
+ ArrayList<Class<?>> classes = new ArrayList<>();
+ ArrayList<byte[]> dex_files = new ArrayList<>();
+
+ for (CommonClassDefinition d : defs) {
+ classes.add(d.target);
+ dex_files.add(d.dex_file_bytes);
+ }
+ doCommonMultiStructuralClassRedefinition(classes.toArray(new Class<?>[0]),
+ dex_files.toArray(new byte[0][]));
+ }
+ public static native void doCommonMultiStructuralClassRedefinition(Class<?>[] targets,
+ byte[][] dexfiles);
public static native boolean isStructurallyModifiable(Class<?> target);
}