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