7 * published by the Free Software Foundation. 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 8072008 27 * @library /testlibrary /../../test/lib 28 * @build RedefineTest Agent 29 * @run main ClassFileInstaller sun.hotspot.WhiteBox 30 * sun.hotspot.WhiteBox$WhiteBoxPermission 31 * java.lang.invoke.RedefineTest 32 * Agent 33 * jdk.test.lib.Asserts 34 * @run main Agent agent.jar java.lang.invoke.RedefineTest 35 * @run main/othervm -Xbootclasspath/a:. -javaagent:agent.jar 36 * -XX:+IgnoreUnrecognizedVMOptions 37 * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI 38 * -Xbatch -XX:-TieredCompilation -XX:CICompilerCount=1 39 * java.lang.invoke.RedefineTest 40 */ 41 package java.lang.invoke; 42 43 import sun.hotspot.WhiteBox; 44 import sun.misc.Unsafe; 45 46 import jdk.internal.org.objectweb.asm.*; 47 import jdk.internal.vm.annotation.DontInline; 48 49 import java.lang.instrument.ClassDefinition; 50 import java.lang.instrument.Instrumentation; 51 52 import static jdk.internal.org.objectweb.asm.Opcodes.*; 53 54 public class RedefineTest { 55 static final MethodHandles.Lookup LOOKUP = MethodHandles.Lookup.IMPL_LOOKUP; 56 static final Unsafe UNSAFE = Unsafe.getUnsafe(); 57 58 static final String NAME = "java/lang/invoke/RedefineTest$T"; 59 60 static Class<?> getClass(int r) { 61 byte[] classFile = getClassFile(r); 62 return UNSAFE.defineClass(NAME, classFile, 0, classFile.length, null, null); 63 } 64 65 /** 66 * Generates a class of the following shape: 67 * static class T { 68 * @DontInline public static int f() { return $r; } | 7 * published by the Free Software Foundation. 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 8072008 27 * @library /testlibrary /test/lib 28 * @compile RedefineTest.java Agent.java 29 * @run main ClassFileInstaller sun.hotspot.WhiteBox 30 * sun.hotspot.WhiteBox$WhiteBoxPermission 31 * java.lang.invoke.RedefineTest 32 * Agent 33 * jdk.test.lib.Asserts 34 * @run main Agent agent.jar java.lang.invoke.RedefineTest 35 * @run main/othervm -Xbootclasspath/a:. -javaagent:agent.jar 36 * -XX:+IgnoreUnrecognizedVMOptions 37 * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI 38 * -Xbatch -XX:-TieredCompilation -XX:CICompilerCount=1 39 * java.lang.invoke.RedefineTest 40 */ 41 package java.lang.invoke; 42 43 import sun.hotspot.WhiteBox; 44 import sun.misc.Unsafe; 45 import jdk.internal.org.objectweb.asm.*; 46 import jdk.internal.vm.annotation.DontInline; 47 import java.lang.instrument.ClassDefinition; 48 import java.lang.instrument.Instrumentation; 49 50 import static jdk.internal.org.objectweb.asm.Opcodes.*; 51 52 public class RedefineTest { 53 static final MethodHandles.Lookup LOOKUP = MethodHandles.Lookup.IMPL_LOOKUP; 54 static final Unsafe UNSAFE = Unsafe.getUnsafe(); 55 56 static final String NAME = "java/lang/invoke/RedefineTest$T"; 57 58 static Class<?> getClass(int r) { 59 byte[] classFile = getClassFile(r); 60 return UNSAFE.defineClass(NAME, classFile, 0, classFile.length, null, null); 61 } 62 63 /** 64 * Generates a class of the following shape: 65 * static class T { 66 * @DontInline public static int f() { return $r; } |