8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @bug 8042235 27 * @summary redefining method used by multiple MethodHandles crashes VM 28 * @modules java.base/jdk.internal.org.objectweb.asm 29 * java.compiler 30 * java.instrument 31 * java.management 32 * @compile -XDignore.symbol.file RedefineMethodUsedByMultipleMethodHandles.java 33 * @run main/othervm RedefineMethodUsedByMultipleMethodHandles 34 */ 35 36 import java.io.*; 37 import java.lang.instrument.*; 38 import java.lang.invoke.*; 39 import java.lang.invoke.MethodHandles.Lookup; 40 import java.lang.management.*; 41 import java.lang.reflect.*; 42 import java.nio.file.*; 43 import java.security.*; 44 import java.util.jar.*; 45 46 import javax.tools.*; 47 48 import jdk.internal.org.objectweb.asm.*; 49 50 public class RedefineMethodUsedByMultipleMethodHandles { 51 52 static class Foo { 53 public static Object getName() { 54 return "foo"; 55 } 56 } 57 58 public static void main(String[] args) throws Throwable { 59 60 Lookup lookup = MethodHandles.lookup(); 61 Method fooMethod = Foo.class.getDeclaredMethod("getName"); 62 63 // fooMH2 displaces fooMH1 from the MemberNamesTable 64 MethodHandle fooMH1 = lookup.unreflect(fooMethod); 65 MethodHandle fooMH2 = lookup.unreflect(fooMethod); 66 67 System.out.println("fooMH1.invoke = " + fooMH1.invokeExact()); 68 System.out.println("fooMH2.invoke = " + fooMH2.invokeExact()); | 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @bug 8042235 27 * @summary redefining method used by multiple MethodHandles crashes VM 28 * @library / 29 * @modules java.base/jdk.internal.org.objectweb.asm 30 * java.compiler 31 * java.instrument 32 * java.management 33 * 34 * @run main/othervm compiler.jsr292.RedefineMethodUsedByMultipleMethodHandles 35 */ 36 37 package compiler.jsr292; 38 39 import jdk.internal.org.objectweb.asm.ClassReader; 40 import jdk.internal.org.objectweb.asm.ClassVisitor; 41 import jdk.internal.org.objectweb.asm.ClassWriter; 42 import jdk.internal.org.objectweb.asm.MethodVisitor; 43 import jdk.internal.org.objectweb.asm.Opcodes; 44 45 import javax.tools.ToolProvider; 46 import java.io.FileOutputStream; 47 import java.io.IOException; 48 import java.io.InputStream; 49 import java.lang.instrument.ClassFileTransformer; 50 import java.lang.instrument.IllegalClassFormatException; 51 import java.lang.instrument.Instrumentation; 52 import java.lang.invoke.MethodHandle; 53 import java.lang.invoke.MethodHandles; 54 import java.lang.invoke.MethodHandles.Lookup; 55 import java.lang.management.ManagementFactory; 56 import java.lang.reflect.Method; 57 import java.nio.file.Files; 58 import java.nio.file.Path; 59 import java.security.ProtectionDomain; 60 import java.util.jar.Attributes; 61 import java.util.jar.JarEntry; 62 import java.util.jar.JarOutputStream; 63 import java.util.jar.Manifest; 64 65 public class RedefineMethodUsedByMultipleMethodHandles { 66 67 static class Foo { 68 public static Object getName() { 69 return "foo"; 70 } 71 } 72 73 public static void main(String[] args) throws Throwable { 74 75 Lookup lookup = MethodHandles.lookup(); 76 Method fooMethod = Foo.class.getDeclaredMethod("getName"); 77 78 // fooMH2 displaces fooMH1 from the MemberNamesTable 79 MethodHandle fooMH1 = lookup.unreflect(fooMethod); 80 MethodHandle fooMH2 = lookup.unreflect(fooMethod); 81 82 System.out.println("fooMH1.invoke = " + fooMH1.invokeExact()); 83 System.out.println("fooMH2.invoke = " + fooMH2.invokeExact()); |