1 /*
   2  * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package jdk.vm.ci.hotspot;
  24 
  25 import jdk.vm.ci.meta.Signature;
  26 
  27 /**
  28  * Describes a method for which the VM has an intrinsic implementation.
  29  */
  30 public final class VMIntrinsicMethod {
  31 
  32     /**
  33      * The name of the class declaring the intrinsified method. The name is in
  34      * <a href="https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.2.1">class
  35      * file format</a> (e.g., {@code "java/lang/Thread"} instead of {@code "java.lang.Thread"}).
  36      */
  37     public final String declaringClass;
  38 
  39     /**
  40      * The name of the intrinsified method. This is not guaranteed to be a legal method name (e.g.,
  41      * there is a HotSpot intrinsic with the name {@code "<compiledLambdaForm>"}).
  42      */
  43     public final String name;
  44 
  45     /**
  46      * The {@link Signature#toMethodDescriptor() descriptor} of the intrinsified method. This is not
  47      * guaranteed to be a legal method descriptor (e.g., intrinsics for signature polymorphic
  48      * methods have a descriptor of {@code "*"}).
  49      */
  50     public final String descriptor;
  51 
  52     /**
  53      * The unique VM identifier for the intrinsic.
  54      */
  55     public final int id;
  56 
  57     @VMEntryPoint
  58     VMIntrinsicMethod(String declaringClass, String name, String descriptor, int id) {
  59         this.declaringClass = declaringClass;
  60         this.name = name;
  61         this.descriptor = descriptor;
  62         this.id = id;
  63     }
  64 
  65     @Override
  66     public boolean equals(Object obj) {
  67         if (obj instanceof VMIntrinsicMethod) {
  68             VMIntrinsicMethod that = (VMIntrinsicMethod) obj;
  69             if (that.id == this.id) {
  70                 assert that.name.equals(this.name) &&
  71                                 that.declaringClass.equals(this.declaringClass) &&
  72                                 that.descriptor.equals(this.descriptor);
  73                 return true;
  74             }
  75         }
  76         return false;
  77     }
  78 
  79     @Override
  80     public int hashCode() {
  81         return id;
  82     }
  83 
  84     @Override
  85     public String toString() {
  86         return String.format("IntrinsicMethod[declaringClass=%s, name=%s, descriptor=%s, id=%d]", declaringClass, name, descriptor, id);
  87     }
  88 }