--- old/src/hotspot/share/classfile/classFileParser.cpp 2018-07-18 14:33:17.339069286 -0400 +++ new/src/hotspot/share/classfile/classFileParser.cpp 2018-07-18 14:33:16.551862329 -0400 @@ -3486,15 +3486,18 @@ inner_classes_attribute_length = attribute_length; cfs->skip_u1(inner_classes_attribute_length, CHECK); } else if (tag == vmSymbols::tag_value_types()) { - // Check for ValueTypes tag - if (parsed_value_types_attribute) { - classfile_parse_error("Multiple ValueTypes attributes in class file %s", CHECK); - } else { - parsed_value_types_attribute = true; + // Ignore ValueTypes attribute unless value type support is enabled. + if (supports_value_types()) { + // Check for ValueTypes tag + if (parsed_value_types_attribute) { + classfile_parse_error("Multiple ValueTypes attributes in class file %s", CHECK); + } else { + parsed_value_types_attribute = true; + } + value_types_attribute_start = cfs->current(); + value_types_attribute_length = attribute_length; } - value_types_attribute_start = cfs->current(); - value_types_attribute_length = attribute_length; - cfs->skip_u1(value_types_attribute_length, CHECK); + cfs->skip_u1(attribute_length, CHECK); } else if (tag == vmSymbols::tag_synthetic()) { // Check for Synthetic tag // Shouldn't we check that the synthetic flags wasn't already set? - not required in spec @@ -4701,7 +4704,7 @@ bool ClassFileParser::supports_value_types() const { // Value types are only supported by class file version 55 and later - return _major_version >= JAVA_11_VERSION; + return EnableValhalla && _major_version >= JAVA_11_VERSION; } // Attach super classes and interface classes to class loader data --- old/src/hotspot/share/classfile/verifier.cpp 2018-07-18 14:33:19.008621705 -0400 +++ new/src/hotspot/share/classfile/verifier.cpp 2018-07-18 14:33:18.230100578 -0400 @@ -1630,6 +1630,12 @@ &bcs, ¤t_frame, cp, false, CHECK_VERIFY(this)); no_control_flow = false; break; case Bytecodes::_withfield : + if (!EnableValhalla) { + verify_error(ErrorContext::bad_code(bci), + "The withfield instruction in class %s requires option -XX:+EnableValhalla", + _klass->external_name()); + return; + } if (_klass->major_version() < VALUETYPE_MAJOR_VERSION) { class_format_error( "withfield not supported by this class file version (%d.%d), class %s", @@ -1676,6 +1682,12 @@ } case Bytecodes::_defaultvalue : { + if (!EnableValhalla) { + verify_error(ErrorContext::bad_code(bci), + "The defaultvalue instruction in class %s requires option -XX:+EnableValhalla", + _klass->external_name()); + return; + } if (_klass->major_version() < VALUETYPE_MAJOR_VERSION) { class_format_error( "defaultvalue not supported by this class file version (%d.%d), class %s", --- old/src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java 2018-07-18 14:33:21.163734798 -0400 +++ new/src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java 2018-07-18 14:33:20.385464161 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -55,7 +55,7 @@ private static final Unsafe UNSAFE = Unsafe.getUnsafe(); private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess(); - private static final int CLASSFILE_VERSION = 52; + private static final int CLASSFILE_VERSION = 55; private static final String METHOD_DESCRIPTOR_VOID = Type.getMethodDescriptor(Type.VOID_TYPE); private static final String JAVA_LANG_OBJECT = "java/lang/Object"; private static final String NAME_CTOR = ""; --- old/src/java.base/share/classes/jdk/experimental/value/MethodHandleBuilder.java 2018-07-18 14:33:23.246767666 -0400 +++ new/src/java.base/share/classes/jdk/experimental/value/MethodHandleBuilder.java 2018-07-18 14:33:22.470418752 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -93,7 +93,7 @@ IsolatedMethodBuilder isolatedMethodBuilder = new IsolatedMethodBuilder(className, lookup); isolatedMethodBuilder .withSuperclass(Object.class) - .withMajorVersion(52) + .withMajorVersion(55) .withMinorVersion(0) .withFlags(Flag.ACC_PUBLIC) .withValueTypes(valueTypes) --- /dev/null 2018-07-05 12:06:57.010000296 -0400 +++ new/test/hotspot/jtreg/runtime/valhalla/valuetypes/verifier/NewVTOpcodes.java 2018-07-18 14:33:24.004284144 -0400 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +/* + * @test + * @summary test that class files get VerifyError exceptions if they have + * withfield or defaultvalue instructions but not -XX:+EnableValhalla. + * @compile vrfTests.jcod + * @run main/othervm -XX:-EnableValhalla NewVTOpcodes + */ +public class NewVTOpcodes { + + public static void runTest(String test_name, String message) throws Exception { + System.out.println("Testing: " + test_name); + try { + Class newClass = Class.forName(test_name); + } catch (java.lang.VerifyError e) { + if (!e.getMessage().contains(message)) { + throw new RuntimeException( "Wrong VerifyError: " + e.getMessage()); + } + } + } + + public static void main(String[] args) throws Exception { + + // Test withfield and defaultvalue opcodes cause VerifyError exceptions unless + // -XX:+EnableValhalla is specified. + runTest("HasWithfield", + "withfield instruction in class HasWithfield requires option -XX:+EnableValhalla"); + runTest("HasDefaultvalue", + "defaultvalue instruction in class HasDefaultvalue requires option -XX:+EnableValhalla"); + } +} + --- /dev/null 2018-07-05 12:06:57.010000296 -0400 +++ new/test/hotspot/jtreg/runtime/valhalla/valuetypes/verifier/vrfTests.jcod 2018-07-18 14:33:25.694306413 -0400 @@ -0,0 +1,357 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +// This file contains multiple illegal value type classes that should cause +// ClassFormatError exceptions when attempted to be loaded. +// +// The .jcod classes were originally generated from this Java file and then +// modified to cause ClassFormatError or ClassCircularityError exceptions. The +// '(bad)' comments in most of the tests show where the modifications were made. +// +// final __ByValue class Value { +// static final Value VT = makeValue(0x01234567); +// final int int_v; +// Value() { +// int_v = 1; +// } +// static Value makeValue(int x) { +// Value v = __MakeDefault Value(); +// v = __WithField(v.int_v, x); +// return v; +// } +// } + +////////////////////////////////////////////////////////////////////// + +// Test that a defaultvalue opcodes causes a VerifyError exception if +// -XX:+EnableValhalla is not specified. +// +class HasDefaultvalue { + 0xCAFEBABE; + 0; // minor version + 55; // version + [28] { // Constant Pool + ; // first element is empty + Method #7 #23; // #1 at 0x0A + Field #3 #24; // #2 at 0x0F + class #9; // #3 at 0x14 + int 0x01234567; // #4 at 0x17 + Method #3 #25; // #5 at 0x1C + Field #3 #26; // #6 at 0x21 + class #27; // #7 at 0x26 + Utf8 "VT"; // #8 at 0x29 + Utf8 "HasDefaultvalue"; // #9 at 0x2E + Utf8 "ValueTypes"; // #10 at 0x36 + Utf8 "LHasDefaultvalue;"; // #11 at 0x43 + Utf8 "int_v"; // #12 at 0x4D + Utf8 "I"; // #13 at 0x55 + Utf8 ""; // #14 at 0x59 + Utf8 "()V"; // #15 at 0x62 + Utf8 "Code"; // #16 at 0x68 + Utf8 "LineNumberTable"; // #17 at 0x6F + Utf8 "makeHasDefaultvalue"; // #18 at 0x81 + Utf8 "(I)LHasDefaultvalue;"; // #19 at 0x8D + Utf8 ""; // #20 at 0x9A + Utf8 "SourceFile"; // #21 at 0xA5 + Utf8 "HasDefaultvalue.java"; // #22 at 0xB2 + NameAndType #14 #15; // #23 at 0xBF + NameAndType #12 #13; // #24 at 0xC4 + NameAndType #18 #19; // #25 at 0xC9 + NameAndType #8 #11; // #26 at 0xCE + Utf8 "java/lang/Object"; // #27 at 0xD3 + } // Constant Pool + + 0x0130; // access [ ACC_VALUE ACC_SUPER ACC_FINAL ] + #3;// this_cpx + #7;// super_cpx + + [0] { // Interfaces + } // Interfaces + + [2] { // fields + { // Member at 0xF0 + 0x0118; // access + #8; // name_cpx + #11; // sig_cpx + [0] { // Attributes + } // Attributes + } // Member + ; + { // Member at 0xF8 + 0x0010; // access [ ACC_FINAL ] + #12; // name_cpx + #13; // sig_cpx + [0] { // Attributes + } // Attributes + } // Member + } // fields + + [3] { // methods + { // Member at 0x0102 + 0x0000; // access + #14; // name_cpx + #15; // sig_cpx + [1] { // Attributes + Attr(#16, 42) { // Code at 0x010A + 2; // max_stack + 1; // max_locals + Bytes[10]{ + 0x2AB700012A04B500; + 0x02B1; + }; + [0] { // Traps + } // end Traps + [1] { // Attributes + Attr(#17, 14) { // LineNumberTable at 0x0126 + [3] { // LineNumberTable + 0 4; // at 0x0132 + 4 5; // at 0x0136 + 9 6; // at 0x013A + } + } // end LineNumberTable + } // Attributes + } // end Code + } // Attributes + } // Member + ; + { // Member at 0x013A + 0x0008; // access + #18; // name_cpx + #19; // sig_cpx + [1] { // Attributes + Attr(#16, 44) { // Code at 0x0142 + 2; // max_stack + 2; // max_locals + Bytes[12]{ + 0xCB00034C2B1ACC00; + 0x024C2BB0; + }; + [0] { // Traps + } // end Traps + [1] { // Attributes + Attr(#17, 14) { // LineNumberTable at 0x0160 + [3] { // LineNumberTable + 0 8; // at 0x016C + 4 9; // at 0x0170 + 10 10; // at 0x0174 + } + } // end LineNumberTable + } // Attributes + } // end Code + } // Attributes + } // Member + ; + { // Member at 0x0174 + 0x0008; // access + #20; // name_cpx + #15; // sig_cpx + [1] { // Attributes + Attr(#16, 33) { // Code at 0x017C + 1; // max_stack + 0; // max_locals + Bytes[9]{ + 0x1204B80005B30006; + 0xB1; + }; + [0] { // Traps + } // end Traps + [1] { // Attributes + Attr(#17, 6) { // LineNumberTable at 0x0197 + [1] { // LineNumberTable + 0 2; // at 0x01A3 + } + } // end LineNumberTable + } // Attributes + } // end Code + } // Attributes + } // Member + } // methods + + [2] { // Attributes + Attr(#21, 2) { // SourceFile at 0x01A5 + #22; + } // end SourceFile + ; + Attr(#10, 4) { // ValueTypes at 0x01AD + 0x00010003; + } // end ValueTypes + } // Attributes +} + +////////////////////////////////////////////////////////////////////// + +// Test that a withfield opcode causes a VerifyError exception if +// -XX:+EnableValhalla is not specified. +// +class HasWithfield { + 0xCAFEBABE; + 0; // minor version + 55; // version + [28] { // Constant Pool + ; // first element is empty + Method #7 #23; // #1 at 0x0A + Field #3 #24; // #2 at 0x0F + class #9; // #3 at 0x14 + int 0x01234567; // #4 at 0x17 + Method #3 #25; // #5 at 0x1C + Field #3 #26; // #6 at 0x21 + class #27; // #7 at 0x26 + Utf8 "VT"; // #8 at 0x29 + Utf8 "HasWithfield"; // #9 at 0x2E + Utf8 "ValueTypes"; // #10 at 0x36 + Utf8 "LHasWithfield;"; // #11 at 0x43 + Utf8 "int_v"; // #12 at 0x4D + Utf8 "I"; // #13 at 0x55 + Utf8 ""; // #14 at 0x59 + Utf8 "()V"; // #15 at 0x62 + Utf8 "Code"; // #16 at 0x68 + Utf8 "LineNumberTable"; // #17 at 0x6F + Utf8 "makeHasWithfield"; // #18 at 0x81 + Utf8 "(I)LHasWithfield;"; // #19 at 0x8D + Utf8 ""; // #20 at 0x9A + Utf8 "SourceFile"; // #21 at 0xA5 + Utf8 "HasWithfield.java"; // #22 at 0xB2 + NameAndType #14 #15; // #23 at 0xBF + NameAndType #12 #13; // #24 at 0xC4 + NameAndType #18 #19; // #25 at 0xC9 + NameAndType #8 #11; // #26 at 0xCE + Utf8 "java/lang/Object"; // #27 at 0xD3 + } // Constant Pool + + 0x0130; // access [ ACC_VALUE ACC_SUPER ACC_FINAL ] + #3;// this_cpx + #7;// super_cpx + + [0] { // Interfaces + } // Interfaces + + [2] { // fields + { // Member at 0xF0 + 0x0118; // access + #8; // name_cpx + #11; // sig_cpx + [0] { // Attributes + } // Attributes + } // Member + ; + { // Member at 0xF8 + 0x0010; // access [ ACC_FINAL ] + #12; // name_cpx + #13; // sig_cpx + [0] { // Attributes + } // Attributes + } // Member + } // fields + + [3] { // methods + { // Member at 0x0102 + 0x0000; // access + #14; // name_cpx + #15; // sig_cpx + [1] { // Attributes + Attr(#16, 42) { // Code at 0x010A + 2; // max_stack + 1; // max_locals + Bytes[10]{ + 0x2AB700012A04B500; + 0x02B1; + }; + [0] { // Traps + } // end Traps + [1] { // Attributes + Attr(#17, 14) { // LineNumberTable at 0x0126 + [3] { // LineNumberTable + 0 4; // at 0x0132 + 4 5; // at 0x0136 + 9 6; // at 0x013A + } + } // end LineNumberTable + } // Attributes + } // end Code + } // Attributes + } // Member + ; + { // Member at 0x013A + 0x0008; // access + #18; // name_cpx + #19; // sig_cpx + [1] { // Attributes + Attr(#16, 44) { // Code at 0x0142 + 2; // max_stack + 2; // max_locals + Bytes[12]{ + 0xCC00034C2B1ACC00; // Change defaultvalue (oxCB) to withfield (0xCC) + 0x024C2BB0; + }; + [0] { // Traps + } // end Traps + [1] { // Attributes + Attr(#17, 14) { // LineNumberTable at 0x0160 + [3] { // LineNumberTable + 0 8; // at 0x016C + 4 9; // at 0x0170 + 10 10; // at 0x0174 + } + } // end LineNumberTable + } // Attributes + } // end Code + } // Attributes + } // Member + ; + { // Member at 0x0174 + 0x0008; // access + #20; // name_cpx + #15; // sig_cpx + [1] { // Attributes + Attr(#16, 33) { // Code at 0x017C + 1; // max_stack + 0; // max_locals + Bytes[9]{ + 0x1204B80005B30006; + 0xB1; + }; + [0] { // Traps + } // end Traps + [1] { // Attributes + Attr(#17, 6) { // LineNumberTable at 0x0197 + [1] { // LineNumberTable + 0 2; // at 0x01A3 + } + } // end LineNumberTable + } // Attributes + } // end Code + } // Attributes + } // Member + } // methods + + [2] { // Attributes + Attr(#21, 2) { // SourceFile at 0x01A5 + #22; + } // end SourceFile + ; + Attr(#10, 4) { // ValueTypes at 0x01AD + 0x00010003; + } // end ValueTypes + } // Attributes +} // end class HasWithfield --- old/test/hotspot/jtreg/runtime/valhalla/valuetypes/classfileparser/BadACCValue.java 2018-07-18 14:33:28.157867220 -0400 +++ /dev/null 2018-07-05 12:06:57.010000296 -0400 @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ -/* - * @test - * @summary test that if a class file has ACC_VALUE set then it must be run - * with option -XX:+EnableValhalla. - * @compile cfpTests.jcod - * @run main/othervm -XX:-EnableValhalla BadACCValue - */ - -public class BadACCValue { - - public static void runTest(String test_name, String message) throws Exception { - System.out.println("Testing: " + test_name); - try { - Class newClass = Class.forName(test_name); - } catch (java.lang.ClassFormatError e) { - if (!e.getMessage().contains(message)) { - throw new RuntimeException( "Wrong ClassFormatError: " + e.getMessage()); - } - } - } - - public static void main(String[] args) throws Exception { - - // Test ACC_VALUE causes a CFE unless -XX:+EnableValhalla is specified. - runTest("ValueFieldNotFinal", - "Class modifier ACC_VALUE in class ValueFieldNotFinal requires option -XX:+EnableValhalla"); - } -}