test/hotspot/jtreg/runtime/defineAnonClass/UnsafeDefMeths.java
author iignatyev
Thu, 02 Aug 2018 14:40:55 -0700
changeset 51287 7b1ddbafa134
parent 49677 a1a7456dd8b9
child 53739 4dab92cc7aed
permissions -rw-r--r--
8208655: use JTreg skipped status in hotspot tests Reviewed-by: kvn, hseigel, iklam
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49677
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
     1
/*
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
     4
 *
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
     8
 *
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    13
 * accompanied this code).
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    14
 *
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    18
 *
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    21
 * questions.
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    22
 */
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    23
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    24
/*
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    25
 * @test
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    26
 * @bug 8200261
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    27
 * @summary Tests an anonymous class that implements interfaces with default methods.
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    28
 * @library /testlibrary
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    29
 * @modules java.base/jdk.internal.org.objectweb.asm
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    30
 *          java.management
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    31
 * @compile -XDignore.symbol.file=true UnsafeDefMeths.java
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    32
 * @run main UnsafeDefMeths
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    33
 */
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    34
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    35
import jdk.internal.org.objectweb.asm.ClassWriter;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    36
import jdk.internal.org.objectweb.asm.MethodVisitor;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    37
import jdk.internal.org.objectweb.asm.Type;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    38
import sun.misc.Unsafe;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    39
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    40
import java.lang.invoke.MethodType;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    41
import java.lang.reflect.Field;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    42
import java.lang.reflect.Method;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    43
import java.util.stream.Collectors;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    44
import java.util.stream.Stream;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    45
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    46
import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PRIVATE;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    47
import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PUBLIC;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    48
import static jdk.internal.org.objectweb.asm.Opcodes.ACC_SUPER;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    49
import static jdk.internal.org.objectweb.asm.Opcodes.ALOAD;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    50
import static jdk.internal.org.objectweb.asm.Opcodes.ARETURN;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    51
import static jdk.internal.org.objectweb.asm.Opcodes.DUP;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    52
import static jdk.internal.org.objectweb.asm.Opcodes.GETFIELD;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    53
import static jdk.internal.org.objectweb.asm.Opcodes.INVOKESPECIAL;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    54
import static jdk.internal.org.objectweb.asm.Opcodes.PUTFIELD;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    55
import static jdk.internal.org.objectweb.asm.Opcodes.RETURN;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    56
import static jdk.internal.org.objectweb.asm.Opcodes.V1_8;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    57
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    58
public class UnsafeDefMeths {
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    59
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    60
    static final Unsafe UNSAFE;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    61
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    62
    static {
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    63
        try {
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    64
            Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    65
            unsafeField.setAccessible(true);
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    66
            UNSAFE = (Unsafe) unsafeField.get(null);
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    67
        }
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    68
        catch (Exception e) {
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    69
            throw new InternalError(e);
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    70
        }
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    71
    }
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    72
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    73
    interface Resource {
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    74
        Pointer ptr();
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    75
    }
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    76
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    77
    interface Struct extends Resource {
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    78
       StructPointer ptr();
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    79
    }
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    80
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    81
    interface Pointer { }
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    82
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    83
    interface StructPointer extends Pointer { }
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    84
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    85
    interface I extends Struct {
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    86
        void m();
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    87
    }
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    88
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    89
    static String IMPL_PREFIX = "$$impl";
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    90
    static String PTR_FIELD_NAME = "ptr";
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    91
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    92
    public static void main(String[] args) throws Throwable {
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    93
        byte[] bytes = new UnsafeDefMeths().generate(I.class);
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    94
        Class<?> cl = UNSAFE.defineAnonymousClass(I.class, bytes, new Object[0]);
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    95
        I i = (I)cl.getConstructors()[0].newInstance(new Object[] { null }); //exception here!
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    96
    }
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    97
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    98
    // Generate a class similar to:
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
    99
    //
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   100
    // public class UnsafeDefMeths$I$$impl implements UnsafeDefMeths$I, UnsafeDefMeths$Struct {
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   101
    //
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   102
    //     public UnsafeDefMeths$StructPointer ptr;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   103
    //
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   104
    //     public UnsafeDefMeths$I$$impl(UnsafeDefMeths$StructPointer p) {
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   105
    //         ptr = p;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   106
    //     }
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   107
    //
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   108
    //     public UnsafeDefMeths$StructPointer ptr() {
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   109
    //         return ptr;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   110
    //     }
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   111
    // }
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   112
    //
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   113
    byte[] generate(Class<?> iface) {
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   114
        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   115
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   116
        String ifaceTypeName = Type.getInternalName(iface);
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   117
        String proxyClassName = ifaceTypeName + IMPL_PREFIX;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   118
        // class definition
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   119
        cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, proxyClassName,
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   120
                desc(Object.class) + desc(ifaceTypeName) + desc(Struct.class),
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   121
                name(Object.class),
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   122
                new String[] { ifaceTypeName, name(Struct.class) });
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   123
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   124
        cw.visitField(ACC_PUBLIC, PTR_FIELD_NAME, desc(StructPointer.class), desc(StructPointer.class), null);
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   125
        cw.visitEnd();
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   126
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   127
        // constructor
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   128
        MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>",
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   129
                meth(desc(void.class), desc(StructPointer.class)),
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   130
                meth(desc(void.class), desc(StructPointer.class)), null);
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   131
        mv.visitCode();
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   132
        mv.visitVarInsn(ALOAD, 0);
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   133
        mv.visitInsn(DUP);
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   134
        mv.visitMethodInsn(INVOKESPECIAL, name(Object.class), "<init>", meth(desc(void.class)), false);
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   135
        mv.visitVarInsn(ALOAD, 1);
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   136
        // Execution of this PUTFIELD instruction causes the bug's ClassNotFoundException.
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   137
        mv.visitFieldInsn(PUTFIELD, proxyClassName, PTR_FIELD_NAME, desc(StructPointer.class));
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   138
        mv.visitInsn(RETURN);
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   139
        mv.visitMaxs(0, 0);
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   140
        mv.visitEnd();
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   141
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   142
        // ptr() impl
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   143
        mv = cw.visitMethod(ACC_PUBLIC, PTR_FIELD_NAME, meth(desc(StructPointer.class)),
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   144
                meth(desc(StructPointer.class)), null);
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   145
        mv.visitCode();
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   146
        mv.visitVarInsn(ALOAD, 0);
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   147
        mv.visitFieldInsn(GETFIELD, proxyClassName, PTR_FIELD_NAME, desc(StructPointer.class));
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   148
        mv.visitInsn(ARETURN);
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   149
        mv.visitMaxs(0, 0);
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   150
        mv.visitEnd();
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   151
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   152
        return cw.toByteArray();
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   153
    }
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   154
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   155
    String name(Class<?> clazz) {
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   156
        if (clazz.isPrimitive()) {
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   157
            throw new IllegalStateException();
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   158
        } else if (clazz.isArray()) {
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   159
            return desc(clazz);
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   160
        } else {
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   161
            return clazz.getName().replaceAll("\\.", "/");
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   162
        }
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   163
    }
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   164
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   165
    String desc(Class<?> clazz) {
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   166
        String mdesc = MethodType.methodType(clazz).toMethodDescriptorString();
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   167
        return mdesc.substring(mdesc.indexOf(')') + 1);
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   168
    }
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   169
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   170
    String desc(String clazzName) {
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   171
        return "L" + clazzName + ";";
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   172
    }
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   173
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   174
    String gen(String clazz, String... typeargs) {
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   175
        return clazz.substring(0, clazz.length() - 1) + Stream.of(typeargs).collect(Collectors.joining("", "<", ">")) + ";";
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   176
    }
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   177
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   178
    String meth(String restype, String... argtypes) {
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   179
        return Stream.of(argtypes).collect(Collectors.joining("", "(", ")")) + restype;
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   180
    }
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   181
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   182
    String meth(Method m) {
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   183
        return MethodType.methodType(m.getReturnType(), m.getParameterTypes()).toMethodDescriptorString();
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   184
    }
a1a7456dd8b9 8200261: Regression with JVM anonymous class
hseigel
parents:
diff changeset
   185
}