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