Skip to content
This repository has been archived by the owner on Oct 21, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into jdk21-fix-8240567
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jun 27, 2023
2 parents be49724 + 6a4552c commit d611cc0
Show file tree
Hide file tree
Showing 20 changed files with 324 additions and 96 deletions.
77 changes: 45 additions & 32 deletions src/java.base/share/classes/java/lang/Class.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ static String typeVarBounds(TypeVariable<?> typeVar) {
* the current class.
*
* <p> For example, the following code fragment returns the
* runtime {@code Class} descriptor for the class named
* runtime {@code Class} object for the class named
* {@code java.lang.Thread}:
*
* {@snippet lang="java" :
Expand All @@ -392,9 +392,10 @@ static String typeVarBounds(TypeVariable<?> typeVar) {
* caller frame on the stack (e.g. when called directly from a JNI
* attached thread), the system class loader is used.
*
* @param className the fully qualified name of the desired class.
* @return the {@code Class} object for the class with the
* specified name.
* @param className the {@linkplain ClassLoader##binary-name binary name}
* of the class or the string representing an array type
* @return the {@code Class} object for the class with the
* specified name.
* @throws LinkageError if the linkage fails
* @throws ExceptionInInitializerError if the initialization provoked
* by this method fails
Expand Down Expand Up @@ -423,45 +424,52 @@ private static Class<?> forName(String className, Class<?> caller)
/**
* Returns the {@code Class} object associated with the class or
* interface with the given string name, using the given class loader.
* Given the fully qualified name for a class or interface (in the same
* format returned by {@code getName}) this method attempts to
* locate and load the class or interface. The specified class
* loader is used to load the class or interface. If the parameter
* {@code loader} is null, the class is loaded through the bootstrap
* Given the {@linkplain ClassLoader##binary-name binary name} for a class or interface,
* this method attempts to locate and load the class or interface. The specified
* class loader is used to load the class or interface. If the parameter
* {@code loader} is {@code null}, the class is loaded through the bootstrap
* class loader. The class is initialized only if the
* {@code initialize} parameter is {@code true} and if it has
* not been initialized earlier.
*
* <p> If {@code name} denotes a primitive type or void, an attempt
* will be made to locate a user-defined class in the unnamed package whose
* name is {@code name}. Therefore, this method cannot be used to
* obtain any of the {@code Class} objects representing primitive
* types or void.
* <p> This method cannot be used to obtain any of the {@code Class} objects
* representing primitive types or void, hidden classes or interfaces,
* or array classes whose element type is a hidden class or interface.
* If {@code name} denotes a primitive type or void, for example {@code I},
* an attempt will be made to locate a user-defined class in the unnamed package
* whose name is {@code I} instead.
*
* <p> If {@code name} denotes an array class, the component type of
* the array class is loaded but not initialized.
*
* <p> For example, in an instance method the expression:
* <p> To obtain the {@code Class} object associated with an array class,
* the name consists of one or more {@code '['} representing the depth
* of the array nesting, followed by the element type as encoded in
* {@linkplain ##nameFormat the table} specified in {@code Class.getName()}.
*
* <p> Examples:
* {@snippet lang="java" :
* Class.forName("Foo")
* Class<?> threadClass = Class.forName("java.lang.Thread", false, currentLoader);
* Class<?> stringArrayClass = Class.forName("[Ljava.lang.String;", false, currentLoader);
* Class<?> intArrayClass = Class.forName("[[[I", false, currentLoader); // Class of int[][][]
* Class<?> nestedClass = Class.forName("java.lang.Character$UnicodeBlock", false, currentLoader);
* Class<?> fooClass = Class.forName("Foo", true, currentLoader);
* }
*
* is equivalent to:
* <p> A call to {@code getName()} on the {@code Class} object returned
* from {@code forName(}<i>N</i>{@code )} returns <i>N</i>.
*
* {@snippet lang="java" :
* Class.forName("Foo", true, this.getClass().getClassLoader())
* }
* <p> A call to {@code forName("[L}<i>N</i>{@code ;")} causes the element type
* named <i>N</i> to be loaded but not initialized regardless of the value
* of the {@code initialize} parameter.
*
* Note that this method throws errors related to loading, linking
* or initializing as specified in Sections {@jls 12.2}, {@jls
* 12.3}, and {@jls 12.4} of <cite>The Java Language
* Specification</cite>.
* Note that this method does not check whether the requested class
* @apiNote
* This method throws errors related to loading, linking or initializing
* as specified in Sections {@jls 12.2}, {@jls 12.3}, and {@jls 12.4} of
* <cite>The Java Language Specification</cite>.
* In addition, this method does not check whether the requested class
* is accessible to its caller.
*
* @param name fully qualified name of the desired class
* @param name the {@linkplain ClassLoader##binary-name binary name}
* of the class or the string representing an array class
*
* @param initialize if {@code true} the class will be initialized
* (which implies linking). See Section {@jls
* 12.4} of <cite>The Java Language
Expand All @@ -486,6 +494,7 @@ private static Class<?> forName(String className, Class<?> caller)
* @jls 12.2 Loading of Classes and Interfaces
* @jls 12.3 Linking of Classes and Interfaces
* @jls 12.4 Initialization of Classes and Interfaces
* @jls 13.1 The Form of a Binary
* @since 1.2
*/
@CallerSensitive
Expand Down Expand Up @@ -548,7 +557,9 @@ private static native Class<?> forName0(String name, boolean initialize,
* accessible to its caller. </p>
*
* @apiNote
* This method returns {@code null} on failure rather than
* This method does not support loading of array types, unlike
* {@link #forName(String, boolean, ClassLoader)}. The class name must be
* a binary name. This method returns {@code null} on failure rather than
* throwing a {@link ClassNotFoundException}, as is done by
* the {@link #forName(String, boolean, ClassLoader)} method.
* The security check is a stack-based permission check if the caller
Expand Down Expand Up @@ -888,7 +899,7 @@ public boolean isSynthetic() {
* representing the depth of the array nesting, followed by the element
* type as encoded using the following table:
*
* <blockquote><table class="striped">
* <blockquote><table class="striped" id="nameFormat">
* <caption style="display:none">Element types and encodings</caption>
* <thead>
* <tr><th scope="col"> Element Type <th scope="col"> Encoding
Expand All @@ -915,6 +926,8 @@ public boolean isSynthetic() {
* <blockquote><pre>
* String.class.getName()
* returns "java.lang.String"
* Character.UnicodeBlock.class.getName()
* returns "java.lang.Character$UnicodeBlock"
* byte.class.getName()
* returns "byte"
* (new Object[3]).getClass().getName()
Expand Down
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/lang/Thread.java
Original file line number Diff line number Diff line change
Expand Up @@ -1702,7 +1702,7 @@ public final void stop() {
*
* @implNote In the JDK Reference Implementation, interruption of a thread
* that is not alive still records that the interrupt request was made and
* will report it via {@link #interrupted} and {@link #isInterrupted()}.
* will report it via {@link #interrupted()} and {@link #isInterrupted()}.
*
* @throws SecurityException
* if the current thread cannot modify this thread
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ java.launcher.opt.footer = \
\ and ZIP archives to search for class files.\n\
\ -p <module path>\n\
\ --module-path <module path>...\n\
\ A {0} separated list of directories, each directory\n\
\ is a directory of modules.\n\
\ A {0} separated list of elements, each element is a file path\n\
\ to a module or a directory containing modules. Each module is either\n\
\ a modular JAR or an exploded-module directory.\n\
\ --upgrade-module-path <module path>...\n\
\ A {0} separated list of directories, each directory\n\
\ is a directory of modules that replace upgradeable\n\
\ modules in the runtime image\n\
\ A {0} separated list of elements, each element is a file path\n\
\ to a module or a directory containing modules to replace\n\
\ upgradeable modules in the runtime image. Each module is either\n\
\ a modular JAR or an exploded-module directory.\n\
\ --add-modules <module name>[,<module name>...]\n\
\ root modules to resolve in addition to the initial module.\n\
\ <module name> can also be ALL-DEFAULT, ALL-SYSTEM,\n\
Expand Down
17 changes: 11 additions & 6 deletions src/java.base/share/man/java.1
Original file line number Diff line number Diff line change
Expand Up @@ -530,20 +530,25 @@ The value \[dq]disabled\[dq] disables finalization, so that no
finalizers are invoked.
.TP
\f[V]--module-path\f[R] \f[I]modulepath\f[R]... or \f[V]-p\f[R] \f[I]modulepath\f[R]
Specifies a list of directories in which each directory is a directory
of modules.
Specifies where to find application modules with a list of path elements.
The elements of a module path can be a file path to a module or a directory
containing modules. Each module is either a modular JAR or an
exploded-module directory.
.RS
.PP
On Windows, semicolons (\f[V];\f[R]) separate directories in this list;
On Windows, semicolons (\f[V];\f[R]) separate path elements in this list;
on other platforms it is a colon (\f[V]:\f[R]).
.RE
.TP
\f[V]--upgrade-module-path\f[R] \f[I]modulepath\f[R]...
Specifies a list of directories in which each directory is a directory
of modules that replace upgradeable modules in the runtime image.
Specifies where to find module replacements of upgradeable modules in the
runtime image with a list of path elements.
The elements of a module path can be a file path to a module or a directory
containing modules. Each module is either a modular JAR or an
exploded-module directory.
.RS
.PP
On Windows, semicolons (\f[V];\f[R]) separate directories in this list;
On Windows, semicolons (\f[V];\f[R]) separate path elements in this list;
on other platforms it is a colon (\f[V]:\f[R]).
.RE
.TP
Expand Down
30 changes: 21 additions & 9 deletions src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
Original file line number Diff line number Diff line change
Expand Up @@ -5048,16 +5048,19 @@ private void checkSerialPersistentFields(JCClassDecl tree, Element e, VarSymbol
if ((spf.flags() & (PRIVATE | STATIC | FINAL)) !=
(PRIVATE | STATIC | FINAL)) {
log.warning(LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(spf, tree), Warnings.ImproperSPF);
TreeInfo.diagnosticPositionFor(spf, tree),
Warnings.ImproperSPF);
}

if (!types.isSameType(spf.type, OSF_TYPE)) {
log.warning(LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(spf, tree), Warnings.OSFArraySPF);
TreeInfo.diagnosticPositionFor(spf, tree),
Warnings.OSFArraySPF);
}

if (isExternalizable((Type)(e.asType()))) {
log.warning(LintCategory.SERIAL, tree.pos(),
log.warning(LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(spf, tree),
Warnings.IneffectualSerialFieldExternalizable);
}

Expand Down Expand Up @@ -5165,15 +5168,19 @@ public Void visitTypeAsEnum(TypeElement e,
String name = enclosed.getSimpleName().toString();
switch(enclosed.getKind()) {
case FIELD -> {
var field = (VarSymbol)enclosed;
if (serialFieldNames.contains(name)) {
log.warning(LintCategory.SERIAL, tree.pos(),
log.warning(LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(field, tree),
Warnings.IneffectualSerialFieldEnum(name));
}
}

case METHOD -> {
var method = (MethodSymbol)enclosed;
if (serialMethodNames.contains(name)) {
log.warning(LintCategory.SERIAL, tree.pos(),
log.warning(LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(method, tree),
Warnings.IneffectualSerialMethodEnum(name));
}
}
Expand Down Expand Up @@ -5293,17 +5300,19 @@ public Void visitTypeAsRecord(TypeElement e,
String name = enclosed.getSimpleName().toString();
switch(enclosed.getKind()) {
case FIELD -> {
var field = (VarSymbol)enclosed;
switch(name) {
case "serialPersistentFields" -> {
log.warning(LintCategory.SERIAL, tree.pos(),
log.warning(LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(field, tree),
Warnings.IneffectualSerialFieldRecord);
}

case "serialVersionUID" -> {
// Could generate additional warning that
// svuid value is not checked to match for
// records.
checkSerialVersionUID(tree, e, (VarSymbol)enclosed);
checkSerialVersionUID(tree, e, field);
}

}
Expand All @@ -5314,9 +5323,11 @@ public Void visitTypeAsRecord(TypeElement e,
switch(name) {
case "writeReplace" -> checkWriteReplace(tree, e, method);
case "readResolve" -> checkReadResolve(tree, e, method);

default -> {
if (serialMethodNames.contains(name)) {
log.warning(LintCategory.SERIAL, tree.pos(),
log.warning(LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(method, tree),
Warnings.IneffectualSerialMethodRecord(name));
}
}
Expand Down Expand Up @@ -5394,7 +5405,8 @@ private void checkNoArgs(JCClassDecl tree, Element enclosing, MethodSymbol metho
private void checkExternalizable(JCClassDecl tree, Element enclosing, MethodSymbol method) {
// If the enclosing class is externalizable, warn for the method
if (isExternalizable((Type)enclosing.asType())) {
log.warning(LintCategory.SERIAL, tree.pos(),
log.warning(LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(method, tree),
Warnings.IneffectualSerialMethodExternalizable(method.getSimpleName()));
}
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,14 @@ private boolean shouldIndex(Element element) {
}

private static Character keyCharacter(String s) {
return s.isEmpty() ? '*' : Character.toUpperCase(s.charAt(0));
// Use first valid java identifier start character as key,
// or '*' for strings that do not contain one.
for (int i = 0; i < s.length(); i++) {
if (Character.isJavaIdentifierStart(s.charAt(i))) {
return Character.toUpperCase(s.charAt(i));
}
}
return '*';
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2023, 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
Expand Down
10 changes: 6 additions & 4 deletions src/jdk.jfr/share/classes/jdk/jfr/internal/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,13 @@ private static enum TimespanUnit {
}
}

// handle Long.MIN_VALUE as a special case since its absolute value is negative
private static String formatDataAmount(String formatter, long amount) {
int exp = (amount == Long.MIN_VALUE) ? 6 : (int) (Math.log(Math.abs(amount)) / Math.log(1024));
char unitPrefix = "kMGTPE".charAt(exp - 1);
return String.format(formatter, amount / Math.pow(1024, exp), unitPrefix);
if (amount == Long.MIN_VALUE) {
return "N/A";
}
int exp = (int) (Math.log(Math.abs(amount)) / Math.log(1024));
char unit = "kMGTPE".charAt(exp - 1);
return String.format(formatter, amount / Math.pow(1024, exp), unit);
}

public static String formatBytesCompact(long bytes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,13 @@ public static String formatClass(RecordedClass clazz) {
return name;
}

// handle Long.MIN_VALUE as a special case since its absolute value is negative
private static String formatDataAmount(String formatter, long amount) {
int exp = (amount == Long.MIN_VALUE) ? 6 : (int) (Math.log(Math.abs(amount)) / Math.log(1024));
char unitPrefix = "kMGTPE".charAt(exp - 1);
return String.format(formatter, amount / Math.pow(1024, exp), unitPrefix);
if (amount == Long.MIN_VALUE) {
return "N/A";
}
int exp = (int) (Math.log(Math.abs(amount)) / Math.log(1024));
char unit = "kMGTPE".charAt(exp - 1);
return String.format(formatter, amount / Math.pow(1024, exp), unit);
}

public static String formatBytesCompact(long bytes) {
Expand Down
Loading

0 comments on commit d611cc0

Please sign in to comment.