test/hotspot/jtreg/runtime/condy/BadBSMUseTest.java
author lfoltan
Fri, 04 May 2018 12:14:09 -0400
changeset 49987 e4b3cc56e2b2
parent 48959 7b2c4f35fc28
permissions -rw-r--r--
8189916: Dynamic Constant support for Sparc Summary: Change to the template interpreter to support dynamic constant on Sparc. Reviewed-by: coleenp, psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48959
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
     1
/*
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
     4
 *
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
     8
 *
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    13
 * accompanied this code).
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    14
 *
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    18
 *
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    21
 * questions.
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    22
 */
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    23
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    24
/*
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    25
 * @test
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    26
 * @bug 8186211
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    27
 * @summary CONSTANT_Dynamic_info structure's tries to use a BSM index whose signature is for an invokedynamic and vice versa.
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    28
 * @modules java.base/jdk.internal.misc
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    29
 * @library /test/lib
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    30
 * @compile CondyUsesIndyBSM.jcod
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    31
 * @compile IndyUsesCondyBSM.jcod
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    32
 * @run main/othervm -Xverify:all BadBSMUseTest
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    33
 */
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    34
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    35
import jdk.test.lib.process.ProcessTools;
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    36
import jdk.test.lib.process.OutputAnalyzer;
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    37
import jdk.test.lib.compiler.InMemoryJavaCompiler;
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    38
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    39
// BootstrapMethodError expected in each test case below.
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    40
public class BadBSMUseTest {
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    41
    public static void main(String args[]) throws Throwable {
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    42
        // 1. Test a CONSTANT_Dynamic_info's bootstrap_method_attr_index points
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    43
        //    at a BSM meant for a CONSTANT_InvokeDynamic_info
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    44
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("CondyUsesIndyBSM");
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    45
        OutputAnalyzer oa = new OutputAnalyzer(pb.start());
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    46
        oa.shouldContain("In Indybsm target CallSite method foo");
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    47
        oa.shouldContain("BootstrapMethodError: bootstrap method initialization exception");
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    48
        oa.shouldHaveExitValue(1);
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    49
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    50
        // 2. Test a CONSTANT_InvokeDynamic_info's bootstrap_method_attr_index points
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    51
        //    at a BSM meant for a CONSTANT_Dynamic_info
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    52
        pb = ProcessTools.createJavaProcessBuilder("IndyUsesCondyBSM");
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    53
        oa = new OutputAnalyzer(pb.start());
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    54
        oa.shouldContain("In Condybsm");
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    55
        oa.shouldContain("BootstrapMethodError: bootstrap method initialization exception");
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    56
        oa.shouldHaveExitValue(1);
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    57
    }
7b2c4f35fc28 8186211: Negative tests for CONSTANT_Dynamic
lfoltan
parents:
diff changeset
    58
}