test/hotspot/jtreg/runtime/InvocationTests/shared/GenericClassGenerator.java
author hseigel
Wed, 26 Jun 2019 09:06:32 -0400
changeset 55497 d3a33953b936
permissions -rw-r--r--
8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo Summary: Add JTReg compatible main programs to run tests for various invoke* instructions Reviewed-by: lfoltan, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55497
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
     1
/*
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
     2
 * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
     4
 *
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
     8
 *
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    13
 * accompanied this code).
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    14
 *
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    18
 *
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    21
 * questions.
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    22
 *
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    23
 */
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    24
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    25
package shared;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    26
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    27
import jdk.internal.org.objectweb.asm.ClassWriter;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    28
import static jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_FRAMES;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    29
import static jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_MAXS;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    30
import jdk.internal.org.objectweb.asm.MethodVisitor;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    31
import static jdk.internal.org.objectweb.asm.Opcodes.*;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    32
import static shared.AccessCheck.*;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    33
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    34
public class GenericClassGenerator<T extends GenericClassGenerator> {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    35
    private static final String targetMethodName = Utils.TARGET_METHOD_NAME;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    36
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    37
    private int flags = 0;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    38
    private ClassWriter writer;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    39
    private String fullClassName = null;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    40
    private String parentClassName = null;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    41
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    42
    /*******************************************************************/
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    43
    public GenericClassGenerator(String fullClassName) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    44
        this(fullClassName, "java/lang/Object");
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    45
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    46
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    47
    /*******************************************************************/
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    48
    public GenericClassGenerator(String fullClassName, String parentClassName ) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    49
        this(fullClassName, parentClassName, ACC_PUBLIC);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    50
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    51
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    52
    /*******************************************************************/
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    53
    public GenericClassGenerator(String fullClassName, String parentClassName, int flags) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    54
        this(fullClassName, parentClassName, flags, new String[0]);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    55
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    56
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    57
    /*******************************************************************/
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    58
    public GenericClassGenerator(String fullClassName, String parentClassName, int flags, String[] implementedInterfaces) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    59
        writer = new ClassWriter(COMPUTE_FRAMES | COMPUTE_MAXS);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    60
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    61
        this.fullClassName = fullClassName;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    62
        this.flags = flags;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    63
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    64
        // Construct simple class
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    65
        if (parentClassName != null) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    66
            this.parentClassName = getInternalName(parentClassName);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    67
        } else {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    68
            this.parentClassName = "java/lang/Object";
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    69
        }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    70
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    71
        String parent = this.parentClassName;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    72
        String name = getInternalName(fullClassName);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    73
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    74
        if (Utils.isACC_SUPER) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    75
            flags = flags | ACC_SUPER;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    76
        }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    77
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    78
        writer.visit(Utils.version, flags, name, null, parent, implementedInterfaces);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    79
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    80
        // Add constructor
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    81
        if ( !isInterface(flags) ) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    82
            MethodVisitor m =
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    83
                    writer.visitMethod(
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    84
                            ACC_PUBLIC
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    85
                            , "<init>"
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    86
                            , "()V"
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    87
                            , null
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    88
                            , null
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    89
                    );
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    90
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    91
            m.visitCode();
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    92
            m.visitVarInsn(ALOAD, 0);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    93
            m.visitMethodInsn(
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    94
                      INVOKESPECIAL
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    95
                    , getInternalName(parent)
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    96
                    , "<init>"
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    97
                    , "()V"
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    98
            );
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
    99
            m.visitInsn(RETURN);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   100
            m.visitEnd();
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   101
            m.visitMaxs(0,0);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   102
        }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   103
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   104
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   105
    /*******************************************************************/
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   106
    protected static String getInternalName(String fullClassName) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   107
        return fullClassName.replaceAll("\\.", "/");
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   108
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   109
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   110
    /*******************************************************************/
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   111
    public T addTargetConstructor(AccessType access) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   112
        // AccessType.UNDEF means that the target method isn't defined, so do nothing
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   113
        if (access == AccessType.UNDEF || isInterface(flags) ) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   114
            return (T)this;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   115
        }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   116
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   117
        // Add target constructor
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   118
        int methodAccessType = access.value();
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   119
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   120
        MethodVisitor m =
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   121
                writer.visitMethod(
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   122
                        methodAccessType
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   123
                        , "<init>"
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   124
                        , "(I)V"
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   125
                        , null
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   126
                        , null
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   127
                );
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   128
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   129
        // Add a call to parent constructor
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   130
        m.visitCode();
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   131
        m.visitVarInsn(ALOAD, 0);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   132
        m.visitMethodInsn(
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   133
                  INVOKESPECIAL
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   134
                , getInternalName(parentClassName)
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   135
                , "<init>"
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   136
                , "()V"
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   137
        );
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   138
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   139
        // Add result reporting
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   140
        String shortName = fullClassName.substring(fullClassName.lastIndexOf('.') + 1);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   141
        m.visitLdcInsn(shortName+".<init>");
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   142
        m.visitFieldInsn(
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   143
                  PUTSTATIC
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   144
                , "Result"
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   145
                , "value"
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   146
                , "Ljava/lang/String;"
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   147
        );
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   148
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   149
        m.visitInsn(RETURN);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   150
        m.visitEnd();
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   151
        m.visitMaxs(0,0);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   152
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   153
        return (T)this;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   154
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   155
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   156
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   157
    /*******************************************************************/
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   158
    public T addTargetMethod(AccessType access) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   159
        return addTargetMethod(access, 0);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   160
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   161
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   162
    /*******************************************************************/
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   163
    public T addTargetMethod(AccessType access, int additionalFlags) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   164
        // AccessType.UNDEF means that the target method isn't defined, so do nothing
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   165
        if (access == AccessType.UNDEF) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   166
            return (T)this;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   167
        }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   168
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   169
        // Add target method
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   170
        int methodAccessType = access.value();
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   171
        if ( isInterface(flags) || isAbstract(flags) ) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   172
            methodAccessType |= ACC_ABSTRACT;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   173
        }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   174
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   175
        // Skip method declaration for abstract private case, which doesn't pass
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   176
        // classfile verification stage
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   177
        if ( isPrivate(methodAccessType) && isAbstract(methodAccessType) ) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   178
            return (T)this;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   179
        }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   180
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   181
        MethodVisitor m =
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   182
                writer.visitMethod(
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   183
                        methodAccessType | additionalFlags
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   184
                        , targetMethodName
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   185
                        , "()Ljava/lang/String;"
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   186
                        , null
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   187
                        , null
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   188
                );
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   189
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   190
        // Don't generate body if the method is abstract
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   191
        if ( (methodAccessType & ACC_ABSTRACT) == 0 ) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   192
            String shortName = fullClassName.substring(fullClassName.lastIndexOf('.') + 1);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   193
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   194
            // Simply returns info about itself
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   195
            m.visitCode();
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   196
            m.visitLdcInsn(shortName+"."+targetMethodName);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   197
            m.visitInsn(ARETURN);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   198
            m.visitEnd();
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   199
            m.visitMaxs(0,0);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   200
        }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   201
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   202
        return (T)this;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   203
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   204
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   205
    /*******************************************************************/
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   206
    public T addField(int access, String name, String type) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   207
        writer.visitField(
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   208
                access
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   209
                , name
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   210
                , getInternalName(type)
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   211
                , null
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   212
                , null
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   213
        )
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   214
                .visitEnd();
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   215
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   216
        return (T)this;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   217
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   218
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   219
    /*******************************************************************/
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   220
    // Add target method call site into current class
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   221
    public T addCaller(String targetClass, int callType) {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   222
        MethodVisitor m = writer.visitMethod(
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   223
                ACC_PUBLIC | ACC_STATIC
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   224
                , "call"
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   225
                , String.format( "(L%s;)Ljava/lang/String;" , getInternalName(targetClass))
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   226
                , null
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   227
                , null
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   228
        );
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   229
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   230
        m.visitCode();
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   231
        m.visitVarInsn(ALOAD, 0);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   232
        m.visitMethodInsn(
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   233
                  callType
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   234
                , getInternalName(targetClass)
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   235
                , targetMethodName
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   236
                , "()Ljava/lang/String;"
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   237
        );
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   238
        m.visitInsn(ARETURN);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   239
        m.visitEnd();
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   240
        m.visitMaxs(0,0);
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   241
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   242
        return (T)this;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   243
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   244
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   245
    /*******************************************************************/
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   246
    public byte[] getClassFile() {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   247
        writer.visitEnd();
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   248
        return writer.toByteArray();
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   249
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   250
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   251
    /*******************************************************************/
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   252
    public String getFullClassName() {
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   253
        return fullClassName;
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   254
    }
d3a33953b936 8224137: Analyze and port invocation tests to jtreg and co-locate to jdk repo
hseigel
parents:
diff changeset
   255
}