test/compiler/jvmci/compilerToVM/ConstantPoolTestCase.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8073191-work Sdiff test/compiler/jvmci/compilerToVM

test/compiler/jvmci/compilerToVM/ConstantPoolTestCase.java

Print this page




  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 package compiler.jvmci.compilerToVM;
  26 
  27 import java.util.HashMap;
  28 import java.util.Map;
  29 import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;

  30 import sun.hotspot.WhiteBox;
  31 import jdk.internal.reflect.ConstantPool;
  32 import jdk.internal.reflect.ConstantPool.Tag;
  33 import compiler.jvmci.compilerToVM.ConstantPoolTestsHelper.DummyClasses;
  34 import static compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes.*;
  35 
  36 /**
  37  * Common class for jdk.vm.ci.hotspot.CompilerToVM constant pool tests
  38  */
  39 public class ConstantPoolTestCase {
  40 
  41     private static final Map<Tag, ConstantTypes> TAG_TO_TYPE_MAP;
  42     static {
  43         TAG_TO_TYPE_MAP = new HashMap<>();
  44         TAG_TO_TYPE_MAP.put(Tag.CLASS, CONSTANT_CLASS);
  45         TAG_TO_TYPE_MAP.put(Tag.FIELDREF, CONSTANT_FIELDREF);
  46         TAG_TO_TYPE_MAP.put(Tag.METHODREF, CONSTANT_METHODREF);
  47         TAG_TO_TYPE_MAP.put(Tag.INTERFACEMETHODREF, CONSTANT_INTERFACEMETHODREF);
  48         TAG_TO_TYPE_MAP.put(Tag.STRING, CONSTANT_STRING);
  49         TAG_TO_TYPE_MAP.put(Tag.INTEGER, CONSTANT_INTEGER);


 167             if (!this.equals(type)) {
 168                 String msg = String.format("TESTBUG: CP tag should be a %s, but is %s",
 169                                            this.name(),
 170                                            type.name());
 171                throw new Error(msg);
 172             }
 173         }
 174     }
 175 
 176     public static interface Validator {
 177         void validate(jdk.vm.ci.meta.ConstantPool constantPoolCTVM,
 178                       ConstantTypes cpType,
 179                       DummyClasses dummyClass,
 180                       int index);
 181     }
 182 
 183     public static class TestedCPEntry {
 184         public final String klass;
 185         public final String name;
 186         public final String type;

 187         public final byte[] opcodes;
 188         public final long accFlags;
 189 
 190         public TestedCPEntry(String klass, String name, String type, byte[] opcodes, long accFlags) {




 191             this.klass = klass;
 192             this.name = name;
 193             this.type = type;






 194             if (opcodes != null) {
 195                 this.opcodes = new byte[opcodes.length];
 196                 System.arraycopy(opcodes, 0, this.opcodes, 0, opcodes.length);
 197             } else {
 198                 this.opcodes = null;
 199             }
 200             this.accFlags = accFlags;
 201         }
 202 
 203         public TestedCPEntry(String klass, String name, String type, byte[] opcodes) {
 204             this(klass, name, type, opcodes, 0);
 205         }
 206 
 207         public TestedCPEntry(String klass, String name, String type) {
 208             this(klass, name, type, null, 0);
 209         }
 210     }
 211 
 212     public static ConstantTypes mapTagToCPType(Tag tag) {
 213         return TAG_TO_TYPE_MAP.get(tag);




  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 package compiler.jvmci.compilerToVM;
  26 
  27 import java.util.HashMap;
  28 import java.util.Map;
  29 import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
  30 import jdk.vm.ci.meta.ResolvedJavaMethod;
  31 import sun.hotspot.WhiteBox;
  32 import jdk.internal.reflect.ConstantPool;
  33 import jdk.internal.reflect.ConstantPool.Tag;
  34 import compiler.jvmci.compilerToVM.ConstantPoolTestsHelper.DummyClasses;
  35 import static compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes.*;
  36 
  37 /**
  38  * Common class for jdk.vm.ci.hotspot.CompilerToVM constant pool tests
  39  */
  40 public class ConstantPoolTestCase {
  41 
  42     private static final Map<Tag, ConstantTypes> TAG_TO_TYPE_MAP;
  43     static {
  44         TAG_TO_TYPE_MAP = new HashMap<>();
  45         TAG_TO_TYPE_MAP.put(Tag.CLASS, CONSTANT_CLASS);
  46         TAG_TO_TYPE_MAP.put(Tag.FIELDREF, CONSTANT_FIELDREF);
  47         TAG_TO_TYPE_MAP.put(Tag.METHODREF, CONSTANT_METHODREF);
  48         TAG_TO_TYPE_MAP.put(Tag.INTERFACEMETHODREF, CONSTANT_INTERFACEMETHODREF);
  49         TAG_TO_TYPE_MAP.put(Tag.STRING, CONSTANT_STRING);
  50         TAG_TO_TYPE_MAP.put(Tag.INTEGER, CONSTANT_INTEGER);


 168             if (!this.equals(type)) {
 169                 String msg = String.format("TESTBUG: CP tag should be a %s, but is %s",
 170                                            this.name(),
 171                                            type.name());
 172                throw new Error(msg);
 173             }
 174         }
 175     }
 176 
 177     public static interface Validator {
 178         void validate(jdk.vm.ci.meta.ConstantPool constantPoolCTVM,
 179                       ConstantTypes cpType,
 180                       DummyClasses dummyClass,
 181                       int index);
 182     }
 183 
 184     public static class TestedCPEntry {
 185         public final String klass;
 186         public final String name;
 187         public final String type;
 188         public final ResolvedJavaMethod[] methods;
 189         public final byte[] opcodes;
 190         public final long accFlags;
 191 
 192         public TestedCPEntry(String klass, String name, String type, byte[] opcodes, long accFlags) {
 193                 this(klass, name, type, null, opcodes, accFlags);
 194         }
 195 
 196         public TestedCPEntry(String klass, String name, String type, ResolvedJavaMethod[] methods, byte[] opcodes, long accFlags) {
 197             this.klass = klass;
 198             this.name = name;
 199             this.type = type;
 200             if (methods != null) {
 201                 this.methods = new ResolvedJavaMethod[methods.length];
 202                 System.arraycopy(methods, 0, this.methods, 0, methods.length);
 203             } else {
 204                 this.methods = null;
 205             }
 206             if (opcodes != null) {
 207                 this.opcodes = new byte[opcodes.length];
 208                 System.arraycopy(opcodes, 0, this.opcodes, 0, opcodes.length);
 209             } else {
 210                 this.opcodes = null;
 211             }
 212             this.accFlags = accFlags;
 213         }
 214 
 215         public TestedCPEntry(String klass, String name, String type, byte[] opcodes) {
 216             this(klass, name, type, opcodes, 0);
 217         }
 218 
 219         public TestedCPEntry(String klass, String name, String type) {
 220             this(klass, name, type, null, 0);
 221         }
 222     }
 223 
 224     public static ConstantTypes mapTagToCPType(Tag tag) {
 225         return TAG_TO_TYPE_MAP.get(tag);


test/compiler/jvmci/compilerToVM/ConstantPoolTestCase.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File