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
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -58,8 +58,8 @@ final class AsTypeMethodHandleDesc extends DynamicConstantDesc<MethodHandle>
|
|||||||
@Override
|
@Override
|
||||||
public MethodHandle resolveConstantDesc(MethodHandles.Lookup lookup)
|
public MethodHandle resolveConstantDesc(MethodHandles.Lookup lookup)
|
||||||
throws ReflectiveOperationException {
|
throws ReflectiveOperationException {
|
||||||
MethodHandle handle = (MethodHandle) underlying.resolveConstantDesc(lookup);
|
MethodHandle handle = underlying.resolveConstantDesc(lookup);
|
||||||
MethodType methodType = (MethodType) type.resolveConstantDesc(lookup);
|
MethodType methodType = type.resolveConstantDesc(lookup);
|
||||||
return handle.asType(methodType);
|
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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -24,6 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
package java.lang.constant;
|
package java.lang.constant;
|
||||||
|
|
||||||
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.lang.invoke.TypeDescriptor;
|
import java.lang.invoke.TypeDescriptor;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@ -362,6 +363,9 @@ public sealed interface ClassDesc
|
|||||||
*/
|
*/
|
||||||
String descriptorString();
|
String descriptorString();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
Class<?> resolveConstantDesc(MethodHandles.Lookup lookup) throws ReflectiveOperationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare the specified object with this descriptor for equality. Returns
|
* Compare the specified object with this descriptor for equality. Returns
|
||||||
* {@code true} if and only if the specified object is also a
|
* {@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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* 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
|
* could not be reflectively resolved in the course of resolution
|
||||||
* @throws LinkageError if a linkage error occurs
|
* @throws LinkageError if a linkage error occurs
|
||||||
*
|
*
|
||||||
* @apiNote {@linkplain MethodTypeDesc} can represent method type descriptors
|
* @apiNote Some constant descriptors, such as {@linkplain MethodTypeDesc}, can represent
|
||||||
* that are not representable by {@linkplain MethodType}, such as methods with
|
* a value that is not representable by run-time entities. Attempts to resolve these may
|
||||||
* more than 255 parameter slots, so attempts to resolve these may result in errors.
|
* result in errors.
|
||||||
*
|
*
|
||||||
* @jvms 5.4.3 Resolution
|
* @jvms 5.4.3 Resolution
|
||||||
* @jvms 5.4.4 Access Control
|
* @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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* 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)
|
public MethodHandle resolveConstantDesc(MethodHandles.Lookup lookup)
|
||||||
throws ReflectiveOperationException {
|
throws ReflectiveOperationException {
|
||||||
Class<?> resolvedOwner = (Class<?>) owner.resolveConstantDesc(lookup);
|
Class<?> resolvedOwner = owner.resolveConstantDesc(lookup);
|
||||||
MethodType invocationType = (MethodType) this.invocationType().resolveConstantDesc(lookup);
|
MethodType invocationType = this.invocationType().resolveConstantDesc(lookup);
|
||||||
return switch (kind) {
|
return switch (kind) {
|
||||||
case STATIC,
|
case STATIC,
|
||||||
INTERFACE_STATIC -> lookup.findStatic(resolvedOwner, name, invocationType);
|
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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* 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 {
|
public CallSite resolveCallSiteDesc(MethodHandles.Lookup lookup) throws Throwable {
|
||||||
assert bootstrapMethod.invocationType().parameterType(1).equals(CD_String);
|
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];
|
Object[] args = new Object[bootstrapArgs.length + 3];
|
||||||
args[0] = lookup;
|
args[0] = lookup;
|
||||||
args[1] = invocationName;
|
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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* 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")
|
@SuppressWarnings("unchecked")
|
||||||
public T resolveConstantDesc(MethodHandles.Lookup lookup) throws ReflectiveOperationException {
|
public T resolveConstantDesc(MethodHandles.Lookup lookup) throws ReflectiveOperationException {
|
||||||
try {
|
try {
|
||||||
MethodHandle bsm = (MethodHandle) bootstrapMethod.resolveConstantDesc(lookup);
|
MethodHandle bsm = bootstrapMethod.resolveConstantDesc(lookup);
|
||||||
if (bsm.type().parameterCount() < 2 ||
|
if (bsm.type().parameterCount() < 2 ||
|
||||||
!MethodHandles.Lookup.class.isAssignableFrom(bsm.type().parameterType(0))) {
|
!MethodHandles.Lookup.class.isAssignableFrom(bsm.type().parameterType(0))) {
|
||||||
throw new BootstrapMethodError(
|
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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -204,6 +204,9 @@ public sealed interface MethodHandleDesc
|
|||||||
*/
|
*/
|
||||||
MethodTypeDesc invocationType();
|
MethodTypeDesc invocationType();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
MethodHandle resolveConstantDesc(MethodHandles.Lookup lookup) throws ReflectiveOperationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares the specified object with this descriptor for equality. Returns
|
* Compares the specified object with this descriptor for equality. Returns
|
||||||
* {@code true} if and only if the specified object is also a
|
* {@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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -24,6 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
package java.lang.constant;
|
package java.lang.constant;
|
||||||
|
|
||||||
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.lang.invoke.MethodType;
|
import java.lang.invoke.MethodType;
|
||||||
import java.lang.invoke.TypeDescriptor;
|
import java.lang.invoke.TypeDescriptor;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -188,6 +189,16 @@ public sealed interface MethodTypeDesc
|
|||||||
returnType().displayName());
|
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
|
* Compares the specified object with this descriptor for equality. Returns
|
||||||
* {@code true} if and only if the specified object is also a
|
* {@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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -59,15 +59,15 @@ public class ClassDescTest extends SymbolicDescTest {
|
|||||||
if (!r.descriptorString().equals("V")) {
|
if (!r.descriptorString().equals("V")) {
|
||||||
assertEquals(r, r.arrayType().componentType());
|
assertEquals(r, r.arrayType().componentType());
|
||||||
// Commutativity: array -> resolve -> componentType -> toSymbolic
|
// Commutativity: array -> resolve -> componentType -> toSymbolic
|
||||||
assertEquals(r, ((Class<?>) r.arrayType().resolveConstantDesc(LOOKUP)).getComponentType().describeConstable().orElseThrow());
|
assertEquals(r, r.arrayType().resolveConstantDesc(LOOKUP).getComponentType().describeConstable().orElseThrow());
|
||||||
// Commutativity: resolve -> array -> toSymbolic -> component type
|
// Commutativity: resolve -> array -> toSymbolic -> component type
|
||||||
assertEquals(r, Array.newInstance(((Class<?>) r.resolveConstantDesc(LOOKUP)), 0).getClass().describeConstable().orElseThrow().componentType());
|
assertEquals(r, Array.newInstance(r.resolveConstantDesc(LOOKUP), 0).getClass().describeConstable().orElseThrow().componentType());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r.isArray()) {
|
if (r.isArray()) {
|
||||||
assertEquals(r, r.componentType().arrayType());
|
assertEquals(r, r.componentType().arrayType());
|
||||||
assertEquals(r, ((Class<?>) r.resolveConstantDesc(LOOKUP)).getComponentType().describeConstable().orElseThrow().arrayType());
|
assertEquals(r, r.resolveConstantDesc(LOOKUP).getComponentType().describeConstable().orElseThrow().arrayType());
|
||||||
assertEquals(r, Array.newInstance(((Class<?>) r.componentType().resolveConstantDesc(LOOKUP)), 0).getClass().describeConstable().orElseThrow());
|
assertEquals(r, Array.newInstance(r.componentType().resolveConstantDesc(LOOKUP), 0).getClass().describeConstable().orElseThrow());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ public class ClassDescTest extends SymbolicDescTest {
|
|||||||
&& ((f.getModifiers() & Modifier.STATIC) != 0)
|
&& ((f.getModifiers() & Modifier.STATIC) != 0)
|
||||||
&& ((f.getModifiers() & Modifier.PUBLIC) != 0)) {
|
&& ((f.getModifiers() & Modifier.PUBLIC) != 0)) {
|
||||||
ClassDesc cr = (ClassDesc) f.get(null);
|
ClassDesc cr = (ClassDesc) f.get(null);
|
||||||
Class c = (Class)cr.resolveConstantDesc(MethodHandles.lookup());
|
Class<?> c = cr.resolveConstantDesc(MethodHandles.lookup());
|
||||||
testClassDesc(cr, c);
|
testClassDesc(cr, c);
|
||||||
++tested;
|
++tested;
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ public class ClassDescTest extends SymbolicDescTest {
|
|||||||
for (Primitives p : Primitives.values()) {
|
for (Primitives p : Primitives.values()) {
|
||||||
List<ClassDesc> descs = List.of(ClassDesc.ofDescriptor(p.descriptor),
|
List<ClassDesc> descs = List.of(ClassDesc.ofDescriptor(p.descriptor),
|
||||||
p.classDesc,
|
p.classDesc,
|
||||||
(ClassDesc) p.clazz.describeConstable().orElseThrow());
|
p.clazz.describeConstable().orElseThrow());
|
||||||
for (ClassDesc c : descs) {
|
for (ClassDesc c : descs) {
|
||||||
testClassDesc(c, p.clazz);
|
testClassDesc(c, p.clazz);
|
||||||
assertTrue(c.isPrimitive());
|
assertTrue(c.isPrimitive());
|
||||||
@ -115,7 +115,7 @@ public class ClassDescTest extends SymbolicDescTest {
|
|||||||
descs.forEach(cc -> assertEquals(c, cc));
|
descs.forEach(cc -> assertEquals(c, cc));
|
||||||
if (p != Primitives.VOID) {
|
if (p != Primitives.VOID) {
|
||||||
testClassDesc(c.arrayType(), p.arrayClass);
|
testClassDesc(c.arrayType(), p.arrayClass);
|
||||||
assertEquals(c, ((ClassDesc) p.arrayClass.describeConstable().orElseThrow()).componentType());
|
assertEquals(c, p.arrayClass.describeConstable().orElseThrow().componentType());
|
||||||
assertEquals(c, p.classDesc.arrayType().componentType());
|
assertEquals(c, p.classDesc.arrayType().componentType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -228,9 +228,9 @@ public class ClassDescTest extends SymbolicDescTest {
|
|||||||
|
|
||||||
assertEquals(a1, ClassDesc.ofDescriptor("[" + d));
|
assertEquals(a1, ClassDesc.ofDescriptor("[" + d));
|
||||||
assertEquals(a2, ClassDesc.ofDescriptor("[[" + d));
|
assertEquals(a2, ClassDesc.ofDescriptor("[[" + d));
|
||||||
assertEquals(classToDescriptor((Class<?>) a0.resolveConstantDesc(LOOKUP)), a0.descriptorString());
|
assertEquals(classToDescriptor(a0.resolveConstantDesc(LOOKUP)), a0.descriptorString());
|
||||||
assertEquals(classToDescriptor((Class<?>) a1.resolveConstantDesc(LOOKUP)), a1.descriptorString());
|
assertEquals(classToDescriptor(a1.resolveConstantDesc(LOOKUP)), a1.descriptorString());
|
||||||
assertEquals(classToDescriptor((Class<?>) a2.resolveConstantDesc(LOOKUP)), a2.descriptorString());
|
assertEquals(classToDescriptor(a2.resolveConstantDesc(LOOKUP)), a2.descriptorString());
|
||||||
|
|
||||||
testBadArrayRank(ConstantDescs.CD_int);
|
testBadArrayRank(ConstantDescs.CD_int);
|
||||||
testBadArrayRank(ConstantDescs.CD_String);
|
testBadArrayRank(ConstantDescs.CD_String);
|
||||||
|
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
import java.lang.Enum.EnumDesc;
|
import java.lang.Enum.EnumDesc;
|
||||||
import java.lang.constant.MethodTypeDesc;
|
import java.lang.constant.MethodTypeDesc;
|
||||||
import java.lang.invoke.MethodHandle;
|
|
||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.lang.invoke.VarHandle;
|
import java.lang.invoke.VarHandle;
|
||||||
import java.lang.invoke.VarHandle.VarHandleDesc;
|
import java.lang.invoke.VarHandle.VarHandleDesc;
|
||||||
@ -49,7 +48,7 @@ import static org.testng.Assert.assertNull;
|
|||||||
import static org.testng.Assert.assertSame;
|
import static org.testng.Assert.assertSame;
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @compile CondyDescTest.java
|
* @compile CondyDescTest.java
|
||||||
* @run testng CondyDescTest
|
* @run testng CondyDescTest
|
||||||
@ -99,7 +98,7 @@ public class CondyDescTest extends SymbolicDescTest {
|
|||||||
DirectMethodHandleDesc format = MethodHandleDesc.ofMethod(DirectMethodHandleDesc.Kind.STATIC, CD_String, "format",
|
DirectMethodHandleDesc format = MethodHandleDesc.ofMethod(DirectMethodHandleDesc.Kind.STATIC, CD_String, "format",
|
||||||
MethodTypeDesc.of(CD_String, CD_String, CD_Object.arrayType()));
|
MethodTypeDesc.of(CD_String, CD_String, CD_Object.arrayType()));
|
||||||
|
|
||||||
String s = (String) ((MethodHandle) invoker.resolveConstantDesc(LOOKUP))
|
String s = (String) invoker.resolveConstantDesc(LOOKUP)
|
||||||
.invoke(LOOKUP, "", String.class,
|
.invoke(LOOKUP, "", String.class,
|
||||||
format.resolveConstantDesc(LOOKUP), "%s%s", "moo", "cow");
|
format.resolveConstantDesc(LOOKUP), "%s%s", "moo", "cow");
|
||||||
assertEquals(s, "moocow");
|
assertEquals(s, "moocow");
|
||||||
|
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -90,7 +90,7 @@ public class MethodHandleDescTest extends SymbolicDescTest {
|
|||||||
|
|
||||||
DirectMethodHandleDesc rr = (DirectMethodHandleDesc) r;
|
DirectMethodHandleDesc rr = (DirectMethodHandleDesc) r;
|
||||||
assertEquals(r, MethodHandleDesc.of(rr.kind(), rr.owner(), rr.methodName(), rr.lookupDescriptor()));
|
assertEquals(r, MethodHandleDesc.of(rr.kind(), rr.owner(), rr.methodName(), rr.lookupDescriptor()));
|
||||||
assertEquals(r.invocationType().resolveConstantDesc(LOOKUP), ((MethodHandle) r.resolveConstantDesc(LOOKUP)).type());
|
assertEquals(r.invocationType().resolveConstantDesc(LOOKUP), r.resolveConstantDesc(LOOKUP).type());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
testSymbolicDescForwardOnly(r);
|
testSymbolicDescForwardOnly(r);
|
||||||
@ -114,7 +114,7 @@ public class MethodHandleDescTest extends SymbolicDescTest {
|
|||||||
private void testMethodHandleDesc(MethodHandleDesc r, MethodHandle mh) throws ReflectiveOperationException {
|
private void testMethodHandleDesc(MethodHandleDesc r, MethodHandle mh) throws ReflectiveOperationException {
|
||||||
testMethodHandleDesc(r);
|
testMethodHandleDesc(r);
|
||||||
|
|
||||||
assertMHEquals(((MethodHandle) r.resolveConstantDesc(LOOKUP)), mh);
|
assertMHEquals(r.resolveConstantDesc(LOOKUP), mh);
|
||||||
assertEquals(mh.describeConstable().orElseThrow(), r);
|
assertEquals(mh.describeConstable().orElseThrow(), r);
|
||||||
|
|
||||||
// compare extractable properties: refKind, owner, name, type
|
// compare extractable properties: refKind, owner, name, type
|
||||||
@ -179,7 +179,7 @@ public class MethodHandleDescTest extends SymbolicDescTest {
|
|||||||
MethodTypeDesc.of(CD_Integer, CD_int));
|
MethodTypeDesc.of(CD_Integer, CD_int));
|
||||||
MethodHandleDesc takesInteger = mhr.asType(MethodTypeDesc.of(CD_Integer, CD_Integer));
|
MethodHandleDesc takesInteger = mhr.asType(MethodTypeDesc.of(CD_Integer, CD_Integer));
|
||||||
testMethodHandleDesc(takesInteger);
|
testMethodHandleDesc(takesInteger);
|
||||||
MethodHandle mh1 = (MethodHandle) takesInteger.resolveConstantDesc(LOOKUP);
|
MethodHandle mh1 = takesInteger.resolveConstantDesc(LOOKUP);
|
||||||
assertEquals((Integer) 3, (Integer) mh1.invokeExact((Integer) 3));
|
assertEquals((Integer) 3, (Integer) mh1.invokeExact((Integer) 3));
|
||||||
assertEquals(takesInteger.toString(), "MethodHandleDesc[STATIC/Integer::valueOf(int)Integer].asType(Integer)Integer");
|
assertEquals(takesInteger.toString(), "MethodHandleDesc[STATIC/Integer::valueOf(int)Integer].asType(Integer)Integer");
|
||||||
|
|
||||||
@ -191,7 +191,7 @@ public class MethodHandleDescTest extends SymbolicDescTest {
|
|||||||
|
|
||||||
MethodHandleDesc takesInt = takesInteger.asType(MethodTypeDesc.of(CD_Integer, CD_int));
|
MethodHandleDesc takesInt = takesInteger.asType(MethodTypeDesc.of(CD_Integer, CD_int));
|
||||||
testMethodHandleDesc(takesInt);
|
testMethodHandleDesc(takesInt);
|
||||||
MethodHandle mh2 = (MethodHandle) takesInt.resolveConstantDesc(LOOKUP);
|
MethodHandle mh2 = takesInt.resolveConstantDesc(LOOKUP);
|
||||||
assertEquals((Integer) 3, (Integer) mh2.invokeExact(3));
|
assertEquals((Integer) 3, (Integer) mh2.invokeExact(3));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -241,47 +241,47 @@ public class MethodHandleDescTest extends SymbolicDescTest {
|
|||||||
for (MethodHandleDesc r : List.of(ctorDesc, staticMethodDesc, staticIMethodDesc, instanceMethodDesc, instanceIMethodDesc))
|
for (MethodHandleDesc r : List.of(ctorDesc, staticMethodDesc, staticIMethodDesc, instanceMethodDesc, instanceIMethodDesc))
|
||||||
testMethodHandleDesc(r);
|
testMethodHandleDesc(r);
|
||||||
|
|
||||||
TestHelpers.TestClass instance = (TestHelpers.TestClass) ((MethodHandle)ctorDesc.resolveConstantDesc(LOOKUP)).invokeExact();
|
TestHelpers.TestClass instance = (TestHelpers.TestClass) ctorDesc.resolveConstantDesc(LOOKUP).invokeExact();
|
||||||
TestHelpers.TestClass instance2 = (TestHelpers.TestClass) ((MethodHandle)ctorDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP)).invokeExact();
|
TestHelpers.TestClass instance2 = (TestHelpers.TestClass) ctorDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact();
|
||||||
TestHelpers.TestInterface instanceI = instance;
|
TestHelpers.TestInterface instanceI = instance;
|
||||||
|
|
||||||
assertNotSame(instance, instance2);
|
assertNotSame(instance, instance2);
|
||||||
|
|
||||||
assertEquals(5, (int) ((MethodHandle)staticMethodDesc.resolveConstantDesc(LOOKUP)).invokeExact(5));
|
assertEquals(5, (int) staticMethodDesc.resolveConstantDesc(LOOKUP).invokeExact(5));
|
||||||
assertEquals(5, (int) ((MethodHandle)staticMethodDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP)).invokeExact(5));
|
assertEquals(5, (int) staticMethodDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(5));
|
||||||
assertEquals(0, (int) ((MethodHandle)staticIMethodDesc.resolveConstantDesc(LOOKUP)).invokeExact(5));
|
assertEquals(0, (int) staticIMethodDesc.resolveConstantDesc(LOOKUP).invokeExact(5));
|
||||||
assertEquals(0, (int) ((MethodHandle)staticIMethodDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP)).invokeExact(5));
|
assertEquals(0, (int) staticIMethodDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(5));
|
||||||
|
|
||||||
assertEquals(5, (int) ((MethodHandle)instanceMethodDesc.resolveConstantDesc(LOOKUP)).invokeExact(instance, 5));
|
assertEquals(5, (int) instanceMethodDesc.resolveConstantDesc(LOOKUP).invokeExact(instance, 5));
|
||||||
assertEquals(5, (int) ((MethodHandle)instanceMethodDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP)).invokeExact(instance, 5));
|
assertEquals(5, (int) instanceMethodDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(instance, 5));
|
||||||
assertEquals(5, (int) ((MethodHandle)instanceIMethodDesc.resolveConstantDesc(LOOKUP)).invokeExact(instanceI, 5));
|
assertEquals(5, (int) instanceIMethodDesc.resolveConstantDesc(LOOKUP).invokeExact(instanceI, 5));
|
||||||
assertEquals(5, (int) ((MethodHandle)instanceIMethodDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP)).invokeExact(instanceI, 5));
|
assertEquals(5, (int) instanceIMethodDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(instanceI, 5));
|
||||||
|
|
||||||
try { superMethodDesc.resolveConstantDesc(LOOKUP); fail(); }
|
try { superMethodDesc.resolveConstantDesc(LOOKUP); fail(); }
|
||||||
catch (IllegalAccessException e) { /* expected */ }
|
catch (IllegalAccessException e) { /* expected */ }
|
||||||
assertEquals(-1, (int) ((MethodHandle)superMethodDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP)).invokeExact(instance, 5));
|
assertEquals(-1, (int) superMethodDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(instance, 5));
|
||||||
|
|
||||||
try { superIMethodDesc.resolveConstantDesc(LOOKUP); fail(); }
|
try { superIMethodDesc.resolveConstantDesc(LOOKUP); fail(); }
|
||||||
catch (IllegalAccessException e) { /* expected */ }
|
catch (IllegalAccessException e) { /* expected */ }
|
||||||
assertEquals(0, (int) ((MethodHandle)superIMethodDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP)).invokeExact(instance, 5));
|
assertEquals(0, (int) superIMethodDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(instance, 5));
|
||||||
|
|
||||||
try { privateMethodDesc.resolveConstantDesc(LOOKUP); fail(); }
|
try { privateMethodDesc.resolveConstantDesc(LOOKUP); fail(); }
|
||||||
catch (IllegalAccessException e) { /* expected */ }
|
catch (IllegalAccessException e) { /* expected */ }
|
||||||
assertEquals(5, (int) ((MethodHandle)privateMethodDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP)).invokeExact(instance, 5));
|
assertEquals(5, (int) privateMethodDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(instance, 5));
|
||||||
|
|
||||||
try { privateIMethodDesc.resolveConstantDesc(LOOKUP); fail(); }
|
try { privateIMethodDesc.resolveConstantDesc(LOOKUP); fail(); }
|
||||||
catch (IllegalAccessException e) { /* expected */ }
|
catch (IllegalAccessException e) { /* expected */ }
|
||||||
assertEquals(0, (int) ((MethodHandle)privateIMethodDesc.resolveConstantDesc(TestHelpers.TestInterface.LOOKUP)).invokeExact(instanceI, 5));
|
assertEquals(0, (int) privateIMethodDesc.resolveConstantDesc(TestHelpers.TestInterface.LOOKUP).invokeExact(instanceI, 5));
|
||||||
assertEquals(0, (int) ((MethodHandle)privateIMethodDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP)).invoke(instanceI, 5));
|
assertEquals(0, (int) privateIMethodDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invoke(instanceI, 5));
|
||||||
|
|
||||||
try { privateStaticMethodDesc.resolveConstantDesc(LOOKUP); fail(); }
|
try { privateStaticMethodDesc.resolveConstantDesc(LOOKUP); fail(); }
|
||||||
catch (IllegalAccessException e) { /* expected */ }
|
catch (IllegalAccessException e) { /* expected */ }
|
||||||
assertEquals(5, (int) ((MethodHandle)privateStaticMethodDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP)).invokeExact(5));
|
assertEquals(5, (int) privateStaticMethodDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(5));
|
||||||
|
|
||||||
try { privateStaticIMethodDesc.resolveConstantDesc(LOOKUP); fail(); }
|
try { privateStaticIMethodDesc.resolveConstantDesc(LOOKUP); fail(); }
|
||||||
catch (IllegalAccessException e) { /* expected */ }
|
catch (IllegalAccessException e) { /* expected */ }
|
||||||
assertEquals(0, (int) ((MethodHandle)privateStaticIMethodDesc.resolveConstantDesc(TestHelpers.TestInterface.LOOKUP)).invokeExact(5));
|
assertEquals(0, (int) privateStaticIMethodDesc.resolveConstantDesc(TestHelpers.TestInterface.LOOKUP).invokeExact(5));
|
||||||
assertEquals(0, (int) ((MethodHandle)privateStaticIMethodDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP)).invokeExact(5));
|
assertEquals(0, (int) privateStaticIMethodDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(5));
|
||||||
|
|
||||||
MethodHandleDesc staticSetterDesc = MethodHandleDesc.ofField(STATIC_SETTER, testClass, "sf", CD_int);
|
MethodHandleDesc staticSetterDesc = MethodHandleDesc.ofField(STATIC_SETTER, testClass, "sf", CD_int);
|
||||||
MethodHandleDesc staticGetterDesc = MethodHandleDesc.ofField(STATIC_GETTER, testClass, "sf", CD_int);
|
MethodHandleDesc staticGetterDesc = MethodHandleDesc.ofField(STATIC_GETTER, testClass, "sf", CD_int);
|
||||||
@ -292,22 +292,22 @@ public class MethodHandleDescTest extends SymbolicDescTest {
|
|||||||
for (MethodHandleDesc r : List.of(staticSetterDesc, staticGetterDesc, staticGetterIDesc, setterDesc, getterDesc))
|
for (MethodHandleDesc r : List.of(staticSetterDesc, staticGetterDesc, staticGetterIDesc, setterDesc, getterDesc))
|
||||||
testMethodHandleDesc(r);
|
testMethodHandleDesc(r);
|
||||||
|
|
||||||
((MethodHandle)staticSetterDesc.resolveConstantDesc(LOOKUP)).invokeExact(6); assertEquals(TestHelpers.TestClass.sf, 6);
|
staticSetterDesc.resolveConstantDesc(LOOKUP).invokeExact(6); assertEquals(TestHelpers.TestClass.sf, 6);
|
||||||
assertEquals(6, (int) ((MethodHandle)staticGetterDesc.resolveConstantDesc(LOOKUP)).invokeExact());
|
assertEquals(6, (int) staticGetterDesc.resolveConstantDesc(LOOKUP).invokeExact());
|
||||||
assertEquals(6, (int) ((MethodHandle)staticGetterDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP)).invokeExact());
|
assertEquals(6, (int) staticGetterDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact());
|
||||||
((MethodHandle)staticSetterDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP)).invokeExact(7); assertEquals(TestHelpers.TestClass.sf, 7);
|
staticSetterDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(7); assertEquals(TestHelpers.TestClass.sf, 7);
|
||||||
assertEquals(7, (int) ((MethodHandle)staticGetterDesc.resolveConstantDesc(LOOKUP)).invokeExact());
|
assertEquals(7, (int) staticGetterDesc.resolveConstantDesc(LOOKUP).invokeExact());
|
||||||
assertEquals(7, (int) ((MethodHandle)staticGetterDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP)).invokeExact());
|
assertEquals(7, (int) staticGetterDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact());
|
||||||
|
|
||||||
assertEquals(3, (int) ((MethodHandle)staticGetterIDesc.resolveConstantDesc(LOOKUP)).invokeExact());
|
assertEquals(3, (int) staticGetterIDesc.resolveConstantDesc(LOOKUP).invokeExact());
|
||||||
assertEquals(3, (int) ((MethodHandle)staticGetterIDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP)).invokeExact());
|
assertEquals(3, (int) staticGetterIDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact());
|
||||||
|
|
||||||
((MethodHandle)setterDesc.resolveConstantDesc(LOOKUP)).invokeExact(instance, 6); assertEquals(instance.f, 6);
|
setterDesc.resolveConstantDesc(LOOKUP).invokeExact(instance, 6); assertEquals(instance.f, 6);
|
||||||
assertEquals(6, (int) ((MethodHandle)getterDesc.resolveConstantDesc(LOOKUP)).invokeExact(instance));
|
assertEquals(6, (int) getterDesc.resolveConstantDesc(LOOKUP).invokeExact(instance));
|
||||||
assertEquals(6, (int) ((MethodHandle)getterDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP)).invokeExact(instance));
|
assertEquals(6, (int) getterDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(instance));
|
||||||
((MethodHandle)setterDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP)).invokeExact(instance, 7); assertEquals(instance.f, 7);
|
setterDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(instance, 7); assertEquals(instance.f, 7);
|
||||||
assertEquals(7, (int) ((MethodHandle)getterDesc.resolveConstantDesc(LOOKUP)).invokeExact(instance));
|
assertEquals(7, (int) getterDesc.resolveConstantDesc(LOOKUP).invokeExact(instance));
|
||||||
assertEquals(7, (int) ((MethodHandle)getterDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP)).invokeExact(instance));
|
assertEquals(7, (int) getterDesc.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(instance));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertBadArgs(Supplier<MethodHandleDesc> supplier, String s) {
|
private void assertBadArgs(Supplier<MethodHandleDesc> supplier, String s) {
|
||||||
@ -346,7 +346,7 @@ public class MethodHandleDescTest extends SymbolicDescTest {
|
|||||||
&& ((f.getModifiers() & Modifier.STATIC) != 0)
|
&& ((f.getModifiers() & Modifier.STATIC) != 0)
|
||||||
&& ((f.getModifiers() & Modifier.PUBLIC) != 0)) {
|
&& ((f.getModifiers() & Modifier.PUBLIC) != 0)) {
|
||||||
MethodHandleDesc r = (MethodHandleDesc) f.get(null);
|
MethodHandleDesc r = (MethodHandleDesc) f.get(null);
|
||||||
MethodHandle m = (MethodHandle)r.resolveConstantDesc(MethodHandles.lookup());
|
MethodHandle m = r.resolveConstantDesc(MethodHandles.lookup());
|
||||||
testMethodHandleDesc(r, m);
|
testMethodHandleDesc(r, m);
|
||||||
++tested;
|
++tested;
|
||||||
}
|
}
|
||||||
|
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -100,7 +100,7 @@ public class MethodTypeDescTest extends SymbolicDescTest {
|
|||||||
ClassDesc rc = ClassDesc.ofDescriptor(r);
|
ClassDesc rc = ClassDesc.ofDescriptor(r);
|
||||||
MethodTypeDesc newDesc = mtDesc.changeReturnType(rc);
|
MethodTypeDesc newDesc = mtDesc.changeReturnType(rc);
|
||||||
assertEquals(newDesc, MethodTypeDesc.of(rc, paramTypes));
|
assertEquals(newDesc, MethodTypeDesc.of(rc, paramTypes));
|
||||||
testMethodTypeDesc(newDesc, mt.changeReturnType((Class<?>)rc.resolveConstantDesc(LOOKUP)));
|
testMethodTypeDesc(newDesc, mt.changeReturnType(rc.resolveConstantDesc(LOOKUP)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// try with null parameter
|
// try with null parameter
|
||||||
@ -119,7 +119,7 @@ public class MethodTypeDescTest extends SymbolicDescTest {
|
|||||||
ps[i] = pc;
|
ps[i] = pc;
|
||||||
MethodTypeDesc newDesc = mtDesc.changeParameterType(i, pc);
|
MethodTypeDesc newDesc = mtDesc.changeParameterType(i, pc);
|
||||||
assertEquals(newDesc, MethodTypeDesc.of(returnType, ps));
|
assertEquals(newDesc, MethodTypeDesc.of(returnType, ps));
|
||||||
testMethodTypeDesc(newDesc, mt.changeParameterType(i, (Class<?>)pc.resolveConstantDesc(LOOKUP)));
|
testMethodTypeDesc(newDesc, mt.changeParameterType(i, pc.resolveConstantDesc(LOOKUP)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +146,7 @@ public class MethodTypeDescTest extends SymbolicDescTest {
|
|||||||
.toArray(ClassDesc[]::new);
|
.toArray(ClassDesc[]::new);
|
||||||
MethodTypeDesc newDesc = mtDesc.insertParameterTypes(i, p);
|
MethodTypeDesc newDesc = mtDesc.insertParameterTypes(i, p);
|
||||||
assertEquals(newDesc, MethodTypeDesc.of(returnType, ps));
|
assertEquals(newDesc, MethodTypeDesc.of(returnType, ps));
|
||||||
testMethodTypeDesc(newDesc, mt.insertParameterTypes(i, (Class<?>)p.resolveConstantDesc(LOOKUP)));
|
testMethodTypeDesc(newDesc, mt.insertParameterTypes(i, p.resolveConstantDesc(LOOKUP)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -66,7 +66,7 @@ public class MethodTypeDescriptorAccessTest {
|
|||||||
|
|
||||||
private void checkValidAccess(MethodTypeDesc mtd, Lookup lookup) {
|
private void checkValidAccess(MethodTypeDesc mtd, Lookup lookup) {
|
||||||
try {
|
try {
|
||||||
MethodType mt = (MethodType)mtd.resolveConstantDesc(lookup);
|
MethodType mt = mtd.resolveConstantDesc(lookup);
|
||||||
} catch (ReflectiveOperationException unexpected) {
|
} catch (ReflectiveOperationException unexpected) {
|
||||||
throw new Error("resolveConstantDesc() threw ReflectiveOperationException unexpectedly with cause " +
|
throw new Error("resolveConstantDesc() threw ReflectiveOperationException unexpectedly with cause " +
|
||||||
unexpected.getCause() + " for " + mtd);
|
unexpected.getCause() + " for " + mtd);
|
||||||
@ -75,7 +75,7 @@ public class MethodTypeDescriptorAccessTest {
|
|||||||
|
|
||||||
private void checkInvalidAccess(MethodTypeDesc mtd, Lookup lookup) {
|
private void checkInvalidAccess(MethodTypeDesc mtd, Lookup lookup) {
|
||||||
try {
|
try {
|
||||||
MethodType mt = (MethodType)mtd.resolveConstantDesc(lookup);
|
MethodType mt = mtd.resolveConstantDesc(lookup);
|
||||||
throw new Error("resolveConstantDesc() succeeded unexpectedly " + mtd);
|
throw new Error("resolveConstantDesc() succeeded unexpectedly " + mtd);
|
||||||
} catch (ReflectiveOperationException expected) {
|
} catch (ReflectiveOperationException expected) {
|
||||||
if (expected.getClass() != IllegalAccessException.class) {
|
if (expected.getClass() != IllegalAccessException.class) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -87,14 +87,14 @@ public class ResolveConstantDesc {
|
|||||||
// IAE thrown when resolving MethodType using the given Lookup object
|
// IAE thrown when resolving MethodType using the given Lookup object
|
||||||
private static void throwIAE(Lookup lookup, MethodTypeDesc mtd) throws Exception {
|
private static void throwIAE(Lookup lookup, MethodTypeDesc mtd) throws Exception {
|
||||||
try {
|
try {
|
||||||
MethodType mtype = (MethodType)mtd.resolveConstantDesc(lookup);
|
MethodType mtype = mtd.resolveConstantDesc(lookup);
|
||||||
throw new RuntimeException("unexpected IAE not thrown");
|
throw new RuntimeException("unexpected IAE not thrown");
|
||||||
} catch (IllegalAccessException e) { }
|
} catch (IllegalAccessException e) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void throwACC(Lookup lookup, MethodTypeDesc mtd) throws Exception {
|
private static void throwACC(Lookup lookup, MethodTypeDesc mtd) throws Exception {
|
||||||
try {
|
try {
|
||||||
MethodType mtype = (MethodType)mtd.resolveConstantDesc(lookup);
|
MethodType mtype = mtd.resolveConstantDesc(lookup);
|
||||||
throw new RuntimeException("unexpected IAE not thrown");
|
throw new RuntimeException("unexpected IAE not thrown");
|
||||||
} catch (AccessControlException e) {
|
} catch (AccessControlException e) {
|
||||||
Permission perm = e.getPermission();
|
Permission perm = e.getPermission();
|
||||||
|
@ -56,16 +56,16 @@ public class ReferenceClassDescResolve {
|
|||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
public Class<?> resolveClassOrInterface() throws ReflectiveOperationException {
|
public Class<?> resolveClassOrInterface() throws ReflectiveOperationException {
|
||||||
return (Class<?>) CLASS_OR_INTERFACE.resolveConstantDesc(LOOKUP);
|
return CLASS_OR_INTERFACE.resolveConstantDesc(LOOKUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
public Class<?> resolveReferenceArray() throws ReflectiveOperationException {
|
public Class<?> resolveReferenceArray() throws ReflectiveOperationException {
|
||||||
return (Class<?>) REFERENCE_ARRAY.resolveConstantDesc(LOOKUP);
|
return REFERENCE_ARRAY.resolveConstantDesc(LOOKUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
public Class<?> resolvePrimitiveArray() throws ReflectiveOperationException {
|
public Class<?> resolvePrimitiveArray() throws ReflectiveOperationException {
|
||||||
return (Class<?>) PRIMITIVE_ARRAY.resolveConstantDesc(LOOKUP);
|
return PRIMITIVE_ARRAY.resolveConstantDesc(LOOKUP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user