mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8284871: Use covariant overrides for the resolveConstantDesc(Lookup) method in sub‑interfaces of java.lang.constant.ConstantDesc
Reviewed-by: mchung
This commit is contained in:
parent
cd7d53c88c
commit
e5ce7d9e43
15 changed files with 100 additions and 83 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 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
|
||||
|
@ -58,8 +58,8 @@ final class AsTypeMethodHandleDesc extends DynamicConstantDesc<MethodHandle>
|
|||
@Override
|
||||
public MethodHandle resolveConstantDesc(MethodHandles.Lookup lookup)
|
||||
throws ReflectiveOperationException {
|
||||
MethodHandle handle = (MethodHandle) underlying.resolveConstantDesc(lookup);
|
||||
MethodType methodType = (MethodType) type.resolveConstantDesc(lookup);
|
||||
MethodHandle handle = underlying.resolveConstantDesc(lookup);
|
||||
MethodType methodType = type.resolveConstantDesc(lookup);
|
||||
return handle.asType(methodType);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 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
|
||||
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
package java.lang.constant;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.TypeDescriptor;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
@ -362,6 +363,9 @@ public sealed interface ClassDesc
|
|||
*/
|
||||
String descriptorString();
|
||||
|
||||
@Override
|
||||
Class<?> resolveConstantDesc(MethodHandles.Lookup lookup) throws ReflectiveOperationException;
|
||||
|
||||
/**
|
||||
* Compare the specified object with this descriptor for equality. Returns
|
||||
* {@code true} if and only if the specified object is also a
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 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
|
||||
|
@ -99,9 +99,9 @@ public sealed interface ConstantDesc
|
|||
* could not be reflectively resolved in the course of resolution
|
||||
* @throws LinkageError if a linkage error occurs
|
||||
*
|
||||
* @apiNote {@linkplain MethodTypeDesc} can represent method type descriptors
|
||||
* that are not representable by {@linkplain MethodType}, such as methods with
|
||||
* more than 255 parameter slots, so attempts to resolve these may result in errors.
|
||||
* @apiNote Some constant descriptors, such as {@linkplain MethodTypeDesc}, can represent
|
||||
* a value that is not representable by run-time entities. Attempts to resolve these may
|
||||
* result in errors.
|
||||
*
|
||||
* @jvms 5.4.3 Resolution
|
||||
* @jvms 5.4.4 Access Control
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 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
|
||||
|
@ -152,8 +152,8 @@ final class DirectMethodHandleDescImpl implements DirectMethodHandleDesc {
|
|||
|
||||
public MethodHandle resolveConstantDesc(MethodHandles.Lookup lookup)
|
||||
throws ReflectiveOperationException {
|
||||
Class<?> resolvedOwner = (Class<?>) owner.resolveConstantDesc(lookup);
|
||||
MethodType invocationType = (MethodType) this.invocationType().resolveConstantDesc(lookup);
|
||||
Class<?> resolvedOwner = owner.resolveConstantDesc(lookup);
|
||||
MethodType invocationType = this.invocationType().resolveConstantDesc(lookup);
|
||||
return switch (kind) {
|
||||
case STATIC,
|
||||
INTERFACE_STATIC -> lookup.findStatic(resolvedOwner, name, invocationType);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 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
|
||||
|
@ -234,7 +234,7 @@ public class DynamicCallSiteDesc {
|
|||
*/
|
||||
public CallSite resolveCallSiteDesc(MethodHandles.Lookup lookup) throws Throwable {
|
||||
assert bootstrapMethod.invocationType().parameterType(1).equals(CD_String);
|
||||
MethodHandle bsm = (MethodHandle) bootstrapMethod.resolveConstantDesc(lookup);
|
||||
MethodHandle bsm = bootstrapMethod.resolveConstantDesc(lookup);
|
||||
Object[] args = new Object[bootstrapArgs.length + 3];
|
||||
args[0] = lookup;
|
||||
args[1] = invocationName;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 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
|
||||
|
@ -252,7 +252,7 @@ public abstract non-sealed class DynamicConstantDesc<T>
|
|||
@SuppressWarnings("unchecked")
|
||||
public T resolveConstantDesc(MethodHandles.Lookup lookup) throws ReflectiveOperationException {
|
||||
try {
|
||||
MethodHandle bsm = (MethodHandle) bootstrapMethod.resolveConstantDesc(lookup);
|
||||
MethodHandle bsm = bootstrapMethod.resolveConstantDesc(lookup);
|
||||
if (bsm.type().parameterCount() < 2 ||
|
||||
!MethodHandles.Lookup.class.isAssignableFrom(bsm.type().parameterType(0))) {
|
||||
throw new BootstrapMethodError(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 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
|
||||
|
@ -204,6 +204,9 @@ public sealed interface MethodHandleDesc
|
|||
*/
|
||||
MethodTypeDesc invocationType();
|
||||
|
||||
@Override
|
||||
MethodHandle resolveConstantDesc(MethodHandles.Lookup lookup) throws ReflectiveOperationException;
|
||||
|
||||
/**
|
||||
* Compares the specified object with this descriptor for equality. Returns
|
||||
* {@code true} if and only if the specified object is also a
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 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
|
||||
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
package java.lang.constant;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.lang.invoke.TypeDescriptor;
|
||||
import java.util.List;
|
||||
|
@ -188,6 +189,16 @@ public sealed interface MethodTypeDesc
|
|||
returnType().displayName());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @apiNote {@linkplain MethodTypeDesc} can represent method type descriptors
|
||||
* that are not representable by {@linkplain MethodType}, such as methods with
|
||||
* more than 255 parameter slots, so attempts to resolve these may result in errors.
|
||||
*/
|
||||
@Override
|
||||
MethodType resolveConstantDesc(MethodHandles.Lookup lookup) throws ReflectiveOperationException;
|
||||
|
||||
/**
|
||||
* Compares the specified object with this descriptor for equality. Returns
|
||||
* {@code true} if and only if the specified object is also a
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue