From c971eafeff43e4e26959a6e86b62ab0a8f1a6e1c Mon Sep 17 00:00:00 2001 From: Alex Light Date: Tue, 13 Aug 2019 10:50:38 -0700 Subject: Basic structural redefinition support This adds basic support for adding methods and fields to already loaded classes using redefinition. This 'structural class redefinition' is currently limited to classes without any virtual methods or instance fields. One cannot currently structurally redefine multiple classes at once nor will structural redefinition trigger the standard redefinition events. After structural redefinition all references to the old class, and its fields and methods are atomically updated. Any memory associated with the static fields of the old class is zeroed. Offsets for field access might change. If there are any active stack frames for methods from the redefined class the original (obsolete method) code will continue to execute. The identity hash code of the redefined class will not change. Any locks being held, waited or blocked on by the old class will be transferred to the new class. To use this feature the process must be debuggable and running with -Xopaque-jni-ids:true. For device testing use a wrap.sh that adds the following flags: '-Xopaque-jni-ids:true -Xcompiler-option --debuggable -XjdwpProvider:adbconnection' Structural redefinition only available using the "com.android.art.UNSAFE.class.structurally_redefine_class_direct" extension. This will not trigger the normal class-redefinition events. Only one class may be redefined at a time. NB There are still some holes in this potentially allowing obsolete methods/fields to be visible. Most notably during jni-id, MethodHandle and VarHandle creation as well as potentially other places in the runtime. These holes will be closed by later CLs. Until then the extension to access structural class redefinition will remain tagged as UNSAFE. Test: ./test.py --host --all-compiler Bug: 134162467 Change-Id: I825d3a4bdb9594c0147223ae69f433ce9bbfc307 --- libdexfile/dex/modifiers.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'libdexfile/dex/modifiers.h') diff --git a/libdexfile/dex/modifiers.h b/libdexfile/dex/modifiers.h index 5caa402d51..918feb34f4 100644 --- a/libdexfile/dex/modifiers.h +++ b/libdexfile/dex/modifiers.h @@ -55,6 +55,9 @@ static constexpr uint32_t kAccSkipAccessChecks = 0x00080000; // method (ru // Used by a class to denote that the verifier has attempted to check it at least once. static constexpr uint32_t kAccVerificationAttempted = 0x00080000; // class (runtime) static constexpr uint32_t kAccSkipHiddenapiChecks = 0x00100000; // class (runtime) +// Used by a class to denote that this class and any objects with this as a +// declaring-class/super-class are to be considered obsolete, meaning they should not be used by. +static constexpr uint32_t kAccObsoleteObject = 0x00200000; // class (runtime) // This is set by the class linker during LinkInterfaceMethods. It is used by a method to represent // that it was copied from its declaring class into another class. All methods marked kAccMiranda // and kAccDefaultConflict will have this bit set. Any kAccDefault method contained in the methods_ -- cgit v1.2.3-59-g8ed1b