/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*/
/** Generator for sun.reflect.MethodAccessor and
sun.reflect.ConstructorAccessor objects using bytecodes to
implement reflection. A java.lang.reflect.Method or
java.lang.reflect.Constructor object can delegate its invoke or
newInstance method to an accessor using native code or to one
generated by this class. (Methods and Constructors were merged
together in this class to ensure maximum code sharing.) */
// One for invoke() plus one for constructor
// Only used if forSerialization is true
private boolean isConstructor;
private boolean forSerialization;
private short targetMethodRef;
private short invokeIdx;
private short invokeDescriptorIdx;
// Constant pool index of CONSTANT_Class_info for first
// non-primitive parameter type. Should be incremented by 2.
private short nonPrimitiveParametersBaseIdx;
}
/** This routine is not thread-safe */
int modifiers)
{
name,
false,
false,
null);
}
/** This routine is not thread-safe */
int modifiers)
{
"<init>",
true,
false,
null);
}
/** This routine is not thread-safe */
int modifiers,
{
return (SerializationConstructorAccessorImpl)
"<init>",
true,
true,
}
/** This routine is not thread-safe */
int modifiers,
boolean isConstructor,
boolean forSerialization,
{
this.declaringClass = declaringClass;
this.parameterTypes = parameterTypes;
this.returnType = returnType;
this.isConstructor = isConstructor;
this.forSerialization = forSerialization;
// Constant pool entries:
// ( * = Boxing information: optional)
// (+ = Shared entries provided by AccessorGenerator)
// (^ = Only present if generating SerializationConstructorAccessor)
// [UTF-8] [This class's name]
// [CONSTANT_Class_info] for above
// [UTF-8] "sun/reflect/{MethodAccessorImpl,ConstructorAccessorImpl,SerializationConstructorAccessorImpl}"
// [CONSTANT_Class_info] for above
// [UTF-8] [Target class's name]
// [CONSTANT_Class_info] for above
// ^ [UTF-8] [Serialization: Class's name in which to invoke constructor]
// ^ [CONSTANT_Class_info] for above
// [UTF-8] target method or constructor name
// [UTF-8] target method or constructor signature
// [CONSTANT_NameAndType_info] for above
// [CONSTANT_Methodref_info or CONSTANT_InterfaceMethodref_info] for target method
// [UTF-8] "invoke" or "newInstance"
// [UTF-8] invoke or newInstance descriptor
// [UTF-8] descriptor for type of non-primitive parameter 1
// [CONSTANT_Class_info] for type of non-primitive parameter 1
// ...
// [UTF-8] descriptor for type of non-primitive parameter n
// [CONSTANT_Class_info] for type of non-primitive parameter n
// + [CONSTANT_Class_info] for above
// + [UTF-8] "java/lang/ClassCastException"
// + [CONSTANT_Class_info] for above
// + [UTF-8] "java/lang/NullPointerException"
// + [CONSTANT_Class_info] for above
// + [UTF-8] "java/lang/IllegalArgumentException"
// + [CONSTANT_Class_info] for above
// + [UTF-8] "java/lang/InvocationTargetException"
// + [CONSTANT_Class_info] for above
// + [UTF-8] "<init>"
// + [UTF-8] "()V"
// + [CONSTANT_NameAndType_info] for above
// + [CONSTANT_Methodref_info] for NullPointerException's constructor
// + [CONSTANT_Methodref_info] for IllegalArgumentException's constructor
// + [CONSTANT_Methodref_info] for IllegalArgumentException's constructor taking a String
// + [CONSTANT_Methodref_info] for InvocationTargetException's constructor
// + [CONSTANT_Methodref_info] for "super()"
// + [CONSTANT_Class_info] for above
// + [UTF-8] "toString"
// + [CONSTANT_Methodref_info] for Object's toString method
// + [UTF-8] "Code"
// + [UTF-8] "Exceptions"
// * [CONSTANT_Class_info] for above
// * [UTF-8] "(Z)V"
// * [CONSTANT_NameAndType_info] for above
// * [CONSTANT_Methodref_info] for above
// * [UTF-8] "booleanValue"
// * [UTF-8] "()Z"
// * [CONSTANT_NameAndType_info] for above
// * [CONSTANT_Methodref_info] for above
// * [CONSTANT_Class_info] for above
// * [UTF-8] "(B)V"
// * [CONSTANT_NameAndType_info] for above
// * [CONSTANT_Methodref_info] for above
// * [UTF-8] "byteValue"
// * [UTF-8] "()B"
// * [CONSTANT_NameAndType_info] for above
// * [CONSTANT_Methodref_info] for above
// * [CONSTANT_Class_info] for above
// * [UTF-8] "(C)V"
// * [CONSTANT_NameAndType_info] for above
// * [CONSTANT_Methodref_info] for above
// * [UTF-8] "charValue"
// * [UTF-8] "()C"
// * [CONSTANT_NameAndType_info] for above
// * [CONSTANT_Methodref_info] for above
// * [CONSTANT_Class_info] for above
// * [UTF-8] "(D)V"
// * [CONSTANT_NameAndType_info] for above
// * [CONSTANT_Methodref_info] for above
// * [UTF-8] "doubleValue"
// * [UTF-8] "()D"
// * [CONSTANT_NameAndType_info] for above
// * [CONSTANT_Methodref_info] for above
// * [CONSTANT_Class_info] for above
// * [UTF-8] "(F)V"
// * [CONSTANT_NameAndType_info] for above
// * [CONSTANT_Methodref_info] for above
// * [UTF-8] "floatValue"
// * [UTF-8] "()F"
// * [CONSTANT_NameAndType_info] for above
// * [CONSTANT_Methodref_info] for above
// * [CONSTANT_Class_info] for above
// * [UTF-8] "(I)V"
// * [CONSTANT_NameAndType_info] for above
// * [CONSTANT_Methodref_info] for above
// * [UTF-8] "intValue"
// * [UTF-8] "()I"
// * [CONSTANT_NameAndType_info] for above
// * [CONSTANT_Methodref_info] for above
// * [CONSTANT_Class_info] for above
// * [UTF-8] "(J)V"
// * [CONSTANT_NameAndType_info] for above
// * [CONSTANT_Methodref_info] for above
// * [UTF-8] "longValue"
// * [UTF-8] "()J"
// * [CONSTANT_NameAndType_info] for above
// * [CONSTANT_Methodref_info] for above
// * [CONSTANT_Class_info] for above
// * [UTF-8] "(S)V"
// * [CONSTANT_NameAndType_info] for above
// * [CONSTANT_Methodref_info] for above
// * [UTF-8] "shortValue"
// * [UTF-8] "()S"
// * [CONSTANT_NameAndType_info] for above
// * [CONSTANT_Methodref_info] for above
boolean usesPrimitives = usesPrimitiveTypes();
if (usesPrimitives) {
}
if (forSerialization) {
}
// Add in variable-length number of entries to be able to describe
// non-primitive parameter types and checked exceptions.
if (isConstructor) {
if (forSerialization) {
} else {
}
} else {
}
short serializationTargetClassIdx = (short) 0;
if (forSerialization) {
}
if (isInterface()) {
} else {
if (forSerialization) {
} else {
}
}
if (isConstructor) {
} else {
}
if (isConstructor) {
} else {
}
// Output class information for non-primitive parameter types
Class c = parameterTypes[i];
if (!isPrimitive(c)) {
}
}
// Entries common to FieldAccessor, MethodAccessor and ConstructorAccessor
// Boxing entries
if (usesPrimitives) {
}
}
// Access flags
// This class
// Superclass
// Interfaces count and interfaces
// Fields count and fields
// Methods count and methods
emitInvoke();
// Additional attributes (none)
// Load class
// Note: the class loader is the only thing that really matters
// here -- it's important to get the generated code into the
// same namespace as the target class. Since the generated code
// is privileged anyway, the protection domain probably doesn't
// matter.
return AccessController.doPrivileged(
new PrivilegedAction<MagicAccessorImpl>() {
public MagicAccessorImpl run() {
try {
return (MagicAccessorImpl)
0,
} catch (InstantiationException e) {
throw (InternalError)
new InternalError().initCause(e);
} catch (IllegalAccessException e) {
throw (InternalError)
new InternalError().initCause(e);
}
}
});
}
/** This emits the code for either invoke() or newInstance() */
private void emitInvoke() {
// NOTE that this code will only handle 65535 parameters since we
// use the sipush instruction to get the array index on the
// operand stack.
throw new InternalError("Can't handle more than 65535 parameters");
}
// Generate code into fresh code buffer
if (isConstructor) {
// 1 incoming argument
} else {
// 2 incoming arguments
}
short illegalArgStartPC = 0;
if (isConstructor) {
// Instantiate target class before continuing
// new <target class type>
// dup
} else {
// Setup before iterating down argument list
if (isPrimitive(returnType)) {
// new <boxing type for primitive type>
// dup
// ... (see below:)
// invokespecial <constructor for boxing type for primitive type>
// areturn
}
// Get target object on operand stack if necessary.
// We need to do an explicit null check here; we won't see
// NullPointerExceptions from the invoke bytecode, since it's
// covered by an exception handler.
if (!isStatic()) {
// aload_1
// ifnonnull <checkcast label>
// new <NullPointerException>
// dup
// invokespecial <NullPointerException ctor>
// athrow
// <checkcast label:>
// aload_1
// checkcast <target class's type>
cb.opc_aload_1();
cb.opc_ifnonnull(l);
cb.opc_athrow();
l.bind();
cb.opc_aload_1();
}
}
// Have to check length of incoming array and throw
// IllegalArgumentException if not correct. A concession to the
// JCK (isn't clearly specified in the spec): we allow null in the
// case where the argument list is zero length.
// if no-arg:
// aload_2 | aload_1 (Method | Constructor)
// ifnull <success label>
// aload_2 | aload_1
// arraylength
// sipush <num parameter types>
// if_icmpeq <success label>
// new <IllegalArgumentException>
// dup
// invokespecial <IllegalArgumentException ctor>
// athrow
// <success label:>
if (isConstructor) {
cb.opc_aload_1();
} else {
cb.opc_aload_2();
}
}
if (isConstructor) {
cb.opc_aload_1();
} else {
cb.opc_aload_2();
}
cb.opc_athrow();
successLabel.bind();
// Iterate through incoming actual parameters, ensuring that each
// is compatible with the formal parameter type, and pushing the
// actual on the operand stack (unboxing and widening if necessary).
// num args of other invoke bytecodes
if (nextParamLabel != null) {
}
// aload_2 | aload_1
// sipush <index>
// aaload
if (isConstructor) {
cb.opc_aload_1();
} else {
cb.opc_aload_2();
}
cb.opc_sipush((short) i);
cb.opc_aaload();
if (isPrimitive(paramType)) {
// Unboxing code.
// Put parameter into temporary local variable
// astore_3 | astore_2
if (isConstructor) {
cb.opc_astore_2();
} else {
cb.opc_astore_3();
}
// repeat for all possible widening conversions:
// aload_3 | aload_2
// instanceof <primitive boxing type>
// ifeq <next unboxing label>
// aload_3 | aload_2
// checkcast <primitive boxing type> // Note: this is "redundant",
// // but necessary for the verifier
// invokevirtual <unboxing method>
// <widening conversion bytecode, if necessary>
// goto <next parameter label>
// <next unboxing label:> ...
// last unboxing label:
// new <IllegalArgumentException>
// dup
// invokespecial <IllegalArgumentException ctor>
// athrow
nextParamLabel = new Label();
Class c = primitiveTypes[j];
if (canWidenTo(c, paramType)) {
if (l != null) {
l.bind();
}
// Emit checking and unboxing code for this type
if (isConstructor) {
cb.opc_aload_2();
} else {
cb.opc_aload_3();
}
l = new Label();
if (isConstructor) {
cb.opc_aload_2();
} else {
cb.opc_aload_3();
}
0,
typeSizeInStackSlots(c));
c,
}
}
if (l == null) {
throw new InternalError
("Must have found at least identity conversion");
}
// Fell through; given object is null or invalid. According to
// the spec, we can throw IllegalArgumentException for both of
// these cases.
l.bind();
cb.opc_athrow();
} else {
// Emit appropriate checkcast
// Fall through to next argument
}
}
// Bind last goto if present
if (nextParamLabel != null) {
}
// OK, ready to perform the invocation.
if (isConstructor) {
} else {
if (isStatic()) {
} else {
if (isInterface()) {
} else {
}
}
}
if (!isConstructor) {
// Box return value if necessary
if (isPrimitive(returnType)) {
0);
}
}
cb.opc_areturn();
// We generate two exception handlers; one which is responsible
// for catching ClassCastException and NullPointerException and
// throwing IllegalArgumentException, and the other which catches
// and wraps them in InvocationTargetExceptions.
// ClassCast, etc. exception handler
cb.opc_dup_x1();
cb.opc_athrow();
// InvocationTargetException exception handler
cb.opc_dup_x1();
cb.opc_athrow();
// Generate exception table. We cover the entire code sequence
// with an exception handler which catches ClassCastException and
// converts it into an IllegalArgumentException.
new short[] { invocationTargetClass });
}
private boolean usesPrimitiveTypes() {
// the method takes a primitive type for any of its parameters or
// returns a primitive value (except void)
if (returnType.isPrimitive()) {
return true;
}
if (parameterTypes[i].isPrimitive()) {
return true;
}
}
return false;
}
private int numNonPrimitiveParameterTypes() {
int num = 0;
if (!parameterTypes[i].isPrimitive()) {
++num;
}
}
return num;
}
private boolean isInterface() {
return declaringClass.isInterface();
}
}
}
boolean forSerialization)
{
if (isConstructor) {
if (forSerialization) {
int num = ++serializationConstructorSymnum;
return "sun/reflect/GeneratedSerializationConstructorAccessor" + num;
} else {
int num = ++constructorSymnum;
return "sun/reflect/GeneratedConstructorAccessor" + num;
}
} else {
int num = ++methodSymnum;
return "sun/reflect/GeneratedMethodAccessor" + num;
}
}
}