hotspot/test/runtime/ClassFile/UnsupportedClassFileVersion.java
author stefank
Wed, 20 Apr 2016 09:58:15 +0200
changeset 38000 7519aefb5b86
parent 36851 03e2f4d0a421
child 40631 ed82623d7831
permissions -rw-r--r--
8079843: do_young_space_rescan - comment out of sync with code Reviewed-by: mgerdin, sjohanss, ehelin, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22752
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
     1
/*
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 22752
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
22752
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
     4
 *
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
     8
 *
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    13
 * accompanied this code).
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    14
 *
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    18
 *
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    21
 * questions.
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    22
 */
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    23
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    24
/*
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    25
 * @test
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    26
 * @library /testlibrary
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 22752
diff changeset
    27
 * @modules java.base/jdk.internal.org.objectweb.asm
36851
03e2f4d0a421 8153737: Unsupported Module
chegar
parents: 30604
diff changeset
    28
 *          java.base/jdk.internal.misc
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 22752
diff changeset
    29
 *          java.management
22752
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    30
 * @compile -XDignore.symbol.file UnsupportedClassFileVersion.java
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    31
 * @run main UnsupportedClassFileVersion
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    32
 */
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    33
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    34
import java.io.File;
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    35
import java.io.FileOutputStream;
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    36
import jdk.internal.org.objectweb.asm.ClassWriter;
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    37
import jdk.internal.org.objectweb.asm.MethodVisitor;
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    38
import jdk.internal.org.objectweb.asm.Opcodes;
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29678
diff changeset
    39
import jdk.test.lib.*;
22752
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    40
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    41
public class UnsupportedClassFileVersion implements Opcodes {
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    42
    public static void main(String... args) throws Exception {
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    43
        writeClassFile();
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    44
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, "-cp", ".",  "ClassFile");
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    45
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    46
        output.shouldContain("ClassFile has been compiled by a more recent version of the " +
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    47
                            "Java Runtime (class file version 99.0), this version of " +
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    48
                            "the Java Runtime only recognizes class file versions up to " +
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    49
                            System.getProperty("java.class.version"));
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    50
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    51
        output.shouldHaveExitValue(1);
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    52
    }
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    53
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    54
    public static void writeClassFile() throws Exception {
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    55
        ClassWriter cw = new ClassWriter(0);
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    56
        MethodVisitor mv;
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    57
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    58
        cw.visit(99, ACC_PUBLIC + ACC_SUPER, "ClassFile", null, "java/lang/Object", null);
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    59
        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    60
        mv.visitCode();
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    61
        mv.visitVarInsn(ALOAD, 0);
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    62
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    63
        mv.visitInsn(RETURN);
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    64
        mv.visitMaxs(1, 1);
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    65
        mv.visitEnd();
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    66
        cw.visitEnd();
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    67
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    68
        try (FileOutputStream fos = new FileOutputStream(new File("ClassFile.class"))) {
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    69
             fos.write(cw.toByteArray());
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    70
        }
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    71
    }
5796083e0729 8016644: Improve UnsupportedClassVersionError message
ctornqvi
parents:
diff changeset
    72
}