/* * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /** * PROVISIONAL API, WORK IN PROGRESS: * This package contains dynamic language support provided directly by * the Java core class libraries and virtual machine. *

* Certain types in this package have special relations to dynamic * language support in the virtual machine: *

* *

Corresponding JVM bytecode format changes

* The following low-level information is presented here as a preview of * changes being made to the Java Virtual Machine specification for JSR 292. * *

{@code invokedynamic} instruction format

* In bytecode, an {@code invokedynamic} instruction is formatted as five bytes. * The first byte is the opcode 186 (hexadecimal {@code BA}). * The next two bytes are a constant pool index (in the same format as for the other {@code invoke} instructions). * The final two bytes are reserved for future use and required to be zero. * The constant pool reference is to a entry with tag {@code CONSTANT_NameAndType} * (decimal 12). It is thus not a method reference of any sort, but merely * the method name, argument types, and return type of the dynamic call site. * (TBD: The EG is discussing the possibility of a special constant pool entry type, * so that other information may be added, such as a per-instruction bootstrap * method and/or annotations.) * *

constant pool entries for {@code MethodType}s

* If a constant pool entry has the tag {@code CONSTANT_MethodType} (decimal 16), * it must contain exactly two more bytes, which are an index to a {@code CONSTANT_Utf8} * entry which represents a method type signature. The JVM will ensure that on first * execution of an {@code ldc} instruction for this entry, a {@link java.dyn.MethodType} * will be created which represents the signature. * Any classes mentioned in the {@code MethodType} will be loaded if necessary, * but not initialized. * Access checking and error reporting is performed exactly as it is for * references by {@code ldc} instructions to {@code CONSTANT_Class} constants. * *

constant pool entries for {@code MethodHandle}s

* If a constant pool entry has the tag {@code CONSTANT_MethodHandle} (decimal 15), * it must contain exactly three more bytes. The first byte after the tag is a subtag * value in the range 1 through 9, and the last two are an index to a * {@code CONSTANT_Fieldref}, {@code CONSTANT_Methodref}, or * {@code CONSTANT_InterfaceMethodref} entry which represents a field or method * for which a method handle is to be created. * The JVM will ensure that on first execution of an {@code ldc} instruction * for this entry, a {@link java.dyn.MethodHandle} will be created which represents * the field or method reference, according to the specific mode implied by the subtag. *

* As with {@code CONSTANT_Class} and {@code CONSTANT_MethodType} constants, * the {@code Class} or {@code MethodType} object which reifies the field or method's * type is created. Any classes mentioned in this reificaiton will be loaded if necessary, * but not initialized, and access checking and error reporting performed as usual. *

* The method handle itself will have a type and behavior determined by the subtag as follows: * * * * * * * * * * * * *
Nsubtag namememberMH typeMH behavior
1REF_getFieldC.f:T(C)Tgetfield C.f:T
2REF_getStaticC.f:T( )Tgetstatic C.f:T
3REF_putFieldC.f:T(C,T)voidputfield C.f:T
4REF_putStaticC.f:T(T)voidputstatic C.f:T
5REF_invokeVirtualC.m(A*)T(C,A*)Tinvokevirtual C.m(A*)T
6REF_invokeStaticC.m(A*)T(C,A*)Tinvokestatic C.m(A*)T
7REF_invokeSpecialC.m(A*)T(C,A*)Tinvokespecial C.m(A*)T
8REF_newInvokeSpecialC.<init>(A*)void(A*)Cnew C; dup; invokespecial C.<init>(A*)void
9REF_invokeInterfaceC.m(A*)T(C,A*)Tinvokeinterface C.m(A*)T
*
*

* The special names {@code } and {@code } are not allowed except for subtag 8 as shown. *

* The verifier applies the same access checks and restrictions for these references as for the hypothetical * bytecode instructions specified in the last column of the table. In particular, method handles to * private and protected members can be created in exactly those classes for which the corresponding * normal accesses are legal. *

* None of these constant types force class initialization. * Method handles for subtags {@code REF_getStatic}, {@code REF_putStatic}, and {@code REF_invokeStatic} * may force class initialization on their first invocation, just like the corresponding bytecodes. * * @author John Rose, JSR 292 EG */ package java.dyn;