2
|
1 |
/*
|
|
2 |
* Copyright 1994-2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
/*-
|
|
27 |
* Verify that the code within a method block doesn't exploit any
|
|
28 |
* security holes.
|
|
29 |
*/
|
|
30 |
/*
|
|
31 |
Exported function:
|
|
32 |
|
|
33 |
jboolean
|
|
34 |
VerifyClass(JNIEnv *env, jclass cb, char *message_buffer,
|
|
35 |
jint buffer_length)
|
|
36 |
jboolean
|
|
37 |
VerifyClassForMajorVersion(JNIEnv *env, jclass cb, char *message_buffer,
|
|
38 |
jint buffer_length, jint major_version)
|
|
39 |
|
|
40 |
This file now only uses the standard JNI and the following VM functions
|
|
41 |
exported in jvm.h:
|
|
42 |
|
|
43 |
JVM_FindClassFromClass
|
|
44 |
JVM_IsInterface
|
|
45 |
JVM_GetClassNameUTF
|
|
46 |
JVM_GetClassCPEntriesCount
|
|
47 |
JVM_GetClassCPTypes
|
|
48 |
JVM_GetClassFieldsCount
|
|
49 |
JVM_GetClassMethodsCount
|
|
50 |
|
|
51 |
JVM_GetFieldIxModifiers
|
|
52 |
|
|
53 |
JVM_GetMethodIxModifiers
|
|
54 |
JVM_GetMethodIxExceptionTableLength
|
|
55 |
JVM_GetMethodIxLocalsCount
|
|
56 |
JVM_GetMethodIxArgsSize
|
|
57 |
JVM_GetMethodIxMaxStack
|
|
58 |
JVM_GetMethodIxNameUTF
|
|
59 |
JVM_GetMethodIxSignatureUTF
|
|
60 |
JVM_GetMethodIxExceptionsCount
|
|
61 |
JVM_GetMethodIxExceptionIndexes
|
|
62 |
JVM_GetMethodIxByteCodeLength
|
|
63 |
JVM_GetMethodIxByteCode
|
|
64 |
JVM_GetMethodIxExceptionTableEntry
|
|
65 |
JVM_IsConstructorIx
|
|
66 |
|
|
67 |
JVM_GetCPClassNameUTF
|
|
68 |
JVM_GetCPFieldNameUTF
|
|
69 |
JVM_GetCPMethodNameUTF
|
|
70 |
JVM_GetCPFieldSignatureUTF
|
|
71 |
JVM_GetCPMethodSignatureUTF
|
|
72 |
JVM_GetCPFieldClassNameUTF
|
|
73 |
JVM_GetCPMethodClassNameUTF
|
|
74 |
JVM_GetCPFieldModifiers
|
|
75 |
JVM_GetCPMethodModifiers
|
|
76 |
|
|
77 |
JVM_ReleaseUTF
|
|
78 |
JVM_IsSameClassPackage
|
|
79 |
|
|
80 |
*/
|
|
81 |
|
|
82 |
#include <string.h>
|
|
83 |
#include <setjmp.h>
|
|
84 |
#include <assert.h>
|
|
85 |
#include <limits.h>
|
|
86 |
#include <stdlib.h>
|
|
87 |
|
|
88 |
#include "jni.h"
|
|
89 |
#include "jvm.h"
|
|
90 |
#include "typedefs.h"
|
|
91 |
|
|
92 |
#include "opcodes.h"
|
|
93 |
#include "opcodes.length"
|
|
94 |
#include "opcodes.in_out"
|
|
95 |
|
|
96 |
#define MAX_ARRAY_DIMENSIONS 255
|
|
97 |
/* align byte code */
|
|
98 |
#ifndef ALIGN_UP
|
|
99 |
#define ALIGN_UP(n,align_grain) (((n) + ((align_grain) - 1)) & ~((align_grain)-1))
|
|
100 |
#endif /* ALIGN_UP */
|
|
101 |
#define UCALIGN(n) ((unsigned char *)ALIGN_UP((uintptr_t)(n),sizeof(int)))
|
|
102 |
|
|
103 |
#ifdef DEBUG
|
|
104 |
|
|
105 |
int verify_verbose = 0;
|
|
106 |
static struct context_type *GlobalContext;
|
|
107 |
#endif
|
|
108 |
|
|
109 |
enum {
|
|
110 |
ITEM_Bogus,
|
|
111 |
ITEM_Void, /* only as a function return value */
|
|
112 |
ITEM_Integer,
|
|
113 |
ITEM_Float,
|
|
114 |
ITEM_Double,
|
|
115 |
ITEM_Double_2, /* 2nd word of double in register */
|
|
116 |
ITEM_Long,
|
|
117 |
ITEM_Long_2, /* 2nd word of long in register */
|
|
118 |
ITEM_Array,
|
|
119 |
ITEM_Object, /* Extra info field gives name. */
|
|
120 |
ITEM_NewObject, /* Like object, but uninitialized. */
|
|
121 |
ITEM_InitObject, /* "this" is init method, before call
|
|
122 |
to super() */
|
|
123 |
ITEM_ReturnAddress, /* Extra info gives instr # of start pc */
|
|
124 |
/* The following three are only used within array types.
|
|
125 |
* Normally, we use ITEM_Integer, instead. */
|
|
126 |
ITEM_Byte,
|
|
127 |
ITEM_Short,
|
|
128 |
ITEM_Char
|
|
129 |
};
|
|
130 |
|
|
131 |
|
|
132 |
#define UNKNOWN_STACK_SIZE -1
|
|
133 |
#define UNKNOWN_REGISTER_COUNT -1
|
|
134 |
#define UNKNOWN_RET_INSTRUCTION -1
|
|
135 |
|
|
136 |
#undef MAX
|
|
137 |
#undef MIN
|
|
138 |
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
|
139 |
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
|
140 |
|
|
141 |
#define BITS_PER_INT (CHAR_BIT * sizeof(int)/sizeof(char))
|
|
142 |
#define SET_BIT(flags, i) (flags[(i)/BITS_PER_INT] |= \
|
|
143 |
((unsigned)1 << ((i) % BITS_PER_INT)))
|
|
144 |
#define IS_BIT_SET(flags, i) (flags[(i)/BITS_PER_INT] & \
|
|
145 |
((unsigned)1 << ((i) % BITS_PER_INT)))
|
|
146 |
|
|
147 |
typedef unsigned int fullinfo_type;
|
|
148 |
typedef unsigned int *bitvector;
|
|
149 |
|
|
150 |
#define GET_ITEM_TYPE(thing) ((thing) & 0x1F)
|
|
151 |
#define GET_INDIRECTION(thing) (((thing) & 0xFFFF) >> 5)
|
|
152 |
#define GET_EXTRA_INFO(thing) ((thing) >> 16)
|
|
153 |
#define WITH_ZERO_INDIRECTION(thing) ((thing) & ~(0xFFE0))
|
|
154 |
#define WITH_ZERO_EXTRA_INFO(thing) ((thing) & 0xFFFF)
|
|
155 |
|
|
156 |
#define MAKE_FULLINFO(type, indirect, extra) \
|
|
157 |
((type) + ((indirect) << 5) + ((extra) << 16))
|
|
158 |
|
|
159 |
#define MAKE_Object_ARRAY(indirect) \
|
|
160 |
(context->object_info + ((indirect) << 5))
|
|
161 |
|
|
162 |
#define NULL_FULLINFO MAKE_FULLINFO(ITEM_Object, 0, 0)
|
|
163 |
|
|
164 |
/* opc_invokespecial calls to <init> need to be treated special */
|
|
165 |
#define opc_invokeinit 0x100
|
|
166 |
|
|
167 |
/* A hash mechanism used by the verifier.
|
|
168 |
* Maps class names to unique 16 bit integers.
|
|
169 |
*/
|
|
170 |
|
|
171 |
#define HASH_TABLE_SIZE 503
|
|
172 |
|
|
173 |
/* The buckets are managed as a 256 by 256 matrix. We allocate an entire
|
|
174 |
* row (256 buckets) at a time to minimize fragmentation. Rows are
|
|
175 |
* allocated on demand so that we don't waste too much space.
|
|
176 |
*/
|
|
177 |
|
|
178 |
#define MAX_HASH_ENTRIES 65536
|
|
179 |
#define HASH_ROW_SIZE 256
|
|
180 |
|
|
181 |
typedef struct hash_bucket_type {
|
|
182 |
char *name;
|
|
183 |
unsigned int hash;
|
|
184 |
jclass class;
|
|
185 |
unsigned short ID;
|
|
186 |
unsigned short next;
|
|
187 |
unsigned loadable:1; /* from context->class loader */
|
|
188 |
} hash_bucket_type;
|
|
189 |
|
|
190 |
typedef struct {
|
|
191 |
hash_bucket_type **buckets;
|
|
192 |
unsigned short *table;
|
|
193 |
int entries_used;
|
|
194 |
} hash_table_type;
|
|
195 |
|
|
196 |
#define GET_BUCKET(class_hash, ID)\
|
|
197 |
(class_hash->buckets[ID / HASH_ROW_SIZE] + ID % HASH_ROW_SIZE)
|
|
198 |
|
|
199 |
/*
|
|
200 |
* There are currently two types of resources that we need to keep
|
|
201 |
* track of (in addition to the CCalloc pool).
|
|
202 |
*/
|
|
203 |
enum {
|
|
204 |
VM_STRING_UTF, /* VM-allocated UTF strings */
|
|
205 |
VM_MALLOC_BLK /* malloc'ed blocks */
|
|
206 |
};
|
|
207 |
|
|
208 |
#define LDC_CLASS_MAJOR_VERSION 49
|
|
209 |
|
|
210 |
#define ALLOC_STACK_SIZE 16 /* big enough */
|
|
211 |
|
|
212 |
typedef struct alloc_stack_type {
|
|
213 |
void *ptr;
|
|
214 |
int kind;
|
|
215 |
struct alloc_stack_type *next;
|
|
216 |
} alloc_stack_type;
|
|
217 |
|
|
218 |
/* The context type encapsulates the current invocation of the byte
|
|
219 |
* code verifier.
|
|
220 |
*/
|
|
221 |
struct context_type {
|
|
222 |
|
|
223 |
JNIEnv *env; /* current JNIEnv */
|
|
224 |
|
|
225 |
/* buffers etc. */
|
|
226 |
char *message;
|
|
227 |
jint message_buf_len;
|
|
228 |
jboolean err_code;
|
|
229 |
|
|
230 |
alloc_stack_type *allocated_memory; /* all memory blocks that we have not
|
|
231 |
had a chance to free */
|
|
232 |
/* Store up to ALLOC_STACK_SIZE number of handles to allocated memory
|
|
233 |
blocks here, to save mallocs. */
|
|
234 |
alloc_stack_type alloc_stack[ALLOC_STACK_SIZE];
|
|
235 |
int alloc_stack_top;
|
|
236 |
|
|
237 |
/* these fields are per class */
|
|
238 |
jclass class; /* current class */
|
|
239 |
jint major_version;
|
|
240 |
jint nconstants;
|
|
241 |
unsigned char *constant_types;
|
|
242 |
hash_table_type class_hash;
|
|
243 |
|
|
244 |
fullinfo_type object_info; /* fullinfo for java/lang/Object */
|
|
245 |
fullinfo_type string_info; /* fullinfo for java/lang/String */
|
|
246 |
fullinfo_type throwable_info; /* fullinfo for java/lang/Throwable */
|
|
247 |
fullinfo_type cloneable_info; /* fullinfo for java/lang/Cloneable */
|
|
248 |
fullinfo_type serializable_info; /* fullinfo for java/io/Serializable */
|
|
249 |
|
|
250 |
fullinfo_type currentclass_info; /* fullinfo for context->class */
|
|
251 |
fullinfo_type superclass_info; /* fullinfo for superclass */
|
|
252 |
|
|
253 |
/* these fields are per method */
|
|
254 |
int method_index; /* current method */
|
|
255 |
unsigned short *exceptions; /* exceptions */
|
|
256 |
unsigned char *code; /* current code object */
|
|
257 |
jint code_length;
|
|
258 |
int *code_data; /* offset to instruction number */
|
|
259 |
struct instruction_data_type *instruction_data; /* info about each */
|
|
260 |
struct handler_info_type *handler_info;
|
|
261 |
fullinfo_type *superclasses; /* null terminated superclasses */
|
|
262 |
int instruction_count; /* number of instructions */
|
|
263 |
fullinfo_type return_type; /* function return type */
|
|
264 |
fullinfo_type swap_table[4]; /* used for passing information */
|
|
265 |
int bitmask_size; /* words needed to hold bitmap of arguments */
|
|
266 |
|
|
267 |
/* these fields are per field */
|
|
268 |
int field_index;
|
|
269 |
|
|
270 |
/* Used by the space allocator */
|
|
271 |
struct CCpool *CCroot, *CCcurrent;
|
|
272 |
char *CCfree_ptr;
|
|
273 |
int CCfree_size;
|
|
274 |
|
|
275 |
/* Jump here on any error. */
|
|
276 |
jmp_buf jump_buffer;
|
|
277 |
|
|
278 |
#ifdef DEBUG
|
|
279 |
/* keep track of how many global refs are allocated. */
|
|
280 |
int n_globalrefs;
|
|
281 |
#endif
|
|
282 |
};
|
|
283 |
|
|
284 |
struct stack_info_type {
|
|
285 |
struct stack_item_type *stack;
|
|
286 |
int stack_size;
|
|
287 |
};
|
|
288 |
|
|
289 |
struct register_info_type {
|
|
290 |
int register_count; /* number of registers used */
|
|
291 |
fullinfo_type *registers;
|
|
292 |
int mask_count; /* number of masks in the following */
|
|
293 |
struct mask_type *masks;
|
|
294 |
};
|
|
295 |
|
|
296 |
struct mask_type {
|
|
297 |
int entry;
|
|
298 |
int *modifies;
|
|
299 |
};
|
|
300 |
|
|
301 |
typedef unsigned short flag_type;
|
|
302 |
|
|
303 |
struct instruction_data_type {
|
|
304 |
opcode_type opcode; /* may turn into "canonical" opcode */
|
|
305 |
unsigned changed:1; /* has it changed */
|
|
306 |
unsigned protected:1; /* must accessor be a subclass of "this" */
|
|
307 |
union {
|
|
308 |
int i; /* operand to the opcode */
|
|
309 |
int *ip;
|
|
310 |
fullinfo_type fi;
|
|
311 |
} operand, operand2;
|
|
312 |
fullinfo_type p;
|
|
313 |
struct stack_info_type stack_info;
|
|
314 |
struct register_info_type register_info;
|
|
315 |
#define FLAG_REACHED 0x01 /* instruction reached */
|
|
316 |
#define FLAG_NEED_CONSTRUCTOR 0x02 /* must call this.<init> or super.<init> */
|
|
317 |
#define FLAG_NO_RETURN 0x04 /* must throw out of method */
|
|
318 |
flag_type or_flags; /* true for at least one path to this inst */
|
|
319 |
#define FLAG_CONSTRUCTED 0x01 /* this.<init> or super.<init> called */
|
|
320 |
flag_type and_flags; /* true for all paths to this instruction */
|
|
321 |
};
|
|
322 |
|
|
323 |
struct handler_info_type {
|
|
324 |
int start, end, handler;
|
|
325 |
struct stack_info_type stack_info;
|
|
326 |
};
|
|
327 |
|
|
328 |
struct stack_item_type {
|
|
329 |
fullinfo_type item;
|
|
330 |
struct stack_item_type *next;
|
|
331 |
};
|
|
332 |
|
|
333 |
typedef struct context_type context_type;
|
|
334 |
typedef struct instruction_data_type instruction_data_type;
|
|
335 |
typedef struct stack_item_type stack_item_type;
|
|
336 |
typedef struct register_info_type register_info_type;
|
|
337 |
typedef struct stack_info_type stack_info_type;
|
|
338 |
typedef struct mask_type mask_type;
|
|
339 |
|
|
340 |
static void read_all_code(context_type *context, jclass cb, int num_methods,
|
|
341 |
int** code_lengths, unsigned char*** code);
|
|
342 |
static void verify_method(context_type *context, jclass cb, int index,
|
|
343 |
int code_length, unsigned char* code);
|
|
344 |
static void free_all_code(int num_methods, int* lengths, unsigned char** code);
|
|
345 |
static void verify_field(context_type *context, jclass cb, int index);
|
|
346 |
|
|
347 |
static void verify_opcode_operands (context_type *, unsigned int inumber, int offset);
|
|
348 |
static void set_protected(context_type *, unsigned int inumber, int key, opcode_type);
|
|
349 |
static jboolean is_superclass(context_type *, fullinfo_type);
|
|
350 |
|
|
351 |
static void initialize_exception_table(context_type *);
|
|
352 |
static int instruction_length(unsigned char *iptr, unsigned char *end);
|
|
353 |
static jboolean isLegalTarget(context_type *, int offset);
|
|
354 |
static void verify_constant_pool_type(context_type *, int, unsigned);
|
|
355 |
|
|
356 |
static void initialize_dataflow(context_type *);
|
|
357 |
static void run_dataflow(context_type *context);
|
|
358 |
static void check_register_values(context_type *context, unsigned int inumber);
|
|
359 |
static void check_flags(context_type *context, unsigned int inumber);
|
|
360 |
static void pop_stack(context_type *, unsigned int inumber, stack_info_type *);
|
|
361 |
static void update_registers(context_type *, unsigned int inumber, register_info_type *);
|
|
362 |
static void update_flags(context_type *, unsigned int inumber,
|
|
363 |
flag_type *new_and_flags, flag_type *new_or_flags);
|
|
364 |
static void push_stack(context_type *, unsigned int inumber, stack_info_type *stack);
|
|
365 |
|
|
366 |
static void merge_into_successors(context_type *, unsigned int inumber,
|
|
367 |
register_info_type *register_info,
|
|
368 |
stack_info_type *stack_info,
|
|
369 |
flag_type and_flags, flag_type or_flags);
|
|
370 |
static void merge_into_one_successor(context_type *context,
|
|
371 |
unsigned int from_inumber,
|
|
372 |
unsigned int inumber,
|
|
373 |
register_info_type *register_info,
|
|
374 |
stack_info_type *stack_info,
|
|
375 |
flag_type and_flags, flag_type or_flags,
|
|
376 |
jboolean isException);
|
|
377 |
static void merge_stack(context_type *, unsigned int inumber,
|
|
378 |
unsigned int to_inumber, stack_info_type *);
|
|
379 |
static void merge_registers(context_type *, unsigned int inumber,
|
|
380 |
unsigned int to_inumber,
|
|
381 |
register_info_type *);
|
|
382 |
static void merge_flags(context_type *context, unsigned int from_inumber,
|
|
383 |
unsigned int to_inumber,
|
|
384 |
flag_type new_and_flags, flag_type new_or_flags);
|
|
385 |
|
|
386 |
static stack_item_type *copy_stack(context_type *, stack_item_type *);
|
|
387 |
static mask_type *copy_masks(context_type *, mask_type *masks, int mask_count);
|
|
388 |
static mask_type *add_to_masks(context_type *, mask_type *, int , int);
|
|
389 |
|
|
390 |
static fullinfo_type decrement_indirection(fullinfo_type);
|
|
391 |
|
|
392 |
static fullinfo_type merge_fullinfo_types(context_type *context,
|
|
393 |
fullinfo_type a,
|
|
394 |
fullinfo_type b,
|
|
395 |
jboolean assignment);
|
|
396 |
static jboolean isAssignableTo(context_type *,
|
|
397 |
fullinfo_type a,
|
|
398 |
fullinfo_type b);
|
|
399 |
|
|
400 |
static jclass object_fullinfo_to_classclass(context_type *, fullinfo_type);
|
|
401 |
|
|
402 |
|
|
403 |
#define NEW(type, count) \
|
|
404 |
((type *)CCalloc(context, (count)*(sizeof(type)), JNI_FALSE))
|
|
405 |
#define ZNEW(type, count) \
|
|
406 |
((type *)CCalloc(context, (count)*(sizeof(type)), JNI_TRUE))
|
|
407 |
|
|
408 |
static void CCinit(context_type *context);
|
|
409 |
static void CCreinit(context_type *context);
|
|
410 |
static void CCdestroy(context_type *context);
|
|
411 |
static void *CCalloc(context_type *context, int size, jboolean zero);
|
|
412 |
|
|
413 |
static fullinfo_type cp_index_to_class_fullinfo(context_type *, int, int);
|
|
414 |
|
|
415 |
static char signature_to_fieldtype(context_type *context,
|
|
416 |
const char **signature_p, fullinfo_type *info);
|
|
417 |
|
|
418 |
static void CCerror (context_type *, char *format, ...);
|
|
419 |
static void CFerror (context_type *, char *format, ...);
|
|
420 |
static void CCout_of_memory (context_type *);
|
|
421 |
|
|
422 |
/* Because we can longjmp any time, we need to be very careful about
|
|
423 |
* remembering what needs to be freed. */
|
|
424 |
|
|
425 |
static void check_and_push(context_type *context, const void *ptr, int kind);
|
|
426 |
static void pop_and_free(context_type *context);
|
|
427 |
|
|
428 |
static int signature_to_args_size(const char *method_signature);
|
|
429 |
|
|
430 |
#ifdef DEBUG
|
|
431 |
static void print_stack (context_type *, stack_info_type *stack_info);
|
|
432 |
static void print_registers(context_type *, register_info_type *register_info);
|
|
433 |
static void print_flags(context_type *, flag_type, flag_type);
|
|
434 |
static void print_formatted_fieldname(context_type *context, int index);
|
|
435 |
static void print_formatted_methodname(context_type *context, int index);
|
|
436 |
#endif
|
|
437 |
|
|
438 |
void initialize_class_hash(context_type *context)
|
|
439 |
{
|
|
440 |
hash_table_type *class_hash = &(context->class_hash);
|
|
441 |
class_hash->buckets = (hash_bucket_type **)
|
|
442 |
calloc(MAX_HASH_ENTRIES / HASH_ROW_SIZE, sizeof(hash_bucket_type *));
|
|
443 |
class_hash->table = (unsigned short *)
|
|
444 |
calloc(HASH_TABLE_SIZE, sizeof(unsigned short));
|
|
445 |
if (class_hash->buckets == 0 ||
|
|
446 |
class_hash->table == 0)
|
|
447 |
CCout_of_memory(context);
|
|
448 |
class_hash->entries_used = 0;
|
|
449 |
}
|
|
450 |
|
|
451 |
static void finalize_class_hash(context_type *context)
|
|
452 |
{
|
|
453 |
hash_table_type *class_hash = &(context->class_hash);
|
|
454 |
JNIEnv *env = context->env;
|
|
455 |
int i;
|
|
456 |
/* 4296677: bucket index starts from 1. */
|
|
457 |
for (i=1;i<=class_hash->entries_used;i++) {
|
|
458 |
hash_bucket_type *bucket = GET_BUCKET(class_hash, i);
|
|
459 |
assert(bucket != NULL);
|
|
460 |
free(bucket->name);
|
|
461 |
if (bucket->class) {
|
|
462 |
(*env)->DeleteGlobalRef(env, bucket->class);
|
|
463 |
#ifdef DEBUG
|
|
464 |
context->n_globalrefs--;
|
|
465 |
#endif
|
|
466 |
}
|
|
467 |
}
|
|
468 |
if (class_hash->buckets) {
|
|
469 |
for (i=0;i<MAX_HASH_ENTRIES / HASH_ROW_SIZE; i++) {
|
|
470 |
if (class_hash->buckets[i] == 0)
|
|
471 |
break;
|
|
472 |
free(class_hash->buckets[i]);
|
|
473 |
}
|
|
474 |
}
|
|
475 |
free(class_hash->buckets);
|
|
476 |
free(class_hash->table);
|
|
477 |
}
|
|
478 |
|
|
479 |
static hash_bucket_type *
|
|
480 |
new_bucket(context_type *context, unsigned short *pID)
|
|
481 |
{
|
|
482 |
hash_table_type *class_hash = &(context->class_hash);
|
|
483 |
int i = *pID = class_hash->entries_used + 1;
|
|
484 |
int row = i / HASH_ROW_SIZE;
|
|
485 |
if (i >= MAX_HASH_ENTRIES)
|
|
486 |
CCerror(context, "Exceeded verifier's limit of 65535 referred classes");
|
|
487 |
if (class_hash->buckets[row] == 0) {
|
|
488 |
class_hash->buckets[row] = (hash_bucket_type*)
|
|
489 |
calloc(HASH_ROW_SIZE, sizeof(hash_bucket_type));
|
|
490 |
if (class_hash->buckets[row] == 0)
|
|
491 |
CCout_of_memory(context);
|
|
492 |
}
|
|
493 |
class_hash->entries_used++; /* only increment when we are sure there
|
|
494 |
is no overflow. */
|
|
495 |
return GET_BUCKET(class_hash, i);
|
|
496 |
}
|
|
497 |
|
|
498 |
static unsigned int
|
|
499 |
class_hash_fun(const char *s)
|
|
500 |
{
|
|
501 |
int i;
|
|
502 |
unsigned raw_hash;
|
|
503 |
for (raw_hash = 0; (i = *s) != '\0'; ++s)
|
|
504 |
raw_hash = raw_hash * 37 + i;
|
|
505 |
return raw_hash;
|
|
506 |
}
|
|
507 |
|
|
508 |
/*
|
|
509 |
* Find a class using the defining loader of the current class
|
|
510 |
* and return a local reference to it.
|
|
511 |
*/
|
|
512 |
static jclass load_class_local(context_type *context,const char *classname)
|
|
513 |
{
|
|
514 |
jclass cb = JVM_FindClassFromClass(context->env, classname,
|
|
515 |
JNI_FALSE, context->class);
|
|
516 |
if (cb == 0)
|
|
517 |
CCerror(context, "Cannot find class %s", classname);
|
|
518 |
return cb;
|
|
519 |
}
|
|
520 |
|
|
521 |
/*
|
|
522 |
* Find a class using the defining loader of the current class
|
|
523 |
* and return a global reference to it.
|
|
524 |
*/
|
|
525 |
static jclass load_class_global(context_type *context, const char *classname)
|
|
526 |
{
|
|
527 |
JNIEnv *env = context->env;
|
|
528 |
jclass local, global;
|
|
529 |
|
|
530 |
local = load_class_local(context, classname);
|
|
531 |
global = (*env)->NewGlobalRef(env, local);
|
|
532 |
if (global == 0)
|
|
533 |
CCout_of_memory(context);
|
|
534 |
#ifdef DEBUG
|
|
535 |
context->n_globalrefs++;
|
|
536 |
#endif
|
|
537 |
(*env)->DeleteLocalRef(env, local);
|
|
538 |
return global;
|
|
539 |
}
|
|
540 |
|
|
541 |
/*
|
|
542 |
* Return a unique ID given a local class reference. The loadable
|
|
543 |
* flag is true if the defining class loader of context->class
|
|
544 |
* is known to be capable of loading the class.
|
|
545 |
*/
|
|
546 |
static unsigned short
|
|
547 |
class_to_ID(context_type *context, jclass cb, jboolean loadable)
|
|
548 |
{
|
|
549 |
JNIEnv *env = context->env;
|
|
550 |
hash_table_type *class_hash = &(context->class_hash);
|
|
551 |
unsigned int hash;
|
|
552 |
hash_bucket_type *bucket;
|
|
553 |
unsigned short *pID;
|
|
554 |
const char *name = JVM_GetClassNameUTF(env, cb);
|
|
555 |
|
|
556 |
check_and_push(context, name, VM_STRING_UTF);
|
|
557 |
hash = class_hash_fun(name);
|
|
558 |
pID = &(class_hash->table[hash % HASH_TABLE_SIZE]);
|
|
559 |
while (*pID) {
|
|
560 |
bucket = GET_BUCKET(class_hash, *pID);
|
|
561 |
if (bucket->hash == hash && strcmp(name, bucket->name) == 0) {
|
|
562 |
/*
|
|
563 |
* There is an unresolved entry with our name
|
|
564 |
* so we're forced to load it in case it matches us.
|
|
565 |
*/
|
|
566 |
if (bucket->class == 0) {
|
|
567 |
assert(bucket->loadable == JNI_TRUE);
|
|
568 |
bucket->class = load_class_global(context, name);
|
|
569 |
}
|
|
570 |
|
|
571 |
/*
|
|
572 |
* It's already in the table. Update the loadable
|
|
573 |
* state if it's known and then we're done.
|
|
574 |
*/
|
|
575 |
if ((*env)->IsSameObject(env, cb, bucket->class)) {
|
|
576 |
if (loadable && !bucket->loadable)
|
|
577 |
bucket->loadable = JNI_TRUE;
|
|
578 |
goto done;
|
|
579 |
}
|
|
580 |
}
|
|
581 |
pID = &bucket->next;
|
|
582 |
}
|
|
583 |
bucket = new_bucket(context, pID);
|
|
584 |
bucket->next = 0;
|
|
585 |
bucket->hash = hash;
|
|
586 |
bucket->name = malloc(strlen(name) + 1);
|
|
587 |
if (bucket->name == 0)
|
|
588 |
CCout_of_memory(context);
|
|
589 |
strcpy(bucket->name, name);
|
|
590 |
bucket->loadable = loadable;
|
|
591 |
bucket->class = (*env)->NewGlobalRef(env, cb);
|
|
592 |
if (bucket->class == 0)
|
|
593 |
CCout_of_memory(context);
|
|
594 |
#ifdef DEBUG
|
|
595 |
context->n_globalrefs++;
|
|
596 |
#endif
|
|
597 |
|
|
598 |
done:
|
|
599 |
pop_and_free(context);
|
|
600 |
return *pID;
|
|
601 |
}
|
|
602 |
|
|
603 |
/*
|
|
604 |
* Return a unique ID given a class name from the constant pool.
|
|
605 |
* All classes are lazily loaded from the defining loader of
|
|
606 |
* context->class.
|
|
607 |
*/
|
|
608 |
static unsigned short
|
|
609 |
class_name_to_ID(context_type *context, const char *name)
|
|
610 |
{
|
|
611 |
hash_table_type *class_hash = &(context->class_hash);
|
|
612 |
unsigned int hash = class_hash_fun(name);
|
|
613 |
hash_bucket_type *bucket;
|
|
614 |
unsigned short *pID;
|
|
615 |
jboolean force_load = JNI_FALSE;
|
|
616 |
|
|
617 |
pID = &(class_hash->table[hash % HASH_TABLE_SIZE]);
|
|
618 |
while (*pID) {
|
|
619 |
bucket = GET_BUCKET(class_hash, *pID);
|
|
620 |
if (bucket->hash == hash && strcmp(name, bucket->name) == 0) {
|
|
621 |
if (bucket->loadable)
|
|
622 |
goto done;
|
|
623 |
force_load = JNI_TRUE;
|
|
624 |
}
|
|
625 |
pID = &bucket->next;
|
|
626 |
}
|
|
627 |
|
|
628 |
if (force_load) {
|
|
629 |
/*
|
|
630 |
* We found at least one matching named entry for a class that
|
|
631 |
* was not known to be loadable through the defining class loader
|
|
632 |
* of context->class. We must load our named class and update
|
|
633 |
* the hash table in case one these entries matches our class.
|
|
634 |
*/
|
|
635 |
JNIEnv *env = context->env;
|
|
636 |
jclass cb = load_class_local(context, name);
|
|
637 |
unsigned short id = class_to_ID(context, cb, JNI_TRUE);
|
|
638 |
(*env)->DeleteLocalRef(env, cb);
|
|
639 |
return id;
|
|
640 |
}
|
|
641 |
|
|
642 |
bucket = new_bucket(context, pID);
|
|
643 |
bucket->next = 0;
|
|
644 |
bucket->class = 0;
|
|
645 |
bucket->loadable = JNI_TRUE; /* name-only IDs are implicitly loadable */
|
|
646 |
bucket->hash = hash;
|
|
647 |
bucket->name = malloc(strlen(name) + 1);
|
|
648 |
if (bucket->name == 0)
|
|
649 |
CCout_of_memory(context);
|
|
650 |
strcpy(bucket->name, name);
|
|
651 |
|
|
652 |
done:
|
|
653 |
return *pID;
|
|
654 |
}
|
|
655 |
|
|
656 |
static const char *
|
|
657 |
ID_to_class_name(context_type *context, unsigned short ID)
|
|
658 |
{
|
|
659 |
hash_table_type *class_hash = &(context->class_hash);
|
|
660 |
hash_bucket_type *bucket = GET_BUCKET(class_hash, ID);
|
|
661 |
return bucket->name;
|
|
662 |
}
|
|
663 |
|
|
664 |
static jclass
|
|
665 |
ID_to_class(context_type *context, unsigned short ID)
|
|
666 |
{
|
|
667 |
hash_table_type *class_hash = &(context->class_hash);
|
|
668 |
hash_bucket_type *bucket = GET_BUCKET(class_hash, ID);
|
|
669 |
if (bucket->class == 0) {
|
|
670 |
assert(bucket->loadable == JNI_TRUE);
|
|
671 |
bucket->class = load_class_global(context, bucket->name);
|
|
672 |
}
|
|
673 |
return bucket->class;
|
|
674 |
}
|
|
675 |
|
|
676 |
static fullinfo_type
|
|
677 |
make_loadable_class_info(context_type *context, jclass cb)
|
|
678 |
{
|
|
679 |
return MAKE_FULLINFO(ITEM_Object, 0,
|
|
680 |
class_to_ID(context, cb, JNI_TRUE));
|
|
681 |
}
|
|
682 |
|
|
683 |
static fullinfo_type
|
|
684 |
make_class_info(context_type *context, jclass cb)
|
|
685 |
{
|
|
686 |
return MAKE_FULLINFO(ITEM_Object, 0,
|
|
687 |
class_to_ID(context, cb, JNI_FALSE));
|
|
688 |
}
|
|
689 |
|
|
690 |
static fullinfo_type
|
|
691 |
make_class_info_from_name(context_type *context, const char *name)
|
|
692 |
{
|
|
693 |
return MAKE_FULLINFO(ITEM_Object, 0,
|
|
694 |
class_name_to_ID(context, name));
|
|
695 |
}
|
|
696 |
|
|
697 |
/* RETURNS
|
|
698 |
* 1: on success chosen to be consistent with previous VerifyClass
|
|
699 |
* 0: verify error
|
|
700 |
* 2: out of memory
|
|
701 |
* 3: class format error
|
|
702 |
*
|
|
703 |
* Called by verify_class. Verify the code of each of the methods
|
|
704 |
* in a class. Note that this function apparently can't be JNICALL,
|
|
705 |
* because if it is the dynamic linker doesn't appear to be able to
|
|
706 |
* find it on Win32.
|
|
707 |
*/
|
|
708 |
|
|
709 |
#define CC_OK 1
|
|
710 |
#define CC_VerifyError 0
|
|
711 |
#define CC_OutOfMemory 2
|
|
712 |
#define CC_ClassFormatError 3
|
|
713 |
|
|
714 |
JNIEXPORT jboolean
|
|
715 |
VerifyClassForMajorVersion(JNIEnv *env, jclass cb, char *buffer, jint len,
|
|
716 |
jint major_version)
|
|
717 |
{
|
|
718 |
context_type context_structure;
|
|
719 |
context_type *context = &context_structure;
|
|
720 |
jboolean result = CC_OK;
|
|
721 |
int i;
|
|
722 |
int num_methods;
|
|
723 |
int* code_lengths;
|
|
724 |
unsigned char** code;
|
|
725 |
|
|
726 |
#ifdef DEBUG
|
|
727 |
GlobalContext = context;
|
|
728 |
#endif
|
|
729 |
|
|
730 |
memset(context, 0, sizeof(context_type));
|
|
731 |
context->message = buffer;
|
|
732 |
context->message_buf_len = len;
|
|
733 |
|
|
734 |
context->env = env;
|
|
735 |
context->class = cb;
|
|
736 |
|
|
737 |
/* Set invalid method/field index of the context, in case anyone
|
|
738 |
calls CCerror */
|
|
739 |
context->method_index = -1;
|
|
740 |
context->field_index = -1;
|
|
741 |
|
|
742 |
/* Don't call CCerror or anything that can call it above the setjmp! */
|
|
743 |
if (!setjmp(context->jump_buffer)) {
|
|
744 |
jclass super;
|
|
745 |
|
|
746 |
CCinit(context); /* initialize heap; may throw */
|
|
747 |
|
|
748 |
initialize_class_hash(context);
|
|
749 |
|
|
750 |
context->major_version = major_version;
|
|
751 |
context->nconstants = JVM_GetClassCPEntriesCount(env, cb);
|
|
752 |
context->constant_types = (unsigned char *)
|
|
753 |
malloc(sizeof(unsigned char) * context->nconstants + 1);
|
|
754 |
|
|
755 |
if (context->constant_types == 0)
|
|
756 |
CCout_of_memory(context);
|
|
757 |
|
|
758 |
JVM_GetClassCPTypes(env, cb, context->constant_types);
|
|
759 |
|
|
760 |
if (context->constant_types == 0)
|
|
761 |
CCout_of_memory(context);
|
|
762 |
|
|
763 |
context->object_info =
|
|
764 |
make_class_info_from_name(context, "java/lang/Object");
|
|
765 |
context->string_info =
|
|
766 |
make_class_info_from_name(context, "java/lang/String");
|
|
767 |
context->throwable_info =
|
|
768 |
make_class_info_from_name(context, "java/lang/Throwable");
|
|
769 |
context->cloneable_info =
|
|
770 |
make_class_info_from_name(context, "java/lang/Cloneable");
|
|
771 |
context->serializable_info =
|
|
772 |
make_class_info_from_name(context, "java/io/Serializable");
|
|
773 |
|
|
774 |
context->currentclass_info = make_loadable_class_info(context, cb);
|
|
775 |
|
|
776 |
super = (*env)->GetSuperclass(env, cb);
|
|
777 |
|
|
778 |
if (super != 0) {
|
|
779 |
fullinfo_type *gptr;
|
|
780 |
int i = 0;
|
|
781 |
|
|
782 |
context->superclass_info = make_loadable_class_info(context, super);
|
|
783 |
|
|
784 |
while(super != 0) {
|
|
785 |
jclass tmp_cb = (*env)->GetSuperclass(env, super);
|
|
786 |
(*env)->DeleteLocalRef(env, super);
|
|
787 |
super = tmp_cb;
|
|
788 |
i++;
|
|
789 |
}
|
|
790 |
(*env)->DeleteLocalRef(env, super);
|
|
791 |
super = 0;
|
|
792 |
|
|
793 |
/* Can't go on context heap since it survives more than
|
|
794 |
one method */
|
|
795 |
context->superclasses = gptr =
|
|
796 |
malloc(sizeof(fullinfo_type)*(i + 1));
|
|
797 |
if (gptr == 0) {
|
|
798 |
CCout_of_memory(context);
|
|
799 |
}
|
|
800 |
|
|
801 |
super = (*env)->GetSuperclass(env, context->class);
|
|
802 |
while(super != 0) {
|
|
803 |
jclass tmp_cb;
|
|
804 |
*gptr++ = make_class_info(context, super);
|
|
805 |
tmp_cb = (*env)->GetSuperclass(env, super);
|
|
806 |
(*env)->DeleteLocalRef(env, super);
|
|
807 |
super = tmp_cb;
|
|
808 |
}
|
|
809 |
*gptr = 0;
|
|
810 |
} else {
|
|
811 |
context->superclass_info = 0;
|
|
812 |
}
|
|
813 |
|
|
814 |
(*env)->DeleteLocalRef(env, super);
|
|
815 |
|
|
816 |
/* Look at each method */
|
|
817 |
for (i = JVM_GetClassFieldsCount(env, cb); --i >= 0;)
|
|
818 |
verify_field(context, cb, i);
|
|
819 |
num_methods = JVM_GetClassMethodsCount(env, cb);
|
|
820 |
read_all_code(context, cb, num_methods, &code_lengths, &code);
|
|
821 |
for (i = num_methods - 1; i >= 0; --i)
|
|
822 |
verify_method(context, cb, i, code_lengths[i], code[i]);
|
|
823 |
free_all_code(num_methods, code_lengths, code);
|
|
824 |
result = CC_OK;
|
|
825 |
} else {
|
|
826 |
result = context->err_code;
|
|
827 |
}
|
|
828 |
|
|
829 |
/* Cleanup */
|
|
830 |
finalize_class_hash(context);
|
|
831 |
|
|
832 |
while(context->allocated_memory)
|
|
833 |
pop_and_free(context);
|
|
834 |
|
|
835 |
#ifdef DEBUG
|
|
836 |
GlobalContext = 0;
|
|
837 |
#endif
|
|
838 |
|
|
839 |
if (context->exceptions)
|
|
840 |
free(context->exceptions);
|
|
841 |
|
|
842 |
if (context->code)
|
|
843 |
free(context->code);
|
|
844 |
|
|
845 |
if (context->constant_types)
|
|
846 |
free(context->constant_types);
|
|
847 |
|
|
848 |
if (context->superclasses)
|
|
849 |
free(context->superclasses);
|
|
850 |
|
|
851 |
#ifdef DEBUG
|
|
852 |
/* Make sure all global refs created in the verifier are freed */
|
|
853 |
assert(context->n_globalrefs == 0);
|
|
854 |
#endif
|
|
855 |
|
|
856 |
CCdestroy(context); /* destroy heap */
|
|
857 |
return result;
|
|
858 |
}
|
|
859 |
|
|
860 |
#define OLD_FORMAT_MAX_MAJOR_VERSION 48
|
|
861 |
|
|
862 |
JNIEXPORT jboolean
|
|
863 |
VerifyClass(JNIEnv *env, jclass cb, char *buffer, jint len)
|
|
864 |
{
|
|
865 |
static int warned = 0;
|
|
866 |
if (!warned) {
|
|
867 |
jio_fprintf(stdout, "Warning! An old version of jvm is used. This is not supported.\n");
|
|
868 |
warned = 1;
|
|
869 |
}
|
|
870 |
return VerifyClassForMajorVersion(env, cb, buffer, len,
|
|
871 |
OLD_FORMAT_MAX_MAJOR_VERSION);
|
|
872 |
}
|
|
873 |
|
|
874 |
static void
|
|
875 |
verify_field(context_type *context, jclass cb, int field_index)
|
|
876 |
{
|
|
877 |
JNIEnv *env = context->env;
|
|
878 |
int access_bits = JVM_GetFieldIxModifiers(env, cb, field_index);
|
|
879 |
context->field_index = field_index;
|
|
880 |
|
|
881 |
if ( ((access_bits & JVM_ACC_PUBLIC) != 0) &&
|
|
882 |
((access_bits & (JVM_ACC_PRIVATE | JVM_ACC_PROTECTED)) != 0)) {
|
|
883 |
CCerror(context, "Inconsistent access bits.");
|
|
884 |
}
|
|
885 |
context->field_index = -1;
|
|
886 |
}
|
|
887 |
|
|
888 |
|
|
889 |
/**
|
|
890 |
* We read all of the class's methods' code because it is possible that
|
|
891 |
* the verification of one method could resulting in linking further
|
|
892 |
* down the stack (due to class loading), which could end up rewriting
|
|
893 |
* some of the bytecode of methods we haven't verified yet. Since we
|
|
894 |
* don't want to see the rewritten bytecode, cache all the code and
|
|
895 |
* operate only on that.
|
|
896 |
*/
|
|
897 |
static void
|
|
898 |
read_all_code(context_type* context, jclass cb, int num_methods,
|
|
899 |
int** lengths_addr, unsigned char*** code_addr)
|
|
900 |
{
|
|
901 |
int* lengths = malloc(sizeof(int) * num_methods);
|
|
902 |
unsigned char** code = malloc(sizeof(unsigned char*) * num_methods);
|
|
903 |
|
|
904 |
*(lengths_addr) = lengths;
|
|
905 |
*(code_addr) = code;
|
|
906 |
|
|
907 |
if (lengths == 0 || code == 0) {
|
|
908 |
CCout_of_memory(context);
|
|
909 |
} else {
|
|
910 |
int i;
|
|
911 |
for (i = 0; i < num_methods; ++i) {
|
|
912 |
lengths[i] = JVM_GetMethodIxByteCodeLength(context->env, cb, i);
|
|
913 |
if (lengths[i] != 0) {
|
|
914 |
code[i] = malloc(sizeof(unsigned char) * (lengths[i] + 1));
|
|
915 |
if (code[i] == NULL) {
|
|
916 |
CCout_of_memory(context);
|
|
917 |
} else {
|
|
918 |
JVM_GetMethodIxByteCode(context->env, cb, i, code[i]);
|
|
919 |
}
|
|
920 |
} else {
|
|
921 |
code[i] = NULL;
|
|
922 |
}
|
|
923 |
}
|
|
924 |
}
|
|
925 |
}
|
|
926 |
|
|
927 |
static void
|
|
928 |
free_all_code(int num_methods, int* lengths, unsigned char** code)
|
|
929 |
{
|
|
930 |
int i;
|
|
931 |
for (i = 0; i < num_methods; ++i) {
|
|
932 |
free(code[i]);
|
|
933 |
}
|
|
934 |
free(lengths);
|
|
935 |
free(code);
|
|
936 |
}
|
|
937 |
|
|
938 |
/* Verify the code of one method */
|
|
939 |
static void
|
|
940 |
verify_method(context_type *context, jclass cb, int method_index,
|
|
941 |
int code_length, unsigned char* code)
|
|
942 |
{
|
|
943 |
JNIEnv *env = context->env;
|
|
944 |
int access_bits = JVM_GetMethodIxModifiers(env, cb, method_index);
|
|
945 |
int *code_data;
|
|
946 |
instruction_data_type *idata = 0;
|
|
947 |
int instruction_count;
|
|
948 |
int i, offset;
|
|
949 |
unsigned int inumber;
|
|
950 |
jint nexceptions;
|
|
951 |
|
|
952 |
if ((access_bits & (JVM_ACC_NATIVE | JVM_ACC_ABSTRACT)) != 0) {
|
|
953 |
/* not much to do for abstract and native methods */
|
|
954 |
return;
|
|
955 |
}
|
|
956 |
|
|
957 |
context->code_length = code_length;
|
|
958 |
context->code = code;
|
|
959 |
|
|
960 |
/* CCerror can give method-specific info once this is set */
|
|
961 |
context->method_index = method_index;
|
|
962 |
|
|
963 |
CCreinit(context); /* initial heap */
|
|
964 |
code_data = NEW(int, code_length);
|
|
965 |
|
|
966 |
#ifdef DEBUG
|
|
967 |
if (verify_verbose) {
|
|
968 |
const char *classname = JVM_GetClassNameUTF(env, cb);
|
|
969 |
const char *methodname =
|
|
970 |
JVM_GetMethodIxNameUTF(env, cb, method_index);
|
|
971 |
const char *signature =
|
|
972 |
JVM_GetMethodIxSignatureUTF(env, cb, method_index);
|
|
973 |
jio_fprintf(stdout, "Looking at %s.%s%s\n",
|
|
974 |
(classname ? classname : ""),
|
|
975 |
(methodname ? methodname : ""),
|
|
976 |
(signature ? signature : ""));
|
|
977 |
JVM_ReleaseUTF(classname);
|
|
978 |
JVM_ReleaseUTF(methodname);
|
|
979 |
JVM_ReleaseUTF(signature);
|
|
980 |
}
|
|
981 |
#endif
|
|
982 |
|
|
983 |
if (((access_bits & JVM_ACC_PUBLIC) != 0) &&
|
|
984 |
((access_bits & (JVM_ACC_PRIVATE | JVM_ACC_PROTECTED)) != 0)) {
|
|
985 |
CCerror(context, "Inconsistent access bits.");
|
|
986 |
}
|
|
987 |
|
|
988 |
/* Run through the code. Mark the start of each instruction, and give
|
|
989 |
* the instruction a number */
|
|
990 |
for (i = 0, offset = 0; offset < code_length; i++) {
|
|
991 |
int length = instruction_length(&code[offset], code + code_length);
|
|
992 |
int next_offset = offset + length;
|
|
993 |
if (length <= 0)
|
|
994 |
CCerror(context, "Illegal instruction found at offset %d", offset);
|
|
995 |
if (next_offset > code_length)
|
|
996 |
CCerror(context, "Code stops in the middle of instruction "
|
|
997 |
" starting at offset %d", offset);
|
|
998 |
code_data[offset] = i;
|
|
999 |
while (++offset < next_offset)
|
|
1000 |
code_data[offset] = -1; /* illegal location */
|
|
1001 |
}
|
|
1002 |
instruction_count = i; /* number of instructions in code */
|
|
1003 |
|
|
1004 |
/* Allocate a structure to hold info about each instruction. */
|
|
1005 |
idata = NEW(instruction_data_type, instruction_count);
|
|
1006 |
|
|
1007 |
/* Initialize the heap, and other info in the context structure. */
|
|
1008 |
context->code = code;
|
|
1009 |
context->instruction_data = idata;
|
|
1010 |
context->code_data = code_data;
|
|
1011 |
context->instruction_count = instruction_count;
|
|
1012 |
context->handler_info =
|
|
1013 |
NEW(struct handler_info_type,
|
|
1014 |
JVM_GetMethodIxExceptionTableLength(env, cb, method_index));
|
|
1015 |
context->bitmask_size =
|
|
1016 |
(JVM_GetMethodIxLocalsCount(env, cb, method_index)
|
|
1017 |
+ (BITS_PER_INT - 1))/BITS_PER_INT;
|
|
1018 |
|
|
1019 |
if (instruction_count == 0)
|
|
1020 |
CCerror(context, "Empty code");
|
|
1021 |
|
|
1022 |
for (inumber = 0, offset = 0; offset < code_length; inumber++) {
|
|
1023 |
int length = instruction_length(&code[offset], code + code_length);
|
|
1024 |
instruction_data_type *this_idata = &idata[inumber];
|
|
1025 |
this_idata->opcode = code[offset];
|
|
1026 |
this_idata->stack_info.stack = NULL;
|
|
1027 |
this_idata->stack_info.stack_size = UNKNOWN_STACK_SIZE;
|
|
1028 |
this_idata->register_info.register_count = UNKNOWN_REGISTER_COUNT;
|
|
1029 |
this_idata->changed = JNI_FALSE; /* no need to look at it yet. */
|
|
1030 |
this_idata->protected = JNI_FALSE; /* no need to look at it yet. */
|
|
1031 |
this_idata->and_flags = (flag_type) -1; /* "bottom" and value */
|
|
1032 |
this_idata->or_flags = 0; /* "bottom" or value*/
|
|
1033 |
/* This also sets up this_data->operand. It also makes the
|
|
1034 |
* xload_x and xstore_x instructions look like the generic form. */
|
|
1035 |
verify_opcode_operands(context, inumber, offset);
|
|
1036 |
offset += length;
|
|
1037 |
}
|
|
1038 |
|
|
1039 |
|
|
1040 |
/* make sure exception table is reasonable. */
|
|
1041 |
initialize_exception_table(context);
|
|
1042 |
/* Set up first instruction, and start of exception handlers. */
|
|
1043 |
initialize_dataflow(context);
|
|
1044 |
/* Run data flow analysis on the instructions. */
|
|
1045 |
run_dataflow(context);
|
|
1046 |
|
|
1047 |
/* verify checked exceptions, if any */
|
|
1048 |
nexceptions = JVM_GetMethodIxExceptionsCount(env, cb, method_index);
|
|
1049 |
context->exceptions = (unsigned short *)
|
|
1050 |
malloc(sizeof(unsigned short) * nexceptions + 1);
|
|
1051 |
if (context->exceptions == 0)
|
|
1052 |
CCout_of_memory(context);
|
|
1053 |
JVM_GetMethodIxExceptionIndexes(env, cb, method_index,
|
|
1054 |
context->exceptions);
|
|
1055 |
for (i = 0; i < nexceptions; i++) {
|
|
1056 |
/* Make sure the constant pool item is JVM_CONSTANT_Class */
|
|
1057 |
verify_constant_pool_type(context, (int)context->exceptions[i],
|
|
1058 |
1 << JVM_CONSTANT_Class);
|
|
1059 |
}
|
|
1060 |
free(context->exceptions);
|
|
1061 |
context->exceptions = 0;
|
|
1062 |
context->code = 0;
|
|
1063 |
context->method_index = -1;
|
|
1064 |
}
|
|
1065 |
|
|
1066 |
|
|
1067 |
/* Look at a single instruction, and verify its operands. Also, for
|
|
1068 |
* simplicity, move the operand into the ->operand field.
|
|
1069 |
* Make sure that branches don't go into the middle of nowhere.
|
|
1070 |
*/
|
|
1071 |
|
|
1072 |
static jint ntohl(jint n)
|
|
1073 |
{
|
|
1074 |
unsigned char *p = (unsigned char *)&n;
|
|
1075 |
return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
|
|
1076 |
}
|
|
1077 |
|
|
1078 |
static void
|
|
1079 |
verify_opcode_operands(context_type *context, unsigned int inumber, int offset)
|
|
1080 |
{
|
|
1081 |
JNIEnv *env = context->env;
|
|
1082 |
instruction_data_type *idata = context->instruction_data;
|
|
1083 |
instruction_data_type *this_idata = &idata[inumber];
|
|
1084 |
int *code_data = context->code_data;
|
|
1085 |
int mi = context->method_index;
|
|
1086 |
unsigned char *code = context->code;
|
|
1087 |
opcode_type opcode = this_idata->opcode;
|
|
1088 |
int var;
|
|
1089 |
|
|
1090 |
/*
|
|
1091 |
* Set the ip fields to 0 not the i fields because the ip fields
|
|
1092 |
* are 64 bits on 64 bit architectures, the i field is only 32
|
|
1093 |
*/
|
|
1094 |
this_idata->operand.ip = 0;
|
|
1095 |
this_idata->operand2.ip = 0;
|
|
1096 |
|
|
1097 |
switch (opcode) {
|
|
1098 |
|
|
1099 |
case opc_jsr:
|
|
1100 |
/* instruction of ret statement */
|
|
1101 |
this_idata->operand2.i = UNKNOWN_RET_INSTRUCTION;
|
|
1102 |
/* FALLTHROUGH */
|
|
1103 |
case opc_ifeq: case opc_ifne: case opc_iflt:
|
|
1104 |
case opc_ifge: case opc_ifgt: case opc_ifle:
|
|
1105 |
case opc_ifnull: case opc_ifnonnull:
|
|
1106 |
case opc_if_icmpeq: case opc_if_icmpne: case opc_if_icmplt:
|
|
1107 |
case opc_if_icmpge: case opc_if_icmpgt: case opc_if_icmple:
|
|
1108 |
case opc_if_acmpeq: case opc_if_acmpne:
|
|
1109 |
case opc_goto: {
|
|
1110 |
/* Set the ->operand to be the instruction number of the target. */
|
|
1111 |
int jump = (((signed char)(code[offset+1])) << 8) + code[offset+2];
|
|
1112 |
int target = offset + jump;
|
|
1113 |
if (!isLegalTarget(context, target))
|
|
1114 |
CCerror(context, "Illegal target of jump or branch");
|
|
1115 |
this_idata->operand.i = code_data[target];
|
|
1116 |
break;
|
|
1117 |
}
|
|
1118 |
|
|
1119 |
case opc_jsr_w:
|
|
1120 |
/* instruction of ret statement */
|
|
1121 |
this_idata->operand2.i = UNKNOWN_RET_INSTRUCTION;
|
|
1122 |
/* FALLTHROUGH */
|
|
1123 |
case opc_goto_w: {
|
|
1124 |
/* Set the ->operand to be the instruction number of the target. */
|
|
1125 |
int jump = (((signed char)(code[offset+1])) << 24) +
|
|
1126 |
(code[offset+2] << 16) + (code[offset+3] << 8) +
|
|
1127 |
(code[offset + 4]);
|
|
1128 |
int target = offset + jump;
|
|
1129 |
if (!isLegalTarget(context, target))
|
|
1130 |
CCerror(context, "Illegal target of jump or branch");
|
|
1131 |
this_idata->operand.i = code_data[target];
|
|
1132 |
break;
|
|
1133 |
}
|
|
1134 |
|
|
1135 |
case opc_tableswitch:
|
|
1136 |
case opc_lookupswitch: {
|
|
1137 |
/* Set the ->operand to be a table of possible instruction targets. */
|
|
1138 |
int *lpc = (int *) UCALIGN(code + offset + 1);
|
|
1139 |
int *lptr;
|
|
1140 |
int *saved_operand;
|
|
1141 |
int keys;
|
|
1142 |
int k, delta;
|
|
1143 |
/* 4639449, 4647081: Padding bytes must be zero. */
|
|
1144 |
unsigned char* bptr = (unsigned char*) (code + offset + 1);
|
|
1145 |
for (; bptr < (unsigned char*)lpc; bptr++) {
|
|
1146 |
if (*bptr != 0) {
|
|
1147 |
CCerror(context, "Non zero padding bytes in switch");
|
|
1148 |
}
|
|
1149 |
}
|
|
1150 |
if (opcode == opc_tableswitch) {
|
|
1151 |
keys = ntohl(lpc[2]) - ntohl(lpc[1]) + 1;
|
|
1152 |
delta = 1;
|
|
1153 |
} else {
|
|
1154 |
keys = ntohl(lpc[1]); /* number of pairs */
|
|
1155 |
delta = 2;
|
|
1156 |
/* Make sure that the tableswitch items are sorted */
|
|
1157 |
for (k = keys - 1, lptr = &lpc[2]; --k >= 0; lptr += 2) {
|
|
1158 |
int this_key = ntohl(lptr[0]); /* NB: ntohl may be unsigned */
|
|
1159 |
int next_key = ntohl(lptr[2]);
|
|
1160 |
if (this_key >= next_key) {
|
|
1161 |
CCerror(context, "Unsorted lookup switch");
|
|
1162 |
}
|
|
1163 |
}
|
|
1164 |
}
|
|
1165 |
saved_operand = NEW(int, keys + 2);
|
|
1166 |
if (!isLegalTarget(context, offset + ntohl(lpc[0])))
|
|
1167 |
CCerror(context, "Illegal default target in switch");
|
|
1168 |
saved_operand[keys + 1] = code_data[offset + ntohl(lpc[0])];
|
|
1169 |
for (k = keys, lptr = &lpc[3]; --k >= 0; lptr += delta) {
|
|
1170 |
int target = offset + ntohl(lptr[0]);
|
|
1171 |
if (!isLegalTarget(context, target))
|
|
1172 |
CCerror(context, "Illegal branch in opc_tableswitch");
|
|
1173 |
saved_operand[k + 1] = code_data[target];
|
|
1174 |
}
|
|
1175 |
saved_operand[0] = keys + 1; /* number of successors */
|
|
1176 |
this_idata->operand.ip = saved_operand;
|
|
1177 |
break;
|
|
1178 |
}
|
|
1179 |
|
|
1180 |
case opc_ldc: {
|
|
1181 |
/* Make sure the constant pool item is the right type. */
|
|
1182 |
int key = code[offset + 1];
|
|
1183 |
int types = (1 << JVM_CONSTANT_Integer) | (1 << JVM_CONSTANT_Float) |
|
|
1184 |
(1 << JVM_CONSTANT_String);
|
|
1185 |
if (context->major_version >= LDC_CLASS_MAJOR_VERSION) {
|
|
1186 |
types |= 1 << JVM_CONSTANT_Class;
|
|
1187 |
}
|
|
1188 |
this_idata->operand.i = key;
|
|
1189 |
verify_constant_pool_type(context, key, types);
|
|
1190 |
break;
|
|
1191 |
}
|
|
1192 |
|
|
1193 |
case opc_ldc_w: {
|
|
1194 |
/* Make sure the constant pool item is the right type. */
|
|
1195 |
int key = (code[offset + 1] << 8) + code[offset + 2];
|
|
1196 |
int types = (1 << JVM_CONSTANT_Integer) | (1 << JVM_CONSTANT_Float) |
|
|
1197 |
(1 << JVM_CONSTANT_String);
|
|
1198 |
if (context->major_version >= LDC_CLASS_MAJOR_VERSION) {
|
|
1199 |
types |= 1 << JVM_CONSTANT_Class;
|
|
1200 |
}
|
|
1201 |
this_idata->operand.i = key;
|
|
1202 |
verify_constant_pool_type(context, key, types);
|
|
1203 |
break;
|
|
1204 |
}
|
|
1205 |
|
|
1206 |
case opc_ldc2_w: {
|
|
1207 |
/* Make sure the constant pool item is the right type. */
|
|
1208 |
int key = (code[offset + 1] << 8) + code[offset + 2];
|
|
1209 |
int types = (1 << JVM_CONSTANT_Double) | (1 << JVM_CONSTANT_Long);
|
|
1210 |
this_idata->operand.i = key;
|
|
1211 |
verify_constant_pool_type(context, key, types);
|
|
1212 |
break;
|
|
1213 |
}
|
|
1214 |
|
|
1215 |
case opc_getfield: case opc_putfield:
|
|
1216 |
case opc_getstatic: case opc_putstatic: {
|
|
1217 |
/* Make sure the constant pool item is the right type. */
|
|
1218 |
int key = (code[offset + 1] << 8) + code[offset + 2];
|
|
1219 |
this_idata->operand.i = key;
|
|
1220 |
verify_constant_pool_type(context, key, 1 << JVM_CONSTANT_Fieldref);
|
|
1221 |
if (opcode == opc_getfield || opcode == opc_putfield)
|
|
1222 |
set_protected(context, inumber, key, opcode);
|
|
1223 |
break;
|
|
1224 |
}
|
|
1225 |
|
|
1226 |
case opc_invokevirtual:
|
|
1227 |
case opc_invokespecial:
|
|
1228 |
case opc_invokestatic:
|
|
1229 |
case opc_invokeinterface: {
|
|
1230 |
/* Make sure the constant pool item is the right type. */
|
|
1231 |
int key = (code[offset + 1] << 8) + code[offset + 2];
|
|
1232 |
const char *methodname;
|
|
1233 |
jclass cb = context->class;
|
|
1234 |
fullinfo_type clazz_info;
|
|
1235 |
int is_constructor, is_internal;
|
|
1236 |
int kind = (opcode == opc_invokeinterface
|
|
1237 |
? 1 << JVM_CONSTANT_InterfaceMethodref
|
|
1238 |
: 1 << JVM_CONSTANT_Methodref);
|
|
1239 |
/* Make sure the constant pool item is the right type. */
|
|
1240 |
verify_constant_pool_type(context, key, kind);
|
|
1241 |
methodname = JVM_GetCPMethodNameUTF(env, cb, key);
|
|
1242 |
check_and_push(context, methodname, VM_STRING_UTF);
|
|
1243 |
is_constructor = !strcmp(methodname, "<init>");
|
|
1244 |
is_internal = methodname[0] == '<';
|
|
1245 |
pop_and_free(context);
|
|
1246 |
|
|
1247 |
clazz_info = cp_index_to_class_fullinfo(context, key,
|
|
1248 |
JVM_CONSTANT_Methodref);
|
|
1249 |
this_idata->operand.i = key;
|
|
1250 |
this_idata->operand2.fi = clazz_info;
|
|
1251 |
if (is_constructor) {
|
|
1252 |
if (opcode != opc_invokespecial) {
|
|
1253 |
CCerror(context,
|
|
1254 |
"Must call initializers using invokespecial");
|
|
1255 |
}
|
|
1256 |
this_idata->opcode = opc_invokeinit;
|
|
1257 |
} else {
|
|
1258 |
if (is_internal) {
|
|
1259 |
CCerror(context, "Illegal call to internal method");
|
|
1260 |
}
|
|
1261 |
if (opcode == opc_invokespecial
|
|
1262 |
&& clazz_info != context->currentclass_info
|
|
1263 |
&& clazz_info != context->superclass_info) {
|
|
1264 |
int not_found = 1;
|
|
1265 |
|
|
1266 |
jclass super = (*env)->GetSuperclass(env, context->class);
|
|
1267 |
while(super != 0) {
|
|
1268 |
jclass tmp_cb;
|
|
1269 |
fullinfo_type new_info = make_class_info(context, super);
|
|
1270 |
if (clazz_info == new_info) {
|
|
1271 |
not_found = 0;
|
|
1272 |
break;
|
|
1273 |
}
|
|
1274 |
tmp_cb = (*env)->GetSuperclass(env, super);
|
|
1275 |
(*env)->DeleteLocalRef(env, super);
|
|
1276 |
super = tmp_cb;
|
|
1277 |
}
|
|
1278 |
(*env)->DeleteLocalRef(env, super);
|
|
1279 |
|
|
1280 |
/* The optimizer make cause this to happen on local code */
|
|
1281 |
if (not_found) {
|
|
1282 |
#ifdef BROKEN_JAVAC
|
|
1283 |
jobject loader = JVM_GetClassLoader(env, context->class);
|
|
1284 |
int has_loader = (loader != 0);
|
|
1285 |
(*env)->DeleteLocalRef(env, loader);
|
|
1286 |
if (has_loader)
|
|
1287 |
#endif /* BROKEN_JAVAC */
|
|
1288 |
CCerror(context,
|
|
1289 |
"Illegal use of nonvirtual function call");
|
|
1290 |
}
|
|
1291 |
}
|
|
1292 |
}
|
|
1293 |
if (opcode == opc_invokeinterface) {
|
|
1294 |
unsigned int args1;
|
|
1295 |
unsigned int args2;
|
|
1296 |
const char *signature =
|
|
1297 |
JVM_GetCPMethodSignatureUTF(env, context->class, key);
|
|
1298 |
check_and_push(context, signature, VM_STRING_UTF);
|
|
1299 |
args1 = signature_to_args_size(signature) + 1;
|
|
1300 |
args2 = code[offset + 3];
|
|
1301 |
if (args1 != args2) {
|
|
1302 |
CCerror(context,
|
|
1303 |
"Inconsistent args_size for opc_invokeinterface");
|
|
1304 |
}
|
|
1305 |
if (code[offset + 4] != 0) {
|
|
1306 |
CCerror(context,
|
|
1307 |
"Fourth operand byte of invokeinterface must be zero");
|
|
1308 |
}
|
|
1309 |
pop_and_free(context);
|
|
1310 |
} else if (opcode == opc_invokevirtual
|
|
1311 |
|| opcode == opc_invokespecial)
|
|
1312 |
set_protected(context, inumber, key, opcode);
|
|
1313 |
break;
|
|
1314 |
}
|
|
1315 |
|
|
1316 |
|
|
1317 |
case opc_instanceof:
|
|
1318 |
case opc_checkcast:
|
|
1319 |
case opc_new:
|
|
1320 |
case opc_anewarray:
|
|
1321 |
case opc_multianewarray: {
|
|
1322 |
/* Make sure the constant pool item is a class */
|
|
1323 |
int key = (code[offset + 1] << 8) + code[offset + 2];
|
|
1324 |
fullinfo_type target;
|
|
1325 |
verify_constant_pool_type(context, key, 1 << JVM_CONSTANT_Class);
|
|
1326 |
target = cp_index_to_class_fullinfo(context, key, JVM_CONSTANT_Class);
|
|
1327 |
if (GET_ITEM_TYPE(target) == ITEM_Bogus)
|
|
1328 |
CCerror(context, "Illegal type");
|
|
1329 |
switch(opcode) {
|
|
1330 |
case opc_anewarray:
|
|
1331 |
if ((GET_INDIRECTION(target)) >= MAX_ARRAY_DIMENSIONS)
|
|
1332 |
CCerror(context, "Array with too many dimensions");
|
|
1333 |
this_idata->operand.fi = MAKE_FULLINFO(GET_ITEM_TYPE(target),
|
|
1334 |
GET_INDIRECTION(target) + 1,
|
|
1335 |
GET_EXTRA_INFO(target));
|
|
1336 |
break;
|
|
1337 |
case opc_new:
|
|
1338 |
if (WITH_ZERO_EXTRA_INFO(target) !=
|
|
1339 |
MAKE_FULLINFO(ITEM_Object, 0, 0))
|
|
1340 |
CCerror(context, "Illegal creation of multi-dimensional array");
|
|
1341 |
/* operand gets set to the "unitialized object". operand2 gets
|
|
1342 |
* set to what the value will be after it's initialized. */
|
|
1343 |
this_idata->operand.fi = MAKE_FULLINFO(ITEM_NewObject, 0, inumber);
|
|
1344 |
this_idata->operand2.fi = target;
|
|
1345 |
break;
|
|
1346 |
case opc_multianewarray:
|
|
1347 |
this_idata->operand.fi = target;
|
|
1348 |
this_idata->operand2.i = code[offset + 3];
|
|
1349 |
if ( (this_idata->operand2.i > GET_INDIRECTION(target))
|
|
1350 |
|| (this_idata->operand2.i == 0))
|
|
1351 |
CCerror(context, "Illegal dimension argument");
|
|
1352 |
break;
|
|
1353 |
default:
|
|
1354 |
this_idata->operand.fi = target;
|
|
1355 |
}
|
|
1356 |
break;
|
|
1357 |
}
|
|
1358 |
|
|
1359 |
case opc_newarray: {
|
|
1360 |
/* Cache the result of the opc_newarray into the operand slot */
|
|
1361 |
fullinfo_type full_info;
|
|
1362 |
switch (code[offset + 1]) {
|
|
1363 |
case JVM_T_INT:
|
|
1364 |
full_info = MAKE_FULLINFO(ITEM_Integer, 1, 0); break;
|
|
1365 |
case JVM_T_LONG:
|
|
1366 |
full_info = MAKE_FULLINFO(ITEM_Long, 1, 0); break;
|
|
1367 |
case JVM_T_FLOAT:
|
|
1368 |
full_info = MAKE_FULLINFO(ITEM_Float, 1, 0); break;
|
|
1369 |
case JVM_T_DOUBLE:
|
|
1370 |
full_info = MAKE_FULLINFO(ITEM_Double, 1, 0); break;
|
|
1371 |
case JVM_T_BYTE: case JVM_T_BOOLEAN:
|
|
1372 |
full_info = MAKE_FULLINFO(ITEM_Byte, 1, 0); break;
|
|
1373 |
case JVM_T_CHAR:
|
|
1374 |
full_info = MAKE_FULLINFO(ITEM_Char, 1, 0); break;
|
|
1375 |
case JVM_T_SHORT:
|
|
1376 |
full_info = MAKE_FULLINFO(ITEM_Short, 1, 0); break;
|
|
1377 |
default:
|
|
1378 |
full_info = 0; /* Keep lint happy */
|
|
1379 |
CCerror(context, "Bad type passed to opc_newarray");
|
|
1380 |
}
|
|
1381 |
this_idata->operand.fi = full_info;
|
|
1382 |
break;
|
|
1383 |
}
|
|
1384 |
|
|
1385 |
/* Fudge iload_x, aload_x, etc to look like their generic cousin. */
|
|
1386 |
case opc_iload_0: case opc_iload_1: case opc_iload_2: case opc_iload_3:
|
|
1387 |
this_idata->opcode = opc_iload;
|
|
1388 |
var = opcode - opc_iload_0;
|
|
1389 |
goto check_local_variable;
|
|
1390 |
|
|
1391 |
case opc_fload_0: case opc_fload_1: case opc_fload_2: case opc_fload_3:
|
|
1392 |
this_idata->opcode = opc_fload;
|
|
1393 |
var = opcode - opc_fload_0;
|
|
1394 |
goto check_local_variable;
|
|
1395 |
|
|
1396 |
case opc_aload_0: case opc_aload_1: case opc_aload_2: case opc_aload_3:
|
|
1397 |
this_idata->opcode = opc_aload;
|
|
1398 |
var = opcode - opc_aload_0;
|
|
1399 |
goto check_local_variable;
|
|
1400 |
|
|
1401 |
case opc_lload_0: case opc_lload_1: case opc_lload_2: case opc_lload_3:
|
|
1402 |
this_idata->opcode = opc_lload;
|
|
1403 |
var = opcode - opc_lload_0;
|
|
1404 |
goto check_local_variable2;
|
|
1405 |
|
|
1406 |
case opc_dload_0: case opc_dload_1: case opc_dload_2: case opc_dload_3:
|
|
1407 |
this_idata->opcode = opc_dload;
|
|
1408 |
var = opcode - opc_dload_0;
|
|
1409 |
goto check_local_variable2;
|
|
1410 |
|
|
1411 |
case opc_istore_0: case opc_istore_1: case opc_istore_2: case opc_istore_3:
|
|
1412 |
this_idata->opcode = opc_istore;
|
|
1413 |
var = opcode - opc_istore_0;
|
|
1414 |
goto check_local_variable;
|
|
1415 |
|
|
1416 |
case opc_fstore_0: case opc_fstore_1: case opc_fstore_2: case opc_fstore_3:
|
|
1417 |
this_idata->opcode = opc_fstore;
|
|
1418 |
var = opcode - opc_fstore_0;
|
|
1419 |
goto check_local_variable;
|
|
1420 |
|
|
1421 |
case opc_astore_0: case opc_astore_1: case opc_astore_2: case opc_astore_3:
|
|
1422 |
this_idata->opcode = opc_astore;
|
|
1423 |
var = opcode - opc_astore_0;
|
|
1424 |
goto check_local_variable;
|
|
1425 |
|
|
1426 |
case opc_lstore_0: case opc_lstore_1: case opc_lstore_2: case opc_lstore_3:
|
|
1427 |
this_idata->opcode = opc_lstore;
|
|
1428 |
var = opcode - opc_lstore_0;
|
|
1429 |
goto check_local_variable2;
|
|
1430 |
|
|
1431 |
case opc_dstore_0: case opc_dstore_1: case opc_dstore_2: case opc_dstore_3:
|
|
1432 |
this_idata->opcode = opc_dstore;
|
|
1433 |
var = opcode - opc_dstore_0;
|
|
1434 |
goto check_local_variable2;
|
|
1435 |
|
|
1436 |
case opc_wide:
|
|
1437 |
this_idata->opcode = code[offset + 1];
|
|
1438 |
var = (code[offset + 2] << 8) + code[offset + 3];
|
|
1439 |
switch(this_idata->opcode) {
|
|
1440 |
case opc_lload: case opc_dload:
|
|
1441 |
case opc_lstore: case opc_dstore:
|
|
1442 |
goto check_local_variable2;
|
|
1443 |
default:
|
|
1444 |
goto check_local_variable;
|
|
1445 |
}
|
|
1446 |
|
|
1447 |
case opc_iinc: /* the increment amount doesn't matter */
|
|
1448 |
case opc_ret:
|
|
1449 |
case opc_aload: case opc_iload: case opc_fload:
|
|
1450 |
case opc_astore: case opc_istore: case opc_fstore:
|
|
1451 |
var = code[offset + 1];
|
|
1452 |
check_local_variable:
|
|
1453 |
/* Make sure that the variable number isn't illegal. */
|
|
1454 |
this_idata->operand.i = var;
|
|
1455 |
if (var >= JVM_GetMethodIxLocalsCount(env, context->class, mi))
|
|
1456 |
CCerror(context, "Illegal local variable number");
|
|
1457 |
break;
|
|
1458 |
|
|
1459 |
case opc_lload: case opc_dload: case opc_lstore: case opc_dstore:
|
|
1460 |
var = code[offset + 1];
|
|
1461 |
check_local_variable2:
|
|
1462 |
/* Make sure that the variable number isn't illegal. */
|
|
1463 |
this_idata->operand.i = var;
|
|
1464 |
if ((var + 1) >= JVM_GetMethodIxLocalsCount(env, context->class, mi))
|
|
1465 |
CCerror(context, "Illegal local variable number");
|
|
1466 |
break;
|
|
1467 |
|
|
1468 |
default:
|
|
1469 |
if (opcode >= opc_breakpoint)
|
|
1470 |
CCerror(context, "Quick instructions shouldn't appear yet.");
|
|
1471 |
break;
|
|
1472 |
} /* of switch */
|
|
1473 |
}
|
|
1474 |
|
|
1475 |
|
|
1476 |
static void
|
|
1477 |
set_protected(context_type *context, unsigned int inumber, int key, opcode_type opcode)
|
|
1478 |
{
|
|
1479 |
JNIEnv *env = context->env;
|
|
1480 |
fullinfo_type clazz_info;
|
|
1481 |
if (opcode != opc_invokevirtual && opcode != opc_invokespecial) {
|
|
1482 |
clazz_info = cp_index_to_class_fullinfo(context, key,
|
|
1483 |
JVM_CONSTANT_Fieldref);
|
|
1484 |
} else {
|
|
1485 |
clazz_info = cp_index_to_class_fullinfo(context, key,
|
|
1486 |
JVM_CONSTANT_Methodref);
|
|
1487 |
}
|
|
1488 |
if (is_superclass(context, clazz_info)) {
|
|
1489 |
jclass calledClass =
|
|
1490 |
object_fullinfo_to_classclass(context, clazz_info);
|
|
1491 |
int access;
|
|
1492 |
/* 4734966: JVM_GetCPFieldModifiers() or JVM_GetCPMethodModifiers() only
|
|
1493 |
searches the referenced field or method in calledClass. The following
|
|
1494 |
while loop is added to search up the superclass chain to make this
|
|
1495 |
symbolic resolution consistent with the field/method resolution
|
|
1496 |
specified in VM spec 5.4.3. */
|
|
1497 |
calledClass = (*env)->NewLocalRef(env, calledClass);
|
|
1498 |
do {
|
|
1499 |
jclass tmp_cb;
|
|
1500 |
if (opcode != opc_invokevirtual && opcode != opc_invokespecial) {
|
|
1501 |
access = JVM_GetCPFieldModifiers
|
|
1502 |
(env, context->class, key, calledClass);
|
|
1503 |
} else {
|
|
1504 |
access = JVM_GetCPMethodModifiers
|
|
1505 |
(env, context->class, key, calledClass);
|
|
1506 |
}
|
|
1507 |
if (access != -1) {
|
|
1508 |
break;
|
|
1509 |
}
|
|
1510 |
tmp_cb = (*env)->GetSuperclass(env, calledClass);
|
|
1511 |
(*env)->DeleteLocalRef(env, calledClass);
|
|
1512 |
calledClass = tmp_cb;
|
|
1513 |
} while (calledClass != 0);
|
|
1514 |
|
|
1515 |
if (access == -1) {
|
|
1516 |
/* field/method not found, detected at runtime. */
|
|
1517 |
} else if (access & JVM_ACC_PROTECTED) {
|
|
1518 |
if (!JVM_IsSameClassPackage(env, calledClass, context->class))
|
|
1519 |
context->instruction_data[inumber].protected = JNI_TRUE;
|
|
1520 |
}
|
|
1521 |
(*env)->DeleteLocalRef(env, calledClass);
|
|
1522 |
}
|
|
1523 |
}
|
|
1524 |
|
|
1525 |
|
|
1526 |
static jboolean
|
|
1527 |
is_superclass(context_type *context, fullinfo_type clazz_info) {
|
|
1528 |
fullinfo_type *fptr = context->superclasses;
|
|
1529 |
|
|
1530 |
if (fptr == 0)
|
|
1531 |
return JNI_FALSE;
|
|
1532 |
for (; *fptr != 0; fptr++) {
|
|
1533 |
if (*fptr == clazz_info)
|
|
1534 |
return JNI_TRUE;
|
|
1535 |
}
|
|
1536 |
return JNI_FALSE;
|
|
1537 |
}
|
|
1538 |
|
|
1539 |
|
|
1540 |
/* Look through each item on the exception table. Each of the fields must
|
|
1541 |
* refer to a legal instruction.
|
|
1542 |
*/
|
|
1543 |
static void
|
|
1544 |
initialize_exception_table(context_type *context)
|
|
1545 |
{
|
|
1546 |
JNIEnv *env = context->env;
|
|
1547 |
int mi = context->method_index;
|
|
1548 |
struct handler_info_type *handler_info = context->handler_info;
|
|
1549 |
int *code_data = context->code_data;
|
|
1550 |
int code_length = context->code_length;
|
|
1551 |
int max_stack_size = JVM_GetMethodIxMaxStack(env, context->class, mi);
|
|
1552 |
int i = JVM_GetMethodIxExceptionTableLength(env, context->class, mi);
|
|
1553 |
if (max_stack_size < 1 && i > 0) {
|
|
1554 |
// If the method contains exception handlers, it must have room
|
|
1555 |
// on the expression stack for the exception that the VM could push
|
|
1556 |
CCerror(context, "Stack size too large");
|
|
1557 |
}
|
|
1558 |
for (; --i >= 0; handler_info++) {
|
|
1559 |
JVM_ExceptionTableEntryType einfo;
|
|
1560 |
stack_item_type *stack_item = NEW(stack_item_type, 1);
|
|
1561 |
|
|
1562 |
JVM_GetMethodIxExceptionTableEntry(env, context->class, mi,
|
|
1563 |
i, &einfo);
|
|
1564 |
|
|
1565 |
if (!(einfo.start_pc < einfo.end_pc &&
|
|
1566 |
einfo.start_pc >= 0 &&
|
|
1567 |
isLegalTarget(context, einfo.start_pc) &&
|
|
1568 |
(einfo.end_pc == code_length ||
|
|
1569 |
isLegalTarget(context, einfo.end_pc)))) {
|
|
1570 |
CFerror(context, "Illegal exception table range");
|
|
1571 |
}
|
|
1572 |
if (!((einfo.handler_pc > 0) &&
|
|
1573 |
isLegalTarget(context, einfo.handler_pc))) {
|
|
1574 |
CFerror(context, "Illegal exception table handler");
|
|
1575 |
}
|
|
1576 |
|
|
1577 |
handler_info->start = code_data[einfo.start_pc];
|
|
1578 |
/* einfo.end_pc may point to one byte beyond the end of bytecodes. */
|
|
1579 |
handler_info->end = (einfo.end_pc == context->code_length) ?
|
|
1580 |
context->instruction_count : code_data[einfo.end_pc];
|
|
1581 |
handler_info->handler = code_data[einfo.handler_pc];
|
|
1582 |
handler_info->stack_info.stack = stack_item;
|
|
1583 |
handler_info->stack_info.stack_size = 1;
|
|
1584 |
stack_item->next = NULL;
|
|
1585 |
if (einfo.catchType != 0) {
|
|
1586 |
const char *classname;
|
|
1587 |
/* Constant pool entry type has been checked in format checker */
|
|
1588 |
classname = JVM_GetCPClassNameUTF(env,
|
|
1589 |
context->class,
|
|
1590 |
einfo.catchType);
|
|
1591 |
check_and_push(context, classname, VM_STRING_UTF);
|
|
1592 |
stack_item->item = make_class_info_from_name(context, classname);
|
|
1593 |
if (!isAssignableTo(context,
|
|
1594 |
stack_item->item,
|
|
1595 |
context->throwable_info))
|
|
1596 |
CCerror(context, "catch_type not a subclass of Throwable");
|
|
1597 |
pop_and_free(context);
|
|
1598 |
} else {
|
|
1599 |
stack_item->item = context->throwable_info;
|
|
1600 |
}
|
|
1601 |
}
|
|
1602 |
}
|
|
1603 |
|
|
1604 |
|
|
1605 |
/* Given a pointer to an instruction, return its length. Use the table
|
|
1606 |
* opcode_length[] which is automatically built.
|
|
1607 |
*/
|
|
1608 |
static int instruction_length(unsigned char *iptr, unsigned char *end)
|
|
1609 |
{
|
|
1610 |
int instruction = *iptr;
|
|
1611 |
switch (instruction) {
|
|
1612 |
case opc_tableswitch: {
|
|
1613 |
int *lpc = (int *)UCALIGN(iptr + 1);
|
|
1614 |
int index;
|
|
1615 |
if (lpc + 2 >= (int *)end) {
|
|
1616 |
return -1; /* do not read pass the end */
|
|
1617 |
}
|
|
1618 |
index = ntohl(lpc[2]) - ntohl(lpc[1]);
|
|
1619 |
if ((index < 0) || (index > 65535)) {
|
|
1620 |
return -1; /* illegal */
|
|
1621 |
} else {
|
|
1622 |
return (unsigned char *)(&lpc[index + 4]) - iptr;
|
|
1623 |
}
|
|
1624 |
}
|
|
1625 |
|
|
1626 |
case opc_lookupswitch: {
|
|
1627 |
int *lpc = (int *) UCALIGN(iptr + 1);
|
|
1628 |
int npairs;
|
|
1629 |
if (lpc + 1 >= (int *)end)
|
|
1630 |
return -1; /* do not read pass the end */
|
|
1631 |
npairs = ntohl(lpc[1]);
|
|
1632 |
/* There can't be more than 64K labels because of the limit
|
|
1633 |
* on per-method byte code length.
|
|
1634 |
*/
|
|
1635 |
if (npairs < 0 || npairs >= 65536)
|
|
1636 |
return -1;
|
|
1637 |
else
|
|
1638 |
return (unsigned char *)(&lpc[2 * (npairs + 1)]) - iptr;
|
|
1639 |
}
|
|
1640 |
|
|
1641 |
case opc_wide:
|
|
1642 |
if (iptr + 1 >= end)
|
|
1643 |
return -1; /* do not read pass the end */
|
|
1644 |
switch(iptr[1]) {
|
|
1645 |
case opc_ret:
|
|
1646 |
case opc_iload: case opc_istore:
|
|
1647 |
case opc_fload: case opc_fstore:
|
|
1648 |
case opc_aload: case opc_astore:
|
|
1649 |
case opc_lload: case opc_lstore:
|
|
1650 |
case opc_dload: case opc_dstore:
|
|
1651 |
return 4;
|
|
1652 |
case opc_iinc:
|
|
1653 |
return 6;
|
|
1654 |
default:
|
|
1655 |
return -1;
|
|
1656 |
}
|
|
1657 |
|
|
1658 |
default: {
|
|
1659 |
/* A length of 0 indicates an error. */
|
|
1660 |
int length = opcode_length[instruction];
|
|
1661 |
return (length <= 0) ? -1 : length;
|
|
1662 |
}
|
|
1663 |
}
|
|
1664 |
}
|
|
1665 |
|
|
1666 |
|
|
1667 |
/* Given the target of a branch, make sure that it's a legal target. */
|
|
1668 |
static jboolean
|
|
1669 |
isLegalTarget(context_type *context, int offset)
|
|
1670 |
{
|
|
1671 |
int code_length = context->code_length;
|
|
1672 |
int *code_data = context->code_data;
|
|
1673 |
return (offset >= 0 && offset < code_length && code_data[offset] >= 0);
|
|
1674 |
}
|
|
1675 |
|
|
1676 |
|
|
1677 |
/* Make sure that an element of the constant pool really is of the indicated
|
|
1678 |
* type.
|
|
1679 |
*/
|
|
1680 |
static void
|
|
1681 |
verify_constant_pool_type(context_type *context, int index, unsigned mask)
|
|
1682 |
{
|
|
1683 |
int nconstants = context->nconstants;
|
|
1684 |
unsigned char *type_table = context->constant_types;
|
|
1685 |
unsigned type;
|
|
1686 |
|
|
1687 |
if ((index <= 0) || (index >= nconstants))
|
|
1688 |
CCerror(context, "Illegal constant pool index");
|
|
1689 |
|
|
1690 |
type = type_table[index];
|
|
1691 |
if ((mask & (1 << type)) == 0)
|
|
1692 |
CCerror(context, "Illegal type in constant pool");
|
|
1693 |
}
|
|
1694 |
|
|
1695 |
|
|
1696 |
static void
|
|
1697 |
initialize_dataflow(context_type *context)
|
|
1698 |
{
|
|
1699 |
JNIEnv *env = context->env;
|
|
1700 |
instruction_data_type *idata = context->instruction_data;
|
|
1701 |
int mi = context->method_index;
|
|
1702 |
jclass cb = context->class;
|
|
1703 |
int args_size = JVM_GetMethodIxArgsSize(env, cb, mi);
|
|
1704 |
fullinfo_type *reg_ptr;
|
|
1705 |
fullinfo_type full_info;
|
|
1706 |
const char *p;
|
|
1707 |
const char *signature;
|
|
1708 |
|
|
1709 |
/* Initialize the function entry, since we know everything about it. */
|
|
1710 |
idata[0].stack_info.stack_size = 0;
|
|
1711 |
idata[0].stack_info.stack = NULL;
|
|
1712 |
idata[0].register_info.register_count = args_size;
|
|
1713 |
idata[0].register_info.registers = NEW(fullinfo_type, args_size);
|
|
1714 |
idata[0].register_info.mask_count = 0;
|
|
1715 |
idata[0].register_info.masks = NULL;
|
|
1716 |
idata[0].and_flags = 0; /* nothing needed */
|
|
1717 |
idata[0].or_flags = FLAG_REACHED; /* instruction reached */
|
|
1718 |
reg_ptr = idata[0].register_info.registers;
|
|
1719 |
|
|
1720 |
if ((JVM_GetMethodIxModifiers(env, cb, mi) & JVM_ACC_STATIC) == 0) {
|
|
1721 |
/* A non static method. If this is an <init> method, the first
|
|
1722 |
* argument is an uninitialized object. Otherwise it is an object of
|
|
1723 |
* the given class type. java.lang.Object.<init> is special since
|
|
1724 |
* we don't call its superclass <init> method.
|
|
1725 |
*/
|
|
1726 |
if (JVM_IsConstructorIx(env, cb, mi)
|
|
1727 |
&& context->currentclass_info != context->object_info) {
|
|
1728 |
*reg_ptr++ = MAKE_FULLINFO(ITEM_InitObject, 0, 0);
|
|
1729 |
idata[0].or_flags |= FLAG_NEED_CONSTRUCTOR;
|
|
1730 |
} else {
|
|
1731 |
*reg_ptr++ = context->currentclass_info;
|
|
1732 |
}
|
|
1733 |
}
|
|
1734 |
signature = JVM_GetMethodIxSignatureUTF(env, cb, mi);
|
|
1735 |
check_and_push(context, signature, VM_STRING_UTF);
|
|
1736 |
/* Fill in each of the arguments into the registers. */
|
|
1737 |
for (p = signature + 1; *p != JVM_SIGNATURE_ENDFUNC; ) {
|
|
1738 |
char fieldchar = signature_to_fieldtype(context, &p, &full_info);
|
|
1739 |
switch (fieldchar) {
|
|
1740 |
case 'D': case 'L':
|
|
1741 |
*reg_ptr++ = full_info;
|
|
1742 |
*reg_ptr++ = full_info + 1;
|
|
1743 |
break;
|
|
1744 |
default:
|
|
1745 |
*reg_ptr++ = full_info;
|
|
1746 |
break;
|
|
1747 |
}
|
|
1748 |
}
|
|
1749 |
p++; /* skip over right parenthesis */
|
|
1750 |
if (*p == 'V') {
|
|
1751 |
context->return_type = MAKE_FULLINFO(ITEM_Void, 0, 0);
|
|
1752 |
} else {
|
|
1753 |
signature_to_fieldtype(context, &p, &full_info);
|
|
1754 |
context->return_type = full_info;
|
|
1755 |
}
|
|
1756 |
pop_and_free(context);
|
|
1757 |
/* Indicate that we need to look at the first instruction. */
|
|
1758 |
idata[0].changed = JNI_TRUE;
|
|
1759 |
}
|
|
1760 |
|
|
1761 |
|
|
1762 |
/* Run the data flow analysis, as long as there are things to change. */
|
|
1763 |
static void
|
|
1764 |
run_dataflow(context_type *context) {
|
|
1765 |
JNIEnv *env = context->env;
|
|
1766 |
int mi = context->method_index;
|
|
1767 |
jclass cb = context->class;
|
|
1768 |
int max_stack_size = JVM_GetMethodIxMaxStack(env, cb, mi);
|
|
1769 |
instruction_data_type *idata = context->instruction_data;
|
|
1770 |
int icount = context->instruction_count;
|
|
1771 |
jboolean work_to_do = JNI_TRUE;
|
|
1772 |
unsigned int inumber;
|
|
1773 |
|
|
1774 |
/* Run through the loop, until there is nothing left to do. */
|
|
1775 |
while (work_to_do) {
|
|
1776 |
work_to_do = JNI_FALSE;
|
|
1777 |
for (inumber = 0; inumber < icount; inumber++) {
|
|
1778 |
instruction_data_type *this_idata = &idata[inumber];
|
|
1779 |
if (this_idata->changed) {
|
|
1780 |
register_info_type new_register_info;
|
|
1781 |
stack_info_type new_stack_info;
|
|
1782 |
flag_type new_and_flags, new_or_flags;
|
|
1783 |
|
|
1784 |
this_idata->changed = JNI_FALSE;
|
|
1785 |
work_to_do = JNI_TRUE;
|
|
1786 |
#ifdef DEBUG
|
|
1787 |
if (verify_verbose) {
|
|
1788 |
int opcode = this_idata->opcode;
|
|
1789 |
jio_fprintf(stdout, "Instruction %d: ", inumber);
|
|
1790 |
print_stack(context, &this_idata->stack_info);
|
|
1791 |
print_registers(context, &this_idata->register_info);
|
|
1792 |
print_flags(context,
|
|
1793 |
this_idata->and_flags, this_idata->or_flags);
|
|
1794 |
fflush(stdout);
|
|
1795 |
}
|
|
1796 |
#endif
|
|
1797 |
/* Make sure the registers and flags are appropriate */
|
|
1798 |
check_register_values(context, inumber);
|
|
1799 |
check_flags(context, inumber);
|
|
1800 |
|
|
1801 |
/* Make sure the stack can deal with this instruction */
|
|
1802 |
pop_stack(context, inumber, &new_stack_info);
|
|
1803 |
|
|
1804 |
/* Update the registers and flags */
|
|
1805 |
update_registers(context, inumber, &new_register_info);
|
|
1806 |
update_flags(context, inumber, &new_and_flags, &new_or_flags);
|
|
1807 |
|
|
1808 |
/* Update the stack. */
|
|
1809 |
push_stack(context, inumber, &new_stack_info);
|
|
1810 |
|
|
1811 |
if (new_stack_info.stack_size > max_stack_size)
|
|
1812 |
CCerror(context, "Stack size too large");
|
|
1813 |
#ifdef DEBUG
|
|
1814 |
if (verify_verbose) {
|
|
1815 |
jio_fprintf(stdout, " ");
|
|
1816 |
print_stack(context, &new_stack_info);
|
|
1817 |
print_registers(context, &new_register_info);
|
|
1818 |
print_flags(context, new_and_flags, new_or_flags);
|
|
1819 |
fflush(stdout);
|
|
1820 |
}
|
|
1821 |
#endif
|
|
1822 |
/* Add the new stack and register information to any
|
|
1823 |
* instructions that can follow this instruction. */
|
|
1824 |
merge_into_successors(context, inumber,
|
|
1825 |
&new_register_info, &new_stack_info,
|
|
1826 |
new_and_flags, new_or_flags);
|
|
1827 |
}
|
|
1828 |
}
|
|
1829 |
}
|
|
1830 |
}
|
|
1831 |
|
|
1832 |
|
|
1833 |
/* Make sure that the registers contain a legitimate value for the given
|
|
1834 |
* instruction.
|
|
1835 |
*/
|
|
1836 |
|
|
1837 |
static void
|
|
1838 |
check_register_values(context_type *context, unsigned int inumber)
|
|
1839 |
{
|
|
1840 |
instruction_data_type *idata = context->instruction_data;
|
|
1841 |
instruction_data_type *this_idata = &idata[inumber];
|
|
1842 |
opcode_type opcode = this_idata->opcode;
|
|
1843 |
int operand = this_idata->operand.i;
|
|
1844 |
int register_count = this_idata->register_info.register_count;
|
|
1845 |
fullinfo_type *registers = this_idata->register_info.registers;
|
|
1846 |
jboolean double_word = JNI_FALSE; /* default value */
|
|
1847 |
int type;
|
|
1848 |
|
|
1849 |
switch (opcode) {
|
|
1850 |
default:
|
|
1851 |
return;
|
|
1852 |
case opc_iload: case opc_iinc:
|
|
1853 |
type = ITEM_Integer; break;
|
|
1854 |
case opc_fload:
|
|
1855 |
type = ITEM_Float; break;
|
|
1856 |
case opc_aload:
|
|
1857 |
type = ITEM_Object; break;
|
|
1858 |
case opc_ret:
|
|
1859 |
type = ITEM_ReturnAddress; break;
|
|
1860 |
case opc_lload:
|
|
1861 |
type = ITEM_Long; double_word = JNI_TRUE; break;
|
|
1862 |
case opc_dload:
|
|
1863 |
type = ITEM_Double; double_word = JNI_TRUE; break;
|
|
1864 |
}
|
|
1865 |
if (!double_word) {
|
|
1866 |
fullinfo_type reg;
|
|
1867 |
/* Make sure we don't have an illegal register or one with wrong type */
|
|
1868 |
if (operand >= register_count) {
|
|
1869 |
CCerror(context,
|
|
1870 |
"Accessing value from uninitialized register %d", operand);
|
|
1871 |
}
|
|
1872 |
reg = registers[operand];
|
|
1873 |
|
|
1874 |
if (WITH_ZERO_EXTRA_INFO(reg) == MAKE_FULLINFO(type, 0, 0)) {
|
|
1875 |
/* the register is obviously of the given type */
|
|
1876 |
return;
|
|
1877 |
} else if (GET_INDIRECTION(reg) > 0 && type == ITEM_Object) {
|
|
1878 |
/* address type stuff be used on all arrays */
|
|
1879 |
return;
|
|
1880 |
} else if (GET_ITEM_TYPE(reg) == ITEM_ReturnAddress) {
|
|
1881 |
CCerror(context, "Cannot load return address from register %d",
|
|
1882 |
operand);
|
|
1883 |
/* alternatively
|
|
1884 |
(GET_ITEM_TYPE(reg) == ITEM_ReturnAddress)
|
|
1885 |
&& (opcode == opc_iload)
|
|
1886 |
&& (type == ITEM_Object || type == ITEM_Integer)
|
|
1887 |
but this never occurs
|
|
1888 |
*/
|
|
1889 |
} else if (reg == ITEM_InitObject && type == ITEM_Object) {
|
|
1890 |
return;
|
|
1891 |
} else if (WITH_ZERO_EXTRA_INFO(reg) ==
|
|
1892 |
MAKE_FULLINFO(ITEM_NewObject, 0, 0) &&
|
|
1893 |
type == ITEM_Object) {
|
|
1894 |
return;
|
|
1895 |
} else {
|
|
1896 |
CCerror(context, "Register %d contains wrong type", operand);
|
|
1897 |
}
|
|
1898 |
} else {
|
|
1899 |
/* Make sure we don't have an illegal register or one with wrong type */
|
|
1900 |
if ((operand + 1) >= register_count) {
|
|
1901 |
CCerror(context,
|
|
1902 |
"Accessing value from uninitialized register pair %d/%d",
|
|
1903 |
operand, operand+1);
|
|
1904 |
} else {
|
|
1905 |
if ((registers[operand] == MAKE_FULLINFO(type, 0, 0)) &&
|
|
1906 |
(registers[operand + 1] == MAKE_FULLINFO(type + 1, 0, 0))) {
|
|
1907 |
return;
|
|
1908 |
} else {
|
|
1909 |
CCerror(context, "Register pair %d/%d contains wrong type",
|
|
1910 |
operand, operand+1);
|
|
1911 |
}
|
|
1912 |
}
|
|
1913 |
}
|
|
1914 |
}
|
|
1915 |
|
|
1916 |
|
|
1917 |
/* Make sure the flags contain legitimate values for this instruction.
|
|
1918 |
*/
|
|
1919 |
|
|
1920 |
static void
|
|
1921 |
check_flags(context_type *context, unsigned int inumber)
|
|
1922 |
{
|
|
1923 |
instruction_data_type *idata = context->instruction_data;
|
|
1924 |
instruction_data_type *this_idata = &idata[inumber];
|
|
1925 |
opcode_type opcode = this_idata->opcode;
|
|
1926 |
switch (opcode) {
|
|
1927 |
case opc_return:
|
|
1928 |
/* We need a constructor, but we aren't guaranteed it's called */
|
|
1929 |
if ((this_idata->or_flags & FLAG_NEED_CONSTRUCTOR) &&
|
|
1930 |
!(this_idata->and_flags & FLAG_CONSTRUCTED))
|
|
1931 |
CCerror(context, "Constructor must call super() or this()");
|
|
1932 |
/* fall through */
|
|
1933 |
case opc_ireturn: case opc_lreturn:
|
|
1934 |
case opc_freturn: case opc_dreturn: case opc_areturn:
|
|
1935 |
if (this_idata->or_flags & FLAG_NO_RETURN)
|
|
1936 |
/* This method cannot exit normally */
|
|
1937 |
CCerror(context, "Cannot return normally");
|
|
1938 |
default:
|
|
1939 |
break; /* nothing to do. */
|
|
1940 |
}
|
|
1941 |
}
|
|
1942 |
|
|
1943 |
/* Make sure that the top of the stack contains reasonable values for the
|
|
1944 |
* given instruction. The post-pop values of the stack and its size are
|
|
1945 |
* returned in *new_stack_info.
|
|
1946 |
*/
|
|
1947 |
|
|
1948 |
static void
|
|
1949 |
pop_stack(context_type *context, unsigned int inumber, stack_info_type *new_stack_info)
|
|
1950 |
{
|
|
1951 |
instruction_data_type *idata = context->instruction_data;
|
|
1952 |
instruction_data_type *this_idata = &idata[inumber];
|
|
1953 |
opcode_type opcode = this_idata->opcode;
|
|
1954 |
stack_item_type *stack = this_idata->stack_info.stack;
|
|
1955 |
int stack_size = this_idata->stack_info.stack_size;
|
|
1956 |
char *stack_operands, *p;
|
|
1957 |
char buffer[257]; /* for holding manufactured argument lists */
|
|
1958 |
fullinfo_type stack_extra_info_buffer[256]; /* save info popped off stack */
|
|
1959 |
fullinfo_type *stack_extra_info = &stack_extra_info_buffer[256];
|
|
1960 |
fullinfo_type full_info; /* only used in case of invoke instructions */
|
|
1961 |
fullinfo_type put_full_info; /* only used in case opc_putstatic and opc_putfield */
|
|
1962 |
|
|
1963 |
switch(opcode) {
|
|
1964 |
default:
|
|
1965 |
/* For most instructions, we just use a built-in table */
|
|
1966 |
stack_operands = opcode_in_out[opcode][0];
|
|
1967 |
break;
|
|
1968 |
|
|
1969 |
case opc_putstatic: case opc_putfield: {
|
|
1970 |
/* The top thing on the stack depends on the signature of
|
|
1971 |
* the object. */
|
|
1972 |
int operand = this_idata->operand.i;
|
|
1973 |
const char *signature =
|
|
1974 |
JVM_GetCPFieldSignatureUTF(context->env,
|
|
1975 |
context->class,
|
|
1976 |
operand);
|
|
1977 |
char *ip = buffer;
|
|
1978 |
check_and_push(context, signature, VM_STRING_UTF);
|
|
1979 |
#ifdef DEBUG
|
|
1980 |
if (verify_verbose) {
|
|
1981 |
print_formatted_fieldname(context, operand);
|
|
1982 |
}
|
|
1983 |
#endif
|
|
1984 |
if (opcode == opc_putfield)
|
|
1985 |
*ip++ = 'A'; /* object for putfield */
|
|
1986 |
*ip++ = signature_to_fieldtype(context, &signature, &put_full_info);
|
|
1987 |
*ip = '\0';
|
|
1988 |
stack_operands = buffer;
|
|
1989 |
pop_and_free(context);
|
|
1990 |
break;
|
|
1991 |
}
|
|
1992 |
|
|
1993 |
case opc_invokevirtual: case opc_invokespecial:
|
|
1994 |
case opc_invokeinit: /* invokespecial call to <init> */
|
|
1995 |
case opc_invokestatic: case opc_invokeinterface: {
|
|
1996 |
/* The top stuff on the stack depends on the method signature */
|
|
1997 |
int operand = this_idata->operand.i;
|
|
1998 |
const char *signature =
|
|
1999 |
JVM_GetCPMethodSignatureUTF(context->env,
|
|
2000 |
context->class,
|
|
2001 |
operand);
|
|
2002 |
char *ip = buffer;
|
|
2003 |
const char *p;
|
|
2004 |
check_and_push(context, signature, VM_STRING_UTF);
|
|
2005 |
#ifdef DEBUG
|
|
2006 |
if (verify_verbose) {
|
|
2007 |
print_formatted_methodname(context, operand);
|
|
2008 |
}
|
|
2009 |
#endif
|
|
2010 |
if (opcode != opc_invokestatic)
|
|
2011 |
/* First, push the object */
|
|
2012 |
*ip++ = (opcode == opc_invokeinit ? '@' : 'A');
|
|
2013 |
for (p = signature + 1; *p != JVM_SIGNATURE_ENDFUNC; ) {
|
|
2014 |
*ip++ = signature_to_fieldtype(context, &p, &full_info);
|
|
2015 |
if (ip >= buffer + sizeof(buffer) - 1)
|
|
2016 |
CCerror(context, "Signature %s has too many arguments",
|
|
2017 |
signature);
|
|
2018 |
}
|
|
2019 |
*ip = 0;
|
|
2020 |
stack_operands = buffer;
|
|
2021 |
pop_and_free(context);
|
|
2022 |
break;
|
|
2023 |
}
|
|
2024 |
|
|
2025 |
case opc_multianewarray: {
|
|
2026 |
/* Count can't be larger than 255. So can't overflow buffer */
|
|
2027 |
int count = this_idata->operand2.i; /* number of ints on stack */
|
|
2028 |
memset(buffer, 'I', count);
|
|
2029 |
buffer[count] = '\0';
|
|
2030 |
stack_operands = buffer;
|
|
2031 |
break;
|
|
2032 |
}
|
|
2033 |
|
|
2034 |
} /* of switch */
|
|
2035 |
|
|
2036 |
/* Run through the list of operands >>backwards<< */
|
|
2037 |
for ( p = stack_operands + strlen(stack_operands);
|
|
2038 |
p > stack_operands;
|
|
2039 |
stack = stack->next) {
|
|
2040 |
int type = *--p;
|
|
2041 |
fullinfo_type top_type = stack ? stack->item : 0;
|
|
2042 |
int size = (type == 'D' || type == 'L') ? 2 : 1;
|
|
2043 |
*--stack_extra_info = top_type;
|
|
2044 |
if (stack == NULL)
|
|
2045 |
CCerror(context, "Unable to pop operand off an empty stack");
|
|
2046 |
|
|
2047 |
switch (type) {
|
|
2048 |
case 'I':
|
|
2049 |
if (top_type != MAKE_FULLINFO(ITEM_Integer, 0, 0))
|
|
2050 |
CCerror(context, "Expecting to find integer on stack");
|
|
2051 |
break;
|
|
2052 |
|
|
2053 |
case 'F':
|
|
2054 |
if (top_type != MAKE_FULLINFO(ITEM_Float, 0, 0))
|
|
2055 |
CCerror(context, "Expecting to find float on stack");
|
|
2056 |
break;
|
|
2057 |
|
|
2058 |
case 'A': /* object or array */
|
|
2059 |
if ( (GET_ITEM_TYPE(top_type) != ITEM_Object)
|
|
2060 |
&& (GET_INDIRECTION(top_type) == 0)) {
|
|
2061 |
/* The thing isn't an object or an array. Let's see if it's
|
|
2062 |
* one of the special cases */
|
|
2063 |
if ( (WITH_ZERO_EXTRA_INFO(top_type) ==
|
|
2064 |
MAKE_FULLINFO(ITEM_ReturnAddress, 0, 0))
|
|
2065 |
&& (opcode == opc_astore))
|
|
2066 |
break;
|
|
2067 |
if ( (GET_ITEM_TYPE(top_type) == ITEM_NewObject
|
|
2068 |
|| (GET_ITEM_TYPE(top_type) == ITEM_InitObject))
|
|
2069 |
&& ((opcode == opc_astore) || (opcode == opc_aload)
|
|
2070 |
|| (opcode == opc_ifnull) || (opcode == opc_ifnonnull)))
|
|
2071 |
break;
|
|
2072 |
/* The 2nd edition VM of the specification allows field
|
|
2073 |
* initializations before the superclass initializer,
|
|
2074 |
* if the field is defined within the current class.
|
|
2075 |
*/
|
|
2076 |
if ( (GET_ITEM_TYPE(top_type) == ITEM_InitObject)
|
|
2077 |
&& (opcode == opc_putfield)) {
|
|
2078 |
int operand = this_idata->operand.i;
|
|
2079 |
int access_bits = JVM_GetCPFieldModifiers(context->env,
|
|
2080 |
context->class,
|
|
2081 |
operand,
|
|
2082 |
context->class);
|
|
2083 |
/* Note: This relies on the fact that
|
|
2084 |
* JVM_GetCPFieldModifiers retrieves only local fields,
|
|
2085 |
* and does not respect inheritance.
|
|
2086 |
*/
|
|
2087 |
if (access_bits != -1) {
|
|
2088 |
if ( cp_index_to_class_fullinfo(context, operand, JVM_CONSTANT_Fieldref) ==
|
|
2089 |
context->currentclass_info ) {
|
|
2090 |
top_type = context->currentclass_info;
|
|
2091 |
*stack_extra_info = top_type;
|
|
2092 |
break;
|
|
2093 |
}
|
|
2094 |
}
|
|
2095 |
}
|
|
2096 |
CCerror(context, "Expecting to find object/array on stack");
|
|
2097 |
}
|
|
2098 |
break;
|
|
2099 |
|
|
2100 |
case '@': { /* unitialized object, for call to <init> */
|
|
2101 |
int item_type = GET_ITEM_TYPE(top_type);
|
|
2102 |
if (item_type != ITEM_NewObject && item_type != ITEM_InitObject)
|
|
2103 |
CCerror(context,
|
|
2104 |
"Expecting to find unitialized object on stack");
|
|
2105 |
break;
|
|
2106 |
}
|
|
2107 |
|
|
2108 |
case 'O': /* object, not array */
|
|
2109 |
if (WITH_ZERO_EXTRA_INFO(top_type) !=
|
|
2110 |
MAKE_FULLINFO(ITEM_Object, 0, 0))
|
|
2111 |
CCerror(context, "Expecting to find object on stack");
|
|
2112 |
break;
|
|
2113 |
|
|
2114 |
case 'a': /* integer, object, or array */
|
|
2115 |
if ( (top_type != MAKE_FULLINFO(ITEM_Integer, 0, 0))
|
|
2116 |
&& (GET_ITEM_TYPE(top_type) != ITEM_Object)
|
|
2117 |
&& (GET_INDIRECTION(top_type) == 0))
|
|
2118 |
CCerror(context,
|
|
2119 |
"Expecting to find object, array, or int on stack");
|
|
2120 |
break;
|
|
2121 |
|
|
2122 |
case 'D': /* double */
|
|
2123 |
if (top_type != MAKE_FULLINFO(ITEM_Double, 0, 0))
|
|
2124 |
CCerror(context, "Expecting to find double on stack");
|
|
2125 |
break;
|
|
2126 |
|
|
2127 |
case 'L': /* long */
|
|
2128 |
if (top_type != MAKE_FULLINFO(ITEM_Long, 0, 0))
|
|
2129 |
CCerror(context, "Expecting to find long on stack");
|
|
2130 |
break;
|
|
2131 |
|
|
2132 |
case ']': /* array of some type */
|
|
2133 |
if (top_type == NULL_FULLINFO) {
|
|
2134 |
/* do nothing */
|
|
2135 |
} else switch(p[-1]) {
|
|
2136 |
case 'I': /* array of integers */
|
|
2137 |
if (top_type != MAKE_FULLINFO(ITEM_Integer, 1, 0) &&
|
|
2138 |
top_type != NULL_FULLINFO)
|
|
2139 |
CCerror(context,
|
|
2140 |
"Expecting to find array of ints on stack");
|
|
2141 |
break;
|
|
2142 |
|
|
2143 |
case 'L': /* array of longs */
|
|
2144 |
if (top_type != MAKE_FULLINFO(ITEM_Long, 1, 0))
|
|
2145 |
CCerror(context,
|
|
2146 |
"Expecting to find array of longs on stack");
|
|
2147 |
break;
|
|
2148 |
|
|
2149 |
case 'F': /* array of floats */
|
|
2150 |
if (top_type != MAKE_FULLINFO(ITEM_Float, 1, 0))
|
|
2151 |
CCerror(context,
|
|
2152 |
"Expecting to find array of floats on stack");
|
|
2153 |
break;
|
|
2154 |
|
|
2155 |
case 'D': /* array of doubles */
|
|
2156 |
if (top_type != MAKE_FULLINFO(ITEM_Double, 1, 0))
|
|
2157 |
CCerror(context,
|
|
2158 |
"Expecting to find array of doubles on stack");
|
|
2159 |
break;
|
|
2160 |
|
|
2161 |
case 'A': { /* array of addresses (arrays or objects) */
|
|
2162 |
int indirection = GET_INDIRECTION(top_type);
|
|
2163 |
if ((indirection == 0) ||
|
|
2164 |
((indirection == 1) &&
|
|
2165 |
(GET_ITEM_TYPE(top_type) != ITEM_Object)))
|
|
2166 |
CCerror(context,
|
|
2167 |
"Expecting to find array of objects or arrays "
|
|
2168 |
"on stack");
|
|
2169 |
break;
|
|
2170 |
}
|
|
2171 |
|
|
2172 |
case 'B': /* array of bytes */
|
|
2173 |
if (top_type != MAKE_FULLINFO(ITEM_Byte, 1, 0))
|
|
2174 |
CCerror(context,
|
|
2175 |
"Expecting to find array of bytes on stack");
|
|
2176 |
break;
|
|
2177 |
|
|
2178 |
case 'C': /* array of characters */
|
|
2179 |
if (top_type != MAKE_FULLINFO(ITEM_Char, 1, 0))
|
|
2180 |
CCerror(context,
|
|
2181 |
"Expecting to find array of chars on stack");
|
|
2182 |
break;
|
|
2183 |
|
|
2184 |
case 'S': /* array of shorts */
|
|
2185 |
if (top_type != MAKE_FULLINFO(ITEM_Short, 1, 0))
|
|
2186 |
CCerror(context,
|
|
2187 |
"Expecting to find array of shorts on stack");
|
|
2188 |
break;
|
|
2189 |
|
|
2190 |
case '?': /* any type of array is okay */
|
|
2191 |
if (GET_INDIRECTION(top_type) == 0)
|
|
2192 |
CCerror(context,
|
|
2193 |
"Expecting to find array on stack");
|
|
2194 |
break;
|
|
2195 |
|
|
2196 |
default:
|
|
2197 |
CCerror(context, "Internal error #1");
|
|
2198 |
break;
|
|
2199 |
}
|
|
2200 |
p -= 2; /* skip over [ <char> */
|
|
2201 |
break;
|
|
2202 |
|
|
2203 |
case '1': case '2': case '3': case '4': /* stack swapping */
|
|
2204 |
if (top_type == MAKE_FULLINFO(ITEM_Double, 0, 0)
|
|
2205 |
|| top_type == MAKE_FULLINFO(ITEM_Long, 0, 0)) {
|
|
2206 |
if ((p > stack_operands) && (p[-1] == '+')) {
|
|
2207 |
context->swap_table[type - '1'] = top_type + 1;
|
|
2208 |
context->swap_table[p[-2] - '1'] = top_type;
|
|
2209 |
size = 2;
|
|
2210 |
p -= 2;
|
|
2211 |
} else {
|
|
2212 |
CCerror(context,
|
|
2213 |
"Attempt to split long or double on the stack");
|
|
2214 |
}
|
|
2215 |
} else {
|
|
2216 |
context->swap_table[type - '1'] = stack->item;
|
|
2217 |
if ((p > stack_operands) && (p[-1] == '+'))
|
|
2218 |
p--; /* ignore */
|
|
2219 |
}
|
|
2220 |
break;
|
|
2221 |
case '+': /* these should have been caught. */
|
|
2222 |
default:
|
|
2223 |
CCerror(context, "Internal error #2");
|
|
2224 |
}
|
|
2225 |
stack_size -= size;
|
|
2226 |
}
|
|
2227 |
|
|
2228 |
/* For many of the opcodes that had an "A" in their field, we really
|
|
2229 |
* need to go back and do a little bit more accurate testing. We can, of
|
|
2230 |
* course, assume that the minimal type checking has already been done.
|
|
2231 |
*/
|
|
2232 |
switch (opcode) {
|
|
2233 |
default: break;
|
|
2234 |
case opc_aastore: { /* array index object */
|
|
2235 |
fullinfo_type array_type = stack_extra_info[0];
|
|
2236 |
fullinfo_type object_type = stack_extra_info[2];
|
|
2237 |
fullinfo_type target_type = decrement_indirection(array_type);
|
|
2238 |
if ((GET_ITEM_TYPE(object_type) != ITEM_Object)
|
|
2239 |
&& (GET_INDIRECTION(object_type) == 0)) {
|
|
2240 |
CCerror(context, "Expecting reference type on operand stack in aastore");
|
|
2241 |
}
|
|
2242 |
if ((GET_ITEM_TYPE(target_type) != ITEM_Object)
|
|
2243 |
&& (GET_INDIRECTION(target_type) == 0)) {
|
|
2244 |
CCerror(context, "Component type of the array must be reference type in aastore");
|
|
2245 |
}
|
|
2246 |
break;
|
|
2247 |
}
|
|
2248 |
|
|
2249 |
case opc_putfield:
|
|
2250 |
case opc_getfield:
|
|
2251 |
case opc_putstatic: {
|
|
2252 |
int operand = this_idata->operand.i;
|
|
2253 |
fullinfo_type stack_object = stack_extra_info[0];
|
|
2254 |
if (opcode == opc_putfield || opcode == opc_getfield) {
|
|
2255 |
if (!isAssignableTo
|
|
2256 |
(context,
|
|
2257 |
stack_object,
|
|
2258 |
cp_index_to_class_fullinfo
|
|
2259 |
(context, operand, JVM_CONSTANT_Fieldref))) {
|
|
2260 |
CCerror(context,
|
|
2261 |
"Incompatible type for getting or setting field");
|
|
2262 |
}
|
|
2263 |
if (this_idata->protected &&
|
|
2264 |
!isAssignableTo(context, stack_object,
|
|
2265 |
context->currentclass_info)) {
|
|
2266 |
CCerror(context, "Bad access to protected data");
|
|
2267 |
}
|
|
2268 |
}
|
|
2269 |
if (opcode == opc_putfield || opcode == opc_putstatic) {
|
|
2270 |
int item = (opcode == opc_putfield ? 1 : 0);
|
|
2271 |
if (!isAssignableTo(context,
|
|
2272 |
stack_extra_info[item], put_full_info)) {
|
|
2273 |
CCerror(context, "Bad type in putfield/putstatic");
|
|
2274 |
}
|
|
2275 |
}
|
|
2276 |
break;
|
|
2277 |
}
|
|
2278 |
|
|
2279 |
case opc_athrow:
|
|
2280 |
if (!isAssignableTo(context, stack_extra_info[0],
|
|
2281 |
context->throwable_info)) {
|
|
2282 |
CCerror(context, "Can only throw Throwable objects");
|
|
2283 |
}
|
|
2284 |
break;
|
|
2285 |
|
|
2286 |
case opc_aaload: { /* array index */
|
|
2287 |
/* We need to pass the information to the stack updater */
|
|
2288 |
fullinfo_type array_type = stack_extra_info[0];
|
|
2289 |
context->swap_table[0] = decrement_indirection(array_type);
|
|
2290 |
break;
|
|
2291 |
}
|
|
2292 |
|
|
2293 |
case opc_invokevirtual: case opc_invokespecial:
|
|
2294 |
case opc_invokeinit:
|
|
2295 |
case opc_invokeinterface: case opc_invokestatic: {
|
|
2296 |
int operand = this_idata->operand.i;
|
|
2297 |
const char *signature =
|
|
2298 |
JVM_GetCPMethodSignatureUTF(context->env,
|
|
2299 |
context->class,
|
|
2300 |
operand);
|
|
2301 |
int item;
|
|
2302 |
const char *p;
|
|
2303 |
check_and_push(context, signature, VM_STRING_UTF);
|
|
2304 |
if (opcode == opc_invokestatic) {
|
|
2305 |
item = 0;
|
|
2306 |
} else if (opcode == opc_invokeinit) {
|
|
2307 |
fullinfo_type init_type = this_idata->operand2.fi;
|
|
2308 |
fullinfo_type object_type = stack_extra_info[0];
|
|
2309 |
context->swap_table[0] = object_type; /* save value */
|
|
2310 |
if (GET_ITEM_TYPE(stack_extra_info[0]) == ITEM_NewObject) {
|
|
2311 |
/* We better be calling the appropriate init. Find the
|
|
2312 |
* inumber of the "opc_new" instruction", and figure
|
|
2313 |
* out what the type really is.
|
|
2314 |
*/
|
|
2315 |
unsigned int new_inumber = GET_EXTRA_INFO(stack_extra_info[0]);
|
|
2316 |
fullinfo_type target_type = idata[new_inumber].operand2.fi;
|
|
2317 |
context->swap_table[1] = target_type;
|
|
2318 |
|
|
2319 |
if (target_type != init_type) {
|
|
2320 |
CCerror(context, "Call to wrong initialization method");
|
|
2321 |
}
|
|
2322 |
if (this_idata->protected
|
|
2323 |
&& context->major_version > LDC_CLASS_MAJOR_VERSION
|
|
2324 |
&& !isAssignableTo(context, object_type,
|
|
2325 |
context->currentclass_info)) {
|
|
2326 |
CCerror(context, "Bad access to protected data");
|
|
2327 |
}
|
|
2328 |
} else {
|
|
2329 |
/* We better be calling super() or this(). */
|
|
2330 |
if (init_type != context->superclass_info &&
|
|
2331 |
init_type != context->currentclass_info) {
|
|
2332 |
CCerror(context, "Call to wrong initialization method");
|
|
2333 |
}
|
|
2334 |
context->swap_table[1] = context->currentclass_info;
|
|
2335 |
}
|
|
2336 |
item = 1;
|
|
2337 |
} else {
|
|
2338 |
fullinfo_type target_type = this_idata->operand2.fi;
|
|
2339 |
fullinfo_type object_type = stack_extra_info[0];
|
|
2340 |
if (!isAssignableTo(context, object_type, target_type)){
|
|
2341 |
CCerror(context,
|
|
2342 |
"Incompatible object argument for function call");
|
|
2343 |
}
|
|
2344 |
if (opcode == opc_invokespecial
|
|
2345 |
&& !isAssignableTo(context, object_type,
|
|
2346 |
context->currentclass_info)) {
|
|
2347 |
/* Make sure object argument is assignment compatible to current class */
|
|
2348 |
CCerror(context,
|
|
2349 |
"Incompatible object argument for invokespecial");
|
|
2350 |
}
|
|
2351 |
if (this_idata->protected
|
|
2352 |
&& !isAssignableTo(context, object_type,
|
|
2353 |
context->currentclass_info)) {
|
|
2354 |
/* This is ugly. Special dispensation. Arrays pretend to
|
|
2355 |
implement public Object clone() even though they don't */
|
|
2356 |
const char *utfName =
|
|
2357 |
JVM_GetCPMethodNameUTF(context->env,
|
|
2358 |
context->class,
|
|
2359 |
this_idata->operand.i);
|
|
2360 |
int is_clone = utfName && (strcmp(utfName, "clone") == 0);
|
|
2361 |
JVM_ReleaseUTF(utfName);
|
|
2362 |
|
|
2363 |
if ((target_type == context->object_info) &&
|
|
2364 |
(GET_INDIRECTION(object_type) > 0) &&
|
|
2365 |
is_clone) {
|
|
2366 |
} else {
|
|
2367 |
CCerror(context, "Bad access to protected data");
|
|
2368 |
}
|
|
2369 |
}
|
|
2370 |
item = 1;
|
|
2371 |
}
|
|
2372 |
for (p = signature + 1; *p != JVM_SIGNATURE_ENDFUNC; item++)
|
|
2373 |
if (signature_to_fieldtype(context, &p, &full_info) == 'A') {
|
|
2374 |
if (!isAssignableTo(context,
|
|
2375 |
stack_extra_info[item], full_info)) {
|
|
2376 |
CCerror(context, "Incompatible argument to function");
|
|
2377 |
}
|
|
2378 |
}
|
|
2379 |
|
|
2380 |
pop_and_free(context);
|
|
2381 |
break;
|
|
2382 |
}
|
|
2383 |
|
|
2384 |
case opc_return:
|
|
2385 |
if (context->return_type != MAKE_FULLINFO(ITEM_Void, 0, 0))
|
|
2386 |
CCerror(context, "Wrong return type in function");
|
|
2387 |
break;
|
|
2388 |
|
|
2389 |
case opc_ireturn: case opc_lreturn: case opc_freturn:
|
|
2390 |
case opc_dreturn: case opc_areturn: {
|
|
2391 |
fullinfo_type target_type = context->return_type;
|
|
2392 |
fullinfo_type object_type = stack_extra_info[0];
|
|
2393 |
if (!isAssignableTo(context, object_type, target_type)) {
|
|
2394 |
CCerror(context, "Wrong return type in function");
|
|
2395 |
}
|
|
2396 |
break;
|
|
2397 |
}
|
|
2398 |
|
|
2399 |
case opc_new: {
|
|
2400 |
/* Make sure that nothing on the stack already looks like what
|
|
2401 |
* we want to create. I can't image how this could possibly happen
|
|
2402 |
* but we should test for it anyway, since if it could happen, the
|
|
2403 |
* result would be an unitialized object being able to masquerade
|
|
2404 |
* as an initialized one.
|
|
2405 |
*/
|
|
2406 |
stack_item_type *item;
|
|
2407 |
for (item = stack; item != NULL; item = item->next) {
|
|
2408 |
if (item->item == this_idata->operand.fi) {
|
|
2409 |
CCerror(context,
|
|
2410 |
"Uninitialized object on stack at creating point");
|
|
2411 |
}
|
|
2412 |
}
|
|
2413 |
/* Info for update_registers */
|
|
2414 |
context->swap_table[0] = this_idata->operand.fi;
|
|
2415 |
context->swap_table[1] = MAKE_FULLINFO(ITEM_Bogus, 0, 0);
|
|
2416 |
|
|
2417 |
break;
|
|
2418 |
}
|
|
2419 |
}
|
|
2420 |
new_stack_info->stack = stack;
|
|
2421 |
new_stack_info->stack_size = stack_size;
|
|
2422 |
}
|
|
2423 |
|
|
2424 |
|
|
2425 |
/* We've already determined that the instruction is legal. Perform the
|
|
2426 |
* operation on the registers, and return the updated results in
|
|
2427 |
* new_register_count_p and new_registers.
|
|
2428 |
*/
|
|
2429 |
|
|
2430 |
static void
|
|
2431 |
update_registers(context_type *context, unsigned int inumber,
|
|
2432 |
register_info_type *new_register_info)
|
|
2433 |
{
|
|
2434 |
instruction_data_type *idata = context->instruction_data;
|
|
2435 |
instruction_data_type *this_idata = &idata[inumber];
|
|
2436 |
opcode_type opcode = this_idata->opcode;
|
|
2437 |
int operand = this_idata->operand.i;
|
|
2438 |
int register_count = this_idata->register_info.register_count;
|
|
2439 |
fullinfo_type *registers = this_idata->register_info.registers;
|
|
2440 |
stack_item_type *stack = this_idata->stack_info.stack;
|
|
2441 |
int mask_count = this_idata->register_info.mask_count;
|
|
2442 |
mask_type *masks = this_idata->register_info.masks;
|
|
2443 |
|
|
2444 |
/* Use these as default new values. */
|
|
2445 |
int new_register_count = register_count;
|
|
2446 |
int new_mask_count = mask_count;
|
|
2447 |
fullinfo_type *new_registers = registers;
|
|
2448 |
mask_type *new_masks = masks;
|
|
2449 |
|
|
2450 |
enum { ACCESS_NONE, ACCESS_SINGLE, ACCESS_DOUBLE } access = ACCESS_NONE;
|
|
2451 |
int i;
|
|
2452 |
|
|
2453 |
/* Remember, we've already verified the type at the top of the stack. */
|
|
2454 |
switch (opcode) {
|
|
2455 |
default: break;
|
|
2456 |
case opc_istore: case opc_fstore: case opc_astore:
|
|
2457 |
access = ACCESS_SINGLE;
|
|
2458 |
goto continue_store;
|
|
2459 |
|
|
2460 |
case opc_lstore: case opc_dstore:
|
|
2461 |
access = ACCESS_DOUBLE;
|
|
2462 |
goto continue_store;
|
|
2463 |
|
|
2464 |
continue_store: {
|
|
2465 |
/* We have a modification to the registers. Copy them if needed. */
|
|
2466 |
fullinfo_type stack_top_type = stack->item;
|
|
2467 |
int max_operand = operand + ((access == ACCESS_DOUBLE) ? 1 : 0);
|
|
2468 |
|
|
2469 |
if ( max_operand < register_count
|
|
2470 |
&& registers[operand] == stack_top_type
|
|
2471 |
&& ((access == ACCESS_SINGLE) ||
|
|
2472 |
(registers[operand + 1]== stack_top_type + 1)))
|
|
2473 |
/* No changes have been made to the registers. */
|
|
2474 |
break;
|
|
2475 |
new_register_count = MAX(max_operand + 1, register_count);
|
|
2476 |
new_registers = NEW(fullinfo_type, new_register_count);
|
|
2477 |
for (i = 0; i < register_count; i++)
|
|
2478 |
new_registers[i] = registers[i];
|
|
2479 |
for (i = register_count; i < new_register_count; i++)
|
|
2480 |
new_registers[i] = MAKE_FULLINFO(ITEM_Bogus, 0, 0);
|
|
2481 |
new_registers[operand] = stack_top_type;
|
|
2482 |
if (access == ACCESS_DOUBLE)
|
|
2483 |
new_registers[operand + 1] = stack_top_type + 1;
|
|
2484 |
break;
|
|
2485 |
}
|
|
2486 |
|
|
2487 |
case opc_iload: case opc_fload: case opc_aload:
|
|
2488 |
case opc_iinc: case opc_ret:
|
|
2489 |
access = ACCESS_SINGLE;
|
|
2490 |
break;
|
|
2491 |
|
|
2492 |
case opc_lload: case opc_dload:
|
|
2493 |
access = ACCESS_DOUBLE;
|
|
2494 |
break;
|
|
2495 |
|
|
2496 |
case opc_jsr: case opc_jsr_w:
|
|
2497 |
for (i = 0; i < new_mask_count; i++)
|
|
2498 |
if (new_masks[i].entry == operand)
|
|
2499 |
CCerror(context, "Recursive call to jsr entry");
|
|
2500 |
new_masks = add_to_masks(context, masks, mask_count, operand);
|
|
2501 |
new_mask_count++;
|
|
2502 |
break;
|
|
2503 |
|
|
2504 |
case opc_invokeinit:
|
|
2505 |
case opc_new: {
|
|
2506 |
/* For invokeinit, an uninitialized object has been initialized.
|
|
2507 |
* For new, all previous occurrences of an uninitialized object
|
|
2508 |
* from the same instruction must be made bogus.
|
|
2509 |
* We find all occurrences of swap_table[0] in the registers, and
|
|
2510 |
* replace them with swap_table[1];
|
|
2511 |
*/
|
|
2512 |
fullinfo_type from = context->swap_table[0];
|
|
2513 |
fullinfo_type to = context->swap_table[1];
|
|
2514 |
|
|
2515 |
int i;
|
|
2516 |
for (i = 0; i < register_count; i++) {
|
|
2517 |
if (new_registers[i] == from) {
|
|
2518 |
/* Found a match */
|
|
2519 |
break;
|
|
2520 |
}
|
|
2521 |
}
|
|
2522 |
if (i < register_count) { /* We broke out loop for match */
|
|
2523 |
/* We have to change registers, and possibly a mask */
|
|
2524 |
jboolean copied_mask = JNI_FALSE;
|
|
2525 |
int k;
|
|
2526 |
new_registers = NEW(fullinfo_type, register_count);
|
|
2527 |
memcpy(new_registers, registers,
|
|
2528 |
register_count * sizeof(registers[0]));
|
|
2529 |
for ( ; i < register_count; i++) {
|
|
2530 |
if (new_registers[i] == from) {
|
|
2531 |
new_registers[i] = to;
|
|
2532 |
for (k = 0; k < new_mask_count; k++) {
|
|
2533 |
if (!IS_BIT_SET(new_masks[k].modifies, i)) {
|
|
2534 |
if (!copied_mask) {
|
|
2535 |
new_masks = copy_masks(context, new_masks,
|
|
2536 |
mask_count);
|
|
2537 |
copied_mask = JNI_TRUE;
|
|
2538 |
}
|
|
2539 |
SET_BIT(new_masks[k].modifies, i);
|
|
2540 |
}
|
|
2541 |
}
|
|
2542 |
}
|
|
2543 |
}
|
|
2544 |
}
|
|
2545 |
break;
|
|
2546 |
}
|
|
2547 |
} /* of switch */
|
|
2548 |
|
|
2549 |
if ((access != ACCESS_NONE) && (new_mask_count > 0)) {
|
|
2550 |
int i, j;
|
|
2551 |
for (i = 0; i < new_mask_count; i++) {
|
|
2552 |
int *mask = new_masks[i].modifies;
|
|
2553 |
if ((!IS_BIT_SET(mask, operand)) ||
|
|
2554 |
((access == ACCESS_DOUBLE) &&
|
|
2555 |
!IS_BIT_SET(mask, operand + 1))) {
|
|
2556 |
new_masks = copy_masks(context, new_masks, mask_count);
|
|
2557 |
for (j = i; j < new_mask_count; j++) {
|
|
2558 |
SET_BIT(new_masks[j].modifies, operand);
|
|
2559 |
if (access == ACCESS_DOUBLE)
|
|
2560 |
SET_BIT(new_masks[j].modifies, operand + 1);
|
|
2561 |
}
|
|
2562 |
break;
|
|
2563 |
}
|
|
2564 |
}
|
|
2565 |
}
|
|
2566 |
|
|
2567 |
new_register_info->register_count = new_register_count;
|
|
2568 |
new_register_info->registers = new_registers;
|
|
2569 |
new_register_info->masks = new_masks;
|
|
2570 |
new_register_info->mask_count = new_mask_count;
|
|
2571 |
}
|
|
2572 |
|
|
2573 |
|
|
2574 |
|
|
2575 |
/* We've already determined that the instruction is legal, and have updated
|
|
2576 |
* the registers. Update the flags, too.
|
|
2577 |
*/
|
|
2578 |
|
|
2579 |
|
|
2580 |
static void
|
|
2581 |
update_flags(context_type *context, unsigned int inumber,
|
|
2582 |
flag_type *new_and_flags, flag_type *new_or_flags)
|
|
2583 |
|
|
2584 |
{
|
|
2585 |
instruction_data_type *idata = context->instruction_data;
|
|
2586 |
instruction_data_type *this_idata = &idata[inumber];
|
|
2587 |
flag_type and_flags = this_idata->and_flags;
|
|
2588 |
flag_type or_flags = this_idata->or_flags;
|
|
2589 |
|
|
2590 |
/* Set the "we've done a constructor" flag */
|
|
2591 |
if (this_idata->opcode == opc_invokeinit) {
|
|
2592 |
fullinfo_type from = context->swap_table[0];
|
|
2593 |
if (from == MAKE_FULLINFO(ITEM_InitObject, 0, 0))
|
|
2594 |
and_flags |= FLAG_CONSTRUCTED;
|
|
2595 |
}
|
|
2596 |
*new_and_flags = and_flags;
|
|
2597 |
*new_or_flags = or_flags;
|
|
2598 |
}
|
|
2599 |
|
|
2600 |
|
|
2601 |
|
|
2602 |
/* We've already determined that the instruction is legal. Perform the
|
|
2603 |
* operation on the stack;
|
|
2604 |
*
|
|
2605 |
* new_stack_size_p and new_stack_p point to the results after the pops have
|
|
2606 |
* already been done. Do the pushes, and then put the results back there.
|
|
2607 |
*/
|
|
2608 |
|
|
2609 |
static void
|
|
2610 |
push_stack(context_type *context, unsigned int inumber, stack_info_type *new_stack_info)
|
|
2611 |
{
|
|
2612 |
instruction_data_type *idata = context->instruction_data;
|
|
2613 |
instruction_data_type *this_idata = &idata[inumber];
|
|
2614 |
opcode_type opcode = this_idata->opcode;
|
|
2615 |
int operand = this_idata->operand.i;
|
|
2616 |
|
|
2617 |
int stack_size = new_stack_info->stack_size;
|
|
2618 |
stack_item_type *stack = new_stack_info->stack;
|
|
2619 |
char *stack_results;
|
|
2620 |
|
|
2621 |
fullinfo_type full_info = 0;
|
|
2622 |
char buffer[5], *p; /* actually [2] is big enough */
|
|
2623 |
|
|
2624 |
/* We need to look at all those opcodes in which either we can't tell the
|
|
2625 |
* value pushed onto the stack from the opcode, or in which the value
|
|
2626 |
* pushed onto the stack is an object or array. For the latter, we need
|
|
2627 |
* to make sure that full_info is set to the right value.
|
|
2628 |
*/
|
|
2629 |
switch(opcode) {
|
|
2630 |
default:
|
|
2631 |
stack_results = opcode_in_out[opcode][1];
|
|
2632 |
break;
|
|
2633 |
|
|
2634 |
case opc_ldc: case opc_ldc_w: case opc_ldc2_w: {
|
|
2635 |
/* Look to constant pool to determine correct result. */
|
|
2636 |
unsigned char *type_table = context->constant_types;
|
|
2637 |
switch (type_table[operand]) {
|
|
2638 |
case JVM_CONSTANT_Integer:
|
|
2639 |
stack_results = "I"; break;
|
|
2640 |
case JVM_CONSTANT_Float:
|
|
2641 |
stack_results = "F"; break;
|
|
2642 |
case JVM_CONSTANT_Double:
|
|
2643 |
stack_results = "D"; break;
|
|
2644 |
case JVM_CONSTANT_Long:
|
|
2645 |
stack_results = "L"; break;
|
|
2646 |
case JVM_CONSTANT_String:
|
|
2647 |
stack_results = "A";
|
|
2648 |
full_info = context->string_info;
|
|
2649 |
break;
|
|
2650 |
case JVM_CONSTANT_Class:
|
|
2651 |
if (context->major_version < LDC_CLASS_MAJOR_VERSION)
|
|
2652 |
CCerror(context, "Internal error #3");
|
|
2653 |
stack_results = "A";
|
|
2654 |
full_info = make_class_info_from_name(context,
|
|
2655 |
"java/lang/Class");
|
|
2656 |
break;
|
|
2657 |
default:
|
|
2658 |
CCerror(context, "Internal error #3");
|
|
2659 |
stack_results = ""; /* Never reached: keep lint happy */
|
|
2660 |
}
|
|
2661 |
break;
|
|
2662 |
}
|
|
2663 |
|
|
2664 |
case opc_getstatic: case opc_getfield: {
|
|
2665 |
/* Look to signature to determine correct result. */
|
|
2666 |
int operand = this_idata->operand.i;
|
|
2667 |
const char *signature = JVM_GetCPFieldSignatureUTF(context->env,
|
|
2668 |
context->class,
|
|
2669 |
operand);
|
|
2670 |
check_and_push(context, signature, VM_STRING_UTF);
|
|
2671 |
#ifdef DEBUG
|
|
2672 |
if (verify_verbose) {
|
|
2673 |
print_formatted_fieldname(context, operand);
|
|
2674 |
}
|
|
2675 |
#endif
|
|
2676 |
buffer[0] = signature_to_fieldtype(context, &signature, &full_info);
|
|
2677 |
buffer[1] = '\0';
|
|
2678 |
stack_results = buffer;
|
|
2679 |
pop_and_free(context);
|
|
2680 |
break;
|
|
2681 |
}
|
|
2682 |
|
|
2683 |
case opc_invokevirtual: case opc_invokespecial:
|
|
2684 |
case opc_invokeinit:
|
|
2685 |
case opc_invokestatic: case opc_invokeinterface: {
|
|
2686 |
/* Look to signature to determine correct result. */
|
|
2687 |
int operand = this_idata->operand.i;
|
|
2688 |
const char *signature = JVM_GetCPMethodSignatureUTF(context->env,
|
|
2689 |
context->class,
|
|
2690 |
operand);
|
|
2691 |
const char *result_signature;
|
|
2692 |
check_and_push(context, signature, VM_STRING_UTF);
|
|
2693 |
result_signature = strchr(signature, JVM_SIGNATURE_ENDFUNC) + 1;
|
|
2694 |
if (result_signature[0] == JVM_SIGNATURE_VOID) {
|
|
2695 |
stack_results = "";
|
|
2696 |
} else {
|
|
2697 |
buffer[0] = signature_to_fieldtype(context, &result_signature,
|
|
2698 |
&full_info);
|
|
2699 |
buffer[1] = '\0';
|
|
2700 |
stack_results = buffer;
|
|
2701 |
}
|
|
2702 |
pop_and_free(context);
|
|
2703 |
break;
|
|
2704 |
}
|
|
2705 |
|
|
2706 |
case opc_aconst_null:
|
|
2707 |
stack_results = opcode_in_out[opcode][1];
|
|
2708 |
full_info = NULL_FULLINFO; /* special NULL */
|
|
2709 |
break;
|
|
2710 |
|
|
2711 |
case opc_new:
|
|
2712 |
case opc_checkcast:
|
|
2713 |
case opc_newarray:
|
|
2714 |
case opc_anewarray:
|
|
2715 |
case opc_multianewarray:
|
|
2716 |
stack_results = opcode_in_out[opcode][1];
|
|
2717 |
/* Conveniently, this result type is stored here */
|
|
2718 |
full_info = this_idata->operand.fi;
|
|
2719 |
break;
|
|
2720 |
|
|
2721 |
case opc_aaload:
|
|
2722 |
stack_results = opcode_in_out[opcode][1];
|
|
2723 |
/* pop_stack() saved value for us. */
|
|
2724 |
full_info = context->swap_table[0];
|
|
2725 |
break;
|
|
2726 |
|
|
2727 |
case opc_aload:
|
|
2728 |
stack_results = opcode_in_out[opcode][1];
|
|
2729 |
/* The register hasn't been modified, so we can use its value. */
|
|
2730 |
full_info = this_idata->register_info.registers[operand];
|
|
2731 |
break;
|
|
2732 |
} /* of switch */
|
|
2733 |
|
|
2734 |
for (p = stack_results; *p != 0; p++) {
|
|
2735 |
int type = *p;
|
|
2736 |
stack_item_type *new_item = NEW(stack_item_type, 1);
|
|
2737 |
new_item->next = stack;
|
|
2738 |
stack = new_item;
|
|
2739 |
switch (type) {
|
|
2740 |
case 'I':
|
|
2741 |
stack->item = MAKE_FULLINFO(ITEM_Integer, 0, 0); break;
|
|
2742 |
case 'F':
|
|
2743 |
stack->item = MAKE_FULLINFO(ITEM_Float, 0, 0); break;
|
|
2744 |
case 'D':
|
|
2745 |
stack->item = MAKE_FULLINFO(ITEM_Double, 0, 0);
|
|
2746 |
stack_size++; break;
|
|
2747 |
case 'L':
|
|
2748 |
stack->item = MAKE_FULLINFO(ITEM_Long, 0, 0);
|
|
2749 |
stack_size++; break;
|
|
2750 |
case 'R':
|
|
2751 |
stack->item = MAKE_FULLINFO(ITEM_ReturnAddress, 0, operand);
|
|
2752 |
break;
|
|
2753 |
case '1': case '2': case '3': case '4': {
|
|
2754 |
/* Get the info saved in the swap_table */
|
|
2755 |
fullinfo_type stype = context->swap_table[type - '1'];
|
|
2756 |
stack->item = stype;
|
|
2757 |
if (stype == MAKE_FULLINFO(ITEM_Long, 0, 0) ||
|
|
2758 |
stype == MAKE_FULLINFO(ITEM_Double, 0, 0)) {
|
|
2759 |
stack_size++; p++;
|
|
2760 |
}
|
|
2761 |
break;
|
|
2762 |
}
|
|
2763 |
case 'A':
|
|
2764 |
/* full_info should have the appropriate value. */
|
|
2765 |
assert(full_info != 0);
|
|
2766 |
stack->item = full_info;
|
|
2767 |
break;
|
|
2768 |
default:
|
|
2769 |
CCerror(context, "Internal error #4");
|
|
2770 |
|
|
2771 |
} /* switch type */
|
|
2772 |
stack_size++;
|
|
2773 |
} /* outer for loop */
|
|
2774 |
|
|
2775 |
if (opcode == opc_invokeinit) {
|
|
2776 |
/* If there are any instances of "from" on the stack, we need to
|
|
2777 |
* replace it with "to", since calling <init> initializes all versions
|
|
2778 |
* of the object, obviously. */
|
|
2779 |
fullinfo_type from = context->swap_table[0];
|
|
2780 |
stack_item_type *ptr;
|
|
2781 |
for (ptr = stack; ptr != NULL; ptr = ptr->next) {
|
|
2782 |
if (ptr->item == from) {
|
|
2783 |
fullinfo_type to = context->swap_table[1];
|
|
2784 |
stack = copy_stack(context, stack);
|
|
2785 |
for (ptr = stack; ptr != NULL; ptr = ptr->next)
|
|
2786 |
if (ptr->item == from) ptr->item = to;
|
|
2787 |
break;
|
|
2788 |
}
|
|
2789 |
}
|
|
2790 |
}
|
|
2791 |
|
|
2792 |
new_stack_info->stack_size = stack_size;
|
|
2793 |
new_stack_info->stack = stack;
|
|
2794 |
}
|
|
2795 |
|
|
2796 |
|
|
2797 |
/* We've performed an instruction, and determined the new registers and stack
|
|
2798 |
* value. Look at all of the possibly subsequent instructions, and merge
|
|
2799 |
* this stack value into theirs.
|
|
2800 |
*/
|
|
2801 |
|
|
2802 |
static void
|
|
2803 |
merge_into_successors(context_type *context, unsigned int inumber,
|
|
2804 |
register_info_type *register_info,
|
|
2805 |
stack_info_type *stack_info,
|
|
2806 |
flag_type and_flags, flag_type or_flags)
|
|
2807 |
{
|
|
2808 |
instruction_data_type *idata = context->instruction_data;
|
|
2809 |
instruction_data_type *this_idata = &idata[inumber];
|
|
2810 |
opcode_type opcode = this_idata->opcode;
|
|
2811 |
int operand = this_idata->operand.i;
|
|
2812 |
struct handler_info_type *handler_info = context->handler_info;
|
|
2813 |
int handler_info_length =
|
|
2814 |
JVM_GetMethodIxExceptionTableLength(context->env,
|
|
2815 |
context->class,
|
|
2816 |
context->method_index);
|
|
2817 |
|
|
2818 |
|
|
2819 |
int buffer[2]; /* default value for successors */
|
|
2820 |
int *successors = buffer; /* table of successors */
|
|
2821 |
int successors_count;
|
|
2822 |
int i;
|
|
2823 |
|
|
2824 |
switch (opcode) {
|
|
2825 |
default:
|
|
2826 |
successors_count = 1;
|
|
2827 |
buffer[0] = inumber + 1;
|
|
2828 |
break;
|
|
2829 |
|
|
2830 |
case opc_ifeq: case opc_ifne: case opc_ifgt:
|
|
2831 |
case opc_ifge: case opc_iflt: case opc_ifle:
|
|
2832 |
case opc_ifnull: case opc_ifnonnull:
|
|
2833 |
case opc_if_icmpeq: case opc_if_icmpne: case opc_if_icmpgt:
|
|
2834 |
case opc_if_icmpge: case opc_if_icmplt: case opc_if_icmple:
|
|
2835 |
case opc_if_acmpeq: case opc_if_acmpne:
|
|
2836 |
successors_count = 2;
|
|
2837 |
buffer[0] = inumber + 1;
|
|
2838 |
buffer[1] = operand;
|
|
2839 |
break;
|
|
2840 |
|
|
2841 |
case opc_jsr: case opc_jsr_w:
|
|
2842 |
if (this_idata->operand2.i != UNKNOWN_RET_INSTRUCTION)
|
|
2843 |
idata[this_idata->operand2.i].changed = JNI_TRUE;
|
|
2844 |
/* FALLTHROUGH */
|
|
2845 |
case opc_goto: case opc_goto_w:
|
|
2846 |
successors_count = 1;
|
|
2847 |
buffer[0] = operand;
|
|
2848 |
break;
|
|
2849 |
|
|
2850 |
|
|
2851 |
case opc_ireturn: case opc_lreturn: case opc_return:
|
|
2852 |
case opc_freturn: case opc_dreturn: case opc_areturn:
|
|
2853 |
case opc_athrow:
|
|
2854 |
/* The testing for the returns is handled in pop_stack() */
|
|
2855 |
successors_count = 0;
|
|
2856 |
break;
|
|
2857 |
|
|
2858 |
case opc_ret: {
|
|
2859 |
/* This is slightly slow, but good enough for a seldom used instruction.
|
|
2860 |
* The EXTRA_ITEM_INFO of the ITEM_ReturnAddress indicates the
|
|
2861 |
* address of the first instruction of the subroutine. We can return
|
|
2862 |
* to 1 after any instruction that jsr's to that instruction.
|
|
2863 |
*/
|
|
2864 |
if (this_idata->operand2.ip == NULL) {
|
|
2865 |
fullinfo_type *registers = this_idata->register_info.registers;
|
|
2866 |
int called_instruction = GET_EXTRA_INFO(registers[operand]);
|
|
2867 |
int i, count, *ptr;;
|
|
2868 |
for (i = context->instruction_count, count = 0; --i >= 0; ) {
|
|
2869 |
if (((idata[i].opcode == opc_jsr) ||
|
|
2870 |
(idata[i].opcode == opc_jsr_w)) &&
|
|
2871 |
(idata[i].operand.i == called_instruction))
|
|
2872 |
count++;
|
|
2873 |
}
|
|
2874 |
this_idata->operand2.ip = ptr = NEW(int, count + 1);
|
|
2875 |
*ptr++ = count;
|
|
2876 |
for (i = context->instruction_count, count = 0; --i >= 0; ) {
|
|
2877 |
if (((idata[i].opcode == opc_jsr) ||
|
|
2878 |
(idata[i].opcode == opc_jsr_w)) &&
|
|
2879 |
(idata[i].operand.i == called_instruction))
|
|
2880 |
*ptr++ = i + 1;
|
|
2881 |
}
|
|
2882 |
}
|
|
2883 |
successors = this_idata->operand2.ip; /* use this instead */
|
|
2884 |
successors_count = *successors++;
|
|
2885 |
break;
|
|
2886 |
|
|
2887 |
}
|
|
2888 |
|
|
2889 |
case opc_tableswitch:
|
|
2890 |
case opc_lookupswitch:
|
|
2891 |
successors = this_idata->operand.ip; /* use this instead */
|
|
2892 |
successors_count = *successors++;
|
|
2893 |
break;
|
|
2894 |
}
|
|
2895 |
|
|
2896 |
#ifdef DEBUG
|
|
2897 |
if (verify_verbose) {
|
|
2898 |
jio_fprintf(stdout, " [");
|
|
2899 |
for (i = handler_info_length; --i >= 0; handler_info++)
|
|
2900 |
if (handler_info->start <= inumber && handler_info->end > inumber)
|
|
2901 |
jio_fprintf(stdout, "%d* ", handler_info->handler);
|
|
2902 |
for (i = 0; i < successors_count; i++)
|
|
2903 |
jio_fprintf(stdout, "%d ", successors[i]);
|
|
2904 |
jio_fprintf(stdout, "]\n");
|
|
2905 |
}
|
|
2906 |
#endif
|
|
2907 |
|
|
2908 |
handler_info = context->handler_info;
|
|
2909 |
for (i = handler_info_length; --i >= 0; handler_info++) {
|
|
2910 |
if (handler_info->start <= inumber && handler_info->end > inumber) {
|
|
2911 |
int handler = handler_info->handler;
|
|
2912 |
if (opcode != opc_invokeinit) {
|
|
2913 |
merge_into_one_successor(context, inumber, handler,
|
|
2914 |
&this_idata->register_info, /* old */
|
|
2915 |
&handler_info->stack_info,
|
|
2916 |
(flag_type) (and_flags
|
|
2917 |
& this_idata->and_flags),
|
|
2918 |
(flag_type) (or_flags
|
|
2919 |
| this_idata->or_flags),
|
|
2920 |
JNI_TRUE);
|
|
2921 |
} else {
|
|
2922 |
/* We need to be a little bit more careful with this
|
|
2923 |
* instruction. Things could either be in the state before
|
|
2924 |
* the instruction or in the state afterwards */
|
|
2925 |
fullinfo_type from = context->swap_table[0];
|
|
2926 |
flag_type temp_or_flags = or_flags;
|
|
2927 |
if (from == MAKE_FULLINFO(ITEM_InitObject, 0, 0))
|
|
2928 |
temp_or_flags |= FLAG_NO_RETURN;
|
|
2929 |
merge_into_one_successor(context, inumber, handler,
|
|
2930 |
&this_idata->register_info, /* old */
|
|
2931 |
&handler_info->stack_info,
|
|
2932 |
this_idata->and_flags,
|
|
2933 |
this_idata->or_flags,
|
|
2934 |
JNI_TRUE);
|
|
2935 |
merge_into_one_successor(context, inumber, handler,
|
|
2936 |
register_info,
|
|
2937 |
&handler_info->stack_info,
|
|
2938 |
and_flags, temp_or_flags, JNI_TRUE);
|
|
2939 |
}
|
|
2940 |
}
|
|
2941 |
}
|
|
2942 |
for (i = 0; i < successors_count; i++) {
|
|
2943 |
int target = successors[i];
|
|
2944 |
if (target >= context->instruction_count)
|
|
2945 |
CCerror(context, "Falling off the end of the code");
|
|
2946 |
merge_into_one_successor(context, inumber, target,
|
|
2947 |
register_info, stack_info, and_flags, or_flags,
|
|
2948 |
JNI_FALSE);
|
|
2949 |
}
|
|
2950 |
}
|
|
2951 |
|
|
2952 |
/* We have a new set of registers and stack values for a given instruction.
|
|
2953 |
* Merge this new set into the values that are already there.
|
|
2954 |
*/
|
|
2955 |
|
|
2956 |
static void
|
|
2957 |
merge_into_one_successor(context_type *context,
|
|
2958 |
unsigned int from_inumber, unsigned int to_inumber,
|
|
2959 |
register_info_type *new_register_info,
|
|
2960 |
stack_info_type *new_stack_info,
|
|
2961 |
flag_type new_and_flags, flag_type new_or_flags,
|
|
2962 |
jboolean isException)
|
|
2963 |
{
|
|
2964 |
instruction_data_type *idata = context->instruction_data;
|
|
2965 |
register_info_type register_info_buf;
|
|
2966 |
stack_info_type stack_info_buf;
|
|
2967 |
#ifdef DEBUG
|
|
2968 |
instruction_data_type *this_idata = &idata[to_inumber];
|
|
2969 |
register_info_type old_reg_info;
|
|
2970 |
stack_info_type old_stack_info;
|
|
2971 |
flag_type old_and_flags, old_or_flags;
|
|
2972 |
#endif
|
|
2973 |
|
|
2974 |
#ifdef DEBUG
|
|
2975 |
if (verify_verbose) {
|
|
2976 |
old_reg_info = this_idata->register_info;
|
|
2977 |
old_stack_info = this_idata->stack_info;
|
|
2978 |
old_and_flags = this_idata->and_flags;
|
|
2979 |
old_or_flags = this_idata->or_flags;
|
|
2980 |
}
|
|
2981 |
#endif
|
|
2982 |
|
|
2983 |
/* All uninitialized objects are set to "bogus" when jsr and
|
|
2984 |
* ret are executed. Thus uninitialized objects can't propagate
|
|
2985 |
* into or out of a subroutine.
|
|
2986 |
*/
|
|
2987 |
if (idata[from_inumber].opcode == opc_ret ||
|
|
2988 |
idata[from_inumber].opcode == opc_jsr ||
|
|
2989 |
idata[from_inumber].opcode == opc_jsr_w) {
|
|
2990 |
int new_register_count = new_register_info->register_count;
|
|
2991 |
fullinfo_type *new_registers = new_register_info->registers;
|
|
2992 |
int i;
|
|
2993 |
stack_item_type *item;
|
|
2994 |
|
|
2995 |
for (item = new_stack_info->stack; item != NULL; item = item->next) {
|
|
2996 |
if (GET_ITEM_TYPE(item->item) == ITEM_NewObject) {
|
|
2997 |
/* This check only succeeds for hand-contrived code.
|
|
2998 |
* Efficiency is not an issue.
|
|
2999 |
*/
|
|
3000 |
stack_info_buf.stack = copy_stack(context,
|
|
3001 |
new_stack_info->stack);
|
|
3002 |
stack_info_buf.stack_size = new_stack_info->stack_size;
|
|
3003 |
new_stack_info = &stack_info_buf;
|
|
3004 |
for (item = new_stack_info->stack; item != NULL;
|
|
3005 |
item = item->next) {
|
|
3006 |
if (GET_ITEM_TYPE(item->item) == ITEM_NewObject) {
|
|
3007 |
item->item = MAKE_FULLINFO(ITEM_Bogus, 0, 0);
|
|
3008 |
}
|
|
3009 |
}
|
|
3010 |
break;
|
|
3011 |
}
|
|
3012 |
}
|
|
3013 |
for (i = 0; i < new_register_count; i++) {
|
|
3014 |
if (GET_ITEM_TYPE(new_registers[i]) == ITEM_NewObject) {
|
|
3015 |
/* This check only succeeds for hand-contrived code.
|
|
3016 |
* Efficiency is not an issue.
|
|
3017 |
*/
|
|
3018 |
fullinfo_type *new_set = NEW(fullinfo_type,
|
|
3019 |
new_register_count);
|
|
3020 |
for (i = 0; i < new_register_count; i++) {
|
|
3021 |
fullinfo_type t = new_registers[i];
|
|
3022 |
new_set[i] = GET_ITEM_TYPE(t) != ITEM_NewObject ?
|
|
3023 |
t : MAKE_FULLINFO(ITEM_Bogus, 0, 0);
|
|
3024 |
}
|
|
3025 |
register_info_buf.register_count = new_register_count;
|
|
3026 |
register_info_buf.registers = new_set;
|
|
3027 |
register_info_buf.mask_count = new_register_info->mask_count;
|
|
3028 |
register_info_buf.masks = new_register_info->masks;
|
|
3029 |
new_register_info = ®ister_info_buf;
|
|
3030 |
break;
|
|
3031 |
}
|
|
3032 |
}
|
|
3033 |
}
|
|
3034 |
|
|
3035 |
/* Returning from a subroutine is somewhat ugly. The actual thing
|
|
3036 |
* that needs to get merged into the new instruction is a joining
|
|
3037 |
* of info from the ret instruction with stuff in the jsr instruction
|
|
3038 |
*/
|
|
3039 |
if (idata[from_inumber].opcode == opc_ret && !isException) {
|
|
3040 |
int new_register_count = new_register_info->register_count;
|
|
3041 |
fullinfo_type *new_registers = new_register_info->registers;
|
|
3042 |
int new_mask_count = new_register_info->mask_count;
|
|
3043 |
mask_type *new_masks = new_register_info->masks;
|
|
3044 |
int operand = idata[from_inumber].operand.i;
|
|
3045 |
int called_instruction = GET_EXTRA_INFO(new_registers[operand]);
|
|
3046 |
instruction_data_type *jsr_idata = &idata[to_inumber - 1];
|
|
3047 |
register_info_type *jsr_reginfo = &jsr_idata->register_info;
|
|
3048 |
if (jsr_idata->operand2.i != from_inumber) {
|
|
3049 |
if (jsr_idata->operand2.i != UNKNOWN_RET_INSTRUCTION)
|
|
3050 |
CCerror(context, "Multiple returns to single jsr");
|
|
3051 |
jsr_idata->operand2.i = from_inumber;
|
|
3052 |
}
|
|
3053 |
if (jsr_reginfo->register_count == UNKNOWN_REGISTER_COUNT) {
|
|
3054 |
/* We don't want to handle the returned-to instruction until
|
|
3055 |
* we've dealt with the jsr instruction. When we get to the
|
|
3056 |
* jsr instruction (if ever), we'll re-mark the ret instruction
|
|
3057 |
*/
|
|
3058 |
;
|
|
3059 |
} else {
|
|
3060 |
int register_count = jsr_reginfo->register_count;
|
|
3061 |
fullinfo_type *registers = jsr_reginfo->registers;
|
|
3062 |
int max_registers = MAX(register_count, new_register_count);
|
|
3063 |
fullinfo_type *new_set = NEW(fullinfo_type, max_registers);
|
|
3064 |
int *return_mask;
|
|
3065 |
struct register_info_type new_new_register_info;
|
|
3066 |
int i;
|
|
3067 |
/* Make sure the place we're returning from is legal! */
|
|
3068 |
for (i = new_mask_count; --i >= 0; )
|
|
3069 |
if (new_masks[i].entry == called_instruction)
|
|
3070 |
break;
|
|
3071 |
if (i < 0)
|
|
3072 |
CCerror(context, "Illegal return from subroutine");
|
|
3073 |
/* pop the masks down to the indicated one. Remember the mask
|
|
3074 |
* we're popping off. */
|
|
3075 |
return_mask = new_masks[i].modifies;
|
|
3076 |
new_mask_count = i;
|
|
3077 |
for (i = 0; i < max_registers; i++) {
|
|
3078 |
if (IS_BIT_SET(return_mask, i))
|
|
3079 |
new_set[i] = i < new_register_count ?
|
|
3080 |
new_registers[i] : MAKE_FULLINFO(ITEM_Bogus, 0, 0);
|
|
3081 |
else
|
|
3082 |
new_set[i] = i < register_count ?
|
|
3083 |
registers[i] : MAKE_FULLINFO(ITEM_Bogus, 0, 0);
|
|
3084 |
}
|
|
3085 |
new_new_register_info.register_count = max_registers;
|
|
3086 |
new_new_register_info.registers = new_set;
|
|
3087 |
new_new_register_info.mask_count = new_mask_count;
|
|
3088 |
new_new_register_info.masks = new_masks;
|
|
3089 |
|
|
3090 |
|
|
3091 |
merge_stack(context, from_inumber, to_inumber, new_stack_info);
|
|
3092 |
merge_registers(context, to_inumber - 1, to_inumber,
|
|
3093 |
&new_new_register_info);
|
|
3094 |
merge_flags(context, from_inumber, to_inumber, new_and_flags, new_or_flags);
|
|
3095 |
}
|
|
3096 |
} else {
|
|
3097 |
merge_stack(context, from_inumber, to_inumber, new_stack_info);
|
|
3098 |
merge_registers(context, from_inumber, to_inumber, new_register_info);
|
|
3099 |
merge_flags(context, from_inumber, to_inumber,
|
|
3100 |
new_and_flags, new_or_flags);
|
|
3101 |
}
|
|
3102 |
|
|
3103 |
#ifdef DEBUG
|
|
3104 |
if (verify_verbose && idata[to_inumber].changed) {
|
|
3105 |
register_info_type *register_info = &this_idata->register_info;
|
|
3106 |
stack_info_type *stack_info = &this_idata->stack_info;
|
|
3107 |
if (memcmp(&old_reg_info, register_info, sizeof(old_reg_info)) ||
|
|
3108 |
memcmp(&old_stack_info, stack_info, sizeof(old_stack_info)) ||
|
|
3109 |
(old_and_flags != this_idata->and_flags) ||
|
|
3110 |
(old_or_flags != this_idata->or_flags)) {
|
|
3111 |
jio_fprintf(stdout, " %2d:", to_inumber);
|
|
3112 |
print_stack(context, &old_stack_info);
|
|
3113 |
print_registers(context, &old_reg_info);
|
|
3114 |
print_flags(context, old_and_flags, old_or_flags);
|
|
3115 |
jio_fprintf(stdout, " => ");
|
|
3116 |
print_stack(context, &this_idata->stack_info);
|
|
3117 |
print_registers(context, &this_idata->register_info);
|
|
3118 |
print_flags(context, this_idata->and_flags, this_idata->or_flags);
|
|
3119 |
jio_fprintf(stdout, "\n");
|
|
3120 |
}
|
|
3121 |
}
|
|
3122 |
#endif
|
|
3123 |
|
|
3124 |
}
|
|
3125 |
|
|
3126 |
static void
|
|
3127 |
merge_stack(context_type *context, unsigned int from_inumber,
|
|
3128 |
unsigned int to_inumber, stack_info_type *new_stack_info)
|
|
3129 |
{
|
|
3130 |
instruction_data_type *idata = context->instruction_data;
|
|
3131 |
instruction_data_type *this_idata = &idata[to_inumber];
|
|
3132 |
|
|
3133 |
int new_stack_size = new_stack_info->stack_size;
|
|
3134 |
stack_item_type *new_stack = new_stack_info->stack;
|
|
3135 |
|
|
3136 |
int stack_size = this_idata->stack_info.stack_size;
|
|
3137 |
|
|
3138 |
if (stack_size == UNKNOWN_STACK_SIZE) {
|
|
3139 |
/* First time at this instruction. Just copy. */
|
|
3140 |
this_idata->stack_info.stack_size = new_stack_size;
|
|
3141 |
this_idata->stack_info.stack = new_stack;
|
|
3142 |
this_idata->changed = JNI_TRUE;
|
|
3143 |
} else if (new_stack_size != stack_size) {
|
|
3144 |
CCerror(context, "Inconsistent stack height %d != %d",
|
|
3145 |
new_stack_size, stack_size);
|
|
3146 |
} else {
|
|
3147 |
stack_item_type *stack = this_idata->stack_info.stack;
|
|
3148 |
stack_item_type *old, *new;
|
|
3149 |
jboolean change = JNI_FALSE;
|
|
3150 |
for (old = stack, new = new_stack; old != NULL;
|
|
3151 |
old = old->next, new = new->next) {
|
|
3152 |
if (!isAssignableTo(context, new->item, old->item)) {
|
|
3153 |
change = JNI_TRUE;
|
|
3154 |
break;
|
|
3155 |
}
|
|
3156 |
}
|
|
3157 |
if (change) {
|
|
3158 |
stack = copy_stack(context, stack);
|
|
3159 |
for (old = stack, new = new_stack; old != NULL;
|
|
3160 |
old = old->next, new = new->next) {
|
|
3161 |
if (new == NULL) {
|
|
3162 |
break;
|
|
3163 |
}
|
|
3164 |
old->item = merge_fullinfo_types(context, old->item, new->item,
|
|
3165 |
JNI_FALSE);
|
|
3166 |
if (GET_ITEM_TYPE(old->item) == ITEM_Bogus) {
|
|
3167 |
CCerror(context, "Mismatched stack types");
|
|
3168 |
}
|
|
3169 |
}
|
|
3170 |
if (old != NULL || new != NULL) {
|
|
3171 |
CCerror(context, "Mismatched stack types");
|
|
3172 |
}
|
|
3173 |
this_idata->stack_info.stack = stack;
|
|
3174 |
this_idata->changed = JNI_TRUE;
|
|
3175 |
}
|
|
3176 |
}
|
|
3177 |
}
|
|
3178 |
|
|
3179 |
static void
|
|
3180 |
merge_registers(context_type *context, unsigned int from_inumber,
|
|
3181 |
unsigned int to_inumber, register_info_type *new_register_info)
|
|
3182 |
{
|
|
3183 |
instruction_data_type *idata = context->instruction_data;
|
|
3184 |
instruction_data_type *this_idata = &idata[to_inumber];
|
|
3185 |
register_info_type *this_reginfo = &this_idata->register_info;
|
|
3186 |
|
|
3187 |
int new_register_count = new_register_info->register_count;
|
|
3188 |
fullinfo_type *new_registers = new_register_info->registers;
|
|
3189 |
int new_mask_count = new_register_info->mask_count;
|
|
3190 |
mask_type *new_masks = new_register_info->masks;
|
|
3191 |
|
|
3192 |
|
|
3193 |
if (this_reginfo->register_count == UNKNOWN_REGISTER_COUNT) {
|
|
3194 |
this_reginfo->register_count = new_register_count;
|
|
3195 |
this_reginfo->registers = new_registers;
|
|
3196 |
this_reginfo->mask_count = new_mask_count;
|
|
3197 |
this_reginfo->masks = new_masks;
|
|
3198 |
this_idata->changed = JNI_TRUE;
|
|
3199 |
} else {
|
|
3200 |
/* See if we've got new information on the register set. */
|
|
3201 |
int register_count = this_reginfo->register_count;
|
|
3202 |
fullinfo_type *registers = this_reginfo->registers;
|
|
3203 |
int mask_count = this_reginfo->mask_count;
|
|
3204 |
mask_type *masks = this_reginfo->masks;
|
|
3205 |
|
|
3206 |
jboolean copy = JNI_FALSE;
|
|
3207 |
int i, j;
|
|
3208 |
if (register_count > new_register_count) {
|
|
3209 |
/* Any register larger than new_register_count is now bogus */
|
|
3210 |
this_reginfo->register_count = new_register_count;
|
|
3211 |
register_count = new_register_count;
|
|
3212 |
this_idata->changed = JNI_TRUE;
|
|
3213 |
}
|
|
3214 |
for (i = 0; i < register_count; i++) {
|
|
3215 |
fullinfo_type prev_value = registers[i];
|
|
3216 |
if ((i < new_register_count)
|
|
3217 |
? (!isAssignableTo(context, new_registers[i], prev_value))
|
|
3218 |
: (prev_value != MAKE_FULLINFO(ITEM_Bogus, 0, 0))) {
|
|
3219 |
copy = JNI_TRUE;
|
|
3220 |
break;
|
|
3221 |
}
|
|
3222 |
}
|
|
3223 |
|
|
3224 |
if (copy) {
|
|
3225 |
/* We need a copy. So do it. */
|
|
3226 |
fullinfo_type *new_set = NEW(fullinfo_type, register_count);
|
|
3227 |
for (j = 0; j < i; j++)
|
|
3228 |
new_set[j] = registers[j];
|
|
3229 |
for (j = i; j < register_count; j++) {
|
|
3230 |
if (i >= new_register_count)
|
|
3231 |
new_set[j] = MAKE_FULLINFO(ITEM_Bogus, 0, 0);
|
|
3232 |
else
|
|
3233 |
new_set[j] = merge_fullinfo_types(context,
|
|
3234 |
new_registers[j],
|
|
3235 |
registers[j], JNI_FALSE);
|
|
3236 |
}
|
|
3237 |
/* Some of the end items might now be bogus. This step isn't
|
|
3238 |
* necessary, but it may save work later. */
|
|
3239 |
while ( register_count > 0
|
|
3240 |
&& GET_ITEM_TYPE(new_set[register_count-1]) == ITEM_Bogus)
|
|
3241 |
register_count--;
|
|
3242 |
this_reginfo->register_count = register_count;
|
|
3243 |
this_reginfo->registers = new_set;
|
|
3244 |
this_idata->changed = JNI_TRUE;
|
|
3245 |
}
|
|
3246 |
if (mask_count > 0) {
|
|
3247 |
/* If the target instruction already has a sequence of masks, then
|
|
3248 |
* we need to merge new_masks into it. We want the entries on
|
|
3249 |
* the mask to be the longest common substring of the two.
|
|
3250 |
* (e.g. a->b->d merged with a->c->d should give a->d)
|
|
3251 |
* The bits set in the mask should be the or of the corresponding
|
|
3252 |
* entries in each of the original masks.
|
|
3253 |
*/
|
|
3254 |
int i, j, k;
|
|
3255 |
int matches = 0;
|
|
3256 |
int last_match = -1;
|
|
3257 |
jboolean copy_needed = JNI_FALSE;
|
|
3258 |
for (i = 0; i < mask_count; i++) {
|
|
3259 |
int entry = masks[i].entry;
|
|
3260 |
for (j = last_match + 1; j < new_mask_count; j++) {
|
|
3261 |
if (new_masks[j].entry == entry) {
|
|
3262 |
/* We have a match */
|
|
3263 |
int *prev = masks[i].modifies;
|
|
3264 |
int *new = new_masks[j].modifies;
|
|
3265 |
matches++;
|
|
3266 |
/* See if new_mask has bits set for "entry" that
|
|
3267 |
* weren't set for mask. If so, need to copy. */
|
|
3268 |
for (k = context->bitmask_size - 1;
|
|
3269 |
!copy_needed && k >= 0;
|
|
3270 |
k--)
|
|
3271 |
if (~prev[k] & new[k])
|
|
3272 |
copy_needed = JNI_TRUE;
|
|
3273 |
last_match = j;
|
|
3274 |
break;
|
|
3275 |
}
|
|
3276 |
}
|
|
3277 |
}
|
|
3278 |
if ((matches < mask_count) || copy_needed) {
|
|
3279 |
/* We need to make a copy for the new item, since either the
|
|
3280 |
* size has decreased, or new bits are set. */
|
|
3281 |
mask_type *copy = NEW(mask_type, matches);
|
|
3282 |
for (i = 0; i < matches; i++) {
|
|
3283 |
copy[i].modifies = NEW(int, context->bitmask_size);
|
|
3284 |
}
|
|
3285 |
this_reginfo->masks = copy;
|
|
3286 |
this_reginfo->mask_count = matches;
|
|
3287 |
this_idata->changed = JNI_TRUE;
|
|
3288 |
matches = 0;
|
|
3289 |
last_match = -1;
|
|
3290 |
for (i = 0; i < mask_count; i++) {
|
|
3291 |
int entry = masks[i].entry;
|
|
3292 |
for (j = last_match + 1; j < new_mask_count; j++) {
|
|
3293 |
if (new_masks[j].entry == entry) {
|
|
3294 |
int *prev1 = masks[i].modifies;
|
|
3295 |
int *prev2 = new_masks[j].modifies;
|
|
3296 |
int *new = copy[matches].modifies;
|
|
3297 |
copy[matches].entry = entry;
|
|
3298 |
for (k = context->bitmask_size - 1; k >= 0; k--)
|
|
3299 |
new[k] = prev1[k] | prev2[k];
|
|
3300 |
matches++;
|
|
3301 |
last_match = j;
|
|
3302 |
break;
|
|
3303 |
}
|
|
3304 |
}
|
|
3305 |
}
|
|
3306 |
}
|
|
3307 |
}
|
|
3308 |
}
|
|
3309 |
}
|
|
3310 |
|
|
3311 |
|
|
3312 |
static void
|
|
3313 |
merge_flags(context_type *context, unsigned int from_inumber,
|
|
3314 |
unsigned int to_inumber,
|
|
3315 |
flag_type new_and_flags, flag_type new_or_flags)
|
|
3316 |
{
|
|
3317 |
/* Set this_idata->and_flags &= new_and_flags
|
|
3318 |
this_idata->or_flags |= new_or_flags
|
|
3319 |
*/
|
|
3320 |
instruction_data_type *idata = context->instruction_data;
|
|
3321 |
instruction_data_type *this_idata = &idata[to_inumber];
|
|
3322 |
flag_type this_and_flags = this_idata->and_flags;
|
|
3323 |
flag_type this_or_flags = this_idata->or_flags;
|
|
3324 |
flag_type merged_and = this_and_flags & new_and_flags;
|
|
3325 |
flag_type merged_or = this_or_flags | new_or_flags;
|
|
3326 |
|
|
3327 |
if ((merged_and != this_and_flags) || (merged_or != this_or_flags)) {
|
|
3328 |
this_idata->and_flags = merged_and;
|
|
3329 |
this_idata->or_flags = merged_or;
|
|
3330 |
this_idata->changed = JNI_TRUE;
|
|
3331 |
}
|
|
3332 |
}
|
|
3333 |
|
|
3334 |
|
|
3335 |
/* Make a copy of a stack */
|
|
3336 |
|
|
3337 |
static stack_item_type *
|
|
3338 |
copy_stack(context_type *context, stack_item_type *stack)
|
|
3339 |
{
|
|
3340 |
int length;
|
|
3341 |
stack_item_type *ptr;
|
|
3342 |
|
|
3343 |
/* Find the length */
|
|
3344 |
for (ptr = stack, length = 0; ptr != NULL; ptr = ptr->next, length++);
|
|
3345 |
|
|
3346 |
if (length > 0) {
|
|
3347 |
stack_item_type *new_stack = NEW(stack_item_type, length);
|
|
3348 |
stack_item_type *new_ptr;
|
|
3349 |
for ( ptr = stack, new_ptr = new_stack;
|
|
3350 |
ptr != NULL;
|
|
3351 |
ptr = ptr->next, new_ptr++) {
|
|
3352 |
new_ptr->item = ptr->item;
|
|
3353 |
new_ptr->next = new_ptr + 1;
|
|
3354 |
}
|
|
3355 |
new_stack[length - 1].next = NULL;
|
|
3356 |
return new_stack;
|
|
3357 |
} else {
|
|
3358 |
return NULL;
|
|
3359 |
}
|
|
3360 |
}
|
|
3361 |
|
|
3362 |
|
|
3363 |
static mask_type *
|
|
3364 |
copy_masks(context_type *context, mask_type *masks, int mask_count)
|
|
3365 |
{
|
|
3366 |
mask_type *result = NEW(mask_type, mask_count);
|
|
3367 |
int bitmask_size = context->bitmask_size;
|
|
3368 |
int *bitmaps = NEW(int, mask_count * bitmask_size);
|
|
3369 |
int i;
|
|
3370 |
for (i = 0; i < mask_count; i++) {
|
|
3371 |
result[i].entry = masks[i].entry;
|
|
3372 |
result[i].modifies = &bitmaps[i * bitmask_size];
|
|
3373 |
memcpy(result[i].modifies, masks[i].modifies, bitmask_size * sizeof(int));
|
|
3374 |
}
|
|
3375 |
return result;
|
|
3376 |
}
|
|
3377 |
|
|
3378 |
|
|
3379 |
static mask_type *
|
|
3380 |
add_to_masks(context_type *context, mask_type *masks, int mask_count, int d)
|
|
3381 |
{
|
|
3382 |
mask_type *result = NEW(mask_type, mask_count + 1);
|
|
3383 |
int bitmask_size = context->bitmask_size;
|
|
3384 |
int *bitmaps = NEW(int, (mask_count + 1) * bitmask_size);
|
|
3385 |
int i;
|
|
3386 |
for (i = 0; i < mask_count; i++) {
|
|
3387 |
result[i].entry = masks[i].entry;
|
|
3388 |
result[i].modifies = &bitmaps[i * bitmask_size];
|
|
3389 |
memcpy(result[i].modifies, masks[i].modifies, bitmask_size * sizeof(int));
|
|
3390 |
}
|
|
3391 |
result[mask_count].entry = d;
|
|
3392 |
result[mask_count].modifies = &bitmaps[mask_count * bitmask_size];
|
|
3393 |
memset(result[mask_count].modifies, 0, bitmask_size * sizeof(int));
|
|
3394 |
return result;
|
|
3395 |
}
|
|
3396 |
|
|
3397 |
|
|
3398 |
|
|
3399 |
/* We create our own storage manager, since we malloc lots of little items,
|
|
3400 |
* and I don't want to keep trace of when they become free. I sure wish that
|
|
3401 |
* we had heaps, and I could just free the heap when done.
|
|
3402 |
*/
|
|
3403 |
|
|
3404 |
#define CCSegSize 2000
|
|
3405 |
|
|
3406 |
struct CCpool { /* a segment of allocated memory in the pool */
|
|
3407 |
struct CCpool *next;
|
|
3408 |
int segSize; /* almost always CCSegSize */
|
|
3409 |
int poolPad;
|
|
3410 |
char space[CCSegSize];
|
|
3411 |
};
|
|
3412 |
|
|
3413 |
/* Initialize the context's heap. */
|
|
3414 |
static void CCinit(context_type *context)
|
|
3415 |
{
|
|
3416 |
struct CCpool *new = (struct CCpool *) malloc(sizeof(struct CCpool));
|
|
3417 |
/* Set context->CCroot to 0 if new == 0 to tell CCdestroy to lay off */
|
|
3418 |
context->CCroot = context->CCcurrent = new;
|
|
3419 |
if (new == 0) {
|
|
3420 |
CCout_of_memory(context);
|
|
3421 |
}
|
|
3422 |
new->next = NULL;
|
|
3423 |
new->segSize = CCSegSize;
|
|
3424 |
context->CCfree_size = CCSegSize;
|
|
3425 |
context->CCfree_ptr = &new->space[0];
|
|
3426 |
}
|
|
3427 |
|
|
3428 |
|
|
3429 |
/* Reuse all the space that we have in the context's heap. */
|
|
3430 |
static void CCreinit(context_type *context)
|
|
3431 |
{
|
|
3432 |
struct CCpool *first = context->CCroot;
|
|
3433 |
context->CCcurrent = first;
|
|
3434 |
context->CCfree_size = CCSegSize;
|
|
3435 |
context->CCfree_ptr = &first->space[0];
|
|
3436 |
}
|
|
3437 |
|
|
3438 |
/* Destroy the context's heap. */
|
|
3439 |
static void CCdestroy(context_type *context)
|
|
3440 |
{
|
|
3441 |
struct CCpool *this = context->CCroot;
|
|
3442 |
while (this) {
|
|
3443 |
struct CCpool *next = this->next;
|
|
3444 |
free(this);
|
|
3445 |
this = next;
|
|
3446 |
}
|
|
3447 |
/* These two aren't necessary. But can't hurt either */
|
|
3448 |
context->CCroot = context->CCcurrent = NULL;
|
|
3449 |
context->CCfree_ptr = 0;
|
|
3450 |
}
|
|
3451 |
|
|
3452 |
/* Allocate an object of the given size from the context's heap. */
|
|
3453 |
static void *
|
|
3454 |
CCalloc(context_type *context, int size, jboolean zero)
|
|
3455 |
{
|
|
3456 |
|
|
3457 |
register char *p;
|
|
3458 |
/* Round CC to the size of a pointer */
|
|
3459 |
size = (size + (sizeof(void *) - 1)) & ~(sizeof(void *) - 1);
|
|
3460 |
|
|
3461 |
if (context->CCfree_size < size) {
|
|
3462 |
struct CCpool *current = context->CCcurrent;
|
|
3463 |
struct CCpool *new;
|
|
3464 |
if (size > CCSegSize) { /* we need to allocate a special block */
|
|
3465 |
new = (struct CCpool *)malloc(sizeof(struct CCpool) +
|
|
3466 |
(size - CCSegSize));
|
|
3467 |
if (new == 0) {
|
|
3468 |
CCout_of_memory(context);
|
|
3469 |
}
|
|
3470 |
new->next = current->next;
|
|
3471 |
new->segSize = size;
|
|
3472 |
current->next = new;
|
|
3473 |
} else {
|
|
3474 |
new = current->next;
|
|
3475 |
if (new == NULL) {
|
|
3476 |
new = (struct CCpool *) malloc(sizeof(struct CCpool));
|
|
3477 |
if (new == 0) {
|
|
3478 |
CCout_of_memory(context);
|
|
3479 |
}
|
|
3480 |
current->next = new;
|
|
3481 |
new->next = NULL;
|
|
3482 |
new->segSize = CCSegSize;
|
|
3483 |
}
|
|
3484 |
}
|
|
3485 |
context->CCcurrent = new;
|
|
3486 |
context->CCfree_ptr = &new->space[0];
|
|
3487 |
context->CCfree_size = new->segSize;
|
|
3488 |
}
|
|
3489 |
p = context->CCfree_ptr;
|
|
3490 |
context->CCfree_ptr += size;
|
|
3491 |
context->CCfree_size -= size;
|
|
3492 |
if (zero)
|
|
3493 |
memset(p, 0, size);
|
|
3494 |
return p;
|
|
3495 |
}
|
|
3496 |
|
|
3497 |
/* Get the class associated with a particular field or method or class in the
|
|
3498 |
* constant pool. If is_field is true, we've got a field or method. If
|
|
3499 |
* false, we've got a class.
|
|
3500 |
*/
|
|
3501 |
static fullinfo_type
|
|
3502 |
cp_index_to_class_fullinfo(context_type *context, int cp_index, int kind)
|
|
3503 |
{
|
|
3504 |
JNIEnv *env = context->env;
|
|
3505 |
fullinfo_type result;
|
|
3506 |
const char *classname;
|
|
3507 |
switch (kind) {
|
|
3508 |
case JVM_CONSTANT_Class:
|
|
3509 |
classname = JVM_GetCPClassNameUTF(env,
|
|
3510 |
context->class,
|
|
3511 |
cp_index);
|
|
3512 |
break;
|
|
3513 |
case JVM_CONSTANT_Methodref:
|
|
3514 |
classname = JVM_GetCPMethodClassNameUTF(env,
|
|
3515 |
context->class,
|
|
3516 |
cp_index);
|
|
3517 |
break;
|
|
3518 |
case JVM_CONSTANT_Fieldref:
|
|
3519 |
classname = JVM_GetCPFieldClassNameUTF(env,
|
|
3520 |
context->class,
|
|
3521 |
cp_index);
|
|
3522 |
break;
|
|
3523 |
default:
|
|
3524 |
classname = NULL;
|
|
3525 |
CCerror(context, "Internal error #5");
|
|
3526 |
}
|
|
3527 |
|
|
3528 |
check_and_push(context, classname, VM_STRING_UTF);
|
|
3529 |
if (classname[0] == JVM_SIGNATURE_ARRAY) {
|
|
3530 |
/* This make recursively call us, in case of a class array */
|
|
3531 |
signature_to_fieldtype(context, &classname, &result);
|
|
3532 |
} else {
|
|
3533 |
result = make_class_info_from_name(context, classname);
|
|
3534 |
}
|
|
3535 |
pop_and_free(context);
|
|
3536 |
return result;
|
|
3537 |
}
|
|
3538 |
|
|
3539 |
|
|
3540 |
static int
|
|
3541 |
print_CCerror_info(context_type *context)
|
|
3542 |
{
|
|
3543 |
JNIEnv *env = context->env;
|
|
3544 |
jclass cb = context->class;
|
|
3545 |
const char *classname = JVM_GetClassNameUTF(env, cb);
|
|
3546 |
const char *name = 0;
|
|
3547 |
const char *signature = 0;
|
|
3548 |
int n = 0;
|
|
3549 |
if (context->method_index != -1) {
|
|
3550 |
name = JVM_GetMethodIxNameUTF(env, cb, context->method_index);
|
|
3551 |
signature =
|
|
3552 |
JVM_GetMethodIxSignatureUTF(env, cb, context->method_index);
|
|
3553 |
n += jio_snprintf(context->message, context->message_buf_len,
|
|
3554 |
"(class: %s, method: %s signature: %s) ",
|
|
3555 |
(classname ? classname : ""),
|
|
3556 |
(name ? name : ""),
|
|
3557 |
(signature ? signature : ""));
|
|
3558 |
} else if (context->field_index != -1 ) {
|
|
3559 |
name = JVM_GetMethodIxNameUTF(env, cb, context->field_index);
|
|
3560 |
n += jio_snprintf(context->message, context->message_buf_len,
|
|
3561 |
"(class: %s, field: %s) ",
|
|
3562 |
(classname ? classname : 0),
|
|
3563 |
(name ? name : 0));
|
|
3564 |
} else {
|
|
3565 |
n += jio_snprintf(context->message, context->message_buf_len,
|
|
3566 |
"(class: %s) ", classname ? classname : "");
|
|
3567 |
}
|
|
3568 |
JVM_ReleaseUTF(classname);
|
|
3569 |
JVM_ReleaseUTF(name);
|
|
3570 |
JVM_ReleaseUTF(signature);
|
|
3571 |
return n;
|
|
3572 |
}
|
|
3573 |
|
|
3574 |
static void
|
|
3575 |
CCerror (context_type *context, char *format, ...)
|
|
3576 |
{
|
|
3577 |
int n = print_CCerror_info(context);
|
|
3578 |
va_list args;
|
|
3579 |
if (n >= 0 && n < context->message_buf_len) {
|
|
3580 |
va_start(args, format);
|
|
3581 |
jio_vsnprintf(context->message + n, context->message_buf_len - n,
|
|
3582 |
format, args);
|
|
3583 |
va_end(args);
|
|
3584 |
}
|
|
3585 |
context->err_code = CC_VerifyError;
|
|
3586 |
longjmp(context->jump_buffer, 1);
|
|
3587 |
}
|
|
3588 |
|
|
3589 |
static void
|
|
3590 |
CCout_of_memory(context_type *context)
|
|
3591 |
{
|
|
3592 |
int n = print_CCerror_info(context);
|
|
3593 |
context->err_code = CC_OutOfMemory;
|
|
3594 |
longjmp(context->jump_buffer, 1);
|
|
3595 |
}
|
|
3596 |
|
|
3597 |
static void
|
|
3598 |
CFerror(context_type *context, char *format, ...)
|
|
3599 |
{
|
|
3600 |
int n = print_CCerror_info(context);
|
|
3601 |
va_list args;
|
|
3602 |
if (n >= 0 && n < context->message_buf_len) {
|
|
3603 |
va_start(args, format);
|
|
3604 |
jio_vsnprintf(context->message + n, context->message_buf_len - n,
|
|
3605 |
format, args);
|
|
3606 |
va_end(args);
|
|
3607 |
}
|
|
3608 |
context->err_code = CC_ClassFormatError;
|
|
3609 |
longjmp(context->jump_buffer, 1);
|
|
3610 |
}
|
|
3611 |
|
|
3612 |
static char
|
|
3613 |
signature_to_fieldtype(context_type *context,
|
|
3614 |
const char **signature_p, fullinfo_type *full_info_p)
|
|
3615 |
{
|
|
3616 |
const char *p = *signature_p;
|
|
3617 |
fullinfo_type full_info = MAKE_FULLINFO(0, 0, 0);
|
|
3618 |
char result;
|
|
3619 |
int array_depth = 0;
|
|
3620 |
|
|
3621 |
for (;;) {
|
|
3622 |
switch(*p++) {
|
|
3623 |
default:
|
|
3624 |
full_info = MAKE_FULLINFO(ITEM_Bogus, 0, 0);
|
|
3625 |
result = 0;
|
|
3626 |
break;
|
|
3627 |
|
|
3628 |
case JVM_SIGNATURE_BOOLEAN: case JVM_SIGNATURE_BYTE:
|
|
3629 |
full_info = (array_depth > 0)
|
|
3630 |
? MAKE_FULLINFO(ITEM_Byte, 0, 0)
|
|
3631 |
: MAKE_FULLINFO(ITEM_Integer, 0, 0);
|
|
3632 |
result = 'I';
|
|
3633 |
break;
|
|
3634 |
|
|
3635 |
case JVM_SIGNATURE_CHAR:
|
|
3636 |
full_info = (array_depth > 0)
|
|
3637 |
? MAKE_FULLINFO(ITEM_Char, 0, 0)
|
|
3638 |
: MAKE_FULLINFO(ITEM_Integer, 0, 0);
|
|
3639 |
result = 'I';
|
|
3640 |
break;
|
|
3641 |
|
|
3642 |
case JVM_SIGNATURE_SHORT:
|
|
3643 |
full_info = (array_depth > 0)
|
|
3644 |
? MAKE_FULLINFO(ITEM_Short, 0, 0)
|
|
3645 |
: MAKE_FULLINFO(ITEM_Integer, 0, 0);
|
|
3646 |
result = 'I';
|
|
3647 |
break;
|
|
3648 |
|
|
3649 |
case JVM_SIGNATURE_INT:
|
|
3650 |
full_info = MAKE_FULLINFO(ITEM_Integer, 0, 0);
|
|
3651 |
result = 'I';
|
|
3652 |
break;
|
|
3653 |
|
|
3654 |
case JVM_SIGNATURE_FLOAT:
|
|
3655 |
full_info = MAKE_FULLINFO(ITEM_Float, 0, 0);
|
|
3656 |
result = 'F';
|
|
3657 |
break;
|
|
3658 |
|
|
3659 |
case JVM_SIGNATURE_DOUBLE:
|
|
3660 |
full_info = MAKE_FULLINFO(ITEM_Double, 0, 0);
|
|
3661 |
result = 'D';
|
|
3662 |
break;
|
|
3663 |
|
|
3664 |
case JVM_SIGNATURE_LONG:
|
|
3665 |
full_info = MAKE_FULLINFO(ITEM_Long, 0, 0);
|
|
3666 |
result = 'L';
|
|
3667 |
break;
|
|
3668 |
|
|
3669 |
case JVM_SIGNATURE_ARRAY:
|
|
3670 |
array_depth++;
|
|
3671 |
continue; /* only time we ever do the loop > 1 */
|
|
3672 |
|
|
3673 |
case JVM_SIGNATURE_CLASS: {
|
|
3674 |
char buffer_space[256];
|
|
3675 |
char *buffer = buffer_space;
|
|
3676 |
char *finish = strchr(p, JVM_SIGNATURE_ENDCLASS);
|
|
3677 |
int length = finish - p;
|
|
3678 |
if (length + 1 > sizeof(buffer_space)) {
|
|
3679 |
buffer = malloc(length + 1);
|
|
3680 |
check_and_push(context, buffer, VM_MALLOC_BLK);
|
|
3681 |
}
|
|
3682 |
memcpy(buffer, p, length);
|
|
3683 |
buffer[length] = '\0';
|
|
3684 |
full_info = make_class_info_from_name(context, buffer);
|
|
3685 |
result = 'A';
|
|
3686 |
p = finish + 1;
|
|
3687 |
if (buffer != buffer_space)
|
|
3688 |
pop_and_free(context);
|
|
3689 |
break;
|
|
3690 |
}
|
|
3691 |
} /* end of switch */
|
|
3692 |
break;
|
|
3693 |
}
|
|
3694 |
*signature_p = p;
|
|
3695 |
if (array_depth == 0 || result == 0) {
|
|
3696 |
/* either not an array, or result is bogus */
|
|
3697 |
*full_info_p = full_info;
|
|
3698 |
return result;
|
|
3699 |
} else {
|
|
3700 |
if (array_depth > MAX_ARRAY_DIMENSIONS)
|
|
3701 |
CCerror(context, "Array with too many dimensions");
|
|
3702 |
*full_info_p = MAKE_FULLINFO(GET_ITEM_TYPE(full_info),
|
|
3703 |
array_depth,
|
|
3704 |
GET_EXTRA_INFO(full_info));
|
|
3705 |
return 'A';
|
|
3706 |
}
|
|
3707 |
}
|
|
3708 |
|
|
3709 |
|
|
3710 |
/* Given an array type, create the type that has one less level of
|
|
3711 |
* indirection.
|
|
3712 |
*/
|
|
3713 |
|
|
3714 |
static fullinfo_type
|
|
3715 |
decrement_indirection(fullinfo_type array_info)
|
|
3716 |
{
|
|
3717 |
if (array_info == NULL_FULLINFO) {
|
|
3718 |
return NULL_FULLINFO;
|
|
3719 |
} else {
|
|
3720 |
int type = GET_ITEM_TYPE(array_info);
|
|
3721 |
int indirection = GET_INDIRECTION(array_info) - 1;
|
|
3722 |
int extra_info = GET_EXTRA_INFO(array_info);
|
|
3723 |
if ( (indirection == 0)
|
|
3724 |
&& ((type == ITEM_Short || type == ITEM_Byte || type == ITEM_Char)))
|
|
3725 |
type = ITEM_Integer;
|
|
3726 |
return MAKE_FULLINFO(type, indirection, extra_info);
|
|
3727 |
}
|
|
3728 |
}
|
|
3729 |
|
|
3730 |
|
|
3731 |
/* See if we can assign an object of the "from" type to an object
|
|
3732 |
* of the "to" type.
|
|
3733 |
*/
|
|
3734 |
|
|
3735 |
static jboolean isAssignableTo(context_type *context,
|
|
3736 |
fullinfo_type from, fullinfo_type to)
|
|
3737 |
{
|
|
3738 |
return (merge_fullinfo_types(context, from, to, JNI_TRUE) == to);
|
|
3739 |
}
|
|
3740 |
|
|
3741 |
/* Given two fullinfo_type's, find their lowest common denominator. If
|
|
3742 |
* the assignable_p argument is non-null, we're really just calling to find
|
|
3743 |
* out if "<target> := <value>" is a legitimate assignment.
|
|
3744 |
*
|
|
3745 |
* We treat all interfaces as if they were of type java/lang/Object, since the
|
|
3746 |
* runtime will do the full checking.
|
|
3747 |
*/
|
|
3748 |
static fullinfo_type
|
|
3749 |
merge_fullinfo_types(context_type *context,
|
|
3750 |
fullinfo_type value, fullinfo_type target,
|
|
3751 |
jboolean for_assignment)
|
|
3752 |
{
|
|
3753 |
JNIEnv *env = context->env;
|
|
3754 |
if (value == target) {
|
|
3755 |
/* If they're identical, clearly just return what we've got */
|
|
3756 |
return value;
|
|
3757 |
}
|
|
3758 |
|
|
3759 |
/* Both must be either arrays or objects to go further */
|
|
3760 |
if (GET_INDIRECTION(value) == 0 && GET_ITEM_TYPE(value) != ITEM_Object)
|
|
3761 |
return MAKE_FULLINFO(ITEM_Bogus, 0, 0);
|
|
3762 |
if (GET_INDIRECTION(target) == 0 && GET_ITEM_TYPE(target) != ITEM_Object)
|
|
3763 |
return MAKE_FULLINFO(ITEM_Bogus, 0, 0);
|
|
3764 |
|
|
3765 |
/* If either is NULL, return the other. */
|
|
3766 |
if (value == NULL_FULLINFO)
|
|
3767 |
return target;
|
|
3768 |
else if (target == NULL_FULLINFO)
|
|
3769 |
return value;
|
|
3770 |
|
|
3771 |
/* If either is java/lang/Object, that's the result. */
|
|
3772 |
if (target == context->object_info)
|
|
3773 |
return target;
|
|
3774 |
else if (value == context->object_info) {
|
|
3775 |
/* Minor hack. For assignments, Interface := Object, return Interface
|
|
3776 |
* rather than Object, so that isAssignableTo() will get the right
|
|
3777 |
* result. */
|
|
3778 |
if (for_assignment && (WITH_ZERO_EXTRA_INFO(target) ==
|
|
3779 |
MAKE_FULLINFO(ITEM_Object, 0, 0))) {
|
|
3780 |
jclass cb = object_fullinfo_to_classclass(context,
|
|
3781 |
target);
|
|
3782 |
int is_interface = cb && JVM_IsInterface(env, cb);
|
|
3783 |
if (is_interface)
|
|
3784 |
return target;
|
|
3785 |
}
|
|
3786 |
return value;
|
|
3787 |
}
|
|
3788 |
if (GET_INDIRECTION(value) > 0 || GET_INDIRECTION(target) > 0) {
|
|
3789 |
/* At least one is an array. Neither is java/lang/Object or NULL.
|
|
3790 |
* Moreover, the types are not identical.
|
|
3791 |
* The result must either be Object, or an array of some object type.
|
|
3792 |
*/
|
|
3793 |
fullinfo_type value_base, target_base;
|
|
3794 |
int dimen_value = GET_INDIRECTION(value);
|
|
3795 |
int dimen_target = GET_INDIRECTION(target);
|
|
3796 |
|
|
3797 |
if (target == context->cloneable_info ||
|
|
3798 |
target == context->serializable_info) {
|
|
3799 |
return target;
|
|
3800 |
}
|
|
3801 |
|
|
3802 |
if (value == context->cloneable_info ||
|
|
3803 |
value == context->serializable_info) {
|
|
3804 |
return value;
|
|
3805 |
}
|
|
3806 |
|
|
3807 |
/* First, if either item's base type isn't ITEM_Object, promote it up
|
|
3808 |
* to an object or array of object. If either is elemental, we can
|
|
3809 |
* punt.
|
|
3810 |
*/
|
|
3811 |
if (GET_ITEM_TYPE(value) != ITEM_Object) {
|
|
3812 |
if (dimen_value == 0)
|
|
3813 |
return MAKE_FULLINFO(ITEM_Bogus, 0, 0);
|
|
3814 |
dimen_value--;
|
|
3815 |
value = MAKE_Object_ARRAY(dimen_value);
|
|
3816 |
|
|
3817 |
}
|
|
3818 |
if (GET_ITEM_TYPE(target) != ITEM_Object) {
|
|
3819 |
if (dimen_target == 0)
|
|
3820 |
return MAKE_FULLINFO(ITEM_Bogus, 0, 0);
|
|
3821 |
dimen_target--;
|
|
3822 |
target = MAKE_Object_ARRAY(dimen_target);
|
|
3823 |
}
|
|
3824 |
/* Both are now objects or arrays of some sort of object type */
|
|
3825 |
value_base = WITH_ZERO_INDIRECTION(value);
|
|
3826 |
target_base = WITH_ZERO_INDIRECTION(target);
|
|
3827 |
if (dimen_value == dimen_target) {
|
|
3828 |
/* Arrays of the same dimension. Merge their base types. */
|
|
3829 |
fullinfo_type result_base =
|
|
3830 |
merge_fullinfo_types(context, value_base, target_base,
|
|
3831 |
for_assignment);
|
|
3832 |
if (result_base == MAKE_FULLINFO(ITEM_Bogus, 0, 0))
|
|
3833 |
/* bogus in, bogus out */
|
|
3834 |
return result_base;
|
|
3835 |
return MAKE_FULLINFO(ITEM_Object, dimen_value,
|
|
3836 |
GET_EXTRA_INFO(result_base));
|
|
3837 |
} else {
|
|
3838 |
/* Arrays of different sizes. If the smaller dimension array's base
|
|
3839 |
* type is java/lang/Cloneable or java/io/Serializable, return it.
|
|
3840 |
* Otherwise return java/lang/Object with a dimension of the smaller
|
|
3841 |
* of the two */
|
|
3842 |
if (dimen_value < dimen_target) {
|
|
3843 |
if (value_base == context->cloneable_info ||
|
|
3844 |
value_base == context ->serializable_info) {
|
|
3845 |
return value;
|
|
3846 |
}
|
|
3847 |
return MAKE_Object_ARRAY(dimen_value);
|
|
3848 |
} else {
|
|
3849 |
if (target_base == context->cloneable_info ||
|
|
3850 |
target_base == context->serializable_info) {
|
|
3851 |
return target;
|
|
3852 |
}
|
|
3853 |
return MAKE_Object_ARRAY(dimen_target);
|
|
3854 |
}
|
|
3855 |
}
|
|
3856 |
} else {
|
|
3857 |
/* Both are non-array objects. Neither is java/lang/Object or NULL */
|
|
3858 |
jclass cb_value, cb_target, cb_super_value, cb_super_target;
|
|
3859 |
fullinfo_type result_info;
|
|
3860 |
|
|
3861 |
/* Let's get the classes corresponding to each of these. Treat
|
|
3862 |
* interfaces as if they were java/lang/Object. See hack note above. */
|
|
3863 |
cb_target = object_fullinfo_to_classclass(context, target);
|
|
3864 |
if (cb_target == 0)
|
|
3865 |
return MAKE_FULLINFO(ITEM_Bogus, 0, 0);
|
|
3866 |
if (JVM_IsInterface(env, cb_target))
|
|
3867 |
return for_assignment ? target : context->object_info;
|
|
3868 |
cb_value = object_fullinfo_to_classclass(context, value);
|
|
3869 |
if (cb_value == 0)
|
|
3870 |
return MAKE_FULLINFO(ITEM_Bogus, 0, 0);
|
|
3871 |
if (JVM_IsInterface(env, cb_value))
|
|
3872 |
return context->object_info;
|
|
3873 |
|
|
3874 |
/* If this is for assignment of target := value, we just need to see if
|
|
3875 |
* cb_target is a superclass of cb_value. Save ourselves a lot of
|
|
3876 |
* work.
|
|
3877 |
*/
|
|
3878 |
if (for_assignment) {
|
|
3879 |
cb_super_value = (*env)->GetSuperclass(env, cb_value);
|
|
3880 |
while (cb_super_value != 0) {
|
|
3881 |
jclass tmp_cb;
|
|
3882 |
if ((*env)->IsSameObject(env, cb_super_value, cb_target)) {
|
|
3883 |
(*env)->DeleteLocalRef(env, cb_super_value);
|
|
3884 |
return target;
|
|
3885 |
}
|
|
3886 |
tmp_cb = (*env)->GetSuperclass(env, cb_super_value);
|
|
3887 |
(*env)->DeleteLocalRef(env, cb_super_value);
|
|
3888 |
cb_super_value = tmp_cb;
|
|
3889 |
}
|
|
3890 |
(*env)->DeleteLocalRef(env, cb_super_value);
|
|
3891 |
return context->object_info;
|
|
3892 |
}
|
|
3893 |
|
|
3894 |
/* Find out whether cb_value or cb_target is deeper in the class
|
|
3895 |
* tree by moving both toward the root, and seeing who gets there
|
|
3896 |
* first. */
|
|
3897 |
cb_super_value = (*env)->GetSuperclass(env, cb_value);
|
|
3898 |
cb_super_target = (*env)->GetSuperclass(env, cb_target);
|
|
3899 |
while((cb_super_value != 0) &&
|
|
3900 |
(cb_super_target != 0)) {
|
|
3901 |
jclass tmp_cb;
|
|
3902 |
/* Optimization. If either hits the other when going up looking
|
|
3903 |
* for a parent, then might as well return the parent immediately */
|
|
3904 |
if ((*env)->IsSameObject(env, cb_super_value, cb_target)) {
|
|
3905 |
(*env)->DeleteLocalRef(env, cb_super_value);
|
|
3906 |
(*env)->DeleteLocalRef(env, cb_super_target);
|
|
3907 |
return target;
|
|
3908 |
}
|
|
3909 |
if ((*env)->IsSameObject(env, cb_super_target, cb_value)) {
|
|
3910 |
(*env)->DeleteLocalRef(env, cb_super_value);
|
|
3911 |
(*env)->DeleteLocalRef(env, cb_super_target);
|
|
3912 |
return value;
|
|
3913 |
}
|
|
3914 |
tmp_cb = (*env)->GetSuperclass(env, cb_super_value);
|
|
3915 |
(*env)->DeleteLocalRef(env, cb_super_value);
|
|
3916 |
cb_super_value = tmp_cb;
|
|
3917 |
|
|
3918 |
tmp_cb = (*env)->GetSuperclass(env, cb_super_target);
|
|
3919 |
(*env)->DeleteLocalRef(env, cb_super_target);
|
|
3920 |
cb_super_target = tmp_cb;
|
|
3921 |
}
|
|
3922 |
cb_value = (*env)->NewLocalRef(env, cb_value);
|
|
3923 |
cb_target = (*env)->NewLocalRef(env, cb_target);
|
|
3924 |
/* At most one of the following two while clauses will be executed.
|
|
3925 |
* Bring the deeper of cb_target and cb_value to the depth of the
|
|
3926 |
* shallower one.
|
|
3927 |
*/
|
|
3928 |
while (cb_super_value != 0) {
|
|
3929 |
/* cb_value is deeper */
|
|
3930 |
jclass cb_tmp;
|
|
3931 |
|
|
3932 |
cb_tmp = (*env)->GetSuperclass(env, cb_super_value);
|
|
3933 |
(*env)->DeleteLocalRef(env, cb_super_value);
|
|
3934 |
cb_super_value = cb_tmp;
|
|
3935 |
|
|
3936 |
cb_tmp = (*env)->GetSuperclass(env, cb_value);
|
|
3937 |
(*env)->DeleteLocalRef(env, cb_value);
|
|
3938 |
cb_value = cb_tmp;
|
|
3939 |
}
|
|
3940 |
while (cb_super_target != 0) {
|
|
3941 |
/* cb_target is deeper */
|
|
3942 |
jclass cb_tmp;
|
|
3943 |
|
|
3944 |
cb_tmp = (*env)->GetSuperclass(env, cb_super_target);
|
|
3945 |
(*env)->DeleteLocalRef(env, cb_super_target);
|
|
3946 |
cb_super_target = cb_tmp;
|
|
3947 |
|
|
3948 |
cb_tmp = (*env)->GetSuperclass(env, cb_target);
|
|
3949 |
(*env)->DeleteLocalRef(env, cb_target);
|
|
3950 |
cb_target = cb_tmp;
|
|
3951 |
}
|
|
3952 |
|
|
3953 |
/* Walk both up, maintaining equal depth, until a join is found. We
|
|
3954 |
* know that we will find one. */
|
|
3955 |
while (!(*env)->IsSameObject(env, cb_value, cb_target)) {
|
|
3956 |
jclass cb_tmp;
|
|
3957 |
cb_tmp = (*env)->GetSuperclass(env, cb_value);
|
|
3958 |
(*env)->DeleteLocalRef(env, cb_value);
|
|
3959 |
cb_value = cb_tmp;
|
|
3960 |
cb_tmp = (*env)->GetSuperclass(env, cb_target);
|
|
3961 |
(*env)->DeleteLocalRef(env, cb_target);
|
|
3962 |
cb_target = cb_tmp;
|
|
3963 |
}
|
|
3964 |
result_info = make_class_info(context, cb_value);
|
|
3965 |
(*env)->DeleteLocalRef(env, cb_value);
|
|
3966 |
(*env)->DeleteLocalRef(env, cb_super_value);
|
|
3967 |
(*env)->DeleteLocalRef(env, cb_target);
|
|
3968 |
(*env)->DeleteLocalRef(env, cb_super_target);
|
|
3969 |
return result_info;
|
|
3970 |
} /* both items are classes */
|
|
3971 |
}
|
|
3972 |
|
|
3973 |
|
|
3974 |
/* Given a fullinfo_type corresponding to an Object, return the jclass
|
|
3975 |
* of that type.
|
|
3976 |
*
|
|
3977 |
* This function always returns a global reference!
|
|
3978 |
*/
|
|
3979 |
|
|
3980 |
static jclass
|
|
3981 |
object_fullinfo_to_classclass(context_type *context, fullinfo_type classinfo)
|
|
3982 |
{
|
|
3983 |
unsigned short info = GET_EXTRA_INFO(classinfo);
|
|
3984 |
return ID_to_class(context, info);
|
|
3985 |
}
|
|
3986 |
|
|
3987 |
static void free_block(void *ptr, int kind)
|
|
3988 |
{
|
|
3989 |
switch (kind) {
|
|
3990 |
case VM_STRING_UTF:
|
|
3991 |
JVM_ReleaseUTF(ptr);
|
|
3992 |
break;
|
|
3993 |
case VM_MALLOC_BLK:
|
|
3994 |
free(ptr);
|
|
3995 |
break;
|
|
3996 |
}
|
|
3997 |
}
|
|
3998 |
|
|
3999 |
static void check_and_push(context_type *context, const void *ptr, int kind)
|
|
4000 |
{
|
|
4001 |
alloc_stack_type *p;
|
|
4002 |
if (ptr == 0)
|
|
4003 |
CCout_of_memory(context);
|
|
4004 |
if (context->alloc_stack_top < ALLOC_STACK_SIZE)
|
|
4005 |
p = &(context->alloc_stack[context->alloc_stack_top++]);
|
|
4006 |
else {
|
|
4007 |
/* Otherwise we have to malloc */
|
|
4008 |
p = malloc(sizeof(alloc_stack_type));
|
|
4009 |
if (p == 0) {
|
|
4010 |
/* Make sure we clean up. */
|
|
4011 |
free_block((void *)ptr, kind);
|
|
4012 |
CCout_of_memory(context);
|
|
4013 |
}
|
|
4014 |
}
|
|
4015 |
p->kind = kind;
|
|
4016 |
p->ptr = (void *)ptr;
|
|
4017 |
p->next = context->allocated_memory;
|
|
4018 |
context->allocated_memory = p;
|
|
4019 |
}
|
|
4020 |
|
|
4021 |
static void pop_and_free(context_type *context)
|
|
4022 |
{
|
|
4023 |
alloc_stack_type *p = context->allocated_memory;
|
|
4024 |
context->allocated_memory = p->next;
|
|
4025 |
free_block(p->ptr, p->kind);
|
|
4026 |
if (p < context->alloc_stack + ALLOC_STACK_SIZE &&
|
|
4027 |
p >= context->alloc_stack)
|
|
4028 |
context->alloc_stack_top--;
|
|
4029 |
else
|
|
4030 |
free(p);
|
|
4031 |
}
|
|
4032 |
|
|
4033 |
static int signature_to_args_size(const char *method_signature)
|
|
4034 |
{
|
|
4035 |
const char *p;
|
|
4036 |
int args_size = 0;
|
|
4037 |
for (p = method_signature; *p != JVM_SIGNATURE_ENDFUNC; p++) {
|
|
4038 |
switch (*p) {
|
|
4039 |
case JVM_SIGNATURE_BOOLEAN:
|
|
4040 |
case JVM_SIGNATURE_BYTE:
|
|
4041 |
case JVM_SIGNATURE_CHAR:
|
|
4042 |
case JVM_SIGNATURE_SHORT:
|
|
4043 |
case JVM_SIGNATURE_INT:
|
|
4044 |
case JVM_SIGNATURE_FLOAT:
|
|
4045 |
args_size += 1;
|
|
4046 |
break;
|
|
4047 |
case JVM_SIGNATURE_CLASS:
|
|
4048 |
args_size += 1;
|
|
4049 |
while (*p != JVM_SIGNATURE_ENDCLASS) p++;
|
|
4050 |
break;
|
|
4051 |
case JVM_SIGNATURE_ARRAY:
|
|
4052 |
args_size += 1;
|
|
4053 |
while ((*p == JVM_SIGNATURE_ARRAY)) p++;
|
|
4054 |
/* If an array of classes, skip over class name, too. */
|
|
4055 |
if (*p == JVM_SIGNATURE_CLASS) {
|
|
4056 |
while (*p != JVM_SIGNATURE_ENDCLASS)
|
|
4057 |
p++;
|
|
4058 |
}
|
|
4059 |
break;
|
|
4060 |
case JVM_SIGNATURE_DOUBLE:
|
|
4061 |
case JVM_SIGNATURE_LONG:
|
|
4062 |
args_size += 2;
|
|
4063 |
break;
|
|
4064 |
case JVM_SIGNATURE_FUNC: /* ignore initial (, if given */
|
|
4065 |
break;
|
|
4066 |
default:
|
|
4067 |
/* Indicate an error. */
|
|
4068 |
return 0;
|
|
4069 |
}
|
|
4070 |
}
|
|
4071 |
return args_size;
|
|
4072 |
}
|
|
4073 |
|
|
4074 |
#ifdef DEBUG
|
|
4075 |
|
|
4076 |
/* Below are for debugging. */
|
|
4077 |
|
|
4078 |
static void print_fullinfo_type(context_type *, fullinfo_type, jboolean);
|
|
4079 |
|
|
4080 |
static void
|
|
4081 |
print_stack(context_type *context, stack_info_type *stack_info)
|
|
4082 |
{
|
|
4083 |
stack_item_type *stack = stack_info->stack;
|
|
4084 |
if (stack_info->stack_size == UNKNOWN_STACK_SIZE) {
|
|
4085 |
jio_fprintf(stdout, "x");
|
|
4086 |
} else {
|
|
4087 |
jio_fprintf(stdout, "(");
|
|
4088 |
for ( ; stack != 0; stack = stack->next)
|
|
4089 |
print_fullinfo_type(context, stack->item,
|
|
4090 |
(jboolean)(verify_verbose > 1 ? JNI_TRUE : JNI_FALSE));
|
|
4091 |
jio_fprintf(stdout, ")");
|
|
4092 |
}
|
|
4093 |
}
|
|
4094 |
|
|
4095 |
static void
|
|
4096 |
print_registers(context_type *context, register_info_type *register_info)
|
|
4097 |
{
|
|
4098 |
int register_count = register_info->register_count;
|
|
4099 |
if (register_count == UNKNOWN_REGISTER_COUNT) {
|
|
4100 |
jio_fprintf(stdout, "x");
|
|
4101 |
} else {
|
|
4102 |
fullinfo_type *registers = register_info->registers;
|
|
4103 |
int mask_count = register_info->mask_count;
|
|
4104 |
mask_type *masks = register_info->masks;
|
|
4105 |
int i, j;
|
|
4106 |
|
|
4107 |
jio_fprintf(stdout, "{");
|
|
4108 |
for (i = 0; i < register_count; i++)
|
|
4109 |
print_fullinfo_type(context, registers[i],
|
|
4110 |
(jboolean)(verify_verbose > 1 ? JNI_TRUE : JNI_FALSE));
|
|
4111 |
jio_fprintf(stdout, "}");
|
|
4112 |
for (i = 0; i < mask_count; i++) {
|
|
4113 |
char *separator = "";
|
|
4114 |
int *modifies = masks[i].modifies;
|
|
4115 |
jio_fprintf(stdout, "<%d: ", masks[i].entry);
|
|
4116 |
for (j = 0;
|
|
4117 |
j < JVM_GetMethodIxLocalsCount(context->env,
|
|
4118 |
context->class,
|
|
4119 |
context->method_index);
|
|
4120 |
j++)
|
|
4121 |
if (IS_BIT_SET(modifies, j)) {
|
|
4122 |
jio_fprintf(stdout, "%s%d", separator, j);
|
|
4123 |
separator = ",";
|
|
4124 |
}
|
|
4125 |
jio_fprintf(stdout, ">");
|
|
4126 |
}
|
|
4127 |
}
|
|
4128 |
}
|
|
4129 |
|
|
4130 |
|
|
4131 |
static void
|
|
4132 |
print_flags(context_type *context, flag_type and_flags, flag_type or_flags)
|
|
4133 |
{
|
|
4134 |
if (and_flags != ((flag_type)-1) || or_flags != 0) {
|
|
4135 |
jio_fprintf(stdout, "<%x %x>", and_flags, or_flags);
|
|
4136 |
}
|
|
4137 |
}
|
|
4138 |
|
|
4139 |
static void
|
|
4140 |
print_fullinfo_type(context_type *context, fullinfo_type type, jboolean verbose)
|
|
4141 |
{
|
|
4142 |
int i;
|
|
4143 |
int indirection = GET_INDIRECTION(type);
|
|
4144 |
for (i = indirection; i-- > 0; )
|
|
4145 |
jio_fprintf(stdout, "[");
|
|
4146 |
switch (GET_ITEM_TYPE(type)) {
|
|
4147 |
case ITEM_Integer:
|
|
4148 |
jio_fprintf(stdout, "I"); break;
|
|
4149 |
case ITEM_Float:
|
|
4150 |
jio_fprintf(stdout, "F"); break;
|
|
4151 |
case ITEM_Double:
|
|
4152 |
jio_fprintf(stdout, "D"); break;
|
|
4153 |
case ITEM_Double_2:
|
|
4154 |
jio_fprintf(stdout, "d"); break;
|
|
4155 |
case ITEM_Long:
|
|
4156 |
jio_fprintf(stdout, "L"); break;
|
|
4157 |
case ITEM_Long_2:
|
|
4158 |
jio_fprintf(stdout, "l"); break;
|
|
4159 |
case ITEM_ReturnAddress:
|
|
4160 |
jio_fprintf(stdout, "a"); break;
|
|
4161 |
case ITEM_Object:
|
|
4162 |
if (!verbose) {
|
|
4163 |
jio_fprintf(stdout, "A");
|
|
4164 |
} else {
|
|
4165 |
unsigned short extra = GET_EXTRA_INFO(type);
|
|
4166 |
if (extra == 0) {
|
|
4167 |
jio_fprintf(stdout, "/Null/");
|
|
4168 |
} else {
|
|
4169 |
const char *name = ID_to_class_name(context, extra);
|
|
4170 |
const char *name2 = strrchr(name, '/');
|
|
4171 |
jio_fprintf(stdout, "/%s/", name2 ? name2 + 1 : name);
|
|
4172 |
}
|
|
4173 |
}
|
|
4174 |
break;
|
|
4175 |
case ITEM_Char:
|
|
4176 |
jio_fprintf(stdout, "C"); break;
|
|
4177 |
case ITEM_Short:
|
|
4178 |
jio_fprintf(stdout, "S"); break;
|
|
4179 |
case ITEM_Byte:
|
|
4180 |
jio_fprintf(stdout, "B"); break;
|
|
4181 |
case ITEM_NewObject:
|
|
4182 |
if (!verbose) {
|
|
4183 |
jio_fprintf(stdout, "@");
|
|
4184 |
} else {
|
|
4185 |
int inum = GET_EXTRA_INFO(type);
|
|
4186 |
fullinfo_type real_type =
|
|
4187 |
context->instruction_data[inum].operand2.fi;
|
|
4188 |
jio_fprintf(stdout, ">");
|
|
4189 |
print_fullinfo_type(context, real_type, JNI_TRUE);
|
|
4190 |
jio_fprintf(stdout, "<");
|
|
4191 |
}
|
|
4192 |
break;
|
|
4193 |
case ITEM_InitObject:
|
|
4194 |
jio_fprintf(stdout, verbose ? ">/this/<" : "@");
|
|
4195 |
break;
|
|
4196 |
|
|
4197 |
default:
|
|
4198 |
jio_fprintf(stdout, "?"); break;
|
|
4199 |
}
|
|
4200 |
for (i = indirection; i-- > 0; )
|
|
4201 |
jio_fprintf(stdout, "]");
|
|
4202 |
}
|
|
4203 |
|
|
4204 |
|
|
4205 |
static void
|
|
4206 |
print_formatted_fieldname(context_type *context, int index)
|
|
4207 |
{
|
|
4208 |
JNIEnv *env = context->env;
|
|
4209 |
jclass cb = context->class;
|
|
4210 |
const char *classname = JVM_GetCPFieldClassNameUTF(env, cb, index);
|
|
4211 |
const char *fieldname = JVM_GetCPFieldNameUTF(env, cb, index);
|
|
4212 |
jio_fprintf(stdout, " <%s.%s>",
|
|
4213 |
classname ? classname : "", fieldname ? fieldname : "");
|
|
4214 |
JVM_ReleaseUTF(classname);
|
|
4215 |
JVM_ReleaseUTF(fieldname);
|
|
4216 |
}
|
|
4217 |
|
|
4218 |
static void
|
|
4219 |
print_formatted_methodname(context_type *context, int index)
|
|
4220 |
{
|
|
4221 |
JNIEnv *env = context->env;
|
|
4222 |
jclass cb = context->class;
|
|
4223 |
const char *classname = JVM_GetCPMethodClassNameUTF(env, cb, index);
|
|
4224 |
const char *methodname = JVM_GetCPMethodNameUTF(env, cb, index);
|
|
4225 |
jio_fprintf(stdout, " <%s.%s>",
|
|
4226 |
classname ? classname : "", methodname ? methodname : "");
|
|
4227 |
JVM_ReleaseUTF(classname);
|
|
4228 |
JVM_ReleaseUTF(methodname);
|
|
4229 |
}
|
|
4230 |
|
|
4231 |
#endif /*DEBUG*/
|