Skip to content

Commit e621cff

Browse files
committedAug 2, 2021
8271627: Use local field access in favor of Class.getClassLoader0
Reviewed-by: mchung
1 parent 0a85236 commit e621cff

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed
 

‎src/java.base/share/classes/java/lang/Class.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ public String getName() {
892892
@CallerSensitive
893893
@ForceInline // to ensure Reflection.getCallerClass optimization
894894
public ClassLoader getClassLoader() {
895-
ClassLoader cl = getClassLoader0();
895+
ClassLoader cl = classLoader;
896896
if (cl == null)
897897
return null;
898898
@SuppressWarnings("removal")
@@ -1041,7 +1041,7 @@ public Package getPackage() {
10411041
if (isPrimitive() || isArray()) {
10421042
return null;
10431043
}
1044-
ClassLoader cl = getClassLoader0();
1044+
ClassLoader cl = classLoader;
10451045
return cl != null ? cl.definePackage(this)
10461046
: BootLoader.definePackage(this);
10471047
}
@@ -2823,7 +2823,7 @@ public InputStream getResourceAsStream(String name) {
28232823

28242824
// resource not encapsulated or in package open to caller
28252825
String mn = thisModule.getName();
2826-
ClassLoader cl = getClassLoader0();
2826+
ClassLoader cl = classLoader;
28272827
try {
28282828

28292829
// special-case built-in class loaders to avoid the
@@ -2843,7 +2843,7 @@ public InputStream getResourceAsStream(String name) {
28432843
}
28442844

28452845
// unnamed module
2846-
ClassLoader cl = getClassLoader0();
2846+
ClassLoader cl = classLoader;
28472847
if (cl == null) {
28482848
return ClassLoader.getSystemResourceAsStream(name);
28492849
} else {
@@ -2919,7 +2919,7 @@ public URL getResource(String name) {
29192919

29202920
// resource not encapsulated or in package open to caller
29212921
String mn = thisModule.getName();
2922-
ClassLoader cl = getClassLoader0();
2922+
ClassLoader cl = classLoader;
29232923
try {
29242924
if (cl == null) {
29252925
return BootLoader.findResource(mn, name);
@@ -2932,7 +2932,7 @@ public URL getResource(String name) {
29322932
}
29332933

29342934
// unnamed module
2935-
ClassLoader cl = getClassLoader0();
2935+
ClassLoader cl = classLoader;
29362936
if (cl == null) {
29372937
return ClassLoader.getSystemResource(name);
29382938
} else {
@@ -3046,7 +3046,7 @@ private void checkMemberAccess(@SuppressWarnings("removal") SecurityManager sm,
30463046
*/
30473047
final ClassLoader ccl = ClassLoader.getClassLoader(caller);
30483048
if (which != Member.PUBLIC) {
3049-
final ClassLoader cl = getClassLoader0();
3049+
final ClassLoader cl = classLoader;
30503050
if (ccl != cl) {
30513051
sm.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
30523052
}
@@ -3063,7 +3063,7 @@ private void checkMemberAccess(@SuppressWarnings("removal") SecurityManager sm,
30633063
*/
30643064
private void checkPackageAccess(@SuppressWarnings("removal") SecurityManager sm, final ClassLoader ccl,
30653065
boolean checkProxyInterfaces) {
3066-
final ClassLoader cl = getClassLoader0();
3066+
final ClassLoader cl = classLoader;
30673067

30683068
if (ReflectUtil.needsPackageAccessCheck(ccl, cl)) {
30693069
String pkg = this.getPackageName();
@@ -3092,7 +3092,7 @@ private void checkPackageAccess(@SuppressWarnings("removal") SecurityManager sm,
30923092
*/
30933093
private static void checkPackageAccessForPermittedSubclasses(@SuppressWarnings("removal") SecurityManager sm,
30943094
final ClassLoader ccl, Class<?>[] subClasses) {
3095-
final ClassLoader cl = subClasses[0].getClassLoader0();
3095+
final ClassLoader cl = subClasses[0].classLoader;
30963096

30973097
if (ReflectUtil.needsPackageAccessCheck(ccl, cl)) {
30983098
Set<String> packages = new HashSet<>();
@@ -3717,7 +3717,7 @@ private String methodToString(String name, Class<?>[] argTypes) {
37173717
* @since 1.4
37183718
*/
37193719
public boolean desiredAssertionStatus() {
3720-
ClassLoader loader = getClassLoader0();
3720+
ClassLoader loader = classLoader;
37213721
// If the loader is null this is a system class, so ask the VM
37223722
if (loader == null)
37233723
return desiredAssertionStatus0(this);

0 commit comments

Comments
 (0)
Please sign in to comment.