Update asm to version 9.6

Fixes: b/301189814
Fixes: b/307901751
Change-Id: Ia53766cecbeaa279647781b532a4c915784ea2c9
diff --git a/d8_r8/commonBuildSrc/src/main/kotlin/DependenciesPlugin.kt b/d8_r8/commonBuildSrc/src/main/kotlin/DependenciesPlugin.kt
index f792379..32e3732 100644
--- a/d8_r8/commonBuildSrc/src/main/kotlin/DependenciesPlugin.kt
+++ b/d8_r8/commonBuildSrc/src/main/kotlin/DependenciesPlugin.kt
@@ -308,7 +308,7 @@
 }
 
 object Versions {
-  const val asmVersion = "9.5"
+  const val asmVersion = "9.6"
   const val errorproneVersion = "2.18.0"
   const val fastUtilVersion = "7.2.1"
   const val gsonVersion = "2.10.1"
diff --git a/src/main/java/com/android/tools/r8/cf/CfVersion.java b/src/main/java/com/android/tools/r8/cf/CfVersion.java
index c85f50f..0c1d72b 100644
--- a/src/main/java/com/android/tools/r8/cf/CfVersion.java
+++ b/src/main/java/com/android/tools/r8/cf/CfVersion.java
@@ -46,8 +46,8 @@
   public static final CfVersion V20_PREVIEW = new CfVersion(Opcodes.V20 | Opcodes.V_PREVIEW);
   public static final CfVersion V21 = new CfVersion(Opcodes.V21);
   public static final CfVersion V21_PREVIEW = new CfVersion(Opcodes.V21 | Opcodes.V_PREVIEW);
-  public static final CfVersion V22 = new CfVersion(66);
-  public static final CfVersion V22_PREVIEW = new CfVersion(66 | Opcodes.V_PREVIEW);
+  public static final CfVersion V22 = new CfVersion(Opcodes.V22);
+  public static final CfVersion V22_PREVIEW = new CfVersion(Opcodes.V22 | Opcodes.V_PREVIEW);
 
   private final int version;
 
@@ -72,7 +72,8 @@
     CfVersion.V18,
     CfVersion.V19,
     CfVersion.V20,
-    CfVersion.V21
+    CfVersion.V21,
+    CfVersion.V22
   };
 
   // Private constructor in case we want to canonicalize versions.
diff --git a/src/test/java/com/android/tools/r8/ToolHelper.java b/src/test/java/com/android/tools/r8/ToolHelper.java
index eceaf77..f1f836b 100644
--- a/src/test/java/com/android/tools/r8/ToolHelper.java
+++ b/src/test/java/com/android/tools/r8/ToolHelper.java
@@ -212,8 +212,8 @@
 
   public static final String R8_TEST_BUCKET = "r8-test-results";
 
-  public static final String ASM_JAR = BUILD_DIR + "deps/asm-9.5.jar";
-  public static final String ASM_UTIL_JAR = BUILD_DIR + "deps/asm-util-9.5.jar";
+  public static final String ASM_JAR = BUILD_DIR + "deps/asm-9.6.jar";
+  public static final String ASM_UTIL_JAR = BUILD_DIR + "deps/asm-util-9.6.jar";
 
   public static final Path API_SAMPLE_JAR =
       Paths.get(getProjectRoot(), "tests", "r8_api_usage_sample.jar");
diff --git a/src/test/java/com/android/tools/r8/cf/ClassFileVersion66Test.java b/src/test/java/com/android/tools/r8/cf/ClassFileVersion66Test.java
index d97f14c..aabbf04 100644
--- a/src/test/java/com/android/tools/r8/cf/ClassFileVersion66Test.java
+++ b/src/test/java/com/android/tools/r8/cf/ClassFileVersion66Test.java
@@ -4,7 +4,6 @@
 
 package com.android.tools.r8.cf;
 
-import com.android.tools.r8.CompilationFailedException;
 import com.android.tools.r8.TestBase;
 import com.android.tools.r8.TestParameters;
 import com.android.tools.r8.TestParametersCollection;
@@ -34,8 +33,7 @@
     this.parameters = parameters;
   }
 
-  // TODO(b/301189814): Update ASM once it has a release with v22 support.
-  @Test(expected = CompilationFailedException.class)
+  @Test
   public void test() throws Exception {
     testForD8(parameters.getBackend())
         .addProgramClassFileData(transformer(TestClass.class).setVersion(CfVersion.V22).transform())
diff --git a/src/test/java/com/android/tools/r8/cf/frames/InitBeforeNewInInstructionStreamTest.java b/src/test/java/com/android/tools/r8/cf/frames/InitBeforeNewInInstructionStreamTest.java
index 1d93a7a..c0808d2 100644
--- a/src/test/java/com/android/tools/r8/cf/frames/InitBeforeNewInInstructionStreamTest.java
+++ b/src/test/java/com/android/tools/r8/cf/frames/InitBeforeNewInInstructionStreamTest.java
@@ -3,7 +3,7 @@
 // BSD-style license that can be found in the LICENSE file.
 package com.android.tools.r8.cf.frames;
 
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertTrue;
 
 import com.android.tools.r8.TestBase;
 import com.android.tools.r8.TestParameters;
@@ -41,7 +41,7 @@
   public void testJvm() throws Exception {
     parameters.assumeJvmTestParameters();
     testForJvm(parameters)
-        .addProgramClassFileData(patchedDump())
+        .addProgramClassFileData(dump())
         .run(parameters.getRuntime(), MAIN_CLASS)
         .assertSuccessWithOutput(EXPECTED_OUTPUT);
   }
@@ -50,7 +50,7 @@
   public void testD8() throws Exception {
     parameters.assumeDexRuntime();
     testForD8(parameters.getBackend())
-        .addProgramClassFileData(patchedDump())
+        .addProgramClassFileData(dump())
         .setMinApi(parameters)
         .run(parameters.getRuntime(), MAIN_CLASS)
         .assertSuccessWithOutput(EXPECTED_OUTPUT);
@@ -60,21 +60,16 @@
   public void testR8() throws Exception {
     parameters.assumeR8TestParameters();
     testForR8(parameters.getBackend())
-        .addProgramClassFileData(patchedDump())
+        .addProgramClassFileData(dump())
         .addKeepMainRule(MAIN_CLASS)
         .setMinApi(parameters)
         .run(parameters.getRuntime(), MAIN_CLASS)
         .assertSuccessWithOutput(EXPECTED_OUTPUT);
   }
 
-  // This is reproducing b/b274337639, where a new instruction is before the corresponding
-  // invokespecial of <init> in the instruction stream. The code is correct as control flow ensures
-  // new is called before init, and the stack map encodes this.
-  //
-  // Writing this code with ASM did not generate the correct stack map, so using javassist to patch
-  // it up.
-
-  public static byte[] patchedDump() throws Exception {
+  @Test
+  public void checkDump() throws Exception {
+    parameters.assumeJvmTestParameters();
     ClassPool classPool = new ClassPool();
     classPool.insertClassPath(new ByteArrayClassPath(MAIN_CLASS, dump()));
     CtClass clazz = classPool.get(MAIN_CLASS);
@@ -85,24 +80,19 @@
     byte[] stackMapTable = stackMapTableAttribute.get();
     // Uninitialized has type 8 in the stack map. See
     // https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.4.
-    // The instruction index 0 generated by ASM is not correct, patch to index 12.
-    if (stackMapTable[15] == 8
-        && stackMapTable[16] == 0
-        && stackMapTable[17] == 0
-        && stackMapTable[18] == 8
-        && stackMapTable[19] == 0
-        && stackMapTable[20] == 0) {
-      stackMapTable[17] = 12;
-      stackMapTable[20] = 12;
-    } else {
-      // If an ASM update fails here maybe the stack map is generated correctly and the javassist
-      // patching can be removed.
-      fail("Unexpected class file*");
-    }
-    stackMapTableAttribute.set(stackMapTable);
-    return clazz.toBytecode();
+    // Keep to validate https://gitlab.ow2.org/asm/asm/-/issues/317995 is fixed.
+    assertTrue(
+        stackMapTable[15] == 8
+            && stackMapTable[16] == 0
+            && stackMapTable[17] == 12
+            && stackMapTable[18] == 8
+            && stackMapTable[19] == 0
+            && stackMapTable[20] == 12);
   }
 
+  // This is reproducing b/274337639, where a new instruction is before the corresponding
+  // invokespecial of <init> in the instruction stream. The code is correct as control flow ensures
+  // new is called before init, and the stack map encodes this.
   public static byte[] dump() throws Exception {
 
     ClassWriter classWriter = new ClassWriter(0);
diff --git a/third_party/dependencies.tar.gz.sha1 b/third_party/dependencies.tar.gz.sha1
index 9898030..c41f552 100644
--- a/third_party/dependencies.tar.gz.sha1
+++ b/third_party/dependencies.tar.gz.sha1
@@ -1 +1 @@
-988112588dc40844879db1f2463433b7147d7263
\ No newline at end of file
+0276892a18f142c7399e09f5dada5e5f98857114
\ No newline at end of file
diff --git a/tools/asmifier.py b/tools/asmifier.py
index 9af1499..f599876 100755
--- a/tools/asmifier.py
+++ b/tools/asmifier.py
@@ -10,7 +10,7 @@
 import sys
 import utils
 
-ASM_VERSION = '9.5'
+ASM_VERSION = '9.6'
 ASM_JAR = os.path.join(utils.DEPENDENCIES_DIR, 'org', 'ow2', 'asm', 'asm',
                        ASM_VERSION, 'asm-' + ASM_VERSION + '.jar')
 ASM_UTIL_JAR = os.path.join(utils.DEPENDENCIES_DIR, 'org', 'ow2', 'asm',
diff --git a/tools/create_local_maven_with_dependencies.py b/tools/create_local_maven_with_dependencies.py
index 28f7401..fd06fa4 100755
--- a/tools/create_local_maven_with_dependencies.py
+++ b/tools/create_local_maven_with_dependencies.py
@@ -21,7 +21,7 @@
 ]
 
 ANDRDID_SUPPORT_VERSION = '25.4.0'
-ASM_VERSION = '9.5'
+ASM_VERSION = '9.6' # When updating update tools/asmifier.py and Toolhelper as well.
 ESPRESSO_VERSION = '3.0.0'
 FASTUTIL_VERSION = '7.2.1'
 KOTLIN_METADATA_VERSION = '0.7.0'