src/java.base/share/classes/java/lang/invoke/SimpleMethodHandle.java

Print this page
rev 17771 : 8184777: species logic for BoundMethodHandle doesn't scale, needs refactor


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  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 
  26 package java.lang.invoke;
  27 


  28 import static java.lang.invoke.LambdaForm.BasicType.*;
  29 import static java.lang.invoke.MethodHandleStatics.*;
  30 
  31 /**
  32  * A method handle whose behavior is determined only by its LambdaForm.
  33  * @author jrose
  34  */
  35 final class SimpleMethodHandle extends BoundMethodHandle {
  36     private SimpleMethodHandle(MethodType type, LambdaForm form) {
  37         super(type, form);
  38     }
  39 
  40     /*non-public*/ static BoundMethodHandle make(MethodType type, LambdaForm form) {
  41         return new SimpleMethodHandle(type, form);
  42     }
  43 
  44     /*non-public*/ static final SpeciesData SPECIES_DATA = SpeciesData.EMPTY;
  45 
  46     /*non-public*/ public SpeciesData speciesData() {
  47             return SPECIES_DATA;
  48     }
  49 
  50     @Override
  51     /*non-public*/ BoundMethodHandle copyWith(MethodType mt, LambdaForm lf) {
  52         return make(mt, lf);
  53     }
  54 
  55     @Override
  56     String internalProperties() {
  57         return "\n& Class="+getClass().getSimpleName();
  58     }
  59 
  60     @Override
  61     /*non-public*/ public int fieldCount() {
  62         return 0;
  63     }
  64 
  65     @Override
  66     /*non-public*/ final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object narg) {
  67         return BoundMethodHandle.bindSingle(mt, lf, narg); // Use known fast path.
  68     }
  69     @Override
  70     /*non-public*/ final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) {
  71         try {
  72             return (BoundMethodHandle) SPECIES_DATA.extendWith(I_TYPE).constructor().invokeBasic(mt, lf, narg);
  73         } catch (Throwable ex) {
  74             throw uncaughtException(ex);
  75         }
  76     }
  77     @Override
  78     /*non-public*/ final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) {
  79         try {
  80             return (BoundMethodHandle) SPECIES_DATA.extendWith(J_TYPE).constructor().invokeBasic(mt, lf, narg);
  81         } catch (Throwable ex) {
  82             throw uncaughtException(ex);
  83         }
  84     }
  85     @Override
  86     /*non-public*/ final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) {
  87         try {
  88             return (BoundMethodHandle) SPECIES_DATA.extendWith(F_TYPE).constructor().invokeBasic(mt, lf, narg);
  89         } catch (Throwable ex) {
  90             throw uncaughtException(ex);
  91         }
  92     }
  93     @Override
  94     /*non-public*/ final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) {
  95         try {
  96             return (BoundMethodHandle) SPECIES_DATA.extendWith(D_TYPE).constructor().invokeBasic(mt, lf, narg);
  97         } catch (Throwable ex) {
  98             throw uncaughtException(ex);
  99         }
 100     }
 101 }


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  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 
  26 package java.lang.invoke;
  27 
  28 import jdk.internal.vm.annotation.Stable;
  29 
  30 import static java.lang.invoke.LambdaForm.BasicType.*;
  31 import static java.lang.invoke.MethodHandleStatics.*;
  32 
  33 /**
  34  * A method handle whose behavior is determined only by its LambdaForm.
  35  * @author jrose
  36  */
  37 final class SimpleMethodHandle extends BoundMethodHandle {
  38     private SimpleMethodHandle(MethodType type, LambdaForm form) {
  39         super(type, form);
  40     }
  41 
  42     /*non-public*/ static BoundMethodHandle make(MethodType type, LambdaForm form) {
  43         return new SimpleMethodHandle(type, form);
  44     }
  45 
  46     /*non-public*/ @Stable static BMHSpecies BMH_SPECIES;
  47 
  48     /*non-public*/ public BMHSpecies speciesData() {
  49             return BMH_SPECIES;
  50     }
  51 
  52     @Override
  53     /*non-public*/ BoundMethodHandle copyWith(MethodType mt, LambdaForm lf) {
  54         return make(mt, lf);
  55     }
  56 
  57     @Override
  58     String internalProperties() {
  59         return "\n& Class="+getClass().getSimpleName();
  60     }
  61 
  62     @Override





  63     /*non-public*/ final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object narg) {
  64         return BoundMethodHandle.bindSingle(mt, lf, narg); // Use known fast path.
  65     }
  66     @Override
  67     /*non-public*/ final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) {
  68         try {
  69             return (BoundMethodHandle) BMH_SPECIES.extendWith(I_TYPE_NUM).factory().invokeBasic(mt, lf, narg);
  70         } catch (Throwable ex) {
  71             throw uncaughtException(ex);
  72         }
  73     }
  74     @Override
  75     /*non-public*/ final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) {
  76         try {
  77             return (BoundMethodHandle) BMH_SPECIES.extendWith(J_TYPE_NUM).factory().invokeBasic(mt, lf, narg);
  78         } catch (Throwable ex) {
  79             throw uncaughtException(ex);
  80         }
  81     }
  82     @Override
  83     /*non-public*/ final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) {
  84         try {
  85             return (BoundMethodHandle) BMH_SPECIES.extendWith(F_TYPE_NUM).factory().invokeBasic(mt, lf, narg);
  86         } catch (Throwable ex) {
  87             throw uncaughtException(ex);
  88         }
  89     }
  90     @Override
  91     /*non-public*/ final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) {
  92         try {
  93             return (BoundMethodHandle) BMH_SPECIES.extendWith(D_TYPE_NUM).factory().invokeBasic(mt, lf, narg);
  94         } catch (Throwable ex) {
  95             throw uncaughtException(ex);
  96         }
  97     }
  98 }