src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/CustomizedBytecodePatternTest.java
author never
Wed, 27 Jun 2018 17:02:41 -0700
changeset 50858 2d3e99a72541
parent 50609 bf414874c28f
child 55509 d58442b8abc1
child 55619 3595fb8794c5
child 58678 9cf78a70fa4f
permissions -rw-r--r--
8205824: Update Graal Reviewed-by: iveresov, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50609
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
     1
/*
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
     4
 *
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
     7
 * published by the Free Software Foundation.
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
     8
 *
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    13
 * accompanied this code).
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    14
 *
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    18
 *
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    21
 * questions.
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    22
 */
50858
2d3e99a72541 8205824: Update Graal
never
parents: 50609
diff changeset
    23
2d3e99a72541 8205824: Update Graal
never
parents: 50609
diff changeset
    24
50609
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    25
package org.graalvm.compiler.core.test;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    26
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    27
import org.objectweb.asm.Opcodes;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    28
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    29
public abstract class CustomizedBytecodePatternTest extends GraalCompilerTest implements Opcodes {
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    30
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    31
    protected Class<?> getClass(String className) throws ClassNotFoundException {
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    32
        return new CachedLoader(CustomizedBytecodePatternTest.class.getClassLoader(), className).findClass(className);
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    33
    }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    34
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    35
    private class CachedLoader extends ClassLoader {
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    36
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    37
        final String className;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    38
        Class<?> loaded;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    39
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    40
        CachedLoader(ClassLoader parent, String className) {
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    41
            super(parent);
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    42
            this.className = className;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    43
        }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    44
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    45
        @Override
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    46
        protected Class<?> findClass(String name) throws ClassNotFoundException {
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    47
            if (name.equals(className)) {
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    48
                if (loaded == null) {
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    49
                    byte[] gen = generateClass(name.replace('.', '/'));
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    50
                    loaded = defineClass(name, gen, 0, gen.length);
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    51
                }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    52
                return loaded;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    53
            } else {
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    54
                return super.findClass(name);
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    55
            }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    56
        }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    57
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    58
    }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    59
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    60
    protected abstract byte[] generateClass(String internalClassName);
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    61
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    62
}