< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2008, 2016, 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.  Oracle designates this
   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


 288     /*package-private*/
 289     MethodHandle getTargetVolatile() {
 290         return (MethodHandle) UNSAFE.getReferenceVolatile(this, getTargetOffset());
 291     }
 292     /*package-private*/
 293     void setTargetVolatile(MethodHandle newTarget) {
 294         MethodHandleNatives.setCallSiteTargetVolatile(this, newTarget);
 295     }
 296 
 297     // this implements the upcall from the JVM, MethodHandleNatives.linkCallSite:
 298     static CallSite makeSite(MethodHandle bootstrapMethod,
 299                              // Callee information:
 300                              String name, MethodType type,
 301                              // Extra arguments for BSM, if any:
 302                              Object info,
 303                              // Caller information:
 304                              Class<?> callerClass) {
 305         CallSite site;
 306         try {
 307             Object binding = BootstrapMethodInvoker.invoke(
 308                     CallSite.class, bootstrapMethod, name, type, info, callerClass);

 309             if (binding instanceof CallSite) {
 310                 site = (CallSite) binding;
 311             } else {
 312                 // See the "Linking Exceptions" section for the invokedynamic
 313                 // instruction in JVMS 6.5.
 314                 // Throws a runtime exception defining the cause that is then
 315                 // in the "catch (Throwable ex)" a few lines below wrapped in
 316                 // BootstrapMethodError
 317                 throw new ClassCastException("CallSite bootstrap method failed to produce an instance of CallSite");
 318             }
 319             if (!site.getTarget().type().equals(type)) {
 320                 // See the "Linking Exceptions" section for the invokedynamic
 321                 // instruction in JVMS 6.5.
 322                 // Throws a runtime exception defining the cause that is then
 323                 // in the "catch (Throwable ex)" a few lines below wrapped in
 324                 // BootstrapMethodError
 325                 throw wrongTargetType(site.getTarget(), type);
 326             }
 327         } catch (Error e) {
 328             // Pass through an Error, including BootstrapMethodError, any other
   1 /*
   2  * Copyright (c) 2008, 2018, 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.  Oracle designates this
   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


 288     /*package-private*/
 289     MethodHandle getTargetVolatile() {
 290         return (MethodHandle) UNSAFE.getReferenceVolatile(this, getTargetOffset());
 291     }
 292     /*package-private*/
 293     void setTargetVolatile(MethodHandle newTarget) {
 294         MethodHandleNatives.setCallSiteTargetVolatile(this, newTarget);
 295     }
 296 
 297     // this implements the upcall from the JVM, MethodHandleNatives.linkCallSite:
 298     static CallSite makeSite(MethodHandle bootstrapMethod,
 299                              // Callee information:
 300                              String name, MethodType type,
 301                              // Extra arguments for BSM, if any:
 302                              Object info,
 303                              // Caller information:
 304                              Class<?> callerClass) {
 305         CallSite site;
 306         try {
 307             Object binding = BootstrapMethodInvoker.invoke(
 308                     CallSite.class, bootstrapMethod, name, type, info, callerClass,
 309                     true);
 310             if (binding instanceof CallSite) {
 311                 site = (CallSite) binding;
 312             } else {
 313                 // See the "Linking Exceptions" section for the invokedynamic
 314                 // instruction in JVMS 6.5.
 315                 // Throws a runtime exception defining the cause that is then
 316                 // in the "catch (Throwable ex)" a few lines below wrapped in
 317                 // BootstrapMethodError
 318                 throw new ClassCastException("CallSite bootstrap method failed to produce an instance of CallSite");
 319             }
 320             if (!site.getTarget().type().equals(type)) {
 321                 // See the "Linking Exceptions" section for the invokedynamic
 322                 // instruction in JVMS 6.5.
 323                 // Throws a runtime exception defining the cause that is then
 324                 // in the "catch (Throwable ex)" a few lines below wrapped in
 325                 // BootstrapMethodError
 326                 throw wrongTargetType(site.getTarget(), type);
 327             }
 328         } catch (Error e) {
 329             // Pass through an Error, including BootstrapMethodError, any other
< prev index next >