1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package art; 18 19 import java.util.Base64; 20 public class Test1990 { 21 22 static class Transform { saySomething()23 public static void saySomething() { 24 System.out.println("hello"); 25 } 26 } 27 28 /** 29 * base64 encoded class/dex file for 30 * static class Transform { 31 * public static void saySomething() { 32 * System.out.println("I say hello and " + sayGoodbye()); 33 * } 34 * public static String sayGoodbye() { 35 * return "you say goodbye!"; 36 * } 37 * } 38 */ 39 // NB The actual dex codes are as follows. This is an explanation of the error this test checks. 40 // 41 // The exact order of instructions is important. Notice the 'invoke-static sayGoodbye' 42 // (instruction 0002) dominates the rest of the block. During the first (runnable) verification 43 // step the verifier will first check and verify there are no hard-failures in this class. Next it 44 // will realize it cannot find the sayGoodbye method on the loaded & resolved Transform class. 45 // This is (correctly) recognized as a soft-verification failure but then the verifier decides the 46 // rest of the method is dead-code. This means the verifier will not perform any of the 47 // soft-failure checks on the rest of the method (since control would never reach there). 48 // 49 // Later after performing the redefinition we do a reverify. At this time we held an exclusive 50 // mutator-lock though so it cannot resolve classes and will not add anything to the dex-cache. 51 // Here we can get past instruction 0002 and successfully determine the rest of the function is 52 // fine. In the process we filled in the methods into the dex-cache but not the classes. This 53 // caused this test to crash when run through the interpreter. 54 // 55 // #2 : (in Lart/Test1990$Transform;) 56 // name : 'saySomething' 57 // type : '()V' 58 // access : 0x0009 (PUBLIC STATIC) 59 // code - 60 // registers : 4 61 // ins : 0 62 // outs : 2 63 // insns size : 27 16-bit code units 64 // 0001d0: |[0001d0] art.Test1990$Transform.saySomething:()V 65 // 0001e0: 6200 0000 |0000: sget-object v0, Ljava/lang/System;.out:Ljava/io/PrintStream; // field@0000 66 // 0001e4: 7100 0100 0000 |0002: invoke-static {}, Lart/Test1990$Transform;.sayGoodbye:()Ljava/lang/String; // method@0001 67 // 0001ea: 0c01 |0005: move-result-object v1 68 // 0001ec: 2202 0700 |0006: new-instance v2, Ljava/lang/StringBuilder; // type@0007 69 // 0001f0: 7010 0500 0200 |0008: invoke-direct {v2}, Ljava/lang/StringBuilder;.<init>:()V // method@0005 70 // 0001f6: 1a03 0100 |000b: const-string v3, "I say hello and " // string@0001 71 // 0001fa: 6e20 0600 3200 |000d: invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;.append:(Ljava/lang/String;)Ljava/lang/StringBuilder; // method@0006 72 // 000200: 6e20 0600 1200 |0010: invoke-virtual {v2, v1}, Ljava/lang/StringBuilder;.append:(Ljava/lang/String;)Ljava/lang/StringBuilder; // method@0006 73 // 000206: 6e10 0700 0200 |0013: invoke-virtual {v2}, Ljava/lang/StringBuilder;.toString:()Ljava/lang/String; // method@0007 74 // 00020c: 0c01 |0016: move-result-object v1 75 // 00020e: 6e20 0300 1000 |0017: invoke-virtual {v0, v1}, Ljava/io/PrintStream;.println:(Ljava/lang/String;)V // method@0003 76 // 000214: 0e00 |001a: return-void 77 // catches : (none) 78 // positions : 79 // 0x0000 line=5 80 // 0x001a line=6 81 // locals : 82 83 // Virtual methods - 84 // source_file_idx : 13 (Test1990.java) 85 private static final byte[] DEX_BYTES = Base64.getDecoder().decode( 86 "ZGV4CjAzNQCV0LekDslEGFglxYgCw7HSyxVegIDjERswBQAAcAAAAHhWNBIAAAAAAAAAAGwEAAAc" + 87 "AAAAcAAAAAoAAADgAAAABAAAAAgBAAABAAAAOAEAAAgAAABAAQAAAQAAAIABAACQAwAAoAEAAC4C" + 88 "AAA2AgAASAIAAEsCAABPAgAAaQIAAHkCAACdAgAAvQIAANQCAADoAgAA/AIAABcDAAArAwAAOgMA" + 89 "AEUDAAB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cABXZhbHVlABB5b3Ugc2F5IGdvb2RieWUhAHZ+fkQ4eyJjb21waWxhdGlvbi1tb2Rl" + 103 "IjoiZGVidWciLCJtaW4tYXBpIjoxLCJzaGEtMSI6IjYwZGE0ZDY3YjM4MWM0MjQ2Nzc1N2M0OWZi" + 104 "NmU1NTc1NmQ4OGEyZjMiLCJ2ZXJzaW9uIjoiMS43LjEyLWRldiJ9AAICARkYAQIDAhEECBMXDgAA" + 105 "AwAAgIAEuAMBCaADAQnQAwAAAAAAAgAAACoEAAAwBAAAUAQAAAAAAAAAAAAAAAAAABAAAAAAAAAA" + 106 "AQAAAAAAAAABAAAAHAAAAHAAAAACAAAACgAAAOAAAAADAAAABAAAAAgBAAAEAAAAAQAAADgBAAAF" + 107 "AAAACAAAAEABAAAGAAAAAQAAAIABAAABIAAAAwAAAKABAAADIAAAAwAAABYCAAABEAAAAQAAACgC" + 108 "AAACIAAAHAAAAC4CAAAEIAAAAgAAACoEAAAAIAAAAQAAADkEAAADEAAAAgAAAEwEAAAGIAAAAQAA" + 109 "AFwEAAAAEAAAAQAAAGwEAAA="); 110 111 112 run()113 public static void run() throws Exception { 114 Redefinition.setTestConfiguration(Redefinition.Config.COMMON_REDEFINE); 115 doTest(new Transform()); 116 } 117 doTest(Transform t)118 public static void doTest(Transform t) throws Exception { 119 Transform.saySomething(); 120 Redefinition.doCommonStructuralClassRedefinition(Transform.class, DEX_BYTES); 121 Transform.saySomething(); 122 } 123 } 124