Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/mlvm/cp/share/GenCPFullOfMH.java
41162 views
/*1* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package vm.mlvm.cp.share;2425import jdk.internal.org.objectweb.asm.ClassWriter;26import jdk.internal.org.objectweb.asm.ClassWriterExt;27import jdk.internal.org.objectweb.asm.MethodVisitor;28import jdk.internal.org.objectweb.asm.Opcodes;29import jdk.internal.org.objectweb.asm.Handle;3031import vm.mlvm.share.ClassfileGenerator;32import vm.mlvm.share.Env;3334public class GenCPFullOfMH extends GenFullCP {3536public static void main(String[] args) {37ClassfileGenerator.main(args);38}3940@Override41protected void generateCommonData(ClassWriterExt cw) {42cw.setCacheMHandles(false);4344cw.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC,45STATIC_FIELD_NAME,46STATIC_FIELD_SIGNATURE, null, false);4748cw.visitField(Opcodes.ACC_PUBLIC,49INSTANCE_FIELD_NAME,50INSTANCE_FIELD_SIGNATURE, null, false);5152createInitMethod(cw);53createTargetMethod(cw);5455MethodVisitor mv = cw.visitMethod(56Opcodes.ACC_PUBLIC,57INSTANCE_TARGET_METHOD_NAME,58INSTANCE_TARGET_METHOD_SIGNATURE,59null,60new String[0]);61finishMethodCode(mv);62}6364@Override65protected void generateCPEntryData(ClassWriter cw, MethodVisitor mw) {66HandleType[] types = HandleType.values();67HandleType type = types[Env.getRNG().nextInt(types.length)];6869switch (type) {70case PUTFIELD:71case PUTSTATIC:72mw.visitInsn(Opcodes.ICONST_0);73break;74case INVOKESPECIAL:75case INVOKEVIRTUAL:76case INVOKEINTERFACE:77mw.visitInsn(Opcodes.ACONST_NULL);78break;79}8081Handle handle;82switch (type) {83case GETFIELD:84case PUTFIELD:85handle = new Handle(type.asmTag,86fullClassName,87INSTANCE_FIELD_NAME,88INSTANCE_FIELD_SIGNATURE);89break;90case GETSTATIC:91case PUTSTATIC:92handle = new Handle(type.asmTag,93fullClassName,94STATIC_FIELD_NAME,95STATIC_FIELD_SIGNATURE);96break;97case NEWINVOKESPECIAL:98handle = new Handle(type.asmTag,99fullClassName,100INIT_METHOD_NAME,101INIT_METHOD_SIGNATURE);102break;103case INVOKESTATIC:104handle = new Handle(type.asmTag,105fullClassName,106TARGET_METHOD_NAME,107TARGET_METHOD_SIGNATURE);108break;109case INVOKEINTERFACE:110handle = new Handle(type.asmTag,111getDummyInterfaceClassName(),112INSTANCE_TARGET_METHOD_NAME,113INSTANCE_TARGET_METHOD_SIGNATURE);114break;115case INVOKESPECIAL:116case INVOKEVIRTUAL:117handle = new Handle(type.asmTag,118fullClassName,119INSTANCE_TARGET_METHOD_NAME,120INSTANCE_TARGET_METHOD_SIGNATURE);121break;122default:123throw new Error("Unexpected handle type " + type);124}125mw.visitLdcInsn(handle);126127switch (type) {128case GETFIELD:129case GETSTATIC:130mw.visitInsn(Opcodes.POP);131break;132}133}134}135136137