8266530: HotSpot changes for JEP 306

Reviewed-by: dholmes, hseigel
This commit is contained in:
Joe Darcy 2021-06-01 22:00:48 +00:00
parent 0ae4ceb413
commit 8624cb53cd
6 changed files with 420 additions and 3 deletions

View File

@ -2276,7 +2276,7 @@ Method* ClassFileParser::parse_method(const ClassFileStream* const cfs,
if (_major_version < 51) { // backward compatibility
flags = JVM_ACC_STATIC;
} else if ((flags & JVM_ACC_STATIC) == JVM_ACC_STATIC) {
flags &= JVM_ACC_STATIC | JVM_ACC_STRICT;
flags &= JVM_ACC_STATIC | (_major_version <= JAVA_16_VERSION ? JVM_ACC_STRICT : 0);
} else {
classfile_parse_error("Method <clinit> is not static in class file %s", THREAD);
return NULL;
@ -4649,6 +4649,7 @@ void ClassFileParser::verify_legal_method_modifiers(jint flags,
const bool is_protected = (flags & JVM_ACC_PROTECTED) != 0;
const bool major_gte_1_5 = _major_version >= JAVA_1_5_VERSION;
const bool major_gte_8 = _major_version >= JAVA_8_VERSION;
const bool major_gte_17 = _major_version >= JAVA_17_VERSION;
const bool is_initializer = (name == vmSymbols::object_initializer_name());
bool is_illegal = false;
@ -4667,7 +4668,7 @@ void ClassFileParser::verify_legal_method_modifiers(jint flags,
// ACC_STRICT, or ACC_SYNCHRONIZED flags set. No need to
// check for ACC_FINAL, ACC_NATIVE or ACC_SYNCHRONIZED as
// those flags are illegal irrespective of ACC_ABSTRACT being set or not.
(is_abstract && (is_private || is_static || is_strict))) {
(is_abstract && (is_private || is_static || (!major_gte_17 && is_strict)))) {
is_illegal = true;
}
} else if (major_gte_1_5) {
@ -4694,7 +4695,7 @@ void ClassFileParser::verify_legal_method_modifiers(jint flags,
} else { // not initializer
if (is_abstract) {
if ((is_final || is_native || is_private || is_static ||
(major_gte_1_5 && (is_synchronized || is_strict)))) {
(major_gte_1_5 && (is_synchronized || (!major_gte_17 && is_strict))))) {
is_illegal = true;
}
}

View File

@ -0,0 +1,70 @@
/*
* Copyright (c) 2021, 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.
*/
// Code below is equivalent to:
// public interface AbstractStrictfpIntMethod60 {
// public abstract double bar();
// }
class AbstractStrictfpIntMethod60 {
0xCAFEBABE;
0; // minor version
60; // version
[9] { // Constant Pool
; // first element is empty
class #2; // #1 at 0x0A
Utf8 "AbstractStrictfpIntMethod60"; // #2 at 0x0D
class #4; // #3 at 0x2B
Utf8 "java/lang/Object"; // #4 at 0x2E
Utf8 "bar"; // #5 at 0x41
Utf8 "()D"; // #6 at 0x47
Utf8 "SourceFile"; // #7 at 0x4D
Utf8 "AbstractStrictfpIntMethod60.java"; // #8 at 0x5A
} // Constant Pool
0x0601; // access [ ACC_PUBLIC ACC_INTERFACE ]
#1;// this_cpx
#3;// super_cpx
[0] { // Interfaces
} // Interfaces
[0] { // Fields
} // Fields
[1] { // Methods
{ // method at 0x89
0x0C01; // access [public abstract strictfp]
#5; // name_index : bar
#6; // descriptor_index : ()D
[0] { // Attributes
} // Attributes
}
} // Methods
[1] { // Attributes
Attr(#7, 2) { // SourceFile at 0x93
#8;
} // end SourceFile
} // Attributes
} // end class AbstractStrictfpIntMethod60

View File

@ -0,0 +1,70 @@
/*
* Copyright (c) 2021, 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.
*/
// Code below is equivalent to
// public interface AbstractStrictfpIntMethod61 {
// public abstract double bar();
// }
class AbstractStrictfpIntMethod61 {
0xCAFEBABE;
0; // minor version
61; // version
[9] { // Constant Pool
; // first element is empty
class #2; // #1 at 0x0A
Utf8 "AbstractStrictfpIntMethod61"; // #2 at 0x0D
class #4; // #3 at 0x2B
Utf8 "java/lang/Object"; // #4 at 0x2E
Utf8 "bar"; // #5 at 0x41
Utf8 "()D"; // #6 at 0x47
Utf8 "SourceFile"; // #7 at 0x4D
Utf8 "AbstractStrictfpIntMethod61.java"; // #8 at 0x5A
} // Constant Pool
0x0601; // access [ ACC_PUBLIC ACC_INTERFACE ]
#1;// this_cpx
#3;// super_cpx
[0] { // Interfaces
} // Interfaces
[0] { // Fields
} // Fields
[1] { // Methods
{ // method at 0x89
0x0C01; // access [public abstract strictfp]
#5; // name_index : bar
#6; // descriptor_index : ()D
[0] { // Attributes
} // Attributes
}
} // Methods
[1] { // Attributes
Attr(#7, 2) { // SourceFile at 0x93
#8;
} // end SourceFile
} // Attributes
} // end class AbstractStrictfpIntMethod61

View File

@ -0,0 +1,102 @@
/*
* Copyright (c) 2021, 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.
*/
// Code below is equivalent to
// public abstract class AbstractStrictfpMethod60 {
// public AbstractStrictfpMethod60() {}
//
// abstract strictfp double foo();
// }
class AbstractStrictfpMethod60 {
0xCAFEBABE;
0; // minor version
60; // version
[15] { // Constant Pool
; // first element is empty
Method #2 #3; // #1 at 0x0A
class #4; // #2 at 0x0F
NameAndType #5 #6; // #3 at 0x12
Utf8 "java/lang/Object"; // #4 at 0x17
Utf8 "<init>"; // #5 at 0x2A
Utf8 "()V"; // #6 at 0x33
class #8; // #7 at 0x39
Utf8 "AbstractStrictfpMethod60"; // #8 at 0x3C
Utf8 "Code"; // #9 at 0x57
Utf8 "LineNumberTable"; // #10 at 0x5E
Utf8 "foo"; // #11 at 0x70
Utf8 "()D"; // #12 at 0x76
Utf8 "SourceFile"; // #13 at 0x7C
Utf8 "AbstractStrictfpMethod60.java"; // #14 at 0x89
} // Constant Pool
0x0421; // access [ ACC_PUBLIC ACC_SUPER ACC_ABSTRACT ]
#7;// this_cpx
#2;// super_cpx
[0] { // Interfaces
} // Interfaces
[0] { // Fields
} // Fields
[2] { // Methods
{ // method at 0xB5
0x0001; // access
#5; // name_index : <init>
#6; // descriptor_index : ()V
[1] { // Attributes
Attr(#9, 29) { // Code at 0xBD
1; // max_stack
1; // max_locals
Bytes[5]{
0x2AB70001B1;
}
[0] { // Traps
} // end Traps
[1] { // Attributes
Attr(#10, 6) { // LineNumberTable at 0xD4
[1] { // line_number_table
0 2; // at 0xE0
}
} // end LineNumberTable
} // Attributes
} // end Code
} // Attributes
}
;
{ // method at 0xE0
0x0C00; // access [ACC_STRICTFP ACC_ABSTRACT]
#11; // name_index : foo
#12; // descriptor_index : ()D
[0] { // Attributes
} // Attributes
}
} // Methods
[1] { // Attributes
Attr(#13, 2) { // SourceFile at 0xEA
#14;
} // end SourceFile
} // Attributes
} // end class AbstractStrictfpMethod60

View File

@ -0,0 +1,102 @@
/*
* Copyright (c) 2021, 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.
*/
// Code below is equivalent to
// public abstract class AbstractStrictfpMethod61 {
// public AbstractStrictfpMethod61() {}
//
// abstract strictfp double foo();
// }
class AbstractStrictfpMethod61 {
0xCAFEBABE;
0; // minor version
61; // version
[15] { // Constant Pool
; // first element is empty
Method #2 #3; // #1 at 0x0A
class #4; // #2 at 0x0F
NameAndType #5 #6; // #3 at 0x12
Utf8 "java/lang/Object"; // #4 at 0x17
Utf8 "<init>"; // #5 at 0x2A
Utf8 "()V"; // #6 at 0x33
class #8; // #7 at 0x39
Utf8 "AbstractStrictfpMethod61"; // #8 at 0x3C
Utf8 "Code"; // #9 at 0x57
Utf8 "LineNumberTable"; // #10 at 0x5E
Utf8 "foo"; // #11 at 0x70
Utf8 "()D"; // #12 at 0x76
Utf8 "SourceFile"; // #13 at 0x7C
Utf8 "AbstractStrictfpMethod61.java"; // #14 at 0x89
} // Constant Pool
0x0421; // access [ ACC_PUBLIC ACC_SUPER ACC_ABSTRACT ]
#7;// this_cpx
#2;// super_cpx
[0] { // Interfaces
} // Interfaces
[0] { // Fields
} // Fields
[2] { // Methods
{ // method at 0xB5
0x0001; // access
#5; // name_index : <init>
#6; // descriptor_index : ()V
[1] { // Attributes
Attr(#9, 29) { // Code at 0xBD
1; // max_stack
1; // max_locals
Bytes[5]{
0x2AB70001B1;
}
[0] { // Traps
} // end Traps
[1] { // Attributes
Attr(#10, 6) { // LineNumberTable at 0xD4
[1] { // line_number_table
0 2; // at 0xE0
}
} // end LineNumberTable
} // Attributes
} // end Code
} // Attributes
}
;
{ // method at 0xE0
0x0C00; // access [ACC_STRICTFP ACC_ABSTRACT]
#11; // name_index : foo
#12; // descriptor_index : ()D
[0] { // Attributes
} // Attributes
}
} // Methods
[1] { // Attributes
Attr(#13, 2) { // SourceFile at 0xEA
#14;
} // end SourceFile
} // Attributes
} // end class AbstractStrictfpMethod61

View File

@ -0,0 +1,72 @@
/*
* Copyright (c) 2021, 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
* @bug 8266530
* @compile AbstractStrictfpMethod60.jcod AbstractStrictfpMethod61.jcod
* @compile AbstractStrictfpIntMethod60.jcod AbstractStrictfpIntMethod61.jcod
* @run main StrictfpModifierChecksTest
*/
import java.util.List;
/*
* Load classes and catch exceptions, or not depending on class file
* version. A class or interface method with "abstract strictfp"
* modifiers is rejected for a version 60.0 class file but accepted
* for a version 61.0 class file. The bit position used for ACC_STRICT
* is unassigned under version 61.0 and is thus ignored.
*/
public class StrictfpModifierChecksTest {
public static void main(String... args) throws Throwable {
for (String version60ClassName : List.of("AbstractStrictfpMethod60",
"AbstractStrictfpIntMethod60")) {
try {
// The AbstractStrictfp*Method60 classes have a
// combination of method modifiers, abstract &
// strictfp, illegal for class file version 60 per
// JVMS 4.6. A ClassFormatError should be thrown when
// trying to load the classes.
Class<?> newClass = Class.forName(version60ClassName);
throw new RuntimeException("Should not reach; expected ClassFormatError not thrown");
} catch (ClassFormatError cfe) {
// Check of content will need updating if the error
// message is rephrased.
String message = cfe.getMessage();
if (!message.contains("has illegal modifier")) {
throw new RuntimeException("Unexpected exception message: " + message);
}
}
}
for (String version61ClassName : List.of("AbstractStrictfpMethod61",
"AbstractStrictfpIntMethod61")) {
// Same combination of modifiers is accepted in class file version 61
Class<?> newClass = Class.forName(version61ClassName);
// Should succeed without an exception
}
}
}