Skip to content

Commit

Permalink
8255009: delta apply fixes for JDK-8246774 and JDK-8253455, pushed to…
Browse files Browse the repository at this point in the history
…o soon

Reviewed-by: jlahoda
  • Loading branch information
Vicente Romero committed Oct 19, 2020
1 parent a0382cd commit 1da28de
Show file tree
Hide file tree
Showing 121 changed files with 923 additions and 312 deletions.
63 changes: 42 additions & 21 deletions src/hotspot/share/classfile/classFileParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3567,6 +3567,12 @@ bool ClassFileParser::supports_sealed_types() {
Arguments::enable_preview();
}

bool ClassFileParser::supports_records() {
return _major_version == JVM_CLASSFILE_MAJOR_VERSION &&
_minor_version == JAVA_PREVIEW_MINOR_VERSION &&
Arguments::enable_preview();
}

void ClassFileParser::parse_classfile_attributes(const ClassFileStream* const cfs,
ConstantPool* cp,
ClassFileParser::ClassAnnotationCollector* parsed_annotations,
Expand Down Expand Up @@ -3814,28 +3820,12 @@ void ClassFileParser::parse_classfile_attributes(const ClassFileStream* const cf
"Nest-host class_info_index %u has bad constant type in class file %s",
class_info_index, CHECK);
_nest_host = class_info_index;

} else if (_major_version >= JAVA_15_VERSION) {
// Check for PermittedSubclasses tag
if (tag == vmSymbols::tag_permitted_subclasses()) {
if (supports_sealed_types()) {
if (parsed_permitted_subclasses_attribute) {
classfile_parse_error("Multiple PermittedSubclasses attributes in class file %s", CHECK);
}
// Classes marked ACC_FINAL cannot have a PermittedSubclasses attribute.
if (_access_flags.is_final()) {
classfile_parse_error("PermittedSubclasses attribute in final class file %s", CHECK);
}
parsed_permitted_subclasses_attribute = true;
permitted_subclasses_attribute_start = cfs->current();
permitted_subclasses_attribute_length = attribute_length;
}
cfs->skip_u1(attribute_length, CHECK);

} else if (_major_version >= JAVA_16_VERSION) {
} else if (_major_version >= JAVA_14_VERSION) {
if (tag == vmSymbols::tag_record()) {
// Skip over Record attribute if super class is not java.lang.Record.
if (cp->klass_name_at(_super_class_index) == vmSymbols::java_lang_Record()) {
// Skip over Record attribute if not supported or if super class is
// not java.lang.Record.
if (supports_records() &&
cp->klass_name_at(_super_class_index) == vmSymbols::java_lang_Record()) {
if (parsed_record_attribute) {
classfile_parse_error("Multiple Record attributes in class file %s", THREAD);
return;
Expand All @@ -3849,13 +3839,44 @@ void ClassFileParser::parse_classfile_attributes(const ClassFileStream* const cf
record_attribute_start = cfs->current();
record_attribute_length = attribute_length;
} else if (log_is_enabled(Info, class, record)) {
// Log why the Record attribute was ignored. Note that if the
// class file version is JVM_CLASSFILE_MAJOR_VERSION.65535 and
// --enable-preview wasn't specified then a java.lang.UnsupportedClassVersionError
// exception would have been thrown.
ResourceMark rm(THREAD);
if (supports_records()) {
log_info(class, record)(
"Ignoring Record attribute in class %s because super type is not java.lang.Record",
_class_name->as_C_string());
} else {
log_info(class, record)(
"Ignoring Record attribute in class %s because class file version is not %d.65535",
_class_name->as_C_string(), JVM_CLASSFILE_MAJOR_VERSION);
}
}
cfs->skip_u1(attribute_length, CHECK);
} else if (_major_version >= JAVA_15_VERSION) {
// Check for PermittedSubclasses tag
if (tag == vmSymbols::tag_permitted_subclasses()) {
if (supports_sealed_types()) {
if (parsed_permitted_subclasses_attribute) {
classfile_parse_error("Multiple PermittedSubclasses attributes in class file %s", THREAD);
return;
}
// Classes marked ACC_FINAL cannot have a PermittedSubclasses attribute.
if (_access_flags.is_final()) {
classfile_parse_error("PermittedSubclasses attribute in final class file %s", THREAD);
return;
}
parsed_permitted_subclasses_attribute = true;
permitted_subclasses_attribute_start = cfs->current();
permitted_subclasses_attribute_length = attribute_length;
}
cfs->skip_u1(attribute_length, CHECK);
} else {
// Unknown attribute
cfs->skip_u1(attribute_length, CHECK);
}
} else {
// Unknown attribute
cfs->skip_u1(attribute_length, CHECK);
Expand Down
23 changes: 21 additions & 2 deletions src/java.base/share/classes/java/lang/Class.java
Original file line number Diff line number Diff line change
Expand Up @@ -2342,6 +2342,13 @@ public Field[] getDeclaredFields() throws SecurityException {
}

/**
* {@preview Associated with records, a preview feature of the Java language.
*
* This method is associated with <i>records</i>, a preview
* feature of the Java language. Preview features
* may be removed in a future release, or upgraded to permanent
* features of the Java language.}
*
* Returns an array of {@code RecordComponent} objects representing all the
* record components of this record class, or {@code null} if this class is
* not a record class.
Expand Down Expand Up @@ -2378,8 +2385,11 @@ public Field[] getDeclaredFields() throws SecurityException {
* </ul>
*
* @jls 8.10 Record Types
* @since 16
* @since 14
*/
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
essentialAPI=false)
@SuppressWarnings("preview")
@CallerSensitive
public RecordComponent[] getRecordComponents() {
SecurityManager sm = System.getSecurityManager();
Expand Down Expand Up @@ -3678,6 +3688,13 @@ private static Class<?> javaLangRecordClass() {
}

/**
* {@preview Associated with records, a preview feature of the Java language.
*
* This method is associated with <i>records</i>, a preview
* feature of the Java language. Preview features
* may be removed in a future release, or upgraded to permanent
* features of the Java language.}
*
* Returns {@code true} if and only if this class is a record class.
*
* <p> The {@linkplain #getSuperclass() direct superclass} of a record
Expand All @@ -3690,8 +3707,10 @@ private static Class<?> javaLangRecordClass() {
*
* @return true if and only if this class is a record class, otherwise false
* @jls 8.10 Record Types
* @since 16
* @since 14
*/
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
essentialAPI=false)
public boolean isRecord() {
return getSuperclass() == JAVA_LANG_RECORD_CLASS && isRecord0();
}
Expand Down
12 changes: 11 additions & 1 deletion src/java.base/share/classes/java/lang/Record.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
package java.lang;

/**
* {@preview Associated with records, a preview feature of the Java language.
*
* This class is associated with <i>records</i>, a preview
* feature of the Java language. Programs can only use this
* class when preview features are enabled. Preview features
* may be removed in a future release, or upgraded to permanent
* features of the Java language.}
*
* This is the common base class of all Java language record classes.
*
* <p>More information about records, including descriptions of the
Expand Down Expand Up @@ -78,8 +86,10 @@
* <a href="{@docRoot}/java.base/java/io/ObjectInputStream.html#record-serialization">record serialization</a>.
*
* @jls 8.10 Record Types
* @since 16
* @since 14
*/
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
essentialAPI=true)
public abstract class Record {
/**
* Constructor for record classes to call.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,22 @@ public enum ElementType {
MODULE,

/**
* {@preview Associated with records, a preview feature of the Java language.
*
* This constant is associated with <i>records</i>, a preview
* feature of the Java language. Programs can only use this
* constant when preview features are enabled. Preview features
* may be removed in a future release, or upgraded to permanent
* features of the Java language.}
*
* Record component
*
* @jls 8.10.3 Record Members
* @jls 9.7.4 Where Annotations May Appear
*
* @since 16
* @since 14
*/
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
essentialAPI=true)
RECORD_COMPONENT;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,23 @@
import java.util.Objects;

/**
* {@preview Associated with records, a preview feature of the Java language.
*
* This class is associated with <i>records</i>, a preview
* feature of the Java language. Preview features
* may be removed in a future release, or upgraded to permanent
* features of the Java language.}
*
* A {@code RecordComponent} provides information about, and dynamic access to, a
* component of a record class.
*
* @see Class#getRecordComponents()
* @see java.lang.Record
* @jls 8.10 Record Types
* @since 16
* @since 14
*/
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
essentialAPI=false)
public final class RecordComponent implements AnnotatedElement {
// declaring class
private Class<?> clazz;
Expand Down
11 changes: 10 additions & 1 deletion src/java.base/share/classes/java/lang/runtime/ObjectMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,23 @@
import java.util.Objects;

/**
* {@preview Associated with records, a preview feature of the Java language.
*
* This class is associated with <i>records</i>, a preview
* feature of the Java language. Preview features
* may be removed in a future release, or upgraded to permanent
* features of the Java language.}
*
* Bootstrap methods for state-driven implementations of core methods,
* including {@link Object#equals(Object)}, {@link Object#hashCode()}, and
* {@link Object#toString()}. These methods may be used, for example, by
* Java compiler implementations to implement the bodies of {@link Object}
* methods for record classes.
*
* @since 16
* @since 14
*/
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
essentialAPI=false)
public class ObjectMethods {

private ObjectMethods() { }
Expand Down
5 changes: 0 additions & 5 deletions src/java.base/share/classes/jdk/internal/PreviewFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ public enum Feature {
// JDK 15. Since the JDK 14 codebase uses the enum constant, it is
// necessary for PreviewFeature in JDK 15 to declare the enum constant.
TEXT_BLOCKS,
// The RECORDS enum constant is not used in the JDK 16 codebase, but
// exists to support the bootcycle build of JDK 16. The bootcycle build
// of JDK 16 is performed with JDK 15 and the PreviewFeature type from
// JDK 16. Since the JDK 15 codebase uses the enum constant, it is
// necessary for PreviewFeature in JDK 16 to declare the enum constant.
RECORDS,
SEALED_CLASSES,
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,16 @@ public static enum TypeAnnotationTarget {
METHOD_FORMAL_PARAMETER,
THROWS,
/**
* @since 16
* {@preview Associated with records, a preview feature of the Java language.
*
* This enum constant is associated with <i>records</i>, a preview
* feature of the Java language. Preview features
* may be removed in a future release, or upgraded to permanent
* features of the Java language.}
* @since 14
*/
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
essentialAPI=false)
RECORD_COMPONENT;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,33 @@ public enum ElementKind {
MODULE,

/**
* {@preview Associated with records, a preview feature of the Java language.
*
* This enum constant is associated with <i>records</i>, a preview
* feature of the Java language. Preview features
* may be removed in a future release, or upgraded to permanent
* features of the Java language.}
*
* A record type.
* @since 16
* @since 14
*/
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
essentialAPI=false)
RECORD,

/**
* {@preview Associated with records, a preview feature of the Java language.
*
* This enum constant is associated with <i>records</i>, a preview
* feature of the Java language. Preview features
* may be removed in a future release, or upgraded to permanent
* features of the Java language.}
*
* A record component of a {@code record}.
* @since 16
* @since 14
*/
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
essentialAPI=false)
RECORD_COMPONENT,

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ default R visitModule(ModuleElement e, P p) {
}

/**
* {@preview Associated with records, a preview feature of the Java language.
*
* This method is associated with <i>records</i>, a preview
* feature of the Java language. Preview features
* may be removed in a future release, or upgraded to permanent
* features of the Java language.}
*
* Visits a record component element.
*
* @implSpec The default implementation visits a {@code
Expand All @@ -220,8 +227,11 @@ default R visitModule(ModuleElement e, P p) {
* @param e the element to visit
* @param p a visitor-specified parameter
* @return a visitor-specified result
* @since 16
* @since 14
*/
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
essentialAPI=false)
@SuppressWarnings("preview")
default R visitRecordComponent(RecordComponentElement e, P p) {
return visitUnknown(e, p);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,19 @@
package javax.lang.model.element;

/**
* {@preview Associated with records, a preview feature of the Java language.
*
* This class is associated with <i>records</i>, a preview
* feature of the Java language. Preview features
* may be removed in a future release, or upgraded to permanent
* features of the Java language.}
*
* Represents a record component.
*
* @since 16
* @since 14
*/
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
essentialAPI=false)
public interface RecordComponentElement extends Element {
/**
* Returns the enclosing element of this record component.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ public interface TypeElement extends Element, Parameterizable, QualifiedNameable
List<? extends TypeParameterElement> getTypeParameters();

/**
* {@preview Associated with records, a preview feature of the Java language.
*
* This method is associated with <i>records</i>, a preview
* feature of the Java language. Preview features
* may be removed in a future release, or upgraded to permanent
* features of the Java language.}
*
* Returns the record components of this type element in
* declaration order.
*
Expand All @@ -189,8 +196,11 @@ public interface TypeElement extends Element, Parameterizable, QualifiedNameable
* @return the record components, or an empty list if there are
* none
*
* @since 16
* @since 14
*/
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
essentialAPI=false)
@SuppressWarnings("preview")
default List<? extends RecordComponentElement> getRecordComponents() {
return List.of();
}
Expand Down
Loading

1 comment on commit 1da28de

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on 1da28de Oct 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.