< prev index next >

src/java.base/share/classes/java/lang/constant/DirectMethodHandleDescImpl.java

Print this page
rev 52749 : Bootstrap method consolidation
* clean up and simplify JDK support code for BSM invocation
* simplify JVM bootstrap handshake: use BootstrapCallInfo only
* remove unused JVM paths and data fields
* move bootstrap argument processing from MethodHandleNatives to ConstantPool
* remove ConstantGroup; merge argument access into BootstrapCallInfo
* adjust BSM argument access: remove copyArguments, add argumentRef API
* add metadata-free BSM modes, including symbolic arguments from CP


  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.lang.constant;
  26 
  27 import java.lang.invoke.MethodHandle;
  28 import java.lang.invoke.MethodHandles;
  29 import java.lang.invoke.MethodType;
  30 import java.util.Objects;
  31 import java.util.Optional;
  32 
  33 import static java.lang.constant.ConstantDescs.BSM_INVOKE;
  34 import static java.lang.constant.ConstantDescs.BSM_METHODHANDLEDESC;
  35 import static java.lang.constant.ConstantDescs.CR_DirectMethodHandleDesc;
  36 import static java.lang.constant.ConstantDescs.DEFAULT_NAME;
  37 import static java.lang.constant.ConstantDescs.MHR_METHODHANDLEDESC_FACTORY;
  38 import static java.lang.constant.ConstantDescs.MHR_METHODTYPEDESC_FACTORY;
  39 import static java.lang.constant.ConstantUtils.validateClassOrInterface;
  40 import static java.lang.constant.ConstantUtils.validateMemberName;
  41 import static java.lang.constant.DirectMethodHandleDesc.Kind.CONSTRUCTOR;
  42 import static java.util.Objects.requireNonNull;
  43 
  44 /**
  45  * A <a href="package-summary.html#nominal">nominal descriptor</a> for a direct
  46  * {@link MethodHandle}.  A {@linkplain DirectMethodHandleDescImpl} corresponds to
  47  * a {@code Constant_MethodHandle_info} entry in the constant pool of a classfile.
  48  */
  49 final class DirectMethodHandleDescImpl implements DirectMethodHandleDesc {
  50 
  51     private final Kind kind;
  52     private final ClassDesc owner;
  53     private final String name;
  54     private final MethodTypeDesc type;
  55 
  56     /**
  57      * Construct a {@linkplain DirectMethodHandleDescImpl} for a method or field
  58      * from a kind, owner, name, and type


 148             case SPECIAL:
 149             case INTERFACE_SPECIAL:
 150                 return lookup.findSpecial(resolvedOwner, name, resolvedType, lookup.lookupClass());
 151             case CONSTRUCTOR:
 152                 return lookup.findConstructor(resolvedOwner, resolvedType);
 153             case GETTER:
 154                 return lookup.findGetter(resolvedOwner, name, resolvedType.returnType());
 155             case STATIC_GETTER:
 156                 return lookup.findStaticGetter(resolvedOwner, name, resolvedType.returnType());
 157             case SETTER:
 158                 return lookup.findSetter(resolvedOwner, name, resolvedType.parameterType(1));
 159             case STATIC_SETTER:
 160                 return lookup.findStaticSetter(resolvedOwner, name, resolvedType.parameterType(0));
 161             default:
 162                 throw new IllegalStateException(kind.name());
 163         }
 164     }
 165 
 166     @Override
 167     public Optional<? extends ConstantDesc<ConstantDesc<MethodHandle>>> describeConstable() {
 168         return Optional.of(DynamicConstantDesc.of(BSM_INVOKE, MHR_METHODHANDLEDESC_FACTORY,
 169                                                   kind.toString(),
 170                                                   owner.descriptorString(),
 171                                                   name,
 172                                                   type.descriptorString()));
 173     }
 174 
 175     @Override
 176     public boolean equals(Object o) {
 177         if (this == o) return true;
 178         if (o == null || getClass() != o.getClass()) return false;
 179         DirectMethodHandleDescImpl desc = (DirectMethodHandleDescImpl) o;
 180         return kind == desc.kind &&
 181                Objects.equals(owner, desc.owner) &&
 182                Objects.equals(name, desc.name) &&
 183                Objects.equals(type, desc.type);
 184     }
 185 
 186     @Override
 187     public int hashCode() {
 188         return Objects.hash(kind, owner, name, type);
 189     }
 190 
 191     @Override
 192     public String toString() {


  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.lang.constant;
  26 
  27 import java.lang.invoke.MethodHandle;
  28 import java.lang.invoke.MethodHandles;
  29 import java.lang.invoke.MethodType;
  30 import java.util.Objects;
  31 import java.util.Optional;
  32 


  33 import static java.lang.constant.ConstantDescs.CR_DirectMethodHandleDesc;
  34 import static java.lang.constant.ConstantDescs.DEFAULT_NAME;


  35 import static java.lang.constant.ConstantUtils.validateClassOrInterface;
  36 import static java.lang.constant.ConstantUtils.validateMemberName;
  37 import static java.lang.constant.DirectMethodHandleDesc.Kind.CONSTRUCTOR;
  38 import static java.util.Objects.requireNonNull;
  39 
  40 /**
  41  * A <a href="package-summary.html#nominal">nominal descriptor</a> for a direct
  42  * {@link MethodHandle}.  A {@linkplain DirectMethodHandleDescImpl} corresponds to
  43  * a {@code Constant_MethodHandle_info} entry in the constant pool of a classfile.
  44  */
  45 final class DirectMethodHandleDescImpl implements DirectMethodHandleDesc {
  46 
  47     private final Kind kind;
  48     private final ClassDesc owner;
  49     private final String name;
  50     private final MethodTypeDesc type;
  51 
  52     /**
  53      * Construct a {@linkplain DirectMethodHandleDescImpl} for a method or field
  54      * from a kind, owner, name, and type


 144             case SPECIAL:
 145             case INTERFACE_SPECIAL:
 146                 return lookup.findSpecial(resolvedOwner, name, resolvedType, lookup.lookupClass());
 147             case CONSTRUCTOR:
 148                 return lookup.findConstructor(resolvedOwner, resolvedType);
 149             case GETTER:
 150                 return lookup.findGetter(resolvedOwner, name, resolvedType.returnType());
 151             case STATIC_GETTER:
 152                 return lookup.findStaticGetter(resolvedOwner, name, resolvedType.returnType());
 153             case SETTER:
 154                 return lookup.findSetter(resolvedOwner, name, resolvedType.parameterType(1));
 155             case STATIC_SETTER:
 156                 return lookup.findStaticSetter(resolvedOwner, name, resolvedType.parameterType(0));
 157             default:
 158                 throw new IllegalStateException(kind.name());
 159         }
 160     }
 161 
 162     @Override
 163     public Optional<? extends ConstantDesc<ConstantDesc<MethodHandle>>> describeConstable() {
 164         return Optional.of(DynamicConstantDesc.ofSymbolic(this));




 165     }
 166 
 167     @Override
 168     public boolean equals(Object o) {
 169         if (this == o) return true;
 170         if (o == null || getClass() != o.getClass()) return false;
 171         DirectMethodHandleDescImpl desc = (DirectMethodHandleDescImpl) o;
 172         return kind == desc.kind &&
 173                Objects.equals(owner, desc.owner) &&
 174                Objects.equals(name, desc.name) &&
 175                Objects.equals(type, desc.type);
 176     }
 177 
 178     @Override
 179     public int hashCode() {
 180         return Objects.hash(kind, owner, name, type);
 181     }
 182 
 183     @Override
 184     public String toString() {
< prev index next >