8311084: Add typeSymbol() API for applicable constant pool entries

Reviewed-by: briangoetz, asotona
This commit is contained in:
Chen Liang 2023-09-21 08:05:01 +00:00 committed by Adam Sotona
parent 9f5d2b947f
commit 1749ba265b
7 changed files with 48 additions and 4 deletions

@ -26,6 +26,8 @@ package jdk.internal.classfile.constantpool;
import jdk.internal.classfile.TypeKind;
import jdk.internal.classfile.impl.Util;
import java.lang.constant.ClassDesc;
import java.lang.constant.ConstantDesc;
import java.lang.constant.DynamicConstantDesc;
@ -40,6 +42,13 @@ public sealed interface ConstantDynamicEntry
extends DynamicConstantPoolEntry, LoadableConstantEntry
permits AbstractPoolEntry.ConstantDynamicEntryImpl {
/**
* {@return a symbolic descriptor for the dynamic constant's type}
*/
default ClassDesc typeSymbol() {
return Util.fieldTypeSymbol(nameAndType());
}
@Override
default ConstantDesc constantValue() {
return asSymbol();
@ -51,7 +60,7 @@ public sealed interface ConstantDynamicEntry
default DynamicConstantDesc<?> asSymbol() {
return DynamicConstantDesc.ofNamed(bootstrap().bootstrapMethod().asSymbol(),
name().stringValue(),
Util.fieldTypeSymbol(nameAndType()),
typeSymbol(),
bootstrap().arguments().stream()
.map(LoadableConstantEntry::constantValue)
.toArray(ConstantDesc[]::new));

@ -25,6 +25,9 @@
package jdk.internal.classfile.constantpool;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import jdk.internal.classfile.impl.Util;
import java.lang.constant.ClassDesc;
/**
* Models a {@code CONSTANT_Fieldref_info} constant in the constant pool of a
@ -34,4 +37,10 @@ import jdk.internal.classfile.impl.AbstractPoolEntry;
public sealed interface FieldRefEntry extends MemberRefEntry
permits AbstractPoolEntry.FieldRefEntryImpl {
/**
* {@return a symbolic descriptor for the field's type}
*/
default ClassDesc typeSymbol() {
return Util.fieldTypeSymbol(nameAndType());
}
}

@ -25,6 +25,9 @@
package jdk.internal.classfile.constantpool;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import jdk.internal.classfile.impl.Util;
import java.lang.constant.MethodTypeDesc;
/**
* Models a {@code CONSTANT_InterfaceMethodRef_info} constant in the constant pool of a
@ -35,4 +38,10 @@ public sealed interface InterfaceMethodRefEntry
extends MemberRefEntry
permits AbstractPoolEntry.InterfaceMethodRefEntryImpl {
/**
* {@return a symbolic descriptor for the interface method's type}
*/
default MethodTypeDesc typeSymbol() {
return Util.methodTypeSymbol(nameAndType());
}
}

@ -26,6 +26,7 @@ package jdk.internal.classfile.constantpool;
import java.lang.constant.ConstantDesc;
import java.lang.constant.DynamicCallSiteDesc;
import java.lang.constant.MethodTypeDesc;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import jdk.internal.classfile.impl.Util;
@ -38,13 +39,20 @@ public sealed interface InvokeDynamicEntry
extends DynamicConstantPoolEntry
permits AbstractPoolEntry.InvokeDynamicEntryImpl {
/**
* {@return a symbolic descriptor for the call site's invocation type}
*/
default MethodTypeDesc typeSymbol() {
return Util.methodTypeSymbol(nameAndType());
}
/**
* {@return a symbolic descriptor for the dynamic call site}
*/
default DynamicCallSiteDesc asSymbol() {
return DynamicCallSiteDesc.of(bootstrap().bootstrapMethod().asSymbol(),
name().stringValue(),
Util.methodTypeSymbol(nameAndType()),
typeSymbol(),
bootstrap().arguments().stream()
.map(LoadableConstantEntry::constantValue)
.toArray(ConstantDesc[]::new));

@ -25,6 +25,9 @@
package jdk.internal.classfile.constantpool;
import jdk.internal.classfile.impl.AbstractPoolEntry;
import jdk.internal.classfile.impl.Util;
import java.lang.constant.MethodTypeDesc;
/**
* Models a {@code CONSTANT_MethodRef_info} constant in the constant pool of a
@ -34,4 +37,10 @@ import jdk.internal.classfile.impl.AbstractPoolEntry;
public sealed interface MethodRefEntry extends MemberRefEntry
permits AbstractPoolEntry.MethodRefEntryImpl {
/**
* {@return a symbolic descriptor for the method's type}
*/
default MethodTypeDesc typeSymbol() {
return Util.methodTypeSymbol(nameAndType());
}
}

@ -77,7 +77,7 @@ public sealed interface FieldInstruction extends Instruction
* {@return a symbolic descriptor for the type of the field}
*/
default ClassDesc typeSymbol() {
return Util.fieldTypeSymbol(field().nameAndType());
return field().typeSymbol();
}
/**

@ -70,7 +70,7 @@ public sealed interface InvokeDynamicInstruction extends Instruction
* {@return the invocation type of the call site, as a symbolic descriptor}
*/
default MethodTypeDesc typeSymbol() {
return Util.methodTypeSymbol(invokedynamic().nameAndType());
return invokedynamic().typeSymbol();
}
/**