Skip to content

Commit

Permalink
8311084: Add typeSymbol() API for applicable constant pool entries
Browse files Browse the repository at this point in the history
Reviewed-by: briangoetz, asotona
  • Loading branch information
liach authored and asotona committed Sep 21, 2023
1 parent 9f5d2b9 commit 1749ba2
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

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;

Expand All @@ -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();
Expand All @@ -51,7 +60,7 @@ default ConstantDesc constantValue() {
default DynamicConstantDesc<?> asSymbol() {
return DynamicConstantDesc.ofNamed(bootstrap().bootstrapMethod().asSymbol(),
name().stringValue(),
Util.fieldTypeSymbol(nameAndType()),
typeSymbol(),
bootstrap().arguments().stream()
.map(LoadableConstantEntry::constantValue)
.toArray(ConstantDesc[]::new));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,4 +37,10 @@
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

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;
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,4 +37,10 @@
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ default Utf8Entry type() {
* {@return a symbolic descriptor for the type of the field}
*/
default ClassDesc typeSymbol() {
return Util.fieldTypeSymbol(field().nameAndType());
return field().typeSymbol();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ default Utf8Entry type() {
* {@return the invocation type of the call site, as a symbolic descriptor}
*/
default MethodTypeDesc typeSymbol() {
return Util.methodTypeSymbol(invokedynamic().nameAndType());
return invokedynamic().typeSymbol();
}

/**
Expand Down

0 comments on commit 1749ba2

Please sign in to comment.