/* * Copyright (c) 1994, 2022, 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.
*/
/*- * Verify that the code within a method block doesn't exploit any * security holes.
*/ /* Exported function:
/* On AIX malloc(0) and calloc(0, ...) return a NULL pointer, which is legal, * but the code here does not handles it. So we wrap the methods and return non-NULL * pointers even if we allocate 0 bytes.
*/ #ifdef _AIX staticint aix_dummy; staticvoid* aix_malloc(size_t len) { if (len == 0) { return &aix_dummy;
} return malloc(len);
}
staticvoid* aix_calloc(size_t n, size_t size) { if (n == 0) { return &aix_dummy;
} return calloc(n, size);
}
int verify_verbose = 0; staticstruct context_type *GlobalContext; #endif
enum {
ITEM_Bogus,
ITEM_Void, /* only as a function return value */
ITEM_Integer,
ITEM_Float,
ITEM_Double,
ITEM_Double_2, /* 2nd word of double in register */
ITEM_Long,
ITEM_Long_2, /* 2nd word of long in register */
ITEM_Array,
ITEM_Object, /* Extra info field gives name. */
ITEM_NewObject, /* Like object, but uninitialized. */
ITEM_InitObject, /* "this" is init method, before call
to super() */
ITEM_ReturnAddress, /* Extra info gives instr # of start pc */ /* The following four are only used within array types.
* Normally, we use ITEM_Integer, instead. */
ITEM_Byte,
ITEM_Short,
ITEM_Char,
ITEM_Boolean
};
/* JVM_OPC_invokespecial calls to <init> need to be treated special */ #define JVM_OPC_invokeinit 0x100
/* A hash mechanism used by the verifier. * Maps class names to unique 16 bit integers.
*/
#define HASH_TABLE_SIZE 503
/* The buckets are managed as a 256 by 256 matrix. We allocate an entire * row (256 buckets) at a time to minimize fragmentation. Rows are * allocated on demand so that we don't waste too much space.
*/
typedefstruct {
hash_bucket_type **buckets; unsignedshort *table; int entries_used;
} hash_table_type;
#define GET_BUCKET(class_hash, ID)\
(class_hash->buckets[ID / HASH_ROW_SIZE] + ID % HASH_ROW_SIZE)
/* * There are currently two types of resources that we need to keep * track of (in addition to the CCalloc pool).
*/ enum {
VM_STRING_UTF, /* VM-allocated UTF strings */
VM_MALLOC_BLK /* malloc'ed blocks */
};
/* The context type encapsulates the current invocation of the byte * code verifier.
*/ struct context_type {
JNIEnv *env; /* current JNIEnv */
/* buffers etc. */ char *message;
jint message_buf_len;
jboolean err_code;
alloc_stack_type *allocated_memory; /* all memory blocks that we have not
had a chance to free */ /* Store up to ALLOC_STACK_SIZE number of handles to allocated memory
blocks here, to save mallocs. */
alloc_stack_type alloc_stack[ALLOC_STACK_SIZE]; int alloc_stack_top;
/* these fields are per class */
jclass class; /* current class */
jint major_version;
jint nconstants; unsignedchar *constant_types;
hash_table_type class_hash;
fullinfo_type object_info; /* fullinfo for java/lang/Object */
fullinfo_type string_info; /* fullinfo for java/lang/String */
fullinfo_type throwable_info; /* fullinfo for java/lang/Throwable */
fullinfo_type cloneable_info; /* fullinfo for java/lang/Cloneable */
fullinfo_type serializable_info; /* fullinfo for java/io/Serializable */
fullinfo_type currentclass_info; /* fullinfo for context->class */
fullinfo_type superclass_info; /* fullinfo for superclass */
/* these fields are per method */ int method_index; /* current method */ unsignedshort *exceptions; /* exceptions */ unsignedchar *code; /* current code object */
jint code_length; int *code_data; /* offset to instruction number */ struct instruction_data_type *instruction_data; /* info about each */ struct handler_info_type *handler_info;
fullinfo_type *superclasses; /* null terminated superclasses */ int instruction_count; /* number of instructions */
fullinfo_type return_type; /* function return type */
fullinfo_type swap_table[4]; /* used for passing information */ int bitmask_size; /* words needed to hold bitmap of arguments */
/* these fields are per field */ int field_index;
/* Used by the space allocator */ struct CCpool *CCroot, *CCcurrent; char *CCfree_ptr; int CCfree_size;
/* Jump here on any error. */
jmp_buf jump_buffer;
#ifdef DEBUG /* keep track of how many global refs are allocated. */ int n_globalrefs; #endif
};
struct stack_info_type { struct stack_item_type *stack; int stack_size;
};
struct register_info_type { int register_count; /* number of registers used */
fullinfo_type *registers; int mask_count; /* number of masks in the following */ struct mask_type *masks;
};
struct mask_type { int entry; int *modifies;
};
typedefunsignedshort flag_type;
struct instruction_data_type { int opcode; /* may turn into "canonical" opcode */ unsigned changed:1; /* has it changed */ unsignedprotected:1; /* must accessor be a subclass of "this" */ union { int i; /* operand to the opcode */ int *ip;
fullinfo_type fi;
} operand, operand2;
fullinfo_type p; struct stack_info_type stack_info; struct register_info_type register_info; #define FLAG_REACHED 0x01 /* instruction reached */ #define FLAG_NEED_CONSTRUCTOR 0x02 /* must call this.<init> or super.<init> */ #define FLAG_NO_RETURN 0x04 /* must throw out of method */
flag_type or_flags; /* true for at least one path to this inst */ #define FLAG_CONSTRUCTED 0x01 /* this.<init> or super.<init> called */
flag_type and_flags; /* true for all paths to this instruction */
};
staticvoid finalize_class_hash(context_type *context)
{
hash_table_type *class_hash = &(context->class_hash);
JNIEnv *env = context->env; int i; /* 4296677: bucket index starts from 1. */ for (i=1;i<=class_hash->entries_used;i++) {
hash_bucket_type *bucket = GET_BUCKET(class_hash, i);
assert(bucket != NULL);
free(bucket->name); if (bucket->class) {
(*env)->DeleteGlobalRef(env, bucket->class); #ifdef DEBUG
context->n_globalrefs--; #endif
}
} if (class_hash->buckets) { for (i=0;i<MAX_HASH_ENTRIES / HASH_ROW_SIZE; i++) { if (class_hash->buckets[i] == 0) break;
free(class_hash->buckets[i]);
}
}
free(class_hash->buckets);
free(class_hash->table);
}
static hash_bucket_type *
new_bucket(context_type *context, unsignedshort *pID)
{
hash_table_type *class_hash = &(context->class_hash); int i = *pID = class_hash->entries_used + 1; int row = i / HASH_ROW_SIZE; if (i >= MAX_HASH_ENTRIES)
CCerror(context, "Exceeded verifier's limit of 65535 referred classes"); if (class_hash->buckets[row] == 0) {
class_hash->buckets[row] = (hash_bucket_type*)
calloc(HASH_ROW_SIZE, sizeof(hash_bucket_type)); if (class_hash->buckets[row] == 0)
CCout_of_memory(context);
}
class_hash->entries_used++; /* only increment when we are sure there
is no overflow. */ return GET_BUCKET(class_hash, i);
}
staticunsignedint
class_hash_fun(constchar *s)
{ int i; unsigned raw_hash; for (raw_hash = 0; (i = *s) != '\0'; ++s)
raw_hash = raw_hash * 37 + i; return raw_hash;
}
/* * Find a class using the defining loader of the current class * and return a local reference to it.
*/ static jclass load_class_local(context_type *context,constchar *classname)
{
jclass cb = JVM_FindClassFromClass(context->env, classname,
JNI_FALSE, context->class); if (cb == 0)
CCerror(context, "Cannot find class %s", classname); return cb;
}
/* * Find a class using the defining loader of the current class * and return a global reference to it.
*/ static jclass load_class_global(context_type *context, constchar *classname)
{
JNIEnv *env = context->env;
jclass local, global;
local = load_class_local(context, classname);
global = (*env)->NewGlobalRef(env, local); if (global == 0)
CCout_of_memory(context); #ifdef DEBUG
context->n_globalrefs++; #endif
(*env)->DeleteLocalRef(env, local); return global;
}
/* * Return a unique ID given a local class reference. The loadable * flag is true if the defining class loader of context->class * is known to be capable of loading the class.
*/ staticunsignedshort
class_to_ID(context_type *context, jclass cb, jboolean loadable)
{
JNIEnv *env = context->env;
hash_table_type *class_hash = &(context->class_hash); unsignedint hash;
hash_bucket_type *bucket; unsignedshort *pID; constchar *name = JVM_GetClassNameUTF(env, cb);
check_and_push_string_utf(context, name);
hash = class_hash_fun(name);
pID = &(class_hash->table[hash % HASH_TABLE_SIZE]); while (*pID) {
bucket = GET_BUCKET(class_hash, *pID); if (bucket->hash == hash && strcmp(name, bucket->name) == 0) { /* * There is an unresolved entry with our name * so we're forced to load it in case it matches us.
*/ if (bucket->class == 0) {
assert(bucket->loadable == JNI_TRUE);
bucket->class = load_class_global(context, name);
}
/* * It's already in the table. Update the loadable * state if it's known and then we're done.
*/ if ((*env)->IsSameObject(env, cb, bucket->class)) { if (loadable && !bucket->loadable)
bucket->loadable = JNI_TRUE; goto done;
}
}
pID = &bucket->next;
}
bucket = new_bucket(context, pID);
bucket->next = 0;
bucket->hash = hash;
bucket->name = malloc(strlen(name) + 1); if (bucket->name == 0)
CCout_of_memory(context);
strcpy(bucket->name, name);
bucket->loadable = loadable;
bucket->class = (*env)->NewGlobalRef(env, cb); if (bucket->class == 0)
CCout_of_memory(context); #ifdef DEBUG
context->n_globalrefs++; #endif
done:
pop_and_free(context); return *pID;
}
/* * Return a unique ID given a class name from the constant pool. * All classes are lazily loaded from the defining loader of * context->class.
*/ staticunsignedshort
class_name_to_ID(context_type *context, constchar *name)
{
hash_table_type *class_hash = &(context->class_hash); unsignedint hash = class_hash_fun(name);
hash_bucket_type *bucket; unsignedshort *pID;
jboolean force_load = JNI_FALSE;
if (force_load) { /* * We found at least one matching named entry for a class that * was not known to be loadable through the defining class loader * of context->class. We must load our named class and update * the hash table in case one these entries matches our class.
*/
JNIEnv *env = context->env;
jclass cb = load_class_local(context, name); unsignedshort id = class_to_ID(context, cb, JNI_TRUE);
(*env)->DeleteLocalRef(env, cb); return id;
}
/* RETURNS * 1: on success chosen to be consistent with previous VerifyClass * 0: verify error * 2: out of memory * 3: class format error * * Called by verify_class. Verify the code of each of the methods * in a class. Note that this function apparently can't be JNICALL, * because if it is the dynamic linker doesn't appear to be able to * find it on Win32.
*/
/* Can't go on context heap since it survives more than
one method */
context->superclasses = gptr =
malloc(sizeof(fullinfo_type)*(i + 1)); if (gptr == 0) {
CCout_of_memory(context);
}
/** * We read all of the class's methods' code because it is possible that * the verification of one method could resulting in linking further * down the stack (due to class loading), which could end up rewriting * some of the bytecode of methods we haven't verified yet. Since we * don't want to see the rewritten bytecode, cache all the code and * operate only on that.
*/ staticvoid
read_all_code(context_type* context, jclass cb, int num_methods, int** lengths_addr, unsignedchar*** code_addr)
{ int* lengths; unsignedchar** code; int i;
for (i = 0; i < num_methods; ++i) {
lengths[i] = JVM_GetMethodIxByteCodeLength(context->env, cb, i); if (lengths[i] > 0) {
code[i] = malloc(sizeof(unsignedchar) * (lengths[i] + 1));
check_and_push_malloc_block(context, code[i]);
JVM_GetMethodIxByteCode(context->env, cb, i, code[i]);
} else {
code[i] = NULL;
}
}
}
staticvoid
free_all_code(context_type* context, int num_methods, unsignedchar** code)
{ int i; for (i = 0; i < num_methods; ++i) { if (code[i] != NULL) {
pop_and_free(context);
}
}
pop_and_free(context); /* code */
pop_and_free(context); /* lengths */
}
/* Verify the code of one method */ staticvoid
verify_method(context_type *context, jclass cb, int method_index, int code_length, unsignedchar* code)
{
JNIEnv *env = context->env; int access_bits = JVM_GetMethodIxModifiers(env, cb, method_index); int *code_data;
instruction_data_type *idata = 0; int instruction_count; int i, offset; unsignedint inumber;
jint nexceptions;
if ((access_bits & (JVM_ACC_NATIVE | JVM_ACC_ABSTRACT)) != 0) { /* not much to do for abstract and native methods */ return;
}
// If this method is an overpass method, which is generated by the VM, // we trust the code and no check needs to be done. if (JVM_IsVMGeneratedMethodIx(env, cb, method_index)) { return;
}
/* Run through the code. Mark the start of each instruction, and give
* the instruction a number */ for (i = 0, offset = 0; offset < code_length; i++) { int length = instruction_length(&code[offset], code + code_length); int next_offset = offset + length; if (length <= 0)
CCerror(context, "Illegal instruction found at offset %d", offset); if (next_offset > code_length)
CCerror(context, "Code stops in the middle of instruction " " starting at offset %d", offset);
code_data[offset] = i; while (++offset < next_offset)
code_data[offset] = -1; /* illegal location */
}
instruction_count = i; /* number of instructions in code */
/* Allocate a structure to hold info about each instruction. */
idata = NEW(instruction_data_type, instruction_count);
/* Initialize the heap, and other info in the context structure. */
context->code = code;
context->instruction_data = idata;
context->code_data = code_data;
context->instruction_count = instruction_count;
context->handler_info = NEW(struct handler_info_type,
JVM_GetMethodIxExceptionTableLength(env, cb, method_index));
context->bitmask_size =
(JVM_GetMethodIxLocalsCount(env, cb, method_index)
+ (BITS_PER_INT - 1))/BITS_PER_INT;
if (instruction_count == 0)
CCerror(context, "Empty code");
for (inumber = 0, offset = 0; offset < code_length; inumber++) { int length = instruction_length(&code[offset], code + code_length);
instruction_data_type *this_idata = &idata[inumber];
this_idata->opcode = code[offset];
this_idata->stack_info.stack = NULL;
this_idata->stack_info.stack_size = UNKNOWN_STACK_SIZE;
this_idata->register_info.register_count = UNKNOWN_REGISTER_COUNT;
this_idata->changed = JNI_FALSE; /* no need to look at it yet. */
this_idata->protected = JNI_FALSE; /* no need to look at it yet. */
this_idata->and_flags = (flag_type) -1; /* "bottom" and value */
this_idata->or_flags = 0; /* "bottom" or value*/ /* This also sets up this_data->operand. It also makes the
* xload_x and xstore_x instructions look like the generic form. */
verify_opcode_operands(context, inumber, offset);
offset += length;
}
/* make sure exception table is reasonable. */
initialize_exception_table(context); /* Set up first instruction, and start of exception handlers. */
initialize_dataflow(context); /* Run data flow analysis on the instructions. */
run_dataflow(context);
/* verify checked exceptions, if any */
nexceptions = JVM_GetMethodIxExceptionsCount(env, cb, method_index);
context->exceptions = (unsignedshort *)
malloc(sizeof(unsignedshort) * nexceptions + 1); if (context->exceptions == 0)
CCout_of_memory(context);
JVM_GetMethodIxExceptionIndexes(env, cb, method_index,
context->exceptions); for (i = 0; i < nexceptions; i++) { /* Make sure the constant pool item is JVM_CONSTANT_Class */
verify_constant_pool_type(context, (int)context->exceptions[i],
1 << JVM_CONSTANT_Class);
}
free(context->exceptions);
context->exceptions = 0;
context->code = 0;
context->method_index = -1;
}
/* Look at a single instruction, and verify its operands. Also, for * simplicity, move the operand into the ->operand field. * Make sure that branches don't go into the middle of nowhere.
*/
staticvoid
verify_opcode_operands(context_type *context, unsignedint inumber, int offset)
{
JNIEnv *env = context->env;
instruction_data_type *idata = context->instruction_data;
instruction_data_type *this_idata = &idata[inumber]; int *code_data = context->code_data; int mi = context->method_index; unsignedchar *code = context->code; int opcode = this_idata->opcode; int var;
/* * Set the ip fields to 0 not the i fields because the ip fields * are 64 bits on 64 bit architectures, the i field is only 32
*/
this_idata->operand.ip = 0;
this_idata->operand2.ip = 0;
switch (opcode) {
case JVM_OPC_jsr: /* instruction of ret statement */
this_idata->operand2.i = UNKNOWN_RET_INSTRUCTION; /* FALLTHROUGH */ case JVM_OPC_ifeq: case JVM_OPC_ifne: case JVM_OPC_iflt: case JVM_OPC_ifge: case JVM_OPC_ifgt: case JVM_OPC_ifle: case JVM_OPC_ifnull: case JVM_OPC_ifnonnull: case JVM_OPC_if_icmpeq: case JVM_OPC_if_icmpne: case JVM_OPC_if_icmplt: case JVM_OPC_if_icmpge: case JVM_OPC_if_icmpgt: case JVM_OPC_if_icmple: case JVM_OPC_if_acmpeq: case JVM_OPC_if_acmpne: case JVM_OPC_goto: { /* Set the ->operand to be the instruction number of the target. */ int jump = (((signedchar)(code[offset+1])) << 8) + code[offset+2]; int target = offset + jump; if (!isLegalTarget(context, target))
CCerror(context, "Illegal target of jump or branch");
this_idata->operand.i = code_data[target]; break;
}
case JVM_OPC_jsr_w: /* instruction of ret statement */
this_idata->operand2.i = UNKNOWN_RET_INSTRUCTION; /* FALLTHROUGH */ case JVM_OPC_goto_w: { /* Set the ->operand to be the instruction number of the target. */ int jump = (((signedchar)(code[offset+1])) << 24) +
(code[offset+2] << 16) + (code[offset+3] << 8) +
(code[offset + 4]); int target = offset + jump; if (!isLegalTarget(context, target))
CCerror(context, "Illegal target of jump or branch");
this_idata->operand.i = code_data[target]; break;
}
case JVM_OPC_tableswitch: case JVM_OPC_lookupswitch: { /* Set the ->operand to be a table of possible instruction targets. */ int *lpc = (int *) UCALIGN(code + offset + 1); int *lptr; int *saved_operand; int keys; int k, delta;
if (context->major_version < NONZERO_PADDING_BYTES_IN_SWITCH_MAJOR_VERSION) { /* 4639449, 4647081: Padding bytes must be zero. */ unsignedchar* bptr = (unsignedchar*) (code + offset + 1); for (; bptr < (unsignedchar*)lpc; bptr++) { if (*bptr != 0) {
CCerror(context, "Non zero padding bytes in switch");
}
}
} if (opcode == JVM_OPC_tableswitch) {
keys = _ck_ntohl(lpc[2]) - _ck_ntohl(lpc[1]) + 1;
delta = 1;
} else {
keys = _ck_ntohl(lpc[1]); /* number of pairs */
delta = 2; /* Make sure that the tableswitch items are sorted */ for (k = keys - 1, lptr = &lpc[2]; --k >= 0; lptr += 2) { int this_key = _ck_ntohl(lptr[0]); /* NB: ntohl may be unsigned */ int next_key = _ck_ntohl(lptr[2]); if (this_key >= next_key) {
CCerror(context, "Unsorted lookup switch");
}
}
}
saved_operand = NEW(int, keys + 2); if (!isLegalTarget(context, offset + _ck_ntohl(lpc[0])))
CCerror(context, "Illegal default target in switch");
saved_operand[keys + 1] = code_data[offset + _ck_ntohl(lpc[0])]; for (k = keys, lptr = &lpc[3]; --k >= 0; lptr += delta) { int target = offset + _ck_ntohl(lptr[0]); if (!isLegalTarget(context, target))
CCerror(context, "Illegal branch in tableswitch");
saved_operand[k + 1] = code_data[target];
}
saved_operand[0] = keys + 1; /* number of successors */
this_idata->operand.ip = saved_operand; break;
}
case JVM_OPC_ldc: { /* Make sure the constant pool item is the right type. */ int key = code[offset + 1]; int types = (1 << JVM_CONSTANT_Integer) | (1 << JVM_CONSTANT_Float) |
(1 << JVM_CONSTANT_String); if (context->major_version >= LDC_CLASS_MAJOR_VERSION) {
types |= 1 << JVM_CONSTANT_Class;
} if (context->major_version >= LDC_METHOD_HANDLE_MAJOR_VERSION) {
types |= (1 << JVM_CONSTANT_MethodHandle) |
(1 << JVM_CONSTANT_MethodType);
}
this_idata->operand.i = key;
verify_constant_pool_type(context, key, types); break;
}
case JVM_OPC_ldc_w: { /* Make sure the constant pool item is the right type. */ int key = (code[offset + 1] << 8) + code[offset + 2]; int types = (1 << JVM_CONSTANT_Integer) | (1 << JVM_CONSTANT_Float) |
(1 << JVM_CONSTANT_String); if (context->major_version >= LDC_CLASS_MAJOR_VERSION) {
types |= 1 << JVM_CONSTANT_Class;
} if (context->major_version >= LDC_METHOD_HANDLE_MAJOR_VERSION) {
types |= (1 << JVM_CONSTANT_MethodHandle) |
(1 << JVM_CONSTANT_MethodType);
}
this_idata->operand.i = key;
verify_constant_pool_type(context, key, types); break;
}
case JVM_OPC_ldc2_w: { /* Make sure the constant pool item is the right type. */ int key = (code[offset + 1] << 8) + code[offset + 2]; int types = (1 << JVM_CONSTANT_Double) | (1 << JVM_CONSTANT_Long);
this_idata->operand.i = key;
verify_constant_pool_type(context, key, types); break;
}
case JVM_OPC_getfield: case JVM_OPC_putfield: case JVM_OPC_getstatic: case JVM_OPC_putstatic: { /* Make sure the constant pool item is the right type. */ int key = (code[offset + 1] << 8) + code[offset + 2];
this_idata->operand.i = key;
verify_constant_pool_type(context, key, 1 << JVM_CONSTANT_Fieldref); if (opcode == JVM_OPC_getfield || opcode == JVM_OPC_putfield)
set_protected(context, inumber, key, opcode); break;
}
case JVM_OPC_invokevirtual: case JVM_OPC_invokespecial: case JVM_OPC_invokestatic: case JVM_OPC_invokeinterface: { /* Make sure the constant pool item is the right type. */ int key = (code[offset + 1] << 8) + code[offset + 2]; constchar *methodname;
jclass cb = context->class;
fullinfo_type clazz_info; int is_constructor, is_internal; int kind;
/* The optimizer may cause this to happen on local code */ if (not_found) {
CCerror(context, "Illegal use of nonvirtual function call");
}
}
} if (opcode == JVM_OPC_invokeinterface) { unsignedint args1; unsignedint args2; constchar *signature =
JVM_GetCPMethodSignatureUTF(env, context->class, key);
check_and_push_string_utf(context, signature);
args1 = signature_to_args_size(signature) + 1;
args2 = code[offset + 3]; if (args1 != args2) {
CCerror(context, "Inconsistent args_size for invokeinterface");
} if (code[offset + 4] != 0) {
CCerror(context, "Fourth operand byte of invokeinterface must be zero");
}
pop_and_free(context);
} elseif (opcode == JVM_OPC_invokevirtual
|| opcode == JVM_OPC_invokespecial)
set_protected(context, inumber, key, opcode); break;
}
case JVM_OPC_invokedynamic:
CCerror(context, "invokedynamic bytecode is not supported in this class file version"); break; case JVM_OPC_instanceof: case JVM_OPC_checkcast: case JVM_OPC_new: case JVM_OPC_anewarray: case JVM_OPC_multianewarray: { /* Make sure the constant pool item is a class */ int key = (code[offset + 1] << 8) + code[offset + 2];
fullinfo_type target;
verify_constant_pool_type(context, key, 1 << JVM_CONSTANT_Class);
target = cp_index_to_class_fullinfo(context, key, JVM_CONSTANT_Class); if (GET_ITEM_TYPE(target) == ITEM_Bogus)
CCerror(context, "Illegal type"); switch(opcode) { case JVM_OPC_anewarray: if ((GET_INDIRECTION(target)) >= MAX_ARRAY_DIMENSIONS)
CCerror(context, "Array with too many dimensions");
this_idata->operand.fi = MAKE_FULLINFO(GET_ITEM_TYPE(target),
GET_INDIRECTION(target) + 1,
GET_EXTRA_INFO(target)); break; case JVM_OPC_new: if (WITH_ZERO_EXTRA_INFO(target) !=
MAKE_FULLINFO(ITEM_Object, 0, 0))
CCerror(context, "Illegal creation of multi-dimensional array"); /* operand gets set to the "uninitialized object". operand2 gets
* set to what the value will be after it's initialized. */
this_idata->operand.fi = MAKE_FULLINFO(ITEM_NewObject, 0, inumber);
this_idata->operand2.fi = target; break; case JVM_OPC_multianewarray:
this_idata->operand.fi = target;
this_idata->operand2.i = code[offset + 3]; if ( (this_idata->operand2.i > (int)GET_INDIRECTION(target))
|| (this_idata->operand2.i == 0))
CCerror(context, "Illegal dimension argument"); break; default:
this_idata->operand.fi = target;
} break;
}
case JVM_OPC_newarray: { /* Cache the result of the JVM_OPC_newarray into the operand slot */
fullinfo_type full_info; switch (code[offset + 1]) { case JVM_T_INT:
full_info = MAKE_FULLINFO(ITEM_Integer, 1, 0); break; case JVM_T_LONG:
full_info = MAKE_FULLINFO(ITEM_Long, 1, 0); break; case JVM_T_FLOAT:
full_info = MAKE_FULLINFO(ITEM_Float, 1, 0); break; case JVM_T_DOUBLE:
full_info = MAKE_FULLINFO(ITEM_Double, 1, 0); break; case JVM_T_BOOLEAN:
full_info = MAKE_FULLINFO(ITEM_Boolean, 1, 0); break; case JVM_T_BYTE:
full_info = MAKE_FULLINFO(ITEM_Byte, 1, 0); break; case JVM_T_CHAR:
full_info = MAKE_FULLINFO(ITEM_Char, 1, 0); break; case JVM_T_SHORT:
full_info = MAKE_FULLINFO(ITEM_Short, 1, 0); break; default:
full_info = 0; /* Keep lint happy */
CCerror(context, "Bad type passed to newarray");
}
this_idata->operand.fi = full_info; break;
}
/* Fudge iload_x, aload_x, etc to look like their generic cousin. */ case JVM_OPC_iload_0: case JVM_OPC_iload_1: case JVM_OPC_iload_2: case JVM_OPC_iload_3:
this_idata->opcode = JVM_OPC_iload;
var = opcode - JVM_OPC_iload_0; goto check_local_variable;
case JVM_OPC_fload_0: case JVM_OPC_fload_1: case JVM_OPC_fload_2: case JVM_OPC_fload_3:
this_idata->opcode = JVM_OPC_fload;
var = opcode - JVM_OPC_fload_0; goto check_local_variable;
case JVM_OPC_aload_0: case JVM_OPC_aload_1: case JVM_OPC_aload_2: case JVM_OPC_aload_3:
this_idata->opcode = JVM_OPC_aload;
var = opcode - JVM_OPC_aload_0; goto check_local_variable;
case JVM_OPC_lload_0: case JVM_OPC_lload_1: case JVM_OPC_lload_2: case JVM_OPC_lload_3:
this_idata->opcode = JVM_OPC_lload;
var = opcode - JVM_OPC_lload_0; goto check_local_variable2;
case JVM_OPC_dload_0: case JVM_OPC_dload_1: case JVM_OPC_dload_2: case JVM_OPC_dload_3:
this_idata->opcode = JVM_OPC_dload;
var = opcode - JVM_OPC_dload_0; goto check_local_variable2;
case JVM_OPC_istore_0: case JVM_OPC_istore_1: case JVM_OPC_istore_2: case JVM_OPC_istore_3:
this_idata->opcode = JVM_OPC_istore;
var = opcode - JVM_OPC_istore_0; goto check_local_variable;
case JVM_OPC_fstore_0: case JVM_OPC_fstore_1: case JVM_OPC_fstore_2: case JVM_OPC_fstore_3:
this_idata->opcode = JVM_OPC_fstore;
var = opcode - JVM_OPC_fstore_0; goto check_local_variable;
case JVM_OPC_astore_0: case JVM_OPC_astore_1: case JVM_OPC_astore_2: case JVM_OPC_astore_3:
this_idata->opcode = JVM_OPC_astore;
var = opcode - JVM_OPC_astore_0; goto check_local_variable;
case JVM_OPC_lstore_0: case JVM_OPC_lstore_1: case JVM_OPC_lstore_2: case JVM_OPC_lstore_3:
this_idata->opcode = JVM_OPC_lstore;
var = opcode - JVM_OPC_lstore_0; goto check_local_variable2;
case JVM_OPC_dstore_0: case JVM_OPC_dstore_1: case JVM_OPC_dstore_2: case JVM_OPC_dstore_3:
this_idata->opcode = JVM_OPC_dstore;
var = opcode - JVM_OPC_dstore_0; goto check_local_variable2;
case JVM_OPC_wide:
this_idata->opcode = code[offset + 1];
var = (code[offset + 2] << 8) + code[offset + 3]; switch(this_idata->opcode) { case JVM_OPC_lload: case JVM_OPC_dload: case JVM_OPC_lstore: case JVM_OPC_dstore: goto check_local_variable2; default: goto check_local_variable;
}
case JVM_OPC_iinc: /* the increment amount doesn't matter */ case JVM_OPC_ret: case JVM_OPC_aload: case JVM_OPC_iload: case JVM_OPC_fload: case JVM_OPC_astore: case JVM_OPC_istore: case JVM_OPC_fstore:
var = code[offset + 1];
check_local_variable: /* Make sure that the variable number isn't illegal. */
this_idata->operand.i = var; if (var >= JVM_GetMethodIxLocalsCount(env, context->class, mi))
CCerror(context, "Illegal local variable number"); break;
case JVM_OPC_lload: case JVM_OPC_dload: case JVM_OPC_lstore: case JVM_OPC_dstore:
var = code[offset + 1];
check_local_variable2: /* Make sure that the variable number isn't illegal. */
this_idata->operand.i = var; if ((var + 1) >= JVM_GetMethodIxLocalsCount(env, context->class, mi))
CCerror(context, "Illegal local variable number"); break;
default: if (opcode > JVM_OPC_MAX)
CCerror(context, "Quick instructions shouldn't appear yet."); break;
} /* of switch */
}
staticvoid
set_protected(context_type *context, unsignedint inumber, int key, int opcode)
{
JNIEnv *env = context->env;
fullinfo_type clazz_info; if (opcode != JVM_OPC_invokevirtual && opcode != JVM_OPC_invokespecial) {
clazz_info = cp_index_to_class_fullinfo(context, key,
JVM_CONSTANT_Fieldref);
} else {
clazz_info = cp_index_to_class_fullinfo(context, key,
JVM_CONSTANT_Methodref);
} if (is_superclass(context, clazz_info)) {
jclass calledClass =
object_fullinfo_to_classclass(context, clazz_info); int access; /* 4734966: JVM_GetCPFieldModifiers() or JVM_GetCPMethodModifiers() only searches the referenced field or method in calledClass. The following while loop is added to search up the superclass chain to make this symbolic resolution consistent with the field/method resolution
specified in VM spec 5.4.3. */
calledClass = (*env)->NewLocalRef(env, calledClass); do {
jclass tmp_cb; if (opcode != JVM_OPC_invokevirtual && opcode != JVM_OPC_invokespecial) {
access = JVM_GetCPFieldModifiers
(env, context->class, key, calledClass);
} else {
access = JVM_GetCPMethodModifiers
(env, context->class, key, calledClass);
} if (access != -1) { break;
}
tmp_cb = (*env)->GetSuperclass(env, calledClass);
(*env)->DeleteLocalRef(env, calledClass);
calledClass = tmp_cb;
} while (calledClass != 0);
if (access == -1) { /* field/method not found, detected at runtime. */
} elseif (access & JVM_ACC_PROTECTED) { if (!JVM_IsSameClassPackage(env, calledClass, context->class))
context->instruction_data[inumber].protected = JNI_TRUE;
}
(*env)->DeleteLocalRef(env, calledClass);
}
}
if (fptr == 0) return JNI_FALSE; for (; *fptr != 0; fptr++) { if (*fptr == clazz_info) return JNI_TRUE;
} return JNI_FALSE;
}
/* Look through each item on the exception table. Each of the fields must * refer to a legal instruction.
*/ staticvoid
initialize_exception_table(context_type *context)
{
JNIEnv *env = context->env; int mi = context->method_index; struct handler_info_type *handler_info = context->handler_info; int *code_data = context->code_data; int code_length = context->code_length; int max_stack_size = JVM_GetMethodIxMaxStack(env, context->class, mi); int i = JVM_GetMethodIxExceptionTableLength(env, context->class, mi); if (max_stack_size < 1 && i > 0) { // If the method contains exception handlers, it must have room // on the expression stack for the exception that the VM could push
CCerror(context, "Stack size too large");
} for (; --i >= 0; handler_info++) {
JVM_ExceptionTableEntryType einfo;
stack_item_type *stack_item = NEW(stack_item_type, 1);
JVM_GetMethodIxExceptionTableEntry(env, context->class, mi,
i, &einfo);
handler_info->start = code_data[einfo.start_pc]; /* einfo.end_pc may point to one byte beyond the end of bytecodes. */
handler_info->end = (einfo.end_pc == context->code_length) ?
context->instruction_count : code_data[einfo.end_pc];
handler_info->handler = code_data[einfo.handler_pc];
handler_info->stack_info.stack = stack_item;
handler_info->stack_info.stack_size = 1;
stack_item->next = NULL; if (einfo.catchType != 0) { constchar *classname; /* Constant pool entry type has been checked in format checker */
classname = JVM_GetCPClassNameUTF(env,
context->class,
einfo.catchType);
check_and_push_string_utf(context, classname);
stack_item->item = make_class_info_from_name(context, classname); if (!isAssignableTo(context,
stack_item->item,
context->throwable_info))
CCerror(context, "catch_type not a subclass of Throwable");
pop_and_free(context);
} else {
stack_item->item = context->throwable_info;
}
}
}
/* Given a pointer to an instruction, return its length. Use the table * opcode_length[] which is automatically built.
*/ staticint instruction_length(unsignedchar *iptr, unsignedchar *end)
{ staticunsignedchar opcode_length[] = JVM_OPCODE_LENGTH_INITIALIZER; int instruction = *iptr; switch (instruction) { case JVM_OPC_tableswitch: { int *lpc = (int *)UCALIGN(iptr + 1); int index; if (lpc + 2 >= (int *)end) { return -1; /* do not read pass the end */
}
index = _ck_ntohl(lpc[2]) - _ck_ntohl(lpc[1]); if ((index < 0) || (index > 65535)) { return -1; /* illegal */
} else { unsignedchar *finish = (unsignedchar *)(&lpc[index + 4]);
assert(finish >= iptr); return (int)(finish - iptr);
}
}
case JVM_OPC_lookupswitch: { int *lpc = (int *) UCALIGN(iptr + 1); int npairs; if (lpc + 1 >= (int *)end) return -1; /* do not read pass the end */
npairs = _ck_ntohl(lpc[1]); /* There can't be more than 64K labels because of the limit * on per-method byte code length.
*/ if (npairs < 0 || npairs >= 65536) return -1; else { unsignedchar *finish = (unsignedchar *)(&lpc[2 * (npairs + 1)]);
assert(finish >= iptr); return (int)(finish - iptr);
}
}
case JVM_OPC_wide: if (iptr + 1 >= end) return -1; /* do not read pass the end */ switch(iptr[1]) { case JVM_OPC_ret: case JVM_OPC_iload: case JVM_OPC_istore: case JVM_OPC_fload: case JVM_OPC_fstore: case JVM_OPC_aload: case JVM_OPC_astore: case JVM_OPC_lload: case JVM_OPC_lstore: case JVM_OPC_dload: case JVM_OPC_dstore: return 4; case JVM_OPC_iinc: return 6; default: return -1;
}
/* A length of 0 indicates an error. */ if (opcode_length[instruction] <= 0) return -1;
return opcode_length[instruction];
}
}
}
/* Given the target of a branch, make sure that it's a legal target. */ static jboolean
isLegalTarget(context_type *context, int offset)
{ int code_length = context->code_length; int *code_data = context->code_data; return (offset >= 0 && offset < code_length && code_data[offset] >= 0);
}
/* Make sure that an element of the constant pool really is of the indicated * type.
*/ staticvoid
verify_constant_pool_type(context_type *context, int index, unsigned mask)
{ int nconstants = context->nconstants; unsignedchar *type_table = context->constant_types; unsigned type;
if ((index <= 0) || (index >= nconstants))
CCerror(context, "Illegal constant pool index");
type = type_table[index]; if ((mask & (1 << type)) == 0)
CCerror(context, "Illegal type in constant pool");
}
/* Initialize the function entry, since we know everything about it. */
idata[0].stack_info.stack_size = 0;
idata[0].stack_info.stack = NULL;
idata[0].register_info.register_count = args_size;
idata[0].register_info.registers = NEW(fullinfo_type, args_size);
idata[0].register_info.mask_count = 0;
idata[0].register_info.masks = NULL;
idata[0].and_flags = 0; /* nothing needed */
idata[0].or_flags = FLAG_REACHED; /* instruction reached */
reg_ptr = idata[0].register_info.registers;
if ((JVM_GetMethodIxModifiers(env, cb, mi) & JVM_ACC_STATIC) == 0) { /* A non static method. If this is an <init> method, the first * argument is an uninitialized object. Otherwise it is an object of * the given class type. java.lang.Object.<init> is special since * we don't call its superclass <init> method.
*/ if (JVM_IsConstructorIx(env, cb, mi)
&& context->currentclass_info != context->object_info) {
*reg_ptr++ = MAKE_FULLINFO(ITEM_InitObject, 0, 0);
idata[0].or_flags |= FLAG_NEED_CONSTRUCTOR;
} else {
*reg_ptr++ = context->currentclass_info;
}
}
signature = JVM_GetMethodIxSignatureUTF(env, cb, mi);
check_and_push_string_utf(context, signature); /* Fill in each of the arguments into the registers. */ for (p = signature + 1; *p != JVM_SIGNATURE_ENDFUNC; ) { char fieldchar = signature_to_fieldtype(context, &p, &full_info); switch (fieldchar) { case'D': case'L':
*reg_ptr++ = full_info;
*reg_ptr++ = full_info + 1; break; default:
*reg_ptr++ = full_info; break;
}
}
p++; /* skip over right parenthesis */ if (*p == 'V') {
context->return_type = MAKE_FULLINFO(ITEM_Void, 0, 0);
} else {
signature_to_fieldtype(context, &p, &full_info);
context->return_type = full_info;
}
pop_and_free(context); /* Indicate that we need to look at the first instruction. */
idata[0].changed = JNI_TRUE;
}
/* Run the data flow analysis, as long as there are things to change. */ staticvoid
run_dataflow(context_type *context) {
JNIEnv *env = context->env; int mi = context->method_index;
jclass cb = context->class; int max_stack_size = JVM_GetMethodIxMaxStack(env, cb, mi);
instruction_data_type *idata = context->instruction_data; unsignedint icount = context->instruction_count;
jboolean work_to_do = JNI_TRUE; unsignedint inumber;
/* Run through the loop, until there is nothing left to do. */ while (work_to_do) {
work_to_do = JNI_FALSE; for (inumber = 0; inumber < icount; inumber++) {
instruction_data_type *this_idata = &idata[inumber]; if (this_idata->changed) {
register_info_type new_register_info;
stack_info_type new_stack_info;
flag_type new_and_flags, new_or_flags;
this_idata->changed = JNI_FALSE;
work_to_do = JNI_TRUE; #ifdef DEBUG if (verify_verbose) {
jio_fprintf(stdout, "Instruction %d: ", inumber);
print_stack(context, &this_idata->stack_info);
print_registers(context, &this_idata->register_info);
print_flags(context,
this_idata->and_flags, this_idata->or_flags);
fflush(stdout);
} #endif /* Make sure the registers and flags are appropriate */
check_register_values(context, inumber);
check_flags(context, inumber);
/* Make sure the stack can deal with this instruction */
pop_stack(context, inumber, &new_stack_info);
/* Update the registers and flags */
update_registers(context, inumber, &new_register_info);
update_flags(context, inumber, &new_and_flags, &new_or_flags);
/* Update the stack. */
push_stack(context, inumber, &new_stack_info);
if (new_stack_info.stack_size > max_stack_size)
CCerror(context, "Stack size too large"); #ifdef DEBUG if (verify_verbose) {
jio_fprintf(stdout, " ");
print_stack(context, &new_stack_info);
print_registers(context, &new_register_info);
print_flags(context, new_and_flags, new_or_flags);
fflush(stdout);
} #endif /* Add the new stack and register information to any
* instructions that can follow this instruction. */
merge_into_successors(context, inumber,
&new_register_info, &new_stack_info,
new_and_flags, new_or_flags);
}
}
}
}
/* Make sure that the registers contain a legitimate value for the given * instruction.
*/
staticvoid
check_register_values(context_type *context, unsignedint inumber)
{
instruction_data_type *idata = context->instruction_data;
instruction_data_type *this_idata = &idata[inumber]; int opcode = this_idata->opcode; int operand = this_idata->operand.i; int register_count = this_idata->register_info.register_count;
fullinfo_type *registers = this_idata->register_info.registers;
jboolean double_word = JNI_FALSE; /* default value */ int type;
switch (opcode) { default: return; case JVM_OPC_iload: case JVM_OPC_iinc:
type = ITEM_Integer; break; case JVM_OPC_fload:
type = ITEM_Float; break; case JVM_OPC_aload:
type = ITEM_Object; break; case JVM_OPC_ret:
type = ITEM_ReturnAddress; break; case JVM_OPC_lload:
type = ITEM_Long; double_word = JNI_TRUE; break; case JVM_OPC_dload:
type = ITEM_Double; double_word = JNI_TRUE; break;
} if (!double_word) {
fullinfo_type reg; /* Make sure we don't have an illegal register or one with wrong type */ if (operand >= register_count) {
CCerror(context, "Accessing value from uninitialized register %d", operand);
}
reg = registers[operand];
if (WITH_ZERO_EXTRA_INFO(reg) == (unsigned)MAKE_FULLINFO(type, 0, 0)) { /* the register is obviously of the given type */ return;
} elseif (GET_INDIRECTION(reg) > 0 && type == ITEM_Object) { /* address type stuff be used on all arrays */ return;
} elseif (GET_ITEM_TYPE(reg) == ITEM_ReturnAddress) {
CCerror(context, "Cannot load return address from register %d",
operand); /* alternatively (GET_ITEM_TYPE(reg) == ITEM_ReturnAddress) && (opcode == JVM_OPC_iload) && (type == ITEM_Object || type == ITEM_Integer) but this never occurs
*/
} elseif (reg == ITEM_InitObject && type == ITEM_Object) { return;
} elseif (WITH_ZERO_EXTRA_INFO(reg) ==
MAKE_FULLINFO(ITEM_NewObject, 0, 0) &&
type == ITEM_Object) { return;
} else {
CCerror(context, "Register %d contains wrong type", operand);
}
} else { /* Make sure we don't have an illegal register or one with wrong type */ if ((operand + 1) >= register_count) {
CCerror(context, "Accessing value from uninitialized register pair %d/%d",
operand, operand+1);
} else { if ((registers[operand] == (unsigned)MAKE_FULLINFO(type, 0, 0)) &&
(registers[operand + 1] == (unsigned)MAKE_FULLINFO(type + 1, 0, 0))) { return;
} else {
CCerror(context, "Register pair %d/%d contains wrong type",
operand, operand+1);
}
}
}
}
/* Make sure the flags contain legitimate values for this instruction.
*/
staticvoid
check_flags(context_type *context, unsignedint inumber)
{
instruction_data_type *idata = context->instruction_data;
instruction_data_type *this_idata = &idata[inumber]; int opcode = this_idata->opcode; switch (opcode) { case JVM_OPC_return: /* We need a constructor, but we aren't guaranteed it's called */ if ((this_idata->or_flags & FLAG_NEED_CONSTRUCTOR) &&
!(this_idata->and_flags & FLAG_CONSTRUCTED))
CCerror(context, "Constructor must call super() or this()"); /* fall through */ case JVM_OPC_ireturn: case JVM_OPC_lreturn: case JVM_OPC_freturn: case JVM_OPC_dreturn: case JVM_OPC_areturn: if (this_idata->or_flags & FLAG_NO_RETURN) /* This method cannot exit normally */
CCerror(context, "Cannot return normally"); default: break; /* nothing to do. */
}
}
/* Make sure that the top of the stack contains reasonable values for the * given instruction. The post-pop values of the stack and its size are * returned in *new_stack_info.
*/
staticvoid
pop_stack(context_type *context, unsignedint inumber, stack_info_type *new_stack_info)
{
instruction_data_type *idata = context->instruction_data;
instruction_data_type *this_idata = &idata[inumber]; int opcode = this_idata->opcode;
stack_item_type *stack = this_idata->stack_info.stack; int stack_size = this_idata->stack_info.stack_size; char *stack_operands, *p; char buffer[257]; /* for holding manufactured argument lists */
fullinfo_type stack_extra_info_buffer[256]; /* save info popped off stack */
fullinfo_type *stack_extra_info = &stack_extra_info_buffer[256];
fullinfo_type full_info; /* only used in case of invoke instructions */
fullinfo_type put_full_info; /* only used in case JVM_OPC_putstatic and JVM_OPC_putfield */
switch(opcode) { default: /* For most instructions, we just use a built-in table */
stack_operands = opcode_in_out[opcode][0]; break;
case JVM_OPC_putstatic: case JVM_OPC_putfield: { /* The top thing on the stack depends on the signature of
* the object. */ int operand = this_idata->operand.i; constchar *signature =
JVM_GetCPFieldSignatureUTF(context->env,
context->class,
operand); char *ip = buffer;
check_and_push_string_utf(context, signature); #ifdef DEBUG if (verify_verbose) {
print_formatted_fieldname(context, operand);
} #endif if (opcode == JVM_OPC_putfield)
*ip++ = 'A'; /* object for putfield */
*ip++ = signature_to_fieldtype(context, &signature, &put_full_info);
*ip = '\0';
stack_operands = buffer;
pop_and_free(context); break;
}
case JVM_OPC_invokevirtual: case JVM_OPC_invokespecial: case JVM_OPC_invokeinit: /* invokespecial call to <init> */ case JVM_OPC_invokestatic: case JVM_OPC_invokeinterface: { /* The top stuff on the stack depends on the method signature */ int operand = this_idata->operand.i; constchar *signature =
JVM_GetCPMethodSignatureUTF(context->env,
context->class,
operand); char *ip = buffer; constchar *p;
check_and_push_string_utf(context, signature); #ifdef DEBUG if (verify_verbose) {
print_formatted_methodname(context, operand);
} #endif if (opcode != JVM_OPC_invokestatic) /* First, push the object */
*ip++ = (opcode == JVM_OPC_invokeinit ? '@' : 'A'); for (p = signature + 1; *p != JVM_SIGNATURE_ENDFUNC; ) {
*ip++ = signature_to_fieldtype(context, &p, &full_info); if (ip >= buffer + sizeof(buffer) - 1)
CCerror(context, "Signature %s has too many arguments",
signature);
}
*ip = 0;
stack_operands = buffer;
pop_and_free(context); break;
}
case JVM_OPC_multianewarray: { /* Count can't be larger than 255. So can't overflow buffer */ int count = this_idata->operand2.i; /* number of ints on stack */
memset(buffer, 'I', count);
buffer[count] = '\0';
stack_operands = buffer; break;
}
} /* of switch */
/* Run through the list of operands >>backwards<< */ for ( p = stack_operands + strlen(stack_operands);
p > stack_operands;
stack = stack->next) { int type = *--p;
fullinfo_type top_type = stack ? stack->item : 0; int size = (type == 'D' || type == 'L') ? 2 : 1;
*--stack_extra_info = top_type; if (stack == NULL)
CCerror(context, "Unable to pop operand off an empty stack");
switch (type) { case'I': if (top_type != MAKE_FULLINFO(ITEM_Integer, 0, 0))
CCerror(context, "Expecting to find integer on stack"); break;
case'F': if (top_type != MAKE_FULLINFO(ITEM_Float, 0, 0))
CCerror(context, "Expecting to find float on stack"); break;
case'A': /* object or array */ if ( (GET_ITEM_TYPE(top_type) != ITEM_Object)
&& (GET_INDIRECTION(top_type) == 0)) { /* The thing isn't an object or an array. Let's see if it's
* one of the special cases */ if ( (WITH_ZERO_EXTRA_INFO(top_type) ==
MAKE_FULLINFO(ITEM_ReturnAddress, 0, 0))
&& (opcode == JVM_OPC_astore)) break; if ( (GET_ITEM_TYPE(top_type) == ITEM_NewObject
|| (GET_ITEM_TYPE(top_type) == ITEM_InitObject))
&& ((opcode == JVM_OPC_astore) || (opcode == JVM_OPC_aload)
|| (opcode == JVM_OPC_ifnull) || (opcode == JVM_OPC_ifnonnull))) break; /* The 2nd edition VM of the specification allows field * initializations before the superclass initializer, * if the field is defined within the current class.
*/ if ( (GET_ITEM_TYPE(top_type) == ITEM_InitObject)
&& (opcode == JVM_OPC_putfield)) { int operand = this_idata->operand.i; int access_bits = JVM_GetCPFieldModifiers(context->env,
context->class,
operand,
context->class); /* Note: This relies on the fact that * JVM_GetCPFieldModifiers retrieves only local fields, * and does not respect inheritance.
*/ if (access_bits != -1) { if ( cp_index_to_class_fullinfo(context, operand, JVM_CONSTANT_Fieldref) ==
context->currentclass_info ) {
top_type = context->currentclass_info;
*stack_extra_info = top_type; break;
}
}
}
CCerror(context, "Expecting to find object/array on stack");
} break;
case'@': { /* uninitialized object, for call to <init> */ int item_type = GET_ITEM_TYPE(top_type); if (item_type != ITEM_NewObject && item_type != ITEM_InitObject)
CCerror(context, "Expecting to find uninitialized object on stack"); break;
}
case'O': /* object, not array */ if (WITH_ZERO_EXTRA_INFO(top_type) !=
MAKE_FULLINFO(ITEM_Object, 0, 0))
CCerror(context, "Expecting to find object on stack"); break;
case'a': /* integer, object, or array */ if ( (top_type != MAKE_FULLINFO(ITEM_Integer, 0, 0))
&& (GET_ITEM_TYPE(top_type) != ITEM_Object)
&& (GET_INDIRECTION(top_type) == 0))
CCerror(context, "Expecting to find object, array, or int on stack"); break;
case'D': /* double */ if (top_type != MAKE_FULLINFO(ITEM_Double, 0, 0))
CCerror(context, "Expecting to find double on stack"); break;
case'L': /* long */ if (top_type != MAKE_FULLINFO(ITEM_Long, 0, 0))
CCerror(context, "Expecting to find long on stack"); break;
case']': /* array of some type */ if (top_type == NULL_FULLINFO) { /* do nothing */
} elseswitch(p[-1]) { case'I': /* array of integers */ if (top_type != MAKE_FULLINFO(ITEM_Integer, 1, 0) &&
top_type != NULL_FULLINFO)
CCerror(context, "Expecting to find array of ints on stack"); break;
case'L': /* array of longs */ if (top_type != MAKE_FULLINFO(ITEM_Long, 1, 0))
CCerror(context, "Expecting to find array of longs on stack"); break;
case'F': /* array of floats */ if (top_type != MAKE_FULLINFO(ITEM_Float, 1, 0))
CCerror(context, "Expecting to find array of floats on stack"); break;
case'D': /* array of doubles */ if (top_type != MAKE_FULLINFO(ITEM_Double, 1, 0))
CCerror(context, "Expecting to find array of doubles on stack"); break;
case'A': { /* array of addresses (arrays or objects) */ int indirection = GET_INDIRECTION(top_type); if ((indirection == 0) ||
((indirection == 1) &&
(GET_ITEM_TYPE(top_type) != ITEM_Object)))
CCerror(context, "Expecting to find array of objects or arrays " "on stack"); break;
}
case'B': /* array of bytes or booleans */ if (top_type != MAKE_FULLINFO(ITEM_Byte, 1, 0) &&
top_type != MAKE_FULLINFO(ITEM_Boolean, 1, 0))
CCerror(context, "Expecting to find array of bytes or Booleans on stack"); break;
case'C': /* array of characters */ if (top_type != MAKE_FULLINFO(ITEM_Char, 1, 0))
CCerror(context, "Expecting to find array of chars on stack"); break;
case'S': /* array of shorts */ if (top_type != MAKE_FULLINFO(ITEM_Short, 1, 0))
CCerror(context, "Expecting to find array of shorts on stack"); break;
case'?': /* any type of array is okay */ if (GET_INDIRECTION(top_type) == 0)
CCerror(context, "Expecting to find array on stack"); break;
default:
CCerror(context, "Internal error #1"); break;
}
p -= 2; /* skip over [ <char> */ break;
case'1': case'2': case'3': case'4': /* stack swapping */ if (top_type == MAKE_FULLINFO(ITEM_Double, 0, 0)
|| top_type == MAKE_FULLINFO(ITEM_Long, 0, 0)) { if ((p > stack_operands) && (p[-1] == '+')) {
context->swap_table[type - '1'] = top_type + 1;
context->swap_table[p[-2] - '1'] = top_type;
size = 2;
p -= 2;
} else {
CCerror(context, "Attempt to split long or double on the stack");
}
} else {
context->swap_table[type - '1'] = stack->item; if ((p > stack_operands) && (p[-1] == '+'))
p--; /* ignore */
} break; case'+': /* these should have been caught. */ default:
CCerror(context, "Internal error #2");
}
stack_size -= size;
}
/* For many of the opcodes that had an "A" in their field, we really * need to go back and do a little bit more accurate testing. We can, of * course, assume that the minimal type checking has already been done.
*/ switch (opcode) { default: break; case JVM_OPC_aastore: { /* array index object */
fullinfo_type array_type = stack_extra_info[0];
fullinfo_type object_type = stack_extra_info[2];
fullinfo_type target_type = decrement_indirection(array_type); if ((GET_ITEM_TYPE(object_type) != ITEM_Object)
&& (GET_INDIRECTION(object_type) == 0)) {
CCerror(context, "Expecting reference type on operand stack in aastore");
} if ((GET_ITEM_TYPE(target_type) != ITEM_Object)
&& (GET_INDIRECTION(target_type) == 0)) {
CCerror(context, "Component type of the array must be reference type in aastore");
} break;
}
case JVM_OPC_putfield: case JVM_OPC_getfield: case JVM_OPC_putstatic: { int operand = this_idata->operand.i;
fullinfo_type stack_object = stack_extra_info[0]; if (opcode == JVM_OPC_putfield || opcode == JVM_OPC_getfield) { if (!isAssignableTo
(context,
stack_object,
cp_index_to_class_fullinfo
(context, operand, JVM_CONSTANT_Fieldref))) {
CCerror(context, "Incompatible type for getting or setting field");
} if (this_idata->protected &&
!isAssignableTo(context, stack_object,
context->currentclass_info)) {
CCerror(context, "Bad access to protected data");
}
} if (opcode == JVM_OPC_putfield || opcode == JVM_OPC_putstatic) { int item = (opcode == JVM_OPC_putfield ? 1 : 0); if (!isAssignableTo(context,
stack_extra_info[item], put_full_info)) {
CCerror(context, "Bad type in putfield/putstatic");
}
} break;
}
case JVM_OPC_athrow: if (!isAssignableTo(context, stack_extra_info[0],
context->throwable_info)) {
CCerror(context, "Can only throw Throwable objects");
} break;
case JVM_OPC_aaload: { /* array index */ /* We need to pass the information to the stack updater */
fullinfo_type array_type = stack_extra_info[0];
context->swap_table[0] = decrement_indirection(array_type); break;
}
case JVM_OPC_invokevirtual: case JVM_OPC_invokespecial: case JVM_OPC_invokeinit: case JVM_OPC_invokeinterface: case JVM_OPC_invokestatic: { int operand = this_idata->operand.i; constchar *signature =
JVM_GetCPMethodSignatureUTF(context->env,
context->class,
operand); int item; constchar *p;
check_and_push_string_utf(context, signature); if (opcode == JVM_OPC_invokestatic) {
item = 0;
} elseif (opcode == JVM_OPC_invokeinit) {
fullinfo_type init_type = this_idata->operand2.fi;
fullinfo_type object_type = stack_extra_info[0];
context->swap_table[0] = object_type; /* save value */ if (GET_ITEM_TYPE(stack_extra_info[0]) == ITEM_NewObject) { /* We better be calling the appropriate init. Find the * inumber of the "JVM_OPC_new" instruction", and figure * out what the type really is.
*/ unsignedint new_inumber = GET_EXTRA_INFO(stack_extra_info[0]);
fullinfo_type target_type = idata[new_inumber].operand2.fi;
context->swap_table[1] = target_type;
if (target_type != init_type) {
CCerror(context, "Call to wrong initialization method");
} if (this_idata->protected
&& !isAssignableTo(context, object_type,
context->currentclass_info)) {
CCerror(context, "Bad access to protected data");
}
} else { /* We better be calling super() or this(). */ if (init_type != context->superclass_info &&
init_type != context->currentclass_info) {
CCerror(context, "Call to wrong initialization method");
}
context->swap_table[1] = context->currentclass_info;
}
item = 1;
} else {
fullinfo_type target_type = this_idata->operand2.fi;
fullinfo_type object_type = stack_extra_info[0]; if (!isAssignableTo(context, object_type, target_type)){
CCerror(context, "Incompatible object argument for function call");
} if (opcode == JVM_OPC_invokespecial
&& !isAssignableTo(context, object_type,
context->currentclass_info)) { /* Make sure object argument is assignment compatible to current class */
CCerror(context, "Incompatible object argument for invokespecial");
} if (this_idata->protected
&& !isAssignableTo(context, object_type,
context->currentclass_info)) { /* This is ugly. Special dispensation. Arrays pretend to
implement public Object clone() even though they don't */ constchar *utfName =
JVM_GetCPMethodNameUTF(context->env,
context->class,
this_idata->operand.i); int is_clone = utfName && (strcmp(utfName, "clone") == 0);
JVM_ReleaseUTF(utfName);
if ((target_type == context->object_info) &&
(GET_INDIRECTION(object_type) > 0) &&
is_clone) {
} else {
CCerror(context, "Bad access to protected data");
}
}
item = 1;
} for (p = signature + 1; *p != JVM_SIGNATURE_ENDFUNC; item++) if (signature_to_fieldtype(context, &p, &full_info) == 'A') { if (!isAssignableTo(context,
stack_extra_info[item], full_info)) {
CCerror(context, "Incompatible argument to function");
}
}
pop_and_free(context); break;
}
case JVM_OPC_return: if (context->return_type != MAKE_FULLINFO(ITEM_Void, 0, 0))
CCerror(context, "Wrong return type in function"); break;
case JVM_OPC_ireturn: case JVM_OPC_lreturn: case JVM_OPC_freturn: case JVM_OPC_dreturn: case JVM_OPC_areturn: {
fullinfo_type target_type = context->return_type;
fullinfo_type object_type = stack_extra_info[0]; if (!isAssignableTo(context, object_type, target_type)) {
CCerror(context, "Wrong return type in function");
} break;
}
case JVM_OPC_new: { /* Make sure that nothing on the stack already looks like what * we want to create. I can't image how this could possibly happen * but we should test for it anyway, since if it could happen, the * result would be an uninitialized object being able to masquerade * as an initialized one.
*/
stack_item_type *item; for (item = stack; item != NULL; item = item->next) { if (item->item == this_idata->operand.fi) {
CCerror(context, "Uninitialized object on stack at creating point");
}
} /* Info for update_registers */
context->swap_table[0] = this_idata->operand.fi;
context->swap_table[1] = MAKE_FULLINFO(ITEM_Bogus, 0, 0);
/* We've already determined that the instruction is legal. Perform the * operation on the registers, and return the updated results in * new_register_count_p and new_registers.
*/
/* Use these as default new values. */ int new_register_count = register_count; int new_mask_count = mask_count;
fullinfo_type *new_registers = registers;
mask_type *new_masks = masks;
/* Remember, we've already verified the type at the top of the stack. */ switch (opcode) { default: break; case JVM_OPC_istore: case JVM_OPC_fstore: case JVM_OPC_astore:
access = ACCESS_SINGLE; goto continue_store;
case JVM_OPC_lstore: case JVM_OPC_dstore:
access = ACCESS_DOUBLE; goto continue_store;
continue_store: { /* We have a modification to the registers. Copy them if needed. */
fullinfo_type stack_top_type = stack->item; int max_operand = operand + ((access == ACCESS_DOUBLE) ? 1 : 0);
if ( max_operand < register_count
&& registers[operand] == stack_top_type
&& ((access == ACCESS_SINGLE) ||
(registers[operand + 1]== stack_top_type + 1))) /* No changes have been made to the registers. */ break;
new_register_count = MAX(max_operand + 1, register_count);
new_registers = NEW(fullinfo_type, new_register_count); for (i = 0; i < register_count; i++)
new_registers[i] = registers[i]; for (i = register_count; i < new_register_count; i++)
new_registers[i] = MAKE_FULLINFO(ITEM_Bogus, 0, 0);
new_registers[operand] = stack_top_type; if (access == ACCESS_DOUBLE)
new_registers[operand + 1] = stack_top_type + 1; break;
}
case JVM_OPC_iload: case JVM_OPC_fload: case JVM_OPC_aload: case JVM_OPC_iinc: case JVM_OPC_ret:
access = ACCESS_SINGLE; break;
case JVM_OPC_lload: case JVM_OPC_dload:
access = ACCESS_DOUBLE; break;
case JVM_OPC_jsr: case JVM_OPC_jsr_w: for (i = 0; i < new_mask_count; i++) if (new_masks[i].entry == operand)
CCerror(context, "Recursive call to jsr entry");
new_masks = add_to_masks(context, masks, mask_count, operand);
new_mask_count++; break;
case JVM_OPC_invokeinit: case JVM_OPC_new: { /* For invokeinit, an uninitialized object has been initialized. * For new, all previous occurrences of an uninitialized object * from the same instruction must be made bogus. * We find all occurrences of swap_table[0] in the registers, and * replace them with swap_table[1];
*/
fullinfo_type from = context->swap_table[0];
fullinfo_type to = context->swap_table[1];
int i; for (i = 0; i < register_count; i++) { if (new_registers[i] == from) { /* Found a match */ break;
}
} if (i < register_count) { /* We broke out loop for match */ /* We have to change registers, and possibly a mask */
jboolean copied_mask = JNI_FALSE; int k;
new_registers = NEW(fullinfo_type, register_count);
memcpy(new_registers, registers,
register_count * sizeof(registers[0])); for ( ; i < register_count; i++) { if (new_registers[i] == from) {
new_registers[i] = to; for (k = 0; k < new_mask_count; k++) { if (!IS_BIT_SET(new_masks[k].modifies, i)) { if (!copied_mask) {
new_masks = copy_masks(context, new_masks,
mask_count);
copied_mask = JNI_TRUE;
}
SET_BIT(new_masks[k].modifies, i);
}
}
}
}
} break;
}
} /* of switch */
if ((access != ACCESS_NONE) && (new_mask_count > 0)) { int i, j; for (i = 0; i < new_mask_count; i++) { int *mask = new_masks[i].modifies; if ((!IS_BIT_SET(mask, operand)) ||
((access == ACCESS_DOUBLE) &&
!IS_BIT_SET(mask, operand + 1))) {
new_masks = copy_masks(context, new_masks, mask_count); for (j = i; j < new_mask_count; j++) {
SET_BIT(new_masks[j].modifies, operand); if (access == ACCESS_DOUBLE)
SET_BIT(new_masks[j].modifies, operand + 1);
} break;
}
}
}
/* Set the "we've done a constructor" flag */ if (this_idata->opcode == JVM_OPC_invokeinit) {
fullinfo_type from = context->swap_table[0]; if (from == MAKE_FULLINFO(ITEM_InitObject, 0, 0))
and_flags |= FLAG_CONSTRUCTED;
}
*new_and_flags = and_flags;
*new_or_flags = or_flags;
}
/* We've already determined that the instruction is legal. Perform the * operation on the stack; * * new_stack_size_p and new_stack_p point to the results after the pops have * already been done. Do the pushes, and then put the results back there.
*/
int stack_size = new_stack_info->stack_size;
stack_item_type *stack = new_stack_info->stack; char *stack_results;
fullinfo_type full_info = 0; char buffer[5], *p; /* actually [2] is big enough */
/* We need to look at all those opcodes in which either we can't tell the * value pushed onto the stack from the opcode, or in which the value * pushed onto the stack is an object or array. For the latter, we need * to make sure that full_info is set to the right value.
*/ switch(opcode) { default:
stack_results = opcode_in_out[opcode][1]; break;
case JVM_OPC_ldc: case JVM_OPC_ldc_w: case JVM_OPC_ldc2_w: { /* Look to constant pool to determine correct result. */ unsignedchar *type_table = context->constant_types; switch (type_table[operand]) { case JVM_CONSTANT_Integer:
stack_results = "I"; break; case JVM_CONSTANT_Float:
stack_results = "F"; break; case JVM_CONSTANT_Double:
stack_results = "D"; break; case JVM_CONSTANT_Long:
stack_results = "L"; break; case JVM_CONSTANT_String:
stack_results = "A";
full_info = context->string_info; break; case JVM_CONSTANT_Class: if (context->major_version < LDC_CLASS_MAJOR_VERSION)
CCerror(context, "Internal error #3");
stack_results = "A";
full_info = make_class_info_from_name(context, "java/lang/Class"); break; case JVM_CONSTANT_MethodHandle: case JVM_CONSTANT_MethodType: if (context->major_version < LDC_METHOD_HANDLE_MAJOR_VERSION)
CCerror(context, "Internal error #3");
stack_results = "A"; switch (type_table[operand]) { case JVM_CONSTANT_MethodType:
full_info = make_class_info_from_name(context, "java/lang/invoke/MethodType"); break; default: //JVM_CONSTANT_MethodHandle
full_info = make_class_info_from_name(context, "java/lang/invoke/MethodHandle"); break;
} break; default:
CCerror(context, "Internal error #3");
stack_results = ""; /* Never reached: keep lint happy */
} break;
}
case JVM_OPC_getstatic: case JVM_OPC_getfield: { /* Look to signature to determine correct result. */ int operand = this_idata->operand.i; constchar *signature = JVM_GetCPFieldSignatureUTF(context->env,
context->class,
operand);
check_and_push_string_utf(context, signature); #ifdef DEBUG if (verify_verbose) {
print_formatted_fieldname(context, operand);
} #endif
buffer[0] = signature_to_fieldtype(context, &signature, &full_info);
buffer[1] = '\0';
stack_results = buffer;
pop_and_free(context); break;
}
case JVM_OPC_invokevirtual: case JVM_OPC_invokespecial: case JVM_OPC_invokeinit: case JVM_OPC_invokestatic: case JVM_OPC_invokeinterface: { /* Look to signature to determine correct result. */ int operand = this_idata->operand.i; constchar *signature = JVM_GetCPMethodSignatureUTF(context->env,
context->class,
operand); constchar *result_signature;
check_and_push_string_utf(context, signature);
result_signature = get_result_signature(signature); if (result_signature++ == NULL) {
CCerror(context, "Illegal signature %s", signature);
} if (result_signature[0] == JVM_SIGNATURE_VOID) {
stack_results = "";
} else {
buffer[0] = signature_to_fieldtype(context, &result_signature,
&full_info);
buffer[1] = '\0';
stack_results = buffer;
}
pop_and_free(context); break;
}
case JVM_OPC_aconst_null:
stack_results = opcode_in_out[opcode][1];
full_info = NULL_FULLINFO; /* special NULL */ break;
case JVM_OPC_new: case JVM_OPC_checkcast: case JVM_OPC_newarray: case JVM_OPC_anewarray: case JVM_OPC_multianewarray:
stack_results = opcode_in_out[opcode][1]; /* Conveniently, this result type is stored here */
full_info = this_idata->operand.fi; break;
case JVM_OPC_aaload:
stack_results = opcode_in_out[opcode][1]; /* pop_stack() saved value for us. */
full_info = context->swap_table[0]; break;
case JVM_OPC_aload:
stack_results = opcode_in_out[opcode][1]; /* The register hasn't been modified, so we can use its value. */
full_info = this_idata->register_info.registers[operand]; break;
} /* of switch */
} /* switch type */
stack_size++;
} /* outer for loop */
if (opcode == JVM_OPC_invokeinit) { /* If there are any instances of "from" on the stack, we need to * replace it with "to", since calling <init> initializes all versions
* of the object, obviously. */
fullinfo_type from = context->swap_table[0];
stack_item_type *ptr; for (ptr = stack; ptr != NULL; ptr = ptr->next) { if (ptr->item == from) {
fullinfo_type to = context->swap_table[1];
stack = copy_stack(context, stack); for (ptr = stack; ptr != NULL; ptr = ptr->next) if (ptr->item == from) ptr->item = to; break;
}
}
}
/* We've performed an instruction, and determined the new registers and stack * value. Look at all of the possibly subsequent instructions, and merge * this stack value into theirs.
*/
case JVM_OPC_ifeq: case JVM_OPC_ifne: case JVM_OPC_ifgt: case JVM_OPC_ifge: case JVM_OPC_iflt: case JVM_OPC_ifle: case JVM_OPC_ifnull: case JVM_OPC_ifnonnull: case JVM_OPC_if_icmpeq: case JVM_OPC_if_icmpne: case JVM_OPC_if_icmpgt: case JVM_OPC_if_icmpge: case JVM_OPC_if_icmplt: case JVM_OPC_if_icmple: case JVM_OPC_if_acmpeq: case JVM_OPC_if_acmpne:
successors_count = 2;
buffer[0] = inumber + 1;
buffer[1] = operand; break;
case JVM_OPC_jsr: case JVM_OPC_jsr_w: if (this_idata->operand2.i != UNKNOWN_RET_INSTRUCTION)
idata[this_idata->operand2.i].changed = JNI_TRUE; /* FALLTHROUGH */ case JVM_OPC_goto: case JVM_OPC_goto_w:
successors_count = 1;
buffer[0] = operand; break;
case JVM_OPC_ireturn: case JVM_OPC_lreturn: case JVM_OPC_return: case JVM_OPC_freturn: case JVM_OPC_dreturn: case JVM_OPC_areturn: case JVM_OPC_athrow: /* The testing for the returns is handled in pop_stack() */
successors_count = 0; break;
case JVM_OPC_ret: { /* This is slightly slow, but good enough for a seldom used instruction. * The EXTRA_ITEM_INFO of the ITEM_ReturnAddress indicates the * address of the first instruction of the subroutine. We can return * to 1 after any instruction that jsr's to that instruction.
*/ if (this_idata->operand2.ip == NULL) {
fullinfo_type *registers = this_idata->register_info.registers; int called_instruction = GET_EXTRA_INFO(registers[operand]); int i, count, *ptr;; for (i = context->instruction_count, count = 0; --i >= 0; ) { if (((idata[i].opcode == JVM_OPC_jsr) ||
(idata[i].opcode == JVM_OPC_jsr_w)) &&
(idata[i].operand.i == called_instruction))
count++;
}
this_idata->operand2.ip = ptr = NEW(int, count + 1);
*ptr++ = count; for (i = context->instruction_count, count = 0; --i >= 0; ) { if (((idata[i].opcode == JVM_OPC_jsr) ||
(idata[i].opcode == JVM_OPC_jsr_w)) &&
(idata[i].operand.i == called_instruction))
*ptr++ = i + 1;
}
}
successors = this_idata->operand2.ip; /* use this instead */
successors_count = *successors++; break;
}
case JVM_OPC_tableswitch: case JVM_OPC_lookupswitch:
successors = this_idata->operand.ip; /* use this instead */
successors_count = *successors++; break;
}
#ifdef DEBUG if (verify_verbose) {
jio_fprintf(stdout, " ["); for (i = handler_info_length; --i >= 0; handler_info++) if (handler_info->start <= (int)inumber && handler_info->end > (int)inumber)
jio_fprintf(stdout, "%d* ", handler_info->handler); for (i = 0; i < successors_count; i++)
jio_fprintf(stdout, "%d ", successors[i]);
jio_fprintf(stdout, "]\n");
} #endif
handler_info = context->handler_info; for (i = handler_info_length; --i >= 0; handler_info++) { if (handler_info->start <= (int)inumber && handler_info->end > (int)inumber) { int handler = handler_info->handler; if (opcode != JVM_OPC_invokeinit) {
merge_into_one_successor(context, inumber, handler,
&this_idata->register_info, /* old */
&handler_info->stack_info,
(flag_type) (and_flags
& this_idata->and_flags),
(flag_type) (or_flags
| this_idata->or_flags),
JNI_TRUE);
} else { /* We need to be a little bit more careful with this * instruction. Things could either be in the state before
* the instruction or in the state afterwards */
fullinfo_type from = context->swap_table[0];
flag_type temp_or_flags = or_flags; if (from == MAKE_FULLINFO(ITEM_InitObject, 0, 0))
temp_or_flags |= FLAG_NO_RETURN;
merge_into_one_successor(context, inumber, handler,
&this_idata->register_info, /* old */
&handler_info->stack_info,
this_idata->and_flags,
this_idata->or_flags,
JNI_TRUE);
merge_into_one_successor(context, inumber, handler,
register_info,
&handler_info->stack_info,
and_flags, temp_or_flags, JNI_TRUE);
}
}
} for (i = 0; i < successors_count; i++) { int target = successors[i]; if (target >= context->instruction_count)
CCerror(context, "Falling off the end of the code");
merge_into_one_successor(context, inumber, target,
register_info, stack_info, and_flags, or_flags,
JNI_FALSE);
}
}
/* We have a new set of registers and stack values for a given instruction. * Merge this new set into the values that are already there.
*/
/* All uninitialized objects are set to "bogus" when jsr and * ret are executed. Thus uninitialized objects can't propagate * into or out of a subroutine.
*/ if (idata[from_inumber].opcode == JVM_OPC_ret ||
idata[from_inumber].opcode == JVM_OPC_jsr ||
idata[from_inumber].opcode == JVM_OPC_jsr_w) { int new_register_count = new_register_info->register_count;
fullinfo_type *new_registers = new_register_info->registers; int i;
stack_item_type *item;
for (item = new_stack_info->stack; item != NULL; item = item->next) { if (GET_ITEM_TYPE(item->item) == ITEM_NewObject) { /* This check only succeeds for hand-contrived code. * Efficiency is not an issue.
*/
stack_info_buf.stack = copy_stack(context,
new_stack_info->stack);
stack_info_buf.stack_size = new_stack_info->stack_size;
new_stack_info = &stack_info_buf; for (item = new_stack_info->stack; item != NULL;
item = item->next) { if (GET_ITEM_TYPE(item->item) == ITEM_NewObject) {
item->item = MAKE_FULLINFO(ITEM_Bogus, 0, 0);
}
} break;
}
} for (i = 0; i < new_register_count; i++) { if (GET_ITEM_TYPE(new_registers[i]) == ITEM_NewObject) { /* This check only succeeds for hand-contrived code. * Efficiency is not an issue.
*/
fullinfo_type *new_set = NEW(fullinfo_type,
new_register_count); for (i = 0; i < new_register_count; i++) {
fullinfo_type t = new_registers[i];
new_set[i] = GET_ITEM_TYPE(t) != ITEM_NewObject ?
t : MAKE_FULLINFO(ITEM_Bogus, 0, 0);
}
register_info_buf.register_count = new_register_count;
register_info_buf.registers = new_set;
register_info_buf.mask_count = new_register_info->mask_count;
register_info_buf.masks = new_register_info->masks;
new_register_info = ®ister_info_buf; break;
}
}
}
/* Returning from a subroutine is somewhat ugly. The actual thing * that needs to get merged into the new instruction is a joining * of info from the ret instruction with stuff in the jsr instruction
*/ if (idata[from_inumber].opcode == JVM_OPC_ret && !isException) { int new_register_count = new_register_info->register_count;
fullinfo_type *new_registers = new_register_info->registers; int new_mask_count = new_register_info->mask_count;
mask_type *new_masks = new_register_info->masks; int operand = idata[from_inumber].operand.i; int called_instruction = GET_EXTRA_INFO(new_registers[operand]);
instruction_data_type *jsr_idata = &idata[to_inumber - 1];
register_info_type *jsr_reginfo = &jsr_idata->register_info; if (jsr_idata->operand2.i != (int)from_inumber) { if (jsr_idata->operand2.i != UNKNOWN_RET_INSTRUCTION)
CCerror(context, "Multiple returns to single jsr");
jsr_idata->operand2.i = from_inumber;
} if (jsr_reginfo->register_count == UNKNOWN_REGISTER_COUNT) { /* We don't want to handle the returned-to instruction until * we've dealt with the jsr instruction. When we get to the * jsr instruction (if ever), we'll re-mark the ret instruction
*/
;
} else { int register_count = jsr_reginfo->register_count;
fullinfo_type *registers = jsr_reginfo->registers; int max_registers = MAX(register_count, new_register_count);
fullinfo_type *new_set = NEW(fullinfo_type, max_registers); int *return_mask; struct register_info_type new_new_register_info; int i; /* Make sure the place we're returning from is legal! */ for (i = new_mask_count; --i >= 0; ) if (new_masks[i].entry == called_instruction) break; if (i < 0)
CCerror(context, "Illegal return from subroutine"); /* pop the masks down to the indicated one. Remember the mask
* we're popping off. */
return_mask = new_masks[i].modifies;
new_mask_count = i; for (i = 0; i < max_registers; i++) { if (IS_BIT_SET(return_mask, i))
new_set[i] = i < new_register_count ?
new_registers[i] : MAKE_FULLINFO(ITEM_Bogus, 0, 0); else
new_set[i] = i < register_count ?
registers[i] : MAKE_FULLINFO(ITEM_Bogus, 0, 0);
}
new_new_register_info.register_count = max_registers;
new_new_register_info.registers = new_set;
new_new_register_info.mask_count = new_mask_count;
new_new_register_info.masks = new_masks;
int new_register_count = new_register_info->register_count;
fullinfo_type *new_registers = new_register_info->registers; int new_mask_count = new_register_info->mask_count;
mask_type *new_masks = new_register_info->masks;
if (this_reginfo->register_count == UNKNOWN_REGISTER_COUNT) {
this_reginfo->register_count = new_register_count;
this_reginfo->registers = new_registers;
this_reginfo->mask_count = new_mask_count;
this_reginfo->masks = new_masks;
this_idata->changed = JNI_TRUE;
} else { /* See if we've got new information on the register set. */ int register_count = this_reginfo->register_count;
fullinfo_type *registers = this_reginfo->registers; int mask_count = this_reginfo->mask_count;
mask_type *masks = this_reginfo->masks;
jboolean copy = JNI_FALSE; int i, j; if (register_count > new_register_count) { /* Any register larger than new_register_count is now bogus */
this_reginfo->register_count = new_register_count;
register_count = new_register_count;
this_idata->changed = JNI_TRUE;
} for (i = 0; i < register_count; i++) {
fullinfo_type prev_value = registers[i]; if ((i < new_register_count)
? (!isAssignableTo(context, new_registers[i], prev_value))
: (prev_value != MAKE_FULLINFO(ITEM_Bogus, 0, 0))) {
copy = JNI_TRUE; break;
}
}
if (copy) { /* We need a copy. So do it. */
fullinfo_type *new_set = NEW(fullinfo_type, register_count); for (j = 0; j < i; j++)
new_set[j] = registers[j]; for (j = i; j < register_count; j++) { if (i >= new_register_count)
new_set[j] = MAKE_FULLINFO(ITEM_Bogus, 0, 0); else
new_set[j] = merge_fullinfo_types(context,
new_registers[j],
registers[j], JNI_FALSE);
} /* Some of the end items might now be bogus. This step isn't
* necessary, but it may save work later. */ while ( register_count > 0
&& GET_ITEM_TYPE(new_set[register_count-1]) == ITEM_Bogus)
register_count--;
this_reginfo->register_count = register_count;
this_reginfo->registers = new_set;
this_idata->changed = JNI_TRUE;
} if (mask_count > 0) { /* If the target instruction already has a sequence of masks, then * we need to merge new_masks into it. We want the entries on * the mask to be the longest common substring of the two. * (e.g. a->b->d merged with a->c->d should give a->d) * The bits set in the mask should be the or of the corresponding * entries in each of the original masks.
*/ int i, j, k; int matches = 0; int last_match = -1;
jboolean copy_needed = JNI_FALSE; for (i = 0; i < mask_count; i++) { int entry = masks[i].entry; for (j = last_match + 1; j < new_mask_count; j++) { if (new_masks[j].entry == entry) { /* We have a match */ int *prev = masks[i].modifies; int *new = new_masks[j].modifies;
matches++; /* See if new_mask has bits set for "entry" that
* weren't set for mask. If so, need to copy. */ for (k = context->bitmask_size - 1;
!copy_needed && k >= 0;
k--) if (~prev[k] & new[k])
copy_needed = JNI_TRUE;
last_match = j; break;
}
}
} if ((matches < mask_count) || copy_needed) { /* We need to make a copy for the new item, since either the
* size has decreased, or new bits are set. */
mask_type *copy = NEW(mask_type, matches); for (i = 0; i < matches; i++) {
copy[i].modifies = NEW(int, context->bitmask_size);
}
this_reginfo->masks = copy;
this_reginfo->mask_count = matches;
this_idata->changed = JNI_TRUE;
matches = 0;
last_match = -1; for (i = 0; i < mask_count; i++) { int entry = masks[i].entry; for (j = last_match + 1; j < new_mask_count; j++) { if (new_masks[j].entry == entry) { int *prev1 = masks[i].modifies; int *prev2 = new_masks[j].modifies; int *new = copy[matches].modifies;
copy[matches].entry = entry; for (k = context->bitmask_size - 1; k >= 0; k--) new[k] = prev1[k] | prev2[k];
matches++;
last_match = j; break;
}
}
}
}
}
}
}
static mask_type *
copy_masks(context_type *context, mask_type *masks, int mask_count)
{
mask_type *result = NEW(mask_type, mask_count); int bitmask_size = context->bitmask_size; int *bitmaps = NEW(int, mask_count * bitmask_size); int i; for (i = 0; i < mask_count; i++) {
result[i].entry = masks[i].entry;
result[i].modifies = &bitmaps[i * bitmask_size];
memcpy(result[i].modifies, masks[i].modifies, bitmask_size * sizeof(int));
} return result;
}
static mask_type *
add_to_masks(context_type *context, mask_type *masks, int mask_count, int d)
{
mask_type *result = NEW(mask_type, mask_count + 1); int bitmask_size = context->bitmask_size; int *bitmaps = NEW(int, (mask_count + 1) * bitmask_size); int i; for (i = 0; i < mask_count; i++) {
result[i].entry = masks[i].entry;
result[i].modifies = &bitmaps[i * bitmask_size];
memcpy(result[i].modifies, masks[i].modifies, bitmask_size * sizeof(int));
}
result[mask_count].entry = d;
result[mask_count].modifies = &bitmaps[mask_count * bitmask_size];
memset(result[mask_count].modifies, 0, bitmask_size * sizeof(int)); return result;
}
/* We create our own storage manager, since we malloc lots of little items, * and I don't want to keep trace of when they become free. I sure wish that * we had heaps, and I could just free the heap when done.
*/
#define CCSegSize 2000
struct CCpool { /* a segment of allocated memory in the pool */ struct CCpool *next; int segSize; /* almost always CCSegSize */ int poolPad; char space[CCSegSize];
};
/* Initialize the context's heap. */ staticvoid CCinit(context_type *context)
{ struct CCpool *new = (struct CCpool *) malloc(sizeof(struct CCpool)); /* Set context->CCroot to 0 if new == 0 to tell CCdestroy to lay off */
context->CCroot = context->CCcurrent = new; if (new == 0) {
CCout_of_memory(context);
}
new->next = NULL;
new->segSize = CCSegSize;
context->CCfree_size = CCSegSize;
context->CCfree_ptr = &new->space[0];
}
/* Reuse all the space that we have in the context's heap. */ staticvoid CCreinit(context_type *context)
{ struct CCpool *first = context->CCroot;
context->CCcurrent = first;
context->CCfree_size = CCSegSize;
context->CCfree_ptr = &first->space[0];
}
/* Destroy the context's heap. */ staticvoid CCdestroy(context_type *context)
{ struct CCpool *this = context->CCroot; while (this) { struct CCpool *next = this->next;
free(this); this = next;
} /* These two aren't necessary. But can't hurt either */
context->CCroot = context->CCcurrent = NULL;
context->CCfree_ptr = 0;
}
/* Allocate an object of the given size from the context's heap. */ staticvoid *
CCalloc(context_type *context, int size, jboolean zero)
{
registerchar *p; /* Round CC to the size of a pointer */
size = (size + (sizeof(void *) - 1)) & ~(sizeof(void *) - 1);
if (context->CCfree_size < size) { struct CCpool *current = context->CCcurrent; struct CCpool *new; if (size > CCSegSize) { /* we need to allocate a special block */ new = (struct CCpool *)malloc(sizeof(struct CCpool) +
(size - CCSegSize)); if (new == 0) {
CCout_of_memory(context);
}
new->next = current->next;
new->segSize = size;
current->next = new;
} else { new = current->next; if (new == NULL) { new = (struct CCpool *) malloc(sizeof(struct CCpool)); if (new == 0) {
CCout_of_memory(context);
}
current->next = new;
new->next = NULL;
new->segSize = CCSegSize;
}
}
context->CCcurrent = new;
context->CCfree_ptr = &new->space[0];
context->CCfree_size = new->segSize;
}
p = context->CCfree_ptr;
context->CCfree_ptr += size;
context->CCfree_size -= size; if (zero)
memset(p, 0, size); return p;
}
/* Get the class associated with a particular field or method or class in the * constant pool. If is_field is true, we've got a field or method. If * false, we've got a class.
*/ static fullinfo_type
cp_index_to_class_fullinfo(context_type *context, int cp_index, int kind)
{
JNIEnv *env = context->env;
fullinfo_type result; constchar *classname; switch (kind) { case JVM_CONSTANT_Class:
classname = JVM_GetCPClassNameUTF(env,
context->class,
cp_index); break; case JVM_CONSTANT_Methodref:
classname = JVM_GetCPMethodClassNameUTF(env,
context->class,
cp_index); break; case JVM_CONSTANT_Fieldref:
classname = JVM_GetCPFieldClassNameUTF(env,
context->class,
cp_index); break; default:
classname = NULL;
CCerror(context, "Internal error #5");
}
check_and_push_string_utf(context, classname); if (classname[0] == JVM_SIGNATURE_ARRAY) { /* This make recursively call us, in case of a class array */
signature_to_fieldtype(context, &classname, &result);
} else {
result = make_class_info_from_name(context, classname);
}
pop_and_free(context); return result;
}
staticvoid
CCerror (context_type *context, char *format, ...)
{ int n = print_CCerror_info(context);
va_list args; if (n >= 0 && n < context->message_buf_len) {
va_start(args, format);
jio_vsnprintf(context->message + n, context->message_buf_len - n,
format, args);
va_end(args);
}
context->err_code = CC_VerifyError;
longjmp(context->jump_buffer, 1);
}
staticvoid
CCout_of_memory(context_type *context)
{ int n = print_CCerror_info(context);
context->err_code = CC_OutOfMemory;
longjmp(context->jump_buffer, 1);
}
staticvoid
CFerror(context_type *context, char *format, ...)
{ int n = print_CCerror_info(context);
va_list args; if (n >= 0 && n < context->message_buf_len) {
va_start(args, format);
jio_vsnprintf(context->message + n, context->message_buf_len - n,
format, args);
va_end(args);
}
context->err_code = CC_ClassFormatError;
longjmp(context->jump_buffer, 1);
}
/* * Need to scan the entire signature to find the result type because * types in the arg list and the result type could contain embedded ')'s.
*/ staticconstchar* get_result_signature(constchar* signature) { constchar *p; for (p = signature; *p != JVM_SIGNATURE_ENDFUNC; p++) { switch (*p) { case JVM_SIGNATURE_BOOLEAN: case JVM_SIGNATURE_BYTE: case JVM_SIGNATURE_CHAR: case JVM_SIGNATURE_SHORT: case JVM_SIGNATURE_INT: case JVM_SIGNATURE_FLOAT: case JVM_SIGNATURE_DOUBLE: case JVM_SIGNATURE_LONG: case JVM_SIGNATURE_FUNC: /* ignore initial (, if given */ break; case JVM_SIGNATURE_CLASS: while (*p != JVM_SIGNATURE_ENDCLASS) p++; break; case JVM_SIGNATURE_ARRAY: while (*p == JVM_SIGNATURE_ARRAY) p++; /* If an array of classes, skip over class name, too. */ if (*p == JVM_SIGNATURE_CLASS) { while (*p != JVM_SIGNATURE_ENDCLASS) p++;
} break; default: /* Indicate an error. */ return NULL;
}
} return p++; /* skip over ')'. */
}
for (;;) { switch(*p++) { default:
result = 0; break;
case JVM_SIGNATURE_BOOLEAN:
full_info = (array_depth > 0)
? MAKE_FULLINFO(ITEM_Boolean, 0, 0)
: MAKE_FULLINFO(ITEM_Integer, 0, 0);
result = 'I'; break;
case JVM_SIGNATURE_BYTE:
full_info = (array_depth > 0)
? MAKE_FULLINFO(ITEM_Byte, 0, 0)
: MAKE_FULLINFO(ITEM_Integer, 0, 0);
result = 'I'; break;
case JVM_SIGNATURE_CHAR:
full_info = (array_depth > 0)
? MAKE_FULLINFO(ITEM_Char, 0, 0)
: MAKE_FULLINFO(ITEM_Integer, 0, 0);
result = 'I'; break;
case JVM_SIGNATURE_SHORT:
full_info = (array_depth > 0)
? MAKE_FULLINFO(ITEM_Short, 0, 0)
: MAKE_FULLINFO(ITEM_Integer, 0, 0);
result = 'I'; break;
case JVM_SIGNATURE_INT:
full_info = MAKE_FULLINFO(ITEM_Integer, 0, 0);
result = 'I'; break;
case JVM_SIGNATURE_FLOAT:
full_info = MAKE_FULLINFO(ITEM_Float, 0, 0);
result = 'F'; break;
case JVM_SIGNATURE_DOUBLE:
full_info = MAKE_FULLINFO(ITEM_Double, 0, 0);
result = 'D'; break;
case JVM_SIGNATURE_LONG:
full_info = MAKE_FULLINFO(ITEM_Long, 0, 0);
result = 'L'; break;
case JVM_SIGNATURE_ARRAY:
array_depth++; continue; /* only time we ever do the loop > 1 */
case JVM_SIGNATURE_CLASS: { char buffer_space[256]; char *buffer = buffer_space; char *finish = strchr(p, JVM_SIGNATURE_ENDCLASS); int length; if (finish == NULL) { /* Signature must have ';' after the class name.
* If it does not, return 0 and ITEM_Bogus in full_info. */
result = 0; break;
}
assert(finish >= p);
length = (int)(finish - p); if (length + 1 > (int)sizeof(buffer_space)) {
buffer = malloc(length + 1);
check_and_push_malloc_block(context, buffer);
}
memcpy(buffer, p, length);
buffer[length] = '\0';
full_info = make_class_info_from_name(context, buffer);
result = 'A';
p = finish + 1; if (buffer != buffer_space)
pop_and_free(context); break;
}
} /* end of switch */ break;
}
*signature_p = p; if (array_depth == 0 || result == 0) { /* either not an array, or result is bogus */
*full_info_p = full_info; return result;
} else { if (array_depth > MAX_ARRAY_DIMENSIONS)
CCerror(context, "Array with too many dimensions");
*full_info_p = MAKE_FULLINFO(GET_ITEM_TYPE(full_info),
array_depth,
GET_EXTRA_INFO(full_info)); return'A';
}
}
/* Given an array type, create the type that has one less level of * indirection.
*/
static fullinfo_type
decrement_indirection(fullinfo_type array_info)
{ if (array_info == NULL_FULLINFO) { return NULL_FULLINFO;
} else { int type = GET_ITEM_TYPE(array_info); int indirection = GET_INDIRECTION(array_info) - 1; int extra_info = GET_EXTRA_INFO(array_info); if ( (indirection == 0)
&& ((type == ITEM_Short || type == ITEM_Byte || type == ITEM_Boolean || type == ITEM_Char)))
type = ITEM_Integer; return MAKE_FULLINFO(type, indirection, extra_info);
}
}
/* See if we can assign an object of the "from" type to an object * of the "to" type.
*/
/* Given two fullinfo_type's, find their lowest common denominator. If * the assignable_p argument is non-null, we're really just calling to find * out if "<target> := <value>" is a legitimate assignment. * * We treat all interfaces as if they were of type java/lang/Object, since the * runtime will do the full checking.
*/ static fullinfo_type
merge_fullinfo_types(context_type *context,
fullinfo_type value, fullinfo_type target,
jboolean for_assignment)
{
JNIEnv *env = context->env; if (value == target) { /* If they're identical, clearly just return what we've got */ return value;
}
/* Both must be either arrays or objects to go further */ if (GET_INDIRECTION(value) == 0 && GET_ITEM_TYPE(value) != ITEM_Object) return MAKE_FULLINFO(ITEM_Bogus, 0, 0); if (GET_INDIRECTION(target) == 0 && GET_ITEM_TYPE(target) != ITEM_Object) return MAKE_FULLINFO(ITEM_Bogus, 0, 0);
/* If either is NULL, return the other. */ if (value == NULL_FULLINFO) return target; elseif (target == NULL_FULLINFO) return value;
/* If either is java/lang/Object, that's the result. */ if (target == context->object_info) return target; elseif (value == context->object_info) { /* Minor hack. For assignments, Interface := Object, return Interface * rather than Object, so that isAssignableTo() will get the right
* result. */ if (for_assignment && (WITH_ZERO_EXTRA_INFO(target) ==
MAKE_FULLINFO(ITEM_Object, 0, 0))) {
jclass cb = object_fullinfo_to_classclass(context,
target); int is_interface = cb && JVM_IsInterface(env, cb); if (is_interface) return target;
} return value;
} if (GET_INDIRECTION(value) > 0 || GET_INDIRECTION(target) > 0) { /* At least one is an array. Neither is java/lang/Object or NULL. * Moreover, the types are not identical. * The result must either be Object, or an array of some object type.
*/
fullinfo_type value_base, target_base; int dimen_value = GET_INDIRECTION(value); int dimen_target = GET_INDIRECTION(target);
if (value == context->cloneable_info ||
value == context->serializable_info) { return value;
}
/* First, if either item's base type isn't ITEM_Object, promote it up * to an object or array of object. If either is elemental, we can * punt.
*/ if (GET_ITEM_TYPE(value) != ITEM_Object) { if (dimen_value == 0) return MAKE_FULLINFO(ITEM_Bogus, 0, 0);
dimen_value--;
value = MAKE_Object_ARRAY(dimen_value);
} if (GET_ITEM_TYPE(target) != ITEM_Object) { if (dimen_target == 0) return MAKE_FULLINFO(ITEM_Bogus, 0, 0);
dimen_target--;
target = MAKE_Object_ARRAY(dimen_target);
} /* Both are now objects or arrays of some sort of object type */
value_base = WITH_ZERO_INDIRECTION(value);
target_base = WITH_ZERO_INDIRECTION(target); if (dimen_value == dimen_target) { /* Arrays of the same dimension. Merge their base types. */
fullinfo_type result_base =
merge_fullinfo_types(context, value_base, target_base,
for_assignment); if (result_base == MAKE_FULLINFO(ITEM_Bogus, 0, 0)) /* bogus in, bogus out */ return result_base; return MAKE_FULLINFO(ITEM_Object, dimen_value,
GET_EXTRA_INFO(result_base));
} else { /* Arrays of different sizes. If the smaller dimension array's base * type is java/lang/Cloneable or java/io/Serializable, return it. * Otherwise return java/lang/Object with a dimension of the smaller
* of the two */ if (dimen_value < dimen_target) { if (value_base == context->cloneable_info ||
value_base == context ->serializable_info) { return value;
} return MAKE_Object_ARRAY(dimen_value);
} else { if (target_base == context->cloneable_info ||
target_base == context->serializable_info) { return target;
} return MAKE_Object_ARRAY(dimen_target);
}
}
} else { /* Both are non-array objects. Neither is java/lang/Object or NULL */
jclass cb_value, cb_target, cb_super_value, cb_super_target;
fullinfo_type result_info;
/* Let's get the classes corresponding to each of these. Treat
* interfaces as if they were java/lang/Object. See hack note above. */
cb_target = object_fullinfo_to_classclass(context, target); if (cb_target == 0) return MAKE_FULLINFO(ITEM_Bogus, 0, 0); if (JVM_IsInterface(env, cb_target)) return for_assignment ? target : context->object_info;
cb_value = object_fullinfo_to_classclass(context, value); if (cb_value == 0) return MAKE_FULLINFO(ITEM_Bogus, 0, 0); if (JVM_IsInterface(env, cb_value)) return context->object_info;
/* If this is for assignment of target := value, we just need to see if * cb_target is a superclass of cb_value. Save ourselves a lot of * work.
*/ if (for_assignment) {
cb_super_value = (*env)->GetSuperclass(env, cb_value); while (cb_super_value != 0) {
jclass tmp_cb; if ((*env)->IsSameObject(env, cb_super_value, cb_target)) {
(*env)->DeleteLocalRef(env, cb_super_value); return target;
}
tmp_cb = (*env)->GetSuperclass(env, cb_super_value);
(*env)->DeleteLocalRef(env, cb_super_value);
cb_super_value = tmp_cb;
}
(*env)->DeleteLocalRef(env, cb_super_value); return context->object_info;
}
/* Find out whether cb_value or cb_target is deeper in the class * tree by moving both toward the root, and seeing who gets there
* first. */
cb_super_value = (*env)->GetSuperclass(env, cb_value);
cb_super_target = (*env)->GetSuperclass(env, cb_target); while((cb_super_value != 0) &&
(cb_super_target != 0)) {
jclass tmp_cb; /* Optimization. If either hits the other when going up looking
* for a parent, then might as well return the parent immediately */ if ((*env)->IsSameObject(env, cb_super_value, cb_target)) {
(*env)->DeleteLocalRef(env, cb_super_value);
(*env)->DeleteLocalRef(env, cb_super_target); return target;
} if ((*env)->IsSameObject(env, cb_super_target, cb_value)) {
(*env)->DeleteLocalRef(env, cb_super_value);
(*env)->DeleteLocalRef(env, cb_super_target); return value;
}
tmp_cb = (*env)->GetSuperclass(env, cb_super_value);
(*env)->DeleteLocalRef(env, cb_super_value);
cb_super_value = tmp_cb;
tmp_cb = (*env)->GetSuperclass(env, cb_super_target);
(*env)->DeleteLocalRef(env, cb_super_target);
cb_super_target = tmp_cb;
}
cb_value = (*env)->NewLocalRef(env, cb_value);
cb_target = (*env)->NewLocalRef(env, cb_target); /* At most one of the following two while clauses will be executed. * Bring the deeper of cb_target and cb_value to the depth of the * shallower one.
*/ while (cb_super_value != 0) { /* cb_value is deeper */
jclass cb_tmp;
staticint signature_to_args_size(constchar *method_signature)
{ constchar *p; int args_size = 0; for (p = method_signature; *p != JVM_SIGNATURE_ENDFUNC; p++) { switch (*p) { case JVM_SIGNATURE_BOOLEAN: case JVM_SIGNATURE_BYTE: case JVM_SIGNATURE_CHAR: case JVM_SIGNATURE_SHORT: case JVM_SIGNATURE_INT: case JVM_SIGNATURE_FLOAT:
args_size += 1; break; case JVM_SIGNATURE_CLASS:
args_size += 1; while (*p != JVM_SIGNATURE_ENDCLASS) p++; break; case JVM_SIGNATURE_ARRAY:
args_size += 1; while ((*p == JVM_SIGNATURE_ARRAY)) p++; /* If an array of classes, skip over class name, too. */ if (*p == JVM_SIGNATURE_CLASS) { while (*p != JVM_SIGNATURE_ENDCLASS)
p++;
} break; case JVM_SIGNATURE_DOUBLE: case JVM_SIGNATURE_LONG:
args_size += 2; break; case JVM_SIGNATURE_FUNC: /* ignore initial (, if given */ break; default: /* Indicate an error. */ return 0;
}
} return args_size;
}
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.114Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-05-02)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.