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