hotspot/test/compiler/jsr292/VMAnonymousClasses.java
author weijun
Thu, 11 May 2017 07:33:23 +0800
changeset 45063 0909d3bcbacb
parent 40059 c2304140ed64
permissions -rw-r--r--
8179389: X509Certificate generateCRLs is extremely slow using a PEM crl list Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26944
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
     1
/*
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 26944
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
26944
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
     4
 *
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
     8
 *
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    13
 * accompanied this code).
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    14
 *
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    18
 *
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    21
 * questions.
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    22
 */
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    23
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    24
/**
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    25
 * @test
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    26
 * @bug 8058828
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 26944
diff changeset
    27
 * @modules java.base/jdk.internal.org.objectweb.asm
36851
03e2f4d0a421 8153737: Unsupported Module
chegar
parents: 29678
diff changeset
    28
 *          java.base/jdk.internal.misc
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38207
diff changeset
    29
 *
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38207
diff changeset
    30
 * @run main/bootclasspath/othervm -Xbatch compiler.jsr292.VMAnonymousClasses
26944
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    31
 */
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    32
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38207
diff changeset
    33
package compiler.jsr292;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38207
diff changeset
    34
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38207
diff changeset
    35
import jdk.internal.misc.Unsafe;
26944
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    36
import jdk.internal.org.objectweb.asm.ClassWriter;
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    37
import jdk.internal.org.objectweb.asm.MethodVisitor;
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    38
import jdk.internal.org.objectweb.asm.Opcodes;
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    39
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    40
import java.lang.invoke.ConstantCallSite;
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    41
import java.lang.invoke.MethodHandle;
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    42
import java.lang.invoke.MethodHandles;
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    43
import java.lang.invoke.MethodType;
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    44
import java.lang.invoke.MutableCallSite;
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    45
import java.lang.invoke.VolatileCallSite;
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    46
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    47
public class VMAnonymousClasses {
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    48
    static final String TEST_METHOD_NAME = "constant";
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    49
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    50
    static final Unsafe UNSAFE = Unsafe.getUnsafe();
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    51
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    52
    static int getConstantPoolSize(byte[] classFile) {
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    53
        // The first few bytes:
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    54
        // u4 magic;
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    55
        // u2 minor_version;
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    56
        // u2 major_version;
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    57
        // u2 constant_pool_count;
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    58
        return ((classFile[8] & 0xFF) << 8) | (classFile[9] & 0xFF);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    59
    }
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    60
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    61
    static void test(Object value) throws ReflectiveOperationException {
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    62
        System.out.printf("Test: %s", value != null ? value.getClass() : "null");
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    63
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    64
        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    65
        cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, "Test", null, "java/lang/Object", null);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    66
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    67
        MethodVisitor mv = cw.visitMethod(Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC, TEST_METHOD_NAME, "()Ljava/lang/Object;", null, null);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    68
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    69
        String placeholder = "CONSTANT";
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    70
        int index = cw.newConst(placeholder);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    71
        mv.visitLdcInsn(placeholder);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    72
        mv.visitInsn(Opcodes.ARETURN);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    73
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    74
        mv.visitMaxs(0, 0);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    75
        mv.visitEnd();
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    76
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    77
        byte[] classFile = cw.toByteArray();
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    78
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    79
        Object[] cpPatches = new Object[getConstantPoolSize(classFile)];
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    80
        cpPatches[index] = value;
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    81
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    82
        Class<?> test = UNSAFE.defineAnonymousClass(VMAnonymousClasses.class, classFile, cpPatches);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    83
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    84
        Object expectedResult = (value != null) ? value : placeholder;
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    85
        for (int i = 0; i<15000; i++) {
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    86
            Object result = test.getMethod(TEST_METHOD_NAME).invoke(null);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    87
            if (result != expectedResult) {
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    88
                throw new AssertionError(String.format("Wrong value returned: %s != %s", value, result));
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    89
            }
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    90
        }
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    91
        System.out.println(" PASSED");
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    92
    }
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    93
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    94
    public static void main(String[] args) throws ReflectiveOperationException  {
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    95
        // Objects
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    96
        test(new Object());
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    97
        test("TEST");
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    98
        test(new VMAnonymousClasses());
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
    99
        test(null);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   100
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   101
        // Class
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   102
        test(String.class);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   103
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   104
        // Arrays
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   105
        test(new boolean[0]);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   106
        test(new byte[0]);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   107
        test(new char[0]);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   108
        test(new short[0]);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   109
        test(new int[0]);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   110
        test(new long[0]);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   111
        test(new float[0]);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   112
        test(new double[0]);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   113
        test(new Object[0]);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   114
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   115
        // Multi-dimensional arrays
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   116
        test(new byte[0][0]);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   117
        test(new Object[0][0]);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   118
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   119
        // MethodHandle-related
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   120
        MethodType   mt = MethodType.methodType(void.class, String[].class);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   121
        MethodHandle mh = MethodHandles.lookup().findStatic(VMAnonymousClasses.class, "main", mt);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   122
        test(mt);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   123
        test(mh);
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   124
        test(new ConstantCallSite(mh));
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   125
        test(new MutableCallSite(MethodType.methodType(void.class)));
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   126
        test(new VolatileCallSite(MethodType.methodType(void.class)));
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   127
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   128
        System.out.println("TEST PASSED");
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   129
    }
d515f86283be 8058828: Wrong ciConstant type for arrays from ConstantPool::_resolved_reference
vlivanov
parents:
diff changeset
   130
}