/*
* 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.
*/
/** Shared functionality for all accessor generators */
// Constants because there's no way to say "short integer constant",
// i.e., "1S"
// Instance variables for shared functionality between
// FieldAccessorGenerator and MethodAccessorGenerator
protected int modifiers;
protected short thisClass;
protected short superClass;
protected short targetClass;
// Common constant pool entries to FieldAccessor and MethodAccessor
protected short throwableClass;
protected short classCastClass;
protected short nullPointerClass;
protected short illegalArgumentClass;
protected short invocationTargetClass;
protected short initIdx;
protected short initNameAndTypeIdx;
protected short initStringNameAndTypeIdx;
protected short nullPointerCtorIdx;
protected short illegalArgumentCtorIdx;
protected short illegalArgumentStringCtorIdx;
protected short invocationTargetCtorIdx;
protected short superCtorIdx;
protected short objectClass;
protected short toStringIdx;
protected short codeIdx;
protected short exceptionsIdx;
// Boxing
protected short booleanIdx;
protected short booleanCtorIdx;
protected short booleanUnboxIdx;
protected short byteIdx;
protected short byteCtorIdx;
protected short byteUnboxIdx;
protected short characterIdx;
protected short characterCtorIdx;
protected short characterUnboxIdx;
protected short doubleIdx;
protected short doubleCtorIdx;
protected short doubleUnboxIdx;
protected short floatIdx;
protected short floatCtorIdx;
protected short floatUnboxIdx;
protected short integerIdx;
protected short integerCtorIdx;
protected short integerUnboxIdx;
protected short longIdx;
protected short longCtorIdx;
protected short longUnboxIdx;
protected short shortIdx;
protected short shortCtorIdx;
protected short shortUnboxIdx;
// Requires that superClass has been set up
protected void emitCommonConstantPoolEntries() {
// + [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"
}
types. Note that we don't emit these if we don't need them. */
protected void emitBoxingContantPoolEntries() {
// * [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
// Byte
// Character
// Double
// Float
// Integer
// Long
// Short
}
// Necessary because of Java's annoying promotion rules
}
}
protected boolean isStatic() {
}
/** Returns class name in "internal" form (i.e., '/' separators
instead of '.') */
(Class c, boolean addPrefixAndSuffixForNonPrimitiveTypes)
{
if (c.isPrimitive()) {
return "Z";
return "B";
return "C";
return "D";
return "F";
return "I";
return "J";
return "S";
return "V";
}
throw new InternalError("Should have found primitive type");
} else if (c.isArray()) {
} else {
} else {
return internalize(c.getName());
}
}
}
}
protected void emitConstructor() {
// Generate code into fresh code buffer
// 0 incoming arguments
cb.opc_aload_0();
cb.opc_return();
// Emit method
}
// The descriptor's index in the constant pool must be (1 +
// nameIdx). "numArgs" must indicate ALL arguments, including the
// implicit "this" argument; double and long arguments each count
// as 2 in this count. The code buffer must NOT contain the code
// length. The exception table may be null, but if non-null must
// NOT contain the exception table's length. The checked exception
// indices may be null.
int numArgs,
short[] checkedExceptionIndices)
{
int excLen = 0;
if (exceptionTable != null) {
throw new IllegalArgumentException("Illegal exception table");
}
}
if (checkedExceptionIndices == null) {
// Code attribute only
} else {
// Code and Exceptions attributes
}
// Code attribute
if (exceptionTable != null) {
}
if (checkedExceptionIndices != null) {
// Exceptions attribute
}
}
}
return booleanIdx;
return byteIdx;
return characterIdx;
return doubleIdx;
return floatIdx;
return integerIdx;
return longIdx;
return shortIdx;
}
throw new InternalError("Should have found primitive type");
}
return booleanCtorIdx;
return byteCtorIdx;
return characterCtorIdx;
return doubleCtorIdx;
return floatCtorIdx;
return integerCtorIdx;
return longCtorIdx;
return shortCtorIdx;
}
throw new InternalError("Should have found primitive type");
}
/** Returns true for widening or identity conversions for primitive
types only */
if (!type.isPrimitive()) {
return false;
}
// Widening conversions (from JVM spec):
// byte to short, int, long, float, or double
// short to int, long, float, or double
// char to int, long, float, or double
// int to long, float, or double
// long to float or double
// float to double
return true;
}
return true;
}
return true;
}
return true;
}
return true;
}
return true;
}
return true;
}
return true;
}
}
return false;
}
/** Emits the widening bytecode for the given primitive conversion
(or none if the identity conversion). Requires that a primitive
conversion exists; i.e., canWidenTo must have already been
called and returned true. */
protected static void emitWideningBytecodeForPrimitiveConversion
{
// Note that widening conversions for integral types (i.e., "b2s",
// "s2i") are no-ops since values on the Java stack are
// sign-extended.
// Widening conversions (from JVM spec):
// byte to short, int, long, float, or double
// short to int, long, float, or double
// char to int, long, float, or double
// int to long, float, or double
// long to float or double
// float to double
}
}
}
}
// Otherwise, was identity or no-op conversion. Fall through.
}
return booleanUnboxIdx;
return byteUnboxIdx;
return characterUnboxIdx;
return shortUnboxIdx;
return integerUnboxIdx;
return longUnboxIdx;
return floatUnboxIdx;
return doubleUnboxIdx;
}
}
};
/** We don't consider "Void" to be a primitive type */
}
return 0;
}
return 2;
}
return 1;
}
if (illegalArgumentCodeBuffer == null) {
}
return illegalArgumentCodeBuffer;
}
}