hotspot/test/compiler/jvmci/compilerToVM/ConstantPoolTestCase.java
author kshefov
Sat, 20 Feb 2016 11:49:02 +0300
changeset 36305 55c7fe59d6d7
parent 33632 038347770a9e
child 37301 a936b4e01afb
permissions -rw-r--r--
8141618: Change JVMCI compilerToVM constant pool tests to support CP cache Reviewed-by: twisti, dpochepk
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     1
/*
36305
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     4
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     8
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    13
 * accompanied this code).
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    14
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    18
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    21
 * questions.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    22
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    23
 */
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    24
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    25
package compiler.jvmci.compilerToVM;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    26
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    27
import java.util.HashMap;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    28
import java.util.Map;
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    29
import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
36305
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    30
import sun.hotspot.WhiteBox;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    31
import sun.reflect.ConstantPool;
36305
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    32
import sun.reflect.ConstantPool.Tag;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    33
import compiler.jvmci.compilerToVM.ConstantPoolTestsHelper.DummyClasses;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    34
import static compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes.*;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    35
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    36
/**
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    37
 * Common class for jdk.vm.ci.hotspot.CompilerToVM constant pool tests
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    38
 */
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    39
public class ConstantPoolTestCase {
36305
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    40
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    41
    private static final Map<Tag, ConstantTypes> TAG_TO_TYPE_MAP;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    42
    static {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    43
        TAG_TO_TYPE_MAP = new HashMap<>();
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    44
        TAG_TO_TYPE_MAP.put(Tag.CLASS, CONSTANT_CLASS);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    45
        TAG_TO_TYPE_MAP.put(Tag.FIELDREF, CONSTANT_FIELDREF);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    46
        TAG_TO_TYPE_MAP.put(Tag.METHODREF, CONSTANT_METHODREF);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    47
        TAG_TO_TYPE_MAP.put(Tag.INTERFACEMETHODREF, CONSTANT_INTERFACEMETHODREF);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    48
        TAG_TO_TYPE_MAP.put(Tag.STRING, CONSTANT_STRING);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    49
        TAG_TO_TYPE_MAP.put(Tag.INTEGER, CONSTANT_INTEGER);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    50
        TAG_TO_TYPE_MAP.put(Tag.FLOAT, CONSTANT_FLOAT);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    51
        TAG_TO_TYPE_MAP.put(Tag.LONG, CONSTANT_LONG);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    52
        TAG_TO_TYPE_MAP.put(Tag.DOUBLE, CONSTANT_DOUBLE);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    53
        TAG_TO_TYPE_MAP.put(Tag.NAMEANDTYPE, CONSTANT_NAMEANDTYPE);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    54
        TAG_TO_TYPE_MAP.put(Tag.UTF8, CONSTANT_UTF8);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    55
        TAG_TO_TYPE_MAP.put(Tag.METHODHANDLE, CONSTANT_METHODHANDLE);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    56
        TAG_TO_TYPE_MAP.put(Tag.METHODTYPE, CONSTANT_METHODTYPE);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    57
        TAG_TO_TYPE_MAP.put(Tag.INVOKEDYNAMIC, CONSTANT_INVOKEDYNAMIC);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    58
        TAG_TO_TYPE_MAP.put(Tag.INVALID, CONSTANT_INVALID);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    59
    }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    60
    private static final WhiteBox WB = WhiteBox.getWhiteBox();
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    61
    private final Map<ConstantTypes, Validator> typeTests;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    62
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    63
    public static enum ConstantTypes {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    64
        CONSTANT_CLASS {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    65
            @Override
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    66
            public TestedCPEntry getTestedCPEntry(DummyClasses dummyClass, int index) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    67
                ConstantPool constantPoolSS = dummyClass.constantPoolSS;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    68
                checkIndex(constantPoolSS, index);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    69
                Class<?> klass = constantPoolSS.getClassAt(index);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    70
                String klassName = klass.getName();
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    71
                TestedCPEntry[] testedEntries = dummyClass.testedCP.get(this);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    72
                for (TestedCPEntry entry : testedEntries) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    73
                    if (entry.klass.replaceAll("/", "\\.").equals(klassName)) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    74
                        return entry;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    75
                    }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    76
                }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    77
                return null;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    78
            }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    79
        },
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    80
        CONSTANT_FIELDREF {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    81
            @Override
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    82
            public TestedCPEntry getTestedCPEntry(DummyClasses dummyClass, int index) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    83
                return this.getTestedCPEntryForMethodAndField(dummyClass, index);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    84
            }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    85
        },
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    86
        CONSTANT_METHODREF {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    87
            @Override
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    88
            public TestedCPEntry getTestedCPEntry(DummyClasses dummyClass, int index) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    89
                return this.getTestedCPEntryForMethodAndField(dummyClass, index);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    90
            }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    91
        },
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    92
        CONSTANT_INTERFACEMETHODREF {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    93
            @Override
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    94
            public TestedCPEntry getTestedCPEntry(DummyClasses dummyClass, int index) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    95
                return this.getTestedCPEntryForMethodAndField(dummyClass, index);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    96
            }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    97
        },
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    98
        CONSTANT_STRING {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
    99
            @Override
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   100
            public TestedCPEntry getTestedCPEntry(DummyClasses dummyClass, int index) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   101
                ConstantPool constantPoolSS = dummyClass.constantPoolSS;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   102
                checkIndex(constantPoolSS, index);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   103
                String value = constantPoolSS.getStringAt(index);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   104
                TestedCPEntry[] testedEntries = dummyClass.testedCP.get(this);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   105
                for (TestedCPEntry entry : testedEntries) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   106
                    if (entry.name.equals(value)) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   107
                        return entry;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   108
                    }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   109
                }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   110
                return null;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   111
            }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   112
        },
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   113
        CONSTANT_INTEGER,
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   114
        CONSTANT_FLOAT,
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   115
        CONSTANT_LONG,
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   116
        CONSTANT_DOUBLE,
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   117
        CONSTANT_NAMEANDTYPE,
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   118
        CONSTANT_UTF8,
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   119
        CONSTANT_METHODHANDLE,
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   120
        CONSTANT_METHODTYPE,
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   121
        CONSTANT_INVOKEDYNAMIC {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   122
            @Override
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   123
            public TestedCPEntry getTestedCPEntry(DummyClasses dummyClass, int index) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   124
                ConstantPool constantPoolSS = dummyClass.constantPoolSS;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   125
                checkIndex(constantPoolSS, index);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   126
                int nameAndTypeIndex = constantPoolSS.getNameAndTypeRefIndexAt(index);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   127
                String[] info = constantPoolSS.getNameAndTypeRefInfoAt(nameAndTypeIndex);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   128
                TestedCPEntry[] testedEntries = dummyClass.testedCP.get(this);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   129
                for (TestedCPEntry entry : testedEntries) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   130
                    if (info[0].equals(entry.name) && info[1].equals(entry.type)) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   131
                        return entry;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   132
                    }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   133
                }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   134
                return null;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   135
            }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   136
        },
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   137
        CONSTANT_INVALID;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   138
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   139
        public TestedCPEntry getTestedCPEntry(DummyClasses dummyClass, int index) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   140
            return null; // returning null by default
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   141
        }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   142
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   143
        public TestedCPEntry[] getAllCPEntriesForType(DummyClasses dummyClass) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   144
            TestedCPEntry[] toReturn = dummyClass.testedCP.get(this);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   145
            if (toReturn == null) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   146
                return new TestedCPEntry[0];
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   147
            }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   148
            return dummyClass.testedCP.get(this);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   149
        }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   150
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   151
        protected TestedCPEntry getTestedCPEntryForMethodAndField(DummyClasses dummyClass, int index) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   152
            ConstantPool constantPoolSS = dummyClass.constantPoolSS;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   153
            checkIndex(constantPoolSS, index);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   154
            String[] info = constantPoolSS.getMemberRefInfoAt(index);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   155
            TestedCPEntry[] testedEntries = dummyClass.testedCP.get(this);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   156
            for (TestedCPEntry entry : testedEntries) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   157
                if (info[0].equals(entry.klass) && info[1].equals(entry.name) && info[2].equals(entry.type)) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   158
                    return entry;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   159
                }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   160
            }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   161
            return null;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   162
        }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   163
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   164
        protected void checkIndex(ConstantPool constantPoolSS, int index) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   165
            ConstantPool.Tag tag = constantPoolSS.getTagAt(index);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   166
            ConstantTypes type = mapTagToCPType(tag);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   167
            if (!this.equals(type)) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   168
                String msg = String.format("TESTBUG: CP tag should be a %s, but is %s",
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   169
                                           this.name(),
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   170
                                           type.name());
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   171
               throw new Error(msg);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   172
            }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   173
        }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   174
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   175
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   176
    public static interface Validator {
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   177
        void validate(jdk.vm.ci.meta.ConstantPool constantPoolCTVM,
36305
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   178
                      ConstantTypes cpType,
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   179
                      DummyClasses dummyClass,
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   180
                      int index);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   181
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   182
36305
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   183
    public static class TestedCPEntry {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   184
        public final String klass;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   185
        public final String name;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   186
        public final String type;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   187
        public final byte[] opcodes;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   188
        public final long accFlags;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   189
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   190
        public TestedCPEntry(String klass, String name, String type, byte[] opcodes, long accFlags) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   191
            this.klass = klass;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   192
            this.name = name;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   193
            this.type = type;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   194
            if (opcodes != null) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   195
                this.opcodes = new byte[opcodes.length];
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   196
                System.arraycopy(opcodes, 0, this.opcodes, 0, opcodes.length);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   197
            } else {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   198
                this.opcodes = null;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   199
            }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   200
            this.accFlags = accFlags;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   201
        }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   202
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   203
        public TestedCPEntry(String klass, String name, String type, byte[] opcodes) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   204
            this(klass, name, type, opcodes, 0);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   205
        }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   206
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   207
        public TestedCPEntry(String klass, String name, String type) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   208
            this(klass, name, type, null, 0);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   209
        }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   210
    }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   211
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   212
    public static ConstantTypes mapTagToCPType(Tag tag) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   213
        return TAG_TO_TYPE_MAP.get(tag);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   214
    }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   215
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   216
    public ConstantPoolTestCase(Map<ConstantTypes, Validator> typeTests) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   217
        this.typeTests = new HashMap<>();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   218
        this.typeTests.putAll(typeTests);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   219
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   220
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   221
    public void test() {
36305
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   222
        for (DummyClasses dummyClass : DummyClasses.values()) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   223
            boolean isCPCached = WB.getConstantPoolCacheLength(dummyClass.klass) > -1;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   224
            System.out.printf("Testing dummy %s with constant pool cached = %b%n",
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   225
                              dummyClass.klass,
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   226
                              isCPCached);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   227
            HotSpotResolvedObjectType holder = HotSpotResolvedObjectType.fromObjectClass(dummyClass.klass);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   228
            jdk.vm.ci.meta.ConstantPool constantPoolCTVM = holder.getConstantPool();
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   229
            ConstantPool constantPoolSS = dummyClass.constantPoolSS;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   230
            for (int i = 0; i < constantPoolSS.getSize(); i++) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   231
                Tag tag = constantPoolSS.getTagAt(i);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   232
                ConstantTypes cpType = mapTagToCPType(tag);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   233
                if (!typeTests.keySet().contains(cpType)) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   234
                    continue;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   235
                }
36305
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 33632
diff changeset
   236
                typeTests.get(cpType).validate(constantPoolCTVM, cpType, dummyClass, i);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   237
            }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   238
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   239
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   240
}