src/hotspot/share/classfile/verifier.hpp
author psandoz
Fri, 08 Sep 2017 10:46:46 -0700
changeset 48826 c4d9d1b08e2e
parent 47216 71c04702a3d5
child 49364 601146c66cad
permissions -rw-r--r--
8186209: Tool support for ConstantDynamic 8186046: Minimal ConstantDynamic support 8190972: Ensure that AOT/Graal filters out class files containing CONSTANT_Dynamic ahead of full AOT support Reviewed-by: acorn, coleenp, kvn Contributed-by: lois.foltan@oracle.com, john.r.rose@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 40856
diff changeset
     2
 * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3820
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3820
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3820
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7380
diff changeset
    25
#ifndef SHARE_VM_CLASSFILE_VERIFIER_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7380
diff changeset
    26
#define SHARE_VM_CLASSFILE_VERIFIER_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7380
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7380
diff changeset
    28
#include "classfile/verificationType.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30102
diff changeset
    29
#include "gc/shared/gcLocker.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7380
diff changeset
    30
#include "oops/klass.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13476
diff changeset
    31
#include "oops/method.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7380
diff changeset
    32
#include "runtime/handles.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30102
diff changeset
    33
#include "utilities/exceptions.hpp"
25955
8ccc2eddcf22 8050485: super() in a try block in a ctor causes VerifyError
hseigel
parents: 25899
diff changeset
    34
#include "utilities/growableArray.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7380
diff changeset
    35
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// The verifier class
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
class Verifier : AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
 public:
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
    39
  enum {
17863
d77007cf03c1 8015385: Remove RelaxAccessControlCheck for JDK 8 bytecodes
hseigel
parents: 17370
diff changeset
    40
    STRICTER_ACCESS_CTRL_CHECK_VERSION  = 49,
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
    41
    STACKMAP_ATTRIBUTE_MAJOR_VERSION    = 50,
17863
d77007cf03c1 8015385: Remove RelaxAccessControlCheck for JDK 8 bytecodes
hseigel
parents: 17370
diff changeset
    42
    INVOKEDYNAMIC_MAJOR_VERSION         = 51,
48826
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 47216
diff changeset
    43
    NO_RELAX_ACCESS_CTRL_CHECK_VERSION  = 52,
c4d9d1b08e2e 8186209: Tool support for ConstantDynamic
psandoz
parents: 47216
diff changeset
    44
    DYNAMICCONSTANT_MAJOR_VERSION       = 55
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5702
diff changeset
    45
  };
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  typedef enum { ThrowException, NoException } Mode;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  /**
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
   * Verify the bytecodes for a class.  If 'throw_exception' is true
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
   * then the appropriate VerifyError or ClassFormatError will be thrown.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
   * Otherwise, no exception is thrown and the return indicates the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
   * error.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
   */
34628
6d08ec72803b 8142976: Reimplement TraceClassInitialization with Unified Logging
mockner
parents: 33593
diff changeset
    54
  static void log_end_verification(outputStream* st, const char* klassName, Symbol* exception_name, TRAPS);
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 40856
diff changeset
    55
  static bool verify(InstanceKlass* klass, Mode mode, bool should_verify_class, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
3820
0a8fbbe180db 6830542: Performance: JVM_DefineClass already verified.
acorn
parents: 1
diff changeset
    57
  // Return false if the class is loaded by the bootstrap loader,
0a8fbbe180db 6830542: Performance: JVM_DefineClass already verified.
acorn
parents: 1
diff changeset
    58
  // or if defineClass was called requesting skipping verification
0a8fbbe180db 6830542: Performance: JVM_DefineClass already verified.
acorn
parents: 1
diff changeset
    59
  // -Xverify:all/none override this value
0a8fbbe180db 6830542: Performance: JVM_DefineClass already verified.
acorn
parents: 1
diff changeset
    60
  static bool should_verify_for(oop class_loader, bool should_verify_class);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
40856
3378947a95e6 8148854: Class names "SomeClass" and "LSomeClass;" treated by JVM as an equivalent
rprotacio
parents: 38151
diff changeset
    62
  // Relax certain access checks to enable some broken 1.1 apps to run on 1.2.
3378947a95e6 8148854: Class names "SomeClass" and "LSomeClass;" treated by JVM as an equivalent
rprotacio
parents: 38151
diff changeset
    63
  static bool relax_access_for(oop class_loader);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 35219
diff changeset
    65
  // Print output for class+resolve
30616
fde3a4fee412 8076318: split verifier needs to add TraceClassResolution
hseigel
parents: 30102
diff changeset
    66
  static void trace_class_resolution(Klass* resolve_class, InstanceKlass* verify_class);
fde3a4fee412 8076318: split verifier needs to add TraceClassResolution
hseigel
parents: 30102
diff changeset
    67
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
 private:
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 40856
diff changeset
    69
  static bool is_eligible_for_verification(InstanceKlass* klass, bool should_verify_class);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    70
  static Symbol* inference_verify(
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 40856
diff changeset
    71
    InstanceKlass* klass, char* msg, size_t msg_len, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
class RawBytecodeStream;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
class StackMapFrame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
class StackMapTable;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
// Summary of verifier's memory usage:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
// StackMapTable is stack allocated.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    80
// StackMapFrame are resource allocated. There is only one ResourceMark
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    81
// for each class verification, which is created at the top level.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
// There is one mutable StackMapFrame (current_frame) which is updated
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
// by abstract bytecode interpretation. frame_in_exception_handler() returns
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
// a frame that has a mutable one-item stack (ready for pushing the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
// catch type exception object). All the other StackMapFrame's
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
// are immutable (including their locals and stack arrays) after
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
// their constructions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
// locals/stack arrays in StackMapFrame are resource allocated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
// locals/stack arrays can be shared between StackMapFrame's, except
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
// the mutable StackMapFrame (current_frame).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
// These macros are used similarly to CHECK macros but also check
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
// the status of the verifier and return if that has an error.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
#define CHECK_VERIFY(verifier) \
18073
f02460441ddc 8014431: cleanup warnings indicated by the -Wunused-value compiler option on linux
ccheung
parents: 17863
diff changeset
    95
  CHECK); if ((verifier)->has_error()) return; ((void)0
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
#define CHECK_VERIFY_(verifier, result) \
18073
f02460441ddc 8014431: cleanup warnings indicated by the -Wunused-value compiler option on linux
ccheung
parents: 17863
diff changeset
    97
  CHECK_(result)); if ((verifier)->has_error()) return (result); ((void)0
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
    99
class TypeOrigin VALUE_OBJ_CLASS_SPEC {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   100
 private:
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   101
  typedef enum {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   102
    CF_LOCALS,  // Comes from the current frame locals
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   103
    CF_STACK,   // Comes from the current frame expression stack
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   104
    SM_LOCALS,  // Comes from stackmap locals
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   105
    SM_STACK,   // Comes from stackmap expression stack
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   106
    CONST_POOL, // Comes from the constant pool
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   107
    SIG,        // Comes from method signature
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   108
    IMPLICIT,   // Comes implicitly from code or context
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   109
    BAD_INDEX,  // No type, but the index is bad
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   110
    FRAME_ONLY, // No type, context just contains the frame
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   111
    NONE
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   112
  } Origin;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   113
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   114
  Origin _origin;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   115
  u2 _index;              // local, stack, or constant pool index
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   116
  StackMapFrame* _frame;  // source frame if CF or SM
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   117
  VerificationType _type; // The actual type
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   118
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   119
  TypeOrigin(
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   120
      Origin origin, u2 index, StackMapFrame* frame, VerificationType type)
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   121
      : _origin(origin), _index(index), _frame(frame), _type(type) {}
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   122
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   123
 public:
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   124
  TypeOrigin() : _origin(NONE), _index(0), _frame(NULL) {}
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   125
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   126
  static TypeOrigin null();
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   127
  static TypeOrigin local(u2 index, StackMapFrame* frame);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   128
  static TypeOrigin stack(u2 index, StackMapFrame* frame);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   129
  static TypeOrigin sm_local(u2 index, StackMapFrame* frame);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   130
  static TypeOrigin sm_stack(u2 index, StackMapFrame* frame);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   131
  static TypeOrigin cp(u2 index, VerificationType vt);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   132
  static TypeOrigin signature(VerificationType vt);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   133
  static TypeOrigin bad_index(u2 index);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   134
  static TypeOrigin implicit(VerificationType t);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   135
  static TypeOrigin frame(StackMapFrame* frame);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   136
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   137
  void reset_frame();
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   138
  void details(outputStream* ss) const;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   139
  void print_frame(outputStream* ss) const;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   140
  const StackMapFrame* frame() const { return _frame; }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   141
  bool is_valid() const { return _origin != NONE; }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   142
  u2 index() const { return _index; }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   143
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   144
#ifdef ASSERT
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   145
  void print_on(outputStream* str) const;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   146
#endif
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   147
};
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   148
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   149
class ErrorContext VALUE_OBJ_CLASS_SPEC {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   150
 private:
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   151
  typedef enum {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   152
    INVALID_BYTECODE,     // There was a problem with the bytecode
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   153
    WRONG_TYPE,           // Type value was not as expected
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   154
    FLAGS_MISMATCH,       // Frame flags are not assignable
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   155
    BAD_CP_INDEX,         // Invalid constant pool index
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   156
    BAD_LOCAL_INDEX,      // Invalid local index
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   157
    LOCALS_SIZE_MISMATCH, // Frames have differing local counts
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   158
    STACK_SIZE_MISMATCH,  // Frames have different stack sizes
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   159
    STACK_OVERFLOW,       // Attempt to push onto a full expression stack
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   160
    STACK_UNDERFLOW,      // Attempt to pop and empty expression stack
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   161
    MISSING_STACKMAP,     // No stackmap for this location and there should be
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   162
    BAD_STACKMAP,         // Format error in stackmap
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   163
    NO_FAULT,             // No error
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   164
    UNKNOWN
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   165
  } FaultType;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   166
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   167
  int _bci;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   168
  FaultType _fault;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   169
  TypeOrigin _type;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   170
  TypeOrigin _expected;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   171
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   172
  ErrorContext(int bci, FaultType fault) :
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   173
      _bci(bci), _fault(fault)  {}
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   174
  ErrorContext(int bci, FaultType fault, TypeOrigin type) :
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   175
      _bci(bci), _fault(fault), _type(type)  {}
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   176
  ErrorContext(int bci, FaultType fault, TypeOrigin type, TypeOrigin exp) :
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   177
      _bci(bci), _fault(fault), _type(type), _expected(exp)  {}
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   178
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   179
 public:
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   180
  ErrorContext() : _bci(-1), _fault(NO_FAULT) {}
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   181
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   182
  static ErrorContext bad_code(u2 bci) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   183
    return ErrorContext(bci, INVALID_BYTECODE);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   184
  }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   185
  static ErrorContext bad_type(u2 bci, TypeOrigin type) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   186
    return ErrorContext(bci, WRONG_TYPE, type);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   187
  }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   188
  static ErrorContext bad_type(u2 bci, TypeOrigin type, TypeOrigin exp) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   189
    return ErrorContext(bci, WRONG_TYPE, type, exp);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   190
  }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   191
  static ErrorContext bad_flags(u2 bci, StackMapFrame* frame) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   192
    return ErrorContext(bci, FLAGS_MISMATCH, TypeOrigin::frame(frame));
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   193
  }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   194
  static ErrorContext bad_flags(u2 bci, StackMapFrame* cur, StackMapFrame* sm) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   195
    return ErrorContext(bci, FLAGS_MISMATCH,
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   196
                        TypeOrigin::frame(cur), TypeOrigin::frame(sm));
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   197
  }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   198
  static ErrorContext bad_cp_index(u2 bci, u2 index) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   199
    return ErrorContext(bci, BAD_CP_INDEX, TypeOrigin::bad_index(index));
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   200
  }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   201
  static ErrorContext bad_local_index(u2 bci, u2 index) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   202
    return ErrorContext(bci, BAD_LOCAL_INDEX, TypeOrigin::bad_index(index));
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   203
  }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   204
  static ErrorContext locals_size_mismatch(
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   205
      u2 bci, StackMapFrame* frame0, StackMapFrame* frame1) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   206
    return ErrorContext(bci, LOCALS_SIZE_MISMATCH,
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   207
        TypeOrigin::frame(frame0), TypeOrigin::frame(frame1));
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   208
  }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   209
  static ErrorContext stack_size_mismatch(
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   210
      u2 bci, StackMapFrame* frame0, StackMapFrame* frame1) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   211
    return ErrorContext(bci, STACK_SIZE_MISMATCH,
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   212
        TypeOrigin::frame(frame0), TypeOrigin::frame(frame1));
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   213
  }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   214
  static ErrorContext stack_overflow(u2 bci, StackMapFrame* frame) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   215
    return ErrorContext(bci, STACK_OVERFLOW, TypeOrigin::frame(frame));
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   216
  }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   217
  static ErrorContext stack_underflow(u2 bci, StackMapFrame* frame) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   218
    return ErrorContext(bci, STACK_UNDERFLOW, TypeOrigin::frame(frame));
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   219
  }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   220
  static ErrorContext missing_stackmap(u2 bci) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   221
    return ErrorContext(bci, MISSING_STACKMAP);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   222
  }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   223
  static ErrorContext bad_stackmap(int index, StackMapFrame* frame) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   224
    return ErrorContext(0, BAD_STACKMAP, TypeOrigin::frame(frame));
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   225
  }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   226
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   227
  bool is_valid() const { return _fault != NO_FAULT; }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   228
  int bci() const { return _bci; }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   229
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   230
  void reset_frames() {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   231
    _type.reset_frame();
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   232
    _expected.reset_frame();
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   233
  }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   234
17370
59a0620561fa 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 13728
diff changeset
   235
  void details(outputStream* ss, const Method* method) const;
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   236
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   237
#ifdef ASSERT
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   238
  void print_on(outputStream* str) const {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   239
    str->print("error_context(%d, %d,", _bci, _fault);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   240
    _type.print_on(str);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   241
    str->print(",");
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   242
    _expected.print_on(str);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   243
    str->print(")");
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   244
  }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   245
#endif
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   246
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   247
 private:
17370
59a0620561fa 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 13728
diff changeset
   248
  void location_details(outputStream* ss, const Method* method) const;
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   249
  void reason_details(outputStream* ss) const;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   250
  void frame_details(outputStream* ss) const;
17370
59a0620561fa 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 13728
diff changeset
   251
  void bytecode_details(outputStream* ss, const Method* method) const;
59a0620561fa 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 13728
diff changeset
   252
  void handler_details(outputStream* ss, const Method* method) const;
59a0620561fa 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 13728
diff changeset
   253
  void stackmap_details(outputStream* ss, const Method* method) const;
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   254
};
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   255
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
// A new instance of this class is created for each class being verified
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
class ClassVerifier : public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  Thread* _thread;
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   260
  GrowableArray<Symbol*>* _symbols;  // keep a list of symbols created
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   261
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   262
  Symbol* _exception_type;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  char* _message;
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   264
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   265
  ErrorContext _error_context;  // contains information about an error
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 30768
diff changeset
   267
  void verify_method(const methodHandle& method, TRAPS);
35194
7151995ee79e 8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents: 34628
diff changeset
   268
  char* generate_code_data(const methodHandle& m, u4 code_length, TRAPS);
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   269
  void verify_exception_handler_table(u4 code_length, char* code_data,
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   270
                                      int& min, int& max, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  void verify_local_variable_table(u4 code_length, char* code_data, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  VerificationType cp_ref_index_to_type(
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 30768
diff changeset
   274
      int index, const constantPoolHandle& cp, TRAPS) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    return cp_index_to_type(cp->klass_ref_index_at(index), cp, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  bool is_protected_access(
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 40856
diff changeset
   279
    InstanceKlass* this_class, Klass* target_class,
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   280
    Symbol* field_name, Symbol* field_sig, bool is_method);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 30768
diff changeset
   282
  void verify_cp_index(u2 bci, const constantPoolHandle& cp, int index, TRAPS);
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 30768
diff changeset
   283
  void verify_cp_type(u2 bci, int index, const constantPoolHandle& cp,
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   284
      unsigned int types, TRAPS);
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 30768
diff changeset
   285
  void verify_cp_class_type(u2 bci, int index, const constantPoolHandle& cp, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  u2 verify_stackmap_table(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    u2 stackmap_index, u2 bci, StackMapFrame* current_frame,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    StackMapTable* stackmap_table, bool no_control_flow, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  void verify_exception_handler_targets(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    u2 bci, bool this_uninit, StackMapFrame* current_frame,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    StackMapTable* stackmap_table, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  void verify_ldc(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    int opcode, u2 index, StackMapFrame *current_frame,
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 30768
diff changeset
   297
    const constantPoolHandle& cp, u2 bci, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  void verify_switch(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    RawBytecodeStream* bcs, u4 code_length, char* code_data,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    StackMapFrame* current_frame, StackMapTable* stackmap_table, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  void verify_field_instructions(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    RawBytecodeStream* bcs, StackMapFrame* current_frame,
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 30768
diff changeset
   305
    const constantPoolHandle& cp, bool allow_arrays, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  void verify_invoke_init(
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   308
    RawBytecodeStream* bcs, u2 ref_index, VerificationType ref_class_type,
28512
968fe01e1f82 8058982: Better verification of an exceptional invokespecial
hseigel
parents: 26928
diff changeset
   309
    StackMapFrame* current_frame, u4 code_length, bool in_try_block,
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 30768
diff changeset
   310
    bool* this_uninit, const constantPoolHandle& cp, StackMapTable* stackmap_table,
28512
968fe01e1f82 8058982: Better verification of an exceptional invokespecial
hseigel
parents: 26928
diff changeset
   311
    TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
30102
d932845db0fe 8075118: JVM stuck in infinite loop during verification
hseigel
parents: 28652
diff changeset
   313
  // Used by ends_in_athrow() to push all handlers that contain bci onto the
d932845db0fe 8075118: JVM stuck in infinite loop during verification
hseigel
parents: 28652
diff changeset
   314
  // handler_stack, if the handler has not already been pushed on the stack.
25955
8ccc2eddcf22 8050485: super() in a try block in a ctor causes VerifyError
hseigel
parents: 25899
diff changeset
   315
  void push_handlers(ExceptionTable* exhandlers,
30102
d932845db0fe 8075118: JVM stuck in infinite loop during verification
hseigel
parents: 28652
diff changeset
   316
                     GrowableArray<u4>* handler_list,
25955
8ccc2eddcf22 8050485: super() in a try block in a ctor causes VerifyError
hseigel
parents: 25899
diff changeset
   317
                     GrowableArray<u4>* handler_stack,
8ccc2eddcf22 8050485: super() in a try block in a ctor causes VerifyError
hseigel
parents: 25899
diff changeset
   318
                     u4 bci);
8ccc2eddcf22 8050485: super() in a try block in a ctor causes VerifyError
hseigel
parents: 25899
diff changeset
   319
8ccc2eddcf22 8050485: super() in a try block in a ctor causes VerifyError
hseigel
parents: 25899
diff changeset
   320
  // Returns true if all paths starting with start_bc_offset end in athrow
8ccc2eddcf22 8050485: super() in a try block in a ctor causes VerifyError
hseigel
parents: 25899
diff changeset
   321
  // bytecode or loop.
8ccc2eddcf22 8050485: super() in a try block in a ctor causes VerifyError
hseigel
parents: 25899
diff changeset
   322
  bool ends_in_athrow(u4 start_bc_offset);
8ccc2eddcf22 8050485: super() in a try block in a ctor causes VerifyError
hseigel
parents: 25899
diff changeset
   323
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  void verify_invoke_instructions(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame,
28512
968fe01e1f82 8058982: Better verification of an exceptional invokespecial
hseigel
parents: 26928
diff changeset
   326
    bool in_try_block, bool* this_uninit, VerificationType return_type,
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 30768
diff changeset
   327
    const constantPoolHandle& cp, StackMapTable* stackmap_table, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  VerificationType get_newarray_type(u2 index, u2 bci, TRAPS);
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 30768
diff changeset
   330
  void verify_anewarray(u2 bci, u2 index, const constantPoolHandle& cp,
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   331
      StackMapFrame* current_frame, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  void verify_return_value(
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   333
      VerificationType return_type, VerificationType type, u2 offset,
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   334
      StackMapFrame* current_frame, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  void verify_iload (u2 index, StackMapFrame* current_frame, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  void verify_lload (u2 index, StackMapFrame* current_frame, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  void verify_fload (u2 index, StackMapFrame* current_frame, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  void verify_dload (u2 index, StackMapFrame* current_frame, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  void verify_aload (u2 index, StackMapFrame* current_frame, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  void verify_istore(u2 index, StackMapFrame* current_frame, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  void verify_lstore(u2 index, StackMapFrame* current_frame, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  void verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  void verify_dstore(u2 index, StackMapFrame* current_frame, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  void verify_astore(u2 index, StackMapFrame* current_frame, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  void verify_iinc  (u2 index, StackMapFrame* current_frame, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 40856
diff changeset
   348
  bool name_in_supers(Symbol* ref_name, InstanceKlass* current);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
7380
041cf7f1cce6 6865028: Illegal instructions passing verification prior to 'invokespecial Object.<init>'
kamg
parents: 5882
diff changeset
   350
  VerificationType object_type() const;
041cf7f1cce6 6865028: Illegal instructions passing verification prior to 'invokespecial Object.<init>'
kamg
parents: 5882
diff changeset
   351
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 40856
diff changeset
   352
  InstanceKlass*      _klass;  // the class being verified
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  methodHandle        _method; // current method being verified
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  VerificationType    _this_type; // the verification type of the current class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
5693
3015c564fcbc 6956164: nightly regressions from 6939207
jrose
parents: 3820
diff changeset
   356
  // Some recursive calls from the verifier to the name resolver
3015c564fcbc 6956164: nightly regressions from 6939207
jrose
parents: 3820
diff changeset
   357
  // can cause the current class to be re-verified and rewritten.
3015c564fcbc 6956164: nightly regressions from 6939207
jrose
parents: 3820
diff changeset
   358
  // If this happens, the original verification should not continue,
3015c564fcbc 6956164: nightly regressions from 6939207
jrose
parents: 3820
diff changeset
   359
  // because constant pool indexes will have changed.
3015c564fcbc 6956164: nightly regressions from 6939207
jrose
parents: 3820
diff changeset
   360
  // The rewriter is preceded by the verifier.  If the verifier throws
3015c564fcbc 6956164: nightly regressions from 6939207
jrose
parents: 3820
diff changeset
   361
  // an error, rewriting is prevented.  Also, rewriting always precedes
3015c564fcbc 6956164: nightly regressions from 6939207
jrose
parents: 3820
diff changeset
   362
  // bytecode execution or compilation.  Thus, is_rewritten implies
3015c564fcbc 6956164: nightly regressions from 6939207
jrose
parents: 3820
diff changeset
   363
  // that a class has been verified and prepared for execution.
3015c564fcbc 6956164: nightly regressions from 6939207
jrose
parents: 3820
diff changeset
   364
  bool was_recursively_verified() { return _klass->is_rewritten(); }
3015c564fcbc 6956164: nightly regressions from 6939207
jrose
parents: 3820
diff changeset
   365
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 40856
diff changeset
   366
  bool is_same_or_direct_interface(InstanceKlass* klass,
21768
b7dba4cde1c6 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 18073
diff changeset
   367
    VerificationType klass_type, VerificationType ref_class_type);
b7dba4cde1c6 8026065: InterfaceMethodref for invokespecial must name a direct superinterface
hseigel
parents: 18073
diff changeset
   368
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
    BYTECODE_OFFSET = 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
    NEW_OFFSET = 2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  // constructor
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 40856
diff changeset
   376
  ClassVerifier(InstanceKlass* klass, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  // destructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  ~ClassVerifier();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  Thread* thread()             { return _thread; }
35194
7151995ee79e 8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents: 34628
diff changeset
   382
  const methodHandle& method() { return _method; }
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 40856
diff changeset
   383
  InstanceKlass* current_class() const { return _klass; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  VerificationType current_type() const { return _this_type; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  // Verifies the class.  If a verify or class file format error occurs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  // the '_exception_name' symbols will set to the exception name and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  // the message_buffer will be filled in with the exception message.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  void verify_class(TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  // Return status modes
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   392
  Symbol* result() const { return _exception_type; }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   393
  bool has_error() const { return result() != NULL; }
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   394
  char* exception_message() {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   395
    stringStream ss;
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 21768
diff changeset
   396
    ss.print("%s", _message);
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   397
    _error_context.details(&ss, _method());
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   398
    return ss.as_string();
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   399
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  // Called when verify or class format errors are encountered.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  // May throw an exception based upon the mode.
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 21768
diff changeset
   403
  void verify_error(ErrorContext ctx, const char* fmt, ...) ATTRIBUTE_PRINTF(3, 4);
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 21768
diff changeset
   404
  void class_format_error(const char* fmt, ...) ATTRIBUTE_PRINTF(2, 3);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13476
diff changeset
   406
  Klass* load_class(Symbol* name, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  int change_sig_to_verificationType(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
    SignatureStream* sig_type, VerificationType* inference_type, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 30768
diff changeset
   411
  VerificationType cp_index_to_type(int index, const constantPoolHandle& cp, TRAPS) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   412
    return VerificationType::reference_type(cp->klass_name_at(index));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   415
  // Keep a list of temporary symbols created during verification because
26928
744b310d4fdd 8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents: 25955
diff changeset
   416
  // their reference counts need to be decremented when the verifier object
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   417
  // goes out of scope.  Since these symbols escape the scope in which they're
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   418
  // created, we can't use a TempNewSymbol.
26928
744b310d4fdd 8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents: 25955
diff changeset
   419
  Symbol* create_temporary_symbol(const Symbol* s, int begin, int end, TRAPS);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   420
  Symbol* create_temporary_symbol(const char *s, int length, TRAPS);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   421
26928
744b310d4fdd 8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents: 25955
diff changeset
   422
  Symbol* create_temporary_symbol(Symbol* s) {
744b310d4fdd 8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents: 25955
diff changeset
   423
    // This version just updates the reference count and saves the symbol to be
744b310d4fdd 8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents: 25955
diff changeset
   424
    // dereferenced later.
744b310d4fdd 8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents: 25955
diff changeset
   425
    s->increment_refcount();
744b310d4fdd 8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents: 25955
diff changeset
   426
    _symbols->push(s);
744b310d4fdd 8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents: 25955
diff changeset
   427
    return s;
744b310d4fdd 8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents: 25955
diff changeset
   428
  }
744b310d4fdd 8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents: 25955
diff changeset
   429
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   430
  TypeOrigin ref_ctx(const char* str, TRAPS);
25505
9bd829aeb960 8035119: Fix exceptions to bytecode verification
hseigel
parents: 24424
diff changeset
   431
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
inline int ClassVerifier::change_sig_to_verificationType(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
    SignatureStream* sig_type, VerificationType* inference_type, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  BasicType bt = sig_type->type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  switch (bt) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
    case T_OBJECT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
    case T_ARRAY:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
      {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   441
        Symbol* name = sig_type->as_symbol(CHECK_0);
26928
744b310d4fdd 8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents: 25955
diff changeset
   442
        // Create another symbol to save as signature stream unreferences this symbol.
744b310d4fdd 8057846: ClassVerifier::change_sig_to_verificationType temporary symbol creation code is hot
coleenp
parents: 25955
diff changeset
   443
        Symbol* name_copy = create_temporary_symbol(name);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   444
        assert(name_copy == name, "symbols don't match");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
        *inference_type =
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   446
          VerificationType::reference_type(name_copy);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
        return 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
    case T_LONG:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
      *inference_type = VerificationType::long_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
      *++inference_type = VerificationType::long2_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
      return 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    case T_DOUBLE:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
      *inference_type = VerificationType::double_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
      *++inference_type = VerificationType::double2_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
      return 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
    case T_INT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
    case T_BOOLEAN:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
    case T_BYTE:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
    case T_CHAR:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
    case T_SHORT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
      *inference_type = VerificationType::integer_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
      return 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    case T_FLOAT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
      *inference_type = VerificationType::float_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
      return 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
      return 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
}
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7380
diff changeset
   472
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7380
diff changeset
   473
#endif // SHARE_VM_CLASSFILE_VERIFIER_HPP